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

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