summaryrefslogtreecommitdiff
path: root/src/xsane-scan.c
diff options
context:
space:
mode:
authorAurelien Jarno <aurel32@debian.org>2005-02-03 16:24:20 +0100
committerMattia Rizzolo <mattia@mapreri.org>2014-10-03 14:05:06 +0000
commit825ef604db05e42ea267a86187bf62d54670c98c (patch)
treec41b8addd68e573fcf6ef599ec777e251a130b8e /src/xsane-scan.c
parentac8459519a9ef2a1ee635509b52a653da1bfe9d5 (diff)
parent817e6294b42b3e4435f1b99728afc1dca84a6445 (diff)
Imported Debian patch 0.97-3debian/0.97-3
Diffstat (limited to 'src/xsane-scan.c')
-rw-r--r--src/xsane-scan.c504
1 files changed, 261 insertions, 243 deletions
diff --git a/src/xsane-scan.c b/src/xsane-scan.c
index a724e3e..ee0542c 100644
--- a/src/xsane-scan.c
+++ b/src/xsane-scan.c
@@ -3,7 +3,7 @@
xsane-scan.c
Oliver Rauch <Oliver.Rauch@rauch-domain.de>
- Copyright (C) 1998-2002 Oliver Rauch
+ Copyright (C) 1998-2005 Oliver Rauch
This file is part of the XSANE package.
This program is free software; you can redistribute it and/or modify
@@ -50,7 +50,7 @@ static int xsane_test_multi_scan(void);
void xsane_scan_done(SANE_Status status);
void xsane_cancel(void);
static void xsane_start_scan(void);
-void xsane_scan_dialog(GtkWidget * widget, gpointer call_data);
+void xsane_scan_dialog(void);
static void xsane_create_internal_gamma_tables(void);
/* ---------------------------------------------------------------------------------------------------------------------- */
@@ -71,7 +71,7 @@ static int xsane_generate_dummy_filename(int conversion_level)
free(xsane.dummy_filename);
}
- if ( (conversion_level == 0) && (xsane.preview->rotation) ) /* scan level with rotation */
+ if ( (conversion_level == 0) && (xsane.scan_rotation) ) /* scan level with rotation */
{
tempfile = TRUE;
}
@@ -81,24 +81,38 @@ static int xsane_generate_dummy_filename(int conversion_level)
tempfile = TRUE;
}
- if ( (xsane.xsane_mode == XSANE_COPY) ||
- (xsane.xsane_mode == XSANE_FAX) ||
- (xsane.xsane_mode == XSANE_MAIL) ||
+ if ( (xsane.mode == XSANE_GIMP_EXTENSION) ||
+ (xsane.xsane_mode == XSANE_COPY) ||
(xsane.xsane_mode == XSANE_VIEWER) ||
- ( (xsane.xsane_mode == XSANE_SAVE) && (xsane.xsane_output_format != XSANE_PNM) &&
- (xsane.xsane_output_format != XSANE_RAW16) && (xsane.xsane_output_format != XSANE_RGBA) ) )
+ ( (xsane.xsane_mode == XSANE_SAVE) &&
+ (xsane.xsane_output_format != XSANE_PNM) &&
+ (xsane.xsane_output_format != XSANE_RGBA) ) )
{
tempfile = TRUE;
}
if (tempfile) /* save to temporary file */
{
- xsane_back_gtk_make_path(sizeof(filename), filename, 0, 0, "conversion-", xsane.dev_name, ".ppm", XSANE_PATH_TMP);
+ xsane_back_gtk_make_path(sizeof(filename), filename, 0, 0, "xsane-conversion-", xsane.dev_name, ".ppm", XSANE_PATH_TMP);
xsane.dummy_filename = strdup(filename);
DBG(DBG_info, "xsane.dummy_filename = %s\n", xsane.dummy_filename);
return TRUE;
}
+ else if (xsane.xsane_mode == XSANE_FAX) /* no conversion following, save directly to the selected filename */
+ {
+ xsane.dummy_filename = strdup(xsane.fax_filename);
+ DBG(DBG_info, "xsane.dummy_filename = %s\n", xsane.dummy_filename);
+
+ return FALSE;
+ }
+ else if (xsane.xsane_mode == XSANE_MAIL) /* no conversion following, save directly to the selected filename */
+ {
+ xsane.dummy_filename = strdup(xsane.mail_filename);
+ DBG(DBG_info, "xsane.dummy_filename = %s\n", xsane.dummy_filename);
+
+ return FALSE;
+ }
else /* no conversion following, save directly to the selected filename */
{
xsane.dummy_filename = strdup(xsane.output_filename);
@@ -178,14 +192,26 @@ static void xsane_read_image_data(gpointer data, gint source, GdkInputCondition
if (!len) /* nothing read */
{
- break; /* out of data for now, leave while loop */
+ if (xsane.input_tag >= 0)
+ {
+ break; /* leave xsane_read_image_data, will be called by gdk when select_fd event occurs */
+ }
+ else /* no select fd available */
+ {
+ while (gtk_events_pending())
+ {
+ DBG(DBG_info, "calling gtk_main_iteration\n");
+ gtk_main_iteration();
+ }
+ continue; /* we have to keep this loop running because it will never be called again */
+ }
}
xsane.bytes_read += len;
xsane_progress_update(xsane.bytes_read / (gfloat) xsane.num_bytes);
/* it is not allowed to call gtk_main_iteration when we have gdk_input active */
- /* because xsan_read_image_data will be called several times */
+ /* because xsane_read_image_data will be called several times */
if (xsane.input_tag < 0)
{
while (gtk_events_pending())
@@ -245,10 +271,17 @@ static void xsane_read_image_data(gpointer data, gint source, GdkInputCondition
{
*expanded_buf8ptr = (val & (1 << j)) ? 0x00 : 0xff;
expanded_buf8ptr++;
+
+ xsane.lineart_to_grayscale_x--;
+ if (xsane.lineart_to_grayscale_x <= 0)
+ {
+ xsane.lineart_to_grayscale_x = xsane.param.pixels_per_line;
+ break;
+ }
}
buf8ptr++;
}
- fwrite(expanded_buf8, 1, len*8, xsane.out);
+ fwrite(expanded_buf8, 1, (size_t) (expanded_buf8ptr - expanded_buf8), xsane.out);
free(expanded_buf8);
}
else /* save direct to the file */
@@ -301,11 +334,13 @@ static void xsane_read_image_data(gpointer data, gint source, GdkInputCondition
case SANE_FRAME_GREEN:
case SANE_FRAME_BLUE:
{
+ unsigned char rgbbuf[3 * XSANE_3PASS_BUFFER_RGB_SIZE];
+ int pos;
+
DBG(DBG_info, "3 pass color\n");
if (!xsane.scanner_gamma_color) /* gamma correction by xsane */
{
- char val;
SANE_Int *gamma;
if (xsane.param.format == SANE_FRAME_RED)
@@ -323,19 +358,51 @@ static void xsane_read_image_data(gpointer data, gint source, GdkInputCondition
for (i = 0; i < len; ++i)
{
- val = gamma[(int) buf8[i]];
- fputc(val, xsane.out);
- fseek(xsane.out, 2, SEEK_CUR);
+ buf8[i] = gamma[(int) buf8[i]];
}
}
- else /* gamma correction by scanner */
+
+ buf8ptr = buf8;
+ pos = 0;
+
+ while(pos < len)
{
- for (i = 0; i < len; ++i)
+ int cnt, bytes;
+
+ cnt = len - pos;
+
+ if (cnt > XSANE_3PASS_BUFFER_RGB_SIZE)
{
- fputc(buf8[i], xsane.out);
- fseek(xsane.out, 2, SEEK_CUR);
+ cnt = XSANE_3PASS_BUFFER_RGB_SIZE;
}
- }
+
+ bytes = 3 * cnt - 2;
+
+ /* if there already is data: read block of already scanned colors */
+ if( (xsane.param.format > SANE_FRAME_RED) && (cnt > 1) )
+ {
+ long fpos = ftell(xsane.out);
+
+ fseek(xsane.out, 0, SEEK_CUR); /* sync between write and read */
+ fread(rgbbuf, 1, bytes - 1, xsane.out);
+ fseek(xsane.out, fpos, SEEK_SET);
+ }
+
+ /* add just scanned color to block */
+ for(j = 0; j < cnt; j++)
+ {
+ rgbbuf[3 * j] = buf8ptr[j];
+ }
+
+ /* write block back to disk */
+ fwrite(rgbbuf, 1, bytes, xsane.out);
+
+ pos += cnt;
+ buf8ptr += cnt;
+
+ /* skip the bytes for the two other colors */
+ fseek(xsane.out, 2, SEEK_CUR);
+ } /* while(pos < len) */
}
break;
@@ -404,8 +471,6 @@ static void xsane_read_image_data(gpointer data, gint source, GdkInputCondition
unsigned char *buf8 = (unsigned char *) buf16;
unsigned char *buf8ptr;
char buf[255];
- char last = 0;
- int offset = 0;
DBG(DBG_info, "depth = 16 bit\n");
@@ -416,9 +481,9 @@ static void xsane_read_image_data(gpointer data, gint source, GdkInputCondition
break; /* leave while loop */
}
- if (offset) /* if we have had an odd number of bytes */
+ if (xsane.read_offset_16) /* if we have had an odd number of bytes */
{
- buf16[0] = last; /* ATTENTION: that is wrong! */
+ buf8[0] = xsane.last_offset_16_byte;
status = sane_read(dev, ((SANE_Byte *) buf16) + 1, sizeof(buf16) - 1, &len);
if (len)
{
@@ -440,12 +505,12 @@ static void xsane_read_image_data(gpointer data, gint source, GdkInputCondition
if (len % 2) /* odd number of bytes */
{
len--;
- last = buf16[len];
- offset = 1;
+ xsane.last_offset_16_byte = buf16[len];
+ xsane.read_offset_16 = 1;
}
else /* even number of bytes */
{
- offset = 0;
+ xsane.read_offset_16 = 0;
}
if (status == SANE_STATUS_EOF)
@@ -484,7 +549,19 @@ static void xsane_read_image_data(gpointer data, gint source, GdkInputCondition
if (!len) /* nothing read */
{
- break; /* out of data for now, leave while loop */
+ if (xsane.input_tag >= 0)
+ {
+ break; /* leave xsane_read_image_data, will be called by gdk when select_fd event occurs */
+ }
+ else /* no select fd available */
+ {
+ while (gtk_events_pending())
+ {
+ DBG(DBG_info, "calling gtk_main_iteration\n");
+ gtk_main_iteration();
+ }
+ continue; /* we have to keep this loop running because it will never be called again */
+ }
}
xsane.bytes_read += len;
@@ -660,7 +737,7 @@ static void xsane_read_image_data(gpointer data, gint source, GdkInputCondition
{
for (i = 0; i < len/2; ++i)
{
- fwrite(buf16 + i*2, 2, 1, xsane.out);
+ fwrite(buf16 + i, 2, 1, xsane.out);
fseek(xsane.out, 4, SEEK_CUR);
}
}
@@ -896,7 +973,7 @@ static int xsane_reduce_to_lineart()
if (!abort)
{
- abort = xsane_save_image_as_lineart(old_dummy_filename, xsane.dummy_filename, xsane.progress_bar, &xsane.cancel_save);
+ abort = xsane_save_image_as_lineart(xsane.dummy_filename, old_dummy_filename, xsane.progress_bar, &xsane.cancel_save);
}
if (abort)
@@ -981,33 +1058,34 @@ void xsane_scan_done(SANE_Status status)
DBG(DBG_info, "correcting image height to %d lines\n", pixel_height);
xsane.param.lines = pixel_height;
- image_info.image_width = xsane.param.pixels_per_line;
- image_info.image_height = pixel_height;
- image_info.depth = xsane.depth;
- image_info.colors = xsane.xsane_colors;
+ image_info.image_width = xsane.param.pixels_per_line;
+ image_info.image_height = pixel_height;
+ image_info.depth = xsane.depth;
+ image_info.colors = xsane.xsane_colors;
- image_info.resolution_x = xsane.resolution_x;
- image_info.resolution_y = xsane.resolution_y;
+ image_info.resolution_x = xsane.resolution_x;
+ image_info.resolution_y = xsane.resolution_y;
- image_info.gamma = xsane.gamma;
- image_info.gamma_red = xsane.gamma_red;
- image_info.gamma_green = xsane.gamma_green;
- image_info.gamma_blue = xsane.gamma_blue;
+ image_info.gamma = xsane.gamma;
+ image_info.gamma_red = xsane.gamma_red;
+ image_info.gamma_green = xsane.gamma_green;
+ image_info.gamma_blue = xsane.gamma_blue;
- image_info.brightness = xsane.brightness;
- image_info.brightness_red = xsane.brightness_red;
- image_info.brightness_green = xsane.brightness_green;
- image_info.brightness_blue = xsane.brightness_blue;
+ image_info.brightness = xsane.brightness;
+ image_info.brightness_red = xsane.brightness_red;
+ image_info.brightness_green = xsane.brightness_green;
+ image_info.brightness_blue = xsane.brightness_blue;
- image_info.contrast = xsane.contrast;
- image_info.contrast_red = xsane.contrast_red;
- image_info.contrast_green = xsane.contrast_green;
- image_info.contrast_blue = xsane.contrast_blue;
+ image_info.contrast = xsane.contrast;
+ image_info.contrast_red = xsane.contrast_red;
+ image_info.contrast_green = xsane.contrast_green;
+ image_info.contrast_blue = xsane.contrast_blue;
- image_info.threshold = xsane.threshold;
+ image_info.threshold = xsane.threshold;
+ image_info.reduce_to_lineart = xsane.expand_lineart_to_grayscale;
- xsane_write_pnm_header(xsane.out, &image_info);
+ xsane_write_pnm_header(xsane.out, &image_info, 0);
}
DBG(DBG_info, "closing output file\n");
@@ -1020,7 +1098,7 @@ void xsane_scan_done(SANE_Status status)
if ( (status == SANE_STATUS_GOOD) || (status == SANE_STATUS_EOF) ) /* no error, do conversion etc. */
{
/* do we have to rotate the image ? */
- if (xsane.preview->rotation)
+ if (xsane.scan_rotation)
{
char *old_dummy_filename;
int abort = 0;
@@ -1064,7 +1142,7 @@ void xsane_scan_done(SANE_Status status)
if (outfile)
{
- if (xsane_save_rotate_image(outfile, infile, &image_info, xsane.preview->rotation, xsane.progress_bar, &xsane.cancel_save))
+ if (xsane_save_rotate_image(outfile, infile, &image_info, xsane.scan_rotation, xsane.progress_bar, &xsane.cancel_save))
{
abort = 1;
}
@@ -1109,7 +1187,12 @@ void xsane_scan_done(SANE_Status status)
if (xsane.xsane_mode == XSANE_VIEWER)
{
- xsane_viewer_new(xsane.dummy_filename, xsane.expand_lineart_to_grayscale, 0);
+ xsane_viewer_new(xsane.dummy_filename, TRUE, NULL, VIEWER_FULL_MODIFICATION);
+ xsane.expand_lineart_to_grayscale = 0;
+ }
+
+ if ((xsane.xsane_mode == XSANE_FAX) || (xsane.xsane_mode == XSANE_MAIL))
+ {
xsane.expand_lineart_to_grayscale = 0;
}
@@ -1143,7 +1226,6 @@ void xsane_scan_done(SANE_Status status)
}
if ( ( (xsane.xsane_output_format != XSANE_PNM) && /* these files do not need any transformation */
- (xsane.xsane_output_format != XSANE_RAW16) &&
(xsane.xsane_output_format != XSANE_RGBA) ) ||
(xsane.mode == XSANE_GIMP_EXTENSION) )
{ /* ok, we have to do a transformation */
@@ -1156,15 +1238,15 @@ void xsane_scan_done(SANE_Status status)
}
-#ifdef HAVE_LIBGIMP_GIMP_H
+#ifdef HAVE_ANY_GIMP
if (xsane.mode == XSANE_GIMP_EXTENSION) /* xsane runs as gimp plugin */
{
xsane_transfer_to_gimp(xsane.dummy_filename, xsane.progress_bar, &xsane.cancel_save);
}
else
-#endif /* HAVE_LIBGIMP_GIMP_H */
+#endif /* HAVE_ANY_GIMP */
{
- xsane_save_image_as(xsane.dummy_filename, xsane.output_filename, xsane.xsane_output_format, xsane.progress_bar, &xsane.cancel_save);
+ xsane_save_image_as(xsane.output_filename, xsane.dummy_filename, xsane.xsane_output_format, xsane.progress_bar, &xsane.cancel_save);
}
xsane_progress_clear();
@@ -1206,14 +1288,13 @@ void xsane_scan_done(SANE_Status status)
preferences.printer[preferences.printernr]->copy_number_option,
xsane.copy_number);
outfile = popen(buf, "w");
-/* outfile = popen(preferences.printer[preferences.printernr]->command, "w"); */
if ((outfile != 0) && (infile != 0)) /* copy mode, use zoom size */
{
struct SIGACTION act;
float imagewidth, imageheight;
int printer_resolution;
- switch (xsane.param.format)
+ switch (xsane.param.format)
{
case SANE_FRAME_GRAY:
if (xsane.depth == 1)
@@ -1237,48 +1318,26 @@ void xsane_scan_done(SANE_Status status)
xsane_read_pnm_header(infile, &image_info);
- imagewidth = image_info.image_width/(float)printer_resolution; /* width in inch */
- imageheight = image_info.image_height/(float)printer_resolution; /* height in inch */
+ imagewidth = 72.0 * image_info.image_width/(float)printer_resolution; /* width in 1/72 inch */
+ imageheight = 72.0 * image_info.image_height/(float)printer_resolution; /* height in 1/72 inch */
memset (&act, 0, sizeof (act)); /* define broken pipe handler */
act.sa_handler = xsane_sigpipe_handler;
sigaction (SIGPIPE, &act, 0);
-
- if (preferences.psrotate) /* rotate: landscape */
- {
- xsane_save_ps(outfile, infile,
- &image_info,
- (preferences.printer[preferences.printernr]->bottomoffset +
- preferences.printer[preferences.printernr]->height) * 36.0/MM_PER_INCH - imagewidth * 36.0, /* left edge */
- (preferences.printer[preferences.printernr]->leftoffset +
- preferences.printer[preferences.printernr]->width) * 36.0/MM_PER_INCH - imageheight * 36.0, /* bottom edge */
- imagewidth, imageheight,
- (preferences.printer[preferences.printernr]->leftoffset +
- preferences.printer[preferences.printernr]->width ) * 72.0/MM_PER_INCH, /* paperwidth */
- (preferences.printer[preferences.printernr]->bottomoffset +
- preferences.printer[preferences.printernr]->height) * 72.0/MM_PER_INCH, /* paperheight */
- 1 /* landscape */,
- xsane.progress_bar,
- &xsane.cancel_save);
- }
- else /* do not rotate: portrait */
- {
- xsane_save_ps(outfile, infile,
- &image_info,
- (preferences.printer[preferences.printernr]->leftoffset +
- preferences.printer[preferences.printernr]->width) * 36.0/MM_PER_INCH - imagewidth * 36.0, /* left edge */
- (preferences.printer[preferences.printernr]->bottomoffset +
- preferences.printer[preferences.printernr]->height) * 36.0/MM_PER_INCH - imageheight * 36.0, /* bottom edge */
- imagewidth, imageheight,
- (preferences.printer[preferences.printernr]->leftoffset +
- preferences.printer[preferences.printernr]->width ) * 72.0/MM_PER_INCH, /* paperwidth */
- (preferences.printer[preferences.printernr]->bottomoffset +
- preferences.printer[preferences.printernr]->height) * 72.0/MM_PER_INCH, /* paperheight */
- 0 /* portrait */,
- xsane.progress_bar,
- &xsane.cancel_save);
- }
+ DBG(DBG_info, "imagewidth = %f\n 1/72 inch", imagewidth);
+ DBG(DBG_info, "imageheight = %f\n 1/72 inch", imageheight);
+
+ xsane_save_ps(outfile, infile,
+ &image_info,
+ imagewidth, imageheight,
+ preferences.printer[preferences.printernr]->leftoffset * 72.0/MM_PER_INCH, /* paper_left_margin */
+ preferences.printer[preferences.printernr]->bottomoffset * 72.0/MM_PER_INCH, /* paper_bottom_margin */
+ preferences.printer[preferences.printernr]->width * 72.0/MM_PER_INCH, /* usable paperwidth */
+ preferences.printer[preferences.printernr]->height * 72.0/MM_PER_INCH, /* usable paperheight */
+ preferences.paper_orientation,
+ xsane.progress_bar,
+ &xsane.cancel_save);
}
else
{
@@ -1318,120 +1377,6 @@ void xsane_scan_done(SANE_Status status)
pclose(outfile);
}
}
- else if (xsane.xsane_mode == XSANE_FAX)
- {
- FILE *outfile;
- FILE *infile;
-
- /* open progressbar */
- xsane_progress_new(PROGRESS_CONVERTING_DATA, PROGRESS_TRANSFERING_DATA, (GtkSignalFunc) xsane_cancel_save, &xsane.cancel_save);
-
- while (gtk_events_pending())
- {
- gtk_main_iteration();
- }
-
- infile = fopen(xsane.dummy_filename, "rb"); /* read binary (b for win32) */
- if (infile != 0)
- {
- xsane_read_pnm_header(infile, &image_info);
-
- umask((mode_t) preferences.image_umask); /* define image file permissions */
- outfile = fopen(xsane.fax_filename, "wb"); /* b = binary mode for win32 */
- umask(XSANE_DEFAULT_UMASK); /* define new file permissions */
- if (outfile != 0)
- {
- float imagewidth, imageheight;
-
- imagewidth = image_info.image_width/xsane.resolution_x; /* width in inch */
- imageheight = image_info.image_height/xsane.resolution_y; /* height in inch */
-
- DBG(DBG_info, "imagewidth = %f\n", imagewidth);
- DBG(DBG_info, "imageheight = %f\n", imageheight);
-
- xsane_save_ps(outfile, infile,
- &image_info,
- (preferences.fax_leftoffset + preferences.fax_width) * 36.0/MM_PER_INCH - imagewidth * 36.0,
- (preferences.fax_bottomoffset + preferences.fax_height) * 36.0/MM_PER_INCH - imageheight * 36.0,
- imagewidth, imageheight,
- (preferences.fax_leftoffset + preferences.fax_width ) * 72.0/MM_PER_INCH, /* paperwidth */
- (preferences.fax_bottomoffset + preferences.fax_height) * 72.0/MM_PER_INCH, /* paperheight */
- 0 /* portrait */,
- xsane.progress_bar,
- &xsane.cancel_save);
- fclose(outfile);
- }
- else
- {
- char buf[256];
-
- DBG(DBG_info, "open of faxfile `%s'failed : %s\n", xsane.fax_filename, strerror(errno));
-
- snprintf(buf, sizeof(buf), "%s `%s': %s", ERR_OPEN_FAILED, xsane.fax_filename, strerror(errno));
- xsane_back_gtk_error(buf, TRUE);
- }
-
- fclose(infile);
- remove(xsane.dummy_filename);
- }
- else
- {
- char buf[256];
-
- DBG(DBG_info, "open of faxfile `%s'failed : %s\n", xsane.fax_filename, strerror(errno));
-
- snprintf(buf, sizeof(buf), "%s `%s': %s", ERR_OPEN_FAILED, xsane.fax_filename, strerror(errno));
- xsane_back_gtk_error(buf, TRUE);
- }
- xsane_progress_clear();
-
- while (gtk_events_pending())
- {
- DBG(DBG_info, "calling gtk_main_iteration");
- gtk_main_iteration();
- }
- }
-#ifdef XSANE_ACTIVATE_MAIL
- else if (xsane.xsane_mode == XSANE_MAIL)
- {
- FILE *infile;
-
- /* open progressbar */
- xsane_progress_new(PROGRESS_CONVERTING_DATA, PROGRESS_TRANSFERING_DATA, (GtkSignalFunc) xsane_cancel_save, &xsane.cancel_save);
-
- while (gtk_events_pending())
- {
- gtk_main_iteration();
- }
-
- infile = fopen(xsane.dummy_filename, "rb"); /* read binary (b for win32) */
- if (infile != 0)
- {
- xsane_read_pnm_header(infile, &image_info);
-
- xsane_save_image_as(xsane.dummy_filename, xsane.mail_filename, XSANE_PNG, xsane.progress_bar, &xsane.cancel_save);
-
- fclose(infile);
- remove(xsane.dummy_filename);
- }
- else
- {
- char buf[256];
-
- DBG(DBG_info, "open of mailfile `%s'failed : %s\n", xsane.dummy_filename, strerror(errno));
-
- snprintf(buf, sizeof(buf), "%s `%s': %s", ERR_OPEN_FAILED, xsane.dummy_filename, strerror(errno));
- xsane_back_gtk_error(buf, TRUE);
- }
- xsane_progress_clear();
-
- while (gtk_events_pending())
- {
- DBG(DBG_info, "calling gtk_main_iteration");
- gtk_main_iteration();
- }
- }
-#endif
if ( (xsane.xsane_mode == XSANE_SAVE) && (xsane.mode == XSANE_STANDALONE) )
{
@@ -1441,7 +1386,7 @@ void xsane_scan_done(SANE_Status status)
{
xsane_update_counter_in_filename(&preferences.filename, preferences.skip_existing_numbers,
preferences.filename_counter_step, preferences.filename_counter_len);
- gtk_entry_set_text(GTK_ENTRY(xsane.outputfilename_entry), (char *) preferences.filename); /* update filename in entry */
+ xsane_set_filename(preferences.filename); /* update filename in entry */
gtk_entry_set_position(GTK_ENTRY(xsane.outputfilename_entry), strlen(preferences.filename)); /* set cursor to right position of filename */
}
}
@@ -1454,44 +1399,84 @@ void xsane_scan_done(SANE_Status status)
{
GtkWidget *list_item;
char *page;
+ char *type;
char *extension;
page = strdup(strrchr(xsane.fax_filename,'/')+1);
extension = strrchr(page, '.');
if (extension)
{
+ type = strdup(extension);
*extension = 0;
}
+ else
+ {
+ type = "";
+ }
+
list_item = gtk_list_item_new_with_label(page);
gtk_object_set_data(GTK_OBJECT(list_item), "list_item_data", strdup(page));
+ gtk_object_set_data(GTK_OBJECT(list_item), "list_item_type", strdup(type));
gtk_container_add(GTK_CONTAINER(xsane.fax_list), list_item);
gtk_widget_show(list_item);
xsane_update_counter_in_filename(&xsane.fax_filename, TRUE, 1, preferences.filename_counter_len);
xsane_fax_project_save();
free(page);
+ free(type);
+
+ if (xsane.fax_status)
+ {
+ free(xsane.fax_status);
+ }
+ xsane.fax_status = strdup(TEXT_FAX_STATUS_CHANGED);
+
+ xsane_fax_project_save();
+
+ gtk_progress_set_format_string(GTK_PROGRESS(xsane.fax_progress_bar), _(xsane.fax_status));
+ gtk_progress_bar_update(GTK_PROGRESS_BAR(xsane.fax_progress_bar), 0.0);
}
#ifdef XSANE_ACTIVATE_MAIL
else if (xsane.xsane_mode == XSANE_MAIL)
{
GtkWidget *list_item;
- char *image;
+ char *page;
+ char *type;
char *extension;
- image = strdup(strrchr(xsane.mail_filename,'/')+1);
- extension = strrchr(image, '.');
+ page = strdup(strrchr(xsane.mail_filename,'/')+1);
+ extension = strrchr(page, '.');
if (extension)
{
+ type = strdup(extension);
*extension = 0;
}
- list_item = gtk_list_item_new_with_label(image);
- gtk_object_set_data(GTK_OBJECT(list_item), "list_item_data", strdup(image));
+ else
+ {
+ type = "";
+ }
+
+ list_item = gtk_list_item_new_with_label(page);
+ gtk_object_set_data(GTK_OBJECT(list_item), "list_item_data", strdup(page));
+ gtk_object_set_data(GTK_OBJECT(list_item), "list_item_type", strdup(type));
gtk_container_add(GTK_CONTAINER(xsane.mail_list), list_item);
gtk_widget_show(list_item);
xsane_update_counter_in_filename(&xsane.mail_filename, TRUE, 1, preferences.filename_counter_len);
xsane_mail_project_save();
- free(image);
+ free(page);
+ free(type);
+
+ if (xsane.mail_status)
+ {
+ free(xsane.mail_status);
+ }
+ xsane.mail_status = strdup(TEXT_MAIL_STATUS_CHANGED);
+
+ xsane_mail_project_save();
+
+ gtk_progress_set_format_string(GTK_PROGRESS(xsane.mail_progress_bar), _(xsane.mail_status));
+ gtk_progress_bar_update(GTK_PROGRESS_BAR(xsane.mail_progress_bar), 0.0);
}
#endif
}
@@ -1522,16 +1507,26 @@ void xsane_scan_done(SANE_Status status)
/* b) sane_start returns SANE_STATUS_NO_DOCS */
/* c) an error occurs */
+ DBG(DBG_info, "ADF mode end of scan: increment page counter and restart scan\n");
xsane.adf_page_counter += 1;
- gtk_signal_emit_by_name(xsane.start_button, "clicked"); /* press START button */
+ g_signal_emit_by_name(xsane.start_button, "clicked"); /* press START button */
+ }
+ else if ( ( (status == SANE_STATUS_GOOD) || (status == SANE_STATUS_EOF) ) && (xsane.batch_loop) )
+ {
+ /* batch scan loop, this is not the last scan */
+ DBG(DBG_info, "Batch mode end of scan\n");
+ sane_cancel(xsane.dev); /* we have to call sane_cancel otherwise we are not able to set new parameters */
}
- else /* last scan: update histogram */
+ else if ( ( (status != SANE_STATUS_GOOD) && (status != SANE_STATUS_EOF) ) || (!xsane.batch_loop) ) /* last scan: update histogram */
{
+ DBG(DBG_info, "Normal end of scan\n");
xsane_set_sensitivity(TRUE); /* reactivate buttons etc */
sane_cancel(xsane.dev); /* stop scanning */
xsane_update_histogram(TRUE /* update raw */);
xsane_update_param(0);
}
+
+ xsane.status_of_last_scan = status;
}
/* ---------------------------------------------------------------------------------------------------------------------- */
@@ -1581,6 +1576,8 @@ static void xsane_start_scan(void)
gtk_main_iteration();
}
+ xsane.read_offset_16 = 0; /* no last byte of old 16 bit data */
+
status = sane_start(dev);
DBG(DBG_info, "sane_start returned with status %s\n", XSANE_STRSTATUS(status));
@@ -1630,14 +1627,16 @@ static void xsane_start_scan(void)
default: frame_type = "unknown"; break;
}
- if ( (xsane.param.depth == 1) && (xsane.preview->rotation) )
+ if ((xsane.param.depth == 1) && ((xsane.scan_rotation) ||
+ (xsane.xsane_mode == XSANE_VIEWER) ||
+ (xsane.xsane_mode == XSANE_FAX) ||
+ (xsane.xsane_mode == XSANE_MAIL))
+ ) /* We want to do a transformation with a lineart scan */
+ /* or use the viewer to display a lineart scan, */
+ /* so we save it as grayscale */
{
- xsane.expand_lineart_to_grayscale = 1; /* We want to do transformation with lineart scan, so we save it as grayscale */
- }
-
- if ((xsane.xsane_mode == XSANE_VIEWER) && (xsane.param.depth == 1))
- {
- xsane.expand_lineart_to_grayscale = 1; /* we are using the viewer, lineart is not supported, so create grayscale */
+ DBG(DBG_proc, "lineart scan will be expanded to grayscale\n");
+ xsane.expand_lineart_to_grayscale = 1;
}
if (!xsane.header_size) /* first pass of multi pass scan or single pass scan */
@@ -1657,7 +1656,8 @@ static void xsane_start_scan(void)
}
}
- xsane.out = fopen(xsane.dummy_filename, "wb"); /* b = binary mode for win32 */
+ /* create file: + = also allow read for blocked rgb multiplexing, b = binary mode for win32 */
+ xsane.out = fopen(xsane.dummy_filename, "wb+");
if (!xsane.out) /* error while opening the dummy_file for writing */
{
@@ -1698,7 +1698,9 @@ static void xsane_start_scan(void)
image_info.threshold = xsane.threshold;
- xsane_write_pnm_header(xsane.out, &image_info);
+ image_info.reduce_to_lineart = xsane.expand_lineart_to_grayscale;
+
+ xsane_write_pnm_header(xsane.out, &image_info, 0);
fflush(xsane.out);
xsane.header_size = ftell(xsane.out); /* store header size for 3 pass scan */
@@ -1722,17 +1724,14 @@ static void xsane_start_scan(void)
xsane.input_tag = -1;
+ xsane.lineart_to_grayscale_x = xsane.param.pixels_per_line;
#ifndef BUGGY_GDK_INPUT_EXCEPTION
- /* for unix */
if ((sane_set_io_mode(dev, SANE_TRUE) == SANE_STATUS_GOOD) && (sane_get_select_fd(dev, &fd) == SANE_STATUS_GOOD))
{
DBG(DBG_info, "gdk_input_add\n");
xsane.input_tag = gdk_input_add(fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, xsane_read_image_data, 0);
}
else
-#else
- /* for win32 */
- sane_set_io_mode(dev, SANE_FALSE);
#endif
{
xsane_read_image_data(0, -1, GDK_INPUT_READ);
@@ -1743,13 +1742,15 @@ static void xsane_start_scan(void)
/* Invoked when the scan button is pressed */
/* or by scan_done if automatic document feeder is selected */
-void xsane_scan_dialog(GtkWidget * widget, gpointer call_data)
+void xsane_scan_dialog(void)
{
char buf[256];
const SANE_Option_Descriptor *opt;
DBG(DBG_proc, "xsane_scan_dialog\n");
+ xsane_set_sensitivity(FALSE);
+
xsane.reduce_16bit_to_8bit = preferences.reduce_16bit_to_8bit; /* reduce 16 bit image to 8 bit ? */
sane_get_parameters(xsane.dev, &xsane.param); /* update xsane.param */
@@ -1759,8 +1760,12 @@ void xsane_scan_dialog(GtkWidget * widget, gpointer call_data)
/* correct length of filename counter if it is shorter than minimum length */
if (!xsane.force_filename)
{
+ if (xsane.batch_loop) /* we are doing a batch scan, so we need a counter in the filename */
+ {
+ xsane_ensure_counter_in_filename(&preferences.filename, preferences.filename_counter_len);
+ }
xsane_update_counter_in_filename(&preferences.filename, FALSE, 0, preferences.filename_counter_len);
- gtk_entry_set_text(GTK_ENTRY(xsane.outputfilename_entry), preferences.filename);
+ xsane_set_filename(preferences.filename);
}
}
@@ -1781,15 +1786,17 @@ void xsane_scan_dialog(GtkWidget * widget, gpointer call_data)
char buf[256];
fclose(testfile);
+
snprintf(buf, sizeof(buf), WARN_FILE_EXISTS, xsane.output_filename);
if (xsane_back_gtk_decision(ERR_HEADER_WARNING, (gchar **) warning_xpm, buf, BUTTON_OVERWRITE, BUTTON_CANCEL, TRUE /* wait */) == FALSE)
{
+ xsane_set_sensitivity(TRUE);
return;
}
}
}
- xsane.xsane_output_format = xsane_identify_output_format(xsane.output_filename, &extension);
+ xsane.xsane_output_format = xsane_identify_output_format(xsane.output_filename, preferences.filetype, &extension);
if (xsane.xsane_mode == XSANE_SAVE)
{
@@ -1804,8 +1811,10 @@ void xsane_scan_dialog(GtkWidget * widget, gpointer call_data)
snprintf(buf, sizeof(buf), "%s", ERR_NO_OUTPUT_FORMAT);
}
xsane_back_gtk_error(buf, TRUE);
- return;
+ xsane_set_sensitivity(TRUE);
+ return;
}
+#if 0 /* this is not necessary any more because the saving routines do the conversion */
else if ( ( ( (xsane.xsane_output_format == XSANE_JPEG) && xsane.param.depth == 16) ||
( (xsane.xsane_output_format == XSANE_PS) && xsane.param.depth == 16) ) &&
( !xsane.reduce_16bit_to_8bit) )
@@ -1814,17 +1823,20 @@ void xsane_scan_dialog(GtkWidget * widget, gpointer call_data)
snprintf(buf, sizeof(buf), TEXT_REDUCE_16BIT_TO_8BIT);
if (xsane_back_gtk_decision(ERR_HEADER_INFO, (gchar **) info_xpm, buf, BUTTON_REDUCE, BUTTON_CANCEL, TRUE /* wait */) == FALSE)
{
- return;
+ xsane_set_sensitivity(TRUE);
+ return;
}
xsane.reduce_16bit_to_8bit = TRUE;
}
+#endif
#ifdef SUPPORT_RGBA
else if ((xsane.xsane_output_format == XSANE_RGBA) && (xsane.param.format != SANE_FRAME_RGBA))
{
snprintf(buf, sizeof(buf), "No RGBA data format !!!"); /* user selected output format RGBA, scanner uses other format */
xsane_back_gtk_error(buf, TRUE);
- return;
+ xsane_set_sensitivity(TRUE);
+ return;
}
#endif
}
@@ -1833,7 +1845,8 @@ void xsane_scan_dialog(GtkWidget * widget, gpointer call_data)
{
snprintf(buf, sizeof(buf), "Special format RGBA only supported in scan mode !!!");
xsane_back_gtk_error(buf, TRUE);
- return;
+ xsane_set_sensitivity(TRUE);
+ return;
}
#endif
@@ -1844,7 +1857,8 @@ void xsane_scan_dialog(GtkWidget * widget, gpointer call_data)
{
snprintf(buf, sizeof(buf), "Image data of type SANE_FRAME_RGBA\ncan only be saved in rgba or png format");
xsane_back_gtk_error(buf, TRUE);
- return;
+ xsane_set_sensitivity(TRUE);
+ return;
}
}
#endif
@@ -1859,7 +1873,7 @@ void xsane_scan_dialog(GtkWidget * widget, gpointer call_data)
free(extension);
}
}
-#ifdef HAVE_LIBGIMP_GIMP_H
+#ifdef HAVE_ANY_GIMP
else /* We are running in gimp mode */
{
if ((xsane.param.depth != 1) && (xsane.param.depth != 8)) /* not support bit depth ? */
@@ -1871,7 +1885,8 @@ void xsane_scan_dialog(GtkWidget * widget, gpointer call_data)
snprintf(buf, sizeof(buf), TEXT_GIMP_REDUCE_16BIT_TO_8BIT);
if (xsane_back_gtk_decision(ERR_HEADER_INFO, (gchar **) info_xpm, buf, BUTTON_REDUCE, BUTTON_CANCEL, TRUE /* wait */) == FALSE)
{
- return;
+ xsane_set_sensitivity(TRUE);
+ return;
}
xsane.reduce_16bit_to_8bit = TRUE;
}
@@ -1879,6 +1894,7 @@ void xsane_scan_dialog(GtkWidget * widget, gpointer call_data)
{
snprintf(buf, sizeof(buf), ERR_GIMP_BAD_DEPTH, xsane.param.depth);
xsane_back_gtk_error(buf, TRUE);
+ xsane_set_sensitivity(TRUE);
return;
}
}
@@ -2028,9 +2044,11 @@ void xsane_scan_dialog(GtkWidget * widget, gpointer call_data)
xsane.gamma_data = 0;
}
+#if 0
xsane_clear_histogram(&xsane.histogram_raw);
xsane_clear_histogram(&xsane.histogram_enh);
xsane_set_sensitivity(FALSE);
+#endif
while (gtk_events_pending())
{