mirror of
https://gitlab.gnome.org/GNOME/gimp.git
synced 2025-10-06 01:12:40 +02:00
Compare commits
11 Commits
9c74e2fc00
...
bug-357818
Author | SHA1 | Date | |
---|---|---|---|
|
d21771fff2 | ||
|
44f9e8941f | ||
|
9d5415cd5c | ||
|
ec625fa067 | ||
|
7ea329d098 | ||
|
f96ae47bdc | ||
|
f76ee05449 | ||
|
8022de440b | ||
|
bf4dcc0ef3 | ||
|
d5ae769d85 | ||
|
204efe8b26 |
@@ -22,8 +22,9 @@ endif
|
||||
if HAVE_WINDRES
|
||||
include $(top_srcdir)/build/windows/gimprc-plug-ins.rule
|
||||
twain_RC = twain.rc.o
|
||||
twaindata_DATA = twain-menu.png
|
||||
endif
|
||||
|
||||
twaindatadir = $(gimpdatadir)/twain
|
||||
|
||||
twain_SOURCES = \
|
||||
tw_func.c \
|
||||
|
@@ -1,273 +0,0 @@
|
||||
/*
|
||||
* TWAIN Plug-in
|
||||
* Copyright (C) 1999 Craig Setera
|
||||
* Craig Setera <setera@home.com>
|
||||
* 03/31/1999
|
||||
*
|
||||
* Updated for Mac OS X support
|
||||
* Brion Vibber <brion@pobox.com>
|
||||
* 07/22/2004
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
* Based on (at least) the following plug-ins:
|
||||
* Screenshot
|
||||
* GIF
|
||||
* Randomize
|
||||
*
|
||||
* Any suggestions, bug-reports or patches are welcome.
|
||||
*
|
||||
* This plug-in interfaces to the TWAIN support library in order
|
||||
* to capture images from TWAIN devices directly into GIMP images.
|
||||
* The plug-in is capable of acquiring the following type of
|
||||
* images:
|
||||
* - B/W (1 bit images translated to grayscale B/W)
|
||||
* - Grayscale up to 16 bits per pixel
|
||||
* - RGB up to 16 bits per sample (24, 30, 36, etc.)
|
||||
* - Paletted images (both Gray and RGB)
|
||||
*
|
||||
* Prerequisites:
|
||||
* Should compile and run on both Win32 and Mac OS X 10.3 (possibly
|
||||
* also on 10.2).
|
||||
*
|
||||
* Known problems:
|
||||
* - Multiple image transfers will hang the plug-in. The current
|
||||
* configuration compiles with a maximum of single image transfers.
|
||||
* - On Mac OS X, canceling doesn't always close things out fully.
|
||||
* - Epson TWAIN driver on Mac OS X crashes the plugin when scanning.
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <glib/gstdio.h>
|
||||
|
||||
#include "libgimp/gimp.h"
|
||||
|
||||
#include "tw_dump.h"
|
||||
#include "tw_func.h"
|
||||
#include "tw_util.h"
|
||||
|
||||
/* File variables */
|
||||
static FILE *outputFile = NULL;
|
||||
extern pTW_SESSION twSession;
|
||||
|
||||
/*
|
||||
* dumpPreTransferCallback
|
||||
*
|
||||
* This callback function is called before any images
|
||||
* are transferred. Set up the one time only stuff.
|
||||
*/
|
||||
void
|
||||
dumpPreTransferCallback(void *clientData)
|
||||
{
|
||||
/* Open our output file... Not settable... Always
|
||||
* write to the root directory. Simplistic, but
|
||||
* gets the job done.
|
||||
*/
|
||||
outputFile = g_fopen(DUMP_FILE, "wb");
|
||||
}
|
||||
|
||||
/*
|
||||
* dumpBeginTransferCallback
|
||||
*
|
||||
* The following function is called at the beginning
|
||||
* of each image transfer.
|
||||
*/
|
||||
int
|
||||
dumpBeginTransferCallback(pTW_IMAGEINFO imageInfo, void *clientData)
|
||||
{
|
||||
logBegin(imageInfo, clientData);
|
||||
|
||||
/* Dump the image information */
|
||||
fwrite((void *) imageInfo, sizeof(TW_IMAGEINFO), 1, outputFile);
|
||||
|
||||
/* Keep going */
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* dumpDataTransferCallback
|
||||
*
|
||||
* The following function is called for each memory
|
||||
* block that is transferred from the data source.
|
||||
*/
|
||||
int
|
||||
dumpDataTransferCallback(pTW_IMAGEINFO imageInfo,
|
||||
pTW_IMAGEMEMXFER imageMemXfer,
|
||||
void *clientData)
|
||||
{
|
||||
int flag = 1;
|
||||
|
||||
logData(imageInfo, imageMemXfer, clientData);
|
||||
|
||||
/* Write a flag that says that this is a data packet */
|
||||
fwrite((void *) &flag, sizeof(int), 1, outputFile);
|
||||
|
||||
/* Dump the memory information */
|
||||
fwrite((void *) imageMemXfer, sizeof(TW_IMAGEMEMXFER), 1, outputFile);
|
||||
fwrite((void *) imageMemXfer->Memory.TheMem,
|
||||
1, imageMemXfer->BytesWritten, outputFile);
|
||||
|
||||
/* Keep going */
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* dumpEndTransferCallback
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
int
|
||||
dumpEndTransferCallback(int completionState, int pendingCount, void *clientData)
|
||||
{
|
||||
int flag = 0;
|
||||
|
||||
/* Write a flag that says that this is a data packet */
|
||||
fwrite((void *) &flag, sizeof(int), 1, outputFile);
|
||||
|
||||
/* Write the necessary data */
|
||||
fwrite(&completionState, sizeof(int), 1, outputFile);
|
||||
fwrite(&pendingCount, sizeof(int), 1, outputFile);
|
||||
|
||||
/* Only ever transfer a single image */
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* dumpPostTransferCallback
|
||||
*
|
||||
* This callback function will be called
|
||||
* after all possible images have been
|
||||
* transferred.
|
||||
*/
|
||||
void
|
||||
dumpPostTransferCallback(int pendingCount, void *clientData)
|
||||
{
|
||||
char buffer[128];
|
||||
|
||||
/* 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);
|
||||
|
||||
/* Close the dump file */
|
||||
fclose(outputFile);
|
||||
|
||||
/* Tell the user */
|
||||
sprintf(buffer, "Image dumped to file %s\n", DUMP_FILE);
|
||||
gimp_message(buffer);
|
||||
|
||||
/* Post a message to close up the application */
|
||||
twainQuitApplication ();
|
||||
}
|
||||
|
||||
/*
|
||||
* readDumpedImage
|
||||
*
|
||||
* Get a previously dumped image.
|
||||
*/
|
||||
void readDumpedImage(pTW_SESSION twSession)
|
||||
{
|
||||
int moreData;
|
||||
int completionState;
|
||||
int pendingCount;
|
||||
|
||||
TW_IMAGEINFO imageInfo;
|
||||
TW_IMAGEMEMXFER imageMemXfer;
|
||||
|
||||
/* Open our output file... Not settable... Always
|
||||
* write to the root directory. Simplistic, but
|
||||
* gets the job done.
|
||||
*/
|
||||
FILE *inputFile = g_fopen(DUMP_FILE, "rb");
|
||||
|
||||
/*
|
||||
* Inform our application that we are getting ready
|
||||
* to transfer images.
|
||||
*/
|
||||
(*twSession->transferFunctions->preTxfrCb)(NULL);
|
||||
|
||||
/* Read the image information */
|
||||
fread((void *) &imageInfo, sizeof(TW_IMAGEINFO), 1, inputFile);
|
||||
|
||||
/* Call the begin transfer callback */
|
||||
if (!(*twSession->transferFunctions->txfrBeginCb)(&imageInfo, twSession->clientData))
|
||||
return;
|
||||
|
||||
/* Read all of the data packets */
|
||||
fread((void *) &moreData, sizeof(int), 1, inputFile);
|
||||
while (moreData) {
|
||||
/* Read the memory information */
|
||||
fread((void *) &imageMemXfer, sizeof(TW_IMAGEMEMXFER), 1, inputFile);
|
||||
imageMemXfer.Memory.TheMem = (TW_MEMREF) g_malloc (imageMemXfer.BytesWritten);
|
||||
fread((void *) imageMemXfer.Memory.TheMem,
|
||||
1, imageMemXfer.BytesWritten, inputFile);
|
||||
|
||||
/* Call the data transfer callback function */
|
||||
if (!(*twSession->transferFunctions->txfrDataCb)
|
||||
(&imageInfo,
|
||||
&imageMemXfer,
|
||||
twSession->clientData))
|
||||
return;
|
||||
|
||||
/* Clean up the memory */
|
||||
g_free (imageMemXfer.Memory.TheMem);
|
||||
|
||||
/* Check for continuation */
|
||||
fread((void *) &moreData, sizeof(int), 1, inputFile);
|
||||
}
|
||||
|
||||
/* Grab the final information */
|
||||
fread(&completionState, sizeof(int), 1, inputFile);
|
||||
fread(&pendingCount, sizeof(int), 1, inputFile);
|
||||
|
||||
if (twSession->transferFunctions->txfrEndCb)
|
||||
(*twSession->transferFunctions->txfrEndCb)(completionState, 0,
|
||||
twSession->clientData);
|
||||
|
||||
/* Post a message to close up the application */
|
||||
twainQuitApplication ();
|
||||
}
|
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* TWAIN Plug-in
|
||||
* Copyright (C) 1999 Craig Setera
|
||||
* Craig Setera <setera@home.com>
|
||||
* 03/31/1999
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
* Based on (at least) the following plug-ins:
|
||||
* Screenshot
|
||||
* GIF
|
||||
* Randomize
|
||||
*
|
||||
* Any suggestions, bug-reports or patches are welcome.
|
||||
*
|
||||
* This plug-in interfaces to the TWAIN support library in order
|
||||
* to capture images from TWAIN devices directly into GIMP images.
|
||||
* The plug-in is capable of acquiring the following type of
|
||||
* images:
|
||||
* - B/W (1 bit images translated to grayscale B/W)
|
||||
* - Grayscale up to 16 bits per pixel
|
||||
* - RGB up to 16 bits per sample (24, 30, 36, etc.)
|
||||
* - Paletted images (both Gray and RGB)
|
||||
*
|
||||
* Prerequisites:
|
||||
* This plug-in will not compile on anything other than a Win32
|
||||
* platform. Although the TWAIN documentation implies that there
|
||||
* is TWAIN support available on Macintosh, I neither have a
|
||||
* Macintosh nor the interest in porting this. If anyone else
|
||||
* has an interest, consult www.twain.org for more information on
|
||||
* interfacing to TWAIN.
|
||||
*
|
||||
* Known problems:
|
||||
* - Multiple image transfers will hang the plug-in. The current
|
||||
* configuration compiles with a maximum of single image transfers.
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "tw_platform.h"
|
||||
#include "tw_func.h"
|
||||
|
||||
void dumpPreTransferCallback(void *clientData);
|
||||
int dumpBeginTransferCallback(pTW_IMAGEINFO imageInfo, void *clientData);
|
||||
int dumpDataTransferCallback(pTW_IMAGEINFO imageInfo,
|
||||
pTW_IMAGEMEMXFER imageMemXfer,
|
||||
void *clientData);
|
||||
int dumpEndTransferCallback(int completionState, int pendingCount, void *clientData);
|
||||
void dumpPostTransferCallback(int pendingCount, void *clientData);
|
||||
void readDumpedImage(pTW_SESSION twSession);
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -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
|
||||
*
|
||||
@@ -144,6 +146,11 @@ typedef struct _TXFR_CB_FUNCS {
|
||||
TW_POST_TXFR_CB postTxfrCb;
|
||||
} TXFR_CB_FUNCS, *pTXFR_CB_FUNCS;
|
||||
|
||||
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,60 +191,127 @@ typedef struct _TWAIN_SESSION {
|
||||
*/
|
||||
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;
|
||||
|
||||
#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)
|
||||
|
||||
/* 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(s) ((s == NULL) ? NULL : s->appIdentity)
|
||||
#define DS_IDENTITY(s) ((s == NULL) ? NULL : s->dsIdentity)
|
||||
|
||||
/* 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(s) ((s == NULL) ? FALSE : s->twainState >= 2)
|
||||
#define TWAIN_UNLOADED(s) ((s == NULL) ? TRUE : s->twainState < 2)
|
||||
#define DSM_IS_OPEN(s) ((s == NULL) ? FALSE : s->twainState >= 3)
|
||||
#define DSM_IS_CLOSED(s) ((s == NULL) ? TRUE : s->twainState < 3)
|
||||
#define DS_IS_OPEN(s) ((s == NULL) ? FALSE : s->twainState >= 4)
|
||||
#define DS_IS_CLOSED(s) ((s == NULL) ? TRUE : s->twainState < 4)
|
||||
#define DS_IS_ENABLED(s) ((s == NULL) ? FALSE : s->twainState >= 5)
|
||||
#define DS_IS_DISABLED(s) ((s == NULL) ? TRUE : s->twainState < 5)
|
||||
|
||||
#define DSM_GET_STATUS(ses, sta) callDSM(ses->appIdentity, ses->dsIdentity, \
|
||||
DG_CONTROL, DAT_STATUS, MSG_GET, (TW_MEMREF) &sta)
|
||||
|
||||
#define DSM_OPEN(ses) callDSM(ses->appIdentity, NULL,\
|
||||
DG_CONTROL, DAT_PARENT, MSG_OPENDSM, (TW_MEMREF) &(ses->hwnd))
|
||||
|
||||
#define DSM_CLOSE(ses) callDSM(ses->appIdentity, NULL,\
|
||||
DG_CONTROL, DAT_PARENT, MSG_CLOSEDSM, (TW_MEMREF)&(ses->hwnd))
|
||||
|
||||
#define DSM_SET_CALLBACK(ses, cb) callDSM(ses->appIdentity, NULL,\
|
||||
DG_CONTROL, DAT_CALLBACK, MSG_REGISTER_CALLBACK, (TW_MEMREF) &cb)
|
||||
|
||||
#define DSM_PROCESS_EVENT(ses, ev) callDSM(ses->appIdentity, ses->dsIdentity,\
|
||||
DG_CONTROL, DAT_EVENT, MSG_PROCESSEVENT, (TW_MEMREF) &ev)
|
||||
|
||||
#define DSM_GET_PALETTE(ses, d) callDSM(ses->appIdentity, ses->dsIdentity,\
|
||||
DG_IMAGE, DAT_PALETTE8, MSG_GET, (TW_MEMREF) d->paletteData)
|
||||
|
||||
#define DSM_SELECT_USER(ses) callDSM(ses->appIdentity, NULL,\
|
||||
DG_CONTROL, DAT_IDENTITY, MSG_USERSELECT, (TW_MEMREF) ses->dsIdentity)
|
||||
|
||||
#define DSM_SELECT_DEFAULT(ses) callDSM(ses->appIdentity, NULL,\
|
||||
DG_CONTROL, DAT_IDENTITY, MSG_GETDEFAULT, (TW_MEMREF) ses->dsIdentity)
|
||||
|
||||
#define DSM_OPEN_DS(ses) callDSM(ses->appIdentity, NULL,\
|
||||
DG_CONTROL, DAT_IDENTITY, MSG_OPENDS, (TW_MEMREF) ses->dsIdentity)
|
||||
|
||||
#define DSM_CLOSE_DS(ses) callDSM(ses->appIdentity, NULL,\
|
||||
DG_CONTROL, DAT_IDENTITY, MSG_CLOSEDS, (TW_MEMREF) ses->dsIdentity)
|
||||
|
||||
#define DSM_ENABLE_DS(ses, ui) callDSM(ses->appIdentity, ses->dsIdentity,\
|
||||
DG_CONTROL, DAT_USERINTERFACE, MSG_ENABLEDS, (TW_MEMREF) &ui)
|
||||
|
||||
#define DSM_DISABLE_DS(ses, ui) callDSM(ses->appIdentity, ses->dsIdentity,\
|
||||
DG_CONTROL, DAT_USERINTERFACE, MSG_DISABLEDS, (TW_MEMREF) &ui)
|
||||
|
||||
#define DSM_GET_IMAGE(ses, i) callDSM(ses->appIdentity, ses->dsIdentity,\
|
||||
DG_IMAGE, DAT_IMAGEINFO, MSG_GET, (TW_MEMREF) i)
|
||||
|
||||
#define DSM_XFER_SET(ses, x) callDSM(ses->appIdentity, ses->dsIdentity,\
|
||||
DG_CONTROL, DAT_CAPABILITY, MSG_SET, (TW_MEMREF) &x)
|
||||
|
||||
#define DSM_XFER_START(ses, x) callDSM(ses->appIdentity, ses->dsIdentity,\
|
||||
DG_CONTROL, DAT_SETUPMEMXFER, MSG_GET, (TW_MEMREF) &x)
|
||||
|
||||
#define DSM_XFER_GET(ses, x) callDSM(ses->appIdentity, ses->dsIdentity,\
|
||||
DG_IMAGE, DAT_IMAGEMEMXFER, MSG_GET, (TW_MEMREF) &x)
|
||||
|
||||
#define DSM_XFER_STOP(ses, x) callDSM(ses->appIdentity, ses->dsIdentity,\
|
||||
DG_CONTROL, DAT_PENDINGXFERS, MSG_ENDXFER, (TW_MEMREF) &x)
|
||||
|
||||
#define DSM_XFER_RESET(ses, x) callDSM(ses->appIdentity, ses->dsIdentity,\
|
||||
DG_CONTROL, DAT_PENDINGXFERS, MSG_RESET, (TW_MEMREF) &x)
|
||||
|
||||
#define DSM_GET_FIRST_DS(ses, ds) callDSM (ses->appIdentity, NULL, \
|
||||
DG_CONTROL, DAT_IDENTITY, MSG_GETFIRST, (TW_MEMREF) ds);
|
||||
|
||||
#define DSM_GET_NEXT_DS(ses, ds) callDSM (ses->appIdentity, NULL, \
|
||||
DG_CONTROL, DAT_IDENTITY, MSG_GETNEXT, (TW_MEMREF) ds);
|
||||
|
||||
/* Function declarations */
|
||||
char *twainError(int);
|
||||
char *currentTwainError(pTW_SESSION);
|
||||
int getImage(pTW_SESSION);
|
||||
int loadTwainLibrary(pTW_SESSION);
|
||||
int unloadTwainLibrary(pTW_SESSION twSession);
|
||||
int openDSM(pTW_SESSION);
|
||||
int selectDS(pTW_SESSION);
|
||||
int selectDefaultDS(pTW_SESSION);
|
||||
int openDS(pTW_SESSION);
|
||||
int requestImageAcquire(pTW_SESSION, gboolean);
|
||||
int disableDS(pTW_SESSION);
|
||||
int closeDS(pTW_SESSION);
|
||||
int closeDSM(pTW_SESSION);
|
||||
void cancelPendingTransfers(pTW_SESSION);
|
||||
int scanImage (void);
|
||||
|
||||
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);
|
||||
pTW_SESSION initializeTwain(void);
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
void LogLastWinError(void);
|
||||
BOOL InitApplication(HINSTANCE hInstance);
|
||||
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow, pTW_SESSION twSession);
|
||||
#endif
|
||||
char * twainError (int errorCode);
|
||||
char * currentTwainError (pTW_SESSION twSession);
|
||||
int getImage (pTW_SESSION twSession);
|
||||
int loadTwainLibrary (pTW_SESSION twSession);
|
||||
void unloadTwainLibrary (pTW_SESSION twSession);
|
||||
int openDSM (pTW_SESSION twSession);
|
||||
int selectDS (pTW_SESSION twSession);
|
||||
int openDS (pTW_SESSION twSession);
|
||||
int requestImageAcquire (pTW_SESSION twSession, gboolean showUI);
|
||||
void disableDS (pTW_SESSION twSession);
|
||||
void closeDS (pTW_SESSION twSession);
|
||||
void closeDSM (pTW_SESSION twSession);
|
||||
void cancelPendingTransfers (pTW_SESSION twSession);
|
||||
void processTwainMessage (TW_UINT16 message, pTW_SESSION twSession);
|
||||
pTW_SESSION newSession (pTW_IDENTITY twSession);
|
||||
pTW_DATA_SOURCE get_available_ds (pTW_SESSION twSession);
|
||||
int adjust_selected_data_source (pTW_SESSION twSession);
|
||||
|
||||
#endif /* _TW_FUNC_H */
|
||||
|
@@ -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,27 +26,77 @@
|
||||
* 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"
|
||||
/*
|
||||
* 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" }
|
||||
|
||||
/*
|
||||
* Application definitions
|
||||
*/
|
||||
#define MAX_IMAGES 1
|
||||
|
||||
/* Functions which the platform-independent code will call */
|
||||
TW_UINT16 callDSM (
|
||||
pTW_IDENTITY pOrigin,
|
||||
pTW_IDENTITY pDest,
|
||||
TW_UINT32 DG,
|
||||
TW_UINT16 DAT,
|
||||
TW_UINT16 MSG,
|
||||
TW_MEMREF pData);
|
||||
|
||||
TW_UINT16 callDSM(pTW_IDENTITY, pTW_IDENTITY,
|
||||
TW_UINT32, TW_UINT16,
|
||||
TW_UINT16, TW_MEMREF);
|
||||
|
||||
int twainIsAvailable(void);
|
||||
void twainQuitApplication (void);
|
||||
gboolean twainSetupCallback (pTW_SESSION twSession);
|
||||
int twainIsAvailable(void);
|
||||
void twainQuitApplication (void);
|
||||
gboolean twainSetupCallback (pTW_SESSION twSession);
|
||||
|
||||
TW_HANDLE twainAllocHandle(size_t size);
|
||||
TW_MEMREF twainLockHandle (TW_HANDLE handle);
|
||||
void twainUnlockHandle (TW_HANDLE handle);
|
||||
void twainFreeHandle (TW_HANDLE handle);
|
||||
void twainUnlockHandle (TW_HANDLE handle);
|
||||
void twainFreeHandle (TW_HANDLE handle);
|
||||
|
||||
int twainMain (void);
|
||||
int scanImage (void);
|
||||
int twainMain (const gchar *name);
|
||||
int scanImage (void);
|
||||
pTW_SESSION initializeTwain (void);
|
||||
|
||||
#endif
|
||||
void preTransferCallback (void *);
|
||||
int beginTransferCallback (pTW_IMAGEINFO, void *);
|
||||
int dataTransferCallback (pTW_IMAGEINFO, pTW_IMAGEMEMXFER, void *);
|
||||
int endTransferCallback (int, int, void *);
|
||||
void postTransferCallback (int, void *);
|
||||
void register_menu (pTW_IDENTITY dsIdentity);
|
||||
void register_scanner_menus (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;
|
||||
#endif /* _TW_LOCAL_H */
|
||||
|
@@ -4,6 +4,10 @@
|
||||
* Craig Setera <setera@home.com>
|
||||
* 03/31/1999
|
||||
*
|
||||
* 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
|
||||
@@ -18,20 +22,58 @@
|
||||
* 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_PLATFORM_H
|
||||
#define _TW_PLATFORM_H
|
||||
#define _TW_PLATFORM_H
|
||||
|
||||
#include <windows.h>
|
||||
#include "twain.h"
|
||||
/* Coding style violation: Don't include headers in headers */
|
||||
#include <windows.h>
|
||||
/* Coding style violation: Don't include headers in headers */
|
||||
#include "twain.h"
|
||||
|
||||
/* The DLL to be loaded for TWAIN support */
|
||||
#define TWAIN_DLL_NAME "TWAIN_32.DLL"
|
||||
#define DEBUG_LOGFILE "c:\\twain.log"
|
||||
#define DUMP_FILE "C:\\TWAINCAP.BIN"
|
||||
#define DUMP_NAME "DTWAIN.EXE"
|
||||
#define READDUMP_NAME "RTWAIN.EXE"
|
||||
/* 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 /* TWH_64BIT */
|
||||
|
||||
/* Windows uses separate entry point */
|
||||
#define TWAIN_ALTERNATE_MAIN
|
||||
/* Windows uses separate entry point */
|
||||
#define TWAIN_ALTERNATE_MAIN
|
||||
|
||||
/*
|
||||
* Plug-in Definitions
|
||||
*/
|
||||
#define STRINGIFY(x) #x
|
||||
#define TOSTRING(x) STRINGIFY(x)
|
||||
|
||||
#define PRODUCT_FAMILY "GNU"
|
||||
#define PRODUCT_NAME "GIMP"
|
||||
#define PLUG_IN_NAME "TWAIN"
|
||||
#define PLUG_IN_DESCRIPTION N_("Capture an image from a TWAIN datasource")
|
||||
#define PLUG_IN_HELP "This plug-in will capture an image from a TWAIN datasource.\n" \
|
||||
"Recent changes:\n" \
|
||||
" - Support of Win 64 Bit (requires twaindsm.dll from twain.org)\n" \
|
||||
" - Fixed bug while scanning multiple images\n" \
|
||||
" - Added easy Scanner access"
|
||||
#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"
|
||||
#define MP_SELECT "<Image>/File/Create/Acquire"
|
||||
#endif
|
||||
|
@@ -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"
|
||||
@@ -68,103 +73,21 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#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
|
||||
|
||||
/*
|
||||
* 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);
|
||||
va_start (args, format);
|
||||
g_message (format, args);
|
||||
va_end (args);
|
||||
return;
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
if (i != 7)
|
||||
strcat(buffer, ",");
|
||||
}
|
||||
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 */
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/*
|
||||
* LogMessage
|
||||
*/
|
||||
void
|
||||
LogMessage(char *format, ...)
|
||||
{
|
||||
}
|
||||
|
||||
#endif /* DEBUG */
|
||||
|
@@ -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,13 @@
|
||||
* (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"
|
||||
#define FIX32_TO_FLOAT(f) ((float) f.Whole + (float) f.Frac / 65536.0f)
|
||||
|
||||
void LogMessage(char *, ...);
|
||||
|
||||
#ifdef _DEBUG
|
||||
void logBegin(pTW_IMAGEINFO, void *);
|
||||
void logData(pTW_IMAGEINFO, pTW_IMAGEMEMXFER, void *);
|
||||
#endif
|
||||
void log_message (char *format, ...);
|
||||
|
||||
#endif /* __TW_UTIL_H */
|
||||
|
@@ -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,6 +26,17 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Revision history
|
||||
* (02/07/99) v0.1 First working version (internal)
|
||||
* (02/09/99) v0.2 First release to anyone other than myself
|
||||
* (02/15/99) v0.3 Added image dump and read support for debugging
|
||||
* (03/31/99) v0.5 Added support for multi-byte samples and paletted
|
||||
* images.
|
||||
* (07/23/04) v0.6 Added Mac OS X support.
|
||||
* (11/25/11) v0.7 Added Win x64 support, changed data source selection.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Windows platform-specific code
|
||||
*/
|
||||
@@ -34,46 +49,33 @@
|
||||
#include "tw_func.h"
|
||||
#include "tw_util.h"
|
||||
#include "tw_local.h"
|
||||
#include "tw_win.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)
|
||||
#define DLL_NOT_FOUND "Can't load library \"" TWAIN_DLL_NAME "\"!\nPlease install 'TWAIN Data Source Manager' from www.twain.org.\n"
|
||||
|
||||
/* main bits */
|
||||
static HWND hwnd = NULL;
|
||||
static HINSTANCE hInst = NULL;
|
||||
static HWND hwnd = NULL;
|
||||
static HINSTANCE hInst = NULL;
|
||||
|
||||
/* Storage for the DLL handle */
|
||||
static HINSTANCE hDLL = NULL;
|
||||
static HINSTANCE hDLL = NULL;
|
||||
|
||||
/* 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,
|
||||
pTW_IDENTITY pDest,
|
||||
TW_UINT32 DG,
|
||||
TW_UINT16 DAT,
|
||||
TW_UINT16 MSG,
|
||||
TW_MEMREF pData)
|
||||
callDSM (
|
||||
pTW_IDENTITY pOrigin,
|
||||
pTW_IDENTITY pDest,
|
||||
TW_UINT32 DG,
|
||||
TW_UINT16 DAT,
|
||||
TW_UINT16 MSG,
|
||||
TW_MEMREF pData)
|
||||
{
|
||||
/* Call the function */
|
||||
return (*dsmEntryPoint) (pOrigin, pDest, DG, DAT, MSG, pData);
|
||||
@@ -85,22 +87,27 @@ callDSM(pTW_IDENTITY pOrigin,
|
||||
* Return boolean indicating whether TWAIN is available
|
||||
*/
|
||||
int
|
||||
twainIsAvailable(void)
|
||||
twainIsAvailable (void)
|
||||
{
|
||||
/* Already loaded? */
|
||||
if (dsmEntryPoint) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Attempt to load the library */
|
||||
hDLL = LoadLibrary(TWAIN_DLL_NAME);
|
||||
if (hDLL == NULL)
|
||||
return FALSE;
|
||||
|
||||
/* Look up the entry point for use */
|
||||
dsmEntryPoint = (DSMENTRYPROC) GetProcAddress(hDLL, "DSM_Entry");
|
||||
if (dsmEntryPoint == NULL)
|
||||
return FALSE;
|
||||
{
|
||||
/* Attempt to load the library */
|
||||
hDLL = LoadLibrary (TWAIN_DLL_NAME);
|
||||
if (hDLL == NULL)
|
||||
{
|
||||
g_message (DLL_NOT_FOUND);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Look up the entry point for use */
|
||||
dsmEntryPoint = (DSMENTRYPROC) GetProcAddress (hDLL, "DSM_Entry");
|
||||
if (dsmEntryPoint == NULL)
|
||||
{
|
||||
g_message ("Lirary has no DSM Entry point.\n");
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@@ -108,7 +115,7 @@ twainIsAvailable(void)
|
||||
TW_HANDLE
|
||||
twainAllocHandle (size_t size)
|
||||
{
|
||||
return GlobalAlloc(GHND, size);
|
||||
return GlobalAlloc (GHND, size);
|
||||
}
|
||||
|
||||
TW_MEMREF
|
||||
@@ -141,26 +148,27 @@ twainSetupCallback (pTW_SESSION twSession)
|
||||
*
|
||||
* 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;
|
||||
}
|
||||
|
||||
/* the data source id will no longer be valid after
|
||||
* twain is killed. If the id is left around the
|
||||
* data source can not be found or opened
|
||||
*/
|
||||
DS_IDENTITY(twSession)->Id = 0;
|
||||
if (twSession != NULL)
|
||||
{
|
||||
/* the data source id will no longer be valid after
|
||||
* twain is killed. If the id is left around the
|
||||
* data source can not be found or opened
|
||||
*/
|
||||
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 = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -170,32 +178,32 @@ unloadTwainLibrary(pTW_SESSION twSession)
|
||||
* Returns FALSE if the application should skip processing of this message
|
||||
*/
|
||||
int
|
||||
TwainProcessMessage(LPMSG lpMsg, pTW_SESSION twSession)
|
||||
TwainProcessMessage (LPMSG lpMsg, pTW_SESSION twSession)
|
||||
{
|
||||
TW_EVENT twEvent;
|
||||
TW_EVENT twEvent;
|
||||
|
||||
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)) {
|
||||
/*
|
||||
* A Source provides a modeless dialog box as its user interface.
|
||||
* The following call relays Windows messages down to the Source's
|
||||
* UI that were intended for its dialog box. It also retrieves TWAIN
|
||||
* 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);
|
||||
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
|
||||
* UI that were intended for its dialog box. It also retrieves TWAIN
|
||||
* messages sent from the Source to our Application.
|
||||
*/
|
||||
twEvent.pEvent = (TW_MEMREF) lpMsg;
|
||||
twSession->twRC = DSM_PROCESS_EVENT(twSession, twEvent);
|
||||
|
||||
/* Check the return code */
|
||||
if (twSession->twRC == TWRC_NOTDSEVENT) {
|
||||
return FALSE;
|
||||
}
|
||||
/* Check the return code */
|
||||
if (twSession->twRC == TWRC_NOTDSEVENT)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Process the message as necessary */
|
||||
processTwainMessage(twEvent.TWMessage, twSession);
|
||||
/* Process the message as necessary */
|
||||
processTwainMessage (twEvent.TWMessage, twSession);
|
||||
}
|
||||
|
||||
/* tell the caller what happened */
|
||||
@@ -210,14 +218,16 @@ TwainProcessMessage(LPMSG lpMsg, pTW_SESSION twSession)
|
||||
* 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))
|
||||
{
|
||||
if (DS_IS_CLOSED(twSession) || !TwainProcessMessage (&msg, twSession))
|
||||
{
|
||||
TranslateMessage ((LPMSG) &msg);
|
||||
DispatchMessage (&msg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,29 +241,30 @@ twainMessageLoop(pTW_SESSION twSession)
|
||||
* GetLastError.
|
||||
*/
|
||||
void
|
||||
LogLastWinError(void)
|
||||
LogLastWinError (void)
|
||||
{
|
||||
LPVOID lpMsgBuf;
|
||||
LPVOID lpMsgBuf;
|
||||
|
||||
FormatMessage(
|
||||
FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL,
|
||||
GetLastError(),
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
|
||||
(LPTSTR) &lpMsgBuf,
|
||||
0,
|
||||
NULL
|
||||
);
|
||||
FormatMessage (
|
||||
FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL,
|
||||
GetLastError (),
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
|
||||
(LPTSTR) &lpMsgBuf,
|
||||
0,
|
||||
NULL
|
||||
);
|
||||
|
||||
LogMessage("%s\n", lpMsgBuf);
|
||||
g_message ("%s\n", (LPTSTR) lpMsgBuf);
|
||||
|
||||
/* Free the buffer. */
|
||||
LocalFree( lpMsgBuf );
|
||||
/* Free the buffer. */
|
||||
LocalFree ( lpMsgBuf );
|
||||
}
|
||||
|
||||
void twainQuitApplication ()
|
||||
void
|
||||
twainQuitApplication (void)
|
||||
{
|
||||
PostQuitMessage (0);
|
||||
}
|
||||
@@ -273,10 +284,11 @@ void twainQuitApplication ()
|
||||
* datasource.
|
||||
*/
|
||||
int APIENTRY
|
||||
WinMain(HINSTANCE hInstance,
|
||||
HINSTANCE hPrevInstance,
|
||||
LPSTR lpCmdLine,
|
||||
int nCmdShow)
|
||||
WinMain (
|
||||
HINSTANCE hInstance,
|
||||
HINSTANCE hPrevInstance,
|
||||
LPSTR lpCmdLine,
|
||||
int nCmdShow)
|
||||
{
|
||||
|
||||
/*
|
||||
@@ -290,18 +302,11 @@ WinMain(HINSTANCE hInstance,
|
||||
*/
|
||||
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 +314,14 @@ WinMain(HINSTANCE hInstance,
|
||||
*
|
||||
* 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);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -331,7 +330,7 @@ int main (int argc, char *argv[])
|
||||
* Initialize window data and register the window class
|
||||
*/
|
||||
BOOL
|
||||
InitApplication(HINSTANCE hInstance)
|
||||
InitApplication (HINSTANCE hInstance)
|
||||
{
|
||||
WNDCLASS wc;
|
||||
BOOL retValue;
|
||||
@@ -345,18 +344,20 @@ InitApplication(HINSTANCE hInstance)
|
||||
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,27 +369,29 @@ InitApplication(HINSTANCE hInstance)
|
||||
* 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,
|
||||
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
|
||||
NULL, NULL, hInstance, NULL);
|
||||
hwnd = CreateWindow (PLUG_IN_NAME, PLUG_IN_NAME, WS_OVERLAPPEDWINDOW,
|
||||
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
|
||||
NULL, NULL, hInstance, NULL);
|
||||
|
||||
if (!hwnd) {
|
||||
if (!hwnd)
|
||||
{
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
/* 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);
|
||||
UpdateWindow(hwnd);
|
||||
ShowWindow (hwnd, nCmdShow);
|
||||
|
||||
UpdateWindow (hwnd);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@@ -403,25 +406,31 @@ InitInstance(HINSTANCE hInstance, int nCmdShow, pTW_SESSION twSession)
|
||||
* operate.
|
||||
*/
|
||||
int
|
||||
twainMain()
|
||||
twainMain (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...
|
||||
* This call will not return until the application
|
||||
* exits.
|
||||
*/
|
||||
return twainMessageLoop(twSession);
|
||||
return twainMessageLoop (twSession);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -430,23 +439,23 @@ twainMain()
|
||||
* 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) {
|
||||
switch (message)
|
||||
{
|
||||
case WM_TRANSFER_IMAGE:
|
||||
/* Get an image */
|
||||
scanImage ();
|
||||
break;
|
||||
|
||||
case WM_TRANSFER_IMAGE:
|
||||
/* Get an image */
|
||||
scanImage ();
|
||||
break;
|
||||
case WM_DESTROY:
|
||||
PostQuitMessage (0);
|
||||
break;
|
||||
|
||||
case WM_DESTROY:
|
||||
LogMessage("Exiting application\n");
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
|
||||
default:
|
||||
return (DefWindowProc(hWnd, message, wParam, lParam));
|
||||
default:
|
||||
return (DefWindowProc (hWnd, message, wParam, lParam));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
69
plug-ins/twain/tw_win.h
Normal file
69
plug-ins/twain/tw_win.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* TWAIN Plug-in
|
||||
* Copyright (C) 1999 Craig Setera
|
||||
* Craig Setera <setera@home.com>
|
||||
* 03/31/1999
|
||||
*
|
||||
* Updated for Mac OS X support
|
||||
* Brion Vibber <brion@pobox.com>
|
||||
* 07/22/2004
|
||||
*
|
||||
* Added for Win x64 support, changed data source selection.
|
||||
* Jens M. Plonka <jens.plonka@gmx.de>
|
||||
* 11/25/2011
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Revision history
|
||||
* (02/07/99) v0.1 First working version (internal)
|
||||
* (02/09/99) v0.2 First release to anyone other than myself
|
||||
* (02/15/99) v0.3 Added image dump and read support for debugging
|
||||
* (03/31/99) v0.5 Added support for multi-byte samples and paletted
|
||||
* images.
|
||||
* (07/23/04) v0.6 Added Mac OS X support.
|
||||
* (11/25/11) v0.7 Added Win x64 support, changed data source selection.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Windows platform-specific code
|
||||
*/
|
||||
#ifndef _TW_WIN_H
|
||||
#define _TW_WIN_H
|
||||
|
||||
#define SHOW_WINDOW 0
|
||||
#define WM_TRANSFER_IMAGE (WM_USER + 100)
|
||||
|
||||
TW_UINT16 callDSM (
|
||||
pTW_IDENTITY pOrigin,
|
||||
pTW_IDENTITY pDest,
|
||||
TW_UINT32 DG,
|
||||
TW_UINT16 DAT,
|
||||
TW_UINT16 MSG,
|
||||
TW_MEMREF pData);
|
||||
|
||||
extern GimpPlugInInfo PLUG_IN_INFO;
|
||||
|
||||
LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
|
||||
int twainMessageLoop (pTW_SESSION);
|
||||
int TwainProcessMessage (LPMSG lpMsg, pTW_SESSION twSession);
|
||||
void LogLastWinError (void);
|
||||
void twainQuitApplication (void);
|
||||
BOOL InitApplication (HINSTANCE hInstance);
|
||||
BOOL InitInstance (HINSTANCE hInstance, int nCmdShow, pTW_SESSION twSession);
|
||||
int twainMain (const gchar *name);
|
||||
extern pTW_SESSION initializeTwain (void);
|
||||
|
||||
#endif /* _TW_WIN_H */
|
BIN
plug-ins/twain/twain-menu.png
Normal file
BIN
plug-ins/twain/twain-menu.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 682 B |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user