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

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