Only in /usr/src/gimp-2.7.3/plug-ins/twain: .deps
Only in /usr/src/git/gimp/plug-ins/twain: .gitignore
Only in /usr/src/gimp-2.7.3/plug-ins/twain: .libs
Only in /usr/src/gimp-2.7.3/plug-ins/twain: Makefile
Only in /usr/src/gimp-2.7.3/plug-ins/twain: Makefile.in
Only in /usr/src/gimp-2.7.3/plug-ins/twain: patchfile.patch
Only in /usr/src/gimp-2.7.3/plug-ins/twain: screenshot.gif
Only in /usr/src/gimp-2.7.3/plug-ins/twain: screenshot.xcf
Only in /usr/src/git/gimp/plug-ins/twain: tw_dump.c
Only in /usr/src/git/gimp/plug-ins/twain: tw_dump.h
diff -rub /usr/src/git/gimp/plug-ins/twain/tw_func.c /usr/src/gimp-2.7.3/plug-ins/twain/tw_func.c
--- /usr/src/git/gimp/plug-ins/twain/tw_func.c	2011-12-17 16:24:18 +0000
+++ /usr/src/gimp-2.7.3/plug-ins/twain/tw_func.c	2011-12-17 09:08:22 +0000
@@ -8,6 +8,10 @@
  * 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
@@ -57,16 +61,21 @@
  *  (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.
  */
 
 #include "config.h"
 
 #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
  */
@@ -98,49 +107,29 @@
 };
 
 /*
- * FloatToFix32
- *
- * Convert a floating point value into a FIX32.
- */
-TW_FIX32 FloatToFIX32(float floater)
-{
-  TW_FIX32 Fix32_value;
-  TW_INT32 value = (TW_INT32) (floater * 65536.0 + 0.5);
-  Fix32_value.Whole = value >> 16;
-  Fix32_value.Frac = value & 0x0000ffffL;
-  return (Fix32_value);
-}
-
-/*
- * Fix32ToFloat
- *
- * Convert a FIX32 value into a floating point value.
- */
-float FIX32ToFloat(TW_FIX32 fix32)
-{
-  float floater;
-  floater = (float) fix32.Whole + (float) fix32.Frac / 65536.0;
-  return floater;
-}
-
-/*
  * twainError
  *
  * Return the TWAIN error message associated
  * with the specified error code.
  */
 char *
-twainError(int errorCode)
+twainError (int errorCode)
 {
   /* Check whether we've counted */
   if (twainErrorCount == 0)
+  {
     while (twainErrors[twainErrorCount++]) {}
+  }
 
   /* Check out of bounds */
   if (errorCode >= twainErrorCount)
+  {
     return "Unknown TWAIN Error Code";
+  }
   else
+  {
     return twainErrors[errorCode];
+  }
 }
 
 /*
@@ -149,20 +138,17 @@
  * Return the current TWAIN error message.
  */
 char *
-currentTwainError(pTW_SESSION twSession)
+currentTwainError (pTW_SESSION twSession)
 {
   TW_STATUS twStatus;
 
   /* Get the current status code from the DSM */
-  twSession->twRC = callDSM(APP_IDENTITY(twSession), DS_IDENTITY(twSession),
-			    DG_CONTROL, DAT_STATUS, MSG_GET,
-			    (TW_MEMREF) &twStatus);
+  twSession->twRC = DSM_GET_STATUS(twSession, twStatus);
 
   /* Return the mapped error code */
-  return twainError(twStatus.ConditionCode);
+  return twainError (twStatus.ConditionCode);
 }
 
-
 /*
  * getImage
  *
@@ -172,34 +158,34 @@
  * back to the callback function specified in the session structure.
  */
 int
-getImage(pTW_SESSION twSession)
+getImage (pTW_SESSION twSession)
 {
   /* Do some sanity checking first and bail
    * if necessary.
    */
 
-  if (!twainIsAvailable()) {
-    LogMessage("TWAIN is not available for image capture\n");
+  if (!twainIsAvailable ())
+  {
     return FALSE;
   }
 
   /* One step at a time */
-  if (!openDSM(twSession)) {
-    LogMessage("Unable to open data source manager\n");
+  if (!openDSM (twSession))
+  {
     return FALSE;
   }
 
-  if (!selectDS(twSession)) {
-    LogMessage("Data source not selected\n");
+  if (!select_ds (twSession))
+  {
     return FALSE;
   }
 
-  if (!openDS(twSession)) {
-    LogMessage("Unable to open datasource\n");
+  if (!openDS (twSession))
+  {
     return FALSE;
   }
 
-  requestImageAcquire(twSession, TRUE);
+  requestImageAcquire (twSession, TRUE);
 
   return TRUE;
 }
@@ -210,98 +196,106 @@
  * Open the data source manager
  */
 int
-openDSM(pTW_SESSION twSession)
+openDSM (pTW_SESSION twSession)
 {
   /* Make sure that we aren't already open */
   if (DSM_IS_OPEN(twSession))
+  {
     return TRUE;
+  }
 
+  if (twSession != NULL)
+  {
   /* Open the data source manager */
-  twSession->twRC = callDSM(APP_IDENTITY(twSession), NULL,
-			    DG_CONTROL, DAT_PARENT, MSG_OPENDSM,
-			    (TW_MEMREF) &(twSession->hwnd));
+    twSession->twRC = DSM_OPEN(twSession);
 
   /* Check the return code */
-  switch (twSession->twRC) {
+    switch (twSession->twRC)
+    {
     case TWRC_SUCCESS:
       /* We are now at state 3 */
-      twSession->twainState = 3;
+        twSession->twainState = DSM_STATE_LOADED;
       return TRUE;
-      break;
 
     case TWRC_FAILURE:
-    default:
-      LogMessage("OpenDSM failure\n");
+        log_message ("OpenDSM failure: %s\n", currentTwainError(twSession) );
       break;
   }
+  }
 
   return FALSE;
 }
 
 /*
- * selectDS
+ * adjust_selected_data_source
  *
- * Select a datasource using the TWAIN user
- * interface.
+ * Selects the
  */
 int
-selectDS(pTW_SESSION twSession)
+adjust_selected_data_source (pTW_SESSION twSession)
 {
-  /* The datasource manager must be open */
-  if (DSM_IS_CLOSED(twSession)) {
-    LogMessage("Can't select data source with closed source manager\n");
-    return FALSE;
-  }
+  pTW_DATA_SOURCE dataSource;
+  pTW_IDENTITY dsIdentity;
+  gchar *dsName;
 
-  /* Ask TWAIN to present the source select dialog */
-  twSession->twRC = callDSM(APP_IDENTITY(twSession), NULL,
-			    DG_CONTROL, DAT_IDENTITY, MSG_USERSELECT,
-			    (TW_MEMREF) DS_IDENTITY(twSession));
+  twSession->dsIdentity = NULL;
+  /* get all available data source as a linked list into twSession */
+  dataSource = get_available_ds (twSession);
 
-  /* Check the return to determine what the user decided
-   * to do.
-   */
-  switch (twSession->twRC) {
-  case TWRC_SUCCESS:
-    LogMessage("Data source %s selected\n", DS_IDENTITY(twSession)->ProductName);
+  while (dataSource != NULL)
+  {
+    dataSource = twSession->dataSources;
+    /* for each data source create an own menu item */
+    dsIdentity = dataSource->dsIdentity;
+    dsName = dsIdentity->ProductName;
+    if (strcmp (dsName, twSession->name) == 0)
+    {
+      twSession->dsIdentity = dataSource->dsIdentity;
+      twSession->twRC = TWRC_SUCCESS;
     return TRUE;
-    break;
-
-  case TWRC_CANCEL:
-    LogMessage("User cancelled TWAIN source selection\n");
-    break;
-
-  case TWRC_FAILURE:
-  default:
-    LogMessage("Error \"%s\" during TWAIN source selection\n",
-	       currentTwainError(twSession));
-    break;
+    }
   }
 
   return FALSE;
 }
 
 /*
- * selectDefaultDS
+ * select_ds
  *
- * Select the default datasource.
+ * Select a datasource using the TWAIN user
+ * interface.
  */
 int
-selectDefaultDS(pTW_SESSION twSession)
+select_ds (pTW_SESSION twSession)
 {
   /* The datasource manager must be open */
-  if (DSM_IS_CLOSED(twSession)) {
-    LogMessage("Can't select data source with closed source manager\n");
+  if (DSM_IS_CLOSED(twSession))
+  {
+    log_message ("Can't select data source with closed source manager.\n");
     return FALSE;
   }
 
+  if ((strcmp (MID_SELECT, twSession->name) == 0)
+      || (adjust_selected_data_source (twSession) == FALSE))
+  {
   /* Ask TWAIN to present the source select dialog */
-  twSession->twRC = callDSM(APP_IDENTITY(twSession), NULL,
-			    DG_CONTROL, DAT_IDENTITY, MSG_GETDEFAULT,
-			    (TW_MEMREF) DS_IDENTITY(twSession));
+    twSession->twRC = DSM_SELECT_USER(twSession);
+  }
 
-  /* Check the return code */
-  return (twSession->twRC == TWRC_SUCCESS);
+  /* Check the return to determine what the user decided
+   * to do.
+   */
+  switch (twSession->twRC)
+  {
+    case TWRC_SUCCESS:
+      return TRUE;
+
+    case TWRC_FAILURE:
+      log_message ("Error selecting datasource: %s\n", currentTwainError(twSession));
+      break;
+  }
+
+  return FALSE;
 }
 
 /*
@@ -310,51 +304,42 @@
  * Open a data source using the TWAIN user interface.
  */
 int
-openDS(pTW_SESSION twSession)
+openDS (pTW_SESSION twSession)
 {
-  TW_IDENTITY *dsIdentity;
-
   /* The datasource manager must be open */
-  if (DSM_IS_CLOSED(twSession)) {
-    LogMessage("openDS: Cannot open data source... manager closed\n");
+  if (DSM_IS_CLOSED(twSession))
+  {
+    log_message ("The DSM needs to be opened first.\n");
     return FALSE;
   }
 
-  /* Is the data source already open? */
-  if (DS_IS_OPEN(twSession)) {
-    LogMessage("openDS: Data source already open\n");
-    return TRUE;
+  if (DS_IS_OPEN(twSession))
+  {
+    log_message ("A source has already been opened, please close it first.\n");
+    return FALSE;
   }
 
+  if (twSession != NULL)
+  {
   /* Open the TWAIN datasource */
-  dsIdentity = DS_IDENTITY(twSession);
-  twSession->twRC = callDSM(APP_IDENTITY(twSession), NULL,
-			    DG_CONTROL, DAT_IDENTITY, MSG_OPENDS,
-			    (TW_MEMREF) dsIdentity);
+    twSession->twRC = DSM_OPEN_DS(twSession);
 
   /* Check the return to determine what the user decided
    * to do.
 	 */
-  switch (twSession->twRC) {
+    switch (twSession->twRC)
+    {
   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);
+        twSession->twainState = DSM_STATE_DS_OPEN;
+        twainSetupCallback (twSession);
     return TRUE;
-    break;
 
-  default:
-    LogMessage("Error \"%s\" opening data source\n", currentTwainError(twSession));
+      case TWRC_FAILURE:
+        log_message ("Error opening data source: %s\n", currentTwainError(twSession));
     break;
   }
-
+  }
   return FALSE;
 }
 
@@ -369,25 +354,34 @@
 
   /* Make sure the data source is open first */
   if (DS_IS_CLOSED(twSession))
+  {
     return FALSE;
+  }
 
   /* Create the capability information */
   bufXfer.Cap = ICAP_XFERMECH;
   bufXfer.ConType = TWON_ONEVALUE;
-  bufXfer.hContainer = twainAllocHandle(sizeof(TW_ONEVALUE));
-
-  pvalOneValue = (pTW_ONEVALUE) twainLockHandle(bufXfer.hContainer);
+  bufXfer.hContainer = twainAllocHandle (sizeof(TW_ONEVALUE));
+  if (bufXfer.hContainer == NULL)
+  {
+    log_message ("Error allocating memory for XFer mechanism.\n");
+    return FALSE;
+  }
+  pvalOneValue = (pTW_ONEVALUE) twainLockHandle (bufXfer.hContainer);
   pvalOneValue->ItemType = TWTY_UINT16;
   pvalOneValue->Item = TWSX_MEMORY;
-  twainUnlockHandle(bufXfer.hContainer);
+  twainUnlockHandle (bufXfer.hContainer);
 
   /* Make the call to the source manager */
-  twSession->twRC = callDSM(APP_IDENTITY(twSession), DS_IDENTITY(twSession),
-			    DG_CONTROL, DAT_CAPABILITY, MSG_SET,
-			    (TW_MEMREF) &bufXfer);
+  twSession->twRC = DSM_XFER_SET(twSession, bufXfer);
+  if (twSession->twRC == TWRC_FAILURE)
+  {
+    log_message ("Could not set capability: %s\n", currentTwainError(twSession));
+  }
 
   /* Free the container */
-  twainFreeHandle(bufXfer.hContainer);
+  twainUnlockHandle (bufXfer.hContainer);
+  twainFreeHandle (bufXfer.hContainer);
 
   /* Let the caller know what happened */
   return (twSession->twRC==TWRC_SUCCESS);
@@ -404,17 +398,17 @@
 requestImageAcquire(pTW_SESSION twSession, gboolean showUI)
 {
   /* Make sure in the correct state */
-  if (DS_IS_CLOSED(twSession)) {
-    LogMessage("Can't acquire image with closed datasource\n");
+  if (DS_IS_CLOSED(twSession))
+  {
+    log_message ("You need to open the data source first.\n");
     return FALSE;
   }
 
-  twainSetupCallback(twSession);
-
+  if (twSession != NULL)
+  {
   /* Set the transfer mode */
-  if (setBufferedXfer(twSession)) {
-    TW_USERINTERFACE ui;
-
+    if (setBufferedXfer(twSession))
+    {
     /* Set the UI information */
     ui.ShowUI = TRUE;
     ui.ModalUI = TRUE;
@@ -422,24 +416,19 @@
     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_ENABLEDS,
-			      (TW_MEMREF) &ui);
+      twSession->twRC = DSM_ENABLE_DS(twSession, ui);
 
-    if (twSession->twRC == TWRC_SUCCESS) {
+      if (twSession->twRC == TWRC_SUCCESS)
+      {
       /* We are now at a new twain state */
-      twSession->twainState = 5;
+        twSession->twainState = DSM_STATE_ACQUIRE;
 
       return TRUE;
-    } else {
-      LogMessage("Error during data source enable\n");
-      return FALSE;
     }
-  } else {
-    LogMessage("Unable to set buffered transfer mode: %s\n",
-	       currentTwainError(twSession));
-    return FALSE;
   }
+  }
+  log_message ("Error enabeling data source: %s\n", currentTwainError(twSession));
+  return FALSE;
 }
 
 /*
@@ -447,35 +436,30 @@
  *
  * 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;
+  if (DS_IS_DISABLED(twSession))
+  {
+    log_message ("You need to enable the data source first.\n");
+    return;
 	}
 
-    /* Set the UI information */
-    ui.ShowUI = TRUE;
-    ui.ModalUI = TRUE;
-    ui.hParent = twSession->hwnd;
-
+  if (twSession != NULL)
+  {
     /* Make the call to the source manager */
-    twSession->twRC = callDSM(APP_IDENTITY(twSession), DS_IDENTITY(twSession),
-			      DG_CONTROL, DAT_USERINTERFACE, MSG_DISABLEDS,
-			      (TW_MEMREF) &ui);
+    twSession->twRC = DSM_DISABLE_DS(twSession, ui);
 
-    if (twSession->twRC == TWRC_SUCCESS) {
+    if (twSession->twRC == TWRC_SUCCESS)
+    {
       /* We are now at a new twain state */
-      twSession->twainState = 4;
-
-      return TRUE;
-    } else {
-      LogMessage("Error during data source disable\n");
-      return FALSE;
+      twSession->twainState = DSM_STATE_DS_OPEN;
+    }
+    else
+    {
+      log_message  ("Can't disable data source.\n");
+    }
     }
 }
 
@@ -485,37 +469,36 @@
  * 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;
+  if (DS_IS_CLOSED(twSession))
+  {
+    log_message ("closeDS: Data source already closed\n");
+    return;
   }
 
+  if (twSession != NULL)
+  {
   /* Open the TWAIN datasource */
-  twSession->twRC = callDSM(APP_IDENTITY(twSession), NULL,
-			    DG_CONTROL, DAT_IDENTITY, MSG_CLOSEDS,
-			    (TW_MEMREF) DS_IDENTITY(twSession));
+    twSession->twRC = DSM_CLOSE_DS(twSession);
 
   /* Check the return to determine what the user decided
    * to do.
 	 */
-  switch (twSession->twRC) {
+    switch (twSession->twRC)
+    {
   case TWRC_SUCCESS:
     /* We are now in TWAIN state 3 */
-    twSession->twainState = 3;
-    LogMessage("Data source %s closed\n", DS_IDENTITY(twSession)->ProductName);
-    return TRUE;
+        twSession->twainState = DSM_STATE_LOADED;
     break;
 
   default:
-    LogMessage("Error \"%s\" closing data source\n", currentTwainError(twSession));
+        log_message ("Error closing data source: %s\n", currentTwainError(twSession));
     break;
   }
-
-  return FALSE;
+  }
 }
 
 /*
@@ -523,68 +506,55 @@
  *
  * 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)) {
-      LogMessage("closeDSM: Can't close source manager with open source\n");
-      return FALSE;
-    } 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));
+  if (DSM_IS_CLOSED(twSession))
+  {
+    log_message ("Data Source Manager not open\n");
+    return;
       }
-      else {
 
+  twSession->twRC = DSM_CLOSE(twSession);
+
+  switch (twSession->twRC)
+  {
+    case TWRC_SUCCESS:
 				/* We are now in state 2 */
-				twSession->twainState = 2;
-      }
-    }
+      twSession->twainState = DSM_STATE_CLOSED;
+      break;
+    case TWRC_FAILURE:
+      log_message ("Error closing Data Source Manager: %s\n", currentTwainError(twSession));
+      break;
   }
-
-  /* Let the caller know what happened */
-  return (twSession->twRC==TWRC_SUCCESS);
 }
 
-
 /*
  * beginImageTransfer
  *
  * Begin an image transfer.
  */
 static int
-beginImageTransfer(pTW_SESSION twSession, pTW_IMAGEINFO imageInfo)
+beginImageTransfer (pTW_SESSION twSession, pTW_IMAGEINFO imageInfo)
 {
   /* Clear our structures */
-  memset(imageInfo, 0, sizeof(TW_IMAGEINFO));
+  memset(imageInfo, 0, sizeof (TW_IMAGEINFO));
 
   /* Query the image information */
-  twSession->twRC = callDSM(
-			    APP_IDENTITY(twSession), DS_IDENTITY(twSession),
-			    DG_IMAGE, DAT_IMAGEINFO, MSG_GET,
-			    (TW_MEMREF) imageInfo);
+  twSession->twRC = DSM_GET_IMAGE(twSession, imageInfo);
 
   /* Check the return code */
-  if (twSession->twRC != TWRC_SUCCESS) {
-    LogMessage("Get Image Info failure - %s\n", currentTwainError(twSession));
+  switch (twSession->twRC)
+  {
+    case TWRC_SUCCESS:
+      /* Call the beginTransferCallback */
+      CB_XFER_BEGIN(twSession, imageInfo);
 
-    return FALSE;
+	case TWRC_FAILURE:
+      log_message ("Get Image Info failure - %s\n", currentTwainError(twSession));
+      break;
   }
-
-  /* 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;
 }
 
 /*
@@ -596,20 +566,18 @@
  * from State 6 to 7.  Return the reason for exiting the transfer.
  */
 static void
-transferImage(pTW_SESSION twSession, pTW_IMAGEINFO imageInfo)
+transferImage (pTW_SESSION twSession, pTW_IMAGEINFO imageInfo)
 {
   TW_SETUPMEMXFER setupMemXfer;
   TW_IMAGEMEMXFER imageMemXfer;
   char *buffer;
 
   /* Clear our structures */
-  memset(&setupMemXfer, 0, sizeof(TW_SETUPMEMXFER));
-  memset(&imageMemXfer, 0, sizeof(TW_IMAGEMEMXFER));
+  memset(&setupMemXfer, 0, sizeof (TW_SETUPMEMXFER));
+  memset(&imageMemXfer, 0, sizeof (TW_IMAGEMEMXFER));
 
   /* Find out how the source would like to transfer... */
-  twSession->twRC = callDSM(APP_IDENTITY(twSession), DS_IDENTITY(twSession),
-			    DG_CONTROL, DAT_SETUPMEMXFER, MSG_GET,
-			    (TW_MEMREF) &setupMemXfer);
+  twSession->twRC = DSM_XFER_START(twSession, setupMemXfer);
 
   /* Allocate the buffer for the transfer */
   buffer = g_new (char, setupMemXfer.Preferred);
@@ -618,7 +586,8 @@
   imageMemXfer.Memory.TheMem = (TW_MEMREF) buffer;
 
   /* Get the data */
-  do {
+  do
+  {
     /* Setup for the memory transfer */
     imageMemXfer.Compression = TWON_DONTCARE16;
     imageMemXfer.BytesPerRow = TWON_DONTCARE32;
@@ -629,22 +598,23 @@
     imageMemXfer.BytesWritten = TWON_DONTCARE32;
 
     /* Get the next block of memory */
-    twSession->twRC = callDSM(APP_IDENTITY(twSession), DS_IDENTITY(twSession),
-			      DG_IMAGE, DAT_IMAGEMEMXFER, MSG_GET,
-			      (TW_MEMREF) &imageMemXfer);
+    twSession->twRC = DSM_XFER_GET(twSession, imageMemXfer);
 
     if ((twSession->twRC == TWRC_SUCCESS) ||
-	(twSession->twRC == TWRC_XFERDONE)) {
-      /* Call the callback function */
-      if (!(*twSession->transferFunctions->txfrDataCb) (
-							imageInfo,
-							&imageMemXfer,
-							twSession->clientData)) {
+        (twSession->twRC == TWRC_XFERDONE))
+    {
+      /* Call dataTransferCallback */
+      if (!CB_XFER_DATA(twSession, imageInfo, imageMemXfer))
+      {
 	/* Callback function requested to cancel */
 	twSession->twRC = TWRC_CANCEL;
 	break;
       }
     }
+    else
+    {
+      g_error ("Transfer image %d data faild for %s!", ((pClientDataStruct) twSession->clientData)->image_id, currentTwainError(twSession));
+    }
   } while (twSession->twRC == TWRC_SUCCESS);
 
   /* Free the memory buffer */
@@ -662,12 +632,12 @@
 {
   TW_PENDINGXFERS pendingXfers;
 
-  twSession->twRC = callDSM(APP_IDENTITY(twSession), DS_IDENTITY(twSession),
-			    DG_CONTROL, DAT_PENDINGXFERS, MSG_ENDXFER,
-			    (TW_MEMREF) &pendingXfers);
+  twSession->twRC = DSM_XFER_STOP(twSession, pendingXfers);
 
   if (!pendingXfers.Count)
-    twSession->twainState = 5;
+  {
+    twSession->twainState = DSM_STATE_ACQUIRE;
+  }
 
   return pendingXfers.Count;
 }
@@ -678,13 +648,11 @@
  * Cancel all pending image transfers.
  */
 void
-cancelPendingTransfers(pTW_SESSION twSession)
+cancelPendingTransfers (pTW_SESSION twSession)
 {
   TW_PENDINGXFERS pendingXfers;
 
-  twSession->twRC = callDSM(APP_IDENTITY(twSession), DS_IDENTITY(twSession),
-			      DG_CONTROL, DAT_PENDINGXFERS, MSG_RESET,
-			      (TW_MEMREF) &pendingXfers);
+  twSession->twRC = DSM_XFER_RESET(twSession, pendingXfers);
 }
 
 /*
@@ -694,7 +662,7 @@
  * of pending images.
  */
 static int
-endImageTransfer(pTW_SESSION twSession, int *pendingCount)
+endImageTransfer (pTW_SESSION twSession, int *pendingCount)
 {
   gboolean continueTransfers;
   int exitCode = twSession->twRC;
@@ -702,25 +670,20 @@
   /* Have now exited the transfer for some reason... Figure out
    * why and what to do about it
    */
-  switch (twSession->twRC) {
+  switch (twSession->twRC)
+  {
   case TWRC_XFERDONE:
   case TWRC_CANCEL:
-    LogMessage("Xfer done received\n");
-    *pendingCount = endPendingTransfer(twSession);
     break;
 
   case TWRC_FAILURE:
-    LogMessage("Failure received\n");
-    *pendingCount = endPendingTransfer(twSession);
+      log_message ("Failure received: %s\n", currentTwainError(twSession));
     break;
   }
+  *pendingCount = endPendingTransfer (twSession);
 
-  /* Call the end transfer callback */
-  if (twSession->transferFunctions->txfrEndCb)
-    continueTransfers =
-      (*twSession->transferFunctions->txfrEndCb)(exitCode,
-						 *pendingCount,
-						 twSession->clientData);
+  /* Call the endTransferCallback */
+  CB_XFER_END(twSession, continueTransfers, exitCode, pendingCount);
 
   return (*pendingCount && continueTransfers);
 }
@@ -732,7 +695,7 @@
  * datasource.
  */
 static void
-transferImages(pTW_SESSION twSession)
+transferImages (pTW_SESSION twSession)
 {
   TW_IMAGEINFO imageInfo;
   int pendingCount;
@@ -740,58 +703,63 @@
   /* Check the image transfer callback function
    * before even attempting to do the transfer
    */
-  if (!twSession->transferFunctions || !twSession->transferFunctions->txfrDataCb) {
-    LogMessage("Attempting image transfer without callback function\n");
+  if (!twSession || !twSession->transferFunctions || !twSession->transferFunctions->txfrDataCb)
+  {
+    log_message ("Attempting image transfer without callback function.\n");
     return;
   }
 
   /*
    * Inform our application that we are getting ready
    * to transfer images.
+   * Call preTransferCallback
    */
   if (twSession->transferFunctions->preTxfrCb)
-    (*twSession->transferFunctions->preTxfrCb)(twSession->clientData);
+  {
+    CB_XFER_PRE(twSession);
+  }
 
   /* Loop through the available images */
-  do {
+  do
+  {
     /* Move to the new state */
-    twSession->twainState = 6;
+    twSession->twainState = DSM_STATE_TRANSFER;
 
     /* Begin the image transfer */
-    if (!beginImageTransfer(twSession, &imageInfo))
+    if (!beginImageTransfer (twSession, &imageInfo))
+    {
       continue;
+    }
 
     /* Call the image transfer function */
     transferImage(twSession, &imageInfo);
 
-  } while (endImageTransfer(twSession, &pendingCount));
+  } while (endImageTransfer (twSession, &pendingCount));
 
   /*
    * Inform our application that we are done
    * transferring images.
+   * Call postTransferCallback
    */
-  if (twSession->transferFunctions->postTxfrCb)
-    (*twSession->transferFunctions->postTxfrCb)(pendingCount,
-						twSession->clientData);
+  CB_XFER_POST(twSession, pendingCount);
 }
 
 void
-processTwainMessage(TW_UINT16 message, pTW_SESSION twSession)
+processTwainMessage (TW_UINT16 message, pTW_SESSION twSession)
 {
-  switch (message) {
+  switch (message)
+  {
   case MSG_XFERREADY:
-    LogMessage("Source says that data is ready\n");
-    transferImages(twSession);
+      transferImages (twSession);
     break;
 
   case MSG_CLOSEDSREQ:
     /* Disable the datasource, Close the Data source
      * and close the data source manager
      */
-    LogMessage("CloseDSReq\n");
-    disableDS(twSession);
-    closeDS(twSession);
-    closeDSM(twSession);
+      disableDS (twSession);
+      closeDS (twSession);
+      closeDSM (twSession);
     break;
 
   /* No message from the Source to the App break;
@@ -813,7 +781,8 @@
  * Create a new TWAIN session.
  */
 pTW_SESSION
-newSession(pTW_IDENTITY appIdentity) {
+newSession (pTW_IDENTITY appIdentity)
+{
   /* Create the structure */
   pTW_SESSION session = g_new (TW_SESSION, 1);
 
@@ -826,49 +795,82 @@
   session->dsIdentity->ProductName[0] = '\0';
   session->transferFunctions = NULL;
 
-  if (twainIsAvailable())
-    session->twainState = 2;
+  if (twainIsAvailable ())
+  {
+    session->twainState = DSM_STATE_CLOSED;
+  }
   else
-    session->twainState = 0;
+  {
+    session->twainState = DSM_STATE_UNDEFIND;
+  }
 
   return session;
 }
 
 /*
- * registerWindowHandle
+ * get_available_ds
  *
- * Register the window handle to be used for this
- * session.
+ * Get the list of available data sources.
  */
-void
-registerWindowHandle(pTW_SESSION session, TW_HANDLE hwnd)
+pTW_DATA_SOURCE
+get_available_ds (pTW_SESSION twSession)
 {
-  session->hwnd = hwnd;
-}
+  pTW_DATA_SOURCE data_source = NULL;
+  pTW_IDENTITY dsIdentity;
 
-/*
- * registerTransferCallback
- *
- * Register the callback to use when transferring
- * image data.
- */
-void
-registerTransferCallbacks(pTW_SESSION session,
-			  pTXFR_CB_FUNCS txfrFuncs,
-			  void *clientData)
-{
-  session->transferFunctions = txfrFuncs;
-  session->clientData = clientData;
-}
+  if(DSM_IS_CLOSED(twSession))
+  {
+    log_message ("You need to open the DSM first.\n");
+    return NULL;
+  }
 
-/*
- * setClientData
- *
- * Set the client data associated with the specified
- * TWAIN session.
- */
-void
-setClientData(pTW_SESSION session, void *clientData)
-{
-  session->clientData = clientData;
+  if (twSession != NULL)
+  {
+    dsIdentity = g_new (TW_IDENTITY, 1);
+    twSession->twRC = DSM_GET_FIRST_DS(twSession, dsIdentity);
+
+    switch (twSession->twRC)
+    {
+      case TWRC_SUCCESS:
+        data_source = g_new (TW_DATA_SOURCE, 1);
+        data_source->dsIdentity = dsIdentity;
+        data_source->dsNext = NULL;
+        twSession->dataSources = data_source;
+        break;
+
+    case TWRC_ENDOFLIST:
+        twSession->dataSources = NULL;
+        break;
+
+      case TWRC_FAILURE:
+        log_message ("Error getting first data source: %s\n", currentTwainError(twSession));
+        break;
+    }
+
+    /* get the rest of the data sources */
+    while (TWRC_SUCCESS == twSession->twRC)
+    {
+      dsIdentity = g_new (TW_IDENTITY, 1);
+      twSession->twRC = DSM_GET_NEXT_DS(twSession, dsIdentity);
+
+      switch (twSession->twRC)
+      {
+        case TWRC_SUCCESS:
+          data_source->dsNext = g_new (TW_DATA_SOURCE, 1);
+          data_source = data_source->dsNext;
+          data_source->dsIdentity = dsIdentity;
+          data_source->dsNext = NULL;
+          break;
+
+        case TWRC_ENDOFLIST:
+          break;
+
+        case TWRC_FAILURE:
+          log_message ("Error getting next data source: %s\n", currentTwainError(twSession));
+          break;
+      }
+    }
+  }
+
+  return twSession->dataSources;
 }
diff -rub /usr/src/git/gimp/plug-ins/twain/tw_func.h /usr/src/gimp-2.7.3/plug-ins/twain/tw_func.h
--- /usr/src/git/gimp/plug-ins/twain/tw_func.h	2011-12-17 16:24:18 +0000
+++ /usr/src/gimp-2.7.3/plug-ins/twain/tw_func.h	2011-12-16 18:36:47 +0000
@@ -8,6 +8,10 @@
  * 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
@@ -57,13 +61,11 @@
  *  (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.
  */
 
 #ifndef _TW_FUNC_H
 #define _TW_FUNC_H
-
-#include "tw_platform.h"
-
 /*
  * Pre-image transfer function type
  *
@@ -119,6 +121,20 @@
  */
 typedef void (* TW_POST_TXFR_CB)(int, void *);
 
+/* 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;
+
 /*
  * The following structure defines the
  * three callback functions that are called
@@ -144,6 +160,28 @@
   TW_POST_TXFR_CB postTxfrCb;
 } TXFR_CB_FUNCS, *pTXFR_CB_FUNCS;
 
+#define CB_XFER_PRE(s) if (s->transferFunctions->preTxfrCb) \
+    (*s->transferFunctions->preTxfrCb) (s->clientData);
+
+#define CB_XFER_BEGIN(s, i)   if (s->transferFunctions->txfrBeginCb) \
+    if (!(*s->transferFunctions->txfrBeginCb) (imageInfo, s->clientData)) \
+      return FALSE; \
+  return TRUE;
+
+#define CB_XFER_DATA(s, i, m) (*s->transferFunctions->txfrDataCb) \
+    (i, &m, s->clientData)
+
+#define CB_XFER_END(s, c, e, p)   if (s->transferFunctions->txfrEndCb) \
+    c = (*s->transferFunctions->txfrEndCb) (e, *p, s->clientData)
+
+#define CB_XFER_POST(s, p) if (s->transferFunctions->postTxfrCb) \
+    (*s->transferFunctions->postTxfrCb) (p, s->clientData)
+
+typedef struct _TW_DATA_SOURCE {
+  pTW_IDENTITY dsIdentity;
+  struct _TW_DATA_SOURCE *dsNext;
+} TW_DATA_SOURCE, *pTW_DATA_SOURCE;
+
 /*
  * Data representing a TWAIN
  * application to data source
@@ -184,51 +222,119 @@
    */
   int twainState;
 
+  const gchar *name;
+  /*
+   * The available data sources for this session.
+   * The list will be updated each time the plugin is invoked on query.
+   */
+  struct _TW_DATA_SOURCE *dataSources;
+
 } TW_SESSION, *pTW_SESSION;
 
 /* Session structure access
  * macros
  */
-/* #define pAPP_IDENTITY(tw_session) (&(tw_session->appIdentity)) */
-#define APP_IDENTITY(tw_session) (tw_session->appIdentity)
-/* #define pDS_IDENTITY(tw_session) (&(tw_session->dsIdentity)) */
-#define DS_IDENTITY(tw_session) (tw_session->dsIdentity)
+#define APP_IDENTITY(tw_session)   ((tw_session == NULL) ? NULL : tw_session->appIdentity)
+#define DS_IDENTITY(tw_session)    ((tw_session == NULL) ? NULL : tw_session->dsIdentity)
+
+enum DSM_STATES
+{
+  DSM_STATE_UNDEFIND = 0,
+  DSM_STATE_CLOSED   = 2,
+  DSM_STATE_LOADED   = 3,
+  DSM_STATE_DS_OPEN  = 4,
+  DSM_STATE_ACQUIRE  = 5,
+  DSM_STATE_TRANSFER = 6
+};
 
 /* State macros... Each expects
  * a Twain Session pointer
  */
-#define TWAIN_LOADED(tw_session) (tw_session->twainState >= 2)
-#define TWAIN_UNLOADED(tw_session) (tw_session->twainState < 2)
-#define DSM_IS_OPEN(tw_session) (tw_session->twainState >= 3)
-#define DSM_IS_CLOSED(tw_session) (tw_session->twainState < 3)
-#define DS_IS_OPEN(tw_session) (tw_session->twainState >= 4)
-#define DS_IS_CLOSED(tw_session) (tw_session->twainState < 4)
-#define DS_IS_ENABLED(tw_session) (tw_session->twainState >= 5)
-#define DS_IS_DISABLED(tw_session) (tw_session->twainState < 5)
+#define TWAIN_LOADED(tw_session)   ((tw_session == NULL) ? FALSE : tw_session->twainState >= DSM_STATE_CLOSED)
+#define TWAIN_UNLOADED(tw_session) ((tw_session == NULL) ? FALSE : tw_session->twainState <  DSM_STATE_CLOSED)
+#define DSM_IS_OPEN(tw_session)    ((tw_session == NULL) ? FALSE : tw_session->twainState >= DSM_STATE_LOADED)
+#define DSM_IS_CLOSED(tw_session)  ((tw_session == NULL) ? FALSE : tw_session->twainState <  DSM_STATE_LOADED)
+#define DS_IS_OPEN(tw_session)     ((tw_session == NULL) ? FALSE : tw_session->twainState >= DSM_STATE_DS_OPEN)
+#define DS_IS_CLOSED(tw_session)   ((tw_session == NULL) ? FALSE : tw_session->twainState <  DSM_STATE_DS_OPEN)
+#define DS_IS_ENABLED(tw_session)  ((tw_session == NULL) ? FALSE : tw_session->twainState >= DSM_STATE_ACQUIRE)
+#define DS_IS_DISABLED(tw_session) ((tw_session == NULL) ? FALSE : tw_session->twainState <  DSM_STATE_ACQUIRE)
+
+#define DSM_GET_STATUS(session, status)  callDSM(session->appIdentity, session->dsIdentity, \
+          DG_CONTROL, DAT_STATUS, MSG_GET, (TW_MEMREF) &status)
+
+#define DSM_OPEN(session) callDSM(session->appIdentity, NULL,\
+          DG_CONTROL, DAT_PARENT, MSG_OPENDSM, (TW_MEMREF) &(session->hwnd))
+
+#define DSM_CLOSE(session) callDSM(session->appIdentity, NULL,\
+          DG_CONTROL, DAT_PARENT, MSG_CLOSEDSM, (TW_MEMREF)&(session->hwnd))
+
+#define DSM_SET_CALLBACK(session, callback) callDSM(session->appIdentity, NULL,\
+          DG_CONTROL, DAT_CALLBACK, MSG_REGISTER_CALLBACK, (TW_MEMREF) &callback)
+
+#define DSM_PROCESS_EVENT(session, event) callDSM(session->appIdentity, session->dsIdentity,\
+          DG_CONTROL, DAT_EVENT, MSG_PROCESSEVENT, (TW_MEMREF) &event)
+
+#define DSM_GET_PALETTE(session, data) callDSM(session->appIdentity, session->dsIdentity,\
+            DG_IMAGE, DAT_PALETTE8, MSG_GET, (TW_MEMREF) data->paletteData)
+
+#define DSM_SELECT_USER(session) callDSM(session->appIdentity, NULL,\
+          DG_CONTROL, DAT_IDENTITY, MSG_USERSELECT, (TW_MEMREF) session->dsIdentity)
+
+#define DSM_SELECT_DEFAULT(session) callDSM(session->appIdentity, NULL,\
+          DG_CONTROL, DAT_IDENTITY, MSG_GETDEFAULT, (TW_MEMREF) session->dsIdentity)
+
+#define DSM_OPEN_DS(session) callDSM(session->appIdentity, NULL,\
+          DG_CONTROL, DAT_IDENTITY, MSG_OPENDS, (TW_MEMREF) session->dsIdentity)
+
+#define DSM_CLOSE_DS(session) callDSM(session->appIdentity, NULL,\
+          DG_CONTROL, DAT_IDENTITY, MSG_CLOSEDS, (TW_MEMREF) session->dsIdentity)
+
+#define DSM_ENABLE_DS(session, ui) callDSM(session->appIdentity, session->dsIdentity,\
+          DG_CONTROL, DAT_USERINTERFACE, MSG_ENABLEDS, (TW_MEMREF) &ui)
+
+#define DSM_DISABLE_DS(session, ui) callDSM(session->appIdentity, session->dsIdentity,\
+          DG_CONTROL, DAT_USERINTERFACE, MSG_DISABLEDS, (TW_MEMREF) &ui)
+
+#define DSM_GET_IMAGE(session, info) callDSM(session->appIdentity, session->dsIdentity,\
+          DG_IMAGE, DAT_IMAGEINFO, MSG_GET, (TW_MEMREF) info)
+
+#define DSM_XFER_SET(session, buffer) callDSM(session->appIdentity, session->dsIdentity,\
+          DG_CONTROL, DAT_CAPABILITY, MSG_SET, (TW_MEMREF) &buffer)
+
+#define DSM_XFER_START(session, memRef) callDSM(session->appIdentity, session->dsIdentity,\
+          DG_CONTROL, DAT_SETUPMEMXFER, MSG_GET, (TW_MEMREF) &memRef)
+
+#define DSM_XFER_GET(session, memRef) callDSM(session->appIdentity, session->dsIdentity,\
+          DG_IMAGE, DAT_IMAGEMEMXFER, MSG_GET, (TW_MEMREF) &memRef)
+
+#define DSM_XFER_STOP(session, memRef) callDSM(session->appIdentity, session->dsIdentity,\
+          DG_CONTROL, DAT_PENDINGXFERS, MSG_ENDXFER, (TW_MEMREF) &memRef)
+
+#define DSM_XFER_RESET(session, memRef) callDSM(session->appIdentity, session->dsIdentity,\
+          DG_CONTROL, DAT_PENDINGXFERS, MSG_RESET, (TW_MEMREF) &memRef)
+
+#define DSM_GET_FIRST_DS(session, source) callDSM (session->appIdentity, NULL, \
+          DG_CONTROL, DAT_IDENTITY, MSG_GETFIRST, (TW_MEMREF) source);
+
+#define DSM_GET_NEXT_DS(session, source) callDSM (session->appIdentity, NULL, \
+          DG_CONTROL, DAT_IDENTITY, MSG_GETNEXT, (TW_MEMREF) source);
 
 /* Function declarations */
-char *twainError(int);
+char * twainError (int errorCode);
 char *currentTwainError(pTW_SESSION);
-int getImage(pTW_SESSION);
-int loadTwainLibrary(pTW_SESSION);
-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);
-
-TW_FIX32 FloatToFix32(float);
-float FIX32ToFloat(TW_FIX32);
-
-void processTwainMessage(TW_UINT16 message, pTW_SESSION twSession);
-
-pTW_SESSION newSession(pTW_IDENTITY);
-void registerWindowHandle(pTW_SESSION, TW_HANDLE);
-void registerTransferCallbacks(pTW_SESSION, pTXFR_CB_FUNCS, void *);
-void setClientData(pTW_SESSION session, void *clientData);
+int             getImage (pTW_SESSION);
+int             loadTwainLibrary (pTW_SESSION);
+int             openDSM (pTW_SESSION);
+int             select_ds (pTW_SESSION);
+pTW_DATA_SOURCE get_available_ds (pTW_SESSION twSession);
+int             openDS (pTW_SESSION);
+int             requestImageAcquire (pTW_SESSION, gboolean);
+void            disableDS (pTW_SESSION);
+void            closeDS (pTW_SESSION);
+void            closeDSM (pTW_SESSION);
+void            cancelPendingTransfers (pTW_SESSION);
+void            processTwainMessage (TW_UINT16 message, pTW_SESSION twSession);
+pTW_SESSION     newSession (pTW_IDENTITY);
+int             adjust_selected_data_source (pTW_SESSION twSession);
 
 #endif /* _TW_FUNC_H */
Only in /usr/src/gimp-2.7.3/plug-ins/twain: tw_func.o
diff -rub /usr/src/git/gimp/plug-ins/twain/tw_local.h /usr/src/gimp-2.7.3/plug-ins/twain/tw_local.h
--- /usr/src/git/gimp/plug-ins/twain/tw_local.h	2011-12-17 16:24:18 +0000
+++ /usr/src/gimp-2.7.3/plug-ins/twain/tw_local.h	2011-12-15 17:06:02 +0000
@@ -8,6 +8,10 @@
  * 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
@@ -22,19 +26,33 @@
  * 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.
+ */
+
 #ifndef _TW_LOCAL_H
 #define _TW_LOCAL_H
 
-#include "tw_func.h"
-
 /* Functions which the platform-independent code will call */
 
-TW_UINT16 callDSM(pTW_IDENTITY, pTW_IDENTITY,
-		  TW_UINT32, TW_UINT16,
-		  TW_UINT16, TW_MEMREF);
+TW_UINT16
+callDSM(
+  pTW_IDENTITY pOrigin,
+  pTW_IDENTITY pDest,
+  TW_UINT32    DG,
+  TW_UINT16    DAT,
+  TW_UINT16    MSG,
+  TW_MEMREF    pData);
 
 int twainIsAvailable(void);
-void twainQuitApplication ();
+void twainQuitApplication(void);
 gboolean twainSetupCallback (pTW_SESSION twSession);
 
 TW_HANDLE twainAllocHandle(size_t size);
@@ -42,7 +60,7 @@
 void twainUnlockHandle (TW_HANDLE handle);
 void twainFreeHandle (TW_HANDLE handle);
 
-int twainMain ();
-int scanImage ();
+int twain_main (const gchar *name);
+int scanImage (void);
 
-#endif
+#endif /* _TW_LOCAL_H */
diff -rub /usr/src/git/gimp/plug-ins/twain/tw_mac.c /usr/src/gimp-2.7.3/plug-ins/twain/tw_mac.c
--- /usr/src/git/gimp/plug-ins/twain/tw_mac.c	2011-12-17 16:24:18 +0000
+++ /usr/src/gimp-2.7.3/plug-ins/twain/tw_mac.c	2011-12-17 09:06:47 +0000
@@ -42,6 +42,9 @@
                          TW_UINT16    MSG,
                          TW_MEMREF    pData);
 extern pTW_SESSION initializeTwain ();
+/* http://lists.wxwidgets.org/archive/wxPython-mac/msg00117.html */
+extern OSErr CPSSetProcessName (ProcessSerialNumber *psn, char *processname);
+extern OSErr CPSEnableForegroundOperation ( ProcessSerialNumber *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
 
 
 /*
@@ -50,7 +53,7 @@
  * Call the specified function on the data source manager.
  */
 TW_UINT16
-callDSM(pTW_IDENTITY pOrigin,
+callDSM (pTW_IDENTITY pOrigin,
 	pTW_IDENTITY pDest,
 	TW_UINT32    DG,
 	TW_UINT16    DAT,
@@ -75,7 +78,7 @@
 TW_HANDLE
 twainAllocHandle(size_t size)
 {
-	return NewHandle(size);
+  return NewHandle (size);
 }
 
 TW_MEMREF
@@ -101,15 +104,18 @@
 {
   TW_CALLBACK callback;
   /* We need to set up our callback to receive messages */
-  callback.CallBackProc = (TW_MEMREF)twainCallback;
-  callback.RefCon = (TW_UINT32)twSession;
+  callback.CallBackProc = (TW_MEMREF) twainCallback;
+  callback.RefCon = (TW_UINT32) twSession;
   callback.Message = 0;
-  twSession->twRC = callDSM(APP_IDENTITY(twSession), NULL,
-                            DG_CONTROL, DAT_CALLBACK, MSG_REGISTER_CALLBACK,
-                            (TW_MEMREF) &callback);
-  if (twSession->twRC != TWRC_SUCCESS) {
-    LogMessage("Couldn't set callback function (retval %d)", (int)(twSession->twRC));
-    return FALSE;
+  twSession->twRC = DSM_SET_CALLBACK(twSession, callback);
+  switch (twSession->twRC)
+  {
+    case TWRC_SUCCESS:
+      return TRUE;
+
+	case TWRC FAILURE:
+      log_message ("Couldn't set callback function (retval %d).", (int) (twSession->twRC));
+      break;
   }
   return TRUE;
 }
@@ -119,20 +125,17 @@
  *
  * Unload the TWAIN dynamic link library
  */
-int
-unloadTwainLibrary(pTW_SESSION twSession)
+void
+unloadTwainLibrary (pTW_SESSION twSession)
 {
   /* We're statically linked; just clear the session */
   DS_IDENTITY(twSession)->Id = 0;
 
-	/* We are now back at state 1 */
-  twSession->twainState = 1;
-  LogMessage("Source Manager successfully closed\n");
-
-  return TRUE;
+  /* We are now back at state 0 */
+  twSession->twainState = DSM_STATE_UNDEFIND;
 }
 
-TW_UINT16 twainCallback(pTW_IDENTITY pOrigin,
+TW_UINT16 twainCallback (pTW_IDENTITY pOrigin,
                         pTW_IDENTITY pDest,
                         TW_UINT32    DG,
                         TW_UINT16    DAT,
@@ -140,24 +143,20 @@
                         TW_MEMREF    pData)
 {
   pTW_SESSION twSession = (pTW_SESSION)(((TW_CALLBACK *)pData)->RefCon);
-  LogMessage("twainCallback! DG 0x%x, DAT 0x%x, MSG 0x%x\n",
-    (int)DG, (int)DAT, (int)MSG);
+  log_message ("twainCallback! DG 0x%x, DAT 0x%x, MSG 0x%x\n",
+      (int) DG, (int) DAT, (int) MSG);
   processTwainMessage (MSG, twSession);
   return TWRC_SUCCESS;
 }
 
 void twainQuitApplication ()
 {
-  QuitApplicationEventLoop();
+  QuitApplicationEventLoop ();
 }
 
 
 /* main bits */
 
-/* http://lists.wxwidgets.org/archive/wxPython-mac/msg00117.html */
-extern OSErr CPSSetProcessName (ProcessSerialNumber *psn, char *processname);
-extern OSErr CPSEnableForegroundOperation( ProcessSerialNumber *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
-
 static void
 doGetImage (EventLoopTimerRef inTimer, void *inUserData)
 {
@@ -165,7 +164,7 @@
     QuitApplicationEventLoop ();
 }
 
-static void twainSetupMacUI()
+static void twainSetupMacUI (void)
 {
   ProcessSerialNumber psn;
   GetCurrentProcess (&psn);
@@ -192,19 +191,19 @@
 
   /* Voodoo magic fix inspired by java_swt launcher */
   /* Without this the icon setting doesn't work about half the time. */
-  CGrafPtr p = BeginQDContextForApplicationDockTile();
-  EndQDContextForApplicationDockTile(p);
+  CGrafPtr p = BeginQDContextForApplicationDockTile ();
+  EndQDContextForApplicationDockTile (p);
 
   SetApplicationDockTileImage (icon);
 }
 
 int
-twainMain()
+twain_main (const gchar *name)
 {
   EventLoopTimerRef timer;
   OSStatus err;
 
-  twainSetupMacUI();
+  twainSetupMacUI ();
 
   /* Ok, back to work! */
   initializeTwain ();
@@ -216,12 +215,11 @@
                                NULL, &timer);
   if (err)
     {
-      g_warning ("InstallEventLoopTimer returned error %d", (int)err);
-      g_message ("Something went horribly awry.");
-      return -1;
+    log_message ("InstallEventLoopTimer returned error %d.", (int)err);
+    return FALSE;
     }
 
-  RunApplicationEventLoop();
-  return 0;
+  RunApplicationEventLoop ();
+  return TRUE;
 }
 
diff -rub /usr/src/git/gimp/plug-ins/twain/tw_platform.h /usr/src/gimp-2.7.3/plug-ins/twain/tw_platform.h
--- /usr/src/git/gimp/plug-ins/twain/tw_platform.h	2011-12-17 16:24:18 +0000
+++ /usr/src/gimp-2.7.3/plug-ins/twain/tw_platform.h	2011-12-16 15:53:19 +0000
@@ -8,6 +8,10 @@
  * 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
@@ -22,40 +26,71 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef _TW_PLATFORM_H
-#define _TW_PLATFORM_H
-
-#ifdef __APPLE__
-
-/* Mac OS X */
-
-#include <Carbon/Carbon.h>
-#include <TWAIN/TWAIN.h>
-
-#define DEBUG_LOGFILE "/tmp/twain.log"
-#define DUMP_FILE "/tmp/twaincap.bin"
-#define DUMP_NAME "dtwain"
-#define READDUMP_NAME "rtwain"
-
-#define _stricmp strcasecmp
+/*
+ * 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.
+ */
 
-#else
+#ifndef _TW_PLATFORM_H
+  #define _TW_PLATFORM_H
 
-/* Win32 */
+  #ifdef __APPLE__
+    /* Mac OS X */
 
-#include <windows.h>
-#include "twain.h"
+    /* Coding style violation: Don't include headers in headers */
+    #include <Carbon/Carbon.h>
+    /* Coding style violation: Don't include headers in headers */
+    #include "twain.h"
+
+    #define _stricmp strcasecmp
+  #else
+    /* Win32 */
+
+    /* 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 */
+    #ifdef TWH_64BIT
+      #define TWAIN_DLL_NAME "TWAINDSM.DLL"
+    #else
+      #define TWAIN_DLL_NAME "TWAIN_32.DLL"
+    #endif /* #ifdef TWH_64BIT */
+
+
+    /* Windows uses separate entry point */
+    #define TWAIN_ALTERNATE_MAIN
+  #endif /* __APPLE__ */
 
-/* The DLL to be loaded for TWAIN support */
-#define TWAIN_DLL_NAME "TWAIN_32.DLL"
-#define DEBUG_LOGFILE "c:\\twain.log"
-#define DUMP_FILE "C:\\TWAINCAP.BIN"
-#define DUMP_NAME "DTWAIN.EXE"
-#define READDUMP_NAME "RTWAIN.EXE"
+  /*
+   * Plug-in Definitions
+   */
+  #define STRINGIFY(x) #x
+  #define TOSTRING(x) STRINGIFY(x)
 
-/* Windows uses separate entry point */
-#define TWAIN_ALTERNATE_MAIN
+  #define LOG_FILE "twain-plugin.log"
 
-#endif
+  #define PRODUCT_FAMILY      "GNU"
+  #define PRODUCT_NAME        "GIMP"
+  #define PLUG_IN_NAME        "TWAIN"
+  #define PLUG_IN_DESCRIPTION N_("Capture an image from a 64 bit TWAIN datasource")
+  #define PLUG_IN_HELP        "This plug-in will capture an image from a 64 bit TWAIN datasource.\n" \
+                              "Logs will be written to " LOG_FILE " in your temp folder,\n" \
+                              "if GIMP_LOG_TWAIN is set in environment."
+  #define PLUG_IN_AUTHOR      "Jens Plonka (jens.plonka@gmx.de)"
+  #define PLUG_IN_COPYRIGHT   "Craig Setera"
+  #define PLUG_IN_MAJOR       0
+  #define PLUG_IN_MINOR       7
+  #define PLUG_IN_DATE        "11/25/2011"
+  #define PLUG_IN_VERSION     "v" TOSTRING(PLUG_IN_MAJOR) "." TOSTRING(PLUG_IN_MINOR) " (" PLUG_IN_DATE ")"
+  #define PLUG_IN_HINT        PRODUCT_NAME " " PLUG_IN_NAME " v" TOSTRING(PLUG_IN_MAJOR) "." TOSTRING(PLUG_IN_MINOR)
 
+  #define MID_SELECT          "twain-acquire"
 #endif
diff -rub /usr/src/git/gimp/plug-ins/twain/tw_util.c /usr/src/gimp-2.7.3/plug-ins/twain/tw_util.c
--- /usr/src/git/gimp/plug-ins/twain/tw_util.c	2011-12-17 16:24:18 +0000
+++ /usr/src/gimp-2.7.3/plug-ins/twain/tw_util.c	2011-12-17 09:06:47 +0000
@@ -8,6 +8,10 @@
  * 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
@@ -57,6 +61,7 @@
  *  (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.
  */
 
 #include "config.h"
@@ -70,101 +75,52 @@
 #include <string.h>
 #include <time.h>
 
+#include "tw_platform.h"
 #include "tw_util.h"
-#ifdef _DEBUG
-#include "tw_func.h"
-FILE *logFile = NULL;
-#endif
 
-#ifdef _DEBUG
+char *fileName = NULL;
+FILE *logFile = NULL;
 
 /*
- * LogMessage
+ * log_message
  */
 void
-LogMessage(char *format, ...)
+log_message (char *format, ...)
 {
   va_list args;
   time_t time_of_day;
   char *ctime_string;
 
-  /* Open the log file as necessary */
-  if (!logFile)
-    logFile = g_fopen(DEBUG_LOGFILE, "w");
-
-  time_of_day = time(NULL);
-  ctime_string = ctime(&time_of_day);
-  ctime_string[19] = '\0';
-
-  fprintf(logFile, "[%s] ", (ctime_string + 11));
-  va_start(args, format);
-  vfprintf(logFile, format, args);
-  fflush(logFile);
-  va_end(args);
-}
-
-void
-logBegin(pTW_IMAGEINFO imageInfo, void *clientData)
-{
-  int i;
-  char buffer[256];
-
-  LogMessage("\n");
-  LogMessage("*************************************\n");
-  LogMessage("\n");
-  LogMessage("Image transfer begin:\n");
-  /*	LogMessage("\tClient data: %s\n", (char *) clientData); */
-
-  /* Log the image information */
-  LogMessage("Image information:\n");
-  LogMessage("\tXResolution: %f\n", FIX32ToFloat(imageInfo->XResolution));
-  LogMessage("\tYResolution: %f\n", FIX32ToFloat(imageInfo->YResolution));
-  LogMessage("\tImageWidth: %d\n", imageInfo->ImageWidth);
-  LogMessage("\tImageLength: %d\n", imageInfo->ImageLength);
-  LogMessage("\tSamplesPerPixel: %d\n", imageInfo->SamplesPerPixel);
-  sprintf(buffer, "\tBitsPerSample: {");
-  for (i = 0; i < 8; i++) {
-    if (imageInfo->BitsPerSample[i])
-      strcat(buffer, "1");
-    else
-      strcat(buffer, "0");
+  /* Check if user want's to have a log file. */
+  if (getenv(GIMP_LOG_TWAIN) == NULL)
+  {
+    va_start (args, format);
+    g_message (format, args);
+    va_end (args);
+    return;
+  }
 
-    if (i != 7)
-      strcat(buffer, ",");
+  if (fileName == NULL)
+  {
+    fileName = g_new (char, 255);
+    strcpy (fileName, getenv (TEMP));
+    strcat (fileName, SEP_CHAR);
+    strcat (fileName, LOG_FILE);
   }
-  LogMessage("%s}\n", buffer);
 
-  LogMessage("\tBitsPerPixel: %d\n", imageInfo->BitsPerPixel);
-  LogMessage("\tPlanar: %s\n", (imageInfo->Planar ? "TRUE" : "FALSE"));
-  LogMessage("\tPixelType: %d\n", imageInfo->PixelType);
-  /* Compression */
+  /* Open the log file if necessary */
+  logFile = g_fopen(fileName, (logFile == NULL) ? "w" : "a");
 
-}
+  time_of_day = time (NULL);
+  ctime_string = ctime (&time_of_day);
+  ctime_string[19] = '\0';
 
-void
-logData(pTW_IMAGEINFO imageInfo,
-	pTW_IMAGEMEMXFER imageMemXfer,
-	void *clientData)
-{
-  LogMessage("Image transfer callback called:\n");
-  LogMessage("\tClient data: %s\n", (char *) clientData);
-  LogMessage("Memory block transferred:\n");
-  LogMessage("\tBytesPerRow = %d\n", imageMemXfer->BytesPerRow);
-  LogMessage("\tColumns = %d\n", imageMemXfer->Columns);
-  LogMessage("\tRows = %d\n", imageMemXfer->Rows);
-  LogMessage("\tXOffset = %d\n", imageMemXfer->XOffset);
-  LogMessage("\tYOffset = %d\n", imageMemXfer->YOffset);
-  LogMessage("\tBytesWritten = %d\n", imageMemXfer->BytesWritten);
-}
+  fprintf(logFile, "[%s] ", (ctime_string + 11));
 
-#else
+  va_start (args, format);
+  vfprintf (logFile, format, args);
+  va_end (args);
 
-/*
- * LogMessage
- */
-void
-LogMessage(char *format, ...)
-{
+  fflush (logFile);
+  fclose (logFile);
 }
-
-#endif /* DEBUG */
diff -rub /usr/src/git/gimp/plug-ins/twain/tw_util.h /usr/src/gimp-2.7.3/plug-ins/twain/tw_util.h
--- /usr/src/git/gimp/plug-ins/twain/tw_util.h	2011-12-17 16:24:18 +0000
+++ /usr/src/gimp-2.7.3/plug-ins/twain/tw_util.h	2011-12-17 09:06:47 +0000
@@ -8,6 +8,10 @@
  * 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
@@ -57,17 +61,23 @@
  *  (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.
  */
+
 #ifndef __TW_UTIL_H
 #define __TW_UTIL_H
 
-#include "tw_platform.h"
+#ifdef __APPLE__
+#define TEMP "TMP"
+#define SEP_CHAR "/"
+#else
+#define TEMP "TEMP"
+#define SEP_CHAR "\\"
+#endif
 
-void LogMessage(char *, ...);
+#define GIMP_LOG_TWAIN "GIMP_LOG_TWAIN"
+#define FIX32_TO_FLOAT(f) ((float) f.Whole + (float) f.Frac / 65536.0f)
 
-#ifdef _DEBUG
-void logBegin(pTW_IMAGEINFO, void *);
-void logData(pTW_IMAGEINFO, pTW_IMAGEMEMXFER, void *);
-#endif
+void  log_message (char *, ...);
 
 #endif /* __TW_UTIL_H */
Only in /usr/src/gimp-2.7.3/plug-ins/twain: tw_util.o
diff -rub /usr/src/git/gimp/plug-ins/twain/tw_win.c /usr/src/gimp-2.7.3/plug-ins/twain/tw_win.c
--- /usr/src/git/gimp/plug-ins/twain/tw_win.c	2011-12-17 16:24:18 +0000
+++ /usr/src/gimp-2.7.3/plug-ins/twain/tw_win.c	2011-12-17 09:06:47 +0000
@@ -8,6 +8,10 @@
  * 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
@@ -23,6 +27,17 @@
  */
 
 /*
+ * 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
  */
 
@@ -34,22 +49,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;
@@ -61,14 +61,14 @@
 /* Storage for the entry point into the DSM */
 static DSMENTRYPROC dsmEntryPoint = NULL;
 
-
 /*
  * callDSM
  *
  * Call the specified function on the data source manager.
  */
 TW_UINT16
-callDSM(pTW_IDENTITY pOrigin,
+callDSM (
+  pTW_IDENTITY pOrigin,
 	pTW_IDENTITY pDest,
 	TW_UINT32    DG,
 	TW_UINT16    DAT,
@@ -85,22 +85,27 @@
  * Return boolean indicating whether TWAIN is available
  */
 int
-twainIsAvailable(void)
+twainIsAvailable (void)
 {
   /* Already loaded? */
-  if (dsmEntryPoint) {
-    return TRUE;
-  }
-
+  if (dsmEntryPoint == NULL)
+  {
   /* Attempt to load the library */
-  hDLL = LoadLibrary(TWAIN_DLL_NAME);
+    hDLL = LoadLibrary (TWAIN_DLL_NAME);
   if (hDLL == NULL)
+    {
+      log_message ("Can't load library \"%s\"!\n", TWAIN_DLL_NAME);
     return FALSE;
+    }
 
   /* Look up the entry point for use */
-  dsmEntryPoint = (DSMENTRYPROC) GetProcAddress(hDLL, "DSM_Entry");
+    dsmEntryPoint = (DSMENTRYPROC) GetProcAddress (hDLL, "DSM_Entry");
   if (dsmEntryPoint == NULL)
+    {
+      log_message ("Lirary has no DSM Entry point.\n");
     return FALSE;
+    }
+  }
 
   return TRUE;
 }
@@ -108,7 +113,7 @@
 TW_HANDLE
 twainAllocHandle (size_t size)
 {
-  return GlobalAlloc(GHND, size);
+  return GlobalAlloc (GHND, size);
 }
 
 TW_MEMREF
@@ -141,12 +146,13 @@
  *
  * Unload the TWAIN dynamic link library
  */
-int
-unloadTwainLibrary(pTW_SESSION twSession)
+void
+unloadTwainLibrary (pTW_SESSION twSession)
 {
   /* Explicitly free the SM library */
-  if (hDLL) {
-    FreeLibrary(hDLL);
+  if (hDLL)
+  {
+    FreeLibrary (hDLL);
     hDLL=NULL;
   }
 
@@ -154,13 +160,10 @@
    * twain is killed.  If the id is left around the
    * data source can not be found or opened
 	 */
-  DS_IDENTITY(twSession)->Id = 0;
+  twSession->dsIdentity->Id = 0;
 
-	/* We are now back at state 1 */
-  twSession->twainState = 1;
-  LogMessage("Source Manager successfully closed\n");
-
-  return TRUE;
+  /* We are now back at state 0 */
+  twSession->twainState = DSM_STATE_UNDEFIND;
 }
 
 /*
@@ -177,7 +180,8 @@
   twSession->twRC = TWRC_NOTDSEVENT;
 
   /* Only ask Source Manager to process event if there is a Source connected. */
-  if (DSM_IS_OPEN(twSession) && DS_IS_OPEN(twSession)) {
+  if (DS_IS_OPEN(twSession))
+  {
 		/*
 		 * A Source provides a modeless dialog box as its user interface.
 		 * The following call relays Windows messages down to the Source's
@@ -185,17 +189,16 @@
 		 * messages sent from the Source to our Application.
 		 */
 		twEvent.pEvent = (TW_MEMREF) lpMsg;
-		twSession->twRC = callDSM(APP_IDENTITY(twSession), DS_IDENTITY(twSession),
-			DG_CONTROL, DAT_EVENT, MSG_PROCESSEVENT,
-			(TW_MEMREF) &twEvent);
+    twSession->twRC = DSM_PROCESS_EVENT(twSession, twEvent);
 
 		/* Check the return code */
-		if (twSession->twRC == TWRC_NOTDSEVENT) {
+    if (twSession->twRC == TWRC_NOTDSEVENT)
+    {
 			return FALSE;
 		}
 
 		/* Process the message as necessary */
-		processTwainMessage(twEvent.TWMessage, twSession);
+    processTwainMessage (twEvent.TWMessage, twSession);
   }
 
   /* tell the caller what happened */
@@ -210,14 +213,16 @@
  * the application exits.
  */
 int
-twainMessageLoop(pTW_SESSION twSession)
+twainMessageLoop (pTW_SESSION twSession)
 {
   MSG msg;
 
-  while (GetMessage(&msg, NULL, 0, 0)) {
-    if (DS_IS_CLOSED(twSession) || !TwainProcessMessage(&msg, twSession)) {
-      TranslateMessage((LPMSG)&msg);
-      DispatchMessage(&msg);
+  while (GetMessage (&msg, NULL, 0, 0) > 0)
+  {
+    if (DS_IS_CLOSED(twSession) || !TwainProcessMessage (&msg, twSession))
+    {
+      TranslateMessage ((LPMSG)&msg);
+      DispatchMessage (&msg);
     }
   }
 
@@ -231,29 +236,30 @@
  * GetLastError.
  */
 void
-LogLastWinError(void)
+LogLastWinError (void)
 {
 	LPVOID lpMsgBuf;
 
-	FormatMessage(
+  FormatMessage (
 		FORMAT_MESSAGE_ALLOCATE_BUFFER |
 		FORMAT_MESSAGE_FROM_SYSTEM |
 		FORMAT_MESSAGE_IGNORE_INSERTS,
 		NULL,
-		GetLastError(),
+    GetLastError (),
 		MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
 		(LPTSTR) &lpMsgBuf,
 		0,
 		NULL
 		);
 
-	LogMessage("%s\n", lpMsgBuf);
+  log_message ("%s\n", lpMsgBuf);
 
 	/* Free the buffer. */
-	LocalFree( lpMsgBuf );
+  LocalFree ( lpMsgBuf );
 }
 
-void twainQuitApplication ()
+void
+twainQuitApplication (void)
 {
   PostQuitMessage (0);
 }
@@ -273,7 +279,7 @@
  * datasource.
  */
 int APIENTRY
-WinMain(HINSTANCE hInstance,
+WinMain (HINSTANCE hInstance,
 	HINSTANCE hPrevInstance,
 	LPSTR     lpCmdLine,
 	int       nCmdShow)
@@ -290,18 +296,11 @@
    */
   hInst = hInstance;
 
-#ifdef _DEBUG
-  /* When in debug version, we allow different run modes...
-   * make sure that it is correctly set.
-   */
-  setRunMode(__argv);
-#endif /* _DEBUG */
-
   /*
    * Now, call gimp_main... This is what the MAIN() macro
    * would usually do.
    */
-  return gimp_main(&PLUG_IN_INFO, __argc, __argv);
+  return gimp_main (&PLUG_IN_INFO, __argc, __argv);
 }
 
 /*
@@ -309,20 +308,14 @@
  *
  * allow to build as console app as well
  */
-int main (int argc, char *argv[])
+int
+main (int argc, char *argv[])
 {
-#ifdef _DEBUG
-  /* When in debug version, we allow different run modes...
-   * make sure that it is correctly set.
-   */
-  setRunMode(__argv);
-#endif /* _DEBUG */
-
   /*
    * Now, call gimp_main... This is what the MAIN() macro
    * would usually do.
    */
-  return gimp_main(&PLUG_IN_INFO, __argc, __argv);
+  return gimp_main (&PLUG_IN_INFO, __argc, __argv);
 }
 
 /*
@@ -345,18 +338,20 @@
   wc.cbClsExtra = 0;
   wc.cbWndExtra = 0;
   wc.hInstance = hInstance;
-  wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
-  wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+  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. */
-  retValue = RegisterClass(&wc);
+  retValue = RegisterClass (&wc);
 
   /* Log error */
   if (!retValue)
-    LogLastWinError();
+  {
+    LogLastWinError ();
+  }
 
   return retValue;
 }
@@ -368,10 +363,10 @@
  * interface with the TWAIN datasource.
  */
 BOOL
-InitInstance(HINSTANCE hInstance, int nCmdShow, pTW_SESSION twSession)
+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);
 
@@ -382,13 +377,14 @@
   /* Register our window handle with the TWAIN
    * support.
    */
-  registerWindowHandle(twSession, hwnd);
+  twSession->hwnd = hwnd;
 
   /* Schedule the image transfer by posting a message */
-  PostMessage(hwnd, WM_TRANSFER_IMAGE, 0, 0);
+  PostMessage (hwnd, WM_TRANSFER_IMAGE, 0, 0);
+
+  ShowWindow (hwnd, nCmdShow);
 
-  ShowWindow(hwnd, nCmdShow);
-  UpdateWindow(hwnd);
+  UpdateWindow (hwnd);
 
   return TRUE;
 }
@@ -403,18 +399,24 @@
  * operate.
  */
 int
-twainMain()
+twain_main (const gchar *name)
 {
   /* Initialize the twain information */
   pTW_SESSION twSession = initializeTwain();
 
+  twSession->name = name;
+
   /* Perform instance initialization */
-  if (!InitApplication(hInst))
+  if (!InitApplication (hInst))
+  {
     return (FALSE);
+  }
 
   /* Perform application initialization */
-  if (!InitInstance(hInst, SHOW_WINDOW, twSession))
+  if (!InitInstance (hInst, SHOW_WINDOW, twSession))
+  {
     return (FALSE);
+  }
 
   /*
    * Call the main message processing loop...
@@ -430,7 +432,7 @@
  * Process window message for the main window.
  */
 LRESULT CALLBACK
-WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
+WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 {
   switch (message) {
 
@@ -440,12 +442,11 @@
     break;
 
   case WM_DESTROY:
-    LogMessage("Exiting application\n");
-    PostQuitMessage(0);
+    PostQuitMessage (0);
     break;
 
   default:
-    return (DefWindowProc(hWnd, message, wParam, lParam));
+    return (DefWindowProc (hWnd, message, wParam, lParam));
   }
   return 0;
 }
Only in /usr/src/gimp-2.7.3/plug-ins/twain: tw_win.h
Only in /usr/src/gimp-2.7.3/plug-ins/twain: tw_win.o
Only in /usr/src/gimp-2.7.3/plug-ins/twain: twain-menu.png
diff -rub /usr/src/git/gimp/plug-ins/twain/twain.c /usr/src/gimp-2.7.3/plug-ins/twain/twain.c
--- /usr/src/git/gimp/plug-ins/twain/twain.c	2011-12-17 16:24:18 +0000
+++ /usr/src/gimp-2.7.3/plug-ins/twain/twain.c	2011-12-17 08:30:41 +0000
@@ -8,6 +8,10 @@
  * 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
@@ -57,7 +61,9 @@
  *  (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.
  */
+
 #include "config.h"
 
 #include <glib.h>		/* Needed when compiling with gcc */
@@ -66,61 +72,52 @@
 #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
 
 /*
- * Definition of the run states
+ * Plug-in Parameter definitions
  */
-#define RUN_STANDARD 0
-#define RUN_DUMP 1
-#define RUN_READDUMP 2
-
-/* Global variables */
+#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" }
+/******************************************************************
+ * Global variables
+ ******************************************************************/
 pTW_SESSION twSession = NULL;
+static const GimpParamDef args[] = { IN_ARGS };
+static const GimpParamDef returns[]  = { OUT_ARGS };
 
 static char        *destBuf = NULL;
-#ifdef _DEBUG
-static int         twain_run_mode = RUN_STANDARD;
-#endif
-
-/* 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 *);
 
+/* The list of images to be transferred */
+GList        *images = NULL;
+
+/******************************************************************
+ * 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 *);
+pTW_SESSION initializeTwain (void);
+void register_menu (pTW_IDENTITY dsIdentity, const gchar *menu_path);
+void register_scanner_menus (void);
 static void query (void);
 static void run   (const gchar      *name,
 		   gint              nparams,
@@ -137,108 +134,70 @@
   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 =
-{
-  "",
-  100.0, 100.0,
-  0, 0,
-  0, 0,
-  TWPT_RGB
-};
-
 /* The standard callback functions */
-TXFR_CB_FUNCS standardCbFuncs = {
-  preTransferCallback,
-  beginTransferCallback,
-  dataTransferCallback,
-  endTransferCallback,
-  postTransferCallback };
+TXFR_CB_FUNCS standardCbFuncs =
+{
+  /* preTxfrCb   */ preTransferCallback,
+  /* txfrBeginCb */ beginTransferCallback,
+  /* txfrDataCb  */ dataTransferCallback,
+  /* txfrEndCb   */ endTransferCallback,
+  /* postTxfrCb  */ postTransferCallback
+};
 
 /******************************************************************
- * Dump handling
+ * Type definitions
  ******************************************************************/
 
-#ifdef _DEBUG
-/* The dumper callback functions */
-TXFR_CB_FUNCS dumperCbFuncs = {
-  dumpPreTransferCallback,
-  dumpBeginTransferCallback,
-  dumpDataTransferCallback,
-  dumpEndTransferCallback,
-  dumpPostTransferCallback };
-
-void
-setRunMode(char *argv[])
-{
-  char *exeName = strrchr(argv[0], '\\') + 1;
-
-  LogMessage("Executable name: %s\n", exeName);
+static char bitMasks[] = { 128, 64, 32, 16, 8, 4, 2, 1 };
 
-  if (!_stricmp(exeName, DUMP_NAME))
-    twain_run_mode = RUN_DUMP;
+/* Return values storage */
+static GimpParam values[3];
 
-  if (!_stricmp(exeName, RUNDUMP_NAME))
-    twain_run_mode = RUN_READDUMP;
-}
-#endif /* _DEBUG */
+/******************************************************************
+ * Dump handling
+ ******************************************************************/
 
 #ifndef TWAIN_ALTERNATE_MAIN
-MAIN()
-#endif
+MAIN ()
+#endif /* TWAIN_ALTERNATE_MAIN */
 
+/*
+ * scan_image
+ *
+ * Callback function for OS dependant implementation inside the
+ * event loop.
+ */
 int
 scanImage (void)
 {
-#ifdef _DEBUG
-  if (twain_run_mode == RUN_READDUMP)
-    return readDumpedImage (twSession);
-  else
-#endif /* _DEBUG */
     return getImage (twSession);
 }
 
 /*
- * initTwainAppIdentity
+ * get_app_identity
  *
  * Initialize and return our application's identity for
- * the TWAIN runtime.
+ * the TWAIN DataSourceManager.
  */
 static pTW_IDENTITY
-getAppIdentity(void)
+getAppIdentity (void)
 {
   pTW_IDENTITY appIdentity = g_new (TW_IDENTITY, 1);
 
   /* 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");
+  /* Tell the data source manger that we only accept image data sources */
+  appIdentity->SupportedGroups = DF_APP2 | DG_CONTROL | DG_IMAGE;
+  strcpy (appIdentity->Manufacturer, PLUG_IN_COPYRIGHT);
+  strcpy (appIdentity->ProductFamily, PRODUCT_FAMILY);
+  strcpy (appIdentity->ProductName, PRODUCT_NAME);
 
   return appIdentity;
 }
@@ -252,97 +211,110 @@
  * datasource manager calls.
  */
 pTW_SESSION
-initializeTwain(void)
+initializeTwain (void)
 {
   pTW_IDENTITY appIdentity;
 
   /* Get our application's identity */
-  appIdentity = getAppIdentity();
+  appIdentity = getAppIdentity ();
 
   /* Create a new session object */
-  twSession = newSession(appIdentity);
+  twSession = newSession (appIdentity);
 
   /* Register our image transfer callback functions */
-#ifdef _DEBUG
-  if (twain_run_mode == RUN_DUMP)
-    registerTransferCallbacks(twSession, &dumperCbFuncs, NULL);
-  else
-#endif /* _DEBUG */
-    registerTransferCallbacks(twSession, &standardCbFuncs, NULL);
+  twSession->transferFunctions = &standardCbFuncs;
+  twSession->clientData = NULL;
+
   return twSession;
 }
 
-/******************************************************************
- * GIMP Plug-in entry points
- ******************************************************************/
-
 /*
- * 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
+ * register_menu
  *
- * The plug-in is being queried.  Install our procedure for
- * acquiring.
+ * Registers a menu item for the given scanner.
  */
-static void
-query (void)
+void
+register_menu (const pTW_IDENTITY dsIdentity, const gchar *menu_path)
 {
-  static const GimpParamDef args[] = { IN_ARGS };
-  static const GimpParamDef return_vals[] = { OUT_ARGS };
+  guint8 *iconfile;
+  gchar *name;
 
-#ifdef _DEBUG
-  if (twain_run_mode == RUN_DUMP)
-    {
-      /* the installation of the plugin */
-      gimp_install_procedure(PLUG_IN_D_NAME,
+  name = dsIdentity->ProductName;
+
+  gimp_install_procedure (
+      name,
                              PLUG_IN_DESCRIPTION,
                              PLUG_IN_HELP,
-                             PLUG_IN_AUTHOR,
+      dsIdentity->Manufacturer,
                              PLUG_IN_COPYRIGHT,
                              PLUG_IN_VERSION,
-                             "TWAIN (Dump)...",
+      name,
                              NULL,
                              GIMP_PLUGIN,
                              NUMBER_IN_ARGS,
                              NUMBER_OUT_ARGS,
-                             args,
-                             return_vals);
+      args, returns);
 
-      gimp_plugin_menu_register (PLUG_IN_D_NAME, "<Image>/File/Create/Acquire");
-    }
-  else if (twain_run_mode == RUN_READDUMP)
+  gimp_plugin_menu_register (name, menu_path);
+  iconfile = (guint8 *) g_build_filename (gimp_data_directory (),
+                                      "twain",
+                                      "twain-menu.png",
+                                      NULL);
+  gimp_plugin_icon_register (name, GIMP_ICON_TYPE_IMAGE_FILE, iconfile);
+  g_free (iconfile);
+}
+
+/*
+ * register_scanner_menus
+ *
+ * Initilizes communication with the Data Source Manager.
+ * Communication will be kept open till shutdown of GIMP
+ * because the id might change due to new installed data
+ * sources wile GIMP is open!
+ * The name of each scanner is the identifyer of the menu.
+ */
+void
+register_scanner_menus (void)
+{
+  pTW_DATA_SOURCE dataSource;
+  pTW_IDENTITY dsIdentity;
+
+  // Get the list of available TWAIN data sources
+  initializeTwain ();
+
+  if (openDSM (twSession))
     {
-      /* the installation of the plugin */
-      gimp_install_procedure(PLUG_IN_R_NAME,
-                             PLUG_IN_DESCRIPTION,
-                             PLUG_IN_HELP,
-                             PLUG_IN_AUTHOR,
-                             PLUG_IN_COPYRIGHT,
-                             PLUG_IN_VERSION,
-                             "TWAIN (Read)...",
-                             NULL,
-                             GIMP_PLUGIN,
-                             NUMBER_IN_ARGS,
-                             NUMBER_OUT_ARGS,
-                             args,
-                             return_vals);
+    /* get all available data source as a linked list into twSession */
+    dataSource = get_available_ds (twSession);
 
-      gimp_plugin_menu_register (PLUG_IN_R_NAME, "<Image>/File/Create/Acquire");
-    }
-  else
-#endif /* _DEBUG */
+    /* for each found data source create an own menu item */
+    while (dataSource != NULL)
     {
-      /* the installation of the plugin */
-      gimp_install_procedure(PLUG_IN_NAME,
+      dsIdentity = dataSource->dsIdentity;
+      register_menu (dsIdentity, "<Toolbox>/File/Create");
+
+      /* handle the next data source */
+      dataSource = dataSource->dsNext;
+    }
+
+    closeDSM (twSession);
+  }
+}
+
+/******************************************************************
+ * GIMP Plug-in entry points
+ ******************************************************************/
+
+/*
+ * query
+ *
+ * The plug-in is being queried. Install our procedure for acquiring.
+ */
+static void
+query (void)
+{
+  /* Old style of scanner selection */
+  gimp_install_procedure (MID_SELECT,
                              PLUG_IN_DESCRIPTION,
                              PLUG_IN_HELP,
                              PLUG_IN_AUTHOR,
@@ -353,16 +325,13 @@
                              GIMP_PLUGIN,
                              NUMBER_IN_ARGS,
                              NUMBER_OUT_ARGS,
-                             args,
-                             return_vals);
-
-      gimp_plugin_menu_register (PLUG_IN_NAME, "<Image>/File/Create/Acquire");
-    }
-}
+      args, returns);
 
+  gimp_plugin_menu_register (MID_SELECT, "<Toolbox>/File/Create/Acquire");
 
-/* Return values storage */
-static GimpParam values[3];
+  /* New style of scanner selection */
+  register_scanner_menus ();
+}
 
 /*
  * run
@@ -377,6 +346,9 @@
      gint             *nreturn_vals,
      GimpParam       **return_vals)
 {
+  GList       *list;
+  gint32       count = 0;
+  gint32       i;
   GimpRunMode run_mode = param[0].data.d_int32;
 
   /* Initialize the return values
@@ -384,7 +356,7 @@
    */
   values[0].type = GIMP_PDB_STATUS;
   values[0].data.d_status = GIMP_PDB_SUCCESS;
-  *nreturn_vals = 1;
+  *nreturn_vals = 3;
   *return_vals = values;
 
   INIT_I18N ();
@@ -393,7 +365,8 @@
    * TWAIN and that there is actually a datasource
    * to be used in doing the acquire.
    */
-  if (!twainIsAvailable()) {
+  if (!twainIsAvailable ())
+  {
     values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
     return;
   }
@@ -402,55 +375,53 @@
   values[1].type = GIMP_PDB_INT32;
   values[1].data.d_int32 = 0;
   values[2].type = GIMP_PDB_INT32ARRAY;
-  values[2].data.d_int32array = g_new (gint32, MAX_IMAGES);
+  values[2].data.d_int32array = NULL; /* Will be assigned when acquiring an image */
 
   /* How are we running today? */
-  switch (run_mode) {
-  case GIMP_RUN_INTERACTIVE:
-    /* Retrieve values from the last run...
-     * Currently ignored
-     */
-    gimp_get_data(PLUG_IN_NAME, &twainvals);
-    break;
-
+  switch (run_mode)
+  {
   case GIMP_RUN_NONINTERACTIVE:
-    /* Currently, we don't do non-interactive calls.
-     * Bail if someone tries to call us non-interactively
+      /* Non-interactive calls are not supported!
+       * Bail if someone tries to call this way.
      */
     values[0].data.d_status = GIMP_PDB_CALLING_ERROR;
     return;
 
-  case GIMP_RUN_WITH_LAST_VALS:
+    default:
     /* Retrieve values from the last run...
      * Currently ignored
      */
-    gimp_get_data(PLUG_IN_NAME, &twainvals);
     break;
-
-  default:
-    break;
-  } /* switch */
+  }
 
   /* Have we succeeded so far? */
   if (values[0].data.d_status == GIMP_PDB_SUCCESS)
-    twainMain ();
+  {
+    if (twain_main (name))
+    {
+      count = g_list_length (images);
+    }
+
+    if (count > 0)
+    {
+      /* Return the list of image IDs */
+      values[2].data.d_int32array = g_new (gint32, count);
+      for (list = images, i = 0; list; list = g_list_next (list), i++)
+      {
+        values[2].data.d_int32array[i] = GPOINTER_TO_INT (list->data);
+      }
+      g_list_free (images);
+    }
+  }
+
+  /* Retrun the number of images */
+  values[1].data.d_int32      = count;
 
   /* Check to make sure we got at least one valid
    * image.
    */
-  if (values[1].data.d_int32 > 0) {
-    /* An image was captured from the TWAIN
-     * datasource.  Do final Interactive
-     * steps.
-     */
-    if (run_mode == GIMP_RUN_INTERACTIVE) {
-      /* Store variable states for next run */
-      gimp_set_data(PLUG_IN_NAME, &twainvals, sizeof (TwainValues));
-    }
-
-    /* Set return values */
-    *nreturn_vals = 3;
-  } else {
+  if (count == 0)
+  {
     values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
   }
 }
@@ -459,19 +430,6 @@
  * 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
  *
@@ -479,7 +437,7 @@
  * are transferred.  Set up the one time only stuff.
  */
 void
-preTransferCallback(void *clientData)
+preTransferCallback (void *clientData)
 {
   /* Initialize our progress dialog */
   gimp_progress_init (_("Transferring data from scanner/camera"));
@@ -492,18 +450,17 @@
  * of each image transfer.
  */
 int
-beginTransferCallback(pTW_IMAGEINFO imageInfo, void *clientData)
+beginTransferCallback (pTW_IMAGEINFO imageInfo, void *clientData)
 {
   int imageType, layerType;
+  TW_INT32 width = imageInfo->ImageWidth;
+  TW_INT32 length = imageInfo->ImageLength;
 
   pClientDataStruct theClientData = g_new (ClientDataStruct, 1);
 
-#ifdef _DEBUG
-  logBegin(imageInfo, clientData);
-#endif
-
   /* Decide on the image type */
-  switch (imageInfo->PixelType) {
+  switch (imageInfo->PixelType)
+  {
   case TWPT_BW:
   case TWPT_GRAY:
     /* Set up the image and layer types */
@@ -520,13 +477,14 @@
   case TWPT_PALETTE:
     /* Get the palette data */
     theClientData->paletteData = g_new (TW_PALETTE8, 1);
-    twSession->twRC = callDSM(APP_IDENTITY(twSession), DS_IDENTITY(twSession),
-			      DG_IMAGE, DAT_PALETTE8, MSG_GET,
-			      (TW_MEMREF) theClientData->paletteData);
+      twSession->twRC = DSM_GET_PALETTE(twSession, theClientData);
     if (twSession->twRC != TWRC_SUCCESS)
+      {
       return FALSE;
+      }
 
-    switch (theClientData->paletteData->PaletteType) {
+      switch (theClientData->paletteData->PaletteType)
+      {
     case TWPA_RGB:
       /* Set up the image and layer types */
       imageType = GIMP_RGB;
@@ -553,43 +511,41 @@
   }
 
   /* Create the GIMP image */
-  theClientData->image_id = gimp_image_new(imageInfo->ImageWidth,
-					   imageInfo->ImageLength, imageType);
+  theClientData->image_id = gimp_image_new (width, length, imageType);
 
   /* Set the actual resolution */
   gimp_image_set_resolution (theClientData->image_id,
-                             FIX32ToFloat(imageInfo->XResolution),
-                             FIX32ToFloat(imageInfo->YResolution));
+      FIX32_TO_FLOAT(imageInfo->XResolution),
+      FIX32_TO_FLOAT(imageInfo->YResolution));
   gimp_image_set_unit (theClientData->image_id, GIMP_UNIT_INCH);
 
   /* Create a layer */
   theClientData->layer_id = gimp_layer_new(theClientData->image_id,
-					   _("Background"),
-					   imageInfo->ImageWidth,
-					   imageInfo->ImageLength,
-					   layerType, 100, GIMP_NORMAL_MODE);
+      _("Background"), width, length, layerType, 100, GIMP_NORMAL_MODE);
 
   /* Add the layer to the image */
-  gimp_image_insert_layer(theClientData->image_id,
+  gimp_image_insert_layer (theClientData->image_id,
                           theClientData->layer_id, -1, 0);
 
   /* Update the progress dialog */
-  theClientData->totalPixels = imageInfo->ImageWidth * imageInfo->ImageLength;
+  theClientData->totalPixels = width * length;
   theClientData->completedPixels = 0;
-  gimp_progress_update((double) 0);
+  gimp_progress_update ((double) 0);
 
   /* Get our drawable */
   theClientData->drawable = gimp_drawable_get(theClientData->layer_id);
 
   /* Initialize a pixel region for writing to the image */
-  gimp_pixel_rgn_init(&(theClientData->pixel_rgn), theClientData->drawable,
-		      0, 0, imageInfo->ImageWidth, imageInfo->ImageLength,
-		      TRUE, FALSE);
+  gimp_pixel_rgn_init (&(theClientData->pixel_rgn), theClientData->drawable,
+          0, 0, width, length, TRUE, FALSE);
 
   /* Store our client data for the data transfer callbacks */
   if (clientData)
+  {
     g_free (clientData);
-  setClientData(twSession, (void *) theClientData);
+  }
+
+  twSession->clientData = (void *) theClientData;
 
   /* Make sure to return TRUE to continue the image
    * transfer
@@ -608,7 +564,6 @@
  * 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,
@@ -622,13 +577,17 @@
 
   /* Allocate a buffer as necessary */
   if (!destBuf)
+  {
     destBuf = g_new (char, rows * cols);
+  }
 
   /* Unpack the image data from bits into bytes */
   srcBuf = (char *) imageMemXfer->Memory.TheMem;
   offset = 0;
-  for (row = 0; row < rows; row++) {
-    for (col = 0; col < cols; col++) {
+  for (row = 0; row < rows; row++)
+  {
+    for (col = 0; col < cols; col++)
+    {
       char byte = srcBuf[(row * imageMemXfer->BytesPerRow) + (col / 8)];
       destBuf[offset++] = ((byte & bitMasks[col % 8]) != 0) ? 255 : 0;
     }
@@ -645,6 +604,7 @@
   gimp_progress_update((double) theClientData->completedPixels /
 		       (double) theClientData->totalPixels);
 
+
   return TRUE;
 }
 
@@ -672,7 +632,9 @@
 
   /* Allocate a buffer as necessary */
   if (!destBuf)
+  {
     destBuf = g_new (char, rows * cols * bytesPerPixel);
+  }
 
   /* The bytes coming from the source may not be padded in
    * a way that GIMP is terribly happy with.  It is
@@ -683,7 +645,8 @@
    * a non-padded chunk for GIMP.
    */
   srcBuf = (char *) imageMemXfer->Memory.TheMem;
-  for (row = 0; row < rows; row++) {
+  for (row = 0; row < rows; row++)
+  {
     /* Copy the current row */
     memcpy((destBuf + (row * bytesPerPixel * cols)),
 	   (srcBuf + (row * imageMemXfer->BytesPerRow)),
@@ -712,11 +675,11 @@
  * the image type is Grayscale or RGB.
  */
 static int
-twoBytesPerSampleTransferCallback(pTW_IMAGEINFO imageInfo,
+twoBytesPerSampleTransferCallback (pTW_IMAGEINFO imageInfo,
 		     pTW_IMAGEMEMXFER imageMemXfer,
 		     void *clientData)
 {
-  static float ratio = 0.00390625;
+  static float ratio = 0.00390625; /* 1/256 */
   int row, col, sample;
   char *destByte;
   int rows = imageMemXfer->Rows;
@@ -728,7 +691,9 @@
 
   /* Allocate a buffer as necessary */
   if (!destBuf)
+  {
     destBuf = g_new (char, rows * cols * imageInfo->SamplesPerPixel);
+  }
 
   /* The bytes coming from the source may not be padded in
    * a way that GIMP is terribly happy with.  It is
@@ -741,7 +706,8 @@
    * per sample.
    */
   /* Work through the rows */
-  for (row = 0; row < rows; row++) {
+  for (row = 0; row < rows; row++)
+  {
     /* The start of this source row */
     samplePtr = (TW_UINT16 *)
       ((char *) imageMemXfer->Memory.TheMem + (row * imageMemXfer->BytesPerRow));
@@ -750,9 +716,11 @@
     destByte = destBuf + (row * imageInfo->SamplesPerPixel * cols);
 
     /* Work through the columns */
-    for (col = 0; col < cols; col++) {
+    for (col = 0; col < cols; col++)
+    {
       /* Finally, work through each of the samples */
-      for (sample = 0; sample < imageInfo->SamplesPerPixel; sample++) {
+      for (sample = 0; sample < imageInfo->SamplesPerPixel; sample++)
+      {
 				/* Get the value */
 	TW_UINT16 value = *samplePtr;
 
@@ -793,7 +761,7 @@
  * the pixels.
  */
 static int
-palettedTransferCallback(pTW_IMAGEINFO imageInfo,
+palettedTransferCallback (pTW_IMAGEINFO imageInfo,
 			 pTW_IMAGEMEMXFER imageMemXfer,
 			 void *clientData)
 {
@@ -812,21 +780,26 @@
 
   /* Allocate a buffer as necessary */
   if (!destBuf)
+  {
     destBuf = g_new (char, rows * cols * channelsPerEntry);
+  }
 
   /* Work through the rows */
   destPtr = destBuf;
-  for (row = 0; row < rows; row++) {
+  for (row = 0; row < rows; row++)
+  {
     srcPtr = (char *) ((char *) imageMemXfer->Memory.TheMem +
 		       (row * imageMemXfer->BytesPerRow));
 
     /* Work through the columns */
-    for (col = 0; col < cols; col++) {
+    for (col = 0; col < cols; col++)
+    {
       /* Get the palette index */
       int index = (unsigned char) *srcPtr;
       srcPtr++;
 
-      switch (theClientData->paletteData->PaletteType) {
+      switch (theClientData->paletteData->PaletteType)
+      {
       case TWPA_GRAY:
 	*destPtr = theClientData->paletteData->Colors[index].Channel1;
 	destPtr++;
@@ -868,26 +841,24 @@
 		     pTW_IMAGEMEMXFER imageMemXfer,
 		     void *clientData)
 {
-#ifdef _DEBUG
-  logData(imageInfo, imageMemXfer, clientData);
-#endif
-
   /* Choose the appropriate transfer handler */
-  switch (imageInfo->PixelType) {
+  switch (imageInfo->PixelType)
+  {
   case TWPT_PALETTE:
-    return palettedTransferCallback(imageInfo, imageMemXfer, clientData);
+      return palettedTransferCallback (imageInfo, imageMemXfer, clientData);
 
   case TWPT_BW:
-    return bitTransferCallback(imageInfo, imageMemXfer, clientData);
+      return bitTransferCallback (imageInfo, imageMemXfer, clientData);
 
   case TWPT_GRAY:
   case TWPT_RGB:
-    switch (imageInfo->BitsPerPixel / imageInfo->SamplesPerPixel) {
+      switch (imageInfo->BitsPerPixel / imageInfo->SamplesPerPixel)
+      {
     case 8:
-      return oneBytePerSampleTransferCallback(imageInfo, imageMemXfer, clientData);
+          return oneBytePerSampleTransferCallback (imageInfo, imageMemXfer, clientData);
 
     case 16:
-      return twoBytesPerSampleTransferCallback(imageInfo, imageMemXfer, clientData);
+          return twoBytesPerSampleTransferCallback (imageInfo, imageMemXfer, clientData);
 
     default:
       return FALSE;
@@ -901,51 +872,43 @@
 /*
  * endTransferCallback
  *
- * The following function is called at the end of the
- * image transfer.  The caller will be handed
- * the image transfer completion state.  The
- * following values (defined in twain.h) are
- * possible:
- *
- * TWRC_XFERDONE
- *  The transfer completed successfully
- * TWRC_CANCEL
- *  The transfer was completed by the user
- * TWRC_FAILURE
- *  The transfer failed.
+ * The following function is called at the end of the image transfer.
+ * The caller will be handed the image transfer completion state.
+ * The following values (defined in twain.h) are possible:
+ *
+ * TWRC_XFERDONE: Transfer completed successfully.
+ * TWRC_CANCEL:   Transfer cancled by user.
+ * TWRC_FAILURE:  Transfer failed.
  */
 int
-endTransferCallback(int completionState, int pendingCount, void *clientData)
+endTransferCallback (int completionState, int pendingCount, void *clientData)
 {
   pClientDataStruct theClientData = (pClientDataStruct) clientData;
 
-  LogMessage("endTransferCallback: CompState = %d, pending = %d\n",
-	     completionState, pendingCount);
-
   /* Clean up and detach from the drawable */
-  if (destBuf) {
+  if (destBuf)
+  {
     g_free (destBuf);
     destBuf = NULL;
   }
-  gimp_drawable_flush(theClientData->drawable);
-  gimp_drawable_detach(theClientData->drawable);
+  gimp_drawable_flush (theClientData->drawable);
+  gimp_drawable_detach (theClientData->drawable);
 
   /* Make sure to check our return code */
-  if (completionState == TWRC_XFERDONE) {
-    /* We have a completed image transfer */
-    values[2].type = GIMP_PDB_INT32ARRAY;
-    values[2].data.d_int32array[values[1].data.d_int32++] =
-      theClientData->image_id;
-
+  if (completionState == TWRC_XFERDONE)
+  {
+    images = g_list_prepend (images, GINT_TO_POINTER (theClientData->image_id));
     /* Display the image */
-    LogMessage("Displaying image %d\n", theClientData->image_id);
     gimp_display_new (theClientData->image_id);
-  } else {
+  }
+  else
+  {
     /* The transfer did not complete successfully */
-    LogMessage("Deleting image\n");
-    gimp_image_delete(theClientData->image_id);
+    gimp_image_delete (theClientData->image_id);
   }
 
+  gimp_displays_flush ();
+
   /* Shut down if we have received all of the possible images */
   return (values[1].data.d_int32 < MAX_IMAGES);
 }
@@ -958,20 +921,22 @@
  * transferred.
  */
 void
-postTransferCallback(int pendingCount, void *clientData)
+postTransferCallback (int pendingCount, void *clientData)
 {
   /* Shut things down. */
   if (pendingCount != 0)
+  {
     cancelPendingTransfers(twSession);
+  }
 
   /* This will close the datasource and datasource
    * manager.  Then the message queue will be shut
    * down and the run() procedure will finally be
    * able to finish.
    */
-  disableDS(twSession);
-  closeDS(twSession);
-  closeDSM(twSession);
+  disableDS (twSession);
+  closeDS (twSession);
+  closeDSM (twSession);
 
   /* Post a message to close up the application */
   twainQuitApplication ();
Only in /usr/src/gimp-2.7.3/plug-ins/twain: twain.exe
diff -rub /usr/src/git/gimp/plug-ins/twain/twain.h /usr/src/gimp-2.7.3/plug-ins/twain/twain.h
--- /usr/src/git/gimp/plug-ins/twain/twain.h	2011-12-17 16:24:18 +0000
+++ /usr/src/gimp-2.7.3/plug-ins/twain/twain.h	2011-12-13 16:54:11 +0000
@@ -1,5 +1,10 @@
 /* ======================================================================== *\
 
+  Copyright (C) 2007 TWAIN Working Group: Adobe Systems Incorporated,
+  AnyDoc Software Inc., Eastman Kodak Company, Fujitsu Computer Products
+  of America, JFL Peripheral Solutions Inc., Ricoh Corporation, and
+  Xerox Corporation.  All rights reserved.
+
   Copyright (C) 1991, 1992 TWAIN Working Group: Aldus, Caere, Eastman-Kodak,
   Hewlett-Packard and Logitech Corporations.  All rights reserved.
 
@@ -14,6 +19,13 @@
 	JFL Peripheral Solutions Inc., Ricoh Corporation, and Xerox Corporation.
 	All rights reserved.
 
+  Copyright © 2000 TWAIN Working Group: Adobe Systems Incorporated,
+  Canon Information Systems, Digimarc Corporation, Eastman Kodak Company,
+  Fujitsu Computer Products of America, Hewlett-Packard Company,
+  JFL Peripheral Solutions Inc., Ricoh Corporation, and Xerox Corporation.
+  All rights reserved.
+
+
   TWAIN.h -  This is the definitive include file for applications and
           data sources written to the TWAIN specification.
           It defines constants, data structures, messages etc.
@@ -44,66 +56,141 @@
                                  TWBCOR_ types JMH
     version 1.8  August 1998     Added new types and definitions required
                                  for 1.8 Specification JMH
+    version 1.8  January 1999    Changed search mode from SRCH_ to TWBD_ as
+                                 in 1.8 Specification, added TWBT_MAXICODE JMH
+    version 1.8  January 1999    Removed undocumented duplicate AUTO<cap> JMH
+    version 1.8  March 1999      Removed undocumented 1.8 caps:
+                                 CAP_FILESYSTEM
+                                 CAP_PAPERBINDING
+                                 CAP_PASSTHRU
+                                 CAP_POWERDOWNTIME
+                                 ICAP_AUTODISCARDBLANKPAGES
+                               * CAP_PAGEMULTIPLEACQUIRE - is CAP_REACQUIREALLOWED,
+                               requires spec change.  JMH
+                                 Added Mac structure packing modifications JMH
+    version 1.9  March 2000  Added new types and definations required
+                             for 1.9 Specification MLM
+    version 1.9  March 2000  Added ICAP_JPEGQUALITY, TWJQ_ values,
+                                 updated TWON_PROTOCOLMINOR for Release v1.9 MN
+    version 1.91 August 2007     Added new types and definitions required
+                                 for 1.91 Specification MLM
+    version 2.0  Sept 2007       Added new types and definitions required
+                                 for 2.0 Specification FHH
+    version 2.0  Mar 2008        Depreciated ICAP_PIXELTYPEs TWPT_SRGB64, TWPT_BGR,
+                                 TWPT_CIELAB, TWPT_CIELUV, and TWPT_YCBCR  JMW
+    version 2.0  Mar 2008        Added missing new 2.0 CAP_ definitions JMW
+    version 2.0  Dec 2008        Updated TW_INFO structure for 64bit JMW
+    version 2.1  Mar 2009        Added new types and definitions required
+                                 for 2.1 Specification JMW
 \* ======================================================================== */
 
 #ifndef TWAIN
 #define TWAIN
 
-/*  SDH - 02/08/95 - TWUNK */
-/*  Force 32-bit twain to use same packing of twain structures as existing */
-/*  16-bit twain.  This allows 16/32-bit thunking.                         */
-#ifdef  WIN32
-    #ifdef __BORLANDC__ /* (Mentor June 13, 1996) if using a Borland compiler */
-        #pragma option -a2  /*(Mentor June 13, 1996) switch to word alignment*/
-    #else   /*(Mentor June 13, 1996) if we're using some other compiler*/
-        #pragma pack (push, before_twain)
-        #pragma pack (2)
-    #endif  /*(Mentor June 13, 1996)*/
-#else   /* WIN32 */
-#endif  /* WIN32 */
-
 /****************************************************************************
  * TWAIN Version                                                            *
  ****************************************************************************/
-#define TWON_PROTOCOLMINOR   8        /* Changed for Version 1.8            */
-#define TWON_PROTOCOLMAJOR   1
+#define TWON_PROTOCOLMINOR   1        /* Changed for Version 2.1            */
+#define TWON_PROTOCOLMAJOR   2
 
 /****************************************************************************
  * Platform Dependent Definitions and Typedefs                              *
  ****************************************************************************/
 
-/* Define one of the following, depending on the platform */
-/* #define _MAC_   */
-/* #define _UNIX_  */
-#define _MSWIN_
+/* Microsoft C/C++ Compiler */
+#if defined(WIN32) || defined(WIN64) || defined (_WINDOWS)
+    #define TWH_CMP_MSC
+    #if  defined(_WIN64) || defined(WIN64)
+      #define TWH_64BIT
+    #elif defined(WIN32) || defined(_WIN32)
+      #define TWH_32BIT
+    #endif
+
+/* Apple Compiler (which is GNU now) */
+#elif defined(__APPLE__)
+    #define TWH_CMP_XCODE
+    #define TWH_32BIT
+
+/* GNU C/C++ Compiler */
+#elif defined(__GNUC__)
+    #define TWH_CMP_GNU
+    #if defined(__alpha__)\
+        ||defined(__ia64__)\
+        ||defined(__ppc64__)\
+        ||defined(__s390x__)\
+        ||defined(__x86_64__)
+      #define TWH_64BIT
+    #else
+      #define TWH_32BIT
+    #endif
+
+/* Borland C/C++ Compiler */
+#elif defined(__BORLAND__)
+    #define TWH_CMP_BORLAND
+    #define TWH_32BIT
+/* Unrecognized */
+#else
+    #error Unrecognized compiler
+#endif
 
-#ifdef  _MSWIN_
+/* Win32 and Win64 systems */
+#if defined(TWH_CMP_MSC) | defined(TWH_CMP_BORLAND)
     typedef HANDLE         TW_HANDLE;
     typedef LPVOID         TW_MEMREF;
+    typedef UINT_PTR TW_UINTPTR;
 
-    /*  SDH - 05/05/95 - TWUNK */
-    /*  For common code between 16 and 32 bits.  */
-    #ifdef  WIN32
-        #define TW_HUGE
-    #else   /* WIN32 */
-        #define TW_HUGE    huge
-    #endif  /* WIN32 */
-    typedef BYTE TW_HUGE * HPBYTE;
-    typedef void TW_HUGE * HPVOID;
-#endif  /* _MSWIN_ */
-
-#ifdef  _MAC_
+/* MacOS/X... */
+#elif defined(TWH_CMP_XCODE)
     #define PASCAL         pascal
     #define FAR
     typedef Handle         TW_HANDLE;
     typedef char          *TW_MEMREF;
-#endif  /* _MAC_ */
 
-#ifdef  _UNIX_
-    #define PASCAL         pascal
-    typedef unsigned char *TW_HANDLE;
-    typedef unsigned char *TW_MEMREF;
-#endif  /* _UNIX_ */
+    #ifdef TWH_32BIT
+      //32 bit GNU
+      typedef unsigned long      TW_UINTPTR;
+    #else
+      //64 bit GNU
+      typedef unsigned long long TW_UINTPTR;
+    #endif
+
+/* Everything else... */
+#else
+    #define PASCAL
+    #define FAR
+    typedef void* TW_HANDLE;
+    typedef void* TW_MEMREF;
+    typedef unsigned char BYTE;
+
+    #ifdef TWH_32BIT
+      //32 bit GNU
+      typedef unsigned long      TW_UINTPTR;
+    #else
+      //64 bit GNU
+      typedef unsigned long long TW_UINTPTR;
+    #endif
+#endif
+
+
+/* Set the packing: this occurs before any structures are defined */
+#ifdef TWH_CMP_MSC
+    #pragma pack (push, before_twain)
+    #pragma pack (2)
+#elif defined(TWH_CMP_GNU)
+    #pragma pack (push, before_twain)
+    #pragma pack (2)
+#elif defined(TWH_CMP_BORLAND)
+    #pragma option -a2
+#elif defined(TWH_CMP_XCODE)
+    #if PRAGMA_STRUCT_ALIGN
+        #pragma options align=mac68k
+    #elif PRAGMA_STRUCT_PACKPUSH
+        #pragma pack (push, 2)
+    #elif PRAGMA_STRUCT_PACK
+        #pragma pack (2)
+    #endif
+#endif
+
 
 /****************************************************************************
  * Type Definitions                                                         *
@@ -126,22 +213,24 @@
 typedef unsigned long  TW_UINT32, FAR *pTW_UINT32;
 typedef unsigned short TW_BOOL,   FAR *pTW_BOOL;
 
+
+/****************************************************************************
+ * Structure Definitions                                                    *
+ ****************************************************************************/
+
 /* Fixed point structure type. */
 typedef struct {
     TW_INT16     Whole;        /* maintains the sign */
     TW_UINT16    Frac;
 } TW_FIX32,  FAR *pTW_FIX32;
 
-/****************************************************************************
- * Structure Definitions                                                    *
- ****************************************************************************/
-
-/* No DAT needed. */
+/* No DAT.  Defines a frame rectangle in ICAP_UNITS coordinates. */
 typedef struct {
-   TW_FIX32   X;
-   TW_FIX32   Y;
-   TW_FIX32   Z;
-} TW_CIEPOINT, FAR * pTW_CIEPOINT;
+   TW_FIX32   Left;
+   TW_FIX32   Top;
+   TW_FIX32   Right;
+   TW_FIX32   Bottom;
+} TW_FRAME, FAR * pTW_FRAME;
 
 /* No DAT needed. */
 typedef struct {
@@ -157,42 +246,10 @@
 
 /* No DAT needed. */
 typedef struct {
-   TW_UINT8    Index;    /* Value used to index into the color table. */
-   TW_UINT8    Channel1; /* First  tri-stimulus value (e.g Red)       */
-   TW_UINT8    Channel2; /* Second tri-stimulus value (e.g Green)     */
-   TW_UINT8    Channel3; /* Third  tri-stimulus value (e.g Blue)      */
-} TW_ELEMENT8, FAR * pTW_ELEMENT8;
-
-/* No DAT.  Defines a frame rectangle in ICAP_UNITS coordinates. */
-typedef struct {
-   TW_FIX32   Left;
-   TW_FIX32   Top;
-   TW_FIX32   Right;
-   TW_FIX32   Bottom;
-} TW_FRAME, FAR * pTW_FRAME;
-
-/* No DAT needed.  Used to manage memory buffers. */
-typedef struct {
-   TW_UINT32  Flags;  /* Any combination of the TWMF_ constants.           */
-   TW_UINT32  Length; /* Number of bytes stored in buffer TheMem.          */
-   TW_MEMREF  TheMem; /* Pointer or handle to the allocated memory buffer. */
-} TW_MEMORY, FAR * pTW_MEMORY;
-
-/* No DAT needed. */
-typedef struct {
    TW_DECODEFUNCTION   Decode[3];
    TW_FIX32            Mix[3][3];
 } TW_TRANSFORMSTAGE, FAR * pTW_TRANSFORMSTAGE;
 
-/* No DAT needed.  Describes version of software currently running. */
-typedef struct {
-   TW_UINT16  MajorNum;  /* Major revision number of the software. */
-   TW_UINT16  MinorNum;  /* Incremental revision number of the software. */
-   TW_UINT16  Language;  /* e.g. TWLG_SWISSFRENCH */
-   TW_UINT16  Country;   /* e.g. TWCY_SWITZERLAND */
-   TW_STR32   Info;      /* e.g. "1.0b3 Beta release" */
-} TW_VERSION, FAR * pTW_VERSION;
-
 /* TWON_ARRAY. Container for array of values (a simplified TW_ENUMERATION) */
 typedef struct {
    TW_UINT16  ItemType;
@@ -200,30 +257,18 @@
    TW_UINT8   ItemList[1]; /* Array of ItemType values starts here */
 } TW_ARRAY, FAR * pTW_ARRAY;
 
-/* TWON_ENUMERATION. Container for a collection of values. */
-typedef struct {
-   TW_UINT16  ItemType;
-   TW_UINT32  NumItems;     /* How many items in ItemList                 */
-   TW_UINT32  CurrentIndex; /* Current value is in ItemList[CurrentIndex] */
-   TW_UINT32  DefaultIndex; /* Powerup value is in ItemList[DefaultIndex] */
-   TW_UINT8   ItemList[1];  /* Array of ItemType values starts here       */
-} TW_ENUMERATION, FAR * pTW_ENUMERATION;
-
-/* TWON_ONEVALUE. Container for one value. */
+/* DAT_AUDIOINFO, information about audio data */
 typedef struct {
-   TW_UINT16  ItemType;
-   TW_UINT32  Item;
-} TW_ONEVALUE, FAR * pTW_ONEVALUE;
+   TW_STR255  Name;       /* name of audio data */
+   TW_UINT32  Reserved;   /* reserved space */
+} TW_AUDIOINFO, FAR * pTW_AUDIOINFO;
 
-/* TWON_RANGE. Container for a range of values. */
+/* TW_CALLBACK, used to register callbacks Added 2.0 */
 typedef struct {
-   TW_UINT16  ItemType;
-   TW_UINT32  MinValue;     /* Starting value in the range.           */
-   TW_UINT32  MaxValue;     /* Final value in the range.              */
-   TW_UINT32  StepSize;     /* Increment from MinValue to MaxValue.   */
-   TW_UINT32  DefaultValue; /* Power-up value.                        */
-   TW_UINT32  CurrentValue; /* The value that is currently in effect. */
-} TW_RANGE, FAR * pTW_RANGE;
+    TW_MEMREF   CallBackProc;
+    TW_UINT32   RefCon;
+    TW_INT16    Message;
+} TW_CALLBACK, FAR * pTW_CALLBACK;
 
 /* DAT_CAPABILITY. Used by application to get/set capability from/in a data source. */
 typedef struct {
@@ -232,6 +277,13 @@
    TW_HANDLE  hContainer; /* Handle to container of type Dat              */
 } TW_CAPABILITY, FAR * pTW_CAPABILITY;
 
+/* No DAT needed. */
+typedef struct {
+   TW_FIX32   X;
+   TW_FIX32   Y;
+   TW_FIX32   Z;
+} TW_CIEPOINT, FAR * pTW_CIEPOINT;
+
 /* DAT_CIECOLOR. */
 typedef struct {
    TW_UINT16           ColorSpace;
@@ -247,17 +299,100 @@
    TW_FIX32            Samples[1];
 } TW_CIECOLOR, FAR * pTW_CIECOLOR;
 
+typedef struct {
+    TW_UINT32  InfoLength;     /* Length of Information in bytes.  */
+    TW_HANDLE  hData;          /* Place holder for data, DS Allocates */
+}TW_CUSTOMDSDATA, FAR *pTW_CUSTOMDSDATA;
+
+/* DAT_DEVICEEVENT, information about events */
+typedef struct {
+   TW_UINT32  Event;                  /* One of the TWDE_xxxx values. */
+   TW_STR255  DeviceName;             /* The name of the device that generated the event */
+   TW_UINT32  BatteryMinutes;         /* Battery Minutes Remaining    */
+   TW_INT16   BatteryPercentage;      /* Battery Percentage Remaining */
+   TW_INT32   PowerSupply;            /* Power Supply                 */
+   TW_FIX32   XResolution;            /* Resolution                   */
+   TW_FIX32   YResolution;            /* Resolution                   */
+   TW_UINT32  FlashUsed2;             /* Flash Used2                  */
+   TW_UINT32  AutomaticCapture;       /* Automatic Capture            */
+   TW_UINT32  TimeBeforeFirstCapture; /* Automatic Capture            */
+   TW_UINT32  TimeBetweenCaptures;    /* Automatic Capture            */
+} TW_DEVICEEVENT, FAR * pTW_DEVICEEVENT;
+
+/* No DAT needed. */
+typedef struct {
+   TW_UINT8    Index;    /* Value used to index into the color table. */
+   TW_UINT8    Channel1; /* First  tri-stimulus value (e.g Red)       */
+   TW_UINT8    Channel2; /* Second tri-stimulus value (e.g Green)     */
+   TW_UINT8    Channel3; /* Third  tri-stimulus value (e.g Blue)      */
+} TW_ELEMENT8, FAR * pTW_ELEMENT8;
+
+/* TWON_ENUMERATION. Container for a collection of values. */
+typedef struct {
+   TW_UINT16  ItemType;
+   TW_UINT32  NumItems;     /* How many items in ItemList                 */
+   TW_UINT32  CurrentIndex; /* Current value is in ItemList[CurrentIndex] */
+   TW_UINT32  DefaultIndex; /* Powerup value is in ItemList[DefaultIndex] */
+   TW_UINT8   ItemList[1];  /* Array of ItemType values starts here       */
+} TW_ENUMERATION, FAR * pTW_ENUMERATION;
+
 /* DAT_EVENT. For passing events down from the application to the DS. */
 typedef struct {
    TW_MEMREF  pEvent;    /* Windows pMSG or Mac pEvent.                 */
    TW_UINT16  TWMessage; /* TW msg from data source, e.g. MSG_XFERREADY */
 } TW_EVENT, FAR * pTW_EVENT;
 
+typedef struct {
+    TW_UINT16   InfoID;
+    TW_UINT16   ItemType;
+    TW_UINT16   NumItems;
+    union {
+      TW_UINT16   CondCode;    /* Depreciated, use ReturnCode. TWAIN 2.0 and older. */
+      TW_UINT16   ReturnCode;  /* TWAIN 2.1 and newer */
+    };
+    TW_UINTPTR  Item;
+}TW_INFO, FAR* pTW_INFO;
+
+typedef struct {
+    TW_UINT32   NumInfos;
+    TW_INFO     Info[1];
+}TW_EXTIMAGEINFO, FAR* pTW_EXTIMAGEINFO;
+
+/* DAT_FILESYSTEM, information about TWAIN file system */
+typedef struct {
+   /* DG_CONTROL / DAT_FILESYSTEM / MSG_xxxx fields     */
+   TW_STR255  InputName; /* The name of the input or source file */
+   TW_STR255  OutputName; /* The result of an operation or the name of a destination file */
+   TW_MEMREF  Context; /* Source specific data used to remember state information */
+   /* DG_CONTROL / DAT_FILESYSTEM / MSG_DELETE field    */
+   int        Recursive; /* recursively delete all sub-directories */
+   /* DG_CONTROL / DAT_FILESYSTEM / MSG_GETINFO fields  */
+   TW_INT32   FileType; /* One of the TWFY_xxxx values */
+   TW_UINT32  Size; /* Size of current FileType */
+   TW_STR32   CreateTimeDate; /* creation date of the file */
+   TW_STR32   ModifiedTimeDate; /* last date the file was modified */
+   TW_UINT32  FreeSpace; /* bytes of free space on the current device */
+   TW_INT32   NewImageSize; /* estimate of the amount of space a new image would take up */
+   TW_UINT32  NumberOfFiles; /* number of files, depends on FileType */
+   TW_UINT32  NumberOfSnippets; /* number of audio snippets */
+   TW_UINT32  DeviceGroupMask; /* used to group cameras (ex: front/rear bitonal, front/rear grayscale...) */
+   char       Reserved[508]; /**/
+} TW_FILESYSTEM, FAR * pTW_FILESYSTEM;
+
 /* DAT_GRAYRESPONSE */
 typedef struct {
    TW_ELEMENT8         Response[1];
 } TW_GRAYRESPONSE, FAR * pTW_GRAYRESPONSE;
 
+/* No DAT needed.  Describes version of software currently running. */
+typedef struct {
+   TW_UINT16  MajorNum;  /* Major revision number of the software. */
+   TW_UINT16  MinorNum;  /* Incremental revision number of the software. */
+   TW_UINT16  Language;  /* e.g. TWLG_SWISSFRENCH */
+   TW_UINT16  Country;   /* e.g. TWCY_SWITZERLAND */
+   TW_STR32   Info;      /* e.g. "1.0b3 Beta release" */
+} TW_VERSION, FAR * pTW_VERSION;
+
 /* DAT_IDENTITY. Identifies the program/library/code resource. */
 typedef struct {
    TW_UINT32  Id;              /* Unique number.  In Windows, application hWnd      */
@@ -292,6 +427,13 @@
    TW_UINT32  FrameNumber;    /* Reset when you go to next page      */
 } TW_IMAGELAYOUT, FAR * pTW_IMAGELAYOUT;
 
+/* No DAT needed.  Used to manage memory buffers. */
+typedef struct {
+   TW_UINT32  Flags;  /* Any combination of the TWMF_ constants.           */
+   TW_UINT32  Length; /* Number of bytes stored in buffer TheMem.          */
+   TW_MEMREF  TheMem; /* Pointer or handle to the allocated memory buffer. */
+} TW_MEMORY, FAR * pTW_MEMORY;
+
 /* DAT_IMAGEMEMXFER. Used to pass image data (e.g. in strips) from DS to application.*/
 typedef struct {
    TW_UINT16  Compression;  /* How the data is compressed                */
@@ -318,6 +460,12 @@
    TW_MEMORY   HuffmanAC[2];     /* AC Huffman tables                          */
 } TW_JPEGCOMPRESSION, FAR * pTW_JPEGCOMPRESSION;
 
+/* TWON_ONEVALUE. Container for one value. */
+typedef struct {
+   TW_UINT16  ItemType;
+   TW_UINT32  Item;
+} TW_ONEVALUE, FAR * pTW_ONEVALUE;
+
 /* DAT_PALETTE8. Color palette when TWPT_PALETTE pixels xfer'd in mem buf. */
 typedef struct {
    TW_UINT16    NumColors;   /* Number of colors in the color table.  */
@@ -325,6 +473,16 @@
    TW_ELEMENT8  Colors[256]; /* Array of palette values starts here.  */
 } TW_PALETTE8, FAR * pTW_PALETTE8;
 
+/* DAT_PASSTHRU, device dependant data to pass through Data Source */
+typedef struct {
+   TW_MEMREF  pCommand;        /* Pointer to Command buffer */
+   TW_UINT32  CommandBytes;    /* Number of bytes in Command buffer */
+   TW_INT32   Direction;       /* One of the TWDR_xxxx values.  Defines the direction of data flow */
+   TW_MEMREF  pData;           /* Pointer to Data buffer */
+   TW_UINT32  DataBytes;       /* Number of bytes in Data buffer */
+   TW_UINT32  DataBytesXfered; /* Number of bytes successfully transferred */
+} TW_PASSTHRU, FAR * pTW_PASSTHRU;
+
 /* DAT_PENDINGXFERS. Used with MSG_ENDXFER to indicate additional data. */
 typedef struct {
    TW_UINT16 Count;
@@ -334,6 +492,16 @@
    };
 } TW_PENDINGXFERS, FAR *pTW_PENDINGXFERS;
 
+/* TWON_RANGE. Container for a range of values. */
+typedef struct {
+   TW_UINT16  ItemType;
+   TW_UINT32  MinValue;     /* Starting value in the range.           */
+   TW_UINT32  MaxValue;     /* Final value in the range.              */
+   TW_UINT32  StepSize;     /* Increment from MinValue to MaxValue.   */
+   TW_UINT32  DefaultValue; /* Power-up value.                        */
+   TW_UINT32  CurrentValue; /* The value that is currently in effect. */
+} TW_RANGE, FAR * pTW_RANGE;
+
 /* DAT_RGBRESPONSE */
 typedef struct {
    TW_ELEMENT8         Response[1];
@@ -356,9 +524,19 @@
 /* DAT_STATUS. Application gets detailed status info from a data source with this. */
 typedef struct {
    TW_UINT16  ConditionCode; /* Any TWCC_ constant     */
-   TW_UINT16  Reserved;      /* Future expansion space */
+   union {
+     TW_UINT16  Data;         /* output (TWAIN 2.1 and newer) This field contains additional data. */
+     TW_UINT16  Reserved;     /* output (TWAIN 2.0 and older) */
+   };
 } TW_STATUS, FAR * pTW_STATUS;
 
+/* DAT_STATUSUTF8. Application gets detailed UTF8 status info from a data source with this.  Added 2.1 */
+typedef struct {
+   TW_STATUS    Status;         /* input  TW_STATUS data received from a previous call to DG_CONTROL / DAT_STATUS / MSG_GET. */
+   TW_UINT32    Size;           /* output Total number of bytes in the UTF8string, plus the terminating NUL byte.  This is not the same as the total number of characters in the string. */
+   TW_HANDLE    UTF8string;     /* output TW_HANDLE to a UTF-8 encoded localized string (based on TW_IDENTITY.Language or CAP_LANGUAGE).  The Source allocates it, the Application frees it. */
+} TW_STATUSUTF8, FAR * pTW_STATUSUTF8;
+
 /* DAT_USERINTERFACE. Coordinates UI between application and data source. */
 typedef struct {
    TW_BOOL    ShowUI;  /* TRUE if DS should bring up its UI           */
@@ -366,145 +544,11 @@
    TW_HANDLE  hParent; /* For windows only - Application window handle        */
 } TW_USERINTERFACE, FAR * pTW_USERINTERFACE;
 
-/* SDH - 03/21/95 - TWUNK */
-/* DAT_TWUNKIDENTITY. Provides DS identity and 'other' information necessary */
-/*                    across thunk link. */
-typedef struct {
-   TW_IDENTITY identity;        /* Identity of data source.                 */
-   TW_STR255   dsPath;          /* Full path and file name of data source.  */
-} TW_TWUNKIDENTITY, FAR * pTW_TWUNKIDENTITY;
 
-/* SDH - 03/21/95 - TWUNK */
-/* Provides DS_Entry parameters over thunk link. */
-typedef struct
-{
-    TW_INT8     destFlag;       /* TRUE if dest is not NULL                 */
-    TW_IDENTITY dest;           /* Identity of data source (if used)        */
-    TW_INT32    dataGroup;      /* DSM_Entry dataGroup parameter            */
-    TW_INT16    dataArgType;    /* DSM_Entry dataArgType parameter          */
-    TW_INT16    message;        /* DSM_Entry message parameter              */
-    TW_INT32    pDataSize;      /* Size of pData (0 if NULL)                */
-    /*  TW_MEMREF   pData;         Based on implementation specifics, a     */
-                                /* pData parameter makes no sense in this   */
-                                /* structure, but data (if provided) will be*/
-                                /* appended in the data block.              */
-   } TW_TWUNKDSENTRYPARAMS, FAR * pTW_TWUNKDSENTRYPARAMS;
 
-/* SDH - 03/21/95 - TWUNK */
-/* Provides DS_Entry results over thunk link. */
-typedef struct
-{
-    TW_UINT16   returnCode;     /* Thunker DsEntry return code.             */
-    TW_UINT16   conditionCode;  /* Thunker DsEntry condition code.          */
-    TW_INT32    pDataSize;      /* Size of pData (0 if NULL)                */
-    /*  TW_MEMREF   pData;         Based on implementation specifics, a     */
-                                /* pData parameter makes no sense in this   */
-                                /* structure, but data (if provided) will be*/
-                                /* appended in the data block.              */
-} TW_TWUNKDSENTRYRETURN, FAR * pTW_TWUNKDSENTRYRETURN;
-
-/* WJD - 950818 */
-/* Added for 1.6 Specification */
-/* TWAIN 1.6 CAP_SUPPORTEDCAPSEXT structure */
-typedef struct
-{
-    TW_UINT16 Cap;   /* Which CAP/ICAP info is relevant to */
-    TW_UINT16 Properties;  /* Messages this CAP/ICAP supports */
-} TW_CAPEXT, FAR * pTW_CAPEXT;
-
-/* ----------------------------------------------------------------------- *\
-
-  Version 1.7:      Added Following data structure for Document Imaging
-  July 1997         Enhancement.
-  KHL               TW_CUSTOMDSDATA --  For Saving and Restoring Source's
-                                        state.
-                    TW_INFO         --  Each attribute for extended image
-                                        information.
-                    TW_EXTIMAGEINFO --  Extended image information structure.
-
-\* ----------------------------------------------------------------------- */
-
-typedef struct {
-    TW_UINT32  InfoLength;     /* Length of Information in bytes.  */
-    TW_HANDLE  hData;          /* Place holder for data, DS Allocates */
-}TW_CUSTOMDSDATA, FAR *pTW_CUSTOMDSDATA;
-
-typedef struct {
-    TW_UINT16   InfoID;
-    TW_UINT16   ItemType;
-    TW_UINT16   NumItems;
-    TW_UINT16   CondCode;
-    TW_UINT32   Item;
-}TW_INFO, FAR* pTW_INFO;
-
-typedef struct {
-    TW_UINT32   NumInfos;
-    TW_INFO     Info[1];
-}TW_EXTIMAGEINFO, FAR* pTW_EXTIMAGEINFO;
-
-/* Added 1.8 */
-
-/* DAT_AUDIOINFO, information about audio data */
-typedef struct {
-   TW_STR255	Name;       /* name of audio data */
-   TW_UINT32	Reserved;   /* reserved space */
-} TW_AUDIOINFO, FAR * pTW_AUDIOINFO;
-
-/* DAT_DEVICEEVENT, information about events */
-typedef struct {
-   TW_UINT32  Event;                  /* One of the TWDE_xxxx values. */
-   TW_STR255  DeviceName;             /* The name of the device that generated the event */
-   TW_UINT32  BatteryMinutes;         /* Battery Minutes Remaining    */
-   TW_INT16   BatteryPercentage;      /* Battery Percentage Remaining */
-   TW_INT32   PowerSupply;            /* Power Supply                 */
-   TW_FIX32   XResolution;            /* Resolution                   */
-   TW_FIX32   YResolution;            /* Resolution                   */
-   TW_UINT32  FlashUsed2;             /* Flash Used2                  */
-   TW_UINT32  AutomaticCapture;       /* Automatic Capture            */
-   TW_UINT32  TimeBeforeFirstCapture; /* Automatic Capture            */
-   TW_UINT32  TimeBetweenCaptures;    /* Automatic Capture            */
-} TW_DEVICEEVENT, FAR * pTW_DEVICEEVENT;
-
-/* DAT_FILESYSTEM, information about TWAIN file system */
-typedef struct {
-   /* DG_CONTROL / DAT_FILESYSTEM / MSG_xxxx fields     */
-   TW_STR255  InputName; /* The name of the input or source file */
-   TW_STR255  OutputName; /* The result of an operation or the name of a destination file */
-   TW_MEMREF  Context; /* Source specific data used to remember state information */
-   /* DG_CONTROL / DAT_FILESYSTEM / MSG_DELETE field    */
-   int        Recursive; /* recursively delete all sub-directories */
-   /* DG_CONTROL / DAT_FILESYSTEM / MSG_GETINFO fields  */
-   TW_INT32   FileType; /* One of the TWFT_xxxx values */
-   TW_UINT32  Size; /* Size of current FileType */
-   TW_STR32   CreateTimeDate; /* creation date of the file */
-   TW_STR32   ModifiedTimeDate; /* last date the file was modified */
-   TW_UINT32  FreeSpace; /* bytes of free space on the current device */
-   TW_INT32   NewImageSize; /* estimate of the amount of space a new image would take up */
-   TW_UINT32  NumberOfFiles; /* number of files, depends on FileType */
-   TW_UINT32  NumberOfSnippets; /**/
-   char       Reserved[512]; /**/
-} TW_FILESYSTEM, FAR * pTW_FILESYSTEM;
-
-/* DAT_PASSTHRU, device dependant data to pass through Data Source */
-typedef struct {
-   TW_MEMREF  pCommand;        /* Pointer to Command buffer */
-   TW_UINT32  CommandBytes;    /* Number of bytes in Command buffer */
-   TW_INT32   Direction;       /* One of the TWDR_xxxx values.  Defines the direction of data flow */
-   TW_MEMREF  pData;           /* Pointer to Data buffer */
-   TW_UINT32  DataBytes;       /* Number of bytes in Data buffer */
-   TW_UINT32  DataBytesXfered; /* Number of bytes successfully transferred */
-} TW_PASSTHRU, FAR * pTW_PASSTHRU;
-
-/* DAT_SETUPAUDIOFILEXFER, information required to setup an audio file transfer */
-typedef struct {
-   TW_STR255	FileName; /* full path target file */
-   TW_UINT16	Format;   /* one of TWAF_xxxx */
-   TW_INT16	VRefNum;
-} TW_SETUPAUDIOFILEXFER, FAR * pTW_SETUPAUDIOFILEXFER;
-
-/****************************************************************************
- * Generic Constants                                                        *
- ****************************************************************************/
+/****************************************************************************
+ * Generic Constants                                                        *
+ ****************************************************************************/
 
 #define TWON_ARRAY           3 /* indicates TW_ARRAY container       */
 #define TWON_ENUMERATION     4 /* indicates TW_ENUMERATION container */
@@ -526,11 +570,6 @@
 #define TWMF_POINTER     0x8
 #define TWMF_HANDLE      0x10
 
-/* Palette types for TW_PALETTE8 */
-#define TWPA_RGB         0
-#define TWPA_GRAY        1
-#define TWPA_CMY         2
-
 /* There are four containers used for capabilities negotiation:
  *    TWON_ONEVALUE, TWON_RANGE, TWON_ENUMERATION, TWON_ARRAY
  * In each container structure ItemType can be TWTY_INT8, TWTY_INT16, etc.
@@ -561,15 +600,78 @@
 #define TWTY_STR64       0x000a    /* Means Item is a TW_STR64  */
 #define TWTY_STR128      0x000b    /* Means Item is a TW_STR128 */
 #define TWTY_STR255      0x000c    /* Means Item is a TW_STR255 */
+#define TWTY_HANDLE      0x000f    /* Means Item is a TW_HANDLE */
+
 
 /****************************************************************************
  * Capability Constants                                                     *
  ****************************************************************************/
 
+/* CAP_ALARMS values (AL_ means alarms) Added 1.8  */
+#define TWAL_ALARM               0
+#define TWAL_FEEDERERROR         1
+#define TWAL_FEEDERWARNING       2
+#define TWAL_BARCODE             3
+#define TWAL_DOUBLEFEED          4
+#define TWAL_JAM                 5
+#define TWAL_PATCHCODE           6
+#define TWAL_POWER               7
+#define TWAL_SKEW                8
+
+/* ICAP_AUTOSIZE values Added 2.0 */
+#define TWAS_NONE                0
+#define TWAS_AUTO                1
+#define TWAS_CURRENT             2
+
+/* TWEI_BARCODEROTATION values (BCOR_ means barcode rotation) Added 1.7 */
+#define TWBCOR_ROT0              0
+#define TWBCOR_ROT90             1
+#define TWBCOR_ROT180            2
+#define TWBCOR_ROT270            3
+#define TWBCOR_ROTX              4
+
+/* ICAP_BARCODESEARCHMODE values (TWBD_ means search) */
+#define TWBD_HORZ                0
+#define TWBD_VERT                1
+#define TWBD_HORZVERT            2
+#define TWBD_VERTHORZ            3
+
 /* ICAP_BITORDER values (BO_ means Bit Order) */
 #define TWBO_LSBFIRST    0
 #define TWBO_MSBFIRST    1
 
+/* ICAP_AUTODISCARDBLANKPAGES values Added 2.0 */
+#define TWBP_DISABLE            -2
+#define TWBP_AUTO               -1
+
+/* ICAP_BITDEPTHREDUCTION values (BR_ means Bitdepth Reduction) Added 1.5 */
+#define TWBR_THRESHOLD           0
+#define TWBR_HALFTONE            1
+#define TWBR_CUSTHALFTONE        2
+#define TWBR_DIFFUSION           3
+
+/* ICAP_SUPPORTEDBARCODETYPES and TWEI_BARCODETYPE values Added 1.7 */
+#define TWBT_3OF9                 0
+#define TWBT_2OF5INTERLEAVED      1
+#define TWBT_2OF5NONINTERLEAVED   2
+#define TWBT_CODE93               3
+#define TWBT_CODE128              4
+#define TWBT_UCC128               5
+#define TWBT_CODABAR              6
+#define TWBT_UPCA                 7
+#define TWBT_UPCE                 8
+#define TWBT_EAN8                 9
+#define TWBT_EAN13                10
+#define TWBT_POSTNET              11
+#define TWBT_PDF417               12
+#define TWBT_2OF5INDUSTRIAL       13 /* Added 1.8 */
+#define TWBT_2OF5MATRIX           14 /* Added 1.8 */
+#define TWBT_2OF5DATALOGIC        15 /* Added 1.8 */
+#define TWBT_2OF5IATA             16 /* Added 1.8 */
+#define TWBT_3OF9FULLASCII        17 /* Added 1.8 */
+#define TWBT_CODABARWITHSTARTSTOP 18 /* Added 1.8 */
+#define TWBT_MAXICODE             19 /* Added 1.8 */
+
 /* ICAP_COMPRESSION values (CP_ means ComPression ) */
 #define TWCP_NONE        0
 #define TWCP_PACKBITS    1
@@ -580,12 +682,65 @@
 #define TWCP_JPEG        6 /* Use capability for more info                 */
 #define TWCP_LZW         7 /* Must license from Unisys and IBM to use      */
 #define TWCP_JBIG        8 /* For Bitonal images  -- Added 1.7 KHL         */
-/* Added 1.8 */
-#define TWCP_PNG         9
-#define TWCP_RLE4        10
-#define TWCP_RLE8        11
-#define TWCP_BITFIELDS   12
+#define TWCP_PNG                 9 /* Added 1.8 */
+#define TWCP_RLE4               10 /* Added 1.8 */
+#define TWCP_RLE8               11 /* Added 1.8 */
+#define TWCP_BITFIELDS          12 /* Added 1.8 */
+
+/* CAP_CAMERASIDE and TWEI_PAGESIDE values (CS_ means camera side) Added 1.91 */
+#define TWCS_BOTH                0
+#define TWCS_TOP                 1
+#define TWCS_BOTTOM              2
+
+/* CAP_CLEARBUFFERS values (CB_ means clear buffers) */
+#define TWCB_AUTO                0
+#define TWCB_CLEAR               1
+#define TWCB_NOCLEAR             2
 
+/* CAP_DEVICEEVENT values (DE_ means device event) */
+#define TWDE_CUSTOMEVENTS           0x8000
+#define TWDE_CHECKAUTOMATICCAPTURE  0
+#define TWDE_CHECKBATTERY           1
+#define TWDE_CHECKDEVICEONLINE      2
+#define TWDE_CHECKFLASH             3
+#define TWDE_CHECKPOWERSUPPLY       4
+#define TWDE_CHECKRESOLUTION        5
+#define TWDE_DEVICEADDED            6
+#define TWDE_DEVICEOFFLINE          7
+#define TWDE_DEVICEREADY            8
+#define TWDE_DEVICEREMOVED          9
+#define TWDE_IMAGECAPTURED          10
+#define TWDE_IMAGEDELETED           11
+#define TWDE_PAPERDOUBLEFEED        12
+#define TWDE_PAPERJAM               13
+#define TWDE_LAMPFAILURE            14
+#define TWDE_POWERSAVE              15
+#define TWDE_POWERSAVENOTIFY        16
+
+/* TW_PASSTHRU.Direction values.  Added 1.8 */
+#define TWDR_GET                 1
+#define TWDR_SET                 2
+
+/* TWEI_DESKEWSTATUS values Added 1.7 */
+#define TWDSK_SUCCESS            0
+#define TWDSK_REPORTONLY         1
+#define TWDSK_FAIL               2
+#define TWDSK_DISABLED           3
+
+/* CAP_DUPLEX values Added 1.7 */
+#define TWDX_NONE                0
+#define TWDX_1PASSDUPLEX         1
+#define TWDX_2PASSDUPLEX         2
+
+/* CAP_FEEDERALIGNMENT values (FA_ means feeder alignment) */
+#define TWFA_NONE                0
+#define TWFA_LEFT                1
+#define TWFA_CENTER              2
+#define TWFA_RIGHT               3
+
+/* ICAP_FEEDERTYPE */
+#define TWFE_GENERAL             0
+#define TWFE_PHOTO               1
 
 /* ICAP_IMAGEFILEFORMAT values (FF_means File Format)   */
 #define TWFF_TIFF        0    /* Tagged Image File Format     */
@@ -598,7 +753,46 @@
 #define TWFF_PNG         7
 #define TWFF_SPIFF       8
 #define	TWFF_EXIF				 9
+#define TWFF_PDF                10    /* 1.91 NB: this is not PDF/A */
+#define TWFF_JP2                11    /* 1.91 */
+#define TWFF_JPX                13    /* 1.91 */
+#define TWFF_DEJAVU             14    /* 1.91 */
+#define TWFF_PDFA               15    /* 2.0 Adobe PDF/A, Version 1*/
+#define TWFF_PDFA2              16    /* 2.1 Adobe PDF/A, Version 2*/
+
+/* ICAP_FLASHUSED2 values (FL_ means flash) */
+#define TWFL_NONE                0
+#define TWFL_OFF                 1
+#define TWFL_ON                  2
+#define TWFL_AUTO                3
+#define TWFL_REDEYE              4
 
+/* CAP_FEEDERORDER values (FO_ means feeder order) */
+#define TWFO_FIRSTPAGEFIRST      0
+#define TWFO_LASTPAGEFIRST       1
+
+/* CAP_FEEDERPOCKET */
+#define TWFP_POCKETERROR         0
+#define TWFP_POCKET1             1
+#define TWFP_POCKET2             2
+#define TWFP_POCKET3             3
+#define TWFP_POCKET4             4
+#define TWFP_POCKET5             5
+#define TWFP_POCKET6             6
+#define TWFP_POCKET7             7
+#define TWFP_POCKET8             8
+#define TWFP_POCKET9             9
+#define TWFP_POCKET10           10
+#define TWFP_POCKET11           11
+#define TWFP_POCKET12           12
+#define TWFP_POCKET13           13
+#define TWFP_POCKET14           14
+#define TWFP_POCKET15           15
+#define TWFP_POCKET16           16
+
+/* ICAP_FLIPROTATION values (FR_ means flip rotation) */
+#define TWFR_BOOK                0
+#define TWFR_FANFOLD             1
 
 /* ICAP_FILTER values (FT_ means Filter Type) */
 #define TWFT_RED         0
@@ -611,6 +805,51 @@
 #define TWFT_YELLOW      7
 #define TWFT_BLACK       8
 
+/* TW_FILESYSTEM.FileType values (FY_ means file type) */
+#define TWFY_CAMERA              0
+#define TWFY_CAMERATOP           1
+#define TWFY_CAMERABOTTOM        2
+#define TWFY_CAMERAPREVIEW       3
+#define TWFY_DOMAIN              4
+#define TWFY_HOST                5
+#define TWFY_DIRECTORY           6
+#define TWFY_IMAGE               7
+#define TWFY_UNKNOWN             8
+
+/* ICAP_ICCPROFILE */
+#define TWIC_NONE                0
+#define TWIC_LINK                1
+#define TWIC_EMBED               2
+
+/* ICAP_IMAGEFILTER values (IF_ means image filter) */
+#define TWIF_NONE                0
+#define TWIF_AUTO                1
+#define TWIF_LOWPASS             2
+#define TWIF_BANDPASS            3
+#define TWIF_HIGHPASS            4
+#define TWIF_TEXT                TWIF_BANDPASS
+#define TWIF_FINELINE            TWIF_HIGHPASS
+
+/* ICAP_IMAGEMERGE values (IM_ means image merge) */
+#define TWIM_NONE                0
+#define TWIM_FRONTONTOP          1
+#define TWIM_FRONTONBOTTOM       2
+#define TWIM_FRONTONLEFT         3
+#define TWIM_FRONTONRIGHT        4
+
+/* CAP_JOBCONTROL values Added 1.7  */
+#define TWJC_NONE                0
+#define TWJC_JSIC                1
+#define TWJC_JSIS                2
+#define TWJC_JSXC                3
+#define TWJC_JSXS                4
+
+/* ICAP_JPEGQUALITY values (JQ_ means jpeg quality) */
+#define TWJQ_UNKNOWN            -4
+#define TWJQ_LOW                -3
+#define TWJQ_MEDIUM             -2
+#define TWJQ_HIGH               -1
+
 /* ICAP_LIGHTPATH values (LP_ means Light Path) */
 #define TWLP_REFLECTIVE   0
 #define TWLP_TRANSMISSIVE 1
@@ -624,6 +863,17 @@
 #define TWLS_UV          5
 #define TWLS_IR          6
 
+/* TWEI_MAGTYPE values (MD_ means Mag Type) Added 2.0 */
+#define TWMD_MICR                0  /* Added 2.0 */
+#define TWMD_RAW                 1  /* added 2.1 */
+#define TWMD_INVALID             2  /* added 2.1 */
+
+/* ICAP_NOISEFILTER values (NF_ means noise filter) */
+#define TWNF_NONE                0
+#define TWNF_AUTO                1
+#define TWNF_LONEPIXEL           2
+#define TWNF_MAJORITYRULE        3
+
 /* ICAP_ORIENTATION values (OR_ means ORientation) */
 #define TWOR_ROT0        0
 #define TWOR_ROT90       1
@@ -631,149 +881,27 @@
 #define TWOR_ROT270      3
 #define TWOR_PORTRAIT    TWOR_ROT0
 #define TWOR_LANDSCAPE   TWOR_ROT270
+#define TWOR_AUTO                4           /* 2.0 */
+#define TWOR_AUTOTEXT            5           /* 2.0 */
+#define TWOR_AUTOPICTURE         6           /* 2.0 */
+
+/* ICAP_OVERSCAN values (OV_ means overscan) */
+#define TWOV_NONE                0
+#define TWOV_AUTO                1
+#define TWOV_TOPBOTTOM           2
+#define TWOV_LEFTRIGHT           3
+#define TWOV_ALL                 4
+
+/* Palette types for TW_PALETTE8 */
+#define TWPA_RGB         0
+#define TWPA_GRAY        1
+#define TWPA_CMY         2
 
 /* ICAP_PLANARCHUNKY values (PC_ means Planar/Chunky ) */
 #define TWPC_CHUNKY      0
 #define TWPC_PLANAR      1
 
-/* ICAP_PIXELFLAVOR values (PF_ means Pixel Flavor) */
-#define TWPF_CHOCOLATE   0  /* zero pixel represents darkest shade  */
-#define TWPF_VANILLA     1  /* zero pixel represents lightest shade */
-
-/* ICAP_PIXELTYPE values (PT_ means Pixel Type) */
-#define TWPT_BW          0 /* Black and White */
-#define TWPT_GRAY        1
-#define TWPT_RGB         2
-#define TWPT_PALETTE     3
-#define TWPT_CMY         4
-#define TWPT_CMYK        5
-#define TWPT_YUV         6
-#define TWPT_YUVK        7
-#define TWPT_CIEXYZ      8
-
-/* ICAP_SUPPORTEDSIZES values (SS_ means Supported Sizes) */
-#define TWSS_NONE        0
-#define TWSS_A4LETTER    1
-#define TWSS_B5LETTER    2
-#define TWSS_USLETTER    3
-#define TWSS_USLEGAL     4
-/* Added 1.5 */
-#define TWSS_A5          5
-#define TWSS_B4          6
-#define TWSS_B6          7
-/*#define TWSS_B          8 */
-/* Added 1.7 */
-#define TWSS_USLEDGER    9
-#define TWSS_USEXECUTIVE 10
-#define TWSS_A3          11
-#define TWSS_B3          12
-#define TWSS_A6          13
-#define TWSS_C4          14
-#define TWSS_C5          15
-#define TWSS_C6          16
-/* Added 1.8 */
-#define TWSS_4A0          17
-#define TWSS_2A0          18
-#define TWSS_A0           19
-#define TWSS_A1           20
-#define TWSS_A2           21
-#define TWSS_A4           TWSS_A4LETTER
-#define TWSS_A7           22
-#define TWSS_A8           23
-#define TWSS_A9           24
-#define TWSS_A10          25
-#define TWSS_ISOB0        26
-#define TWSS_ISOB1        27
-#define TWSS_ISOB2        28
-#define TWSS_ISOB3        TWSS_B3
-#define TWSS_ISOB4        TWSS_B4
-#define TWSS_ISOB5        29
-#define TWSS_ISOB6        TWSS_B6
-#define TWSS_ISOB7        30
-#define TWSS_ISOB8        31
-#define TWSS_ISOB9        32
-#define TWSS_ISOB10       33
-#define TWSS_JISB0        34
-#define TWSS_JISB1        35
-#define TWSS_JISB2        36
-#define TWSS_JISB3        37
-#define TWSS_JISB4        38
-#define TWSS_JISB5        TWSS_B5LETTER
-#define TWSS_JISB6        39
-#define TWSS_JISB7        40
-#define TWSS_JISB8        41
-#define TWSS_JISB9        42
-#define TWSS_JISB10       43
-#define TWSS_C0           44
-#define TWSS_C1           45
-#define TWSS_C2           46
-#define TWSS_C3           47
-#define TWSS_C7           48
-#define TWSS_C8           49
-#define TWSS_C9           50
-#define TWSS_C10          51
-#define TWSS_USSTATEMENT  52
-#define TWSS_BUSINESSCARD 53
-
-/* ICAP_XFERMECH values (SX_ means Setup XFer) */
-#define TWSX_NATIVE      0
-#define TWSX_FILE        1
-#define TWSX_MEMORY      2
-
-/* ICAP_UNITS values (UN_ means UNits) */
-#define TWUN_INCHES      0
-#define TWUN_CENTIMETERS 1
-#define TWUN_PICAS       2
-#define TWUN_POINTS      3
-#define TWUN_TWIPS       4
-#define TWUN_PIXELS      5
-
-/* Added 1.5 */
-/* ICAP_BITDEPTHREDUCTION values (BR_ means Bitdepth Reduction) */
-#define TWBR_THRESHOLD     0
-#define TWBR_HALFTONE      1
-#define TWBR_CUSTHALFTONE  2
-#define TWBR_DIFFUSION     3
-
-/* Added 1.7 */
-/* ICAP_DUPLEX values */
-#define TWDX_NONE         0
-#define TWDX_1PASSDUPLEX  1
-#define TWDX_2PASSDUPLEX  2
-
-/* Added 1.7 */
-/* TWEI_BARCODETYPE values */
-#define TWBT_3OF9                 0
-#define TWBT_2OF5INTERLEAVED      1
-#define TWBT_2OF5NONINTERLEAVED   2
-#define TWBT_CODE93               3
-#define TWBT_CODE128              4
-#define TWBT_UCC128               5
-#define TWBT_CODABAR              6
-#define TWBT_UPCA                 7
-#define TWBT_UPCE                 8
-#define TWBT_EAN8                 9
-#define TWBT_EAN13                10
-#define TWBT_POSTNET              11
-#define TWBT_PDF417               12
-/* Added 1.8 */
-#define TWBT_2OF5INDUSTRIAL       13
-#define TWBT_2OF5MATRIX           14
-#define TWBT_2OF5DATALOGIC        15
-#define TWBT_2OF5IATA             16
-#define TWBT_3OF9FULLASCII        17
-#define TWBT_CODABARWITHSTARTSTOP 18
-
-
-/* Added 1.7 */
-/* TWEI_DESKEWSTATUS values */
-#define TWDSK_SUCCESS     0
-#define TWDSK_REPORTONLY  1
-#define TWDSK_FAIL        2
-#define TWDSK_DISABLED    3
-
-/* Added 1.7 */
-/* TWEI_PATCHCODE values */
+/* TWEI_PATCHCODE values Added 1.7 */
 #define TWPCH_PATCH1      0
 #define TWPCH_PATCH2      1
 #define TWPCH_PATCH3      2
@@ -781,82 +909,14 @@
 #define TWPCH_PATCH6      4
 #define TWPCH_PATCHT      5
 
-/* Added 1.7 */
-/* CAP_JOBCONTROL values */
-#define TWJC_NONE   0
-#define TWJC_JSIC   1
-#define TWJC_JSIS   2
-#define TWJC_JSXC   3
-#define TWJC_JSXS   4
-
-/* Added 1.7 */
-/* TWEI_BARCODEROTATION values (BCOR_ means barcode rotation) */
-#define TWBCOR_ROT0   0
-#define TWBCOR_ROT90  1
-#define TWBCOR_ROT180 2
-#define TWBCOR_ROT270 3
-#define TWBCOR_ROTX   4
-
-/* Added 1.8 */
-/* ACAP_AUDIOFILEFORMAT values (AF_ means audio format) */
-#define TWAF_WAV      0
-#define TWAF_AIFF     1
-#define TWAF_AU       3
-#define TWAF_SND      4
-
-/* CAP_ALARMS values (AL_ means alarms) */
-#define TWAL_ALARM	        0
-#define TWAL_FEEDERERROR	  1
-#define TWAL_FEEDERWARNING  2
-#define TWAL_BARCODE	      3
-#define TWAL_DOUBLEFEED	    4
-#define TWAL_JAM	          5
-#define TWAL_PATCHCODE	    6
-#define TWAL_POWER	        7
-#define TWAL_SKEW	          8
-
-/* CAP_CLEARBUFFERS values (CB_ means clear buffers) */
-#define TWCB_AUTO           0
-#define TWCB_CLEAR          1
-#define TWCB_NOCLEAR        2
-
-/* CAP_DEVICEEVENT values (DE_ means device event) */
-#define TWDE_CUSTOMEVENTS						0x8000
-#define TWDE_CHECKAUTOMATICCAPTURE	0
-#define TWDE_CHECKBATTERY						1
-#define TWDE_CHECKDEVICEONLINE			2
-#define TWDE_CHECKFLASH							3
-#define TWDE_CHECKPOWERSUPPLY				4
-#define TWDE_CHECKRESOLUTION				5
-#define TWDE_DEVICEADDED						6
-#define TWDE_DEVICEOFFLINE					7
-#define TWDE_DEVICEREADY						8
-#define TWDE_DEVICEREMOVED					9
-#define TWDE_IMAGECAPTURED					10
-#define TWDE_IMAGEDELETED						11
-#define TWDE_PAPERDOUBLEFEED				12
-#define TWDE_PAPERJAM								13
-#define TWDE_LAMPFAILURE						14
-#define TWDE_POWERSAVE							15
-#define TWDE_POWERSAVENOTIFY				16
-
-/* CAP_FEEDERALIGNMENT values (FA_ means feeder alignment) */
-#define TWFA_NONE	  0
-#define TWFA_LEFT	  1
-#define TWFA_CENTER 2
-#define TWFA_RIGHT  3
-
-/* CAP_FEEDERORDER values (FO_ means feeder order) */
-#define TWFO_FIRSTPAGEFIRST 0
-#define TWFO_LASTPAGEFIRST  1
-
-/* CAP_FILESYSTEM values (FS_ means file system) */
-#define TWFS_FILESYSTEM       0
-#define TWFS_RECURSIVEDELETE  1
+/* ICAP_PIXELFLAVOR values (PF_ means Pixel Flavor) */
+#define TWPF_CHOCOLATE           0  /* zero pixel represents darkest shade  */
+#define TWPF_VANILLA             1  /* zero pixel represents lightest shade */
 
-/* CAP_POWERSUPPLY values (PS_ means power supply) */
-#define TWPS_EXTERNAL 0
-#define TWPS_BATTERY  1
+/* CAP_PRINTERMODE values (PM_ means printer mode) */
+#define TWPM_SINGLESTRING        0
+#define TWPM_MULTISTRING         1
+#define TWPM_COMPOUNDSTRING      2
 
 /* CAP_PRINTER values (PR_ means printer) */
 #define TWPR_IMPRINTERTOPBEFORE     0
@@ -868,60 +928,103 @@
 #define TWPR_ENDORSERBOTTOMBEFORE   6
 #define TWPR_ENDORSERBOTTOMAFTER    7
 
-/* CAP_PRINTERMODE values (PM_ means printer mode) */
-#define TWPM_SINGLESTRING     0
-#define TWPM_MULTISTRING      1
-#define TWPM_COMPOUNDSTRING   2
-
-/* ICAP_BARCODESEARCHMODE values (SRCH_ means search) */
-#define SRCH_HORZ     0
-#define SRCH_VERT     1
-#define SRCH_HORZVERT 2
-#define SRCH_VERTHORZ 3
-
-/* ICAP_FLASHUSED2 values (FL_ means flash) */
-#define TWFL_NONE     0
-#define TWFL_OFF      1
-#define TWFL_ON       2
-#define TWFL_AUTO     3
-#define TWFL_REDEYE   4
+/* CAP_POWERSUPPLY values (PS_ means power supply) */
+#define TWPS_EXTERNAL            0
+#define TWPS_BATTERY             1
 
-/* ICAP_FLIPROTATION values (FR_ means flip rotation) */
-#define TWFR_BOOK     0
-#define TWFR_FANFOLD  1
+/* ICAP_PIXELTYPE values (PT_ means Pixel Type) */
+#define TWPT_BW                  0 /* Black and White */
+#define TWPT_GRAY                1
+#define TWPT_RGB                 2
+#define TWPT_PALETTE             3
+#define TWPT_CMY                 4
+#define TWPT_CMYK                5
+#define TWPT_YUV                 6
+#define TWPT_YUVK                7
+#define TWPT_CIEXYZ              8
+#define TWPT_LAB                 9
+#define TWPT_SRGB               10 /* 1.91 */
+#define TWPT_SCRGB              11 /* 1.91 */
+#define TWPT_INFRARED           16 /* 2.0 */
+
+/* CAP_SEGMENTED values (SG_ means segmented) Added 1.91 */
+#define TWSG_NONE                0
+#define TWSG_AUTO                1
 
-/* ICAP_IMAGEFILTER values (IF_ means image filter) */
-#define TWIF_NONE     0
-#define TWIF_AUTO     1
-#define TWIF_LOWPASS  2
-#define TWIF_BANDPASS 3
-#define TWIF_HIGHPASS 4
-#define TWIF_TEXT     TWIF_BANDPASS
-#define TWIF_FINELINE TWIF_HIGHPASS
+/* ICAP_SUPPORTEDSIZES values (SS_ means Supported Sizes) */
+#define TWSS_NONE                0
+#define TWSS_A4                  1
+#define TWSS_JISB5               2
+#define TWSS_USLETTER            3
+#define TWSS_USLEGAL             4
+/* Added 1.5 */
+#define TWSS_A5                  5
+#define TWSS_ISOB4               6
+#define TWSS_ISOB6               7
+/* Added 1.7 */
+#define TWSS_USLEDGER            9
+#define TWSS_USEXECUTIVE        10
+#define TWSS_A3                 11
+#define TWSS_ISOB3              12
+#define TWSS_A6                 13
+#define TWSS_C4                 14
+#define TWSS_C5                 15
+#define TWSS_C6                 16
+/* Added 1.8 */
+#define TWSS_4A0                17
+#define TWSS_2A0                18
+#define TWSS_A0                 19
+#define TWSS_A1                 20
+#define TWSS_A2                 21
+#define TWSS_A7                 22
+#define TWSS_A8                 23
+#define TWSS_A9                 24
+#define TWSS_A10                25
+#define TWSS_ISOB0              26
+#define TWSS_ISOB1              27
+#define TWSS_ISOB2              28
+#define TWSS_ISOB5              29
+#define TWSS_ISOB7              30
+#define TWSS_ISOB8              31
+#define TWSS_ISOB9              32
+#define TWSS_ISOB10             33
+#define TWSS_JISB0              34
+#define TWSS_JISB1              35
+#define TWSS_JISB2              36
+#define TWSS_JISB3              37
+#define TWSS_JISB4              38
+#define TWSS_JISB6              39
+#define TWSS_JISB7              40
+#define TWSS_JISB8              41
+#define TWSS_JISB9              42
+#define TWSS_JISB10             43
+#define TWSS_C0                 44
+#define TWSS_C1                 45
+#define TWSS_C2                 46
+#define TWSS_C3                 47
+#define TWSS_C7                 48
+#define TWSS_C8                 49
+#define TWSS_C9                 50
+#define TWSS_C10                51
+#define TWSS_USSTATEMENT        52
+#define TWSS_BUSINESSCARD       53
+#define TWSS_MAXSIZE            54  /* Added 2.1 */
 
-/* ICAP_NOISEFILTER values (NF_ means noise filter) */
-#define TWNF_NONE         0
-#define TWNF_AUTO         1
-#define TWNF_LONEPIXEL    2
-#define TWNF_MAJORITYRULE 3
+/* ICAP_XFERMECH values (SX_ means Setup XFer) */
+#define TWSX_NATIVE              0
+#define TWSX_FILE                1
+#define TWSX_MEMORY              2
+#define TWSX_MEMFILE             4    /* added 1.91 */
 
-/* ICAP_OVERSCAN values (OV_ means overscan) */
-#define TWOV_NONE       0
-#define TWOV_AUTO       1
-#define TWOV_TOPBOTTOM  2
-#define TWOV_LEFTRIGHT  3
-#define TWOV_ALL        4
+/* ICAP_UNITS values (UN_ means UNits) */
+#define TWUN_INCHES              0
+#define TWUN_CENTIMETERS         1
+#define TWUN_PICAS               2
+#define TWUN_POINTS              3
+#define TWUN_TWIPS               4
+#define TWUN_PIXELS              5
+#define TWUN_MILLIMETERS         6    /* added 1.91 */
 
-/* TW_FILESYSTEM.FileType values (FT_ means file type) */
-#define TWFY_CAMERA         0
-#define TWFY_CAMERATOP      1
-#define TWFY_CAMERABOTTOM   2
-#define TWFY_CAMERAPREVIEW  3
-#define TWFY_DOMAIN         4
-#define TWFY_HOST           5
-#define TWFY_DIRECTORY      6
-#define TWFY_IMAGE          7
-#define TWFY_UNKNOWN        8
 
 /****************************************************************************
  * Country Constants                                                        *
@@ -1137,27 +1240,56 @@
 #define TWCY_ZAIRE          243
 #define TWCY_ZAMBIA         260
 #define TWCY_ZIMBABWE       263
+/* Added for 1.8 */
+#define TWCY_ALBANIA        355
+#define TWCY_ARMENIA        374
+#define TWCY_AZERBAIJAN     994
+#define TWCY_BELARUS        375
+#define TWCY_BOSNIAHERZGO   387
+#define TWCY_CAMBODIA       855
+#define TWCY_CROATIA        385
+#define TWCY_CZECHREPUBLIC  420
+#define TWCY_DIEGOGARCIA    246
+#define TWCY_ERITREA        291
+#define TWCY_ESTONIA        372
+#define TWCY_GEORGIA        995
+#define TWCY_LATVIA         371
+#define TWCY_LESOTHO        266
+#define TWCY_LITHUANIA      370
+#define TWCY_MACEDONIA      389
+#define TWCY_MAYOTTEIS      269
+#define TWCY_MOLDOVA        373
+#define TWCY_MYANMAR        95
+#define TWCY_NORTHKOREA     850
+#define TWCY_PUERTORICO     787
+#define TWCY_RUSSIA         7
+#define TWCY_SERBIA         381
+#define TWCY_SLOVAKIA       421
+#define TWCY_SLOVENIA       386
+#define TWCY_SOUTHKOREA     82
+#define TWCY_UKRAINE        380
+#define TWCY_USVIRGINIS     340
+#define TWCY_VIETNAM        84
 
 /****************************************************************************
  * Language Constants                                                       *
  ****************************************************************************/
-
-#define TWLG_DAN              0 /* Danish                 */
-#define TWLG_DUT              1 /* Dutch                  */
-#define TWLG_ENG              2 /* International English  */
-#define TWLG_FCF              3 /* French Canadian        */
-#define TWLG_FIN              4 /* Finnish                */
-#define TWLG_FRN              5 /* French                 */
-#define TWLG_GER              6 /* German                 */
-#define TWLG_ICE              7 /* Icelandic              */
-#define TWLG_ITN              8 /* Italian                */
-#define TWLG_NOR              9 /* Norwegian              */
-#define TWLG_POR             10 /* Portuguese             */
-#define TWLG_SPA             11 /* Spanish                */
-#define TWLG_SWE             12 /* Swedish                */
-#define TWLG_USA             13 /* U.S. English           */
 /* Added for 1.8 */
 #define TWLG_USERLOCALE           -1
+#define TWLG_DANISH               0    /* Danish                 */
+#define TWLG_DUTCH                1    /* Dutch                  */
+#define TWLG_ENGLISH              2    /* International English  */
+#define TWLG_FRENCH_CANADIAN      3    /* French Canadian        */
+#define TWLG_FINNISH              4    /* Finnish                */
+#define TWLG_FRENCH               5    /* French                 */
+#define TWLG_GERMAN               6    /* German                 */
+#define TWLG_ICELANDIC            7    /* Icelandic              */
+#define TWLG_ITALIAN              8    /* Italian                */
+#define TWLG_NORWEGIAN            9    /* Norwegian              */
+#define TWLG_PORTUGUESE           10   /* Portuguese             */
+#define TWLG_SPANISH              11   /* Spanish                */
+#define TWLG_SWEDISH              12   /* Swedish                */
+#define TWLG_ENGLISH_USA          13   /* U.S. English           */
 #define TWLG_AFRIKAANS            14
 #define TWLG_ALBANIA              15
 #define TWLG_ARABIC               16
@@ -1190,27 +1322,19 @@
 #define TWLG_CHINESE_TRADITIONAL  43
 #define TWLG_CROATIA              44
 #define TWLG_CZECH                45
-#define TWLG_DANISH               TWLG_DAN
-#define TWLG_DUTCH                TWLG_DUT
 #define TWLG_DUTCH_BELGIAN        46
-#define TWLG_ENGLISH              TWLG_ENG
 #define TWLG_ENGLISH_AUSTRALIAN   47
 #define TWLG_ENGLISH_CANADIAN     48
 #define TWLG_ENGLISH_IRELAND      49
 #define TWLG_ENGLISH_NEWZEALAND   50
 #define TWLG_ENGLISH_SOUTHAFRICA  51
 #define TWLG_ENGLISH_UK           52
-#define TWLG_ENGLISH_USA          TWLG_USA
 #define TWLG_ESTONIAN             53
 #define TWLG_FAEROESE             54
 #define TWLG_FARSI                55
-#define TWLG_FINNISH              TWLG_FIN
-#define TWLG_FRENCH               TWLG_FRN
 #define TWLG_FRENCH_BELGIAN       56
-#define TWLG_FRENCH_CANADIAN      TWLG_FCF
 #define TWLG_FRENCH_LUXEMBOURG    57
 #define TWLG_FRENCH_SWISS         58
-#define TWLG_GERMAN               TWLG_GER
 #define TWLG_GERMAN_AUSTRIAN      59
 #define TWLG_GERMAN_LUXEMBOURG    60
 #define TWLG_GERMAN_LIECHTENSTEIN 61
@@ -1218,33 +1342,55 @@
 #define TWLG_GREEK                63
 #define TWLG_HEBREW               64
 #define TWLG_HUNGARIAN            65
-#define TWLG_ICELANDIC            TWLG_ICE
 #define TWLG_INDONESIAN           66
-#define TWLG_ITALIAN              TWLG_ITN
 #define TWLG_ITALIAN_SWISS        67
 #define TWLG_JAPANESE             68
 #define TWLG_KOREAN               69
 #define TWLG_KOREAN_JOHAB         70
 #define TWLG_LATVIAN              71
 #define TWLG_LITHUANIAN           72
-#define TWLG_NORWEGIAN            TWLG_NOR
 #define TWLG_NORWEGIAN_BOKMAL	    73
 #define TWLG_NORWEGIAN_NYNORSK    74
 #define TWLG_POLISH               75
-#define TWLG_PORTUGUESE           TWLG_POR
 #define TWLG_PORTUGUESE_BRAZIL    76
 #define TWLG_ROMANIAN             77
 #define TWLG_RUSSIAN              78
 #define TWLG_SERBIAN_LATIN        79
 #define TWLG_SLOVAK               80
 #define TWLG_SLOVENIAN            81
-#define TWLG_SPANISH              TWLG_SPA
 #define TWLG_SPANISH_MEXICAN      82
 #define TWLG_SPANISH_MODERN       83
-#define TWLG_SWEDISH              TWLG_SWE
 #define TWLG_THAI                 84
 #define TWLG_TURKISH              85
 #define TWLG_UKRANIAN             86
+/* More stuff added for 1.8 */
+#define TWLG_ASSAMESE             87
+#define TWLG_BENGALI              88
+#define TWLG_BIHARI               89
+#define TWLG_BODO                 90
+#define TWLG_DOGRI                91
+#define TWLG_GUJARATI             92
+#define TWLG_HARYANVI             93
+#define TWLG_HINDI                94
+#define TWLG_KANNADA              95
+#define TWLG_KASHMIRI             96
+#define TWLG_MALAYALAM            97
+#define TWLG_MARATHI              98
+#define TWLG_MARWARI              99
+#define TWLG_MEGHALAYAN          100
+#define TWLG_MIZO                101
+#define TWLG_NAGA                102
+#define TWLG_ORISSI              103
+#define TWLG_PUNJABI             104
+#define TWLG_PUSHTU              105
+#define TWLG_SERBIAN_CYRILLIC    106
+#define TWLG_SIKKIMI             107
+#define TWLG_SWEDISH_FINLAND     108
+#define TWLG_TAMIL               109
+#define TWLG_TELUGU              110
+#define TWLG_TRIPURI             111
+#define TWLG_URDU                112
+#define TWLG_VIETNAMESE          113
 
 /****************************************************************************
  * Data Groups                                                              *
@@ -1256,26 +1402,26 @@
  *       as bitflags when Application asks DSM to present a list of DSs.
  */
 
-#define DG_CONTROL          0x0001L /* data pertaining to control       */
-#define DG_IMAGE            0x0002L /* data pertaining to raster images */
-/* Added 1.8 */
-#define DG_AUDIO            0x0004L /* data pertaining to audio */
+#define DG_CONTROL          0x00000001L   /* data pertaining to control       */
+#define DG_IMAGE            0x00000002L   /* data pertaining to raster images */
+#define DG_AUDIO            0x00000004L   /* data pertaining to audio.  Added for 1.8 */
+
+/* More Data Functionality may be added in the future.
+ * These are for items that need to be determined before DS is opened.
+ * NOTE: Supported Functionality constants must be powers of 2 as they are
+ *       used as bitflags when Application asks DSM to present a list of DSs.
+ *       to support backward capability the App and DS will not use the fields
+ */
+#define DF_DSM2             0x10000000L   /* added to the identity by the DSM  */
+#define DF_APP2             0x20000000L   /* Set by the App to indicate it would
+                                             prefer to use DSM2 */
+#define DF_DS2              0x40000000L   /* Set by the DS to indicate it would
+                                             prefer to use DSM2 */
+#define DG_MASK             0x0000FFFFL   /* all Data Groups limited to 16 bit. Added for 2.1  */
 
 /****************************************************************************
- * Data Argument Types                                                      *
+ *                                                        *
  ****************************************************************************/
-
-/*  SDH - 03/23/95 - WATCH                                                  */
-/*  The thunker requires knowledge about size of data being passed in the   */
-/*  lpData parameter to DS_Entry (which is not readily available due to     */
-/*  type LPVOID.  Thus, we key off the DAT_ argument to determine the size. */
-/*  This has a couple implications:                                         */
-/*  1) Any additional DAT_ features require modifications to the thunk code */
-/*     for thunker support.                                                 */
-/*  2) Any applications which use the custom capabailites are not supported */
-/*     under thunking since we have no way of knowing what size data (if    */
-/*     any) is being passed.                                                */
-
 #define DAT_NULL            0x0000 /* No data or structure. */
 #define DAT_CUSTOMBASE      0x8000 /* Base of custom DATs.  */
 
@@ -1290,15 +1436,12 @@
 #define DAT_STATUS          0x0008 /* TW_STATUS                            */
 #define DAT_USERINTERFACE   0x0009 /* TW_USERINTERFACE                     */
 #define DAT_XFERGROUP       0x000a /* TW_UINT32                            */
-/*  SDH - 03/21/95 - TWUNK                                         */
-/*  Additional message required for thunker to request the special */
-/*  identity information.                                          */
-#define DAT_TWUNKIDENTITY   0x000b /* TW_TWUNKIDENTITY                     */
 #define DAT_CUSTOMDSDATA    0x000c /* TW_CUSTOMDSDATA.                     */
-/* Added 1.8 */
-#define DAT_DEVICEEVENT     0x000d /* TW_DEVICEEVENT                       */
-#define DAT_FILESYSTEM      0x000e /* TW_FILESYSTEM                        */
-#define DAT_PASSTHRU        0x000f /* TW_PASSTHRU                          */
+#define DAT_DEVICEEVENT     0x000d /* TW_DEVICEEVENT     Added 1.8         */
+#define DAT_FILESYSTEM      0x000e /* TW_FILESYSTEM      Added 1.8         */
+#define DAT_PASSTHRU        0x000f /* TW_PASSTHRU        Added 1.8         */
+#define DAT_CALLBACK        0x0010 /* TW_CALLBACK        Added 2.0         */
+#define DAT_STATUSUTF8      0x0011 /* TW_STATUSUTF8      Added 2.1         */
 
 /* Data Argument Types for the DG_IMAGE Data Group. */
 #define DAT_IMAGEINFO       0x0101 /* TW_IMAGEINFO                         */
@@ -1313,11 +1456,16 @@
 #define DAT_PALETTE8        0x010a /* TW_PALETTE8                          */
 #define DAT_EXTIMAGEINFO    0x010b /* TW_EXTIMAGEINFO -- for 1.7 Spec.     */
 
-/* Added 1.8 */
 /* Data Argument Types for the DG_AUDIO Data Group. */
-#define DAT_AUDIOFILEXFER   0x0201 /* Null data                            */
-#define DAT_AUDIOINFO       0x0202 /* TW_AUDIOINFO                         */
-#define DAT_AUDIONATIVEXFER 0x0203 /* TW_UINT32 handle to WAV, (AIFF Mac)  */
+#define DAT_AUDIOFILEXFER   0x0201 /* Null data          Added 1.8         */
+#define DAT_AUDIOINFO       0x0202 /* TW_AUDIOINFO       Added 1.8         */
+#define DAT_AUDIONATIVEXFER 0x0203 /* TW_UINT32 handle to WAV, (AIFF Mac) Added 1.8 */
+
+/* misplaced */
+#define DAT_ICCPROFILE        0x0401 /* TW_MEMORY        Added 1.91  This Data Argument is misplaced but belongs to the DG_IMAGE Data Group */
+#define DAT_IMAGEMEMFILEXFER  0x0402 /* TW_IMAGEMEMXFER  Added 1.91  This Data Argument is misplaced but belongs to the DG_IMAGE Data Group */
+#define DAT_ENTRYPOINT        0x0403 /* TW_ENTRYPOINT    Added 2.0   This Data Argument is misplaced but belongs to the DG_CONTROL Data Group */
+
 
 /****************************************************************************
  * Messages                                                                 *
@@ -1338,16 +1486,16 @@
 #define MSG_SET          0x0006 /* Set one or more values                   */
 #define MSG_RESET        0x0007 /* Set current value to default value       */
 #define MSG_QUERYSUPPORT 0x0008 /* Get supported operations on the cap.     */
+#define MSG_GETHELP         0x0009 /* Returns help text suitable for use in a GUI        Added 2.1 */
+#define MSG_GETLABEL        0x000a /* Returns a label suitable for use in a GUI          Added 2.1 */
+#define MSG_GETLABELENUM    0x000b /* Return all of the labels for a capability of type  Added 2.1 */
+
 
 /* Messages used with DAT_NULL                                              */
 #define MSG_XFERREADY    0x0101 /* The data source has data ready           */
 #define MSG_CLOSEDSREQ   0x0102 /* Request for Application. to close DS             */
 #define MSG_CLOSEDSOK    0x0103 /* Tell the Application. to save the state.         */
-/* Added 1.8 */
-#define MSG_DEVICEEVENT  0X0104 /* Some event has taken place               */
-
-/* Messages used with a pointer to a DAT_STATUS structure                   */
-#define MSG_CHECKSTATUS  0x0201 /* Get status information                   */
+#define MSG_DEVICEEVENT  0X0104 /* Some event has taken place               Added 1.8 */
 
 /* Messages used with a pointer to DAT_PARENT data                          */
 #define MSG_OPENDSM      0x0301 /* Open the DSM                             */
@@ -1368,22 +1516,30 @@
 
 /* Messages used with a pointer to a DAT_PENDINGXFERS structure             */
 #define MSG_ENDXFER      0x0701
+#define MSG_STOPFEEDER   0x0702
 
-/* Added 1.8 */
 /* Messages used with a pointer to a DAT_FILESYSTEM structure               */
-#define MSG_CHANGEDIRECTORY   0x0801
-#define MSG_CREATEDIRECTORY   0x0802
-#define MSG_DELETE            0x0803
-#define MSG_FORMATMEDIA       0x0804
-#define MSG_GETCLOSE          0x0805
-#define MSG_GETFIRSTFILE      0x0806
-#define MSG_GETINFO           0x0807
-#define MSG_GETNEXTFILE       0x0808
-#define MSG_RENAME            0x0809
+#define MSG_CHANGEDIRECTORY   0x0801 /* Added 1.8 */
+#define MSG_CREATEDIRECTORY   0x0802 /* Added 1.8 */
+#define MSG_DELETE            0x0803 /* Added 1.8 */
+#define MSG_FORMATMEDIA       0x0804 /* Added 1.8 */
+#define MSG_GETCLOSE          0x0805 /* Added 1.8 */
+#define MSG_GETFIRSTFILE      0x0806 /* Added 1.8 */
+#define MSG_GETINFO           0x0807 /* Added 1.8 */
+#define MSG_GETNEXTFILE       0x0808 /* Added 1.8 */
+#define MSG_RENAME            0x0809 /* Added 1.8 */
+#define MSG_COPY              0x080A /* Added 1.8 */
+#define MSG_AUTOMATICCAPTUREDIRECTORY 0x080B /* Added 1.8 */
 
 /* Messages used with a pointer to a DAT_PASSTHRU structure                 */
 #define MSG_PASSTHRU          0x0901
 
+/* used with DAT_CALLBACK */
+#define MSG_REGISTER_CALLBACK 0x0902
+
+/* used with DAT_CAPABILITY */
+#define MSG_RESETALL          0x0A01 /*  Added 1.91 */
+
 /****************************************************************************
  * Capabilities                                                             *
  ****************************************************************************/
@@ -1435,9 +1591,7 @@
 #define CAP_POWERSUPPLY             0x1020   /* Added 1.8 */
 #define CAP_CAMERAPREVIEWUI         0x1021   /* Added 1.8 */
 #define CAP_DEVICEEVENT							0x1022   /* Added 1.8 */
-#define CAP_PAGEMULTIPLEACQUIRE			0x1023   /* Added 1.8 */
 #define CAP_SERIALNUMBER            0x1024   /* Added 1.8 */
-#define CAP_FILESYSTEM              0x1025   /* Added 1.8 */
 #define CAP_PRINTER                 0x1026   /* Added 1.8 */
 #define CAP_PRINTERENABLED          0x1027   /* Added 1.8 */
 #define CAP_PRINTERINDEX            0x1028   /* Added 1.8 */
@@ -1447,12 +1601,19 @@
 #define CAP_LANGUAGE                0x102c   /* Added 1.8 */
 #define CAP_FEEDERALIGNMENT         0x102d   /* Added 1.8 */
 #define CAP_FEEDERORDER             0x102e   /* Added 1.8 */
-#define CAP_PAPERBINDING            0x102f   /* Added 1.8 */
 #define CAP_REACQUIREALLOWED        0x1030   /* Added 1.8 */
-#define CAP_PASSTHRU                0x1031   /* Added 1.8 */
 #define CAP_BATTERYMINUTES          0x1032   /* Added 1.8 */
 #define CAP_BATTERYPERCENTAGE       0x1033   /* Added 1.8 */
-#define CAP_POWERDOWNTIME           0x1034   /* Added 1.8 */
+#define CAP_CAMERASIDE              0x1034   /* Added 1.91 */
+#define CAP_SEGMENTED               0x1035   /* Added 1.91 */
+#define CAP_CAMERAENABLED           0x1036   /* Added 2.0 */
+#define CAP_CAMERAORDER             0x1037   /* Added 2.0 */
+#define CAP_MICRENABLED             0x1038   /* Added 2.0 */
+#define CAP_FEEDERPREP              0x1039   /* Added 2.0 */
+#define CAP_FEEDERPOCKET            0x103a   /* Added 2.0 */
+#define CAP_AUTOMATICSENSEMEDIUM    0x103b   /* Added 2.1 */
+#define CAP_CUSTOMINTERFACEGUID     0x103c   /* Added 2.1 */
+
 
 /* image data sources MAY support these caps */
 #define ICAP_AUTOBRIGHT                   0x1100
@@ -1500,10 +1661,7 @@
 #define ICAP_EXTIMAGEINFO                 0x112f  /* Added 1.7 */
 #define ICAP_MINIMUMHEIGHT                0x1130  /* Added 1.7 */
 #define ICAP_MINIMUMWIDTH                 0x1131  /* Added 1.7 */
-#define ICAP_AUTOBORDERDETECTION          0x1132  /* Added 1.8 */
-#define ICAP_AUTODESKEW                   0x1133  /* Added 1.8 */
-#define ICAP_AUTODISCARDBLANKPAGES        0x1134  /* Added 1.8 */
-#define ICAP_AUTOROTATE                   0x1135  /* Added 1.8 */
+#define ICAP_AUTODISCARDBLANKPAGES        0x1134  /* Added 2.0 */
 #define ICAP_FLIPROTATION                 0x1136  /* Added 1.8 */
 #define ICAP_BARCODEDETECTIONENABLED      0x1137  /* Added 1.8 */
 #define ICAP_SUPPORTEDBARCODETYPES        0x1138  /* Added 1.8 */
@@ -1527,18 +1685,26 @@
 #define ICAP_AUTOMATICBORDERDETECTION			0x1150  /* Added 1.8 */
 #define ICAP_AUTOMATICDESKEW							0x1151  /* Added 1.8 */
 #define ICAP_AUTOMATICROTATE							0x1152  /* Added 1.8 */
+#define ICAP_JPEGQUALITY                  0x1153  /* Added 1.9 */
+#define ICAP_FEEDERTYPE                   0x1154  /* Added 1.91 */
+#define ICAP_ICCPROFILE                   0x1155  /* Added 1.91 */
+#define ICAP_AUTOSIZE                     0x1156  /* Added 2.0 */
+#define ICAP_AUTOMATICCROPUSESFRAME       0x1157  /* Added 2.1 */
+#define ICAP_AUTOMATICLENGTHDETECTION     0x1158  /* Added 2.1 */
+#define ICAP_AUTOMATICCOLORENABLED        0x1159  /* Added 2.1 */
+#define ICAP_AUTOMATICCOLORNONCOLORPIXELTYPE 0x115a  /* Added 2.1 */
+#define ICAP_COLORMANAGEMENTENABLED       0x115b  /* Added 2.1 */
+#define ICAP_IMAGEMERGE                   0x115c  /* Added 2.1 */
+#define ICAP_IMAGEMERGEHEIGHTTHRESHOLD    0x115d  /* Added 2.1 */
+#define ICAP_SUPPORTEDEXTIMAGEINFO        0x115e  /* Added 2.1 */
 
 /* image data sources MAY support these audio caps */
-#define ACAP_AUDIOFILEFORMAT    0x1201  /* Added 1.8 */
 #define ACAP_XFERMECH           0x1202  /* Added 1.8 */
 
-/* ----------------------------------------------------------------------- *\
 
-  Version 1.7:      Following is Extended Image Info Attributes.
-  July 1997
-  KHL
-
-\* ----------------------------------------------------------------------- */
+/***************************************************************************
+ *            Extended Image Info Attributes section  Added 1.7            *
+ ***************************************************************************/
 
 #define TWEI_BARCODEX               0x1200
 #define TWEI_BARCODEY               0x1201
@@ -1595,6 +1761,23 @@
 #define TWEI_SKEWWINDOWY3           0x1234
 #define TWEI_SKEWWINDOWX4           0x1235
 #define TWEI_SKEWWINDOWY4           0x1236
+#define TWEI_BOOKNAME               0x1238  /* added 1.9 */
+#define TWEI_CHAPTERNUMBER          0x1239  /* added 1.9 */
+#define TWEI_DOCUMENTNUMBER         0x123A  /* added 1.9 */
+#define TWEI_PAGENUMBER             0x123B  /* added 1.9 */
+#define TWEI_CAMERA                 0x123C  /* added 1.9 */
+#define TWEI_FRAMENUMBER            0x123D  /* added 1.9 */
+#define TWEI_FRAME                  0x123E  /* added 1.9 */
+#define TWEI_PIXELFLAVOR            0x123F  /* added 1.9 */
+#define TWEI_ICCPROFILE             0x1240  /* added 1.91 */
+#define TWEI_LASTSEGMENT            0x1241  /* added 1.91 */
+#define TWEI_SEGMENTNUMBER          0x1242  /* added 1.91 */
+#define TWEI_MAGDATA                0x1243  /* added 2.0 */
+#define TWEI_MAGTYPE                0x1244  /* added 2.0 */
+#define TWEI_PAGESIDE               0x1245  /* added 2.0 */
+#define TWEI_FILESYSTEMSOURCE       0x1246  /* added 2.0 */
+#define TWEI_IMAGEMERGED            0x1247  /* added 2.1 */
+#define TWEI_MAGDATALENGTH          0x1248  /* added 2.1 */
 
 #define TWEJ_NONE                   0x0000
 #define TWEJ_MIDSEPARATOR           0x0001
@@ -1605,6 +1788,7 @@
 #define TWEJ_PATCH6                 0x0006
 #define TWEJ_PATCHT                 0x0007
 
+
 /***************************************************************************
  *            Return Codes and Condition Codes section                     *
  ***************************************************************************/
@@ -1640,16 +1824,20 @@
 #define TWCC_CAPUNSUPPORTED			13 /* Capability not supported by source            */
 #define TWCC_CAPBADOPERATION		14 /* Operation not supported by capability         */
 #define TWCC_CAPSEQERROR				15 /* Capability has dependancy on other capability */
-/* Added 1.8 */
-#define TWCC_DENIED							16 /* File System operation is denied (file is protected) */
-#define TWCC_FILEEXISTS					17 /* Operation failed because file already exists. */
-#define TWCC_FILENOTFOUND				18 /* File not found */
-#define TWCC_NOTEMPTY						19 /* Operation failed because directory is not empty */
-#define TWCC_PAPERJAM						20  /* The feeder is jammed */
-#define TWCC_PAPERDOUBLEFEED		21  /* The feeder detected multiple pages */
-#define TWCC_FILEWRITEERROR			22  /* Error writing the file (meant for things like disk full conditions) */
-#define	TWCC_CHECKDEVICEONLINE	23  /* The device went offline prior to or during this operation */
-
+#define TWCC_DENIED             16 /* File System operation is denied (file is protected) Added 1.8 */
+#define TWCC_FILEEXISTS         17 /* Operation failed because file already exists.       Added 1.8 */
+#define TWCC_FILENOTFOUND       18 /* File not found                                      Added 1.8 */
+#define TWCC_NOTEMPTY           19 /* Operation failed because directory is not empty     Added 1.8 */
+#define TWCC_PAPERJAM           20 /* The feeder is jammed                                Added 1.8 */
+#define TWCC_PAPERDOUBLEFEED    21 /* The feeder detected multiple pages                  Added 1.8 */
+#define TWCC_FILEWRITEERROR     22 /* Error writing the file (meant for things like disk full conditions)Added 1.8 */
+#define TWCC_CHECKDEVICEONLINE  23 /* The device went offline prior to or during this operation Added 1.8 */
+#define TWCC_INTERLOCK          24 /* Added 2.0 */
+#define TWCC_DAMAGEDCORNER      25 /* Added 2.0 */
+#define TWCC_FOCUSERROR         26 /* Added 2.0 */
+#define TWCC_DOCTOOLIGHT        27 /* Added 2.0 */
+#define TWCC_DOCTOODARK         28 /* Added 2.0 */
+#define TWCC_NOMEDIA            29 /* Added 2.1 */
 
 /* bit patterns: for query the operation that are supported by the data source on a capability */
 /* Application gets these through DG_CONTROL/DAT_CAPABILITY/MSG_QUERYSUPPORT */
@@ -1662,6 +1850,163 @@
 
 
 /****************************************************************************
+ * Depreciated Items                                                        *
+ ****************************************************************************/
+#if defined(WIN32) || defined(WIN64)
+        #define TW_HUGE
+#elif !defined(TWH_CMP_GNU)
+        #define TW_HUGE    huge
+#else
+        #define TW_HUGE
+#endif
+
+
+
+typedef BYTE TW_HUGE * HPBYTE;
+typedef void TW_HUGE * HPVOID;
+
+typedef unsigned char     TW_STR1024[1026],   FAR *pTW_STR1026;
+typedef wchar_t           TW_UNI512[512],     FAR *pTW_UNI512;
+
+#define TWTY_STR1024          0x000d    /* Means Item is a TW_STR1024...added 1.9 */
+#define TWTY_UNI512           0x000e    /* Means Item is a TW_UNI512...added 1.9 */
+
+#define TWFF_JPN              12        /* 1.91 */
+
+#define DAT_TWUNKIDENTITY     0x000b    /* Additional message required for thunker to request the special identity information. */
+#define DAT_SETUPFILEXFER2    0x0301    /* Data transfer via a file. deprecated - use DAT_SETUPFILEXFER instead*/
+
+#define CAP_SUPPORTEDCAPSEXT      0x100c
+#define CAP_FILESYSTEM            //0x????
+#define CAP_PAGEMULTIPLEACQUIRE   0x1023    /* Added 1.8 */
+#define CAP_PAPERBINDING          0x102f    /* Added 1.8 */
+#define CAP_PASSTHRU              0x1031    /* Added 1.8 */
+#define CAP_POWERDOWNTIME         0x1034    /* Added 1.8 */  //0x1034 is reused by CAP_CAMERASIDE
+#define ACAP_AUDIOFILEFORMAT      0x1201    /* Added 1.8 */
+
+#define MSG_CHECKSTATUS       0x0201    /* Get status information - use MSG_GET instead */
+
+#define MSG_INVOKE_CALLBACK   0x0903    /* Mac Only, deprecated - use DAT_NULL and MSG_xxx instead */
+
+#define TWSX_FILE2            3
+
+/* CAP_FILESYSTEM values (FS_ means file system) */
+#define TWFS_FILESYSTEM       0
+#define TWFS_RECURSIVEDELETE  1
+
+/* ICAP_PIXELTYPE values (PT_ means Pixel Type) */
+#define TWPT_SRGB64     11 /* 1.91 */
+#define TWPT_BGR        12 /* 1.91 */
+#define TWPT_CIELAB     13 /* 1.91 */
+#define TWPT_CIELUV     14 /* 1.91 */
+#define TWPT_YCBCR      15 /* 1.91 */
+
+/* ICAP_SUPPORTEDSIZES values (SS_ means Supported Sizes) */
+#define TWSS_B                8
+#define TWSS_A4LETTER    TWSS_A4      /* use TWSS_A4 instead */
+#define TWSS_B3          TWSS_ISOB3   /* use TWSS_ISOB3 instead */
+#define TWSS_B4          TWSS_ISOB4   /* use TWSS_ISOB4 instead */
+#define TWSS_B6          TWSS_ISOB6   /* use TWSS_ISOB6 instead */
+#define TWSS_B5LETTER    TWSS_JISB5   /* use TWSS_JISB5 instead */
+
+/* CAP_LANGUAGE Language Constants */
+#define TWLG_DAN    TWLG_DANISH           /* use TWLG_DANISH instead */
+#define TWLG_DUT    TWLG_DUTCH            /* use TWLG_DUTCH instead */
+#define TWLG_ENG    TWLG_ENGLISH          /* use TWLG_ENGLISH instead */
+#define TWLG_USA    TWLG_ENGLISH_USA      /* use TWLG_ENGLISH_USA instead */
+#define TWLG_FIN    TWLG_FINNISH          /* use TWLG_FINNISH instead */
+#define TWLG_FRN    TWLG_FRENCH           /* use TWLG_FRENCH instead */
+#define TWLG_FCF    TWLG_FRENCH_CANADIAN  /* use TWLG_FRENCH_CANADIAN instead */
+#define TWLG_GER    TWLG_GERMAN           /* use TWLG_GERMAN instead */
+#define TWLG_ICE    TWLG_ICELANDIC        /* use TWLG_ICELANDIC instead */
+#define TWLG_ITN    TWLG_ITALIAN          /* use TWLG_ITALIAN instead */
+#define TWLG_NOR    TWLG_NORWEGIAN        /* use TWLG_NORWEGIAN instead */
+#define TWLG_POR    TWLG_PORTUGUESE       /* use TWLG_PORTUGUESE instead */
+#define TWLG_SPA    TWLG_SPANISH          /* use TWLG_SPANISH instead */
+#define TWLG_SWE    TWLG_SWEDISH          /* use TWLG_SWEDISH instead */
+
+
+/* ACAP_AUDIOFILEFORMAT values (AF_ means audio format).  Added 1.8 */
+#define TWAF_WAV      0
+#define TWAF_AIFF     1
+#define TWAF_AU       3
+#define TWAF_SND      4
+
+
+/* DAT_SETUPFILEXFER2. Sets up DS to application data transfer via a file. Added 1.9 */
+typedef struct {
+   TW_MEMREF FileName;     /* Pointer to file name text */
+   TW_UINT16 FileNameType; /* TWTY_STR1024 or TWTY_UNI512 */
+   TW_UINT16 Format;       /* Any TWFF_ constant */
+   TW_INT16  VRefNum;      /* Used for Mac only  */
+   TW_UINT32 parID;        /* Used for Mac only */
+} TW_SETUPFILEXFER2, FAR * pTW_SETUPFILEXFER2;
+
+/* SDH - 03/21/95 - TWUNK */
+/* DAT_TWUNKIDENTITY. Provides DS identity and 'other' information necessary */
+/*                    across thunk link. */
+typedef struct {
+   TW_IDENTITY identity;        /* Identity of data source.                 */
+   TW_STR255   dsPath;          /* Full path and file name of data source.  */
+} TW_TWUNKIDENTITY, FAR * pTW_TWUNKIDENTITY;
+
+/* SDH - 03/21/95 - TWUNK */
+/* Provides DS_Entry parameters over thunk link. */
+/*  SDH - 03/23/95 - WATCH                                                  */
+/*  The thunker requires knowledge about size of data being passed in the   */
+/*  lpData parameter to DS_Entry (which is not readily available due to     */
+/*  type LPVOID.  Thus, we key off the DAT_ argument to determine the size. */
+/*  This has a couple implications:                                         */
+/*  1) Any additional DAT_ features require modifications to the thunk code */
+/*     for thunker support.                                                 */
+/*  2) Any applications which use the custom capabailites are not supported */
+/*     under thunking since we have no way of knowing what size data (if    */
+/*     any) is being passed.                                                */
+typedef struct
+{
+    TW_INT8     destFlag;       /* TRUE if dest is not NULL                 */
+    TW_IDENTITY dest;           /* Identity of data source (if used)        */
+    TW_INT32    dataGroup;      /* DSM_Entry dataGroup parameter            */
+    TW_INT16    dataArgType;    /* DSM_Entry dataArgType parameter          */
+    TW_INT16    message;        /* DSM_Entry message parameter              */
+    TW_INT32    pDataSize;      /* Size of pData (0 if NULL)                */
+    //  TW_MEMREF   pData;      /* Based on implementation specifics, a     */
+                                /* pData parameter makes no sense in this   */
+                                /* structure, but data (if provided) will be*/
+                                /* appended in the data block.              */
+} TW_TWUNKDSENTRYPARAMS, FAR * pTW_TWUNKDSENTRYPARAMS;
+
+/* SDH - 03/21/95 - TWUNK */
+/* Provides DS_Entry results over thunk link. */
+typedef struct
+{
+    TW_UINT16   returnCode;     /* Thunker DsEntry return code.             */
+    TW_UINT16   conditionCode;  /* Thunker DsEntry condition code.          */
+    TW_INT32    pDataSize;      /* Size of pData (0 if NULL)                */
+    //  TW_MEMREF   pData;      /* Based on implementation specifics, a     */
+                                /* pData parameter makes no sense in this   */
+                                /* structure, but data (if provided) will be*/
+                                /* appended in the data block.              */
+} TW_TWUNKDSENTRYRETURN, FAR * pTW_TWUNKDSENTRYRETURN;
+
+/* WJD - 950818 */
+/* Added for 1.6 Specification */
+/* TWAIN 1.6 CAP_SUPPORTEDCAPSEXT structure */
+typedef struct
+{
+    TW_UINT16 Cap;   /* Which CAP/ICAP info is relevant to */
+    TW_UINT16 Properties;  /* Messages this CAP/ICAP supports */
+} TW_CAPEXT, FAR * pTW_CAPEXT;
+
+/* DAT_SETUPAUDIOFILEXFER, information required to setup an audio file transfer */
+typedef struct {
+   TW_STR255  FileName; /* full path target file */
+   TW_UINT16  Format;   /* one of TWAF_xxxx */
+   TW_INT16 VRefNum;
+} TW_SETUPAUDIOFILEXFER, FAR * pTW_SETUPAUDIOFILEXFER;
+
+
+/****************************************************************************
  * Entry Points                                                             *
  ****************************************************************************/
 
@@ -1702,30 +2047,39 @@
 extern "C" {
 #endif  /* __cplusplus */
 
-#ifdef  _MSWIN_
-TW_UINT16 FAR PASCAL DSM_Entry( pTW_IDENTITY pOrigin,
+#ifdef TWH_CMP_MSC
+
+  TW_UINT16 FAR PASCAL DSM_Entry( pTW_IDENTITY pOrigin,
                                 pTW_IDENTITY pDest,
                                 TW_UINT32    DG,
                                 TW_UINT16    DAT,
                                 TW_UINT16    MSG,
                                 TW_MEMREF    pData);
 
-typedef TW_UINT16 (FAR PASCAL *DSMENTRYPROC)(pTW_IDENTITY, pTW_IDENTITY,
-                                             TW_UINT32,    TW_UINT16,
-                                             TW_UINT16,    TW_MEMREF);
-#else   /* _MSWIN_ */
+  typedef TW_UINT16 (FAR PASCAL *DSMENTRYPROC)(pTW_IDENTITY pOrigin,
+                                               pTW_IDENTITY pDest,
+                                               TW_UINT32 DG,
+                                               TW_UINT16 DAT,
+                                               TW_UINT16 MSG,
+                                               TW_MEMREF pData);
+
+#else
+
+  FAR PASCAL TW_UINT16 DSM_Entry( pTW_IDENTITY pOrigin,
+                                  pTW_IDENTITY pDest,
+                                  TW_UINT32    DG,
+                                  TW_UINT16    DAT,
+                                  TW_UINT16    MSG,
+                                  TW_MEMREF    pData);
 
-FAR PASCAL TW_UINT16 DSM_Entry( pTW_IDENTITY pOrigin,
+  typedef TW_UINT16 (*DSMENTRYPROC)(pTW_IDENTITY pOrigin,
                                 pTW_IDENTITY pDest,
                                 TW_UINT32    DG,
                                 TW_UINT16    DAT,
                                 TW_UINT16    MSG,
                                 TW_MEMREF    pData);
 
-typedef TW_UINT16 (*DSMENTRYPROC)(pTW_IDENTITY, pTW_IDENTITY,
-                                  TW_UINT32,    TW_UINT16,
-                                  TW_UINT16,    TW_MEMREF);
-#endif  /* _MSWIN_ */
+#endif  /* TWH_CMP_MSC */
 
 #ifdef  __cplusplus
 }
@@ -1768,52 +2122,72 @@
 extern "C" {
 #endif  /* __cplusplus */
 
-#ifdef  _MSWIN_
-  #ifdef _WIN32
-     __declspec(dllexport) TW_UINT16 FAR PASCAL DS_Entry (pTW_IDENTITY pOrigin,
+#ifdef TWH_CMP_MSC
+
+  TW_UINT16 FAR PASCAL DS_Entry(pTW_IDENTITY pOrigin,
                                                           TW_UINT32    DG,
                                                           TW_UINT16    DAT,
                                                           TW_UINT16    MSG,
                                                           TW_MEMREF    pData);
-  #else   /* _WIN32 */
-     TW_UINT16 FAR PASCAL DS_Entry (pTW_IDENTITY pOrigin,
+
+  typedef TW_UINT16 (FAR PASCAL *DSENTRYPROC)(pTW_IDENTITY pOrigin,
                                     TW_UINT32    DG,
                                     TW_UINT16    DAT,
                                     TW_UINT16    MSG,
                                     TW_MEMREF    pData);
-  #endif  /* _WIN32 */
 
-  typedef TW_UINT16 (FAR PASCAL *DSENTRYPROC) (pTW_IDENTITY pOrigin,
+#else
+
+  FAR PASCAL TW_UINT16 DS_Entry(pTW_IDENTITY pOrigin,
                                                TW_UINT32    DG,
                                                TW_UINT16    DAT,
                                                TW_UINT16    MSG,
                                                TW_MEMREF    pData);
-#else   /* _MSWIN_ */
-FAR PASCAL TW_UINT16 DS_Entry( pTW_IDENTITY pOrigin,
+
+  typedef TW_UINT16 (*DSENTRYPROC)(pTW_IDENTITY pOrigin,
                                TW_UINT32    DG,
                                TW_UINT16    DAT,
                                TW_UINT16    MSG,
                                TW_MEMREF    pData);
 
-typedef TW_UINT16 (*DSENTRYPROC)(pTW_IDENTITY,
-                                  TW_UINT32,    TW_UINT16,
-                                  TW_UINT16,    TW_MEMREF);
-#endif  /* _MSWIN_ */
+#endif /* TWH_CMP_MSC */
+
+
+  typedef TW_HANDLE (PASCAL *DSM_MEMALLOCATE)(TW_UINT32 _size);
+  typedef void (PASCAL *DSM_MEMFREE)(TW_HANDLE _handle);
+  typedef TW_MEMREF (PASCAL *DSM_MEMLOCK)(TW_HANDLE _handle);
+  typedef void (PASCAL *DSM_MEMUNLOCK)(TW_HANDLE _handle);
 
 #ifdef  __cplusplus
 }
-#endif  /* cplusplus */
+#endif  /* __cplusplus */
 
-/*  SDH - 02/08/95 - TWUNK */
-/*  Force 32-bit twain to use same packing of twain structures as existing */
-/*  16-bit twain.  This allows 16/32-bit thunking. */
-#ifdef  WIN32
-    #ifdef __BORLANDC__ /*(Mentor June 13, 1996) if we're using a Borland compiler */
-        #pragma option -a.  /*(Mentor October 30, 1996) switch back to original alignment */
-    #else   /*(Mentor June 13, 1996) if NOT using a Borland compiler */
+/* DAT_ENTRYPOINT. returns essential entry points. */
+typedef struct {
+   TW_UINT32         Size;
+   DSMENTRYPROC      DSM_Entry;
+   DSM_MEMALLOCATE   DSM_MemAllocate;
+   DSM_MEMFREE       DSM_MemFree;
+   DSM_MEMLOCK       DSM_MemLock;
+   DSM_MEMUNLOCK     DSM_MemUnlock;
+} TW_ENTRYPOINT, FAR * pTW_ENTRYPOINT;
+
+/* Restore the previous packing alignment: this occurs after all structures are defined */
+#ifdef TWH_CMP_MSC
         #pragma pack (pop, before_twain)
-    #endif  /*(Mentor June 13, 1996) */
-#else   /* WIN32 */
-#endif  /* WIN32 */
+#elif defined(TWH_CMP_GNU)
+    #pragma pack (pop, before_twain)
+#elif defined(TWH_CMP_BORLAND)
+    #pragma option -a.
+#elif defined(TWH_CMP_XCODE)
+    #if PRAGMA_STRUCT_ALIGN
+        #pragma options align=reset
+    #elif PRAGMA_STRUCT_PACKPUSH
+        #pragma pack (pop)
+    #elif PRAGMA_STRUCT_PACK
+        #pragma pack ()
+    #endif
+#endif
 
 #endif  /* TWAIN */
+
Only in /usr/src/gimp-2.7.3/plug-ins/twain: twain.o
Only in /usr/src/gimp-2.7.3/plug-ins/twain: twain.rc.o
Only in /usr/src/gimp-2.7.3/plug-ins/twain: twain.zip
