home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / gfx / misc / imagefx_sdk / sas / examples / xdraw / add.c next >
Encoding:
C/C++ Source or Header  |  1995-02-15  |  5.1 KB  |  232 lines

  1. /*
  2.  * An Add Enhanced Drawing Mode for ImageFX 2.0
  3.  *
  4.  */
  5.  
  6. #include <exec/types.h>
  7. #include <scan/modall.h>
  8. #include <scan/drawinfo.h>
  9.  
  10. /**********************************************************************\
  11.  
  12.                                 Library Vectors
  13.  
  14. \**********************************************************************/
  15.  
  16. /*
  17.  * XDM_Attr:
  18.  *
  19.  * Return to ImageFX some information about the Drawing Mode (eg.
  20.  * whether Options are needed, whether we work on greyscale or
  21.  * color, etc.).  Called when ImageFX first scans the drawing
  22.  * mode directory.
  23.  *
  24.  */
  25. ULONG __saveds __asm XDM_Attr (register __a0 struct XDrawAttr *da)
  26. {
  27.    da->Flags      = XDMF_ScanLine;
  28.    da->Priority   = 116;
  29.    return(0);
  30. }
  31.  
  32. /*
  33.  * XDM_Begin:
  34.  *
  35.  * Prepare before a pixel affecting operation.
  36.  *
  37.  */
  38. int __saveds __asm XDM_Begin (register __a0 struct IDrawInfo *di)
  39. {
  40.    return(1);
  41. }
  42.  
  43. /*
  44.  * XDM_End:
  45.  *
  46.  * Cleanup after a pixel affecting operation.
  47.  *
  48.  */
  49. void __saveds __asm XDM_End (register __a0 struct IDrawInfo *di)
  50. {
  51. }
  52.  
  53.  
  54. /*
  55.  * XDM_Affect:
  56.  *
  57.  * Affect a block of pixels.  We may also affect some of the
  58.  * parameters of the IDrawInfo structure, such as the X & Y
  59.  * location of the block of pixels.
  60.  *
  61.  */
  62. void __saveds __asm XDM_Affect (register __a0 struct IDrawInfo *di)
  63. {
  64. #ifdef USE_BUFFERS
  65.  
  66.    UBYTE *dr, *dg, *db;
  67.    UBYTE *or, *og, *ob;
  68.    UBYTE *pr, *pg, *pb;
  69.    int i, j;
  70.    short t;
  71.  
  72.    for (j = 0; j < di->Height; j++)
  73.    {
  74.       GetBufLine(di->BBuf, &dr, &dg, &db, j);
  75.       GetBufLine(di->BPen, &pr, &pg, &pb, j);
  76.       GetBufLine(di->BOut, &or, &og, &ob, j);
  77.       for (i = 0; i < di->Width; i++)
  78.       {
  79.          t = (*dr++) + (*pr++) - 128; if (t < 0) t = 0; else if (t > 255) t = 255;
  80.          *or++ = t;
  81.          t = (*dg++) + (*pg++) - 128; if (t < 0) t = 0; else if (t > 255) t = 255;
  82.          *og++ = t;
  83.          t = (*db++) + (*pb++) - 128; if (t < 0) t = 0; else if (t > 255) t = 255;
  84.          *ob++ = t;
  85.       }
  86.       PutBufLine(di->BOut);
  87.    }
  88.  
  89. #else
  90.  
  91.    int n = di->Width * di->Height;
  92.    UBYTE *dr, *dg, *db;
  93.    UBYTE *or, *og, *ob;
  94.    UBYTE *pr, *pg, *pb;
  95.    short t;
  96.  
  97.    dr = di->BufR;
  98.    dg = di->BufG;
  99.    db = di->BufB;
  100.    pr = di->PenR;
  101.    pg = di->PenG;
  102.    pb = di->PenB;
  103.    or = di->OutR;
  104.    og = di->OutG;
  105.    ob = di->OutB;
  106.  
  107.    while (n--)
  108.    {
  109.       t = (*dr++) + (*pr++) - 128; if (t < 0) t = 0; else if (t > 255) t = 255;
  110.       *or++ = t;
  111.       t = (*dg++) + (*pg++) - 128; if (t < 0) t = 0; else if (t > 255) t = 255;
  112.       *og++ = t;
  113.       t = (*db++) + (*pb++) - 128; if (t < 0) t = 0; else if (t > 255) t = 255;
  114.       *ob++ = t;
  115.    }
  116. #endif
  117. }
  118.  
  119. /*
  120.  * XDM_Options:
  121.  *
  122.  * Present a window to the user allowing him to adjust drawing mode
  123.  * options.  Arguments may optionally be passed from an Arexx command.
  124.  * This function will only be called if the flag XDMF_AreOptions is
  125.  * returned from XDM_Attr().
  126.  *
  127.  */
  128. int __saveds __asm XDM_Options (register __a0 LONG *args)
  129. {
  130.    return(0);
  131. }
  132.  
  133. /*
  134.  * XDM_LoadPrefs:
  135.  *
  136.  * Set preferences according to information loaded from disk.
  137.  *
  138.  */
  139. int __saveds __asm XDM_LoadPrefs (register __a0 void *prefs)
  140. {
  141.    return(1);
  142. }
  143.  
  144. /*
  145.  * XDM_SavePrefs:
  146.  *
  147.  * Request preferences settings that are about to be saved to disk.
  148.  *
  149.  */
  150. int __saveds __asm XDM_SavePrefs (register __a0 void *prefs)
  151. {
  152.    return(1);
  153. }
  154.  
  155.  
  156. int __saveds __asm XDM_Init (void)
  157. {
  158.    return(1);
  159. }
  160.  
  161. void __saveds __asm XDM_Cleanup (void)
  162. {
  163. }
  164.  
  165.  
  166. /**********************************************************************\
  167.  
  168.                          Library Initialization Stuff
  169.  
  170. \**********************************************************************/
  171.  
  172. /*
  173.  * This is the table of all the functions that can be called in this
  174.  * module.  The first four (Open, Close, Expunge, and Null) are reserved
  175.  * for system use and MUST be specified in the order shown.  The actual
  176.  * functions are in the standard module startup code.
  177.  */
  178. ULONG FuncTable[] = {
  179.    /* These four MUST be present in this order */
  180.    (ULONG) LibOpen,
  181.    (ULONG) LibClose,
  182.    (ULONG) LibExpunge,
  183.    (ULONG) LibNull,
  184.  
  185.    /* Specific to the module */
  186.    (ULONG) XDM_Attr,
  187.    (ULONG) XDM_Begin,
  188.    (ULONG) XDM_End,
  189.    (ULONG) XDM_Affect,
  190.    (ULONG) XDM_Options,
  191.    (ULONG) XDM_LoadPrefs,
  192.    (ULONG) XDM_SavePrefs,
  193.    (ULONG) 0,
  194.    (ULONG) 0,
  195.    (ULONG) XDM_Init,
  196.    (ULONG) XDM_Cleanup,
  197.  
  198.    /* End with -1L */
  199.    (ULONG) -1L
  200. };
  201.  
  202. /*
  203.  * These are used by the standard module startup code.
  204.  * LibraryName is the name of the library, and LibraryID is a short
  205.  * description of the library.  Both of these are largely irrelavent,
  206.  * but they are included just for completeness.
  207.  */
  208. UBYTE LibraryID[]    = "$VER: Add Extended Drawing Mode 2.0.6 (15.2.95)";
  209. UBYTE LibraryType    = NT_XDRAWMODE;
  210.  
  211. /*
  212.  * This is called by the standard module startup code when Image Scan
  213.  * first opens the module.  Here we should fill in the NumGads,
  214.  * NewGad, Language, and LangCount fields of the provided ModuleBase
  215.  * structure if necessary.
  216.  */
  217. long  __asm UserOpen (register __a6 struct ModuleBase *modbase)
  218. {
  219.    return(TRUE);
  220. }
  221.  
  222. /*
  223.  * This is called by the standard module startup code when Image Scan
  224.  * closes the module.  It should cleanup anything allocated or obtained
  225.  * in the UserOpen() function.
  226.  */
  227. long  __asm UserClose (register __a6 struct ModuleBase *modbase)
  228. {
  229.    return(TRUE);
  230. }
  231.  
  232.