home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / gfx / misc / imagefx_sdk / sas / examples / xstyle / apus.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-15  |  7.0 KB  |  323 lines

  1. /*
  2.  * Rub-Through Drawing Style
  3.  *
  4.  * Brings swap buffer pixels into the main buffer.
  5.  *
  6.  * Revision History:
  7.  *
  8.  *    02.01.94 tek   Fixed enforcer hits caused by using Mask instead of BMask.
  9.  *
  10.  */
  11.  
  12. #include <exec/types.h>
  13. #include <scan/modall.h>
  14. #include <scan/drawinfo.h>
  15. #include <string.h>
  16. #include "common.h"
  17.  
  18. /**********************************************************************\
  19.  
  20.                                 Library Vectors
  21.  
  22. \**********************************************************************/
  23.  
  24. /*
  25.  * XDM_Attr:
  26.  *
  27.  * Return to ImageFX some information about the Drawing Style (eg.
  28.  * whether Options are needed, whether we work on greyscale or
  29.  * color, etc.).  Called when ImageFX first scans the drawing
  30.  * style directory.
  31.  *
  32.  */
  33. ULONG __saveds __asm XDS_Attr (register __a0 struct XDrawAttr *attr)
  34. {
  35.    attr->Flags    = 0;
  36.    attr->Priority = 125;
  37.    return(0);
  38. }
  39.  
  40. /*
  41.  * XDS_Begin:
  42.  *
  43.  * Prepare before a pixel affecting operation.
  44.  *
  45.  */
  46. int __saveds __asm XDS_Begin (register __a0 struct IDrawInfo *di)
  47. {
  48.    return(1);
  49. }
  50.  
  51. /*
  52.  * XDS_End:
  53.  *
  54.  * Cleanup after a pixel affecting operation.
  55.  *
  56.  */
  57. void __saveds __asm XDS_End (register __a0 struct IDrawInfo *di)
  58. {
  59. }
  60.  
  61. /*
  62.  * XDS_Get:
  63.  *
  64.  *
  65.  */
  66. int __saveds __asm XDS_Get (register __a0 struct IDrawInfo *di)
  67. {
  68.    struct Buffer *buf = ScanBase->MainBuffer;
  69.    struct Buffer *sbuf = ScanBase->SwapBuffer;
  70.    UBYTE *red, *grn, *blu;
  71.    int i, j;
  72.    UBYTE *rp, *gp, *bp;
  73.    UBYTE *maskptr;
  74.    LONG totalr, totalg, totalb, num;
  75.  
  76.    if (!buf) return(0);
  77.    if (!sbuf) return(0);
  78.  
  79.    GetFromBuf(buf, di);
  80.  
  81. #ifdef USE_BUFFERS
  82.  
  83.    /*
  84.     * Only copy if space has been allocated for us.  Some drawing
  85.     * modes may not require this information, so the buffers may
  86.     * not be allocated to save time & space.
  87.     */
  88.  
  89.    if (di->BPen)
  90.    {
  91.  
  92.       if (GetBufLines(sbuf, &red, &grn, &blu, di->TE, di->Height))
  93.       {
  94.          totalr = totalg = totalb = num = 0;
  95.  
  96.          //maskptr = di->Mask;
  97.  
  98.          for (j = 0; j < di->Height; j++)
  99.          {
  100.             GetBufLine(di->BMask, &maskptr, NULL, NULL, j);
  101.  
  102.             rp = red + (j * sbuf->Width) + di->LE;
  103.             gp = grn + (j * sbuf->Width) + di->LE;
  104.             bp = blu + (j * sbuf->Width) + di->LE;
  105.  
  106.             for (i = 0; i < di->Width; i++)
  107.             {
  108.                if (*maskptr)
  109.                {
  110.                   totalr += *rp;
  111.                   totalg += *gp;
  112.                   totalb += *bp;
  113.                   num++;
  114.                }
  115.                rp++; gp++; bp++;
  116.                maskptr++;
  117.             }
  118.          }
  119.  
  120.          if (num)
  121.          {
  122.             totalr = (totalr / num);
  123.             totalg = (totalg / num);
  124.             totalb = (totalb / num);
  125.          }
  126.  
  127.          for (j = 0; j < di->Height; j++)
  128.          {
  129.             GetBufLine(di->BPen, &red, &grn, &blu, j);
  130.             memset(red, totalr, di->Width);
  131.             memset(grn, totalg, di->Width);
  132.             memset(blu, totalb, di->Width);
  133.             PutBufLine(di->BPen);
  134.          }
  135.       }
  136.  
  137.    }
  138.  
  139. #else
  140.  
  141.    /*
  142.     * Only copy if space has been allocated for us.  Some drawing
  143.     * modes may not require this information, so the buffers may
  144.     * not be allocated to save time & space.
  145.     */
  146.  
  147.    if (di->PenR && di->PenG && di->PenB)
  148.    {
  149.  
  150.       if (GetBufLines(sbuf, &red, &grn, &blu, di->TE, di->Height))
  151.       {
  152.          totalr = totalg = totalb = num = 0;
  153.          maskptr = di->Mask;
  154.  
  155.          for (j = 0; j < di->Height; j++)
  156.          {
  157.             rp = red + (j * sbuf->Width) + di->LE;
  158.             gp = grn + (j * sbuf->Width) + di->LE;
  159.             bp = blu + (j * sbuf->Width) + di->LE;
  160.  
  161.             for (i = 0; i < di->Width; i++)
  162.             {
  163.                if (*maskptr)
  164.                {
  165.                   totalr += *rp;
  166.                   totalg += *gp;
  167.                   totalb += *bp;
  168.                   num++;
  169.                }
  170.                rp++; gp++; bp++;
  171.                maskptr++;
  172.             }
  173.          }
  174.  
  175.          if (num)
  176.          {
  177.             totalr = (totalr / num);
  178.             totalg = (totalg / num);
  179.             totalb = (totalb / num);
  180.          }
  181.  
  182.          memset(di->PenR, totalr, di->Width * di->Height);
  183.          memset(di->PenG, totalg, di->Width * di->Height);
  184.          memset(di->PenB, totalb, di->Width * di->Height);
  185.       }
  186.  
  187.    }
  188.  
  189. #endif
  190.  
  191.    return(1);
  192. }
  193.  
  194. /*
  195.  * XDS_Put:
  196.  *
  197.  *
  198.  */
  199. int __saveds __asm XDS_Put (register __a0 struct IDrawInfo *di)
  200. {
  201.    struct Buffer *buf = ScanBase->MainBuffer;
  202.  
  203.    if (!ScanBase->SwapBuffer) return(0);
  204.  
  205.    PutToBuf(buf, di);
  206.  
  207.    return(1);
  208. }
  209.  
  210. /*
  211.  * XDS_Options:
  212.  *
  213.  * Present a window to the user allowing him to adjust drawing style
  214.  * options.  Arguments may optionally be passed from an Arexx command.
  215.  *
  216.  */
  217. int __saveds __asm XDS_Options (register __a0 LONG *args)
  218. {
  219.    return(0);
  220. }
  221.  
  222. /*
  223.  * XDS_LoadPrefs:
  224.  *
  225.  * Set preferences according to information loaded from disk.
  226.  *
  227.  */
  228. int __saveds __asm XDS_LoadPrefs (register __a0 void *prefs)
  229. {
  230.    return(1);
  231. }
  232.  
  233. /*
  234.  * XDS_SavePrefs:
  235.  *
  236.  * Request preferences settings that are about to be saved to disk.
  237.  *
  238.  */
  239. int __saveds __asm XDS_SavePrefs (register __a0 void *prefs)
  240. {
  241.    return(1);
  242. }
  243.  
  244.  
  245. int __saveds __asm XDS_Init (void)
  246. {
  247.    return(1);
  248. }
  249.  
  250. void __saveds __asm XDS_Cleanup (void)
  251. {
  252. }
  253.  
  254.  
  255.  
  256. /**********************************************************************\
  257.  
  258.                          Library Initialization Stuff
  259.  
  260. \**********************************************************************/
  261.  
  262. /*
  263.  * This is the table of all the functions that can be called in this
  264.  * module.  The first four (Open, Close, Expunge, and Null) are reserved
  265.  * for system use and MUST be specified in the order shown.  The actual
  266.  * functions are in the standard module startup code.
  267.  */
  268. ULONG FuncTable[] = {
  269.    /* These four MUST be present in this order */
  270.    (ULONG) LibOpen,
  271.    (ULONG) LibClose,
  272.    (ULONG) LibExpunge,
  273.    (ULONG) LibNull,
  274.  
  275.    /* Specific to the module */
  276.    (ULONG) XDS_Attr,
  277.    (ULONG) XDS_Begin,
  278.    (ULONG) XDS_End,
  279.    (ULONG) XDS_Get,
  280.    (ULONG) XDS_Put,
  281.    (ULONG) XDS_Options,
  282.    (ULONG) XDS_LoadPrefs,
  283.    (ULONG) XDS_SavePrefs,
  284.    (ULONG) 0,
  285.    (ULONG) 0,
  286.    (ULONG) XDS_Init,
  287.    (ULONG) XDS_Cleanup,
  288.  
  289.    /* End with -1L */
  290.    (ULONG) -1L
  291. };
  292.  
  293. /*
  294.  * These are used by the standard module startup code.
  295.  * LibraryName is the name of the library, and LibraryID is a short
  296.  * description of the library.  Both of these are largely irrelavent,
  297.  * but they are included just for completeness.
  298.  */
  299. UBYTE LibraryID[]    = "$VER: Rub-Through Drawing Style 2.0.20 (15.2.95)";
  300. UBYTE LibraryType    = NT_XDRAWSTYLE;
  301.  
  302. /*
  303.  * This is called by the standard module startup code when Image Scan
  304.  * first opens the module.  Here we should fill in the NumGads,
  305.  * NewGad, Language, and LangCount fields of the provided ModuleBase
  306.  * structure if necessary.
  307.  */
  308. long  __asm UserOpen (register __a6 struct ModuleBase *modbase)
  309. {
  310.    return(TRUE);
  311. }
  312.  
  313. /*
  314.  * This is called by the standard module startup code when Image Scan
  315.  * closes the module.  It should cleanup anything allocated or obtained
  316.  * in the UserOpen() function.
  317.  */
  318. long  __asm UserClose (register __a6 struct ModuleBase *modbase)
  319. {
  320.    return(TRUE);
  321. }
  322.  
  323.