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

  1. /*
  2.  * A Relief 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_NoPen;
  28.    da->Priority   = 114;
  29.    da->HorizOffs  = 1;
  30.    da->VertOffs   = 1;
  31.    return(0);
  32. }
  33.  
  34. /*
  35.  * XDM_Init:
  36.  *
  37.  * Initialize the drawing mode.
  38.  *
  39.  */
  40. int __saveds __asm XDM_Init (void)
  41. {
  42.    return(1);
  43. }
  44.  
  45. /*
  46.  * XDM_Cleanup:
  47.  *
  48.  * Cleanup the drawing mode.
  49.  *
  50.  */
  51. void __saveds __asm XDM_Cleanup (void)
  52. {
  53. }
  54.  
  55. /*
  56.  * XDM_Begin:
  57.  *
  58.  * Prepare before a pixel affecting operation.
  59.  *
  60.  */
  61. int __saveds __asm XDM_Begin (register __a0 struct IDrawInfo *di)
  62. {
  63.    return(1);
  64. }
  65.  
  66. /*
  67.  * XDM_End:
  68.  *
  69.  * Cleanup after a pixel affecting operation.
  70.  *
  71.  */
  72. void __saveds __asm XDM_End (register __a0 struct IDrawInfo *di)
  73. {
  74. }
  75.  
  76. /*
  77.  * XDM_Affect:
  78.  *
  79.  * Affect a block of pixels.  We may also affect some of the
  80.  * parameters of the IDrawInfo structure, such as the X & Y
  81.  * location of the block of pixels.
  82.  *
  83.  */
  84. void __saveds __asm XDM_Affect (register __a0 struct IDrawInfo *di)
  85. {
  86. #ifdef USE_BUFFERS
  87.  
  88.    int i, j;
  89.    UBYTE *ored, *ogrn, *oblu;
  90.    UBYTE *ired, *igrn, *iblu;
  91.    int t;
  92.  
  93.    for (j = 0; j < di->Height; j++) {
  94.       GetBufLines(di->BBuf, &ired, &igrn, &iblu, j, 3);
  95.       ired += di->BufW + 1;
  96.       igrn += di->BufW + 1;
  97.       iblu += di->BufW + 1;
  98.       GetBufLine(di->BOut, &ored, &ogrn, &oblu, j);
  99.       for (i = 0; i < di->Width; i++) {
  100.  
  101.          t     = ( (int)(*(ired + di->BufW + 1)) -
  102.                    (int)(*(ired - di->BufW - 1)) ) + 128;
  103.          if (t < 0) t = 0; else if (t > 255) t = 255;
  104.          *ored = t;
  105.  
  106.          t     = ( (int)(*(igrn + di->BufW + 1)) -
  107.                    (int)(*(igrn - di->BufW - 1)) ) + 128;
  108.          if (t < 0) t = 0; else if (t > 255) t = 255;
  109.          *ogrn = t;
  110.  
  111.          t     = ( (int)(*(iblu + di->BufW + 1)) -
  112.                    (int)(*(iblu - di->BufW - 1)) ) + 128;
  113.          if (t < 0) t = 0; else if (t > 255) t = 255;
  114.          *oblu = t;
  115.  
  116.          ored++; ogrn++; oblu++;
  117.          ired++; igrn++; iblu++;
  118.       }
  119.       PutBufLine(di->BOut);
  120.    }
  121.  
  122. #else
  123.  
  124.    int i, j;
  125.    UBYTE *ored, *ogrn, *oblu;
  126.    UBYTE *ired, *igrn, *iblu;
  127.    int t;
  128.  
  129.    ored = di->OutR;
  130.    ogrn = di->OutG;
  131.    oblu = di->OutB;
  132.  
  133.    for (j = 0; j < di->Height; j++) {
  134.       ired = di->BufR + (j * di->BufW);
  135.       igrn = di->BufG + (j * di->BufW);
  136.       iblu = di->BufB + (j * di->BufW);
  137.       for (i = 0; i < di->Width; i++) {
  138.  
  139.          t     = ( (int)(*(ired + di->BufW + 1)) -
  140.                    (int)(*(ired - di->BufW - 1)) ) + 128;
  141.          if (t < 0) t = 0; else if (t > 255) t = 255;
  142.          *ored = t;
  143.  
  144.          t     = ( (int)(*(igrn + di->BufW + 1)) -
  145.                    (int)(*(igrn - di->BufW - 1)) ) + 128;
  146.          if (t < 0) t = 0; else if (t > 255) t = 255;
  147.          *ogrn = t;
  148.  
  149.          t     = ( (int)(*(iblu + di->BufW + 1)) -
  150.                    (int)(*(iblu - di->BufW - 1)) ) + 128;
  151.          if (t < 0) t = 0; else if (t > 255) t = 255;
  152.          *oblu = t;
  153.  
  154.          ored++; ogrn++; oblu++;
  155.          ired++; igrn++; iblu++;
  156.       }
  157.    }
  158.  
  159. #endif
  160. }
  161.  
  162. /*
  163.  * XDM_Options:
  164.  *
  165.  * Present a window to the user allowing him to adjust drawing mode
  166.  * options.  Arguments may optionally be passed from an Arexx command.
  167.  * This function will only be called if the flag XDMF_AreOptions is
  168.  * returned from XDM_Attr().
  169.  *
  170.  */
  171. int __saveds __asm XDM_Options (register __a0 LONG *args)
  172. {
  173.    return(0);
  174. }
  175.  
  176. /*
  177.  * XDM_LoadPrefs:
  178.  *
  179.  * Set preferences according to information loaded from disk.
  180.  *
  181.  */
  182. int __saveds __asm XDM_LoadPrefs (register __a0 void *prefs)
  183. {
  184.    return(1);
  185. }
  186.  
  187. /*
  188.  * XDM_SavePrefs:
  189.  *
  190.  * Request preferences settings that are about to be saved to disk.
  191.  *
  192.  */
  193. int __saveds __asm XDM_SavePrefs (register __a0 void *prefs)
  194. {
  195.    return(1);
  196. }
  197.  
  198.  
  199. /**********************************************************************\
  200.  
  201.                          Library Initialization Stuff
  202.  
  203. \**********************************************************************/
  204.  
  205. /*
  206.  * This is the table of all the functions that can be called in this
  207.  * module.  The first four (Open, Close, Expunge, and Null) are reserved
  208.  * for system use and MUST be specified in the order shown.  The actual
  209.  * functions are in the standard module startup code.
  210.  */
  211. ULONG FuncTable[] = {
  212.    /* These four MUST be present in this order */
  213.    (ULONG) LibOpen,
  214.    (ULONG) LibClose,
  215.    (ULONG) LibExpunge,
  216.    (ULONG) LibNull,
  217.  
  218.    /* Specific to the module */
  219.    (ULONG) XDM_Attr,
  220.    (ULONG) XDM_Begin,
  221.    (ULONG) XDM_End,
  222.    (ULONG) XDM_Affect,
  223.    (ULONG) XDM_Options,
  224.    (ULONG) XDM_LoadPrefs,
  225.    (ULONG) XDM_SavePrefs,
  226.    (ULONG) 0,
  227.    (ULONG) 0,
  228.    (ULONG) XDM_Init,
  229.    (ULONG) XDM_Cleanup,
  230.  
  231.    /* End with -1L */
  232.    (ULONG) -1L
  233. };
  234.  
  235. /*
  236.  * These are used by the standard module startup code.
  237.  * LibraryName is the name of the library, and LibraryID is a short
  238.  * description of the library.  Both of these are largely irrelavent,
  239.  * but they are included just for completeness.
  240.  */
  241. UBYTE LibraryID[]    = "$VER: Relief Extended Drawing Mode 2.0.7 (15.2.95)";
  242. UBYTE LibraryType    = NT_XDRAWMODE;
  243.  
  244. /*
  245.  * This is called by the standard module startup code when Image Scan
  246.  * first opens the module.  Here we should fill in the NumGads,
  247.  * NewGad, Language, and LangCount fields of the provided ModuleBase
  248.  * structure if necessary.
  249.  */
  250. long  __asm UserOpen (register __a6 struct ModuleBase *modbase)
  251. {
  252.    return(TRUE);
  253. }
  254.  
  255. /*
  256.  * This is called by the standard module startup code when Image Scan
  257.  * closes the module.  It should cleanup anything allocated or obtained
  258.  * in the UserOpen() function.
  259.  */
  260. long  __asm UserClose (register __a6 struct ModuleBase *modbase)
  261. {
  262.    return(TRUE);
  263. }
  264.  
  265.