Added 16 bit support for stand-alone mode SANE_FRAME_GRAY and SANE_FRAME_RGB

(from Sergey Vlasov <vsu@altlinux.ru>.). Call scan_done if an error occurs
during scan_start. Run sane_cancel even if sane_read wasn't called once.
DEVEL_2_0_BRANCH-1 DEVEL_2_0_TRUNK-1
Henning Geinitz 2002-11-14 16:49:45 +00:00
rodzic 5b796a36c4
commit 988a002348
2 zmienionych plików z 87 dodań i 5 usunięć

Wyświetl plik

@ -1,3 +1,11 @@
2002-11-14 Henning Meier-Geinitz <henning@meier-geinitz.de>
* src/xscanimage.c: Added 16 bit support for stand-alone mode
SANE_FRAME_GRAY and SANE_FRAME_RGB (from Sergey Vlasov
<vsu@altlinux.ru>.). Call scan_done if an error occurs during
scan_start. Run sane_cancel even if sane_read wasn't called
once.
2002-10-24 Henning Meier-Geinitz <henning@meier-geinitz.de>
* configure configure.in: Addded extra version -cvs again.

Wyświetl plik

@ -126,6 +126,8 @@ static struct
GtkWidget *filename_entry;
FILE *out;
long header_size;
gboolean have_odd_byte;
guint8 odd_byte;
#ifdef HAVE_LIBGIMP_GIMP_H
/* for GIMP mode: */
gint32 image_ID;
@ -145,6 +147,7 @@ static const SANE_Device **devlist;
static gint seldev = -1; /* The selected device */
static gint defdev = -1; /* The default device */
static gint ndevs; /* The number of available devices */
static gboolean little_endian; /* Is this computer little-endian ?*/
static struct option long_options[] =
{
{"help", no_argument, NULL, 'h'},
@ -163,6 +166,18 @@ static void interface (int argc, char **argv);
static void scan_start (void);
static void scan_done (void);
/* Test if this machine is little endian (from coolscan.c) */
static gboolean
calc_little_endian (void)
{
SANE_Int testvalue = 255;
u_int8_t *firstbyte = (u_int8_t *) & testvalue;
if (*firstbyte == 255)
return TRUE;
return FALSE;
}
#ifdef HAVE_LIBGIMP_GIMP_H
static int
@ -588,6 +603,40 @@ advance (void)
#endif /* HAVE_LIBGIMP_GIMP_H */
static void
write_swapped_words(FILE *f, char *buf, guint len)
{
char tmp_buf[2];
char tmp;
unsigned int i;
if (!len)
return;
if (scan_win.have_odd_byte)
{
tmp_buf[0] = *buf++;
tmp_buf[1] = scan_win.odd_byte;
fwrite(tmp_buf, 1, 2, f);
--len;
scan_win.have_odd_byte = FALSE;
}
if (len)
{
for (i = 1; i < len; i += 2)
{
tmp = buf[i];
buf[i] = buf[i - 1];
buf[i - 1] = tmp;
}
fwrite(buf, 1, len & ~1, f);
if (len & 1)
{
scan_win.have_odd_byte = TRUE;
scan_win.odd_byte = buf[len - 1];
}
}
}
static void
input_available (gpointer data, gint source, GdkInputCondition cond)
{
@ -652,7 +701,12 @@ input_available (gpointer data, gint source, GdkInputCondition cond)
{
case SANE_FRAME_GRAY:
if (scan_win.mode == STANDALONE)
fwrite (buf, 1, len, scan_win.out);
{
if (scan_win.param.depth > 8 && little_endian)
write_swapped_words(scan_win.out, buf, len);
else
fwrite (buf, 1, len, scan_win.out);
}
#ifdef HAVE_LIBGIMP_GIMP_H
else
{
@ -693,7 +747,12 @@ input_available (gpointer data, gint source, GdkInputCondition cond)
case SANE_FRAME_RGB:
if (scan_win.mode == STANDALONE)
fwrite (buf, 1, len, scan_win.out);
{
if (scan_win.param.depth > 8 && little_endian)
write_swapped_words(scan_win.out, buf, len);
else
fwrite (buf, 1, len, scan_win.out);
}
#ifdef HAVE_LIBGIMP_GIMP_H
else
{
@ -816,6 +875,8 @@ scan_done (void)
scan_win.input_tag = -1;
}
sane_cancel (gsg_dialog_get_device (dialog));
if (!scan_win.progress)
return;
@ -849,7 +910,6 @@ scan_done (void)
scan_win.tile = 0;
}
#endif /* HAVE_LIBGIMP_GIMP_H */
sane_cancel (gsg_dialog_get_device (dialog));
}
static void
@ -919,6 +979,7 @@ scan_start (void)
snprintf (buf, sizeof (buf), "Failed to get parameters: %s",
sane_strstatus (status));
gsg_error (buf);
scan_done ();
return;
}
@ -927,12 +988,13 @@ scan_start (void)
gsg_set_sensitivity (dialog, TRUE);
snprintf (buf, sizeof (buf), "Hand-Scanner mode not supported");
gsg_error (buf);
sane_cancel (dev);
scan_done ();
return;
}
scan_win.num_bytes = scan_win.param.lines * scan_win.param.bytes_per_line;
scan_win.bytes_read = 0;
scan_win.have_odd_byte = FALSE;
switch (scan_win.param.format)
{
@ -949,10 +1011,21 @@ scan_start (void)
{
switch (scan_win.param.format)
{
case SANE_FRAME_RGB:
case SANE_FRAME_RED:
case SANE_FRAME_GREEN:
case SANE_FRAME_BLUE:
if (scan_win.param.depth > 8)
{
gsg_set_sensitivity (dialog, TRUE);
snprintf (buf, sizeof (buf),
"Separate channel transfers are not supported "
"with %d bits/channel.", scan_win.param.depth);
gsg_error (buf);
scan_done ();
return;
}
/*FALLTHROUGH*/
case SANE_FRAME_RGB:
fprintf (scan_win.out, "P6\n# SANE data follows\n%d %d\n%d\n",
scan_win.param.pixels_per_line, scan_win.param.lines,
(scan_win.param.depth <= 8) ? 255 : 65535);
@ -1831,6 +1904,7 @@ main (int argc, char **argv)
DBG_INIT();
DBG(DBG_error, "xscanimage (version: %s, package: %s) starting\n", VERSION,
PACKAGE);
little_endian = calc_little_endian();
scan_win.mode = STANDALONE;
gtk_quit_flag = 0;
prog_name = strrchr (argv[0], '/');