home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / gfx / misc / imagefx_sdk / sas / examples / scanner / skeleton.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-02  |  10.7 KB  |  435 lines

  1. /*
  2.  * Sample Scanner Module
  3.  *
  4.  */
  5.  
  6. #include <exec/types.h>
  7. #include <scan/modall.h>
  8.  
  9.  
  10. /**********************************************************************\
  11.  
  12.                            Language Indexes
  13.  
  14. \**********************************************************************/
  15.  
  16. #define TXT(i)             GetStr((i), Default_Strings[(i)])
  17.  
  18. enum {
  19.    TXT_ScanBar,            /* Scanning */
  20.    TXT_ModuleName,         /* Skeleton */
  21.    TXT_ScanLabel,          /* Scan */
  22.    TXT_ModuleLabel,        /* Module: */
  23.    TXT_COUNT
  24. };
  25.  
  26. char *Default_Strings[] = {
  27.    "Scanning",
  28.    "Skeleton",
  29.    "Scan",
  30.    "Module:"
  31. };
  32.  
  33. /**********************************************************************\
  34.  
  35.                          GED Gadget Functions
  36.  
  37. \**********************************************************************/
  38.  
  39. /*
  40.  * This function will be called when the user clicks on the Scan
  41.  * button.  Normally one would create a new image buffer by scanning
  42.  * or grabbing or whatever.
  43.  *
  44.  */
  45. int __saveds ScanCode (GedButtonProto)
  46. {
  47.    struct Buffer *buf;
  48.    UBYTE *red, *grn, *blu;
  49.    int i, j;
  50.  
  51.    /*
  52.     * This example just creates a 320x200 buffer and fills it
  53.     * with some color.  Normally, you would control some kind
  54.     * of scanner or framegrabbing device here.
  55.     */
  56.  
  57.    if (InitBuffer(NULL, 320, 200, 3, 8, 0)) {
  58.  
  59.       buf = ObtainBuffer(0);
  60.  
  61.       BeginBar(TXT(TXT_ScanBar), 200, TRUE);
  62.  
  63.       /*
  64.        * Fill in some image data.
  65.        */
  66.  
  67.       for (j = 0; j < 200; j++) {
  68.          if (Bar(j)) {
  69.             /* user cancelled! */
  70.             FreeBuffer();
  71.             return(0);
  72.          }
  73.  
  74.          if (!GetBufLine(buf, &red, &grn, &blu, j)) break;
  75.          for (i = 0; i < 320; i++) {
  76.             red[i] = i * 255 / 319;
  77.             grn[i] = 0;  /* don't assume InitBuffer clears the image data!!! */
  78.             blu[i] = i * 255 / 319;
  79.          }
  80.          if (!PutBufLine(buf)) break;
  81.       }
  82.  
  83.       /*
  84.        * Here we could set the image's DPI, Aspect, etc.
  85.        */
  86.  
  87.       buf->PixAspectX = 22;
  88.       buf->PixAspectY = 26;
  89.       buf->DPIX = 72;
  90.       buf->DPIY = 72;
  91.  
  92.       EndBar(NULL);
  93.  
  94.       ReleaseBuffer(buf);
  95.  
  96.       /*
  97.        * Make sure you redraw the image when you're done.
  98.        */
  99.       RenderVirtual();
  100.  
  101.    }
  102.    else {
  103.       Error();
  104.    }
  105.  
  106.    return(0);
  107. }
  108.  
  109. /**********************************************************************\
  110.  
  111.                          GED GUI Description
  112.  
  113. \**********************************************************************/
  114.  
  115. enum {
  116.    ID_Module = 1,
  117.    ID_Scan
  118. };
  119.  
  120. struct NewGad newGads[] = {
  121.       /* button to change the scan module */
  122.     { Button_ID, ID_Module, 16,24,102,12, TXT_ModuleName, ChangeScanner,0, NULL, 0,'\0',NULL,0  },
  123.        /* button to initiate scanning */
  124.     { Button_ID, ID_Scan, 16,62,102,12, TXT_ScanLabel, ScanCode,0, NULL, 0,'\0',NULL,0 },
  125.        /* text labelling the change-module gadget above */
  126.     { Text_ID, 0, 67,15,0,0, TXT_ModuleLabel, NULL,0,NULL, 2,0,2,0  },
  127.     { End_ID }
  128. };
  129.  
  130. /**********************************************************************\
  131.  
  132.                              Housekeeping
  133.  
  134. \**********************************************************************/
  135.  
  136. BOOL clear_text = FALSE;
  137.  
  138. /*
  139.  * SM_Init()
  140.  *
  141.  * Module initialization function.  ImageFX will call this function
  142.  * when the module is first loaded into memory (once).  Return TRUE
  143.  * if all goes well or FALSE on failure.
  144.  *
  145.  * We need to do a little bit of voodoo magic with the text strings
  146.  * to make the Ged stuff work right.
  147.  *
  148.  */
  149. int __saveds SM_Init (void)
  150. {
  151.    if (ModuleBase->Text == NULL) {
  152.       clear_text = TRUE;
  153.       ModuleBase->Text = Default_Strings;
  154.    }
  155.    return(TRUE);
  156. }
  157.  
  158. /*
  159.  * SM_Cleanup()
  160.  *
  161.  * Cleanup any and all resources, memory, or whatever allocated
  162.  * in the SM_Init() function above.  ImageFX will call this function
  163.  * just before unloading the module.
  164.  *
  165.  */
  166. void __saveds SM_Cleanup (void)
  167. {
  168.    if (clear_text) ModuleBase->Text = NULL;
  169. }
  170.  
  171. /*
  172.  * SM_Show()
  173.  *
  174.  * This function is called when ImageFX displays this module's
  175.  * GUI onscreen.  This can be used as an indicator of when the
  176.  * user "enters" this module (to bring up additional screens or
  177.  * whatever).
  178.  *
  179.  * The window argument is a pointer to ImageFX's main window
  180.  * (where all of this module's gadgets have been added).
  181.  *
  182.  * Return TRUE on success or FALSE on failure.
  183.  *
  184.  */
  185. int __saveds __asm SM_Show (register __a0 struct Window *window)
  186. {
  187.    return(TRUE);
  188. }
  189.  
  190. /*
  191.  * SM_Clear()
  192.  *
  193.  * This function is called when ImageFX is removing this module's
  194.  * GUI from the display.  This can be used as an indicator of when
  195.  * the user "leaves" this module.  Generally you should 'undo' whatever
  196.  * it is you did in the SM_Show() function above.
  197.  *
  198.  * The window argument is a pointer to ImageFX's main window
  199.  * (where all of this module's gadgets have been added).
  200.  *
  201.  */
  202. void __saveds __asm SM_Clear (register __a0 struct Window *window)
  203. {
  204. }
  205.  
  206. /**********************************************************************\
  207.  
  208.                           Preferences Handling
  209.  
  210. \**********************************************************************/
  211.  
  212. /*
  213.  * This structure defines the format for your preferences.  ImageFX
  214.  * will store this structure in the user's prefs files.
  215.  */
  216. struct MyPrefs {
  217.    short Stuff[4];
  218.    LONG  Reserved[8];   /* Always a good idea to reserve some space */
  219. };
  220.  
  221. /*
  222.  * SM_LoadPrefs()
  223.  *
  224.  * Configure your module based on the settings in the supplied
  225.  * preferences structure.  Note that your module does not necessarily
  226.  * have to be displayed for this function to be called, so make sure
  227.  * that your gadgets exist before fiddling with them.  Return TRUE
  228.  * on success, or FALSE on failure.
  229.  *
  230.  */
  231. BOOL __saveds __asm SM_LoadPrefs (register __a0 struct MyPrefs *prefs)
  232. {
  233.    return(TRUE);
  234. }
  235.  
  236. /*
  237.  * SM_SavePrefs()
  238.  *
  239.  * Store your current module configuration into the supplied
  240.  * preferences structure.  ImageFX will then save it to disk.
  241.  *
  242.  */
  243. BOOL __saveds __asm SM_SavePrefs (register __a0 struct MyPrefs *prefs)
  244. {
  245.    return(TRUE);
  246. }
  247.  
  248. /**********************************************************************\
  249.  
  250.                               Miscellaneous
  251.  
  252. \**********************************************************************/
  253.  
  254. /*
  255.  * SM_HandleMMove()
  256.  *
  257.  * Called whenever a MOUSEMOVE event is received by ImageFX that it
  258.  * does not understand.  You can use this to process events for your
  259.  * own windows that you open.
  260.  *
  261.  * The message passed to you is a copy, DO NOT REPLY TO IT!
  262.  *
  263.  * You should return 1 if you knew how to deal with the event, or
  264.  * 0 if you ignored it.
  265.  *
  266.  * You must set the XF_MOUSETRAP flag in your ModuleBase's ExtFlags
  267.  * field (in the UserOpen function below) to use this feature.
  268.  *
  269.  */
  270. int __saveds __asm SM_HandleMMove (register __a0 struct IntuiMessage *msg)
  271. {
  272.    return(0);
  273. }
  274.  
  275. /*
  276.  * SM_HandleMButton()
  277.  *
  278.  * Called whenever a MOUSEBUTTON event is received by ImageFX that it
  279.  * does not understand.  You can use this to process events for your
  280.  * own windows that you open.
  281.  *
  282.  * The message passed to you is a copy, DO NOT REPLY TO IT!
  283.  *
  284.  * You should return 1 if you knew how to deal with the event, or
  285.  * 0 if you ignored it.
  286.  *
  287.  * You must set the XF_MOUSETRAP flag in your ModuleBase's ExtFlags
  288.  * field (in the UserOpen function below) to use this feature.
  289.  *
  290.  */
  291. int __saveds __asm SM_HandleMButton (register __a0 struct IntuiMessage *msg)
  292. {
  293.    return(0);
  294. }
  295.  
  296. /*
  297.  * SM_ChangeNotify()
  298.  *
  299.  * Called whenever the main buffer in ImageFX changes (eg. when the
  300.  * user loads or creates a new image).  This can be used to update
  301.  * display fields that depend on the image in some way.
  302.  *
  303.  * You must set the XF_LOADNOTIFY flag in your ModuleBase's ExtFlags
  304.  * field (in the UserOpen function below) to use this feature.
  305.  *
  306.  * (Requires ImageFX 1.50 or later.)
  307.  *
  308.  */
  309. void __saveds SM_ChangeNotify (void)
  310. {
  311. }
  312.  
  313. /**********************************************************************\
  314.  
  315.                              Arexx Functions
  316.  
  317. \**********************************************************************/
  318.  
  319. /*
  320.  * Sample Arexx command handler.  All scanner modules should have a
  321.  * command that starts scanning.  This one simply calls the Scan
  322.  * gadget's code handler to do the scanning.  You should probably
  323.  * do better return code handling.
  324.  */
  325. static int __saveds __stdargs Arexx_Go (ArexxProto)
  326. {
  327.    ScanCode(NULL, NULL, 0);
  328.    return(0);
  329. }
  330.  
  331. /*
  332.  * This table defines all the Arexx commands we understand.  The
  333.  * user sends us Arexx commands via. the ImageFX "SCANNER" command.
  334.  * We must supply a pointer to this table in the UserOpen()
  335.  * function below.
  336.  */
  337. static RXCMD MyRexxCommands[] = {
  338.    { "SCAN",      Arexx_Go,      "" },
  339.    { NULL }
  340. };
  341.  
  342. /**********************************************************************\
  343.  
  344.                          Standard Module Stuff
  345.  
  346. \**********************************************************************/
  347.  
  348.  
  349. /*
  350.  * Function table.  Referenced in "lib.o".
  351.  *
  352.  * The first four entries are the standard library vectors, defined
  353.  * in "lib.o", the remaining entries define functions specific to
  354.  * this module.
  355.  *
  356.  * The table ends with -1.
  357.  *
  358.  */
  359. ULONG FuncTable[] = {
  360.    (ULONG) LibOpen,
  361.    (ULONG) LibClose,
  362.    (ULONG) LibExpunge,
  363.    (ULONG) LibNull,
  364.  
  365.    (ULONG) SM_Init,
  366.    (ULONG) SM_Cleanup,
  367.    (ULONG) SM_Show,
  368.    (ULONG) SM_Clear,
  369.    (ULONG) 0,              /* unused */
  370.  
  371.    (ULONG) SM_LoadPrefs,
  372.    (ULONG) SM_SavePrefs,
  373.  
  374.    (ULONG) SM_HandleMMove,
  375.    (ULONG) SM_HandleMButton,
  376.  
  377.    (ULONG) SM_ChangeNotify,
  378.  
  379.    (ULONG) 0,              /* reserved */
  380.    (ULONG) 0,              /* reserved */
  381.    (ULONG) 0,              /* reserved */
  382.  
  383.    (ULONG) -1L
  384. };
  385.  
  386. /*
  387.  * ID string for this module.  References in "lib.o".
  388.  *
  389.  * Should be given in the standard 2.0 version string style.
  390.  */
  391. UBYTE LibraryID[] = "$VER: Untitled 1.00.00 (19.6.92)";
  392.  
  393. /*
  394.  * Type of module.  Referenced in "lib.o".
  395.  *
  396.  * Should be one of the NT_* defines in <scan/mod.h>
  397.  *
  398.  */
  399. UBYTE LibraryType = NT_SCANNER;
  400.  
  401. /*
  402.  * Module initialization code.  Referenced by "lib.o".
  403.  *
  404.  * This is where you would initialize the ModuleBase structure that
  405.  * is passed to you.
  406.  *
  407.  * Returns TRUE if all went well, or FALSE if something went wrong and
  408.  * the module open should fail.
  409.  *
  410.  */
  411. LONG __saveds __stdargs UserOpen (struct ModuleBase *modbase)
  412. {
  413.    modbase->NewGad = newGads;                   /* GUI */
  414.    modbase->Language = "Scanner_Skeleton";      /* Language tag */
  415.    modbase->LangCount = TXT_COUNT;              /* Number of texts */
  416.    modbase->CmdTable = MyRexxCommands;          /* Arexx cmd table */
  417.    modbase->PrefID = 'SSKL';                    /* Preferences tag */
  418.    modbase->PrefLen = sizeof(struct MyPrefs);   /* Size of prefs data */
  419.    return(TRUE);
  420. }
  421.  
  422. /*
  423.  * Module cleanup code.  Referenced by "lib.o".
  424.  *
  425.  * This should cleanup anything you allocated or opened in UserOpen()
  426.  * above.
  427.  *
  428.  * Always return TRUE.
  429.  *
  430.  */
  431. LONG __saveds __stdargs UserClose (struct ModuleBase *modbase)
  432. {
  433.    return(TRUE);
  434. }
  435.