Issue #4210 - GIMP reports errors on scanning ...
... since GEGLification of the twain plug-in (2.10.14 and later versions) In the data-transfer functions, allocate a temporary buffer for the converted data on each call using the current chunk size, instead of reusing the buffer allocated on the first chunk. This allows for different chunks sizes across calls.
This commit is contained in:
@ -109,7 +109,6 @@
|
|||||||
/* Global variables */
|
/* Global variables */
|
||||||
pTW_SESSION twSession = NULL;
|
pTW_SESSION twSession = NULL;
|
||||||
|
|
||||||
static char *destBuf = NULL;
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
static int twain_run_mode = RUN_STANDARD;
|
static int twain_run_mode = RUN_STANDARD;
|
||||||
#endif
|
#endif
|
||||||
@ -651,13 +650,13 @@ bitTransferCallback (pTW_IMAGEINFO imageInfo,
|
|||||||
{
|
{
|
||||||
int row, col, offset;
|
int row, col, offset;
|
||||||
char *srcBuf;
|
char *srcBuf;
|
||||||
|
char *destBuf;
|
||||||
int rows = imageMemXfer->Rows;
|
int rows = imageMemXfer->Rows;
|
||||||
int cols = imageMemXfer->Columns;
|
int cols = imageMemXfer->Columns;
|
||||||
pClientDataStruct theClientData = (pClientDataStruct) clientData;
|
pClientDataStruct theClientData = (pClientDataStruct) clientData;
|
||||||
|
|
||||||
/* Allocate a buffer as necessary */
|
/* Allocate a buffer as necessary */
|
||||||
if (! destBuf)
|
destBuf = gegl_scratch_new (char, rows * cols);
|
||||||
destBuf = g_new (char, rows * cols);
|
|
||||||
|
|
||||||
/* Unpack the image data from bits into bytes */
|
/* Unpack the image data from bits into bytes */
|
||||||
srcBuf = (char *) imageMemXfer->Memory.TheMem;
|
srcBuf = (char *) imageMemXfer->Memory.TheMem;
|
||||||
@ -678,6 +677,9 @@ bitTransferCallback (pTW_IMAGEINFO imageInfo,
|
|||||||
theClientData->format, destBuf,
|
theClientData->format, destBuf,
|
||||||
GEGL_AUTO_ROWSTRIDE);
|
GEGL_AUTO_ROWSTRIDE);
|
||||||
|
|
||||||
|
/* Free the buffer */
|
||||||
|
gegl_scratch_free (destBuf);
|
||||||
|
|
||||||
/* Update the user on our progress */
|
/* Update the user on our progress */
|
||||||
theClientData->completedPixels += (cols * rows);
|
theClientData->completedPixels += (cols * rows);
|
||||||
gimp_progress_update ((double) theClientData->completedPixels /
|
gimp_progress_update ((double) theClientData->completedPixels /
|
||||||
@ -703,14 +705,14 @@ oneBytePerSampleTransferCallback (pTW_IMAGEINFO imageInfo,
|
|||||||
{
|
{
|
||||||
int row;
|
int row;
|
||||||
char *srcBuf;
|
char *srcBuf;
|
||||||
|
char *destBuf;
|
||||||
int bytesPerPixel = imageInfo->BitsPerPixel / 8;
|
int bytesPerPixel = imageInfo->BitsPerPixel / 8;
|
||||||
int rows = imageMemXfer->Rows;
|
int rows = imageMemXfer->Rows;
|
||||||
int cols = imageMemXfer->Columns;
|
int cols = imageMemXfer->Columns;
|
||||||
pClientDataStruct theClientData = (pClientDataStruct) clientData;
|
pClientDataStruct theClientData = (pClientDataStruct) clientData;
|
||||||
|
|
||||||
/* Allocate a buffer as necessary */
|
/* Allocate a buffer as necessary */
|
||||||
if (! destBuf)
|
destBuf = gegl_scratch_new (char, rows * cols * bytesPerPixel);
|
||||||
destBuf = g_new (char, rows * cols * bytesPerPixel);
|
|
||||||
|
|
||||||
/* The bytes coming from the source may not be padded in
|
/* The bytes coming from the source may not be padded in
|
||||||
* a way that GIMP is terribly happy with. It is
|
* a way that GIMP is terribly happy with. It is
|
||||||
@ -736,6 +738,9 @@ oneBytePerSampleTransferCallback (pTW_IMAGEINFO imageInfo,
|
|||||||
theClientData->format, destBuf,
|
theClientData->format, destBuf,
|
||||||
GEGL_AUTO_ROWSTRIDE);
|
GEGL_AUTO_ROWSTRIDE);
|
||||||
|
|
||||||
|
/* Free the buffer */
|
||||||
|
gegl_scratch_free (destBuf);
|
||||||
|
|
||||||
/* Update the user on our progress */
|
/* Update the user on our progress */
|
||||||
theClientData->completedPixels += (cols * rows);
|
theClientData->completedPixels += (cols * rows);
|
||||||
gimp_progress_update ((double) theClientData->completedPixels /
|
gimp_progress_update ((double) theClientData->completedPixels /
|
||||||
@ -758,6 +763,7 @@ twoBytesPerSampleTransferCallback (pTW_IMAGEINFO imageInfo,
|
|||||||
{
|
{
|
||||||
static float ratio = 0.00390625;
|
static float ratio = 0.00390625;
|
||||||
int row, col, sample;
|
int row, col, sample;
|
||||||
|
char *destBuf;
|
||||||
char *destByte;
|
char *destByte;
|
||||||
int rows = imageMemXfer->Rows;
|
int rows = imageMemXfer->Rows;
|
||||||
int cols = imageMemXfer->Columns;
|
int cols = imageMemXfer->Columns;
|
||||||
@ -766,8 +772,7 @@ twoBytesPerSampleTransferCallback (pTW_IMAGEINFO imageInfo,
|
|||||||
pClientDataStruct theClientData = (pClientDataStruct) clientData;
|
pClientDataStruct theClientData = (pClientDataStruct) clientData;
|
||||||
|
|
||||||
/* Allocate a buffer as necessary */
|
/* Allocate a buffer as necessary */
|
||||||
if (! destBuf)
|
destBuf = gegl_scratch_new (char, rows * cols * imageInfo->SamplesPerPixel);
|
||||||
destBuf = g_new (char, rows * cols * imageInfo->SamplesPerPixel);
|
|
||||||
|
|
||||||
/* The bytes coming from the source may not be padded in
|
/* The bytes coming from the source may not be padded in
|
||||||
* a way that GIMP is terribly happy with. It is
|
* a way that GIMP is terribly happy with. It is
|
||||||
@ -815,6 +820,9 @@ twoBytesPerSampleTransferCallback (pTW_IMAGEINFO imageInfo,
|
|||||||
theClientData->format, destBuf,
|
theClientData->format, destBuf,
|
||||||
GEGL_AUTO_ROWSTRIDE);
|
GEGL_AUTO_ROWSTRIDE);
|
||||||
|
|
||||||
|
/* Free the buffer */
|
||||||
|
gegl_scratch_free (destBuf);
|
||||||
|
|
||||||
/* Update the user on our progress */
|
/* Update the user on our progress */
|
||||||
theClientData->completedPixels += (cols * rows);
|
theClientData->completedPixels += (cols * rows);
|
||||||
gimp_progress_update ((double) theClientData->completedPixels /
|
gimp_progress_update ((double) theClientData->completedPixels /
|
||||||
@ -844,6 +852,7 @@ palettedTransferCallback (pTW_IMAGEINFO imageInfo,
|
|||||||
int row, col;
|
int row, col;
|
||||||
int rows = imageMemXfer->Rows;
|
int rows = imageMemXfer->Rows;
|
||||||
int cols = imageMemXfer->Columns;
|
int cols = imageMemXfer->Columns;
|
||||||
|
char *destBuf;
|
||||||
char *destPtr = NULL;
|
char *destPtr = NULL;
|
||||||
char *srcPtr = NULL;
|
char *srcPtr = NULL;
|
||||||
|
|
||||||
@ -855,8 +864,7 @@ palettedTransferCallback (pTW_IMAGEINFO imageInfo,
|
|||||||
(theClientData->paletteData->PaletteType == TWPA_RGB) ? 3 : 1;
|
(theClientData->paletteData->PaletteType == TWPA_RGB) ? 3 : 1;
|
||||||
|
|
||||||
/* Allocate a buffer as necessary */
|
/* Allocate a buffer as necessary */
|
||||||
if (! destBuf)
|
destBuf = gegl_scratch_new (char, rows * cols * channelsPerEntry);
|
||||||
destBuf = g_new (char, rows * cols * channelsPerEntry);
|
|
||||||
|
|
||||||
/* Work through the rows */
|
/* Work through the rows */
|
||||||
destPtr = destBuf;
|
destPtr = destBuf;
|
||||||
@ -898,6 +906,9 @@ palettedTransferCallback (pTW_IMAGEINFO imageInfo,
|
|||||||
theClientData->format, destBuf,
|
theClientData->format, destBuf,
|
||||||
GEGL_AUTO_ROWSTRIDE);
|
GEGL_AUTO_ROWSTRIDE);
|
||||||
|
|
||||||
|
/* Free the buffer */
|
||||||
|
gegl_scratch_free (destBuf);
|
||||||
|
|
||||||
/* Update the user on our progress */
|
/* Update the user on our progress */
|
||||||
theClientData->completedPixels += (cols * rows);
|
theClientData->completedPixels += (cols * rows);
|
||||||
gimp_progress_update ((double) theClientData->completedPixels /
|
gimp_progress_update ((double) theClientData->completedPixels /
|
||||||
|
Reference in New Issue
Block a user