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

  1. /*
  2.  * Lighten
  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 MIN (short a, short b)
  17. {
  18.    if (a < b) return(a);
  19.    return(b);
  20. }
  21.  
  22. static int lighten_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_ScanLine | XDMF_AreOptions;
  42.    da->Priority   = 125;
  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.    UBYTE *br, *bg, *bb;
  78.    UBYTE *or, *og, *ob;
  79.    int i, j;
  80.  
  81. #ifdef USE_BUFFERS
  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++ = MIN(255, *br + lighten_factor);
  90.          *og++ = MIN(255, *bg + lighten_factor);
  91.          *ob++ = MIN(255, *bb + lighten_factor);
  92.       }
  93.       PutBufLine(di->BOut);
  94.    }
  95.  
  96. #else
  97.  
  98.    or = di->OutR;
  99.    og = di->OutG;
  100.    ob = di->OutB;
  101.    for (j = 0; j < di->Height; j++)
  102.    {
  103.       br = di->BufR + (j * di->BufW);
  104.       bg = di->BufG + (j * di->BufW);
  105.       bb = di->BufB + (j * di->BufW);
  106.       for (i = di->Width; i > 0; i--, br++, bg++, bb++)
  107.       {
  108.          *or++ = MIN(255, *br + lighten_factor);
  109.          *og++ = MIN(255, *bg + lighten_factor);
  110.          *ob++ = MIN(255, *bb + lighten_factor);
  111.       }
  112.    }
  113.  
  114. #endif
  115. }
  116.  
  117. /*
  118.  * XDM_Options:
  119.  *
  120.  * Present a window to the user allowing him to adjust drawing mode
  121.  * options.  Arguments may optionally be passed from an Arexx command.
  122.  *
  123.  */
  124. int __saveds __asm XDM_Options (register __a0 LONG *args)
  125. {
  126.    int i;
  127.  
  128.    if (args)
  129.    {
  130.       lighten_factor = atoi((char *)args[0]);
  131.       if (lighten_factor < 1) lighten_factor = 1;
  132.       if (lighten_factor > 256) lighten_factor = 256;
  133.    }
  134.    else
  135.    {
  136.  
  137.       i = IntegerRequest("Lightening Amount:", 1, 255, lighten_factor);
  138.       if (i >= 1)
  139.       {
  140.          lighten_factor = i;
  141.          Learn("DrawMode ARGS %ld", lighten_factor);
  142.       }
  143.    }
  144.  
  145.    return(0);
  146. }
  147.  
  148. /*
  149.  * XDM_LoadPrefs:
  150.  *
  151.  * Set preferences according to information loaded from disk.
  152.  *
  153.  */
  154. int __saveds __asm XDM_LoadPrefs (register __a0 void *prefs)
  155. {
  156.    return(1);
  157. }
  158.  
  159. /*
  160.  * XDM_SavePrefs:
  161.  *
  162.  * Request preferences settings that are about to be saved to disk.
  163.  *
  164.  */
  165. int __saveds __asm XDM_SavePrefs (register __a0 void *prefs)
  166. {
  167.    return(1);
  168. }
  169.  
  170.  
  171. int __saveds __asm XDM_Init (void)
  172. {
  173.    lighten_factor = GetIfxVar("LightenAmount", lighten_factor);
  174.    return(1);
  175. }
  176.  
  177. void __saveds __asm XDM_Cleanup (void)
  178. {
  179.    SetIfxVar("LightenAmount", lighten_factor);
  180. }
  181.  
  182.  
  183. /**********************************************************************\
  184.  
  185.                          Library Initialization Stuff
  186.  
  187. \**********************************************************************/
  188.  
  189. /*
  190.  * This is the table of all the functions that can be called in this
  191.  * module.  The first four (Open, Close, Expunge, and Null) are reserved
  192.  * for system use and MUST be specified in the order shown.  The actual
  193.  * functions are in the standard module startup code.
  194.  */
  195. ULONG FuncTable[] = {
  196.    /* These four MUST be present in this order */
  197.    (ULONG) LibOpen,
  198.    (ULONG) LibClose,
  199.    (ULONG) LibExpunge,
  200.    (ULONG) LibNull,
  201.  
  202.    /* Specific to the module */
  203.    (ULONG) XDM_Attr,
  204.    (ULONG) XDM_Begin,
  205.    (ULONG) XDM_End,
  206.    (ULONG) XDM_Affect,
  207.    (ULONG) XDM_Options,
  208.    (ULONG) XDM_LoadPrefs,
  209.    (ULONG) XDM_SavePrefs,
  210.    (ULONG) 0,
  211.    (ULONG) 0,
  212.    (ULONG) XDM_Init,
  213.    (ULONG) XDM_Cleanup,
  214.  
  215.    /* End with -1L */
  216.    (ULONG) -1L
  217. };
  218.  
  219. /*
  220.  * These are used by the standard module startup code.
  221.  * LibraryName is the name of the library, and LibraryID is a short
  222.  * description of the library.  Both of these are largely irrelavent,
  223.  * but they are included just for completeness.
  224.  */
  225. UBYTE LibraryID[]    = "$VER: Lighten Drawing Mode 2.0.12 (15.2.95)";
  226. UBYTE LibraryType    = NT_XDRAWMODE;
  227.  
  228.  
  229. RXCMD RxCmd = { NULL, NULL, "Amount/N" };
  230.  
  231. /*
  232.  * This is called by the standard module startup code when Image Scan
  233.  * first opens the module.  Here we should fill in the NumGads,
  234.  * NewGad, Language, and LangCount fields of the provided ModuleBase
  235.  * structure if necessary.
  236.  */
  237. long  __asm UserOpen (register __a6 struct ModuleBase *modbase)
  238. {
  239.    modbase->CmdTable = &RxCmd;
  240.  
  241.    return(TRUE);
  242. }
  243.  
  244. /*
  245.  * This is called by the standard module startup code when Image Scan
  246.  * closes the module.  It should cleanup anything allocated or obtained
  247.  * in the UserOpen() function.
  248.  */
  249. long  __asm UserClose (register __a6 struct ModuleBase *modbase)
  250. {
  251.    return(TRUE);
  252. }
  253.  
  254.