home *** CD-ROM | disk | FTP | other *** search
- /*
- * Sample3
- *
- * This sample demonstrates some of the newer features in ImageFX.
- * It shows the recommended way to handle Arexx arguments, remember
- * GUI settings,
- *
- * This hook does a simple blur.
- *
- * Written by Thomas Krehbiel, 15-Jan-95
- *
- */
-
- #include <scan/hooks.h>
- #include <scan/procinfo.h>
- #include <clib/dos_protos.h>
- #include <clib/intuition_protos.h>
- #include <clib/graphics_protos.h>
-
-
- /* This information is required by the "start.o" startup code. */
- char *HookName = "Sample3";
-
- /* A version string so the Version command works on us. */
- char *HookVersion = "\0$VER: Sample3 2.0.6 (15.2.95)";
-
-
- /*******************************************************************
- *
- * Defines
- *
- *******************************************************************/
-
- #define MIN(a,b) ((a) < (b) ? (a) : (b))
-
-
- /*******************************************************************
- *
- * Text Array and Indexes
- *
- *******************************************************************/
-
- /* This information is required by the "start.o" startup code. */
- /* For this example, we're not doing any localization stuff. */
-
- char *HookText = "Hook_Sample3";
- int HookTextCount = 0;
- char **HookStrings[] = { NULL };
-
-
- /*******************************************************************
- *
- * Support functions
- *
- *******************************************************************/
-
- static void __inline do_blur (UBYTE *src, UBYTE *dst, LONG n, LONG bytes, LONG center)
- {
- register LONG total;
- register LONG bytes2 = bytes * 2;
-
- while (n--)
- {
-
- total = *(src-1) + *(src) + *(src+1) +
- *(src+bytes-1) + *(src+bytes) * center + *(src+bytes+1) +
- *(src+bytes2-1) + *(src+bytes2) + *(src+bytes2+1);
-
- *dst++ = total / (8 + center);
- src++;
-
- }
- }
-
- /*******************************************************************
- *
- * Hook entry point is here.
- *
- *******************************************************************/
-
- void hook_main (int argc, char **argv)
- {
- struct Buffer *buf;
- struct ProcessInfo *pi;
- LONG argarray[8] = { 0 };
- APTR as;
- int amount;
- int j;
- BOOL success = FALSE;
-
- // ObtainCurrentBuffer() returns a pointer to the buffer we should
- // work on. This could be either the main buffer or the current
- // brush, depending on the Region setting.
-
- if (!(buf = ObtainCurrentBuffer()))
- hook_exit(20);
-
- if (argc > 1)
- {
- // arexx arguments were provided. We use the ReadArgv() function
- // found in scan.lib to parse the arguments. ReadArgv() performs
- // almost the same function as ReadArgs() in dos.library. The
- // format of the results in argarray[] are the same as ReadArgs().
-
- if (as = ReadArgv(argc, argv, "Amount/N", argarray))
- {
- amount = *((LONG *)argarray[0]);
- FreeArgv(as);
- }
- }
- else
- {
- // no arexx arguments provided. Show our interface. We use
- // GetIfxVar() in scan.lib to find out what the last value the
- // user entered into this requester was.
-
- amount = GetIfxVar("HookBlurAmount", 8);
- amount = IntegerRequest("Enter blur amount:", 1, 16, amount);
- if (amount < 1)
- {
- SetError(ERR_UserCancel);
- hook_exit(20);
- }
-
- // save this setting with SetIfxVar() for the next time we run
- // this hook.
- SetIfxVar("HookBlurAmount", amount);
- }
-
- amount = 17 - amount; // reverse logic of amount
-
- // This example uses the PrepareProcess()/FinishProcess() function
- // calls to process the image. The PFF_UNDO flag tells PrepareProcess()
- // to save an undo buffer before proceeding. Using these functions
- // ensures that your hook will handle feathering, regions, include/exclude,
- // channel masks, virtual memory, and any other miscellaneous settings
- // properly.
-
- if (pi = PrepareProcess("Sample3", buf, 3, 3, PPF_UNDO))
- {
- for (j = 0; j < pi->Height; j++)
- {
- if (!(success = GetData(pi, j - 1, 3, 0))) break;
- do_blur(pi->SR, pi->TR, pi->Width, pi->Bytes, amount);
- if (buf->Depth > 1)
- {
- do_blur(pi->SG, pi->TG, pi->Width, pi->Bytes, amount);
- do_blur(pi->SB, pi->TB, pi->Width, pi->Bytes, amount);
- }
- if (!(success = PutData(pi, j, 1, 0))) break;
- }
- FinishProcess(pi);
-
- // if successful, we should call the scan.library Learn() function
- // to record the settings necessary to duplicate what was just
- // done. This is recorded into a learn file if this feature is
- // enabled by the user.
- if (success) Learn("Hook Sample3 %ld", 17 - amount);
- }
-
- // if successful, redraw what was modified
- if (success)
- RedrawCurrent();
-
- // ImageFX checks the error value after the hook is finished. If it
- // is non-zero, ImageFX displays an error requester corresponding
- // to the error value returned. Otherwise, no requester is shown.
- SetError(0);
- }
-