[gimp/bug-357818: 3/10] Bug 357818 - TWAIN plug-in - Moved defines, typedefs and prototypes into headers.



commit 1469596baeda208cd33273392435fb08a10a046b
Author: Jens M. Plonka <jens plonka gmx de>
Date:   Fri Jun 3 01:26:27 2016 +0200

    Bug 357818 - TWAIN plug-in - Moved defines, typedefs and prototypes into headers.
    
    Adapted to 2.8 by Dieter Verfaillie <dieterv optionexplicit be>
    Applying a slightly changed patch to accommodate for the code changes since the original patch had been 
made.

 plug-ins/twain/tw_func.c     |  117 +++++++++++++++++----------------------
 plug-ins/twain/tw_func.h     |   35 +++++------
 plug-ins/twain/tw_local.h    |   67 +++++++++++++++++++++--
 plug-ins/twain/tw_platform.h |   25 ++++++++-
 plug-ins/twain/tw_util.c     |    3 +-
 plug-ins/twain/tw_util.h     |    2 -
 plug-ins/twain/tw_win.c      |   33 +++--------
 plug-ins/twain/tw_win.h      |   69 +++++++++++++++++++++++
 plug-ins/twain/twain.c       |  126 ++++++++---------------------------------
 9 files changed, 255 insertions(+), 222 deletions(-)
---
diff --git a/plug-ins/twain/tw_func.c b/plug-ins/twain/tw_func.c
index 22e6dcf..d8b689d 100644
--- a/plug-ins/twain/tw_func.c
+++ b/plug-ins/twain/tw_func.c
@@ -63,10 +63,15 @@
 
 #include <glib.h>   /* Needed when compiling with gcc */
 
+#include "libgimp/gimp.h"
+
+#include "tw_platform.h"
 #include "tw_func.h"
 #include "tw_util.h"
 #include "tw_local.h"
 
+TW_USERINTERFACE ui;
+
 /*
  * Twain error code to string mappings
  */
@@ -240,10 +245,8 @@ openDSM (pTW_SESSION twSession)
       /* We are now at state 3 */
       twSession->twainState = 3;
       return TRUE;
-      break;
 
     case TWRC_FAILURE:
-    default:
       LogMessage("OpenDSM failure\n");
       break;
   }
@@ -358,18 +361,11 @@ openDS (pTW_SESSION twSession)
     case TWRC_SUCCESS:
       /* We are now in TWAIN state 4 */
       twSession->twainState = 4;
-      LogMessage("Data source %s opened\n", DS_IDENTITY(twSession)->ProductName);
-      LogMessage("\tVersion.MajorNum = %d\n", dsIdentity->Version.MajorNum);
-      LogMessage("\tVersion.MinorNum = %d\n", dsIdentity->Version.MinorNum);
-      LogMessage("\tVersion.Info = %s\n", dsIdentity->Version.Info);
-      LogMessage("\tProtocolMajor = %d\n", dsIdentity->ProtocolMajor);
-      LogMessage("\tProtocolMinor = %d\n", dsIdentity->ProtocolMinor);
-      LogMessage("\tManufacturer = %s\n", dsIdentity->Manufacturer);
-      LogMessage("\tProductFamily = %s\n", dsIdentity->ProductFamily);
+      twainSetupCallback (twSession);
       return TRUE;
       break;
 
-    default:
+    case TWRC_FAILURE:
       LogMessage("Error \"%s\" opening data source\n", currentTwainError(twSession));
       break;
   }
@@ -431,13 +427,9 @@ requestImageAcquire (pTW_SESSION twSession, gboolean showUI)
     return FALSE;
   }
 
-  twainSetupCallback(twSession);
-
   /* Set the transfer mode */
   if (setBufferedXfer (twSession))
   {
-    TW_USERINTERFACE ui;
-
     /* Set the UI information */
     ui.ShowUI = TRUE;
     ui.ModalUI = TRUE;
@@ -475,22 +467,16 @@ requestImageAcquire (pTW_SESSION twSession, gboolean showUI)
  *
  * Disable the datasource associated with twSession.
  */
-int
+void
 disableDS(pTW_SESSION twSession)
 {
-    TW_USERINTERFACE ui;
   /* Verify the datasource is enabled */
   if (DS_IS_DISABLED(twSession))
   {
     LogMessage("disableDS: Data source not enabled\n");
-    return TRUE;
+    return;
   }
 
-    /* Set the UI information */
-    ui.ShowUI = TRUE;
-    ui.ModalUI = TRUE;
-    ui.hParent = twSession->hwnd;
-
     /* Make the call to the source manager */
     twSession->twRC = callDSM(APP_IDENTITY(twSession), DS_IDENTITY(twSession),
                              DG_CONTROL, DAT_USERINTERFACE, MSG_DISABLEDS,
@@ -500,13 +486,10 @@ disableDS(pTW_SESSION twSession)
     {
       /* We are now at a new twain state */
       twSession->twainState = 4;
-
-      return TRUE;
     }
     else
     {
       LogMessage("Error during data source disable\n");
-      return FALSE;
     }
 }
 
@@ -516,14 +499,14 @@ disableDS(pTW_SESSION twSession)
  * Close the datasource associated with the
  * specified session.
  */
-int
+void
 closeDS (pTW_SESSION twSession)
 {
   /* Can't close a closed data source */
   if (DS_IS_CLOSED(twSession))
   {
     LogMessage("closeDS: Data source already closed\n");
-    return TRUE;
+    return;
   }
 
   /* Open the TWAIN datasource */
@@ -540,15 +523,12 @@ closeDS (pTW_SESSION twSession)
       /* We are now in TWAIN state 3 */
       twSession->twainState = 3;
       LogMessage("Data source %s closed\n", DS_IDENTITY(twSession)->ProductName);
-      return TRUE;
       break;
 
     default:
       LogMessage("Error \"%s\" closing data source\n", currentTwainError(twSession));
       break;
   }
-
-  return FALSE;
 }
 
 /*
@@ -556,39 +536,40 @@ closeDS (pTW_SESSION twSession)
  *
  * Close the data source manager
  */
-int
+void
 closeDSM (pTW_SESSION twSession)
 {
   if (DSM_IS_CLOSED(twSession))
   {
     LogMessage("closeDSM: Source Manager not open\n");
-    return FALSE;
   }
   else
   {
-    if (DS_IS_OPEN(twSession)) {
+    if (DS_IS_OPEN(twSession))
+    {
       LogMessage("closeDSM: Can't close source manager with open source\n");
-      return FALSE;
-    } else {
+    }
+    else
+    {
       twSession->twRC = callDSM(APP_IDENTITY(twSession), NULL,
                                DG_CONTROL, DAT_PARENT, MSG_CLOSEDSM,
                                (TW_MEMREF)&(twSession->hwnd));
 
-      if (twSession->twRC != TWRC_SUCCESS) {
-                               LogMessage("CloseDSM failure -- %s\n", currentTwainError(twSession));
-      }
-      else {
-        /* We are now in state 2 */
-        twSession->twainState = 2;
+      switch (twSession->twRC)
+         {
+        case TWRC_SUCCESS:
+          /* We are now in state 2 */
+          twSession->twainState = 2;
+          break;
+
+        case TWRC_FAILURE:
+          LogMessage("CloseDSM failure -- %s\n", currentTwainError(twSession));
+          break;
       }
     }
   }
-
-  /* Let the caller know what happened */
-  return (twSession->twRC==TWRC_SUCCESS);
 }
 
-
 /*
  * beginImageTransfer
  *
@@ -607,23 +588,24 @@ beginImageTransfer (pTW_SESSION twSession, pTW_IMAGEINFO imageInfo)
                            (TW_MEMREF) imageInfo);
 
   /* Check the return code */
-  if (twSession->twRC != TWRC_SUCCESS)
-  {
-    LogMessage("Get Image Info failure - %s\n", currentTwainError(twSession));
-
-    return FALSE;
-  }
-
-  /* Call the begin transfer callback if registered */
-  if (twSession->transferFunctions->txfrBeginCb)
+  switch (twSession->twRC)
   {
-    if (!(*twSession->transferFunctions->txfrBeginCb) (imageInfo, twSession->clientData))
-    {
-      return FALSE;
-    }
+    case TWRC_SUCCESS:
+      /* Call the begin transfer callback if registered */
+      if (twSession->transferFunctions->txfrBeginCb)
+      {
+        if (!(*twSession->transferFunctions->txfrBeginCb) (imageInfo, twSession->clientData))
+        {
+          return FALSE;
+        }
+      }
+      /* We should continue */
+      return TRUE;
+       case TWRC_FAILURE:
+      LogMessage("Get Image Info failure - %s\n", currentTwainError(twSession));
+      break;
   }
-  /* We should continue */
-  return TRUE;
+  return FALSE;
 }
 
 /*
@@ -751,22 +733,23 @@ endImageTransfer (pTW_SESSION twSession, int *pendingCount)
     case TWRC_XFERDONE:
     case TWRC_CANCEL:
     LogMessage("Xfer done received\n");
-      *pendingCount = endPendingTransfer(twSession);
+      *pendingCount = endPendingTransfer (twSession);
       break;
 
     case TWRC_FAILURE:
       LogMessage("Failure received\n");
-      *pendingCount = endPendingTransfer(twSession);
+      *pendingCount = endPendingTransfer (twSession);
       break;
   }
 
   /* Call the end transfer callback */
   if (twSession->transferFunctions->txfrEndCb)
+  {
     continueTransfers =
-      (*twSession->transferFunctions->txfrEndCb)(exitCode,
+      (*twSession->transferFunctions->txfrEndCb) (exitCode,
                                                 *pendingCount,
                                                 twSession->clientData);
-
+  }
   return (*pendingCount && continueTransfers);
 }
 
@@ -813,7 +796,7 @@ transferImages (pTW_SESSION twSession)
     }
 
     /* Call the image transfer function */
-    transferImage(twSession, &imageInfo);
+    transferImage (twSession, &imageInfo);
 
   } while (endImageTransfer (twSession, &pendingCount));
 
@@ -823,7 +806,7 @@ transferImages (pTW_SESSION twSession)
    */
   if (twSession->transferFunctions->postTxfrCb)
   {
-    (*twSession->transferFunctions->postTxfrCb)(pendingCount,
+    (*twSession->transferFunctions->postTxfrCb) (pendingCount,
                                                twSession->clientData);
   }
 }
diff --git a/plug-ins/twain/tw_func.h b/plug-ins/twain/tw_func.h
index 4778d91..d70fe35 100644
--- a/plug-ins/twain/tw_func.h
+++ b/plug-ins/twain/tw_func.h
@@ -61,9 +61,6 @@
 
 #ifndef _TW_FUNC_H
 #define _TW_FUNC_H
-
-#include "tw_platform.h"
-
 /*
  * Pre-image transfer function type
  *
@@ -207,20 +204,20 @@ typedef struct _TWAIN_SESSION {
 #define DS_IS_DISABLED(tw_session) (tw_session->twainState < 5)
 
 /* Function declarations */
-char *          twainError (int);
-char *          currentTwainError (pTW_SESSION);
-int             getImage (pTW_SESSION);
-int             loadTwainLibrary (pTW_SESSION);
-int unloadTwainLibrary(pTW_SESSION twSession);
-int             openDSM (pTW_SESSION);
-int             selectDS (pTW_SESSION);
-int             selectDefaultDS (pTW_SESSION);
-int             openDS (pTW_SESSION);
-int             requestImageAcquire (pTW_SESSION, gboolean);
-int             disableDS (pTW_SESSION);
-int             closeDS (pTW_SESSION);
-int             closeDSM (pTW_SESSION);
-void            cancelPendingTransfers (pTW_SESSION);
+char *          twainError (int errorCode);
+char *          currentTwainError (pTW_SESSION twSession);
+int             getImage (pTW_SESSION twSession);
+int             loadTwainLibrary (pTW_SESSION twSession);
+void            unloadTwainLibrary (pTW_SESSION twSession);
+int             openDSM (pTW_SESSION twSession);
+int             selectDS (pTW_SESSION twSession);
+int             selectDefaultDS (pTW_SESSION twSession);
+int             openDS (pTW_SESSION twSession);
+int             requestImageAcquire (pTW_SESSION twSession, gboolean showUI);
+void            disableDS (pTW_SESSION twSession);
+void            closeDS (pTW_SESSION twSession);
+void            closeDSM (pTW_SESSION twSession);
+void            cancelPendingTransfers (pTW_SESSION twSession);
 int scanImage (void);
 
 TW_FIX32 FloatToFIX32(float);
@@ -228,11 +225,11 @@ float           FIX32ToFloat(TW_FIX32);
 
 void            processTwainMessage (TW_UINT16 message, pTW_SESSION twSession);
 
-pTW_SESSION     newSession (pTW_IDENTITY);
+pTW_SESSION     newSession (pTW_IDENTITY twSession);
 void            registerWindowHandle(pTW_SESSION, TW_HANDLE);
 void            registerTransferCallbacks(pTW_SESSION, pTXFR_CB_FUNCS, void *);
 void            setClientData(pTW_SESSION session, void *clientData);
-pTW_SESSION initializeTwain(void);
+pTW_SESSION     initializeTwain (void);
 
 #ifdef G_OS_WIN32
 void LogLastWinError(void);
diff --git a/plug-ins/twain/tw_local.h b/plug-ins/twain/tw_local.h
index 30094eb..0d0ccae 100644
--- a/plug-ins/twain/tw_local.h
+++ b/plug-ins/twain/tw_local.h
@@ -1,4 +1,4 @@
-/*
+.re/*
  * TWAIN Plug-in
  * Copyright (C) 1999 Craig Setera
  * Craig Setera <setera home com>
@@ -25,10 +25,30 @@
 #ifndef _TW_LOCAL_H
 #define _TW_LOCAL_H
 
-#include "tw_func.h"
+/*
+ * Plug-in Parameter definitions
+ */
+#define NUMBER_IN_ARGS 1
+#define IN_ARGS \
+    { GIMP_PDB_INT32, "run-mode", "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }" }
+#define NUMBER_OUT_ARGS 2
+#define OUT_ARGS \
+    { GIMP_PDB_INT32, "image-count", "Number of acquired images" }, \
+    { GIMP_PDB_INT32ARRAY, "image-ids", "Array of acquired image identifiers" }
 
-/* Functions which the platform-independent code will call */
+/*
+ * Application definitions
+ */
+#define MAX_IMAGES 1
+
+/*
+ * Definition of the run states
+ */
+#define RUN_STANDARD 0
+#define RUN_DUMP 1
+#define RUN_READDUMP 2
 
+/* Functions which the platform-independent code will call */
 TW_UINT16 callDSM (
     pTW_IDENTITY,
     pTW_IDENTITY,
@@ -46,7 +66,44 @@ TW_MEMREF twainLockHandle (TW_HANDLE handle);
 void      twainUnlockHandle (TW_HANDLE handle);
 void      twainFreeHandle (TW_HANDLE handle);
 
-int twainMain (void);
-int scanImage (void);
+int       twainMain (void);
+int       scanImage (void);
+
+void      preTransferCallback (void *);
+int       beginTransferCallback (pTW_IMAGEINFO, void *);
+int       dataTransferCallback (pTW_IMAGEINFO, pTW_IMAGEMEMXFER, void *);
+int       endTransferCallback (int, int, void *);
+void      postTransferCallback (int, void *);
+
+extern void set_gimp_PLUG_IN_INFO_PTR(GimpPlugInInfo *);
+
+/* Data structure holding data between runs */
+/* Currently unused... Eventually may be used
+ * to track dialog data.
+ */
+typedef struct {
+  gchar  sourceName[34];
+  gfloat xResolution;
+  gfloat yResolution;
+  gint   xOffset;
+  gint   yOffset;
+  gint   width;
+  gint   height;
+  gint   imageType;
+} TwainValues;
+
+/* Data used to carry data between each
+ * of the callback function calls.
+ */
+typedef struct
+{
+  gint32 image_id;
+  gint32 layer_id;
+  GimpPixelRgn pixel_rgn;
+  GimpDrawable *drawable;
+  pTW_PALETTE8 paletteData;
+  int totalPixels;
+  int completedPixels;
+} ClientDataStruct, *pClientDataStruct;
 
 #endif
diff --git a/plug-ins/twain/tw_platform.h b/plug-ins/twain/tw_platform.h
index 850a1ba..891553f 100644
--- a/plug-ins/twain/tw_platform.h
+++ b/plug-ins/twain/tw_platform.h
@@ -21,8 +21,10 @@
 #ifndef _TW_PLATFORM_H
 #define _TW_PLATFORM_H
 
-#include <windows.h>
-#include "twain.h"
+    /* Coding style violation: Don't include headers in headers */
+    #include <windows.h>
+    /* Coding style violation: Don't include headers in headers */
+    #include "twain.h"
 
 /* The DLL to be loaded for TWAIN support */
 #define TWAIN_DLL_NAME "TWAIN_32.DLL"
@@ -34,4 +36,23 @@
 /* Windows uses separate entry point */
 #define TWAIN_ALTERNATE_MAIN
 
+/*
+ * Plug-in Definitions
+ */
+  #define PRODUCT_FAMILY      "GNU"
+  #define PRODUCT_NAME        "GIMP"
+  #define PLUG_IN_NAME        "TWAIN"
+  #define PLUG_IN_DESCRIPTION N_("Capture an image from a TWAIN datasource")
+  #define PLUG_IN_HELP        "This plug-in will capture an image from a TWAIN datasource"
+  #define PLUG_IN_AUTHOR      "Craig Setera (setera home com)"
+  #define PLUG_IN_COPYRIGHT   "Craig Setera"
+  #define PLUG_IN_MAJOR       0
+  #define PLUG_IN_MINOR       6
+  #define PLUG_IN_VERSION     "v0.6 (07/22/2004)"
+  #define MID_SELECT          "twain-acquire"
+
+  #ifdef _DEBUG
+  #define PLUG_IN_D_NAME      "twain-acquire-dump"
+  #define PLUG_IN_R_NAME      "twain-acquire-read"
+  #endif /* _DEBUG */
 #endif
diff --git a/plug-ins/twain/tw_util.c b/plug-ins/twain/tw_util.c
index 43ee831..5060b1c 100644
--- a/plug-ins/twain/tw_util.c
+++ b/plug-ins/twain/tw_util.c
@@ -70,11 +70,12 @@
 #include <string.h>
 #include <time.h>
 
-#include "tw_util.h"
+#include "tw_platform.h"
 #ifdef _DEBUG
 #include "tw_func.h"
 FILE *logFile = NULL;
 #endif
+#include "tw_util.h"
 
 #ifdef _DEBUG
 
diff --git a/plug-ins/twain/tw_util.h b/plug-ins/twain/tw_util.h
index c6faa22..e0c46ed 100644
--- a/plug-ins/twain/tw_util.h
+++ b/plug-ins/twain/tw_util.h
@@ -61,8 +61,6 @@
 #ifndef __TW_UTIL_H
 #define __TW_UTIL_H
 
-#include "tw_platform.h"
-
 void LogMessage(char *, ...);
 
 #ifdef _DEBUG
diff --git a/plug-ins/twain/tw_win.c b/plug-ins/twain/tw_win.c
index 082e374..b931189 100644
--- a/plug-ins/twain/tw_win.c
+++ b/plug-ins/twain/tw_win.c
@@ -34,22 +34,7 @@
 #include "tw_func.h"
 #include "tw_util.h"
 #include "tw_local.h"
-
-LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
-
-int twainMessageLoop (pTW_SESSION);
-int TwainProcessMessage (LPMSG lpMsg, pTW_SESSION twSession);
-
-extern GimpPlugInInfo PLUG_IN_INFO;
-extern pTW_SESSION initializeTwain ();
-#ifdef _DEBUG
-extern void setRunMode(char *argv[]);
-#endif
-
-
-#define APP_NAME "TWAIN"
-#define SHOW_WINDOW 0
-#define WM_TRANSFER_IMAGE (WM_USER + 100)
+#include "tw_win.h"
 
 /* main bits */
 static HWND         hwnd  = NULL;
@@ -146,7 +131,7 @@ twainSetupCallback (pTW_SESSION twSession)
  *
  * Unload the TWAIN dynamic link library
  */
-int
+void
 unloadTwainLibrary (pTW_SESSION twSession)
 {
   /* Explicitly free the SM library */
@@ -162,11 +147,9 @@ unloadTwainLibrary (pTW_SESSION twSession)
    */
   DS_IDENTITY(twSession)->Id = 0;
 
-       /* We are now back at state 1 */
-  twSession->twainState = 1;
+       /* We are now back at state 0 */
+  twSession->twainState = 0;
   LogMessage("Source Manager successfully closed\n");
-
-  return TRUE;
 }
 
 /*
@@ -264,7 +247,7 @@ LogLastWinError (void)
 }
 
 void
-twainQuitApplication ()
+twainQuitApplication (void)
 {
   PostQuitMessage (0);
 }
@@ -361,7 +344,7 @@ InitApplication (HINSTANCE hInstance)
   wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
   wc.hCursor = LoadCursor (NULL, IDC_ARROW);
   wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
-  wc.lpszClassName = APP_NAME;
+  wc.lpszClassName = PLUG_IN_NAME;
   wc.lpszMenuName = NULL;
 
   /* Register the window class and stash success/failure code. */
@@ -386,7 +369,7 @@ BOOL
 InitInstance (HINSTANCE hInstance, int nCmdShow, pTW_SESSION twSession)
 {
   /* Create our window */
-  hwnd = CreateWindow (APP_NAME, APP_NAME, WS_OVERLAPPEDWINDOW,
+  hwnd = CreateWindow (PLUG_IN_NAME, PLUG_IN_NAME, WS_OVERLAPPEDWINDOW,
       CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
       NULL, NULL, hInstance, NULL);
 
@@ -420,7 +403,7 @@ InitInstance (HINSTANCE hInstance, int nCmdShow, pTW_SESSION twSession)
  * operate.
  */
 int
-twainMain ()
+twainMain (void)
 {
   /* Initialize the twain information */
   pTW_SESSION twSession = initializeTwain();
diff --git a/plug-ins/twain/tw_win.h b/plug-ins/twain/tw_win.h
new file mode 100644
index 0000000..998eb6d
--- /dev/null
+++ b/plug-ins/twain/tw_win.h
@@ -0,0 +1,69 @@
+/*
+ * TWAIN Plug-in
+ * Copyright (C) 1999 Craig Setera
+ * Craig Setera <setera home com>
+ * 03/31/1999
+ *
+ * Updated for Mac OS X support
+ * Brion Vibber <brion pobox com>
+ * 07/22/2004
+ *
+ * Added for Win x64 support, changed data source selection.
+ * Jens M. Plonka <jens plonka gmx de>
+ * 11/25/2011
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * Revision history
+ *  (02/07/99)  v0.1   First working version (internal)
+ *  (02/09/99)  v0.2   First release to anyone other than myself
+ *  (02/15/99)  v0.3   Added image dump and read support for debugging
+ *  (03/31/99)  v0.5   Added support for multi-byte samples and paletted
+ *                     images.
+ *  (07/23/04)  v0.6   Added Mac OS X support.
+ *  (11/25/11)  v0.7   Added Win x64 support, changed data source selection.
+ */
+
+/*
+ * Windows platform-specific code
+ */
+#ifndef _TW_WIN_H
+#define _TW_WIN_H
+
+#define SHOW_WINDOW 0
+#define WM_TRANSFER_IMAGE (WM_USER + 100)
+
+TW_UINT16 callDSM (
+  pTW_IDENTITY pOrigin,
+  pTW_IDENTITY pDest,
+  TW_UINT32    DG,
+  TW_UINT16    DAT,
+  TW_UINT16    MSG,
+  TW_MEMREF    pData);
+
+extern GimpPlugInInfo PLUG_IN_INFO;
+
+LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
+int     twainMessageLoop (pTW_SESSION);
+int     TwainProcessMessage (LPMSG lpMsg, pTW_SESSION twSession);
+void    LogLastWinError (void);
+void    twainQuitApplication (void);
+BOOL    InitApplication (HINSTANCE hInstance);
+BOOL    InitInstance (HINSTANCE hInstance, int nCmdShow, pTW_SESSION twSession);
+int     twainMain (void);
+extern  pTW_SESSION initializeTwain (void);
+
+#endif /* _TW_WIN_H */
diff --git a/plug-ins/twain/twain.c b/plug-ins/twain/twain.c
index 568b615..049e648 100644
--- a/plug-ins/twain/twain.c
+++ b/plug-ins/twain/twain.c
@@ -66,68 +66,40 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "tw_platform.h"
-#include "tw_local.h"
-
 #include "libgimp/gimp.h"
 #include "libgimp/stdplugins-intl.h"
 
+#include "tw_platform.h"
 #include "tw_func.h"
+#include "tw_local.h"
 #include "tw_util.h"
 
 #ifdef _DEBUG
 #include "tw_dump.h"
 #endif /* _DEBUG */
 
-/*
- * Plug-in Definitions
- */
-#define PLUG_IN_NAME        "twain-acquire"
-#define PLUG_IN_DESCRIPTION N_("Capture an image from a TWAIN datasource")
-#define PLUG_IN_HELP        "This plug-in will capture an image from a TWAIN datasource"
-#define PLUG_IN_AUTHOR      "Craig Setera (setera home com)"
-#define PLUG_IN_COPYRIGHT   "Craig Setera"
-#define PLUG_IN_VERSION     "v0.6 (07/22/2004)"
-
-#ifdef _DEBUG
-#define PLUG_IN_D_NAME      "twain-acquire-dump"
-#define PLUG_IN_R_NAME      "twain-acquire-read"
-#endif /* _DEBUG */
-
-/*
- * Application definitions
- */
-#define MAX_IMAGES 1
+static void query (void);
+static void run (
+    const gchar      *name,
+    gint              nparams,
+    const GimpParam  *param,
+    gint             *nreturn_vals,
+    GimpParam       **return_vals);
 
-/*
- * Definition of the run states
- */
-#define RUN_STANDARD 0
-#define RUN_DUMP 1
-#define RUN_READDUMP 2
 
 /* Global variables */
-pTW_SESSION twSession = NULL;
+pTW_SESSION  twSession = NULL;
+static const GimpParamDef args[] = { IN_ARGS };
+static const GimpParamDef return_vals[] = { OUT_ARGS };
 
-static char        *destBuf = NULL;
+static char  *destBuf = NULL;
 #ifdef _DEBUG
 static int         twain_run_mode = RUN_STANDARD;
 #endif
+static char bitMasks[] = { 128, 64, 32, 16, 8, 4, 2, 1 };
 
-/* Forward declarations */
-void preTransferCallback (void *);
-int  beginTransferCallback (pTW_IMAGEINFO, void *);
-int  dataTransferCallback (pTW_IMAGEINFO, pTW_IMAGEMEMXFER, void *);
-int  endTransferCallback (int, int, void *);
-void postTransferCallback (int, void *);
-
-static void query (void);
-static void run (
-    const gchar      *name,
-    gint              nparams,
-    const GimpParam  *param,
-    gint             *nreturn_vals,
-    GimpParam       **return_vals);
+/* Return values storage */
+static GimpParam values[3];
 
 /* This plug-in's functions */
 const GimpPlugInInfo PLUG_IN_INFO =
@@ -138,23 +110,6 @@ const GimpPlugInInfo PLUG_IN_INFO =
   run,     /* run_proc */
 };
 
-extern void set_gimp_PLUG_IN_INFO_PTR(GimpPlugInInfo *);
-
-/* Data structure holding data between runs */
-/* Currently unused... Eventually may be used
- * to track dialog data.
- */
-typedef struct {
-  gchar  sourceName[34];
-  gfloat xResolution;
-  gfloat yResolution;
-  gint   xOffset;
-  gint   yOffset;
-  gint   width;
-  gint   height;
-  gint   imageType;
-} TwainValues;
-
 /* Default Twain values */
 static TwainValues twainvals =
 {
@@ -231,17 +186,17 @@ getAppIdentity(void)
 
   /* Set up the application identity */
   appIdentity->Id = 0;
-  appIdentity->Version.MajorNum = 0;
-  appIdentity->Version.MinorNum = 1;
+  appIdentity->Version.MajorNum = PLUG_IN_MAJOR;
+  appIdentity->Version.MinorNum = PLUG_IN_MINOR;
   appIdentity->Version.Language = TWLG_USA;
   appIdentity->Version.Country = TWCY_USA;
-  strcpy(appIdentity->Version.Info, "GIMP TWAIN 0.6");
+  strcpy(appIdentity->Version.Info, PLUG_IN_VERSION);
   appIdentity->ProtocolMajor = TWON_PROTOCOLMAJOR;
   appIdentity->ProtocolMinor = TWON_PROTOCOLMINOR;
   appIdentity->SupportedGroups = DG_IMAGE;
-  strcpy(appIdentity->Manufacturer, "Craig Setera");
-  strcpy(appIdentity->ProductFamily, "GIMP");
-  strcpy(appIdentity->ProductName, "GIMP");
+  strcpy (appIdentity->Manufacturer, PLUG_IN_COPYRIGHT);
+  strcpy (appIdentity->ProductFamily, PRODUCT_FAMILY);
+  strcpy (appIdentity->ProductName, PRODUCT_NAME);
 
   return appIdentity;
 }
@@ -280,17 +235,6 @@ initializeTwain (void)
  ******************************************************************/
 
 /*
- * Plug-in Parameter definitions
- */
-#define NUMBER_IN_ARGS 1
-#define IN_ARGS { GIMP_PDB_INT32, "run-mode", "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }" 
}
-#define NUMBER_OUT_ARGS 2
-#define OUT_ARGS \
-       { GIMP_PDB_INT32, "image-count", "Number of acquired images" }, \
-       { GIMP_PDB_INT32ARRAY, "image-ids", "Array of acquired image identifiers" }
-
-
-/*
  * query
  *
  * The plug-in is being queried.  Install our procedure for
@@ -299,8 +243,6 @@ initializeTwain (void)
 static void
 query (void)
 {
-  static const GimpParamDef args[] = { IN_ARGS };
-  static const GimpParamDef return_vals[] = { OUT_ARGS };
 
 #ifdef _DEBUG
   if (twain_run_mode == RUN_DUMP)
@@ -345,7 +287,7 @@ query (void)
 #endif /* _DEBUG */
     {
       /* the installation of the plugin */
-      gimp_install_procedure(PLUG_IN_NAME,
+      gimp_install_procedure(MID_SELECT,
                              PLUG_IN_DESCRIPTION,
                              PLUG_IN_HELP,
                              PLUG_IN_AUTHOR,
@@ -359,14 +301,10 @@ query (void)
                              args,
                              return_vals);
 
-      gimp_plugin_menu_register (PLUG_IN_NAME, "<Image>/File/Create/Acquire");
+      gimp_plugin_menu_register (MID_SELECT, "<Image>/File/Create/Acquire");
     }
 }
 
-
-/* Return values storage */
-static GimpParam values[3];
-
 /*
  * run
  *
@@ -466,19 +404,6 @@ run (const gchar      *name,
  * Image transfer callback functions
  ***********************************************************************/
 
-/* Data used to carry data between each of
- * the callback function calls.
- */
-typedef struct {
-  gint32 image_id;
-  gint32 layer_id;
-  GimpPixelRgn pixel_rgn;
-  GimpDrawable *drawable;
-  pTW_PALETTE8 paletteData;
-  int totalPixels;
-  int completedPixels;
-} ClientDataStruct, *pClientDataStruct;
-
 /*
  * preTransferCallback
  *
@@ -622,7 +547,6 @@ beginTransferCallback (pTW_IMAGEINFO imageInfo, void *clientData)
  * into byte data and written into a gray scale GIMP
  * image.
  */
-static char bitMasks[] = { 128, 64, 32, 16, 8, 4, 2, 1 };
 static int
 bitTransferCallback(pTW_IMAGEINFO imageInfo,
         pTW_IMAGEMEMXFER imageMemXfer,
@@ -951,7 +875,7 @@ dataTransferCallback (
  *  The transfer failed.
  */
 int
-endTransferCallback(int completionState, int pendingCount, void *clientData)
+endTransferCallback (int completionState, int pendingCount, void *clientData)
 {
   pClientDataStruct theClientData = (pClientDataStruct) clientData;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]