home *** CD-ROM | disk | FTP | other *** search
- /*
- * A Disperse Enhanced Drawing Mode for ImageFX 2.0
- *
- * 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 <math.h>
- #include <string.h>
-
-
- static int density = 1;
-
-
- /**********************************************************************\
-
- 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;
- da->Priority = 113;
- da->HorizOffs = 1;
- da->VertOffs = 1;
- return(0);
- }
-
- /*
- * XDM_Init:
- *
- * Initialize the drawing mode.
- *
- */
- int __saveds __asm XDM_Init (void)
- {
- density = GetIfxVar("DisperseDensity", density);
- return(1);
- }
-
- /*
- * XDM_Cleanup:
- *
- * Cleanup the drawing mode.
- *
- */
- void __saveds __asm XDM_Cleanup (void)
- {
- SetIfxVar("DisperseDensity", density);
- }
-
- /*
- * 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
-
- int i, j;
- UBYTE *ored, *ogrn, *oblu;
- UBYTE *ired, *igrn, *iblu;
- int brow = di->BufW;
- int x, y;
- int t, u;
- int c;
-
- for (j = 0; j < di->Height; j++)
- {
- GetBufLines(di->BBuf, &ired, &igrn, &iblu, j, 3);
- ired += di->BufW + 1;
- igrn += di->BufW + 1;
- iblu += di->BufW + 1;
- for (i = 0; i < di->Width; i++)
- {
-
- for (c = 0; c < density; c++)
- {
- x = ((lrand48() >> 11) & 3) - 1; if (x == 2) x = 1;
- y = ((lrand48() >> 13) & 3) - 1; if (y == 2) y = 1;
-
- t = *(ired+(y*brow)+x);
- u = *(ired);
- *(ired+(y*brow)+x) = u;
- *(ired) = t;
-
- t = *(igrn+(y*brow)+x);
- u = *(igrn);
- *(igrn+(y*brow)+x) = u;
- *(igrn) = t;
-
- t = *(iblu+(y*brow)+x);
- u = *(iblu);
- *(iblu+(y*brow)+x) = u;
- *(iblu) = t;
- }
-
- ired++; igrn++; iblu++;
- }
- PutBufLines(di->BBuf, -1, -1);
- }
-
- ored = di->OutR;
- ogrn = di->OutG;
- oblu = di->OutB;
-
- for (j = 0; j < di->Height; j++)
- {
- GetBufLine(di->BBuf, &ired, &igrn, &iblu, j + 1);
- GetBufLine(di->BOut, &ored, &ogrn, &oblu, j);
- memcpy(ored, ired + 1, di->Width);
- memcpy(ogrn, igrn + 1, di->Width);
- memcpy(oblu, iblu + 1, di->Width);
- PutBufLine(di->BOut);
- }
-
- #else
-
- int i, j;
- UBYTE *ored, *ogrn, *oblu;
- UBYTE *ired, *igrn, *iblu;
- int brow = di->BufW;
- int x, y;
- int t, u;
- int c;
-
- for (j = 0; j < di->Height; j++)
- {
- ired = di->BufR + (j * di->BufW);
- igrn = di->BufG + (j * di->BufW);
- iblu = di->BufB + (j * di->BufW);
- for (i = 0; i < di->Width; i++)
- {
-
- for (c = 0; c < density; c++)
- {
- x = ((lrand48() >> 11) & 3) - 1; if (x == 2) x = 1;
- y = ((lrand48() >> 13) & 3) - 1; if (y == 2) y = 1;
-
- t = *(ired+(y*brow)+x);
- u = *(ired);
- *(ired+(y*brow)+x) = u;
- *(ired) = t;
-
- t = *(igrn+(y*brow)+x);
- u = *(igrn);
- *(igrn+(y*brow)+x) = u;
- *(igrn) = t;
-
- t = *(iblu+(y*brow)+x);
- u = *(iblu);
- *(iblu+(y*brow)+x) = u;
- *(iblu) = t;
- }
-
- ired++; igrn++; iblu++;
- }
- }
-
- ored = di->OutR;
- ogrn = di->OutG;
- oblu = di->OutB;
-
- for (j = 0; j < di->Height; j++)
- {
- ired = di->BufR + (j * di->BufW);
- igrn = di->BufG + (j * di->BufW);
- iblu = di->BufB + (j * di->BufW);
- for (i = 0; i < di->Width; i++)
- {
- *ored++ = *ired++;
- *ogrn++ = *igrn++;
- *oblu++ = *iblu++;
- }
- }
-
- #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.
- * This function will only be called if the flag XDMF_AreOptions is
- * returned from XDM_Attr().
- *
- */
- int __saveds __asm XDM_Options (register __a0 LONG *args)
- {
- int d;
-
- d = IntegerRequest("Disperse Density:", 1, 8, density);
- if (d < 1) return(0);
- density = d;
- 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);
- }
-
-
- /**********************************************************************\
-
- 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: Disperse Extended Drawing Mode 2.0.9 (15.2.95)";
- UBYTE LibraryType = NT_XDRAWMODE;
-
- /*
- * 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)
- {
- 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);
- }
-
-