summaryrefslogtreecommitdiff
path: root/frontend
diff options
context:
space:
mode:
Diffstat (limited to 'frontend')
-rw-r--r--frontend/Makefile.am2
-rw-r--r--frontend/Makefile.in10
-rw-r--r--frontend/scanimage.c343
-rw-r--r--frontend/tstbackend.c27
4 files changed, 321 insertions, 61 deletions
diff --git a/frontend/Makefile.am b/frontend/Makefile.am
index a501931..23061b3 100644
--- a/frontend/Makefile.am
+++ b/frontend/Makefile.am
@@ -18,7 +18,7 @@ AM_CPPFLAGS = -I. -I$(srcdir) -I$(top_builddir)/include -I$(top_srcdir)/include
scanimage_SOURCES = scanimage.c stiff.c stiff.h
scanimage_LDADD = ../backend/libsane.la ../sanei/libsanei.la ../lib/liblib.la \
- ../lib/libfelib.la
+ ../lib/libfelib.la @PNG_LIBS@ @JPEG_LIBS@
saned_SOURCES = saned.c
saned_LDADD = ../backend/libsane.la ../sanei/libsanei.la ../lib/liblib.la \
diff --git a/frontend/Makefile.in b/frontend/Makefile.in
index 18b9877..c157a8c 100644
--- a/frontend/Makefile.in
+++ b/frontend/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.13.4 from Makefile.am.
+# Makefile.in generated by automake 1.14.1 from Makefile.am.
# @configure_input@
# Copyright (C) 1994-2013 Free Software Foundation, Inc.
@@ -275,6 +275,7 @@ PATH_SEPARATOR = @PATH_SEPARATOR@
PKG_CONFIG = @PKG_CONFIG@
PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
+PNG_LIBS = @PNG_LIBS@
PRELOADABLE_BACKENDS = @PRELOADABLE_BACKENDS@
PRELOADABLE_BACKENDS_ENABLED = @PRELOADABLE_BACKENDS_ENABLED@
PTHREAD_LIBS = @PTHREAD_LIBS@
@@ -291,6 +292,7 @@ SOCKET_LIBS = @SOCKET_LIBS@
STRICT_LDFLAGS = @STRICT_LDFLAGS@
STRIP = @STRIP@
SYSLOG_LIBS = @SYSLOG_LIBS@
+SYSTEMD_CFLAGS = @SYSTEMD_CFLAGS@
SYSTEMD_LIBS = @SYSTEMD_LIBS@
TIFF_LIBS = @TIFF_LIBS@
USB_LIBS = @USB_LIBS@
@@ -357,7 +359,7 @@ top_srcdir = @top_srcdir@
AM_CPPFLAGS = -I. -I$(srcdir) -I$(top_builddir)/include -I$(top_srcdir)/include
scanimage_SOURCES = scanimage.c stiff.c stiff.h
scanimage_LDADD = ../backend/libsane.la ../sanei/libsanei.la ../lib/liblib.la \
- ../lib/libfelib.la
+ ../lib/libfelib.la @PNG_LIBS@ @JPEG_LIBS@
saned_SOURCES = saned.c
saned_LDADD = ../backend/libsane.la ../sanei/libsanei.la ../lib/liblib.la \
@@ -533,14 +535,14 @@ distclean-compile:
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c $<
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $<
.c.obj:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c `$(CYGPATH_W) '$<'`
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
.c.lo:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
diff --git a/frontend/scanimage.c b/frontend/scanimage.c
index b1d2481..7f7c1f0 100644
--- a/frontend/scanimage.c
+++ b/frontend/scanimage.c
@@ -1,5 +1,6 @@
/* scanimage -- command line scanning utility
Uses the SANE library.
+ Copyright (C) 2015 Rolf Bensch <rolf at bensch hyphen online dot de>
Copyright (C) 1996, 1997, 1998 Andreas Beck and David Mosberger
Copyright (C) 1999 - 2009 by the SANE Project -- See AUTHORS and ChangeLog
@@ -41,6 +42,14 @@
#include <sys/types.h>
#include <sys/stat.h>
+#ifdef HAVE_LIBPNG
+#include <png.h>
+#endif
+
+#ifdef HAVE_LIBJPEG
+#include <jpeglib.h>
+#endif
+
#include "../include/_stdint.h"
#include "../include/sane/sane.h"
@@ -55,10 +64,6 @@
#define PATH_MAX 1024
#endif
-#ifndef HAVE_ATEXIT
-# define atexit(func) on_exit(func, 0) /* works for SunOS, at least */
-#endif
-
typedef struct
{
uint8_t *data;
@@ -107,6 +112,8 @@ static struct option basic_options[] = {
#define OUTPUT_PNM 0
#define OUTPUT_TIFF 1
+#define OUTPUT_PNG 2
+#define OUTPUT_JPEG 3
#define BASE_OPTSTRING "d:hi:Lf:B::nvVTAbp"
#define STRIP_HEIGHT 256 /* # lines we increment image height */
@@ -135,7 +142,7 @@ static int accept_only_md5_auth = 0;
static const char *icc_profile = NULL;
static void fetch_options (SANE_Device * device);
-static void scanimage_exit (void);
+static void scanimage_exit (int);
static SANE_Word tl_x = 0;
static SANE_Word tl_y = 0;
@@ -687,7 +694,7 @@ parse_scalar (const SANE_Option_Descriptor * opt, const char *str,
fprintf (stderr,
"%s: option --%s: bad option value (rest of option: %s)\n",
prog_name, opt->name, str);
- exit (1);
+ scanimage_exit (1);
}
str = end;
@@ -796,7 +803,7 @@ parse_vector (const SANE_Option_Descriptor * opt, const char *str,
{
fprintf (stderr, "%s: option --%s: closing bracket missing "
"(rest of option: %s)\n", prog_name, opt->name, str);
- exit (1);
+ scanimage_exit (1);
}
str = end + 1;
}
@@ -808,20 +815,20 @@ parse_vector (const SANE_Option_Descriptor * opt, const char *str,
fprintf (stderr,
"%s: option --%s: index %d out of range [0..%ld]\n",
prog_name, opt->name, index, (long) vector_length - 1);
- exit (1);
+ scanimage_exit (1);
}
/* read value */
str = parse_scalar (opt, str, &value);
if (!str)
- exit (1);
+ scanimage_exit (1);
if (*str && *str != '-' && *str != ',')
{
fprintf (stderr,
"%s: option --%s: illegal separator (rest of option: %s)\n",
prog_name, opt->name, str);
- exit (1);
+ scanimage_exit (1);
}
/* store value: */
@@ -874,7 +881,7 @@ fetch_options (SANE_Device * device)
if (opt == NULL)
{
fprintf (stderr, "Could not get option descriptor for option 0\n");
- exit (1);
+ scanimage_exit (1);
}
status = sane_control_option (device, 0, SANE_ACTION_GET_VALUE,
@@ -883,7 +890,7 @@ fetch_options (SANE_Device * device)
{
fprintf (stderr, "Could not get value for option 0: %s\n",
sane_strstatus (status));
- exit (1);
+ scanimage_exit (1);
}
/* build the full table of long options */
@@ -894,7 +901,7 @@ fetch_options (SANE_Device * device)
if (opt == NULL)
{
fprintf (stderr, "Could not get option descriptor for option %d\n",i);
- exit (1);
+ scanimage_exit (1);
}
/* create command line option only for settable options */
@@ -1013,7 +1020,7 @@ set_option (SANE_Handle device, int optnum, void *valuep)
{
fprintf (stderr, "%s: setting of option --%s failed (%s)\n",
prog_name, opt->name, sane_strstatus (status));
- exit (1);
+ scanimage_exit (1);
}
if ((info & SANE_INFO_INEXACT) && opt->size == sizeof (SANE_Word))
@@ -1048,7 +1055,7 @@ process_backend_option (SANE_Handle device, int optnum, const char *optarg)
{
fprintf (stderr, "%s: attempted to set inactive option %s\n",
prog_name, opt->name);
- exit (1);
+ scanimage_exit (1);
}
if ((opt->cap & SANE_CAP_AUTOMATIC) && optarg &&
@@ -1061,7 +1068,7 @@ process_backend_option (SANE_Handle device, int optnum, const char *optarg)
fprintf (stderr,
"%s: failed to set option --%s to automatic (%s)\n",
prog_name, opt->name, sane_strstatus (status));
- exit (1);
+ scanimage_exit (1);
}
return;
}
@@ -1081,7 +1088,7 @@ process_backend_option (SANE_Handle device, int optnum, const char *optarg)
{
fprintf (stderr, "%s: option --%s: bad option value `%s'\n",
prog_name, opt->name, optarg);
- exit (1);
+ scanimage_exit (1);
}
}
break;
@@ -1097,7 +1104,7 @@ process_backend_option (SANE_Handle device, int optnum, const char *optarg)
if (!vector)
{
fprintf (stderr, "%s: out of memory\n", prog_name);
- exit (1);
+ scanimage_exit (1);
}
}
parse_vector (opt, optarg, vector, vector_length);
@@ -1109,7 +1116,7 @@ process_backend_option (SANE_Handle device, int optnum, const char *optarg)
if (!valuep)
{
fprintf (stderr, "%s: out of memory\n", prog_name);
- exit (1);
+ scanimage_exit (1);
}
strncpy (valuep, optarg, opt->size);
((char *) valuep)[opt->size - 1] = 0;
@@ -1156,6 +1163,79 @@ write_pnm_header (SANE_Frame format, int width, int height, int depth, FILE *ofp
#endif
}
+#ifdef HAVE_LIBPNG
+static void
+write_png_header (SANE_Frame format, int width, int height, int depth, FILE *ofp, png_structp* png_ptr, png_infop* info_ptr)
+{
+ int color_type;
+
+ *png_ptr = png_create_write_struct
+ (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+ if (!*png_ptr) {
+ fprintf(stderr, "png_create_write_struct failed\n");
+ exit(1);
+ }
+ *info_ptr = png_create_info_struct(*png_ptr);
+ if (!*info_ptr) {
+ fprintf(stderr, "png_create_info_struct failed\n");
+ exit(1);
+ }
+ png_init_io(*png_ptr, ofp);
+
+ switch (format)
+ {
+ case SANE_FRAME_RED:
+ case SANE_FRAME_GREEN:
+ case SANE_FRAME_BLUE:
+ case SANE_FRAME_RGB:
+ color_type = PNG_COLOR_TYPE_RGB;
+ break;
+
+ default:
+ color_type = PNG_COLOR_TYPE_GRAY;
+ break;
+ }
+
+ png_set_IHDR(*png_ptr, *info_ptr, width, height,
+ depth, color_type, PNG_INTERLACE_NONE,
+ PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
+
+ png_write_info(*png_ptr, *info_ptr);
+}
+#endif
+
+#ifdef HAVE_LIBJPEG
+static void
+write_jpeg_header (SANE_Frame format, int width, int height, FILE *ofp, struct jpeg_compress_struct *cinfo, struct jpeg_error_mgr *jerr)
+{
+ cinfo->err = jpeg_std_error(jerr);
+ jpeg_create_compress(cinfo);
+ jpeg_stdio_dest(cinfo, ofp);
+
+ cinfo->image_width = width;
+ cinfo->image_height = height;
+ switch (format)
+ {
+ case SANE_FRAME_RED:
+ case SANE_FRAME_GREEN:
+ case SANE_FRAME_BLUE:
+ case SANE_FRAME_RGB:
+ cinfo->in_color_space = JCS_RGB;
+ cinfo->input_components = 3;
+ break;
+
+ default:
+ cinfo->in_color_space = JCS_GRAYSCALE;
+ cinfo->input_components = 1;
+ break;
+ }
+
+ jpeg_set_defaults(cinfo);
+ jpeg_set_quality(cinfo, 75, TRUE);
+ jpeg_start_compress(cinfo, TRUE);
+}
+#endif
+
static void *
advance (Image * image)
{
@@ -1199,6 +1279,18 @@ scan_it (FILE *ofp)
};
SANE_Word total_bytes = 0, expected_bytes;
SANE_Int hang_over = -1;
+#ifdef HAVE_LIBPNG
+ int pngrow = 0;
+ png_bytep pngbuf = NULL;
+ png_structp png_ptr;
+ png_infop info_ptr;
+#endif
+#ifdef HAVE_LIBJPEG
+ int jpegrow = 0;
+ JSAMPLE *jpegbuf = NULL;
+ struct jpeg_compress_struct cinfo;
+ struct jpeg_error_mgr jerr;
+#endif
do
{
@@ -1237,12 +1329,12 @@ scan_it (FILE *ofp)
fprintf (stderr, "%s: scanning image of size %dx%d pixels at "
"%d bits/pixel\n",
prog_name, parm.pixels_per_line, parm.lines,
- 8 * parm.bytes_per_line / parm.pixels_per_line);
+ parm.depth * (SANE_FRAME_RGB == parm.format ? 3 : 1));
else
fprintf (stderr, "%s: scanning image %d pixels wide and "
"variable height at %d bits/pixel\n",
prog_name, parm.pixels_per_line,
- 8 * parm.bytes_per_line / parm.pixels_per_line);
+ parm.depth * (SANE_FRAME_RGB == parm.format ? 3 : 1));
}
fprintf (stderr, "%s: acquiring %s frame\n", prog_name,
@@ -1272,21 +1364,44 @@ scan_it (FILE *ofp)
offset = 0;
}
else
- {
- if (output_format == OUTPUT_TIFF)
+ switch(output_format)
+ {
+ case OUTPUT_TIFF:
sanei_write_tiff_header (parm.format,
parm.pixels_per_line, parm.lines,
parm.depth, resolution_value,
icc_profile, ofp);
- else
+ break;
+ case OUTPUT_PNM:
write_pnm_header (parm.format, parm.pixels_per_line,
parm.lines, parm.depth, ofp);
- }
+ break;
+#ifdef HAVE_LIBPNG
+ case OUTPUT_PNG:
+ write_png_header (parm.format, parm.pixels_per_line,
+ parm.lines, parm.depth, ofp, &png_ptr, &info_ptr);
+ break;
+#endif
+#ifdef HAVE_LIBJPEG
+ case OUTPUT_JPEG:
+ write_jpeg_header (parm.format, parm.pixels_per_line,
+ parm.lines, ofp, &cinfo, &jerr);
+ break;
+#endif
+ }
break;
default:
break;
}
+#ifdef HAVE_LIBPNG
+ if(output_format == OUTPUT_PNG)
+ pngbuf = malloc(parm.bytes_per_line);
+#endif
+#ifdef HAVE_LIBJPEG
+ if(output_format == OUTPUT_JPEG)
+ jpegbuf = malloc(parm.bytes_per_line);
+#endif
if (must_buffer)
{
@@ -1400,6 +1515,59 @@ scan_it (FILE *ofp)
}
else /* ! must_buffer */
{
+#ifdef HAVE_LIBPNG
+ if (output_format == OUTPUT_PNG)
+ {
+ int i = 0;
+ int left = len;
+ while(pngrow + left >= parm.bytes_per_line)
+ {
+ memcpy(pngbuf + pngrow, buffer + i, parm.bytes_per_line - pngrow);
+ if(parm.depth == 1)
+ {
+ int j;
+ for(j = 0; j < parm.bytes_per_line; j++)
+ pngbuf[j] = ~pngbuf[j];
+ }
+ png_write_row(png_ptr, pngbuf);
+ i += parm.bytes_per_line - pngrow;
+ left -= parm.bytes_per_line - pngrow;
+ pngrow = 0;
+ }
+ memcpy(pngbuf + pngrow, buffer + i, left);
+ pngrow += left;
+ }
+ else
+#endif
+#ifdef HAVE_LIBJPEG
+ if (output_format == OUTPUT_JPEG)
+ {
+ int i = 0;
+ int left = len;
+ while(jpegrow + left >= parm.bytes_per_line)
+ {
+ memcpy(jpegbuf + jpegrow, buffer + i, parm.bytes_per_line - jpegrow);
+ if(parm.depth == 1)
+ {
+ int col1, col8;
+ JSAMPLE *buf8 = malloc(parm.bytes_per_line * 8);
+ for(col1 = 0; col1 < parm.bytes_per_line; col1++)
+ for(col8 = 0; col8 < 8; col8++)
+ buf8[col1 * 8 + col8] = jpegbuf[col1] & (1 << (8 - col8 - 1)) ? 0 : 0xff;
+ jpeg_write_scanlines(&cinfo, &buf8, 1);
+ free(buf8);
+ } else {
+ jpeg_write_scanlines(&cinfo, &jpegbuf, 1);
+ }
+ i += parm.bytes_per_line - jpegrow;
+ left -= parm.bytes_per_line - jpegrow;
+ jpegrow = 0;
+ }
+ memcpy(jpegbuf + jpegrow, buffer + i, left);
+ jpegrow += left;
+ }
+ else
+#endif
if ((output_format == OUTPUT_TIFF) || (parm.depth != 16))
fwrite (buffer, 1, len, ofp);
else
@@ -1454,13 +1622,29 @@ scan_it (FILE *ofp)
{
image.height = image.y;
- if (output_format == OUTPUT_TIFF)
+ switch(output_format) {
+ case OUTPUT_TIFF:
sanei_write_tiff_header (parm.format, parm.pixels_per_line,
image.height, parm.depth, resolution_value,
icc_profile, ofp);
- else
+ break;
+ case OUTPUT_PNM:
write_pnm_header (parm.format, parm.pixels_per_line,
image.height, parm.depth, ofp);
+ break;
+#ifdef HAVE_LIBPNG
+ case OUTPUT_PNG:
+ write_png_header (parm.format, parm.pixels_per_line,
+ image.height, parm.depth, ofp, &png_ptr, &info_ptr);
+ break;
+#endif
+#ifdef HAVE_LIBJPEG
+ case OUTPUT_JPEG:
+ write_jpeg_header (parm.format, parm.pixels_per_line,
+ parm.lines, ofp, &cinfo, &jerr);
+ break;
+#endif
+ }
#if !defined(WORDS_BIGENDIAN)
/* multibyte pnm file may need byte swap to LE */
@@ -1480,11 +1664,31 @@ scan_it (FILE *ofp)
fwrite (image.data, 1, image.height * image.width, ofp);
}
+#ifdef HAVE_LIBPNG
+ if(output_format == OUTPUT_PNG)
+ png_write_end(png_ptr, info_ptr);
+#endif
+#ifdef HAVE_LIBJPEG
+ if(output_format == OUTPUT_JPEG)
+ jpeg_finish_compress(&cinfo);
+#endif
/* flush the output buffer */
fflush( ofp );
cleanup:
+#ifdef HAVE_LIBPNG
+ if(output_format == OUTPUT_PNG) {
+ png_destroy_write_struct(&png_ptr, &info_ptr);
+ free(pngbuf);
+ }
+#endif
+#ifdef HAVE_LIBJPEG
+ if(output_format == OUTPUT_JPEG) {
+ jpeg_destroy_compress(&cinfo);
+ free(jpegbuf);
+ }
+#endif
if (image.data)
free (image.data);
@@ -1565,12 +1769,12 @@ test_it (void)
if (parm.lines >= 0)
fprintf (stderr, "%s: scanning image of size %dx%d pixels at "
"%d bits/pixel\n", prog_name, parm.pixels_per_line, parm.lines,
- 8 * parm.bytes_per_line / parm.pixels_per_line);
+ parm.depth * (SANE_FRAME_RGB == parm.format ? 3 : 1));
else
fprintf (stderr, "%s: scanning image %d pixels wide and "
"variable height at %d bits/pixel\n",
prog_name, parm.pixels_per_line,
- 8 * parm.bytes_per_line / parm.pixels_per_line);
+ parm.depth * (SANE_FRAME_RGB == parm.format ? 3 : 1));
fprintf (stderr, "%s: acquiring %s frame, %d bits/sample\n", prog_name,
parm.format <= SANE_FRAME_BLUE ? format_name[parm.format]:"Unknown",
parm.depth);
@@ -1648,7 +1852,7 @@ get_resolution (void)
}
static void
-scanimage_exit (void)
+scanimage_exit (int status)
{
if (device)
{
@@ -1666,6 +1870,7 @@ scanimage_exit (void)
free (option_number);
if (verbose > 1)
fprintf (stderr, "scanimage: finished\n");
+ exit (status);
}
/** @brief print device options to stdout
@@ -1721,8 +1926,6 @@ main (int argc, char **argv)
SANE_Int version_code;
FILE *ofp = NULL;
- atexit (scanimage_exit);
-
buffer_size = (32 * 1024); /* default size */
prog_name = strrchr (argv[0], '/');
@@ -1803,6 +2006,24 @@ main (int argc, char **argv)
case OPTION_FORMAT:
if (strcmp (optarg, "tiff") == 0)
output_format = OUTPUT_TIFF;
+ else if (strcmp (optarg, "png") == 0)
+ {
+#ifdef HAVE_LIBPNG
+ output_format = OUTPUT_PNG;
+#else
+ fprintf(stderr, "PNG support not compiled in\n");
+ exit(1);
+#endif
+ }
+ else if (strcmp (optarg, "jpeg") == 0)
+ {
+#ifdef HAVE_LIBJPEG
+ output_format = OUTPUT_JPEG;
+#else
+ fprintf(stderr, "JPEG support not compiled in\n");
+ exit(1);
+#endif
+ }
else
output_format = OUTPUT_PNM;
break;
@@ -1819,7 +2040,7 @@ main (int argc, char **argv)
{
fprintf (stderr, "%s: sane_get_devices() failed: %s\n",
prog_name, sane_strstatus (status));
- exit (1);
+ scanimage_exit (1);
}
if (ch == 'L')
@@ -1916,7 +2137,7 @@ main (int argc, char **argv)
if (defdevname)
printf ("default device is `%s'\n", defdevname);
- exit (0);
+ scanimage_exit (0);
}
case 'V':
@@ -1924,7 +2145,7 @@ main (int argc, char **argv)
VERSION, SANE_VERSION_MAJOR (version_code),
SANE_VERSION_MINOR (version_code),
SANE_VERSION_BUILD (version_code));
- exit (0);
+ scanimage_exit (0);
default:
break; /* ignore device specific options for now */
@@ -1941,7 +2162,7 @@ standard output.\n\
Parameters are separated by a blank from single-character options (e.g.\n\
-d epson) and by a \"=\" from multi-character options (e.g. --device-name=epson).\n\
-d, --device-name=DEVICE use a given scanner device (e.g. hp:/dev/scanner)\n\
- --format=pnm|tiff file format of output file\n\
+ --format=pnm|tiff|png|jpeg file format of output file\n\
-i, --icc-profile=PROFILE include this ICC profile into TIFF file\n", prog_name);
printf ("\
-L, --list-devices show available scanner devices\n\
@@ -1949,8 +2170,8 @@ Parameters are separated by a blank from single-character options (e.g.\n\
can be specified: %%d (device name), %%v (vendor),\n\
%%m (model), %%t (type), %%i (index number), and\n\
%%n (newline)\n\
--b, --batch[=FORMAT] working in batch mode, FORMAT is `out%%d.pnm' or\n\
- `out%%d.tif' by default depending on --format\n");
+-b, --batch[=FORMAT] working in batch mode, FORMAT is `out%%d.pnm' `out%%d.tif'\n\
+ `out%%d.png' or `out%%d.jpg' by default depending on --format\n");
printf ("\
--batch-start=# page number to start naming files with\n\
--batch-count=# how many pages to scan in batch mode\n\
@@ -1985,12 +2206,12 @@ Parameters are separated by a blank from single-character options (e.g.\n\
{
fprintf (stderr, "%s: sane_get_devices() failed: %s\n",
prog_name, sane_strstatus (status));
- exit (1);
+ scanimage_exit (1);
}
if (!device_list[0])
{
fprintf (stderr, "%s: no SANE devices found\n", prog_name);
- exit (1);
+ scanimage_exit (1);
}
devname = device_list[0]->name;
}
@@ -2012,7 +2233,7 @@ Parameters are separated by a blank from single-character options (e.g.\n\
if (help)
device = 0;
else
- exit (1);
+ scanimage_exit (1);
}
if (device)
@@ -2025,7 +2246,7 @@ Parameters are separated by a blank from single-character options (e.g.\n\
{
fprintf (stderr, "%s: unable to get option count descriptor\n",
prog_name);
- exit (1);
+ scanimage_exit (1);
}
/* We got a device, find out how many options it has */
@@ -2035,7 +2256,7 @@ Parameters are separated by a blank from single-character options (e.g.\n\
{
fprintf (stderr, "%s: unable to determine option count\n",
prog_name);
- exit (1);
+ scanimage_exit (1);
}
/* malloc global option lists */
@@ -2047,7 +2268,7 @@ Parameters are separated by a blank from single-character options (e.g.\n\
{
fprintf (stderr, "%s: out of memory in main()\n",
prog_name);
- exit (1);
+ scanimage_exit (1);
}
/* load global option lists */
@@ -2078,7 +2299,7 @@ Parameters are separated by a blank from single-character options (e.g.\n\
if (!full_optstring)
{
fprintf (stderr, "%s: out of memory\n", prog_name);
- exit (1);
+ scanimage_exit (1);
}
strcpy (full_optstring, BASE_OPTSTRING);
@@ -2099,7 +2320,7 @@ Parameters are separated by a blank from single-character options (e.g.\n\
{
case ':':
case '?':
- exit (1); /* error message is printed by getopt_long() */
+ scanimage_exit (1); /* error message is printed by getopt_long() */
case 'd':
case 'h':
@@ -2139,7 +2360,7 @@ Parameters are separated by a blank from single-character options (e.g.\n\
fprintf (stderr, "%s: argument without option: `%s'; ", prog_name,
argv[argc - 1]);
fprintf (stderr, "try %s --help\n", prog_name);
- exit (1);
+ scanimage_exit (1);
}
free (full_optstring);
@@ -2172,7 +2393,7 @@ Parameters are separated by a blank from single-character options (e.g.\n\
{
printf ("\nAll options specific to device `%s':\n", devname);
print_options(device, num_dev_options, SANE_TRUE);
- exit (0);
+ scanimage_exit (0);
}
}
@@ -2205,11 +2426,11 @@ List of available devices:", prog_name);
}
}
fputc ('\n', stdout);
- exit (0);
+ scanimage_exit (0);
}
if (dont_scan)
- exit (0);
+ scanimage_exit (0);
if (output_format != OUTPUT_PNM)
resolution_value = get_resolution ();
@@ -2229,10 +2450,24 @@ List of available devices:", prog_name);
if (batch && NULL == format)
{
- if (output_format == OUTPUT_TIFF)
+ switch(output_format) {
+ case OUTPUT_TIFF:
format = "out%d.tif";
- else
+ break;
+ case OUTPUT_PNM:
format = "out%d.pnm";
+ break;
+#ifdef HAVE_LIBPNG
+ case OUTPUT_PNG:
+ format = "out%d.png";
+ break;
+#endif
+#ifdef HAVE_LIBJPEG
+ case OUTPUT_JPEG:
+ format = "out%d.jpg";
+ break;
+#endif
+ }
}
if (!batch)
@@ -2245,7 +2480,7 @@ List of available devices:", prog_name);
else if(isatty(fileno(ofp))){
fprintf (stderr,"%s: output is not a file, exiting\n", prog_name);
- exit (1);
+ scanimage_exit (1);
}
buffer = malloc (buffer_size);
@@ -2388,5 +2623,7 @@ List of available devices:", prog_name);
else
status = test_it ();
+ scanimage_exit (status);
+ /* the line below avoids compiler warnings */
return status;
}
diff --git a/frontend/tstbackend.c b/frontend/tstbackend.c
index 6dcd940..82c54dc 100644
--- a/frontend/tstbackend.c
+++ b/frontend/tstbackend.c
@@ -46,6 +46,7 @@
static struct option basic_options[] = {
{"device-name", required_argument, NULL, 'd'},
{"level", required_argument, NULL, 'l'},
+ {"scan", NULL, NULL, 's'},
{"recursion", required_argument, NULL, 'r'},
{"get-devices", required_argument, NULL, 'g'},
{"help", 0, NULL, 'h'}
@@ -1134,7 +1135,7 @@ static void test_scan(SANE_Handle device)
unsigned char *image = NULL;
SANE_Parameters params;
size_t to_read;
- SANE_Int len;
+ SANE_Int len=0;
int ask_len;
int rc;
int fd;
@@ -1660,12 +1661,22 @@ SANE_Status status;
return 0;
}
+/** test test_default
+ * test by scanning using default values
+ * @param device device to use for the scan
+ */
+static void test_default(SANE_Device * device)
+{
+ test_scan(device);
+}
+
static void usage(const char *execname)
{
- printf("Usage: %s [-d backend_name] [-l test_level] [-r recursion_level] [-g time (s)]\n", execname);
+ printf("Usage: %s [-d backend_name] [-l test_level] [-s] [-r recursion_level] [-g time (s)]\n", execname);
printf("\t-v\tverbose level\n");
printf("\t-d\tbackend name\n");
printf("\t-l\tlevel of testing (0=some, 1=0+options, 2=1+scans, 3=longest tests)\n");
+ printf("\t-s\tdo a scan during open/close tests\n");
printf("\t-r\trecursion level for option testing (the higher, the longer)\n");
printf("\t-g\ttime to loop on sane_get_devices function to test scannet hotplug detection (time is in seconds).\n");
}
@@ -1684,6 +1695,7 @@ main (int argc, char **argv)
int rc;
int recursion_level;
int time;
+ int default_scan;
printf("tstbackend, Copyright (C) 2002 Frank Zago\n");
printf("tstbackend comes with ABSOLUTELY NO WARRANTY\n");
@@ -1696,8 +1708,9 @@ main (int argc, char **argv)
recursion_level = 5; /* 5 levels or recursion should be enough */
test_level = 0; /* basic tests only */
time = 0; /* no get devices loop */
+ default_scan = 0;
- while ((ch = getopt_long (argc, argv, "-v:d:l:r:g:h", basic_options,
+ while ((ch = getopt_long (argc, argv, "-v:d:l:r:g:h:s", basic_options,
&index)) != EOF) {
switch(ch) {
case 'v':
@@ -1716,6 +1729,10 @@ main (int argc, char **argv)
}
break;
+ case 's':
+ default_scan = 1;
+ break;
+
case 'r':
recursion_level = atoi(optarg);
break;
@@ -1824,6 +1841,10 @@ main (int argc, char **argv)
rc = check(ERR, (status == SANE_STATUS_GOOD),
"sane_open failed with %s for device %s", sane_strstatus (status), devname);
if (!rc) goto the_exit;
+
+ if (default_scan) {
+ test_default (device);
+ }
sane_close (device);
}