|
From: <mi...@us...> - 2009-12-22 19:41:06
|
Revision: 65
http://twain-samples.svn.sourceforge.net/twain-samples/?rev=65&view=rev
Author: mihailm
Date: 2009-12-22 19:40:56 +0000 (Tue, 22 Dec 2009)
Log Message:
-----------
Linux compatible
Multi-page TIFF just one file for all pages
Initialize capability containers
Free some resources
Modified Paths:
--------------
trunk/TWAIN-Samples/Twain_App_sample01/src/DSMInterface.cpp
trunk/TWAIN-Samples/Twain_App_sample01/src/TwainApp.cpp
trunk/TWAIN-Samples/Twain_App_sample01/src/TwainAppCMD.cpp
trunk/TWAIN-Samples/Twain_App_sample01/src/TwainAppCMD.h
trunk/TWAIN-Samples/Twain_App_sample01/src/src.pro
Modified: trunk/TWAIN-Samples/Twain_App_sample01/src/DSMInterface.cpp
===================================================================
--- trunk/TWAIN-Samples/Twain_App_sample01/src/DSMInterface.cpp 2009-12-22 19:38:04 UTC (rev 64)
+++ trunk/TWAIN-Samples/Twain_App_sample01/src/DSMInterface.cpp 2009-12-22 19:40:56 UTC (rev 65)
@@ -79,9 +79,9 @@
{
TW_UINT16 ret = TWRC_FAILURE;
- if((0 == gpDSM) && !LoadDSMLib(kTWAIN_DS_DIR kTWAIN_DSM_DLL_NAME))
+ if((0 == gpDSM) && !LoadDSMLib(kTWAIN_DSM_DIR kTWAIN_DSM_DLL_NAME))
{
- cerr << "Could not load the DSM: " << kTWAIN_DS_DIR kTWAIN_DSM_DLL_NAME << endl;
+ cerr << "Could not load the DSM: " << kTWAIN_DSM_DIR kTWAIN_DSM_DLL_NAME << endl;
return 0; /*< return 0. @todo are we sure of this return? */
}
Modified: trunk/TWAIN-Samples/Twain_App_sample01/src/TwainApp.cpp
===================================================================
--- trunk/TWAIN-Samples/Twain_App_sample01/src/TwainApp.cpp 2009-12-22 19:38:04 UTC (rev 64)
+++ trunk/TWAIN-Samples/Twain_App_sample01/src/TwainApp.cpp 2009-12-22 19:40:56 UTC (rev 65)
@@ -229,10 +229,10 @@
return;
}
- if(!LoadDSMLib(kTWAIN_DS_DIR kTWAIN_DSM_DLL_NAME))
+ if(!LoadDSMLib(kTWAIN_DSM_DIR kTWAIN_DSM_DLL_NAME))
{
PrintCMDMessage("The DSM could not be opened. Please ensure that it is installed into a directory that is in the library path:");
- PrintCMDMessage(kTWAIN_DS_DIR kTWAIN_DSM_DLL_NAME);
+ PrintCMDMessage(kTWAIN_DSM_DIR kTWAIN_DSM_DLL_NAME);
return;
}
else
@@ -1187,7 +1187,21 @@
// start the transfer
bool bPendingXfers = true;
TW_UINT16 twrc = TWRC_SUCCESS;
+ // setup the file xfer
+ TW_SETUPFILEXFER filexfer;
+ memset(&filexfer, 0, sizeof(filexfer));
+ const char * pExt = convertICAP_IMAGEFILEFORMAT_toExt(fileformat);
+ if(fileformat==TWFF_TIFFMULTI)
+ {
+ SSNPRINTF(filexfer.FileName, sizeof(filexfer.FileName), sizeof(filexfer.FileName), "FROM_SCANNER_F%s", pExt);
+ }
+ else
+ {
+ SSNPRINTF(filexfer.FileName, sizeof(filexfer.FileName), sizeof(filexfer.FileName), "FROM_SCANNER_%06dF%s", m_nXferNum, pExt);
+ }
+ filexfer.Format = fileformat;
+
while(bPendingXfers)
{
m_nXferNum++;
@@ -1196,17 +1210,11 @@
{
break;
}
+ if(fileformat!=TWFF_TIFFMULTI)
+ {
+ SSNPRINTF(filexfer.FileName, sizeof(filexfer.FileName), sizeof(filexfer.FileName), "FROM_SCANNER_%06dF%s", m_nXferNum, pExt);
+ }
- // setup the file xfer
- TW_SETUPFILEXFER filexfer;
- memset(&filexfer, 0, sizeof(filexfer));
-
- const char * pExt = convertICAP_IMAGEFILEFORMAT_toExt(fileformat);
-
- SSNPRINTF(filexfer.FileName, sizeof(filexfer.FileName), sizeof(filexfer.FileName), "FROM_SCANNER_%06dF%s", m_nXferNum, pExt);
-
- filexfer.Format = fileformat;
-
PrintCMDMessage("app: Sending file transfer details...\n");
twrc = DSM_Entry( DG_CONTROL, DAT_SETUPFILEXFER, MSG_SET, (TW_MEMREF)&(filexfer));
@@ -1226,7 +1234,10 @@
PrintCMDMessage("app: File \"%s\" saved...\n", filexfer.FileName);
#ifdef _WINDOWS
- ShellExecute(m_Parent, "open", filexfer.FileName, NULL, NULL, SW_SHOWNORMAL);
+ if(fileformat!=TWFF_TIFFMULTI)
+ {
+ ShellExecute(m_Parent, "open", filexfer.FileName, NULL, NULL, SW_SHOWNORMAL);
+ }
#endif
updateEXIMAGEINFO();
@@ -1265,7 +1276,12 @@
break;
}
}
-
+#ifdef _WINDOWS
+ if(TWRC_SUCCESS == twrc && fileformat==TWFF_TIFFMULTI)
+ {
+ ShellExecute(m_Parent, "open", filexfer.FileName, NULL, NULL, SW_SHOWNORMAL);
+ }
+#endif
// Check to see if we left the scan loop before we were actualy done scanning
// This will hapen if we had an error. Need to let the DS know we are not going
// to transfer more images
Modified: trunk/TWAIN-Samples/Twain_App_sample01/src/TwainAppCMD.cpp
===================================================================
--- trunk/TWAIN-Samples/Twain_App_sample01/src/TwainAppCMD.cpp 2009-12-22 19:38:04 UTC (rev 64)
+++ trunk/TWAIN-Samples/Twain_App_sample01/src/TwainAppCMD.cpp 2009-12-22 19:40:56 UTC (rev 65)
@@ -146,7 +146,13 @@
initCaps();
}
}
+//////////////////////////////////////////////////////////////////////////////
+void TwainAppCMD::unloadDS()
+{
+ uninitCaps();
+ TwainApp::unloadDS();
+}
//////////////////////////////////////////////////////////////////////////////
void TwainAppCMD::initCaps()
{
@@ -162,33 +168,43 @@
}
// get the default pixel type
+ memset(&m_CAP_XFERCOUNT,0,sizeof(TW_CAPABILITY));
m_CAP_XFERCOUNT.Cap = CAP_XFERCOUNT;
get_CAP(m_CAP_XFERCOUNT);
+ memset(&m_ICAP_PIXELTYPE,0,sizeof(TW_CAPABILITY));
m_ICAP_PIXELTYPE.Cap = ICAP_PIXELTYPE;
get_CAP(m_ICAP_PIXELTYPE);
+ memset(&m_ICAP_XFERMECH,0,sizeof(TW_CAPABILITY));
m_ICAP_XFERMECH.Cap = ICAP_XFERMECH;
get_CAP(m_ICAP_XFERMECH);
+ memset(&m_ICAP_IMAGEFILEFORMAT,0,sizeof(TW_CAPABILITY));
m_ICAP_IMAGEFILEFORMAT.Cap = ICAP_IMAGEFILEFORMAT;
get_CAP(m_ICAP_IMAGEFILEFORMAT);
+ memset(&m_ICAP_COMPRESSION,0,sizeof(TW_CAPABILITY));
m_ICAP_COMPRESSION.Cap = ICAP_COMPRESSION;
get_CAP(m_ICAP_COMPRESSION);
+ memset(&m_ICAP_UNITS,0,sizeof(TW_CAPABILITY));
m_ICAP_UNITS.Cap = ICAP_UNITS;
get_CAP(m_ICAP_UNITS);
+ memset(&m_ICAP_BITDEPTH,0,sizeof(TW_CAPABILITY));
m_ICAP_BITDEPTH.Cap = ICAP_BITDEPTH;
get_CAP(m_ICAP_BITDEPTH);
+ memset(&m_ICAP_XRESOLUTION,0,sizeof(TW_CAPABILITY));
m_ICAP_XRESOLUTION.Cap = ICAP_XRESOLUTION;
get_CAP(m_ICAP_XRESOLUTION);
+ memset(&m_ICAP_YRESOLUTION,0,sizeof(TW_CAPABILITY));
m_ICAP_YRESOLUTION.Cap = ICAP_YRESOLUTION;
get_CAP(m_ICAP_YRESOLUTION);
+ memset(&m_ICAP_FRAMES,0,sizeof(TW_CAPABILITY));
m_ICAP_FRAMES.Cap = ICAP_FRAMES;
get_CAP(m_ICAP_FRAMES);
@@ -196,6 +212,73 @@
}
//////////////////////////////////////////////////////////////////////////////
+void TwainAppCMD::uninitCaps()
+{
+ if(m_DSMState < 3)
+ {
+ PrintCMDMessage("The DSM needs to be opened first.\n");
+ return;
+ }
+ else if(m_DSMState < 4)
+ {
+ PrintCMDMessage("A Data Source needs to be opened first.\n");
+ return;
+ }
+
+ if(m_CAP_XFERCOUNT.hContainer)
+ {
+ _DSM_Free(m_CAP_XFERCOUNT.hContainer);
+ m_CAP_XFERCOUNT.hContainer=0;
+ }
+ if(m_ICAP_PIXELTYPE.hContainer)
+ {
+ _DSM_Free(m_ICAP_PIXELTYPE.hContainer);
+ m_ICAP_PIXELTYPE.hContainer=0;
+ }
+ if(m_ICAP_XFERMECH.hContainer)
+ {
+ _DSM_Free(m_ICAP_XFERMECH.hContainer);
+ m_ICAP_XFERMECH.hContainer=0;
+ }
+ if(m_ICAP_IMAGEFILEFORMAT.hContainer)
+ {
+ _DSM_Free(m_ICAP_IMAGEFILEFORMAT.hContainer);
+ m_ICAP_IMAGEFILEFORMAT.hContainer=0;
+ }
+ if(m_ICAP_COMPRESSION.hContainer)
+ {
+ _DSM_Free(m_ICAP_COMPRESSION.hContainer);
+ m_ICAP_COMPRESSION.hContainer=0;
+ }
+ if(m_ICAP_UNITS.hContainer)
+ {
+ _DSM_Free(m_ICAP_UNITS.hContainer);
+ m_ICAP_UNITS.hContainer=0;
+ }
+ if(m_ICAP_BITDEPTH.hContainer)
+ {
+ _DSM_Free(m_ICAP_BITDEPTH.hContainer);
+ m_ICAP_BITDEPTH.hContainer=0;
+ }
+ if(m_ICAP_XRESOLUTION.hContainer)
+ {
+ _DSM_Free(m_ICAP_XRESOLUTION.hContainer);
+ m_ICAP_XRESOLUTION.hContainer=0;
+ }
+ if(m_ICAP_YRESOLUTION.hContainer)
+ {
+ _DSM_Free(m_ICAP_YRESOLUTION.hContainer);
+ m_ICAP_YRESOLUTION.hContainer=0;
+ }
+ if(m_ICAP_FRAMES.hContainer)
+ {
+ _DSM_Free(m_ICAP_FRAMES.hContainer);
+ m_ICAP_FRAMES.hContainer=0;
+ }
+
+ return;
+}
+//////////////////////////////////////////////////////////////////////////////
void TwainAppCMD::startScan()
{
if(m_DSMState != 6)
Modified: trunk/TWAIN-Samples/Twain_App_sample01/src/TwainAppCMD.h
===================================================================
--- trunk/TWAIN-Samples/Twain_App_sample01/src/TwainAppCMD.h 2009-12-22 19:38:04 UTC (rev 64)
+++ trunk/TWAIN-Samples/Twain_App_sample01/src/TwainAppCMD.h 2009-12-22 19:40:56 UTC (rev 65)
@@ -97,6 +97,12 @@
virtual void loadDS(const TW_INT32 _dsID);
/**
+* Unloads the currently loaded datasource. If successful moves the
+* app to state 3.
+*/
+ virtual void unloadDS();
+
+/**
* Print a list of Data Sources. Prints to stdout a quick list of the
* Data Sources the app knows about.
*/
@@ -121,8 +127,11 @@
* Negotiates the default capabilities with the currently opened data source.
*/
void initCaps();
-
/**
+* Free allocated capabilities.
+*/
+ void uninitCaps();
+/**
* Tries to starts the scanning process. Must be in state 6 to start.
* If successfully finishes scan moves app to state 5.
*/
Modified: trunk/TWAIN-Samples/Twain_App_sample01/src/src.pro
===================================================================
--- trunk/TWAIN-Samples/Twain_App_sample01/src/src.pro 2009-12-22 19:38:04 UTC (rev 64)
+++ trunk/TWAIN-Samples/Twain_App_sample01/src/src.pro 2009-12-22 19:40:56 UTC (rev 65)
@@ -1,35 +1,32 @@
-unix {
- TEMPLATE = app
- VERSION = 1.0
- DEFINES += UNIX kTWAIN_DS_DIR=\"/usr/local/lib/twain\"
-}
-
-TARGET = twain_app_sample01
-
-LIBS += -lfreeimage
-
-INCLUDEPATH = /usr/local/include ../../pub/external/include ../../pub/include ../../common
-
-SOURCES += \
- ../../common/CTiffWriter.cpp \
- ../../common/CommonTWAIN.cpp \
- DSMInterface.cpp \
- main.cpp \
- TwainApp.cpp \
- TwainApp_ui.cpp
-
-
-HEADERS += \
- ../../common/Common.h \
- ../../common/CTiffWriter.h \
- ../../common/CommonTWAIN.h \
- DSMInterface.h \
- TwainApp.h \
- TwainApp_ui.h
-
-CONFIG += warn_off debug
-
-# this project doesn't need any QT libs.
-QMAKE_LIBS_QT =
-QMAKE_LIBS_QT_THREAD =
-
+unix {
+ TEMPLATE = app
+ VERSION = 1.0
+ DEFINES += UNIX \
+ kTWAIN_DS_DIR=\"/usr/local/lib/twain\"
+}
+TARGET = twain_app_sample01
+LIBS += -lfreeimage
+INCLUDEPATH = /usr/local/include \
+ ../../pub/external/include \
+ ../../pub/include \
+ ../../common
+SOURCES += ../../common/CTiffWriter.cpp \
+ ../../common/CommonTWAIN.cpp \
+ DSMInterface.cpp \
+ main.cpp \
+ TwainApp.cpp \
+ TwainApp_ui.cpp \
+ ../../common/TwainString.cpp \
+ TwainAppCMD.cpp
+HEADERS += ../../common/Common.h \
+ ../../common/CTiffWriter.h \
+ ../../common/CommonTWAIN.h \
+ DSMInterface.h \
+ TwainApp.h \
+ TwainApp_ui.h
+CONFIG += warn_off \
+ debug
+
+# this project doesn't need any QT libs.
+QMAKE_LIBS_QT =
+QMAKE_LIBS_QT_THREAD =
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|