diff options
author | Jörg Frings-Fürst <debian@jff.email> | 2023-02-12 17:36:29 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff.email> | 2023-02-12 17:36:29 +0100 |
commit | 882fd010527b8d8823f09e19edbed3746265fa08 (patch) | |
tree | be5c7cace6697afc753c152d13ad5145d0884a42 /backend | |
parent | 527bedac30eb120915718eb7997e6dacd583512e (diff) | |
parent | e0d94cf4d39395df1e2c6bb4d967200298c13881 (diff) |
Merge branch 'feature/upstream' into develop
Diffstat (limited to 'backend')
170 files changed, 3706 insertions, 3903 deletions
diff --git a/backend/Makefile.am b/backend/Makefile.am index e56e7f1..35ad206 100644 --- a/backend/Makefile.am +++ b/backend/Makefile.am @@ -18,6 +18,8 @@ DIST_LIBS_LDFLAGS = $(AM_LDFLAGS) -rpath '$(libdir)' -version-number $(V_MAJOR): LIBTOOL += --silent FIRMWARE_DIRS = artec_eplus48u gt68xx snapscan epjitsu +BUILT_SOURCES = + # Needed by most backends as they add sane_strstatus.lo to their list # of libraries to link with via libsane_${BACKEND}_la_LIBADD. Due to # the implicit dependency, automake does not notice the need to clean @@ -93,7 +95,8 @@ becfg: $(BACKEND_CONFS) SUFFIXES = .conf.in .conf .conf.in.conf: - @echo Generating $@ from $^ + $(AM_V_GEN) + @if $(AM_V_P); then echo Generating $@ from $^; fi @sed -e 's|@DATADIR@|$(datadir)|g' \ -e 's|@CONFIGDIR@|$(configdir)|g' \ -e 's|@DOCDIR@|$(docdir)|g' \ @@ -109,9 +112,9 @@ install-data-hook: install-becfg install-firmware-path $(INSTALL_LOCKPATH) # are not lost. install-becfg: becfg @# Libtool has a bug where it will sometimes symlink the last - @# installed library in $(sanelibdir) to $(sanelibdir)/libsane.*. - @# Having two libsane's can cause issues so get rid of it. - -rm -f $(DESTDIR)$(sanelibdir)/libsane.* + @# installed library in $(execsanelibdir) to libsane.*, which + @# causes a conflict with the actual libsane.* in $(libdir). + -rm -f $(DESTDIR)$(execsanelibdir)/libsane.* test -z "$(configdir)" || $(MKDIR_P) "$(DESTDIR)$(configdir)" test -z "$(configdir)/dll.d" || $(MKDIR_P) "$(DESTDIR)$(configdir)/dll.d" @list="$(BACKEND_CONFS_ENABLED) saned.conf dll.conf"; for cfg in $$list; do \ @@ -225,8 +228,11 @@ EXTRA_LTLIBRARIES = $(be_convenience_libs) $(be_dlopen_libs) lib_LTLIBRARIES = libsane.la -sanelibdir = $(libdir)/sane -sanelib_LTLIBRARIES = $(BACKEND_LIBS_ENABLED) libsane-dll.la +# The libraries in $(libdir)/sane are platform-dependent files, so they +# should be installed during "make install-exec". For that reason, the +# variable names here must contain "exec". +execsanelibdir = $(libdir)/sane +execsanelib_LTLIBRARIES = $(BACKEND_LIBS_ENABLED) libsane-dll.la COMMON_LIBS = ../lib/liblib.la $(XML_LIBS) @@ -678,6 +684,7 @@ libsane_epson_la_LIBADD = $(COMMON_LIBS) \ ../sanei/sanei_usb.lo \ ../sanei/sanei_scsi.lo \ ../sanei/sanei_pio.lo \ + ../sanei/sanei_directio.lo \ $(SCSI_LIBS) $(USB_LIBS) $(RESMGR_LIBS) EXTRA_DIST += epson.conf.in @@ -699,6 +706,7 @@ libsane_epson2_la_LIBADD = $(COMMON_LIBS) \ ../sanei/sanei_pio.lo \ ../sanei/sanei_tcp.lo \ ../sanei/sanei_udp.lo \ + ../sanei/sanei_directio.lo \ $(SCSI_LIBS) $(USB_LIBS) $(SOCKET_LIBS) $(MATH_LIB) $(RESMGR_LIBS) EXTRA_DIST += epson2.conf.in @@ -853,6 +861,7 @@ libsane_hp_la_LIBADD = $(COMMON_LIBS) \ ../sanei/sanei_scsi.lo \ ../sanei/sanei_pio.lo \ ../sanei/sanei_thread.lo \ + ../sanei/sanei_directio.lo \ $(SCSI_LIBS) $(USB_LIBS) $(SANEI_THREAD_LIBS) $(RESMGR_LIBS) EXTRA_DIST += hp.conf.in # TODO: These should be moved to ../docs/hp; don't belong here. @@ -1243,6 +1252,7 @@ libsane_mustek_la_LIBADD = $(COMMON_LIBS) \ ../sanei/sanei_thread.lo \ ../sanei/sanei_ab306.lo \ ../sanei/sanei_pa4s2.lo \ + ../sanei/sanei_directio.lo \ $(IEEE1284_LIBS) $(SCSI_LIBS) $(SANEI_THREAD_LIBS) $(RESMGR_LIBS) EXTRA_DIST += mustek.conf.in # TODO: Why are these distributed but not compiled? @@ -1261,6 +1271,7 @@ libsane_mustek_pp_la_LIBADD = $(COMMON_LIBS) \ ../sanei/sanei_config.lo \ sane_strstatus.lo \ ../sanei/sanei_pa4s2.lo \ + ../sanei/sanei_directio.lo \ $(MATH_LIB) $(IEEE1284_LIBS) EXTRA_DIST += mustek_pp.conf.in # TODO: Why are these distributed but not compiled? @@ -1420,7 +1431,9 @@ libsane_pint_la_LIBADD = $(COMMON_LIBS) \ ../sanei/sanei_config.lo \ sane_strstatus.lo -libpixma_la_SOURCES = pixma/pixma.c \ +libpixma_la_SOURCES = \ + pixma/pixma_sane_options.h \ + pixma/pixma.c \ pixma/pixma.h \ pixma/pixma_io_sanei.c \ pixma/pixma_io.h \ @@ -1437,26 +1450,25 @@ libpixma_la_SOURCES = pixma/pixma.c \ pixma/pixma_rename.h libpixma_la_CPPFLAGS = $(AM_CPPFLAGS) $(XML_CFLAGS) -DBACKEND_NAME=pixma -# Generate options files included by pixma/pixma.c from said file. -# The circular dependency means we cannot add it as a prerequisite -# for the targets that build the options files. - -$(srcdir)/pixma/pixma.c: \ - $(srcdir)/pixma/pixma_sane_options.h \ - $(srcdir)/pixma/pixma_sane_options.c - -$(srcdir)/pixma/pixma_sane_options.h: - @echo Generating $@ from $(@D)/pixma.c - @(cd $(@D); $(PYTHON) scripts/pixma_gen_options.py h < pixma.c > $(@F)) -$(srcdir)/pixma/pixma_sane_options.c: - @echo Generating $@ from $(@D)/pixma.c - @(cd $(@D); $(PYTHON) scripts/pixma_gen_options.py < pixma.c > $(@F)) +$(srcdir)/pixma/pixma_sane_options.h: $(srcdir)/pixma/pixma.c + @if $(AM_V_P); then \ + echo "Generating pixma/$(@F) from pixma/$(^F)"; \ + else \ + echo " GEN pixma/$(@F)"; \ + fi + @$(PYTHON) $(srcdir)/pixma/scripts/pixma_gen_options.py h < $^ > $@ +$(srcdir)/pixma/pixma_sane_options.c: $(srcdir)/pixma/pixma.c + @if $(AM_V_P); then \ + echo "Generating pixma/$(@F) from pixma/$(^F)"; \ + else \ + echo " GEN pixma/$(@F)"; \ + fi + @$(PYTHON) $(srcdir)/pixma/scripts/pixma_gen_options.py < $^ > $@ +BUILT_SOURCES += pixma/pixma_sane_options.c +BUILT_SOURCES += pixma/pixma_sane_options.h EXTRA_DIST += pixma/pixma_sane_options.c -EXTRA_DIST += pixma/pixma_sane_options.h EXTRA_DIST += pixma/scripts/pixma_gen_options.py -CLEANFILES += pixma/pixma_sane_options.c -CLEANFILES += pixma/pixma_sane_options.h nodist_libsane_pixma_la_SOURCES = pixma-s.c libsane_pixma_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=pixma @@ -1498,7 +1510,16 @@ libplustek_pp_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=plustek_pp nodist_libsane_plustek_pp_la_SOURCES = plustek_pp-s.c libsane_plustek_pp_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=plustek_pp libsane_plustek_pp_la_LDFLAGS = $(DIST_SANELIBS_LDFLAGS) -libsane_plustek_pp_la_LIBADD = $(COMMON_LIBS) libplustek_pp.la ../sanei/sanei_init_debug.lo ../sanei/sanei_constrain_value.lo ../sanei/sanei_config.lo sane_strstatus.lo ../sanei/sanei_pp.lo ../sanei/sanei_thread.lo $(MATH_LIB) $(IEEE1284_LIBS) $(SANEI_THREAD_LIBS) +libsane_plustek_pp_la_LIBADD = $(COMMON_LIBS) \ + libplustek_pp.la \ + ../sanei/sanei_init_debug.lo \ + ../sanei/sanei_constrain_value.lo \ + ../sanei/sanei_config.lo \ + sane_strstatus.lo \ + ../sanei/sanei_pp.lo \ + ../sanei/sanei_thread.lo \ + ../sanei/sanei_directio.lo \ + $(MATH_LIB) $(IEEE1284_LIBS) $(SANEI_THREAD_LIBS) EXTRA_DIST += plustek_pp.conf.in # TODO: Why are these distributed but not compiled? EXTRA_DIST += plustek-pp_dac.c plustek-pp_dbg.h plustek-pp_detect.c plustek-pp_genericio.c plustek-pp_hwdefs.h plustek-pp_image.c plustek-pp_io.c plustek-pp_map.c plustek-pp_misc.c plustek-pp_models.c plustek-pp_motor.c plustek-pp_p12.c plustek-pp_p12ccd.c plustek-pp_p48xx.c plustek-pp_p9636.c plustek-pp_procfs.c plustek-pp_procs.h plustek-pp_ptdrv.c plustek-pp_scale.c plustek-pp_scan.h plustek-pp_scandata.h plustek-pp_sysdep.h plustek-pp_tpa.c plustek-pp_types.h plustek-pp_wrapper.c @@ -1528,7 +1549,8 @@ libsane_qcam_la_LIBADD = $(COMMON_LIBS) \ ../sanei/sanei_constrain_value.lo \ ../sanei/sanei_config.lo \ sane_strstatus.lo \ - ../sanei/sanei_pio.lo + ../sanei/sanei_pio.lo \ + ../sanei/sanei_directio.lo EXTRA_DIST += qcam.conf.in @@ -1903,6 +1925,7 @@ libsane_umax_pp_la_LIBADD = $(COMMON_LIBS) \ ../sanei/sanei_init_debug.lo \ ../sanei/sanei_constrain_value.lo \ ../sanei/sanei_config.lo \ + ../sanei/sanei_directio.lo \ sane_strstatus.lo \ $(MATH_LIB) EXTRA_DIST += umax_pp.conf.in @@ -1939,6 +1962,7 @@ libsane_xerox_mfp_la_LIBADD = $(COMMON_LIBS) \ $(MATH_LIB) $(SOCKET_LIBS) $(USB_LIBS) $(RESMGR_LIBS) EXTRA_DIST += xerox_mfp.conf.in +nodist_libdll_preload_la_SOURCES = dll-preload.h libdll_preload_la_SOURCES = dll.c libdll_preload_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=dll -DENABLE_PRELOAD libdll_preload_la_LIBADD = ../sanei/sanei_usb.lo \ @@ -1947,7 +1971,7 @@ libdll_la_SOURCES = dll.c libdll_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=dll libdll_la_LIBADD = ../sanei/sanei_usb.lo \ $(USB_LIBS) $(XML_LIBS) -BUILT_SOURCES = dll-preload.h +BUILT_SOURCES += dll-preload.h CLEANFILES += dll-preload.h nodist_libsane_dll_la_SOURCES = dll-s.c @@ -2001,6 +2025,7 @@ PRELOADABLE_BACKENDS_LIBS = \ ../sanei/sanei_tcp.lo \ ../sanei/sanei_udp.lo \ ../sanei/sanei_magic.lo \ + ../sanei/sanei_directio.lo \ $(LIBV4L_LIBS) $(MATH_LIB) \ $(IEEE1284_LIBS) \ $(TIFF_LIBS) \ @@ -2035,6 +2060,7 @@ PRELOADABLE_BACKENDS_DEPS = ../sanei/sanei_config2.lo \ ../sanei/sanei_tcp.lo \ ../sanei/sanei_udp.lo \ ../sanei/sanei_magic.lo \ + ../sanei/sanei_directio.lo \ $(SANEI_SANEI_JPEG_LO) endif nodist_libsane_la_SOURCES = dll-s.c diff --git a/backend/abaton.c b/backend/abaton.c index 06e60f1..3aaf7ce 100644 --- a/backend/abaton.c +++ b/backend/abaton.c @@ -236,8 +236,8 @@ wait_ready (int fd) static SANE_Status sense_handler (int scsi_fd, u_char * result, void *arg) { - scsi_fd = scsi_fd; /* silence gcc */ - arg = arg; /* silence gcc */ + (void) scsi_fd; /* silence gcc */ + (void) arg; /* silence gcc */ switch (result[2] & 0x0F) { @@ -850,7 +850,7 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize) size_t len; FILE *fp; - authorize = authorize; /* silence gcc */ + (void) authorize; /* silence gcc */ DBG_INIT (); @@ -915,7 +915,7 @@ sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only) Abaton_Device *dev; int i; - local_only = local_only; /* silence gcc */ + (void) local_only; /* silence gcc */ if (devlist) free (devlist); @@ -1399,7 +1399,7 @@ sane_read (SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, status = sanei_scsi_cmd (s->fd, test_unit_ready, sizeof (test_unit_ready), 0, 0); - if (status != SANE_STATUS_GOOD || status != SANE_STATUS_INVAL) + if (status != SANE_STATUS_GOOD && status != SANE_STATUS_INVAL) return status; return SANE_STATUS_CANCELLED; } @@ -1472,8 +1472,8 @@ sane_cancel (SANE_Handle handle) SANE_Status sane_set_io_mode (SANE_Handle handle, SANE_Bool non_blocking) { - handle = handle; /* silence gcc */ - non_blocking = non_blocking; /* silence gcc */ + (void) handle; /* silence gcc */ + (void) non_blocking; /* silence gcc */ DBG (FLOW_CONTROL, "sane_set_io_mode: Don't call me please. " "Unimplemented function\n"); @@ -1483,8 +1483,8 @@ sane_set_io_mode (SANE_Handle handle, SANE_Bool non_blocking) SANE_Status sane_get_select_fd (SANE_Handle handle, SANE_Int * fd) { - handle = handle; /* silence gcc */ - fd = fd; /* silence gcc */ + (void) handle; /* silence gcc */ + (void) fd; /* silence gcc */ DBG (FLOW_CONTROL, "sane_get_select_fd: Don't call me please. " "Unimplemented function\n"); diff --git a/backend/agfafocus.c b/backend/agfafocus.c index d972f59..f297e41 100644 --- a/backend/agfafocus.c +++ b/backend/agfafocus.c @@ -236,8 +236,8 @@ test_ready (int fd) static SANE_Status sense_handler (int scsi_fd, u_char *result, void *arg) { - scsi_fd = scsi_fd; /* silence gcc */ - arg = arg; /* silence gcc */ + (void) scsi_fd; /* silence gcc */ + (void) arg; /* silence gcc */ if (result[0]) { @@ -253,7 +253,7 @@ sense_handler (int scsi_fd, u_char *result, void *arg) static SANE_Status stop_scan (int fd) { - fd = fd; /* silence gcc */ + (void) fd; /* silence gcc */ /* XXX don't know how to stop the scanner. To be tested ! */ #if 0 @@ -1280,7 +1280,7 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize) size_t len; FILE *fp; - authorize = authorize; /* silence gcc */ + (void) authorize; /* silence gcc */ DBG_INIT (); @@ -1335,7 +1335,7 @@ sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only) AgfaFocus_Device *dev; int i; - local_only = local_only; /* silence gcc */ + (void) local_only; /* silence gcc */ if (devlist) free (devlist); diff --git a/backend/apple.c b/backend/apple.c index 7b37248..b360e5c 100644 --- a/backend/apple.c +++ b/backend/apple.c @@ -328,8 +328,8 @@ return SANE_STATUS_GOOD; static SANE_Status sense_handler (int scsi_fd, u_char * result, void *arg) { - scsi_fd = scsi_fd; /* silence gcc */ - arg = arg; /* silence gcc */ + (void) scsi_fd; /* silence gcc */ + (void) arg; /* silence gcc */ switch (result[2] & 0x0F) { @@ -1866,7 +1866,7 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize) size_t len; FILE *fp; - authorize = authorize; /* silence gcc */ + (void) authorize; /* silence gcc */ DBG_INIT (); @@ -1930,7 +1930,7 @@ sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only) Apple_Device *dev; int i; - local_only = local_only; /* silence gcc */ + (void) local_only; /* silence gcc */ if (devlist) free (devlist); @@ -2667,7 +2667,7 @@ sane_set_io_mode (SANE_Handle handle, SANE_Bool non_blocking) { DBG (FLOW_CONTROL,"sane_set_io_mode: Entering.\n"); - handle = handle; /* silence gcc */ + (void) handle; /* silence gcc */ if (non_blocking) { @@ -2682,8 +2682,8 @@ return SANE_STATUS_GOOD; SANE_Status sane_get_select_fd (SANE_Handle handle, SANE_Int * fd) { - handle = handle; /* silence gcc */ - fd = fd; /* silence gcc */ + (void) handle; /* silence gcc */ + (void) fd; /* silence gcc */ DBG (FLOW_CONTROL, "sane_get_select_fd: Don't call me please. " "Unimplemented function\n"); diff --git a/backend/artec.c b/backend/artec.c index ea211eb..61007c8 100644 --- a/backend/artec.c +++ b/backend/artec.c @@ -3474,7 +3474,7 @@ artec_sane_read (SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, SANE_Int SANE_Byte line_buf[ARTEC_MAX_READ_SIZE]; - DBG (7, "artec_sane_read( %p, %p, %d, %d )\n", handle, buf, max_len, *len); + DBG (7, "artec_sane_read( %p, %p, %d, %d )\n", handle, (void *) buf, max_len, *len); *len = 0; @@ -3674,7 +3674,7 @@ sane_read (SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, SANE_Int * len static SANE_Byte temp_buf[ARTEC_MAX_READ_SIZE]; static int bytes_in_buf = 0; - DBG (7, "sane_read( %p, %p, %d, %d )\n", handle, buf, max_len, *len); + DBG (7, "sane_read( %p, %p, %d, %d )\n", handle, (void *) buf, max_len, *len); DBG (9, "sane_read: bib = %d, ml = %d\n", bytes_in_buf, max_len); if (bytes_in_buf != 0) diff --git a/backend/artec_eplus48u.c b/backend/artec_eplus48u.c index a4a3c24..e96e96f 100644 --- a/backend/artec_eplus48u.c +++ b/backend/artec_eplus48u.c @@ -351,9 +351,6 @@ static void finish_shading_buffer (Artec48U_Scanner * s, SANE_Bool white) { unsigned int i, j, cnt, c, div; - unsigned long max_r; - unsigned long max_g; - unsigned long max_b; unsigned char *shading_buffer; cnt = 0; @@ -379,18 +376,12 @@ finish_shading_buffer (Artec48U_Scanner * s, SANE_Bool white) ++cnt; } } - max_r = 0; - max_g = 0; - max_b = 0; for (c = 0; c < (30720 * s->dev->epro_mult) - 5; c += 6) /*epro*/ { i = (int) shading_buffer[c] + ((int) shading_buffer[c + 1] << 8); - max_r += i; i = (int) shading_buffer[c + 2] + ((int) shading_buffer[c + 3] << 8); - max_g += i; i = (int) shading_buffer[c + 4] + ((int) shading_buffer[c + 5] << 8); - max_b += i; } } @@ -1628,7 +1619,7 @@ artec48u_device_memory_read (Artec48U_Device * dev, SANE_Status status; XDBG ((8, "%s: dev=%p, addr=0x%x, size=0x%x, data=%p\n", - function_name, (void *) dev, addr, size, data)); + function_name, (void *) dev, addr, size, (void *) data)); CHECK_DEV_ACTIVE (dev, function_name); status = sanei_usb_control_msg (dev->fd, 0xc0, 0x01, diff --git a/backend/avision.c b/backend/avision.c index b81578a..c807d9f 100644 --- a/backend/avision.c +++ b/backend/avision.c @@ -112,7 +112,7 @@ * * . . - sane_cancel() : cancel operation, kill reader_process * - * . - sane_close() : close opened scanner-device, do_cancel, free buffer and handle + * . - sane_close() : do_cancel, close opened scanner-device, free buffer and handle * - sane_exit() : terminate use of backend, free devicename and device-structure */ @@ -159,6 +159,15 @@ static Avision_HWEntry Avision_Device_List [] = { + { NULL, NULL, + 0x0638, 0x2E59, + "Avision", "AD345F", + AV_INT_BUTTON | AV_CANCEL_BUTTON | AV_USE_GRAY_FILTER, + { 0, {0, 0}, {{0, 0}, {0, 0}} } + }, + /* comment="duplex! sheetfed + flatbed scanner" */ + /* status="basic" */ + { "AVISION", "AV100CS", 0, 0, "Avision", "AV100CS", @@ -688,6 +697,15 @@ static Avision_HWEntry Avision_Device_List [] = /* comment="1 pass, 600 dpi, zero-edge" ASIC 7 */ /* status="basic" */ + { NULL, NULL, + 0x0638, 0x2a1f, + "Avision", "FB2280E", + 0, + { 0, {0, 0}, {{0, 0}, {0, 0}} } + }, + /* comment="1 pass, 600 dpi, zero-edge" ASIC 7 */ + /* status="basic" */ + { "AVISION", "AV8000S", 0, 0, "Avision", "AV8000S", @@ -1592,7 +1610,7 @@ Lexmark X4500 MFP }\ }\ -static int num_devices; +static unsigned int num_devices; static Avision_Device* first_dev; static Avision_Scanner* first_handle; static const SANE_Device** devlist = 0; @@ -2149,8 +2167,8 @@ sense_handler (int fd, u_char* sense, void* arg) uint8_t sense_key = sense[2] & 0xf; uint8_t additional_sense = sense[7]; - fd = fd; /* silence gcc */ - arg = arg; /* silence gcc */ + (void) fd; /* silence gcc */ + (void) arg; /* silence gcc */ DBG (3, "sense_handler:\n"); @@ -2690,8 +2708,8 @@ bubble_sort (uint8_t* sort_data, size_t count) for (j = (i + 1); j < count; ++j) { - ti = get_double ((sort_data + i*2)); - tj = get_double ((sort_data + j*2)); + ti = (uint16_t) get_double ((sort_data + i*2)); + tj = (uint16_t) get_double ((sort_data + j*2)); if (ti > tj) { set_double ((sort_data + i*2), tj); @@ -2708,7 +2726,7 @@ bubble_sort (uint8_t* sort_data, size_t count) /* DBG (7, "bubble_sort: %d values for average\n", k); */ if (k > 0) /* if avg to compute */ - return (uint16_t) (sum / k); + return (uint16_t) (sum /(double) k); else return (uint16_t) (sum); /* always zero? */ } @@ -2969,14 +2987,14 @@ compute_parameters (Avision_Scanner* s) SANE_UNFIX (s->val[OPT_BR_X].w), SANE_UNFIX (s->val[OPT_BR_Y].w)); /* window parameter in pixel */ - s->avdimen.tlx = s->avdimen.hw_xres * SANE_UNFIX (s->val[OPT_TL_X].w) - / MM_PER_INCH; - s->avdimen.tly = s->avdimen.hw_yres * SANE_UNFIX (s->val[OPT_TL_Y].w) - / MM_PER_INCH; - s->avdimen.brx = s->avdimen.hw_xres * SANE_UNFIX (s->val[OPT_BR_X].w) - / MM_PER_INCH; - s->avdimen.bry = s->avdimen.hw_yres * SANE_UNFIX (s->val[OPT_BR_Y].w) - / MM_PER_INCH; + s->avdimen.tlx = (long int) (s->avdimen.hw_xres * SANE_UNFIX (s->val[OPT_TL_X].w) + / MM_PER_INCH); + s->avdimen.tly = (long int) (s->avdimen.hw_yres * SANE_UNFIX (s->val[OPT_TL_Y].w) + / MM_PER_INCH); + s->avdimen.brx = (long int) (s->avdimen.hw_xres * SANE_UNFIX (s->val[OPT_BR_X].w) + / MM_PER_INCH); + s->avdimen.bry = (long int) (s->avdimen.hw_yres * SANE_UNFIX (s->val[OPT_BR_Y].w) + / MM_PER_INCH); /* line difference */ if (color_mode_is_color (s->c_mode) && @@ -2990,8 +3008,8 @@ compute_parameters (Avision_Scanner* s) /* limit bry + line_difference to real scan boundary */ { - long y_max = dev->inquiry_y_ranges[s->source_mode_dim] * - s->avdimen.hw_yres / MM_PER_INCH; + long y_max = (long int) (dev->inquiry_y_ranges[s->source_mode_dim] * + s->avdimen.hw_yres / MM_PER_INCH); DBG (3, "sane_compute_parameters: y_max: %ld, bry: %ld, line_difference: %d\n", y_max, s->avdimen.bry, s->avdimen.line_difference); @@ -3009,10 +3027,10 @@ compute_parameters (Avision_Scanner* s) /* add overscan */ if (dev->inquiry_tune_scan_length && is_adf_scan (s)) { /* some extra effort for precise rounding ... */ - int overscan = (s->avdimen.hw_yres * + int overscan = (int) ((s->avdimen.hw_yres * (SANE_UNFIX (s->val[OPT_OVERSCAN_TOP].w) + SANE_UNFIX (s->val[OPT_OVERSCAN_BOTTOM].w)) + (MM_PER_INCH - 1) - ) / MM_PER_INCH; + ) / MM_PER_INCH); DBG (3, "sane_compute_parameters: overscan lines: %d\n", overscan); s->avdimen.bry += overscan; } @@ -3171,10 +3189,10 @@ compute_parameters (Avision_Scanner* s) memset (&s->params, 0, sizeof (s->params)); - s->avdimen.hw_pixels_per_line = (s->avdimen.brx - s->avdimen.tlx); + s->avdimen.hw_pixels_per_line = (int) (s->avdimen.brx - s->avdimen.tlx); s->avdimen.hw_pixels_per_line -= s->avdimen.hw_pixels_per_line % boundary; - s->avdimen.hw_lines = (s->avdimen.bry - s->avdimen.tly - + s->avdimen.hw_lines = (int) (s->avdimen.bry - s->avdimen.tly - 2 * s->avdimen.line_difference); if (s->avdimen.interlaced_duplex && dev->scanner_type != AV_FILM) @@ -3252,7 +3270,7 @@ inquiry (Avision_Connection av_con, uint8_t* data, size_t len) memset (&inquiry, 0, sizeof(inquiry)); inquiry.opc = AVISION_SCSI_INQUIRY; - inquiry.len = len; + inquiry.len = (uint8_t) len; do { size_t size = inquiry.len; @@ -3281,7 +3299,7 @@ wait_ready (Avision_Connection* av_con, int delay) DBG (3, "wait_ready: sending TEST_UNIT_READY\n"); status = avision_cmd (av_con, test_unit_ready, sizeof (test_unit_ready), 0, 0, 0, 0); - sleep (delay); + sleep ((unsigned int) delay); switch (status) { @@ -3338,6 +3356,7 @@ wait_4_light (Avision_Scanner* s) status = avision_cmd (&s->av_con, &rcmd, sizeof (rcmd), 0, 0, &result, &size); if (status != SANE_STATUS_GOOD || size != sizeof (result)) { + status = (status != SANE_STATUS_GOOD)? status: SANE_STATUS_IO_ERROR; DBG (1, "wait_4_light: read failed (%s)\n", sane_strstatus (status)); return status; } @@ -3432,6 +3451,7 @@ get_firmware_status (Avision_Connection* av_con) status = avision_cmd (av_con, &rcmd, sizeof (rcmd), 0, 0, &result, &size); if (status != SANE_STATUS_GOOD || size != sizeof (result)) { + status = (status != SANE_STATUS_GOOD)? status: SANE_STATUS_IO_ERROR; DBG (1, "get_firmware_status: read failed (%s)\n", sane_strstatus (status)); return (status); @@ -3469,6 +3489,7 @@ get_flash_ram_info (Avision_Connection* av_con) status = avision_cmd (av_con, &rcmd, sizeof (rcmd), 0, 0, result, &size); if (status != SANE_STATUS_GOOD || size != sizeof (result)) { + status = (status != SANE_STATUS_GOOD)? status: SANE_STATUS_IO_ERROR; DBG (1, "get_flash_ram_info: read failed (%s)\n", sane_strstatus (status)); return (status); @@ -3550,21 +3571,21 @@ get_nvram_data (Avision_Scanner* s, nvram_data* nvram) } static SANE_Status -get_and_parse_nvram (Avision_Scanner* s, char* str, int n) +get_and_parse_nvram (Avision_Scanner* s, char* str, size_t n) { SANE_Status status; - int i = 0; + size_t i = 0; int x; nvram_data nvram; uint8_t inquiry_result [AVISION_INQUIRY_SIZE_V1]; status = inquiry (s->av_con, inquiry_result, sizeof(inquiry_result)); if (status == SANE_STATUS_GOOD) { - i += snprintf (str+i, n-i, "Vendor: %.8s", + i += (size_t) snprintf (str+i, n-i, "Vendor: %.8s", inquiry_result+8); - i += snprintf (str+i, n-i, "\nModel: %.16s", + i += (size_t) snprintf (str+i, n-i, "\nModel: %.16s", inquiry_result+16); - i += snprintf (str+i, n-i, "\nFirmware: %.4s", + i += (size_t) snprintf (str+i, n-i, "\nFirmware: %.4s", inquiry_result+32); } @@ -3575,32 +3596,32 @@ get_and_parse_nvram (Avision_Scanner* s, char* str, int n) if (status == SANE_STATUS_GOOD) { if (nvram.serial[0]) - i += snprintf (str+i, n-i, "\nSerial: %.24s", + i += (size_t) snprintf (str+i, n-i, "\nSerial: %.24s", nvram.serial); - if (nvram.born_year) - i += snprintf (str+i, n-i, "\nManufacturing date: %d-%d-%d", + if (get_double(nvram.born_year)) + i += (size_t) snprintf (str+i, n-i, "\nManufacturing date: %d-%d-%d", get_double(nvram.born_year), get_double(nvram.born_month), get_double(nvram.born_day)); - if (nvram.first_scan_year) - i += snprintf (str+i, n-i, "\nFirst scan date: %d-%d-%d", + if (get_double(nvram.first_scan_year)) + i += (size_t) snprintf (str+i, n-i, "\nFirst scan date: %d-%d-%d", get_double(nvram.first_scan_year), get_double(nvram.first_scan_month), get_double(nvram.first_scan_day)); x = get_quad (nvram.flatbed_scans); if (x) - i += snprintf (str+i, n-i, "\nFlatbed scans: %d", x); + i += (size_t) snprintf (str+i, n-i, "\nFlatbed scans: %d", x); x = get_quad (nvram.pad_scans); if (x) - i += snprintf (str+i, n-i, "\nPad scans: %d", x); + i += (size_t) snprintf (str+i, n-i, "\nPad scans: %d", x); x = get_quad (nvram.adf_simplex_scans); if (x) - i += snprintf (str+i, n-i, "\nADF simplex scans: %d", x); + i += (size_t) snprintf (str+i, n-i, "\nADF simplex scans: %d", x); x = get_quad (nvram.adf_duplex_scans); if (x) - i += snprintf (str+i, n-i, "\nADF duplex scans: %d", x); + i += (size_t) snprintf (str+i, n-i, "\nADF duplex scans: %d", x); } return status; @@ -3703,12 +3724,12 @@ adf_reset (Avision_Scanner* s) uint8_t payload[4]; size_t size; size_t n; - int i; + ssize_t i; DBG (3, "adf_reset\n"); /* loop twice */ for (i=1; i >= 0; i--) { - n=i; + n= (size_t) i; memset (&scmd, 0, sizeof (scmd)); memset (&payload, 0, sizeof (payload)); scmd.opc = AVISION_SCSI_SEND; @@ -3716,26 +3737,26 @@ adf_reset (Avision_Scanner* s) set_double (scmd.datatypequal, 0); size = 2; set_triple (scmd.transferlen, size); - payload[1] = 0x10 * i; /* write 0x10 the first time, 0x00 the second */ + payload[1] = (uint8_t) (0x10 * i); /* write 0x10 the first time, 0x00 the second */ status = avision_cmd (&s->av_con, &scmd, sizeof (scmd), payload, size, 0, 0); if (status != SANE_STATUS_GOOD) { - DBG (1, "adf_reset: write %d failed (%s)\n", (2-i), + DBG (1, "adf_reset: write %zu failed (%s)\n", (2-i), sane_strstatus (status)); return (status); } - DBG (3, "adf_reset: write %d complete.\n", (2-i)); + DBG (3, "adf_reset: write %zu complete.\n", (2-i)); memset (&rcmd, 0, sizeof (rcmd)); memset (&payload, 0, sizeof (payload)); rcmd.opc = AVISION_SCSI_READ; rcmd.datatypecode = AVISION_DATATYPECODE_READ_NVRAM_DATA; /* Read NVRAM data */ set_double (rcmd.datatypequal, dev->data_dq); - size = 4 - i; /* read 3 bytes the first time, 4 the second */ + size = (size_t) (4 - i); /* read 3 bytes the first time, 4 the second */ set_triple (rcmd.transferlen, size); status = avision_cmd (&s->av_con, &rcmd, sizeof (rcmd), 0, 0, payload, &size); if (status != SANE_STATUS_GOOD || size != (4-n)) { - DBG (1, "adf_reset: read %zu failed (%s)\n", (4-n), - sane_strstatus (status)); + status = (status != SANE_STATUS_GOOD)? status: SANE_STATUS_IO_ERROR; + DBG (1, "adf_reset: read %zu failed (%s)\n", (4-n), sane_strstatus (status)); return (status); } debug_print_raw (3, "adf_reset: raw data:\n", payload, size); @@ -3776,8 +3797,8 @@ get_accessories_info (Avision_Scanner* s) status = avision_cmd (&s->av_con, &rcmd, sizeof (rcmd), 0, 0, result, &size); if (status != SANE_STATUS_GOOD || size != sizeof (result)) { - DBG (1, "get_accessories_info: read failed (%s)\n", - sane_strstatus (status)); + status = (status != SANE_STATUS_GOOD)? status: SANE_STATUS_IO_ERROR; + DBG (1, "get_accessories_info: read failed (%s)\n", sane_strstatus (status)); return (status); } @@ -3839,7 +3860,7 @@ get_accessories_info (Avision_Scanner* s) /* Returns a pointer to static char* strings or NULL for cancel (we do not want to start memcmp'ing for the cancel case). */ static const char* -string_for_button (Avision_Scanner* s, int button) +string_for_button (Avision_Scanner* s, uint8_t button) { static char buffer [16]; Avision_Device* dev = s->hw; @@ -3931,6 +3952,7 @@ get_button_status (Avision_Scanner* s) status = avision_cmd (&s->av_con, &rcmd, sizeof (rcmd), 0, 0, (uint8_t*)&result, &size); if (status != SANE_STATUS_GOOD || size != sizeof (result)) { + status = (status != SANE_STATUS_GOOD)? status: SANE_STATUS_IO_ERROR; DBG (1, "get_button_status: read failed (%s)\n", sane_strstatus (status)); return status; } @@ -3982,7 +4004,7 @@ get_button_status (Avision_Scanner* s) /* simulate button press of the last button ... */ result.press_state = 0x80 | 1; - result.buttons[0] = dev->inquiry_buttons; /* 1 based */ + result.buttons[0] = (uint8_t) dev->inquiry_buttons; /* 1 based */ } } @@ -4001,7 +4023,7 @@ get_button_status (Avision_Scanner* s) char* message = message_begin; #define add_token(format,value) do { \ - int n = snprintf (message, message_end - message, "%s" format, \ + int n = snprintf (message, (size_t) (message_end - message), "%s" format, \ message == message_begin ? "" : ":", value); \ message += n > 0 ? n : 0; \ } while (0) @@ -4041,7 +4063,7 @@ get_button_status (Avision_Scanner* s) } for (i = 0; i < buttons_pressed; ++i) { - const unsigned int button = result.buttons[i] - 1; /* 1 based ... */ + const uint8_t button = result.buttons[i] - 1; /* 1 based ... */ DBG (3, "get_button_status: button %d pressed\n", button); if (button >= dev->inquiry_buttons) { DBG (1, "get_button_status: button %d not allocated as not indicated in inquiry\n", @@ -4089,6 +4111,7 @@ get_frame_info (Avision_Scanner* s) status = avision_cmd (&s->av_con, &rcmd, sizeof (rcmd), 0, 0, result, &size); if (status != SANE_STATUS_GOOD || size != sizeof (result)) { + status = (status != SANE_STATUS_GOOD)? status: SANE_STATUS_IO_ERROR; DBG (1, "get_frame_info: read failed (%s)\n", sane_strstatus (status)); return (status); } @@ -4104,10 +4127,10 @@ get_frame_info (Avision_Scanner* s) DBG (3, "get_frame_info: [2] Frame amount: %d\n", result[2]); DBG (3, "get_frame_info: [3] Mode: %s\n", BIT(result[3],4)?"APS":"Not APS"); DBG (3, "get_frame_info: [3] Exposures (if APS): %s\n", - ((i=(BIT(result[3],3)<<1)+BIT(result[2],2))==0)?"Unknown": + ((i=(size_t) (BIT(result[3],3)<<1)+BIT(result[2],2))==0)?"Unknown": (i==1)?"15":(i==2)?"25":"40"); DBG (3, "get_frame_info: [3] Film Type (if APS): %s\n", - ((i=(BIT(result[1],3)<<1)+BIT(result[0],2))==0)?"Unknown": + ((i=(size_t) (BIT(result[1],3)<<1)+BIT(result[0],2))==0)?"Unknown": (i==1)?"B&W Negative":(i==2)?"Color slide":"Color Negative"); dev->holder_type = result[0]; @@ -4157,6 +4180,7 @@ get_duplex_info (Avision_Scanner* s) status = avision_cmd (&s->av_con, &rcmd, sizeof (rcmd), 0, 0, &result, &size); if (status != SANE_STATUS_GOOD || size != sizeof (result)) { + status = (status != SANE_STATUS_GOOD)? status: SANE_STATUS_IO_ERROR; DBG (1, "get_duplex_info: read failed (%s)\n", sane_strstatus (status)); return (status); } @@ -4220,8 +4244,8 @@ set_frame (Avision_Scanner* s, SANE_Word frame) set_double (scmd.cmd.datatypequal, dev->data_dq); set_triple (scmd.cmd.transferlen, sizeof (scmd.data) ); - scmd.data[0] = dev->holder_type; - scmd.data[1] = frame; + scmd.data[0] = (uint8_t) dev->holder_type; + scmd.data[1] = (uint8_t) frame; status = avision_cmd (&s->av_con, &scmd.cmd, sizeof (scmd.cmd), &scmd.data, sizeof (scmd.data), 0, 0); @@ -4970,7 +4994,7 @@ send_tune_scan_length (Avision_Scanner* s) if (dev->hw->feature_type & AV_OVERSCAN_OPTDPI) dpi = dev->inquiry_optical_res; - top = dpi * SANE_UNFIX (s->val[OPT_OVERSCAN_TOP].w) / MM_PER_INCH; + top = (int) (dpi * SANE_UNFIX (s->val[OPT_OVERSCAN_TOP].w) / MM_PER_INCH); DBG (3, "send_tune_scan_length: top: %d\n", top); /* top offset compensation */ @@ -4986,7 +5010,7 @@ send_tune_scan_length (Avision_Scanner* s) offset += dev->hw->offset.first; /* convert to lines */ - int top_offset = dpi * offset / MM_PER_INCH; + int top_offset = (int) (dpi * offset / MM_PER_INCH); top += top_offset; DBG (3, "send_tune_scan_length: top offset: %d\n", top_offset); } @@ -5007,7 +5031,7 @@ send_tune_scan_length (Avision_Scanner* s) } scmd.datatypecode = AVISION_DATATYPECODE_ATTACH_TRUNCATE_TAIL; /* Attach/Truncate tail(right) of scan length */ - bottom = dpi * SANE_UNFIX (s->val[OPT_OVERSCAN_BOTTOM].w) / MM_PER_INCH; + bottom = (int) (dpi * SANE_UNFIX (s->val[OPT_OVERSCAN_BOTTOM].w) / MM_PER_INCH); DBG (3, "send_tune_scan_length: bottom: %d\n", bottom); /* bottom offset compensation */ @@ -5024,7 +5048,7 @@ send_tune_scan_length (Avision_Scanner* s) offset += fabs(dev->hw->offset.first); /* convert to lines */ - int bottom_offset = dpi * offset / MM_PER_INCH; + int bottom_offset = (int) (dpi * offset / MM_PER_INCH); bottom += bottom_offset; DBG (3, "send_tune_scan_length: bottom offset: %d\n", bottom_offset); } @@ -5161,14 +5185,14 @@ get_calib_format (Avision_Scanner* s, struct calibration_format* format) DBG (3, "get_calib_format: read_data: %lu bytes\n", (u_long) size); status = avision_cmd (&s->av_con, &rcmd, sizeof (rcmd), 0, 0, result, &size); if (status != SANE_STATUS_GOOD || size != sizeof (result) ) { - DBG (1, "get_calib_format: read calib. info failed (%s)\n", - sane_strstatus (status) ); + status = (status != SANE_STATUS_GOOD)? status: SANE_STATUS_IO_ERROR; + DBG (1, "get_calib_format: read calib. info failed (%s)\n", sane_strstatus (status) ); return status; } debug_print_calib_format (3, "get_calib_format", result); - format->pixel_per_line = get_double (&(result[0])); + format->pixel_per_line = (uint16_t) get_double (&(result[0])); format->bytes_per_channel = result[2]; format->lines = result[3]; format->flags = result[4]; @@ -5176,12 +5200,12 @@ get_calib_format (Avision_Scanner* s, struct calibration_format* format) format->r_gain = result[6]; format->g_gain = result[7]; format->b_gain = result[8]; - format->r_shading_target = get_double (&(result[9])); - format->g_shading_target = get_double (&(result[11])); - format->b_shading_target = get_double (&(result[13])); - format->r_dark_shading_target = get_double (&(result[15])); - format->g_dark_shading_target = get_double (&(result[17])); - format->b_dark_shading_target = get_double (&(result[19])); + format->r_shading_target = (uint16_t) get_double (&(result[9])); + format->g_shading_target = (uint16_t) get_double (&(result[11])); + format->b_shading_target = (uint16_t) get_double (&(result[13])); + format->r_dark_shading_target = (uint16_t) get_double (&(result[15])); + format->g_dark_shading_target = (uint16_t) get_double (&(result[17])); + format->b_dark_shading_target = (uint16_t) get_double (&(result[19])); /* now translate to normal! */ /* firmware return R--RG--GB--B with 3 line count */ @@ -5261,7 +5285,7 @@ set_calib_data (Avision_Scanner* s, struct calibration_format* format, { Avision_Device* dev = s->hw; - const int elements_per_line = format->pixel_per_line * format->channels; + const size_t elements_per_line = format->pixel_per_line * format->channels; SANE_Status status; @@ -5270,7 +5294,7 @@ set_calib_data (Avision_Scanner* s, struct calibration_format* format, struct command_send scmd; - int i; + size_t i; DBG (3, "set_calib_data:\n"); @@ -5295,13 +5319,13 @@ set_calib_data (Avision_Scanner* s, struct calibration_format* format, if (BIT (format->ability1, 2) ) { DBG (3, "set_calib_data: merging dark calibration data\n"); for (i = 0; i < elements_per_line; ++i) { - uint16_t value_orig = get_double_le (white_data + i*2); + uint16_t value_orig = (uint16_t) get_double_le (white_data + i*2); uint16_t value_new = value_orig; value_new &= 0xffc0; - value_new |= (get_double_le (dark_data + i*2) >> 10) & 0x3f; + value_new |= (uint16_t) ((get_double_le (dark_data + i*2) >> 10) & 0x3f); - DBG (9, "set_calib_data: element %d, dark difference %d\n", + DBG (9, "set_calib_data: element %zu, dark difference %d\n", i, value_orig - value_new); set_double_le ((white_data + i*2), value_new); @@ -5318,7 +5342,7 @@ set_calib_data (Avision_Scanner* s, struct calibration_format* format, { size_t send_size = elements_per_line * 2; DBG (3, "set_calib_data: all channels in one command\n"); - DBG (3, "set_calib_data: send_size: %lu\n", (u_long) send_size); + DBG (3, "set_calib_data: send_size: %zu\n", send_size); memset (&scmd, 0, sizeof (scmd) ); scmd.opc = AVISION_SCSI_SEND; @@ -5332,7 +5356,7 @@ set_calib_data (Avision_Scanner* s, struct calibration_format* format, } else /* send data channel by channel (some USB ones) */ { - int conv_out_size = format->pixel_per_line * 2; + size_t conv_out_size = format->pixel_per_line * 2; uint16_t* conv_out_data; /* here it is save to use 16bit data since we only move whole words around */ @@ -5356,7 +5380,7 @@ set_calib_data (Avision_Scanner* s, struct calibration_format* format, for (i = 0; i < format->pixel_per_line; ++ i) conv_out_data [i] = casted_avg_data [i * 3 + channel]; - DBG (3, "set_calib_data: sending %i bytes now\n", + DBG (3, "set_calib_data: sending %zu bytes now\n", conv_out_size); memset (&scmd, 0, sizeof (scmd)); @@ -5393,9 +5417,9 @@ set_calib_data (Avision_Scanner* s, struct calibration_format* format, static uint8_t* sort_and_average (struct calibration_format* format, uint8_t* data) { - const int elements_per_line = format->pixel_per_line * format->channels; - const int stride = format->bytes_per_channel * elements_per_line; - int i, line; + const size_t elements_per_line = format->pixel_per_line * format->channels; + const size_t stride = format->bytes_per_channel * elements_per_line; + size_t i, line; uint8_t *sort_data, *avg_data; @@ -5454,7 +5478,7 @@ compute_dark_shading_data (Avision_Scanner* s, DBG (3, "compute_dark_shading_data:\n"); if (s->hw->inquiry_max_shading_target != INVALID_DARK_SHADING) - map_value = s->hw->inquiry_max_shading_target << 8; + map_value = (uint16_t) (s->hw->inquiry_max_shading_target << 8); rgb_map_value[0] = format->r_dark_shading_target; rgb_map_value[1] = format->g_dark_shading_target; @@ -5477,7 +5501,7 @@ compute_dark_shading_data (Avision_Scanner* s, /* Avision SCSI protocol document has bad description. */ for (i = 0; i < elements_per_line; ++i) { - uint16_t tmp_data = get_double_le((data + i*2)); + uint16_t tmp_data = (uint16_t) get_double_le((data + i*2)); if (tmp_data > rgb_map_value[i % 3]) { set_double ((data + i*2), tmp_data - rgb_map_value[i % 3]); } @@ -5504,7 +5528,7 @@ compute_white_shading_data (Avision_Scanner* s, DBG (3, "compute_white_shading_data:\n"); if (s->hw->inquiry_max_shading_target != INVALID_WHITE_SHADING) - inquiry_mst = s->hw->inquiry_max_shading_target << 4; + inquiry_mst = (uint16_t) (s->hw->inquiry_max_shading_target << 4); mst[0] = format->r_shading_target; mst[1] = format->g_shading_target; @@ -5547,14 +5571,14 @@ compute_white_shading_data (Avision_Scanner* s, { int result; /* calculate calibration value for pixel i */ - uint16_t tmp_data = get_double((data + i*2)); + uint16_t tmp_data = (uint16_t) get_double((data + i*2)); if (tmp_data == INVALID_WHITE_SHADING) { tmp_data = DEFAULT_WHITE_SHADING; ++ values_invalid; } - result = ( (int)mst[i % 3] * WHITE_MAP_RANGE / (tmp_data + 0.5)); + result = (int) ( (int)mst[i % 3] * WHITE_MAP_RANGE / (tmp_data + 0.5)); /* sanity check for over-amplification, clipping */ if (result > MAX_WHITE_SHADING) { @@ -5582,7 +5606,8 @@ normal_calibration (Avision_Scanner* s) struct calibration_format calib_format; - int calib_data_size, calib_bytes_per_line; + size_t calib_data_size; + int calib_bytes_per_line; uint8_t read_type; uint8_t *calib_tmp_data; @@ -5604,7 +5629,7 @@ normal_calibration (Avision_Scanner* s) calib_bytes_per_line = calib_format.bytes_per_channel * calib_format.pixel_per_line * calib_format.channels; - calib_data_size = calib_format.lines * calib_bytes_per_line; + calib_data_size = (size_t) calib_format.lines * (size_t) calib_bytes_per_line; calib_tmp_data = malloc (calib_data_size); if (!calib_tmp_data) @@ -5889,7 +5914,7 @@ send_gamma (Avision_Scanner* s) /* interpolate gamma_values to gamma_data */ for (k = 0; k < gamma_values; ++ k, ++ i) { gamma_data [i] = (uint8_t) - (((v1 * (gamma_values - k)) + (v2 * k) ) / (double) gamma_values); + (((v1 * (double) (gamma_values - k)) + (v2 * (double) k) ) / (double) gamma_values); } } @@ -5965,7 +5990,7 @@ send_3x3_matrix (Avision_Scanner* s) a_i = (int) a_f; /* integer */ b_f = a_f - (double) a_i; /* float */ - m |= ((a_i & 0x3) << INT_PART); + m |= (uint16_t) ((a_i & 0x3) << INT_PART); m |= (uint16_t) (b_f * 1024); set_double (((uint8_t*)(&cmd.matrix.v[i])), m); } @@ -6009,6 +6034,7 @@ get_acceleration_info (Avision_Scanner* s, struct acceleration_info* info) DBG (3, "get_acceleration_info: read_data: %lu bytes\n", (u_long) size); status = avision_cmd (&s->av_con, &rcmd, sizeof (rcmd), 0, 0, result, &size); if (status != SANE_STATUS_GOOD || size != sizeof (result) ) { + status = (status != SANE_STATUS_GOOD)? status: SANE_STATUS_IO_ERROR; DBG (1, "get_acceleration_info: read accel. info failed (%s)\n", sane_strstatus (status) ); return status; @@ -6016,12 +6042,12 @@ get_acceleration_info (Avision_Scanner* s, struct acceleration_info* info) debug_print_accel_info (3, "get_acceleration_info", result); - info->total_steps = get_double (&(result[0])); - info->stable_steps = get_double (&(result[2])); - info->table_units = get_quad (&(result[4])); - info->base_units = get_quad (&(result[8])); - info->start_speed = get_double (&(result[12])); - info->target_speed = get_double (&(result[14])); + info->total_steps = (uint16_t) get_double (&(result[0])); + info->stable_steps = (uint16_t) get_double (&(result[2])); + info->table_units = (uint32_t) get_quad (&(result[4])); + info->base_units = (uint32_t) get_quad (&(result[8])); + info->start_speed = (uint16_t) get_double (&(result[12])); + info->target_speed = (uint16_t) get_double (&(result[14])); info->ability = result[16]; info->table_count = result[17]; @@ -6076,10 +6102,10 @@ send_acceleration_table (Avision_Scanner* s) needs such a dumb table and also do not know /why/ it has to be constructed this way. "Works for me" -ReneR */ { - float low_lim = 0.001; + float low_lim = (float) 0.001; float up_lim = 1.0; - uint16_t accel_steps = accel_info.total_steps - accel_info.stable_steps + 1; + uint16_t accel_steps = (uint16_t) (accel_info.total_steps - accel_info.stable_steps + 1); /* acceleration ramp */ while ((up_lim - low_lim) > 0.0001) @@ -6122,7 +6148,7 @@ send_acceleration_table (Avision_Scanner* s) int add_count; /* count total steps in table */ - int table_total = 0; + uint32_t table_total = 0; for (i = 0; i < accel_info.total_steps; i++) table_total += table_data [i]; @@ -6130,9 +6156,9 @@ send_acceleration_table (Avision_Scanner* s) if (((table_total * accel_info.table_units) % accel_info.base_units) == 0) add_count = 0; else - add_count = (accel_info.base_units - - ((table_total*accel_info.table_units) % accel_info.base_units)) - / accel_info.table_units; + add_count = (int) ((accel_info.base_units - + ((table_total*accel_info.table_units) % accel_info.base_units)) + / accel_info.table_units); /* add_count should not be bigger than 255 */ if (add_count > 255) { @@ -6142,7 +6168,7 @@ send_acceleration_table (Avision_Scanner* s) for (i = 0; i < accel_info.total_steps - 1 && add_count > 0; i++) { uint16_t temp_count = 255 - table_data [i]; - temp_count = temp_count > add_count ? add_count : temp_count; + temp_count = (uint16_t) (temp_count > add_count ? add_count : temp_count); table_data [i] += (uint8_t) temp_count; add_count -= temp_count; @@ -6186,8 +6212,8 @@ set_window (Avision_Scanner* s) Avision_Device* dev = s->hw; SANE_Status status; int base_dpi_abs, base_dpi_rel; - int transferlen; - int paralen; + size_t transferlen; + size_t paralen; int bytes_per_line; int line_count; @@ -6225,7 +6251,7 @@ set_window (Avision_Scanner* s) /* optional parameter length to use */ paralen = sizeof (cmd.window.avision) - sizeof (cmd.window.avision.type); - DBG (2, "set_window: base paralen: %d\n", paralen); + DBG (2, "set_window: base paralen: %zu\n", paralen); if (dev->hw->feature_type & AV_FUJITSU) paralen += sizeof (cmd.window.avision.type.fujitsu); @@ -6236,12 +6262,12 @@ set_window (Avision_Scanner* s) else paralen += sizeof (cmd.window.avision.type.normal) - 1; - DBG (2, "set_window: final paralen: %d\n", paralen); + DBG (2, "set_window: final paralen: %zu\n", paralen); transferlen = sizeof (cmd.window) - sizeof (cmd.window.avision) + paralen; - DBG (2, "set_window: transferlen: %d\n", transferlen); + DBG (2, "set_window: transferlen: %zu\n", transferlen); /* command setup */ cmd.cmd.opc = AVISION_SCSI_SET_WINDOW; @@ -6278,20 +6304,20 @@ set_window (Avision_Scanner* s) /* here go the most significant bits if bigger than 16 bit */ if (dev->inquiry_new_protocol && !(dev->hw->feature_type & AV_FUJITSU) ) { DBG (2, "set_window: large data-transfer support (>16bit)!\n"); - cmd.window.avision.type.normal.line_width_msb = - bytes_per_line >> 16; - cmd.window.avision.type.normal.line_count_msb = - line_count >> 16; + cmd.window.avision.type.normal.line_width_msb = (uint8_t) + (bytes_per_line >> 16); + cmd.window.avision.type.normal.line_count_msb = (uint8_t) + (line_count >> 16); } if (dev->inquiry_background_raster) - cmd.window.avision.type.normal.background_lines = s->val[OPT_BACKGROUND].w; + cmd.window.avision.type.normal.background_lines = (uint8_t) s->val[OPT_BACKGROUND].w; /* scanner should use our line-width and count */ SET_BIT (cmd.window.avision.bitset1, 6); /* set speed */ - cmd.window.avision.bitset1 |= s->val[OPT_SPEED].w & 0x07; /* only 3 bit */ + cmd.window.avision.bitset1 |= (uint8_t) (s->val[OPT_SPEED].w & 0x07); /* only 3 bit */ /* ADF scan? */ DBG (3, "set_window: source mode %d source mode dim %d\n", @@ -6371,7 +6397,7 @@ set_window (Avision_Scanner* s) /* fixed values */ cmd.window.descriptor.padding_and_bitset = 3; cmd.window.descriptor.vendor_specific = 0xFF; - cmd.window.descriptor.paralen = paralen; /* R² was: 9, later 14 */ + cmd.window.descriptor.paralen = (uint8_t) paralen; /* R² was: 9, later 14 */ /* This is normally unsupported by Avision scanners, and we do this via the gamma table - which works for all devices ... */ @@ -6443,7 +6469,7 @@ set_window (Avision_Scanner* s) debug_print_window_descriptor (5, "set_window", &(cmd.window)); - DBG (3, "set_window: sending command. Bytes: %d\n", transferlen); + DBG (3, "set_window: sending command. Bytes: %zu\n", transferlen); status = avision_cmd (&s->av_con, &cmd, sizeof (cmd.cmd), &(cmd.window), transferlen, 0, 0); @@ -6482,7 +6508,7 @@ get_background_raster (Avision_Scanner* s) dev->inquiry_background_raster_pixel, bytes_per_line); /* according to spec only 8-bit gray or color, TODO: test for bi-level scans */ - size = bytes_per_line * lines; + size = (size_t) bytes_per_line * (size_t) lines; DBG (3, "get_background_raster: buffer size: %ld\n", (long)size); @@ -6518,7 +6544,7 @@ get_background_raster (Avision_Scanner* s) else { this_lines = s->val[OPT_BACKGROUND].w; } - this_read = bytes_per_line * this_lines; + this_read = (size_t) bytes_per_line * (size_t) this_lines; DBG (3, "get_background_raster: line: %d, lines: %d, %lu bytes\n", i, this_lines, (u_long) this_read); @@ -6528,8 +6554,8 @@ get_background_raster (Avision_Scanner* s) read_size = this_read; status = avision_cmd (&s->av_con, &rcmd, sizeof (rcmd), 0, 0, dst_raster, &read_size); if (status != SANE_STATUS_GOOD || read_size != this_read) { - DBG (1, "get_background_raster: read raster failed (%s)\n", - sane_strstatus (status) ); + status = (status != SANE_STATUS_GOOD)? status: SANE_STATUS_IO_ERROR; + DBG (1, "get_background_raster: read raster failed (%s)\n", sane_strstatus (status) ); return status; } @@ -6545,7 +6571,7 @@ get_background_raster (Avision_Scanner* s) write_pnm_header (f, (color_mode_is_color (s->c_mode) ? AV_TRUECOLOR : AV_GRAYSCALE), 8, bytes_per_line / bpp, lines); - fwrite (background, 1, bytes_per_line * lines, f); + fwrite (background, 1, (size_t) bytes_per_line * (size_t) lines, f); fclose (f); } @@ -6555,7 +6581,7 @@ get_background_raster (Avision_Scanner* s) /* TODO: add 16bit per sample code? */ int l, p; - uint8_t* tmp_data = malloc (bytes_per_line); + uint8_t* tmp_data = malloc ((size_t) bytes_per_line); for (l = 0; l < lines; ++l) { uint8_t* out_data = tmp_data; @@ -6569,7 +6595,7 @@ get_background_raster (Avision_Scanner* s) out_data [p++] = *(b_ptr++); } - memcpy (background + (bytes_per_line * l), tmp_data, bytes_per_line); + memcpy (background + (bytes_per_line * l), tmp_data, (size_t) bytes_per_line); } free (tmp_data); @@ -6596,7 +6622,7 @@ get_background_raster (Avision_Scanner* s) src_raster = background + bytes_per_line * i; DBG(3, "get_background_raster: deinterlaced %d -> %d\n", i, dst_i); - memcpy(dst_raster, src_raster, bytes_per_line); + memcpy(dst_raster, src_raster, (size_t) bytes_per_line); } free (background); @@ -6619,7 +6645,7 @@ get_background_raster (Avision_Scanner* s) write_pnm_header (f, (color_mode_is_color (s->c_mode) ? AV_TRUECOLOR : AV_GRAYSCALE), 8, bytes_per_line / bpp, s->val[OPT_BACKGROUND].w); - fwrite (raster, 1, bytes_per_line * s->val[OPT_BACKGROUND].w, f); + fwrite (raster, 1, (size_t) bytes_per_line * (size_t) s->val[OPT_BACKGROUND].w, f); fclose (f); } @@ -6630,7 +6656,7 @@ get_background_raster (Avision_Scanner* s) src_ptr = background + s->avdimen.tlx * bpp; for (i = 0; i < lines; ++i) { - memmove (dst_ptr, src_ptr, s->avdimen.hw_bytes_per_line); + memmove (dst_ptr, src_ptr, (size_t) s->avdimen.hw_bytes_per_line); dst_ptr += s->avdimen.hw_bytes_per_line; src_ptr += bytes_per_line; } @@ -6659,10 +6685,10 @@ get_background_raster (Avision_Scanner* s) switch (bpp) { case 1: { - uint8_t v = - ( out_data [sy*hwbpl + sx ] * (256-xdist) + + uint8_t v = (uint8_t) + (( out_data [sy*hwbpl + sx ] * (256-xdist) + out_data [sy*hwbpl + sxx] * xdist - ) / (256); + ) / (256)); *dst++ = v; } break; @@ -6672,10 +6698,10 @@ get_background_raster (Avision_Scanner* s) int c; for (c = 0; c < 3; ++c) { - uint8_t v = - ( out_data [sy*hwbpl + sx*3 + c] * (256-xdist) + + uint8_t v = (uint8_t) + (( out_data [sy*hwbpl + sx*3 + c] * (256-xdist) + out_data [sy*hwbpl + sxx*3 + c] * xdist - ) / (256); + ) / (256)); *dst++ = v; } } @@ -6702,7 +6728,7 @@ get_background_raster (Avision_Scanner* s) write_pnm_header (f, (color_mode_is_color (s->c_mode) ? AV_TRUECOLOR : AV_GRAYSCALE), 8, s->params.bytes_per_line / bpp, s->val[OPT_BACKGROUND].w); - fwrite (raster, 1, s->params.bytes_per_line * s->val[OPT_BACKGROUND].w, f); + fwrite (raster, 1, (size_t) s->params.bytes_per_line * (size_t) s->val[OPT_BACKGROUND].w, f); fclose (f); } } @@ -6731,7 +6757,7 @@ release_unit (Avision_Scanner* s, int type) SANE_Status status; DBG (1, "release unit: type: %d\n", type); - cmd[5] = type; /* latest scanners also allow 1: release paper and 2: end job */ + cmd[5] = (char) type; /* latest scanners also allow 1: release paper and 2: end job */ status = avision_cmd (&s->av_con, cmd, sizeof (cmd), 0, 0, 0, 0); return status; } @@ -6944,8 +6970,9 @@ init_options (Avision_Scanner* s) case AV_ASIC_C5: dev->dpi_range.min = 80; break; - case AV_ASIC_C6: /* TODO: AV610 in ADF mode does not scan less than 180 or so */ - dev->dpi_range.min = 50; + case AV_ASIC_C6: /* TODO: AV610 in ADF mode does not scan less than 180 or so; */ + /* Scanjet 8250 does not work with 50 in normal mode */ + dev->dpi_range.min = 60; break; case AV_ASIC_C7: /* AV610C2 empirically tested out */ dev->dpi_range.min = 75; @@ -6983,7 +7010,7 @@ init_options (Avision_Scanner* s) s->opt[OPT_MODE].title = SANE_TITLE_SCAN_MODE; s->opt[OPT_MODE].desc = SANE_DESC_SCAN_MODE; s->opt[OPT_MODE].type = SANE_TYPE_STRING; - s->opt[OPT_MODE].size = max_string_size (dev->color_list); + s->opt[OPT_MODE].size = (SANE_Int) max_string_size (dev->color_list); s->opt[OPT_MODE].constraint_type = SANE_CONSTRAINT_STRING_LIST; s->opt[OPT_MODE].constraint.string_list = dev->color_list; s->val[OPT_MODE].s = strdup (dev->color_list[dev->color_list_default]); @@ -6994,7 +7021,7 @@ init_options (Avision_Scanner* s) s->opt[OPT_SOURCE].title = SANE_TITLE_SCAN_SOURCE; s->opt[OPT_SOURCE].desc = SANE_DESC_SCAN_SOURCE; s->opt[OPT_SOURCE].type = SANE_TYPE_STRING; - s->opt[OPT_SOURCE].size = max_string_size(dev->source_list); + s->opt[OPT_SOURCE].size = (SANE_Int) max_string_size(dev->source_list); s->opt[OPT_SOURCE].constraint_type = SANE_CONSTRAINT_STRING_LIST; s->opt[OPT_SOURCE].constraint.string_list = &dev->source_list[0]; s->val[OPT_SOURCE].s = strdup(dev->source_list[0]); @@ -7314,7 +7341,7 @@ init_options (Avision_Scanner* s) s->opt[OPT_MESSAGE].cap = SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED; s->opt[OPT_MESSAGE].size = 129; s->opt[OPT_MESSAGE].constraint_type = SANE_CONSTRAINT_NONE; - s->val[OPT_MESSAGE].s = malloc(s->opt[OPT_MESSAGE].size); + s->val[OPT_MESSAGE].s = malloc((size_t) s->opt[OPT_MESSAGE].size); s->val[OPT_MESSAGE].s[0] = 0; /* NVRAM */ @@ -7328,7 +7355,7 @@ init_options (Avision_Scanner* s) s->opt[OPT_NVRAM].unit = SANE_UNIT_NONE; s->opt[OPT_NVRAM].size = 1024; s->opt[OPT_NVRAM].constraint_type = SANE_CONSTRAINT_NONE; - s->val[OPT_NVRAM].s = malloc(s->opt[OPT_NVRAM].size); + s->val[OPT_NVRAM].s = malloc((size_t) s->opt[OPT_NVRAM].size); s->val[OPT_NVRAM].s[0] = 0; /* paper_length */ @@ -7472,11 +7499,27 @@ reader_process (void *data) return SANE_STATUS_NO_MEM; if (dev->adf_offset_compensation) { + char duplex_offtmp_fname [] = "/tmp/avision-offtmp-XXXXXX"; + + int fd = mkstemp(duplex_offtmp_fname); + if (fd == -1) { + DBG (1, "reader_process: failed to generate temporary fname for ADF offset compensation temp file\n"); + return SANE_STATUS_NO_MEM; + } + DBG (1, "reader_process: temporary fname for ADF offset compensation temp file: %s\n", + duplex_offtmp_fname); + + if (unlink(duplex_offtmp_fname) == -1) { + DBG(1, "reader_process: failed to delete temporary file prior to use: %s\n", duplex_offtmp_fname); + // continue though. + } + DBG (3, "reader_process: redirecting output data to temp file for ADF offset compensation.\n"); fp_fd = fp; - fp = fopen (s->duplex_offtmp_fname, "w+"); + fp = fdopen (fd, "w+"); if (!fp) { fclose(fp_fd); + close(fd); return SANE_STATUS_NO_MEM; } } @@ -7525,37 +7568,34 @@ reader_process (void *data) if (!s->duplex_rear_valid) { /* create new file for writing */ DBG (3, "reader_process: opening duplex rear file for writing.\n"); rear_fp = fopen (s->duplex_rear_fname, "w"); - if (! rear_fp) { - fclose (fp); - return SANE_STATUS_NO_MEM; - } } else { /* open saved rear data */ DBG (3, "reader_process: opening duplex rear file for reading.\n"); rear_fp = fopen (s->duplex_rear_fname, "r"); - if (! rear_fp) { - fclose (fp); - return SANE_STATUS_IO_ERROR; - } + } + if (! rear_fp) { + fclose (fp); + fclose (fp_fd); + return SANE_STATUS_IO_ERROR; } } /* it takes quite a few lines to saturate the (USB) bus */ - lines_per_stripe = dev->read_stripe_size; + lines_per_stripe = (unsigned int) dev->read_stripe_size; if (s->avdimen.line_difference) - lines_per_stripe += 2 * s->avdimen.line_difference; + lines_per_stripe += (2 * (unsigned int) s->avdimen.line_difference); - stripe_size = s->avdimen.hw_bytes_per_line * lines_per_stripe; - lines_per_output = lines_per_stripe - 2 * s->avdimen.line_difference; + stripe_size = (unsigned int) s->avdimen.hw_bytes_per_line * lines_per_stripe; + lines_per_output = lines_per_stripe - 2 * (unsigned int) s->avdimen.line_difference; if (s->av_con.connection_type == AV_SCSI) /* maybe better not /2 ... */ - max_bytes_per_read = dev->scsi_buffer_size / 2; + max_bytes_per_read = (unsigned int) dev->scsi_buffer_size / 2; else /* vast buffer size to saturate the bus */ max_bytes_per_read = 0x100000; - out_size = s->avdimen.hw_bytes_per_line * lines_per_output; + out_size = (unsigned int) s->avdimen.hw_bytes_per_line * lines_per_output; DBG (3, "dev->scsi_buffer_size / 2: %d\n", dev->scsi_buffer_size / 2); @@ -7576,18 +7616,18 @@ reader_process (void *data) s->avdimen.hw_yres != s->avdimen.yres) { /* layout out_data so that the interpolation history is exactly in front */ - ip_history = malloc (s->avdimen.hw_bytes_per_line + out_size); + ip_history = malloc ((size_t) s->avdimen.hw_bytes_per_line + out_size); out_data = ip_history + s->avdimen.hw_bytes_per_line; - ip_data = malloc (s->params.bytes_per_line); + ip_data = malloc ((size_t) s->params.bytes_per_line); } else { out_data = malloc (out_size); } /* calculate params for the reading loop */ - total_size = s->avdimen.hw_bytes_per_line * - (s->avdimen.hw_lines + 2 * s->avdimen.line_difference); + total_size = (size_t) s->avdimen.hw_bytes_per_line * + ((size_t) s->avdimen.hw_lines + 2 * (size_t) s->avdimen.line_difference); if (deinterlace != NONE && !s->duplex_rear_valid) total_size *= 2; @@ -7599,7 +7639,7 @@ reader_process (void *data) { raw_fp = fopen ("/tmp/sane-avision.raw", "w"); write_pnm_header (fp, s->c_mode, s->params.depth, - s->avdimen.hw_pixels_per_line, total_size / s->avdimen.hw_bytes_per_line); + s->avdimen.hw_pixels_per_line, (int) (total_size / (size_t) s->avdimen.hw_bytes_per_line)); } processed_bytes = 0; @@ -7613,7 +7653,7 @@ reader_process (void *data) background += s->params.bytes_per_line * s->val[OPT_BACKGROUND].w; DBG (5, "reader_process: dumping background raster\n"); - fwrite (background, s->params.bytes_per_line, s->val[OPT_BACKGROUND].w, fp); + fwrite (background, (size_t) s->params.bytes_per_line, (size_t) s->val[OPT_BACKGROUND].w, fp); } /* Data read; loop until all data has been processed. Might exit @@ -7636,7 +7676,7 @@ reader_process (void *data) byte_per_lines, otherwise some scanners freeze. */ if (this_read > max_bytes_per_read) this_read = (max_bytes_per_read - - max_bytes_per_read % s->avdimen.hw_bytes_per_line); + max_bytes_per_read % (unsigned int) s->avdimen.hw_bytes_per_line); if (processed_bytes + this_read > total_size) this_read = total_size - processed_bytes; @@ -7694,7 +7734,7 @@ reader_process (void *data) exit_status = status; } - stripe_fill += this_read; + stripe_fill += (unsigned int) this_read; processed_bytes += this_read; } @@ -7716,7 +7756,7 @@ reader_process (void *data) DBG (5, "reader_process: virtual this_read: %lu\n", (u_long) this_read); got = fread (stripe_data + stripe_fill, 1, this_read, rear_fp); - stripe_fill += got; + stripe_fill += (unsigned int) got; processed_bytes += got; if (got != this_read) exit_status = SANE_STATUS_EOF; @@ -7727,7 +7767,7 @@ reader_process (void *data) useful_bytes = stripe_fill; if (color_mode_is_color (s->c_mode)) - useful_bytes -= 2 * s->avdimen.line_difference * s->avdimen.hw_bytes_per_line; + useful_bytes -= (unsigned int) (2 * s->avdimen.line_difference * s->avdimen.hw_bytes_per_line); DBG (3, "reader_process: useful_bytes %i\n", useful_bytes); @@ -7737,26 +7777,26 @@ reader_process (void *data) if (deinterlace != NONE && !s->duplex_rear_valid) { /* for all lines we have in the buffer: */ - unsigned int absline = (processed_bytes - stripe_fill) / s->avdimen.hw_bytes_per_line; - unsigned int abslines = absline + useful_bytes / s->avdimen.hw_bytes_per_line; + unsigned int absline = (unsigned int) ((processed_bytes - stripe_fill) / (size_t) s->avdimen.hw_bytes_per_line); + unsigned int abslines = absline + useful_bytes / (unsigned int) s->avdimen.hw_bytes_per_line; uint8_t* ptr = stripe_data; for ( ; absline < abslines; ++absline) { DBG (9, "reader_process: deinterlacing line %d\n", absline); /* interlaced? save the back data to the rear buffer */ if ( (deinterlace == STRIPE && absline % (lines_per_stripe*2) >= lines_per_stripe) || - (deinterlace == HALF && absline >= total_size / s->avdimen.hw_bytes_per_line / 2) || + (deinterlace == HALF && absline >= total_size / (size_t) s->avdimen.hw_bytes_per_line / 2) || (deinterlace == LINE && (absline & 0x1)) ) /* last bit equals % 2 */ { DBG (9, "reader_process: saving rear line %d to temporary file.\n", absline); - fwrite (ptr, s->avdimen.hw_bytes_per_line, 1, rear_fp); + fwrite (ptr, (size_t) s->avdimen.hw_bytes_per_line, 1, rear_fp); if (deinterlace == LINE) memmove (ptr, ptr+s->avdimen.hw_bytes_per_line, - stripe_data + stripe_fill - ptr - s->avdimen.hw_bytes_per_line); + (size_t) (stripe_data + stripe_fill - ptr - s->avdimen.hw_bytes_per_line)); else ptr += s->avdimen.hw_bytes_per_line; - useful_bytes -= s->avdimen.hw_bytes_per_line; - stripe_fill -= s->avdimen.hw_bytes_per_line; + useful_bytes -= (unsigned int) s->avdimen.hw_bytes_per_line; + stripe_fill -= (unsigned int) s->avdimen.hw_bytes_per_line; } else ptr += s->avdimen.hw_bytes_per_line; @@ -7766,14 +7806,14 @@ reader_process (void *data) } if ((dev->hw->feature_type & AV_ADF_FLIPPING_DUPLEX) && s->source_mode == AV_ADF_DUPLEX && !(s->page % 2) && !s->duplex_rear_valid) { /* Here we flip the image by writing the lines from the end of the file to the beginning. */ - unsigned int absline = (processed_bytes - stripe_fill) / s->avdimen.hw_bytes_per_line; - unsigned int abslines = absline + useful_bytes / s->avdimen.hw_bytes_per_line; + unsigned int absline = (unsigned int) ((processed_bytes - stripe_fill) / (size_t) s->avdimen.hw_bytes_per_line); + unsigned int abslines = absline + useful_bytes / (unsigned int) s->avdimen.hw_bytes_per_line; uint8_t* ptr = stripe_data; for ( ; absline < abslines; ++absline) { - fseek (rear_fp, ((0 - s->params.lines) - absline - 2) * s->avdimen.hw_bytes_per_line, SEEK_SET); - fwrite (ptr, s->avdimen.hw_bytes_per_line, 1, rear_fp); - useful_bytes -= s->avdimen.hw_bytes_per_line; - stripe_fill -= s->avdimen.hw_bytes_per_line; + fseek (rear_fp, ((0 - s->params.lines) - (SANE_Int) absline - 2) * s->avdimen.hw_bytes_per_line, SEEK_SET); + fwrite (ptr, (size_t) s->avdimen.hw_bytes_per_line, 1, rear_fp); + useful_bytes -= (unsigned int) s->avdimen.hw_bytes_per_line; + stripe_fill -= (unsigned int) s->avdimen.hw_bytes_per_line; ptr += s->avdimen.hw_bytes_per_line; } DBG (9, "reader_process: after page flip: useful_bytes: %d, stripe_fill: %d\n", @@ -7813,16 +7853,16 @@ reader_process (void *data) else if (dev->inquiry_needs_line_pack) /* line-pack */ { /* TODO: add 16bit per sample code? */ - int i = 0, l, p; - const int lines = useful_bytes / s->avdimen.hw_bytes_per_line; + unsigned int i = 0, l, p; + const unsigned int lines = useful_bytes / (unsigned int) s->avdimen.hw_bytes_per_line; for (l = 0; l < lines; ++l) { - uint8_t* r_ptr = stripe_data + (s->avdimen.hw_bytes_per_line * l); + uint8_t* r_ptr = stripe_data + ((unsigned int) s->avdimen.hw_bytes_per_line * l); uint8_t* g_ptr = r_ptr + s->avdimen.hw_pixels_per_line; uint8_t* b_ptr = g_ptr + s->avdimen.hw_pixels_per_line; - for (p = 0; p < s->avdimen.hw_pixels_per_line; ++p) { + for (p = 0; p < (unsigned int) s->avdimen.hw_pixels_per_line; ++p) { out_data [i++] = *(r_ptr++); out_data [i++] = *(g_ptr++); out_data [i++] = *(b_ptr++); @@ -7846,12 +7886,12 @@ reader_process (void *data) /* Mirroring with bgr -> rgb conversion: Just mirror the * whole line */ - int l; - int lines = useful_bytes / s->avdimen.hw_bytes_per_line; + unsigned int l; + unsigned int lines = useful_bytes / (unsigned int) s->avdimen.hw_bytes_per_line; for (l = 0; l < lines; ++l) { - uint8_t* begin_ptr = out_data + (l * s->avdimen.hw_bytes_per_line); + uint8_t* begin_ptr = out_data + (l * (unsigned int) s->avdimen.hw_bytes_per_line); uint8_t* end_ptr = begin_ptr + s->avdimen.hw_bytes_per_line; while (begin_ptr < end_ptr) { @@ -7866,12 +7906,12 @@ reader_process (void *data) { /* Non-trivial Mirroring with element swapping */ - int l; - int lines = useful_bytes / s->avdimen.hw_bytes_per_line; + unsigned int l; + unsigned int lines = useful_bytes / (unsigned int) s->avdimen.hw_bytes_per_line; for (l = 0; l < lines; ++l) { - uint8_t* begin_ptr = out_data + (l * s->avdimen.hw_bytes_per_line); + uint8_t* begin_ptr = out_data + (l * (unsigned int) s->avdimen.hw_bytes_per_line); uint8_t* end_ptr = begin_ptr + s->avdimen.hw_bytes_per_line - 3; while (begin_ptr < end_ptr) { @@ -7904,8 +7944,8 @@ reader_process (void *data) s->c_mode == AV_TRUECOLOR12 || s->c_mode == AV_TRUECOLOR16) { - int l; - int lines = useful_bytes / s->avdimen.hw_bytes_per_line; + unsigned int l; + unsigned int lines = useful_bytes / (unsigned int) s->avdimen.hw_bytes_per_line; uint8_t* dark_avg_data = s->dark_avg_data; uint8_t* white_avg_data = s->white_avg_data; @@ -7923,9 +7963,9 @@ reader_process (void *data) uint16_t white_avg = WHITE_MAP_RANGE; if (dark_avg_data) - dark_avg = get_double_le (dark_avg_data); + dark_avg = (uint16_t) get_double_le (dark_avg_data); if (white_avg_data) - white_avg = get_double_le (white_avg_data); + white_avg = (uint16_t) get_double_le (white_avg_data); line_ptr = begin_ptr; for (l = 0; l < lines; ++ l) @@ -7935,11 +7975,11 @@ reader_process (void *data) if (0) v = (v - dark_avg) * white_avg / WHITE_MAP_RANGE; - v2 = v < 0xFFFF ? v : 0xFFFF; + v2 = ((uint16_t) v) < 0xFFFF ? ((uint16_t) v) : 0xFFFF; /* SANE Standard 3.2.1 "... bytes of each sample value are transmitted in the machine's native byte order." */ - *line_ptr = v2; + *line_ptr = (uint8_t) v2; line_ptr += s->avdimen.hw_bytes_per_line; } @@ -7954,19 +7994,14 @@ reader_process (void *data) /* SOFTWARE SCALING WITH INTERPOLATION (IF NECESSARY) */ - if (s->avdimen.hw_xres == s->avdimen.xres && - s->avdimen.hw_yres == s->avdimen.yres) /* No scaling */ - { - fwrite (out_data, useful_bytes, 1, fp); - line += useful_bytes / s->avdimen.hw_bytes_per_line; - } - else /* Software scaling - watch out - this code bites back! */ + if (s->avdimen.hw_xres != s->avdimen.xres || + s->avdimen.hw_yres != s->avdimen.yres) /* Software scaling */ { int x; /* for convenience in the 16bit code path */ uint16_t* out_data16 = (uint16_t*) out_data; - const int hw_line_end = hw_line + useful_bytes / s->avdimen.hw_bytes_per_line; + const int hw_line_end = hw_line + (int) useful_bytes / s->avdimen.hw_bytes_per_line; /* on-the-fly bi-linear interpolation */ while (1) { @@ -7993,6 +8028,9 @@ reader_process (void *data) break; } + DBG (8, "reader_process: out line: %d <- from: %d-%d\n", + line, sy, syy); + /* convert to offset in current stripe */ sy -= hw_line; syy -= hw_line; @@ -8002,9 +8040,6 @@ reader_process (void *data) sy = -1; } - DBG (8, "reader_process: out line: %d <- from: %d-%d\n", - line, sy, syy); - for (x = 0; x < s->params.pixels_per_line; ++x) { const double bx = (-1.0 + s->avdimen.hw_pixels_per_line) * x / s->params.pixels_per_line; const int sx = (int)floor(bx); @@ -8022,16 +8057,16 @@ reader_process (void *data) /* Repeating this over and over again is not fast, but as a seldom used code-path we want it readable. x/8 is the byte, and x%8 the bit position. */ - v = + v = (unsigned int) ( ( ((out_data [sy*hwbpl + sx/8 ] >> (7-sx%8 )) & 1) * (256-xdist) * (256-ydist) + ((out_data [sy*hwbpl + sxx/8] >> (7-sxx%8)) & 1) * xdist * (256-ydist) + ((out_data [syy*hwbpl + sx/8 ] >> (7-sx%8 )) & 1) * (256-xdist) * ydist + ((out_data [syy*hwbpl + sxx/8] >> (7-sxx%8)) & 1) * xdist * ydist - ) / (1 + 1 * 256); + ) / (1 + 1 * 256)); /* Shift and or the result together and eventually jump to the next byte. */ - *dst = (*dst << 1) | ((v>>7)&1); + *dst = (uint8_t) ((*dst << 1) | ((v>>7)&1)); if (x % 8 == 7) ++dst; } @@ -8039,13 +8074,13 @@ reader_process (void *data) case AV_GRAYSCALE: { - v = + v = (unsigned int) ( ( out_data [sy*hwbpl + sx ] * (256-xdist) * (256-ydist) + out_data [sy*hwbpl + sxx] * xdist * (256-ydist) + out_data [syy*hwbpl + sx ] * (256-xdist) * ydist + out_data [syy*hwbpl + sxx] * xdist * ydist - ) / (256 * 256); - *dst++ = v; + ) / (256 * 256)); + *dst++ = (uint8_t) v; } break; @@ -8053,13 +8088,13 @@ reader_process (void *data) case AV_GRAYSCALE16: { /* TODO: test! */ - v = + v = (unsigned int) ( ( out_data16 [sy*hwbpl + sx ] * (256-xdist) * (256-ydist) + out_data16 [sy*hwbpl + sxx] * xdist * (256-ydist) + out_data16 [syy*hwbpl + sx ] * (256-xdist) * ydist + out_data16 [syy*hwbpl + sxx] * xdist * ydist - ) / (256 * 256); - *dst16++ = v; + ) / (256 * 256)); + *dst16++ = (uint16_t) v; } break; @@ -8068,13 +8103,13 @@ reader_process (void *data) int c; for (c = 0; c < 3; ++c) { - v = + v = (unsigned int) ( ( out_data [sy*hwbpl + sx*3 + c] * (256-xdist) * (256-ydist) + out_data [sy*hwbpl + sxx*3 + c] * xdist * (256-ydist) + out_data [syy*hwbpl + sx*3 + c] * (256-xdist) * ydist + out_data [syy*hwbpl + sxx*3 + c] * xdist * ydist - ) / (256 * 256); - *dst++ = v; + ) / (256 * 256)); + *dst++ = (uint8_t) v; } } break; @@ -8086,13 +8121,13 @@ reader_process (void *data) int c; for (c = 0; c < 3; ++c) { - v = + v = (unsigned int) ( ( out_data16 [sy*hwbpl + sx*3 + c] * (256-xdist) * (256-ydist) + out_data16 [sy*hwbpl + sxx*3 + c] * xdist * (256-ydist) + out_data16 [syy*hwbpl + sx*3 + c] * (256-xdist) * ydist + out_data16 [syy*hwbpl + sxx*3 + c] * xdist * ydist - ) / (256 * 256); - *dst16++ = v; + ) / (256 * 256)); + *dst16++ = (uint16_t) v; } } break; @@ -8101,13 +8136,18 @@ reader_process (void *data) ; /* silence compiler warning */ } } - fwrite (ip_data, s->params.bytes_per_line, 1, fp); + fwrite (ip_data, (size_t) s->params.bytes_per_line, 1, fp); ++line; } /* copy one line of history for the next pass */ memcpy (ip_history, out_data + useful_bytes - s->avdimen.hw_bytes_per_line, - s->avdimen.hw_bytes_per_line); + (size_t) s->avdimen.hw_bytes_per_line); + } + else /* No scaling */ + { + fwrite (out_data, useful_bytes, 1, fp); + line += (int) useful_bytes / s->avdimen.hw_bytes_per_line; } } @@ -8116,7 +8156,7 @@ reader_process (void *data) if (stripe_fill > 0) memcpy (stripe_data, stripe_data + useful_bytes, stripe_fill); - hw_line += useful_bytes / s->avdimen.hw_bytes_per_line; + hw_line += (int) useful_bytes / s->avdimen.hw_bytes_per_line; DBG (3, "reader_process: end of iteration\n"); } /* end while not all lines or inf. mode */ @@ -8131,12 +8171,12 @@ reader_process (void *data) /* maybe we need to fill in some white data */ if (exit_status == SANE_STATUS_EOF && line < s->params.lines) { DBG (3, "reader_process: padding with white data\n"); - memset (out_data, gray_mode ? 0xff : 0x00, s->params.bytes_per_line); + memset (out_data, gray_mode ? 0xff : 0x00, (size_t) s->params.bytes_per_line); DBG (6, "reader_process: padding line %d - %d\n", line, s->params.lines); while (line < s->params.lines) { - fwrite (out_data, s->params.bytes_per_line, 1, fp); + fwrite (out_data, (size_t) s->params.bytes_per_line, 1, fp); ++line; } } @@ -8147,12 +8187,12 @@ reader_process (void *data) long lines; uint8_t* buffer; - buffer = malloc (s->params.bytes_per_line); + buffer = malloc ((size_t) s->params.bytes_per_line); lines = ftell(fp) / s->params.bytes_per_line; rewind(fp); for (long line = 0; line < lines; line++) { - fread(buffer, s->params.bytes_per_line, 1, fp); + fread(buffer, (size_t) s->params.bytes_per_line, 1, fp); if ( (!s->duplex_rear_valid && (line < s->avdimen.offset.front.top)) || (s->duplex_rear_valid && (line < s->avdimen.offset.rear.top)) ) { @@ -8166,7 +8206,7 @@ reader_process (void *data) break; /* nothing more to write, so break out here */ } - fwrite(buffer, s->params.bytes_per_line, 1, fp_fd); + fwrite(buffer, (size_t) s->params.bytes_per_line, 1, fp_fd); } } @@ -8442,7 +8482,7 @@ sane_reload_devices (void) SANE_Status sane_init (SANE_Int* version_code, SANE_Auth_Callback authorize) { - authorize = authorize; /* silence gcc */ + (void) authorize; /* silence gcc */ DBG_INIT(); @@ -8489,9 +8529,9 @@ SANE_Status sane_get_devices (const SANE_Device*** device_list, SANE_Bool local_only) { Avision_Device* dev; - int i; + unsigned int i; - local_only = local_only; /* silence gcc */ + (void) local_only; /* silence gcc */ DBG (3, "sane_get_devices:\n"); @@ -8581,7 +8621,7 @@ sane_open (SANE_String_Const devicename, SANE_Handle *handle) for (i = 0; i < 4; ++ i) for (j = 0; j < 256; ++ j) - s->gamma_table[i][j] = pow( (double) j / 255, one_over_gamma) * 255; + s->gamma_table[i][j] = (SANE_Int) (pow( (double) j / 255, one_over_gamma) * 255); } /* insert newly opened handle into list of open handles: */ @@ -8640,33 +8680,21 @@ sane_open (SANE_String_Const devicename, SANE_Handle *handle) dev->hw->offset.duplex.rear.bottom != 0) ) dev->adf_offset_compensation = SANE_TRUE; - if (dev->adf_offset_compensation) { - strncpy(s->duplex_offtmp_fname, "/tmp/avision-offtmp-XXXXXX", PATH_MAX); - - if (! mktemp(s->duplex_offtmp_fname) ) { - DBG (1, "sane_open: failed to generate temporary fname for ADF offset compensation temp file\n"); - return SANE_STATUS_NO_MEM; - } - else { - DBG (1, "sane_open: temporary fname for ADF offset compensation temp file: %s\n", - s->duplex_offtmp_fname); - } - } - if (dev->inquiry_duplex_interlaced || dev->scanner_type == AV_FILM || dev->hw->feature_type & AV_ADF_FLIPPING_DUPLEX) { /* Might need at least *DOS (Windows flavour and OS/2) portability fix However, I was told Cygwin (et al.) takes care of it. */ + + /* Create the file but close the fd. It is not used to open the file later. :( */ strncpy(s->duplex_rear_fname, "/tmp/avision-rear-XXXXXX", PATH_MAX); - if (! mkstemp(s->duplex_rear_fname) ) { + int fd = mkstemp(s->duplex_rear_fname); + if (fd == -1) { DBG (1, "sane_open: failed to generate temporary fname for duplex scans\n"); return SANE_STATUS_NO_MEM; } - else { - DBG (1, "sane_open: temporary fname for duplex scans: %s\n", - s->duplex_rear_fname); - } + DBG (1, "sane_open: temporary fname for duplex scans: %s\n", s->duplex_rear_fname); + close(fd); } /* calibrate film scanners, as this must be done without the @@ -8713,22 +8741,14 @@ void sane_close (SANE_Handle handle) { Avision_Scanner* prev; - Avision_Scanner* s = handle; + Avision_Scanner* s; int i; DBG (3, "sane_close:\n"); - /* close the device */ - if (avision_is_open (&s->av_con) ) { - avision_close (&s->av_con); - } - - /* remove handle from list of open handles: */ - prev = 0; - for (s = first_handle; s; s = s->next) { + for (prev = 0, s = first_handle; s; prev = s, s = s->next) { if (s == handle) break; - prev = s; } /* a handle we know about ? */ @@ -8740,6 +8760,12 @@ sane_close (SANE_Handle handle) if (s->scanning) do_cancel (handle); + /* close the device */ + if (avision_is_open(&s->av_con)) { + avision_close(&s->av_con); + } + + /* remove handle from list of open handles */ if (prev) prev->next = s->next; else @@ -8764,11 +8790,6 @@ sane_close (SANE_Handle handle) *(s->duplex_rear_fname) = 0; } - if (*(s->duplex_offtmp_fname)) { - unlink (s->duplex_offtmp_fname); - *(s->duplex_offtmp_fname) = 0; - } - free (handle); } @@ -8863,7 +8884,7 @@ sane_control_option (SANE_Handle handle, SANE_Int option, case OPT_GAMMA_VECTOR_R: case OPT_GAMMA_VECTOR_G: case OPT_GAMMA_VECTOR_B: - memcpy (val, s->val[option].wa, s->opt[option].size); + memcpy (val, s->val[option].wa, (size_t) s->opt[option].size); return SANE_STATUS_GOOD; /* string options: */ @@ -8923,7 +8944,7 @@ sane_control_option (SANE_Handle handle, SANE_Int option, case OPT_GAMMA_VECTOR_R: case OPT_GAMMA_VECTOR_G: case OPT_GAMMA_VECTOR_B: - memcpy (s->val[option].wa, val, s->opt[option].size); + memcpy (s->val[option].wa, val, (size_t) s->opt[option].size); return SANE_STATUS_GOOD; /* options with side-effects: */ @@ -9327,7 +9348,7 @@ sane_read (SANE_Handle handle, SANE_Byte* buf, SANE_Int max_len, SANE_Int* len) DBG (8, "sane_read: max_len: %d\n", max_len); - nread = read (s->read_fds, buf, max_len); + nread = read (s->read_fds, buf, (size_t) max_len); if (nread > 0) { DBG (8, "sane_read: got %ld bytes\n", (long) nread); } @@ -9347,7 +9368,7 @@ sane_read (SANE_Handle handle, SANE_Byte* buf, SANE_Int max_len, SANE_Int* len) } } - *len = nread; + *len = (SANE_Int) nread; /* if all data was passed through */ if (nread == 0) diff --git a/backend/avision.h b/backend/avision.h index aed6d9e..d2d84ef 100644 --- a/backend/avision.h +++ b/backend/avision.h @@ -502,7 +502,6 @@ typedef struct Avision_Scanner /* Internal data for duplex scans */ char duplex_rear_fname [PATH_MAX]; - char duplex_offtmp_fname [PATH_MAX]; SANE_Bool duplex_rear_valid; color_mode c_mode; @@ -795,17 +794,17 @@ typedef struct acceleration_info /* set/get SCSI highended (big-endian) variables. Declare them as an array * of chars endianness-safe, int-size safe ... */ -#define set_double(var,val) var[0] = ((val) >> 8) & 0xff; \ - var[1] = ((val) ) & 0xff +#define set_double(var,val) var[0] = (uint8_t) (((val) >> 8) & 0xff); \ + var[1] = (uint8_t) (((val) ) & 0xff) -#define set_triple(var,val) var[0] = ((val) >> 16) & 0xff; \ - var[1] = ((val) >> 8 ) & 0xff; \ - var[2] = ((val) ) & 0xff +#define set_triple(var,val) var[0] = (uint8_t) (((val) >> 16) & 0xff); \ + var[1] = (uint8_t) (((val) >> 8 ) & 0xff); \ + var[2] = (uint8_t) (((val) ) & 0xff) -#define set_quad(var,val) var[0] = ((val) >> 24) & 0xff; \ - var[1] = ((val) >> 16) & 0xff; \ - var[2] = ((val) >> 8 ) & 0xff; \ - var[3] = ((val) ) & 0xff +#define set_quad(var,val) var[0] = (uint8_t) (((val) >> 24) & 0xff); \ + var[1] = (uint8_t) (((val) >> 16) & 0xff); \ + var[2] = (uint8_t) (((val) >> 8 ) & 0xff); \ + var[3] = (uint8_t) (((val) ) & 0xff) #define get_double(var) ((*var << 8) + *(var + 1)) @@ -817,10 +816,10 @@ typedef struct acceleration_info (*(var + 2) << 8) + *(var + 3)) /* set/get Avision lowended (little-endian) shading data */ -#define set_double_le(var,val) var[0] = ((val) ) & 0xff; \ - var[1] = ((val) >> 8) & 0xff +#define set_double_le(var,val) var[0] = (uint8_t) (((val) ) & 0xff); \ + var[1] = (uint8_t) (((val) >> 8) & 0xff) -#define get_double_le(var) ((*(var + 1) << 8) + *var) +#define get_double_le(var) ((uint16_t) ((*(var + 1) << 8) + *(var))) #define BIT(n, p) ((n & (1 << p)) ? 1 : 0) diff --git a/backend/bh.c b/backend/bh.c index 0f2e70e..31ebe93 100644 --- a/backend/bh.c +++ b/backend/bh.c @@ -1895,6 +1895,11 @@ start_scan (BH_Scanner *s) { DBG(1, "sane_start: error opening barfile `%s'\n", s->barfname); + if (fd !=-1) + { + close(fd); + unlink(s->barfname); + } status = SANE_STATUS_IO_ERROR; } } @@ -1979,7 +1984,7 @@ sense_handler (int scsi_fd, u_char *result, void *arg) SANE_Status status = SANE_STATUS_INVAL; SANE_Char print_sense[(16 * 3) + 1]; - scsi_fd = scsi_fd; /* get rid of compiler warning */ + (void) scsi_fd; /* get rid of compiler warning */ ErrorCode = result[0] & 0x7F; ValidData = (result[0] & 0x80) != 0; sense = result[2] & 0x0f; /* Key */ @@ -3145,7 +3150,7 @@ sane_init (SANE_Int *version_code, SANE_Auth_Callback authorize) char devnam[PATH_MAX] = "/dev/scanner"; FILE *fp; - authorize = authorize; /* get rid of compiler warning */ + (void) authorize; /* get rid of compiler warning */ DBG_INIT(); DBG(3, "sane_init called\n"); @@ -3233,7 +3238,7 @@ sane_get_devices (const SANE_Device ***device_list, SANE_Bool local) int i; DBG(3, "sane_get_devices called\n"); - local = local; /* get rid of compiler warning */ + (void) local; /* get rid of compiler warning */ if (devlist) free (devlist); devlist = malloc ((num_devices + 1) * sizeof (devlist[0])); @@ -3806,7 +3811,7 @@ sane_set_io_mode (SANE_Handle handle, SANE_Bool non_blocking) return SANE_STATUS_GOOD; #else - handle = handle; /* get rid of compiler warning */ + (void) handle; /* get rid of compiler warning */ return (non_blocking == 1) ? SANE_STATUS_UNSUPPORTED : SANE_STATUS_GOOD; #endif } @@ -3828,7 +3833,7 @@ sane_get_select_fd (SANE_Handle handle, SANE_Int *fd) return SANE_STATUS_GOOD; #else - handle = handle; fd = fd; /* get rid of compiler warning */ + (void) handle; (void) fd; /* get rid of compiler warning */ return SANE_STATUS_UNSUPPORTED; #endif } diff --git a/backend/canon-sane.c b/backend/canon-sane.c index 6957aa7..e313457 100644 --- a/backend/canon-sane.c +++ b/backend/canon-sane.c @@ -1111,9 +1111,6 @@ sane_start (SANE_Handle handle) u_char cbuf[2]; /* modification for FB620S */ size_t buf_size, i; - char tmpfilename[] = "/tmp/canon.XXXXXX"; /* for FB1200S */ - char *thistmpfile; /* for FB1200S */ - DBG (1, ">> sane_start\n"); s->tmpfile = -1; /* for FB1200S */ @@ -1121,36 +1118,18 @@ sane_start (SANE_Handle handle) /******* making a tempfile for 1200 dpi scanning of FB1200S ******/ if (s->hw->info.model == FB1200) { - thistmpfile = strdup(tmpfilename); - - if (thistmpfile != NULL) - { - if (!mkstemp(thistmpfile)) - { - DBG(1, "mkstemp(thistmpfile) is failed\n"); - return (SANE_STATUS_INVAL); - } - } - else - { - DBG(1, "strdup(thistmpfile) is failed\n"); - return (SANE_STATUS_INVAL); - } - - s->tmpfile = open(thistmpfile, O_RDWR | O_CREAT | O_EXCL, 0600); + char tmpfilename[] = "/tmp/canon.XXXXXX"; /* for FB1200S */ + s->tmpfile = mkstemp(tmpfilename); if (s->tmpfile == -1) { - DBG(1, "error opening temp file %s\n", thistmpfile); + DBG(1, "error opening temp file %s\n", tmpfilename); DBG(1, "errno: %i; %s\n", errno, strerror(errno)); errno = 0; return (SANE_STATUS_INVAL); } DBG(1, " ****** tmpfile is opened ****** \n"); - - unlink(thistmpfile); - free (thistmpfile); - DBG(1, "free thistmpfile\n"); + unlink(tmpfilename); } /******************************************************************/ diff --git a/backend/canon.c b/backend/canon.c index e2ef932..d17cd01 100644 --- a/backend/canon.c +++ b/backend/canon.c @@ -817,14 +817,12 @@ attach (const char *devnam, CANON_Device ** devp) dev->sane.name = strdup (devnam); dev->sane.vendor = "CANON"; - if ((str = calloc (16 + 1, 1)) == NULL) + if ((str = strndup ((char *) ibuf + 16, 16)) == NULL) { sanei_scsi_close (fd); fd = -1; return (SANE_STATUS_NO_MEM); } - strncpy (str, (char *) (ibuf + 16), 16); - dev->sane.model = str; /* Register the fixed properties of the scanner below: - whether it is a film scanner or a flatbed scanner @@ -842,6 +840,7 @@ attach (const char *devnam, CANON_Device ** devp) if (!strncmp (str, "IX-27015", 8)) /* FS2700S */ { dev->info.model = CS2700; + dev->sane.model = strdup("FS2700S"); dev->sane.type = SANE_I18N("film scanner"); dev->adf.Status = ADF_STAT_NONE; dev->tpu.Status = TPU_STAT_NONE; @@ -857,6 +856,7 @@ attach (const char *devnam, CANON_Device ** devp) else if (!strncmp (str, "IX-27025E", 9)) /* FS2710S */ { dev->info.model = FS2710; + dev->sane.model = strdup("FS2710S"); dev->sane.type = SANE_I18N("film scanner"); dev->adf.Status = ADF_STAT_NONE; dev->tpu.Status = TPU_STAT_NONE; @@ -872,6 +872,7 @@ attach (const char *devnam, CANON_Device ** devp) else if (!strncmp (str, "IX-06035E", 9)) /* FB620S */ { dev->info.model = FB620; + dev->sane.model = strdup("FB620S"); dev->sane.type = SANE_I18N("flatbed scanner"); dev->adf.Status = ADF_STAT_NONE; dev->tpu.Status = TPU_STAT_NONE; @@ -887,6 +888,7 @@ attach (const char *devnam, CANON_Device ** devp) else if (!strncmp (str, "IX-12015E", 9)) /* FB1200S */ { dev->info.model = FB1200; + dev->sane.model = strdup("FB1200S"); dev->sane.type = SANE_I18N("flatbed scanner"); dev->adf.Status = ADF_STAT_INACTIVE; dev->tpu.Status = TPU_STAT_INACTIVE; @@ -930,6 +932,20 @@ attach (const char *devnam, CANON_Device ** devp) dev->info.has_fixed_resolutions = SANE_FALSE; } + /* + * Use the model from the device if we don't have more + * common model name for the device, otherwise free the + * string with internal model name. + * + * Please keep the memory allocation source consistent + * for model string - allocate on the heap via dynamic + * allocation. + */ + if (dev->sane.model == NULL) + dev->sane.model = str; + else + free(str); + DBG (5, "dev->sane.name = '%s'\n", dev->sane.name); DBG (5, "dev->sane.vendor = '%s'\n", dev->sane.vendor); DBG (5, "dev->sane.model = '%s'\n", dev->sane.model); diff --git a/backend/canon630u-common.c b/backend/canon630u-common.c index e6fcf33..deaef66 100644 --- a/backend/canon630u-common.c +++ b/backend/canon630u-common.c @@ -937,7 +937,10 @@ plugin_cal (CANON_Handle * s) { DBG (1, "No temp filename!\n"); s->fname = strdup ("/tmp/cal.XXXXXX"); - mkstemp (s->fname); + + /* FIXME: we should be using fd, not discarding it, and also checking for error! */ + int fd = mkstemp (s->fname); + close(fd); } s->width = 2551; s->height = 75; @@ -1546,7 +1549,7 @@ CANON_open_device (CANON_Handle * scan, const char *dev) static const char * CANON_get_device_name (CANON_Handle * scanner) { - scanner = scanner; /* Eliminate warning about unused parameters */ + (void) scanner; /* Eliminate warning about unused parameters */ return "Canoscan FB630U"; } @@ -1581,8 +1584,12 @@ CANON_start_scan (CANON_Handle * scanner) /* choose a temp file name for scan data */ scanner->fname = strdup ("/tmp/scan.XXXXXX"); - if (!mkstemp (scanner->fname)) + + /* FIXME: we should be using fd, not discarding it! */ + int fd = mkstemp (scanner->fname); + if (fd == -1) return SANE_STATUS_IO_ERROR; + close(fd); /* calibrate if needed */ rv = init (scanner->fd); diff --git a/backend/canon630u.c b/backend/canon630u.c index 659c31f..25c59d6 100644 --- a/backend/canon630u.c +++ b/backend/canon630u.c @@ -133,9 +133,9 @@ static SANE_Status optionNumOptionsCallback (SANE_Option * option, SANE_Handle handle, SANE_Action action, void *value, SANE_Int * info) { - option = option; - handle = handle; - info = info; /* Eliminate warning about unused parameters */ + (void) option; + (void) handle; + (void) info; /* Eliminate warning about unused parameters */ if (action != SANE_ACTION_GET_VALUE) return SANE_STATUS_INVAL; @@ -168,8 +168,8 @@ static SANE_Status optionCalibrateCallback (SANE_Option * option, SANE_Handle handle, SANE_Action action, void *value, SANE_Int * info) { - handle = handle; - option = option; /* Eliminate warning about unused parameters */ + (void) handle; + (void) option; /* Eliminate warning about unused parameters */ switch (action) { @@ -221,7 +221,7 @@ optionResolutionCallback (SANE_Option * option, SANE_Handle handle, SANE_Status status; SANE_Word autoValue = 75; - handle = handle; /* Eliminate warning about unused parameters */ + (void) handle; /* Eliminate warning about unused parameters */ switch (action) { @@ -268,8 +268,8 @@ static SANE_Status optionGrayscaleCallback (SANE_Option * option, SANE_Handle handle, SANE_Action action, void *value, SANE_Int * info) { - handle = handle; - option = option; /* Eliminate warning about unused parameters */ + (void) handle; + (void) option; /* Eliminate warning about unused parameters */ switch (action) { @@ -315,9 +315,9 @@ static SANE_Status optionAGainCallback (SANE_Option * option, SANE_Handle handle, SANE_Action action, void *value, SANE_Int * info) { - option = option; - handle = handle; - info = info; /* Eliminate warning about unused parameters */ + (void) option; + (void) handle; + (void) info; /* Eliminate warning about unused parameters */ switch (action) { @@ -357,9 +357,9 @@ static SANE_Status optionGammaCallback (SANE_Option * option, SANE_Handle handle, SANE_Action action, void *value, SANE_Int * info) { - option = option; - handle = handle; - info = info; /* Eliminate warning about unused parameters */ + (void) option; + (void) handle; + (void) info; /* Eliminate warning about unused parameters */ switch (action) { @@ -418,9 +418,9 @@ static SANE_Status optionTopLeftXCallback (SANE_Option * option, SANE_Handle handle, SANE_Action action, void *value, SANE_Int * info) { - option = option; - handle = handle; - value = value; /* Eliminate warning about unused parameters */ + (void) option; + (void) handle; + (void) value; /* Eliminate warning about unused parameters */ switch (action) { @@ -462,8 +462,8 @@ optionTopLeftYCallback (SANE_Option * option, SANE_Handle handle, SANE_Action action, void *value, SANE_Int * info) { /* Eliminate warnings about unused parameters */ - option = option; - handle = handle; + (void) option; + (void) handle; switch (action) { @@ -506,8 +506,8 @@ optionBotRightXCallback (SANE_Option * option, SANE_Handle handle, SANE_Action action, void *value, SANE_Int * info) { /* Eliminate warnings about unused parameters */ - option = option; - handle = handle; + (void) option; + (void) handle; switch (action) { @@ -550,8 +550,8 @@ optionBotRightYCallback (SANE_Option * option, SANE_Handle handle, SANE_Action action, void *value, SANE_Int * info) { /* Eliminate warnings about unused parameters */ - option = option; - handle = handle; + (void) option; + (void) handle; switch (action) { @@ -912,7 +912,7 @@ sane_close (SANE_Handle handle) const SANE_Option_Descriptor * sane_get_option_descriptor (SANE_Handle handle, SANE_Int option) { - handle = handle; /* Eliminate compiler warning */ + (void) handle; /* Eliminate compiler warning */ DBG (3, "sane_get_option_descriptor: option = %d\n", option); if (option < 0 || option >= NELEMS (so)) @@ -924,7 +924,7 @@ SANE_Status sane_control_option (SANE_Handle handle, SANE_Int option, SANE_Action action, void *value, SANE_Int * info) { - handle = handle; /* Eliminate compiler warning */ + (void) handle; /* Eliminate compiler warning */ DBG (3, "sane_control_option: handle=%p, opt=%d, act=%d, val=%p, info=%p\n", @@ -945,7 +945,7 @@ sane_get_parameters (SANE_Handle handle, SANE_Parameters * params) SANE_UNFIX (optionBotRightYValue - optionTopLeftYValue) / MM_IN_INCH * optionResolutionValue; - handle = handle; /* Eliminate compiler warning */ + (void) handle; /* Eliminate compiler warning */ DBG (3, "sane_get_parameters\n"); parms.depth = 8; @@ -1035,7 +1035,7 @@ sane_set_io_mode (SANE_Handle handle, SANE_Bool non_blocking) SANE_Status sane_get_select_fd (SANE_Handle handle, SANE_Int * fd) { - handle = handle; /* silence gcc */ - fd = fd; /* silence gcc */ + (void) handle; /* silence gcc */ + (void) fd; /* silence gcc */ return SANE_STATUS_UNSUPPORTED; } diff --git a/backend/canon_dr-cmd.h b/backend/canon_dr-cmd.h index e9fc54b..0ef883f 100644 --- a/backend/canon_dr-cmd.h +++ b/backend/canon_dr-cmd.h @@ -131,9 +131,12 @@ putnbyte (unsigned char *pnt, unsigned int value, unsigned int nbytes) #define IN_periph_devtype_unknown 0x1f #define get_IN_response_format(in) getbitfield(in + 0x03, 0x07, 0) #define IN_recognized 0x02 -#define get_IN_vendor(in, buf) strncpy(buf, (char *)in + 0x08, 0x08) -#define get_IN_product(in, buf) strncpy(buf, (char *)in + 0x10, 0x010) -#define get_IN_version(in, buf) strncpy(buf, (char *)in + 0x20, 0x04) +#define get_IN_vendor(in, buf) snprintf(buf, 0x08 + 1, "%.*s", \ + 0x08, (char*)in + 0x08) +#define get_IN_product(in, buf) snprintf(buf, 0x10 + 1, "%.*s", \ + 0x10, (char*)in + 0x10) +#define get_IN_version(in, buf) snprintf(buf, 0x04 + 1, "%.*s", \ + 0x04, (char*)in + 0x20) /* the VPD response */ #define get_IN_page_length(in) in[0x04] @@ -219,6 +222,7 @@ putnbyte (unsigned char *pnt, unsigned int value, unsigned int nbytes) #define SR_datatype_endorser 0x90 #define SR_datatype_fineoffset 0x90 #define SR_datatype_finegain 0x91 +#define SR_datatype_imprinters 0x96 /*DR-X10C*/ /* ==================================================================== */ /* READ */ @@ -252,7 +256,20 @@ putnbyte (unsigned char *pnt, unsigned int value, unsigned int nbytes) /*counters*/ #define R_COUNTERS_len 0x80 -#define get_R_COUNTERS_scans(in) getnbyte(in + 0x04, 4) +#define get_R_COUNTERS_total(in) getnbyte(in + 0x04, 4) +#define get_R_COUNTERS_last_srv(in) getnbyte(in + 0x44, 4) + +/*imprinters*/ +#define R_IMPRINTER_len 0x20 +#define R_PRE_IMPRINTER 0 +#define R_POST_IMPRINTER 1 +#define get_R_IMPRINTER_found(in) getbitfield(in+1, 1, 0) +/*4 bytes at in + 0: (DR-X10C) +pre-imprinter on: 0x07010000 +pre-imprinter off: 0x06000000 +post-imprinter on: 0x03010000 +post-imprinter off: 0x02000000 +*/ /*endorser unread?*/ @@ -454,6 +471,14 @@ putnbyte (unsigned char *pnt, unsigned int value, unsigned int nbytes) #define SM2_pc_buffer 0x02 #define SM2_pc_hw_enhancement 0x03 #define SM2_pc_dropout 0x06 +#define SM2_pc_date_time 0x07 +#define SM2_pc_imprinter_settings 0x33 +#define SM2_pc_imprinter_specstring 0x34 + +/* ==================================================================== */ +/* GET SCAN MODE 2 */ +#define GET_SCAN_MODE2_code 0xe4 +#define GET_SCAN_MODE2_len 12 /* ==================================================================== */ /* SET SCAN MODE 2 */ @@ -465,11 +490,15 @@ putnbyte (unsigned char *pnt, unsigned int value, unsigned int nbytes) /* the payload */ #define SSM2_PAY_len 0x10 +#define SSM2_IMPRINTER_STRING_PAY_len 0x8e /* for DF (0x00) page */ -#define set_SSM2_DF_thick(sb, val) setbitfield(sb+3, 1, 2, val) +#define set_SSM2_DF_imprint(sb, val) setbitfield(sb+2, 1, 0, val) +#define set_SSM2_DF_post_addon(sb, val) setbitfield(sb+2, 1, 1, val) #define set_SSM2_DF_len(sb, val) setbitfield(sb+3, 1, 0, val) +#define set_SSM2_DF_thick(sb, val) setbitfield(sb+3, 1, 2, val) #define set_SSM2_DF_staple(sb, val) setbitfield(sb+3, 1, 4, val) +#define set_SSM2_DF_imprint2(sb, val) setbitfield(sb+3, 1, 6, val) /* for ULTRA (0x01) page */ #define set_SSM2_ULTRA_top(sb, val) putnbyte(sb + 0x07, val, 2) @@ -489,6 +518,32 @@ putnbyte (unsigned char *pnt, unsigned int value, unsigned int nbytes) #define set_SSM2_DO_en(sb, val) sb[0x0a] = val #define set_SSM2_DO_side(sb, val) sb[0x05] = val +/* for IMPRINT DATE & TIME (0x07) */ +#define set_SSM2_imprint_year(sb, val) putnbyte(sb + 0x02, val, 2) +#define set_SSM2_imprint_month(sb, val) putnbyte(sb + 0x04, val, 1) +#define set_SSM2_imprint_day(sb, val) putnbyte(sb + 0x05, val, 1) +#define set_SSM2_imprint_hour(sb, val) putnbyte(sb + 0x06, val, 1) +#define set_SSM2_imprint_min(sb, val) putnbyte(sb + 0x07, val, 1) +#define set_SSM2_imprint_sec(sb, val) putnbyte(sb + 0x08, val, 1) + +/* for IMPRINTER SETTINGS (0x33) page */ +#define set_SSM2_postimprint_cmd(sb) sb[0x04] = 1 +#define set_SSM2_postimprint_addon(sb) setbitfield(sb, 1, 1, 1) +#define set_SSM2_imprint_hoffset(sb, val) putnbyte(sb + 0x05, val, 2) +#define set_SSM2_imprint_voffset(sb, val) putnbyte(sb + 0x07, val, 2) + +/* for IMPRINTER STRING SPECIFICATION (0x34) page */ +#define IMPRINTER_12x12_FONT 0 +#define IMPRINTER_8x12_FONT 1 +#define set_SSM2_imprint_fontsize(sb, val) setbitfield(sb + 0xA, 1, 0, val) +#define set_SSM2_imprint_spacing(sb, val) setbitfield(sb + 0xA, 1, 1, val) +#define set_SSM2_imprint_addonmode(sb, val) setbitfield(sb + 0x9, 3, 4, val) +#define IMPRINTER_0_FONT_ROT 0 +#define IMPRINTER_90_FONT_ROT 1 +#define IMPRINTER_180_FONT_ROT 2 +#define IMPRINTER_270_FONT_ROT 3 +#define set_SSM2_imprint_fontrot(sb, val) setbitfield(sb + 0x9, 3, 0, val) + /* ==================================================================== */ /* window descriptor macros for SET_WINDOW and GET_WINDOW */ diff --git a/backend/canon_dr.c b/backend/canon_dr.c index 95799e7..58299d7 100644 --- a/backend/canon_dr.c +++ b/backend/canon_dr.c @@ -3,7 +3,7 @@ This file is part of the SANE package, and implements a SANE backend for various Canon DR-series scanners. - Copyright (C) 2008-2021 m. allan noah + Copyright (C) 2008-2022 m. allan noah Yabarana Corp. www.yabarana.com provided significant funding EvriChart, Inc. www.evrichart.com provided funding and loaned equipment @@ -355,6 +355,10 @@ - rewrite do_cmd() timeout handling - remove long timeout TUR from v61 (did not help) - allow config file to set initial tur timeout for DR-X10C (#142) + v63 2022-11-18, CQ, MAN + - add support for reading the total and roller counters + v64 2022-11-18, CQ, MAN + - add complete support for imprinters on X10C (#585) SANE FLOW DIAGRAM @@ -393,6 +397,7 @@ #include <math.h> /*tan*/ #include <unistd.h> /*usleep*/ #include <sys/time.h> /*gettimeofday*/ +#include <time.h> /*localtime*/ #include <stdlib.h> /*strtol*/ #include "../include/sane/sanei_backend.h" @@ -406,7 +411,7 @@ #include "canon_dr.h" #define DEBUG 1 -#define BUILD 62 +#define BUILD 64 /* values for SANE_DEBUG_CANON_DR env var: - errors 5 @@ -449,6 +454,13 @@ #define STRING_NONE SANE_I18N("None") #define STRING_JPEG SANE_I18N("JPEG") +#define STRING_IMPRINTER_8x12_FONT SANE_I18N("8x12") +#define STRING_IMPRINTER_12x12_FONT SANE_I18N("12x12") + +#define STRING_IMPRINTER_ADDON_BoW SANE_I18N("Black-on-White") +#define STRING_IMPRINTER_ADDON_BoI SANE_I18N("Black-on-Image") +#define STRING_IMPRINTER_ADDON_WoB SANE_I18N("White-on-Black") + /* Also set via config file. */ static int global_buffer_size; static int global_buffer_size_default = 2 * 1024 * 1024; @@ -494,7 +506,7 @@ static struct scanner *scanner_devList = NULL; SANE_Status sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize) { - authorize = authorize; /* get rid of compiler warning */ + (void) authorize; /* get rid of compiler warning */ DBG_INIT (); DBG (10, "sane_init: start\n"); @@ -547,7 +559,7 @@ sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only) int num_devices=0; int i=0; - local_only = local_only; /* get rid of compiler warning */ + (void) local_only; /* get rid of compiler warning */ DBG (10, "sane_get_devices: start\n"); @@ -992,6 +1004,12 @@ attach_one (const char *device_name, int connType) return ret; } + /* this detects imprinters if they are available */ + ret = init_imprinters (s); + if (ret != SANE_STATUS_GOOD) { + DBG (5, "attach_one: errors while trying to detect optional imprinters, continuing\n"); + } + /* enable/read the buttons */ ret = init_panel (s); if (ret != SANE_STATUS_GOOD) { @@ -1001,6 +1019,13 @@ attach_one (const char *device_name, int connType) return ret; } + /* enable/read the lifecycle counters */ + ret = init_counters (s); + if (ret != SANE_STATUS_GOOD) { + DBG (5, "attach_one: unable to detect lifecycle counters, continuing\n"); + return ret; + } + /* sets SANE option 'values' to good defaults */ ret = init_user (s); if (ret != SANE_STATUS_GOOD) { @@ -1168,6 +1193,7 @@ init_inquire (struct scanner *s) if (strncmp ("DR", s->model_name, 2) && strncmp ("CR", s->model_name, 2) && strncmp ("P-", s->model_name, 2) + && strncmp ("R", s->model_name, 1) ) { DBG (5, "The device at '%s' is reported to be a '%s'\n", s->device_name, s->model_name); @@ -1388,8 +1414,9 @@ init_model (struct scanner *s) s->max_x_fb = s->max_x; s->max_y_fb = s->max_y; - /* missing from vpd- we will unset this for b&w machines below */ + /* missing from vpd- we will unset these for some machines below */ s->can_color = 1; + s->can_read_lifecycle_counters = 1; /* specific settings missing from vpd */ if (strstr (s->model_name,"DR-9080")){ @@ -1491,6 +1518,34 @@ init_model (struct scanner *s) s->can_monochrome=0; } + else if (strstr (s->model_name,"R40") + ){ + /* confirmed */ + s->gray_interlace[SIDE_FRONT] = GRAY_INTERLACE_C120; + s->gray_interlace[SIDE_BACK] = GRAY_INTERLACE_C120; + s->color_interlace[SIDE_FRONT] = COLOR_INTERLACE_C120; + s->color_interlace[SIDE_BACK] = COLOR_INTERLACE_C120; + s->duplex_interlace = DUPLEX_INTERLACE_2510; + /*s->duplex_offset = 320; now set in config file*/ + s->fixed_width = 1; + s->need_ccal = 1; + s->fcal_src = FCAL_SRC_SCAN; + s->fcal_dest = FCAL_DEST_SW; + s->rgb_format = 1; + s->sw_lut = 1; + + /*only in Y direction, so we trash them in X*/ + s->std_res_x[DPI_100]=0; + s->std_res_x[DPI_150]=0; + s->std_res_x[DPI_200]=0; + s->std_res_x[DPI_240]=0; + s->std_res_x[DPI_400]=0; + + /* suspected settings */ + s->ccal_version = 3; + s->has_df_ultra = 1; + } + /* copied from 2510, possibly incorrect */ else if (strstr (s->model_name,"DR-3010")){ s->rgb_format = 1; @@ -1840,6 +1895,7 @@ init_model (struct scanner *s) } else if (strstr (s->model_name,"DR-X10C")){ + int i = 0; /* Required for USB coms */ s->has_ssm = 0; @@ -1862,6 +1918,61 @@ init_model (struct scanner *s) s->std_res_y[DPI_600]=1; s->has_hwcrop = 1; + + /*valid horizontal offsets for post-imprinter*/ + s->post_imprinter_h_offset_list[++i] = 21; + s->post_imprinter_h_offset_list[++i] = 35; + s->post_imprinter_h_offset_list[++i] = 47; + s->post_imprinter_h_offset_list[++i] = 59; + s->post_imprinter_h_offset_list[++i] = 72; + s->post_imprinter_h_offset_list[++i] = 99; + s->post_imprinter_h_offset_list[++i] = 114; + s->post_imprinter_h_offset_list[++i] = 143; + s->post_imprinter_h_offset_list[++i] = 155; + s->post_imprinter_h_offset_list[++i] = 167; + s->post_imprinter_h_offset_list[++i] = 196; + s->post_imprinter_h_offset_list[++i] = 211; + s->post_imprinter_h_offset_list[++i] = 239; + s->post_imprinter_h_offset_list[++i] = 251; + s->post_imprinter_h_offset_list[++i] = 263; + s->post_imprinter_h_offset_list[++i] = 275; + s->post_imprinter_h_offset_list[++i] = 289; + s->post_imprinter_h_offset_list[0] = i; + + i = 0; + /*valid horizontal offsets for pre-imprinter*/ + s->pre_imprinter_h_offset_list[++i] = 14; + s->pre_imprinter_h_offset_list[++i] = 28; + s->pre_imprinter_h_offset_list[++i] = 41; + s->pre_imprinter_h_offset_list[++i] = 53; + s->pre_imprinter_h_offset_list[++i] = 65; + s->pre_imprinter_h_offset_list[++i] = 106; + s->pre_imprinter_h_offset_list[0] = i; + + /*valid vertical offsets for imprinters*/ + s->imprinter_v_offset_range.min = 0; + s->imprinter_v_offset_range.max = 500; + s->imprinter_v_offset_range.quant = 1; + + i = 0; + /*valid font angles for imprinters*/ + s->imprinter_font_angle_list[++i] = 0; + s->imprinter_font_angle_list[++i] = 90; + s->imprinter_font_angle_list[++i] = 180; + s->imprinter_font_angle_list[++i] = 270; + s->imprinter_font_angle_list[0] = i; + + i = 0; + s->imprint_font_size_list[i++] = STRING_IMPRINTER_8x12_FONT; + s->imprint_font_size_list[i++] = STRING_IMPRINTER_12x12_FONT; + s->imprint_font_size_list[i] = NULL; + + i = 0; + s->imprint_addon_mode_list[i++] = STRING_IMPRINTER_ADDON_BoI; + s->imprint_addon_mode_list[i++] = STRING_IMPRINTER_ADDON_BoW; + s->imprint_addon_mode_list[i++] = STRING_IMPRINTER_ADDON_WoB; + s->imprint_addon_mode_list[i++] = STRING_NONE; + s->imprint_addon_mode_list[i] = NULL; } DBG (10, "init_model: finish\n"); @@ -1870,6 +1981,30 @@ init_model (struct scanner *s) } /* + * try to detect imprinters. + */ +static SANE_Status +init_imprinters (struct scanner *s) +{ + SANE_Status ret = SANE_STATUS_GOOD; + + s->has_pre_imprinter = 0; + s->has_post_imprinter = 0; + + ret = detect_imprinter(s,R_PRE_IMPRINTER); + if(ret != SANE_STATUS_GOOD){ + return ret; + } + + ret = detect_imprinter(s,R_POST_IMPRINTER); + if(ret != SANE_STATUS_GOOD){ + return ret; + } + + return ret; +} + +/* * This function enables the buttons and preloads the current panel values */ static SANE_Status @@ -1901,6 +2036,28 @@ init_panel (struct scanner *s) } /* + * This function disables the lifecycle counters if not available + */ +static SANE_Status +init_counters (struct scanner *s) +{ + SANE_Status ret = SANE_STATUS_GOOD; + + DBG (10, "init_counters: start\n"); + + ret = read_counters(s); + if(ret){ + DBG (5, "init_counters: disabling lifecycle counters\n"); + s->can_read_lifecycle_counters = 0; + return ret; + } + + DBG (10, "init_counters: finish\n"); + + return ret; +} + +/* * set good default user values. * struct is already initialized to 0. */ @@ -1953,6 +2110,10 @@ init_user (struct scanner *s) s->threshold = 90; s->compress_arg = 50; + s->pre_imprint.h_offset = 65; + s->post_imprint.h_offset = 155; + s->post_imprint_addon_mode = ADDON_BoI; + DBG (10, "init_user: finish\n"); return SANE_STATUS_GOOD; @@ -2737,6 +2898,197 @@ sane_get_option_descriptor (SANE_Handle handle, SANE_Int option) opt->cap = SANE_CAP_INACTIVE; } + /* "Imprinter" group --------------------------------------------------- */ + if(option==OPT_IMPRINT_GROUP){ + opt->name = "imprinter-options"; + opt->title = SANE_I18N ("Imprinter Options"); + opt->desc = SANE_I18N ("Controls for imprinter units"); + opt->type = SANE_TYPE_GROUP; + opt->constraint_type = SANE_CONSTRAINT_NONE; + + /*flaming hack to get scanimage to hide group*/ + if ( !(s->has_pre_imprinter || s->has_post_imprinter) ) + opt->type = SANE_TYPE_BOOL; + } + + if(option==OPT_PRE_IMPRINT_SPECSTRING){ + opt->name = "pre-imprint-string"; + opt->title = "Pre-Imprinter string"; + opt->desc = "String specifier for the pre-imprinter text"; + opt->type = SANE_TYPE_STRING; + opt->size = IMPRINT_SPECSTRING_LEN; + if (s->has_pre_imprinter) + opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED; + else + opt->cap = SANE_CAP_INACTIVE; + } + + if(option==OPT_PRE_IMPRINT_H_OFFSET){ + opt->name = "pre-imprint-h-offset"; + opt->title = "Pre-Imprinter horizontal offset"; + opt->desc = "Integer specifying the horizontal positioning of the pre-imprinter"; + opt->type = SANE_TYPE_INT; + opt->unit = SANE_UNIT_MM; + opt->size = sizeof(SANE_Word); + opt->constraint_type = SANE_CONSTRAINT_WORD_LIST; + opt->constraint.word_list = s->pre_imprinter_h_offset_list; + if (s->has_pre_imprinter) + opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED; + else + opt->cap = SANE_CAP_INACTIVE; + } + + if(option==OPT_PRE_IMPRINT_V_OFFSET){ + opt->name = "pre-imprint-v-offset"; + opt->title = "Pre-Imprinter vertical offset"; + opt->desc = "Integer specifying the vertical positioning of the pre-imprinter"; + opt->type = SANE_TYPE_INT; + opt->unit = SANE_UNIT_MM; + opt->size = sizeof(SANE_Word); + opt->constraint_type = SANE_CONSTRAINT_RANGE; + opt->constraint.range = &s->imprinter_v_offset_range; + if (s->has_pre_imprinter) + opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED; + else + opt->cap = SANE_CAP_INACTIVE; + } + + if(option==OPT_PRE_IMPRINT_FONT_SIZE){ + opt->name = "pre-imprint-font-size"; + opt->title = "Pre-Imprinter font size"; + opt->desc = "Integer specifying the pre-imprint font size"; + opt->type = SANE_TYPE_STRING; + opt->constraint_type = SANE_CONSTRAINT_STRING_LIST; + opt->constraint.string_list = s->imprint_font_size_list; + opt->size = maxStringSize (opt->constraint.string_list); + if (s->has_pre_imprinter) + opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED; + else + opt->cap = SANE_CAP_INACTIVE; + } + + if(option==OPT_PRE_IMPRINT_FONT_ROT){ + opt->name = "pre-imprint-font-rot"; + opt->title = "Pre-Imprinter font rotation"; + opt->desc = "Integer specifying the pre-imprint font rotation"; + opt->type = SANE_TYPE_INT; + opt->unit = SANE_UNIT_NONE; + opt->size = sizeof(SANE_Word); + opt->constraint_type = SANE_CONSTRAINT_WORD_LIST; + opt->constraint.word_list = s->imprinter_font_angle_list; + if (s->has_pre_imprinter) + opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED; + else + opt->cap = SANE_CAP_INACTIVE; + } + + if(option==OPT_PRE_IMPRINT_SPACING){ + opt->name = "pre-imprint-spacing"; + opt->title = "Pre-Imprinter spacing"; + opt->desc = "Enables the pre-imprint extra spacing"; + opt->type = SANE_TYPE_BOOL; + if (s->has_pre_imprinter) + opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED; + else + opt->cap = SANE_CAP_INACTIVE; + } + + if(option==OPT_POST_IMPRINT_SPECSTRING){ + opt->name = "post-imprint-string"; + opt->title = "Post-Imprinter string"; + opt->desc = "String specifier for the post-imprinter text"; + opt->type = SANE_TYPE_STRING; + opt->size = IMPRINT_SPECSTRING_LEN; + if (s->has_post_imprinter) + opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED; + else + opt->cap = SANE_CAP_INACTIVE; + } + + if(option==OPT_POST_IMPRINT_H_OFFSET){ + opt->name = "post-imprint-h-offset"; + opt->title = "Post-Imprinter horizontal offset"; + opt->desc = "Integer specifying the horizontal positioning of the post-imprinter"; + opt->type = SANE_TYPE_INT; + opt->unit = SANE_UNIT_MM; + opt->size = sizeof(SANE_Word); + opt->constraint_type = SANE_CONSTRAINT_WORD_LIST; + opt->constraint.word_list = s->post_imprinter_h_offset_list; + if (s->has_post_imprinter) + opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED; + else + opt->cap = SANE_CAP_INACTIVE; + } + + if(option==OPT_POST_IMPRINT_V_OFFSET){ + opt->name = "post-imprint-v-offset"; + opt->title = "Post-Imprinter vertical offset"; + opt->desc = "Integer specifying the vertical positioning of the post-imprinter"; + opt->type = SANE_TYPE_INT; + opt->unit = SANE_UNIT_MM; + opt->size = sizeof(SANE_Word); + opt->constraint_type = SANE_CONSTRAINT_RANGE; + opt->constraint.range = &s->imprinter_v_offset_range; + if (s->has_post_imprinter) + opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED; + else + opt->cap = SANE_CAP_INACTIVE; + } + + if(option==OPT_POST_IMPRINT_FONT_SIZE){ + opt->name = "post-imprint-font-size"; + opt->title = "Post-Imprinter font size"; + opt->desc = "Integer specifying the post-imprint font size"; + opt->type = SANE_TYPE_STRING; + opt->constraint_type = SANE_CONSTRAINT_STRING_LIST; + opt->constraint.string_list = s->imprint_font_size_list; + opt->size = maxStringSize (opt->constraint.string_list); + if (s->has_post_imprinter) + opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED; + else + opt->cap = SANE_CAP_INACTIVE; + } + + if(option==OPT_POST_IMPRINT_FONT_ROT){ + opt->name = "post-imprint-font-rot"; + opt->title = "Post-Imprinter font rotation"; + opt->desc = "Integer specifying the post-imprint font rotation"; + opt->type = SANE_TYPE_INT; + opt->unit = SANE_UNIT_NONE; + opt->size = sizeof(SANE_Word); + opt->constraint_type = SANE_CONSTRAINT_WORD_LIST; + opt->constraint.word_list = s->imprinter_font_angle_list; + if (s->has_post_imprinter) + opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED; + else + opt->cap = SANE_CAP_INACTIVE; + } + + if(option==OPT_POST_IMPRINT_SPACING){ + opt->name = "post-imprint-spacing"; + opt->title = "Post-Imprinter spacing"; + opt->desc = "Enables the post-imprint extra spacing"; + opt->type = SANE_TYPE_BOOL; + if (s->has_post_imprinter) + opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED; + else + opt->cap = SANE_CAP_INACTIVE; + } + + if(option==OPT_POST_IMPRINT_ADDON_MODE){ + opt->name = "post-imprint-addon-mode"; + opt->title = "Post-Imprinter addon mode"; + opt->desc = "Integer specifying the type of post-imprint addon rendered in the scanned image"; + opt->type = SANE_TYPE_STRING; + opt->constraint_type = SANE_CONSTRAINT_STRING_LIST; + opt->constraint.string_list = s->imprint_addon_mode_list; + opt->size = maxStringSize (opt->constraint.string_list); + if (s->has_post_imprinter) + opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED; + else + opt->cap = SANE_CAP_INACTIVE; + } + /* "Sensor" group ------------------------------------------------------ */ if(option==OPT_SENSOR_GROUP){ opt->name = SANE_NAME_SENSORS; @@ -2830,6 +3182,34 @@ sane_get_option_descriptor (SANE_Handle handle, SANE_Int option) opt->cap = SANE_CAP_INACTIVE; } + if(option==OPT_ROLLERCOUNTER){ + opt->name = "roller-counter"; + opt->title = "Roller Counter"; + opt->desc = "Scans since last roller replacement"; + opt->type = SANE_TYPE_INT; + opt->unit = SANE_UNIT_NONE; + opt->constraint_type = SANE_CONSTRAINT_NONE; + + if (s->can_read_lifecycle_counters) + opt->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED; + else + opt->cap = SANE_CAP_INACTIVE; + } + + if(option==OPT_TOTALCOUNTER){ + opt->name = "total-counter"; + opt->title = "Total Counter"; + opt->desc = "Total scan count of the device"; + opt->type = SANE_TYPE_INT; + opt->unit = SANE_UNIT_NONE; + opt->constraint_type = SANE_CONSTRAINT_NONE; + + if (s->can_read_lifecycle_counters) + opt->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED; + else + opt->cap = SANE_CAP_INACTIVE; + } + if(option==OPT_ADF_LOADED){ opt->name = "adf-loaded"; opt->title = "ADF Loaded"; @@ -3108,6 +3488,122 @@ sane_control_option (SANE_Handle handle, SANE_Int option, *val_p = s->hwcrop; return SANE_STATUS_GOOD; + case OPT_PRE_IMPRINT_SPECSTRING: + strcpy(val, s->pre_imprint.specstring); + return SANE_STATUS_GOOD; + + case OPT_PRE_IMPRINT_H_OFFSET: + *val_p = s->pre_imprint.h_offset; + return SANE_STATUS_GOOD; + + case OPT_PRE_IMPRINT_V_OFFSET: + *val_p = s->pre_imprint.v_offset; + return SANE_STATUS_GOOD; + + case OPT_PRE_IMPRINT_FONT_SIZE: + switch (s->pre_imprint.font_size){ + case IMPRINTER_12x12_FONT: + strcpy(val, STRING_IMPRINTER_12x12_FONT); + break; + + case IMPRINTER_8x12_FONT: + strcpy(val, STRING_IMPRINTER_8x12_FONT); + break; + } + return SANE_STATUS_GOOD; + + case OPT_PRE_IMPRINT_FONT_ROT: + switch (s->pre_imprint.font_rot){ + case IMPRINTER_0_FONT_ROT: + *val_p = 0; + break; + + case IMPRINTER_90_FONT_ROT: + *val_p = 90; + break; + + case IMPRINTER_180_FONT_ROT: + *val_p = 180; + break; + + case IMPRINTER_270_FONT_ROT: + *val_p = 270; + break; + } + return SANE_STATUS_GOOD; + + case OPT_PRE_IMPRINT_SPACING: + *val_p = s->pre_imprint.spacing; + return SANE_STATUS_GOOD; + + case OPT_POST_IMPRINT_SPECSTRING: + strcpy(val, s->post_imprint.specstring); + return SANE_STATUS_GOOD; + + case OPT_POST_IMPRINT_H_OFFSET: + *val_p = s->post_imprint.h_offset; + return SANE_STATUS_GOOD; + + case OPT_POST_IMPRINT_V_OFFSET: + *val_p = s->post_imprint.v_offset; + return SANE_STATUS_GOOD; + + case OPT_POST_IMPRINT_FONT_SIZE: + switch (s->post_imprint.font_size){ + case IMPRINTER_12x12_FONT: + strcpy(val, STRING_IMPRINTER_12x12_FONT); + break; + + case IMPRINTER_8x12_FONT: + strcpy(val, STRING_IMPRINTER_8x12_FONT); + break; + } + return SANE_STATUS_GOOD; + + case OPT_POST_IMPRINT_FONT_ROT: + switch (s->post_imprint.font_rot){ + case IMPRINTER_0_FONT_ROT: + *val_p = 0; + break; + + case IMPRINTER_90_FONT_ROT: + *val_p = 90; + break; + + case IMPRINTER_180_FONT_ROT: + *val_p = 180; + break; + + case IMPRINTER_270_FONT_ROT: + *val_p = 270; + break; + } + return SANE_STATUS_GOOD; + + case OPT_POST_IMPRINT_SPACING: + *val_p = s->post_imprint.spacing; + return SANE_STATUS_GOOD; + + case OPT_POST_IMPRINT_ADDON_MODE: + switch (s->post_imprint_addon_mode){ + case ADDON_BoW: + strcpy(val, STRING_IMPRINTER_ADDON_BoW); + break; + + case ADDON_BoI: + strcpy(val, STRING_IMPRINTER_ADDON_BoI); + break; + + case ADDON_WoB: + strcpy(val, STRING_IMPRINTER_ADDON_WoB); + break; + + case ADDON_DISABLED: + strcpy(val, STRING_NONE); + break; + } + return SANE_STATUS_GOOD; + /* Sensor Group */ case OPT_START: ret = read_panel(s,OPT_START); @@ -3144,6 +3640,16 @@ sane_control_option (SANE_Handle handle, SANE_Int option, *val_p = s->panel_counter; return ret; + case OPT_ROLLERCOUNTER: + ret = read_counters(s); + *val_p = s->roller_counter; + return ret; + + case OPT_TOTALCOUNTER: + ret = read_counters(s); + *val_p = s->total_counter; + return ret; + case OPT_ADF_LOADED: ret = read_sensors(s,OPT_ADF_LOADED); *val_p = s->sensor_adf_loaded; @@ -3431,6 +3937,119 @@ sane_control_option (SANE_Handle handle, SANE_Int option, s->hwcrop = val_c; return SANE_STATUS_GOOD; + case OPT_PRE_IMPRINT_SPECSTRING: + if (strlen(val) < IMPRINT_SPECSTRING_LEN){ + strncpy(s->pre_imprint.specstring, val, IMPRINT_SPECSTRING_LEN); + return SANE_STATUS_GOOD; + } + DBG (5, "sane_control_option: pre-imprint spec string '%s' exceed the limit of %d characters\n", (SANE_String)val, IMPRINT_SPECSTRING_LEN); + return SANE_STATUS_INVAL; + + case OPT_PRE_IMPRINT_H_OFFSET: + s->pre_imprint.h_offset = val_c; + return SANE_STATUS_GOOD; + + case OPT_PRE_IMPRINT_V_OFFSET: + s->pre_imprint.v_offset = val_c; + return SANE_STATUS_GOOD; + + case OPT_PRE_IMPRINT_FONT_SIZE: + if (!strcmp (val, STRING_IMPRINTER_12x12_FONT)) { + s->pre_imprint.font_size = IMPRINTER_12x12_FONT; + } + if (!strcmp (val, STRING_IMPRINTER_8x12_FONT)) { + s->pre_imprint.font_size = IMPRINTER_8x12_FONT; + } + return SANE_STATUS_GOOD; + + case OPT_PRE_IMPRINT_FONT_ROT: + switch (val_c){ + case 0: + s->pre_imprint.font_rot = IMPRINTER_0_FONT_ROT; + break; + + case 90: + s->pre_imprint.font_rot = IMPRINTER_90_FONT_ROT; + break; + + case 180: + s->pre_imprint.font_rot = IMPRINTER_180_FONT_ROT; + break; + + case 270: + s->pre_imprint.font_rot = IMPRINTER_270_FONT_ROT; + break; + } + return SANE_STATUS_GOOD; + + case OPT_PRE_IMPRINT_SPACING: + s->pre_imprint.spacing = val_c; + return SANE_STATUS_GOOD; + + case OPT_POST_IMPRINT_SPECSTRING: + if (strlen(val) < IMPRINT_SPECSTRING_LEN){ + strncpy(s->post_imprint.specstring, val, IMPRINT_SPECSTRING_LEN); + return SANE_STATUS_GOOD; + } + DBG (5, "sane_control_option: post-imprint spec string '%s' exceed the limit of %d characters\n", (SANE_String)val, IMPRINT_SPECSTRING_LEN); + return SANE_STATUS_INVAL; + + case OPT_POST_IMPRINT_H_OFFSET: + s->post_imprint.h_offset = val_c; + return SANE_STATUS_GOOD; + + case OPT_POST_IMPRINT_V_OFFSET: + s->post_imprint.v_offset = val_c; + return SANE_STATUS_GOOD; + + case OPT_POST_IMPRINT_FONT_SIZE: + if (!strcmp (val, STRING_IMPRINTER_12x12_FONT)) { + s->post_imprint.font_size = IMPRINTER_12x12_FONT; + } + if (!strcmp (val, STRING_IMPRINTER_8x12_FONT)) { + s->post_imprint.font_size = IMPRINTER_8x12_FONT; + } + return SANE_STATUS_GOOD; + + case OPT_POST_IMPRINT_FONT_ROT: + switch (val_c){ + case 0: + s->post_imprint.font_rot = IMPRINTER_0_FONT_ROT; + break; + + case 90: + s->post_imprint.font_rot = IMPRINTER_90_FONT_ROT; + break; + + case 180: + s->post_imprint.font_rot = IMPRINTER_180_FONT_ROT; + break; + + case 270: + s->post_imprint.font_rot = IMPRINTER_270_FONT_ROT; + break; + } + return SANE_STATUS_GOOD; + + case OPT_POST_IMPRINT_SPACING: + s->post_imprint.spacing = val_c; + return SANE_STATUS_GOOD; + + case OPT_POST_IMPRINT_ADDON_MODE: + if (!strcmp (val, STRING_IMPRINTER_ADDON_BoW)) { + s->post_imprint_addon_mode = ADDON_BoW; + } + if (!strcmp (val, STRING_IMPRINTER_ADDON_BoI)) { + s->post_imprint_addon_mode = ADDON_BoI; + } + if (!strcmp (val, STRING_IMPRINTER_ADDON_WoB)) { + s->post_imprint_addon_mode = ADDON_WoB; + } + if (!strcmp (val, STRING_NONE)) { + s->post_imprint_addon_mode = ADDON_DISABLED; + } + return SANE_STATUS_GOOD; + } } /* else */ @@ -3636,6 +4255,14 @@ ssm_df (struct scanner *s) set_SSM2_DF_staple(out, 1); } + int requires_postimprint = s->has_post_imprinter && (strlen(s->post_imprint.specstring) > 0); + int requires_preimprint = s->has_pre_imprinter && (strlen(s->pre_imprint.specstring) > 0); + if (s->has_post_imprinter) + set_SSM2_DF_post_addon(out, requires_postimprint); + if (requires_postimprint || requires_preimprint){ + set_SSM2_DF_imprint(out, 1); + } + ret = do_cmd ( s, 1, 0, cmd, cmdLen, @@ -3897,6 +4524,50 @@ ssm_do (struct scanner *s) } static SANE_Status +read_counters(struct scanner *s) +{ + SANE_Status ret = SANE_STATUS_GOOD; + + unsigned char cmd[READ_len]; + size_t cmdLen = READ_len; + + unsigned char in[R_COUNTERS_len]; + size_t inLen = R_COUNTERS_len; + + if (!s->can_read_lifecycle_counters){ + DBG(10, "read_counters: unsupported\n"); + return ret; + } + + DBG(10, "read_counters: start\n"); + + memset(cmd,0,cmdLen); + set_SCSI_opcode(cmd, READ_code); + set_R_datatype_code(cmd, SR_datatype_counters); + set_R_xfer_length(cmd, inLen); + + ret = do_cmd( + s, 1, 0, + cmd, cmdLen, + NULL, 0, + in, &inLen + ); + + if (ret == SANE_STATUS_GOOD || ret == SANE_STATUS_EOF){ + + s->total_counter = get_R_COUNTERS_total(in); + s->roller_counter = s->total_counter - get_R_COUNTERS_last_srv(in); + + DBG(10, "read_counters: total counter: %d roller_counter %d \n",s->total_counter,s->roller_counter); + ret = SANE_STATUS_GOOD; + }else{ + DBG(10, "read_counters: ERROR: %d\n",ret); + } + + return ret; +} + +static SANE_Status read_sensors(struct scanner *s,SANE_Int option) { SANE_Status ret=SANE_STATUS_GOOD; @@ -4382,6 +5053,248 @@ update_params(struct scanner *s, int calib) return ret; } +/* simplify handling cmd SANE_STATUS_EOF as SANE_STATUS_GOOD */ +SANE_Status +send_cmd(struct scanner *s, unsigned char* cmd, size_t cmdLen, + unsigned char* out, size_t outLen, + unsigned char * inBuff, size_t * inLen) +{ + SANE_Status ret=SANE_STATUS_GOOD; + + ret = do_cmd ( + s, 1, 0, + cmd, cmdLen, + out, outLen, + inBuff, inLen + ); + + if (ret == SANE_STATUS_EOF) { + ret = SANE_STATUS_GOOD; + } + + return ret; +} + +SANE_Status +send_imprint_positioning(struct scanner* s, int is_postimprint, int enabled) +{ + unsigned char cmd[SET_SCAN_MODE2_len]; + size_t cmdLen=SET_SCAN_MODE2_len; + + unsigned char out[SSM2_PAY_len]; + size_t outLen=SSM2_PAY_len; + + unsigned char out_prefix[5]={ 0x01, 0x00, 0x60, 0x00, 0x60 }; + size_t outPrefixLen=5; + + memset(cmd,0,cmdLen); + set_SCSI_opcode(cmd,SET_SCAN_MODE2_code); + set_SSM2_page_code(cmd,SM2_pc_imprinter_settings); + if (is_postimprint) + set_SSM2_postimprint_cmd(cmd); + set_SSM2_pay_len(cmd,outLen); + + memset(out,0,outLen); + memcpy(out,out_prefix,outPrefixLen); + + int h_offset; + int v_offset; + if (is_postimprint){ + if (s->post_imprint_addon_mode != ADDON_DISABLED) + set_SSM2_postimprint_addon(out); + h_offset = s->post_imprint.h_offset; + v_offset = s->post_imprint.v_offset; + + if (enabled) + DBG (10, "send_imprint_positioning: post-imprinter: h_offset: %d v_offset: %d\n",h_offset,v_offset); + }else{ + h_offset = s->pre_imprint.h_offset; + v_offset = s->pre_imprint.v_offset; + if (enabled) + DBG (10, "send_imprint_positioning: pre-imprinter: h_offset: %d v_offset: %d\n",h_offset,v_offset); + } + if(!enabled) + h_offset = v_offset = 0; + set_SSM2_imprint_hoffset(out,h_offset); + set_SSM2_imprint_voffset(out,v_offset); + + return send_cmd(s, cmd, cmdLen, out, outLen, NULL, NULL); +} + +SANE_Status +send_imprint_specstring(struct scanner* s, int is_postimprint) +{ + unsigned char cmd[SET_SCAN_MODE2_len]; + size_t cmdLen = SET_SCAN_MODE2_len; + + unsigned char out[SSM2_IMPRINTER_STRING_PAY_len]; + size_t outLen = SSM2_IMPRINTER_STRING_PAY_len; + + memset(cmd,0,cmdLen); + set_SCSI_opcode(cmd, SET_SCAN_MODE2_code); + set_SSM2_page_code(cmd, SM2_pc_imprinter_specstring); + if (is_postimprint) + set_SSM2_postimprint_cmd(cmd); + set_SSM2_pay_len(cmd, outLen); + + memset(out,0,outLen); + /* most of these bytes have yet to be identified to specific functionalities, + as they never seem to change under different imprinting mode */ + unsigned char out_prefix[32] = { + 0x01, 0x00, + 0x60, 0x00, + 0x60, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0x03, 0x00, + 0x00, 0x00, + 0x01, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x01, + 0x04, 0x00, + 0x00, 0x00 + }; + memcpy(out, out_prefix, 32); + if (is_postimprint){ + set_SSM2_imprint_fontsize(out, s->post_imprint.font_size); + set_SSM2_imprint_fontrot(out, s->post_imprint.font_rot); + set_SSM2_imprint_spacing(out, s->post_imprint.spacing); + if (s->post_imprint_addon_mode != ADDON_DISABLED) + set_SSM2_imprint_addonmode(out, s->post_imprint_addon_mode); + strcpy((SANE_Char*)(out + 45), (SANE_String_Const) s->post_imprint.specstring); + DBG (10, "send_imprint_specstring: post-imprinter: font size: %d rotation: %d spacing: %d text: '%s' imprint-addon-mode: %d\n",s->post_imprint.font_size,s->post_imprint.font_rot,s->post_imprint.spacing,s->post_imprint.specstring,s->post_imprint_addon_mode); + }else{ + set_SSM2_imprint_fontsize(out, s->pre_imprint.font_size); + set_SSM2_imprint_fontrot(out, s->pre_imprint.font_rot); + set_SSM2_imprint_spacing(out, s->pre_imprint.spacing); + strcpy((SANE_Char*)(out + 45), (SANE_String_Const) s->pre_imprint.specstring); + DBG (10, "send_imprint_specstring: pre-imprinter: font size: %d rotation: %d spacing: %d text: '%s'\n",s->pre_imprint.font_size,s->pre_imprint.font_rot,s->pre_imprint.spacing,s->pre_imprint.specstring); + } + + return send_cmd(s, cmd, cmdLen, out, outLen, NULL, NULL); +} + +SANE_Status +send_imprint_date_and_time(struct scanner* s) +{ + unsigned char cmd[SET_SCAN_MODE2_len]; + size_t cmdLen = SET_SCAN_MODE2_len; + + unsigned char out[SSM2_PAY_len]; + size_t outLen = SSM2_PAY_len; + + memset(cmd,0,cmdLen); + set_SCSI_opcode(cmd, SET_SCAN_MODE2_code); + set_SSM2_page_code(cmd, SM2_pc_date_time); + set_SSM2_pay_len(cmd, outLen); + + memset(out,0,outLen); + + time_t t = time(NULL); + struct tm tM = *localtime(&t); + + set_SSM2_imprint_year(out, tM.tm_year + 1900); + set_SSM2_imprint_month(out, tM.tm_mon + 1); + set_SSM2_imprint_day(out, tM.tm_mday); + set_SSM2_imprint_hour(out, tM.tm_hour); + set_SSM2_imprint_min(out, tM.tm_min); + set_SSM2_imprint_sec(out, tM.tm_sec); + + return send_cmd(s, cmd, cmdLen, out, outLen, NULL, NULL); +} + +SANE_Status +load_imprinting_settings(struct scanner *s) +{ + SANE_Status ret = SANE_STATUS_GOOD; + + int requires_preimprint = (strlen(s->pre_imprint.specstring) > 0); + int requires_postimprint = (strlen(s->post_imprint.specstring) > 0); + int send_date_time = (s->has_pre_imprinter && requires_preimprint) || (s->has_post_imprinter && requires_postimprint); + + if (s->has_pre_imprinter){ + ret = send_imprint_positioning(s, 0, requires_preimprint); + DBG(10, "load_imprinting_settings: send_pre_imprint_positioning = %d \n", ret); + if (ret != SANE_STATUS_GOOD) + return ret; + if (requires_preimprint){ + ret = send_imprint_specstring(s, 0); + DBG(10, "load_imprinting_settings: send_pre_imprint_specstring = %d \n", ret); + if (ret != SANE_STATUS_GOOD) + return ret; + } + } + + if (s->has_post_imprinter){ + ret = send_imprint_positioning(s, 1, requires_postimprint); + DBG(10, "load_imprinting_settings: send_post_imprint_positioning = %d \n", ret); + if (ret != SANE_STATUS_GOOD) + return ret; + if (requires_postimprint){ + ret = send_imprint_specstring(s, 1); + DBG(10, "load_imprinting_settings: send_post_imprint_specstring = %d \n", ret); + if (ret != SANE_STATUS_GOOD) + return ret; + } + } + + if (send_date_time){ + ret = send_imprint_date_and_time(s); + DBG(10, "load_imprinting_settings: send_imprint_date_and_time = %d \n", ret); + } + return ret; +} + +static SANE_Status +detect_imprinter(struct scanner *s,SANE_Int option) +{ + SANE_Status ret = SANE_STATUS_GOOD; + + unsigned char cmd[READ_len]; + size_t cmdLen = READ_len; + + unsigned char in[R_IMPRINTER_len]; + size_t inLen = R_IMPRINTER_len; + + DBG (10, "detect_imprinter: start %d\n", option); + + memset(cmd,0,cmdLen); + set_SCSI_opcode(cmd, READ_code); + set_R_datatype_code(cmd, SR_datatype_imprinters); + set_R_xfer_uid(cmd, option); + set_R_xfer_length(cmd, inLen); + + ret = do_cmd( + s, 1, 0, + cmd, cmdLen, + NULL, 0, + in, &inLen + ); + + if (ret == SANE_STATUS_GOOD || ret == SANE_STATUS_EOF) { + ret = SANE_STATUS_GOOD; + } + + int imprinter_found = get_R_IMPRINTER_found(in); + const char* imprinter_type = "unknown"; + if (option == R_PRE_IMPRINTER){ + s->has_pre_imprinter = imprinter_found; + imprinter_type = "pre-imprinter"; + } + else if (option == R_POST_IMPRINTER){ + s->has_post_imprinter = imprinter_found; + imprinter_type = "post-imprinter"; + } + + DBG (10, "detect_imprinter: type: %s. found status bit: %d \n",imprinter_type,imprinter_found); + + return ret; +} + /* reset image size parameters after buffer_xxx functions changed them */ SANE_Status update_i_params(struct scanner *s) @@ -4471,6 +5384,14 @@ sane_start (SANE_Handle handle) goto errors; } + if (s->has_pre_imprinter || s->has_post_imprinter){ + ret = load_imprinting_settings(s); + if (ret != SANE_STATUS_GOOD) { + DBG (5, "sane_start: ERROR: invalid imprinting settings\n"); + goto errors; + } + } + /* reset the page counter after calibration */ s->panel_counter = 0; s->prev_page = 0; @@ -7204,7 +8125,7 @@ sense_handler (int fd, unsigned char * sensed_data, void *arg) DBG (5, "sense_handler: start\n"); /* kill compiler warning */ - fd = fd; + (void) fd; /* copy the rs return data into the scanner struct so that the caller can use it if he wants @@ -7465,8 +8386,8 @@ do_scsi_cmd(struct scanner *s, int runRS, int timeout, int ret; /*shut up compiler*/ - runRS=runRS; - timeout=timeout; + (void) runRS; + (void) timeout; DBG(10, "do_scsi_cmd: start\n"); diff --git a/backend/canon_dr.conf.in b/backend/canon_dr.conf.in index 7bce43c..399ed27 100644 --- a/backend/canon_dr.conf.in +++ b/backend/canon_dr.conf.in @@ -214,3 +214,7 @@ usb 0x1083 0x165d # P-208II usb 0x1083 0x165f + +# R40 +option duplex-offset 320 +usb 0x1083 0x1679 diff --git a/backend/canon_dr.h b/backend/canon_dr.h index 7afbb90..e84b5b7 100644 --- a/backend/canon_dr.h +++ b/backend/canon_dr.h @@ -51,6 +51,22 @@ enum scanner_Option OPT_SIDE, OPT_HW_CROP, + /*imprinter option group*/ + OPT_IMPRINT_GROUP, + OPT_PRE_IMPRINT_SPECSTRING, + OPT_PRE_IMPRINT_H_OFFSET, + OPT_PRE_IMPRINT_V_OFFSET, + OPT_PRE_IMPRINT_FONT_SIZE, + OPT_PRE_IMPRINT_FONT_ROT, + OPT_PRE_IMPRINT_SPACING, + OPT_POST_IMPRINT_SPECSTRING, + OPT_POST_IMPRINT_H_OFFSET, + OPT_POST_IMPRINT_V_OFFSET, + OPT_POST_IMPRINT_FONT_SIZE, + OPT_POST_IMPRINT_FONT_ROT, + OPT_POST_IMPRINT_SPACING, + OPT_POST_IMPRINT_ADDON_MODE, + /*sensor group*/ OPT_SENSOR_GROUP, OPT_START, @@ -60,6 +76,8 @@ enum scanner_Option OPT_COUNTONLY, OPT_BYPASSMODE, OPT_COUNTER, + OPT_ROLLERCOUNTER, + OPT_TOTALCOUNTER, OPT_ADF_LOADED, OPT_CARD_LOADED, @@ -106,6 +124,32 @@ struct img_params }; +struct imprint_params +{ + /* ------------------------------------------------------------------------------ */ + /* allowed values for post imprinter (in mm units): */ + /* 21, 35, 47, 59, 72, 99, 114, 143, 155, 167, 196, 211, 239, 251, 263, 275, 289 */ + /* allowed values for pre imprinter (in mm units): */ + /* 14, 28, 41, 53, 65, 106 */ + int h_offset; + /* --------------------------------------- */ + /* allowed values: 0 to 500 (in mm units) */ + int v_offset; + + int font_size; + int font_rot; + int spacing; + +#define IMPRINT_SPECSTRING_LEN 64 + /* ---------------------------------- */ + /* special tokens: */ + /* \TIME time in HH:MM:SS */ + /* \DMY date in DD/MM/YYYY */ + /* \YMD date in YYYY/MM/DD */ + /* [[0-9]+] scan page count */ + char specstring[IMPRINT_SPECSTRING_LEN]; +}; + struct scanner { /* --------------------------------------------------------------------- */ @@ -204,9 +248,12 @@ struct scanner int has_ssm2; /* newer scanners user this similar command */ int has_ssm_pay_head_len; /* newer scanners put the length twice in ssm */ int has_hwcrop; + int has_pre_imprinter; + int has_post_imprinter; int can_read_sensors; int can_read_panel; int can_write_panel; + int can_read_lifecycle_counters; int rgb_format; /* meaning unknown */ int padding; /* meaning unknown */ @@ -317,13 +364,34 @@ struct scanner unsigned char lut[256]; /* --------------------------------------------------------------------- */ - /* values used by the software enhancement code (deskew, crop, etc) */ + /* values used by the software enhancement code (deskew, crop, etc) */ SANE_Status deskew_stat; int deskew_vals[2]; double deskew_slope; int crop_vals[4]; + /* imprinter params */ + struct imprint_params pre_imprint; + struct imprint_params post_imprint; + enum { + /*Black-on-White*/ + ADDON_BoW = 0, + /*White-on-Black*/ + ADDON_WoB, + /*Black-on-Image*/ + ADDON_BoI, + ADDON_DISABLED + } post_imprint_addon_mode; + + /* imprinter param constraints */ + SANE_Int pre_imprinter_h_offset_list[7]; + SANE_Int post_imprinter_h_offset_list[18]; + SANE_Range imprinter_v_offset_range; + SANE_String_Const imprint_font_size_list[3]; + SANE_Int imprinter_font_angle_list[5]; + SANE_String_Const imprint_addon_mode_list[5]; + /* this is defined in sane spec as a struct containing: SANE_Frame format; SANE_Bool last_frame; @@ -379,6 +447,8 @@ struct scanner int panel_counter; int sensor_adf_loaded; int sensor_card_loaded; + int roller_counter; + int total_counter; /* values which are used to track the frontend's access to sensors */ char panel_read[OPT_COUNTER - OPT_START + 1]; @@ -541,7 +611,9 @@ static SANE_Status sense_handler (int scsi_fd, u_char * result, void *arg); static SANE_Status init_inquire (struct scanner *s); static SANE_Status init_vpd (struct scanner *s); static SANE_Status init_model (struct scanner *s); +static SANE_Status init_imprinters (struct scanner *s); static SANE_Status init_panel (struct scanner *s); +static SANE_Status init_counters (struct scanner *s); static SANE_Status init_user (struct scanner *s); static SANE_Status init_options (struct scanner *s); @@ -589,6 +661,7 @@ static SANE_Status update_params (struct scanner *s, int calib); static SANE_Status update_i_params (struct scanner *s); static SANE_Status clean_params (struct scanner *s); +static SANE_Status read_counters(struct scanner *s); static SANE_Status read_sensors(struct scanner *s, SANE_Int option); static SANE_Status read_panel(struct scanner *s, SANE_Int option); static SANE_Status send_panel(struct scanner *s); @@ -632,6 +705,12 @@ static SANE_Status calibrate_fine_dest_hw(struct scanner *s); static SANE_Status write_AFE (struct scanner *s); static SANE_Status calibration_scan (struct scanner *s, int); +static SANE_Status send_imprint_positioning(struct scanner* s, int is_postimprint, int enabled); +static SANE_Status send_imprint_specstring(struct scanner* s, int is_postimprint); +static SANE_Status send_imprint_date_and_time(struct scanner* s); +static SANE_Status load_imprinting_settings(struct scanner *s); +static SANE_Status detect_imprinter(struct scanner *s, SANE_Int option); + static void hexdump (int level, char *comment, unsigned char *p, int l); static void default_globals (void); diff --git a/backend/canon_lide70-common.c b/backend/canon_lide70-common.c index 0882fec..4e58222 100644 --- a/backend/canon_lide70-common.c +++ b/backend/canon_lide70-common.c @@ -3249,7 +3249,7 @@ CANON_start_scan (CANON_Handle * chndl) chndl->fname = strdup ("/tmp/scan.XXXXXX"); fd = mkstemp (chndl->fname); - if (!fd) + if (fd == -1) { return SANE_STATUS_IO_ERROR; } diff --git a/backend/canon_lide70.c b/backend/canon_lide70.c index 4cc8999..2a3bd30 100644 --- a/backend/canon_lide70.c +++ b/backend/canon_lide70.c @@ -819,8 +819,8 @@ sane_control_option (SANE_Handle handle, SANE_Int option, SANE_Action action, "sane_control_option: get option %d (%s), value=%.1f %s\n", option, chndl->opt[option].name, SANE_UNFIX (*(SANE_Fixed *) value), - chndl->opt[option].unit == - SANE_UNIT_MM ? "mm" : SANE_UNIT_DPI ? "dpi" : ""); + chndl->opt[option].unit == SANE_UNIT_MM ? "mm" : + (chndl->opt[option].unit == SANE_UNIT_DPI ? "dpi" : "")); break; } case opt_non_blocking: @@ -863,7 +863,7 @@ sane_get_parameters (SANE_Handle handle, SANE_Parameters * params) Canon_Scanner *hndl = handle; /* Eliminate compiler warning */ CANON_Handle *chndl = &hndl->scan; - int rc = SANE_STATUS_GOOD; + SANE_Status rc = SANE_STATUS_GOOD; int w = SANE_UNFIX (chndl->val[opt_br_x].w - chndl->val[opt_tl_x].w) / MM_IN_INCH * chndl->val[opt_resolution].w; @@ -956,7 +956,7 @@ sane_set_io_mode (SANE_Handle handle, SANE_Bool non_blocking) SANE_Status sane_get_select_fd (SANE_Handle handle, SANE_Int * fd) { - handle = handle; /* silence gcc */ - fd = fd; /* silence gcc */ + (void) handle; /* silence gcc */ + (void) fd; /* silence gcc */ return SANE_STATUS_UNSUPPORTED; } diff --git a/backend/canon_pp-io.c b/backend/canon_pp-io.c index 0b92b11..9e6e006 100644 --- a/backend/canon_pp-io.c +++ b/backend/canon_pp-io.c @@ -178,8 +178,8 @@ int sanei_canon_pp_wake_scanner(struct parport *port, int mode) usleep(100000); } - } while ((i < max_cycles) && (!expect(port,"Scanner wakeup reply 2", - 0x03, 0x1f, 100000) == 0)); + } while ((i < max_cycles) && expect(port, "Scanner wakeup reply 2", + 0x03, 0x1f, 100000)); /* Block just after chessboarding Reply 1 (S3 and S4 on, S5 and S7 off) */ diff --git a/backend/canon_pp.c b/backend/canon_pp.c index b933102..79c6c63 100644 --- a/backend/canon_pp.c +++ b/backend/canon_pp.c @@ -1787,7 +1787,9 @@ static int init_cal(char *file) ************************************************************************/ static SANE_Status fix_weights_file(CANONP_Scanner *cs) { - char *tmp, *myhome, buf[PATH_MAX]; + static const char default_weights_file_prefix[] = + "~/.sane/canon_pp-calibration-"; + char *tmp, *myhome; int i; struct stat *f_stat; @@ -1804,31 +1806,32 @@ static SANE_Status fix_weights_file(CANONP_Scanner *cs) if (cs->weights_file == NULL) { - /* Will be of form canon_pp-calibration-parport0 or -0x378 */ - sprintf(buf, "~/.sane/canon_pp-calibration-%s", + /* Form is ~/.sane/canon_pp-calibration-parport0 or -0x378 */ + i = strlen(default_weights_file_prefix) + + strlen(cs->params.port->name); + if ((cs->weights_file = malloc(i + 1)) == NULL) + return SANE_STATUS_NO_MEM; + sprintf(cs->weights_file, "%s%s", default_weights_file_prefix, cs->params.port->name); - cs->weights_file = strdup(buf); } /* Get the user's home dir if they used ~ */ if (cs->weights_file[0] == '~') { - if ((tmp = malloc(PATH_MAX)) == NULL) - return SANE_STATUS_NO_MEM; if ((myhome = getenv("HOME")) == NULL) { DBG(0,"fix_weights_file: FATAL: ~ used, but $HOME not" " set!\n"); - free(tmp); - tmp = NULL; return SANE_STATUS_INVAL; } - strncpy(tmp, myhome, PATH_MAX); - strncpy(tmp+strlen(tmp), (cs->weights_file)+1, - PATH_MAX-strlen(tmp)); + i = strlen(myhome) + strlen(&cs->weights_file[1]); + if ((tmp = malloc(i + 1)) == NULL) + return SANE_STATUS_NO_MEM; + sprintf(tmp, "%s%s", myhome, &cs->weights_file[1]); free(cs->weights_file); cs->weights_file = tmp; + tmp = NULL; } if ((f_stat = malloc(sizeof(*f_stat))) == NULL) diff --git a/backend/cardscan.c b/backend/cardscan.c index 2adad7c..8984f7a 100644 --- a/backend/cardscan.c +++ b/backend/cardscan.c @@ -271,7 +271,7 @@ static struct scanner *scanner_devList = NULL; SANE_Status sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize) { - authorize = authorize; /* get rid of compiler warning */ + (void) authorize; /* get rid of compiler warning */ DBG_INIT (); DBG (10, "sane_init: start\n"); @@ -323,7 +323,7 @@ sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only) int num_devices=0; int i=0; - local_only = local_only; /* get rid of compiler warning */ + (void) local_only; /* get rid of compiler warning */ DBG (10, "sane_get_devices: start\n"); diff --git a/backend/coolscan.c b/backend/coolscan.c index e51b499..2aaef4e 100644 --- a/backend/coolscan.c +++ b/backend/coolscan.c @@ -1853,8 +1853,8 @@ hexdump (int level, char *comment, unsigned char *p, int l) static SANE_Status sense_handler (int scsi_fd, unsigned char * result, void *arg) { - scsi_fd = scsi_fd; - arg = arg; + (void) scsi_fd; + (void) arg; if (result[0] != 0x70) { @@ -2155,7 +2155,7 @@ attach_one (const char *devName) static void sigterm_handler (int signal) { - signal = signal; + (void) signal; sanei_scsi_req_flush_all (); /* flush SCSI queue */ _exit (SANE_STATUS_GOOD); } @@ -2360,7 +2360,7 @@ static int RGBIfix16(Coolscan_t * scanner, unsigned short *opr,*opg,*opb,*opi; int x; - scanner = scanner; lutr = lutr; lutg = lutg; lutb = lutb; luti = luti; + (void) scanner; (void) lutr; (void) lutg; (void) lutb; (void) luti; for(x=0;x<size;x++) { @@ -2459,7 +2459,7 @@ static int RGBIfix1(unsigned char* rgbimat,unsigned char* orgbimat, int ii; int x; - lutg = lutg; lutb = lutb; + (void) lutg; (void) lutb; /* calculate regression between r and ir */ cc.sum=0; @@ -3237,7 +3237,7 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize) size_t len; FILE *fp; - authorize = authorize; + (void) authorize; DBG_INIT (); sanei_thread_init (); @@ -3297,7 +3297,7 @@ sane_get_devices (const SANE_Device *** device_list, Coolscan_t *dev; int i; - local_only = local_only; + (void) local_only; DBG (10, "sane_get_devices\n"); diff --git a/backend/coolscan2.c b/backend/coolscan2.c index f0d897f..641784a 100644 --- a/backend/coolscan2.c +++ b/backend/coolscan2.c @@ -344,7 +344,7 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize) DBG (10, "sane_init() called.\n"); DBG (1, "coolscan2 backend, version %i.%i.%i initializing.\n", CS2_VERSION_MAJOR, CS2_VERSION_MINOR, CS2_REVISION); - authorize = authorize; /* to shut up compiler */ + (void) authorize; /* to shut up compiler */ if (version_code) *version_code = @@ -378,7 +378,7 @@ sane_get_devices (const SANE_Device *** list, SANE_Bool local_only) char line[PATH_MAX], *p; FILE *config; - local_only = local_only; /* to shut up compiler */ + (void) local_only; /* to shut up compiler */ DBG (10, "sane_get_devices() called.\n"); @@ -468,7 +468,10 @@ sane_open (SANE_String_Const name, SANE_Handle * h) for (i_option = 0; i_option < CS2_N_OPTIONS; i_option++) { o.name = o.title = o.desc = NULL; - o.type = o.unit = o.cap = o.constraint_type = o.size = 0; + o.type = SANE_TYPE_BOOL; + o.unit = SANE_UNIT_NONE; + o.size = o.cap = 0; + o.constraint_type = SANE_CONSTRAINT_NONE; o.constraint.range = NULL; /* only one union member needs to be NULLed */ switch (i_option) { @@ -1738,8 +1741,8 @@ sane_get_select_fd (SANE_Handle h, SANE_Int * fd) DBG (10, "sane_get_select_fd() called.\n"); - fd = fd; /* to shut up compiler */ - s = s; /* to shut up compiler */ + (void) fd; /* to shut up compiler */ + (void) s; /* to shut up compiler */ return SANE_STATUS_UNSUPPORTED; } @@ -2003,7 +2006,7 @@ cs2_scsi_sense_handler (int fd, u_char * sense_buffer, void *arg) { cs2_t *s = (cs2_t *) arg; - fd = fd; /* to shut up compiler */ + (void) fd; /* to shut up compiler */ /* sort this out ! XXXXXXXXX */ diff --git a/backend/coolscan3.c b/backend/coolscan3.c index f279c9c..77a1a5c 100644 --- a/backend/coolscan3.c +++ b/backend/coolscan3.c @@ -314,7 +314,7 @@ sane_init(SANE_Int * version_code, SANE_Auth_Callback authorize) DBG(1, "coolscan3 backend, version %i.%i.%i initializing.\n", CS3_VERSION_MAJOR, CS3_VERSION_MINOR, CS3_REVISION); - authorize = authorize; /* to shut up compiler */ + (void) authorize; /* to shut up compiler */ if (version_code) *version_code = SANE_VERSION_CODE(SANE_CURRENT_MAJOR, SANE_CURRENT_MINOR, 0); @@ -346,7 +346,7 @@ sane_get_devices(const SANE_Device *** list, SANE_Bool local_only) char line[PATH_MAX], *p; FILE *config; - local_only = local_only; /* to shut up compiler */ + (void) local_only; /* to shut up compiler */ DBG(10, "%s\n", __func__); @@ -424,7 +424,10 @@ sane_open(SANE_String_Const name, SANE_Handle * h) for (i_option = 0; i_option < CS3_N_OPTIONS; i_option++) { o.name = o.title = o.desc = NULL; - o.type = o.unit = o.cap = o.constraint_type = o.size = 0; + o.type = SANE_TYPE_BOOL; + o.unit = SANE_UNIT_NONE; + o.size = o.cap = 0; + o.constraint_type = SANE_CONSTRAINT_NONE; o.constraint.range = NULL; /* only one union member needs to be NULLed */ switch (i_option) { case CS3_OPTION_NUM: @@ -1746,8 +1749,8 @@ sane_get_select_fd(SANE_Handle h, SANE_Int * fd) DBG(10, "%s\n", __func__); - fd = fd; /* to shut up compiler */ - s = s; /* to shut up compiler */ + (void) fd; /* to shut up compiler */ + (void) s; /* to shut up compiler */ return SANE_STATUS_UNSUPPORTED; } @@ -2026,7 +2029,7 @@ cs3_scsi_sense_handler(int fd, u_char * sense_buffer, void *arg) { cs3_t *s = (cs3_t *) arg; - fd = fd; /* to shut up compiler */ + (void) fd; /* to shut up compiler */ /* sort this out ! XXX */ diff --git a/backend/dc25.c b/backend/dc25.c index 59597a5..73eb53d 100644 --- a/backend/dc25.c +++ b/backend/dc25.c @@ -134,8 +134,7 @@ static char tty_name[PATH_MAX]; #define DEF_TTY_NAME "/dev/ttyS0" static speed_t tty_baud = DEFAULT_TTY_BAUD; -static char *tmpname; -static char tmpnamebuf[] = "/tmp/dc25XXXXXX"; +#define TMPFILE_PATTERN "/tmp/dc25XXXXXX"; static Dc20Info *dc20_info; static Dc20Info CameraInfo; @@ -925,7 +924,6 @@ adjust_color_and_saturation (short red[], short green[], short blue[]) int line, column; int r_min = SMAX, g_min = SMAX, b_min = SMAX; int r_max = 0, g_max = 0, b_max = 0; - int r_sum = 0, g_sum = 0, b_sum = 0; float sqr_saturation = sqrt (saturation); for (line = TOP_MARGIN; line < HEIGHT - BOTTOM_MARGIN; line++) { @@ -1008,9 +1006,6 @@ adjust_color_and_saturation (short red[], short green[], short blue[]) g_max = g; if (b_max < b) b_max = b; - r_sum += r; - g_sum += g; - b_sum += b; BIDIM_ARRAY (red, column, line, columns) = r; BIDIM_ARRAY (green, column, line, columns) = g; BIDIM_ARRAY (blue, column, line, columns) = b; @@ -1153,7 +1148,6 @@ output_rgb (const short red[], { int r_min = 255, g_min = 255, b_min = 255; int r_max = 0, g_max = 0, b_max = 0; - int r_sum = 0, g_sum = 0, b_sum = 0; int column, line; unsigned char *gamma_table = make_gamma_table (high_i - low_i); @@ -1202,19 +1196,9 @@ output_rgb (const short red[], g_max = g; if (b_max < b) b_max = b; - r_sum += r; - g_sum += g; - b_sum += b; } } free (gamma_table); -/* - { - fprintf (stderr, "%s: output_rgb: r: min = %d, max = %d, ave = %d\n", __progname, r_min, r_max, r_sum / NET_PIXELS); - fprintf (stderr, "%s: output_rgb: g: min = %d, max = %d, ave = %d\n", __progname, g_min, g_max, g_sum / NET_PIXELS); - fprintf (stderr, "%s: output_rgb: b: min = %d, max = %d, ave = %d\n", __progname, b_min, b_max, b_sum / NET_PIXELS); - } -*/ return 0; } @@ -2022,16 +2006,6 @@ sane_open (SANE_String_Const devicename, SANE_Handle * handle) DBG (1, "No device info\n"); } - if (tmpname == NULL) - { - tmpname = tmpnamebuf; - if (!mkstemp (tmpname)) - { - DBG (1, "Unable to make temp file %s\n", tmpname); - return SANE_STATUS_INVAL; - } - } - DBG (3, "sane_open: pictures taken=%d\n", dc20_info->pic_taken); return SANE_STATUS_GOOD; @@ -2445,14 +2419,15 @@ sane_start (SANE_Handle handle) * port overruns on a 90MHz pentium until I used hdparm * to set the "-u1" flag on the system drives. */ - int fd; + char tmpnamebuf[] = TMPFILE_PATTERN; - fd = open (tmpname, O_CREAT | O_EXCL | O_WRONLY, 0600); + int fd = mkstemp (tmpnamebuf); if (fd == -1) - { - DBG (0, "Unable to open tmp file\n"); - return SANE_STATUS_INVAL; - } + { + DBG (0, "Unable to make temp file %s\n", tmpnamebuf); + return SANE_STATUS_INVAL; + } + f = fdopen (fd, "wb"); if (f == NULL) { @@ -2524,12 +2499,12 @@ sane_start (SANE_Handle handle) else { fclose (f); - if (convert_pic (tmpname, SAVE_ADJASPECT | SAVE_24BITS) == -1) + if (convert_pic (tmpnamebuf, SAVE_ADJASPECT | SAVE_24BITS) == -1) { DBG (3, "sane_open: unable to convert\n"); return SANE_STATUS_INVAL; } - unlink (tmpname); + unlink (tmpnamebuf); outbytes = 0; } } diff --git a/backend/dell1600n_net.c b/backend/dell1600n_net.c index 41be589..9f2d48d 100644 --- a/backend/dell1600n_net.c +++ b/backend/dell1600n_net.c @@ -946,7 +946,7 @@ HexDump (int debugLevel, const unsigned char *buf, size_t bufSize) { if (!(i % 16)) - sprintf (lineBuf, "%p: ", (buf + i)); + sprintf (lineBuf, "%p: ", (void *) &buf[i]); sprintf (itemBuf, "%02x ", (const unsigned int) buf[i]); @@ -1199,7 +1199,7 @@ ProcessFindResponse (unsigned char *pData, size_t size) DBG (10, "ProcessFindResponse: processing %lu bytes, pData=%p\n", - (unsigned long)size, pData); + (unsigned long) size, (void *) pData); /* check we have a complete packet */ if (!MessageIsComplete (pData, size)) @@ -1355,7 +1355,7 @@ ProcessUdpResponse (unsigned char *pData, size_t size, HexDump (15, pData, size); DBG (10, "ProcessUdpResponse: processing %lu bytes, pData=%p\n", - (unsigned long)size, pData); + (unsigned long) size, (void *) pData); /* check we have a complete packet */ if (!MessageIsComplete (pData, size)) @@ -1486,7 +1486,7 @@ ProcessTcpResponse (struct ScannerState *pState, struct ComBuf *pTcpBuf) int bProcessImage = 0; DBG (10, "ProcessTcpResponse: processing %lu bytes, pData=%p\n", - (unsigned long)pTcpBuf->m_used, pData); + (unsigned long) pTcpBuf->m_used, (void *) pData); HexDump (15, pData, pTcpBuf->m_used); /* if message not complete then wait for more to arrive */ @@ -1799,7 +1799,7 @@ ProcessPageData (struct ScannerState *pState) struct PageInfo pageInfo; JSAMPLE *pJpegLine = NULL; - uint32 *pTiffRgba = NULL; + uint32_t *pTiffRgba = NULL; unsigned char *pOut; char tiffErrBuf[1024]; diff --git a/backend/dll.c b/backend/dll.c index a3233e8..bf34c4f 100644 --- a/backend/dll.c +++ b/backend/dll.c @@ -1068,7 +1068,7 @@ sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only) char *full_name; int i, num_devs; size_t len; -#define ASSERT_SPACE(n) \ +#define ASSERT_SPACE(n) do \ { \ if (devlist_len + (n) > devlist_size) \ { \ @@ -1080,7 +1080,7 @@ sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only) if (!devlist) \ return SANE_STATUS_NO_MEM; \ } \ - } + } while (0) DBG (3, "sane_get_devices\n"); @@ -1365,7 +1365,7 @@ sane_read (SANE_Handle handle, SANE_Byte * data, SANE_Int max_length, struct meta_scanner *s = handle; DBG (3, "sane_read(handle=%p,data=%p,maxlen=%d,lenp=%p)\n", - handle, data, max_length, (void *) length); + handle, (void *) data, max_length, (void *) length); return (*(op_read_t)s->be->op[OP_READ]) (s->handle, data, max_length, length); } diff --git a/backend/dmc.c b/backend/dmc.c index b1a3b5a..410e48a 100644 --- a/backend/dmc.c +++ b/backend/dmc.c @@ -812,7 +812,7 @@ sane_init(SANE_Int *version_code, SANE_Auth_Callback authorize) size_t len; FILE *fp; - authorize = authorize; + (void) authorize; DBG_INIT(); if (version_code) { @@ -891,7 +891,7 @@ sane_get_devices(SANE_Device const ***device_list, SANE_Bool local_only) DMC_Device *dev; int i = 0; - local_only = local_only; + (void) local_only; if (devlist) free(devlist); devlist = malloc((NumDevices+1) * sizeof(devlist[0])); @@ -1392,8 +1392,8 @@ sane_cancel (SANE_Handle handle) SANE_Status sane_set_io_mode (SANE_Handle handle, SANE_Bool non_blocking) { - handle = handle; - non_blocking = non_blocking; + (void) handle; + (void) non_blocking; return SANE_STATUS_UNSUPPORTED; } @@ -1401,8 +1401,8 @@ sane_set_io_mode (SANE_Handle handle, SANE_Bool non_blocking) SANE_Status sane_get_select_fd (SANE_Handle handle, SANE_Int *fd) { - handle = handle; - fd = fd; + (void) handle; + (void) fd; return SANE_STATUS_UNSUPPORTED; } diff --git a/backend/epjitsu.c b/backend/epjitsu.c index 6fda662..7430108 100644 --- a/backend/epjitsu.c +++ b/backend/epjitsu.c @@ -3,7 +3,7 @@ This file implements a SANE backend for the Fujitsu fi-60F, the ScanSnap S300/S1300, and (hopefully) other Epson-based scanners. - Copyright 2007-2015 by m. allan noah <kitno455 at gmail dot com> + Copyright 2007-2022 by m. allan noah <kitno455 at gmail dot com> Copyright 2009 by Richard Goedeken <richard at fascinationsoftware dot com> Development funded by Microdea, Inc., TrueCheck, Inc. and Archivista, GmbH @@ -155,6 +155,10 @@ v31 2017-04-09, MAN - hardware gray support for fi-60F/65F (disabled pending calibration) - merge fi-60F/65F settings + v32 2022-11-15, MAN + - fix hanging scan when using source = ADF Back (fixes #601) + v33 2022-11-17, MAN + - S1300i: fix color plane offset at 225 and 330 dpi (fixes #538) SANE FLOW DIAGRAM @@ -203,8 +207,14 @@ #include "epjitsu-cmd.h" #define DEBUG 1 -#define BUILD 31 +#define BUILD 33 +#ifndef MIN + #define MIN(a,b) ((a) < (b) ? (a) : (b)) +#endif +#ifndef MAX + #define MAX(a,b) ((a) > (b) ? (a) : (b)) +#endif #ifndef MAX3 #define MAX3(a,b,c) ((a) > (b) ? ((a) > (c) ? a : c) : ((b) > (c) ? b : c)) #endif @@ -265,7 +275,7 @@ static struct scanner *scanner_devList = NULL; SANE_Status sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize) { - authorize = authorize; /* get rid of compiler warning */ + (void) authorize; /* get rid of compiler warning */ DBG_INIT (); DBG (10, "sane_init: start\n"); @@ -317,7 +327,7 @@ sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only) int num_devices=0; int i=0; - local_only = local_only; /* get rid of compiler warning */ + (void) local_only; /* get rid of compiler warning */ DBG (10, "sane_get_devices: start\n"); @@ -1137,7 +1147,7 @@ sane_get_option_descriptor (SANE_Handle handle, SANE_Int option) /* values stored in 1200 dpi units */ /* must be converted to MM for sane */ s->tl_x_range.min = SCANNER_UNIT_TO_FIXED_MM(0); - s->tl_x_range.max = SCANNER_UNIT_TO_FIXED_MM(get_page_width(s)-s->min_x); + s->tl_x_range.max = SCANNER_UNIT_TO_FIXED_MM(MAX(0, get_page_width(s)-s->min_x)); s->tl_x_range.quant = MM_PER_UNIT_FIX; opt->name = SANE_NAME_SCAN_TL_X; @@ -1156,7 +1166,7 @@ sane_get_option_descriptor (SANE_Handle handle, SANE_Int option) /* values stored in 1200 dpi units */ /* must be converted to MM for sane */ s->tl_y_range.min = SCANNER_UNIT_TO_FIXED_MM(0); - s->tl_y_range.max = SCANNER_UNIT_TO_FIXED_MM(get_page_height(s)-s->min_y); + s->tl_y_range.max = SCANNER_UNIT_TO_FIXED_MM(MAX(0, get_page_height(s)-s->min_y)); s->tl_y_range.quant = MM_PER_UNIT_FIX; opt->name = SANE_NAME_SCAN_TL_Y; @@ -1174,7 +1184,7 @@ sane_get_option_descriptor (SANE_Handle handle, SANE_Int option) /* values stored in 1200 dpi units */ /* must be converted to MM for sane */ s->br_x_range.min = SCANNER_UNIT_TO_FIXED_MM(s->min_x); - s->br_x_range.max = SCANNER_UNIT_TO_FIXED_MM(get_page_width(s)); + s->br_x_range.max = SCANNER_UNIT_TO_FIXED_MM(MAX(s->min_x, get_page_width(s))); s->br_x_range.quant = MM_PER_UNIT_FIX; opt->name = SANE_NAME_SCAN_BR_X; @@ -1193,7 +1203,7 @@ sane_get_option_descriptor (SANE_Handle handle, SANE_Int option) /* values stored in 1200 dpi units */ /* must be converted to MM for sane */ s->br_y_range.min = SCANNER_UNIT_TO_FIXED_MM(s->min_y); - s->br_y_range.max = SCANNER_UNIT_TO_FIXED_MM(get_page_height(s)); + s->br_y_range.max = SCANNER_UNIT_TO_FIXED_MM(MAX(s->min_y, get_page_height(s))); s->br_y_range.quant = MM_PER_UNIT_FIX; opt->name = SANE_NAME_SCAN_BR_Y; @@ -2042,14 +2052,12 @@ change_params(struct scanner *s) /* height */ if (s->tl_y > s->max_y - s->min_y) s->tl_y = s->max_y - s->min_y - s->adf_height_padding; - if (s->tl_y + s->page_height > s->max_y - s->adf_height_padding) - s->page_height = s->max_y - s->adf_height_padding - s->tl_y; - if (s->page_height < s->min_y && s->page_height > 0) - s->page_height = s->min_y; + s->page_height = MIN(s->page_height, s->max_y - s->adf_height_padding - s->tl_y); + if (s->page_height > 0) + s->page_height = MAX(s->page_height, s->min_y); if (s->tl_y + s->page_height > s->max_y) s->tl_y = s->max_y - s->adf_height_padding - s->page_height; - if (s->tl_y < 0) - s->tl_y = 0; + s->tl_y = MAX(s->tl_y, 0); if (s->page_height > 0) { s->br_y = s->tl_y + s->page_height; @@ -2059,10 +2067,9 @@ change_params(struct scanner *s) } /*width*/ - if (s->page_width > s->max_x) - s->page_width = s->max_x; - else if (s->page_width < s->min_x) - s->page_width = s->min_x; + s->page_width = MIN(s->page_width, s->max_x); + s->page_width = MAX(s->page_width, s->min_x); + s->tl_x = (s->max_x - s->page_width)/2; s->br_x = (s->max_x + s->page_width)/2; @@ -2177,7 +2184,7 @@ change_params(struct scanner *s) /* adf with specified paper size */ s->front.height = SCANNER_UNIT_TO_PIX(s->page_height, s->front.y_res); } - s->front.width_pix = s->block_img.width_pix; + s->front.width_pix = SCANNER_UNIT_TO_PIX(s->page_width, s->resolution * img_heads); s->front.x_start_offset = (s->block_xfr.image->width_pix - s->front.width_pix)/2; switch (s->mode) { case MODE_COLOR: @@ -2310,12 +2317,8 @@ load_lut (unsigned char * lut, for(i=0;i<=max_in_val;i++){ j = rise*i + shift; - if(j<out_min){ - j=out_min; - } - else if(j>out_max){ - j=out_max; - } + j = MAX(j, out_min); + j = MIN(j, out_max); *lut_p=j; lut_p++; @@ -2654,7 +2657,7 @@ coarsecal_send_cal(struct scanner *s, unsigned char *pay) unsigned char stat[1]; size_t cmdLen,statLen,payLen; - DBG (5, "coarsecal_send_cal: start\n"); + DBG (10, "coarsecal_send_cal: start\n"); /* send coarse cal (c6) */ cmd[0] = 0x1b; cmd[1] = 0xc6; @@ -2697,7 +2700,7 @@ coarsecal_send_cal(struct scanner *s, unsigned char *pay) return SANE_STATUS_IO_ERROR; } - DBG (5, "coarsecal_send_cal: finish\n"); + DBG (10, "coarsecal_send_cal: finish\n"); return ret; } @@ -2709,7 +2712,7 @@ coarsecal_get_line(struct scanner *s, struct image *img) unsigned char stat[1]; size_t cmdLen,statLen; - DBG (5, "coarsecal_get_line: start\n"); + DBG (10, "coarsecal_get_line: start\n"); /* send scan d2 command */ cmd[0] = 0x1b; @@ -2746,7 +2749,7 @@ coarsecal_get_line(struct scanner *s, struct image *img) /* convert the raw data into normal packed pixel data */ descramble_raw(s, &s->cal_image); - DBG (5, "coarsecal_get_line: finish\n"); + DBG (10, "coarsecal_get_line: finish\n"); return ret; } @@ -2758,7 +2761,7 @@ coarsecal_dark(struct scanner *s, unsigned char *pay) int try_count, cal_good[2], x, j; int param[2], zcount[2], high_param[2], low_param[2], avg[2], maxval[2]; - DBG (5, "coarsecal_dark: start\n"); + DBG (10, "coarsecal_dark: start\n"); /* dark cal, lamp off */ ret = lamp(s,0); @@ -2844,7 +2847,7 @@ coarsecal_dark(struct scanner *s, unsigned char *pay) } /* continue looping for up to 8 tries */ - DBG (5, "coarsecal_dark: finish\n"); + DBG (10, "coarsecal_dark: finish\n"); return ret; } @@ -2857,7 +2860,7 @@ coarsecal_light(struct scanner *s, unsigned char *pay) int param[2], zcount[2], high_param[2], low_param[2], avg[2]; int rgb_avg[2][3], rgb_hicount[2][3]; - DBG (5, "coarsecal_light: start\n"); + DBG (10, "coarsecal_light: start\n"); /* light cal, lamp on */ ret = lamp(s,1); @@ -2961,7 +2964,7 @@ coarsecal_light(struct scanner *s, unsigned char *pay) } } - DBG (5, "coarsecal_light: finish\n"); + DBG (10, "coarsecal_light: finish\n"); return ret; } @@ -3023,6 +3026,8 @@ finecal_send_cal(struct scanner *s) unsigned char *p_out, *p_in = s->sendcal.buffer; int planes; + DBG (10, "finecal_send_cal: start\n"); + if(s->model == MODEL_FI60F || s->model == MODEL_FI65F) planes = 3; if(s->model == MODEL_S300 || s->model == MODEL_S1300i) @@ -3165,6 +3170,7 @@ finecal_send_cal(struct scanner *s) return SANE_STATUS_IO_ERROR; } + DBG (10, "finecal_send_cal: finish\n"); return ret; } @@ -3182,6 +3188,8 @@ finecal_get_line(struct scanner *s, struct image *img) int round_offset = img->height / 2; int i, j, k; + DBG (10, "finecal_get_line: start\n"); + /* ask for 16 lines */ ret = set_window(s, WINDOW_FINECAL); if(ret){ @@ -3238,6 +3246,8 @@ finecal_get_line(struct scanner *s, struct image *img) avgpix[j] = (total + round_offset) / img->height; } } + + DBG (10, "finecal_get_line: finish\n"); return ret; } @@ -3385,8 +3395,8 @@ finecal(struct scanner *s) else s->sendcal.buffer[idx * 2 + 1] = newgain; /* update statistics */ - if (pixvalue < min_value[i][k]) min_value[i][k] = pixvalue; - if (pixvalue > max_value[i][k]) max_value[i][k] = pixvalue; + min_value[i][k] = MIN(min_value[i][k], pixvalue); + max_value[i][k] = MAX(max_value[i][k], pixvalue); avg_value[i][k] += pixerror; variance[i][k] += (pixerror * pixerror); idx++; @@ -3658,13 +3668,8 @@ send_lut (struct scanner *s) for(i=0;i<width;i++){ j=slope*i + offset + b; - if(j<0){ - j=0; - } - - if(j>(height-1)){ - j=height-1; - } + j = MAX(j, 0); + j = MIN(j, height-1); if (s->model == MODEL_S1100){ /*only one table, be order*/ @@ -4078,9 +4083,7 @@ sane_read (SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, SANE_Int * len } *len = page->bytes_scanned - page->bytes_read; - if(*len > max_len){ - *len = max_len; - } + *len = MIN(*len, max_len); if(*len){ DBG (10, "sane_read: copy rx:%d tx:%d tot:%d len:%d\n", @@ -4088,12 +4091,12 @@ sane_read (SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, SANE_Int * len memcpy(buf, page->image->buffer + page->bytes_read, *len); page->bytes_read += *len; + } - /* sent it all, return eof on next read */ - if(page->bytes_read == page->bytes_scanned && s->fullscan.done){ - DBG (10, "sane_read: side done\n"); - page->done = 1; - } + /* sent it all, return eof on next read */ + if(page->bytes_read == page->bytes_scanned && s->fullscan.done){ + DBG (10, "sane_read: side done\n"); + page->done = 1; } DBG (10, "sane_read: finish si:%d len:%d max:%d\n",s->side,*len,max_len); @@ -4161,6 +4164,7 @@ descramble_raw(struct scanner *s, struct transfer * tp) for (j = 0; j < height; j++){ /* row (y)*/ int curr_col = 0; int r=0, g=0, b=0, ppc=0; + int g_offset=0, b_offset=0; for (k = 0; k <= tp->plane_width; k++){ /* column (x) */ int this_col = k*tp->image->x_res/tp->x_res; @@ -4185,14 +4189,20 @@ descramble_raw(struct scanner *s, struct transfer * tp) break; } + /* if we're using an S1300i with scan resolution 225 or 300, on AC power, the color planes are shifted */ + if(s->model == MODEL_S1300i && !s->usb_power && (tp->x_res == 225 || tp->x_res == 300) && tp != &s->cal_image && k + 2 <= tp->plane_width){ + g_offset = 3; + b_offset = 6; + } + /*red is first*/ r += tp->raw_data[j*tp->line_stride + k*3 + i]; /*green is second*/ - g += tp->raw_data[j*tp->line_stride + tp->plane_stride + k*3 + i]; + g += tp->raw_data[j*tp->line_stride + tp->plane_stride + k*3 + i + g_offset]; /*blue is third*/ - b += tp->raw_data[j*tp->line_stride + 2*tp->plane_stride + k*3 + i]; + b += tp->raw_data[j*tp->line_stride + 2*tp->plane_stride + k*3 + i + b_offset]; ppc++; } @@ -4341,8 +4351,8 @@ read_from_scanner(struct scanner *s, struct transfer * tp) size_t bufLen; /* determine amount to ask for, S1300i wants big requests */ - if(bytes > remainBlock && s->model != MODEL_S1300i){ - bytes = remainBlock; + if(s->model != MODEL_S1300i){ + bytes = MIN(bytes, remainBlock); } if (tp->image == NULL) @@ -4932,8 +4942,7 @@ maxStringSize (const SANE_String_Const strings[]) for (i = 0; strings[i]; ++i) { size = strlen (strings[i]) + 1; - if (size > max_size) - max_size = size; + max_size = MAX(max_size, size); } return max_size; diff --git a/backend/epson.c b/backend/epson.c index d0f5e54..d2aba4c 100644 --- a/backend/epson.c +++ b/backend/epson.c @@ -2653,7 +2653,7 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize) size_t len; FILE *fp; - authorize = authorize; /* get rid of compiler warning */ + (void) authorize; /* get rid of compiler warning */ /* sanei_authorization(devicename, STRINGIFY(BACKEND_NAME), auth_callback); */ @@ -2753,7 +2753,7 @@ sane_get_devices (const SANE_Device * **device_list, SANE_Bool local_only) DBG (5, "sane_get_devices()\n"); - local_only = local_only; /* just to get rid of the compiler warning */ + (void) local_only; /* just to get rid of the compiler warning */ if (devlist) { @@ -6383,8 +6383,8 @@ SANE_Status sane_set_io_mode (SANE_Handle handle, SANE_Bool non_blocking) { /* get rid of compiler warning */ - handle = handle; - non_blocking = non_blocking; + (void) handle; + (void) non_blocking; return SANE_STATUS_UNSUPPORTED; } @@ -6399,8 +6399,8 @@ SANE_Status sane_get_select_fd (SANE_Handle handle, SANE_Int * fd) { /* get rid of compiler warnings */ - handle = handle; - fd = fd; + (void) handle; + (void) fd; return SANE_STATUS_UNSUPPORTED; } diff --git a/backend/epson2.c b/backend/epson2.c index 5bb75d4..cfc2aca 100644 --- a/backend/epson2.c +++ b/backend/epson2.c @@ -2297,21 +2297,6 @@ sane_start(SANE_Handle handle) return status; } -static inline int -get_color(int status) -{ - switch ((status >> 2) & 0x03) { - case 1: - return 1; - case 2: - return 0; - case 3: - return 2; - default: - return 0; /* required to make the compiler happy */ - } -} - /* this moves data from our buffers to SANE */ SANE_Status @@ -2348,7 +2333,7 @@ sane_read(SANE_Handle handle, SANE_Byte *data, SANE_Int max_length, /* XXX if FS G and STATUS_IOERR, use e2_check_extended_status */ DBG(18, "moving data %p %p, %d (%d lines)\n", - s->ptr, s->end, + (void *) s->ptr, (void *) s->end, max_length, max_length / s->params.bytes_per_line); e2_copy_image_data(s, data, max_length, length); diff --git a/backend/epson2_net.c b/backend/epson2_net.c index 7f804ee..de9aba3 100644 --- a/backend/epson2_net.c +++ b/backend/epson2_net.c @@ -70,7 +70,7 @@ sanei_epson_net_read_buf(Epson_Scanner *s, unsigned char *buf, ssize_t wanted, ssize_t read = 0; DBG(23, "%s: reading up to %lu from buffer at %p, %lu available\n", - __func__, (u_long) wanted, s->netptr, (u_long) s->netlen); + __func__, (u_long) wanted, (void *) s->netptr, (u_long) s->netlen); if ((size_t) wanted > s->netlen) { *status = SANE_STATUS_IO_ERROR; @@ -84,7 +84,7 @@ sanei_epson_net_read_buf(Epson_Scanner *s, unsigned char *buf, ssize_t wanted, s->netlen -= read; if (s->netlen == 0) { - DBG(23, "%s: freeing %p\n", __func__, s->netbuf); + DBG(23, "%s: freeing %p\n", __func__, (void *) s->netbuf); free(s->netbuf); s->netbuf = s->netptr = NULL; s->netlen = 0; @@ -179,7 +179,7 @@ sanei_epson_net_write(Epson_Scanner *s, unsigned int cmd, const unsigned char *b if (reply_len) { if (s->netbuf) { DBG(23, "%s, freeing %p, %ld bytes unprocessed\n", - __func__, s->netbuf, (u_long) s->netlen); + __func__, (void *) s->netbuf, (u_long) s->netlen); free(s->netbuf); s->netbuf = s->netptr = NULL; s->netlen = 0; @@ -192,11 +192,11 @@ sanei_epson_net_write(Epson_Scanner *s, unsigned int cmd, const unsigned char *b } s->netlen = reply_len; DBG(24, "%s: allocated %lu bytes at %p\n", __func__, - (u_long) s->netlen, s->netbuf); + (u_long) s->netlen, (void *) s->netbuf); } DBG(24, "%s: cmd = %04x, buf = %p, buf_size = %lu, reply_len = %lu\n", - __func__, cmd, buf, (u_long) buf_size, (u_long) reply_len); + __func__, cmd, (void *) buf, (u_long) buf_size, (u_long) reply_len); memset(h1, 0x00, 12); memset(h2, 0x00, 8); diff --git a/backend/epson2_scsi.c b/backend/epson2_scsi.c index 8e95c6f..0eaf2c0 100644 --- a/backend/epson2_scsi.c +++ b/backend/epson2_scsi.c @@ -27,8 +27,8 @@ sanei_epson2_scsi_sense_handler(int scsi_fd, unsigned char *result, void *arg) { /* to get rid of warnings */ - scsi_fd = scsi_fd; - arg = arg; + (void) scsi_fd; + (void) arg; if (result[0] && result[0] != 0x70) { DBG(2, "%s: sense code = 0x%02x\n", diff --git a/backend/epson_scsi.c b/backend/epson_scsi.c index 698ec61..747ac4c 100644 --- a/backend/epson_scsi.c +++ b/backend/epson_scsi.c @@ -32,8 +32,8 @@ SANE_Status sanei_epson_scsi_sense_handler (int scsi_fd, u_char * result, void *arg) { /* to get rid of warnings */ - scsi_fd = scsi_fd; - arg = arg; + (void) scsi_fd; + (void) arg; if (result[0] && result[0] != 0x70) { diff --git a/backend/epsonds-cmd.c b/backend/epsonds-cmd.c index 6f0ec64..d1cba09 100644 --- a/backend/epsonds-cmd.c +++ b/backend/epsonds-cmd.c @@ -784,7 +784,7 @@ static SANE_Status stat_cb(void *userdata, char *token, int len) { char *value = token + 3; - userdata = userdata; + (void) userdata; if (DBG_LEVEL >= 11) { debug_token(DBG_LEVEL, __func__, token, len); @@ -816,7 +816,7 @@ static SANE_Status resa_cb(void *userdata, char *token, int len) { /* epsonds_scanner *s = (epsonds_scanner *)userdata; */ - userdata = userdata; + (void) userdata; if (DBG_LEVEL >= 11) { debug_token(DBG_LEVEL, __func__, token, len); @@ -838,7 +838,7 @@ static SANE_Status para_cb(void *userdata, char *token, int len) debug_token(DBG_LEVEL, __func__, token, len); } - userdata = userdata; + (void) userdata; if (strncmp("par", token, 3) == 0) { if (strncmp("FAIL", token + 3, 4) == 0) { diff --git a/backend/epsonds-net.c b/backend/epsonds-net.c index 4f4c1e2..87b44b4 100644 --- a/backend/epsonds-net.c +++ b/backend/epsonds-net.c @@ -79,7 +79,7 @@ epsonds_net_read_buf(epsonds_scanner *s, unsigned char *buf, ssize_t wanted, ssize_t read = 0; DBG(23, "%s: reading up to %lu from buffer at %p, %lu available\n", - __func__, (u_long) wanted, s->netptr, (u_long) s->netlen); + __func__, (u_long) wanted, (void *) s->netptr, (u_long) s->netlen); if ((size_t) wanted > s->netlen) { *status = SANE_STATUS_IO_ERROR; @@ -93,7 +93,7 @@ epsonds_net_read_buf(epsonds_scanner *s, unsigned char *buf, ssize_t wanted, s->netlen -= read; if (s->netlen == 0) { - DBG(23, "%s: freeing %p\n", __func__, s->netbuf); + DBG(23, "%s: freeing %p\n", __func__, (void *) s->netbuf); free(s->netbuf); s->netbuf = s->netptr = NULL; s->netlen = 0; @@ -195,7 +195,7 @@ epsonds_net_write(epsonds_scanner *s, unsigned int cmd, const unsigned char *buf if (reply_len) { if (s->netbuf) { DBG(23, "%s, freeing %p, %ld bytes unprocessed\n", - __func__, s->netbuf, (u_long) s->netlen); + __func__, (void *) s->netbuf, (u_long) s->netlen); free(s->netbuf); s->netbuf = s->netptr = NULL; s->netlen = 0; @@ -208,11 +208,11 @@ epsonds_net_write(epsonds_scanner *s, unsigned int cmd, const unsigned char *buf } s->netlen = reply_len; DBG(24, "%s: allocated %lu bytes at %p\n", __func__, - (u_long) s->netlen, s->netbuf); + (u_long) s->netlen, (void *) s->netbuf); } DBG(24, "%s: cmd = %04x, buf = %p, buf_size = %lu, reply_len = %lu\n", - __func__, cmd, buf, (u_long) buf_size, (u_long) reply_len); + __func__, cmd, (void *) buf, (u_long) buf_size, (u_long) reply_len); memset(h1, 0x00, 12); memset(h2, 0x00, 8); @@ -513,7 +513,7 @@ fail: if (simple_poll) avahi_simple_poll_free(simple_poll); - DBG(10, "epsonds_searchDevices fin\n"); + DBG(10, "epsonds_searchDevices fin\n"); return result; } diff --git a/backend/epsonds.c b/backend/epsonds.c index 0815535..72d01d8 100644 --- a/backend/epsonds.c +++ b/backend/epsonds.c @@ -1258,6 +1258,7 @@ const epsonds_profile_map epsonds_models_predefined[] = { {0x118A, "PID 118A","ET-2810 Series", 7}, {0x118A, "PID 118A","L3250 Series", 7}, {0x119B, "PID 119B","XP-2150 Series", 7}, + {0x11B1, "PID 11B1","XP-2200 Series", 7}, {0x00, "","", 0x00 } }; @@ -1629,10 +1630,7 @@ device_detect(const char *name, int type, SANE_Status *status) {//Convert to user friendly model name free(s->hw->model); - char* deviceName = (char*)malloc(strlen(map->deviceID) + 1); - memset(deviceName, 0, strlen(map->deviceID) + 1); - strncpy(deviceName, map->deviceID, strlen(map->deviceID)); - s->hw->model = deviceName; + s->hw->model = strdup(map->deviceID); s->hw->sane.model = s->hw->model; } {// set lutid diff --git a/backend/escl/escl.c b/backend/escl/escl.c index 5f02ec8..cbbdb60 100644 --- a/backend/escl/escl.c +++ b/backend/escl/escl.c @@ -61,6 +61,26 @@ static const SANE_Device **devlist = NULL; static ESCL_Device *list_devices_primary = NULL; static int num_devices = 0; +#ifdef CURL_SSLVERSION_MAX_DEFAULT +static int proto_tls[] = { + CURL_SSLVERSION_MAX_DEFAULT, + #ifdef CURL_SSLVERSION_MAX_TLSv1_3 + CURL_SSLVERSION_MAX_TLSv1_3, + #endif + #ifdef CURL_SSLVERSION_MAX_TLSv1_2 + CURL_SSLVERSION_MAX_TLSv1_2, + #endif + #ifdef CURL_SSLVERSION_MAX_TLSv1_1 + CURL_SSLVERSION_MAX_TLSv1_1, + #endif + #ifdef CURL_SSLVERSION_MAX_TLSv1_0 + CURL_SSLVERSION_MAX_TLSv1_0, + #endif + -1 +}; +#endif + + typedef struct Handled { struct Handled *next; ESCL_Device *device; @@ -99,6 +119,60 @@ escl_free_device(ESCL_Device *current) return NULL; } + +#ifdef CURL_SSLVERSION_MAX_DEFAULT +static int +escl_tls_protocol_supported(char *url, int proto) +{ + CURLcode res = CURLE_UNSUPPORTED_PROTOCOL; + CURL *curl = curl_easy_init(); + if(curl) { + curl_easy_setopt(curl, CURLOPT_URL, url); + + /* ask libcurl to use TLS version 1.0 or later */ + curl_easy_setopt(curl, CURLOPT_SSLVERSION, proto); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); + curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 3L); + /* Perform the request */ + res = curl_easy_perform(curl); + curl_easy_cleanup(curl); + } + return res; +} + +static int +escl_is_tls(char * url, char *type) +{ + int tls_version = 0; + if(!strcmp(type, "_uscans._tcp") || + !strcmp(type, "https")) + { + while(proto_tls[tls_version] != -1) + { + if (escl_tls_protocol_supported(url, proto_tls[tls_version]) == CURLE_OK) + { + DBG(10, "curl tls compatible (%d)\n", proto_tls[tls_version]); + break; + } + tls_version++; + } + if (proto_tls[tls_version] < 1) + return 0; + } + return proto_tls[tls_version]; +} +#else +static int +escl_is_tls(char * url, char *type) +{ + (void)url; + (void)type; + return 0; +} +#endif + void escl_free_handler(escl_sane_t *handler) { @@ -187,8 +261,13 @@ escl_device_add(int port_nb, { char tmp[PATH_MAX] = { 0 }; char *model = NULL; + char url_port[512] = { 0 }; + int tls_version = 0; ESCL_Device *current = NULL; DBG (10, "escl_device_add\n"); + snprintf(url_port, sizeof(url_port), "https://%s:%d", ip_address, port_nb); + tls_version = escl_is_tls(url_port, type); + for (current = list_devices_primary; current; current = current->next) { if ((strcmp(current->ip_address, ip_address) == 0) || (uuid && current->uuid && !strcmp(current->uuid, uuid))) @@ -206,6 +285,7 @@ escl_device_add(int port_nb, } current->port_nb = port_nb; current->https = SANE_TRUE; + current->tls = tls_version; } return (SANE_STATUS_GOOD); } @@ -226,6 +306,7 @@ escl_device_add(int port_nb, } else { current->https = SANE_FALSE; } + current->tls = tls_version; model = (char*)(tmp[0] != 0 ? tmp : model_name); current->model_name = strdup(model); current->ip_address = strdup(ip_address); @@ -470,7 +551,6 @@ attach_one_config(SANEI_Config __sane_unused__ *config, const char *line, } escl_device->model_name = opt_model ? opt_model : strdup("Unknown model"); escl_device->is = strdup("flatbed or ADF scanner"); - escl_device->type = strdup("In url"); escl_device->uuid = NULL; } @@ -515,6 +595,9 @@ attach_one_config(SANEI_Config __sane_unused__ *config, const char *line, } escl_device->is = strdup("flatbed or ADF scanner"); escl_device->uuid = NULL; + char url_port[512] = { 0 }; + snprintf(url_port, sizeof(url_port), "https://%s:%d", escl_device->ip_address, escl_device->port_nb); + escl_device->tls = escl_is_tls(url_port, escl_device->type); status = escl_check_and_add_device(escl_device); if (status == SANE_STATUS_GOOD) escl_device = NULL; @@ -956,7 +1039,7 @@ init_options(SANE_String_Const name_source, escl_sane_t *s) s->opt[OPT_BRIGHTNESS].constraint_type = SANE_CONSTRAINT_RANGE; if (s->scanner->brightness) { s->opt[OPT_BRIGHTNESS].constraint.range = &s->brightness_range; - s->val[OPT_BRIGHTNESS].w = s->scanner->brightness->normal; + s->val[OPT_BRIGHTNESS].w = s->scanner->brightness->value; s->brightness_range.quant=1; s->brightness_range.min=s->scanner->brightness->min; s->brightness_range.max=s->scanner->brightness->max; @@ -975,7 +1058,7 @@ init_options(SANE_String_Const name_source, escl_sane_t *s) s->opt[OPT_CONTRAST].constraint_type = SANE_CONSTRAINT_RANGE; if (s->scanner->contrast) { s->opt[OPT_CONTRAST].constraint.range = &s->contrast_range; - s->val[OPT_CONTRAST].w = s->scanner->contrast->normal; + s->val[OPT_CONTRAST].w = s->scanner->contrast->value; s->contrast_range.quant=1; s->contrast_range.min=s->scanner->contrast->min; s->contrast_range.max=s->scanner->contrast->max; @@ -994,7 +1077,7 @@ init_options(SANE_String_Const name_source, escl_sane_t *s) s->opt[OPT_SHARPEN].constraint_type = SANE_CONSTRAINT_RANGE; if (s->scanner->sharpen) { s->opt[OPT_SHARPEN].constraint.range = &s->sharpen_range; - s->val[OPT_SHARPEN].w = s->scanner->sharpen->normal; + s->val[OPT_SHARPEN].w = s->scanner->sharpen->value; s->sharpen_range.quant=1; s->sharpen_range.min=s->scanner->sharpen->min; s->sharpen_range.max=s->scanner->sharpen->max; @@ -1014,7 +1097,7 @@ init_options(SANE_String_Const name_source, escl_sane_t *s) s->opt[OPT_THRESHOLD].constraint_type = SANE_CONSTRAINT_RANGE; if (s->scanner->threshold) { s->opt[OPT_THRESHOLD].constraint.range = &s->thresold_range; - s->val[OPT_THRESHOLD].w = s->scanner->threshold->normal; + s->val[OPT_THRESHOLD].w = s->scanner->threshold->value; s->thresold_range.quant=1; s->thresold_range.min= s->scanner->threshold->min; s->thresold_range.max=s->scanner->threshold->max; @@ -1069,9 +1152,11 @@ escl_parse_name(SANE_String_Const name, ESCL_Device *device) if (strncmp(name, "https://", 8) == 0) { device->https = SANE_TRUE; + device->type = strdup("https"); host = name + 8; } else if (strncmp(name, "http://", 7) == 0) { device->https = SANE_FALSE; + device->type = strdup("http"); host = name + 7; } else { DBG(1, "Unknown URL scheme in %s", name); @@ -1811,6 +1896,8 @@ escl_curl_url(CURL *handle, const ESCL_Device *device, SANE_String_Const path) DBG( 1, "Ignoring safety certificates, use https\n"); curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0L); curl_easy_setopt(handle, CURLOPT_SSL_VERIFYHOST, 0L); + if (device->tls > 0) + curl_easy_setopt(handle, CURLOPT_SSLVERSION, device->tls); } if (device->unix_socket != NULL) { DBG( 1, "Using local socket %s\n", device->unix_socket ); diff --git a/backend/escl/escl.h b/backend/escl/escl.h index 142b4b4..f99bff9 100644 --- a/backend/escl/escl.h +++ b/backend/escl/escl.h @@ -92,10 +92,12 @@ typedef struct { typedef struct ESCL_Device { struct ESCL_Device *next; + double version; char *model_name; int port_nb; char *ip_address; char *is; + int tls; char *uuid; char *type; SANE_Bool https; @@ -146,6 +148,7 @@ typedef struct support int min; int max; int normal; + int value; int step; } support_t; diff --git a/backend/escl/escl_capabilities.c b/backend/escl/escl_capabilities.c index 7422896..efbd547 100644 --- a/backend/escl/escl_capabilities.c +++ b/backend/escl/escl_capabilities.c @@ -325,7 +325,8 @@ print_support(xmlNode *node) cpt++; } else if (!strcmp((const char *)node->name, "Normal")) { - sup->normal = atoi((const char *)xmlNodeGetContent(node)); + sup->value = atoi((const char *)xmlNodeGetContent(node)); + sup->normal = sup->value; cpt++; have_norm = 1; } @@ -338,7 +339,8 @@ print_support(xmlNode *node) if (cpt == 4) return sup; if (cpt == 3 && have_norm == 0) { - sup->normal = (sup->max / 2 ); + sup->value = (sup->max / 2 ); + sup->normal = sup->value; return sup; } free(sup); @@ -428,6 +430,10 @@ print_xml_c(xmlNode *node, ESCL_Device *device, capabilities_t *scanner, int typ if (find_nodes_c(node) && type != -1) find_true_variables(node, scanner, type); } + if (!strcmp((const char *)node->name, "Version")&& node->ns && node->ns->prefix){ + if (!strcmp((const char*)node->ns->prefix, "pwg")) + device->version = atof ((const char *)xmlNodeGetContent(node)); + } if (!strcmp((const char *)node->name, "MakeAndModel")){ device->model_name = strdup((const char *)xmlNodeGetContent(node)); } @@ -582,6 +588,7 @@ escl_capabilities(ESCL_Device *device, char *blacklist, SANE_Status *status) strstr(header->memory, "Server: HP_Compact_Server")) device->hack = curl_slist_append(NULL, "Host: localhost"); + device->version = 0.0; scanner->source = 0; scanner->Sources = (SANE_String_Const *)malloc(sizeof(SANE_String_Const) * 4); for (i = 0; i < 4; i++) diff --git a/backend/escl/escl_devices.c b/backend/escl/escl_devices.c index 92e064b..a2fdb80 100644 --- a/backend/escl/escl_devices.c +++ b/backend/escl/escl_devices.c @@ -30,6 +30,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <arpa/inet.h> #include <avahi-client/lookup.h> #include <avahi-common/error.h> @@ -53,47 +54,65 @@ static int count_finish = 0; */ static void resolve_callback(AvahiServiceResolver *r, AVAHI_GCC_UNUSED AvahiIfIndex interface, - AVAHI_GCC_UNUSED AvahiProtocol protocol, - AvahiResolverEvent event, const char *name, + AvahiProtocol protocol, + AvahiResolverEvent event, + const char *name, const char __sane_unused__ *type, const char __sane_unused__ *domain, const char __sane_unused__ *host_name, - const AvahiAddress *address, uint16_t port, AvahiStringList *txt, + const AvahiAddress *address, + uint16_t port, + AvahiStringList *txt, AvahiLookupResultFlags __sane_unused__ flags, void __sane_unused__ *userdata) { - char a[AVAHI_ADDRESS_STR_MAX], *t; + char a[(AVAHI_ADDRESS_STR_MAX + 10)] = { 0 }; + char *t; const char *is; const char *uuid; AvahiStringList *s; assert(r); switch (event) { - case AVAHI_RESOLVER_FAILURE: - break; - case AVAHI_RESOLVER_FOUND: - avahi_address_snprint(a, sizeof(a), address); - t = avahi_string_list_to_string(txt); - if (strstr(t, "\"rs=eSCL\"") || strstr(t, "\"rs=/eSCL\"")) { - char ip_add[PATH_MAX] = {0}; - s = avahi_string_list_find(txt, "is"); - if (s && s->size > 3) - is = (const char*)s->text + 3; - else - is = (const char*)NULL; - s = avahi_string_list_find(txt, "uuid"); - if (s && s->size > 5) - uuid = (const char*)s->text + 5; - else - uuid = (const char*)NULL; - DBG (10, "resolve_callback [%s]\n", a); - if (strstr(a, "127.0.0.1") != NULL) { - snprintf(ip_add, sizeof(ip_add), "%s", "localhost"); - DBG (10,"resolve_callback fix redirect [localhost]\n"); - } + case AVAHI_RESOLVER_FAILURE: + break; + case AVAHI_RESOLVER_FOUND: + { + char *psz_addr = ((void*)0); + char b[128] = { 0 }; + avahi_address_snprint(b, (sizeof(b)/sizeof(b[0]))-1, address); +#ifdef ENABLE_IPV6 + if (protocol == AVAHI_PROTO_INET6 && strchr(b, ':')) + { + if ( asprintf( &psz_addr, "[%s]", b ) == -1 ) + break; + } else - snprintf(ip_add, sizeof(ip_add), "%s", a); - escl_device_add(port, name, ip_add, is, uuid, (char*)type); - } +#endif + { + if ( asprintf( &psz_addr, "%s", b ) == -1 ) + break; + } + t = avahi_string_list_to_string(txt); + if (strstr(t, "\"rs=eSCL\"") || strstr(t, "\"rs=/eSCL\"")) { + s = avahi_string_list_find(txt, "is"); + if (s && s->size > 3) + is = (const char*)s->text + 3; + else + is = (const char*)NULL; + s = avahi_string_list_find(txt, "uuid"); + if (s && s->size > 5) + uuid = (const char*)s->text + 5; + else + uuid = (const char*)NULL; + DBG (10, "resolve_callback [%s]\n", a); + if (strstr(psz_addr, "127.0.0.1") != NULL) { + escl_device_add(port, name, "localhost", is, uuid, (char*)type); + DBG (10,"resolve_callback fix redirect [localhost]\n"); + } + else + escl_device_add(port, name, psz_addr, is, uuid, (char*)type); + } + } } } diff --git a/backend/escl/escl_newjob.c b/backend/escl/escl_newjob.c index 98a953f..e1b326f 100644 --- a/backend/escl/escl_newjob.c +++ b/backend/escl/escl_newjob.c @@ -46,7 +46,7 @@ struct downloading static const char settings[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" \ "<scan:ScanSettings xmlns:pwg=\"http://www.pwg.org/schemas/2010/12/sm\" xmlns:scan=\"http://schemas.hp.com/imaging/escl/2011/05/03\">" \ - " <pwg:Version>2.0</pwg:Version>" \ + " <pwg:Version>%.2f</pwg:Version>" \ " <pwg:ScanRegions>" \ " <pwg:ScanRegion>" \ " <pwg:ContentRegionUnits>escl:ThreeHundredthsOfInches</pwg:ContentRegionUnits>" \ @@ -56,13 +56,11 @@ static const char settings[] = " <pwg:YOffset>%d</pwg:YOffset>" \ " </pwg:ScanRegion>" \ " </pwg:ScanRegions>" \ - " <pwg:DocumentFormat>%s</pwg:DocumentFormat>" \ "%s" \ " <scan:ColorMode>%s</scan:ColorMode>" \ " <scan:XResolution>%d</scan:XResolution>" \ " <scan:YResolution>%d</scan:YResolution>" \ " <pwg:InputSource>%s</pwg:InputSource>" \ - " <scan:InputSource>%s</scan:InputSource>" \ "%s" \ "%s" \ "</scan:ScanSettings>"; @@ -138,8 +136,8 @@ escl_newjob (capabilities_t *scanner, const ESCL_Device *device, SANE_Status *st char *location = NULL; char *result = NULL; char *temporary = NULL; - char *f_ext = ""; char *format_ext = NULL; + char f_ext_tmp[1024]; char duplex_mode[1024] = { 0 }; int wakup_count = 0; @@ -189,16 +187,22 @@ escl_newjob (capabilities_t *scanner, const ESCL_Device *device, SANE_Status *st scanner->caps[scanner->source].default_format = strdup(scanner->caps[scanner->source].DocumentFormats[have_pdf]); } - if (scanner->caps[scanner->source].format_ext == 1) + if (device->version <= 2.0) { - char f_ext_tmp[1024]; + // For eSCL 2.0 and older clients snprintf(f_ext_tmp, sizeof(f_ext_tmp), - " <scan:DocumentFormatExt>%s</scan:DocumentFormatExt>", + " <pwg:DocumentFormat>%s</pwg:DocumentFormat>", scanner->caps[scanner->source].default_format); - format_ext = f_ext_tmp; } else - format_ext = f_ext; + { + // For eSCL 2.1 and newer clients + snprintf(f_ext_tmp, sizeof(f_ext_tmp), + " <scan:DocumentFormatExt>%s</scan:DocumentFormatExt>", + scanner->caps[scanner->source].default_format); + } + format_ext = f_ext_tmp; + if(scanner->source > PLATEN && scanner->Sources[ADFDUPLEX]) { snprintf(duplex_mode, sizeof(duplex_mode), " <scan:Duplex>%s</scan:Duplex>", @@ -215,52 +219,63 @@ escl_newjob (capabilities_t *scanner, const ESCL_Device *device, SANE_Status *st char *source = (scanner->source == PLATEN ? "Platen" : "Feeder"); if (scanner->use_threshold) { - char *tmp = add_support_option("ThresholdSupport", scanner->val_threshold); - if (support_options[0]) - strcat(support_options, tmp); - else - strcpy(support_options, tmp); - free(tmp); + if (scanner->val_threshold != scanner->threshold->value) + { + char *tmp = add_support_option("ThresholdSupport", scanner->val_threshold); + if (support_options[0]) + strcat(support_options, tmp); + else + strcpy(support_options, tmp); + free(tmp); + } } if (scanner->use_sharpen) { - char *tmp = add_support_option("SharpenSupport", scanner->val_sharpen); - if (support_options[0]) - strcat(support_options, tmp); - else - strcpy(support_options, tmp); - free(tmp); + if (scanner->val_sharpen != scanner->sharpen->value) + { + char *tmp = add_support_option("SharpenSupport", scanner->val_sharpen); + if (support_options[0]) + strcat(support_options, tmp); + else + strcpy(support_options, tmp); + free(tmp); + } } if (scanner->use_contrast) { - char *tmp = add_support_option("ContrastSupport", scanner->val_contrast); - if (support_options[0]) - strcat(support_options, tmp); - else - strcpy(support_options, tmp); - free(tmp); + if (scanner->val_contrast != scanner->contrast->value) + { + char *tmp = add_support_option("ContrastSupport", scanner->val_contrast); + if (support_options[0]) + strcat(support_options, tmp); + else + strcpy(support_options, tmp); + free(tmp); + } } if (scanner->use_brightness) { - char *tmp = add_support_option("BrightnessSupport", scanner->val_brightness); - if (support_options[0]) - strcat(support_options, tmp); - else - strcpy(support_options, tmp); - free(tmp); + if (scanner->val_brightness != scanner->brightness->value) + { + char *tmp = add_support_option("BrightnessSupport", scanner->val_brightness); + if (support_options[0]) + strcat(support_options, tmp); + else + strcpy(support_options, tmp); + free(tmp); + } } snprintf(cap_data, sizeof(cap_data), settings, + device->version, scanner->caps[scanner->source].height, scanner->caps[scanner->source].width, off_x, off_y, - scanner->caps[scanner->source].default_format, format_ext, scanner->caps[scanner->source].default_color, scanner->caps[scanner->source].default_resolution, scanner->caps[scanner->source].default_resolution, source, - source, duplex_mode[0] == 0 ? " " : duplex_mode, support_options[0] == 0 ? " " : support_options); upload->memory = strdup(cap_data); diff --git a/backend/escl/escl_pdf.c b/backend/escl/escl_pdf.c index 02dce66..8277e1d 100644 --- a/backend/escl/escl_pdf.c +++ b/backend/escl/escl_pdf.c @@ -44,8 +44,9 @@ #if HAVE_POPPLER_GLIB -#define INPUT_BUFFER_SIZE 4096 +#define ESCL_PDF_USE_MAPPED_FILE POPPLER_CHECK_VERSION(0,82,0) +#if ! ESCL_PDF_USE_MAPPED_FILE static unsigned char* set_file_in_buffer(FILE *fp, int *size) { @@ -70,6 +71,7 @@ set_file_in_buffer(FILE *fp, int *size) *size = nx; return data; } +#endif static unsigned char * cairo_surface_to_pixels (cairo_surface_t *surface, int bps) @@ -109,28 +111,52 @@ get_PDF_data(capabilities_t *scanner, int *width, int *height, int *bps) PopplerPage *page; PopplerDocument *doc; double dw, dh; - int w, h, size = 0; - char *data = NULL; + int w, h; unsigned char* surface = NULL; SANE_Status status = SANE_STATUS_GOOD; +#if ESCL_PDF_USE_MAPPED_FILE + GMappedFile *file; + GBytes *bytes; + + file = g_mapped_file_new_from_fd (fileno (scanner->tmp), 0, NULL); + if (!file) { + DBG(1, "Error : g_mapped_file_new_from_fd"); + status = SANE_STATUS_INVAL; + goto close_file; + } + + bytes = g_mapped_file_get_bytes (file); + if (!bytes) { + DBG(1, "Error : g_mapped_file_get_bytes"); + status = SANE_STATUS_INVAL; + goto free_file; + } + + doc = poppler_document_new_from_bytes (bytes, NULL, NULL); + if (!doc) { + DBG(1, "Error : poppler_document_new_from_bytes"); + status = SANE_STATUS_INVAL; + goto free_bytes; + } +#else + int size = 0; + char *data = NULL; data = (char*)set_file_in_buffer(scanner->tmp, &size); if (!data) { - DBG(1, "Error : poppler_document_new_from_data"); + DBG(1, "Error : set_file_in_buffer"); status = SANE_STATUS_INVAL; goto close_file; } - doc = poppler_document_new_from_data(data, - size, - NULL, - NULL); + doc = poppler_document_new_from_data (data, size, NULL, NULL); if (!doc) { DBG(1, "Error : poppler_document_new_from_data"); status = SANE_STATUS_INVAL; - goto free_file; + goto free_data; } +#endif page = poppler_document_get_page (doc, 0); if (!page) { @@ -201,8 +227,15 @@ free_page: g_object_unref (page); free_doc: g_object_unref (doc); +#if ESCL_PDF_USE_MAPPED_FILE +free_bytes: + g_bytes_unref (bytes); free_file: + g_mapped_file_unref (file); +#else +free_data: free(data); +#endif close_file: if (scanner->tmp) fclose(scanner->tmp); diff --git a/backend/escl/escl_scan.c b/backend/escl/escl_scan.c index 3350c83..8af6bb2 100644 --- a/backend/escl/escl_scan.c +++ b/backend/escl/escl_scan.c @@ -84,6 +84,7 @@ escl_scan(capabilities_t *scanner, const ESCL_Device *device, char *scanJob, cha CURLcode res = curl_easy_perform(curl_handle); if (res != CURLE_OK) { DBG( 1, "Unable to scan: %s\n", curl_easy_strerror(res)); + scanner->real_read = 0; fclose(scanner->tmp); scanner->tmp = NULL; status = SANE_STATUS_INVAL; diff --git a/backend/escl/escl_tiff.c b/backend/escl/escl_tiff.c index e33498c..e17554e 100644 --- a/backend/escl/escl_tiff.c +++ b/backend/escl/escl_tiff.c @@ -26,6 +26,8 @@ #include "escl.h" +#include "../include/_stdint.h" + #include "../include/sane/sanei.h" #include <stdio.h> @@ -53,11 +55,11 @@ SANE_Status get_TIFF_data(capabilities_t *scanner, int *width, int *height, int *bps) { TIFF* tif = NULL; - uint32 w = 0; - uint32 h = 0; + uint32_t w = 0; + uint32_t h = 0; unsigned char *surface = NULL; /* image data*/ int components = 4; - uint32 npixels = 0; + uint32_t npixels = 0; SANE_Status status = SANE_STATUS_GOOD; lseek(fileno(scanner->tmp), 0, SEEK_SET); @@ -71,15 +73,15 @@ get_TIFF_data(capabilities_t *scanner, int *width, int *height, int *bps) TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w); TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h); npixels = w * h; - surface = (unsigned char*) malloc(npixels * sizeof (uint32)); - if (surface != NULL) + surface = (unsigned char*) malloc(npixels * sizeof (uint32_t)); + if (surface == NULL) { DBG( 1, "Escl Tiff : raster Memory allocation problem.\n"); status = SANE_STATUS_INVAL; goto close_tiff; } - if (!TIFFReadRGBAImage(tif, w, h, (uint32 *)surface, 0)) + if (!TIFFReadRGBAImage(tif, w, h, (uint32_t *)surface, 0)) { DBG( 1, "Escl Tiff : Problem reading image data.\n"); status = SANE_STATUS_INVAL; diff --git a/backend/fujitsu-scsi.h b/backend/fujitsu-scsi.h index 3d3cf07..c7616f7 100644 --- a/backend/fujitsu-scsi.h +++ b/backend/fujitsu-scsi.h @@ -140,9 +140,12 @@ putnbyte (unsigned char *pnt, unsigned int value, unsigned int nbytes) #define IN_periph_devtype_unknown 0x1f #define get_IN_response_format(in) getbitfield(in + 0x03, 0x07, 0) #define IN_recognized 0x02 -#define get_IN_vendor(in, buf) strncpy(buf, (char *)in + 0x08, 0x08) -#define get_IN_product(in, buf) strncpy(buf, (char *)in + 0x10, 0x010) -#define get_IN_version(in, buf) strncpy(buf, (char *)in + 0x20, 0x04) +#define get_IN_vendor(in, buf) snprintf(buf, 0x08 + 1, "%.*s", \ + 0x08, (char *)in + 0x08) +#define get_IN_product(in, buf) snprintf(buf, 0x10 + 1, "%.*s", \ + 0x10, (char *)in + 0x10) +#define get_IN_version(in, buf) snprintf(buf, 0x04 + 1, "%.*s", \ + 0x04, (char *)in + 0x20) #define get_IN_color_offset(in) getnbyte (in+0x2A, 2) /* offset between colors */ /* these only in some scanners */ diff --git a/backend/fujitsu.c b/backend/fujitsu.c index d17e015..52d0988 100644 --- a/backend/fujitsu.c +++ b/backend/fujitsu.c @@ -6,7 +6,7 @@ Copyright (C) 2000 Randolph Bentson Copyright (C) 2001 Frederik Ramm Copyright (C) 2001-2004 Oliver Schirrmeister - Copyright (C) 2003-2021 m. allan noah + Copyright (C) 2003-2022 m. allan noah JPEG output and low memory usage support funded by: Archivista GmbH, www.archivista.ch @@ -15,7 +15,7 @@ Automatic length detection support funded by: Martin G. Miller, mgmiller at optonline.net Software image enhancement routines and recent scanner support funded by: - Fujitsu Computer Products of America, Inc. www.fcpa.com + PFU America, Inc., fujitsuscanners.com -------------------------------------------------------------------------- @@ -611,6 +611,11 @@ - fix JPEG duplex memory corruption - change window_gamma init (fixes bright/contrast for iX1500) - only call send_lut after set_window (remove late_lut) + v138 2022-06-01, MAN + - minor updates to company name (FCPA -> PFU) + v139 2022-11-15, MAN + - move updated window_gamma logic to set_window + - use internal gamma table if possible (fixes #618) SANE FLOW DIAGRAM @@ -660,7 +665,7 @@ #include "fujitsu.h" #define DEBUG 1 -#define BUILD 137 +#define BUILD 139 /* values for SANE_DEBUG_FUJITSU env var: - errors 5 @@ -764,7 +769,7 @@ static struct fujitsu *fujitsu_devList = NULL; SANE_Status sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize) { - authorize = authorize; /* get rid of compiler warning */ + (void) authorize; /* get rid of compiler warning */ DBG_INIT (); DBG (10, "sane_init: start\n"); @@ -819,7 +824,7 @@ sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only) int num_devices=0; int i=0; - local_only = local_only; /* get rid of compiler warning */ + (void) local_only; /* get rid of compiler warning */ DBG (10, "sane_get_devices: start\n"); @@ -2107,12 +2112,6 @@ init_model (struct fujitsu *s) s->ppl_mod_by_mode[MODE_GRAYSCALE] = 1; s->ppl_mod_by_mode[MODE_COLOR] = 1; - /* we prefer to use the downloaded (LUT) gamma table (0x80) if possible. - * but if scanner has only built-in gamma tables, we use the first one (0) */ - if (s->num_download_gamma){ - s->window_gamma = 0x80; - } - /* endorser type tells string length (among other things) */ if(s->has_endorser_b){ /*old-style is 40 bytes*/ @@ -2206,7 +2205,10 @@ init_model (struct fujitsu *s) s->color_interlace = COLOR_INTERLACE_3091; s->duplex_interlace = DUPLEX_INTERLACE_3091; s->ghs_in_rs = 1; - s->window_gamma = 0; + + /* might be inaccurate */ + s->num_internal_gamma = 1; + s->num_download_gamma = 0; s->reverse_by_mode[MODE_LINEART] = 1; s->reverse_by_mode[MODE_HALFTONE] = 1; @@ -7055,12 +7057,11 @@ sane_start (SANE_Handle handle) goto errors; } - /* send lut if scanner has no hardware brightness/contrast, - * or we are going to ask it to use a downloaded gamma table */ - if (!s->brightness_steps || !s->contrast_steps || s->window_gamma & 0x80){ + /* send lut if set_window said we would */ + if ( s->window_gamma ){ ret = send_lut(s); if (ret != SANE_STATUS_GOOD) - DBG (5, "sane_start: WARNING: cannot late send_lut %d\n", ret); + DBG (5, "sane_start: WARNING: cannot send_lut %d\n", ret); } /* some scanners need the q table sent, even when not scanning jpeg */ @@ -7614,6 +7615,23 @@ set_window (struct fujitsu *s) /* the remainder of the block varies based on model and mode, * except for gamma and paper size, those are in the same place */ + /* determine if we need to send gamma LUT. + * send lut if scanner supports it and any of: + * has no hardware brightness but user changed it + * has no hardware contrast but user changed it + * has no internal gamma table */ + if ( s->num_download_gamma && ( + (!s->brightness_steps && s->brightness != 0) + || (!s->contrast_steps && s->contrast != 0 ) + || !s->num_internal_gamma + ) ){ + s->window_gamma = 0x80; + } + /* otherwise, use the internal table */ + else{ + s->window_gamma = 0; + } + /*vuid c0*/ if(s->has_vuid_3091){ set_WD_vendor_id_code (desc1, WD_VUID_3091); @@ -9270,7 +9288,7 @@ sense_handler (int fd, unsigned char * sensed_data, void *arg) DBG (5, "sense_handler: start\n"); /* kill compiler warning */ - fd = fd; + (void) fd; /* copy the rs return data into the scanner struct so that the caller can use it if he wants */ @@ -9605,8 +9623,8 @@ do_scsi_cmd(struct fujitsu *s, int runRS, int shortTime, int ret; /*shut up compiler*/ - runRS=runRS; - shortTime=shortTime; + (void) runRS; + (void) shortTime; DBG(10, "do_scsi_cmd: start\n"); diff --git a/backend/fujitsu.conf.in b/backend/fujitsu.conf.in index 1645e87..9da0ae9 100644 --- a/backend/fujitsu.conf.in +++ b/backend/fujitsu.conf.in @@ -267,3 +267,39 @@ usb 0x04c5 0x160b #ScanSnap iX1600 usb 0x04c5 0x1632 + +#ScanPartner SP30 +usb 0x04c5 0x140a + +#fi-7300NX +usb 0x04c5 0x1575 + +#fi-8190 +usb 0x04c5 0x15fd + +#fi-8290 +usb 0x04c5 0x15fe + +#fi-8170 +usb 0x04c5 0x15ff + +#fi-8270 +usb 0x04c5 0x1600 + +#fi-8150 +usb 0x04c5 0x1601 + +#fi-8250 +usb 0x04c5 0x1602 + +#fi-8150U +usb 0x04c5 0x162d + +#fi-8250U +usb 0x04c5 0x162e + +#ScanSnap iX1300 +usb 0x04c5 0x162c + +#ScanSnap iX1400 +usb 0x04c5 0x1630 diff --git a/backend/fujitsu.h b/backend/fujitsu.h index 98278eb..6c42ff8 100644 --- a/backend/fujitsu.h +++ b/backend/fujitsu.h @@ -325,7 +325,6 @@ struct fujitsu int jpeg_interlace; /* different models interlace jpeg sides differently */ int cropping_mode; /* lower-end scanners don't crop from paper size */ int ghs_in_rs; - int window_gamma; int endorser_string_len; int has_pixelsize; int has_short_pixelsize; /* m3091/2 put weird stuff at end, ignore it */ @@ -520,6 +519,7 @@ struct fujitsu /* the user never directly modifies these */ int s_mode; /*color,lineart,etc: sent to scanner*/ + int window_gamma; /* depends on brightness/contrast and lut */ /* this is defined in sane spec as a struct containing: SANE_Frame format; diff --git a/backend/genesys.conf.in b/backend/genesys.conf.in index d9c596a..e6788f5 100644 --- a/backend/genesys.conf.in +++ b/backend/genesys.conf.in @@ -160,3 +160,6 @@ usb 0x1803 0x162e # Plustek OpticBook 3800 usb 0x07b3 0x1300 + +# Plustek OpticFilm 7600i +usb 0x07b3 0x0c3b diff --git a/backend/genesys/fwd.h b/backend/genesys/fwd.h index 9937654..5d341b8 100644 --- a/backend/genesys/fwd.h +++ b/backend/genesys/fwd.h @@ -59,7 +59,7 @@ struct Pixel; struct RawPixel; // low.h -struct UsbDeviceEntry; +class UsbDeviceEntry; // motor.h struct Genesys_Motor; diff --git a/backend/genesys/genesys.cpp b/backend/genesys/genesys.cpp index 5aba58c..ab1367e 100644 --- a/backend/genesys/genesys.cpp +++ b/backend/genesys/genesys.cpp @@ -310,9 +310,8 @@ void sanei_genesys_init_structs (Genesys_Device * dev) * @param gamma gamma to compute values * @return a gamma table filled with the computed values * */ -void -sanei_genesys_create_gamma_table (std::vector<uint16_t>& gamma_table, int size, - float maximum, float gamma_max, float gamma) +void sanei_genesys_create_gamma_table(std::vector<std::uint16_t>& gamma_table, int size, + float maximum, float gamma_max, float gamma) { gamma_table.clear(); gamma_table.resize(size, 0); @@ -334,7 +333,7 @@ sanei_genesys_create_gamma_table (std::vector<uint16_t>& gamma_table, int size, } void sanei_genesys_create_default_gamma_table(Genesys_Device* dev, - std::vector<uint16_t>& gamma_table, float gamma) + std::vector<std::uint16_t>& gamma_table, float gamma) { int size = 0; int max = 0; @@ -346,6 +345,7 @@ void sanei_genesys_create_default_gamma_table(Genesys_Device* dev, } max = size - 1; } else if (dev->model->asic_type == AsicType::GL124 || + dev->model->asic_type == AsicType::GL845 || dev->model->asic_type == AsicType::GL846 || dev->model->asic_type == AsicType::GL847) { size = 257; @@ -396,7 +396,7 @@ SANE_Int sanei_genesys_exposure_time2(Genesys_Device * dev, const MotorProfile& The data needs to be of size "size", and in little endian byte order. */ static void genesys_send_offset_and_shading(Genesys_Device* dev, const Genesys_Sensor& sensor, - uint8_t* data, int size) + std::uint8_t* data, int size) { DBG_HELPER_ARGS(dbg, "(size = %d)", size); int start_address; @@ -427,10 +427,10 @@ void sanei_genesys_init_shading_data(Genesys_Device* dev, const Genesys_Sensor& unsigned channels = dev->settings.get_channels(); - // 16 bit black, 16 bit white - std::vector<uint8_t> shading_data(pixels_per_line * 4 * channels, 0); + // 16 bit black, 16 bit white + std::vector<std::uint8_t> shading_data(pixels_per_line * 4 * channels, 0); - uint8_t* shading_data_ptr = shading_data.data(); + std::uint8_t* shading_data_ptr = shading_data.data(); for (unsigned i = 0; i < pixels_per_line * channels; i++) { *shading_data_ptr++ = 0x00; /* dark lo */ @@ -487,7 +487,7 @@ void scanner_clear_scan_and_feed_counts(Genesys_Device& dev) } void scanner_send_slope_table(Genesys_Device* dev, const Genesys_Sensor& sensor, unsigned table_nr, - const std::vector<uint16_t>& slope_table) + const std::vector<std::uint16_t>& slope_table) { DBG_HELPER_ARGS(dbg, "table_nr = %d, steps = %zu", table_nr, slope_table.size()); @@ -515,7 +515,7 @@ void scanner_send_slope_table(Genesys_Device* dev, const Genesys_Sensor& sensor, throw SaneException("invalid table number %d", table_nr); } - std::vector<uint8_t> table; + std::vector<std::uint8_t> table; table.reserve(slope_table.size() * 2); for (std::size_t i = 0; i < slope_table.size(); i++) { table.push_back(slope_table[i] & 0xff); @@ -1868,7 +1868,7 @@ void scanner_coarse_gain_calibration(Genesys_Device& dev, const Genesys_Sensor& dev.model->asic_type == AsicType::GL842 || dev.model->asic_type == AsicType::GL843) { - std::vector<uint16_t> values; + std::vector<std::uint16_t> values; // FIXME: start from the second line because the first line often has artifacts. Probably // caused by unclean cleanup of previous scan for (std::size_t x = pixels / 4; x < (pixels * 3 / 4); x++) { @@ -2178,12 +2178,12 @@ SensorExposure scanner_led_calibration(Genesys_Device& dev, const Genesys_Sensor } void sanei_genesys_calculate_zmod(bool two_table, - uint32_t exposure_time, - const std::vector<uint16_t>& slope_table, + std::uint32_t exposure_time, + const std::vector<std::uint16_t>& slope_table, unsigned acceleration_steps, unsigned move_steps, unsigned buffer_acceleration_steps, - uint32_t* out_z1, uint32_t* out_z2) + std::uint32_t* out_z1, std::uint32_t* out_z2) { // acceleration total time unsigned sum = std::accumulate(slope_table.begin(), slope_table.begin() + acceleration_steps, @@ -2233,7 +2233,7 @@ static void genesys_shading_calibration_impl(Genesys_Device* dev, const Genesys_ debug_dump(DBG_info, dev->calib_session); size_t size; - uint32_t pixels_per_line; + std::uint32_t pixels_per_line; if (dev->model->asic_type == AsicType::GL842 || dev->model->asic_type == AsicType::GL843 || @@ -2274,7 +2274,7 @@ static void genesys_shading_calibration_impl(Genesys_Device* dev, const Genesys_ size = channels * 2 * pixels_per_line * (dev->calib_session.params.lines + 1); } - std::vector<uint16_t> calibration_data(size / 2); + std::vector<std::uint16_t> calibration_data(size / 2); // turn off motor and lamp power for flatbed scanners, but not for sheetfed scanners // because they have a calibration sheet with a sufficient black strip @@ -2353,8 +2353,8 @@ static void genesys_shading_calibration_impl(Genesys_Device* dev, const Genesys_ static void genesys_dark_shading_by_dummy_pixel(Genesys_Device* dev, const Genesys_Sensor& sensor) { DBG_HELPER(dbg); - uint32_t pixels_per_line; - uint32_t skip, xend; + std::uint32_t pixels_per_line; + std::uint32_t skip, xend; int dummy1, dummy2, dummy3; /* dummy black average per channel */ if (dev->model->asic_type == AsicType::GL842 || @@ -2578,11 +2578,9 @@ static void genesys_dark_white_shading_calibration(Genesys_Device* dev, dev->interface->write_registers(local_reg); } - size_t size; - uint32_t pixels_per_line; + std::size_t size; + std::uint32_t pixels_per_line; unsigned int x; - uint32_t dark, white, dark_sum, white_sum, dark_count, white_count, col, - dif; if (dev->model->asic_type == AsicType::GL842 || dev->model->asic_type == AsicType::GL843) @@ -2618,7 +2616,7 @@ static void genesys_dark_white_shading_calibration(Genesys_Device* dev, size = channels * 2 * pixels_per_line * dev->calib_session.params.lines; } - std::vector<uint8_t> calibration_data(size); + std::vector<std::uint8_t> calibration_data(size); // turn on motor and lamp power sanei_genesys_set_lamp_power(dev, sensor, local_reg, true); @@ -2656,19 +2654,17 @@ static void genesys_dark_white_shading_calibration(Genesys_Device* dev, std::fill(dev->white_average_data.begin(), dev->white_average_data.begin() + start_offset * channels, 0); - uint16_t* average_white = dev->white_average_data.data() + - start_offset * channels; - uint16_t* average_dark = dev->dark_average_data.data() + - start_offset * channels; + std::uint16_t* average_white = dev->white_average_data.data() + start_offset * channels; + std::uint16_t* average_dark = dev->dark_average_data.data() + start_offset * channels; for (x = 0; x < pixels_per_line * channels; x++) { - dark = 0xffff; - white = 0; + std::uint32_t dark = 0xffff; + std::uint32_t white = 0; for (std::size_t y = 0; y < dev->calib_session.params.lines; y++) { - col = calibration_data[(x + y * pixels_per_line * channels) * 2]; + std::uint32_t col = calibration_data[(x + y * pixels_per_line * channels) * 2]; col |= calibration_data[(x + y * pixels_per_line * channels) * 2 + 1] << 8; @@ -2679,20 +2675,20 @@ static void genesys_dark_white_shading_calibration(Genesys_Device* dev, dark = col; } - dif = white - dark; + std::uint32_t dif = white - dark; dark = dark + dif / 8; white = white - dif / 8; - dark_count = 0; - dark_sum = 0; + std::uint32_t dark_count = 0; + std::uint32_t dark_sum = 0; - white_count = 0; - white_sum = 0; + std::uint32_t white_count = 0; + std::uint32_t white_sum = 0; for (std::size_t y = 0; y < dev->calib_session.params.lines; y++) { - col = calibration_data[(x + y * pixels_per_line * channels) * 2]; + std::uint32_t col = calibration_data[(x + y * pixels_per_line * channels) * 2]; col |= calibration_data[(x + y * pixels_per_line * channels) * 2 + 1] << 8; @@ -2780,9 +2776,8 @@ compute_coefficient (unsigned int coeff, unsigned int target, unsigned int value * @param target_bright value of the white target code * @param target_dark value of the black target code */ -static void -compute_averaged_planar (Genesys_Device * dev, const Genesys_Sensor& sensor, - uint8_t * shading_data, +static void compute_averaged_planar(Genesys_Device * dev, const Genesys_Sensor& sensor, + std::uint8_t* shading_data, unsigned int pixels_per_line, unsigned int words_per_color, unsigned int channels, @@ -2852,7 +2847,8 @@ compute_averaged_planar (Genesys_Device * dev, const Genesys_Sensor& sensor, avgpixels = 15; /* LiDE80 packs shading data */ - if (dev->model->sensor_id != SensorId::CIS_CANON_LIDE_80) { + if (dev->model->sensor_id != SensorId::CIS_CANON_LIDE_80) + { factor=1; fill=avgpixels; } @@ -2961,7 +2957,7 @@ static std::array<unsigned, 3> color_order_to_cmat(ColorOrder color_order) * @param target value of the target code */ static void compute_coefficients(Genesys_Device * dev, - uint8_t * shading_data, + std::uint8_t* shading_data, unsigned int pixels_per_line, unsigned int channels, ColorOrder color_order, @@ -2969,7 +2965,6 @@ static void compute_coefficients(Genesys_Device * dev, unsigned int coeff, unsigned int target) { - uint8_t *ptr; /* contain 16bit words in little endian */ unsigned int x, c; unsigned int val, br, dk; unsigned int start, end; @@ -2995,7 +2990,8 @@ static void compute_coefficients(Genesys_Device * dev, for (x = start; x < end; x++) { /* TODO if channels=1 , use filter to know the base addr */ - ptr = shading_data + 4 * ((x + offset) * channels + cmat[c]); + // contain 16bit words in little endian + std::uint8_t* ptr = shading_data + 4 * ((x + offset) * channels + cmat[c]); // dark data dk = dev->dark_average_data[x * channels + c]; @@ -3033,7 +3029,7 @@ static void compute_coefficients(Genesys_Device * dev, * @param target white target value */ static void compute_planar_coefficients(Genesys_Device * dev, - uint8_t * shading_data, + std::uint8_t* shading_data, unsigned int factor, unsigned int pixels_per_line, unsigned int words_per_color, @@ -3043,22 +3039,20 @@ static void compute_planar_coefficients(Genesys_Device * dev, unsigned int coeff, unsigned int target) { - uint8_t *ptr; /* contains 16bit words in little endian */ - uint32_t x, c, i; - uint32_t val, dk, br; + std::uint32_t i; + std::uint32_t val, dk, br; auto cmat = color_order_to_cmat(color_order); DBG(DBG_io, "%s: factor=%d, pixels_per_line=%d, words=0x%X, coeff=0x%04x\n", __func__, factor, pixels_per_line, words_per_color, coeff); - for (c = 0; c < channels; c++) - { + for (unsigned c = 0; c < channels; c++) { /* shading data is larger than pixels_per_line so offset can be neglected */ - for (x = 0; x < pixels_per_line; x+=factor) - { + for (unsigned x = 0; x < pixels_per_line; x += factor) { /* x2 because of 16 bit values, and x2 since one coeff for dark * and another for white */ - ptr = shading_data + words_per_color * cmat[c] * 2 + (x + offset) * 4; + // contains 16bit words in little endian + std::uint8_t* ptr = shading_data + words_per_color * cmat[c] * 2 + (x + offset) * 4; dk = 0; br = 0; @@ -3074,9 +3068,8 @@ static void compute_planar_coefficients(Genesys_Device * dev, val = compute_coefficient (coeff, target, br - dk); - /* we duplicate the information to have calibration data at optical resolution */ - for (i = 0; i < factor; i++) - { + // we duplicate the information to have calibration data at optical resolution + for (unsigned i = 0; i < factor; i++) { ptr[0 + 4 * i] = dk & 255; ptr[1 + 4 * i] = dk / 256; ptr[2 + 4 * i] = val & 0xff; @@ -3097,10 +3090,9 @@ static void compute_planar_coefficients(Genesys_Device * dev, } } -static void -compute_shifted_coefficients (Genesys_Device * dev, - const Genesys_Sensor& sensor, - uint8_t * shading_data, +static void compute_shifted_coefficients(Genesys_Device * dev, + const Genesys_Sensor& sensor, + std::uint8_t* shading_data, unsigned int pixels_per_line, unsigned int channels, ColorOrder color_order, @@ -3112,7 +3104,7 @@ compute_shifted_coefficients (Genesys_Device * dev, { unsigned int x, avgpixels, basepixels, i, j, val1, val2; unsigned int br_tmp [3], dk_tmp [3]; - uint8_t *ptr = shading_data + offset * 3 * 4; /* contain 16bit words in little endian */ + std::uint8_t* ptr = shading_data + offset * 3 * 4; // contain 16bit words in little endian unsigned int patch_cnt = offset * 3; /* at start, offset of first patch */ auto cmat = color_order_to_cmat(color_order); @@ -3198,7 +3190,7 @@ static void genesys_send_shading_coefficient(Genesys_Device* dev, const Genesys_ return; } - uint32_t pixels_per_line; + std::uint32_t pixels_per_line; int o; unsigned int length; /**> number of shading calibration data words */ unsigned int factor; @@ -3255,8 +3247,8 @@ static void genesys_send_shading_coefficient(Genesys_Device* dev, const Genesys_ length = words_per_color * 3 * 2; /* allocate computed size */ - // contains 16bit words in little endian - std::vector<uint8_t> shading_data(length, 0); + // contains 16bit words in little endian + std::vector<std::uint8_t> shading_data(length, 0); if (!dev->calib_session.computed) { genesys_send_offset_and_shading(dev, sensor, shading_data.data(), length); @@ -3584,7 +3576,7 @@ static void genesys_save_calibration(Genesys_Device* dev, const Genesys_Sensor& static void genesys_flatbed_calibration(Genesys_Device* dev, Genesys_Sensor& sensor) { DBG_HELPER(dbg); - uint32_t pixels_per_line; + std::uint32_t pixels_per_line; unsigned coarse_res = sensor.full_resolution; if (dev->settings.yres <= sensor.full_resolution / 2) { @@ -3857,8 +3849,8 @@ static void genesys_warmup_lamp(Genesys_Device* dev) auto channels = dev->session.params.channels; auto lines = dev->session.output_line_count; - std::vector<uint8_t> first_line(total_size); - std::vector<uint8_t> second_line(total_size); + std::vector<std::uint8_t> first_line(total_size); + std::vector<std::uint8_t> second_line(total_size); do { first_line = second_line; @@ -4892,28 +4884,76 @@ static void init_options(Genesys_Scanner* s) s->opt[OPT_POWER_SW].cap = SANE_CAP_INACTIVE; /* extra button */ - s->opt[OPT_EXTRA_SW].name = "extra"; - s->opt[OPT_EXTRA_SW].title = SANE_I18N("Extra button"); - s->opt[OPT_EXTRA_SW].desc = SANE_I18N("Extra button"); - s->opt[OPT_EXTRA_SW].type = SANE_TYPE_BOOL; - s->opt[OPT_EXTRA_SW].unit = SANE_UNIT_NONE; - if (model->buttons & GENESYS_HAS_EXTRA_SW) { - s->opt[OPT_EXTRA_SW].cap = SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED; - } else { - s->opt[OPT_EXTRA_SW].cap = SANE_CAP_INACTIVE; - } - - // transparency/scan_film button - s->opt[OPT_TRANSP_SW].name = "transparency"; - s->opt[OPT_TRANSP_SW].title = SANE_I18N ("Transparency button"); - s->opt[OPT_TRANSP_SW].desc = SANE_I18N ("Transparency button"); - s->opt[OPT_TRANSP_SW].type = SANE_TYPE_BOOL; - s->opt[OPT_TRANSP_SW].unit = SANE_UNIT_NONE; - if (model->buttons & GENESYS_HAS_TRANSP_SW) { - s->opt[OPT_TRANSP_SW].cap = SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED; - } else { - s->opt[OPT_TRANSP_SW].cap = SANE_CAP_INACTIVE; - } + s->opt[OPT_EXTRA_SW].name = "extra"; + s->opt[OPT_EXTRA_SW].title = SANE_I18N("Extra button"); + s->opt[OPT_EXTRA_SW].desc = SANE_I18N("Extra button"); + s->opt[OPT_EXTRA_SW].type = SANE_TYPE_BOOL; + s->opt[OPT_EXTRA_SW].unit = SANE_UNIT_NONE; + if (model->buttons & GENESYS_HAS_EXTRA_SW) + s->opt[OPT_EXTRA_SW].cap = + SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED; + else + s->opt[OPT_EXTRA_SW].cap = SANE_CAP_INACTIVE; + + /* transparency/scan_film button */ + s->opt[OPT_TRANSP_SW].name = "transparency"; + s->opt[OPT_TRANSP_SW].title = SANE_I18N ("Transparency button"); + s->opt[OPT_TRANSP_SW].desc = SANE_I18N ("Transparency button"); + s->opt[OPT_TRANSP_SW].type = SANE_TYPE_BOOL; + s->opt[OPT_TRANSP_SW].unit = SANE_UNIT_NONE; + if (model->buttons & GENESYS_HAS_TRANSP_SW) + s->opt[OPT_TRANSP_SW].cap = + SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED; + else + s->opt[OPT_TRANSP_SW].cap = SANE_CAP_INACTIVE; + + /* PDF special function button 1 */ + s->opt[OPT_PDF1_SW].name = "pdf1"; + s->opt[OPT_PDF1_SW].title = SANE_I18N ("PDF function button 1"); + s->opt[OPT_PDF1_SW].desc = SANE_I18N ("PDF function button 1"); + s->opt[OPT_PDF1_SW].type = SANE_TYPE_BOOL; + s->opt[OPT_PDF1_SW].unit = SANE_UNIT_NONE; + if (model->buttons & GENESYS_HAS_PDF1_SW) + s->opt[OPT_PDF1_SW].cap = + SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED; + else + s->opt[OPT_PDF1_SW].cap = SANE_CAP_INACTIVE; + + /* PDF special function button 2 */ + s->opt[OPT_PDF2_SW].name = "pdf2"; + s->opt[OPT_PDF2_SW].title = SANE_I18N ("PDF function button 2"); + s->opt[OPT_PDF2_SW].desc = SANE_I18N ("PDF function button 2"); + s->opt[OPT_PDF2_SW].type = SANE_TYPE_BOOL; + s->opt[OPT_PDF2_SW].unit = SANE_UNIT_NONE; + if (model->buttons & GENESYS_HAS_PDF2_SW) + s->opt[OPT_PDF2_SW].cap = + SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED; + else + s->opt[OPT_PDF2_SW].cap = SANE_CAP_INACTIVE; + + /* PDF special function button 3 */ + s->opt[OPT_PDF3_SW].name = "pdf3"; + s->opt[OPT_PDF3_SW].title = SANE_I18N ("PDF function button 3"); + s->opt[OPT_PDF3_SW].desc = SANE_I18N ("PDF function button 3"); + s->opt[OPT_PDF3_SW].type = SANE_TYPE_BOOL; + s->opt[OPT_PDF3_SW].unit = SANE_UNIT_NONE; + if (model->buttons & GENESYS_HAS_PDF3_SW) + s->opt[OPT_PDF3_SW].cap = + SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED; + else + s->opt[OPT_PDF3_SW].cap = SANE_CAP_INACTIVE; + + /* PDF special function button 4 */ + s->opt[OPT_PDF4_SW].name = "pdf4"; + s->opt[OPT_PDF4_SW].title = SANE_I18N ("PDF function button 4"); + s->opt[OPT_PDF4_SW].desc = SANE_I18N ("PDF function button 4"); + s->opt[OPT_PDF4_SW].type = SANE_TYPE_BOOL; + s->opt[OPT_PDF4_SW].unit = SANE_UNIT_NONE; + if (model->buttons & GENESYS_HAS_PDF4_SW) + s->opt[OPT_PDF4_SW].cap = + SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED; + else + s->opt[OPT_PDF4_SW].cap = SANE_CAP_INACTIVE; /* calibration needed */ s->opt[OPT_NEED_CALIBRATION_SW].name = "need-calibration"; @@ -5588,7 +5628,7 @@ static void get_option_value(Genesys_Scanner* s, int option, void* val) auto* dev = s->dev; unsigned int i; SANE_Word* table = nullptr; - std::vector<uint16_t> gamma_table; + std::vector<std::uint16_t> gamma_table; unsigned option_size = 0; const Genesys_Sensor* sensor = nullptr; @@ -5734,6 +5774,10 @@ static void get_option_value(Genesys_Scanner* s, int option, void* val) case OPT_POWER_SW: case OPT_EXTRA_SW: case OPT_TRANSP_SW: + case OPT_PDF1_SW: + case OPT_PDF2_SW: + case OPT_PDF3_SW: + case OPT_PDF4_SW: s->dev->cmd_set->update_hardware_sensors(s); *reinterpret_cast<SANE_Bool*>(val) = s->buttons[genesys_option_to_button(option)].read(); break; @@ -6370,6 +6414,10 @@ GenesysButtonName genesys_option_to_button(int option) case OPT_POWER_SW: return BUTTON_POWER_SW; case OPT_EXTRA_SW: return BUTTON_EXTRA_SW; case OPT_TRANSP_SW: return BUTTON_TRANSP_SW; + case OPT_PDF1_SW: return BUTTON_PDF1_SW; + case OPT_PDF2_SW: return BUTTON_PDF2_SW; + case OPT_PDF3_SW: return BUTTON_PDF3_SW; + case OPT_PDF4_SW: return BUTTON_PDF4_SW; default: throw std::runtime_error("Unknown option to convert to button index"); } } diff --git a/backend/genesys/genesys.h b/backend/genesys/genesys.h index 272beaa..65b66e7 100644 --- a/backend/genesys/genesys.h +++ b/backend/genesys/genesys.h @@ -104,6 +104,10 @@ enum Genesys_Option OPT_POWER_SW, OPT_EXTRA_SW, OPT_TRANSP_SW, + OPT_PDF1_SW, + OPT_PDF2_SW, + OPT_PDF3_SW, + OPT_PDF4_SW, OPT_NEED_CALIBRATION_SW, OPT_BUTTON_GROUP, OPT_CALIBRATE, @@ -125,6 +129,10 @@ enum GenesysButtonName : unsigned { BUTTON_POWER_SW, BUTTON_EXTRA_SW, BUTTON_TRANSP_SW, + BUTTON_PDF1_SW, + BUTTON_PDF2_SW, + BUTTON_PDF3_SW, + BUTTON_PDF4_SW, NUM_BUTTONS }; diff --git a/backend/genesys/gl124.cpp b/backend/genesys/gl124.cpp index 1fa4d99..af193a3 100644 --- a/backend/genesys/gl124.cpp +++ b/backend/genesys/gl124.cpp @@ -355,7 +355,7 @@ gl124_init_registers (Genesys_Device * dev) * @param dev device owning the AFE * @param set flag AFE_INIT to specify the AFE must be reset before writing data * */ -static void gl124_set_ti_fe(Genesys_Device* dev, uint8_t set) +static void gl124_set_ti_fe(Genesys_Device* dev, std::uint8_t set) { DBG_HELPER(dbg); int i; @@ -367,9 +367,8 @@ static void gl124_set_ti_fe(Genesys_Device* dev, uint8_t set) // start writing to DAC dev->interface->write_fe_register(0x00, 0x80); - /* write values to analog frontend */ - for (uint16_t addr = 0x01; addr < 0x04; addr++) - { + // write values to analog frontend + for (std::uint16_t addr = 0x01; addr < 0x04; addr++) { dev->interface->write_fe_register(addr, dev->frontend.regs.get_value(addr)); } @@ -392,13 +391,14 @@ static void gl124_set_ti_fe(Genesys_Device* dev, uint8_t set) // Set values of analog frontend -void CommandSetGl124::set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t set) const +void CommandSetGl124::set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, + std::uint8_t set) const { DBG_HELPER_ARGS(dbg, "%s", set == AFE_INIT ? "init" : set == AFE_SET ? "set" : set == AFE_POWER_SAVE ? "powersave" : "huh?"); (void) sensor; - uint8_t val; + std::uint8_t val; if (set == AFE_INIT) { dev->frontend = dev->frontend_initial; @@ -434,7 +434,7 @@ static void gl124_init_motor_regs_scan(Genesys_Device* dev, DBG_HELPER(dbg); unsigned int lincnt, fast_dpi; unsigned int feedl,dist; - uint32_t z1, z2; + std::uint32_t z1, z2; unsigned yres; unsigned min_speed; unsigned int linesel; @@ -489,7 +489,7 @@ static void gl124_init_motor_regs_scan(Genesys_Device* dev, reg->set24(REG_LINCNT, lincnt); /* compute register 02 value */ - uint8_t r02 = REG_0x02_NOTHOME; + std::uint8_t r02 = REG_0x02_NOTHOME; if (has_flag(flags, ScanFlag::AUTO_GO_HOME)) { r02 |= REG_0x02_AGOHOME; @@ -578,7 +578,6 @@ static void gl124_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens const ScanSession& session) { DBG_HELPER_ARGS(dbg, "exposure_time=%d", exposure_time); - uint32_t expmax; scanner_setup_sensor(*dev, sensor, *reg); @@ -659,7 +658,7 @@ static void gl124_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens reg->find_reg(REG_0x60).value &= ~REG_0x60_LEDADD; if (session.enable_ledadd) { reg->find_reg(REG_0x60).value |= REG_0x60_LEDADD; - expmax = reg->get24(REG_EXPR); + std::uint32_t expmax = reg->get24(REG_EXPR); expmax = std::max(expmax, reg->get24(REG_EXPG)); expmax = std::max(expmax, reg->get24(REG_EXPB)); @@ -745,7 +744,7 @@ void CommandSetGl124::init_regs_for_scan_session(Genesys_Device* dev, const Gene dev->session = session; dev->total_bytes_read = 0; - dev->total_bytes_to_read = session.output_line_bytes_requested * session.params.lines; + dev->total_bytes_to_read = (size_t)session.output_line_bytes_requested * (size_t)session.params.lines; DBG(DBG_info, "%s: total bytes to send to frontend = %zu\n", __func__, dev->total_bytes_to_read); @@ -826,7 +825,7 @@ void gl124_setup_scan_gpio(Genesys_Device* dev, int resolution) { DBG_HELPER(dbg); - uint8_t val = dev->interface->read_register(REG_0x32); + std::uint8_t val = dev->interface->read_register(REG_0x32); /* LiDE 110, 210 and 220 cases */ if(dev->model->gpio_id != GpioId::CANON_LIDE_120) { @@ -883,7 +882,7 @@ void CommandSetGl124::begin_scan(Genesys_Device* dev, const Genesys_Sensor& sens scanner_clear_scan_and_feed_counts(*dev); // enable scan and motor - uint8_t val = dev->interface->read_register(REG_0x01); + std::uint8_t val = dev->interface->read_register(REG_0x01); val |= REG_0x01_SCAN; dev->interface->write_register(REG_0x01, val); @@ -974,7 +973,7 @@ void CommandSetGl124::wait_for_motor_stop(Genesys_Device* dev) const DBG_HELPER(dbg); auto status = scanner_read_status(*dev); - uint8_t val40 = dev->interface->read_register(REG_0x100); + std::uint8_t val40 = dev->interface->read_register(REG_0x100); if (!status.is_motor_enabled && (val40 & REG_0x100_MOTMFLG) == 0) { return; @@ -997,7 +996,7 @@ void CommandSetGl124::send_shading_data(Genesys_Device* dev, const Genesys_Senso { DBG_HELPER_ARGS(dbg, "writing %d bytes of shading data", size); std::uint32_t addr, length, segcnt, pixels, i; - uint8_t *ptr, *src; + std::uint8_t *ptr, *src; /* logical size of a color as seen by generic code of the frontend */ length = size / 3; @@ -1020,7 +1019,7 @@ void CommandSetGl124::send_shading_data(Genesys_Device* dev, const Genesys_Senso std::to_string(dev->session.segment_count)); DBG( DBG_io2, "%s: using chunks of %d bytes (%d shading data pixels)\n",__func__,length, length/4); - std::vector<uint8_t> buffer(pixels * dev->session.segment_count, 0); + std::vector<std::uint8_t> buffer(pixels * dev->session.segment_count, 0); /* write actual red data */ for(i=0;i<3;i++) @@ -1047,7 +1046,7 @@ void CommandSetGl124::send_shading_data(Genesys_Device* dev, const Genesys_Senso /* next shading coefficient */ ptr+=4; } - uint8_t val = dev->interface->read_register(0xd0+i); + std::uint8_t val = dev->interface->read_register(0xd0+i); addr = val * 8192 + 0x10000000; dev->interface->write_ahb(addr, pixels * dev->session.segment_count, buffer.data()); } @@ -1254,7 +1253,7 @@ void CommandSetGl124::asic_boot(Genesys_Device* dev, bool cold) const dev->interface->write_register(0x36, 0x01); // set GPIO 17 - uint8_t val = dev->interface->read_register(0x33); + std::uint8_t val = dev->interface->read_register(0x33); val |= 0x01; dev->interface->write_register(0x33, val); @@ -1297,7 +1296,7 @@ void CommandSetGl124::update_hardware_sensors(Genesys_Scanner* s) const any of them. */ DBG_HELPER(dbg); - uint8_t val = s->dev->interface->read_register(REG_0x31); + std::uint8_t val = s->dev->interface->read_register(REG_0x31); /* TODO : for the next scanner special case, * add another per scanner button profile struct to avoid growing diff --git a/backend/genesys/gl124.h b/backend/genesys/gl124.h index 02b733b..2b98b1b 100644 --- a/backend/genesys/gl124.h +++ b/backend/genesys/gl124.h @@ -46,7 +46,7 @@ public: Genesys_Register_Set* reg, const ScanSession& session) const override; - void set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t set) const override; + void set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, std::uint8_t set) const override; void set_powersaving(Genesys_Device* dev, int delay) const override; void save_power(Genesys_Device* dev, bool enable) const override; @@ -80,7 +80,7 @@ public: void eject_document(Genesys_Device* dev) const override; - void send_shading_data(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t* data, + void send_shading_data(Genesys_Device* dev, const Genesys_Sensor& sensor, std::uint8_t* data, int size) const override; ScanSession calculate_scan_session(const Genesys_Device* dev, diff --git a/backend/genesys/gl646.cpp b/backend/genesys/gl646.cpp index bdde703..ac6c617 100644 --- a/backend/genesys/gl646.cpp +++ b/backend/genesys/gl646.cpp @@ -43,11 +43,12 @@ constexpr unsigned CALIBRATION_LINES = 10; static void write_control(Genesys_Device* dev, const Genesys_Sensor& sensor, int resolution); -static void gl646_set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t set, int dpi); +static void gl646_set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, std::uint8_t set, + int dpi); static void simple_scan(Genesys_Device* dev, const Genesys_Sensor& sensor, const ScanSession& session, bool move, - std::vector<uint8_t>& data, const char* test_identifier); + std::vector<std::uint8_t>& data, const char* test_identifier); /** * Send the stop scan command * */ @@ -374,7 +375,7 @@ static Motor_Master motor_master[] = { /** * reads value from gpio endpoint */ -static void gl646_gpio_read(IUsbDevice& usb_dev, uint8_t* value) +static void gl646_gpio_read(IUsbDevice& usb_dev, std::uint8_t* value) { DBG_HELPER(dbg); usb_dev.control_msg(REQUEST_TYPE_IN, REQUEST_REGISTER, GPIO_READ, INDEX, 1, value); @@ -383,7 +384,7 @@ static void gl646_gpio_read(IUsbDevice& usb_dev, uint8_t* value) /** * writes the given value to gpio endpoint */ -static void gl646_gpio_write(IUsbDevice& usb_dev, uint8_t value) +static void gl646_gpio_write(IUsbDevice& usb_dev, std::uint8_t value) { DBG_HELPER_ARGS(dbg, "(0x%02x)", value); usb_dev.control_msg(REQUEST_TYPE_OUT, REQUEST_REGISTER, GPIO_WRITE, INDEX, 1, &value); @@ -392,7 +393,7 @@ static void gl646_gpio_write(IUsbDevice& usb_dev, uint8_t value) /** * writes the given value to gpio output enable endpoint */ -static void gl646_gpio_output_enable(IUsbDevice& usb_dev, uint8_t value) +static void gl646_gpio_output_enable(IUsbDevice& usb_dev, std::uint8_t value) { DBG_HELPER_ARGS(dbg, "(0x%02x)", value); usb_dev.control_msg(REQUEST_TYPE_OUT, REQUEST_REGISTER, GPIO_OUTPUT_ENABLE, INDEX, 1, &value); @@ -440,10 +441,10 @@ void CommandSetGl646::init_regs_for_scan_session(Genesys_Device* dev, const Gene debug_dump(DBG_info, sensor); - uint32_t move = session.params.starty; + std::uint32_t move = session.params.starty; Motor_Master *motor = nullptr; - uint32_t z1, z2; + std::uint32_t z1, z2; int feedl; @@ -817,7 +818,8 @@ void CommandSetGl646::init_regs_for_scan_session(Genesys_Device* dev, const Gene dev->session = session; dev->total_bytes_read = 0; - dev->total_bytes_to_read = session.output_line_bytes_requested * session.params.lines; + dev->total_bytes_to_read = (size_t) session.output_line_bytes_requested + * (size_t) session.params.lines; /* select color filter based on settings */ regs->find_reg(0x04).value &= ~REG_0x04_FILTER; @@ -1023,7 +1025,7 @@ gl646_init_regs (Genesys_Device * dev) } // Set values of Analog Device type frontend -static void gl646_set_ad_fe(Genesys_Device* dev, uint8_t set) +static void gl646_set_ad_fe(Genesys_Device* dev, std::uint8_t set) { DBG_HELPER(dbg); int i; @@ -1058,7 +1060,7 @@ static void gl646_set_ad_fe(Genesys_Device* dev, uint8_t set) * @param set action from AFE_SET, AFE_INIT and AFE_POWERSAVE * @param dpi resolution of the scan since it affects settings */ -static void gl646_wm_hp3670(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t set, +static void gl646_wm_hp3670(Genesys_Device* dev, const Genesys_Sensor& sensor, std::uint8_t set, unsigned dpi) { DBG_HELPER(dbg); @@ -1108,16 +1110,17 @@ static void gl646_wm_hp3670(Genesys_Device* dev, const Genesys_Sensor& sensor, u * @param set action to execute * @param dpi dpi to setup the AFE */ -static void gl646_set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t set, int dpi) +static void gl646_set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, std::uint8_t set, + int dpi) { DBG_HELPER_ARGS(dbg, "%s,%d", set == AFE_INIT ? "init" : set == AFE_SET ? "set" : set == AFE_POWER_SAVE ? "powersave" : "huh?", dpi); int i; - uint8_t val; + std::uint8_t val; /* Analog Device type frontend */ - uint8_t frontend_type = dev->reg.find_reg(0x04).value & REG_0x04_FESET; + std::uint8_t frontend_type = dev->reg.find_reg(0x04).value & REG_0x04_FESET; if (frontend_type == 0x02) { gl646_set_ad_fe(dev, set); return; @@ -1203,7 +1206,8 @@ static void gl646_set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, uint * @param dev device to set * @param set action to execute */ -void CommandSetGl646::set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t set) const +void CommandSetGl646::set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, + std::uint8_t set) const { gl646_set_fe(dev, sensor, set, dev->settings.yres); } @@ -1854,10 +1858,7 @@ void CommandSetGl646::send_gamma_table(Genesys_Device* dev, const Genesys_Sensor bits = 12; } - /* allocate temporary gamma tables: 16 bits words, 3 channels */ - std::vector<uint8_t> gamma(size * 2 * 3); - - sanei_genesys_generate_gamma_buffer(dev, sensor, bits, size-1, size, gamma.data()); + auto gamma = generate_gamma_buffer(dev, sensor, bits, size-1, size); /* table address */ switch (dev->reg.find_reg(0x05).value >> 6) @@ -1892,7 +1893,7 @@ SensorExposure CommandSetGl646::led_calibration(Genesys_Device* dev, const Genes int val; int avg[3], avga, avge; int turn; - uint16_t expr, expg, expb; + std::uint16_t expr, expg, expb; unsigned channels = dev->settings.get_channels(); @@ -1927,7 +1928,7 @@ SensorExposure CommandSetGl646::led_calibration(Genesys_Device* dev, const Genes // colors * bytes_per_color * scan lines unsigned total_size = pixels * channels * 2 * 1; - std::vector<uint8_t> line(total_size); + std::vector<std::uint8_t> line(total_size); /* we try to get equal bright leds here: @@ -2022,13 +2023,12 @@ SensorExposure CommandSetGl646::led_calibration(Genesys_Device* dev, const Genes /** * average dark pixels of a scan */ -static int -dark_average (uint8_t * data, unsigned int pixels, unsigned int lines, - unsigned int channels, unsigned int black) +static int dark_average(std::uint8_t * data, unsigned int pixels, unsigned int lines, + unsigned int channels, unsigned int black) { unsigned int i, j, k, average, count; unsigned int avg[3]; - uint8_t val; + std::uint8_t val; /* computes average value on black margin */ for (k = 0; k < channels; k++) @@ -2110,7 +2110,7 @@ static void ad_fe_offset_calibration(Genesys_Device* dev, const Genesys_Sensor& dev->frontend.set_gain(1, 0); dev->frontend.set_gain(2, 0); - std::vector<uint8_t> line; + std::vector<std::uint8_t> line; /* scan with no move */ bottom = 1; @@ -2231,7 +2231,7 @@ void CommandSetGl646::offset_calibration(Genesys_Device* dev, const Genesys_Sens dev->frontend.set_offset(1, bottom); dev->frontend.set_offset(2, bottom); - std::vector<uint8_t> first_line, second_line; + std::vector<std::uint8_t> first_line, second_line; dev->cmd_set->init_regs_for_scan_session(dev, sensor, &dev->reg, session); simple_scan(dev, calib_sensor, session, false, first_line, "offset_first_line"); @@ -2383,7 +2383,7 @@ void CommandSetGl646::coarse_gain_calibration(Genesys_Device* dev, const Genesys unsigned pass = 0; - std::vector<uint8_t> line; + std::vector<std::uint8_t> line; /* loop until each channel raises to acceptable level */ while (((average[0] < calib_sensor.gain_white_ref) || @@ -2512,8 +2512,8 @@ void CommandSetGl646::init(Genesys_Device* dev) const DBG_INIT(); DBG_HELPER(dbg); - uint8_t val = 0; - uint32_t addr = 0xdead; + std::uint8_t val = 0; + std::uint32_t addr = 0xdead; size_t len; // to detect real power up condition, we write to REG_0x41 with pwrbit set, then read it back. @@ -2643,7 +2643,7 @@ void CommandSetGl646::init(Genesys_Device* dev) const static void simple_scan(Genesys_Device* dev, const Genesys_Sensor& sensor, const ScanSession& session, bool move, - std::vector<uint8_t>& data, const char* scan_identifier) + std::vector<std::uint8_t>& data, const char* scan_identifier) { unsigned lines = session.output_line_count; if (!dev->model->is_cis) { @@ -2695,7 +2695,7 @@ static void simple_scan(Genesys_Device* dev, const Genesys_Sensor& sensor, if (dev->model->is_cis && session.params.scan_mode == ScanColorMode::COLOR_SINGLE_PASS) { auto pixels_count = session.params.pixels; - std::vector<uint8_t> buffer(pixels_count * 3 * bpp); + std::vector<std::uint8_t> buffer(pixels_count * 3 * bpp); if (bpp == 1) { for (unsigned y = 0; y < lines; y++) { @@ -2738,7 +2738,7 @@ void CommandSetGl646::update_hardware_sensors(Genesys_Scanner* session) const { DBG_HELPER(dbg); Genesys_Device *dev = session->dev; - uint8_t value; + std::uint8_t value; // do what is needed to get a new set of events, but try to not loose any of them. gl646_gpio_read(dev->interface->get_usb_device(), &value); @@ -2858,8 +2858,8 @@ void CommandSetGl646::update_home_sensor_gpio(Genesys_Device& dev) const static void write_control(Genesys_Device* dev, const Genesys_Sensor& sensor, int resolution) { DBG_HELPER(dbg); - uint8_t control[4]; - uint32_t addr = 0xdead; + std::uint8_t control[4]; + std::uint32_t addr = 0xdead; /* 2300 does not write to 'control' */ if (dev->model->motor_id == MotorId::HP2300) { diff --git a/backend/genesys/gl646.h b/backend/genesys/gl646.h index 04e5fb2..5bbcfb2 100644 --- a/backend/genesys/gl646.h +++ b/backend/genesys/gl646.h @@ -50,7 +50,7 @@ public: Genesys_Register_Set* reg, const ScanSession& session) const override; - void set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t set) const override; + void set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, std::uint8_t set) const override; void set_powersaving(Genesys_Device* dev, int delay) const override; void save_power(Genesys_Device* dev, bool enable) const override; @@ -84,7 +84,7 @@ public: void eject_document(Genesys_Device* dev) const override; - void send_shading_data(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t* data, + void send_shading_data(Genesys_Device* dev, const Genesys_Sensor& sensor, std::uint8_t* data, int size) const override; bool has_send_shading_data() const override diff --git a/backend/genesys/gl841.cpp b/backend/genesys/gl841.cpp index 27a6a36..3b068d1 100644 --- a/backend/genesys/gl841.cpp +++ b/backend/genesys/gl841.cpp @@ -288,7 +288,7 @@ gl841_init_registers (Genesys_Device * dev) } } -static void gl841_set_lide80_fe(Genesys_Device* dev, uint8_t set) +static void gl841_set_lide80_fe(Genesys_Device* dev, std::uint8_t set) { DBG_HELPER(dbg); @@ -311,7 +311,7 @@ static void gl841_set_lide80_fe(Genesys_Device* dev, uint8_t set) } // Set values of Analog Device type frontend -static void gl841_set_ad_fe(Genesys_Device* dev, uint8_t set) +static void gl841_set_ad_fe(Genesys_Device* dev, std::uint8_t set) { DBG_HELPER(dbg); int i; @@ -361,7 +361,8 @@ static void gl841_set_ad_fe(Genesys_Device* dev, uint8_t set) } // Set values of analog frontend -void CommandSetGl841::set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t set) const +void CommandSetGl841::set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, + std::uint8_t set) const { DBG_HELPER_ARGS(dbg, "%s", set == AFE_INIT ? "init" : set == AFE_SET ? "set" : @@ -369,7 +370,7 @@ void CommandSetGl841::set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, (void) sensor; /* Analog Device type frontend */ - uint8_t frontend_type = dev->reg.find_reg(0x04).value & REG_0x04_FESET; + std::uint8_t frontend_type = dev->reg.find_reg(0x04).value & REG_0x04_FESET; if (frontend_type == 0x02) { gl841_set_ad_fe(dev, set); @@ -453,12 +454,68 @@ static void gl841_write_freq(Genesys_Device* dev, unsigned int ydpi) { DBG_HELPER(dbg); /**< fast table */ -uint8_t tdefault[] = {0x18,0x36,0x18,0x36,0x18,0x36,0x18,0x36,0x18,0x36,0x18,0x36,0x18,0x36,0x18,0x36,0x18,0x36,0x18,0x36,0x18,0x36,0x18,0x36,0x18,0x36,0x18,0x36,0x18,0x36,0x18,0x36,0x18,0xb6,0x18,0xb6,0x18,0xb6,0x18,0xb6,0x18,0xb6,0x18,0xb6,0x18,0xb6,0x18,0xb6,0x18,0xb6,0x18,0xb6,0x18,0xb6,0x18,0xb6,0x18,0xb6,0x18,0xb6,0x18,0xb6,0x18,0xb6,0x18,0xf6,0x18,0xf6,0x18,0xf6,0x18,0xf6,0x18,0xf6,0x18,0xf6,0x18,0xf6,0x18,0xf6,0x18,0xf6,0x18,0xf6,0x18,0xf6,0x18,0xf6,0x18,0xf6,0x18,0xf6,0x18,0xf6,0x18,0xf6,0x18,0x76,0x18,0x76,0x18,0x76,0x18,0x76,0x18,0x76,0x18,0x76,0x18,0x76,0x18,0x76,0x18,0x76,0x18,0x76,0x18,0x76,0x18,0x76,0x18,0x76,0x18,0x76,0x18,0x76,0x18,0x76}; -uint8_t t1200[] = {0xc7,0x31,0xc7,0x31,0xc7,0x31,0xc7,0x31,0xc7,0x31,0xc7,0x31,0xc7,0x31,0xc7,0x31,0xc0,0x11,0xc0,0x11,0xc0,0x11,0xc0,0x11,0xc0,0x11,0xc0,0x11,0xc0,0x11,0xc0,0x11,0xc7,0xb1,0xc7,0xb1,0xc7,0xb1,0xc7,0xb1,0xc7,0xb1,0xc7,0xb1,0xc7,0xb1,0xc7,0xb1,0x07,0xe0,0x07,0xe0,0x07,0xe0,0x07,0xe0,0x07,0xe0,0x07,0xe0,0x07,0xe0,0x07,0xe0,0xc7,0xf1,0xc7,0xf1,0xc7,0xf1,0xc7,0xf1,0xc7,0xf1,0xc7,0xf1,0xc7,0xf1,0xc7,0xf1,0xc0,0x51,0xc0,0x51,0xc0,0x51,0xc0,0x51,0xc0,0x51,0xc0,0x51,0xc0,0x51,0xc0,0x51,0xc7,0x71,0xc7,0x71,0xc7,0x71,0xc7,0x71,0xc7,0x71,0xc7,0x71,0xc7,0x71,0xc7,0x71,0x07,0x20,0x07,0x20,0x07,0x20,0x07,0x20,0x07,0x20,0x07,0x20,0x07,0x20,0x07,0x20}; -uint8_t t300[] = {0x08,0x32,0x08,0x32,0x08,0x32,0x08,0x32,0x08,0x32,0x08,0x32,0x08,0x32,0x08,0x32,0x00,0x13,0x00,0x13,0x00,0x13,0x00,0x13,0x00,0x13,0x00,0x13,0x00,0x13,0x00,0x13,0x08,0xb2,0x08,0xb2,0x08,0xb2,0x08,0xb2,0x08,0xb2,0x08,0xb2,0x08,0xb2,0x08,0xb2,0x0c,0xa0,0x0c,0xa0,0x0c,0xa0,0x0c,0xa0,0x0c,0xa0,0x0c,0xa0,0x0c,0xa0,0x0c,0xa0,0x08,0xf2,0x08,0xf2,0x08,0xf2,0x08,0xf2,0x08,0xf2,0x08,0xf2,0x08,0xf2,0x08,0xf2,0x00,0xd3,0x00,0xd3,0x00,0xd3,0x00,0xd3,0x00,0xd3,0x00,0xd3,0x00,0xd3,0x00,0xd3,0x08,0x72,0x08,0x72,0x08,0x72,0x08,0x72,0x08,0x72,0x08,0x72,0x08,0x72,0x08,0x72,0x0c,0x60,0x0c,0x60,0x0c,0x60,0x0c,0x60,0x0c,0x60,0x0c,0x60,0x0c,0x60,0x0c,0x60}; -uint8_t t150[] = {0x0c,0x33,0xcf,0x33,0xcf,0x33,0xcf,0x33,0xcf,0x33,0xcf,0x33,0xcf,0x33,0xcf,0x33,0x40,0x14,0x80,0x15,0x80,0x15,0x80,0x15,0x80,0x15,0x80,0x15,0x80,0x15,0x80,0x15,0x0c,0xb3,0xcf,0xb3,0xcf,0xb3,0xcf,0xb3,0xcf,0xb3,0xcf,0xb3,0xcf,0xb3,0xcf,0xb3,0x11,0xa0,0x16,0xa0,0x16,0xa0,0x16,0xa0,0x16,0xa0,0x16,0xa0,0x16,0xa0,0x16,0xa0,0x0c,0xf3,0xcf,0xf3,0xcf,0xf3,0xcf,0xf3,0xcf,0xf3,0xcf,0xf3,0xcf,0xf3,0xcf,0xf3,0x40,0xd4,0x80,0xd5,0x80,0xd5,0x80,0xd5,0x80,0xd5,0x80,0xd5,0x80,0xd5,0x80,0xd5,0x0c,0x73,0xcf,0x73,0xcf,0x73,0xcf,0x73,0xcf,0x73,0xcf,0x73,0xcf,0x73,0xcf,0x73,0x11,0x60,0x16,0x60,0x16,0x60,0x16,0x60,0x16,0x60,0x16,0x60,0x16,0x60,0x16,0x60}; - -uint8_t *table; + std::uint8_t tdefault[] = { + 0x18, 0x36, 0x18, 0x36, 0x18, 0x36, 0x18, 0x36, 0x18, 0x36, + 0x18, 0x36, 0x18, 0x36, 0x18, 0x36, 0x18, 0x36, 0x18, 0x36, + 0x18, 0x36, 0x18, 0x36, 0x18, 0x36, 0x18, 0x36, 0x18, 0x36, + 0x18, 0x36, 0x18, 0xb6, 0x18, 0xb6, 0x18, 0xb6, 0x18, 0xb6, + 0x18, 0xb6, 0x18, 0xb6, 0x18, 0xb6, 0x18, 0xb6, 0x18, 0xb6, + 0x18, 0xb6, 0x18, 0xb6, 0x18, 0xb6, 0x18, 0xb6, 0x18, 0xb6, + 0x18, 0xb6, 0x18, 0xb6, 0x18, 0xf6, 0x18, 0xf6, 0x18, 0xf6, + 0x18, 0xf6, 0x18, 0xf6, 0x18, 0xf6, 0x18, 0xf6, 0x18, 0xf6, + 0x18, 0xf6, 0x18, 0xf6, 0x18, 0xf6, 0x18, 0xf6, 0x18, 0xf6, + 0x18, 0xf6, 0x18, 0xf6, 0x18, 0xf6, 0x18, 0x76, 0x18, 0x76, + 0x18, 0x76, 0x18, 0x76, 0x18, 0x76, 0x18, 0x76, 0x18, 0x76, + 0x18, 0x76, 0x18, 0x76, 0x18, 0x76, 0x18, 0x76, 0x18, 0x76, + 0x18, 0x76, 0x18, 0x76, 0x18, 0x76, 0x18, 0x76 + }; + std::uint8_t t1200[] = { + 0xc7, 0x31, 0xc7, 0x31, 0xc7, 0x31, 0xc7, 0x31, 0xc7, 0x31, + 0xc7, 0x31, 0xc7, 0x31, 0xc7, 0x31, 0xc0, 0x11, 0xc0, 0x11, + 0xc0, 0x11, 0xc0, 0x11, 0xc0, 0x11, 0xc0, 0x11, 0xc0, 0x11, + 0xc0, 0x11, 0xc7, 0xb1, 0xc7, 0xb1, 0xc7, 0xb1, 0xc7, 0xb1, + 0xc7, 0xb1, 0xc7, 0xb1, 0xc7, 0xb1, 0xc7, 0xb1, 0x07, 0xe0, + 0x07, 0xe0, 0x07, 0xe0, 0x07, 0xe0, 0x07, 0xe0, 0x07, 0xe0, + 0x07, 0xe0, 0x07, 0xe0, 0xc7, 0xf1, 0xc7, 0xf1, 0xc7, 0xf1, + 0xc7, 0xf1, 0xc7, 0xf1, 0xc7, 0xf1, 0xc7, 0xf1, 0xc7, 0xf1, + 0xc0, 0x51, 0xc0, 0x51, 0xc0, 0x51, 0xc0, 0x51, 0xc0, 0x51, + 0xc0, 0x51, 0xc0, 0x51, 0xc0, 0x51, 0xc7, 0x71, 0xc7, 0x71, + 0xc7, 0x71, 0xc7, 0x71, 0xc7, 0x71, 0xc7, 0x71, 0xc7, 0x71, + 0xc7, 0x71, 0x07, 0x20, 0x07, 0x20, 0x07, 0x20, 0x07, 0x20, + 0x07, 0x20, 0x07, 0x20, 0x07, 0x20, 0x07, 0x20 + }; + std::uint8_t t300[] = { + 0x08, 0x32, 0x08, 0x32, 0x08, 0x32, 0x08, 0x32, 0x08, 0x32, + 0x08, 0x32, 0x08, 0x32, 0x08, 0x32, 0x00, 0x13, 0x00, 0x13, + 0x00, 0x13, 0x00, 0x13, 0x00, 0x13, 0x00, 0x13, 0x00, 0x13, + 0x00, 0x13, 0x08, 0xb2, 0x08, 0xb2, 0x08, 0xb2, 0x08, 0xb2, + 0x08, 0xb2, 0x08, 0xb2, 0x08, 0xb2, 0x08, 0xb2, 0x0c, 0xa0, + 0x0c, 0xa0, 0x0c, 0xa0, 0x0c, 0xa0, 0x0c, 0xa0, 0x0c, 0xa0, + 0x0c, 0xa0, 0x0c, 0xa0, 0x08, 0xf2, 0x08, 0xf2, 0x08, 0xf2, + 0x08, 0xf2, 0x08, 0xf2, 0x08, 0xf2, 0x08, 0xf2, 0x08, 0xf2, + 0x00, 0xd3, 0x00, 0xd3, 0x00, 0xd3, 0x00, 0xd3, 0x00, 0xd3, + 0x00, 0xd3, 0x00, 0xd3, 0x00, 0xd3, 0x08, 0x72, 0x08, 0x72, + 0x08, 0x72, 0x08, 0x72, 0x08, 0x72, 0x08, 0x72, 0x08, 0x72, + 0x08, 0x72, 0x0c, 0x60, 0x0c, 0x60, 0x0c, 0x60, 0x0c, 0x60, + 0x0c, 0x60, 0x0c, 0x60, 0x0c, 0x60, 0x0c, 0x60 + }; + std::uint8_t t150[] = { + 0x0c, 0x33, 0xcf, 0x33, 0xcf, 0x33, 0xcf, 0x33, 0xcf, 0x33, + 0xcf, 0x33, 0xcf, 0x33, 0xcf, 0x33, 0x40, 0x14, 0x80, 0x15, + 0x80, 0x15, 0x80, 0x15, 0x80, 0x15, 0x80, 0x15, 0x80, 0x15, + 0x80, 0x15, 0x0c, 0xb3, 0xcf, 0xb3, 0xcf, 0xb3, 0xcf, 0xb3, + 0xcf, 0xb3, 0xcf, 0xb3, 0xcf, 0xb3, 0xcf, 0xb3, 0x11, 0xa0, + 0x16, 0xa0, 0x16, 0xa0, 0x16, 0xa0, 0x16, 0xa0, 0x16, 0xa0, + 0x16, 0xa0, 0x16, 0xa0, 0x0c, 0xf3, 0xcf, 0xf3, 0xcf, 0xf3, + 0xcf, 0xf3, 0xcf, 0xf3, 0xcf, 0xf3, 0xcf, 0xf3, 0xcf, 0xf3, + 0x40, 0xd4, 0x80, 0xd5, 0x80, 0xd5, 0x80, 0xd5, 0x80, 0xd5, + 0x80, 0xd5, 0x80, 0xd5, 0x80, 0xd5, 0x0c, 0x73, 0xcf, 0x73, + 0xcf, 0x73, 0xcf, 0x73, 0xcf, 0x73, 0xcf, 0x73, 0xcf, 0x73, + 0xcf, 0x73, 0x11, 0x60, 0x16, 0x60, 0x16, 0x60, 0x16, 0x60, + 0x16, 0x60, 0x16, 0x60, 0x16, 0x60, 0x16, 0x60 + }; + + std::uint8_t *table; if(dev->model->motor_id == MotorId::CANON_LIDE_80) { switch(ydpi) @@ -495,7 +552,7 @@ static void gl841_init_motor_regs_feed(Genesys_Device* dev, const Genesys_Sensor /*number of scan lines to add in a scan_lines line*/ { - std::vector<uint16_t> table; + std::vector<std::uint16_t> table; table.resize(256, 0xffff); scanner_send_slope_table(dev, sensor, 0, table); @@ -711,6 +768,7 @@ static void gl841_init_optical_regs_scan(Genesys_Device* dev, const Genesys_Sens const ScanSession& session) { DBG_HELPER_ARGS(dbg, "exposure_time=%d", exposure_time); + dev->cmd_set->set_fe(dev, sensor, AFE_SET); /* gpio part.*/ @@ -920,7 +978,7 @@ dummy \ scanned lines dev->session = session; dev->total_bytes_read = 0; - dev->total_bytes_to_read = session.output_line_bytes_requested * session.params.lines; + dev->total_bytes_to_read = (size_t)session.output_line_bytes_requested * (size_t)session.params.lines; if (session.use_host_side_gray) { dev->total_bytes_to_read /= 3; } @@ -998,7 +1056,7 @@ void CommandSetGl841::save_power(Genesys_Device* dev, bool enable) const /* final state: GPIO8 disabled, GPIO9 enabled, GPIO17 disabled, GPIO18 disabled*/ - uint8_t val = dev->interface->read_register(REG_0x6D); + std::uint8_t val = dev->interface->read_register(REG_0x6D); dev->interface->write_register(REG_0x6D, val | 0x80); dev->interface->sleep_ms(1); @@ -1023,7 +1081,7 @@ void CommandSetGl841::save_power(Genesys_Device* dev, bool enable) const } if (dev->model->gpio_id == GpioId::DP685) { - uint8_t val = dev->interface->read_register(REG_0x6B); + std::uint8_t val = dev->interface->read_register(REG_0x6B); dev->interface->write_register(REG_0x6B, val & ~REG_0x6B_GPO17); dev->reg.find_reg(0x6b).value &= ~REG_0x6B_GPO17; dev->initial_regs.find_reg(0x6b).value &= ~REG_0x6B_GPO17; @@ -1041,7 +1099,7 @@ void CommandSetGl841::save_power(Genesys_Device* dev, bool enable) const /* final state: GPIO8 enabled, GPIO9 disabled, GPIO17 enabled, GPIO18 enabled*/ - uint8_t val = dev->interface->read_register(REG_0x6D); + std::uint8_t val = dev->interface->read_register(REG_0x6D); dev->interface->write_register(REG_0x6D, val | 0x80); dev->interface->sleep_ms(10); @@ -1070,7 +1128,7 @@ void CommandSetGl841::save_power(Genesys_Device* dev, bool enable) const if (dev->model->gpio_id == GpioId::DP665 || dev->model->gpio_id == GpioId::DP685) { - uint8_t val = dev->interface->read_register(REG_0x6B); + std::uint8_t val = dev->interface->read_register(REG_0x6B); dev->interface->write_register(REG_0x6B, val | REG_0x6B_GPO17); dev->reg.find_reg(0x6b).value |= REG_0x6B_GPO17; dev->initial_regs.find_reg(0x6b).value |= REG_0x6B_GPO17; @@ -1147,7 +1205,7 @@ static bool gl841_get_paper_sensor(Genesys_Device* dev) { DBG_HELPER(dbg); - uint8_t val = dev->interface->read_register(REG_0x6D); + std::uint8_t val = dev->interface->read_register(REG_0x6D); return (val & 0x1) == 0; } @@ -1365,7 +1423,7 @@ void CommandSetGl841::begin_scan(Genesys_Device* dev, const Genesys_Sensor& sens (void) sensor; // FIXME: SEQUENTIAL not really needed in this case Genesys_Register_Set local_reg(Genesys_Register_Set::SEQUENTIAL); - uint8_t val; + std::uint8_t val; if (dev->model->gpio_id == GpioId::CANON_LIDE_80) { val = dev->interface->read_register(REG_0x6B); @@ -1476,10 +1534,7 @@ void CommandSetGl841::send_gamma_table(Genesys_Device* dev, const Genesys_Sensor size = 256; - /* allocate temporary gamma tables: 16 bits words, 3 channels */ - std::vector<uint8_t> gamma(size * 2 * 3); - - sanei_genesys_generate_gamma_buffer(dev, sensor, 16, 65535, size, gamma.data()); + auto gamma = generate_gamma_buffer(dev, sensor, 16, 65535, size); dev->interface->write_gamma(0x28, 0x0000, gamma.data(), size * 2 * 3); } @@ -1549,7 +1604,7 @@ static void ad_fe_offset_calibration(Genesys_Device* dev, const Genesys_Sensor& // FIXME: we're reading twice as much data for no reason std::size_t total_size = session.output_line_bytes * 2; - std::vector<uint8_t> line(total_size); + std::vector<std::uint8_t> line(total_size); dev->frontend.set_gain(0, 0); dev->frontend.set_gain(1, 0); @@ -2029,10 +2084,9 @@ void CommandSetGl841::init(Genesys_Device* dev) const void CommandSetGl841::update_hardware_sensors(Genesys_Scanner* s) const { DBG_HELPER(dbg); - /* do what is needed to get a new set of events, but try to not lose - any of them. - */ - uint8_t val; + + // do what is needed to get a new set of events, but try to not lose any of them. + std::uint8_t val; if (s->dev->model->gpio_id == GpioId::CANON_LIDE_35 || s->dev->model->gpio_id == GpioId::CANON_LIDE_80) @@ -2060,11 +2114,10 @@ void CommandSetGl841::update_hardware_sensors(Genesys_Scanner* s) const * for all the channels. */ void CommandSetGl841::send_shading_data(Genesys_Device* dev, const Genesys_Sensor& sensor, - uint8_t* data, int size) const + std::uint8_t* data, int size) const { DBG_HELPER_ARGS(dbg, "writing %d bytes of shading data", size); - uint32_t length, x, pixels, i; - uint8_t *ptr,*src; + std::uint32_t length, x, pixels, i; /* old method if no SHDAREA */ if ((dev->reg.find_reg(0x01).value & REG_0x01_SHDAREA) == 0) { @@ -2094,7 +2147,7 @@ void CommandSetGl841::send_shading_data(Genesys_Device* dev, const Genesys_Senso DBG(DBG_io2, "%s: using chunks of %d bytes (%d shading data pixels)\n", __func__, length, length/4); - std::vector<uint8_t> buffer(pixels, 0); + std::vector<std::uint8_t> buffer(pixels, 0); /* write actual shading data contigously * channel by channel, starting at addr 0x0000 @@ -2103,14 +2156,14 @@ void CommandSetGl841::send_shading_data(Genesys_Device* dev, const Genesys_Senso { /* copy data to work buffer and process it */ /* coefficient destination */ - ptr=buffer.data(); + std::uint8_t* ptr = buffer.data(); /* iterate on both sensor segment, data has been averaged, * so is in the right order and we only have to copy it */ for(x=0;x<pixels;x+=4) { /* coefficient source */ - src = data + x + beginpixel + i * length; + std::uint8_t* src = data + x + beginpixel + i * length; ptr[0]=src[0]; ptr[1]=src[1]; ptr[2]=src[2]; diff --git a/backend/genesys/gl841.h b/backend/genesys/gl841.h index 64b23c8..2bdc3cc 100644 --- a/backend/genesys/gl841.h +++ b/backend/genesys/gl841.h @@ -46,7 +46,7 @@ public: Genesys_Register_Set* reg, const ScanSession& session) const override; - void set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t set) const override; + void set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, std::uint8_t set) const override; void set_powersaving(Genesys_Device* dev, int delay) const override; void save_power(Genesys_Device* dev, bool enable) const override; @@ -80,7 +80,7 @@ public: void eject_document(Genesys_Device* dev) const override; - void send_shading_data(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t* data, + void send_shading_data(Genesys_Device* dev, const Genesys_Sensor& sensor, std::uint8_t* data, int size) const override; ScanSession calculate_scan_session(const Genesys_Device* dev, diff --git a/backend/genesys/gl842.cpp b/backend/genesys/gl842.cpp index a593040..9663799 100644 --- a/backend/genesys/gl842.cpp +++ b/backend/genesys/gl842.cpp @@ -223,7 +223,8 @@ static void gl842_init_registers(Genesys_Device& dev) } // Set values of analog frontend -void CommandSetGl842::set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t set) const +void CommandSetGl842::set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, + std::uint8_t set) const { DBG_HELPER_ARGS(dbg, "%s", set == AFE_INIT ? "init" : set == AFE_SET ? "set" : @@ -236,7 +237,7 @@ void CommandSetGl842::set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, // check analog frontend type // FIXME: looks like we write to that register with initial data - uint8_t fe_type = dev->interface->read_register(REG_0x04) & REG_0x04_FESET; + std::uint8_t fe_type = dev->interface->read_register(REG_0x04) & REG_0x04_FESET; if (fe_type == 2 || dev->model->model_id == ModelId::CANON_LIDE_90) { for (const auto& reg : dev->frontend.regs) { dev->interface->write_fe_register(reg.address, reg.value); @@ -568,7 +569,7 @@ void CommandSetGl842::init_regs_for_scan_session(Genesys_Device* dev, const Gene dev->session = session; dev->total_bytes_read = 0; - dev->total_bytes_to_read = session.output_line_bytes_requested * session.params.lines; + dev->total_bytes_to_read = (size_t)session.output_line_bytes_requested * (size_t)session.params.lines; } ScanSession CommandSetGl842::calculate_scan_session(const Genesys_Device* dev, @@ -841,11 +842,11 @@ void CommandSetGl842::send_gamma_table(Genesys_Device* dev, const Genesys_Sensor unsigned size = 256; - std::vector<uint8_t> gamma(size * 2 * 3); + std::vector<std::uint8_t> gamma(size * 2 * 3); - std::vector<uint16_t> rgamma = get_gamma_table(dev, sensor, GENESYS_RED); - std::vector<uint16_t> ggamma = get_gamma_table(dev, sensor, GENESYS_GREEN); - std::vector<uint16_t> bgamma = get_gamma_table(dev, sensor, GENESYS_BLUE); + std::vector<std::uint16_t> rgamma = get_gamma_table(dev, sensor, GENESYS_RED); + std::vector<std::uint16_t> ggamma = get_gamma_table(dev, sensor, GENESYS_GREEN); + std::vector<std::uint16_t> bgamma = get_gamma_table(dev, sensor, GENESYS_BLUE); // copy sensor specific's gamma tables for (unsigned i = 0; i < size; i++) { @@ -951,7 +952,7 @@ void CommandSetGl842::asic_boot(Genesys_Device* dev, bool cold) const dev->interface->write_registers(dev->reg); if (dev->model->model_id == ModelId::PLUSTEK_OPTICFILM_7200) { - uint8_t data[32] = { + std::uint8_t data[32] = { 0xd0, 0x38, 0x07, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -1006,7 +1007,7 @@ void CommandSetGl842::update_home_sensor_gpio(Genesys_Device& dev) const * for all the channels. */ void CommandSetGl842::send_shading_data(Genesys_Device* dev, const Genesys_Sensor& sensor, - uint8_t* data, int size) const + std::uint8_t* data, int size) const { DBG_HELPER(dbg); @@ -1032,7 +1033,7 @@ void CommandSetGl842::send_shading_data(Genesys_Device* dev, const Genesys_Senso dev->interface->record_key_value("shading_offset", std::to_string(offset)); dev->interface->record_key_value("shading_length", std::to_string(length)); - std::vector<uint8_t> final_data(length, 0); + std::vector<std::uint8_t> final_data(length, 0); unsigned count = 0; if (offset < 0) { diff --git a/backend/genesys/gl842.h b/backend/genesys/gl842.h index 3636bac..7a60819 100644 --- a/backend/genesys/gl842.h +++ b/backend/genesys/gl842.h @@ -46,7 +46,7 @@ public: Genesys_Register_Set* reg, const ScanSession& session) const override; - void set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t set) const override; + void set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, std::uint8_t set) const override; void set_powersaving(Genesys_Device* dev, int delay) const override; void save_power(Genesys_Device* dev, bool enable) const override; @@ -80,7 +80,7 @@ public: void eject_document(Genesys_Device* dev) const override; - void send_shading_data(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t* data, + void send_shading_data(Genesys_Device* dev, const Genesys_Sensor& sensor, std::uint8_t* data, int size) const override; ScanSession calculate_scan_session(const Genesys_Device* dev, diff --git a/backend/genesys/gl843.cpp b/backend/genesys/gl843.cpp index 6180bf9..c2f4b52 100644 --- a/backend/genesys/gl843.cpp +++ b/backend/genesys/gl843.cpp @@ -597,7 +597,7 @@ gl843_init_registers (Genesys_Device * dev) } if (dev->model->model_id == ModelId::PLUSTEK_OPTICFILM_7200I) { - uint8_t data[32] = { + std::uint8_t data[32] = { 0x8c, 0x8f, 0xc9, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -616,7 +616,8 @@ static void gl843_set_ad_fe(Genesys_Device* dev) } // Set values of analog frontend -void CommandSetGl843::set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t set) const +void CommandSetGl843::set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, + std::uint8_t set) const { DBG_HELPER_ARGS(dbg, "%s", set == AFE_INIT ? "init" : set == AFE_SET ? "set" : @@ -629,7 +630,7 @@ void CommandSetGl843::set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, // check analog frontend type // FIXME: looks like we write to that register with initial data - uint8_t fe_type = dev->interface->read_register(REG_0x04) & REG_0x04_FESET; + std::uint8_t fe_type = dev->interface->read_register(REG_0x04) & REG_0x04_FESET; if (fe_type == 2) { gl843_set_ad_fe(dev); return; @@ -1041,7 +1042,7 @@ void CommandSetGl843::init_regs_for_scan_session(Genesys_Device* dev, const Gene dev->session = session; dev->total_bytes_read = 0; - dev->total_bytes_to_read = session.output_line_bytes_requested * session.params.lines; + dev->total_bytes_to_read = (size_t)session.output_line_bytes_requested * (size_t)session.params.lines; DBG(DBG_info, "%s: total bytes to send = %zu\n", __func__, dev->total_bytes_to_read); } @@ -1120,7 +1121,7 @@ void CommandSetGl843::save_power(Genesys_Device* dev, bool enable) const // switch KV-SS080 lamp off if (dev->model->gpio_id == GpioId::KVSS080) { - uint8_t val = dev->interface->read_register(REG_0x6C); + std::uint8_t val = dev->interface->read_register(REG_0x6C); if (enable) { val &= 0xef; } else { @@ -1140,7 +1141,7 @@ static bool gl843_get_paper_sensor(Genesys_Device* dev) { DBG_HELPER(dbg); - uint8_t val = dev->interface->read_register(REG_0x6D); + std::uint8_t val = dev->interface->read_register(REG_0x6D); return (val & 0x1) == 0; } @@ -1283,7 +1284,7 @@ void CommandSetGl843::begin_scan(Genesys_Device* dev, const Genesys_Sensor& sens scanner_clear_scan_and_feed_counts(*dev); // enable scan and motor - uint8_t val = dev->interface->read_register(REG_0x01); + std::uint8_t val = dev->interface->read_register(REG_0x01); val |= REG_0x01_SCAN; dev->interface->write_register(REG_0x01, val); @@ -1436,11 +1437,11 @@ void CommandSetGl843::send_gamma_table(Genesys_Device* dev, const Genesys_Sensor size = 256; /* allocate temporary gamma tables: 16 bits words, 3 channels */ - std::vector<uint8_t> gamma(size * 2 * 3); + std::vector<std::uint8_t> gamma(size * 2 * 3); - std::vector<uint16_t> rgamma = get_gamma_table(dev, sensor, GENESYS_RED); - std::vector<uint16_t> ggamma = get_gamma_table(dev, sensor, GENESYS_GREEN); - std::vector<uint16_t> bgamma = get_gamma_table(dev, sensor, GENESYS_BLUE); + std::vector<std::uint16_t> rgamma = get_gamma_table(dev, sensor, GENESYS_RED); + std::vector<std::uint16_t> ggamma = get_gamma_table(dev, sensor, GENESYS_GREEN); + std::vector<std::uint16_t> bgamma = get_gamma_table(dev, sensor, GENESYS_BLUE); // copy sensor specific's gamma tables for (i = 0; i < size; i++) { @@ -1553,7 +1554,7 @@ static void gl843_init_gpio(Genesys_Device* dev) void CommandSetGl843::asic_boot(Genesys_Device* dev, bool cold) const { DBG_HELPER(dbg); - uint8_t val; + std::uint8_t val; if (cold) { dev->interface->write_register(0x0e, 0x01); @@ -1665,7 +1666,7 @@ void CommandSetGl843::update_hardware_sensors(Genesys_Scanner* s) const any of them. */ - uint8_t val = s->dev->interface->read_register(REG_0x6D); + std::uint8_t val = s->dev->interface->read_register(REG_0x6D); DBG(DBG_io, "%s: read buttons_gpio value=0x%x\n", __func__, (int)val); switch (s->dev->model->gpio_id) @@ -1685,8 +1686,21 @@ void CommandSetGl843::update_hardware_sensors(Genesys_Scanner* s) const s->buttons[BUTTON_TRANSP_SW].write((val & 0x40) == 0); s->buttons[BUTTON_SCAN_SW].write((val & 0x08) == 0); break; - case GpioId::CANON_4400F: case GpioId::CANON_8400F: + s->buttons[BUTTON_COPY_SW].write((val & 0x01) == 0); + s->buttons[BUTTON_SCAN_SW].write((val & 0x02) == 0); + s->buttons[BUTTON_FILE_SW].write((val & 0x04) == 0); + s->buttons[BUTTON_EMAIL_SW].write((val & 0x08) == 0); + break; + case GpioId::CANON_4400F: + s->buttons[BUTTON_COPY_SW].write((val & 0x68) == 0x28); + s->buttons[BUTTON_TRANSP_SW].write((val & 0x68) == 0x20); + s->buttons[BUTTON_EMAIL_SW].write((val & 0x68) == 0x08); + s->buttons[BUTTON_PDF1_SW].write((val & 0x68) == 0x00); + s->buttons[BUTTON_PDF2_SW].write((val & 0x68) == 0x60); + s->buttons[BUTTON_PDF3_SW].write((val & 0x68) == 0x48); + s->buttons[BUTTON_PDF4_SW].write((val & 0x68) == 0x40); + break; default: break; } @@ -1703,11 +1717,10 @@ void CommandSetGl843::update_home_sensor_gpio(Genesys_Device& dev) const * for all the channels. */ void CommandSetGl843::send_shading_data(Genesys_Device* dev, const Genesys_Sensor& sensor, - uint8_t* data, int size) const + std::uint8_t* data, int size) const { DBG_HELPER(dbg); - uint32_t final_size, i; - uint8_t *buffer; + std::uint32_t final_size, i; int count; int offset = 0; @@ -1735,10 +1748,10 @@ void CommandSetGl843::send_shading_data(Genesys_Device* dev, const Genesys_Senso /* compute and allocate size for final data */ final_size = ((length+251) / 252) * 256; DBG(DBG_io, "%s: final shading size=%04x (length=%d)\n", __func__, final_size, length); - std::vector<uint8_t> final_data(final_size, 0); + std::vector<std::uint8_t> final_data(final_size, 0); /* copy regular shading data to the expected layout */ - buffer = final_data.data(); + std::uint8_t* buffer = final_data.data(); count = 0; if (offset < 0) { count += (-offset); diff --git a/backend/genesys/gl843.h b/backend/genesys/gl843.h index ac845bd..6012c36 100644 --- a/backend/genesys/gl843.h +++ b/backend/genesys/gl843.h @@ -46,7 +46,7 @@ public: Genesys_Register_Set* reg, const ScanSession& session) const override; - void set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t set) const override; + void set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, std::uint8_t set) const override; void set_powersaving(Genesys_Device* dev, int delay) const override; void save_power(Genesys_Device* dev, bool enable) const override; @@ -80,7 +80,7 @@ public: void eject_document(Genesys_Device* dev) const override; - void send_shading_data(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t* data, + void send_shading_data(Genesys_Device* dev, const Genesys_Sensor& sensor, std::uint8_t* data, int size) const override; ScanSession calculate_scan_session(const Genesys_Device* dev, diff --git a/backend/genesys/gl846.cpp b/backend/genesys/gl846.cpp index b427376..6db312a 100644 --- a/backend/genesys/gl846.cpp +++ b/backend/genesys/gl846.cpp @@ -284,7 +284,7 @@ gl846_init_registers (Genesys_Device * dev) /** * Set register values of Analog Device type frontend * */ -static void gl846_set_adi_fe(Genesys_Device* dev, uint8_t set) +static void gl846_set_adi_fe(Genesys_Device* dev, std::uint8_t set) { DBG_HELPER(dbg); int i; @@ -314,15 +314,16 @@ static void gl846_set_adi_fe(Genesys_Device* dev, uint8_t set) } // Set values of analog frontend -void CommandSetGl846::set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t set) const +void CommandSetGl846::set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, + std::uint8_t set) const { DBG_HELPER_ARGS(dbg, "%s", set == AFE_INIT ? "init" : set == AFE_SET ? "set" : set == AFE_POWER_SAVE ? "powersave" : "huh?"); (void) sensor; - /* route to specific analog frontend setup */ - uint8_t frontend_type = dev->reg.find_reg(0x04).value & REG_0x04_FESET; + // route to specific analog frontend setup + std::uint8_t frontend_type = dev->reg.find_reg(0x04).value & REG_0x04_FESET; switch (frontend_type) { case 0x02: /* ADI FE */ gl846_set_adi_fe(dev, set); @@ -658,7 +659,7 @@ void CommandSetGl846::init_regs_for_scan_session(Genesys_Device* dev, const Gene dev->session = session; dev->total_bytes_read = 0; - dev->total_bytes_to_read = session.output_line_bytes_requested * session.params.lines; + dev->total_bytes_to_read = (size_t)session.output_line_bytes_requested * (size_t)session.params.lines; DBG(DBG_info, "%s: total bytes to send = %zu\n", __func__, dev->total_bytes_to_read); } @@ -748,7 +749,6 @@ void CommandSetGl846::begin_scan(Genesys_Device* dev, const Genesys_Sensor& sens { DBG_HELPER(dbg); (void) sensor; - uint8_t val; if (reg->state.is_xpa_on && reg->state.is_lamp_on) { dev->cmd_set->set_xpa_lamp_power(*dev, true); @@ -756,7 +756,7 @@ void CommandSetGl846::begin_scan(Genesys_Device* dev, const Genesys_Sensor& sens scanner_clear_scan_and_feed_counts(*dev); - val = dev->interface->read_register(REG_0x01); + std::uint8_t val = dev->interface->read_register(REG_0x01); val |= REG_0x01_SCAN; dev->interface->write_register(REG_0x01, val); reg->set8(REG_0x01, val); @@ -862,11 +862,10 @@ void CommandSetGl846::init_regs_for_shading(Genesys_Device* dev, const Genesys_S * for all the channels. */ void CommandSetGl846::send_shading_data(Genesys_Device* dev, const Genesys_Sensor& sensor, - uint8_t* data, int size) const + std::uint8_t* data, int size) const { DBG_HELPER_ARGS(dbg, "writing %d bytes of shading data", size); std::uint32_t addr, i; - uint8_t val,*ptr,*src; unsigned length = static_cast<unsigned>(size / 3); @@ -884,7 +883,7 @@ void CommandSetGl846::send_shading_data(Genesys_Device* dev, const Genesys_Senso dev->interface->record_key_value("shading_length", std::to_string(length)); dev->interface->record_key_value("shading_factor", std::to_string(sensor.shading_factor)); - std::vector<uint8_t> buffer(pixels, 0); + std::vector<std::uint8_t> buffer(pixels, 0); DBG(DBG_io2, "%s: using chunks of %d (0x%04x) bytes\n", __func__, pixels, pixels); @@ -896,12 +895,12 @@ void CommandSetGl846::send_shading_data(Genesys_Device* dev, const Genesys_Senso { /* build up actual shading data by copying the part from the full width one * to the one corresponding to SHDAREA */ - ptr = buffer.data(); + std::uint8_t* ptr = buffer.data(); /* iterate on both sensor segment */ for (unsigned x = 0; x < pixels; x += 4 * sensor.shading_factor) { // coefficient source - src = (data + offset + i * length) + x; + std::uint8_t* src = (data + offset + i * length) + x; /* coefficient copy */ ptr[0]=src[0]; @@ -913,7 +912,7 @@ void CommandSetGl846::send_shading_data(Genesys_Device* dev, const Genesys_Senso ptr+=4; } - val = dev->interface->read_register(0xd0+i); + std::uint8_t val = dev->interface->read_register(0xd0+i); addr = val * 8192 + 0x10000000; dev->interface->write_ahb(addr, pixels, buffer.data()); } @@ -961,7 +960,7 @@ static void gl846_init_memory_layout(Genesys_Device* dev) void CommandSetGl846::asic_boot(Genesys_Device* dev, bool cold) const { DBG_HELPER(dbg); - uint8_t val; + std::uint8_t val; // reset ASIC if cold boot if (cold) { @@ -1036,8 +1035,7 @@ void CommandSetGl846::update_hardware_sensors(Genesys_Scanner* s) const /* do what is needed to get a new set of events, but try to not lose any of them. */ - uint8_t val; - uint8_t scan, file, email, copy; + std::uint8_t scan, file, email, copy; switch(s->dev->model->gpio_id) { default: @@ -1046,7 +1044,7 @@ void CommandSetGl846::update_hardware_sensors(Genesys_Scanner* s) const email=0x04; copy=0x08; } - val = s->dev->interface->read_register(REG_0x6D); + std::uint8_t val = s->dev->interface->read_register(REG_0x6D); s->buttons[BUTTON_SCAN_SW].write((val & scan) == 0); s->buttons[BUTTON_FILE_SW].write((val & file) == 0); diff --git a/backend/genesys/gl846.h b/backend/genesys/gl846.h index f1d396d..c0acec4 100644 --- a/backend/genesys/gl846.h +++ b/backend/genesys/gl846.h @@ -46,7 +46,7 @@ public: Genesys_Register_Set* reg, const ScanSession& session) const override; - void set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t set) const override; + void set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, std::uint8_t set) const override; void set_powersaving(Genesys_Device* dev, int delay) const override; void save_power(Genesys_Device* dev, bool enable) const override; @@ -80,7 +80,7 @@ public: void eject_document(Genesys_Device* dev) const override; - void send_shading_data(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t* data, + void send_shading_data(Genesys_Device* dev, const Genesys_Sensor& sensor, std::uint8_t* data, int size) const override; ScanSession calculate_scan_session(const Genesys_Device* dev, diff --git a/backend/genesys/gl847.cpp b/backend/genesys/gl847.cpp index 13f9dd9..14d1fd0 100644 --- a/backend/genesys/gl847.cpp +++ b/backend/genesys/gl847.cpp @@ -51,7 +51,7 @@ gl847_init_registers (Genesys_Device * dev) { DBG_HELPER(dbg); int lide700=0; - uint8_t val; + std::uint8_t val; /* 700F class needs some different initial settings */ if (dev->model->model_id == ModelId::CANON_LIDE_700F) { @@ -233,7 +233,8 @@ gl847_init_registers (Genesys_Device * dev) } // Set values of analog frontend -void CommandSetGl847::set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t set) const +void CommandSetGl847::set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, + std::uint8_t set) const { DBG_HELPER_ARGS(dbg, "%s", set == AFE_INIT ? "init" : set == AFE_SET ? "set" : @@ -389,7 +390,7 @@ static void gl847_init_motor_regs_scan(Genesys_Device* dev, unsigned tgtime = 1 << (reg->get8(REG_0x1C) & REG_0x1C_TGTIME); // hi res motor speed GPIO - uint8_t effective = dev->interface->read_register(REG_0x6C); + std::uint8_t effective = dev->interface->read_register(REG_0x6C); // if quarter step, bipolar Vref2 @@ -624,7 +625,7 @@ void CommandSetGl847::init_regs_for_scan_session(Genesys_Device* dev, const Gene dev->session = session; dev->total_bytes_read = 0; - dev->total_bytes_to_read = session.output_line_bytes_requested * session.params.lines; + dev->total_bytes_to_read = (size_t)session.output_line_bytes_requested * (size_t)session.params.lines; DBG(DBG_info, "%s: total bytes to send = %zu\n", __func__, dev->total_bytes_to_read); } @@ -722,7 +723,7 @@ void CommandSetGl847::begin_scan(Genesys_Device* dev, const Genesys_Sensor& sens { DBG_HELPER(dbg); (void) sensor; - uint8_t val; + std::uint8_t val; if (reg->state.is_xpa_on && reg->state.is_lamp_on) { dev->cmd_set->set_xpa_lamp_power(*dev, true); @@ -879,11 +880,10 @@ void CommandSetGl847::init_regs_for_shading(Genesys_Device* dev, const Genesys_S * for all the channels. */ void CommandSetGl847::send_shading_data(Genesys_Device* dev, const Genesys_Sensor& sensor, - uint8_t* data, int size) const + std::uint8_t* data, int size) const { DBG_HELPER_ARGS(dbg, "writing %d bytes of shading data", size); std::uint32_t addr, i; - uint8_t val,*ptr,*src; unsigned length = static_cast<unsigned>(size / 3); @@ -901,7 +901,7 @@ void CommandSetGl847::send_shading_data(Genesys_Device* dev, const Genesys_Senso dev->interface->record_key_value("shading_length", std::to_string(length)); dev->interface->record_key_value("shading_factor", std::to_string(sensor.shading_factor)); - std::vector<uint8_t> buffer(pixels, 0); + std::vector<std::uint8_t> buffer(pixels, 0); DBG(DBG_io2, "%s: using chunks of %d (0x%04x) bytes\n", __func__, pixels, pixels); @@ -917,12 +917,12 @@ void CommandSetGl847::send_shading_data(Genesys_Device* dev, const Genesys_Senso { /* build up actual shading data by copying the part from the full width one * to the one corresponding to SHDAREA */ - ptr = buffer.data(); + std::uint8_t* ptr = buffer.data(); // iterate on both sensor segment for (unsigned x = 0; x < pixels; x += 4 * sensor.shading_factor) { - /* coefficient source */ - src = (data + offset + i * length) + x; + // coefficient source + std::uint8_t* src = (data + offset + i * length) + x; /* coefficient copy */ ptr[0]=src[0]; @@ -934,7 +934,7 @@ void CommandSetGl847::send_shading_data(Genesys_Device* dev, const Genesys_Senso ptr+=4; } - val = dev->interface->read_register(0xd0+i); + std::uint8_t val = dev->interface->read_register(0xd0+i); addr = val * 8192 + 0x10000000; dev->interface->write_ahb(addr, pixels, buffer.data()); } @@ -1030,7 +1030,7 @@ void CommandSetGl847::asic_boot(Genesys_Device* dev, bool cold) const } // test CHKVER - uint8_t val = dev->interface->read_register(REG_0x40); + std::uint8_t val = dev->interface->read_register(REG_0x40); if (val & REG_0x40_CHKVER) { val = dev->interface->read_register(0x00); DBG(DBG_info, "%s: reported version for genesys chip is 0x%02x\n", __func__, val); @@ -1089,27 +1089,46 @@ void CommandSetGl847::update_hardware_sensors(Genesys_Scanner* s) const /* do what is needed to get a new set of events, but try to not lose any of them. */ - uint8_t val; - uint8_t scan, file, email, copy; + std::uint8_t val; switch(s->dev->model->gpio_id) { case GpioId::CANON_LIDE_700F: - scan=0x04; - file=0x02; - email=0x01; - copy=0x08; + val = s->dev->interface->read_register(REG_0x6D); + DBG(DBG_io, "%s: read buttons_gpio value=0x%x\n", __func__, (int)val); + + s->buttons[BUTTON_SCAN_SW].write((val & 0x04) == 0); + s->buttons[BUTTON_FILE_SW].write((val & 0x02) == 0); + s->buttons[BUTTON_EMAIL_SW].write((val & 0x01) == 0); + s->buttons[BUTTON_COPY_SW].write((val & 0x08) == 0); + break; + + case GpioId::CANON_5600F: + val = s->dev->interface->read_register(REG_0x6D); + DBG(DBG_io, "%s: read buttons_gpio 0x6d value=0x%x\n", __func__, (int)val); + s->buttons[BUTTON_SCAN_SW].write((val & 0x02) == 0); + s->buttons[BUTTON_EMAIL_SW].write((val & 0x01) == 0); + s->buttons[BUTTON_COPY_SW].write((val & 0x08) == 0); + s->buttons[BUTTON_PDF4_SW].write((val & 0x04) == 0); + + val = s->dev->interface->read_register(REG_0xA6); + DBG(DBG_io, "%s: read buttons_gpio 0xa6 value=0x%x\n", __func__, (int)val); + s->buttons[BUTTON_PDF1_SW].write((val & 0x03) == 0x01); + s->buttons[BUTTON_PDF2_SW].write((val & 0x03) == 0x02); + + val = s->dev->interface->read_register(REG_0x6C); + DBG(DBG_io, "%s: read buttons_gpio 0x6c value=0x%x\n", __func__, (int)val); + s->buttons[BUTTON_PDF3_SW].write((val & 0x80) == 0x00); break; + default: - scan=0x01; - file=0x02; - email=0x04; - copy=0x08; - } - val = s->dev->interface->read_register(REG_0x6D); + val = s->dev->interface->read_register(REG_0x6D); + DBG(DBG_io, "%s: read buttons_gpio value=0x%x\n", __func__, (int)val); - s->buttons[BUTTON_SCAN_SW].write((val & scan) == 0); - s->buttons[BUTTON_FILE_SW].write((val & file) == 0); - s->buttons[BUTTON_EMAIL_SW].write((val & email) == 0); - s->buttons[BUTTON_COPY_SW].write((val & copy) == 0); + s->buttons[BUTTON_SCAN_SW].write((val & 0x01) == 0); + s->buttons[BUTTON_FILE_SW].write((val & 0x02) == 0); + s->buttons[BUTTON_EMAIL_SW].write((val & 0x04) == 0); + s->buttons[BUTTON_COPY_SW].write((val & 0x08) == 0); + break; + } } void CommandSetGl847::update_home_sensor_gpio(Genesys_Device& dev) const diff --git a/backend/genesys/gl847.h b/backend/genesys/gl847.h index 4b98b7a..68bf553 100644 --- a/backend/genesys/gl847.h +++ b/backend/genesys/gl847.h @@ -46,7 +46,7 @@ public: Genesys_Register_Set* reg, const ScanSession& session) const override; - void set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t set) const override; + void set_fe(Genesys_Device* dev, const Genesys_Sensor& sensor, std::uint8_t set) const override; void set_powersaving(Genesys_Device* dev, int delay) const override; void save_power(Genesys_Device* dev, bool enable) const override; @@ -80,7 +80,7 @@ public: void eject_document(Genesys_Device* dev) const override; - void send_shading_data(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t* data, + void send_shading_data(Genesys_Device* dev, const Genesys_Sensor& sensor, std::uint8_t* data, int size) const override; ScanSession calculate_scan_session(const Genesys_Device* dev, diff --git a/backend/genesys/image.h b/backend/genesys/image.h index 07d3be3..80797ed 100644 --- a/backend/genesys/image.h +++ b/backend/genesys/image.h @@ -15,7 +15,7 @@ General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see <https://www.gnu.org/licenses/>.s + along with this program. If not, see <https://www.gnu.org/licenses/>. */ #ifndef BACKEND_GENESYS_IMAGE_H diff --git a/backend/genesys/image_pipeline.cpp b/backend/genesys/image_pipeline.cpp index f53680f..8dae0c5 100644 --- a/backend/genesys/image_pipeline.cpp +++ b/backend/genesys/image_pipeline.cpp @@ -173,7 +173,7 @@ ImagePipelineNodeDesegment::ImagePipelineNodeDesegment(ImagePipelineNode& source std::iota(segment_order_.begin(), segment_order_.end(), 0); } -bool ImagePipelineNodeDesegment::get_next_row_data(uint8_t* out_data) +bool ImagePipelineNodeDesegment::get_next_row_data(std::uint8_t* out_data) { bool got_data = true; diff --git a/backend/genesys/image_pixel.h b/backend/genesys/image_pixel.h index e414cfb..4f487ea 100644 --- a/backend/genesys/image_pixel.h +++ b/backend/genesys/image_pixel.h @@ -15,7 +15,7 @@ General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see <https://www.gnu.org/licenses/>.s + along with this program. If not, see <https://www.gnu.org/licenses/>. */ #ifndef BACKEND_GENESYS_IMAGE_PIXEL_H diff --git a/backend/genesys/low.cpp b/backend/genesys/low.cpp index a6da2c1..3ffc24a 100644 --- a/backend/genesys/low.cpp +++ b/backend/genesys/low.cpp @@ -106,7 +106,7 @@ unsigned sanei_genesys_get_bulk_max_size(AsicType asic_type) } // Set address for writing data -void sanei_genesys_set_buffer_address(Genesys_Device* dev, uint32_t addr) +void sanei_genesys_set_buffer_address(Genesys_Device* dev, std::uint32_t addr) { DBG_HELPER(dbg); @@ -356,12 +356,12 @@ void wait_until_has_valid_words(Genesys_Device* dev) } // Read data (e.g scanned image) from scan buffer -void sanei_genesys_read_data_from_scanner(Genesys_Device* dev, uint8_t* data, size_t size) +void sanei_genesys_read_data_from_scanner(Genesys_Device* dev, std::uint8_t* data, size_t size) { DBG_HELPER_ARGS(dbg, "size = %zu bytes", size); - if (size & 1) - DBG(DBG_info, "WARNING %s: odd number of bytes\n", __func__); + if (size & 1) + DBG(DBG_info, "WARNING %s: odd number of bytes\n", __func__); wait_until_has_valid_words(dev); @@ -565,7 +565,7 @@ void sanei_genesys_read_feed_steps(Genesys_Device* dev, unsigned int* steps) void sanei_genesys_set_lamp_power(Genesys_Device* dev, const Genesys_Sensor& sensor, Genesys_Register_Set& regs, bool set) { - static const uint8_t REG_0x03_LAMPPWR = 0x10; + static const std::uint8_t REG_0x03_LAMPPWR = 0x10; if (set) { regs.find_reg(0x03).value |= REG_0x03_LAMPPWR; @@ -606,7 +606,7 @@ void sanei_genesys_set_lamp_power(Genesys_Device* dev, const Genesys_Sensor& sen void sanei_genesys_set_motor_power(Genesys_Register_Set& regs, bool set) { - static const uint8_t REG_0x02_MTRPWR = 0x10; + static const std::uint8_t REG_0x02_MTRPWR = 0x10; if (set) { regs.find_reg(0x02).value |= REG_0x02_MTRPWR; @@ -635,13 +635,13 @@ bool should_enable_gamma(const ScanSession& session, const Genesys_Sensor& senso return true; } -std::vector<uint16_t> get_gamma_table(Genesys_Device* dev, const Genesys_Sensor& sensor, - int color) +std::vector<std::uint16_t> get_gamma_table(Genesys_Device* dev, const Genesys_Sensor& sensor, + int color) { if (!dev->gamma_override_tables[color].empty()) { return dev->gamma_override_tables[color]; } else { - std::vector<uint16_t> ret; + std::vector<std::uint16_t> ret; sanei_genesys_create_default_gamma_table(dev, ret, sensor.gamma[color]); return ret; } @@ -654,23 +654,38 @@ std::vector<uint16_t> get_gamma_table(Genesys_Device* dev, const Genesys_Sensor& * @param bits number of bits used by gamma * @param max value for gamma * @param size of the gamma table - * @param gamma allocated gamma buffer to fill */ -void sanei_genesys_generate_gamma_buffer(Genesys_Device* dev, +std::vector<std::uint8_t> generate_gamma_buffer(Genesys_Device* dev, const Genesys_Sensor& sensor, - int bits, - int max, - int size, - uint8_t* gamma) + int bits, int max, int size) { DBG_HELPER(dbg); - std::vector<uint16_t> rgamma = get_gamma_table(dev, sensor, GENESYS_RED); - std::vector<uint16_t> ggamma = get_gamma_table(dev, sensor, GENESYS_GREEN); - std::vector<uint16_t> bgamma = get_gamma_table(dev, sensor, GENESYS_BLUE); + + // the gamma tables are 16 bits words and contain 3 channels + std::vector<std::uint8_t> gamma_buf(size * 2 * 3); + + std::vector<std::uint16_t> rgamma = get_gamma_table(dev, sensor, GENESYS_RED); + std::vector<std::uint16_t> ggamma = get_gamma_table(dev, sensor, GENESYS_GREEN); + std::vector<std::uint16_t> bgamma = get_gamma_table(dev, sensor, GENESYS_BLUE); + + auto get_gamma_value = [](const std::vector<std::uint16_t>& array, + std::size_t index) -> std::uint16_t + { + if (index < array.size()) + return array[index]; + return 0xffff; + }; + + auto set_gamma_buf_value = [](std::vector<std::uint8_t>& array, std::size_t pos, + std::uint16_t value) + { + array[pos * 2 + 0] = value & 0xff; + array[pos * 2 + 1] = (value >> 8) & 0xff; + }; if(dev->settings.contrast!=0 || dev->settings.brightness!=0) { - std::vector<uint16_t> lut(65536); + std::vector<std::uint16_t> lut(65536); sanei_genesys_load_lut(reinterpret_cast<unsigned char *>(lut.data()), bits, bits, @@ -680,39 +695,21 @@ void sanei_genesys_generate_gamma_buffer(Genesys_Device* dev, dev->settings.brightness); for (int i = 0; i < size; i++) { - uint16_t value=rgamma[i]; - value=lut[value]; - gamma[i * 2 + size * 0 + 0] = value & 0xff; - gamma[i * 2 + size * 0 + 1] = (value >> 8) & 0xff; - - value=ggamma[i]; - value=lut[value]; - gamma[i * 2 + size * 2 + 0] = value & 0xff; - gamma[i * 2 + size * 2 + 1] = (value >> 8) & 0xff; - - value=bgamma[i]; - value=lut[value]; - gamma[i * 2 + size * 4 + 0] = value & 0xff; - gamma[i * 2 + size * 4 + 1] = (value >> 8) & 0xff; + set_gamma_buf_value(gamma_buf, i + size * 0, lut[get_gamma_value(rgamma, i)]); + set_gamma_buf_value(gamma_buf, i + size * 1, lut[get_gamma_value(ggamma, i)]); + set_gamma_buf_value(gamma_buf, i + size * 2, lut[get_gamma_value(bgamma, i)]); } } else { for (int i = 0; i < size; i++) { - uint16_t value=rgamma[i]; - gamma[i * 2 + size * 0 + 0] = value & 0xff; - gamma[i * 2 + size * 0 + 1] = (value >> 8) & 0xff; - - value=ggamma[i]; - gamma[i * 2 + size * 2 + 0] = value & 0xff; - gamma[i * 2 + size * 2 + 1] = (value >> 8) & 0xff; - - value=bgamma[i]; - gamma[i * 2 + size * 4 + 0] = value & 0xff; - gamma[i * 2 + size * 4 + 1] = (value >> 8) & 0xff; + set_gamma_buf_value(gamma_buf, i + size * 0, get_gamma_value(rgamma, i)); + set_gamma_buf_value(gamma_buf, i + size * 1, get_gamma_value(ggamma, i)); + set_gamma_buf_value(gamma_buf, i + size * 2, get_gamma_value(bgamma, i)); } } + return gamma_buf; } @@ -730,15 +727,12 @@ void sanei_genesys_send_gamma_table(Genesys_Device* dev, const Genesys_Sensor& s size = 256 + 1; - /* allocate temporary gamma tables: 16 bits words, 3 channels */ - std::vector<uint8_t> gamma(size * 2 * 3, 255); - - sanei_genesys_generate_gamma_buffer(dev, sensor, 16, 65535, size, gamma.data()); + auto gamma = generate_gamma_buffer(dev, sensor, 16, 65535, size); // loop sending gamma tables NOTE: 0x01000000 not 0x10000000 for (i = 0; i < 3; i++) { // clear corresponding GMM_N bit - uint8_t val = dev->interface->read_register(0xbd); + std::uint8_t val = dev->interface->read_register(0xbd); val &= ~(0x01 << i); dev->interface->write_register(0xbd, val); @@ -1410,7 +1404,7 @@ void sanei_genesys_asic_init(Genesys_Device* dev) { DBG_HELPER(dbg); - uint8_t val; + std::uint8_t val; bool cold = true; // URB 16 control 0xc0 0x0c 0x8e 0x0b len 1 read 0x00 */ @@ -1507,13 +1501,13 @@ void scanner_start_action(Genesys_Device& dev, bool start_motor) void sanei_genesys_set_dpihw(Genesys_Register_Set& regs, unsigned dpihw) { // same across GL646, GL841, GL843, GL846, GL847, GL124 - const uint8_t REG_0x05_DPIHW_MASK = 0xc0; - const uint8_t REG_0x05_DPIHW_600 = 0x00; - const uint8_t REG_0x05_DPIHW_1200 = 0x40; - const uint8_t REG_0x05_DPIHW_2400 = 0x80; - const uint8_t REG_0x05_DPIHW_4800 = 0xc0; + const std::uint8_t REG_0x05_DPIHW_MASK = 0xc0; + const std::uint8_t REG_0x05_DPIHW_600 = 0x00; + const std::uint8_t REG_0x05_DPIHW_1200 = 0x40; + const std::uint8_t REG_0x05_DPIHW_2400 = 0x80; + const std::uint8_t REG_0x05_DPIHW_4800 = 0xc0; - uint8_t dpihw_setting; + std::uint8_t dpihw_setting; switch (dpihw) { case 600: dpihw_setting = REG_0x05_DPIHW_600; @@ -1925,8 +1919,8 @@ void sanei_genesys_load_lut(unsigned char* lut, double shift, rise; int max_in_val = (1 << in_bits) - 1; int max_out_val = (1 << out_bits) - 1; - uint8_t *lut_p8 = lut; - uint16_t* lut_p16 = reinterpret_cast<std::uint16_t*>(lut); + std::uint8_t* lut_p8 = lut; + std::uint16_t* lut_p16 = reinterpret_cast<std::uint16_t*>(lut); /* slope is converted to rise per unit run: * first [-127,127] to [-.999,.999] diff --git a/backend/genesys/low.h b/backend/genesys/low.h index b0d23fe..1b96cc5 100644 --- a/backend/genesys/low.h +++ b/backend/genesys/low.h @@ -95,7 +95,11 @@ #define GENESYS_HAS_POWER_SW (1 << 6) /**< scanner has power button */ #define GENESYS_HAS_CALIBRATE (1 << 7) /**< scanner has 'calibrate' software button to start calibration */ #define GENESYS_HAS_EXTRA_SW (1 << 8) /**< scanner has extra function button */ -#define GENESYS_HAS_TRANSP_SW (1 << 9) /**< scanner has TRANSPARCY/SCAN_FILM button */ +#define GENESYS_HAS_TRANSP_SW (1 << 9) /**< scanner has TRANSPARENCY/SCAN_FILM button */ +#define GENESYS_HAS_PDF1_SW (1 << 10) /**< scanner has special PDF button 1 */ +#define GENESYS_HAS_PDF2_SW (1 << 11) /**< scanner has special PDF button 2 */ +#define GENESYS_HAS_PDF3_SW (1 << 12) /**< scanner has special PDF button 3 */ +#define GENESYS_HAS_PDF4_SW (1 << 13) /**< scanner has special PDF button 4 */ /* USB control message values */ #define REQUEST_TYPE_IN (USB_TYPE_VENDOR | USB_DIR_IN) @@ -203,8 +207,8 @@ void scanner_register_rw_set_bits(Genesys_Device& dev, std::uint16_t address, st void scanner_register_rw_bits(Genesys_Device& dev, std::uint16_t address, std::uint8_t value, std::uint8_t mask); -extern void sanei_genesys_write_ahb(Genesys_Device* dev, uint32_t addr, uint32_t size, - uint8_t* data); +void sanei_genesys_write_ahb(Genesys_Device* dev, std::uint32_t addr, std::uint32_t size, + std::uint8_t* data); extern void sanei_genesys_init_structs (Genesys_Device * dev); @@ -251,14 +255,14 @@ bool should_enable_gamma(const ScanSession& session, const Genesys_Sensor& senso i.e. the number written to REG_FWDSTEP. */ void sanei_genesys_calculate_zmod(bool two_table, - uint32_t exposure_time, - const std::vector<uint16_t>& slope_table, + std::uint32_t exposure_time, + const std::vector<std::uint16_t>& slope_table, unsigned acceleration_steps, unsigned move_steps, unsigned buffer_acceleration_steps, - uint32_t* out_z1, uint32_t* out_z2); + std::uint32_t* out_z1, std::uint32_t* out_z2); -extern void sanei_genesys_set_buffer_address(Genesys_Device* dev, uint32_t addr); +extern void sanei_genesys_set_buffer_address(Genesys_Device* dev, std::uint32_t addr); unsigned sanei_genesys_get_bulk_max_size(AsicType asic_type); @@ -266,10 +270,10 @@ SANE_Int sanei_genesys_exposure_time2(Genesys_Device* dev, const MotorProfile& p int endpixel, int led_exposure); void sanei_genesys_create_default_gamma_table(Genesys_Device* dev, - std::vector<uint16_t>& gamma_table, float gamma); + std::vector<std::uint16_t>& gamma_table, float gamma); -std::vector<uint16_t> get_gamma_table(Genesys_Device* dev, const Genesys_Sensor& sensor, - int color); +std::vector<std::uint16_t> get_gamma_table(Genesys_Device* dev, const Genesys_Sensor& sensor, + int color); void sanei_genesys_send_gamma_table(Genesys_Device* dev, const Genesys_Sensor& sensor); @@ -307,14 +311,14 @@ SensorExposure scanner_led_calibration(Genesys_Device& dev, const Genesys_Sensor void scanner_clear_scan_and_feed_counts(Genesys_Device& dev); void scanner_send_slope_table(Genesys_Device* dev, const Genesys_Sensor& sensor, unsigned table_nr, - const std::vector<uint16_t>& slope_table); + const std::vector<std::uint16_t>& slope_table); extern void sanei_genesys_write_file(const char* filename, const std::uint8_t* data, std::size_t length); void wait_until_buffer_non_empty(Genesys_Device* dev, bool check_status_twice = false); -extern void sanei_genesys_read_data_from_scanner(Genesys_Device* dev, uint8_t* data, size_t size); +void sanei_genesys_read_data_from_scanner(Genesys_Device* dev, std::uint8_t* data, size_t size); Image read_unshuffled_image_from_scanner(Genesys_Device* dev, const ScanSession& session, std::size_t total_bytes); @@ -392,12 +396,9 @@ extern void sanei_genesys_load_lut(unsigned char* lut, int out_min, int out_max, int slope, int offset); -extern void sanei_genesys_generate_gamma_buffer(Genesys_Device* dev, - const Genesys_Sensor& sensor, - int bits, - int max, - int size, - uint8_t* gamma); +std::vector<std::uint8_t> generate_gamma_buffer(Genesys_Device* dev, + const Genesys_Sensor& sensor, + int bits, int max, int size); unsigned session_adjust_output_pixels(unsigned output_pixels, const Genesys_Device& dev, const Genesys_Sensor& sensor, diff --git a/backend/genesys/scanner_interface_usb.cpp b/backend/genesys/scanner_interface_usb.cpp index da8823b..542d4ff 100644 --- a/backend/genesys/scanner_interface_usb.cpp +++ b/backend/genesys/scanner_interface_usb.cpp @@ -126,8 +126,8 @@ void ScannerInterfaceUsb::write_registers(const Genesys_Register_Set& regs) if (dev_->model->asic_type == AsicType::GL646 || dev_->model->asic_type == AsicType::GL841) { - uint8_t outdata[8]; - std::vector<uint8_t> buffer; + std::uint8_t outdata[8]; + std::vector<std::uint8_t> buffer; buffer.reserve(regs.size() * 2); /* copy registers and values in data buffer */ @@ -185,7 +185,7 @@ static void bulk_read_data_send_header(UsbDevice& usb_dev, AsicType asic_type, s { DBG_HELPER(dbg); - uint8_t outdata[8]; + std::uint8_t outdata[8]; if (asic_type == AsicType::GL124 || asic_type == AsicType::GL845 || asic_type == AsicType::GL846 || diff --git a/backend/genesys/serialize.cpp b/backend/genesys/serialize.cpp deleted file mode 100644 index e69de29..0000000 --- a/backend/genesys/serialize.cpp +++ /dev/null diff --git a/backend/genesys/serialize.h b/backend/genesys/serialize.h index ed67ea3..5040ed0 100644 --- a/backend/genesys/serialize.h +++ b/backend/genesys/serialize.h @@ -15,7 +15,7 @@ General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see <https://www.gnu.org/licenses/>.s + along with this program. If not, see <https://www.gnu.org/licenses/>. */ #ifndef BACKEND_GENESYS_SERIALIZE_H diff --git a/backend/genesys/tables_model.cpp b/backend/genesys/tables_model.cpp index d139334..6d02db8 100644 --- a/backend/genesys/tables_model.cpp +++ b/backend/genesys/tables_model.cpp @@ -447,7 +447,9 @@ void genesys_init_usb_device_tables() ModelFlag::SHADING_REPARK | ModelFlag::UTA_NO_SECONDARY_MOTOR; - model.buttons = GENESYS_HAS_SCAN_SW | GENESYS_HAS_FILE_SW | GENESYS_HAS_COPY_SW; + model.buttons = GENESYS_HAS_TRANSP_SW | GENESYS_HAS_EMAIL_SW + | GENESYS_HAS_COPY_SW | GENESYS_HAS_PDF1_SW | GENESYS_HAS_PDF2_SW + | GENESYS_HAS_PDF3_SW | GENESYS_HAS_PDF4_SW; model.search_lines = 100; s_usb_devices->emplace_back(0x04a9, 0x2228, model); @@ -517,7 +519,7 @@ void genesys_init_usb_device_tables() ModelFlag::DARK_CALIBRATION | ModelFlag::CUSTOM_GAMMA | ModelFlag::SHADING_REPARK; - model.buttons = GENESYS_HAS_SCAN_SW | GENESYS_HAS_FILE_SW | GENESYS_HAS_COPY_SW; + model.buttons = GENESYS_HAS_SCAN_SW | GENESYS_HAS_FILE_SW | GENESYS_HAS_COPY_SW | GENESYS_HAS_EMAIL_SW; model.search_lines = 100; s_usb_devices->emplace_back(0x04a9, 0x221e, model); @@ -927,7 +929,10 @@ void genesys_init_usb_device_tables() model.buttons = GENESYS_HAS_SCAN_SW | GENESYS_HAS_COPY_SW | GENESYS_HAS_EMAIL_SW | - GENESYS_HAS_FILE_SW; + GENESYS_HAS_PDF1_SW | + GENESYS_HAS_PDF2_SW | + GENESYS_HAS_PDF3_SW | + GENESYS_HAS_PDF4_SW; model.search_lines = 400; s_usb_devices->emplace_back(0x04a9, 0x1906, model); diff --git a/backend/genesys/test_scanner_interface.cpp b/backend/genesys/test_scanner_interface.cpp index 412176e..ef7cdbb 100644 --- a/backend/genesys/test_scanner_interface.cpp +++ b/backend/genesys/test_scanner_interface.cpp @@ -26,8 +26,8 @@ namespace genesys { -TestScannerInterface::TestScannerInterface(Genesys_Device* dev, uint16_t vendor_id, - uint16_t product_id, uint16_t bcd_device) : +TestScannerInterface::TestScannerInterface(Genesys_Device* dev, std::uint16_t vendor_id, + std::uint16_t product_id, std::uint16_t bcd_device) : dev_{dev}, usb_dev_{vendor_id, product_id, bcd_device} { diff --git a/backend/gt68xx_low.c b/backend/gt68xx_low.c index 5aa84ac..c83108b 100644 --- a/backend/gt68xx_low.c +++ b/backend/gt68xx_low.c @@ -425,7 +425,7 @@ gt68xx_device_memory_write (GT68xx_Device * dev, SANE_Status status; DBG (8, "gt68xx_device_memory_write: dev=%p, addr=0x%x, size=0x%x, data=%p\n", - (void *) dev, addr, size, data); + (void *) dev, addr, size, (void *) data); CHECK_DEV_ACTIVE (dev, "gt68xx_device_memory_write"); status = sanei_usb_control_msg (dev->fd, 0x40, @@ -448,7 +448,7 @@ gt68xx_device_memory_read (GT68xx_Device * dev, SANE_Status status; DBG (8, "gt68xx_device_memory_read: dev=%p, addr=0x%x, size=0x%x, data=%p\n", - (void *) dev, addr, size, data); + (void *) dev, addr, size, (void *) data); CHECK_DEV_ACTIVE (dev, "gt68xx_device_memory_read"); status = sanei_usb_control_msg (dev->fd, 0xc0, diff --git a/backend/hp.c b/backend/hp.c index 558a36d..ec43402 100644 --- a/backend/hp.c +++ b/backend/hp.c @@ -581,13 +581,9 @@ hp_get_dev (const char *devname, HpDevice* devp) DBG(3, "hp_get_dev: New device %s, connect-%s, scsi-request=%lu\n", devname, connect, (unsigned long)info->config.use_scsi_request); - if (!ptr) - { - status = sanei_hp_device_new (&new, devname); - - if ( status != SANE_STATUS_GOOD ) - return status; - } + status = sanei_hp_device_new (&new, devname); + if (status != SANE_STATUS_GOOD) + return status; if (devp) *devp = new; diff --git a/backend/hp3500.c b/backend/hp3500.c index bf07b36..acb09b6 100644 --- a/backend/hp3500.c +++ b/backend/hp3500.c @@ -265,7 +265,7 @@ static const SANE_Device **devlist = 0; SANE_Status sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize) { - authorize = authorize; /* get rid of compiler warning */ + (void) authorize; /* get rid of compiler warning */ DBG_INIT (); DBG (10, "sane_init\n"); @@ -1117,7 +1117,7 @@ init_options (struct hp3500_data *scanner) static void do_reset (struct hp3500_data *scanner) { - scanner = scanner; /* kill warning */ + (void) scanner; /* kill warning */ } static void @@ -1530,8 +1530,6 @@ rt_get_available_bytes (void) static int rt_get_data (int bytes, void *data) { - int total = 0; - while (bytes) { int bytesnow = bytes; @@ -1542,7 +1540,6 @@ rt_get_data (int bytes, void *data) (RTCMD_READBYTES, 0, bytesnow, 0, 0, bytesnow, data) < 0 || rt_execute_commands () < 0) return -1; - total += bytesnow; bytes -= bytesnow; data = (char *) data + bytesnow; } @@ -2774,7 +2771,7 @@ rts8801_doscan (unsigned width, int result = 0; unsigned rows_supplied = 0; - calib_info = calib_info; /* Kill warning */ + (void) calib_info; /* Kill warning */ if (cancelled_scan) return -1; rt_start_moving (); @@ -3784,7 +3781,7 @@ writefunc (struct hp3500_write_info *winfo, int bytes, char *data) static void sigtermHandler (int signal) { - signal = signal; /* get rid of compiler warning */ + (void) signal; /* get rid of compiler warning */ cancelled_scan = 1; } #endif diff --git a/backend/hp3900_config.c b/backend/hp3900_config.c index daeb583..c40920f 100644 --- a/backend/hp3900_config.c +++ b/backend/hp3900_config.c @@ -1523,19 +1523,16 @@ static SANE_Int hp3800_checkstable(SANE_Int lamp, struct st_checkstable *check) SANE_Int rst = ERROR; - if (reg != NULL) - { - SANE_Int a; - SANE_Int count = sizeof(reg) / sizeof(struct st_reg); + SANE_Int a; + SANE_Int count = sizeof(reg) / sizeof(struct st_reg); - for (a = 0; a < count; a++) + for (a = 0; a < count; a++) + { + if (reg[a].lamp == lamp) { - if (reg[a].lamp == lamp) - { - memcpy(check, ®[a].values, sizeof(struct st_checkstable)); - rst = OK; - break; - } + memcpy(check, ®[a].values, sizeof(struct st_checkstable)); + rst = OK; + break; } } @@ -1560,19 +1557,16 @@ static SANE_Int hp3970_checkstable(SANE_Int lamp, struct st_checkstable *check) SANE_Int rst = ERROR; - if (reg != NULL) - { - SANE_Int a; - SANE_Int count = sizeof(reg) / sizeof(struct st_reg); + SANE_Int a; + SANE_Int count = sizeof(reg) / sizeof(struct st_reg); - for (a = 0; a < count; a++) + for (a = 0; a < count; a++) + { + if (reg[a].lamp == lamp) { - if (reg[a].lamp == lamp) - { - memcpy(check, ®[a].values, sizeof(struct st_checkstable)); - rst = OK; - break; - } + memcpy(check, ®[a].values, sizeof(struct st_checkstable)); + rst = OK; + break; } } @@ -1597,19 +1591,16 @@ static SANE_Int hp4370_checkstable(SANE_Int lamp, struct st_checkstable *check) SANE_Int rst = ERROR; - if (reg != NULL) - { - SANE_Int a; - SANE_Int count = sizeof(reg) / sizeof(struct st_reg); + SANE_Int a; + SANE_Int count = sizeof(reg) / sizeof(struct st_reg); - for (a = 0; a < count; a++) + for (a = 0; a < count; a++) + { + if (reg[a].lamp == lamp) { - if (reg[a].lamp == lamp) - { - memcpy(check, ®[a].values, sizeof(struct st_checkstable)); - rst = OK; - break; - } + memcpy(check, ®[a].values, sizeof(struct st_checkstable)); + rst = OK; + break; } } @@ -1634,19 +1625,16 @@ static SANE_Int ua4900_checkstable(SANE_Int lamp, struct st_checkstable *check) SANE_Int rst = ERROR; - if (reg != NULL) - { - SANE_Int a; - SANE_Int count = sizeof(reg) / sizeof(struct st_reg); + SANE_Int a; + SANE_Int count = sizeof(reg) / sizeof(struct st_reg); - for (a = 0; a < count; a++) + for (a = 0; a < count; a++) + { + if (reg[a].lamp == lamp) { - if (reg[a].lamp == lamp) - { - memcpy(check, ®[a].values, sizeof(struct st_checkstable)); - rst = OK; - break; - } + memcpy(check, ®[a].values, sizeof(struct st_checkstable)); + rst = OK; + break; } } @@ -2719,7 +2707,7 @@ static SANE_Int bq5550_scanmodes(SANE_Int usb, SANE_Int sm, struct st_scanmode * SANE_Int rst = ERROR; /* silence compiler */ - usb = usb; + (void) usb; if (mymode != NULL) { diff --git a/backend/hp3900_debug.c b/backend/hp3900_debug.c index 25254db..881f400 100644 --- a/backend/hp3900_debug.c +++ b/backend/hp3900_debug.c @@ -600,15 +600,15 @@ dbg_tiff_save (char *sFile, SANE_Int width, SANE_Int height, SANE_Int depth, } #else /* silent gcc */ - sFile = sFile; - width = width; - height = height; - depth = depth; - colortype = colortype; - res_x = res_x; - res_y = res_y; - buffer = buffer; - size = size; + (void) sFile; + (void) width; + (void) height; + (void) depth; + (void) colortype; + (void) res_x; + (void) res_y; + (void) buffer; + (void) size; DBG (DBG_ERR, "- dbg_tiff_save: tiffio not supported\n"); #endif diff --git a/backend/hp3900_rts8822.c b/backend/hp3900_rts8822.c index c818b89..f74d586 100644 --- a/backend/hp3900_rts8822.c +++ b/backend/hp3900_rts8822.c @@ -4856,8 +4856,8 @@ Refs_Analyze_Pattern (struct st_scanparams *scancfg, { /*d4df */ diff_max = color_dif[cnt]; - if (abs (color_dif[cnt] - color_dif[cnt - 1]) > - abs (color_dif[coord] - color_dif[coord - 1])) + if (fabs (color_dif[cnt] - color_dif[cnt - 1]) > + fabs (color_dif[coord] - color_dif[coord - 1])) coord = cnt; } @@ -4907,8 +4907,8 @@ Refs_Analyze_Pattern (struct st_scanparams *scancfg, if ((color_dif[cnt] >= 0) && (color_dif[cnt] > diff_max)) { diff_max = color_dif[cnt]; - if (abs (color_dif[cnt] - color_dif[cnt - 1]) > - abs (color_dif[coord] - color_dif[coord - 1])) + if (fabs (color_dif[cnt] - color_dif[cnt - 1]) > + fabs (color_dif[coord] - color_dif[coord - 1])) coord = cnt; } @@ -4954,8 +4954,8 @@ Refs_Analyze_Pattern (struct st_scanparams *scancfg, if ((color_dif[cnt] >= 0) && (color_dif[cnt] > diff_max)) { diff_max = color_dif[cnt]; - if (abs (color_dif[cnt] - color_dif[cnt - 1]) > - abs (color_dif[coord] - color_dif[coord - 1])) + if (fabs (color_dif[cnt] - color_dif[cnt - 1]) > + fabs (color_dif[coord] - color_dif[coord - 1])) coord = cnt; } @@ -7703,7 +7703,7 @@ Scan_Read_BufferA (struct st_device *dev, SANE_Int buffer_size, SANE_Int arg2, "+ Scan_Read_BufferA(buffer_size=%i, arg2, *pBuffer, *bytes_transferred):\n", buffer_size); - arg2 = arg2; /* silence gcc */ + (void) arg2; /* silence gcc */ *bytes_transferred = 0; if (pBuffer != NULL) @@ -11364,7 +11364,7 @@ Calib_CreateBuffers (struct st_device *dev, struct st_calibration *buffer, SANE_Int ebp, ret, channel; ret = ERROR; - dev = dev; + (void) dev; buffer->shadinglength = scan.coord.width; ebp = 0x14; @@ -12602,9 +12602,9 @@ Calib_BWShading (struct st_calibration_config *calibcfg, /*falta codigo */ /*silence gcc */ - calibcfg = calibcfg; - myCalib = myCalib; - gainmode = gainmode; + (void) calibcfg; + (void) myCalib; + (void) gainmode; return OK; } @@ -13624,7 +13624,7 @@ Calibration (struct st_device *dev, SANE_Byte * Regs, DBG (DBG_FNC, "> Calibration\n"); dbg_ScanParams (scancfg); - value = value; /*silence gcc */ + (void) value; /*silence gcc */ memcpy (&calibdata->Regs, Regs, sizeof (SANE_Byte) * RT_BUFFER_LEN); diff --git a/backend/hp3900_sane.c b/backend/hp3900_sane.c index eae99e0..5face5e 100644 --- a/backend/hp3900_sane.c +++ b/backend/hp3900_sane.c @@ -380,7 +380,7 @@ bknd_colormodes (TScanner * scanner, SANE_Int model) { SANE_VALUE_SCAN_MODE_COLOR, SANE_VALUE_SCAN_MODE_GRAY, SANE_VALUE_SCAN_MODE_LINEART, 0 }; /* silence gcc */ - model = model; + (void) model; colormode = (SANE_String_Const *) malloc (sizeof (mycolormode)); if (colormode != NULL) @@ -460,7 +460,7 @@ bknd_depths (TScanner * scanner, SANE_Int model) SANE_Int mydepth[] = { 2, 8, 16 }; /*{3, 8, 12, 16}; */ /* silence gcc */ - model = model; + (void) model; depth = (SANE_Int *) malloc (sizeof (mydepth)); if (depth != NULL) @@ -1760,7 +1760,7 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize) DBG (DBG_FNC, "> sane_init\n"); /* silence gcc */ - authorize = authorize; + (void) authorize; /* Initialize usb */ sanei_usb_init (); @@ -1816,7 +1816,7 @@ sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only) { SANE_Status rst = SANE_STATUS_GOOD; - local_only = local_only; + (void) local_only; if (_pSaneDevList) free (_pSaneDevList); @@ -2654,7 +2654,7 @@ sane_cancel (SANE_Handle h) DBG (DBG_FNC, "> sane_cancel\n"); /* silence gcc */ - h = h; + (void) h; device->status->cancel = TRUE; } @@ -2665,8 +2665,8 @@ sane_set_io_mode (SANE_Handle handle, SANE_Bool non_blocking) DBG (DBG_FNC, "> sane_set_io_mode\n"); /* silence gcc */ - handle = handle; - non_blocking = non_blocking; + (void) handle; + (void) non_blocking; return SANE_STATUS_UNSUPPORTED; } @@ -2677,8 +2677,8 @@ sane_get_select_fd (SANE_Handle handle, SANE_Int * fd) DBG (DBG_FNC, "> sane_get_select_fd\n"); /* silence gcc */ - handle = handle; - fd = fd; + (void) handle; + (void) fd; return SANE_STATUS_UNSUPPORTED; } diff --git a/backend/hp4200.c b/backend/hp4200.c index 5b21b47..e4e885e 100644 --- a/backend/hp4200.c +++ b/backend/hp4200.c @@ -512,7 +512,7 @@ read_available_data (HP4200_Scanner * s, SANE_Byte * buffer, buffer += really_read; to_read -= really_read; #ifdef DEBUG - fprintf (stderr, "read %d bytes\n", really_read); + fprintf (stderr, "read %zu bytes\n", really_read); #endif } return SANE_STATUS_GOOD; @@ -941,7 +941,6 @@ compute_dpd (HP4200_Scanner * s, int step_size, int line_end) static SANE_Status read_required_bytes (HP4200_Scanner * s, int required, SANE_Byte * buffer) { - int read_count = 0; unsigned char scankb1; unsigned char scankb2; size_t to_read; @@ -987,7 +986,6 @@ read_required_bytes (HP4200_Scanner * s, int required, SANE_Byte * buffer) buffer += really_read; required -= really_read; to_read -= really_read; - read_count += really_read; } } @@ -2369,7 +2367,7 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize) char dev_name[PATH_MAX]; FILE *fp; - authorize = authorize; /* keep gcc quiet */ + (void) authorize; /* keep gcc quiet */ DBG_INIT (); @@ -2939,7 +2937,7 @@ sane_set_io_mode (SANE_Handle handle, SANE_Bool non_blocking) HP4200_Scanner *dev = handle; SANE_Status status; - non_blocking = non_blocking; /* silence gcc */ + (void) non_blocking; /* silence gcc */ if (dev->scanning == SANE_FALSE) { @@ -2965,8 +2963,8 @@ sane_get_select_fd (SANE_Handle h, SANE_Int * fd) { static char me[] = "sane_get_select_fd"; - h = h; /* keep gcc quiet */ - fd = fd; /* keep gcc quiet */ + (void) h; /* keep gcc quiet */ + (void) fd; /* keep gcc quiet */ DBG (DBG_proc, "%s\n", me); return SANE_STATUS_UNSUPPORTED; diff --git a/backend/hp5400_internal.c b/backend/hp5400_internal.c index 322359a..95866c4 100644 --- a/backend/hp5400_internal.c +++ b/backend/hp5400_internal.c @@ -483,7 +483,7 @@ void CircBufferInit (int iHandle, TDataPipe * p, int iBytesPerLine, int bpp, int iMisAlignment, int blksize, int iTransferSize) { - iHandle = iHandle; /* to avoid compilation warning */ + (void) iHandle; /* to avoid compilation warning */ p->buffersize = max (BUFFER_SIZE, 3 * blksize); if (p->buffer) @@ -746,7 +746,7 @@ HP5400_SANE_STATIC int hp5400_test_scan_response (struct ScanResponse *resp, struct ScanRequest *req) { - req = req; /* to avoid compilation warning */ + (void) req; /* to avoid compilation warning */ HP5400_DBG (DBG_MSG, "Scan response:\n"); HP5400_DBG (DBG_MSG, " transfersize=%d htonl-> %d\n", resp->transfersize, htonl (resp->transfersize)); @@ -828,7 +828,7 @@ DoScan (int iHandle, struct ScanRequest *req, const char *filename, int code, /* int bpp, planes; */ int i; - code = code; /*to avoid compilation warning*/ + (void) code; /*to avoid compilation warning*/ if (res == NULL) res = &res_temp; @@ -1011,7 +1011,7 @@ hp5400_scan (int iHandle, TScanParams * params, THWParams * pHWParams, struct ScanResponse res; int result; - pHWParams = pHWParams; /*to avoid compilation warning*/ + (void) pHWParams; /*to avoid compilation warning*/ HP5400_DBG (DBG_MSG, "\n"); HP5400_DBG (DBG_MSG, "Scanning :\n"); diff --git a/backend/hp5400_sane.c b/backend/hp5400_sane.c index 5043dad..5e716a2 100644 --- a/backend/hp5400_sane.c +++ b/backend/hp5400_sane.c @@ -611,7 +611,7 @@ sane_init (SANE_Int * piVersion, SANE_Auth_Callback pfnAuth) int nline = 0; /* prevent compiler from complaining about unused parameters */ - pfnAuth = pfnAuth; + (void) pfnAuth; strcpy(usb_devfile, "/dev/usb/scanner0"); _pFirstSaneDev = 0; @@ -712,7 +712,7 @@ sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only) HP5400_DBG (DBG_MSG, "sane_get_devices\n"); - local_only = local_only; + (void) local_only; if (_pSaneDevList) { @@ -1333,7 +1333,7 @@ sane_set_io_mode (SANE_Handle h, SANE_Bool m) HP5400_DBG (DBG_MSG, "sane_set_io_mode %s\n", m ? "non-blocking" : "blocking"); /* prevent compiler from complaining about unused parameters */ - h = h; + (void) h; if (m) { @@ -1349,8 +1349,8 @@ sane_get_select_fd (SANE_Handle h, SANE_Int * fd) HP5400_DBG (DBG_MSG, "sane_select_fd\n"); /* prevent compiler from complaining about unused parameters */ - h = h; - fd = fd; + (void) h; + (void) fd; return SANE_STATUS_UNSUPPORTED; } diff --git a/backend/hp5590_low.c b/backend/hp5590_low.c index 29e2136..2d19dcf 100644 --- a/backend/hp5590_low.c +++ b/backend/hp5590_low.c @@ -796,8 +796,9 @@ hp5590_bulk_read (SANE_Int dn, DBG (DBG_err, "%s: USB-in-USB: attempted to access over the end of buffer " "(in_ptr: %p, end_ptr: %p, ptr: %p, buffer size: %u\n", - __func__, bulk_read_state->buffer_in_ptr, - bulk_read_state->buffer_end_ptr, bulk_read_state->buffer, + __func__, (void *) bulk_read_state->buffer_in_ptr, + (void *) bulk_read_state->buffer_end_ptr, + (void *) bulk_read_state->buffer, bulk_read_state->buffer_size); return SANE_STATUS_NO_MEM; } diff --git a/backend/hs2p.c b/backend/hs2p.c index 76f4b96..b2c6d76 100644 --- a/backend/hs2p.c +++ b/backend/hs2p.c @@ -3125,7 +3125,7 @@ sane_start (SANE_Handle handle) /* begin scanning */ sane_strstatus (status)); return (status); } - if ((s->data.adf_status & 0x00) == 0x01) + if ((s->data.adf_status & 0x01) == 0x01) { DBG (DBG_warning, "sane_start: No document on ADF\n"); return (SANE_STATUS_NO_DOCS); @@ -3322,8 +3322,8 @@ sane_get_select_fd (SANE_Handle handle, SANE_Int * fd) *fd = s->fd; return SANE_STATUS_GOOD; #else - handle = handle; - fd = fd; /* get rid of compiler warning */ + (void) handle; + (void) fd; /* get rid of compiler warning */ DBG (DBG_proc, "<< sane_get_select_fd\n"); return SANE_STATUS_UNSUPPORTED; #endif diff --git a/backend/ibm.c b/backend/ibm.c index 688cdfb..ab5fbc9 100644 --- a/backend/ibm.c +++ b/backend/ibm.c @@ -568,7 +568,8 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize) continue; /* ignore empty lines */ /* skip white space: */ - for (lp = line; isspace(*lp); ++lp); + for (lp = line; isspace(*lp); ++lp) + ; strcpy (devnam, lp); } fclose (fp); diff --git a/backend/kodak-cmd.h b/backend/kodak-cmd.h index 7d5d506..17e353c 100644 --- a/backend/kodak-cmd.h +++ b/backend/kodak-cmd.h @@ -133,10 +133,14 @@ putnbyte (unsigned char *pnt, unsigned int value, unsigned int nbytes) #define get_I_cmdque(in) getbitfield(in + 7, 1, 1) #define get_I_sftre(in) getbitfield(in + 7, 0, 1) -#define get_I_vendor(in, buf) strncpy(buf,(char *)in + 0x08, 0x08) -#define get_I_product(in, buf) strncpy(buf,(char *)in + 0x10, 0x10) -#define get_I_version(in, buf) strncpy(buf,(char *)in + 0x20, 0x04) -#define get_I_build(in, buf) strncpy(buf,(char *)in + 0x24, 0x02) +#define get_I_vendor(in, buf) snprintf(buf, 0x08 + 1, "%.*s", \ + 0x08, (char *)in + 0x08) +#define get_I_product(in, buf) snprintf(buf, 0x10 + 1, "%.*s", \ + 0x10, (char *)in + 0x10) +#define get_I_version(in, buf) snprintf(buf, 0x04 + 1, "%.*s", \ + 0x04, (char *)in + 0x20) +#define get_I_build(in, buf) snprintf(buf, 0x02 + 1, "%.*s", \ + 0x02, (char *)in + 0x24) #define get_I_mf_disable(in) getbitfield(in + 38, 7, 1) #define get_I_checkdigit(in) getbitfield(in + 38, 6, 1) diff --git a/backend/kodak.c b/backend/kodak.c index c41f088..b46ab2e 100644 --- a/backend/kodak.c +++ b/backend/kodak.c @@ -175,7 +175,7 @@ static struct scanner *scanner_devList = NULL; SANE_Status sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize) { - authorize = authorize; /* get rid of compiler warning */ + (void) authorize; /* get rid of compiler warning */ DBG_INIT (); DBG (10, "sane_init: start\n"); @@ -225,7 +225,7 @@ sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only) int num_devices=0; int i=0; - local_only = local_only; /* get rid of compiler warning */ + (void) local_only; /* get rid of compiler warning */ DBG (10, "sane_get_devices: start\n"); @@ -2550,7 +2550,7 @@ sense_handler (int fd, unsigned char * sensed_data, void *arg) DBG (5, "sense_handler: start\n"); /* kill compiler warning */ - fd = fd; + (void) fd; /* save for later */ s->rs_info = get_RS_information (sensed_data); @@ -2754,8 +2754,8 @@ do_cmd(struct scanner *s, int runRS, int shortTime, SANE_Status ret = SANE_STATUS_GOOD; /*shut up compiler*/ - runRS=runRS; - shortTime=shortTime; + (void) runRS; + (void) shortTime; DBG(10, "do_cmd: start\n"); diff --git a/backend/kodakaio.c b/backend/kodakaio.c index fe83e27..0241e2a 100644 --- a/backend/kodakaio.c +++ b/backend/kodakaio.c @@ -716,7 +716,6 @@ That is probably if the scanner disconnected the network connection /* pollreply is -ve */ DBG(1, "net poll error\n"); *status = SANE_STATUS_IO_ERROR; - return read; } else if((fds[0].revents & POLLIN) && !(fds[0].revents & (POLLERR | POLLHUP | POLLNVAL))) { while (read < wanted) { @@ -733,12 +732,11 @@ That is probably if the scanner disconnected the network connection *status = SANE_STATUS_IO_ERROR; DBG(32, "net read %lu bytes:%x,%x,%x,%x,%x,%x,%x,%x\n",(unsigned long)read,buf[0],buf[1],buf[2],buf[3],buf[4],buf[5],buf[6],buf[7]); - - return read; } else DBG(1, "Unknown problem with poll\n"); - return read; + + return read; } @@ -2046,7 +2044,7 @@ open_scanner(KodakAio_Scanner *s) unsigned int model = 0; if (!split_scanner_name (s->hw->sane.name, IP, &model)) return SANE_STATUS_INVAL; - DBG(10, "split_scanner_name OK model=0x%x\n",model); + DBG(10, "split_scanner_name OK model=0x%x\n",model); /* normal with IP */ status = sanei_tcp_open(IP, 9101, &s->fd); /* (host,port,file pointer) */ diff --git a/backend/kvs1025.c b/backend/kvs1025.c index 9d53690..9c8b56f 100644 --- a/backend/kvs1025.c +++ b/backend/kvs1025.c @@ -442,15 +442,15 @@ sane_cancel (SANE_Handle handle) SANE_Status sane_set_io_mode (SANE_Handle h, SANE_Bool m) { - h=h; - m=m; + (void) h; + (void) m; return SANE_STATUS_UNSUPPORTED; } SANE_Status sane_get_select_fd (SANE_Handle h, SANE_Int * fd) { - h=h; - fd=fd; + (void) h; + (void) fd; return SANE_STATUS_UNSUPPORTED; } diff --git a/backend/kvs20xx_opt.c b/backend/kvs20xx_opt.c index 3e82764..229bf85 100644 --- a/backend/kvs20xx_opt.c +++ b/backend/kvs20xx_opt.c @@ -673,11 +673,6 @@ mm2scanner_units (unsigned mm) { return mm * 12000 / 254; } -static inline unsigned -scanner_units2mm (unsigned u) -{ - return u * 254 / 12000; -} void kvs20xx_init_window (struct scanner *s, struct window *wnd, int wnd_id) diff --git a/backend/kvs40xx.c b/backend/kvs40xx.c index 230bdc2..fd3cfe0 100644 --- a/backend/kvs40xx.c +++ b/backend/kvs40xx.c @@ -118,11 +118,6 @@ static inline void buf_set_st(struct buf *b, SANE_Status st) pthread_mutex_unlock(&b->mu); } -static inline void buf_cancel(struct buf *b) -{ - buf_set_st(b, SANE_STATUS_CANCELLED); -} - static inline void push_buf(struct buf *b, SANE_Int sz) { pthread_mutex_lock(&b->mu); @@ -547,10 +542,10 @@ static void * read_data (void *arg) sane_get_parameters(s, NULL); s->page++; - return SANE_STATUS_GOOD; + return NULL; err: s->scanning = 0; - return (void *) st; + return NULL; } /* Start scanning */ diff --git a/backend/kvs40xx_opt.c b/backend/kvs40xx_opt.c index 8c37711..2d8d870 100644 --- a/backend/kvs40xx_opt.c +++ b/backend/kvs40xx_opt.c @@ -29,11 +29,6 @@ mm2scanner_units (unsigned mm) { return (mm * 12000 / 254.0 + .5); } -static inline unsigned -scanner_units2mm (unsigned u) -{ - return (u * 254.0 / 12000 + .5); -} struct restriction { unsigned ux, uy, ux_pix, uy_pix; diff --git a/backend/lexmark_low.c b/backend/lexmark_low.c index 052ae4d..246455f 100644 --- a/backend/lexmark_low.c +++ b/backend/lexmark_low.c @@ -4994,14 +4994,14 @@ sanei_lexmark_low_read_scan_data (SANE_Byte * data, SANE_Int size, DBG (2, " Filled a buffer from the scanner\n"); DBG (2, " bytes_remaining: %lu\n", (u_long) dev->bytes_remaining); DBG (2, " bytes_in_buffer: %lu\n", (u_long) dev->bytes_in_buffer); - DBG (2, " read_pointer: %p\n", dev->read_pointer); + DBG (2, " read_pointer: %p\n", (void *) dev->read_pointer); } } DBG (5, "READ BUFFER INFO: \n"); - DBG (5, " write ptr: %p\n", dev->read_buffer->writeptr); - DBG (5, " read ptr: %p\n", dev->read_buffer->readptr); - DBG (5, " max write ptr: %p\n", dev->read_buffer->max_writeptr); + DBG (5, " write ptr: %p\n", (void *) dev->read_buffer->writeptr); + DBG (5, " read ptr: %p\n", (void *) dev->read_buffer->readptr); + DBG (5, " max write ptr: %p\n", (void *) dev->read_buffer->max_writeptr); DBG (5, " buffer size: %lu\n", (u_long) dev->read_buffer->size); DBG (5, " line size: %lu\n", (u_long) dev->read_buffer->linesize); DBG (5, " empty: %d\n", dev->read_buffer->empty); @@ -5059,9 +5059,9 @@ sanei_lexmark_low_read_scan_data (SANE_Byte * data, SANE_Int size, } DBG (5, "READ BUFFER INFO: \n"); - DBG (5, " write ptr: %p\n", dev->read_buffer->writeptr); - DBG (5, " read ptr: %p\n", dev->read_buffer->readptr); - DBG (5, " max write ptr: %p\n", dev->read_buffer->max_writeptr); + DBG (5, " write ptr: %p\n", (void *) dev->read_buffer->writeptr); + DBG (5, " read ptr: %p\n", (void *) dev->read_buffer->readptr); + DBG (5, " max write ptr: %p\n", (void *) dev->read_buffer->max_writeptr); DBG (5, " buffer size: %lu\n", (u_long) dev->read_buffer->size); DBG (5, " line size: %lu\n", (u_long) dev->read_buffer->linesize); DBG (5, " empty: %d\n", dev->read_buffer->empty); @@ -5074,7 +5074,7 @@ sanei_lexmark_low_read_scan_data (SANE_Byte * data, SANE_Int size, DBG (2, " Copying lines from buffer to data\n"); DBG (2, " bytes_remaining: %lu\n", (u_long) dev->bytes_remaining); DBG (2, " bytes_in_buffer: %lu\n", (u_long) dev->bytes_in_buffer); - DBG (2, " read_pointer: %p\n", dev->read_buffer->readptr); + DBG (2, " read_pointer: %p\n", (void *) dev->read_buffer->readptr); DBG (2, " bytes_read %lu\n", (u_long) bytes_read); /* if no more bytes to xfer and read buffer empty we're at the end */ @@ -5252,12 +5252,12 @@ read_buffer_bytes_available (Read_Buffer * rb) if (rb->empty) return rb->size; - else if ((size_t) abs (rb->writeptr - rb->readptr) < rb->linesize) - return 0; /* ptrs are less than one line apart */ else if (rb->writeptr < rb->readptr) - return (rb->readptr - rb->writeptr - rb->linesize); + return (size_t)(rb->readptr - rb->writeptr) < rb->linesize ? 0 : + (size_t)(rb->readptr - rb->writeptr) - rb->linesize; else - return (rb->size + rb->readptr - rb->writeptr - rb->linesize); + return (size_t)(rb->writeptr - rb->readptr) < rb->linesize ? 0 : + rb->size - (size_t)(rb->writeptr - rb->readptr) - rb->linesize; } SANE_Status diff --git a/backend/ma1509.c b/backend/ma1509.c index 5966a17..f42541f 100644 --- a/backend/ma1509.c +++ b/backend/ma1509.c @@ -161,7 +161,7 @@ ma1509_cmd (Ma1509_Scanner * s, const SANE_Byte * cmd, SANE_Byte * data, #define MA1509_READ_LIMIT (1024 * 256) DBG (5, "ma1509_cmd: fd=%d, cmd=%p, data=%p, data_size=%ld\n", - s->fd, cmd, data, (long int) (data_size ? *data_size : 0)); + s->fd, (void *) cmd, (void *) data, (long int) (data_size ? *data_size : 0)); DBG (5, "ma1509_cmd: cmd = %02x %02x %02x %02x %02x %02x %02x %02x \n", cmd[0], cmd[1], cmd[2], cmd[3], cmd[4], cmd[5], cmd[6], cmd[7]); diff --git a/backend/magicolor.c b/backend/magicolor.c index 8fc6d31..5278937 100644 --- a/backend/magicolor.c +++ b/backend/magicolor.c @@ -3001,7 +3001,7 @@ sane_read(SANE_Handle handle, SANE_Byte *data, SANE_Int max_length, } DBG(18, "moving data %p %p, %d (%d lines)\n", - s->ptr, s->end, + (void *) s->ptr, (void *) s->end, max_length, max_length / s->params.bytes_per_line); mc_copy_image_data(s, data, max_length, length); diff --git a/backend/microtek.c b/backend/microtek.c index 17f3151..d9b0a6b 100644 --- a/backend/microtek.c +++ b/backend/microtek.c @@ -1502,14 +1502,10 @@ parse_inquiry(Microtek_Info *mi, unsigned char *result) }; #endif DBG(15, "parse_inquiry...\n"); - strncpy(mi->vendor_id, (char *)&result[8], 8); - strncpy(mi->model_name, (char *)&result[16], 16); - strncpy(mi->revision_num, (char *)&result[32], 4); - strncpy(mi->vendor_string, (char *)&result[36], 20); - mi->vendor_id[8] = 0; - mi->model_name[16] = 0; - mi->revision_num[4] = 0; - mi->vendor_string[20] = 0; + snprintf(mi->vendor_id, 8 + 1, "%.*s", 8, (char *)&result[8]); + snprintf(mi->model_name, 16 + 1, "%.*s", 16, (char *)&result[16]); + snprintf(mi->revision_num, 4 + 1, "%.*s", 4, (char *)&result[32]); + snprintf(mi->vendor_string, 20 + 1, "%.*s", 20, (char *)&result[36]); mi->device_type = (SANE_Byte)(result[0] & 0x1f); mi->SCSI_firmware_ver_major = (SANE_Byte)((result[1] & 0xf0) >> 4); @@ -1925,7 +1921,7 @@ static SANE_Status dump_suspect_inquiry(unsigned char *result) { int i; - char vendor_id[64], model_name[64], revision_num[16]; + char vendor_id[9], model_name[17], revision_num[5]; SANE_Byte device_type, model_code; SANE_Byte SCSI_firmware_ver_major, SCSI_firmware_ver_minor; SANE_Byte scanner_firmware_ver_major, scanner_firmware_ver_minor; @@ -1947,12 +1943,9 @@ dump_suspect_inquiry(unsigned char *result) } fprintf(stderr, "\n\n"); #endif - strncpy(vendor_id, (char *)&result[8], 8); - strncpy(model_name, (char *)&result[16], 16); - strncpy(revision_num, (char *)&result[32], 4); - vendor_id[8] = 0; - model_name[16] = 0; - revision_num[5] = 0; + snprintf(vendor_id, 8 + 1, "%.*s", 8, (char *)&result[8]); + snprintf(model_name, 16 + 1, "%.*s", 16, (char *)&result[16]); + snprintf(revision_num, 4 + 1, "%.*s", 4, (char *)&result[32]); device_type = (SANE_Byte)(result[0] & 0x1f); SCSI_firmware_ver_major = (SANE_Byte)((result[1] & 0xf0) >> 4); SCSI_firmware_ver_minor = (SANE_Byte)(result[1] & 0x0f); @@ -2356,7 +2349,8 @@ static SANE_Status do_real_calibrate(Microtek_Scanner *s) input = calloc(STRIPS * 3 * linewidth, sizeof(input[0])); combuff = calloc(linewidth + 6, sizeof(combuff[0])); if ((input == NULL) || (combuff == NULL)) { - DBG(23, "do_real_cal: bad calloc %p %p\n", input, combuff); + DBG(23, "do_real_cal: bad calloc %p %p\n", + (void *) input, (void *) combuff); free(input); free(combuff); return SANE_STATUS_NO_MEM; @@ -2370,7 +2364,7 @@ static SANE_Status do_real_calibrate(Microtek_Scanner *s) ntoget = (nleft > nmax) ? nmax : nleft; buffsize = ntoget * 3 * linewidth; DBG(23, "...nleft %d toget %d size %lu spot %d input+spot %p\n", - nleft, ntoget, (u_long) buffsize, spot, input+spot); + nleft, ntoget, (u_long) buffsize, spot, (void *) (input+spot)); if ((statusA = read_scan_data(s, ntoget, input+spot, &buffsize)) != SANE_STATUS_GOOD) { DBG(23, "...read scan failed\n"); @@ -3060,7 +3054,7 @@ sane_init(SANE_Int *version_code, SANE_Auth_Callback authorize) size_t len; FILE *fp; - authorize = authorize; + (void) authorize; DBG_INIT(); DBG(1, "sane_init: MICROTEK says hello! (v%d.%d.%d)\n", MICROTEK_MAJOR, MICROTEK_MINOR, MICROTEK_PATCH); @@ -3111,7 +3105,7 @@ sane_get_devices(const SANE_Device ***device_list, Microtek_Device *dev; int i; - local_only = local_only; + (void) local_only; DBG(10, "sane_get_devices\n"); /* we keep an internal copy */ if (devlist) @@ -4166,7 +4160,7 @@ SANE_Status sane_set_io_mode (SANE_Handle handle, SANE_Bool non_blocking) { DBG(10, "sane_set_io_mode...\n"); - handle = handle; + (void) handle; if (non_blocking) return SANE_STATUS_UNSUPPORTED; else @@ -4182,6 +4176,6 @@ SANE_Status sane_get_select_fd (SANE_Handle handle, SANE_Int * fd) { DBG(10, "sane_get_select_fd...\n"); - handle = handle, fd = fd; + (void) handle, (void) fd; return SANE_STATUS_UNSUPPORTED; } diff --git a/backend/microtek2.c b/backend/microtek2.c index 505e86b..cc14488 100644 --- a/backend/microtek2.c +++ b/backend/microtek2.c @@ -195,7 +195,7 @@ sane_exit (void) if ( md_first_dev->shading_table_w ) { DBG(100, "free md_first_dev->shading_table_w at %p\n", - md_first_dev->shading_table_w); + (void *) md_first_dev->shading_table_w); free((void *) md_first_dev->shading_table_w); md_first_dev->shading_table_w = NULL; } @@ -203,7 +203,7 @@ sane_exit (void) if ( md_first_dev->shading_table_d ) { DBG(100, "free md_first_dev->shading_table_d at %p\n", - md_first_dev->shading_table_d); + (void *) md_first_dev->shading_table_d); free((void *) md_first_dev->shading_table_d); md_first_dev->shading_table_d = NULL; } @@ -599,7 +599,8 @@ sane_read(SANE_Handle handle, SANE_Byte *buf, SANE_Int maxlen, SANE_Int *len ) ssize_t nread; - DBG(30, "sane_read: handle=%p, buf=%p, maxlen=%d\n", handle, buf, maxlen); + DBG(30, "sane_read: handle=%p, buf=%p, maxlen=%d\n", + handle, (void *) buf, maxlen); *len = 0; @@ -742,7 +743,7 @@ add_device_list(SANE_String_Const dev_name, Microtek2_Device **mdev) md->opts = md_options; ++md_num_devices; *mdev = md; - DBG(100, "free hdev at %p\n", hdev); + DBG(100, "free hdev at %p\n", (void *) hdev); free(hdev); return SANE_STATUS_GOOD; @@ -1360,53 +1361,56 @@ cleanup_scanner(Microtek2_Scanner *ms) /* free buffers */ if ( ms->buf.src_buffer[0] ) { - DBG(100, "free ms->buf.src_buffer[0] at %p\n", ms->buf.src_buffer[0]); + DBG(100, "free ms->buf.src_buffer[0] at %p\n", + (void *) ms->buf.src_buffer[0]); free((void *) ms->buf.src_buffer[0]); ms->buf.src_buffer[0] = NULL; ms->buf.src_buf = NULL; } if ( ms->buf.src_buffer[1] ) { - DBG(100, "free ms->buf.src_buffer[1] at %p\n", ms->buf.src_buffer[1]); + DBG(100, "free ms->buf.src_buffer[1] at %p\n", + (void *) ms->buf.src_buffer[1]); free((void *) ms->buf.src_buffer[1]); ms->buf.src_buffer[1] = NULL; ms->buf.src_buf = NULL; } if ( ms->buf.src_buf ) { - DBG(100, "free ms->buf.src_buf at %p\n", ms->buf.src_buf); + DBG(100, "free ms->buf.src_buf at %p\n", (void *) ms->buf.src_buf); free((void *) ms->buf.src_buf); ms->buf.src_buf = NULL; } if ( ms->temporary_buffer ) { - DBG(100, "free ms->temporary_buffer at %p\n", ms->temporary_buffer); + DBG(100, "free ms->temporary_buffer at %p\n", + (void *) ms->temporary_buffer); free((void *) ms->temporary_buffer); ms->temporary_buffer = NULL; } if ( ms->gamma_table ) { - DBG(100, "free ms->gamma_table at %p\n", ms->gamma_table); + DBG(100, "free ms->gamma_table at %p\n", (void *) ms->gamma_table); free((void *) ms->gamma_table); ms->gamma_table = NULL; } if ( ms->control_bytes ) { - DBG(100, "free ms->control_bytes at %p\n", ms->control_bytes); + DBG(100, "free ms->control_bytes at %p\n", (void *) ms->control_bytes); free((void *) ms->control_bytes); ms->control_bytes = NULL; } if ( ms->condensed_shading_w ) { DBG(100, "free ms->condensed_shading_w at %p\n", - ms->condensed_shading_w); + (void *) ms->condensed_shading_w); free((void *) ms->condensed_shading_w); ms->condensed_shading_w = NULL; } if ( ms->condensed_shading_d ) { DBG(100, "free ms->condensed_shading_d at %p\n", - ms->condensed_shading_d); + (void *) ms->condensed_shading_d); free((void *) ms->condensed_shading_d); ms->condensed_shading_d = NULL; } @@ -3901,8 +3905,8 @@ get_scan_parameters(Microtek2_Scanner *ms) if ( y2_dots >= mi->geo_height ) y2_dots = mi->geo_height - 1; ms->width_dots = x2_dots - ms->x1_dots; - if ( md->model_flags && MD_OFFSET_2 ) /* this firmware has problems with */ - if ( ( ms->width_dots % 2 ) == 1 ) /* odd pixel numbers */ + if ( md->model_flags & MD_OFFSET_2 ) /* this firmware has problems with */ + if ( ( ms->width_dots % 2 ) == 1 ) /* odd pixel numbers */ ms->width_dots -= 1; if ( ms->width_dots < 10 ) ms->width_dots = 10; @@ -4201,7 +4205,8 @@ scsi_send_gamma(Microtek2_Scanner *ms) DBG(30, "scsi_send_gamma: pos=%p, size=%d, word=%d, color=%d\n", - ms->gamma_table, ms->lut_size_bytes, ms->word, ms->current_color); + (void *) ms->gamma_table, ms->lut_size_bytes, ms->word, + ms->current_color); if ( ( 3 * ms->lut_size_bytes ) <= 0xffff ) /*send Gamma with one command*/ { @@ -4465,7 +4470,7 @@ scsi_read_control_bits(Microtek2_Scanner *ms) int count_1s; DBG(30, "scsi_read_control_bits: ms=%p, fd=%d\n", (void *) ms, ms->sfd); - DBG(30, "ms->control_bytes = %p\n", ms->control_bytes); + DBG(30, "ms->control_bytes = %p\n", (void *) ms->control_bytes); RCB_SET_CMD(cmd); RCB_SET_LENGTH(cmd, ms->n_control_bytes); @@ -4520,7 +4525,7 @@ scsi_set_window(Microtek2_Scanner *ms, int n) { /* n windows, not yet */ size = SW_CMD_L + SW_HEADER_L + n * SW_BODY_L; setwindow = (uint8_t *) malloc(size); DBG(100, "scsi_set_window: setwindow= %p, malloc'd %d Bytes\n", - setwindow, size); + (void *) setwindow, size); if ( setwindow == NULL ) { DBG(1, "scsi_set_window: malloc for setwindow failed\n"); @@ -4592,7 +4597,7 @@ scsi_set_window(Microtek2_Scanner *ms, int n) { /* n windows, not yet */ if ( status != SANE_STATUS_GOOD ) DBG(1, "scsi_set_window: '%s'\n", sane_strstatus(status)); - DBG(100, "scsi_set_window: free setwindow at %p\n", setwindow); + DBG(100, "scsi_set_window: free setwindow at %p\n", (void *) setwindow); free((void *) setwindow); return status; } @@ -4665,7 +4670,8 @@ scsi_read_image(Microtek2_Scanner *ms, uint8_t *buffer, int bytes_per_pixel) uint8_t tmp; - DBG(30, "scsi_read_image: ms=%p, buffer=%p\n", (void *) ms, buffer); + DBG(30, "scsi_read_image: ms=%p, buffer=%p\n", + (void *) ms, (void *) buffer); ENDIAN_TYPE(endiantype) RI_SET_CMD(cmd); @@ -4790,7 +4796,7 @@ scsi_read_shading(Microtek2_Scanner *ms, uint8_t *buffer, uint32_t length) size_t size; DBG(30, "scsi_read_shading: pos=%p, size=%d, word=%d, color=%d, dark=%d\n", - buffer, length, ms->word, ms->current_color, ms->dark); + (void *) buffer, length, ms->word, ms->current_color, ms->dark); size = length; @@ -4807,7 +4813,8 @@ scsi_read_shading(Microtek2_Scanner *ms, uint8_t *buffer, uint32_t length) DBG(100, "scsi_read_shading: sfd=%d, cmd=%p, sizeofcmd=%lu," "dest=%p, destsize=%lu\n", - ms->sfd, cmd, (u_long) sizeof(cmd), buffer, (u_long) size); + ms->sfd, (void *) cmd, (u_long) sizeof(cmd), (void *) buffer, + (u_long) size); status = sanei_scsi_cmd(ms->sfd, cmd, sizeof(cmd), buffer, &size); if ( status != SANE_STATUS_GOOD ) @@ -4837,12 +4844,11 @@ scsi_send_shading(Microtek2_Scanner *ms, DBG(30, "scsi_send_shading: pos=%p, size=%d, word=%d, color=%d, dark=%d\n", - shading_data, length, ms->word, ms->current_color, - dark); + (void *) shading_data, length, ms->word, ms->current_color, dark); cmd = (uint8_t *) malloc(SSI_CMD_L + length); DBG(100, "scsi_send_shading: cmd=%p, malloc'd %d bytes\n", - cmd, SSI_CMD_L + length); + (void *) cmd, SSI_CMD_L + length); if ( cmd == NULL ) { DBG(1, "scsi_send_shading: Couldn't get buffer for shading table\n"); @@ -4868,7 +4874,7 @@ scsi_send_shading(Microtek2_Scanner *ms, if ( status != SANE_STATUS_GOOD ) DBG(1, "scsi_send_shading: '%s'\n", sane_strstatus(status)); - DBG(100, "free cmd at %p\n", cmd); + DBG(100, "free cmd at %p\n", (void *) cmd); free((void *) cmd); return status; @@ -5070,7 +5076,8 @@ scsi_sense_handler (int fd, u_char *sense, void *arg) uint8_t ascq; - DBG(30, "scsi_sense_handler: fd=%d, sense=%p arg=%p\n",fd, sense, arg); + DBG(30, "scsi_sense_handler: fd=%d, sense=%p arg=%p\n", + fd, (void *) sense, arg); dump_area(sense, RQS_LENGTH(sense), "SenseBuffer"); @@ -5264,7 +5271,7 @@ sane_start(SANE_Handle handle) if (ms->control_bytes) free((void *)ms->control_bytes); ms->control_bytes = (uint8_t *) malloc(ms->n_control_bytes); DBG(100, "sane_start: ms->control_bytes=%p, malloc'd %lu bytes\n", - ms->control_bytes, (u_long) ms->n_control_bytes); + (void *) ms->control_bytes, (u_long) ms->n_control_bytes); if ( ms->control_bytes == NULL ) { DBG(1, "sane_start: malloc() for control bits failed\n"); @@ -5373,7 +5380,7 @@ sane_start(SANE_Handle handle) ms->gamma_table = (uint8_t *) malloc(3 * ms->lut_size_bytes ); DBG(100, "sane_start: ms->gamma_table=%p, malloc'd %d bytes\n", - ms->gamma_table, 3 * ms->lut_size_bytes); + (void *) ms->gamma_table, 3 * ms->lut_size_bytes); if ( ms->gamma_table == NULL ) { DBG(1, "sane_start: malloc for gammatable failed\n"); @@ -5559,7 +5566,7 @@ prepare_buffers(Microtek2_Scanner *ms) ms->buf.src_buffer[i] = (uint8_t *) malloc(ms->src_buffer_size + extra_buf_size); DBG(100, "prepare_buffers: ms->buf.src_buffer[%d]=%p," - "malloc'd %d bytes\n", i, ms->buf.src_buffer[i], + "malloc'd %d bytes\n", i, (void *) ms->buf.src_buffer[i], ms->src_buffer_size + extra_buf_size); if ( ms->buf.src_buffer[i] == NULL ) { @@ -5579,7 +5586,7 @@ prepare_buffers(Microtek2_Scanner *ms) free((void *) ms->buf.src_buf); ms->buf.src_buf = malloc(ms->src_buffer_size); DBG(100, "sane_start: ms->buf.src_buf=%p, malloc'd %d bytes\n", - ms->buf.src_buf, ms->src_buffer_size); + (void *) ms->buf.src_buf, ms->src_buffer_size); if ( ms->buf.src_buf == NULL ) { DBG(1, "sane_start: malloc for scan buffer failed\n"); @@ -5602,7 +5609,7 @@ prepare_buffers(Microtek2_Scanner *ms) { ms->temporary_buffer = (uint8_t *) malloc(ms->remaining_bytes); DBG(100, "sane_start: ms->temporary_buffer=%p, malloc'd %d bytes\n", - ms->temporary_buffer, ms->remaining_bytes); + (void *) ms->temporary_buffer, ms->remaining_bytes); if ( ms->temporary_buffer == NULL ) { DBG(1, "sane_start: malloc() for temporary buffer failed\n"); @@ -5918,7 +5925,8 @@ condense_shading(Microtek2_Scanner *ms) } ms->condensed_shading_w = (uint8_t *)malloc(cond_length); DBG(100, "condense_shading: ms->condensed_shading_w=%p," - "malloc'd %d bytes\n", ms->condensed_shading_w, cond_length); + "malloc'd %d bytes\n", + (void *) ms->condensed_shading_w, cond_length); if ( ms->condensed_shading_w == NULL ) { DBG(1, "condense_shading: malloc for white table failed\n"); @@ -5938,7 +5946,8 @@ condense_shading(Microtek2_Scanner *ms) } ms->condensed_shading_d = (uint8_t *)malloc(cond_length); DBG(100, "condense_shading: ms->condensed_shading_d=%p," - " malloc'd %d bytes\n", ms->condensed_shading_d, cond_length); + " malloc'd %d bytes\n", + (void *) ms->condensed_shading_d, cond_length); if ( ms->condensed_shading_d == NULL ) { DBG(1, "condense_shading: malloc for dark table failed\n"); @@ -6100,7 +6109,8 @@ read_shading_image(Microtek2_Scanner *ms) ms->shading_image = malloc(ms->bpl * ms->src_remaining_lines); DBG(100, "read shading image: ms->shading_image=%p," " malloc'd %d bytes\n", - ms->shading_image, ms->bpl * ms->src_remaining_lines); + (void *) ms->shading_image, + ms->bpl * ms->src_remaining_lines); if ( ms->shading_image == NULL ) { DBG(1, "read_shading_image: malloc for buffer failed\n"); @@ -6166,7 +6176,7 @@ read_shading_image(Microtek2_Scanner *ms) } DBG(100, "free memory for ms->shading_image at %p\n", - ms->shading_image); + (void *) ms->shading_image); free((void *) ms->shading_image); ms->shading_image = NULL; } @@ -6241,7 +6251,7 @@ read_shading_image(Microtek2_Scanner *ms) ms->shading_image = malloc(ms->bpl * ms->src_remaining_lines); DBG(100, "read shading image: ms->shading_image=%p, malloc'd %d bytes\n", - ms->shading_image, ms->bpl * ms->src_remaining_lines); + (void *) ms->shading_image, ms->bpl * ms->src_remaining_lines); if ( ms->shading_image == NULL ) { DBG(1, "read_shading_image: malloc for buffer failed\n"); @@ -6328,7 +6338,7 @@ read_shading_image(Microtek2_Scanner *ms) return status; DBG(100, "free memory for ms->shading_image at %p\n", - ms->shading_image); + (void *) ms->shading_image); free((void *) ms->shading_image); ms->shading_image = NULL; @@ -6360,7 +6370,7 @@ prepare_shading_data(Microtek2_Scanner *ms, uint32_t lines, uint8_t **data) #endif DBG(30, "prepare_shading_data: ms=%p, lines=%d, *data=%p\n", - (void *) ms, lines, *data); + (void *) ms, lines, (void *) *data); md = ms->dev; mi = &md->info[md->scan_source]; @@ -6373,7 +6383,7 @@ prepare_shading_data(Microtek2_Scanner *ms, uint32_t lines, uint8_t **data) { *data = (uint8_t *) malloc(length); DBG(100, "prepare_shading_data: malloc'd %d bytes at %p\n", - length, *data); + length, (void *) *data); if ( *data == NULL ) { DBG(1, "prepare_shading_data: malloc for shading table failed\n"); @@ -6597,7 +6607,7 @@ read_cx_shading_image(Microtek2_Scanner *ms) } ms->shading_image = malloc(shading_bytes); DBG(100, "read_cx_shading: ms->shading_image=%p, malloc'd %d bytes\n", - ms->shading_image, shading_bytes); + (void *) ms->shading_image, shading_bytes); if ( ms->shading_image == NULL ) { DBG(1, "read_cx_shading: malloc for cx_shading buffer failed\n"); @@ -6642,7 +6652,7 @@ read_cx_shading_image(Microtek2_Scanner *ms) if ( ms->shading_image ) { DBG(100, "free memory for ms->shading_image at %p\n", - ms->shading_image); + (void *) ms->shading_image); free((void *) ms->shading_image); ms->shading_image = NULL; } @@ -6694,7 +6704,7 @@ calc_cx_shading_line(Microtek2_Scanner *ms) free( (void *)md->shading_table_w ); md->shading_table_w = (uint8_t *) malloc(shading_line_bytes); DBG(100, "calc_cx_shading: md->shading_table_w=%p, malloc'd %d bytes\n", - md->shading_table_w, shading_line_bytes); + (void *) md->shading_table_w, shading_line_bytes); if ( md->shading_table_w == NULL ) { DBG(100, "calc_cx_shading: malloc for white shadingtable failed\n"); @@ -6711,7 +6721,7 @@ calc_cx_shading_line(Microtek2_Scanner *ms) free( (void *)md->shading_table_d); md->shading_table_d = (uint8_t *) malloc(shading_line_bytes); DBG(100, "calc_cx_shading: md->shading_table_d=%p, malloc'd %d bytes\n", - md->shading_table_d, shading_line_bytes); + (void *) md->shading_table_d, shading_line_bytes); if ( md->shading_table_d == NULL ) { @@ -6729,8 +6739,9 @@ calc_cx_shading_line(Microtek2_Scanner *ms) "shading_line_bytes=%d\n" "shading_line_pixels=%d\n" "shading_table_pointer=%p\n", - (void *) ms, md->shading_table_w, md->shading_table_d, - shading_line_bytes, shading_line_pixels, shading_table_pointer); + (void *) ms, (void *) md->shading_table_w, + (void *) md->shading_table_d, shading_line_bytes, + shading_line_pixels, (void *) shading_table_pointer); /* calculating the median pixel values over the shading lines */ /* and write them to the shading table */ @@ -6862,7 +6873,7 @@ calculate_gamma(Microtek2_Scanner *ms, uint8_t *pos, int color, char *mode) DBG(30, "calculate_gamma: ms=%p, pos=%p, color=%d, mode=%s\n", - (void *) ms, pos, color, mode); + (void *) ms, (void *) pos, color, mode); md = ms->dev; mi = &md->info[md->scan_source]; @@ -6980,7 +6991,7 @@ shading_function(Microtek2_Scanner *ms, uint8_t *data) int i; - DBG(40, "shading_function: ms=%p, data=%p\n", (void *) ms, data); + DBG(40, "shading_function: ms=%p, data=%p\n", (void *) ms, (void *) data); md = ms->dev; mi = &md->info[md->scan_source]; @@ -7174,8 +7185,9 @@ reader_process(void *data) ms->transfer_length = ms->src_lines_to_read * ms->bpl; DBG(30, "reader_process: transferlength=%d, lines=%d, linelength=%d, " - "real_bpl=%d, srcbuf=%p\n", ms->transfer_length, - ms->src_lines_to_read, ms->bpl, ms->real_bpl, ms->buf.src_buf); + "real_bpl=%d, srcbuf=%p\n", + ms->transfer_length, ms->src_lines_to_read, ms->bpl, + ms->real_bpl, (void *) ms->buf.src_buf); sigprocmask (SIG_BLOCK, &sigterm_set, 0); status = scsi_read_image(ms, ms->buf.src_buf, (ms->depth > 8) ? 2 : 1); @@ -7333,7 +7345,7 @@ chunky_copy_pixels(Microtek2_Scanner *ms, uint8_t *from) int color; DBG(30, "chunky_copy_pixels: from=%p, pixels=%d, fp=%p, depth=%d\n", - from, ms->ppl, (void *) ms->fp, ms->depth); + (void *) from, ms->ppl, (void *) ms->fp, ms->depth); md = ms->dev; if ( ms->depth > 8 ) @@ -7512,7 +7524,7 @@ segreg_proc_data(Microtek2_Scanner *ms) } DBG(30, "segreg_proc_data: src_buf=%p, free_lines=%d\n", - ms->buf.src_buf, ms->buf.free_lines); + (void *) ms->buf.src_buf, ms->buf.free_lines); return SANE_STATUS_GOOD; } @@ -7881,7 +7893,7 @@ wordchunky_copy_pixels(uint8_t *from, uint32_t pixels, int depth, FILE *fp) int color; DBG(30, "wordchunky_copy_pixels: from=%p, pixels=%d, depth=%d\n", - from, pixels, depth); + (void *) from, pixels, depth); if ( depth > 8 ) { @@ -7993,7 +8005,7 @@ gray_copy_pixels(Microtek2_Scanner *ms, float s_w, s_d, shading_factor = 0; DBG(30, "gray_copy_pixels: pixels=%d, from=%p, fp=%p, depth=%d\n", - ms->ppl, from, (void *) ms->fp, ms->depth); + ms->ppl, (void *) from, (void *) ms->fp, ms->depth); md = ms->dev; step = right_to_left == 1 ? -1 : 1; @@ -8228,7 +8240,7 @@ lineartfake_copy_pixels(Microtek2_Scanner *ms, DBG(30, "lineartfake_copy_pixels: from=%p,pixels=%d,threshold=%d,file=%p\n", - from, pixels, threshold, (void *) fp); + (void *) from, pixels, threshold, (void *) fp); md = ms->dev; bit = 0; dest = 0; @@ -8302,7 +8314,7 @@ auto_adjust_proc_data(Microtek2_Scanner *ms, uint8_t **temp_current) DBG(30, "auto_adjust_proc_data: ms=%p, temp_current=%p\n", - (void *) ms, *temp_current); + (void *) ms, (void *) *temp_current); md = ms->dev; mi = &md->info[md->scan_source]; diff --git a/backend/microtek2.h b/backend/microtek2.h index 3cd1365..e3bc493 100644 --- a/backend/microtek2.h +++ b/backend/microtek2.h @@ -827,7 +827,7 @@ typedef struct Microtek2_Info { SANE_Byte nlens; SANE_Byte nwindows; SANE_Byte shtrnsferequ; -#define MI_WHITE_SHADING_ONLY(x) ((x) & 0x20) == 0 +#define MI_WHITE_SHADING_ONLY(x) (((x) & 0x20) == 0) #define MI_HAS_SCNBTTN SANE_TRUE SANE_Bool scnbuttn; #define MI_HAS_PIPOBUF SANE_TRUE diff --git a/backend/mustek.c b/backend/mustek.c index 4d77fb5..bad118a 100644 --- a/backend/mustek.c +++ b/backend/mustek.c @@ -198,15 +198,6 @@ static const SANE_Byte scsi_inquiry[] = { static const SANE_Byte scsi_test_unit_ready[] = { MUSTEK_SCSI_TEST_UNIT_READY, 0x00, 0x00, 0x00, 0x00, 0x00 }; -/* Remove #ifdef and this comment when this SCSI command is used for - something. Keeping this definition around so we don't loose info - about the protocol. - */ -#ifdef ENABLE_MUSTEK_SCSI_AREA_AND_WINDOWS -static const SANE_Byte scsi_area_and_windows[] = { - MUSTEK_SCSI_AREA_AND_WINDOWS, 0x00, 0x00, 0x00, 0x09, 0x00 -}; -#endif static const SANE_Byte scsi_request_sense[] = { MUSTEK_SCSI_REQUEST_SENSE, 0x00, 0x00, 0x00, 0x04, 0x00 }; @@ -219,28 +210,16 @@ static const SANE_Byte scsi_ccd_distance[] = { static const SANE_Byte scsi_get_image_status[] = { MUSTEK_SCSI_GET_IMAGE_STATUS, 0x00, 0x00, 0x00, 0x06, 0x00 }; -static const SANE_Byte scsi_set_window[] = { - MUSTEK_SCSI_SET_WINDOW, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00 -}; static const SANE_Byte scsi_get_window[] = { MUSTEK_SCSI_GET_WINDOW, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00 }; -static const SANE_Byte scsi_read_data[] = { - MUSTEK_SCSI_READ_DATA, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -}; -static const SANE_Byte scsi_send_data[] = { - MUSTEK_SCSI_SEND_DATA, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -}; -/* Remove #ifdef and this comment when this SCSI command is used for - something. Keeping this definition around so we don't loose info - about the protocol. - */ -#ifdef ENABLE_MUSTEK_SCSI_LOOKUP_TABLE -static const SANE_Byte scsi_lookup_table[] = { - MUSTEK_SCSI_LOOKUP_TABLE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00 -}; -#endif + +/* Sizes for fixed-length, non-vendor-specific CDB formats (others are 0) */ +#define CDB_SIZE(opcode) ((opcode) < 0x20 ? 6 : \ + (opcode) < 0x60 ? 10 : \ + (opcode) < 0x80 ? 0 : \ + (opcode) < 0xa0 ? 16 : \ + (opcode) < 0xc0 ? 12 : 0) /* prototypes */ static SANE_Status area_and_windows (Mustek_Scanner * s); @@ -1994,7 +1973,7 @@ set_window_se (Mustek_Scanner * s, SANE_Int lamp) /* setup SCSI command (except length): */ memset (cmd, 0, sizeof (cmd)); cmd[0] = MUSTEK_SCSI_SET_WINDOW; - cp = cmd + sizeof (scsi_set_window); /* skip command block */ + cp = cmd + CDB_SIZE (MUSTEK_SCSI_SET_WINDOW); /* skip command block */ if (s->mode & MUSTEK_MODE_COLOR) { @@ -2093,7 +2072,7 @@ set_window_se (Mustek_Scanner * s, SANE_Int lamp) *cp++ = 0; cp += 5; /* skip reserved bytes */ - cmd[8] = cp - cmd - sizeof (scsi_set_window); + cmd[8] = cp - cmd - CDB_SIZE (MUSTEK_SCSI_SET_WINDOW); return dev_cmd (s, cmd, (cp - cmd), 0, 0); } @@ -2111,7 +2090,7 @@ set_window_pro (Mustek_Scanner * s) else cmd[8] = 0x0a; - cp = cmd + sizeof (scsi_set_window); /* skip command block */ + cp = cmd + CDB_SIZE (MUSTEK_SCSI_SET_WINDOW); /* skip command block */ *cp++ = 0; /* what's this? */ pixels_per_mm = SANE_UNFIX (s->hw->dpi_range.max) / MM_PER_INCH; @@ -2174,7 +2153,7 @@ get_calibration_lines_pro (Mustek_Scanner * s) for (line = 0; line < s->hw->cal.lines; line++) { - status = dev_cmd (s, cmd, sizeof (scsi_read_data), + status = dev_cmd (s, cmd, CDB_SIZE (MUSTEK_SCSI_READ_DATA), s->hw->cal.buffer + line * len, &len); if ((status != SANE_STATUS_GOOD) @@ -2199,17 +2178,17 @@ send_calibration_lines_pro (Mustek_Scanner * s) DBG (5, "send_calibration_lines_pro\n"); buf_size = s->hw->cal.bytes / 2; - cmd1 = (SANE_Byte *) malloc (buf_size + sizeof (scsi_send_data)); - cmd2 = (SANE_Byte *) malloc (buf_size + sizeof (scsi_send_data)); + cmd1 = (SANE_Byte *) malloc (buf_size + CDB_SIZE (MUSTEK_SCSI_SEND_DATA)); + cmd2 = (SANE_Byte *) malloc (buf_size + CDB_SIZE (MUSTEK_SCSI_SEND_DATA)); if (!cmd1 || !cmd2) { - DBG (1, "send_calibration_lines_pro: failed to malloc %ld bytes for " + DBG (1, "send_calibration_lines_pro: failed to malloc %zu bytes for " "sending lines\n", - (long int) (buf_size + sizeof (scsi_send_data))); + buf_size + CDB_SIZE (MUSTEK_SCSI_SEND_DATA)); return SANE_STATUS_NO_MEM; } - memset (cmd1, 0, sizeof (scsi_send_data)); - memset (cmd2, 0, sizeof (scsi_send_data)); + memset (cmd1, 0, CDB_SIZE (MUSTEK_SCSI_SEND_DATA)); + memset (cmd2, 0, CDB_SIZE (MUSTEK_SCSI_SEND_DATA)); cmd1[0] = cmd2[0] = MUSTEK_SCSI_SEND_DATA; cmd1[6] = cmd2[6] = (buf_size >> 16) & 0xff; @@ -2236,21 +2215,21 @@ send_calibration_lines_pro (Mustek_Scanner * s) calibration_word = (1024 * 65536 / calibration_word) - 1024; if (calibration_word > 1023) calibration_word = 1023; - *(cmd1 + sizeof (scsi_send_data) + (buf_size / 3) * color + column) - = calibration_word & 0xff; - *(cmd2 + sizeof (scsi_send_data) + (buf_size / 3) * color + column) - = (calibration_word >> 8) & 0xff; + *(cmd1 + CDB_SIZE (MUSTEK_SCSI_SEND_DATA) + (buf_size / 3) * color + + column) = calibration_word & 0xff; + *(cmd2 + CDB_SIZE (MUSTEK_SCSI_SEND_DATA) + (buf_size / 3) * color + + column) = (calibration_word >> 8) & 0xff; } } - status = dev_cmd (s, cmd1, buf_size + sizeof (scsi_send_data), 0, 0); + status = dev_cmd (s, cmd1, buf_size + CDB_SIZE (MUSTEK_SCSI_SEND_DATA), 0, 0); if (status != SANE_STATUS_GOOD) { DBG (1, "send_calibration_lines_pro: send failed\n"); return status; } - status = dev_cmd (s, cmd2, buf_size + sizeof (scsi_send_data), 0, 0); + status = dev_cmd (s, cmd2, buf_size + CDB_SIZE (MUSTEK_SCSI_SEND_DATA), 0, 0); if (status != SANE_STATUS_GOOD) { DBG (1, "send_calibration_lines_pro: send failed\n"); @@ -2328,7 +2307,8 @@ get_calibration_lines_se (Mustek_Scanner * s) cmd[7] = (lines >> 8) & 0xff; cmd[8] = (lines >> 0) & 0xff; len = lines * bytes_per_color; - status = dev_cmd (s, cmd, sizeof (scsi_read_data), s->hw->cal.buffer, &len); + status = dev_cmd (s, cmd, CDB_SIZE (MUSTEK_SCSI_READ_DATA), + s->hw->cal.buffer, &len); if ((status != SANE_STATUS_GOOD) || (len != (unsigned int) (lines * bytes_per_color))) { @@ -2361,15 +2341,15 @@ send_calibration_lines_se (Mustek_Scanner * s, SANE_Word color) DBG (5, "send_calibration_lines_se: %d bytes, color: %d\n", bytes_per_color, color + 1); - cmd = (SANE_Byte *) malloc (buf_size + sizeof (scsi_send_data)); + cmd = (SANE_Byte *) malloc (buf_size + CDB_SIZE (MUSTEK_SCSI_SEND_DATA)); if (!cmd) { - DBG (1, "send_calibration_lines_se: failed to malloc %ld bytes for " + DBG (1, "send_calibration_lines_se: failed to malloc %zu bytes for " "sending lines\n", - (long int) (buf_size + sizeof (scsi_send_data))); + buf_size + CDB_SIZE (MUSTEK_SCSI_SEND_DATA)); return SANE_STATUS_NO_MEM; } - memset (cmd, 0, sizeof (scsi_send_data)); + memset (cmd, 0, CDB_SIZE (MUSTEK_SCSI_SEND_DATA)); for (column = 0; column < bytes_per_color; column++) { @@ -2386,7 +2366,7 @@ send_calibration_lines_se (Mustek_Scanner * s, SANE_Word color) cali_word = 256 * s->hw->cal.lines * 255 / cali_word - 256; if (cali_word > 255) cali_word = 255; - *(cmd + sizeof (scsi_send_data) + column) = cali_word; + *(cmd + CDB_SIZE (MUSTEK_SCSI_SEND_DATA) + column) = cali_word; } cmd[0] = MUSTEK_SCSI_SEND_DATA; @@ -2395,7 +2375,7 @@ send_calibration_lines_se (Mustek_Scanner * s, SANE_Word color) cmd[7] = (buf_size >> 8) & 0xff; cmd[8] = (buf_size >> 0) & 0xff; - status = dev_cmd (s, cmd, buf_size + sizeof (scsi_send_data), 0, 0); + status = dev_cmd (s, cmd, buf_size + CDB_SIZE (MUSTEK_SCSI_SEND_DATA), 0, 0); if (status != SANE_STATUS_GOOD) { DBG (1, "send_calibration_lines_se: send failed\n"); @@ -2457,14 +2437,15 @@ send_gamma_table_se (Mustek_Scanner * s) SANE_Int i, j; # define CLIP(x) ((x) < 0 ? 0 : ((x) > 255 ? 255 : (x))) - memset (gamma, 0, sizeof (scsi_send_data)); + memset (gamma, 0, CDB_SIZE (MUSTEK_SCSI_SEND_DATA)); gamma[0] = MUSTEK_SCSI_SEND_DATA; gamma[2] = 0x03; /* indicates gamma table */ if ((s->mode & MUSTEK_MODE_GRAY) || (s->mode & MUSTEK_MODE_COLOR)) { - if (s->hw->gamma_length + sizeof (scsi_send_data) > sizeof (gamma)) + if ((size_t) s->hw->gamma_length + CDB_SIZE (MUSTEK_SCSI_SEND_DATA) + > sizeof (gamma)) return SANE_STATUS_NO_MEM; gamma[7] = (s->hw->gamma_length >> 8) & 0xff; gamma[8] = (s->hw->gamma_length >> 0) & 0xff; @@ -2491,7 +2472,7 @@ send_gamma_table_se (Mustek_Scanner * s) val_a = MAX (2 * val_b - val_a, 0); /* Interpolate first entries from 256 entry table */ - cp = gamma + sizeof (scsi_send_data); + cp = gamma + CDB_SIZE (MUSTEK_SCSI_SEND_DATA); for (j = 0; j < factor; j++) *cp++ = CLIP (((factor - j) * val_a + j * val_b + factor / 2) / factor); @@ -2518,7 +2499,7 @@ send_gamma_table_se (Mustek_Scanner * s) DBG (5, "send_gamma_table_se: sending table for color %d\n", gamma[6]); - status = dev_cmd (s, gamma, sizeof (scsi_send_data) + status = dev_cmd (s, gamma, CDB_SIZE (MUSTEK_SCSI_SEND_DATA) + s->hw->gamma_length, 0, 0); ++color; } @@ -2535,7 +2516,7 @@ send_gamma_table_se (Mustek_Scanner * s) DBG (5, "send_gamma_table_se: sending lineart threshold %2X\n", gamma[8]); - return dev_cmd (s, gamma, sizeof (scsi_send_data), 0, 0); + return dev_cmd (s, gamma, CDB_SIZE (MUSTEK_SCSI_SEND_DATA), 0, 0); } } @@ -4656,7 +4637,7 @@ output_data (Mustek_Scanner * s, FILE * fp, SANE_Int y, num_lines; DBG (5, "output_data: data=%p, lpb=%d, bpl=%d, extra=%p\n", - data, lines_per_buffer, bpl, extra); + (void *) data, lines_per_buffer, bpl, (void *) extra); /* convert to pixel-interleaved format: */ if ((s->mode & MUSTEK_MODE_COLOR) diff --git a/backend/mustek_usb2.c b/backend/mustek_usb2.c index 9faeff6..cb511b9 100644 --- a/backend/mustek_usb2.c +++ b/backend/mustek_usb2.c @@ -1165,12 +1165,12 @@ IsTAConnected () DBG (DBG_FUNC, "StopScan: start\n"); - if (Asic_Open (&g_chip, g_pDeviceFile) != STATUS_GOOD) + if (Asic_Open (&g_chip, g_pDeviceFile) != SANE_STATUS_GOOD) { return FALSE; } - if (Asic_IsTAConnected (&g_chip, &hasTA) != STATUS_GOOD) + if (Asic_IsTAConnected (&g_chip, &hasTA) != SANE_STATUS_GOOD) { Asic_Close (&g_chip); return FALSE; @@ -1199,16 +1199,16 @@ static SANE_Bool GetKeyStatus (SANE_Byte * pKey) { SANE_Byte pKeyTemp = 0x00; - STATUS status = Asic_CheckFunctionKey (&g_chip, &pKeyTemp); + SANE_Status status = Asic_CheckFunctionKey (&g_chip, &pKeyTemp); DBG (DBG_FUNC, "GetKeyStatus: start\n"); - if (STATUS_GOOD != Asic_Open (&g_chip, g_pDeviceFile)) + if (SANE_STATUS_GOOD != Asic_Open (&g_chip, g_pDeviceFile)) { DBG (DBG_ERR, "GetKeyStatus: Asic_Open is fail\n"); return FALSE; } - if (STATUS_GOOD != status) + if (SANE_STATUS_GOOD != status) { DBG (DBG_ERR, "GetKeyStatus: Asic_CheckFunctionKey is fail\n"); return FALSE; @@ -1236,7 +1236,7 @@ GetKeyStatus (SANE_Byte * pKey) *pKey = 0x05; /*Panel key pressed */ } - if (STATUS_GOOD != Asic_Close (&g_chip)) + if (SANE_STATUS_GOOD != Asic_Close (&g_chip)) { DBG (DBG_ERR, "GetKeyStatus: Asic_Close is fail\n"); return FALSE; diff --git a/backend/mustek_usb2_asic.c b/backend/mustek_usb2_asic.c index 039ffa1..8a2325e 100644 --- a/backend/mustek_usb2_asic.c +++ b/backend/mustek_usb2_asic.c @@ -49,34 +49,34 @@ static SANE_Byte RegisterBankStatus = -1; -static STATUS +static SANE_Status WriteIOControl (PAsic chip, unsigned short wValue, unsigned short wIndex, unsigned short wLength, SANE_Byte * lpbuf) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; status = sanei_usb_control_msg (chip->fd, 0x40, 0x01, wValue, wIndex, wLength, lpbuf); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { DBG (DBG_ERR, "WriteIOControl Error!\n"); return status; } - return STATUS_GOOD; + return SANE_STATUS_GOOD; } -static STATUS +static SANE_Status ReadIOControl (PAsic chip, unsigned short wValue, unsigned short wIndex, unsigned short wLength, SANE_Byte * lpbuf) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; status = sanei_usb_control_msg (chip->fd, 0xc0, 0x01, wValue, wIndex, wLength, lpbuf); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { DBG (DBG_ERR, "WriteIOControl Error!\n"); return status; @@ -85,10 +85,10 @@ ReadIOControl (PAsic chip, unsigned short wValue, unsigned short wIndex, unsigne return status; } -static STATUS +static SANE_Status Mustek_ClearFIFO (PAsic chip) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; SANE_Byte buf[4]; DBG (DBG_ASIC, "Mustek_ClearFIFO:Enter\n"); @@ -97,24 +97,24 @@ Mustek_ClearFIFO (PAsic chip) buf[2] = 0; buf[3] = 0; status = WriteIOControl (chip, 0x05, 0, 4, (SANE_Byte *) (buf)); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) return status; status = WriteIOControl (chip, 0xc0, 0, 4, (SANE_Byte *) (buf)); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) return status; DBG (DBG_ASIC, "Mustek_ClearFIFO:Exit\n"); - return STATUS_GOOD; + return SANE_STATUS_GOOD; } -static STATUS +static SANE_Status Mustek_SendData (PAsic chip, unsigned short reg, SANE_Byte data) { SANE_Byte buf[4]; - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; DBG (DBG_ASIC, "Mustek_SendData: Enter. reg=%x,data=%x\n", reg, data); @@ -167,16 +167,16 @@ Mustek_SendData (PAsic chip, unsigned short reg, SANE_Byte data) buf[2] = LOBYTE (reg); buf[3] = data; status = WriteIOControl (chip, 0xb0, 0, 4, buf); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) DBG (DBG_ERR, ("Mustek_SendData: write error\n")); return status; } -static STATUS +static SANE_Status Mustek_ReceiveData (PAsic chip, SANE_Byte * reg) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; SANE_Byte buf[4]; DBG (DBG_ASIC, "Mustek_ReceiveData\n"); @@ -187,10 +187,10 @@ Mustek_ReceiveData (PAsic chip, SANE_Byte * reg) return status; } -static STATUS +static SANE_Status Mustek_WriteAddressLineForRegister (PAsic chip, SANE_Byte x) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; SANE_Byte buf[4]; DBG (DBG_ASIC, "Mustek_WriteAddressLineForRegister: Enter\n"); @@ -206,51 +206,51 @@ Mustek_WriteAddressLineForRegister (PAsic chip, SANE_Byte x) } -static STATUS +static SANE_Status SetRWSize (PAsic chip, SANE_Byte ReadWrite, unsigned int size) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; DBG (DBG_ASIC, "SetRWSize: Enter\n"); if (ReadWrite == 0) { /*write */ status = Mustek_SendData (chip, 0x7C, (SANE_Byte) (size)); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) return status; status = Mustek_SendData (chip, 0x7D, (SANE_Byte) (size >> 8)); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) return status; status = Mustek_SendData (chip, 0x7E, (SANE_Byte) (size >> 16)); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) return status; status = Mustek_SendData (chip, 0x7F, (SANE_Byte) (size >> 24)); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) return status; } else { /* read */ status = Mustek_SendData (chip, 0x7C, (SANE_Byte) (size >> 1)); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) return status; status = Mustek_SendData (chip, 0x7D, (SANE_Byte) (size >> 9)); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) return status; status = Mustek_SendData (chip, 0x7E, (SANE_Byte) (size >> 17)); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) return status; status = Mustek_SendData (chip, 0x7F, (SANE_Byte) (size >> 25)); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) return status; } DBG (DBG_ASIC, "SetRWSize: Exit\n"); - return STATUS_GOOD; + return SANE_STATUS_GOOD; } -static STATUS +static SANE_Status Mustek_DMARead (PAsic chip, unsigned int size, SANE_Byte * lpdata) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; unsigned int i, buf[1]; unsigned int read_size; size_t read_size_usb; @@ -258,7 +258,7 @@ Mustek_DMARead (PAsic chip, unsigned int size, SANE_Byte * lpdata) DBG (DBG_ASIC, "Mustek_DMARead: Enter\n"); status = Mustek_ClearFIFO (chip); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) return status; buf[0] = read_size = 32 * 1024; @@ -272,7 +272,7 @@ Mustek_DMARead (PAsic chip, unsigned int size, SANE_Byte * lpdata) sanei_usb_read_bulk (chip->fd, lpdata + i * read_size, &read_size_usb); buf[0] = read_size_usb; - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { DBG (DBG_ERR, "Mustek_DMARead: read error\n"); return status; @@ -290,7 +290,7 @@ Mustek_DMARead (PAsic chip, unsigned int size, SANE_Byte * lpdata) sanei_usb_read_bulk (chip->fd, lpdata + i * read_size, &read_size_usb); buf[0] = read_size_usb; - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { DBG (DBG_ERR, "Mustek_DMARead: read error\n"); return status; @@ -300,13 +300,13 @@ Mustek_DMARead (PAsic chip, unsigned int size, SANE_Byte * lpdata) } DBG (DBG_ASIC, "Mustek_DMARead: Exit\n"); - return STATUS_GOOD; + return SANE_STATUS_GOOD; } -static STATUS +static SANE_Status Mustek_DMAWrite (PAsic chip, unsigned int size, SANE_Byte * lpdata) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; unsigned int buf[1]; unsigned int i; unsigned int write_size; @@ -315,7 +315,7 @@ Mustek_DMAWrite (PAsic chip, unsigned int size, SANE_Byte * lpdata) DBG (DBG_ASIC, "Mustek_DMAWrite: Enter:size=%d\n", size); status = Mustek_ClearFIFO (chip); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) return status; buf[0] = write_size = 32 * 1024; @@ -329,7 +329,7 @@ Mustek_DMAWrite (PAsic chip, unsigned int size, SANE_Byte * lpdata) sanei_usb_write_bulk (chip->fd, lpdata + i * write_size, &write_size_usb); buf[0] = write_size_usb; - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { DBG (DBG_ERR, "Mustek_DMAWrite: write error\n"); return status; @@ -348,7 +348,7 @@ Mustek_DMAWrite (PAsic chip, unsigned int size, SANE_Byte * lpdata) sanei_usb_write_bulk (chip->fd, lpdata + i * write_size, &write_size_usb); buf[0] = write_size_usb; - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { DBG (DBG_ERR, "Mustek_DMAWrite: write error\n"); return status; @@ -358,11 +358,11 @@ Mustek_DMAWrite (PAsic chip, unsigned int size, SANE_Byte * lpdata) Mustek_ClearFIFO (chip); DBG (DBG_ASIC, "Mustek_DMAWrite: Exit\n"); - return STATUS_GOOD; + return SANE_STATUS_GOOD; } -static STATUS +static SANE_Status Mustek_SendData2Byte (PAsic chip, unsigned short reg, SANE_Byte data) { static SANE_Bool isTransfer = FALSE; @@ -425,17 +425,17 @@ Mustek_SendData2Byte (PAsic chip, unsigned short reg, SANE_Byte data) isTransfer = FALSE; } - return STATUS_GOOD; + return SANE_STATUS_GOOD; } /* ---------------------- asic motor functions ----------------------------- */ -static STATUS +static SANE_Status LLFRamAccess (PAsic chip, LLF_RAMACCESS * RamAccess) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; SANE_Byte a[2]; DBG (DBG_ASIC, "LLFRamAccess:Enter\n"); @@ -499,12 +499,12 @@ LLFRamAccess (PAsic chip, LLF_RAMACCESS * RamAccess) } -static STATUS +static SANE_Status LLFSetMotorCurrentAndPhase (PAsic chip, LLF_MOTOR_CURRENT_AND_PHASE * MotorCurrentAndPhase) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; SANE_Byte MotorPhase; DBG (DBG_ASIC, "LLFSetMotorCurrentAndPhase:Enter\n"); @@ -1558,10 +1558,10 @@ LLFSetMotorCurrentAndPhase (PAsic chip, #if SANE_UNUSED -static STATUS +static SANE_Status LLFStopMotorMove (PAsic chip) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; DBG (DBG_ASIC, "LLFStopMotorMove:Enter\n"); Mustek_SendData (chip, ES01_F4_ActiveTriger, ACTION_TRIGER_DISABLE); @@ -1573,10 +1573,10 @@ LLFStopMotorMove (PAsic chip) } #endif -static STATUS +static SANE_Status LLFSetMotorTable (PAsic chip, LLF_SETMOTORTABLE * LLF_SetMotorTable) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; LLF_RAMACCESS RamAccess; DBG (DBG_ASIC, "LLFSetMotorTable:Enter\n"); @@ -1609,10 +1609,10 @@ LLFSetMotorTable (PAsic chip, LLF_SETMOTORTABLE * LLF_SetMotorTable) return status; } -static STATUS +static SANE_Status LLFMotorMove (PAsic chip, LLF_MOTORMOVE * LLF_MotorMove) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; unsigned int motor_steps; SANE_Byte temp_motor_action; @@ -1751,11 +1751,11 @@ LLFMotorMove (PAsic chip, LLF_MOTORMOVE * LLF_MotorMove) return status; } -static STATUS +static SANE_Status SetMotorStepTable (PAsic chip, LLF_MOTORMOVE * MotorStepsTable, unsigned short wStartY, unsigned int dwScanImageSteps, unsigned short wYResolution) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; unsigned short wAccSteps = 511; unsigned short wForwardSteps = 20; SANE_Byte bDecSteps = 255; @@ -1891,11 +1891,11 @@ SetMotorStepTable (PAsic chip, LLF_MOTORMOVE * MotorStepsTable, unsigned short w return status; } -static STATUS +static SANE_Status CalculateMotorTable (LLF_CALCULATEMOTORTABLE * lpCalculateMotorTable, unsigned short wYResolution) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; unsigned short i; unsigned short wEndSpeed, wStartSpeed; unsigned short wScanAccSteps; @@ -1980,10 +1980,10 @@ CalculateMotorTable (LLF_CALCULATEMOTORTABLE * lpCalculateMotorTable, return status; } -static STATUS +static SANE_Status LLFCalculateMotorTable (LLF_CALCULATEMOTORTABLE * LLF_CalculateMotorTable) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; unsigned short i; double PI = 3.1415926535; double x; @@ -2085,14 +2085,14 @@ LLFCalculateMotorTable (LLF_CALCULATEMOTORTABLE * LLF_CalculateMotorTable) } -static STATUS +static SANE_Status SetMotorCurrent (PAsic chip, unsigned short dwMotorSpeed, LLF_MOTOR_CURRENT_AND_PHASE * CurrentPhase) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; DBG (DBG_ASIC, "SetMotorCurrent:Enter\n"); - chip = chip; + (void) chip; if (dwMotorSpeed < 2000) { @@ -2135,10 +2135,10 @@ SetMotorCurrent (PAsic chip, unsigned short dwMotorSpeed, } -static STATUS +static SANE_Status MotorBackHome (PAsic chip, SANE_Byte WaitOrNoWait) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; unsigned short BackHomeMotorTable[512 * 8]; LLF_CALCULATEMOTORTABLE CalMotorTable; LLF_MOTOR_CURRENT_AND_PHASE CurrentPhase; @@ -2184,11 +2184,11 @@ MotorBackHome (PAsic chip, SANE_Byte WaitOrNoWait) } -static STATUS +static SANE_Status LLFSetRamAddress (PAsic chip, unsigned int dwStartAddr, unsigned int dwEndAddr, SANE_Byte byAccessTarget) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; SANE_Byte * pStartAddr = (SANE_Byte *) & dwStartAddr; SANE_Byte * pEndAddr = (SANE_Byte *) & dwEndAddr; @@ -2219,10 +2219,10 @@ LLFSetRamAddress (PAsic chip, unsigned int dwStartAddr, unsigned int dwEndAddr, /* ---------------------- medium level asic functions ---------------------- */ -static STATUS +static SANE_Status InitTiming (PAsic chip) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; DBG (DBG_ASIC, "InitTiming:Enter\n"); chip->Timing.AFE_ADCCLK_Timing = 1010580480; @@ -2267,10 +2267,10 @@ InitTiming (PAsic chip) return status; } -static STATUS +static SANE_Status OpenScanChip (PAsic chip) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; SANE_Byte x[4]; DBG (DBG_ASIC, "OpenScanChip:Enter\n"); @@ -2280,7 +2280,7 @@ OpenScanChip (PAsic chip) x[2] = 0x64; x[3] = 0x64; status = WriteIOControl (chip, 0x90, 0, 4, x); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) return status; x[0] = 0x65; @@ -2288,7 +2288,7 @@ OpenScanChip (PAsic chip) x[2] = 0x65; x[3] = 0x65; status = WriteIOControl (chip, 0x90, 0, 4, x); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) return status; x[0] = 0x44; @@ -2296,7 +2296,7 @@ OpenScanChip (PAsic chip) x[2] = 0x44; x[3] = 0x44; status = WriteIOControl (chip, 0x90, 0, 4, x); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) return status; x[0] = 0x45; @@ -2310,10 +2310,10 @@ OpenScanChip (PAsic chip) } -static STATUS +static SANE_Status CloseScanChip (PAsic chip) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; SANE_Byte x[4]; DBG (DBG_ASIC, "CloseScanChip:Enter\n"); @@ -2323,7 +2323,7 @@ CloseScanChip (PAsic chip) x[2] = 0x64; x[3] = 0x64; status = WriteIOControl (chip, 0x90, 0, 4, x); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) return status; x[0] = 0x65; @@ -2331,7 +2331,7 @@ CloseScanChip (PAsic chip) x[2] = 0x65; x[3] = 0x65; status = WriteIOControl (chip, 0x90, 0, 4, x); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) return status; x[0] = 0x16; @@ -2339,7 +2339,7 @@ CloseScanChip (PAsic chip) x[2] = 0x16; x[3] = 0x16; status = WriteIOControl (chip, 0x90, 0, 4, x); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) return status; x[0] = 0x17; @@ -2353,10 +2353,10 @@ CloseScanChip (PAsic chip) } -static STATUS +static SANE_Status SafeInitialChip (PAsic chip) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; DBG (DBG_ASIC, "SafeInitialChip:Enter\n"); @@ -2372,7 +2372,7 @@ SafeInitialChip (PAsic chip) { DBG (DBG_ASIC, "isFirstOpenChip=%d\n", chip->isFirstOpenChip); status = DRAM_Test (chip); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { DBG (DBG_ASIC, "DRAM_Test: Error\n"); return status; @@ -2385,10 +2385,10 @@ SafeInitialChip (PAsic chip) } -static STATUS +static SANE_Status DRAM_Test (PAsic chip) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; unsigned char *temps; unsigned int i; @@ -2403,14 +2403,14 @@ DRAM_Test (PAsic chip) /*set start address */ status = Mustek_SendData (chip, ES01_A0_HostStartAddr0_7, 0x00); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { free (temps); return status; } status = Mustek_SendData (chip, ES01_A1_HostStartAddr8_15, 0x00); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { free (temps); return status; @@ -2418,7 +2418,7 @@ DRAM_Test (PAsic chip) status = Mustek_SendData (chip, ES01_A2_HostStartAddr16_21, 0x00 | ACCESS_DRAM); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { free (temps); return status; @@ -2427,28 +2427,28 @@ DRAM_Test (PAsic chip) Mustek_SendData (chip, ES01_79_AFEMCLK_SDRAMCLK_DELAY_CONTROL, SDRAMCLK_DELAY_12_ns); status = Mustek_SendData (chip, ES01_A3_HostEndAddr0_7, 0xff); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { free (temps); return status; } status = Mustek_SendData (chip, ES01_A4_HostEndAddr8_15, 0xff); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { free (temps); return status; } status = Mustek_SendData (chip, ES01_A5_HostEndAddr16_21, 0xff); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { free (temps); return status; } status = Mustek_DMAWrite (chip, 64, (SANE_Byte *) (temps)); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { DBG (DBG_ASIC, "Mustek_DMAWrite error\n"); free (temps); @@ -2456,14 +2456,14 @@ DRAM_Test (PAsic chip) } status = Mustek_SendData (chip, ES01_A0_HostStartAddr0_7, 0x00); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { free (temps); return status; } status = Mustek_SendData (chip, ES01_A1_HostStartAddr8_15, 0x00); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { free (temps); return status; @@ -2471,7 +2471,7 @@ DRAM_Test (PAsic chip) status = Mustek_SendData (chip, ES01_A2_HostStartAddr16_21, 0x00 | ACCESS_DRAM); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { free (temps); return status; @@ -2479,21 +2479,21 @@ DRAM_Test (PAsic chip) /*set end address */ status = Mustek_SendData (chip, ES01_A3_HostEndAddr0_7, 0xff); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { free (temps); return status; } status = Mustek_SendData (chip, ES01_A4_HostEndAddr8_15, 0xff); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { free (temps); return status; } status = Mustek_SendData (chip, ES01_A5_HostEndAddr16_21, 0xff); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { free (temps); return status; @@ -2502,7 +2502,7 @@ DRAM_Test (PAsic chip) memset (temps, 0, 64); status = Mustek_DMARead (chip, 64, (SANE_Byte *) (temps)); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { free (temps); return status; @@ -2521,7 +2521,7 @@ DRAM_Test (PAsic chip) if (*(temps + i) != i) { DBG (DBG_ERR, "DRAM Test error...(No.=%d)\n", i + 1); - return STATUS_IO_ERROR; + return SANE_STATUS_IO_ERROR; } } @@ -2532,10 +2532,10 @@ DRAM_Test (PAsic chip) } #if SANE_UNUSED -static STATUS +static SANE_Status SetPowerSave (PAsic chip) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; DBG (DBG_ASIC, "SetPowerSave:Enter\n"); if (chip->firmwarestate < FS_OPENED) @@ -2552,10 +2552,10 @@ SetPowerSave (PAsic chip) } #endif -static STATUS +static SANE_Status SetLineTimeAndExposure (PAsic chip) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; DBG (DBG_ASIC, "SetLineTimeAndExposure:Enter\n"); if (chip->firmwarestate < FS_OPENED) @@ -2584,10 +2584,10 @@ SetLineTimeAndExposure (PAsic chip) -static STATUS +static SANE_Status CCDTiming (PAsic chip) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; unsigned int dwPH1, dwPH2, dwPHRS, dwPHCP; DBG (DBG_ASIC, "CCDTiming:Enter\n"); @@ -2701,16 +2701,16 @@ CCDTiming (PAsic chip) return status; } -static STATUS +static SANE_Status IsCarriageHome (PAsic chip, SANE_Bool * LampHome, SANE_Bool * TAHome) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; SANE_Byte temp; DBG (DBG_ASIC, "IsCarriageHome:Enter\n"); status = GetChipStatus (chip, 0, &temp); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { DBG (DBG_ASIC, "IsCarriageHome:Error!\n"); return status; @@ -2732,33 +2732,33 @@ IsCarriageHome (PAsic chip, SANE_Bool * LampHome, SANE_Bool * TAHome) } -static STATUS +static SANE_Status GetChipStatus (PAsic chip, SANE_Byte Selector, SANE_Byte * ChipStatus) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; DBG (DBG_ASIC, "GetChipStatus:Enter\n"); status = Mustek_SendData (chip, ES01_8B_Status, Selector); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) return status; status = Mustek_WriteAddressLineForRegister (chip, ES01_8B_Status); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) return status; *ChipStatus = ES01_8B_Status; status = Mustek_ReceiveData (chip, ChipStatus); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) return status; DBG (DBG_ASIC, "GetChipStatus:Exit\n"); return status; } -static STATUS +static SANE_Status SetAFEGainOffset (PAsic chip) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; int i = 0; DBG (DBG_ASIC, "SetAFEGainOffset:Enter\n"); @@ -2918,10 +2918,10 @@ SetAFEGainOffset (PAsic chip) return status; } -static STATUS +static SANE_Status SetLEDTime (PAsic chip) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; DBG (DBG_ASIC, "SetLEDTime:Enter\n"); Mustek_SendData (chip, ES01_B8_ChannelRedExpStartPixelLSB, @@ -2955,10 +2955,10 @@ SetLEDTime (PAsic chip) return status; } -static STATUS +static SANE_Status SetScanMode (PAsic chip, SANE_Byte bScanBits) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; SANE_Byte temp_f5_register = 0; SANE_Byte GrayBWChannel; @@ -3019,12 +3019,12 @@ SetScanMode (PAsic chip, SANE_Byte bScanBits) return status; } -static STATUS +static SANE_Status SetPackAddress (PAsic chip, unsigned short wXResolution, unsigned short wWidth, unsigned short wX, double XRatioAdderDouble, double XRatioTypeDouble, SANE_Byte byClear_Pulse_Width, unsigned short * PValidPixelNumber) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; SANE_Byte OverLapPixel; SANE_Byte TotalLineShift; @@ -3402,11 +3402,11 @@ SetPackAddress (PAsic chip, unsigned short wXResolution, unsigned short wWidth, return status; } -static STATUS +static SANE_Status SetExtraSetting (PAsic chip, unsigned short wXResolution, unsigned short wCCD_PixelNumber, SANE_Bool isCaribrate) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; SANE_Byte byPHTG_PulseWidth, byPHTG_WaitWidth; SANE_Byte temp_ff_register = 0; SANE_Byte bThreshold = 128; @@ -3532,10 +3532,10 @@ attach_one_scanner (SANE_String_Const devname) return SANE_STATUS_GOOD; } -static STATUS +static SANE_Status Asic_Open (PAsic chip, SANE_Byte *pDeviceName) { - STATUS status; + SANE_Status status; SANE_Status sane_status; DBG (DBG_ASIC, "Asic_Open: Enter\n"); @@ -3545,7 +3545,7 @@ Asic_Open (PAsic chip, SANE_Byte *pDeviceName) if (chip->firmwarestate > FS_OPENED) { DBG (DBG_ASIC, "chip has been opened. fd=%d\n", chip->fd); - return STATUS_INVAL; + return SANE_STATUS_INVAL; } /* init usb */ @@ -3558,25 +3558,25 @@ Asic_Open (PAsic chip, SANE_Byte *pDeviceName) { DBG (DBG_ERR, "Asic_Open: sanei_usb_find_devices failed: %s\n", sane_strstatus (sane_status)); - return STATUS_INVAL; + return SANE_STATUS_INVAL; } /* open usb */ if (device_name == NULL) { DBG (DBG_ERR, "Asic_Open: no scanner found\n"); - return STATUS_INVAL; + return SANE_STATUS_INVAL; } sane_status = sanei_usb_open (device_name, &chip->fd); if (sane_status != SANE_STATUS_GOOD) { DBG (DBG_ERR, "Asic_Open: sanei_usb_open of %s failed: %s\n", device_name, sane_strstatus (sane_status)); - return STATUS_INVAL; + return SANE_STATUS_INVAL; } /* open scanner chip */ status = OpenScanChip (chip); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { sanei_usb_close (chip->fd); DBG (DBG_ASIC, "Asic_Open: OpenScanChip error\n"); @@ -3601,7 +3601,7 @@ Asic_Open (PAsic chip, SANE_Byte *pDeviceName) Asic_WaitUnitReady (chip); DBG (DBG_ASIC, "Asic_WaitUnitReady\n"); status = SafeInitialChip (chip); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { DBG (DBG_ERR, "Asic_Open: SafeInitialChip error\n"); return status; @@ -3611,7 +3611,7 @@ Asic_Open (PAsic chip, SANE_Byte *pDeviceName) if (!pDeviceName) { DBG (DBG_ERR, "Asic_Open: not enough memory\n"); - return STATUS_INVAL; + return SANE_STATUS_INVAL; } DBG (DBG_INFO, "Asic_Open: device %s successfully opened\n", pDeviceName); DBG (DBG_ASIC, "Asic_Open: Exit\n"); @@ -3619,16 +3619,16 @@ Asic_Open (PAsic chip, SANE_Byte *pDeviceName) } -static STATUS +static SANE_Status Asic_Close (PAsic chip) { - STATUS status; + SANE_Status status; DBG (DBG_ASIC, "Asic_Close: Enter\n"); if (chip->firmwarestate < FS_OPENED) { DBG (DBG_ASIC, "Asic_Close: Scanner is not opened\n"); - return STATUS_GOOD; + return SANE_STATUS_GOOD; } if (chip->firmwarestate > FS_OPENED) @@ -3642,7 +3642,7 @@ Asic_Close (PAsic chip) CLOSE_ALL_CLOCK_ENABLE); status = CloseScanChip (chip); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { DBG (DBG_ERR, "Asic_Close: CloseScanChip error\n"); return status; @@ -3655,10 +3655,10 @@ Asic_Close (PAsic chip) return status; } -static STATUS +static SANE_Status Asic_TurnLamp (PAsic chip, SANE_Bool isLampOn) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; SANE_Byte PWM; DBG (DBG_ASIC, "Asic_TurnLamp: Enter\n"); @@ -3666,7 +3666,7 @@ Asic_TurnLamp (PAsic chip, SANE_Bool isLampOn) if (chip->firmwarestate < FS_OPENED) { DBG (DBG_ERR, "Asic_TurnLamp: Scanner is not opened\n"); - return STATUS_INVAL; + return SANE_STATUS_INVAL; } if (chip->firmwarestate > FS_OPENED) @@ -3693,7 +3693,7 @@ Asic_TurnLamp (PAsic chip, SANE_Bool isLampOn) } -static STATUS +static SANE_Status Asic_TurnTA (PAsic chip, SANE_Bool isTAOn) { SANE_Byte PWM; @@ -3703,7 +3703,7 @@ Asic_TurnTA (PAsic chip, SANE_Bool isTAOn) if (chip->firmwarestate < FS_OPENED) { DBG (DBG_ERR, "Asic_TurnTA: Scanner is not opened\n"); - return STATUS_INVAL; + return SANE_STATUS_INVAL; } if (chip->firmwarestate > FS_OPENED) @@ -3724,13 +3724,13 @@ Asic_TurnTA (PAsic chip, SANE_Bool isTAOn) chip->firmwarestate = FS_OPENED; DBG (DBG_ASIC, "Asic_TurnTA: Exit\n"); - return STATUS_GOOD; + return SANE_STATUS_GOOD; } -static STATUS +static SANE_Status Asic_WaitUnitReady (PAsic chip) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; SANE_Byte temp_status; int i = 0; @@ -3740,14 +3740,14 @@ Asic_WaitUnitReady (PAsic chip) { DBG (DBG_ERR, "Asic_WaitUnitReady: Scanner has not been opened\n"); - return STATUS_INVAL; + return SANE_STATUS_INVAL; } do { status = GetChipStatus (chip, 1, &temp_status); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { DBG (DBG_ASIC, "WaitChipIdle:Error!\n"); return status; @@ -3766,10 +3766,10 @@ Asic_WaitUnitReady (PAsic chip) } #if SANE_UNUSED -static STATUS +static SANE_Status Asic_Release (PAsic chip) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; DBG (DBG_ASIC, "Asic_Release()\n"); if (chip->firmwarestate > FS_ATTACHED) @@ -3782,10 +3782,10 @@ Asic_Release (PAsic chip) } #endif -static STATUS +static SANE_Status Asic_Initialize (PAsic chip) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; DBG (DBG_ASIC, "Asic_Initialize:Enter\n"); @@ -3814,12 +3814,12 @@ Asic_Initialize (PAsic chip) return status; } -static STATUS +static SANE_Status Asic_SetWindow (PAsic chip, SANE_Byte bScanBits, unsigned short wXResolution, unsigned short wYResolution, unsigned short wX, unsigned short wY, unsigned short wWidth, unsigned short wLength) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; unsigned short ValidPixelNumber; @@ -3869,7 +3869,7 @@ Asic_SetWindow (PAsic chip, SANE_Byte bScanBits, if (chip->firmwarestate != FS_OPENED) { DBG (DBG_ERR, "Asic_SetWindow: Scanner is not opened\n"); - return STATUS_INVAL; + return SANE_STATUS_INVAL; } Mustek_SendData (chip, ES01_F3_ActionOption, 0); @@ -3901,12 +3901,12 @@ Asic_SetWindow (PAsic chip, SANE_Byte bScanBits, BytePerPixel = 2; chip->dwBytesCountPerRow = (unsigned int) (wWidth) * 2; } - else if ((bScanBits == 8)) + else if (bScanBits == 8) { BytePerPixel = 1; chip->dwBytesCountPerRow = (unsigned int) (wWidth); } - else if ((bScanBits < 8)) + else if (bScanBits < 8) { BytePerPixel = 1; chip->dwBytesCountPerRow = (unsigned int) (wWidth); @@ -4269,10 +4269,10 @@ Asic_SetWindow (PAsic chip, SANE_Byte bScanBits, return status; } -static STATUS +static SANE_Status Asic_Reset (PAsic chip) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; DBG (DBG_ASIC, "Asic_Reset: Enter\n"); chip->lsLightSource = LS_REFLECTIVE; @@ -4297,10 +4297,10 @@ Asic_Reset (PAsic chip) return status; } -static STATUS +static SANE_Status Asic_SetSource (PAsic chip, LIGHTSOURCE lsLightSource) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; DBG (DBG_ASIC, "Asic_SetSource: Enter\n"); chip->lsLightSource = lsLightSource; @@ -4323,16 +4323,16 @@ Asic_SetSource (PAsic chip, LIGHTSOURCE lsLightSource) return status; } -static STATUS +static SANE_Status Asic_ScanStart (PAsic chip) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; DBG (DBG_ASIC, "Asic_ScanStart: Enter\n"); if (chip->firmwarestate != FS_OPENED) { DBG (DBG_ERR, "Asic_ScanStart: Scanner is not opened\n"); - return STATUS_INVAL; + return SANE_STATUS_INVAL; } Mustek_SendData (chip, ES01_8B_Status, 0x1c | 0x20); @@ -4347,10 +4347,10 @@ Asic_ScanStart (PAsic chip) return status; } -static STATUS +static SANE_Status Asic_ScanStop (PAsic chip) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; SANE_Byte temps[2]; SANE_Byte buf[4]; @@ -4368,7 +4368,7 @@ Asic_ScanStop (PAsic chip) buf[2] = 0x02; buf[3] = 0x02; status = WriteIOControl (chip, 0xc0, 0, 4, buf); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { DBG (DBG_ERR, "Asic_ScanStop: Stop scan error\n"); return status; @@ -4379,14 +4379,14 @@ Asic_ScanStop (PAsic chip) buf[2] = 0x00; buf[3] = 0x00; status = WriteIOControl (chip, 0xc0, 0, 4, buf); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { DBG (DBG_ERR, "Asic_ScanStop: Clear scan error\n"); return status; } status = Mustek_DMARead (chip, 2, temps); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { DBG (DBG_ERR, "Asic_ScanStop: DMAReadGeneralMode error\n"); return status; @@ -4403,10 +4403,10 @@ Asic_ScanStop (PAsic chip) return status; } -static STATUS +static SANE_Status Asic_ReadImage (PAsic chip, SANE_Byte * pBuffer, unsigned short LinesCount) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; unsigned int dwXferBytes; DBG (DBG_ASIC, "Asic_ReadImage: Enter : LinesCount = %d\n", LinesCount); @@ -4414,7 +4414,7 @@ Asic_ReadImage (PAsic chip, SANE_Byte * pBuffer, unsigned short LinesCount) if (chip->firmwarestate != FS_SCANNING) { DBG (DBG_ERR, "Asic_ReadImage: Scanner is not scanning\n"); - return STATUS_INVAL; + return SANE_STATUS_INVAL; } dwXferBytes = (unsigned int) (LinesCount) * chip->dwBytesCountPerRow; @@ -4425,14 +4425,14 @@ Asic_ReadImage (PAsic chip, SANE_Byte * pBuffer, unsigned short LinesCount) if (dwXferBytes < 0) { DBG (DBG_ASIC, "Asic_ReadImage: dwXferBytes <0\n"); - return STATUS_INVAL; + return SANE_STATUS_INVAL; } */ if (dwXferBytes == 0) { DBG (DBG_ASIC, "Asic_ReadImage: dwXferBytes == 0\n"); - return STATUS_GOOD; + return SANE_STATUS_GOOD; } status = Mustek_DMARead (chip, dwXferBytes, pBuffer); @@ -4443,10 +4443,10 @@ Asic_ReadImage (PAsic chip, SANE_Byte * pBuffer, unsigned short LinesCount) #if SANE_UNUSED -static STATUS +static SANE_Status Asic_CheckFunctionKey (PAsic chip, SANE_Byte * key) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; SANE_Byte bBuffer_1 = 0xff; SANE_Byte bBuffer_2 = 0xff; @@ -4455,7 +4455,7 @@ Asic_CheckFunctionKey (PAsic chip, SANE_Byte * key) if (chip->firmwarestate != FS_OPENED) { DBG (DBG_ERR, "Asic_CheckFunctionKey: Scanner is not Opened\n"); - return STATUS_INVAL; + return SANE_STATUS_INVAL; } Mustek_SendData (chip, ES01_97_GPIOControl0_7, 0x00); @@ -4486,7 +4486,7 @@ Asic_CheckFunctionKey (PAsic chip, SANE_Byte * key) } #endif -static STATUS +static SANE_Status Asic_IsTAConnected (PAsic chip, SANE_Bool * hasTA) { SANE_Byte bBuffer_1 = 0xff; @@ -4509,14 +4509,14 @@ Asic_IsTAConnected (PAsic chip, SANE_Bool * hasTA) DBG (DBG_ASIC, "hasTA=%d\n", *hasTA); DBG (DBG_ASIC, "Asic_IsTAConnected():Exit\n"); - return STATUS_GOOD; + return SANE_STATUS_GOOD; } #if SANE_UNUSED -static STATUS +static SANE_Status Asic_DownloadGammaTable (PAsic chip, void * lpBuffer) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; DBG (DBG_ASIC, "Asic_DownloadGammaTable()\n"); chip->lpGammaTable = lpBuffer; @@ -4526,11 +4526,11 @@ Asic_DownloadGammaTable (PAsic chip, void * lpBuffer) } #endif -static STATUS +static SANE_Status Asic_ReadCalibrationData (PAsic chip, void * pBuffer, unsigned int dwXferBytes, SANE_Byte bScanBits) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; SANE_Byte * pCalBuffer; unsigned int dwTotalReadData; unsigned int dwReadImageData; @@ -4540,7 +4540,7 @@ Asic_ReadCalibrationData (PAsic chip, void * pBuffer, if (chip->firmwarestate != FS_SCANNING) { DBG (DBG_ERR, "Asic_ReadCalibrationData: Scanner is not scanning\n"); - return STATUS_INVAL; + return SANE_STATUS_INVAL; } if (bScanBits == 24) @@ -4551,7 +4551,7 @@ Asic_ReadCalibrationData (PAsic chip, void * pBuffer, { DBG (DBG_ERR, "Asic_ReadCalibrationData: Can't malloc bCalBuffer memory\n"); - return STATUS_MEM_ERROR; + return SANE_STATUS_NO_MEM; } for (dwTotalReadData = 0; dwTotalReadData < dwXferBytes;) @@ -4592,11 +4592,11 @@ Asic_ReadCalibrationData (PAsic chip, void * pBuffer, return status; } -static STATUS +static SANE_Status Asic_SetMotorType (PAsic chip, SANE_Bool isMotorMove, SANE_Bool isUniformSpeed) { - STATUS status = STATUS_GOOD; - isUniformSpeed = isUniformSpeed; + SANE_Status status = SANE_STATUS_GOOD; + (void) isUniformSpeed; DBG (DBG_ASIC, "Asic_SetMotorType:Enter\n"); if (isMotorMove) @@ -4611,10 +4611,10 @@ Asic_SetMotorType (PAsic chip, SANE_Bool isMotorMove, SANE_Bool isUniformSpeed) return status; } -static STATUS +static SANE_Status Asic_MotorMove (PAsic chip, SANE_Bool isForward, unsigned int dwTotalSteps) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; unsigned short *NormalMoveMotorTable; LLF_CALCULATEMOTORTABLE CalMotorTable; LLF_MOTOR_CURRENT_AND_PHASE CurrentPhase; @@ -4675,12 +4675,12 @@ Asic_MotorMove (PAsic chip, SANE_Bool isForward, unsigned int dwTotalSteps) return status; } -static STATUS +static SANE_Status Asic_CarriageHome (PAsic chip, SANE_Bool isTA) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; SANE_Bool LampHome, TAHome; - isTA = isTA; + (void) isTA; DBG (DBG_ASIC, "Asic_CarriageHome:Enter\n"); @@ -4694,18 +4694,18 @@ Asic_CarriageHome (PAsic chip, SANE_Bool isTA) return status; } -static STATUS +static SANE_Status Asic_SetShadingTable (PAsic chip, unsigned short * lpWhiteShading, unsigned short * lpDarkShading, unsigned short wXResolution, unsigned short wWidth, unsigned short wX) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; unsigned short i, j, n; unsigned short wValidPixelNumber; double dbXRatioAdderDouble; unsigned int wShadingTableSize; - wX = wX; + (void) wX; DBG (DBG_ASIC, "Asic_SetShadingTable:Enter\n"); if (chip->firmwarestate < FS_OPENED) @@ -4737,7 +4737,7 @@ Asic_SetShadingTable (PAsic chip, unsigned short * lpWhiteShading, if (chip->lpShadingTable == NULL) { DBG (DBG_ASIC, "lpShadingTable == NULL\n"); - return STATUS_MEM_ERROR; + return SANE_STATUS_NO_MEM; } n = 0; @@ -4800,14 +4800,14 @@ Asic_SetShadingTable (PAsic chip, unsigned short * lpWhiteShading, return status; } -static STATUS +static SANE_Status Asic_WaitCarriageHome (PAsic chip, SANE_Bool isTA) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; SANE_Bool LampHome, TAHome; int i; - isTA = isTA; + (void) isTA; DBG (DBG_ASIC, "Asic_WaitCarriageHome:Enter\n"); @@ -4819,7 +4819,7 @@ Asic_WaitCarriageHome (PAsic chip, SANE_Bool isTA) usleep (300000); } if (i == 100) - status = STATUS_DEVICE_BUSY; + status = SANE_STATUS_DEVICE_BUSY; DBG (DBG_ASIC, "Wait %d s\n", (unsigned short) (i * 0.3)); Mustek_SendData (chip, ES01_F4_ActiveTriger, ACTION_TRIGER_DISABLE); @@ -4830,12 +4830,12 @@ Asic_WaitCarriageHome (PAsic chip, SANE_Bool isTA) return status; } -static STATUS +static SANE_Status Asic_SetCalibrate (PAsic chip, SANE_Byte bScanBits, unsigned short wXResolution, unsigned short wYResolution, unsigned short wX, unsigned short wY, unsigned short wWidth, unsigned short wLength, SANE_Bool isShading) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; unsigned short ValidPixelNumber; unsigned short wPerLineNeedBufferSize = 0; @@ -4886,13 +4886,13 @@ Asic_SetCalibrate (PAsic chip, SANE_Byte bScanBits, unsigned short wXResolution, if (chip->firmwarestate != FS_OPENED) { DBG (DBG_ERR, "Asic_SetCalibrate: Scanner is not opened\n"); - return STATUS_INVAL; + return SANE_STATUS_INVAL; } if (lpMotorStepsTable == NULL) { DBG (DBG_ERR, "Asic_SetCalibrate: insufficiency memory!\n"); - return STATUS_INVAL; + return SANE_STATUS_INVAL; } DBG (DBG_ASIC, "malloc LLF_MOTORMOVE =%ld Byte\n", (long int) (sizeof (LLF_MOTORMOVE))); @@ -4926,13 +4926,13 @@ Asic_SetCalibrate (PAsic chip, SANE_Byte bScanBits, unsigned short wXResolution, BytePerPixel = 2; chip->dwBytesCountPerRow = (unsigned int) (wWidth) * 2; } - else if ((bScanBits == 8)) + else if (bScanBits == 8) { wPerLineNeedBufferSize = wWidth; BytePerPixel = 1; chip->dwBytesCountPerRow = (unsigned int) (wWidth); } - else if ((bScanBits < 8)) + else if (bScanBits < 8) { wPerLineNeedBufferSize = wWidth >> 3; BytePerPixel = 1; @@ -5241,10 +5241,10 @@ Asic_SetCalibrate (PAsic chip, SANE_Byte bScanBits, unsigned short wXResolution, } -static STATUS +static SANE_Status Asic_SetAFEGainOffset (PAsic chip) { - STATUS status = STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; DBG (DBG_ASIC, "Asic_SetAFEGainOffset:Enter\n"); status = SetAFEGainOffset (chip); diff --git a/backend/mustek_usb2_asic.h b/backend/mustek_usb2_asic.h index 34ebba7..9550d33 100644 --- a/backend/mustek_usb2_asic.h +++ b/backend/mustek_usb2_asic.h @@ -256,19 +256,6 @@ typedef struct } Asic, *PAsic; -typedef enum -{ - STATUS_GOOD = 0, - STATUS_CANCELLED, - STATUS_EOF, - STATUS_DEVICE_BUSY, - STATUS_INVAL, - STATUS_MEM_ERROR, - STATUS_IO_ERROR, - STATUS_ACCESS_ERROR -} -STATUS; - /* For ScanObj */ typedef struct Point @@ -1211,107 +1198,107 @@ RGBColor; #define ES01_2CF_VALID_PIXEL_PARAMETER_OF_SEGMENT16 0x2CF /* forward declarations */ -static STATUS OpenScanChip (PAsic chip); -static STATUS CloseScanChip (PAsic chip); -static STATUS SafeInitialChip (PAsic chip); -static STATUS DRAM_Test (PAsic chip); +static SANE_Status OpenScanChip (PAsic chip); +static SANE_Status CloseScanChip (PAsic chip); +static SANE_Status SafeInitialChip (PAsic chip); +static SANE_Status DRAM_Test (PAsic chip); #if SANE_UNUSED -static STATUS SetPowerSave (PAsic chip); +static SANE_Status SetPowerSave (PAsic chip); #endif -static STATUS SetLineTimeAndExposure (PAsic chip); -static STATUS CCDTiming (PAsic chip); -static STATUS IsCarriageHome (PAsic chip, SANE_Bool * LampHome, SANE_Bool * TAHome); -static STATUS InitTiming (PAsic chip); -static STATUS GetChipStatus (PAsic chip, SANE_Byte Selector, SANE_Byte * ChipStatus); -static STATUS SetAFEGainOffset (PAsic chip); -static STATUS SetLEDTime (PAsic chip); -static STATUS SetScanMode (PAsic chip, SANE_Byte bScanBits); -static STATUS SetPackAddress (PAsic chip, unsigned short wXResolution, - unsigned short wWidth, unsigned short wX, double XRatioAdderDouble, - double XRatioTypeDouble, - SANE_Byte byClear_Pulse_Width, - unsigned short * PValidPixelNumber); -static STATUS SetExtraSetting (PAsic chip, unsigned short wXResolution, - unsigned short wCCD_PixelNumber, SANE_Bool isCaribrate); +static SANE_Status SetLineTimeAndExposure (PAsic chip); +static SANE_Status CCDTiming (PAsic chip); +static SANE_Status IsCarriageHome (PAsic chip, SANE_Bool * LampHome, SANE_Bool * TAHome); +static SANE_Status InitTiming (PAsic chip); +static SANE_Status GetChipStatus (PAsic chip, SANE_Byte Selector, SANE_Byte * ChipStatus); +static SANE_Status SetAFEGainOffset (PAsic chip); +static SANE_Status SetLEDTime (PAsic chip); +static SANE_Status SetScanMode (PAsic chip, SANE_Byte bScanBits); +static SANE_Status SetPackAddress (PAsic chip, unsigned short wXResolution, + unsigned short wWidth, unsigned short wX, double XRatioAdderDouble, + double XRatioTypeDouble, + SANE_Byte byClear_Pulse_Width, + unsigned short * PValidPixelNumber); +static SANE_Status SetExtraSetting (PAsic chip, unsigned short wXResolution, + unsigned short wCCD_PixelNumber, SANE_Bool isCaribrate); /* Forward declarations */ -static STATUS Mustek_SendData (PAsic chip, unsigned short reg, SANE_Byte data); -static STATUS Mustek_SendData2Byte (PAsic chip, unsigned short reg, SANE_Byte data); -static STATUS Mustek_ReceiveData (PAsic chip, SANE_Byte * reg); -static STATUS Mustek_WriteAddressLineForRegister (PAsic chip, SANE_Byte x); -static STATUS WriteIOControl (PAsic chip, unsigned short wValue, unsigned short wIndex, - unsigned short wLength, SANE_Byte * lpbuf); -static STATUS ReadIOControl (PAsic chip, unsigned short wValue, unsigned short wIndex, - unsigned short wLength, SANE_Byte * lpbuf); -static STATUS Mustek_DMARead (PAsic chip, unsigned int size, SANE_Byte * lpdata); -static STATUS Mustek_DMAWrite (PAsic chip, unsigned int size, SANE_Byte * lpdata); -static STATUS Mustek_ClearFIFO (PAsic chip); -static STATUS SetRWSize (PAsic chip, SANE_Byte ReadWrite, unsigned int size); +static SANE_Status Mustek_SendData (PAsic chip, unsigned short reg, SANE_Byte data); +static SANE_Status Mustek_SendData2Byte (PAsic chip, unsigned short reg, SANE_Byte data); +static SANE_Status Mustek_ReceiveData (PAsic chip, SANE_Byte * reg); +static SANE_Status Mustek_WriteAddressLineForRegister (PAsic chip, SANE_Byte x); +static SANE_Status WriteIOControl (PAsic chip, unsigned short wValue, unsigned short wIndex, + unsigned short wLength, SANE_Byte * lpbuf); +static SANE_Status ReadIOControl (PAsic chip, unsigned short wValue, unsigned short wIndex, + unsigned short wLength, SANE_Byte * lpbuf); +static SANE_Status Mustek_DMARead (PAsic chip, unsigned int size, SANE_Byte * lpdata); +static SANE_Status Mustek_DMAWrite (PAsic chip, unsigned int size, SANE_Byte * lpdata); +static SANE_Status Mustek_ClearFIFO (PAsic chip); +static SANE_Status SetRWSize (PAsic chip, SANE_Byte ReadWrite, unsigned int size); /* Open Scanner by Scanner Name and return Chip Information */ -static STATUS Asic_Open (PAsic chip, SANE_Byte *pDeviceName); +static SANE_Status Asic_Open (PAsic chip, SANE_Byte *pDeviceName); /* Close Scanner */ -static STATUS Asic_Close (PAsic chip); +static SANE_Status Asic_Close (PAsic chip); #if SANE_UNUSED /* Release Scanner Resource */ -static STATUS Asic_Release (PAsic chip); +static SANE_Status Asic_Release (PAsic chip); #endif /* Initialize Scanner Parameters */ -static STATUS Asic_Initialize (PAsic chip); +static SANE_Status Asic_Initialize (PAsic chip); /* Set Scan Window */ -static STATUS Asic_SetWindow (PAsic chip, SANE_Byte bScanBits, - unsigned short wXResolution, unsigned short wYResolution, - unsigned short wX, unsigned short wY, unsigned short wWidth, unsigned short wLength); +static SANE_Status Asic_SetWindow (PAsic chip, SANE_Byte bScanBits, + unsigned short wXResolution, unsigned short wYResolution, + unsigned short wX, unsigned short wY, unsigned short wWidth, unsigned short wLength); /* Turn Lamp ON or OFF */ -static STATUS Asic_TurnLamp (PAsic chip, SANE_Bool isLampOn); +static SANE_Status Asic_TurnLamp (PAsic chip, SANE_Bool isLampOn); /* Turn TA ON or OFF */ -static STATUS Asic_TurnTA (PAsic chip, SANE_Bool isTAOn); +static SANE_Status Asic_TurnTA (PAsic chip, SANE_Bool isTAOn); /* Reset some parameter of asic */ -static STATUS Asic_Reset (PAsic chip); +static SANE_Status Asic_Reset (PAsic chip); /* Set scan source */ -static STATUS Asic_SetSource (PAsic chip, LIGHTSOURCE lsLightSource); +static SANE_Status Asic_SetSource (PAsic chip, LIGHTSOURCE lsLightSource); /* Start scanner to scan */ -static STATUS Asic_ScanStart (PAsic chip); +static SANE_Status Asic_ScanStart (PAsic chip); /* Stop scanner to scan */ -static STATUS Asic_ScanStop (PAsic chip); +static SANE_Status Asic_ScanStop (PAsic chip); /* Read One Scan Line When Scanning */ -static STATUS Asic_ReadImage (PAsic chip, SANE_Byte * pBuffer, unsigned short LinesCount); +static SANE_Status Asic_ReadImage (PAsic chip, SANE_Byte * pBuffer, unsigned short LinesCount); #if SANE_UNUSED /* To Check Hard Key */ -static STATUS Asic_CheckFunctionKey (PAsic chip, SANE_Byte * key); +static SANE_Status Asic_CheckFunctionKey (PAsic chip, SANE_Byte * key); #endif /* To Check if TA id connected */ -static STATUS Asic_IsTAConnected (PAsic chip, SANE_Bool *hasTA); +static SANE_Status Asic_IsTAConnected (PAsic chip, SANE_Bool *hasTA); #if SANE_UNUSED /* Download GammaTable to Scanner */ -static STATUS Asic_DownloadGammaTable (PAsic chip, void * lpBuffer); +static SANE_Status Asic_DownloadGammaTable (PAsic chip, void * lpBuffer); #endif /* For AdjustAD Calculate Scanner*/ -static STATUS Asic_ReadCalibrationData (PAsic chip, void * pBuffer, - unsigned int dwXferBytes, SANE_Byte bScanBits); +static SANE_Status Asic_ReadCalibrationData (PAsic chip, void * pBuffer, + unsigned int dwXferBytes, SANE_Byte bScanBits); /* Set motor move or not */ -static STATUS Asic_SetMotorType (PAsic chip, SANE_Bool isMotorMove, SANE_Bool isUniformSpeed); +static SANE_Status Asic_SetMotorType (PAsic chip, SANE_Bool isMotorMove, SANE_Bool isUniformSpeed); /* Move Motor Forward or Backward */ -static STATUS Asic_MotorMove (PAsic chip, SANE_Bool isForward, unsigned int dwTotalSteps); +static SANE_Status Asic_MotorMove (PAsic chip, SANE_Bool isForward, unsigned int dwTotalSteps); /* Move Motor to Home. */ /* If isTA is TRUE, move TA to home, else move Lamp to home */ -static STATUS Asic_CarriageHome (PAsic chip, SANE_Bool isTA); +static SANE_Status Asic_CarriageHome (PAsic chip, SANE_Bool isTA); /* For ShadingTable */ -static STATUS Asic_SetShadingTable (PAsic chip, unsigned short * lpWhiteShading, - unsigned short * lpDarkShading, - unsigned short wXResolution, unsigned short wWidth, unsigned short wX); +static SANE_Status Asic_SetShadingTable (PAsic chip, unsigned short * lpWhiteShading, + unsigned short * lpDarkShading, + unsigned short wXResolution, unsigned short wWidth, unsigned short wX); /* Wait motor move to home. isTA no used */ -static STATUS Asic_WaitCarriageHome (PAsic chip, SANE_Bool isTA); +static SANE_Status Asic_WaitCarriageHome (PAsic chip, SANE_Bool isTA); /* Wait until asic idle */ -static STATUS Asic_WaitUnitReady (PAsic chip); +static SANE_Status Asic_WaitUnitReady (PAsic chip); /* Set Scan Parameter to Scanner */ -static STATUS Asic_SetCalibrate (PAsic chip, SANE_Byte bScanBits, unsigned short wXResolution, - unsigned short wYResolution, unsigned short wX, unsigned short wY, - unsigned short wWidth, unsigned short wLength, SANE_Bool isShading); +static SANE_Status Asic_SetCalibrate (PAsic chip, SANE_Byte bScanBits, unsigned short wXResolution, + unsigned short wYResolution, unsigned short wX, unsigned short wY, + unsigned short wWidth, unsigned short wLength, SANE_Bool isShading); /* Set AFE Parameter to Scanner */ -static STATUS Asic_SetAFEGainOffset (PAsic chip); +static SANE_Status Asic_SetAFEGainOffset (PAsic chip); /* ---------------------- asic motor defines -------------------------- */ @@ -1393,27 +1380,27 @@ typedef struct tagLLF_MOTORMOVE unsigned short wScanBackHomeExtSteps; } LLF_MOTORMOVE; -static STATUS CalculateMotorTable (LLF_CALCULATEMOTORTABLE * - lpCalculateMotorTable, unsigned short wYResolution); -static STATUS LLFCalculateMotorTable (LLF_CALCULATEMOTORTABLE * - lpCalculateMotorTable); -static STATUS LLFSetMotorCurrentAndPhase (PAsic chip, - LLF_MOTOR_CURRENT_AND_PHASE * - MotorCurrentAndPhase); -static STATUS SetMotorStepTable (PAsic chip, LLF_MOTORMOVE * MotorStepsTable, - unsigned short wStartY, unsigned int dwScanImageSteps, - unsigned short wYResolution); -static STATUS LLFSetMotorTable (PAsic chip, - LLF_SETMOTORTABLE * LLF_SetMotorTable); -static STATUS SetMotorCurrent (PAsic chip, unsigned short dwMotorSpeed, - LLF_MOTOR_CURRENT_AND_PHASE * CurrentPhase); -static STATUS LLFMotorMove (PAsic chip, LLF_MOTORMOVE * LLF_MotorMove); +static SANE_Status CalculateMotorTable (LLF_CALCULATEMOTORTABLE * + lpCalculateMotorTable, unsigned short wYResolution); +static SANE_Status LLFCalculateMotorTable (LLF_CALCULATEMOTORTABLE * + lpCalculateMotorTable); +static SANE_Status LLFSetMotorCurrentAndPhase (PAsic chip, + LLF_MOTOR_CURRENT_AND_PHASE * + MotorCurrentAndPhase); +static SANE_Status SetMotorStepTable (PAsic chip, LLF_MOTORMOVE * MotorStepsTable, + unsigned short wStartY, unsigned int dwScanImageSteps, + unsigned short wYResolution); +static SANE_Status LLFSetMotorTable (PAsic chip, + LLF_SETMOTORTABLE * LLF_SetMotorTable); +static SANE_Status SetMotorCurrent (PAsic chip, unsigned short dwMotorSpeed, + LLF_MOTOR_CURRENT_AND_PHASE * CurrentPhase); +static SANE_Status LLFMotorMove (PAsic chip, LLF_MOTORMOVE * LLF_MotorMove); #if SANE_UNUSED -static STATUS LLFStopMotorMove (PAsic chip); +static SANE_Status LLFStopMotorMove (PAsic chip); #endif -static STATUS LLFSetRamAddress (PAsic chip, unsigned int dwStartAddr, - unsigned int dwEndAddr, SANE_Byte byAccessTarget); -static STATUS LLFRamAccess (PAsic chip, LLF_RAMACCESS * RamAccess); -static STATUS MotorBackHome (PAsic chip, SANE_Byte WaitOrNoWait); +static SANE_Status LLFSetRamAddress (PAsic chip, unsigned int dwStartAddr, + unsigned int dwEndAddr, SANE_Byte byAccessTarget); +static SANE_Status LLFRamAccess (PAsic chip, LLF_RAMACCESS * RamAccess); +static SANE_Status MotorBackHome (PAsic chip, SANE_Byte WaitOrNoWait); #endif diff --git a/backend/mustek_usb2_high.c b/backend/mustek_usb2_high.c index 5119d55..e8b067f 100644 --- a/backend/mustek_usb2_high.c +++ b/backend/mustek_usb2_high.c @@ -204,13 +204,13 @@ MustScanner_Init () DBG (DBG_FUNC, "MustScanner_Init: Call in\n"); g_chip.firmwarestate = FS_NULL; - if (STATUS_GOOD != Asic_Open (&g_chip, g_pDeviceFile)) + if (SANE_STATUS_GOOD != Asic_Open (&g_chip, g_pDeviceFile)) { DBG (DBG_FUNC, "MustScanner_Init: Asic_Open return error\n"); return FALSE; } - if (STATUS_GOOD != Asic_Initialize (&g_chip)) + if (SANE_STATUS_GOOD != Asic_Initialize (&g_chip)) { DBG (DBG_FUNC, "MustScanner_Init: Asic_Initialize return error\n"); return FALSE; @@ -263,7 +263,7 @@ static SANE_Bool MustScanner_GetScannerState () { - if (STATUS_GOOD != Asic_Open (&g_chip, g_pDeviceFile)) + if (SANE_STATUS_GOOD != Asic_Open (&g_chip, g_pDeviceFile)) { DBG (DBG_FUNC, "MustScanner_GetScannerState: Asic_Open return error\n"); return FALSE; @@ -293,20 +293,20 @@ MustScanner_PowerControl (SANE_Bool isLampOn, SANE_Bool isTALampOn) { SANE_Bool hasTA; DBG (DBG_FUNC, "MustScanner_PowerControl: Call in\n"); - if (STATUS_GOOD != Asic_Open (&g_chip, g_pDeviceFile)) + if (SANE_STATUS_GOOD != Asic_Open (&g_chip, g_pDeviceFile)) { DBG (DBG_FUNC, "MustScanner_PowerControl: Asic_Open return error\n"); return FALSE; } - if (STATUS_GOOD != Asic_TurnLamp (&g_chip, isLampOn)) + if (SANE_STATUS_GOOD != Asic_TurnLamp (&g_chip, isLampOn)) { DBG (DBG_FUNC, "MustScanner_PowerControl: Asic_TurnLamp return error\n"); return FALSE; } - if (STATUS_GOOD != Asic_IsTAConnected (&g_chip, &hasTA)) + if (SANE_STATUS_GOOD != Asic_IsTAConnected (&g_chip, &hasTA)) { DBG (DBG_FUNC, "MustScanner_PowerControl: Asic_IsTAConnected return error\n"); @@ -315,7 +315,7 @@ MustScanner_PowerControl (SANE_Bool isLampOn, SANE_Bool isTALampOn) if (hasTA) { - if (STATUS_GOOD != Asic_TurnTA (&g_chip, isTALampOn)) + if (SANE_STATUS_GOOD != Asic_TurnTA (&g_chip, isTALampOn)) { DBG (DBG_FUNC, "MustScanner_PowerControl: Asic_TurnTA return error\n"); @@ -347,20 +347,20 @@ MustScanner_BackHome () { DBG (DBG_FUNC, "MustScanner_BackHome: call in \n"); - if (STATUS_GOOD != Asic_Open (&g_chip, g_pDeviceFile)) + if (SANE_STATUS_GOOD != Asic_Open (&g_chip, g_pDeviceFile)) { DBG (DBG_FUNC, "MustScanner_BackHome: Asic_Open return error\n"); return FALSE; } - if (STATUS_GOOD != Asic_CarriageHome (&g_chip, FALSE)) + if (SANE_STATUS_GOOD != Asic_CarriageHome (&g_chip, FALSE)) { DBG (DBG_FUNC, "MustScanner_BackHome: Asic_CarriageHome return error\n"); return FALSE; } - if (STATUS_GOOD != Asic_WaitUnitReady (&g_chip)) + if (SANE_STATUS_GOOD != Asic_WaitUnitReady (&g_chip)) { DBG (DBG_FUNC, "MustScanner_BackHome: Asic_WaitUnitReady return error\n"); @@ -390,14 +390,14 @@ MustScanner_Prepare (SANE_Byte bScanSource) { DBG (DBG_FUNC, "MustScanner_Prepare: call in\n"); - if (STATUS_GOOD != Asic_Open (&g_chip, g_pDeviceFile)) + if (SANE_STATUS_GOOD != Asic_Open (&g_chip, g_pDeviceFile)) { DBG (DBG_FUNC, "MustScanner_Prepare: Asic_Open return error\n"); return FALSE; } - if (STATUS_GOOD != Asic_WaitUnitReady (&g_chip)) + if (SANE_STATUS_GOOD != Asic_WaitUnitReady (&g_chip)) { DBG (DBG_FUNC, "MustScanner_Prepare: Asic_WaitUnitReady return error\n"); @@ -407,13 +407,13 @@ MustScanner_Prepare (SANE_Byte bScanSource) if (SS_Reflective == bScanSource) { DBG (DBG_FUNC, "MustScanner_Prepare:ScanSource is SS_Reflective\n"); - if (STATUS_GOOD != Asic_TurnLamp (&g_chip, TRUE)) + if (SANE_STATUS_GOOD != Asic_TurnLamp (&g_chip, TRUE)) { DBG (DBG_FUNC, "MustScanner_Prepare: Asic_TurnLamp return error\n"); return FALSE; } - if (STATUS_GOOD != Asic_SetSource (&g_chip, LS_REFLECTIVE)) + if (SANE_STATUS_GOOD != Asic_SetSource (&g_chip, LS_REFLECTIVE)) { DBG (DBG_FUNC, "MustScanner_Prepare: Asic_SetSource return error\n"); @@ -423,12 +423,12 @@ MustScanner_Prepare (SANE_Byte bScanSource) else if (SS_Positive == bScanSource) { DBG (DBG_FUNC, "MustScanner_Prepare:ScanSource is SS_Positive\n"); - if (STATUS_GOOD != Asic_TurnTA (&g_chip, TRUE)) + if (SANE_STATUS_GOOD != Asic_TurnTA (&g_chip, TRUE)) { DBG (DBG_FUNC, "MustScanner_Prepare: Asic_TurnTA return error\n"); return FALSE; } - if (STATUS_GOOD != Asic_SetSource (&g_chip, LS_POSITIVE)) + if (SANE_STATUS_GOOD != Asic_SetSource (&g_chip, LS_POSITIVE)) { DBG (DBG_FUNC, "MustScanner_Prepare: Asic_SetSource return error\n"); @@ -439,13 +439,13 @@ MustScanner_Prepare (SANE_Byte bScanSource) { DBG (DBG_FUNC, "MustScanner_Prepare:ScanSource is SS_Negative\n"); - if (STATUS_GOOD != Asic_TurnTA (&g_chip, TRUE)) + if (SANE_STATUS_GOOD != Asic_TurnTA (&g_chip, TRUE)) { DBG (DBG_FUNC, "MustScanner_Prepare: Asic_TurnTA return error\n"); return FALSE; } - if (STATUS_GOOD != Asic_SetSource (&g_chip, LS_NEGATIVE)) + if (SANE_STATUS_GOOD != Asic_SetSource (&g_chip, LS_NEGATIVE)) { DBG (DBG_FUNC, "MustScanner_Prepare: Asic_SetSource return error\n"); @@ -2132,7 +2132,7 @@ MustScanner_GetMono16BitLine (SANE_Byte * lpLine, SANE_Bool isOrderInvert, unsigned short wLinePos = 0; unsigned short i; - isOrderInvert = isOrderInvert; + (void) isOrderInvert; DBG (DBG_FUNC, "MustScanner_GetMono16BitLine: call in\n"); @@ -2228,7 +2228,7 @@ MustScanner_GetMono16BitLine1200DPI (SANE_Byte * lpLine, SANE_Bool isOrderInvert unsigned short i; SANE_Byte * lpTemp = lpLine; - isOrderInvert = isOrderInvert; + (void) isOrderInvert; DBG (DBG_FUNC, "MustScanner_GetMono16BitLine1200DPI: call in\n"); TotalXferLines = 0; @@ -2407,7 +2407,7 @@ MustScanner_GetMono8BitLine (SANE_Byte * lpLine, SANE_Bool isOrderInvert, unsigned short i; unsigned short wLinePos = 0; - isOrderInvert = isOrderInvert; + (void) isOrderInvert; DBG (DBG_FUNC, "MustScanner_GetMono8BitLine: call in\n"); TotalXferLines = 0; @@ -2502,7 +2502,7 @@ MustScanner_GetMono8BitLine1200DPI (SANE_Byte * lpLine, SANE_Bool isOrderInvert, unsigned short i; SANE_Byte bNextPixel = 0; - isOrderInvert = isOrderInvert; + (void) isOrderInvert; DBG (DBG_FUNC, "MustScanner_GetMono8BitLine1200DPI: call in\n"); TotalXferLines = 0; @@ -2660,7 +2660,7 @@ MustScanner_GetMono1BitLine (SANE_Byte * lpLine, SANE_Bool isOrderInvert, unsigned short wLinePos; unsigned short i; - isOrderInvert = isOrderInvert; + (void) isOrderInvert; DBG (DBG_FUNC, "MustScanner_GetMono1BitLine: call in\n"); @@ -2752,7 +2752,7 @@ MustScanner_GetMono1BitLine1200DPI (SANE_Byte * lpLine, SANE_Bool isOrderInvert, unsigned short wLinePosOdd; unsigned short wLinePosEven; - isOrderInvert = isOrderInvert; + (void) isOrderInvert; DBG (DBG_FUNC, "MustScanner_GetMono1BitLine1200DPI: call in\n"); @@ -2919,7 +2919,7 @@ MustScanner_CalculateMaxMin (SANE_Byte * pBuffer, unsigned short * lpMaxValue, unsigned short *wSecData = NULL, *wDarkSecData = NULL; int i, j; - wResolution = wResolution; + (void) wResolution; wSecData = (unsigned short *) malloc (sizeof (unsigned short) * g_nSecNum); if (wSecData == NULL) @@ -3001,7 +3001,7 @@ MustScanner_ReadDataFromScanner (void * dummy) unsigned short wScanLinesThisBlock; unsigned short wBufferLines = g_wLineDistance * 2 + g_wPixelDistance; - dummy = dummy; + (void) dummy; DBG (DBG_FUNC, "MustScanner_ReadDataFromScanner: call in, and in new thread\n"); @@ -3023,7 +3023,7 @@ MustScanner_ReadDataFromScanner (void * dummy) "MustScanner_ReadDataFromScanner: wScanLinesThisBlock=%d\n", wScanLinesThisBlock); - if (STATUS_GOOD != + if (SANE_STATUS_GOOD != Asic_ReadImage (&g_chip, lpReadImage, wScanLinesThisBlock)) { DBG (DBG_FUNC, diff --git a/backend/mustek_usb2_reflective.c b/backend/mustek_usb2_reflective.c index baf80e4..ed37296 100644 --- a/backend/mustek_usb2_reflective.c +++ b/backend/mustek_usb2_reflective.c @@ -82,31 +82,31 @@ Reflective_Reset () return FALSE; } - if (STATUS_GOOD != Asic_Open (&g_chip, g_pDeviceFile)) + if (SANE_STATUS_GOOD != Asic_Open (&g_chip, g_pDeviceFile)) { DBG (DBG_FUNC, "Reflective_Reset: Asic_Open return error\n"); return FALSE; } - if (STATUS_GOOD != Asic_Reset (&g_chip)) + if (SANE_STATUS_GOOD != Asic_Reset (&g_chip)) { DBG (DBG_FUNC, "Reflective_Reset: Asic_Reset return error\n"); return FALSE; } - if (STATUS_GOOD != Asic_SetSource (&g_chip, LS_REFLECTIVE)) + if (SANE_STATUS_GOOD != Asic_SetSource (&g_chip, LS_REFLECTIVE)) { DBG (DBG_FUNC, "Reflective_Reset: Asic_SetSource return error\n"); return FALSE; } - if (STATUS_GOOD != Asic_TurnLamp (&g_chip, TRUE)) + if (SANE_STATUS_GOOD != Asic_TurnLamp (&g_chip, TRUE)) { DBG (DBG_FUNC, "Reflective_Reset: Asic_TurnLamp return error\n"); return FALSE; } - if (STATUS_GOOD != Asic_Close (&g_chip)) + if (SANE_STATUS_GOOD != Asic_Close (&g_chip)) { DBG (DBG_FUNC, "Reflective_Reset: Asic_Close return error\n"); return FALSE; @@ -362,7 +362,7 @@ Reflective_SetupScan (COLORMODE ColorMode, unsigned short YDpi, SANE_Bool isInvert, unsigned short X, unsigned short Y, unsigned short Width, unsigned short Height) { - isInvert = isInvert; + (void) isInvert; DBG (DBG_FUNC, "Reflective_SetupScan: Call in\n"); if (g_bOpened) { @@ -439,7 +439,7 @@ Reflective_SetupScan (COLORMODE ColorMode, break; } - if (Asic_Open (&g_chip, g_pDeviceFile) != STATUS_GOOD) + if (Asic_Open (&g_chip, g_pDeviceFile) != SANE_STATUS_GOOD) { DBG (DBG_FUNC, "Reflective_SetupScan: Asic_Open return error\n"); return FALSE; @@ -1153,7 +1153,7 @@ Reflective_FindTopLeft (unsigned short * lpwStartX, unsigned short * lpwStartY) Asic_SetCalibrate (&g_chip, 8, wXResolution, wYResolution, 0, 0, wCalWidth, wCalHeight, FALSE); Asic_SetAFEGainOffset (&g_chip); - if (Asic_ScanStart (&g_chip) != STATUS_GOOD) + if (Asic_ScanStart (&g_chip) != SANE_STATUS_GOOD) { DBG (DBG_FUNC, "Reflective_FindTopLeft: Asic_ScanStart return error\n"); free (lpCalData); @@ -1162,7 +1162,7 @@ Reflective_FindTopLeft (unsigned short * lpwStartX, unsigned short * lpwStartY) for (i = 0; i < nScanBlock; i++) { - if (STATUS_GOOD != + if (SANE_STATUS_GOOD != Asic_ReadCalibrationData (&g_chip, lpCalData + i * g_dwCalibrationSize, g_dwCalibrationSize, 8)) @@ -1174,7 +1174,7 @@ Reflective_FindTopLeft (unsigned short * lpwStartX, unsigned short * lpwStartY) } } - if (STATUS_GOOD != + if (SANE_STATUS_GOOD != Asic_ReadCalibrationData (&g_chip, lpCalData + (nScanBlock) * g_dwCalibrationSize, @@ -1340,7 +1340,7 @@ Return value: static SANE_Bool Reflective_LineCalibration16Bits () { - STATUS status; + SANE_Status status; SANE_Byte * lpWhiteData; SANE_Byte * lpDarkData; unsigned int dwWhiteTotalSize; @@ -1403,7 +1403,7 @@ Reflective_LineCalibration16Bits () status = Asic_SetCalibrate (&g_chip, 48, g_XDpi, g_YDpi, g_X, 0, wCalWidth, wCalHeight, TRUE); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { DBG (DBG_FUNC, "Reflective_LineCalibration16Bits: Asic_SetCalibrate return error \n"); @@ -1415,7 +1415,7 @@ Reflective_LineCalibration16Bits () } status = Asic_ScanStart (&g_chip); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { DBG (DBG_FUNC, "Reflective_LineCalibration16Bits: Asic_ScanStart return error \n"); @@ -1427,7 +1427,7 @@ Reflective_LineCalibration16Bits () status = Asic_ReadCalibrationData (&g_chip, lpWhiteData, dwWhiteTotalSize, 8); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { free (lpWhiteData); free (lpDarkData); @@ -1438,7 +1438,7 @@ Reflective_LineCalibration16Bits () /*Read dark level data */ status = Asic_SetMotorType (&g_chip, FALSE, TRUE); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { DBG (DBG_FUNC, "Reflective_LineCalibration16Bits: Asic_SetMotorType return error \n"); @@ -1451,7 +1451,7 @@ Reflective_LineCalibration16Bits () status = Asic_SetCalibrate (&g_chip, 48, g_XDpi, g_YDpi, g_X, 0, wCalWidth, wCalHeight, TRUE); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { DBG (DBG_FUNC, "Reflective_LineCalibration16Bits: Asic_SetCalibrate return error \n"); @@ -1462,7 +1462,7 @@ Reflective_LineCalibration16Bits () } status = Asic_TurnLamp (&g_chip, FALSE); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { DBG (DBG_FUNC, "Reflective_LineCalibration16Bits: Asic_TurnLamp return error \n"); @@ -1475,7 +1475,7 @@ Reflective_LineCalibration16Bits () usleep (500000); status = Asic_ScanStart (&g_chip); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { DBG (DBG_FUNC, "Reflective_LineCalibration16Bits: Asic_ScanStart return error \n"); @@ -1486,7 +1486,7 @@ Reflective_LineCalibration16Bits () } status = Asic_ReadCalibrationData (&g_chip, lpDarkData, dwDarkTotalSize, 8); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { DBG (DBG_FUNC, "Reflective_LineCalibration16Bits: Asic_ReadCalibrationData return error \n"); @@ -1500,7 +1500,7 @@ Reflective_LineCalibration16Bits () /* Turn on lamp */ status = Asic_TurnLamp (&g_chip, TRUE); - if (status != STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { DBG (DBG_FUNC, "Reflective_LineCalibration16Bits: Asic_TurnLamp return error \n"); diff --git a/backend/mustek_usb2_transparent.c b/backend/mustek_usb2_transparent.c index 21c7734..1c4b91b 100644 --- a/backend/mustek_usb2_transparent.c +++ b/backend/mustek_usb2_transparent.c @@ -82,37 +82,37 @@ Transparent_Reset () DBG (DBG_FUNC, "Transparent_Reset: scanner has been opened\n"); return FALSE; } - if (STATUS_GOOD != Asic_Open (&g_chip, g_pDeviceFile)) + if (SANE_STATUS_GOOD != Asic_Open (&g_chip, g_pDeviceFile)) { DBG (DBG_FUNC, "Transparent_Reset: can not open scanner\n"); return FALSE; } - if (STATUS_GOOD != Asic_Reset (&g_chip)) + if (SANE_STATUS_GOOD != Asic_Reset (&g_chip)) { DBG (DBG_FUNC, "Reflective_Reset: Asic_Reset return error\n"); return FALSE; } - if (STATUS_GOOD != Asic_SetSource (&g_chip, LS_POSITIVE)) + if (SANE_STATUS_GOOD != Asic_SetSource (&g_chip, LS_POSITIVE)) { DBG (DBG_FUNC, "Reflective_Reset: Asic_SetSource return error\n"); return FALSE; } - if (STATUS_GOOD != Asic_TurnLamp (&g_chip, FALSE)) + if (SANE_STATUS_GOOD != Asic_TurnLamp (&g_chip, FALSE)) { DBG (DBG_FUNC, "Reflective_Reset: Asic_TurnLamp return error\n"); return FALSE; } - if (STATUS_GOOD != Asic_TurnTA (&g_chip, TRUE)) + if (SANE_STATUS_GOOD != Asic_TurnTA (&g_chip, TRUE)) { DBG (DBG_FUNC, "Reflective_Reset: Asic_TurnTA return error\n"); return FALSE; } - if (STATUS_GOOD != Asic_Close (&g_chip)) + if (SANE_STATUS_GOOD != Asic_Close (&g_chip)) { DBG (DBG_FUNC, "Reflective_Reset: Asic_Close return error\n"); return FALSE; @@ -305,7 +305,7 @@ Transparent_SetupScan (COLORMODE ColorMode, unsigned short XDpi, unsigned short SANE_Bool hasTA; unsigned short wTAShadingMinus = 0; - isInvert = isInvert; + (void) isInvert; DBG (DBG_FUNC, "Transparent_SetupScan: call in\n"); if (g_bOpened) @@ -391,7 +391,7 @@ Transparent_SetupScan (COLORMODE ColorMode, unsigned short XDpi, unsigned short break; } - if (Asic_Open (&g_chip, g_pDeviceFile) != STATUS_GOOD) + if (Asic_Open (&g_chip, g_pDeviceFile) != SANE_STATUS_GOOD) { DBG (DBG_FUNC, "Transparent_SetupScan: Asic_Open return error\n"); return FALSE; @@ -399,13 +399,13 @@ Transparent_SetupScan (COLORMODE ColorMode, unsigned short XDpi, unsigned short g_bOpened = TRUE; - if (STATUS_GOOD != Asic_TurnLamp (&g_chip, FALSE)) + if (SANE_STATUS_GOOD != Asic_TurnLamp (&g_chip, FALSE)) { DBG (DBG_FUNC, "Transparent_SetupScan: Asic_TurnLamp return error\n"); return FALSE; } - if (Asic_IsTAConnected (&g_chip, &hasTA) != STATUS_GOOD) + if (Asic_IsTAConnected (&g_chip, &hasTA) != SANE_STATUS_GOOD) { DBG (DBG_FUNC, "Transparent_SetupScan: Asic_IsTAConnected return error\n"); @@ -417,7 +417,7 @@ Transparent_SetupScan (COLORMODE ColorMode, unsigned short XDpi, unsigned short return FALSE; } - if (Asic_TurnTA (&g_chip, TRUE) != STATUS_GOOD) + if (Asic_TurnTA (&g_chip, TRUE) != SANE_STATUS_GOOD) { DBG (DBG_FUNC, "Transparent_SetupScan: Asic_TurnTA return error\n"); return FALSE; diff --git a/backend/mustek_usb_high.c b/backend/mustek_usb_high.c index 7b03475..8c89571 100644 --- a/backend/mustek_usb_high.c +++ b/backend/mustek_usb_high.c @@ -2672,7 +2672,7 @@ usb_high_scan_get_rgb_24_bit_line (Mustek_Usb_Device * dev, SANE_Byte * line, SANE_Word lines_left; DBG (5, "usb_high_scan_get_rgb_24_bit_line: start, dev=%p, line=%p, " - "is_order_invert=%d\n", (void *) dev, line, is_order_invert); + "is_order_invert=%d\n", (void *) dev, (void *) line, is_order_invert); RIE (usb_low_get_row (dev->chip, dev->green, &lines_left)); @@ -2701,7 +2701,7 @@ usb_high_scan_get_mono_8_bit_line (Mustek_Usb_Device * dev, SANE_Byte * line, SANE_Word lines_left; DBG (5, "usb_high_scan_get_mono_8_bit_line: start, dev=%p, line=%p, " - "is_order_invert=%d\n", (void *) dev, line, is_order_invert); + "is_order_invert=%d\n", (void *) dev, (void *) line, is_order_invert); RIE (usb_low_get_row (dev->chip, dev->green, &lines_left)); RIE (usb_high_cal_calibrate (dev->mono_calibrator, dev->green + diff --git a/backend/nec.c b/backend/nec.c index 66bfc9b..6de89a8 100644 --- a/backend/nec.c +++ b/backend/nec.c @@ -290,7 +290,7 @@ sense_handler(int fd, u_char *sense_buffer, void *ss) int sense_key; NEC_Sense_Data *sdat = (NEC_Sense_Data *) ss; - fd = fd; /* silence compilation warnings */ + (void) fd; /* silence compilation warnings */ #define add_sense_code sense_buffer[12] #define add_sense_qual sense_buffer[13] @@ -1890,7 +1890,7 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize) NEC_New_Device *np; int i; - authorize = authorize; /* silence compilation warnings */ + (void) authorize; /* silence compilation warnings */ DBG_INIT (); DBG (10, "<< sane_init "); @@ -2079,7 +2079,7 @@ sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only) int i; DBG (10, "<< sane_get_devices "); - local_only = local_only; /* silence compilation warnings */ + (void) local_only; /* silence compilation warnings */ if (devlist) free (devlist); @@ -2714,7 +2714,7 @@ send_binary_g_table(NEC_Scanner *s, SANE_Word *a, int dtq) SANE_Status status; unsigned int i, j; - dtq = dtq; /* silence compilation warnings */ + (void) dtq; /* silence compilation warnings */ DBG(11, "<< send_binary_g_table\n"); @@ -3696,8 +3696,8 @@ sane_cancel (SANE_Handle handle) SANE_Status sane_set_io_mode (SANE_Handle handle, SANE_Bool non_blocking) { - handle = handle; - non_blocking = non_blocking; /* silence compilation warnings */ + (void) handle; + (void) non_blocking; /* silence compilation warnings */ DBG (10, "<< sane_set_io_mode"); DBG (10, ">>\n"); @@ -3708,8 +3708,8 @@ sane_set_io_mode (SANE_Handle handle, SANE_Bool non_blocking) SANE_Status sane_get_select_fd (SANE_Handle handle, SANE_Int * fd) { - handle = handle; - fd = fd; /* silence compilation warnings */ + (void) handle; + (void) fd; /* silence compilation warnings */ DBG (10, "<< sane_get_select_fd"); DBG (10, ">>\n"); diff --git a/backend/net.c b/backend/net.c index 7c4aae9..d16119a 100644 --- a/backend/net.c +++ b/backend/net.c @@ -705,9 +705,9 @@ net_avahi_resolve_callback (AvahiServiceResolver *r, AvahiIfIndex interface, Ava char *t; /* unused */ - interface = interface; - protocol = protocol; - userdata = userdata; + (void) interface; + (void) protocol; + (void) userdata; if (!r) return; @@ -759,8 +759,8 @@ net_avahi_browse_callback (AvahiServiceBrowser *b, AvahiIfIndex interface, Avahi AvahiProtocol proto; /* unused */ - flags = flags; - userdata = userdata; + (void) flags; + (void) userdata; if (!b) return; @@ -808,7 +808,7 @@ net_avahi_callback (AvahiClient *c, AvahiClientState state, void * userdata) int error; /* unused */ - userdata = userdata; + (void) userdata; if (!c) return; @@ -1201,7 +1201,7 @@ sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only) char *full_name; int i, num_devs; size_t len; -#define ASSERT_SPACE(n) \ +#define ASSERT_SPACE(n) do \ { \ if (devlist_len + (n) > devlist_size) \ { \ @@ -1216,7 +1216,7 @@ sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only) return SANE_STATUS_NO_MEM; \ } \ } \ - } + } while (0) DBG (3, "sane_get_devices: local_only = %d\n", local_only); @@ -2132,7 +2132,7 @@ sane_read (SANE_Handle handle, SANE_Byte * data, SANE_Int max_length, int is_even; DBG (3, "sane_read: handle=%p, data=%p, max_length=%d, length=%p\n", - handle, data, max_length, (void *) length); + handle, (void *) data, max_length, (void *) length); if (!length) { DBG (1, "sane_read: length == NULL\n"); diff --git a/backend/niash.c b/backend/niash.c index bce6c2f..91d99a9 100644 --- a/backend/niash.c +++ b/backend/niash.c @@ -1368,7 +1368,7 @@ sane_read (SANE_Handle h, SANE_Byte * buf, SANE_Int maxlen, SANE_Int * len) TDataPipe *p; TModeParam const *pMode; - DBG (DBG_MSG, "sane_read: buf=%p, maxlen=%d, ", buf, maxlen); + DBG (DBG_MSG, "sane_read: buf=%p, maxlen=%d, ", (void *) buf, maxlen); s = (TScanner *) h; diff --git a/backend/p5.c b/backend/p5.c index 558d9d2..26d78c6 100644 --- a/backend/p5.c +++ b/backend/p5.c @@ -157,7 +157,7 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize) { SANE_Status status; - authorize = authorize; /* get rid of compiler warning */ + (void) authorize; /* get rid of compiler warning */ init_count++; @@ -459,8 +459,8 @@ SANE_Status sane_get_select_fd (SANE_Handle handle, SANE_Int * fdp) { /* make compiler happy ... */ - handle = handle; - fdp = fdp; + (void) handle; + (void) fdp; DBG (DBG_proc, "sane_get_select_fd: start\n"); DBG (DBG_warn, "sane_get_select_fd: unsupported ...\n"); @@ -1595,7 +1595,7 @@ config_attach (SANEI_Config __sane_unused__ * config, const char *devname, /* currently, the config is a global variable so config is useless here */ /* the correct thing would be to have a generic sanei_attach_matching_devices * using an attach function with a config parameter */ - config = config; + (void) config; /* the devname has been processed and is ready to be used * directly. The config struct contains all the configuration data for diff --git a/backend/p5_device.c b/backend/p5_device.c index a9026f0..83bf63c 100644 --- a/backend/p5_device.c +++ b/backend/p5_device.c @@ -55,7 +55,7 @@ addr_name (uint16_t addr) */ static uint8_t -inb (int fd, uint16_t addr) +p5_inb (int fd, uint16_t addr) { #ifdef HAVE_LINUX_PPDEV_H uint8_t val = 0xff; @@ -84,7 +84,7 @@ inb (int fd, uint16_t addr) rc = read (fd, &val, 1); break; default: - DBG (DBG_error, "inb(%s) escaped ppdev\n", addr_name (addr)); + DBG (DBG_error, "p5_inb(%s) escaped ppdev\n", addr_name (addr)); return 0xFF; } if (rc < 0) @@ -100,7 +100,7 @@ inb (int fd, uint16_t addr) } static void -outb (int fd, uint16_t addr, uint8_t value) +p5_outb (int fd, uint16_t addr, uint8_t value) { #ifdef HAVE_LINUX_PPDEV_H int rc = 0, mode = 0xff; @@ -134,7 +134,7 @@ outb (int fd, uint16_t addr, uint8_t value) rc = write (fd, &value, 1); break; default: - DBG (DBG_error, "outb(%s,0x%02x) escaped ppdev\n", addr_name (addr), + DBG (DBG_error, "p5_outb(%s,0x%02x) escaped ppdev\n", addr_name (addr), value); break; } @@ -157,8 +157,8 @@ write_reg (int fd, uint8_t index, uint8_t value) idx = index & 0x0F; DBG (DBG_io2, "write_reg(REG%X,0x%x)\n", idx, value); idx = idx << 4 | idx; - outb (fd, EPPADR, idx); - outb (fd, EPPDATA, value); + p5_outb (fd, EPPADR, idx); + p5_outb (fd, EPPDATA, value); } static uint8_t @@ -169,8 +169,8 @@ read_reg (int fd, uint8_t index) /* both nibbles hold the same value */ idx = index & 0x0F; idx = idx << 4 | idx; - outb (fd, EPPADR, idx); - return inb (fd, EPPDATA); + p5_outb (fd, EPPADR, idx); + return p5_inb (fd, EPPDATA); } #ifdef HAVE_LINUX_PPDEV_H @@ -311,7 +311,7 @@ memtest (int fd, uint16_t addr) } -#define INB(k,y,z) val=inb(k,y); if(val!=z) { DBG(DBG_error,"expected 0x%02x, got 0x%02x\n",z, val); return SANE_FALSE; } +#define P5_INB(k,y,z) val=p5_inb(k,y); if(val!=z) { DBG(DBG_error,"expected 0x%02x, got 0x%02x\n",z, val); return SANE_FALSE; } /** @brief connect to scanner * This function sends the connect sequence for the scanner. @@ -323,66 +323,66 @@ connect (int fd) { uint8_t val; - inb (fd, CONTROL); - outb (fd, CONTROL, 0x04); - outb (fd, DATA, 0x02); - INB (fd, DATA, 0x02); - outb (fd, DATA, 0x03); - INB (fd, DATA, 0x03); - outb (fd, DATA, 0x03); - outb (fd, DATA, 0x83); - outb (fd, DATA, 0x03); - outb (fd, DATA, 0x83); - INB (fd, DATA, 0x83); - outb (fd, DATA, 0x82); - INB (fd, DATA, 0x82); - outb (fd, DATA, 0x02); - outb (fd, DATA, 0x82); - outb (fd, DATA, 0x02); - outb (fd, DATA, 0x82); - INB (fd, DATA, 0x82); - outb (fd, DATA, 0x82); - INB (fd, DATA, 0x82); - outb (fd, DATA, 0x02); - outb (fd, DATA, 0x82); - outb (fd, DATA, 0x02); - outb (fd, DATA, 0x82); - INB (fd, DATA, 0x82); - outb (fd, DATA, 0x83); - INB (fd, DATA, 0x83); - outb (fd, DATA, 0x03); - outb (fd, DATA, 0x83); - outb (fd, DATA, 0x03); - outb (fd, DATA, 0x83); - INB (fd, DATA, 0x83); - outb (fd, DATA, 0x82); - INB (fd, DATA, 0x82); - outb (fd, DATA, 0x02); - outb (fd, DATA, 0x82); - outb (fd, DATA, 0x02); - outb (fd, DATA, 0x82); - INB (fd, DATA, 0x82); - outb (fd, DATA, 0x83); - INB (fd, DATA, 0x83); - outb (fd, DATA, 0x03); - outb (fd, DATA, 0x83); - outb (fd, DATA, 0x03); - outb (fd, DATA, 0x83); - INB (fd, DATA, 0x83); - outb (fd, DATA, 0x83); - INB (fd, DATA, 0x83); - outb (fd, DATA, 0x03); - outb (fd, DATA, 0x83); - outb (fd, DATA, 0x03); - outb (fd, DATA, 0x83); - INB (fd, DATA, 0x83); - outb (fd, DATA, 0x82); - INB (fd, DATA, 0x82); - outb (fd, DATA, 0x02); - outb (fd, DATA, 0x82); - outb (fd, DATA, 0x02); - outb (fd, DATA, 0x82); - outb (fd, DATA, 0xFF); + p5_inb (fd, CONTROL); + p5_outb (fd, CONTROL, 0x04); + p5_outb (fd, DATA, 0x02); + P5_INB (fd, DATA, 0x02); + p5_outb (fd, DATA, 0x03); + P5_INB (fd, DATA, 0x03); + p5_outb (fd, DATA, 0x03); + p5_outb (fd, DATA, 0x83); + p5_outb (fd, DATA, 0x03); + p5_outb (fd, DATA, 0x83); + P5_INB (fd, DATA, 0x83); + p5_outb (fd, DATA, 0x82); + P5_INB (fd, DATA, 0x82); + p5_outb (fd, DATA, 0x02); + p5_outb (fd, DATA, 0x82); + p5_outb (fd, DATA, 0x02); + p5_outb (fd, DATA, 0x82); + P5_INB (fd, DATA, 0x82); + p5_outb (fd, DATA, 0x82); + P5_INB (fd, DATA, 0x82); + p5_outb (fd, DATA, 0x02); + p5_outb (fd, DATA, 0x82); + p5_outb (fd, DATA, 0x02); + p5_outb (fd, DATA, 0x82); + P5_INB (fd, DATA, 0x82); + p5_outb (fd, DATA, 0x83); + P5_INB (fd, DATA, 0x83); + p5_outb (fd, DATA, 0x03); + p5_outb (fd, DATA, 0x83); + p5_outb (fd, DATA, 0x03); + p5_outb (fd, DATA, 0x83); + P5_INB (fd, DATA, 0x83); + p5_outb (fd, DATA, 0x82); + P5_INB (fd, DATA, 0x82); + p5_outb (fd, DATA, 0x02); + p5_outb (fd, DATA, 0x82); + p5_outb (fd, DATA, 0x02); + p5_outb (fd, DATA, 0x82); + P5_INB (fd, DATA, 0x82); + p5_outb (fd, DATA, 0x83); + P5_INB (fd, DATA, 0x83); + p5_outb (fd, DATA, 0x03); + p5_outb (fd, DATA, 0x83); + p5_outb (fd, DATA, 0x03); + p5_outb (fd, DATA, 0x83); + P5_INB (fd, DATA, 0x83); + p5_outb (fd, DATA, 0x83); + P5_INB (fd, DATA, 0x83); + p5_outb (fd, DATA, 0x03); + p5_outb (fd, DATA, 0x83); + p5_outb (fd, DATA, 0x03); + p5_outb (fd, DATA, 0x83); + P5_INB (fd, DATA, 0x83); + p5_outb (fd, DATA, 0x82); + P5_INB (fd, DATA, 0x82); + p5_outb (fd, DATA, 0x02); + p5_outb (fd, DATA, 0x82); + p5_outb (fd, DATA, 0x02); + p5_outb (fd, DATA, 0x82); + p5_outb (fd, DATA, 0xFF); DBG (DBG_info, "connect() OK...\n"); return SANE_TRUE; } @@ -392,60 +392,60 @@ disconnect (int fd) { uint8_t val; - outb (fd, CONTROL, 0x04); - outb (fd, DATA, 0x00); - INB (fd, DATA, 0x00); - outb (fd, DATA, 0x01); - INB (fd, DATA, 0x01); - outb (fd, DATA, 0x01); - outb (fd, DATA, 0x81); - outb (fd, DATA, 0x01); - outb (fd, DATA, 0x81); - INB (fd, DATA, 0x81); - outb (fd, DATA, 0x80); - INB (fd, DATA, 0x80); - outb (fd, DATA, 0x00); - outb (fd, DATA, 0x80); - outb (fd, DATA, 0x00); - outb (fd, DATA, 0x80); - INB (fd, DATA, 0x80); - outb (fd, DATA, 0x80); - INB (fd, DATA, 0x80); - outb (fd, DATA, 0x00); - outb (fd, DATA, 0x80); - outb (fd, DATA, 0x00); - outb (fd, DATA, 0x80); - INB (fd, DATA, 0x80); - outb (fd, DATA, 0x81); - INB (fd, DATA, 0x81); - outb (fd, DATA, 0x01); - outb (fd, DATA, 0x81); - outb (fd, DATA, 0x01); - outb (fd, DATA, 0x81); - INB (fd, DATA, 0x81); - outb (fd, DATA, 0x80); - INB (fd, DATA, 0x80); - outb (fd, DATA, 0x00); - outb (fd, DATA, 0x80); - outb (fd, DATA, 0x00); - outb (fd, DATA, 0x80); - INB (fd, DATA, 0x80); - outb (fd, DATA, 0x00); - outb (fd, DATA, 0x80); - outb (fd, DATA, 0x00); - outb (fd, DATA, 0x80); - INB (fd, DATA, 0x80); - outb (fd, DATA, 0x00); - outb (fd, DATA, 0x80); - outb (fd, DATA, 0x00); - outb (fd, DATA, 0x80); - INB (fd, DATA, 0x80); - outb (fd, DATA, 0x00); - outb (fd, DATA, 0x80); - outb (fd, DATA, 0x00); - outb (fd, DATA, 0x80); - inb (fd, CONTROL); - outb (fd, CONTROL, 0x0C); + p5_outb (fd, CONTROL, 0x04); + p5_outb (fd, DATA, 0x00); + P5_INB (fd, DATA, 0x00); + p5_outb (fd, DATA, 0x01); + P5_INB (fd, DATA, 0x01); + p5_outb (fd, DATA, 0x01); + p5_outb (fd, DATA, 0x81); + p5_outb (fd, DATA, 0x01); + p5_outb (fd, DATA, 0x81); + P5_INB (fd, DATA, 0x81); + p5_outb (fd, DATA, 0x80); + P5_INB (fd, DATA, 0x80); + p5_outb (fd, DATA, 0x00); + p5_outb (fd, DATA, 0x80); + p5_outb (fd, DATA, 0x00); + p5_outb (fd, DATA, 0x80); + P5_INB (fd, DATA, 0x80); + p5_outb (fd, DATA, 0x80); + P5_INB (fd, DATA, 0x80); + p5_outb (fd, DATA, 0x00); + p5_outb (fd, DATA, 0x80); + p5_outb (fd, DATA, 0x00); + p5_outb (fd, DATA, 0x80); + P5_INB (fd, DATA, 0x80); + p5_outb (fd, DATA, 0x81); + P5_INB (fd, DATA, 0x81); + p5_outb (fd, DATA, 0x01); + p5_outb (fd, DATA, 0x81); + p5_outb (fd, DATA, 0x01); + p5_outb (fd, DATA, 0x81); + P5_INB (fd, DATA, 0x81); + p5_outb (fd, DATA, 0x80); + P5_INB (fd, DATA, 0x80); + p5_outb (fd, DATA, 0x00); + p5_outb (fd, DATA, 0x80); + p5_outb (fd, DATA, 0x00); + p5_outb (fd, DATA, 0x80); + P5_INB (fd, DATA, 0x80); + p5_outb (fd, DATA, 0x00); + p5_outb (fd, DATA, 0x80); + p5_outb (fd, DATA, 0x00); + p5_outb (fd, DATA, 0x80); + P5_INB (fd, DATA, 0x80); + p5_outb (fd, DATA, 0x00); + p5_outb (fd, DATA, 0x80); + p5_outb (fd, DATA, 0x00); + p5_outb (fd, DATA, 0x80); + P5_INB (fd, DATA, 0x80); + p5_outb (fd, DATA, 0x00); + p5_outb (fd, DATA, 0x80); + p5_outb (fd, DATA, 0x00); + p5_outb (fd, DATA, 0x80); + p5_inb (fd, CONTROL); + p5_outb (fd, CONTROL, 0x0C); return SANE_STATUS_GOOD; } @@ -1018,7 +1018,7 @@ wait_document (int fd, uint8_t detector) write_reg (fd, REG2, 0x90); write_reg (fd, REGF, 0x82); write_reg (fd, REG0, 0x00); - val = inb (fd, STATUS) & 0xf8; + val = p5_inb (fd, STATUS) & 0xf8; if (val != 0xf8) { DBG (DBG_error, "wait_document: unexpected STATUS value 0x%02x instead of 0xf8", val); diff --git a/backend/pie-scsidef.h b/backend/pie-scsidef.h index 05aa18f..9563452 100644 --- a/backend/pie-scsidef.h +++ b/backend/pie-scsidef.h @@ -189,9 +189,12 @@ static scsiblk inquiry = { inquiryC, sizeof(inquiryC) }; #define get_inquiry_additional_length(in) in[0x04] #define set_inquiry_length(out,n) out[0x04]=n-5 -#define get_inquiry_vendor(in, buf) strncpy(buf, in + 0x08, 0x08) -#define get_inquiry_product(in, buf) strncpy(buf, in + 0x10, 0x010) -#define get_inquiry_version(in, buf) strncpy(buf, in + 0x20, 0x04) +#define get_inquiry_vendor(in, buf) snprintf(buf, 0x08 + 1, "%.*s", \ + 0x08, in + 0x08) +#define get_inquiry_product(in, buf) snprintf(buf, 0x10 + 1, "%.*s", \ + 0x10, in + 0x10) +#define get_inquiry_version(in, buf) snprintf(buf, 0x04 + 1, "%.*s", \ + 0x04, in + 0x20) #define get_inquiry_max_x_res(in) getnbyte1(in + 0x24, 2) #define get_inquiry_max_y_res(in) getnbyte1(in + 0x26, 2) diff --git a/backend/pie.c b/backend/pie.c index 2db90dc..bfa68f0 100644 --- a/backend/pie.c +++ b/backend/pie.c @@ -744,11 +744,8 @@ pie_get_inquiry_values (Pie_Device * dev, unsigned char *buffer) dev->inquiry_len = get_inquiry_additional_length (buffer) + 5;
get_inquiry_vendor ((char *) buffer, dev->vendor);
- dev->vendor[8] = '\0';
get_inquiry_product ((char *) buffer, dev->product);
- dev->product[16] = '\0';
get_inquiry_version ((char *) buffer, dev->version);
- dev->version[4] = '\0';
dev->inquiry_x_res = get_inquiry_max_x_res (buffer);
dev->inquiry_y_res = get_inquiry_max_y_res (buffer);
diff --git a/backend/pieusb.c b/backend/pieusb.c index f8dc073..ec787d1 100644 --- a/backend/pieusb.c +++ b/backend/pieusb.c @@ -1436,7 +1436,7 @@ SANE_Status sane_get_select_fd (SANE_Handle handle, SANE_Int * fd) { DBG(DBG_info_sane,"sane_get_select_fd(): not supported (only for non-blocking IO)\n"); - handle = handle; - fd = fd; + (void) handle; + (void) fd; return SANE_STATUS_UNSUPPORTED; } diff --git a/backend/pieusb_scancmd.c b/backend/pieusb_scancmd.c index 583c4ac..3ed4f03 100644 --- a/backend/pieusb_scancmd.c +++ b/backend/pieusb_scancmd.c @@ -205,7 +205,8 @@ sanei_pieusb_cmd_test_unit_ready(SANE_Int device_number, struct Pieusb_Command_S status->pieusb_status = sanei_pieusb_command (device_number, command, NULL, 0); - DBG (DBG_info_scan, "sanei_pieusb_cmd_test_unit_ready() return status = %s\n", sane_strstatus(status->pieusb_status)); + DBG (DBG_info_scan, "sanei_pieusb_cmd_test_unit_ready() return status = %s\n", + sane_strstatus (sanei_pieusb_convert_status (status->pieusb_status))); } /** diff --git a/backend/pieusb_specific.c b/backend/pieusb_specific.c index e5471ee..f319278 100644 --- a/backend/pieusb_specific.c +++ b/backend/pieusb_specific.c @@ -260,7 +260,7 @@ sanei_pieusb_find_device_callback (const char *devicename) free (dev); DBG (DBG_error, "sanei_pieusb_find_device_callback: get scanner properties (5 bytes) failed with %d\n", status.pieusb_status); sanei_usb_close (device_number); - return status.pieusb_status; + return sanei_pieusb_convert_status (status.pieusb_status); } /* get full inquiry data */ sanei_pieusb_cmd_inquiry(device_number, &inq, inq.additionalLength+4, &status); @@ -268,7 +268,7 @@ sanei_pieusb_find_device_callback (const char *devicename) free (dev); DBG (DBG_error, "sanei_pieusb_find_device_callback: get scanner properties failed\n"); sanei_usb_close (device_number); - return status.pieusb_status; + return sanei_pieusb_convert_status (status.pieusb_status); } /* Close the device again */ @@ -1781,7 +1781,7 @@ sanei_pieusb_set_frame_from_options(Pieusb_Scanner * scanner) scanner->frame.index = 0x80; /* 0x80: value from cyberview */ sanei_pieusb_cmd_set_scan_frame (scanner->device_number, scanner->frame.index, &(scanner->frame), &status); DBG (DBG_info_sane, "sanei_pieusb_set_frame_from_options(): sanei_pieusb_cmd_set_scan_frame status %s\n", sane_strstatus (sanei_pieusb_convert_status (status.pieusb_status))); - return status.pieusb_status; + return sanei_pieusb_convert_status (status.pieusb_status); } /* diff --git a/backend/pixma/pixma.c b/backend/pixma/pixma.c index 31e71f0..72385b2 100644 --- a/backend/pixma/pixma.c +++ b/backend/pixma/pixma.c @@ -899,7 +899,7 @@ print_scan_param (int level, const pixma_scan_param_t * sp) pixma_dbg (level, " dpi=%ux%u offset=(%u,%u) dimension=%ux%u\n", sp->xdpi, sp->ydpi, sp->x, sp->y, sp->w, sp->h); pixma_dbg (level, " gamma=%f gamma_table=%p source=%d\n", sp->gamma, - sp->gamma_table, sp->source); + (void *) sp->gamma_table, sp->source); pixma_dbg (level, " adf-wait=%d\n", sp->adf_wait); } #endif diff --git a/backend/pixma/pixma_bjnp.c b/backend/pixma/pixma_bjnp.c index 63dd56d..75ad658 100644 --- a/backend/pixma/pixma_bjnp.c +++ b/backend/pixma/pixma_bjnp.c @@ -994,7 +994,7 @@ prepare_socket(const char *if_name, const bjnp_sockaddr_t *local_sa, /* send broadcasts to the broadcast address of the interface */ - memcpy(dest_sa, broadcast_sa, sa_size(dest_sa) ); + memcpy(dest_sa, broadcast_sa, sa_size(broadcast_sa) ); /* we fill port when we send the broadcast */ dest_sa -> ipv4.sin_port = htons(0); diff --git a/backend/pixma/pixma_common.c b/backend/pixma/pixma_common.c index 24912b8..f626db1 100644 --- a/backend/pixma/pixma_common.c +++ b/backend/pixma/pixma_common.c @@ -877,7 +877,7 @@ pixma_scan (pixma_t * s, pixma_scan_param_t * sp) sp->line_size, sp->image_size, sp->channels, sp->depth); pixma_dbg (3, " dpi=%ux%u offset=(%u,%u) dimension=%ux%u\n", sp->xdpi, sp->ydpi, sp->x, sp->y, sp->w, sp->h); - pixma_dbg (3, " gamma=%f gamma_table=%p source=%d\n", sp->gamma, sp->gamma_table, sp->source); + pixma_dbg (3, " gamma=%f gamma_table=%p source=%d\n", sp->gamma, (void *) sp->gamma_table, sp->source); pixma_dbg (3, " threshold=%d threshold_curve=%d\n", sp->threshold, sp->threshold_curve); pixma_dbg (3, " adf-wait=%d\n", sp->adf_wait); pixma_dbg (3, " ADF page count: %d\n", sp->adf_pageid); diff --git a/backend/pixma/pixma_imageclass.c b/backend/pixma/pixma_imageclass.c index ae06180..6a485de 100644 --- a/backend/pixma/pixma_imageclass.c +++ b/backend/pixma/pixma_imageclass.c @@ -77,6 +77,7 @@ #define D420_PID 0x26ef #define MF3200_PID 0x2684 #define MF6500_PID 0x2686 +#define IR1018_PID 0x269d /* generation 2 scanners (>=0x2707) */ #define MF8300_PID 0x2708 #define MF4500_PID 0x2736 @@ -88,8 +89,6 @@ #define MF4700_PID 0x2774 #define MF8200_PID 0x2779 /* the following are all untested */ -#define MF5630_PID 0x264e -#define MF5650_PID 0x264f #define MF8100_PID 0x2659 #define MF5880_PID 0x26f9 #define MF6680_PID 0x26fa @@ -243,6 +242,7 @@ activate (pixma_t * s, uint8_t x) case MF4360_PID: case MF4100_PID: case MF8300_PID: + case IR1018_PID: return iclass_exec (s, &mf->cb, 1); break; default: @@ -275,6 +275,7 @@ select_source (pixma_t * s) case MF4360_PID: case MF4100_PID: case MF8300_PID: + case IR1018_PID: return iclass_exec (s, &mf->cb, 0); break; default: @@ -310,6 +311,7 @@ send_scan_param (pixma_t * s) case MF4360_PID: case MF4100_PID: case MF8300_PID: + case IR1018_PID: return iclass_exec (s, &mf->cb, 0); break; default: @@ -336,7 +338,8 @@ request_image_block (pixma_t * s, unsigned flag, uint8_t * info, expected_len = (mf->generation >= 2 || s->cfg->pid == MF4600_PID || s->cfg->pid == MF6500_PID || - s->cfg->pid == MF8030_PID) ? 512 : hlen; + s->cfg->pid == MF8030_PID || + s->cfg->pid == IR1018_PID) ? 512 : hlen; mf->cb.reslen = pixma_cmd_transaction (s, mf->cb.buf, 11, mf->cb.buf, expected_len); if (mf->cb.reslen >= hlen) { @@ -347,7 +350,8 @@ request_image_block (pixma_t * s, unsigned flag, uint8_t * info, if (mf->generation >= 2 || s->cfg->pid == MF4600_PID || s->cfg->pid == MF6500_PID || - s->cfg->pid == MF8030_PID) + s->cfg->pid == MF8030_PID || + s->cfg->pid == IR1018_PID) { /* 32bit size */ *datalen = mf->cb.reslen - hlen; *size = (*datalen + hlen == 512) ? pixma_get_be32 (mf->cb.buf + 4) - *datalen : *size; @@ -372,7 +376,8 @@ read_image_block (pixma_t * s, uint8_t * data, unsigned size) maxchunksize = MAX_CHUNK_SIZE * ((mf->generation >= 2 || s->cfg->pid == MF4600_PID || s->cfg->pid == MF6500_PID || - s->cfg->pid == MF8030_PID) ? 4 : 1); + s->cfg->pid == MF8030_PID || + s->cfg->pid == IR1018_PID) ? 4 : 1); while (size) { if (size >= maxchunksize) @@ -410,6 +415,7 @@ read_error_info (pixma_t * s, void *buf, unsigned size) case MF4360_PID: case MF4100_PID: case MF8300_PID: + case IR1018_PID: error = iclass_exec (s, &mf->cb, 0); break; default: @@ -790,7 +796,8 @@ iclass_fill_buffer (pixma_t * s, pixma_imagebuf_t * ib) mf->generation == 1 && s->cfg->pid != MF4600_PID && s->cfg->pid != MF6500_PID && - s->cfg->pid != MF8030_PID) + s->cfg->pid != MF8030_PID && + s->cfg->pid != IR1018_PID) { /* color and not MF46xx or MF65xx */ pack_rgb (mf->blkptr, n, mf->raw_width, mf->lineptr); @@ -948,14 +955,14 @@ const pixma_config_t pixma_iclass_devices[] = { DEV ("Canon i-SENSYS MF8200C Series", "MF8200C", MF8200_PID, 600, 300, 640, 1050, PIXMA_CAP_ADF), DEV ("Canon i-SENSYS MF8300 Series", "MF8300", MF8300_PID, 600, 0, 640, 1050, PIXMA_CAP_ADF), DEV ("Canon imageCLASS D530", "D530", D530_PID, 600, 0, 640, 877, 0), + DEV ("Canon imageRUNNER 1018/1022/1023", "iR1018/1022/1023", IR1018_PID, 600, 0, 640, 877, PIXMA_CAP_ADFDUP), /* FIXME: the following capabilities all need updating/verifying */ - DEV ("Canon imageCLASS MF5630", "MF5630", MF5630_PID, 600, 0, 640, 877, PIXMA_CAP_ADF), - DEV ("Canon laserBase MF5650", "MF5650", MF5650_PID, 600, 0, 640, 877, PIXMA_CAP_ADF), DEV ("Canon imageCLASS MF8170c", "MF8170c", MF8100_PID, 600, 0, 640, 877, PIXMA_CAP_ADF), DEV ("Canon imageClass MF8030", "MF8030", MF8030_PID, 600, 0, 640, 877, PIXMA_CAP_ADF), DEV ("Canon i-SENSYS MF5880dn", "MF5880", MF5880_PID, 600, 0, 640, 877, PIXMA_CAP_ADFDUP), DEV ("Canon i-SENSYS MF6680dn", "MF6680", MF6680_PID, 600, 0, 640, 877, PIXMA_CAP_ADFDUP), DEV ("Canon imageRUNNER 1133", "iR1133", IR1133_PID, 600, 0, 637, 877, PIXMA_CAP_ADFDUP), /* max. w = 216mm */ + DEV ("Canon imageRUNNER 1133A", "imageRUNNER1133", IR1133_PID, 600, 0, 637, 877, PIXMA_CAP_ADFDUP), /* max. w = 216mm */ DEV ("Canon i-SENSYS MF5900 Series", "MF5900", MF5900_PID, 600, 0, 640, 1050, PIXMA_CAP_ADFDUP), DEV ("Canon i-SENSYS MF8500C Series", "MF8500C", MF8500_PID, 600, 0, 640, 1050, PIXMA_CAP_ADFDUP), DEV ("Canon i-SENSYS MF6100 Series", "MF6100", MF6100_PID, 600, 300, 640, 1050, PIXMA_CAP_ADFDUP), diff --git a/backend/pixma/pixma_mp150.c b/backend/pixma/pixma_mp150.c index f3d5934..171eccf 100644 --- a/backend/pixma/pixma_mp150.c +++ b/backend/pixma/pixma_mp150.c @@ -230,7 +230,7 @@ #define G3000_PID 0x1794 #define G2000_PID 0x1795 #define TS9000_PID 0x179f -#define TS8000_PID 0x1800 +#define TS8000_PID 0x1800 /* tested: TS8030 */ #define TS6000_PID 0x1801 #define TS5000_PID 0x1802 #define MG3000_PID 0x180b @@ -308,7 +308,7 @@ #define G2060_PID 0x18C1 #define G3020_PID 0x18BF #define TS7430_PID 0x18B2 -#define XK90_PID 0x18B6 +#define XK90_PID 0x18B6 /* tested */ #define TS8430_PID 0x18B5 #define TR7600_PID 0x18AA #define TR8600_PID 0x18AD @@ -316,6 +316,27 @@ #define TS6400_PID 0x18D3 #define TS7400_PID 0x18D7 +/* 2021 new device (untested) */ +#define TS5350i_PID 0x18D9 +#define G600_PID 0x18D5 +#define TS3500_PID 0x18D4 +#define TR4600_PID 0x18DA +#define E4500_PID 0x18DB +#define TR4700_PID 0x18DC +#define XK500_PID 0x18DF +#define TS8530_PID 0x18E0 +#define XK100_PID 0x18E2 +#define TS7530_PID 0x18E1 +#define TS7450i_PID 0x18F7 +#define GX6000_PID 0x18A6 +#define GX7000_PID 0x18A8 +#define TS5400_PID 0x18D8 + +/* 2022 new device (untested) */ +#define TS2400_PID 0x1108 +#define TS2600_PID 0x1107 + + /* Generation 4 XML messages that encapsulates the Pixma protocol messages */ #define XML_START_1 \ "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\ @@ -693,7 +714,7 @@ send_scan_param (pixma_t * s) if (mp->generation <= 2) { - PDBG (pixma_dbg (4, "*send_scan_param gen. 1-2 ***** Setting: xdpi=%hi ydpi=%hi x=%i y=%i wx=%i ***** \n", + PDBG (pixma_dbg (4, "*send_scan_param gen. 1-2 ***** Setting: xdpi=%u ydpi=%u x=%i y=%i wx=%i ***** \n", xdpi, ydpi, x-xs, y, wx)); data = pixma_newcmd (&mp->cb, cmd_scan_param, 0x30, 0); pixma_set_be16 (xdpi | 0x8000, data + 0x04); @@ -715,7 +736,7 @@ send_scan_param (pixma_t * s) } else { - PDBG (pixma_dbg (4, "*send_scan_param gen. 3+ ***** Setting: xdpi=%hi ydpi=%hi x=%i xs=%i y=%i wx=%i h=%i ***** \n", + PDBG (pixma_dbg (4, "*send_scan_param gen. 3+ ***** Setting: xdpi=%u ydpi=%u x=%i xs=%i y=%i wx=%i h=%i ***** \n", xdpi, ydpi, x, xs, y, wx, h)); data = pixma_newcmd (&mp->cb, cmd_scan_param_3, 0x38, 0); data[0x00] = (is_scanning_from_adf (s)) ? 0x02 : 0x01; @@ -929,6 +950,7 @@ handle_interrupt (pixma_t * s, int timeout) * poll event with 'scanimage -A' */ if (s->cfg->pid == MG5300_PID || s->cfg->pid == MG5400_PID + || s->cfg->pid == MG5700_PID || s->cfg->pid == MG6200_PID || s->cfg->pid == MG6300_PID || s->cfg->pid == MX340_PID @@ -1147,7 +1169,7 @@ post_process_image_data (pixma_t * s, pixma_imagebuf_t * ib) n = s->param->xdpi / 600; else n = s->param->xdpi / 2400; - if (s->cfg->pid == MP600_PID || s->cfg->pid == MP600R_PID) + if (s->cfg->pid == MP600_PID || s->cfg->pid == MP600R_PID || s->cfg->pid == XK90_PID) n = s->param->xdpi / 1200; m = (n > 0) ? s->param->wx / n : 1; @@ -1188,6 +1210,7 @@ post_process_image_data (pixma_t * s, pixma_imagebuf_t * ib) || s->cfg->pid == MP230_PID || s->cfg->pid == MX470_PID || s->cfg->pid == MX510_PID + || s->cfg->pid == XK90_PID || s->cfg->pid == MX520_PID)) reorder_pixels (mp->linebuf, sptr, c, n, m, s->param->wx, line_size); @@ -1641,7 +1664,7 @@ mp150_finish_scan (pixma_t * s) else PDBG (pixma_dbg (4, "*mp150_finish_scan***** wait for next page from ADF *****\n")); - mp->state = state_idle; + mp->state = state_idle; /* fall through */ case state_idle: break; @@ -1906,9 +1929,9 @@ const pixma_config_t pixma_mp150_devices[] = { DEVICE ("Canon PIXMA TS8330 Series", "TS8330", TS8330_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), DEVICE ("Canon PIXMA XK60 Series", "XK60", XK60_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), DEVICE ("Canon PIXMA TS6330 Series", "TS6330", TS6330_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), - DEVICE ("Canon PIXMA TS3300 Series", "TS3300", TS3300_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), + DEVICE ("Canon PIXMA TS3300 Series", "TS3300", TS3300_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS), DEVICE ("Canon PIXMA E3300 Series", "E3300", E3300_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS), - DEVICE ("Canon PIXMA TS3400 Series", "TS3400", TS3400_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), + DEVICE ("Canon PIXMA TS3400 Series", "TS3400", TS3400_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS), DEVICE ("Canon PIXMA E3400 Series", "E3400", E3400_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF), DEVICE ("Canon PIXMA TR7000 Series", "TR7000", TR7000_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF), DEVICE ("Canon PIXMA G2020", "G2020", G2020_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS), @@ -1923,8 +1946,26 @@ const pixma_config_t pixma_mp150_devices[] = { DEVICE ("Canon PIXMA TR8630 Series", "TR8630", TR8630_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF), DEVICE ("Canon PIXMA TS6400 Series", "TS6400", TS6400_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), DEVICE ("Canon PIXMA TS7400 Series", "TS7400", TS7400_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), - DEVICE ("Canon PIXMA G7080 Series", "G7080", G7080_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS), - DEVICE ("Canon PIXMA GM4080", "GM4080", GM4080_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF), + DEVICE ("Canon PIXMA G7080 Series", "G7080", G7080_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), + DEVICE ("Canon PIXMA GM4080", "GM4080", GM4080_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF), + DEVICE ("Canon PIXMA TS5350i Series", "TS5350i", TS5350i_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), + DEVICE ("Canon PIXMA G600", "G600", G600_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS), + DEVICE ("Canon PIXMA TS3500 Series", "TS3500", TS3500_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS), + /* ToDo: max. scan resolution = 600x1200dpi */ + DEVICE ("Canon PIXMA TR4600 Series", "TR4600", TR4600_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF | PIXMA_CAP_ADF_JPEG), + /* ToDo: max. scan resolution = 600x1200dpi */ + DEVICE ("Canon PIXMA TR4700 Series", "TR4700", TR4700_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF | PIXMA_CAP_ADF_JPEG), + DEVICE ("Canon PIXMA E4500 Series", "E4500", E4500_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS), + DEVICE ("Canon PIXUS XK500 Series", "XK500", XK500_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), + DEVICE ("Canon PIXMA TS8530 Series", "TS8530", TS8530_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), + DEVICE ("Canon PIXUS XK100 Series", "XK100", XK100_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), + DEVICE ("Canon PIXMA TS7530 Series", "TS7530", TS7530_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), + DEVICE ("Canon PIXMA TS7450i Series", "TS7450i", TS7450i_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), + DEVICE ("Canon PIXMA GX6000 Series", "GX6000", GX6000_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF), + DEVICE ("Canon PIXMA GX7000 Series", "GX7000", GX7000_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF), + DEVICE ("Canon PIXMA TS5400 Series", "TS5400", TS5400_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), + DEVICE ("Canon PIXMA TS2400 Series", "TS2400", TS2400_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS), + DEVICE ("Canon PIXMA TS2600 Series", "TS2600", TS2600_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS), END_OF_DEVICE_LIST }; diff --git a/backend/pixma/pixma_mp730.c b/backend/pixma/pixma_mp730.c index 3a436d7..1fc9a74 100644 --- a/backend/pixma/pixma_mp730.c +++ b/backend/pixma/pixma_mp730.c @@ -76,6 +76,8 @@ #define MP740_PID 0x264c /* Untested */ #define MP710_PID 0x264d +#define MF5630_PID 0x264e /* Untested */ +#define MF5650_PID 0x264f #define MF5730_PID 0x265d /* Untested */ #define MF5750_PID 0x265e /* Untested */ #define MF5770_PID 0x265f @@ -318,6 +320,8 @@ handle_interrupt (pixma_t * s, int timeout) case MP370_PID: case MP375R_PID: case MP390_PID: + case MF5630_PID: + case MF5650_PID: case MF5730_PID: case MF5750_PID: case MF5770_PID: @@ -372,6 +376,8 @@ has_ccd_sensor (pixma_t * s) s->cfg->pid == MP370_PID || s->cfg->pid == MP375R_PID || s->cfg->pid == MP390_PID || + s->cfg->pid == MF5630_PID || + s->cfg->pid == MF5650_PID || s->cfg->pid == MF5730_PID || s->cfg->pid == MF5750_PID || s->cfg->pid == MF5770_PID); @@ -415,6 +421,8 @@ step1 (pixma_t * s) { switch (s->cfg->pid) { + case MF5630_PID: + case MF5650_PID: case MF5730_PID: case MF5750_PID: case MF5770_PID: @@ -424,10 +432,10 @@ step1 (pixma_t * s) int tmo = 10; /* like Windows driver, 10 sec CCD calibration ? */ while (--tmo >= 0) { - error = handle_interrupt (s, 1000); \ - if (s->cancel) \ - return PIXMA_ECANCELED; \ - if (error != PIXMA_ECANCELED && error < 0) \ + error = handle_interrupt (s, 1000); + if (s->cancel) + return PIXMA_ECANCELED; + if (error != PIXMA_ECANCELED && error < 0) return error; PDBG (pixma_dbg (2, "CCD Calibration ends in %d sec.\n", tmo)); } @@ -443,6 +451,8 @@ step1 (pixma_t * s) switch (s->cfg->pid) { + case MF5630_PID: + case MF5650_PID: case MF5730_PID: case MF5750_PID: case MF5770_PID: @@ -696,6 +706,8 @@ mp730_fill_buffer (pixma_t * s, pixma_imagebuf_t * ib) if (n != 0) { if (s->param->channels != 1 && + s->cfg->pid != MF5630_PID && + s->cfg->pid != MF5650_PID && s->cfg->pid != MF5730_PID && s->cfg->pid != MF5750_PID && s->cfg->pid != MF5770_PID && @@ -751,7 +763,9 @@ mp730_finish_scan (pixma_t * s) (s->param->source == PIXMA_SOURCE_ADF || s->param->source == PIXMA_SOURCE_ADFDUP) && has_paper (s) && - (s->cfg->pid == MF5730_PID || + (s->cfg->pid == MF5630_PID || + s->cfg->pid == MF5650_PID || + s->cfg->pid == MF5730_PID || s->cfg->pid == MF5750_PID || s->cfg->pid == MF5770_PID || s->cfg->pid == IR1020_PID)) @@ -833,6 +847,8 @@ const pixma_config_t pixma_mp730_devices[] = { DEVICE ("PIXMA MP730", "MP730", MP730_PID, 1200, 637, 868, PIXMA_CAP_ADF | PIXMA_CAP_LINEART), DEVICE ("PIXMA MP740", "MP740", MP740_PID, 1200, 637, 868, PIXMA_CAP_ADF | PIXMA_CAP_LINEART), + DEVICE ("Canon imageCLASS MF5630", "MF5630", MF5630_PID, 1200, 636, 868, PIXMA_CAP_ADF), + DEVICE ("Canon laserBase MF5650", "MF5650", MF5650_PID, 1200, 636, 868, PIXMA_CAP_ADF), DEVICE ("Canon imageCLASS MF5730", "MF5730", MF5730_PID, 1200, 636, 868, PIXMA_CAP_ADF), DEVICE ("Canon imageCLASS MF5750", "MF5750", MF5750_PID, 1200, 636, 868, PIXMA_CAP_ADF), DEVICE ("Canon imageCLASS MF5770", "MF5770", MF5770_PID, 1200, 636, 868, PIXMA_CAP_ADF), diff --git a/backend/plustek-pp.h b/backend/plustek-pp.h index 447065b..4c0b0f4 100644 --- a/backend/plustek-pp.h +++ b/backend/plustek-pp.h @@ -235,11 +235,7 @@ typedef const struct mode_param #define _E_SEQUENCE (_FIRST_ERR-30) /* caller sequence does not match */ #define _E_NO_ASIC (_FIRST_ERR-31) /* can't detect ASIC */ -#ifdef __KERNEL__ -# define _E_FAULT (-EFAULT) -#else # define _E_FAULT (_E_INTERNAL) /* should never happen in userspace */ -#endif #define _E_LAMP_NOT_IN_POS (_FIRST_ERR-40) #define _E_LAMP_NOT_STABLE (_FIRST_ERR-41) @@ -471,10 +467,6 @@ typedef struct { #define _ScanMode_AverageOut 1 /* CCD averaged 2 pixels value for output*/ #define _ScanMode_Mono 2 /* not color mode */ - -#ifndef __KERNEL__ - - #define PLUSTEK_CONFIG_FILE "plustek_pp.conf" #ifndef PATH_MAX @@ -631,7 +623,6 @@ typedef struct { AdjDef adj; } CnfDef, *pCnfDef; -#endif /* guard __KERNEL__ */ #endif /* guard __PLUSTEKPP_H__ */ diff --git a/backend/plustek-pp_dbg.h b/backend/plustek-pp_dbg.h index 71315bd..d416315 100644 --- a/backend/plustek-pp_dbg.h +++ b/backend/plustek-pp_dbg.h @@ -47,22 +47,11 @@ /* #define _ASIC_98001_SIM */ /* - * the print macros - */ -#ifdef __KERNEL__ -# define _PRINT printk -#endif - -/* * some debug definitions */ #ifdef DEBUG -# ifndef __KERNEL__ # include <assert.h> # define _ASSERT(x) assert(x) -# else -# define _ASSERT(x) -# endif # ifndef DBG # define DBG(level, msg, args...) if ((dbg_level) & (level)) { \ diff --git a/backend/plustek-pp_detect.c b/backend/plustek-pp_detect.c index 2cc6f1a..5099986 100644 --- a/backend/plustek-pp_detect.c +++ b/backend/plustek-pp_detect.c @@ -97,11 +97,6 @@ static int detectScannerConnection( pScanData ps ) UChar data, control, status; int retval = _E_NO_CONN; -#ifdef __KERNEL__ - DBG( DBG_LOW, "Dataport = 0x%04x\n", ps->IO.pbSppDataPort ); - DBG( DBG_LOW, "Ctrlport = 0x%04x\n", ps->IO.pbControlPort ); -#endif - detectResetPort( ps ); /* @@ -177,11 +172,7 @@ static int detectScannerConnection( pScanData ps ) /* work on the result */ if ( _OK == retval ) { -#ifdef __KERNEL__ - ps->sCaps.wIOBase = ps->IO.pbSppDataPort; -#else ps->sCaps.wIOBase = ps->pardev; -#endif ps->PutToIdleMode( ps ); } else { @@ -209,11 +200,7 @@ static int detectSetupBuffers( pScanData ps ) */ if ( 0 == ps->TotalBufferRequire ) { -#ifdef __KERNEL__ - _PRINT( -#else DBG( DBG_HIGH, -#endif "pt_drv: asic 0x%x probably not supported\n", ps->sCaps.AsicID); return _E_ALLOC; /* Out of memory */ @@ -228,11 +215,7 @@ static int detectSetupBuffers( pScanData ps ) if ( NULL == ps->driverbuf ) { -#ifdef __KERNEL__ - _PRINT( -#else DBG( DBG_HIGH, -#endif "pt_drv: Not enough kernel memory %d\n", ps->TotalBufferRequire); return _E_ALLOC; /* Out of memory */ @@ -380,11 +363,7 @@ static int detectAsic98001( pScanData ps ) return detectScannerConnection( ps ); #else -#ifdef __KERNEL__ - _PRINT( -#else DBG( DBG_HIGH, -#endif "!!!! WARNING, have a look at function detectAsic98001() !!!!\n" ); ps->sCaps.AsicID = _ASIC_IS_98001; ps->sCaps.wIOBase = ps->IO.pbSppDataPort; @@ -434,11 +413,7 @@ _LOC int DetectScanner( pScanData ps, int mode ) /* read Register 0x18 (AsicID Register) of Asic9800x based devices */ #ifdef _ASIC_98001_SIM -#ifdef __KERNEL__ - _PRINT( -#else DBG( DBG_HIGH, -#endif "!!!! WARNING, SW-Emulation active !!!!\n" ); asic = _ASIC_IS_98001; #else diff --git a/backend/plustek-pp_hwdefs.h b/backend/plustek-pp_hwdefs.h index 51599f2..7b9213e 100644 --- a/backend/plustek-pp_hwdefs.h +++ b/backend/plustek-pp_hwdefs.h @@ -586,19 +586,6 @@ typedef struct * structure to hold IO port specific stuff */ typedef struct { - -#ifdef __KERNEL__ - pFnOut fnOut; - pFnIn fnIn; - - UShort pbSppDataPort; - UShort pbEppDataPort; - - UShort pbStatusPort; - UShort pbControlPort; - UShort pbAddrOffsetPort; -#endif - UShort portBase; UShort portMode; UShort lastPortMode; diff --git a/backend/plustek-pp_image.c b/backend/plustek-pp_image.c index 63f1f88..80d213a 100644 --- a/backend/plustek-pp_image.c +++ b/backend/plustek-pp_image.c @@ -1288,11 +1288,7 @@ static Bool imageP98003ReadOneImageLine( pScanData ps ) } while( !MiscCheckTimer( &timer )); -#ifdef __KERNEL__ - _PRINT( -#else DBG( DBG_HIGH, -#endif "Timeout - Scanner malfunction !!\n" ); MotorToHomePosition(ps); diff --git a/backend/plustek-pp_io.c b/backend/plustek-pp_io.c index af3e8c4..45ffe8b 100644 --- a/backend/plustek-pp_io.c +++ b/backend/plustek-pp_io.c @@ -257,21 +257,11 @@ static Bool fnEPPRead( pScanData ps, pUChar pBuffer, ULong ulSize ) if( _IS_ASIC98(ps->sCaps.AsicID)) { -#ifndef __KERNEL__ sanei_pp_set_datadir( ps->pardev, SANEI_PP_DATAIN ); -#else - _OUTB_CTRL( ps, (_CTRL_GENSIGNAL + _CTRL_DIRECTION)); - _DO_UDELAY( 1 ); -#endif for( i = 0; i < ulSize; i++ ) pBuffer[i] = _INB_EPPDATA( ps ); -#ifndef __KERNEL__ sanei_pp_set_datadir( ps->pardev, SANEI_PP_DATAOUT ); -#else - _OUTB_CTRL( ps, _CTRL_GENSIGNAL ); - _DO_UDELAY( 1 ); -#endif } else { for( i = 0; i < ulSize; i++ ) @@ -290,18 +280,12 @@ static Bool fnBiDirRead( pScanData ps, pUChar pBuffer, ULong ulSize ) start = _CTRL_START_BIDIREAD; end = _CTRL_END_BIDIREAD; -#ifndef __KERNEL__ sanei_pp_set_datadir( ps->pardev, SANEI_PP_DATAIN ); if( !sanei_pp_uses_directio()) { start &= ~_CTRL_DIRECTION; end &= ~_CTRL_DIRECTION; } -#else - if( _IS_ASIC98(ps->sCaps.AsicID)) { - _OUTB_CTRL( ps, (_CTRL_GENSIGNAL + _CTRL_DIRECTION)); - } -#endif switch( ps->IO.delay ) { @@ -341,13 +325,7 @@ static Bool fnBiDirRead( pScanData ps, pUChar pBuffer, ULong ulSize ) } -#ifndef __KERNEL__ sanei_pp_set_datadir( ps->pardev, SANEI_PP_DATAOUT ); -#else - if( _IS_ASIC98(ps->sCaps.AsicID)) { - _OUTB_CTRL( ps, _CTRL_GENSIGNAL ); - } -#endif return _TRUE; } @@ -953,45 +931,4 @@ _LOC void IOReadScannerImageData( pScanData ps, pUChar pBuf, ULong size ) ps->OpenScanPath( ps ); } -#ifdef __KERNEL__ - -/** the wrapper functions to support delayed and non-delayed I/O - */ -_LOC void IOOut( Byte data, UShort port ) -{ - DBG( DBG_IOF, "outb(0x%04x, 0x%02x)\n", port, data ); - outb( data, port ); -} - -_LOC void IOOutDelayed( Byte data, UShort port ) -{ - DBG( DBG_IOF, "outb_p(0x%04x, 0x%02x)\n", port, data ); - outb_p( data, port ); -} - -_LOC Byte IOIn( UShort port ) -{ -#ifdef DEBUG - Byte data = inb( port ); - - DBG( DBG_IOF, "inb(0x%04x) = 0x%02x\n", port, data ); - return data; -#else - return inb( port ); -#endif -} - -_LOC Byte IOInDelayed( UShort port ) -{ -#ifdef DEBUG - Byte data = inb_p( port ); - - DBG( DBG_IOF, "inb_p(0x%04x) = 0x%02x\n", port, data ); - return data; -#else - return inb_p( port ); -#endif -} -#endif /* guard __KERNEL__ */ - /* END PLUSTEK-PP_IO.C ......................................................*/ diff --git a/backend/plustek-pp_misc.c b/backend/plustek-pp_misc.c index ec2f129..ffcfa7c 100644 --- a/backend/plustek-pp_misc.c +++ b/backend/plustek-pp_misc.c @@ -77,27 +77,11 @@ /*************************** some definitions ********************************/ -#ifndef __KERNEL__ # define PPA_PROBE_SPP 0x0001 # define PPA_PROBE_PS2 0x0002 # define PPA_PROBE_ECR 0x0010 # define PPA_PROBE_EPP17 0x0100 # define PPA_PROBE_EPP19 0x0200 -#else - -/* the parport driver in Kernel 2.4 has changed. It does report the - * possible modes in a different, more general way. As long, as - * we do not use the parport-module change mode facility, I assume - * the following correlations - */ -#if defined LINUX_24 || defined LINUX_26 -# define PARPORT_MODE_PCPS2 PARPORT_MODE_TRISTATE -# define PARPORT_MODE_PCEPP PARPORT_MODE_EPP -# define PARPORT_MODE_PCECPPS2 PARPORT_MODE_TRISTATE -# define PARPORT_MODE_PCECPEPP PARPORT_MODE_EPP -# define PARPORT_MODE_PCECR PARPORT_MODE_ECP -#endif -#endif #define _PP_A 16807 /**< multiplier */ #define _PP_M 2147483647L /**< 2**31 - 1 */ @@ -107,299 +91,10 @@ static int port_feature = 0; static long randomnum = 1; -#ifdef __KERNEL__ -static int portIsClaimed[_MAX_PTDEVS] = { [0 ... (_MAX_PTDEVS-1)] = 0 }; - -MODELSTR; /**< a static char array (see plustek-pp.h) */ - -#else static int portIsClaimed[_MAX_PTDEVS] = { 0, 0, 0, 0 }; -#endif /*************************** local functions *********************************/ -#ifdef __KERNEL__ -#ifdef LINUX_26 - -static pScanData __ps = NULL; -static int __pa = -1; - -/** callback from parport driver - */ -static void misc_attach(struct parport *port) -{ - DBG( DBG_LOW, "misc_attach\n" ); - - __ps->pp = NULL; - if( port->base == (unsigned long)__pa ) { - DBG( DBG_LOW, "Requested port (0x%02x) found\n", __pa ); - DBG( DBG_LOW, "Port mode reported: (0x%04x)\n", port->modes ); - __ps->pp = port; - } -} - -static void misc_detach( struct parport *port ) -{ - DBG( DBG_LOW, "misc_detach\n" ); -} - -static struct parport_driver pt_drv = { - .name = "pt_drv", - .attach = misc_attach, - .detach = misc_detach, -}; -#endif - -/** display the available port-modes - */ -#ifdef DEBUG -static void miscShowPortModes( int modes ) -{ - DBG( DBG_LOW, "parport-modi:" ); - - if( modes & PARPORT_MODE_PCSPP ) - DBG( DBG_LOW, " SPP" ); - - if( modes & PARPORT_MODE_PCPS2 ) - DBG( DBG_LOW, " PS/2" ); - - if( modes & PARPORT_MODE_PCEPP ) - DBG( DBG_LOW, " EPP" ); - - if( modes & PARPORT_MODE_PCECR ) - DBG( DBG_LOW, " ECP" ); - - if( modes & PARPORT_MODE_PCECPEPP ) - DBG( DBG_LOW, " EPP(ECP)" ); - - if( modes & PARPORT_MODE_PCECPPS2 ) - DBG( DBG_LOW, " PS/2(ECP)" ); - - DBG( DBG_LOW, "\n" ); -} -#endif - -/** probe the parallel port - */ -static int initPortProbe( pScanData ps ) -{ - int retv = 0; - - /* clear the controls */ - ps->IO.lastPortMode = 0xFFFF; - - if( NULL != ps->pardev ) - retv = ps->pardev->port->modes; - return retv; -} - -/** will be called by the parport module when we already have access, but - * another module wants access to the port... - */ -static int miscPreemptionCallback( pVoid data ) -{ - pScanData ps = (pScanData)data; - - if( NULL != ps ) { - - /* never release during scanning */ - if( ps->DataInf.dwScanFlag & _SCANNER_SCANNING ) { - DBG( DBG_LOW, "no way!!!\n" ); - return 1; - } - } - - /* let the port go...*/ - return 0; -} - -/** depending on the reported possible port modes, we try to set a faster mode - * than SPP - */ -static int miscSetFastMode( pScanData ps ) -{ - UChar a, b; - - /* - * when previously found the EPP mode, break right here - */ - if (( _PORT_EPP == ps->IO.portMode ) && (!(port_feature & PARPORT_MODE_PCECR))) - return _OK; - - /* CHECK REMOVE: from here we should have SPP (Paranoia Code !) */ - if (( _PORT_SPP != ps->IO.portMode ) && (!(port_feature & PARPORT_MODE_PCECR))) - return _OK; - - DBG(DBG_LOW, "Trying faster mode...\n" ); - - /* - * ECP mode usually has sub-modes of EPP and/or PS2. - * First we try to set EPP - */ - if((port_feature & PARPORT_MODE_PCECR) && - (port_feature & PARPORT_MODE_PCECPEPP)){ - - DBG(DBG_LOW, "Attempting to set EPP from ECP mode.\n" ); - - a = _INB_ECTL(ps); /* get current ECR */ - ps->IO.lastPortMode = a; /* save it for restoring later */ - a = (a & 0x1F) | 0x80; /* set to EPP */ - _OUTB_ECTL(ps, a); /* write it back */ - _DO_UDELAY(1); - - /* - * It is probably unnecessary to - * do this check but it makes me feel better - */ - b = _INB_ECTL(ps); /* check to see if port set */ - if( a == b ) { - DBG( DBG_LOW, "Port is set to (ECP) EPP mode.\n" ); - ps->IO.portMode = _PORT_EPP; - return _OK; - - } else { - DBG( DBG_LOW, "Port could not be set to (ECP) EPP mode. " - "Using SPP mode.\n" ); - _OUTB_ECTL(ps,(Byte)ps->IO.lastPortMode); /* restore */ - _DO_UDELAY(1); - ps->IO.portMode = _PORT_SPP; - - /* go ahead and try with other settings...*/ - } - } - - /* If port cannot be set to EPP, try PS2 */ - if((port_feature & PARPORT_MODE_PCECR) && - (port_feature & PARPORT_MODE_PCECPPS2)) { - - DBG(DBG_LOW, "Attempting to set PS2 from ECPPS2 mode.\n" ); - - a = _INB_ECTL(ps); /* get current ECR */ - ps->IO.lastPortMode = a; /* save it for restoring later */ - - /* set to Fast Centronics/bi-directional/PS2 */ - a = (a & 0x1F) | 0x20; - _OUTB_ECTL(ps,a); /* write it back */ - _DO_UDELAY(1); - - /* - * It is probably unnecessary to do this check - * but it makes me feel better - */ - b = _INB_ECTL(ps); /* check to see if port set */ - if (a == b) { - DBG(DBG_LOW, "Port is set to (ECP) PS2 bidirectional mode.\n"); - ps->IO.portMode = _PORT_BIDI; - return _OK; - } else { - DBG(DBG_LOW, "Port could not be set to (ECP) PS2 mode. " - "Using SPP mode.\n"); - a = ps->IO.lastPortMode & 0x1F; - _OUTB_ECTL(ps, a); /* set ECP ctrl to SPP */ - _DO_UDELAY(1); - ps->IO.portMode = _PORT_SPP; - - /* next mode, last attempt... */ - } - } - - /* - * Some BIOS/cards have only a Bi-directional/PS2 mode (no EPP). - * Make one last attempt to set to PS2 mode. - */ - if ( port_feature & PARPORT_MODE_PCPS2 ){ - - DBG(DBG_LOW, "Attempting to set PS2 mode.\n" ); - - a = _INB_CTRL(ps); /* get current setting of control register*/ - ps->IO.lastPortMode = a; /* save it for restoring later */ - a = a | 0x20; /* set bit 5 of control reg */ - _OUTB_CTRL(ps,a); /* set to Fast Centronics/bi-directional/PS2 */ - _DO_UDELAY(1); - a = 0; - - _OUTB_DATA(ps,0x55); - _DO_UDELAY(1); - if ((inb(ps->IO.portBase)) != 0x55) /* read data */ - a++; - - _OUTB_DATA(ps,0xAA); - _DO_UDELAY(1); - - if (_INB_DATA(ps) != 0xAA) /* read data */ - a++; - - if( 2 == a ) { - DBG(DBG_LOW, "Port is set to PS2 bidirectional mode.\n"); - ps->IO.portMode = _PORT_BIDI; - return _OK; - - } else { - DBG(DBG_LOW, "Port could not be set to PS2 mode. " - "Using SPP mode.\n"); - _OUTB_CTRL(ps,(Byte)ps->IO.lastPortMode); /* restore */ - _DO_UDELAY(1); - ps->IO.portMode = _PORT_SPP; - } - } - - /* reaching this point, we're back in SPP mode and there's no need - * to restore at shutdown... - */ - ps->IO.lastPortMode = 0xFFFF; - - return _OK; -} - -/** check the state of the par-port and switch to EPP-mode if possible - */ -static int miscSetPortMode( pScanData ps ) -{ - /* try to detect the port settings, SPP seems to work in any case ! */ - port_feature = initPortProbe( ps ); - -#ifdef DEBUG - miscShowPortModes( port_feature ); -#endif - - switch( ps->IO.forceMode ) { - - case 1: - DBG( DBG_LOW, "Use of SPP-mode enforced\n" ); - ps->IO.portMode = _PORT_SPP; - return _OK; - break; - - case 2: - DBG( DBG_LOW, "Use of EPP-mode enforced\n" ); - ps->IO.portMode = _PORT_EPP; - return _OK; - break; - - default: - break; - } - - if( !(port_feature & PARPORT_MODE_PCEPP)) { - - if( !(port_feature & PARPORT_MODE_PCSPP )) { - _PRINT("\nThis Port supports not the SPP- or EPP-Mode\n" ); - _PRINT("Please activate SPP-Mode, EPP-Mode or\nEPP + ECP-Mode!\n"); - return _E_NOSUPP; - } else { - DBG(DBG_LOW, "Using SPP-mode\n" ); - ps->IO.portMode = _PORT_SPP; - } - } else { - DBG(DBG_LOW, "Using EPP-mode\n" ); - ps->IO.portMode = _PORT_EPP; - } - - /* else try to set to a faster mode than SPP */ - return miscSetFastMode( ps ); -} -#endif - /** miscNextLongRand() -- generate 2**31-2 random numbers ** ** public domain by Ray Gardner @@ -488,34 +183,6 @@ _LOC int MiscReinitStruct( pScanData ps ) */ _LOC int MiscInitPorts( pScanData ps, int port ) { -#ifdef __KERNEL__ - int status; - - if( NULL == ps ) - return _E_NULLPTR; - - /* - * Get access to the ports - */ - ps->IO.portBase = (UShort)port; - - status = miscSetPortMode(ps); - - if( _OK != status ) { - ps->sCaps.wIOBase = _NO_BASE; - ps->IO.portBase = _NO_BASE; - return status; - } - - /* - * the port settings - */ - ps->IO.pbSppDataPort = (UShort)port; - ps->IO.pbStatusPort = (UShort)port+1; - ps->IO.pbControlPort = (UShort)port+2; - ps->IO.pbEppDataPort = (UShort)port+4; - -#else int mode, mts; if( NULL == ps ) @@ -560,7 +227,6 @@ _LOC int MiscInitPorts( pScanData ps, int port ) sanei_pp_setmode( ps->pardev, mts ); _VAR_NOT_USED( port ); -#endif return _OK; } @@ -568,11 +234,6 @@ _LOC int MiscInitPorts( pScanData ps, int port ) */ _LOC void MiscRestorePort( pScanData ps ) { -#ifdef __KERNEL__ - if( 0 == ps->IO.pbSppDataPort ) - return; -#endif - DBG(DBG_LOW,"MiscRestorePort()\n"); /* don't restore if not necessary */ @@ -582,19 +243,9 @@ _LOC void MiscRestorePort( pScanData ps ) } /*Restore Port-Mode*/ -#ifdef __KERNEL__ - if( port_feature & PARPORT_MODE_PCECR ){ - _OUTB_ECTL( ps, (Byte)ps->IO.lastPortMode ); - _DO_UDELAY(1); - } else { - _OUTB_CTRL( ps, (Byte)ps->IO.lastPortMode ); - _DO_UDELAY(1); - } -#else if( port_feature & PPA_PROBE_ECR ){ _OUTB_ECTL(ps,ps->IO.lastPortMode); } -#endif } /** Initializes a timer. @@ -605,11 +256,7 @@ _LOC void MiscStartTimer( TimerDef *timer , unsigned long us) { struct timeval start_time; -#ifdef __KERNEL__ - _GET_TIME( &start_time ); -#else gettimeofday(&start_time, NULL); -#endif *timer = (TimerDef)start_time.tv_sec * 1000000 + (TimerDef)start_time.tv_usec + us; } @@ -624,21 +271,14 @@ _LOC int MiscCheckTimer( TimerDef *timer ) { struct timeval current_time; -#ifdef __KERNEL__ - _GET_TIME( ¤t_time ); -#else gettimeofday(¤t_time, NULL); -#endif if ((TimerDef)current_time.tv_sec * 1000000 + (TimerDef)current_time.tv_usec > *timer) { return _E_TIMEOUT; } else { -#ifdef __KERNEL__ - schedule(); /*#else sched_yield(); */ -#endif return _OK; } } @@ -673,65 +313,8 @@ _LOC Bool MiscAllPointersSet( pScanData ps ) */ _LOC int MiscRegisterPort( pScanData ps, int portAddr ) { -#ifndef __KERNEL__ DBG( DBG_LOW, "Assigning port handle %i\n", portAddr ); ps->pardev = portAddr; -#else - -#ifdef LINUX_26 - __ps = ps; - __pa = portAddr; - - DBG( DBG_LOW, "Requested port at 0x%02x\n", portAddr ); - - if( parport_register_driver(&pt_drv)) { - /* Failed; nothing we can do. */ - return _E_REGISTER; - } - -#else - struct parport *pp = NULL; - - DBG( DBG_LOW, "Requested port at 0x%02x\n", portAddr ); - - pp = parport_enumerate(); - ps->pardev = NULL; - - if( NULL == pp ) { - return _E_PORTSEARCH; - } - - /* go through the list - */ - for( ps->pp = NULL; NULL != pp; ) { - - if( pp->base == (unsigned long)portAddr ) { - DBG( DBG_LOW, "Requested port (0x%02x) found\n", portAddr ); - DBG( DBG_LOW, "Port mode reported: (0x%04x)\n", pp->modes ); - ps->pp = pp; - break; - } - pp = pp->next; - } -#endif - - if( NULL == ps->pp ) { - printk("PORT not found!!!\n"); - return _E_NO_PORT; - } - - /* - * register this device - */ - ps->pardev = parport_register_device( ps->pp, "Plustek Driver", - miscPreemptionCallback, NULL, NULL, 0, (pVoid)ps ); - - if( NULL == ps->pardev ) { - return _E_REGISTER; - } - - DBG( DBG_LOW, "Port for device %u registered\n", ps->devno ); -#endif portIsClaimed[ps->devno] = 0; return _OK; @@ -741,17 +324,7 @@ _LOC int MiscRegisterPort( pScanData ps, int portAddr ) */ _LOC void MiscUnregisterPort( pScanData ps ) { -#ifdef __KERNEL__ - if( NULL != ps->pardev ) { - DBG( DBG_LOW, "Port unregistered\n" ); - parport_unregister_device( ps->pardev ); - } -#ifdef LINUX_26 - parport_unregister_driver( &pt_drv ); -#endif -#else sanei_pp_close( ps->pardev ); -#endif } /** Try to claim the port @@ -763,11 +336,7 @@ _LOC int MiscClaimPort( pScanData ps ) if( 0 == portIsClaimed[ps->devno] ) { DBG( DBG_HIGH, "Try to claim the parport\n" ); -#ifdef __KERNEL__ - if( 0 != parport_claim( ps->pardev )) { -#else if( SANE_STATUS_GOOD != sanei_pp_claim( ps->pardev )) { -#endif return _E_BUSY; } } @@ -785,11 +354,7 @@ _LOC void MiscReleasePort( pScanData ps ) if( 0 == portIsClaimed[ps->devno] ) { DBG( DBG_HIGH, "Releasing parport\n" ); -#ifdef __KERNEL__ - parport_release( ps->pardev ); -#else sanei_pp_release( ps->pardev ); -#endif } } } diff --git a/backend/plustek-pp_motor.c b/backend/plustek-pp_motor.c index ac6d458..b58e92d 100644 --- a/backend/plustek-pp_motor.c +++ b/backend/plustek-pp_motor.c @@ -3128,7 +3128,7 @@ _LOC Bool MotorP96AheadToDarkArea( pScanData ps ) if((bDark < 0x80) || (wTotalLastLine==wTL)) { IOCmdRegisterToScanner( ps, ps->RegMotorControl, 0 ); - return _TRUE; + return _TRUE; } } #else @@ -3216,9 +3216,10 @@ _LOC void MotorP98003BackToHomeSensor( pScanData ps ) MiscStartTimer( &timer, _SECOND * 2 ); while(!(IOGetScanState( ps, _TRUE ) & _SCANSTATE_STOP) && - !MiscCheckTimer( &timer )); + !MiscCheckTimer( &timer )) + ; - _DODELAY( 1000UL ); + _DODELAY( 1000UL ); ps->AsicReg.RD_ModeControl = _ModeScan; @@ -3324,7 +3325,8 @@ _LOC void MotorP98003PositionYProc( pScanData ps, ULong steps) MiscStartTimer( &timer, _SECOND * 5 ); while(!(IOGetScanState( ps, _TRUE ) & _SCANSTATE_STOP) && - (!MiscCheckTimer( &timer ))); + !MiscCheckTimer( &timer )) + ; _DODELAY( 12 ); diff --git a/backend/plustek-pp_p12.c b/backend/plustek-pp_p12.c index e78c682..26566e5 100644 --- a/backend/plustek-pp_p12.c +++ b/backend/plustek-pp_p12.c @@ -472,7 +472,7 @@ static void p12Init98003( pScanData ps, Bool shading ) if( _AGFA_SCANNER == ps->Device.bPCBID ) ps->Device.bDACType = _DA_WOLFSON8141; - DBG( DBG_LOW, "PCB-ID=0x%02x, CCD-ID=0x%02x, DAC-TYPE=0x%02x\n", + DBG( DBG_LOW, "PCB-ID=0x%02x, CCD-ID=0x%02x, DAC-TYPE=0x%02x\n", ps->Device.bPCBID, ps->Device.bCCDID, ps->Device.bDACType ); p12InitiateComponentModel( ps ); diff --git a/backend/plustek-pp_p48xx.c b/backend/plustek-pp_p48xx.c index 3c28357..9ae1239 100644 --- a/backend/plustek-pp_p48xx.c +++ b/backend/plustek-pp_p48xx.c @@ -613,9 +613,9 @@ static void p48xxSetGeneralRegister( pScanData ps ) if (ps->DataInf.xyPhyDpi.x <= 200) ps->AsicReg.RD_ScanControl |= _SCAN_1ST_AVERAGE; - DBG( DBG_LOW, "RD_ModeControl = 0x%02x\n", ps->AsicReg.RD_ModeControl ); - DBG( DBG_LOW, "RD_MotorControl = 0x%02x\n", ps->Asic96Reg.RD_MotorControl ); - DBG( DBG_LOW, "RD_ScanControl = 0x%02x\n", ps->AsicReg.RD_ScanControl ); + DBG( DBG_LOW, "RD_ModeControl = 0x%02x\n", ps->AsicReg.RD_ModeControl ); + DBG( DBG_LOW, "RD_MotorControl = 0x%02x\n", ps->Asic96Reg.RD_MotorControl ); + DBG( DBG_LOW, "RD_ScanControl = 0x%02x\n", ps->AsicReg.RD_ScanControl ); } /*............................................................................. diff --git a/backend/plustek-pp_procs.h b/backend/plustek-pp_procs.h index 96666ea..972252a 100644 --- a/backend/plustek-pp_procs.h +++ b/backend/plustek-pp_procs.h @@ -219,13 +219,6 @@ _LOC void IORegisterDirectToScanner( pScanData, Byte bReg ); _LOC void IOSoftwareReset ( pScanData ps ); _LOC void IOReadScannerImageData ( pScanData ps, pUChar pBuf, ULong size ); -#ifdef __KERNEL__ -_LOC void IOOut ( Byte data, UShort port ); -_LOC void IOOutDelayed( Byte data, UShort port ); -_LOC Byte IOIn ( UShort port ); -_LOC Byte IOInDelayed ( UShort port ); -#endif - /* * implementation in plustek-pp_tpa.c */ @@ -238,16 +231,6 @@ _LOC void TPAP98003Reshading ( pScanData ps ); */ _LOC void ScaleX( pScanData ps, pUChar inBuf, pUChar outBuf ); -/* - * implementation in plustek-pp_procfs.c (Kernel-mode only) - */ -#ifdef __KERNEL__ -int ProcFsInitialize ( void ); -void ProcFsShutdown ( void ); -void ProcFsRegisterDevice ( pScanData ps ); -void ProcFsUnregisterDevice( pScanData ps ); -#endif - #endif /* guard __PROCS_H__ */ /* END PLUSTEK-PP_PROCS.H ...................................................*/ diff --git a/backend/plustek-pp_ptdrv.c b/backend/plustek-pp_ptdrv.c index bf3a389..58b58b1 100644 --- a/backend/plustek-pp_ptdrv.c +++ b/backend/plustek-pp_ptdrv.c @@ -94,52 +94,13 @@ * If you do not wish that, delete this exception notice. * <hr> */ -#ifdef __KERNEL__ -# include <linux/module.h> -# include <linux/version.h> - -# ifdef CONFIG_DEVFS_FS -# include <linux/devfs_fs_kernel.h> -# if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,69)) -# define DEVFS_26_STYLE -# endif -# endif -#endif - #include "plustek-pp_scan.h" -#ifdef __KERNEL__ -# include <linux/param.h> -#endif - /****************************** static vars **********************************/ /* default port is at 0x378 */ static int port[_MAX_PTDEVS] = { 0x378, 0, 0, 0 }; -#ifdef __KERNEL__ -static pScanData PtDrvDevices[_MAX_PTDEVS] = { [0 ... (_MAX_PTDEVS-1)] = NULL}; - -/* default is 180 secs for lamp switch off */ -static int lampoff[_MAX_PTDEVS] = { [0 ... (_MAX_PTDEVS-1)] = 180 }; - -/* warmup period for lamp (30 secs) */ -static int warmup[_MAX_PTDEVS] = { [0 ... (_MAX_PTDEVS-1)] = 30 }; - -/* switch lamp off on unload (default = no)*/ -static int lOffonEnd[_MAX_PTDEVS] = { [0 ... (_MAX_PTDEVS-1)] = 0 }; - -/* model override (0-->none) */ -static UShort mov[_MAX_PTDEVS] = { [0 ... (_MAX_PTDEVS-1)] = 0 }; - -/* forceMode (0--> auto, 1: SPP, 2:EPP, others: auto) */ -static UShort forceMode[_MAX_PTDEVS] = { [0 ... (_MAX_PTDEVS-1)] = 0 }; - -/* to use delayed I/O for each device */ -static Bool slowIO[_MAX_PTDEVS] = { [0 ... (_MAX_PTDEVS-1)] = _FALSE }; - -#else - static pScanData PtDrvDevices[_MAX_PTDEVS]= { NULL, NULL, NULL, NULL }; static int lampoff[_MAX_PTDEVS] = { 180, 180, 180, 180 }; static int warmup[_MAX_PTDEVS] = { 30, 30, 30, 30 }; @@ -147,140 +108,14 @@ static int lOffonEnd[_MAX_PTDEVS] = { 0, 0, 0, 0 }; static UShort mov[_MAX_PTDEVS] = { 0, 0, 0, 0 }; static UShort forceMode[_MAX_PTDEVS] = { 0, 0, 0, 0 }; -#endif - /* timers for warmup checks */ static TimerDef toTimer[_MAX_PTDEVS]; -#ifndef __KERNEL__ static Bool PtDrvInitialized = _FALSE; #ifdef HAVE_SETITIMER static struct itimerval saveSettings; #endif -#else -static Bool deviceScanning = _FALSE; - -static struct timer_list tl[_MAX_PTDEVS]; - -/* for calculation of the timer expiration */ -extern volatile unsigned long jiffies; - -/* the parameter interface - */ -#if ((LINUX_VERSION_CODE > 0x020111) && defined(MODULE)) -MODULE_AUTHOR("Gerhard Jaeger <gerhard@gjaeger.de>"); -MODULE_DESCRIPTION("Plustek parallelport-scanner driver"); - -/* addresses this 'new' license feature... */ -#ifdef MODULE_LICENSE -MODULE_LICENSE("GPL"); -#endif - -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)) -MODULE_PARM(port, "1-" __MODULE_STRING(_MAX_PTDEVS) "i"); -MODULE_PARM(lampoff, "1-" __MODULE_STRING(_MAX_PTDEVS) "i"); -MODULE_PARM(warmup,"1-" __MODULE_STRING(_MAX_PTDEVS) "i"); -MODULE_PARM(lOffonEnd, "1-" __MODULE_STRING(_MAX_PTDEVS) "i"); -MODULE_PARM(mov, "1-" __MODULE_STRING(_MAX_PTDEVS) "i"); -MODULE_PARM(slowIO,"1-" __MODULE_STRING(_MAX_PTDEVS) "i"); -MODULE_PARM(forceMode,"1-" __MODULE_STRING(_MAX_PTDEVS) "i"); - -#else - -static int array_len = _MAX_PTDEVS; - -module_param_array(port, int, &array_len, 0); -module_param_array(lampoff, int, &array_len, 0); -module_param_array(warmup, int, &array_len, 0); -module_param_array(lOffonEnd, int, &array_len, 0); -module_param_array(mov, ushort, &array_len, 0); -module_param_array(slowIO, int, &array_len, 0); -module_param_array(forceMode, ushort, &array_len, 0); - -#endif - - -MODULE_PARM_DESC(port, "I/O base address of parport"); -MODULE_PARM_DESC(lampoff, "Lamp-Off timer preset in seconds"); -MODULE_PARM_DESC(warmup, "Minimum warmup time in seconds"); -MODULE_PARM_DESC(lOffonEnd, "1 - switchoff lamp on unload"); -MODULE_PARM_DESC(mov, "Modell-override switch"); -MODULE_PARM_DESC(slowIO, "0 = Fast I/O, 1 = Delayed I/O"); -MODULE_PARM_DESC(forceMode, "0 = use auto detection, " - "1 = use SPP mode, 2 = use EPP mode"); -#endif - -#if defined (CONFIG_DEVFS_FS) -# ifndef (DEVFS_26_STYLE) - static devfs_handle_t devfs_handle = NULL; -# endif -#else -# ifdef LINUX_26 - static class_t *ptdrv_class; -# endif -#endif -/* - * the module interface - */ -static int pt_drv_open ( struct inode *, struct file *); -static CLOSETYPE pt_drv_close( struct inode *, struct file *); - -#ifdef LINUX_20 - static int pt_drv_read( struct inode*, struct file*, char*, int ); - static int pt_drv_write( struct inode*, struct file*, const char*, int ); -#else - static ssize_t pt_drv_read ( struct file *file, - char *buffer, size_t count, loff_t *); - static ssize_t pt_drv_write( struct file *file, - const char *buffer, size_t tmp,loff_t *count); -#endif - -#ifdef NOLOCK_IOCTL - static long pt_drv_ioctl( struct file *, UInt, unsigned long ); -#else - static int pt_drv_ioctl( struct inode *, struct file *, UInt, unsigned long ); -#endif - - -/* - * the driver interface - */ -#ifdef LINUX_20 - -static struct file_operations pt_drv_fops = -{ - NULL, /* seek */ - pt_drv_read, /* read */ - pt_drv_write, /* write */ - NULL, /* readdir */ - NULL, /* select */ - pt_drv_ioctl, /* ioctl */ - NULL, /* mmap */ - pt_drv_open, /* open */ - pt_drv_close, /* release */ - NULL, /* fsync */ - NULL, /* fasync */ - NULL, /* check_media_change */ - NULL /* revalidate */ -}; - -#else /* 2.2.x and higher stuff */ - -static struct file_operations pt_drv_fops = { -#ifdef LINUX_24 - owner: THIS_MODULE, -#endif - read: pt_drv_read, - write: pt_drv_write, - IOCTL: pt_drv_ioctl, - open: pt_drv_open, - release: pt_drv_close, -}; - -#endif - -#endif /* guard __KERNEL */ /****************************** some prototypes ******************************/ @@ -288,23 +123,6 @@ static void ptdrvStartLampTimer( pScanData ps ); /****************************** local functions ******************************/ -#ifdef __KERNEL__ -/** depending on the device, return the data structure - */ -static pScanData get_pt_from_inode(struct inode *ip) -{ - int minor = _MINOR(ip); - - /* - * unit out of range - */ - if (minor >= _MAX_PTDEVS ) - return NULL; - - return( PtDrvDevices[minor] ); -} -#endif - /** copy user-space data into kernel memory */ static int getUserPtr(const pVoid useraddr, pVoid where, UInt size ) @@ -315,32 +133,9 @@ static int getUserPtr(const pVoid useraddr, pVoid where, UInt size ) if((NULL == useraddr) || ( 0 == size)) return _E_INVALID; -#ifdef __KERNEL__ - if ((err = verify_area_20(VERIFY_READ, useraddr, size))) - return err; -#endif - switch (size) { -#ifdef __KERNEL__ - case sizeof(u_char): - GET_USER_RET(*(u_char *)where, (u_char *) useraddr, -EFAULT); - break; - - case sizeof(u_short): - GET_USER_RET(*(u_short *)where, (u_short *) useraddr, -EFAULT); - break; - - case sizeof(u_long): - GET_USER_RET(*(u_long *)where, (u_long *) useraddr, -EFAULT); - break; - - default: - if (copy_from_user(where, useraddr, size)) - return -EFAULT; -#else default: memcpy( where, useraddr, size ); -#endif } return err; } @@ -354,20 +149,11 @@ static int putUserPtr( const pVoid ptr, pVoid useraddr, UInt size ) if (NULL == useraddr) return _E_INVALID; -#ifdef __KERNEL__ - if ((err = verify_area_20(VERIFY_WRITE, useraddr, size))) - return err; - - if (copy_to_user(useraddr, ptr, size )) - return -EFAULT; -#else memcpy( useraddr, ptr, size ); -#endif return err; } -#ifndef __KERNEL__ static unsigned long copy_from_user( pVoid dest, pVoid src, unsigned long len ) { memcpy( dest, src, len ); @@ -379,37 +165,16 @@ static unsigned long copy_to_user( pVoid dest, pVoid src, unsigned long len ) memcpy( dest, src, len ); return 0; } -#endif /** */ static int putUserVal(const ULong value, pVoid useraddr, UInt size) { -#ifdef __KERNEL__ - int err; -#endif - if (NULL == useraddr) return _E_INVALID; -#ifdef __KERNEL__ - if ((err = verify_area_20(VERIFY_WRITE, useraddr, size))) - return err; -#endif - switch (size) { -#ifdef __KERNEL__ - case sizeof(u_char): - PUT_USER_RET((u_char)value, (u_char *) useraddr, -EFAULT); - break; - case sizeof(u_short): - PUT_USER_RET((u_short)value, (u_short *) useraddr, -EFAULT); - break; - case sizeof(u_long): - PUT_USER_RET((u_long)value, (u_long *) useraddr, -EFAULT); - break; -#else case sizeof(UChar): *(pUChar)useraddr = (UChar)value; break; @@ -420,7 +185,6 @@ static int putUserVal(const ULong value, pVoid useraddr, UInt size) *(pULong)useraddr = (ULong)value; break; -#endif default: return _E_INVALID; } @@ -506,22 +270,14 @@ static void ptdrvLampWarmup( pScanData ps ) /** */ -#ifdef __KERNEL__ -static void ptdrvLampTimerIrq( unsigned long ptr ) -#else static void ptdrvLampTimerIrq( int sig_num ) -#endif { pScanData ps; DBG( DBG_HIGH, "!! IRQ !! Lamp-Timer stopped.\n" ); -#ifdef __KERNEL__ - ps = (pScanData)ptr; -#else _VAR_NOT_USED( sig_num ); ps = PtDrvDevices[0]; -#endif /* * paranoia check! @@ -559,7 +315,6 @@ static void ptdrvLampTimerIrq( int sig_num ) */ static void ptdrvStartLampTimer( pScanData ps ) { -#ifndef __KERNEL__ sigset_t block, pause_mask; struct sigaction s; #ifdef HAVE_SETITIMER @@ -597,17 +352,6 @@ static void ptdrvStartLampTimer( pScanData ps ) #else alarm( ps->lampoff ); #endif -#else - init_timer( &tl[ps->devno] ); - - /* timeout val in seconds */ - tl[ps->devno].expires = jiffies + ps->lampoff * HZ; - tl[ps->devno].data = (unsigned long)ps; - tl[ps->devno].function = ptdrvLampTimerIrq; - - if( 0 != ps->lampoff ) - add_timer( &tl[ps->devno] ); -#endif DBG( DBG_HIGH, "Lamp-Timer started!\n" ); } @@ -616,7 +360,6 @@ static void ptdrvStartLampTimer( pScanData ps ) */ static void ptdrvStopLampTimer( pScanData ps ) { -#ifndef __KERNEL__ sigset_t block, pause_mask; /* block SIGALRM */ @@ -630,10 +373,6 @@ static void ptdrvStopLampTimer( pScanData ps ) _VAR_NOT_USED( ps ); alarm(0); #endif -#else - if( 0 != ps->lampoff ) - del_timer( &tl[ps->devno] ); -#endif DBG( DBG_HIGH, "Lamp-Timer stopped!\n" ); } @@ -701,23 +440,11 @@ static int ptdrvOpenDevice( pScanData ps ) UShort lastMode; ULong devno; -#ifdef __KERNEL__ - UShort flags; - struct pardevice *pd; - struct parport *pp; - ProcDirDef procDir; -#else int pd; -#endif /* * push some values from the struct */ -#ifdef __KERNEL__ - flags = ps->flags; - pp = ps->pp; - procDir = ps->procDir; -#endif pd = ps->pardev; iobase = ps->sCaps.wIOBase; asic = ps->sCaps.AsicID; @@ -734,29 +461,10 @@ static int ptdrvOpenDevice( pScanData ps ) /* * pop the val(s) */ -#ifdef __KERNEL__ - ps->flags = flags; - ps->pp = pp; - ps->procDir = procDir; -#endif ps->pardev = pd; ps->bLastLampStatus = lastStat; ps->IO.lastPortMode = lastMode; ps->devno = devno; - -#ifdef __KERNEL__ - if( _TRUE == slowIO[devno] ) { - DBG( DBG_LOW, "Using slow I/O\n" ); - ps->IO.slowIO = _TRUE; - ps->IO.fnOut = IOOutDelayed; - ps->IO.fnIn = IOInDelayed; - } else { - DBG( DBG_LOW, "Using fast I/O\n" ); - ps->IO.slowIO = _FALSE; - ps->IO.fnOut = IOOut; - ps->IO.fnIn = IOIn; - } -#endif ps->ModelOverride = mov[devno]; ps->warmup = warmup[devno]; ps->lampoff = lampoff[devno]; @@ -798,19 +506,6 @@ static int ptdrvInit( int devno ) return _E_ALLOC; } -#ifdef __KERNEL__ - if( _TRUE == slowIO[devno] ) { - DBG( DBG_LOW, "Using slow I/O\n" ); - ps->IO.slowIO = _TRUE; - ps->IO.fnOut = IOOutDelayed; - ps->IO.fnIn = IOInDelayed; - } else { - DBG( DBG_LOW, "Using fast I/O\n" ); - ps->IO.slowIO = _FALSE; - ps->IO.fnOut = IOOut; - ps->IO.fnIn = IOIn; - } -#endif ps->ModelOverride = mov[devno]; ps->warmup = warmup[devno]; ps->lampoff = lampoff[devno]; @@ -845,13 +540,8 @@ static int ptdrvInit( int devno ) if( _OK == retval ) { -#ifdef __KERNEL__ - _PRINT( "pt_drv%u: %s found on port 0x%04x\n", - devno, MiscGetModelName(ps->sCaps.Model), ps->IO.pbSppDataPort ); -#else DBG( DBG_LOW, "pt_drv%u: %s found\n", devno, MiscGetModelName(ps->sCaps.Model)); -#endif /* * initialize the timespan timer @@ -859,43 +549,23 @@ static int ptdrvInit( int devno ) MiscStartTimer( &toTimer[ps->devno], (_SECOND * ps->warmup)); if( 0 == ps->lampoff ) -#ifdef __KERNEL__ - _PRINT( -#else DBG( DBG_LOW, -#endif "pt_drv%u: Lamp-Timer switched off.\n", devno ); else { -#ifdef __KERNEL__ - _PRINT( -#else DBG( DBG_LOW, -#endif "pt_drv%u: Lamp-Timer set to %u seconds.\n", devno, ps->lampoff ); } -#ifdef __KERNEL__ - _PRINT( -#else DBG( DBG_LOW, -#endif "pt_drv%u: WarmUp period set to %u seconds.\n", devno, ps->warmup ); if( 0 == ps->lOffonEnd ) { -#ifdef __KERNEL__ - _PRINT( -#else DBG( DBG_LOW, -#endif "pt_drv%u: Lamp untouched on driver unload.\n", devno ); } else { -#ifdef __KERNEL__ - _PRINT( -#else DBG( DBG_LOW, -#endif "pt_drv%u: Lamp switch-off on driver unload.\n", devno ); } @@ -1287,31 +957,19 @@ static int ptdrvRead( pScanData ps, pUChar buffer, int count ) int retval = _OK; #ifdef _ASIC_98001_SIM -#ifdef __KERNEL__ - _PRINT( -#else DBG( DBG_LOW, -#endif "pt_drv : Software-Emulation active, can't read!\n" ); return _E_INVALID; #endif if((NULL == buffer) || (NULL == ps)) { -#ifdef __KERNEL__ - _PRINT( -#else DBG( DBG_HIGH, -#endif "pt_drv : Internal NULL-pointer!\n" ); return _E_NULLPTR; } if( 0 == count ) { -#ifdef __KERNEL__ - _PRINT( -#else DBG( DBG_HIGH, -#endif "pt_drv%u: reading 0 bytes makes no sense!\n", ps->devno ); return _E_INVALID; } @@ -1325,11 +983,7 @@ static int ptdrvRead( pScanData ps, pUChar buffer, int count ) * when using the cat /dev/pt_drv command! */ if (!(ps->DataInf.dwVxdFlag & _VF_ENVIRONMENT_READY)) { -#ifdef __KERNEL__ - _PRINT( -#else DBG( DBG_HIGH, -#endif "pt_drv%u: Cannot read, driver not initialized!\n",ps->devno); return _E_SEQUENCE; } @@ -1340,11 +994,7 @@ static int ptdrvRead( pScanData ps, pUChar buffer, int count ) ps->Scan.bp.pMonoBuf = _KALLOC( ps->DataInf.dwAppPhyBytesPerLine, GFP_KERNEL); if ( NULL == ps->Scan.bp.pMonoBuf ) { -#ifdef __KERNEL__ - _PRINT( -#else DBG( DBG_HIGH, -#endif "pt_drv%u: Not enough memory available!\n", ps->devno ); return _E_ALLOC; } @@ -1355,11 +1005,7 @@ static int ptdrvRead( pScanData ps, pUChar buffer, int count ) scaleBuf = _KALLOC( ps->DataInf.dwAppPhyBytesPerLine, GFP_KERNEL); if ( NULL == scaleBuf ) { _KFREE( ps->Scan.bp.pMonoBuf ); -#ifdef __KERNEL__ - _PRINT( -#else DBG( DBG_HIGH, -#endif "pt_drv%u: Not enough memory available!\n", ps->devno ); return _E_ALLOC; } @@ -1406,11 +1052,7 @@ static int ptdrvRead( pScanData ps, pUChar buffer, int count ) retval = ps->Calibration( ps ); if( _OK != retval ) { -#ifdef __KERNEL__ - _PRINT( -#else DBG( DBG_HIGH, -#endif "pt_drv%u: calibration failed, result = %i\n", ps->devno, retval ); goto ReadFinished; @@ -1507,12 +1149,9 @@ static int ptdrvRead( pScanData ps, pUChar buffer, int count ) ps->Scan.dwLinesToRead--; /* needed, esp. to avoid freezing the system in SPP mode */ -#ifdef __KERNEL__ - schedule(); /*#else sched_yield(); */ -#endif } if (ps->fScanningStatus) { @@ -1565,346 +1204,6 @@ ReadFinished: return retval; } -/*************************** the module interface ****************************/ - -#ifdef __KERNEL__ /* the kernel module interface */ - -/* Designed to be used as a module */ -#ifdef MODULE - -/*............................................................................. - * gets called upon module initialization - */ -#ifdef LINUX_26 -static int __init ptdrv_init( void ) -#else -int init_module( void ) -#endif -{ - UInt devCount; - UInt i; - int retval = _OK; - int result = _OK; -#if (defined(CONFIG_DEVFS_FS) && !defined(DEVFS_26_STYLE)) - char controlname[24]; -#endif -# ifdef LINUX_26 - char devname[20]; -#endif - - DBG( DBG_HIGH, "*********************************************\n" ); - DBG( DBG_HIGH, "pt_drv: init_module()\n" ); - -#if (defined(CONFIG_DEVFS_FS) && !defined(DEVFS_26_STYLE)) - devfs_handle = devfs_mk_dir(NULL, "scanner", NULL); - if( devfs_register_chrdev(_PTDRV_MAJOR, _DRV_NAME, &pt_drv_fops)) { -#else - if( register_chrdev(_PTDRV_MAJOR, _DRV_NAME, &pt_drv_fops)) { -#endif - - _PRINT(KERN_INFO "pt_drv: unable to get major %d for pt_drv devices\n", - _PTDRV_MAJOR); - return -EIO; - } - printk( KERN_INFO "pt_drv : driver version "_PTDRV_VERSTR"\n" ); - -#if !defined (CONFIG_DEVFS_FS) && defined (LINUX_26) - ptdrv_class = class_create(THIS_MODULE, "scanner"); - if (IS_ERR(ptdrv_class)) - goto out_devfs; -#endif - - /* register the proc_fs */ - ProcFsInitialize(); - - /* go through the list of defined ports and try to find a device - */ - devCount = 0; - for( i = 0; i < _MAX_PTDEVS; i++ ) { - - if( 0 != port[i] ) { - result = ptdrvInit( i ); - - if ( _OK == result ) { - PtDrvDevices[i]->flags |= _PTDRV_INITALIZED; - -#ifdef CONFIG_DEVFS_FS -# ifndef DEVFS_26_STYLE - sprintf( controlname, "scanner/pt_drv%d", devCount ); - devfs_register( NULL, controlname, - DEVFS_FL_DEFAULT, _PTDRV_MAJOR, 0, - (S_IFCHR | S_IRUGO | S_IWUGO | S_IFCHR), - &pt_drv_fops, NULL ); -# else /* DEVFS_26_STYLE */ - devfs_mk_cdev(MKDEV(_PTDRV_MAJOR, devCount), - (S_IFCHR | S_IRUGO | S_IWUGO | S_IFCHR), - "scanner/pt_drv%d", devCount); -# endif -#else -# ifdef LINUX_26 - sprintf(devname, "pt_drv%d", devCount); - CLASS_DEV_CREATE(ptdrv_class, - MKDEV(_PTDRV_MAJOR, devCount), NULL, - devname); - -# endif /* LINUX_26 */ -#endif /* CONFIG_DEVFS_FS */ - ProcFsRegisterDevice( PtDrvDevices[i] ); - devCount++; - } else { - retval = result; - ptdrvShutdown( PtDrvDevices[i] ); - PtDrvDevices[i] = NULL; - } - } - } - - /* * if something went wrong, shutdown all... */ - if( devCount == 0 ) { - -#if !defined (CONFIG_DEVFS_FS) && defined (LINUX_26) -out_devfs: - class_destroy(ptdrv_class); -#endif - -#if (defined(CONFIG_DEVFS_FS) && !defined(DEVFS_26_STYLE)) - devfs_unregister_chrdev( _PTDRV_MAJOR, _DRV_NAME ); -#else - unregister_chrdev( _PTDRV_MAJOR, _DRV_NAME ); -#endif - ProcFsShutdown(); - -#ifdef __KERNEL__ - _PRINT( KERN_INFO "pt_drv : no device(s) detected, (%i)\n", retval ); -#endif - - } else { - - DBG( DBG_HIGH, "pt_drv : init done, %u device(s) found\n", devCount ); - retval = _OK; - } - DBG( DBG_HIGH, "---------------------------------------------\n" ); - - deviceScanning = _FALSE; - return retval; -} - -/*............................................................................. - * cleanup the show - */ -#ifdef LINUX_26 -static void __exit ptdrv_exit( void ) -#else -void cleanup_module( void ) -#endif -{ - UInt i; - pScanData ps; -#if (defined(CONFIG_DEVFS_FS) && !defined(DEVFS_26_STYLE)) - char controlname[24]; - devfs_handle_t master; -#endif - - DBG( DBG_HIGH, "pt_drv: cleanup_module()\n" ); - - for ( i = 0; i < _MAX_PTDEVS; i++ ) { - - ps = PtDrvDevices[i]; - PtDrvDevices[i] = NULL; - - if ( NULL != ps ) { -#ifdef CONFIG_DEVFS_FS -# ifndef DEVFS_26_STYLE - sprintf( controlname, "scanner/pt_drv%d", i ); - master = devfs_find_handle( NULL,controlname, 0, 0, - DEVFS_SPECIAL_CHR, 0 ); - devfs_unregister( master ); -# else - devfs_remove("scanner/pt_drv%d", i); -# endif -#else -# ifdef LINUX_26 - CLASS_DEV_DESTROY(ptdrv_class, MKDEV(_PTDRV_MAJOR, i)); -# endif /* LINUX_26 */ -#endif /* CONFIG_DEVFS_FS */ - ptdrvShutdown( ps ); - ProcFsUnregisterDevice( ps ); - } - } - -#if (defined(CONFIG_DEVFS_FS) && !defined(DEVFS_26_STYLE)) - devfs_unregister_chrdev( _PTDRV_MAJOR, _DRV_NAME ); -#else - unregister_chrdev( _PTDRV_MAJOR, _DRV_NAME ); -#endif - ProcFsShutdown(); - -#if !defined (CONFIG_DEVFS_FS) && defined (LINUX_26) - class_destroy(ptdrv_class); -#endif - - DBG( DBG_HIGH, "pt_drv: cleanup done.\n" ); - DBG( DBG_HIGH, "*********************************************\n" ); -} - -#ifdef LINUX_26 -module_init(ptdrv_init); -module_exit(ptdrv_exit); -#endif - -#endif /*MODULE*/ - - -/*............................................................................. - * device open... - */ -static int pt_drv_open(struct inode *inode, struct file *file) -{ - pScanData ps; - - DBG( DBG_HIGH, "pt_drv_open()\n" ); - - ps = get_pt_from_inode(inode); - - if ( NULL == ps ) { - return(-ENXIO); - } - - /* device not found ? */ - if (!(ps->flags & _PTDRV_INITALIZED)) { - return(-ENXIO); - } - - /* device is busy ? */ - if (ps->flags & _PTDRV_OPEN) { - return(-EBUSY); - } - -#ifdef LINUX_26 - if (!try_module_get(THIS_MODULE)) - return -EAGAIN; -#else - MOD_INC_USE_COUNT; -#endif - ps->flags |= _PTDRV_OPEN; - - return _OK; -} - -/*............................................................................. - * device close... - */ -static CLOSETYPE pt_drv_close(struct inode * inode, struct file * file) -{ - pScanData ps; - - DBG( DBG_HIGH, "pt_drv_close()\n" ); - - if ((ps = get_pt_from_inode(inode)) ) { - - ptdrvClose( ps ); - - ps->flags &= ~_PTDRV_OPEN; -#ifdef LINUX_26 - module_put(THIS_MODULE); -#else - MOD_DEC_USE_COUNT; -#endif - CLOSERETURN(0); - } else { - - DBG( DBG_HIGH, "pt_drv: - close failed!\n" ); - CLOSERETURN(-ENXIO); - } -} - -/*............................................................................. - * read data from device - */ -#ifdef LINUX_20 -static int pt_drv_read(struct inode *inode, struct file *file, - char *buffer, int count) -{ - int result; - pScanData ps; - - if ( !(ps = get_pt_from_inode(inode))) - return(-ENXIO); -#else -static ssize_t pt_drv_read( struct file *file, - char *buffer, size_t count, loff_t *tmp ) -{ - int result; - pScanData ps; - - if ( !(ps = get_pt_from_inode(file->f_dentry->d_inode)) ) - return(-ENXIO); -#endif - if ((result = verify_area_20(VERIFY_WRITE, buffer, count))) - return result; - - /* - * as the driver contains some global vars, it is not - * possible to scan simultaenously with two or more devices - */ - if( _TRUE == deviceScanning ) { - printk( KERN_INFO "pt_drv: device %u busy!!!\n", ps->devno ); - return(-EBUSY); - } - - deviceScanning = _TRUE; - - result = ptdrvRead( ps, buffer, count ); - - deviceScanning = _FALSE; - return result; -} - -/*............................................................................. - * writing makes no sense - */ -#ifdef LINUX_20 -static int pt_drv_write(struct inode * inode, struct file * file, - const char * buffer, int count) -{ - return -EPERM; -} -#else - static ssize_t pt_drv_write( struct file * file,const char * buffer, - size_t tmp,loff_t* count) -{ - return -EPERM; -} -#endif - -/*............................................................................. - * the ioctl interface - */ -#ifdef NOLOCK_IOCTL -static long pt_drv_ioctl( struct file *file, UInt cmd, unsigned long arg ) -{ - pScanData ps; - - if ( !(ps = get_pt_from_inode(file->f_dentry->d_inode)) ) - return(-ENXIO); - - return ptdrvIoctl( ps, cmd, (pVoid)arg); -} -#else -static int pt_drv_ioctl( struct inode *inode, struct file *file, - UInt cmd, unsigned long arg ) -{ - pScanData ps; - - if ( !(ps = get_pt_from_inode(inode)) ) - return(-ENXIO); - - return ptdrvIoctl( ps, cmd, (pVoid)arg); -} -#endif - -#else /* the user-mode interface */ - /*............................................................................. * here we only have wrapper functions */ @@ -1980,6 +1279,4 @@ static int PtDrvRead ( pUChar buffer, int count ) return ptdrvRead( PtDrvDevices[0], buffer, count ); } -#endif /* guard __KERNEL__ */ - /* END PLUSTEK-PP_PTDRV.C ...................................................*/ diff --git a/backend/plustek-pp_scan.h b/backend/plustek-pp_scan.h index ccc9b97..b57148f 100644 --- a/backend/plustek-pp_scan.h +++ b/backend/plustek-pp_scan.h @@ -63,8 +63,6 @@ #ifndef __PLUSTEK_SCAN_H__ #define __PLUSTEK_SCAN_H__ -#ifndef __KERNEL__ - # include <stdlib.h> # include <stdarg.h> # include <string.h> @@ -76,19 +74,6 @@ # ifdef HAVE_SYS_IO_H # include <sys/io.h> # endif -#else -# include <linux/kernel.h> -# include <linux/init.h> -# include <linux/version.h> -# include "plustek-pp_sysdep.h" -# include <linux/delay.h> -# include <linux/parport.h> - -#ifdef LINUX_24 -# include <linux/parport_pc.h> -#endif /* LINUX_24 */ - -#endif /* __KERNEL__ */ /*............................................................................. * driver properties @@ -104,20 +89,6 @@ # define _OPF ps->IO.fnOut # define _IPF ps->IO.fnIn -#ifdef __KERNEL__ - -#define _OUTB_CTRL(pSD,port_value) _OPF(port_value,pSD->IO.pbControlPort) -#define _OUTB_DATA(pSD,port_value) _OPF(port_value,pSD->IO.pbSppDataPort) -#define _OUTB_ECTL(pSD,port_value) _OPF(port_value,(pSD->IO.portBase+0x402)) - -#define _INB_CTRL(pSD) _IPF(pSD->IO.pbControlPort) -#define _INB_DATA(pSD) _IPF(pSD->IO.pbSppDataPort) -#define _INB_EPPDATA(pSD) _IPF(pSD->IO.pbEppDataPort) -#define _INB_STATUS(pSD) _IPF(pSD->IO.pbStatusPort) -#define _INB_ECTL(pSD) _IPF((pSD->IO.portBase+0x402)) - -#else - #define _OUTB_CTRL(pSD,port_value) sanei_pp_outb_ctrl(pSD->pardev, port_value) #define _OUTB_DATA(pSD,port_value) sanei_pp_outb_data(pSD->pardev, port_value) #define _OUTB_ECTL(pSD,port_value) @@ -127,32 +98,19 @@ #define _INB_EPPDATA(pSD) sanei_pp_inb_epp(pSD->pardev) #define _INB_STATUS(pSD) sanei_pp_inb_stat(pSD->pardev) -#endif - /*............................................................................. * for memory allocation */ -#ifndef __KERNEL__ # define _KALLOC(x,y) malloc(x) # define _KFREE(x) free(x) # define _VMALLOC(x) malloc(x) # define _VFREE(x) free(x) -#else -# define _KALLOC(x,y) kmalloc(x,y) -# define _KFREE(x) kfree(x) -# define _VMALLOC(x) vmalloc(x) -# define _VFREE(x) vfree(x) -#endif /* * WARNING - never use the _SECOND define with the _DODELAY macro !! * they are for use the MiscStartTimer function and the _DO_UDELAY macro */ -#ifndef __KERNEL__ typedef double TimerDef, *pTimerDef; -#else -typedef long long TimerDef, *pTimerDef; -#endif #define _MSECOND 1000 /* based on 1 us */ #define _SECOND (1000*_MSECOND) @@ -160,13 +118,8 @@ typedef long long TimerDef, *pTimerDef; /*............................................................................. * timer topics */ -#ifndef __KERNEL__ # define _DO_UDELAY(usecs) sanei_pp_udelay(usecs) # define _DODELAY(msecs) { int i; for( i = msecs; i--; ) _DO_UDELAY(1000); } -#else -# define _DO_UDELAY(usecs) udelay(usecs) -# define _DODELAY(msecs) mdelay(msecs) -#endif /*............................................................................. * include the shared stuff right here, this concerns the ioctl interface diff --git a/backend/plustek-pp_scandata.h b/backend/plustek-pp_scandata.h index 1ba0fc5..ea98139 100644 --- a/backend/plustek-pp_scandata.h +++ b/backend/plustek-pp_scandata.h @@ -143,17 +143,7 @@ typedef struct { */ typedef struct scandata { -#ifdef __KERNEL__ - UInt flags; /* as follows: */ -#define _PTDRV_INITALIZED 0x00000001 -#define _PTDRV_OPEN 0x00000002 - - struct pardevice *pardev; /* for accessing parport... */ - struct parport *pp; - ProcDirDef procDir; -#else int pardev; /* parport handle in user-space */ -#endif /* * device control diff --git a/backend/plustek-usbshading.c b/backend/plustek-usbshading.c index c585c8b..f7eb619 100644 --- a/backend/plustek-usbshading.c +++ b/backend/plustek-usbshading.c @@ -685,7 +685,7 @@ static u_char usb_GetNewGain( Plustek_Device *dev, u_short wMax, int channel ) dwInc = (u_long)((0.93 + ceil (dRatio) * 0.067) * wMax / dAmp); dwDec = (u_long)((0.93 + floor (dRatio) * 0.067) * wMax / dAmp); if((dwInc >= 0xff00) || - (labs (dwInc - m_dwIdealGain) > labs(dwDec - m_dwIdealGain))) { + (dwInc - m_dwIdealGain > m_dwIdealGain - dwDec)) { bGain = (u_char)floor(dRatio); } else { bGain = (u_char)ceil(dRatio); diff --git a/backend/qcam.c b/backend/qcam.c index 9d55055..8e302e9 100644 --- a/backend/qcam.c +++ b/backend/qcam.c @@ -191,23 +191,13 @@ static const SANE_Range odd_bw_x_range = { 1, 335, 2 }; static const SANE_Range bw_y_range = { 0, 241, 1 }; static const SANE_Range odd_bw_y_range = { 1, 242, 1 }; -#if defined(HAVE_SYS_IO_H) || defined(HAVE_ASM_IO_H) || defined (HAVE_SYS_HW_H) - -#ifdef HAVE_SYS_IO_H -# include <sys/io.h> /* GNU libc based OS */ -#elif HAVE_ASM_IO_H -# include <asm/io.h> /* older Linux */ -#elif HAVE_SYS_HW_H -# include <sys/hw.h> /* OS/2 */ -#endif - -#endif /* <sys/io.h> || <asm/io.h> || <sys/hw.h> */ +#include "../include/sane/sanei_directio.h" -#define read_lpdata(d) inb ((d)->port) -#define read_lpstatus(d) inb ((d)->port + 1) -#define read_lpcontrol(d) inb ((d)->port + 2) -#define write_lpdata(d,v) outb ((v), (d)->port) -#define write_lpcontrol(d,v) outb ((v), (d)->port + 2) +#define read_lpdata(d) sanei_inb ((d)->port) +#define read_lpstatus(d) sanei_inb ((d)->port + 1) +#define read_lpcontrol(d) sanei_inb ((d)->port + 2) +#define write_lpdata(d,v) sanei_outb ((d)->port, (v)) +#define write_lpcontrol(d,v) sanei_outb ((d)->port + 2, (v)) static SANE_Status @@ -217,7 +207,7 @@ enable_ports (QC_Device * q) if (q->port < 0x278 || q->port > 0x3bc) return SANE_STATUS_INVAL; - if (ioperm (q->port, 3, 1) < 0) + if (sanei_ioperm (q->port, 3, 1) < 0) return SANE_STATUS_INVAL; return SANE_STATUS_GOOD; @@ -226,7 +216,7 @@ enable_ports (QC_Device * q) static SANE_Status disable_ports (QC_Device * q) { - if (ioperm (q->port, 3, 0) < 0) + if (sanei_ioperm (q->port, 3, 0) < 0) return SANE_STATUS_INVAL; return SANE_STATUS_GOOD; @@ -1454,7 +1444,7 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize) char dev_name[PATH_MAX], *str; size_t len; FILE *fp; - authorize = authorize; /* silence compilation warnings */ + (void) authorize; /* silence compilation warnings */ DBG_INIT (); @@ -1521,7 +1511,7 @@ sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only) DBG (5, "sane_get_devices: enter\n"); - local_only = local_only; /* silence compilation warnings */ + (void) local_only; /* silence compilation warnings */ if (devlist) free (devlist); @@ -2129,7 +2119,7 @@ sane_read (SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, len = s->bytes_per_frame - s->num_bytes; DBG (8, "read(buf=%p,num_bytes=%ld,max_len=%d,len=%ld)\n", - buf, (long) s->num_bytes, max_len, (long) len); + (void *) buf, (long) s->num_bytes, max_len, (long) len); nread = read (s->read_fd, buf, len); if (nread <= 0) diff --git a/backend/ricoh.c b/backend/ricoh.c index d1f20c0..c4dd641 100644 --- a/backend/ricoh.c +++ b/backend/ricoh.c @@ -485,7 +485,7 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize) char devnam[PATH_MAX] = "/dev/scanner"; FILE *fp; - authorize = authorize; /* silence gcc */ + (void) authorize; /* silence gcc */ DBG_INIT (); DBG (11, ">> sane_init\n"); @@ -514,7 +514,8 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize) continue; /* ignore empty lines */ /* skip white space: */ - for (lp = line; isspace(*lp); ++lp); + for (lp = line; isspace(*lp); ++lp) + ; strcpy (devnam, lp); } fclose (fp); @@ -550,7 +551,7 @@ sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only) Ricoh_Device *dev; int i; - local_only = local_only; /* silence gcc */ + (void) local_only; /* silence gcc */ DBG (11, ">> sane_get_devices\n"); @@ -1007,8 +1008,8 @@ sane_cancel (SANE_Handle handle) SANE_Status sane_set_io_mode (SANE_Handle handle, SANE_Bool non_blocking) { - handle = handle; /* silence gcc */ - non_blocking = non_blocking; /* silence gcc */ + (void) handle; /* silence gcc */ + (void) non_blocking; /* silence gcc */ DBG (5, ">> sane_set_io_mode\n"); DBG (5, "<< sane_set_io_mode\n"); @@ -1019,8 +1020,8 @@ sane_set_io_mode (SANE_Handle handle, SANE_Bool non_blocking) SANE_Status sane_get_select_fd (SANE_Handle handle, SANE_Int * fd) { - handle = handle; /* silence gcc */ - fd = fd; /* silence gcc */ + (void) handle; /* silence gcc */ + (void) fd; /* silence gcc */ DBG (5, ">> sane_get_select_fd\n"); DBG (5, "<< sane_get_select_fd\n"); diff --git a/backend/rts8891.c b/backend/rts8891.c index fa5d17a..2732871 100644 --- a/backend/rts8891.c +++ b/backend/rts8891.c @@ -76,6 +76,7 @@ #include <errno.h> #include <fcntl.h> #include <limits.h> +#include <math.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> @@ -306,7 +307,7 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize) { SANE_Status status; - authorize = authorize; /* get rid of compiler warning */ + (void) authorize; /* get rid of compiler warning */ /* init ASIC libraries */ sanei_rts88xx_lib_init (); @@ -4778,7 +4779,7 @@ dark_calibration (struct Rts8891_Device *dev, int mode, int light) global, ra, ga, ba); /* dichotomie ... */ - if (abs (ra - DARK_TARGET) < DARK_MARGIN) + if (fabs (ra - DARK_TARGET) < DARK_MARGIN) { /* offset is OK */ tro = ro; @@ -4800,7 +4801,7 @@ dark_calibration (struct Rts8891_Device *dev, int mode, int light) } /* same for blue channel */ - if (abs (ba - DARK_TARGET) < DARK_MARGIN) + if (fabs (ba - DARK_TARGET) < DARK_MARGIN) { bbo = bo; tbo = bo; @@ -4821,7 +4822,7 @@ dark_calibration (struct Rts8891_Device *dev, int mode, int light) } /* and for green channel */ - if (abs (ga - DARK_TARGET) < DARK_MARGIN) + if (fabs (ga - DARK_TARGET) < DARK_MARGIN) { tgo = go; bgo = go; @@ -5084,7 +5085,7 @@ gain_calibration (struct Rts8891_Device *dev, int mode, int light) global, ra, ga, ba); /* dichotomy again ... */ - if (abs (ra - RED_GAIN_TARGET) < GAIN_MARGIN) + if (fabs (ra - RED_GAIN_TARGET) < GAIN_MARGIN) { /* gain is OK, it is whitin the tolerance margin */ trg = rg; @@ -5125,7 +5126,7 @@ gain_calibration (struct Rts8891_Device *dev, int mode, int light) } /* same for blue channel */ - if (abs (ba - BLUE_GAIN_TARGET) < GAIN_MARGIN) + if (fabs (ba - BLUE_GAIN_TARGET) < GAIN_MARGIN) { bbg = bg; tbg = bg; @@ -5161,7 +5162,7 @@ gain_calibration (struct Rts8891_Device *dev, int mode, int light) } /* and for green channel */ - if (abs (ga - GREEN_GAIN_TARGET) < GAIN_MARGIN) + if (fabs (ga - GREEN_GAIN_TARGET) < GAIN_MARGIN) { tgg = gg; bgg = gg; @@ -5367,7 +5368,7 @@ offset_calibration (struct Rts8891_Device *dev, int mode, int light) global, ra, ga, ba); /* dichotomie ... */ - if (abs (ra - OFFSET_TARGET) < OFFSET_MARGIN) + if (fabs (ra - OFFSET_TARGET) < OFFSET_MARGIN) { /* offset is OK */ tro = ro; @@ -5389,7 +5390,7 @@ offset_calibration (struct Rts8891_Device *dev, int mode, int light) } /* same for blue channel */ - if (abs (ba - OFFSET_TARGET) < OFFSET_MARGIN) + if (fabs (ba - OFFSET_TARGET) < OFFSET_MARGIN) { bbo = bo; tbo = bo; @@ -5410,7 +5411,7 @@ offset_calibration (struct Rts8891_Device *dev, int mode, int light) } /* and for green channel */ - if (abs (ga - OFFSET_TARGET) < OFFSET_MARGIN) + if (fabs (ga - OFFSET_TARGET) < OFFSET_MARGIN) { tgo = go; bgo = go; diff --git a/backend/s9036.c b/backend/s9036.c index 8f84ecf..cc8a205 100644 --- a/backend/s9036.c +++ b/backend/s9036.c @@ -124,8 +124,8 @@ test_ready (int fd) static SANE_Status sense_handler (int scsi_fd, u_char *result, void *arg) { - scsi_fd = scsi_fd; - arg = arg; /* silence compilation warnings */ + (void) scsi_fd; + (void) arg; /* silence compilation warnings */ if (result[0]) { @@ -141,7 +141,7 @@ sense_handler (int scsi_fd, u_char *result, void *arg) static SANE_Status stop_scan (int fd) { - fd = fd; /* silence compilation warnings */ + (void) fd; /* silence compilation warnings */ /* XXX don't know how to stop the scanner. To be tested ! */ #if 0 @@ -829,7 +829,7 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize) size_t len; FILE *fp; - authorize = authorize; /* silence compilation warnings */ + (void) authorize; /* silence compilation warnings */ DBG_INIT (); @@ -882,7 +882,7 @@ sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only) S9036_Device *dev; int i; - local_only = local_only; /* silence compilation warnings */ + (void) local_only; /* silence compilation warnings */ if (devlist) free (devlist); @@ -1327,7 +1327,7 @@ sane_cancel (SANE_Handle handle) SANE_Status sane_set_io_mode (SANE_Handle handle, SANE_Bool non_blocking) { - handle = handle; /* silence compilation warnings */ + (void) handle; /* silence compilation warnings */ DBG (1, "sane_set_io_mode(%d)\n", non_blocking); @@ -1338,8 +1338,8 @@ sane_set_io_mode (SANE_Handle handle, SANE_Bool non_blocking) SANE_Status sane_get_select_fd (SANE_Handle handle, SANE_Int * fd) { - handle = handle; - fd = fd; /* silence compilation warnings */ + (void) handle; + (void) fd; /* silence compilation warnings */ return SANE_STATUS_UNSUPPORTED; } diff --git a/backend/sm3600-scanusb.c b/backend/sm3600-scanusb.c index dc9b8d5..997b8ee 100644 --- a/backend/sm3600-scanusb.c +++ b/backend/sm3600-scanusb.c @@ -66,7 +66,7 @@ static int TransferControlMsg(TInstance *this, { SANE_Status err; - cJiffiesTimeout = cJiffiesTimeout; + (void) cJiffiesTimeout; err = sanei_usb_control_msg (this->hScanner, nReqType, @@ -95,8 +95,8 @@ static int TransferBulkRead(TInstance *this, int err; size_t sz = cchMax; - nEndPoint = nEndPoint; - cJiffiesTimeout = cJiffiesTimeout; + (void) nEndPoint; + (void) cJiffiesTimeout; err = sanei_usb_read_bulk(this->hScanner, pBuffer, diff --git a/backend/sm3600.c b/backend/sm3600.c index e1df6b0..0644b5d 100644 --- a/backend/sm3600.c +++ b/backend/sm3600.c @@ -385,7 +385,7 @@ sane_init (SANE_Int *version_code, SANE_Auth_Callback authCB) DBG_INIT(); - authCB=authCB; /* compiler */ + (void) authCB; /* compiler */ DBG(DEBUG_VERBOSE,"SM3600 init\n"); if (version_code) @@ -783,7 +783,7 @@ sane_cancel (SANE_Handle handle) SANE_Status sane_set_io_mode(SANE_Handle h, SANE_Bool m) { - h=h; + (void) h; if (m==SANE_TRUE) /* no non-blocking-mode */ return SANE_STATUS_UNSUPPORTED; return SANE_STATUS_GOOD; @@ -792,6 +792,6 @@ sane_set_io_mode(SANE_Handle h, SANE_Bool m) SANE_Status sane_get_select_fd(SANE_Handle handle, SANE_Int *fd) { - handle=handle; fd=fd; + (void) handle; (void) fd; return SANE_STATUS_UNSUPPORTED; /* we have no file IO */ } diff --git a/backend/sm3840.c b/backend/sm3840.c index 159f600..672fb92 100644 --- a/backend/sm3840.c +++ b/backend/sm3840.c @@ -145,11 +145,12 @@ sane_read (SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, unsigned char c, d; int i; - DBG (2, "+sane-read:%p %p %d %p\n", (unsigned char *) s, buf, max_len, - (unsigned char *) len); + DBG (2, "+sane-read:%p %p %d %p\n", (void *) s, (void *) buf, max_len, + (void *) len); DBG (2, "+sane-read:remain:%lu offset:%lu linesleft:%d linebuff:%p linesread:%d\n", - (u_long)s->remaining, (u_long)s->offset, s->linesleft, s->line_buffer, s->linesread); + (u_long) s->remaining, (u_long) s->offset, s->linesleft, + (void *) s->line_buffer, s->linesread); if (!s->scanning) return SANE_STATUS_INVAL; @@ -798,7 +799,7 @@ sane_open (SANE_String_Const devicename, SANE_Handle * handle) /* empty devicename -> use first device */ dev = first_dev; } - DBG (2, "using device: %s %p\n", dev->sane.name, (unsigned char *) dev); + DBG (2, "using device: %s %p\n", dev->sane.name, (void *) dev); if (!dev) return SANE_STATUS_INVAL; s = calloc (sizeof (*s), 1); diff --git a/backend/sm3840_lib.c b/backend/sm3840_lib.c index 46d9910..80fcec7 100644 --- a/backend/sm3840_lib.c +++ b/backend/sm3840_lib.c @@ -64,8 +64,8 @@ my_usb_bulk_write (p_usb_dev_handle dev, int ep, SANE_Status status; size_t my_size; - timeout = timeout; - ep = ep; + (void) timeout; + (void) ep; my_size = size; status = sanei_usb_write_bulk ((SANE_Int) dev, (SANE_Byte *) bytes, &my_size); @@ -81,8 +81,8 @@ my_usb_bulk_read (p_usb_dev_handle dev, int ep, SANE_Status status; size_t my_size; - timeout = timeout; - ep = ep; + (void) timeout; + (void) ep; my_size = size; status = sanei_usb_read_bulk ((SANE_Int) dev, (SANE_Byte *) bytes, &my_size); @@ -98,7 +98,7 @@ my_usb_control_msg (p_usb_dev_handle dev, int requesttype, { SANE_Status status; - timeout = timeout; + (void) timeout; status = sanei_usb_control_msg ((SANE_Int) dev, (SANE_Int) requesttype, (SANE_Int) request, (SANE_Int) value, (SANE_Int) index, (SANE_Int) size, @@ -200,9 +200,8 @@ idle_ab (p_usb_dev_handle udev) /* CW: 40 04 00b0 0000 <len> : <reg1> <value1> <reg2> <value2> ... */ static void -write_regs (p_usb_dev_handle udev, int regs, unsigned char reg1, - unsigned char val1, - ... /*unsigned char reg, unsigned char val, ... */ ) +write_regs (p_usb_dev_handle udev, int regs, int reg1, int val1, + ... /* int reg, int val, ... */ ) { unsigned char buff[512]; va_list marker; diff --git a/backend/sm3840_lib.h b/backend/sm3840_lib.h index cbbc6d3..5630066 100644 --- a/backend/sm3840_lib.h +++ b/backend/sm3840_lib.h @@ -81,9 +81,8 @@ static int my_usb_control_msg (p_usb_dev_handle dev, int requesttype, #include "sm3840_params.h" static void idle_ab (p_usb_dev_handle udev); -static void write_regs (p_usb_dev_handle udev, int regs, unsigned char reg1, - unsigned char val1, - ... /*unsigned char reg, unsigned char val, ... */ ); +static void write_regs (p_usb_dev_handle udev, int regs, int reg1, int val1, + ... /* int reg, int val, ... */ ); static int write_vctl (p_usb_dev_handle udev, int request, int value, int index, unsigned char byte); static int read_vctl (p_usb_dev_handle udev, int request, int value, @@ -122,9 +121,8 @@ static void set_gain_black (p_usb_dev_handle udev, int r_black, int g_black, int b_black); static void idle_ab (p_usb_dev_handle udev); -static void write_regs (p_usb_dev_handle udev, int regs, unsigned char reg1, - unsigned char val1, - ... /*unsigned char reg, unsigned char val, ... */ ); +static void write_regs (p_usb_dev_handle udev, int regs, int reg1, int val1, + ... /* int reg, int val, ... */ ); static int write_vctl (p_usb_dev_handle udev, int request, int value, int index, unsigned char byte); static int read_vctl (p_usb_dev_handle udev, int request, int value, diff --git a/backend/snapscan-options.c b/backend/snapscan-options.c index 6bccf38..719c1e4 100644 --- a/backend/snapscan-options.c +++ b/backend/snapscan-options.c @@ -1107,7 +1107,7 @@ SANE_Status sane_control_option (SANE_Handle h, "%s: writing \"%s\" to location %p\n", me, pss->mode_s, - (SANE_String) v); + (void *) v); strcpy ((SANE_String) v, pss->mode_s); break; case OPT_PREVIEW_MODE: @@ -1115,7 +1115,7 @@ SANE_Status sane_control_option (SANE_Handle h, "%s: writing \"%s\" to location %p\n", me, pss->preview_mode_s, - (SANE_String) v); + (void *) v); strcpy ((SANE_String) v, pss->preview_mode_s); break; case OPT_SOURCE: @@ -1144,7 +1144,7 @@ SANE_Status sane_control_option (SANE_Handle h, "%s: writing \"%s\" to location %p\n", me, pss->predef_window, - (SANE_String) v); + (void *) v); strcpy ((SANE_String) v, pss->predef_window); break; case OPT_GAMMA_GS: @@ -1179,7 +1179,7 @@ SANE_Status sane_control_option (SANE_Handle h, "%s: writing \"%s\" to location %p\n", me, pss->dither_matrix, - (SANE_String) v); + (void *) v); strcpy ((SANE_String) v, pss->dither_matrix); break; case OPT_NEGATIVE: diff --git a/backend/snapscan-scsi.c b/backend/snapscan-scsi.c index d223f6a..a3fd4d0 100644 --- a/backend/snapscan-scsi.c +++ b/backend/snapscan-scsi.c @@ -144,7 +144,6 @@ static SANE_Status sense_handler (int scsi_fd, u_char * result, void *arg) as_str = "Logical unit is in process of becoming ready."; DBG (DL_MINOR_INFO, "%s: %s (%d seconds)\n", me, as_str, result[18]); status = SANE_STATUS_DEVICE_BUSY; - DBG (DL_MINOR_INFO, "%s: %s\n", me, sense_str); } break; case 0x04: @@ -160,8 +159,10 @@ static SANE_Status sense_handler (int scsi_fd, u_char * result, void *arg) sense_str = "Illegal request."; DBG (DL_MINOR_INFO, "%s: %s\n", me, sense_str); if (asc == 0x25 && ascq == 0x00) + { as_str = "Logical unit not supported."; DBG (DL_MINOR_INFO, "%s: %s\n", me, as_str); + } status = SANE_STATUS_IO_ERROR; break; case 0x09: diff --git a/backend/sp15c-scsi.h b/backend/sp15c-scsi.h index 1d3e0a1..03fee55 100644 --- a/backend/sp15c-scsi.h +++ b/backend/sp15c-scsi.h @@ -209,9 +209,12 @@ static scsiblk inquiryB = #define get_IN_response_format(in) getbitfield(in + 0x03, 0x0f, 0) #define IN_recognized 0x02 #define get_IN_additional_length(in) in[0x04] -#define get_IN_vendor(in, buf) strncpy(buf, in + 0x08, 0x08) -#define get_IN_product(in, buf) strncpy(buf, in + 0x10, 0x010) -#define get_IN_version(in, buf) strncpy(buf, in + 0x20, 0x04) +#define get_IN_vendor(in, buf) snprintf(buf, 0x08 + 1, "%.*s", \ + 0x08, in + 0x08) +#define get_IN_product(in, buf) snprintf(buf, 0x10 + 1, "%.*s", \ + 0x10, in + 0x10) +#define get_IN_version(in, buf) snprintf(buf, 0x04 + 1, "%.*s", \ + 0x04, in + 0x20) #define get_IN_color_mode(in) getbitfield(in + 0x24, 0xf, 0) #define get_IN_color_seq(in) getbitfield(in + 0x24, 0x7, 4) #define get_IN_adf(in) getbitfield(in + 0x24, 0x1, 7) diff --git a/backend/sp15c.c b/backend/sp15c.c index a3ad5c2..bf3ce29 100644 --- a/backend/sp15c.c +++ b/backend/sp15c.c @@ -273,7 +273,7 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize) char dev_name[PATH_MAX]; size_t len; FILE *fp; - authorize = authorize; /* silence compilation warnings */ + (void) authorize; /* silence compilation warnings */ DBG_INIT (); DBG (10, "sane_init\n"); @@ -310,7 +310,7 @@ sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only) struct sp15c *dev; int i; - local_only = local_only; /* silence compilation warnings */ + (void) local_only; /* silence compilation warnings */ DBG (10, "sane_get_devices\n"); @@ -335,7 +335,7 @@ sane_open (SANE_String_Const name, SANE_Handle * handle) { struct sp15c *dev = first_dev; - name = name; /* silence compilation warnings */ + (void) name; /* silence compilation warnings */ /* Strange, name is not used? */ DBG (10, "sane_open\n"); @@ -388,8 +388,8 @@ sane_open (SANE_String_Const name, SANE_Handle * handle) SANE_Status sane_set_io_mode (SANE_Handle h, SANE_Bool non_blocking) { - h = h; - non_blocking = non_blocking; /* silence compilation warnings */ + (void) h; + (void) non_blocking; /* silence compilation warnings */ DBG (10, "sane_set_io_mode\n"); return SANE_STATUS_UNSUPPORTED; @@ -399,8 +399,8 @@ sane_set_io_mode (SANE_Handle h, SANE_Bool non_blocking) SANE_Status sane_get_select_fd (SANE_Handle h, SANE_Int * fdp) { - h = h; - fdp = fdp; /* silence compilation warnings */ + (void) h; + (void) fdp; /* silence compilation warnings */ DBG (10, "sane_get_select_fd\n"); return SANE_STATUS_UNSUPPORTED; @@ -1080,8 +1080,8 @@ attach_one (const char *name) static SANE_Status sense_handler (int scsi_fd, u_char * result, void *arg) { - scsi_fd = scsi_fd; - arg = arg; /* silence compilation warnings */ + (void) scsi_fd; + (void) arg; /* silence compilation warnings */ return request_sense_parse (result); } /* sense_handler */ @@ -1783,7 +1783,7 @@ do_cancel (struct sp15c *scanner) static void swap_res (struct sp15c *s) { - s = s; /* silence compilation warnings */ + (void) s; /* silence compilation warnings */ /* for the time being, do nothing */ } /* swap_res */ @@ -1815,7 +1815,7 @@ sp15c_set_window_param (struct sp15c *s, int prescan) int ret; int active_buffer_size; - prescan = prescan; /* silence compilation warnings */ + (void) prescan; /* silence compilation warnings */ wait_scanner (s); DBG (10, "set_window_param\n"); @@ -1950,7 +1950,7 @@ sp15c_start_scan (struct sp15c *s) static void sigterm_handler (int signal) { - signal = signal; /* silence compilation warnings */ + (void) signal; /* silence compilation warnings */ sanei_scsi_req_flush_all (); /* flush SCSI queue */ _exit (SANE_STATUS_GOOD); diff --git a/backend/st400.c b/backend/st400.c index a75807f..a568e5d 100644 --- a/backend/st400.c +++ b/backend/st400.c @@ -439,8 +439,8 @@ st400_sense_handler( int fd, SANE_Byte *result, void *arg ) /* ST400_Device *dev = arg; */ SANE_Status status; - fd = fd; - arg = arg; /* silence compilation warnings */ + (void) fd; + (void) arg; /* silence compilation warnings */ switch( result[0] & 0x0f ) { case 0x0: @@ -563,7 +563,7 @@ st400_config_get_arg(char **optP, unsigned long *argP, size_t linenum) { int n; - linenum = linenum; /* silence compilation warnings */ + (void) linenum; /* silence compilation warnings */ if( sscanf(*optP, "%lu%n", argP, &n) == 1 ) { *optP += n; @@ -1221,7 +1221,7 @@ sane_read( SANE_Handle handle, SANE_Byte *buf, SANE_Int maxlen, SANE_Int *lenP ) size_t r, i; SANE_Byte val; - DBG(DCODE, "sane_read(%p, %p, %d, %p)\n", handle, buf, (int)maxlen, (void *) lenP); + DBG(DCODE, "sane_read(%p, %p, %d, %p)\n", handle, (void *) buf, (int) maxlen, (void *) lenP); *lenP = 0; if( !dev->status.scanning ) diff --git a/backend/stv680.c b/backend/stv680.c index eb9add5..02ff39d 100644 --- a/backend/stv680.c +++ b/backend/stv680.c @@ -1439,7 +1439,7 @@ stv680_bayer_unshuffle (Stv680_Vidcam * dev, SANE_Byte * buf, size_t * size) "stv680_bayer_unshuffle: if needed, trim to size 160 done\n"); } /* reset to proper width */ - if ((dev->subsample == 160)) + if (dev->subsample == 160) { vw = 160; vh = 120; @@ -1520,7 +1520,7 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize) DBG (DBG_sane_init, "sane_init\n"); - authorize = authorize; /* silence gcc */ + (void) authorize; /* silence gcc */ DBG (DBG_error, "This is sane-stv680 version %d.%d-%d\n", SANE_CURRENT_MAJOR, SANE_CURRENT_MINOR, BUILD); @@ -1584,7 +1584,7 @@ sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only) DBG (DBG_proc, "sane_get_devices: enter\n"); - local_only = local_only; /* silence gcc */ + (void) local_only; /* silence gcc */ if (devlist) free (devlist); @@ -2073,8 +2073,8 @@ sane_set_io_mode (SANE_Handle handle, SANE_Bool non_blocking) DBG (DBG_proc, "sane_set_io_mode: enter\n"); - handle = handle; /* silence gcc */ - non_blocking = non_blocking; /* silence gcc */ + (void) handle; /* silence gcc */ + (void) non_blocking; /* silence gcc */ DBG (DBG_proc, "sane_set_io_mode: exit\n"); @@ -2087,8 +2087,8 @@ sane_get_select_fd (SANE_Handle handle, SANE_Int * fd) { DBG (DBG_proc, "sane_get_select_fd: enter\n"); - handle = handle; /* silence gcc */ - fd = fd; /* silence gcc */ + (void) handle; /* silence gcc */ + (void) fd; /* silence gcc */ DBG (DBG_proc, "sane_get_select_fd: exit\n"); diff --git a/backend/tamarack.c b/backend/tamarack.c index 38cc7ea..916c9ea 100644 --- a/backend/tamarack.c +++ b/backend/tamarack.c @@ -182,8 +182,8 @@ wait_ready (int fd) static SANE_Status sense_handler (int scsi_fd, u_char *result, void *arg) { - scsi_fd = scsi_fd; - arg = arg; /* silence compilation warnings */ + (void) scsi_fd; + (void) arg; /* silence compilation warnings */ switch (result[0]) { @@ -909,7 +909,7 @@ sane_init (SANE_Int *version_code, SANE_Auth_Callback authorize) size_t len; FILE *fp; - authorize = authorize; /* silence compilation warnings */ + (void) authorize; /* silence compilation warnings */ DBG_INIT(); @@ -962,7 +962,7 @@ sane_get_devices (const SANE_Device ***device_list, SANE_Bool local_only) Tamarack_Device *dev; int i; - local_only = local_only; /* silence compilation warnings */ + (void) local_only; /* silence compilation warnings */ if (devlist) free (devlist); diff --git a/backend/test-picture.c b/backend/test-picture.c index d9549ec..49445ac 100644 --- a/backend/test-picture.c +++ b/backend/test-picture.c @@ -48,7 +48,8 @@ init_picture_buffer (Test_Device * test_device, SANE_Byte ** buffer, size_t * buffer_size) { SANE_Word pattern_size = 0, pattern_distance = 0; - SANE_Word line_count, b_size; + SANE_Word line_count; + size_t b_size; SANE_Word lines = 0; SANE_Word bpl = test_device->bytes_per_line; SANE_Word ppl = test_device->pixels_per_line; @@ -83,7 +84,7 @@ init_picture_buffer (Test_Device * test_device, SANE_Byte ** buffer, if (strcmp (test_device->val[opt_test_picture].s, "Solid black") == 0) { DBG (3, "(child) init_picture_buffer: drawing solid black test " - "picture %d bytes\n", b_size); + "picture %zu bytes\n", b_size); if (test_device->params.format == SANE_FRAME_GRAY && test_device->params.depth == 1) pattern = 0xff; @@ -93,7 +94,7 @@ init_picture_buffer (Test_Device * test_device, SANE_Byte ** buffer, else { DBG (3, "(child) init_picture_buffer: drawing solid white test " - "picture %d bytes\n", b_size); + "picture %zu bytes\n", b_size); if (test_device->params.format == SANE_FRAME_GRAY && test_device->params.depth == 1) pattern = 0x00; @@ -115,8 +116,8 @@ init_picture_buffer (Test_Device * test_device, SANE_Byte ** buffer, if (test_device->params.depth == 16) increment *= 2; - lines = 2 * p_size + 0.5; - b_size = lines * bpl; + lines = (SANE_Word) (2 * p_size + 0.5); + b_size = (size_t) lines * (size_t) bpl; if (buffer_size) *buffer_size = b_size; b = malloc (b_size); @@ -128,7 +129,7 @@ init_picture_buffer (Test_Device * test_device, SANE_Byte ** buffer, if (buffer) *buffer = b; DBG (3, "(child) init_picture_buffer: drawing grid test picture " - "%d bytes, %d bpl, %d ppl, %d lines\n", b_size, bpl, ppl, lines); + "%zu bytes, %d bpl, %d ppl, %d lines\n", b_size, bpl, ppl, lines); for (line_count = 0; line_count < lines; line_count++) { @@ -161,7 +162,7 @@ init_picture_buffer (Test_Device * test_device, SANE_Byte ** buffer, } else color = (rand ()) & 0x01; - value |= (color << x1); + value |= (SANE_Byte) (color << x1); } b[line_count * bpl + x] = value; } @@ -182,7 +183,7 @@ init_picture_buffer (Test_Device * test_device, SANE_Byte ** buffer, } else color = (rand ()) & 0x01; - value |= (color << x1); + value |= (SANE_Byte) (color << x1); } for (x1 = 0; x1 < increment; x1++) b[line_count * bpl + x + x1] = value; @@ -197,7 +198,7 @@ init_picture_buffer (Test_Device * test_device, SANE_Byte ** buffer, else color = 0xff; else - color = (rand ()) & 0xff; + color = (SANE_Byte) ((rand ()) & 0xff); for (x1 = 0; x1 < increment; x1++) b[line_count * bpl + x + x1] = color; @@ -215,7 +216,7 @@ init_picture_buffer (Test_Device * test_device, SANE_Byte ** buffer, pattern_size = 16; pattern_distance = 0; lines = 2 * (pattern_size + pattern_distance); - b_size = lines * bpl; + b_size = (size_t) lines * (size_t) bpl; if (buffer_size) *buffer_size = b_size; @@ -228,7 +229,7 @@ init_picture_buffer (Test_Device * test_device, SANE_Byte ** buffer, if (buffer) *buffer = b; DBG (3, "(child) init_picture_buffer: drawing b/w test picture " - "%d bytes, %d bpl, %d lines\n", b_size, bpl, lines); + "%zu bytes, %d bpl, %d lines\n", b_size, bpl, lines); memset (b, 255, b_size); for (line_count = 0; line_count < lines; line_count++) { @@ -244,7 +245,7 @@ init_picture_buffer (Test_Device * test_device, SANE_Byte ** buffer, width = pattern_size / 8; if (x + width >= bpl) width = bpl - x; - memset (b + line_count * bpl + x, 0x00, width); + memset (b + line_count * bpl + x, 0x00, (size_t) width); x += (pattern_size + pattern_distance) * 2 / 8; } } @@ -256,7 +257,7 @@ init_picture_buffer (Test_Device * test_device, SANE_Byte ** buffer, pattern_size = 4; pattern_distance = 1; lines = 2 * (pattern_size + pattern_distance); - b_size = lines * bpl; + b_size = (size_t) lines * (size_t) bpl; if (buffer_size) *buffer_size = b_size; @@ -269,7 +270,7 @@ init_picture_buffer (Test_Device * test_device, SANE_Byte ** buffer, if (buffer) *buffer = b; DBG (3, "(child) init_picture_buffer: drawing 8 bit gray test picture " - "%d bytes, %d bpl, %d lines\n", b_size, bpl, lines); + "%zu bytes, %d bpl, %d lines\n", b_size, bpl, lines); memset (b, 0x55, b_size); for (line_count = 0; line_count < lines; line_count++) { @@ -289,10 +290,10 @@ init_picture_buffer (Test_Device * test_device, SANE_Byte ** buffer, width = bpl - x; if (line_count > (pattern_size + pattern_distance)) color = - 0xff - ((x / (pattern_size + pattern_distance)) & 0xff); + (SANE_Byte) (0xff - ((x / (pattern_size + pattern_distance)) & 0xff)); else - color = (x / (pattern_size + pattern_distance)) & 0xff; - memset (b + line_count * bpl + x, color, width); + color = (SANE_Byte) ((x / (pattern_size + pattern_distance)) & 0xff); + memset (b + line_count * bpl + x, color, (size_t) width); x += (pattern_size + pattern_distance); } } @@ -305,7 +306,7 @@ init_picture_buffer (Test_Device * test_device, SANE_Byte ** buffer, pattern_size = 256; pattern_distance = 4; lines = 1 * (pattern_size + pattern_distance); - b_size = lines * bpl; + b_size = (size_t) lines * (size_t) bpl; if (buffer_size) *buffer_size = b_size; @@ -318,7 +319,7 @@ init_picture_buffer (Test_Device * test_device, SANE_Byte ** buffer, if (buffer) *buffer = b; DBG (3, "(child) init_picture_buffer: drawing 16 bit gray test picture " - "%d bytes, %d bpl, %d lines\n", b_size, bpl, lines); + "%zu bytes, %d bpl, %d lines\n", b_size, bpl, lines); memset (b, 0x55, b_size); for (line_count = 0; line_count < lines; line_count++) { @@ -338,11 +339,11 @@ init_picture_buffer (Test_Device * test_device, SANE_Byte ** buffer, if (x + width >= bpl) width = bpl - x; pattern_lo = - ((line_count - pattern_distance) - % (pattern_size + pattern_distance)) & 0xff; + (SANE_Byte) (((line_count - pattern_distance) + % (pattern_size + pattern_distance)) & 0xff); for (x1 = 0; x1 < width; x1 += 2) { - pattern_hi = (x1 / 2) & 0xff; + pattern_hi = (SANE_Byte) ((x1 / 2) & 0xff); if (is_little_endian) { b[line_count * bpl + x + x1 + 0] = pattern_lo; @@ -366,7 +367,7 @@ init_picture_buffer (Test_Device * test_device, SANE_Byte ** buffer, pattern_size = 16; pattern_distance = 0; lines = 2 * (pattern_size + pattern_distance); - b_size = lines * bpl; + b_size = (size_t) lines * (size_t) bpl; if (buffer_size) *buffer_size = b_size; @@ -379,7 +380,7 @@ init_picture_buffer (Test_Device * test_device, SANE_Byte ** buffer, if (buffer) *buffer = b; DBG (3, "(child) init_picture_buffer: drawing color lineart test " - "picture %d bytes, %d bpl, %d lines\n", b_size, bpl, lines); + "picture %zu bytes, %d bpl, %d lines\n", b_size, bpl, lines); memset (b, 0x55, b_size); for (line_count = 0; line_count < lines; line_count++) @@ -433,7 +434,7 @@ init_picture_buffer (Test_Device * test_device, SANE_Byte ** buffer, pattern_size = 16; pattern_distance = 0; lines = 2 * (pattern_size + pattern_distance); - b_size = lines * bpl; + b_size = (size_t) lines * (size_t) bpl; if (buffer_size) *buffer_size = b_size; @@ -446,7 +447,7 @@ init_picture_buffer (Test_Device * test_device, SANE_Byte ** buffer, if (buffer) *buffer = b; DBG (3, "(child) init_picture_buffer: drawing color lineart three-pass " - "test picture %d bytes, %d bpl, %d lines\n", b_size, bpl, lines); + "test picture %zu bytes, %d bpl, %d lines\n", b_size, bpl, lines); memset (b, 0x55, b_size); for (line_count = 0; line_count < lines; line_count++) @@ -501,7 +502,7 @@ init_picture_buffer (Test_Device * test_device, SANE_Byte ** buffer, pattern_size = 4; pattern_distance = 1; lines = 6 * (pattern_size + pattern_distance); - b_size = lines * bpl; + b_size = (size_t) lines * (size_t) bpl; if (buffer_size) *buffer_size = b_size; @@ -514,7 +515,7 @@ init_picture_buffer (Test_Device * test_device, SANE_Byte ** buffer, if (buffer) *buffer = b; DBG (3, "(child) init_picture_buffer: drawing 8 bit color test picture " - "%d bytes, %d bpl, %d lines\n", b_size, bpl, lines); + "%zu bytes, %d bpl, %d lines\n", b_size, bpl, lines); memset (b, 0x55, b_size); for (line_count = 0; line_count < lines; line_count++) { @@ -536,10 +537,10 @@ init_picture_buffer (Test_Device * test_device, SANE_Byte ** buffer, if ((line_count / (pattern_size + pattern_distance)) & 1) color = - 0xff - ((x / ((pattern_size + pattern_distance) * 3)) - & 0xff); + (SANE_Byte) (0xff - ((x / ((pattern_size + pattern_distance) * 3)) + & 0xff)); else - color = (x / ((pattern_size + pattern_distance) * 3)) & 0xff; + color = (SANE_Byte) ((x / ((pattern_size + pattern_distance) * 3)) & 0xff); if (line_count / (pattern_size + pattern_distance) < 2) { @@ -581,7 +582,7 @@ init_picture_buffer (Test_Device * test_device, SANE_Byte ** buffer, pattern_size = 4; pattern_distance = 1; lines = 6 * (pattern_size + pattern_distance); - b_size = lines * bpl; + b_size = (size_t) lines * (size_t) bpl; if (buffer_size) *buffer_size = b_size; @@ -594,7 +595,7 @@ init_picture_buffer (Test_Device * test_device, SANE_Byte ** buffer, if (buffer) *buffer = b; DBG (3, "(child) init_picture_buffer: drawing 8 bit color three-pass " - "test picture %d bytes, %d bpl, %d lines\n", b_size, bpl, lines); + "test picture %zu bytes, %d bpl, %d lines\n", b_size, bpl, lines); memset (b, 0x55, b_size); for (line_count = 0; line_count < lines; line_count++) { @@ -614,10 +615,10 @@ init_picture_buffer (Test_Device * test_device, SANE_Byte ** buffer, width = bpl - x; if ((line_count / (pattern_size + pattern_distance)) & 1) - color = - 0xff - (x / ((pattern_size + pattern_distance)) & 0xff); + color = (SANE_Byte) + (0xff - (x / ((pattern_size + pattern_distance)) & 0xff)); else - color = (x / (pattern_size + pattern_distance)) & 0xff; + color = (SANE_Byte) ((x / (pattern_size + pattern_distance)) & 0xff); if (line_count / (pattern_size + pattern_distance) < 2) { @@ -634,7 +635,7 @@ init_picture_buffer (Test_Device * test_device, SANE_Byte ** buffer, if (test_device->params.format != SANE_FRAME_BLUE) color = 0x00; } - memset (b + line_count * bpl + x, color, width); + memset (b + line_count * bpl + x, color, (size_t) width); x += (pattern_size + pattern_distance); } @@ -647,7 +648,7 @@ init_picture_buffer (Test_Device * test_device, SANE_Byte ** buffer, pattern_size = 256; pattern_distance = 4; lines = pattern_size + pattern_distance; - b_size = lines * bpl; + b_size = (size_t) lines * (size_t) bpl; if (buffer_size) *buffer_size = b_size; @@ -661,7 +662,7 @@ init_picture_buffer (Test_Device * test_device, SANE_Byte ** buffer, *buffer = b; DBG (3, "(child) init_picture_buffer: drawing 16 bit color test picture " - "%d bytes, %d bpl, %d lines\n", b_size, bpl, lines); + "%zu bytes, %d bpl, %d lines\n", b_size, bpl, lines); memset (b, 0x55, b_size); for (line_count = 0; line_count < lines; line_count++) { @@ -687,10 +688,10 @@ init_picture_buffer (Test_Device * test_device, SANE_Byte ** buffer, for (x1 = 0; x1 < width; x1 += 6) { - color_lo = - ((line_count + pattern_size) - % (pattern_size + pattern_distance)) & 0xff; - color_hi = (x1 / 6) & 0xff; + color_lo = (SANE_Byte) + (((line_count + pattern_size) + % (pattern_size + pattern_distance)) & 0xff); + color_hi = (SANE_Byte) ((x1 / 6) & 0xff); if (((x / ((pattern_size + pattern_distance) * 6)) % 3) == 0) { @@ -753,7 +754,7 @@ init_picture_buffer (Test_Device * test_device, SANE_Byte ** buffer, pattern_size = 256; pattern_distance = 4; lines = pattern_size + pattern_distance; - b_size = lines * bpl; + b_size = (size_t) lines * (size_t) bpl; if (buffer_size) *buffer_size = b_size; @@ -766,7 +767,7 @@ init_picture_buffer (Test_Device * test_device, SANE_Byte ** buffer, if (buffer) *buffer = b; DBG (3, "(child) init_picture_buffer: drawing 16 bit color three-pass " - "test picture %d bytes, %d bpl, %d lines\n", b_size, bpl, lines); + "test picture %zu bytes, %d bpl, %d lines\n", b_size, bpl, lines); memset (b, 0x55, b_size); for (line_count = 0; line_count < lines; line_count++) { @@ -789,10 +790,10 @@ init_picture_buffer (Test_Device * test_device, SANE_Byte ** buffer, for (x1 = 0; x1 < width; x1 += 2) { - color_lo = - ((line_count + pattern_size) - % (pattern_size + pattern_distance)) & 0xff; - color_hi = (x1 / 2) & 0xff; + color_lo = (SANE_Byte) + (((line_count + pattern_size) + % (pattern_size + pattern_distance)) & 0xff); + color_hi = (SANE_Byte) ((x1 / 2) & 0xff); if (((x / ((pattern_size + pattern_distance) * 2)) % 3) == 0) { diff --git a/backend/test.c b/backend/test.c index 3c7a949..ea73290 100644 --- a/backend/test.c +++ b/backend/test.c @@ -391,11 +391,11 @@ init_options (Test_Device * test_device) od->desc = SANE_DESC_SCAN_MODE; od->type = SANE_TYPE_STRING; od->unit = SANE_UNIT_NONE; - od->size = max_string_size (mode_list); + od->size = (SANE_Int) max_string_size (mode_list); od->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_SOFT_SELECT; od->constraint_type = SANE_CONSTRAINT_STRING_LIST; od->constraint.string_list = mode_list; - test_device->val[opt_mode].s = malloc (od->size); + test_device->val[opt_mode].s = malloc ((size_t) od->size); if (!test_device->val[opt_mode].s) goto fail; strcpy (test_device->val[opt_mode].s, init_mode); @@ -454,7 +454,7 @@ init_options (Test_Device * test_device) od->desc = SANE_I18N ("Set the order of frames in three-pass color mode."); od->type = SANE_TYPE_STRING; od->unit = SANE_UNIT_NONE; - od->size = max_string_size (order_list); + od->size = (SANE_Int) max_string_size (order_list); od->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_SOFT_SELECT; if (strcmp (init_mode, SANE_VALUE_SCAN_MODE_COLOR) != 0) od->cap |= SANE_CAP_INACTIVE; @@ -462,7 +462,7 @@ init_options (Test_Device * test_device) od->cap |= SANE_CAP_INACTIVE; od->constraint_type = SANE_CONSTRAINT_STRING_LIST; od->constraint.string_list = order_list; - test_device->val[opt_three_pass_order].s = malloc (od->size); + test_device->val[opt_three_pass_order].s = malloc ((size_t) od->size); if (!test_device->val[opt_three_pass_order].s) goto fail; strcpy (test_device->val[opt_three_pass_order].s, init_three_pass_order); @@ -487,11 +487,11 @@ init_options (Test_Device * test_device) od->desc = SANE_I18N("If Automatic Document Feeder is selected, the feeder will be 'empty' after 10 scans."); od->type = SANE_TYPE_STRING; od->unit = SANE_UNIT_NONE; - od->size = max_string_size (source_list); + od->size = (SANE_Int) max_string_size (source_list); od->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_SOFT_SELECT; od->constraint_type = SANE_CONSTRAINT_STRING_LIST; od->constraint.string_list = source_list; - test_device->val[opt_scan_source].s = malloc (od->size); + test_device->val[opt_scan_source].s = malloc ((size_t) od->size); if (!test_device->val[opt_scan_source].s) goto fail; strcpy (test_device->val[opt_scan_source].s, init_scan_source); @@ -523,11 +523,11 @@ init_options (Test_Device * test_device) "height of 10 mm per square."); od->type = SANE_TYPE_STRING; od->unit = SANE_UNIT_NONE; - od->size = max_string_size (test_picture_list); + od->size = (SANE_Int) max_string_size (test_picture_list); od->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_SOFT_SELECT; od->constraint_type = SANE_CONSTRAINT_STRING_LIST; od->constraint.string_list = test_picture_list; - test_device->val[opt_test_picture].s = malloc (od->size); + test_device->val[opt_test_picture].s = malloc ((size_t) od->size); if (!test_device->val[opt_test_picture].s) goto fail; strcpy (test_device->val[opt_test_picture].s, init_test_picture); @@ -618,11 +618,11 @@ init_options (Test_Device * test_device) "codes are for testing how the frontend handles them."); od->type = SANE_TYPE_STRING; od->unit = SANE_UNIT_NONE; - od->size = max_string_size (read_status_code_list); + od->size = (SANE_Int) max_string_size (read_status_code_list); od->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_SOFT_SELECT; od->constraint_type = SANE_CONSTRAINT_STRING_LIST; od->constraint.string_list = read_status_code_list; - test_device->val[opt_read_status_code].s = malloc (od->size); + test_device->val[opt_read_status_code].s = malloc ((size_t) od->size); if (!test_device->val[opt_read_status_code].s) goto fail; strcpy (test_device->val[opt_read_status_code].s, init_read_status_code); @@ -914,8 +914,8 @@ init_options (Test_Device * test_device) /* opt_int */ od = &test_device->opt[opt_int]; od->name = "int"; - od->title = SANE_I18N ("(1/6) Int"); - od->desc = SANE_I18N ("(1/6) Int test option with no unit and no " + od->title = SANE_I18N ("(1/7) Int"); + od->desc = SANE_I18N ("(1/7) Int test option with no unit and no " "constraint set."); od->type = SANE_TYPE_INT; od->unit = SANE_UNIT_NONE; @@ -930,8 +930,8 @@ init_options (Test_Device * test_device) /* opt_int_constraint_range */ od = &test_device->opt[opt_int_constraint_range]; od->name = "int-constraint-range"; - od->title = SANE_I18N ("(2/6) Int constraint range"); - od->desc = SANE_I18N ("(2/6) Int test option with unit pixel and " + od->title = SANE_I18N ("(2/7) Int constraint range"); + od->desc = SANE_I18N ("(2/7) Int test option with unit pixel and " "constraint range set. Minimum is 4, maximum 192, and " "quant is 2."); od->type = SANE_TYPE_INT; @@ -947,8 +947,8 @@ init_options (Test_Device * test_device) /* opt_int_constraint_word_list */ od = &test_device->opt[opt_int_constraint_word_list]; od->name = "int-constraint-word-list"; - od->title = SANE_I18N ("(3/6) Int constraint word list"); - od->desc = SANE_I18N ("(3/6) Int test option with unit bits and " + od->title = SANE_I18N ("(3/7) Int constraint word list"); + od->desc = SANE_I18N ("(3/7) Int test option with unit bits and " "constraint word list set."); od->type = SANE_TYPE_INT; od->unit = SANE_UNIT_BIT; @@ -963,8 +963,8 @@ init_options (Test_Device * test_device) /* opt_int_array */ od = &test_device->opt[opt_int_array]; od->name = "int-constraint-array"; - od->title = SANE_I18N ("(4/6) Int array"); - od->desc = SANE_I18N ("(4/6) Int test option with unit mm and using " + od->title = SANE_I18N ("(4/7) Int array"); + od->desc = SANE_I18N ("(4/7) Int test option with unit mm and using " "an array without constraints."); od->type = SANE_TYPE_INT; od->unit = SANE_UNIT_MM; @@ -979,8 +979,8 @@ init_options (Test_Device * test_device) /* opt_int_array_constraint_range */ od = &test_device->opt[opt_int_array_constraint_range]; od->name = "int-constraint-array-constraint-range"; - od->title = SANE_I18N ("(5/6) Int array constraint range"); - od->desc = SANE_I18N ("(5/6) Int test option with unit dpi and using " + od->title = SANE_I18N ("(5/7) Int array constraint range"); + od->desc = SANE_I18N ("(5/7) Int test option with unit dpi and using " "an array with a range constraint. Minimum is 4, " "maximum 192, and quant is 2."); od->type = SANE_TYPE_INT; @@ -994,6 +994,40 @@ init_options (Test_Device * test_device) test_device->val[opt_int_array_constraint_range].wa = &int_array_constraint_range[0]; + /* opt_int_array_constraint_word_list */ + od = &test_device->opt[opt_int_array_constraint_word_list]; + od->name = "int-constraint-array-constraint-word-list"; + od->title = SANE_I18N ("(6/7) Int array constraint word list"); + od->desc = SANE_I18N ("(6/7) Int test option with unit percent and using " + "an array with a word list constraint."); + od->type = SANE_TYPE_INT; + od->unit = SANE_UNIT_PERCENT; + od->size = 6 * sizeof (SANE_Word); + od->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_SOFT_SELECT | SANE_CAP_ADVANCED; + if (init_enable_test_options == SANE_FALSE) + od->cap |= SANE_CAP_INACTIVE; + od->constraint_type = SANE_CONSTRAINT_WORD_LIST; + od->constraint.word_list = int_constraint_word_list; + test_device->val[opt_int_array_constraint_word_list].wa = + &int_array_constraint_word_list[0]; + + /* opt_int_inexact */ + od = &test_device->opt[opt_int_inexact]; + od->name = "int-inexact"; + od->title = SANE_I18N ("(7/7) Int inexact"); + od->desc = SANE_I18N ("(7/7) Int test option that modifies the value " + "and returns SANE_INFO_INEXACT."); + od->type = SANE_TYPE_INT; + od->unit = SANE_UNIT_NONE; + od->size = sizeof (SANE_Word); + od->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_SOFT_SELECT | SANE_CAP_ADVANCED; + if (init_enable_test_options == SANE_FALSE) + od->cap |= SANE_CAP_INACTIVE; + od->constraint_type = SANE_CONSTRAINT_NONE; + od->constraint.range = 0; + test_device->val[opt_int_inexact].w = 67; + + /* opt_gamma_red */ init_gamma_table(gamma_red, GAMMA_RED_SIZE, gamma_range.max); od = &test_device->opt[opt_gamma_red]; @@ -1051,23 +1085,6 @@ init_options (Test_Device * test_device) od->constraint.range = &gamma_range; test_device->val[opt_gamma_all].wa = &gamma_all[0]; - /* opt_int_array_constraint_word_list */ - od = &test_device->opt[opt_int_array_constraint_word_list]; - od->name = "int-constraint-array-constraint-word-list"; - od->title = SANE_I18N ("(6/6) Int array constraint word list"); - od->desc = SANE_I18N ("(6/6) Int test option with unit percent and using " - "an array with a word list constraint."); - od->type = SANE_TYPE_INT; - od->unit = SANE_UNIT_PERCENT; - od->size = 6 * sizeof (SANE_Word); - od->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_SOFT_SELECT | SANE_CAP_ADVANCED; - if (init_enable_test_options == SANE_FALSE) - od->cap |= SANE_CAP_INACTIVE; - od->constraint_type = SANE_CONSTRAINT_WORD_LIST; - od->constraint.word_list = int_constraint_word_list; - test_device->val[opt_int_array_constraint_word_list].wa = - &int_array_constraint_word_list[0]; - /* opt_fixed_group */ od = &test_device->opt[opt_fixed_group]; od->name = ""; @@ -1150,13 +1167,13 @@ init_options (Test_Device * test_device) od->desc = SANE_I18N ("(1/3) String test option without constraint."); od->type = SANE_TYPE_STRING; od->unit = SANE_UNIT_NONE; - od->size = strlen (init_string) + 1; + od->size = (SANE_Int) strlen (init_string) + 1; od->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_SOFT_SELECT; if (init_enable_test_options == SANE_FALSE) od->cap |= SANE_CAP_INACTIVE; od->constraint_type = SANE_CONSTRAINT_NONE; od->constraint.string_list = 0; - test_device->val[opt_string].s = malloc (od->size); + test_device->val[opt_string].s = malloc ((size_t) od->size); if (!test_device->val[opt_string].s) goto fail; strcpy (test_device->val[opt_string].s, init_string); @@ -1169,13 +1186,13 @@ init_options (Test_Device * test_device) "constraint."); od->type = SANE_TYPE_STRING; od->unit = SANE_UNIT_NONE; - od->size = max_string_size (string_constraint_string_list); + od->size = (SANE_Int) max_string_size (string_constraint_string_list); od->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_SOFT_SELECT; if (init_enable_test_options == SANE_FALSE) od->cap |= SANE_CAP_INACTIVE; od->constraint_type = SANE_CONSTRAINT_STRING_LIST; od->constraint.string_list = string_constraint_string_list; - test_device->val[opt_string_constraint_string_list].s = malloc (od->size); + test_device->val[opt_string_constraint_string_list].s = malloc ((size_t) od->size); if (!test_device->val[opt_string_constraint_string_list].s) goto fail; strcpy (test_device->val[opt_string_constraint_string_list].s, @@ -1189,14 +1206,14 @@ init_options (Test_Device * test_device) "constraint. Contains some more entries..."); od->type = SANE_TYPE_STRING; od->unit = SANE_UNIT_NONE; - od->size = max_string_size (string_constraint_long_string_list); + od->size = (SANE_Int) max_string_size (string_constraint_long_string_list); od->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_SOFT_SELECT; if (init_enable_test_options == SANE_FALSE) od->cap |= SANE_CAP_INACTIVE; od->constraint_type = SANE_CONSTRAINT_STRING_LIST; od->constraint.string_list = string_constraint_long_string_list; test_device->val[opt_string_constraint_long_string_list].s = - malloc (od->size); + malloc ((size_t) od->size); if (!test_device->val[opt_string_constraint_long_string_list].s) goto fail; strcpy (test_device->val[opt_string_constraint_long_string_list].s, @@ -1419,7 +1436,8 @@ static SANE_Status reader_process (Test_Device * test_device, SANE_Int fd) { SANE_Status status; - SANE_Word byte_count = 0, bytes_total; + size_t byte_count = 0; + size_t bytes_total; SANE_Byte *buffer = 0; ssize_t bytes_written = 0; size_t buffer_size = 0, write_count = 0; @@ -1427,24 +1445,24 @@ reader_process (Test_Device * test_device, SANE_Int fd) DBG (2, "(child) reader_process: test_device=%p, fd=%d\n", (void *) test_device, fd); - bytes_total = test_device->lines * test_device->bytes_per_line; + bytes_total = (size_t) test_device->lines * (size_t) test_device->bytes_per_line; status = init_picture_buffer (test_device, &buffer, &buffer_size); if (status != SANE_STATUS_GOOD) return status; DBG (2, "(child) reader_process: buffer=%p, buffersize=%lu\n", - buffer, (u_long) buffer_size); + (void *) buffer, (u_long) buffer_size); while (byte_count < bytes_total) { if (write_count == 0) { write_count = buffer_size; - if (byte_count + (SANE_Word) write_count > bytes_total) - write_count = bytes_total - byte_count; + if (byte_count + (size_t) write_count > bytes_total) + write_count = (size_t) bytes_total - (size_t) byte_count; if (test_device->val[opt_read_delay].w == SANE_TRUE) - usleep (test_device->val[opt_read_delay_duration].w); + usleep ((useconds_t) test_device->val[opt_read_delay_duration].w); } bytes_written = write (fd, buffer, write_count); if (bytes_written < 0) @@ -1453,17 +1471,17 @@ reader_process (Test_Device * test_device, SANE_Int fd) strerror (errno)); return SANE_STATUS_IO_ERROR; } - byte_count += bytes_written; - DBG (4, "(child) reader_process: wrote %ld bytes of %lu (%d total)\n", - (long) bytes_written, (u_long) write_count, byte_count); - write_count -= bytes_written; + byte_count += (size_t) bytes_written; + DBG (4, "(child) reader_process: wrote %ld bytes of %lu (%zu total)\n", + bytes_written, write_count, byte_count); + write_count -= (size_t) bytes_written; } free (buffer); if (sanei_thread_is_forked ()) { - DBG (4, "(child) reader_process: finished, wrote %d bytes, expected %d " + DBG (4, "(child) reader_process: finished, wrote %zu bytes, expected %zu " "bytes, now waiting\n", byte_count, bytes_total); while (SANE_TRUE) sleep (10); @@ -1472,7 +1490,7 @@ reader_process (Test_Device * test_device, SANE_Int fd) } else { - DBG (4, "(child) reader_process: finished, wrote %d bytes, expected %d " + DBG (4, "(child) reader_process: finished, wrote %zu bytes, expected %zu " "bytes\n", byte_count, bytes_total); } return SANE_STATUS_GOOD; @@ -1824,7 +1842,7 @@ sane_init (SANE_Int * __sane_unused__ version_code, SANE_Auth_Callback __sane_un /* create devices */ sane_device_list = - malloc ((init_number_of_devices + 1) * sizeof (sane_device)); + malloc ((size_t) (init_number_of_devices + 1) * sizeof (sane_device)); if (!sane_device_list) goto fail; for (num = 0; num < init_number_of_devices; num++) @@ -1862,7 +1880,7 @@ sane_init (SANE_Int * __sane_unused__ version_code, SANE_Auth_Callback __sane_un } test_device->next = 0; sane_device_list[num] = 0; - srand (time (NULL)); + srand ((unsigned int) time (NULL)); random_factor = ((double) rand ()) / RAND_MAX + 0.5; inited = SANE_TRUE; return SANE_STATUS_GOOD; @@ -2216,6 +2234,19 @@ sane_control_option (SANE_Handle handle, SANE_Int option, SANE_Action action, DBG (4, "sane_control_option: set option %d (%s) to %d\n", option, test_device->opt[option].name, *(SANE_Int *) value); break; + case opt_int_inexact: + if (test_device->val[option].w == *(SANE_Int *) value) + { + DBG (4, "sane_control_option: option %d (%s) not changed\n", + option, test_device->opt[option].name); + break; + } + *(SANE_Int *) value += 1; + test_device->val[option].w = *(SANE_Int *) value; + myinfo |= SANE_INFO_INEXACT; + DBG (4, "sane_control_option: set option %d (%s) to %d\n", + option, test_device->opt[option].name, *(SANE_Int *) value); + break; case opt_fuzzy_parameters: /* Bool with parameter reloading */ if (test_device->val[option].w == *(SANE_Bool *) value) { @@ -2312,7 +2343,7 @@ sane_control_option (SANE_Handle handle, SANE_Int option, SANE_Action action, case opt_gamma_all: case opt_int_array_constraint_word_list: memcpy (test_device->val[option].wa, value, - test_device->opt[option].size); + (size_t) test_device->opt[option].size); DBG (4, "sane_control_option: set option %d (%s) to %p\n", option, test_device->opt[option].name, (void *) value); if (option == opt_gamma_all) { @@ -2535,6 +2566,7 @@ sane_control_option (SANE_Handle handle, SANE_Int option, SANE_Action action, case opt_ppl_loss: case opt_read_delay_duration: case opt_int: + case opt_int_inexact: case opt_int_constraint_range: case opt_int_constraint_word_list: *(SANE_Int *) value = test_device->val[option].w; @@ -2549,7 +2581,7 @@ sane_control_option (SANE_Handle handle, SANE_Int option, SANE_Action action, case opt_gamma_all: case opt_int_array_constraint_word_list: memcpy (value, test_device->val[option].wa, - test_device->opt[option].size); + (size_t) test_device->opt[option].size); DBG (4, "sane_control_option: get option %d (%s), value=%p\n", option, test_device->opt[option].name, (void *) value); break; @@ -2639,7 +2671,7 @@ sane_get_parameters (SANE_Handle handle, SANE_Parameters * params) p->lines = test_device->lines; if (test_device->val[opt_fuzzy_parameters].w == SANE_TRUE && test_device->scanning == SANE_FALSE) - p->lines *= random_factor; + p->lines *= (SANE_Int) random_factor; } if (strcmp (mode, SANE_VALUE_SCAN_MODE_GRAY) == 0) @@ -2674,7 +2706,7 @@ sane_get_parameters (SANE_Handle handle, SANE_Parameters * params) p->pixels_per_line = (SANE_Int) (res * (br_x - tl_x) / MM_PER_INCH); if (test_device->val[opt_fuzzy_parameters].w == SANE_TRUE && test_device->scanning == SANE_FALSE) - p->pixels_per_line *= random_factor; + p->pixels_per_line *= (SANE_Int) random_factor; if (p->pixels_per_line < 1) p->pixels_per_line = 1; @@ -2842,11 +2874,11 @@ sane_read (SANE_Handle handle, SANE_Byte * data, SANE_Int max_scan_length; ssize_t bytes_read; size_t read_count; - SANE_Int bytes_total = test_device->lines * test_device->bytes_per_line; + size_t bytes_total = (size_t) test_device->lines * (size_t) test_device->bytes_per_line; DBG (4, "sane_read: handle=%p, data=%p, max_length = %d, length=%p\n", - handle, data, max_length, (void *) length); + handle, (void *) data, max_length, (void *) length); if (!inited) { DBG (1, "sane_read: not inited, call sane_init() first\n"); @@ -2927,11 +2959,11 @@ sane_read (SANE_Handle handle, SANE_Byte * data, DBG (1, "sane_read: not scanning (call sane_start first)\n"); return SANE_STATUS_INVAL; } - read_count = max_scan_length; + read_count = (size_t) max_scan_length; bytes_read = read (test_device->pipe, data, read_count); if (bytes_read == 0 - || (bytes_read + test_device->bytes_total >= bytes_total)) + || ((size_t) bytes_read + (size_t) test_device->bytes_total >= bytes_total)) { SANE_Status status; DBG (2, "sane_read: EOF reached\n"); @@ -2966,11 +2998,11 @@ sane_read (SANE_Handle handle, SANE_Byte * data, return SANE_STATUS_IO_ERROR; } } - *length = bytes_read; - test_device->bytes_total += bytes_read; + *length = (SANE_Int) bytes_read; + test_device->bytes_total += (size_t) bytes_read; - DBG (2, "sane_read: read %ld bytes of %d, total %d\n", (long) bytes_read, - max_scan_length, test_device->bytes_total); + DBG (2, "sane_read: read %zu bytes of %zu, total %zu\n", (size_t) bytes_read, + (size_t) max_scan_length, (size_t) test_device->bytes_total); return SANE_STATUS_GOOD; } @@ -3051,6 +3083,7 @@ sane_set_io_mode (SANE_Handle handle, SANE_Bool non_blocking) } else { + DBG (1, "sane_set_io_mode: unsupported\n"); if (non_blocking) return SANE_STATUS_UNSUPPORTED; } @@ -3089,5 +3122,6 @@ sane_get_select_fd (SANE_Handle handle, SANE_Int * fd) *fd = test_device->pipe; return SANE_STATUS_GOOD; } + DBG(1,"sane_get_select_fd: unsupported\n"); return SANE_STATUS_UNSUPPORTED; } diff --git a/backend/test.h b/backend/test.h index 3e7a6aa..61f23de 100644 --- a/backend/test.h +++ b/backend/test.h @@ -98,11 +98,12 @@ typedef enum opt_int_constraint_word_list, opt_int_array, opt_int_array_constraint_range, + opt_int_array_constraint_word_list, + opt_int_inexact, opt_gamma_red, opt_gamma_green, opt_gamma_blue, opt_gamma_all, - opt_int_array_constraint_word_list, opt_fixed_group, opt_fixed, opt_fixed_constraint_range, @@ -136,7 +137,7 @@ typedef struct Test_Device SANE_Word bytes_per_line; SANE_Word pixels_per_line; SANE_Word lines; - SANE_Int bytes_total; + size_t bytes_total; SANE_Bool open; SANE_Bool scanning; SANE_Bool cancelled; diff --git a/backend/umax-scsidef.h b/backend/umax-scsidef.h index 476bac5..db355a0 100644 --- a/backend/umax-scsidef.h +++ b/backend/umax-scsidef.h @@ -1053,7 +1053,7 @@ static char *scanner_error_str[] = "fb sensor error", /* 70 */ "fb home or motor sensor error", "fb filter or motor sensor error", - "fb lens or motor sensor error" + "fb lens or motor sensor error", "first line position error (LER error, vertical)", "first pixel position error (SER error, horizontal)", "first pixel position error for lens 2 (SER2 error, horizontal)", diff --git a/backend/umax-usb.c b/backend/umax-usb.c index 05019c7..ab772fe 100644 --- a/backend/umax-usb.c +++ b/backend/umax-usb.c @@ -261,8 +261,8 @@ sanei_umaxusb_open (const char *dev, int *fdp, { SANE_Status status; - handler = handler; /* silence gcc */ - handler_arg = handler_arg; /* silence gcc */ + (void) handler; /* silence gcc */ + (void) handler_arg; /* silence gcc */ status = sanei_usb_open (dev, fdp); if (status != SANE_STATUS_GOOD) { @@ -306,7 +306,7 @@ static SANE_Status sanei_umaxusb_open_extended (const char *dev, int *fdp, SANEI_SCSI_Sense_Handler handler, void *handler_arg, int *buffersize) { - buffersize = buffersize; + (void) buffersize; return(sanei_umaxusb_open(dev, fdp, handler, handler_arg)); } diff --git a/backend/umax1220u.c b/backend/umax1220u.c index 8c6098c..e5ecbef 100644 --- a/backend/umax1220u.c +++ b/backend/umax1220u.c @@ -131,9 +131,9 @@ static SANE_Status optionNumOptionsCallback (SANE_Option * option, SANE_Handle handle, SANE_Action action, void *value, SANE_Int * info) { - option = option; - handle = handle; - info = info; /* Eliminate warning about unused parameters */ + (void) option; + (void) handle; + (void) info; /* Eliminate warning about unused parameters */ if (action != SANE_ACTION_GET_VALUE) return SANE_STATUS_INVAL; @@ -173,7 +173,7 @@ optionResolutionCallback (SANE_Option * option, SANE_Handle handle, SANE_Status status; SANE_Word autoValue = 75; - handle = handle; /* Eliminate warning about unused parameters */ + (void) handle; /* Eliminate warning about unused parameters */ switch (action) { @@ -217,8 +217,8 @@ static SANE_Status optionGrayscaleCallback (SANE_Option * option, SANE_Handle handle, SANE_Action action, void *value, SANE_Int * info) { - handle = handle; - option = option; /* Eliminate warning about unused parameters */ + (void) handle; + (void) option; /* Eliminate warning about unused parameters */ switch (action) { @@ -261,10 +261,10 @@ optionLampOffCallback (SANE_Option * option, SANE_Handle handle, SANE_Status res = SANE_STATUS_GOOD; /* Eliminate warnings about unused parameters */ - option = option; - handle = handle; - info = info; - value = value; + (void) option; + (void) handle; + (void) info; + (void) value; if (action != SANE_ACTION_SET_VALUE) return SANE_STATUS_INVAL; @@ -308,9 +308,9 @@ static SANE_Status optionTopLeftXCallback (SANE_Option * option, SANE_Handle handle, SANE_Action action, void *value, SANE_Int * info) { - option = option; - handle = handle; - value = value; /* Eliminate warning about unused parameters */ + (void) option; + (void) handle; + (void) value; /* Eliminate warning about unused parameters */ switch (action) { @@ -351,8 +351,8 @@ optionTopLeftYCallback (SANE_Option * option, SANE_Handle handle, SANE_Action action, void *value, SANE_Int * info) { /* Eliminate warnings about unused parameters */ - option = option; - handle = handle; + (void) option; + (void) handle; switch (action) { @@ -394,8 +394,8 @@ optionBotRightXCallback (SANE_Option * option, SANE_Handle handle, SANE_Action action, void *value, SANE_Int * info) { /* Eliminate warnings about unused parameters */ - option = option; - handle = handle; + (void) option; + (void) handle; switch (action) { @@ -437,8 +437,8 @@ optionBotRightYCallback (SANE_Option * option, SANE_Handle handle, SANE_Action action, void *value, SANE_Int * info) { /* Eliminate warnings about unused parameters */ - option = option; - handle = handle; + (void) option; + (void) handle; switch (action) { @@ -780,7 +780,7 @@ sane_close (SANE_Handle handle) const SANE_Option_Descriptor * sane_get_option_descriptor (SANE_Handle handle, SANE_Int option) { - handle = handle; /* Eliminate compiler warning */ + (void) handle; /* Eliminate compiler warning */ DBG (3, "sane_get_option_descriptor: option = %d\n", option); if (option < 0 || option >= NELEMS (so)) @@ -792,7 +792,7 @@ SANE_Status sane_control_option (SANE_Handle handle, SANE_Int option, SANE_Action action, void *value, SANE_Int * info) { - handle = handle; /* Eliminate compiler warning */ + (void) handle; /* Eliminate compiler warning */ DBG (3, "sane_control_option: handle=%p, opt=%d, act=%d, val=%p, info=%p\n", @@ -812,7 +812,7 @@ sane_get_parameters (SANE_Handle handle, SANE_Parameters * params) SANE_UNFIX (optionBotRightYValue - optionTopLeftYValue) / MM_IN_INCH * optionResolutionValue; - handle = handle; /* Eliminate compiler warning */ + (void) handle; /* Eliminate compiler warning */ DBG (3, "sane_get_parameters\n"); parms.depth = 8; diff --git a/backend/umax_pp_low.c b/backend/umax_pp_low.c index 35cefa9..d1f3c16 100644 --- a/backend/umax_pp_low.c +++ b/backend/umax_pp_low.c @@ -53,9 +53,7 @@ #ifdef HAVE_SYS_TYPES_H #include <sys/types.h> #endif -#ifdef HAVE_SYS_IO_H -#include <sys/io.h> -#endif +#include "../include/sane/sanei_directio.h" #ifdef HAVE_UNISTD_H #include <unistd.h> #endif @@ -85,380 +83,6 @@ #include <linux/ppdev.h> #endif -/*************************************************/ -/* here we define sanei_inb/sanei_outb based on */ -/* OS dependent inb/outb definitions */ -/* SANE_INB is defined whenever a valid inb/outb */ -/* definition has been found */ -/* once all these work, it might be moved to */ -/* sanei_pio.c */ -/*************************************************/ - -#ifdef ENABLE_PARPORT_DIRECTIO - -#if (! defined SANE_INB ) && ( defined HAVE_SYS_HW_H ) /* OS/2 EMX case */ -#define SANE_INB 1 -static int -sanei_ioperm (int start, int length, int enable) -{ - if (enable) - return _portaccess (port, port + length - 1); - return 0; -} - -static unsigned char -sanei_inb (unsigned int port) -{ - return _inp8 (port) & 0xFF; -} - -static void -sanei_outb (unsigned int port, unsigned char value) -{ - _outp8 (port, value); -} - -static void -sanei_insb (unsigned int port, unsigned char *addr, unsigned long count) -{ - _inps8 (port, (unsigned char *) addr, count); -} - -static void -sanei_insl (unsigned int port, unsigned char *addr, unsigned long count) -{ - _inps32 (port, (unsigned long *) addr, count); -} - -static void -sanei_outsb (unsigned int port, const unsigned char *addr, - unsigned long count) -{ - _outps8 (port, (unsigned char *) addr, count); -} - -static void -sanei_outsl (unsigned int port, const unsigned char *addr, - unsigned long count) -{ - _outps32 (port, (unsigned long *) addr, count); -} -#endif /* OS/2 EMX case */ - - - -#if (! defined SANE_INB ) && ( defined HAVE_MACHINE_CPUFUNC_H ) /* FreeBSD case */ -#define SANE_INB 2 -static int -sanei_ioperm (int start, int length, int enable) -{ -#ifdef HAVE_I386_SET_IOPERM - return i386_set_ioperm (start, length, enable); -#else - int fd = 0; - - /* makes compilers happy */ - start = length + enable; - fd = open ("/dev/io", O_RDONLY); - if (fd > 0) - return 0; - return -1; -#endif -} - -static unsigned char -sanei_inb (unsigned int port) -{ - return inb (port); -} - -static void -sanei_outb (unsigned int port, unsigned char value) -{ - outb (port, value); -} - -static void -sanei_insb (unsigned int port, unsigned char *addr, unsigned long count) -{ - insb (port, addr, count); -} - -static void -sanei_insl (unsigned int port, unsigned char *addr, unsigned long count) -{ - insl (port, addr, count); -} - -static void -sanei_outsb (unsigned int port, const unsigned char *addr, - unsigned long count) -{ - outsb (port, addr, count); -} - -static void -sanei_outsl (unsigned int port, const unsigned char *addr, - unsigned long count) -{ - outsl (port, addr, count); -} -#endif /* FreeBSD case */ - - -/* linux GCC on i386 */ -#if ( ! defined SANE_INB ) && ( defined HAVE_SYS_IO_H ) && ( defined __GNUC__ ) && ( defined __i386__ ) -#define SANE_INB 3 - -static int -sanei_ioperm (int start, int length, int enable) -{ -#ifdef HAVE_IOPERM - return ioperm (start, length, enable); -#else - /* linux without ioperm ? hum ... */ - /* makes compilers happy */ - start = length + enable; - return 0; -#endif -} - -static unsigned char -sanei_inb (unsigned int port) -{ - return inb (port); -} - -static void -sanei_outb (unsigned int port, unsigned char value) -{ - outb (value, port); -} - -static void -sanei_insb (unsigned int port, unsigned char *addr, unsigned long count) -{ - insb (port, addr, count); -} - -static void -sanei_insl (unsigned int port, unsigned char *addr, unsigned long count) -{ - insl (port, addr, count); -} - -static void -sanei_outsb (unsigned int port, const unsigned char *addr, - unsigned long count) -{ - outsb (port, addr, count); -} - -static void -sanei_outsl (unsigned int port, const unsigned char *addr, - unsigned long count) -{ - /* oddly, 32 bit I/O are done with outsw instead of the expected outsl */ - outsw (port, addr, count); -} -#endif /* linux GCC on i386 */ - - -/* linux GCC non i386 */ -#if ( ! defined SANE_INB ) && ( defined HAVE_SYS_IO_H ) && ( defined __GNUC__ ) && ( ! defined __i386__ ) -#define SANE_INB 4 -static int -sanei_ioperm (int start, int length, int enable) -{ -#ifdef HAVE_IOPERM - return ioperm (start, length, enable); -#else - /* linux without ioperm ? hum ... */ - /* makes compilers happy */ - start = length + enable; - return 0; -#endif -} - -static unsigned char -sanei_inb (unsigned int port) -{ - return inb (port); -} - -static void -sanei_outb (unsigned int port, unsigned char value) -{ - outb (value, port); -} - -static void -sanei_insb (unsigned int port, unsigned char *addr, unsigned long count) -{ - unsigned int i; - - for (i = 0; i < count; i++) - addr[i] = sanei_inb (port); -} - -static void -sanei_insl (unsigned int port, unsigned char *addr, unsigned long count) -{ - unsigned int i; - - for (i = 0; i < count * 4; i++) - addr[i] = sanei_inb (port); -} - -static void -sanei_outsb (unsigned int port, const unsigned char *addr, - unsigned long count) -{ - unsigned int i; - - for (i = 0; i < count; i++) - sanei_outb (port, addr[i]); -} - -static void -sanei_outsl (unsigned int port, const unsigned char *addr, - unsigned long count) -{ - unsigned int i; - - for (i = 0; i < count * 4; i++) - sanei_outb (port, addr[i]); -} -#endif /* linux GCC non i386 */ - - -/* ICC on i386 */ -#if ( ! defined SANE_INB ) && ( defined __INTEL_COMPILER ) && ( defined __i386__ ) -#define SANE_INB 5 -static int -sanei_ioperm (int start, int length, int enable) -{ -#ifdef HAVE_IOPERM - return ioperm (start, length, enable); -#else - /* ICC without ioperm() ... */ - /* makes compilers happy */ - start = length + enable; - return 0; -#endif -} -static unsigned char -sanei_inb (unsigned int port) -{ - unsigned char ret; - - __asm__ __volatile__ ("inb %%dx,%%al":"=a" (ret):"d" ((u_int) port)); - return ret; -} - -static void -sanei_outb (unsigned int port, unsigned char value) -{ - __asm__ __volatile__ ("outb %%al,%%dx"::"a" (value), "d" ((u_int) port)); -} - -static void -sanei_insb (unsigned int port, void *addr, unsigned long count) -{ - __asm__ __volatile__ ("rep ; insb":"=D" (addr), "=c" (count):"d" (port), - "0" (addr), "1" (count)); -} - -static void -sanei_insl (unsigned int port, void *addr, unsigned long count) -{ - __asm__ __volatile__ ("rep ; insl":"=D" (addr), "=c" (count):"d" (port), - "0" (addr), "1" (count)); -} - -static void -sanei_outsb (unsigned int port, const void *addr, unsigned long count) -{ - __asm__ __volatile__ ("rep ; outsb":"=S" (addr), "=c" (count):"d" (port), - "0" (addr), "1" (count)); -} - -static void -sanei_outsl (unsigned int port, const void *addr, unsigned long count) -{ - __asm__ __volatile__ ("rep ; outsl":"=S" (addr), "=c" (count):"d" (port), - "0" (addr), "1" (count)); -} - -#endif /* ICC on i386 */ - -/* direct io requested, but no valid inb/oub */ -#if ( ! defined SANE_INB) && ( defined ENABLE_PARPORT_DIRECTIO ) -#warning "ENABLE_PARPORT_DIRECTIO cannot be used du to lack of inb/out definition" -#undef ENABLE_PARPORT_DIRECTIO -#endif - -#endif /* ENABLE_PARPORT_DIRECTIO */ -/* - * no inb/outb without --enable-parport-directio * - */ -#ifndef ENABLE_PARPORT_DIRECTIO -#define SANE_INB 0 -static int -sanei_ioperm (__sane_unused__ int start, __sane_unused__ int length, - __sane_unused__ int enable) -{ - /* returns failure */ - return -1; -} - -static unsigned char -sanei_inb (__sane_unused__ unsigned int port) -{ - return 255; -} - -static void -sanei_outb (__sane_unused__ unsigned int port, - __sane_unused__ unsigned char value) -{ -} - -static void -sanei_insb (__sane_unused__ unsigned int port, - __sane_unused__ unsigned char *addr, - __sane_unused__ unsigned long count) -{ -} - -static void -sanei_insl (__sane_unused__ unsigned int port, - __sane_unused__ unsigned char *addr, - __sane_unused__ unsigned long count) -{ -} - -static void -sanei_outsb (__sane_unused__ unsigned int port, - __sane_unused__ const unsigned char *addr, - __sane_unused__ unsigned long count) -{ -} - -static void -sanei_outsl (__sane_unused__ unsigned int port, - __sane_unused__ const unsigned char *addr, - __sane_unused__ unsigned long count) -{ -} -#endif /* ENABLE_PARPORT_DIRECTIO is not defined */ - -/* we need either direct io or ppdev */ -#if ! defined ENABLE_PARPORT_DIRECTIO && ! defined HAVE_LINUX_PPDEV_H && ! defined HAVE_DEV_PPBUS_PPI_H -#define IO_SUPPORT_MISSING -#endif - - #include "umax_pp_low.h" #ifdef DMALLOC diff --git a/backend/v4l.c b/backend/v4l.c index bce3c3a..d7ab8e7 100644 --- a/backend/v4l.c +++ b/backend/v4l.c @@ -434,7 +434,7 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize) size_t len; FILE *fp; - authorize = authorize; /* stop gcc from complaining */ + (void) authorize; /* stop gcc from complaining */ DBG_INIT (); DBG (2, "SANE v4l backend version %d.%d build %d from %s\n", SANE_CURRENT_MAJOR, @@ -1007,7 +1007,7 @@ sane_start (SANE_Handle handle) buffer = NULL; return SANE_STATUS_IO_ERROR; } - DBG (3, "sane_start: mmapped frame, capture 1 pict into %p\n", buffer); + DBG (3, "sane_start: mmapped frame, capture 1 pict into %p\n", (void *) buffer); s->mmap.frame = 0; s->mmap.width = s->window.width; /* s->mmap.width = parms.pixels_per_line; ??? huh? */ diff --git a/backend/xerox_mfp.c b/backend/xerox_mfp.c index 310dc53..fc3d94f 100644 --- a/backend/xerox_mfp.c +++ b/backend/xerox_mfp.c @@ -213,6 +213,8 @@ static int isSupportedDevice(struct device __sane_unused__ *dev) if (!strncmp(dev->sane.model, "SCX-4500W", 9) || !strncmp(dev->sane.model, "C460", 4) || !!strstr(dev->sane.model, "CLX-3170") || + !!strstr(dev->sane.model, "4x24") || + !!strstr(dev->sane.model, "4x28") || !strncmp(dev->sane.model, "M288x", 5)) return 0; return 1; @@ -223,6 +225,11 @@ static int isSupportedDevice(struct device __sane_unused__ *dev) #endif } +static int isJPEGEnabled(struct device __sane_unused__ *dev) +{ + return isSupportedDevice(dev) && dev->compressionEnabled; +} + static void dbg_dump(struct device *dev) { int i; @@ -595,6 +602,22 @@ static void init_options(struct device *dev) dev->opt[OPT_SOURCE].constraint_type = SANE_CONSTRAINT_STRING_LIST; dev->opt[OPT_SOURCE].constraint.string_list = doc_sources; + dev->opt[OPT_JPEG].name = "jpeg"; + dev->opt[OPT_JPEG].title = SANE_I18N("jpeg compression"); + dev->opt[OPT_JPEG].desc = SANE_I18N("JPEG Image Compression"); + dev->opt[OPT_JPEG].unit = SANE_UNIT_NONE; + dev->opt[OPT_JPEG].type = SANE_TYPE_BOOL; + dev->opt[OPT_JPEG].cap |= SANE_CAP_ADVANCED; +#ifdef HAVE_LIBJPEG + dev->compressionEnabled = SANE_TRUE; + if (!isSupportedDevice(dev)) + dev->opt[OPT_JPEG].cap |= SANE_CAP_INACTIVE; + dev->val[OPT_JPEG].b = SANE_TRUE; +#else + dev->opt[OPT_JPEG].cap |= SANE_CAP_INACTIVE; + dev->val[OPT_JPEG].b = SANE_FALSE; +#endif + dev->opt[OPT_GROUP_GEO].name = SANE_NAME_GEOMETRY; dev->opt[OPT_GROUP_GEO].title = SANE_TITLE_GEOMETRY; dev->opt[OPT_GROUP_GEO].desc = SANE_DESC_GEOMETRY; @@ -647,7 +670,10 @@ static void set_parameters(struct device *dev) dev->para.pixels_per_line = dev->win_width / px_to_len; dev->para.bytes_per_line = dev->para.pixels_per_line; - if (!isSupportedDevice(dev)) { + DBG(5, dev->val[OPT_JPEG].b ? "JPEG compression enabled\n" : "JPEG compression disabled\n" ); + dev->compressionEnabled = dev->val[OPT_JPEG].b; + + if (!isJPEGEnabled(dev)) { #if BETTER_BASEDPI px_to_len = 1213.9 / dev->val[OPT_RESOLUTION].w; #endif @@ -776,7 +802,7 @@ static int dev_set_window(struct device *dev) /* Set to JPEG Lossy Compression, if mode is color (only for supported model)... * else go with Uncompressed (For backard compatibility with old models )*/ if (dev->composition == MODE_RGB24) { - if (isSupportedDevice(dev)) { + if (isJPEGEnabled(dev)) { cmd[0x14] = 0x6; } } @@ -1161,7 +1187,7 @@ sane_get_parameters(SANE_Handle h, SANE_Parameters *para) static int dev_acquire(struct device *dev) { if (!dev_cmd_wait(dev, CMD_READ)) - return dev->state; + return 0; dev->state = SANE_STATUS_GOOD; dev->vertical = dev->res[0x08] << 8 | dev->res[0x09]; @@ -1188,7 +1214,8 @@ static int dev_acquire(struct device *dev) if (dev->bytes_per_line > DATASIZE) { DBG(1, "%s: unsupported line size: %d bytes > %d\n", __func__, dev->bytes_per_line, DATASIZE); - return ret_cancel(dev, SANE_STATUS_NO_MEM); + ret_cancel(dev, SANE_STATUS_NO_MEM); + return 0; } dev->reading = 0; /* need to issue READ_IMAGE */ @@ -1279,7 +1306,7 @@ sane_read(SANE_Handle h, SANE_Byte *buf, SANE_Int maxlen, SANE_Int *lenp) SANE_Status status; struct device *dev = h; - DBG(3, "%s: %p, %p, %d, %p\n", __func__, h, buf, maxlen, (void *)lenp); + DBG(3, "%s: %p, %p, %d, %p\n", __func__, h, (void *) buf, maxlen, (void *) lenp); if (lenp) *lenp = 0; @@ -1294,7 +1321,7 @@ sane_read(SANE_Handle h, SANE_Byte *buf, SANE_Int maxlen, SANE_Int *lenp) /* copying uncompressed data */ if (dev->composition == MODE_RGB24 && - isSupportedDevice(dev) && + isJPEGEnabled(dev) && dev->decDataSize > 0) { int diff = dev->total_img_size - dev->total_out_size; int bufLen = (diff < maxlen) ? diff : maxlen; @@ -1321,7 +1348,7 @@ sane_read(SANE_Handle h, SANE_Byte *buf, SANE_Int maxlen, SANE_Int *lenp) /* this will never happen */ DBG(1, "image overflow %d bytes\n", dev->total_img_size - dev->total_out_size); } - if (isSupportedDevice(dev) && + if (isJPEGEnabled(dev) && dev->composition == MODE_RGB24) { remove(encTmpFileName); } @@ -1376,7 +1403,7 @@ sane_read(SANE_Handle h, SANE_Byte *buf, SANE_Int maxlen, SANE_Int *lenp) if (buf && lenp) { /* read mode */ /* copy will do minimal of valid data */ if (dev->para.format == SANE_FRAME_RGB && dev->line_order) { - if (isSupportedDevice(dev)) { + if (isJPEGEnabled(dev)) { clrlen = dump_to_tmp_file(dev); /* decompress after reading entire block data*/ if (0 == dev->blocklen) { @@ -1490,7 +1517,7 @@ sane_start(SANE_Handle h) dev->total_img_size = dev->para.bytes_per_line * dev->para.lines; - if (isSupportedDevice(dev) && + if (isJPEGEnabled(dev) && dev->composition == MODE_RGB24) { int fd; remove(encTmpFileName); diff --git a/backend/xerox_mfp.conf.in b/backend/xerox_mfp.conf.in index 4fcbeb6..33e4b38 100644 --- a/backend/xerox_mfp.conf.in +++ b/backend/xerox_mfp.conf.in @@ -245,6 +245,9 @@ usb 0x0924 0x4293 #Xerox WorkCentre 3220 usb 0x0924 0x4294 +#Xerox WorkCentre 3025 +usb 0x0924 0x42da + #Xerox WorkCentre 3225 usb 0x0924 0x42dc diff --git a/backend/xerox_mfp.h b/backend/xerox_mfp.h index d85fe14..6aa83a4 100644 --- a/backend/xerox_mfp.h +++ b/backend/xerox_mfp.h @@ -38,6 +38,7 @@ enum options { OPT_MODE, /* color */ OPT_THRESHOLD, /* brightness */ OPT_SOURCE, /* affects max window size */ + OPT_JPEG, OPT_GROUP_GEO, OPT_SCAN_TL_X, /* for (OPT_SCAN_TL_X to OPT_SCAN_BR_Y) */ OPT_SCAN_TL_Y, @@ -103,6 +104,7 @@ struct device { int doc_source; /* document source */ int threshold; /* brightness */ int compressionTypes; + SANE_Bool compressionEnabled; /* CMD_READ data. It is per block only, image could be in many blocks */ int blocklen; /* image data block len (padding incl.) */ |