home *** CD-ROM | disk | FTP | other *** search
- /*
- * Sample Scanner Module
- *
- */
-
- #include <exec/types.h>
- #include <scan/modall.h>
-
-
- /**********************************************************************\
-
- Language Indexes
-
- \**********************************************************************/
-
- #define TXT(i) GetStr((i), Default_Strings[(i)])
-
- enum {
- TXT_ScanBar, /* Scanning */
- TXT_ModuleName, /* Skeleton */
- TXT_ScanLabel, /* Scan */
- TXT_ModuleLabel, /* Module: */
- TXT_COUNT
- };
-
- char *Default_Strings[] = {
- "Scanning",
- "Skeleton",
- "Scan",
- "Module:"
- };
-
- /**********************************************************************\
-
- GED Gadget Functions
-
- \**********************************************************************/
-
- /*
- * This function will be called when the user clicks on the Scan
- * button. Normally one would create a new image buffer by scanning
- * or grabbing or whatever.
- *
- */
- int __saveds ScanCode (GedButtonProto)
- {
- struct Buffer *buf;
- UBYTE *red, *grn, *blu;
- int i, j;
-
- /*
- * This example just creates a 320x200 buffer and fills it
- * with some color. Normally, you would control some kind
- * of scanner or framegrabbing device here.
- */
-
- if (InitBuffer(NULL, 320, 200, 3, 8, 0)) {
-
- buf = ObtainBuffer(0);
-
- BeginBar(TXT(TXT_ScanBar), 200, TRUE);
-
- /*
- * Fill in some image data.
- */
-
- for (j = 0; j < 200; j++) {
- if (Bar(j)) {
- /* user cancelled! */
- FreeBuffer();
- return(0);
- }
-
- if (!GetBufLine(buf, &red, &grn, &blu, j)) break;
- for (i = 0; i < 320; i++) {
- red[i] = i * 255 / 319;
- grn[i] = 0; /* don't assume InitBuffer clears the image data!!! */
- blu[i] = i * 255 / 319;
- }
- if (!PutBufLine(buf)) break;
- }
-
- /*
- * Here we could set the image's DPI, Aspect, etc.
- */
-
- buf->PixAspectX = 22;
- buf->PixAspectY = 26;
- buf->DPIX = 72;
- buf->DPIY = 72;
-
- EndBar(NULL);
-
- ReleaseBuffer(buf);
-
- /*
- * Make sure you redraw the image when you're done.
- */
- RenderVirtual();
-
- }
- else {
- Error();
- }
-
- return(0);
- }
-
- /**********************************************************************\
-
- GED GUI Description
-
- \**********************************************************************/
-
- enum {
- ID_Module = 1,
- ID_Scan
- };
-
- struct NewGad newGads[] = {
- /* button to change the scan module */
- { Button_ID, ID_Module, 16,24,102,12, TXT_ModuleName, ChangeScanner,0, NULL, 0,'\0',NULL,0 },
- /* button to initiate scanning */
- { Button_ID, ID_Scan, 16,62,102,12, TXT_ScanLabel, ScanCode,0, NULL, 0,'\0',NULL,0 },
- /* text labelling the change-module gadget above */
- { Text_ID, 0, 67,15,0,0, TXT_ModuleLabel, NULL,0,NULL, 2,0,2,0 },
- { End_ID }
- };
-
- /**********************************************************************\
-
- Housekeeping
-
- \**********************************************************************/
-
- BOOL clear_text = FALSE;
-
- /*
- * SM_Init()
- *
- * Module initialization function. ImageFX will call this function
- * when the module is first loaded into memory (once). Return TRUE
- * if all goes well or FALSE on failure.
- *
- * We need to do a little bit of voodoo magic with the text strings
- * to make the Ged stuff work right.
- *
- */
- int __saveds SM_Init (void)
- {
- if (ModuleBase->Text == NULL) {
- clear_text = TRUE;
- ModuleBase->Text = Default_Strings;
- }
- return(TRUE);
- }
-
- /*
- * SM_Cleanup()
- *
- * Cleanup any and all resources, memory, or whatever allocated
- * in the SM_Init() function above. ImageFX will call this function
- * just before unloading the module.
- *
- */
- void __saveds SM_Cleanup (void)
- {
- if (clear_text) ModuleBase->Text = NULL;
- }
-
- /*
- * SM_Show()
- *
- * This function is called when ImageFX displays this module's
- * GUI onscreen. This can be used as an indicator of when the
- * user "enters" this module (to bring up additional screens or
- * whatever).
- *
- * The window argument is a pointer to ImageFX's main window
- * (where all of this module's gadgets have been added).
- *
- * Return TRUE on success or FALSE on failure.
- *
- */
- int __saveds __asm SM_Show (register __a0 struct Window *window)
- {
- return(TRUE);
- }
-
- /*
- * SM_Clear()
- *
- * This function is called when ImageFX is removing this module's
- * GUI from the display. This can be used as an indicator of when
- * the user "leaves" this module. Generally you should 'undo' whatever
- * it is you did in the SM_Show() function above.
- *
- * The window argument is a pointer to ImageFX's main window
- * (where all of this module's gadgets have been added).
- *
- */
- void __saveds __asm SM_Clear (register __a0 struct Window *window)
- {
- }
-
- /**********************************************************************\
-
- Preferences Handling
-
- \**********************************************************************/
-
- /*
- * This structure defines the format for your preferences. ImageFX
- * will store this structure in the user's prefs files.
- */
- struct MyPrefs {
- short Stuff[4];
- LONG Reserved[8]; /* Always a good idea to reserve some space */
- };
-
- /*
- * SM_LoadPrefs()
- *
- * Configure your module based on the settings in the supplied
- * preferences structure. Note that your module does not necessarily
- * have to be displayed for this function to be called, so make sure
- * that your gadgets exist before fiddling with them. Return TRUE
- * on success, or FALSE on failure.
- *
- */
- BOOL __saveds __asm SM_LoadPrefs (register __a0 struct MyPrefs *prefs)
- {
- return(TRUE);
- }
-
- /*
- * SM_SavePrefs()
- *
- * Store your current module configuration into the supplied
- * preferences structure. ImageFX will then save it to disk.
- *
- */
- BOOL __saveds __asm SM_SavePrefs (register __a0 struct MyPrefs *prefs)
- {
- return(TRUE);
- }
-
- /**********************************************************************\
-
- Miscellaneous
-
- \**********************************************************************/
-
- /*
- * SM_HandleMMove()
- *
- * Called whenever a MOUSEMOVE event is received by ImageFX that it
- * does not understand. You can use this to process events for your
- * own windows that you open.
- *
- * The message passed to you is a copy, DO NOT REPLY TO IT!
- *
- * You should return 1 if you knew how to deal with the event, or
- * 0 if you ignored it.
- *
- * You must set the XF_MOUSETRAP flag in your ModuleBase's ExtFlags
- * field (in the UserOpen function below) to use this feature.
- *
- */
- int __saveds __asm SM_HandleMMove (register __a0 struct IntuiMessage *msg)
- {
- return(0);
- }
-
- /*
- * SM_HandleMButton()
- *
- * Called whenever a MOUSEBUTTON event is received by ImageFX that it
- * does not understand. You can use this to process events for your
- * own windows that you open.
- *
- * The message passed to you is a copy, DO NOT REPLY TO IT!
- *
- * You should return 1 if you knew how to deal with the event, or
- * 0 if you ignored it.
- *
- * You must set the XF_MOUSETRAP flag in your ModuleBase's ExtFlags
- * field (in the UserOpen function below) to use this feature.
- *
- */
- int __saveds __asm SM_HandleMButton (register __a0 struct IntuiMessage *msg)
- {
- return(0);
- }
-
- /*
- * SM_ChangeNotify()
- *
- * Called whenever the main buffer in ImageFX changes (eg. when the
- * user loads or creates a new image). This can be used to update
- * display fields that depend on the image in some way.
- *
- * You must set the XF_LOADNOTIFY flag in your ModuleBase's ExtFlags
- * field (in the UserOpen function below) to use this feature.
- *
- * (Requires ImageFX 1.50 or later.)
- *
- */
- void __saveds SM_ChangeNotify (void)
- {
- }
-
- /**********************************************************************\
-
- Arexx Functions
-
- \**********************************************************************/
-
- /*
- * Sample Arexx command handler. All scanner modules should have a
- * command that starts scanning. This one simply calls the Scan
- * gadget's code handler to do the scanning. You should probably
- * do better return code handling.
- */
- static int __saveds __stdargs Arexx_Go (ArexxProto)
- {
- ScanCode(NULL, NULL, 0);
- return(0);
- }
-
- /*
- * This table defines all the Arexx commands we understand. The
- * user sends us Arexx commands via. the ImageFX "SCANNER" command.
- * We must supply a pointer to this table in the UserOpen()
- * function below.
- */
- static RXCMD MyRexxCommands[] = {
- { "SCAN", Arexx_Go, "" },
- { NULL }
- };
-
- /**********************************************************************\
-
- Standard Module Stuff
-
- \**********************************************************************/
-
-
- /*
- * Function table. Referenced in "lib.o".
- *
- * The first four entries are the standard library vectors, defined
- * in "lib.o", the remaining entries define functions specific to
- * this module.
- *
- * The table ends with -1.
- *
- */
- ULONG FuncTable[] = {
- (ULONG) LibOpen,
- (ULONG) LibClose,
- (ULONG) LibExpunge,
- (ULONG) LibNull,
-
- (ULONG) SM_Init,
- (ULONG) SM_Cleanup,
- (ULONG) SM_Show,
- (ULONG) SM_Clear,
- (ULONG) 0, /* unused */
-
- (ULONG) SM_LoadPrefs,
- (ULONG) SM_SavePrefs,
-
- (ULONG) SM_HandleMMove,
- (ULONG) SM_HandleMButton,
-
- (ULONG) SM_ChangeNotify,
-
- (ULONG) 0, /* reserved */
- (ULONG) 0, /* reserved */
- (ULONG) 0, /* reserved */
-
- (ULONG) -1L
- };
-
- /*
- * ID string for this module. References in "lib.o".
- *
- * Should be given in the standard 2.0 version string style.
- */
- UBYTE LibraryID[] = "$VER: Untitled 1.00.00 (19.6.92)";
-
- /*
- * Type of module. Referenced in "lib.o".
- *
- * Should be one of the NT_* defines in <scan/mod.h>
- *
- */
- UBYTE LibraryType = NT_SCANNER;
-
- /*
- * Module initialization code. Referenced by "lib.o".
- *
- * This is where you would initialize the ModuleBase structure that
- * is passed to you.
- *
- * Returns TRUE if all went well, or FALSE if something went wrong and
- * the module open should fail.
- *
- */
- LONG __saveds __stdargs UserOpen (struct ModuleBase *modbase)
- {
- modbase->NewGad = newGads; /* GUI */
- modbase->Language = "Scanner_Skeleton"; /* Language tag */
- modbase->LangCount = TXT_COUNT; /* Number of texts */
- modbase->CmdTable = MyRexxCommands; /* Arexx cmd table */
- modbase->PrefID = 'SSKL'; /* Preferences tag */
- modbase->PrefLen = sizeof(struct MyPrefs); /* Size of prefs data */
- return(TRUE);
- }
-
- /*
- * Module cleanup code. Referenced by "lib.o".
- *
- * This should cleanup anything you allocated or opened in UserOpen()
- * above.
- *
- * Always return TRUE.
- *
- */
- LONG __saveds __stdargs UserClose (struct ModuleBase *modbase)
- {
- return(TRUE);
- }
-