home *** CD-ROM | disk | FTP | other *** search
- /*
- * Darken
- *
- * Revision History:
- *
- * 04.01.95 tek Now remembers setting from one invokation to the next.
- *
- */
-
- #include <exec/types.h>
- #include <scan/modall.h>
- #include <scan/drawinfo.h>
- #include <stdlib.h>
-
-
- static __inline __regargs short MAX (short a, short b)
- {
- if (a > b) return(a);
- return(b);
- }
-
- static int darken_factor = 48;
-
- /**********************************************************************\
-
- Library Vectors
-
- \**********************************************************************/
-
- /*
- * XDM_Attr:
- *
- * Return to ImageFX some information about the Drawing Mode (eg.
- * whether Options are needed, whether we work on greyscale or
- * color, etc.). Called when ImageFX first scans the drawing
- * mode directory.
- *
- */
- ULONG __saveds __asm XDM_Attr (register __a0 struct XDrawAttr *da)
- {
- da->Flags = XDMF_NoPen | XDMF_AreOptions | XDMF_ScanLine;
- da->Priority = 126;
- return(0);
- }
-
- /*
- * XDM_Begin:
- *
- * Prepare before a pixel affecting operation.
- *
- */
- int __saveds __asm XDM_Begin (register __a0 struct IDrawInfo *di)
- {
- return(1);
- }
-
- /*
- * XDM_End:
- *
- * Cleanup after a pixel affecting operation.
- *
- */
- void __saveds __asm XDM_End (register __a0 struct IDrawInfo *di)
- {
- }
-
- /*
- * XDM_Affect:
- *
- * Affect a block of pixels. We may also affect some of the
- * parameters of the IDrawInfo structure, such as the X & Y
- * location of the block of pixels.
- *
- */
- void __saveds __asm XDM_Affect (register __a0 struct IDrawInfo *di)
- {
- #ifdef USE_BUFFERS
-
- UBYTE *br, *bg, *bb;
- UBYTE *or, *og, *ob;
- int i, j;
-
- for (j = 0; j < di->Height; j++)
- {
- GetBufLine(di->BBuf, &br, &bg, &bb, j);
- GetBufLine(di->BOut, &or, &og, &ob, j);
- for (i = di->Width; i > 0; i--, br++, bg++, bb++)
- {
- *or++ = MAX(0, *br - darken_factor);
- *og++ = MAX(0, *bg - darken_factor);
- *ob++ = MAX(0, *bb - darken_factor);
- }
- PutBufLine(di->BOut);
- }
-
- #else
-
- UBYTE *br, *bg, *bb;
- UBYTE *or, *og, *ob;
- int i, j;
-
- or = di->OutR;
- og = di->OutG;
- ob = di->OutB;
- for (j = 0; j < di->Height; j++)
- {
- br = di->BufR + (j * di->BufW);
- bg = di->BufG + (j * di->BufW);
- bb = di->BufB + (j * di->BufW);
- for (i = di->Width; i > 0; i--, br++, bg++, bb++)
- {
- *or++ = MAX(0, *br - darken_factor);
- *og++ = MAX(0, *bg - darken_factor);
- *ob++ = MAX(0, *bb - darken_factor);
- }
- }
-
- #endif
- }
-
- /*
- * XDM_Options:
- *
- * Present a window to the user allowing him to adjust drawing mode
- * options. Arguments may optionally be passed from an Arexx command.
- *
- */
- int __saveds __asm XDM_Options (register __a0 LONG *args)
- {
- int i;
-
- if (args)
- {
- darken_factor = atoi((char *)args[0]);
- if (darken_factor < 1) darken_factor = 1;
- if (darken_factor > 256) darken_factor = 256;
- }
- else
- {
-
- i = IntegerRequest("Darkening Amount:", 1, 255, darken_factor);
- if (i >= 1)
- {
- darken_factor = i;
- Learn("DrawMode ARGS %ld", darken_factor);
- }
- }
-
- return(0);
- }
-
- /*
- * XDM_LoadPrefs:
- *
- * Set preferences according to information loaded from disk.
- *
- */
- int __saveds __asm XDM_LoadPrefs (register __a0 void *prefs)
- {
- return(1);
- }
-
- /*
- * XDM_SavePrefs:
- *
- * Request preferences settings that are about to be saved to disk.
- *
- */
- int __saveds __asm XDM_SavePrefs (register __a0 void *prefs)
- {
- return(1);
- }
-
-
- int __saveds __asm XDM_Init (void)
- {
- darken_factor = GetIfxVar("DarkenAmount", darken_factor);
- return(1);
- }
-
- void __saveds __asm XDM_Cleanup (void)
- {
- SetIfxVar("DarkenAmount", darken_factor);
- }
-
-
- /**********************************************************************\
-
- Library Initialization Stuff
-
- \**********************************************************************/
-
- /*
- * This is the table of all the functions that can be called in this
- * module. The first four (Open, Close, Expunge, and Null) are reserved
- * for system use and MUST be specified in the order shown. The actual
- * functions are in the standard module startup code.
- */
- ULONG FuncTable[] = {
- /* These four MUST be present in this order */
- (ULONG) LibOpen,
- (ULONG) LibClose,
- (ULONG) LibExpunge,
- (ULONG) LibNull,
-
- /* Specific to the module */
- (ULONG) XDM_Attr,
- (ULONG) XDM_Begin,
- (ULONG) XDM_End,
- (ULONG) XDM_Affect,
- (ULONG) XDM_Options,
- (ULONG) XDM_LoadPrefs,
- (ULONG) XDM_SavePrefs,
- (ULONG) 0,
- (ULONG) 0,
- (ULONG) XDM_Init,
- (ULONG) XDM_Cleanup,
-
- /* End with -1L */
- (ULONG) -1L
- };
-
- /*
- * These are used by the standard module startup code.
- * LibraryName is the name of the library, and LibraryID is a short
- * description of the library. Both of these are largely irrelavent,
- * but they are included just for completeness.
- */
- UBYTE LibraryID[] = "$VER: Darken Drawing Mode 2.0.20 (15.2.95)";
- UBYTE LibraryType = NT_XDRAWMODE;
-
-
- RXCMD RxCmd = { NULL, NULL, "Amount/N" };
-
- /*
- * This is called by the standard module startup code when Image Scan
- * first opens the module. Here we should fill in the NumGads,
- * NewGad, Language, and LangCount fields of the provided ModuleBase
- * structure if necessary.
- */
- long __asm UserOpen (register __a6 struct ModuleBase *modbase)
- {
- modbase->CmdTable = &RxCmd;
-
- return(TRUE);
- }
-
- /*
- * This is called by the standard module startup code when Image Scan
- * closes the module. It should cleanup anything allocated or obtained
- * in the UserOpen() function.
- */
- long __asm UserClose (register __a6 struct ModuleBase *modbase)
- {
- return(TRUE);
- }
-
-