home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2002 April / pcpro0402.iso / essentials / graphics / Gimp / gimp-src-20001226.exe / src / gimp / plug-ins / twain / tw_func.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-29  |  7.0 KB  |  236 lines

  1. /*  
  2.  * TWAIN Plug-in
  3.  * Copyright (C) 1999 Craig Setera
  4.  * Craig Setera <setera@home.com>
  5.  * 03/31/1999
  6.  *
  7.  * This program is free software; you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License as published by
  9.  * the Free Software Foundation; either version 2 of the License, or
  10.  * (at your option) any later version.
  11.  *
  12.  * This program is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  * GNU General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU General Public License
  18.  * along with this program; if not, write to the Free Software
  19.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20.  *
  21.  *
  22.  * Based on (at least) the following plug-ins:
  23.  * Screenshot
  24.  * GIF
  25.  * Randomize
  26.  *
  27.  * Any suggestions, bug-reports or patches are welcome.
  28.  * 
  29.  * This plug-in interfaces to the TWAIN support library in order
  30.  * to capture images from TWAIN devices directly into GIMP images.
  31.  * The plug-in is capable of acquiring the following type of
  32.  * images:
  33.  * - B/W (1 bit images translated to grayscale B/W)
  34.  * - Grayscale up to 16 bits per pixel
  35.  * - RGB up to 16 bits per sample (24, 30, 36, etc.)
  36.  * - Paletted images (both Gray and RGB)
  37.  *
  38.  * Prerequisites:
  39.  *  This plug-in will not compile on anything other than a Win32
  40.  *  platform.  Although the TWAIN documentation implies that there
  41.  *  is TWAIN support available on Macintosh, I neither have a 
  42.  *  Macintosh nor the interest in porting this.  If anyone else
  43.  *  has an interest, consult www.twain.org for more information on
  44.  *  interfacing to TWAIN.
  45.  *
  46.  * Known problems:
  47.  * - Multiple image transfers will hang the plug-in.  The current
  48.  *   configuration compiles with a maximum of single image transfers.
  49.  */
  50.  
  51. /* 
  52.  * Revision history
  53.  *  (02/07/99)  v0.1   First working version (internal)
  54.  *  (02/09/99)  v0.2   First release to anyone other than myself
  55.  *  (02/15/99)  v0.3   Added image dump and read support for debugging
  56.  *  (03/31/99)  v0.5   Added support for multi-byte samples and paletted 
  57.  *                     images.
  58.  */
  59.  
  60. #ifndef _TW_FUNC_H
  61. #define _TW_FUNC_H
  62. #include "twain.h"
  63.  
  64. /*
  65.  * Pre-image transfer function type
  66.  *
  67.  * Sent to the caller before any of the
  68.  * images are transferred to the application.
  69.  */
  70. typedef void (* TW_PRE_TXFR_CB)(void *);
  71.  
  72. /*
  73.  * Image transfer begin function type
  74.  *
  75.  * Sent to the caller when an image transfer
  76.  * is about to begin.  The caller may return
  77.  * FALSE if the transfer should not continue.
  78.  * Otherwise, the function should return a
  79.  * TRUE value.
  80.  */
  81. typedef int (* TW_TXFR_BEGIN_CB)(pTW_IMAGEINFO, void *);
  82.  
  83. /*
  84.  * Image transfer callback function type
  85.  *
  86.  * Expected to return true if the image transfer
  87.  * should continue.  False if the transfer should
  88.  * be cancelled.
  89.  */
  90. typedef int (* TW_TXFR_DATA_CB)(pTW_IMAGEINFO, pTW_IMAGEMEMXFER, void *);
  91.  
  92. /*
  93.  * Image transfer end function type
  94.  *
  95.  * Sent to the caller when an image transfer
  96.  * is completed.  The caller will be handed
  97.  * the image transfer completion state.  The
  98.  * following values (defined in twain.h) are
  99.  * possible:
  100.  *
  101.  * TWRC_XFERDONE
  102.  *  The transfer completed successfully
  103.  * TWRC_CANCEL
  104.  *  The transfer was completed by the user
  105.  * TWRC_FAILURE
  106.  *  The transfer failed.
  107.  */
  108. typedef int (* TW_TXFR_END_CB)(int, int, void *);
  109.  
  110. /*
  111.  * Post-image transfer callback
  112.  *
  113.  * This callback function is called after all
  114.  * of the possible images have been transferred
  115.  * from the datasource.
  116.  */
  117. typedef void (* TW_POST_TXFR_CB)(int, void *);
  118.  
  119. /*
  120.  * The following structure defines the
  121.  * three callback functions that are called
  122.  * while an image is being transferred.
  123.  * The types of these functions are defined
  124.  * above.  Any function that is NULL will just
  125.  * not be called.
  126.  */
  127. typedef struct _TXFR_CB_FUNCS {
  128.   /* Pre-transfer function */
  129.   TW_PRE_TXFR_CB preTxfrCb;
  130.  
  131.   /* Begin function */
  132.   TW_TXFR_BEGIN_CB txfrBeginCb;
  133.  
  134.   /* Data transfer */
  135.   TW_TXFR_DATA_CB txfrDataCb;
  136.  
  137.   /* End function */
  138.   TW_TXFR_END_CB txfrEndCb;
  139.  
  140.   /* Post-transfer function */
  141.   TW_POST_TXFR_CB postTxfrCb;
  142. } TXFR_CB_FUNCS, *pTXFR_CB_FUNCS;
  143.  
  144. /*
  145.  * Data representing a TWAIN
  146.  * application to data source
  147.  * session.
  148.  */
  149. typedef struct _TWAIN_SESSION {
  150.   /* The window handle related to the TWAIN application */
  151.   HWND hwnd;
  152.  
  153.   /* The current TWAIN return code */
  154.   TW_UINT16 twRC;
  155.  
  156.   /* The application's TWAIN identity */
  157.   pTW_IDENTITY appIdentity;
  158.  
  159.   /* The datasource's TWAIN identity */
  160.   pTW_IDENTITY dsIdentity;
  161.  
  162.   /* The image data transfer functions */
  163.   pTXFR_CB_FUNCS transferFunctions;
  164.  
  165.   /* Client data that is associated with the image
  166.    * transfer callback
  167.    */
  168.   void *clientData;
  169.  
  170.   /*
  171.    * The following variable tracks the current state
  172.    * as related to the TWAIN engine.  The states are:
  173.    *
  174.    * 1) Pre-session: The DSM has not been loaded
  175.    * 2) Source Manager Loaded (not opened)
  176.    * 3) Source Manager Opened
  177.    * 4) Source Open
  178.    * 5) Source Enabled
  179.    * 6) Transfer ready
  180.    * 7) Transferring
  181.    */
  182.   int twainState;
  183.  
  184. } TW_SESSION, *pTW_SESSION;
  185.  
  186. /* Session structure access
  187.  * macros
  188.  */
  189. /* #define pAPP_IDENTITY(tw_session) (&(tw_session->appIdentity)) */
  190. #define APP_IDENTITY(tw_session) (tw_session->appIdentity)
  191. /* #define pDS_IDENTITY(tw_session) (&(tw_session->dsIdentity)) */
  192. #define DS_IDENTITY(tw_session) (tw_session->dsIdentity)
  193.  
  194. /* State macros... Each expects
  195.  * a Twain Session pointer
  196.  */
  197. #define TWAIN_LOADED(tw_session) (tw_session->twainState >= 2)
  198. #define TWAIN_UNLOADED(tw_session) (tw_session->twainState < 2)
  199. #define DSM_IS_OPEN(tw_session) (tw_session->twainState >= 3)
  200. #define DSM_IS_CLOSED(tw_session) (tw_session->twainState < 3)
  201. #define DS_IS_OPEN(tw_session) (tw_session->twainState >= 4)
  202. #define DS_IS_CLOSED(tw_session) (tw_session->twainState < 4)
  203. #define DS_IS_ENABLED(tw_session) (tw_session->twainState >= 5)
  204. #define DS_IS_DISABLED(tw_session) (tw_session->twainState < 5)
  205.  
  206. /* Function declarations */
  207. TW_UINT16 callDSM(pTW_IDENTITY, pTW_IDENTITY, 
  208.           TW_UINT32, TW_UINT16, 
  209.           TW_UINT16, TW_MEMREF);
  210. char *twainError(int);
  211. char *currentTwainError(pTW_SESSION);
  212. int twainIsAvailable(void);
  213. int getImage(pTW_SESSION);
  214. int loadTwainLibrary(pTW_SESSION);
  215. int openDSM(pTW_SESSION);
  216. int selectDS(pTW_SESSION);
  217. int selectDefaultDS(pTW_SESSION);
  218. int openDS(pTW_SESSION);
  219. int requestImageAcquire(pTW_SESSION, BOOL);
  220. int disableDS(pTW_SESSION);
  221. int closeDS(pTW_SESSION);
  222. int closeDSM(pTW_SESSION);
  223. int unloadTwainLibrary(pTW_SESSION);
  224. int twainMessageLoop(pTW_SESSION);
  225. void cancelPendingTransfers(pTW_SESSION);
  226.  
  227. TW_FIX32 FloatToFix32(float);
  228. float FIX32ToFloat(TW_FIX32);
  229.  
  230. pTW_SESSION newSession(pTW_IDENTITY);
  231. void registerWindowHandle(pTW_SESSION, HWND);
  232. void registerTransferCallbacks(pTW_SESSION, pTXFR_CB_FUNCS, void *);
  233. void setClientData(pTW_SESSION session, void *clientData);
  234.  
  235. #endif /* _TW_FUNC_H */
  236.