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

  1. /*
  2.  * Maximum.
  3.  *
  4.  */
  5.  
  6. #include <exec/types.h>
  7. #include <scan/modall.h>
  8. #include <scan/drawinfo.h>
  9. #include <string.h>
  10. #include "common.h"
  11.  
  12. #define Channel      (ScanBase->sb_Channel)
  13.  
  14. /**********************************************************************\
  15.  
  16.                                 Library Vectors
  17.  
  18. \**********************************************************************/
  19.  
  20. /*
  21.  * XDM_Attr:
  22.  *
  23.  * Return to ImageFX some information about the Drawing Style (eg.
  24.  * whether Options are needed, whether we work on greyscale or
  25.  * color, etc.).  Called when ImageFX first scans the drawing
  26.  * style directory.
  27.  *
  28.  */
  29. ULONG __saveds __asm XDS_Attr (register __a0 struct XDrawAttr *attr)
  30. {
  31.    attr->Flags = 0;
  32.    attr->Priority = 117;
  33.    return(0);
  34. }
  35.  
  36. /*
  37.  * XDS_Begin:
  38.  *
  39.  * Prepare before a pixel affecting operation.
  40.  *
  41.  */
  42. int __saveds __asm XDS_Begin (register __a0 struct IDrawInfo *di)
  43. {
  44.    di->SPrivate = (APTR)ScanBase->MainBuffer;
  45.    return(1);
  46. }
  47.  
  48. /*
  49.  * XDS_End:
  50.  *
  51.  * Cleanup after a pixel affecting operation.
  52.  *
  53.  */
  54. void __saveds __asm XDS_End (register __a0 struct IDrawInfo *di)
  55. {
  56. }
  57.  
  58. /*
  59.  * XDS_Get:
  60.  *
  61.  *
  62.  */
  63. int __saveds __asm XDS_Get (register __a0 struct IDrawInfo *di)
  64. {
  65.    struct Buffer *buf = (struct Buffer *)di->SPrivate;
  66.  
  67.    if (!buf) return(0);
  68.  
  69.    GetFromBuf(buf, di);
  70.  
  71.    return(1);
  72. }
  73.  
  74.  
  75. #define MAX(a,b)     ((a) > (b) ? (a) : (b))
  76.  
  77. BOOL __regargs MaxPutToBuf (struct Buffer *buf, struct IDrawInfo *di)
  78. {
  79.    UBYTE *sr, *sg, *sb;
  80.    UBYTE *dr, *dg, *db;
  81.    UBYTE *red, *grn, *blu;
  82.    UBYTE *mask;
  83.    int i, j, x, y, mx, my;
  84.    int left, top;
  85.    short drawpart = (ScanBase->sb_DrawBlend * 255 / 100);
  86.    int mix;
  87.    short r, g, b;
  88.    UBYTE *alphapix;
  89.    struct Buffer *abuf = ScanBase->Alpha;
  90.  
  91.    if (!buf) return(FALSE);
  92.  
  93.    left = di->LE;
  94.    top = di->TE;
  95.  
  96.    /*
  97.     * Put the pixels into the buffer, applying blending and masking.
  98.     * Also clip to buffer boundaries.
  99.     */
  100.    for (y = top, j = 0; j < di->Height; j++, y++) {
  101.       if (y >= 0 && y < buf->Height) {
  102.          GetBufLine(di->BOut, &sr, &sg, &sb, j);
  103.          GetBufLine(di->BMask, &mask, NULL, NULL, j);
  104.          GetBufLine(buf, &red, &grn, &blu, y);
  105.          if (buf->Mask) my = y - buf->Mask->OffsetY;
  106.          dr = red + left;
  107.          dg = grn + left;
  108.          db = blu + left;
  109.          for (x = left, i = 0; i < di->Width; i++, x++) {
  110.             mix = *mask;
  111.             if (buf->Mask) mx = x - buf->Mask->OffsetX;
  112.             if (x >= 0 && x < buf->Width) {
  113.                if (CheckMask(buf->Mask, mx, my)) {
  114.                   if (mix && !CheckCloseness(*dr,*dg,*db)) {
  115.                      switch(ScanBase->sb_DrawAlpha)
  116.                      {
  117.                         case 0 :    /* alpha = off */
  118.                            r = mixer(*sr, *dr, mixer(drawpart,0,mix));
  119.                            g = mixer(*sg, *dg, mixer(drawpart,0,mix));
  120.                            b = mixer(*sb, *db, mixer(drawpart,0,mix));
  121.                            break;
  122.                         case 1 :    /* alpha = frisket */
  123.                            GetBufLine(abuf, &alphapix, NULL, NULL, y % abuf->Height);
  124.                            mix = mixer(mix, 0, alphapix[x % abuf->Width]);
  125.                            r = mixer(*sr, *dr, mixer(drawpart,0,mix));
  126.                            g = mixer(*sg, *dg, mixer(drawpart,0,mix));
  127.                            b = mixer(*sb, *db, mixer(drawpart,0,mix));
  128.                            break;
  129.                         case 2 :    /* alpha = texture */
  130.                            GetBufLine(abuf, &alphapix, NULL, NULL, y % abuf->Height);
  131.                            r = *sr + alphapix[x % abuf->Width] - 128; if (r < 0) r = 0; else if (r > 255) r = 255;
  132.                            g = *sg + alphapix[x % abuf->Width] - 128; if (g < 0) g = 0; else if (g > 255) g = 255;
  133.                            b = *sb + alphapix[x % abuf->Width] - 128; if (b < 0) b = 0; else if (b > 255) b = 255;
  134.                            r = mixer(r, *dr, mixer(drawpart,0,mix));
  135.                            g = mixer(g, *dg, mixer(drawpart,0,mix));
  136.                            b = mixer(b, *db, mixer(drawpart,0,mix));
  137.                            break;
  138.                      }
  139.                      if (buf->Depth == 1 || (Channel & CHAN_RED)) { *dr = MAX(r,*dr); }
  140.                      if (buf->Depth > 1)
  141.                      {
  142.                         if (Channel & CHAN_GRN) { *dg = MAX(g,*dg); }
  143.                         if (Channel & CHAN_BLU) { *db = MAX(b,*db); }
  144.                      }
  145.                   }
  146.                }
  147.             }
  148.             dr++; dg++; db++;
  149.             sr++; sg++; sb++;
  150.             mask++;
  151.          }
  152.          PutBufLine(buf);
  153.       }
  154.    }
  155. }
  156.  
  157. /*
  158.  * XDS_Put:
  159.  *
  160.  *
  161.  */
  162. int __saveds __asm XDS_Put (register __a0 struct IDrawInfo *di)
  163. {
  164.    struct Buffer *buf = (struct Buffer *)di->SPrivate;
  165.  
  166.    if (!buf) return(0);
  167.  
  168.    MaxPutToBuf(buf, di);
  169.  
  170.    return(1);
  171. }
  172.  
  173. /*
  174.  * XDS_Options:
  175.  *
  176.  * Present a window to the user allowing him to adjust drawing style
  177.  * options.  Arguments may optionally be passed from an Arexx command.
  178.  *
  179.  */
  180. int __saveds __asm XDS_Options (register __a0 LONG *args)
  181. {
  182.    return(0);
  183. }
  184.  
  185. /*
  186.  * XDS_LoadPrefs:
  187.  *
  188.  * Set preferences according to information loaded from disk.
  189.  *
  190.  */
  191. int __saveds __asm XDS_LoadPrefs (register __a0 void *prefs)
  192. {
  193.    return(1);
  194. }
  195.  
  196. /*
  197.  * XDS_SavePrefs:
  198.  *
  199.  * Request preferences settings that are about to be saved to disk.
  200.  *
  201.  */
  202. int __saveds __asm XDS_SavePrefs (register __a0 void *prefs)
  203. {
  204.    return(1);
  205. }
  206.  
  207. int __saveds __asm XDS_Init (void)
  208. {
  209.    return(1);
  210. }
  211.  
  212. void __saveds __asm XDS_Cleanup (void)
  213. {
  214. }
  215.  
  216.  
  217. /**********************************************************************\
  218.  
  219.                          Library Initialization Stuff
  220.  
  221. \**********************************************************************/
  222.  
  223. /*
  224.  * This is the table of all the functions that can be called in this
  225.  * module.  The first four (Open, Close, Expunge, and Null) are reserved
  226.  * for system use and MUST be specified in the order shown.  The actual
  227.  * functions are in the standard module startup code.
  228.  */
  229. ULONG FuncTable[] = {
  230.    /* These four MUST be present in this order */
  231.    (ULONG) LibOpen,
  232.    (ULONG) LibClose,
  233.    (ULONG) LibExpunge,
  234.    (ULONG) LibNull,
  235.  
  236.    /* Specific to the module */
  237.    (ULONG) XDS_Attr,
  238.    (ULONG) XDS_Begin,
  239.    (ULONG) XDS_End,
  240.    (ULONG) XDS_Get,
  241.    (ULONG) XDS_Put,
  242.    (ULONG) XDS_Options,
  243.    (ULONG) XDS_LoadPrefs,
  244.    (ULONG) XDS_SavePrefs,
  245.    (ULONG) 0,
  246.    (ULONG) 0,
  247.    (ULONG) XDS_Init,
  248.    (ULONG) XDS_Cleanup,
  249.  
  250.    /* End with -1L */
  251.    (ULONG) -1L
  252. };
  253.  
  254. /*
  255.  * These are used by the standard module startup code.
  256.  * LibraryName is the name of the library, and LibraryID is a short
  257.  * description of the library.  Both of these are largely irrelavent,
  258.  * but they are included just for completeness.
  259.  */
  260. UBYTE LibraryID[]    = "$VER: Maximum Drawing Style 2.0.3 (15.2.95)";
  261. UBYTE LibraryType    = NT_XDRAWSTYLE;
  262.  
  263. /*
  264.  * This is called by the standard module startup code when Image Scan
  265.  * first opens the module.  Here we should fill in the NumGads,
  266.  * NewGad, Language, and LangCount fields of the provided ModuleBase
  267.  * structure if necessary.
  268.  */
  269. long  __asm UserOpen (register __a6 struct ModuleBase *modbase)
  270. {
  271.    return(TRUE);
  272. }
  273.  
  274. /*
  275.  * This is called by the standard module startup code when Image Scan
  276.  * closes the module.  It should cleanup anything allocated or obtained
  277.  * in the UserOpen() function.
  278.  */
  279. long  __asm UserClose (register __a6 struct ModuleBase *modbase)
  280. {
  281.    return(TRUE);
  282. }
  283.  
  284.