diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2015-10-08 12:32:49 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2015-10-08 12:32:49 +0200 |
commit | cfd27ef2ad8b005fd47ab41ef29b71d9e3d48201 (patch) | |
tree | 56cb8849a5df91b19b72fd4f48c79c343cd9bc5e /backend | |
parent | ba8d09abe681600aad991f4a75e904615b7ed29f (diff) |
Imported Upstream version 1.0.25upstream/1.0.25
Diffstat (limited to 'backend')
130 files changed, 19481 insertions, 4119 deletions
diff --git a/backend/Makefile.am b/backend/Makefile.am index f84d23e..b672490 100644 --- a/backend/Makefile.am +++ b/backend/Makefile.am @@ -24,7 +24,7 @@ USB_LIBS = @USB_LIBS@ SCSI_LIBS = @SCSI_LIBS@ PTHREAD_LIBS = @PTHREAD_LIBS@ -AM_CPPFLAGS = -I. -I$(srcdir) -I$(top_builddir)/include -I$(top_srcdir)/include -DLIBDIR="$(libdir)/sane" +AM_CPPFLAGS = -I. -I$(srcdir) -I$(top_builddir)/include -I$(top_srcdir)/include -DLIBDIR="\"$(libdir)/sane\"" V_MAJOR = @V_MAJOR@ V_MINOR = @V_MINOR@ @@ -83,14 +83,14 @@ BACKEND_CONFS= abaton.conf agfafocus.conf apple.conf artec.conf \ canon_pp.conf cardscan.conf coolscan2.conf coolscan3.conf \ coolscan.conf dc210.conf dc240.conf dc25.conf \ dell1600n_net.conf dmc.conf epjitsu.conf epson2.conf \ - epson.conf fujitsu.conf genesys.conf gphoto2.conf \ + epson.conf epsonds.conf fujitsu.conf genesys.conf gphoto2.conf \ gt68xx.conf hp3900.conf hp4200.conf hp5400.conf \ hp.conf hpsj5s.conf hs2p.conf ibm.conf kodak.conf kodakaio.conf\ leo.conf lexmark.conf ma1509.conf magicolor.conf \ matsushita.conf microtek2.conf microtek.conf mustek.conf \ mustek_pp.conf mustek_usb.conf nec.conf net.conf \ p5.conf \ - pie.conf pixma.conf plustek.conf plustek_pp.conf \ + pie.conf pieusb.conf pixma.conf plustek.conf plustek_pp.conf \ qcam.conf ricoh.conf rts8891.conf s9036.conf sceptre.conf \ sharp.conf sm3840.conf snapscan.conf sp15c.conf \ st400.conf stv680.conf tamarack.conf \ @@ -171,7 +171,7 @@ be_convenience_libs = libabaton.la libagfafocus.la \ libcoolscan2.la libcoolscan3.la libdc25.la \ libdc210.la libdc240.la libdell1600n_net.la \ libdmc.la libdll.la libdll_preload.la libepjitsu.la libepson.la \ - libepson2.la libfujitsu.la libgenesys.la \ + libepson2.la libepsonds.la libfujitsu.la libgenesys.la \ libgphoto2_i.la libgt68xx.la libhp.la \ libhp3500.la libhp3900.la libhp4200.la \ libhp5400.la libhp5590.la libhpljm1005.la \ @@ -182,7 +182,7 @@ be_convenience_libs = libabaton.la libagfafocus.la \ libmustek.la libmustek_pp.la libmustek_usb.la \ libmustek_usb2.la libnec.la libnet.la \ libniash.la libp5.la \ - libpie.la libpint.la libpixma.la \ + libpie.la libpieusb.la libpint.la libpixma.la \ libplustek.la libplustek_pp.la libpnm.la \ libqcam.la libricoh.la librts8891.la \ libs9036.la libsceptre.la libsharp.la \ @@ -204,7 +204,7 @@ be_dlopen_libs = libsane-abaton.la libsane-agfafocus.la \ libsane-coolscan2.la libsane-coolscan3.la libsane-dc25.la \ libsane-dc210.la libsane-dc240.la libsane-dell1600n_net.la \ libsane-dmc.la libsane-epjitsu.la libsane-epson.la \ - libsane-epson2.la libsane-fujitsu.la libsane-genesys.la \ + libsane-epson2.la libsane-epsonds.la libsane-fujitsu.la libsane-genesys.la \ libsane-gphoto2.la libsane-gt68xx.la libsane-hp.la \ libsane-hp3500.la libsane-hp3900.la libsane-hp4200.la \ libsane-hp5400.la libsane-hp5590.la libsane-hpljm1005.la \ @@ -216,7 +216,7 @@ be_dlopen_libs = libsane-abaton.la libsane-agfafocus.la \ libsane-mustek.la libsane-mustek_pp.la libsane-mustek_usb.la \ libsane-mustek_usb2.la libsane-nec.la libsane-net.la \ libsane-niash.la libsane-p5.la \ - libsane-pie.la libsane-pint.la libsane-pixma.la \ + libsane-pie.la libsane-pieusb.la libsane-pint.la libsane-pixma.la \ libsane-plustek.la libsane-plustek_pp.la libsane-pnm.la \ libsane-qcam.la libsane-ricoh.la libsane-rts8891.la \ libsane-s9036.la libsane-sceptre.la libsane-sharp.la \ @@ -462,7 +462,7 @@ libsane_epson_la_LDFLAGS = $(DIST_SANELIBS_LDFLAGS) libsane_epson_la_LIBADD = $(COMMON_LIBS) libepson.la ../sanei/sanei_init_debug.lo ../sanei/sanei_constrain_value.lo ../sanei/sanei_config.lo ../sanei/sanei_config2.lo sane_strstatus.lo ../sanei/sanei_usb.lo ../sanei/sanei_scsi.lo ../sanei/sanei_pio.lo $(SCSI_LIBS) $(USB_LIBS) $(RESMGR_LIBS) EXTRA_DIST += epson.conf.in -libepson2_la_SOURCES = epson2.c epson2.h epson2_scsi.c epson2_scsi.h epson_usb.c epson2_net.c epson2_net.h epson2-io.c epson2-io.h epson2-commands.c epson2-commands.h epson2-ops.c epson2-ops.h epson2-cct.c +libepson2_la_SOURCES = epson2.c epson2.h epson2_scsi.c epson2_scsi.h epson2_usb.c epson2_net.c epson2_net.h epson2-io.c epson2-io.h epson2-commands.c epson2-commands.h epson2-ops.c epson2-ops.h epson2-cct.c libepson2_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=epson2 nodist_libsane_epson2_la_SOURCES = epson2-s.c @@ -471,6 +471,19 @@ libsane_epson2_la_LDFLAGS = $(DIST_SANELIBS_LDFLAGS) libsane_epson2_la_LIBADD = $(COMMON_LIBS) libepson2.la ../sanei/sanei_init_debug.lo ../sanei/sanei_constrain_value.lo ../sanei/sanei_config.lo ../sanei/sanei_config2.lo sane_strstatus.lo ../sanei/sanei_usb.lo ../sanei/sanei_scsi.lo ../sanei/sanei_pio.lo ../sanei/sanei_tcp.lo ../sanei/sanei_udp.lo $(SCSI_LIBS) $(USB_LIBS) $(SOCKET_LIBS) $(MATH_LIB) $(RESMGR_LIBS) EXTRA_DIST += epson2.conf.in +libepsonds_la_SOURCES = epsonds.c epsonds.h epsonds-usb.c epsonds-usb.h epsonds-io.c epsonds-io.h \ + epsonds-cmd.c epsonds-cmd.h epsonds-ops.c epsonds-ops.h epsonds-jpeg.c epsonds-jpeg.h +libepsonds_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=epsonds + +nodist_libsane_epsonds_la_SOURCES = epsonds-s.c +libsane_epsonds_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=epsonds +libsane_epsonds_la_LDFLAGS = $(DIST_SANELIBS_LDFLAGS) +libsane_epsonds_la_LIBADD = $(COMMON_LIBS) libepsonds.la ../sanei/sanei_init_debug.lo ../sanei/sanei_constrain_value.lo \ + ../sanei/sanei_config.lo ../sanei/sanei_config2.lo sane_strstatus.lo \ + ../sanei/sanei_usb.lo ../sanei/sanei_scsi.lo \ + @SANEI_SANEI_JPEG_LO@ $(JPEG_LIBS) $(USB_LIBS) $(MATH_LIB) $(RESMGR_LIBS) +EXTRA_DIST += epsonds.conf.in + libfujitsu_la_SOURCES = fujitsu.c fujitsu.h fujitsu-scsi.h libfujitsu_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=fujitsu @@ -687,12 +700,12 @@ libsane_ma1509_la_LIBADD = $(COMMON_LIBS) libma1509.la ../sanei/sanei_init_debug EXTRA_DIST += ma1509.conf.in libmagicolor_la_SOURCES = magicolor.c magicolor.h -libmagicolor_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=magicolor +libmagicolor_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=magicolor $(SNMP_CFLAGS) nodist_libsane_magicolor_la_SOURCES = magicolor-s.c libsane_magicolor_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=magicolor libsane_magicolor_la_LDFLAGS = $(DIST_SANELIBS_LDFLAGS) -libsane_magicolor_la_LIBADD = $(COMMON_LIBS) libmagicolor.la ../sanei/sanei_init_debug.lo ../sanei/sanei_constrain_value.lo ../sanei/sanei_config.lo ../sanei/sanei_config2.lo sane_strstatus.lo ../sanei/sanei_usb.lo ../sanei/sanei_scsi.lo ../sanei/sanei_tcp.lo ../sanei/sanei_udp.lo $(USB_LIBS) $(SOCKET_LIBS) $(MATH_LIB) $(RESMGR_LIBS) +libsane_magicolor_la_LIBADD = $(COMMON_LIBS) libmagicolor.la ../sanei/sanei_init_debug.lo ../sanei/sanei_constrain_value.lo ../sanei/sanei_config.lo ../sanei/sanei_config2.lo sane_strstatus.lo ../sanei/sanei_usb.lo ../sanei/sanei_scsi.lo ../sanei/sanei_tcp.lo ../sanei/sanei_udp.lo $(USB_LIBS) $(SOCKET_LIBS) $(MATH_LIB) $(RESMGR_LIBS) $(SNMP_LIBS) EXTRA_DIST += magicolor.conf.in libmatsushita_la_SOURCES = matsushita.c matsushita.h @@ -802,6 +815,15 @@ libsane_pie_la_LDFLAGS = $(DIST_SANELIBS_LDFLAGS) libsane_pie_la_LIBADD = $(COMMON_LIBS) libpie.la ../sanei/sanei_init_debug.lo ../sanei/sanei_constrain_value.lo ../sanei/sanei_config.lo ../sanei/sanei_config2.lo sane_strstatus.lo ../sanei/sanei_scsi.lo ../sanei/sanei_thread.lo $(SCSI_LIBS) $(PTHREAD_LIBS) $(RESMGR_LIBS) EXTRA_DIST += pie.conf.in +libpieusb_la_SOURCES = pieusb.h pieusb_buffer.c pieusb_buffer.h pieusb_scancmd.c pieusb_scancmd.h pieusb_specific.c pieusb_specific.h pieusb_usb.c pieusb_usb.h pieusb.c +libpieusb_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=pieusb + +nodist_libsane_pieusb_la_SOURCES = pieusb-s.c +libsane_pieusb_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=pieusb +libsane_pieusb_la_LDFLAGS = $(DIST_SANELIBS_LDFLAGS) +libsane_pieusb_la_LIBADD = $(COMMON_LIBS) libpieusb.la ../sanei/sanei_init_debug.lo ../sanei/sanei_constrain_value.lo ../sanei/sanei_config.lo ../sanei/sanei_config2.lo sane_strstatus.lo ../sanei/sanei_scsi.lo ../sanei/sanei_thread.lo ../sanei/sanei_usb.lo ../sanei/sanei_ir.lo ../sanei/sanei_magic.lo $(PTHREAD_LIBS) $(RESMGR_LIBS) $(USB_LIBS) $(MATH_LIB) +EXTRA_DIST += pieusb.conf.in + libp5_la_SOURCES = p5.c p5.h p5_device.h libp5_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=p5 diff --git a/backend/Makefile.in b/backend/Makefile.in index 3f7fa12..1860295 100644 --- a/backend/Makefile.in +++ b/backend/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.13.4 from Makefile.am. +# Makefile.in generated by automake 1.14.1 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2013 Free Software Foundation, Inc. @@ -206,11 +206,17 @@ am_libepson_la_OBJECTS = libepson_la-epson.lo \ libepson_la_OBJECTS = $(am_libepson_la_OBJECTS) libepson2_la_LIBADD = am_libepson2_la_OBJECTS = libepson2_la-epson2.lo \ - libepson2_la-epson2_scsi.lo libepson2_la-epson_usb.lo \ + libepson2_la-epson2_scsi.lo libepson2_la-epson2_usb.lo \ libepson2_la-epson2_net.lo libepson2_la-epson2-io.lo \ libepson2_la-epson2-commands.lo libepson2_la-epson2-ops.lo \ libepson2_la-epson2-cct.lo libepson2_la_OBJECTS = $(am_libepson2_la_OBJECTS) +libepsonds_la_LIBADD = +am_libepsonds_la_OBJECTS = libepsonds_la-epsonds.lo \ + libepsonds_la-epsonds-usb.lo libepsonds_la-epsonds-io.lo \ + libepsonds_la-epsonds-cmd.lo libepsonds_la-epsonds-ops.lo \ + libepsonds_la-epsonds-jpeg.lo +libepsonds_la_OBJECTS = $(am_libepsonds_la_OBJECTS) libfujitsu_la_LIBADD = am_libfujitsu_la_OBJECTS = libfujitsu_la-fujitsu.lo libfujitsu_la_OBJECTS = $(am_libfujitsu_la_OBJECTS) @@ -327,6 +333,11 @@ libp5_la_OBJECTS = $(am_libp5_la_OBJECTS) libpie_la_LIBADD = am_libpie_la_OBJECTS = libpie_la-pie.lo libpie_la_OBJECTS = $(am_libpie_la_OBJECTS) +libpieusb_la_LIBADD = +am_libpieusb_la_OBJECTS = libpieusb_la-pieusb_buffer.lo \ + libpieusb_la-pieusb_scancmd.lo libpieusb_la-pieusb_specific.lo \ + libpieusb_la-pieusb_usb.lo libpieusb_la-pieusb.lo +libpieusb_la_OBJECTS = $(am_libpieusb_la_OBJECTS) libpint_la_LIBADD = am_libpint_la_OBJECTS = libpint_la-pint.lo libpint_la_OBJECTS = $(am_libpint_la_OBJECTS) @@ -654,6 +665,18 @@ libsane_epson2_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ $(AM_CFLAGS) $(CFLAGS) $(libsane_epson2_la_LDFLAGS) $(LDFLAGS) \ -o $@ +libsane_epsonds_la_DEPENDENCIES = $(COMMON_LIBS) libepsonds.la \ + ../sanei/sanei_init_debug.lo ../sanei/sanei_constrain_value.lo \ + ../sanei/sanei_config.lo ../sanei/sanei_config2.lo \ + sane_strstatus.lo ../sanei/sanei_usb.lo ../sanei/sanei_scsi.lo \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +nodist_libsane_epsonds_la_OBJECTS = libsane_epsonds_la-epsonds-s.lo +libsane_epsonds_la_OBJECTS = $(nodist_libsane_epsonds_la_OBJECTS) +libsane_epsonds_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ + $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ + $(AM_CFLAGS) $(CFLAGS) $(libsane_epsonds_la_LDFLAGS) \ + $(LDFLAGS) -o $@ libsane_fujitsu_la_DEPENDENCIES = $(COMMON_LIBS) libfujitsu.la \ ../sanei/sanei_init_debug.lo ../sanei/sanei_constrain_value.lo \ ../sanei/sanei_config.lo ../sanei/sanei_config2.lo \ @@ -915,7 +938,8 @@ libsane_magicolor_la_DEPENDENCIES = $(COMMON_LIBS) libmagicolor.la \ sane_strstatus.lo ../sanei/sanei_usb.lo ../sanei/sanei_scsi.lo \ ../sanei/sanei_tcp.lo ../sanei/sanei_udp.lo \ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ - $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) nodist_libsane_magicolor_la_OBJECTS = \ libsane_magicolor_la-magicolor-s.lo libsane_magicolor_la_OBJECTS = $(nodist_libsane_magicolor_la_OBJECTS) @@ -1070,6 +1094,20 @@ libsane_pie_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ $(AM_CFLAGS) $(CFLAGS) $(libsane_pie_la_LDFLAGS) $(LDFLAGS) -o \ $@ +libsane_pieusb_la_DEPENDENCIES = $(COMMON_LIBS) libpieusb.la \ + ../sanei/sanei_init_debug.lo ../sanei/sanei_constrain_value.lo \ + ../sanei/sanei_config.lo ../sanei/sanei_config2.lo \ + sane_strstatus.lo ../sanei/sanei_scsi.lo \ + ../sanei/sanei_thread.lo ../sanei/sanei_usb.lo \ + ../sanei/sanei_ir.lo ../sanei/sanei_magic.lo \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +nodist_libsane_pieusb_la_OBJECTS = libsane_pieusb_la-pieusb-s.lo +libsane_pieusb_la_OBJECTS = $(nodist_libsane_pieusb_la_OBJECTS) +libsane_pieusb_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ + $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ + $(AM_CFLAGS) $(CFLAGS) $(libsane_pieusb_la_LDFLAGS) $(LDFLAGS) \ + -o $@ libsane_pint_la_DEPENDENCIES = $(COMMON_LIBS) libpint.la \ ../sanei/sanei_init_debug.lo ../sanei/sanei_constrain_value.lo \ ../sanei/sanei_config.lo sane_strstatus.lo @@ -1505,24 +1543,25 @@ SOURCES = $(libabaton_la_SOURCES) $(libagfafocus_la_SOURCES) \ $(libdll_la_SOURCES) $(libdll_preload_la_SOURCES) \ $(libdmc_la_SOURCES) $(libepjitsu_la_SOURCES) \ $(libepson_la_SOURCES) $(libepson2_la_SOURCES) \ - $(libfujitsu_la_SOURCES) $(libgenesys_la_SOURCES) \ - $(libgphoto2_i_la_SOURCES) $(libgt68xx_la_SOURCES) \ - $(libhp_la_SOURCES) $(libhp3500_la_SOURCES) \ - $(libhp3900_la_SOURCES) $(libhp4200_la_SOURCES) \ - $(libhp5400_la_SOURCES) $(libhp5590_la_SOURCES) \ - $(libhpljm1005_la_SOURCES) $(libhpsj5s_la_SOURCES) \ - $(libhs2p_la_SOURCES) $(libibm_la_SOURCES) \ - $(libkodak_la_SOURCES) $(libkodakaio_la_SOURCES) \ - $(libkvs1025_la_SOURCES) $(libkvs20xx_la_SOURCES) \ - $(libkvs40xx_la_SOURCES) $(libleo_la_SOURCES) \ - $(liblexmark_la_SOURCES) $(libma1509_la_SOURCES) \ - $(libmagicolor_la_SOURCES) $(libmatsushita_la_SOURCES) \ - $(libmicrotek_la_SOURCES) $(libmicrotek2_la_SOURCES) \ - $(libmustek_la_SOURCES) $(libmustek_pp_la_SOURCES) \ - $(libmustek_usb_la_SOURCES) $(libmustek_usb2_la_SOURCES) \ - $(libnec_la_SOURCES) $(libnet_la_SOURCES) \ - $(libniash_la_SOURCES) $(libp5_la_SOURCES) \ - $(libpie_la_SOURCES) $(libpint_la_SOURCES) \ + $(libepsonds_la_SOURCES) $(libfujitsu_la_SOURCES) \ + $(libgenesys_la_SOURCES) $(libgphoto2_i_la_SOURCES) \ + $(libgt68xx_la_SOURCES) $(libhp_la_SOURCES) \ + $(libhp3500_la_SOURCES) $(libhp3900_la_SOURCES) \ + $(libhp4200_la_SOURCES) $(libhp5400_la_SOURCES) \ + $(libhp5590_la_SOURCES) $(libhpljm1005_la_SOURCES) \ + $(libhpsj5s_la_SOURCES) $(libhs2p_la_SOURCES) \ + $(libibm_la_SOURCES) $(libkodak_la_SOURCES) \ + $(libkodakaio_la_SOURCES) $(libkvs1025_la_SOURCES) \ + $(libkvs20xx_la_SOURCES) $(libkvs40xx_la_SOURCES) \ + $(libleo_la_SOURCES) $(liblexmark_la_SOURCES) \ + $(libma1509_la_SOURCES) $(libmagicolor_la_SOURCES) \ + $(libmatsushita_la_SOURCES) $(libmicrotek_la_SOURCES) \ + $(libmicrotek2_la_SOURCES) $(libmustek_la_SOURCES) \ + $(libmustek_pp_la_SOURCES) $(libmustek_usb_la_SOURCES) \ + $(libmustek_usb2_la_SOURCES) $(libnec_la_SOURCES) \ + $(libnet_la_SOURCES) $(libniash_la_SOURCES) \ + $(libp5_la_SOURCES) $(libpie_la_SOURCES) \ + $(libpieusb_la_SOURCES) $(libpint_la_SOURCES) \ $(libpixma_la_SOURCES) $(libplustek_la_SOURCES) \ $(libplustek_pp_la_SOURCES) $(libpnm_la_SOURCES) \ $(libqcam_la_SOURCES) $(libricoh_la_SOURCES) \ @@ -1552,6 +1591,7 @@ SOURCES = $(libabaton_la_SOURCES) $(libagfafocus_la_SOURCES) \ $(nodist_libsane_epjitsu_la_SOURCES) \ $(nodist_libsane_epson_la_SOURCES) \ $(nodist_libsane_epson2_la_SOURCES) \ + $(nodist_libsane_epsonds_la_SOURCES) \ $(nodist_libsane_fujitsu_la_SOURCES) \ $(nodist_libsane_genesys_la_SOURCES) \ $(nodist_libsane_gphoto2_la_SOURCES) \ @@ -1587,6 +1627,7 @@ SOURCES = $(libabaton_la_SOURCES) $(libagfafocus_la_SOURCES) \ $(nodist_libsane_niash_la_SOURCES) \ $(nodist_libsane_p5_la_SOURCES) \ $(nodist_libsane_pie_la_SOURCES) \ + $(nodist_libsane_pieusb_la_SOURCES) \ $(nodist_libsane_pint_la_SOURCES) \ $(nodist_libsane_pixma_la_SOURCES) \ $(nodist_libsane_plustek_la_SOURCES) \ @@ -1638,24 +1679,25 @@ DIST_SOURCES = $(libabaton_la_SOURCES) $(libagfafocus_la_SOURCES) \ $(libdll_la_SOURCES) $(libdll_preload_la_SOURCES) \ $(libdmc_la_SOURCES) $(libepjitsu_la_SOURCES) \ $(libepson_la_SOURCES) $(libepson2_la_SOURCES) \ - $(libfujitsu_la_SOURCES) $(libgenesys_la_SOURCES) \ - $(libgphoto2_i_la_SOURCES) $(libgt68xx_la_SOURCES) \ - $(libhp_la_SOURCES) $(libhp3500_la_SOURCES) \ - $(libhp3900_la_SOURCES) $(libhp4200_la_SOURCES) \ - $(libhp5400_la_SOURCES) $(libhp5590_la_SOURCES) \ - $(libhpljm1005_la_SOURCES) $(libhpsj5s_la_SOURCES) \ - $(libhs2p_la_SOURCES) $(libibm_la_SOURCES) \ - $(libkodak_la_SOURCES) $(libkodakaio_la_SOURCES) \ - $(libkvs1025_la_SOURCES) $(libkvs20xx_la_SOURCES) \ - $(libkvs40xx_la_SOURCES) $(libleo_la_SOURCES) \ - $(liblexmark_la_SOURCES) $(libma1509_la_SOURCES) \ - $(libmagicolor_la_SOURCES) $(libmatsushita_la_SOURCES) \ - $(libmicrotek_la_SOURCES) $(libmicrotek2_la_SOURCES) \ - $(libmustek_la_SOURCES) $(libmustek_pp_la_SOURCES) \ - $(libmustek_usb_la_SOURCES) $(libmustek_usb2_la_SOURCES) \ - $(libnec_la_SOURCES) $(libnet_la_SOURCES) \ - $(libniash_la_SOURCES) $(libp5_la_SOURCES) \ - $(libpie_la_SOURCES) $(libpint_la_SOURCES) \ + $(libepsonds_la_SOURCES) $(libfujitsu_la_SOURCES) \ + $(libgenesys_la_SOURCES) $(libgphoto2_i_la_SOURCES) \ + $(libgt68xx_la_SOURCES) $(libhp_la_SOURCES) \ + $(libhp3500_la_SOURCES) $(libhp3900_la_SOURCES) \ + $(libhp4200_la_SOURCES) $(libhp5400_la_SOURCES) \ + $(libhp5590_la_SOURCES) $(libhpljm1005_la_SOURCES) \ + $(libhpsj5s_la_SOURCES) $(libhs2p_la_SOURCES) \ + $(libibm_la_SOURCES) $(libkodak_la_SOURCES) \ + $(libkodakaio_la_SOURCES) $(libkvs1025_la_SOURCES) \ + $(libkvs20xx_la_SOURCES) $(libkvs40xx_la_SOURCES) \ + $(libleo_la_SOURCES) $(liblexmark_la_SOURCES) \ + $(libma1509_la_SOURCES) $(libmagicolor_la_SOURCES) \ + $(libmatsushita_la_SOURCES) $(libmicrotek_la_SOURCES) \ + $(libmicrotek2_la_SOURCES) $(libmustek_la_SOURCES) \ + $(libmustek_pp_la_SOURCES) $(libmustek_usb_la_SOURCES) \ + $(libmustek_usb2_la_SOURCES) $(libnec_la_SOURCES) \ + $(libnet_la_SOURCES) $(libniash_la_SOURCES) \ + $(libp5_la_SOURCES) $(libpie_la_SOURCES) \ + $(libpieusb_la_SOURCES) $(libpint_la_SOURCES) \ $(libpixma_la_SOURCES) $(libplustek_la_SOURCES) \ $(libplustek_pp_la_SOURCES) $(libpnm_la_SOURCES) \ $(libqcam_la_SOURCES) $(libricoh_la_SOURCES) \ @@ -1789,6 +1831,7 @@ PATH_SEPARATOR = @PATH_SEPARATOR@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ +PNG_LIBS = @PNG_LIBS@ PRELOADABLE_BACKENDS = @PRELOADABLE_BACKENDS@ PRELOADABLE_BACKENDS_ENABLED = @PRELOADABLE_BACKENDS_ENABLED@ PTHREAD_LIBS = @PTHREAD_LIBS@ @@ -1800,11 +1843,14 @@ SCSI_LIBS = @SCSI_LIBS@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SNMP_CFLAGS = @SNMP_CFLAGS@ SNMP_CONFIG_PATH = @SNMP_CONFIG_PATH@ +SNMP_LIBS = @SNMP_LIBS@ SOCKET_LIBS = @SOCKET_LIBS@ STRICT_LDFLAGS = @STRICT_LDFLAGS@ STRIP = @STRIP@ SYSLOG_LIBS = @SYSLOG_LIBS@ +SYSTEMD_CFLAGS = @SYSTEMD_CFLAGS@ SYSTEMD_LIBS = @SYSTEMD_LIBS@ TIFF_LIBS = @TIFF_LIBS@ USB_LIBS = @USB_LIBS@ @@ -1868,7 +1914,7 @@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -AM_CPPFLAGS = -I. -I$(srcdir) -I$(top_builddir)/include -I$(top_srcdir)/include -DLIBDIR="$(libdir)/sane" +AM_CPPFLAGS = -I. -I$(srcdir) -I$(top_builddir)/include -I$(top_srcdir)/include -DLIBDIR="\"$(libdir)/sane\"" AM_LDFLAGS = @STRICT_LDFLAGS@ # The -rpath option is added because we are creating _LTLIBRARIES based # on configure substitution. This causes automake to not know the @@ -1916,65 +1962,67 @@ EXTRA_DIST = sane_strstatus.c stubs.c saned.conf.in abaton.conf.in \ cardscan.conf.in coolscan.conf.in coolscan2.conf.in \ coolscan3.conf.in dc25.conf.in dc210.conf.in dc240.conf.in \ dell1600n_net.conf.in dmc.conf.in epjitsu.conf.in \ - epson.conf.in epson2.conf.in fujitsu.conf.in genesys.conf.in \ - genesys_conv.c genesys_conv_hlp.c genesys_devices.c \ - gphoto2.conf.in gt68xx.conf.in gt68xx_devices.c \ - gt68xx_generic.c gt68xx_generic.h gt68xx_gt6801.c \ - gt68xx_gt6801.h gt68xx_gt6816.c gt68xx_gt6816.h gt68xx_high.c \ - gt68xx_high.h gt68xx_low.c gt68xx_low.h gt68xx_mid.c \ - gt68xx_mid.h gt68xx_shm_channel.c gt68xx_shm_channel.h \ - hp.conf.in hp.README hp.TODO hp3900.conf.in hp3900_config.c \ - hp3900_debug.c hp3900_rts8822.c hp3900_sane.c hp3900_types.c \ - hp3900_usb.c hp4200.conf.in hp4200_lm9830.c hp4200_lm9830.h \ - hp5400.conf.in hp5400_debug.c hp5400_debug.h hp5400_internal.c \ - hp5400_internal.h hp5400_sane.c hp5400_sanei.c hp5400_sanei.h \ - hp5400_xfer.h hp5590_cmds.c hp5590_cmds.h hp5590_low.c \ - hp5590_low.h hpsj5s.conf.in hs2p.conf.in hs2p-scsi.c \ - hs2p-scsi.h ibm.conf.in ibm-scsi.c kodak.conf.in \ - kodakaio.conf.in leo.conf.in lexmark.conf.in lexmark_models.c \ - lexmark_sensors.c ma1509.conf.in magicolor.conf.in \ - matsushita.conf.in microtek.conf.in microtek2.conf.in \ - mustek.conf.in mustek_scsi_pp.c mustek_scsi_pp.h \ - mustek_pp.conf.in mustek_pp_ccd300.c mustek_pp_ccd300.h \ - mustek_pp_cis.c mustek_pp_cis.h mustek_pp_null.c \ - mustek_usb.conf.in mustek_usb_high.c mustek_usb_high.h \ - mustek_usb_low.c mustek_usb_low.h mustek_usb_mid.c \ - mustek_usb_mid.h mustek_usb2_asic.c mustek_usb2_asic.h \ - mustek_usb2_high.c mustek_usb2_high.h mustek_usb2_reflective.c \ + epson.conf.in epson2.conf.in epsonds.conf.in fujitsu.conf.in \ + genesys.conf.in genesys_conv.c genesys_conv_hlp.c \ + genesys_devices.c gphoto2.conf.in gt68xx.conf.in \ + gt68xx_devices.c gt68xx_generic.c gt68xx_generic.h \ + gt68xx_gt6801.c gt68xx_gt6801.h gt68xx_gt6816.c \ + gt68xx_gt6816.h gt68xx_high.c gt68xx_high.h gt68xx_low.c \ + gt68xx_low.h gt68xx_mid.c gt68xx_mid.h gt68xx_shm_channel.c \ + gt68xx_shm_channel.h hp.conf.in hp.README hp.TODO \ + hp3900.conf.in hp3900_config.c hp3900_debug.c hp3900_rts8822.c \ + hp3900_sane.c hp3900_types.c hp3900_usb.c hp4200.conf.in \ + hp4200_lm9830.c hp4200_lm9830.h hp5400.conf.in hp5400_debug.c \ + hp5400_debug.h hp5400_internal.c hp5400_internal.h \ + hp5400_sane.c hp5400_sanei.c hp5400_sanei.h hp5400_xfer.h \ + hp5590_cmds.c hp5590_cmds.h hp5590_low.c hp5590_low.h \ + hpsj5s.conf.in hs2p.conf.in hs2p-scsi.c hs2p-scsi.h \ + ibm.conf.in ibm-scsi.c kodak.conf.in kodakaio.conf.in \ + leo.conf.in lexmark.conf.in lexmark_models.c lexmark_sensors.c \ + ma1509.conf.in magicolor.conf.in matsushita.conf.in \ + microtek.conf.in microtek2.conf.in mustek.conf.in \ + mustek_scsi_pp.c mustek_scsi_pp.h mustek_pp.conf.in \ + mustek_pp_ccd300.c mustek_pp_ccd300.h mustek_pp_cis.c \ + mustek_pp_cis.h mustek_pp_null.c mustek_usb.conf.in \ + mustek_usb_high.c mustek_usb_high.h mustek_usb_low.c \ + mustek_usb_low.h mustek_usb_mid.c mustek_usb_mid.h \ + mustek_usb2_asic.c mustek_usb2_asic.h mustek_usb2_high.c \ + mustek_usb2_high.h mustek_usb2_reflective.c \ mustek_usb2_transparent.c nec.conf.in net.conf.in niash_core.c \ - niash_core.h niash_xfer.c niash_xfer.h pie.conf.in p5.conf.in \ - p5_device.c pixma.conf.in pixma_sane_options.c \ - pixma_sane_options.h plustek.conf.in plustek-usb.c \ - plustek-usb.h plustek-usbcal.c plustek-usbcalfile.c \ - plustek-usbdevs.c plustek-usbhw.c plustek-usbimg.c \ - plustek-usbio.c plustek-usbmap.c plustek-usbscan.c \ - plustek-usbshading.c plustek_pp.conf.in 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 \ - qcam.conf.in ricoh.conf.in ricoh-scsi.c rts8891.conf.in \ - rts8891_devices.c rts8891_low.c rts8891_low.h s9036.conf.in \ - sceptre.conf.in sharp.conf.in sm3600-color.c sm3600-gray.c \ - sm3600-homerun.c sm3600-scanmtek.c sm3600-scantool.h \ - sm3600-scanusb.c sm3600-scanutil.c sm3840.conf.in sm3840_lib.c \ - sm3840_lib.h sm3840_scan.c snapscan.conf.in snapscan-data.c \ - snapscan-mutex.c snapscan-options.c snapscan-scsi.c \ - snapscan-sources.c snapscan-sources.h snapscan-usb.c \ - snapscan-usb.h sp15c.conf.in st400.conf.in stv680.conf.in \ - tamarack.conf.in test.conf.in test-picture.c teco1.conf.in \ - teco2.conf.in teco3.conf.in u12.conf.in u12-ccd.c u12-hw.c \ - u12-hwdef.h u12-if.c u12-image.c u12-io.c u12-map.c \ - u12-motor.c u12-scanner.h u12-shading.c u12-tpa.c umax.conf.in \ - umax-scanner.c umax-scanner.h umax-scsidef.h umax-uc1200s.c \ - umax-uc1200se.c umax-uc1260.c umax-uc630.c umax-uc840.c \ - umax-ug630.c umax-ug80.c umax-usb.c umax1220u.conf.in \ - umax1220u-common.c umax_pp.conf.in v4l.conf.in \ - xerox_mfp.conf.in dll.conf.in dll.aliases + niash_core.h niash_xfer.c niash_xfer.h pie.conf.in \ + pieusb.conf.in p5.conf.in p5_device.c pixma.conf.in \ + pixma_sane_options.c pixma_sane_options.h plustek.conf.in \ + plustek-usb.c plustek-usb.h plustek-usbcal.c \ + plustek-usbcalfile.c plustek-usbdevs.c plustek-usbhw.c \ + plustek-usbimg.c plustek-usbio.c plustek-usbmap.c \ + plustek-usbscan.c plustek-usbshading.c plustek_pp.conf.in \ + 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 qcam.conf.in ricoh.conf.in ricoh-scsi.c \ + rts8891.conf.in rts8891_devices.c rts8891_low.c rts8891_low.h \ + s9036.conf.in sceptre.conf.in sharp.conf.in sm3600-color.c \ + sm3600-gray.c sm3600-homerun.c sm3600-scanmtek.c \ + sm3600-scantool.h sm3600-scanusb.c sm3600-scanutil.c \ + sm3840.conf.in sm3840_lib.c sm3840_lib.h sm3840_scan.c \ + snapscan.conf.in snapscan-data.c snapscan-mutex.c \ + snapscan-options.c snapscan-scsi.c snapscan-sources.c \ + snapscan-sources.h snapscan-usb.c snapscan-usb.h sp15c.conf.in \ + st400.conf.in stv680.conf.in tamarack.conf.in test.conf.in \ + test-picture.c teco1.conf.in teco2.conf.in teco3.conf.in \ + u12.conf.in u12-ccd.c u12-hw.c u12-hwdef.h u12-if.c \ + u12-image.c u12-io.c u12-map.c u12-motor.c u12-scanner.h \ + u12-shading.c u12-tpa.c umax.conf.in umax-scanner.c \ + umax-scanner.h umax-scsidef.h umax-uc1200s.c umax-uc1200se.c \ + umax-uc1260.c umax-uc630.c umax-uc840.c umax-ug630.c \ + umax-ug80.c umax-usb.c umax1220u.conf.in umax1220u-common.c \ + umax_pp.conf.in v4l.conf.in xerox_mfp.conf.in dll.conf.in \ + dll.aliases # Backends are not required to have a config file. Any backend # that wants to install a config file should list it here. @@ -1984,14 +2032,14 @@ BACKEND_CONFS = abaton.conf agfafocus.conf apple.conf artec.conf \ canon_pp.conf cardscan.conf coolscan2.conf coolscan3.conf \ coolscan.conf dc210.conf dc240.conf dc25.conf \ dell1600n_net.conf dmc.conf epjitsu.conf epson2.conf \ - epson.conf fujitsu.conf genesys.conf gphoto2.conf \ + epson.conf epsonds.conf fujitsu.conf genesys.conf gphoto2.conf \ gt68xx.conf hp3900.conf hp4200.conf hp5400.conf \ hp.conf hpsj5s.conf hs2p.conf ibm.conf kodak.conf kodakaio.conf\ leo.conf lexmark.conf ma1509.conf magicolor.conf \ matsushita.conf microtek2.conf microtek.conf mustek.conf \ mustek_pp.conf mustek_usb.conf nec.conf net.conf \ p5.conf \ - pie.conf pixma.conf plustek.conf plustek_pp.conf \ + pie.conf pieusb.conf pixma.conf plustek.conf plustek_pp.conf \ qcam.conf ricoh.conf rts8891.conf s9036.conf sceptre.conf \ sharp.conf sm3840.conf snapscan.conf sp15c.conf \ st400.conf stv680.conf tamarack.conf \ @@ -2020,7 +2068,7 @@ be_convenience_libs = libabaton.la libagfafocus.la \ libcoolscan2.la libcoolscan3.la libdc25.la \ libdc210.la libdc240.la libdell1600n_net.la \ libdmc.la libdll.la libdll_preload.la libepjitsu.la libepson.la \ - libepson2.la libfujitsu.la libgenesys.la \ + libepson2.la libepsonds.la libfujitsu.la libgenesys.la \ libgphoto2_i.la libgt68xx.la libhp.la \ libhp3500.la libhp3900.la libhp4200.la \ libhp5400.la libhp5590.la libhpljm1005.la \ @@ -2031,7 +2079,7 @@ be_convenience_libs = libabaton.la libagfafocus.la \ libmustek.la libmustek_pp.la libmustek_usb.la \ libmustek_usb2.la libnec.la libnet.la \ libniash.la libp5.la \ - libpie.la libpint.la libpixma.la \ + libpie.la libpieusb.la libpint.la libpixma.la \ libplustek.la libplustek_pp.la libpnm.la \ libqcam.la libricoh.la librts8891.la \ libs9036.la libsceptre.la libsharp.la \ @@ -2054,7 +2102,7 @@ be_dlopen_libs = libsane-abaton.la libsane-agfafocus.la \ libsane-coolscan2.la libsane-coolscan3.la libsane-dc25.la \ libsane-dc210.la libsane-dc240.la libsane-dell1600n_net.la \ libsane-dmc.la libsane-epjitsu.la libsane-epson.la \ - libsane-epson2.la libsane-fujitsu.la libsane-genesys.la \ + libsane-epson2.la libsane-epsonds.la libsane-fujitsu.la libsane-genesys.la \ libsane-gphoto2.la libsane-gt68xx.la libsane-hp.la \ libsane-hp3500.la libsane-hp3900.la libsane-hp4200.la \ libsane-hp5400.la libsane-hp5590.la libsane-hpljm1005.la \ @@ -2066,7 +2114,7 @@ be_dlopen_libs = libsane-abaton.la libsane-agfafocus.la \ libsane-mustek.la libsane-mustek_pp.la libsane-mustek_usb.la \ libsane-mustek_usb2.la libsane-nec.la libsane-net.la \ libsane-niash.la libsane-p5.la \ - libsane-pie.la libsane-pint.la libsane-pixma.la \ + libsane-pie.la libsane-pieusb.la libsane-pint.la libsane-pixma.la \ libsane-plustek.la libsane-plustek_pp.la libsane-pnm.la \ libsane-qcam.la libsane-ricoh.la libsane-rts8891.la \ libsane-s9036.la libsane-sceptre.la libsane-sharp.la \ @@ -2238,12 +2286,24 @@ nodist_libsane_epson_la_SOURCES = epson-s.c libsane_epson_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=epson libsane_epson_la_LDFLAGS = $(DIST_SANELIBS_LDFLAGS) libsane_epson_la_LIBADD = $(COMMON_LIBS) libepson.la ../sanei/sanei_init_debug.lo ../sanei/sanei_constrain_value.lo ../sanei/sanei_config.lo ../sanei/sanei_config2.lo sane_strstatus.lo ../sanei/sanei_usb.lo ../sanei/sanei_scsi.lo ../sanei/sanei_pio.lo $(SCSI_LIBS) $(USB_LIBS) $(RESMGR_LIBS) -libepson2_la_SOURCES = epson2.c epson2.h epson2_scsi.c epson2_scsi.h epson_usb.c epson2_net.c epson2_net.h epson2-io.c epson2-io.h epson2-commands.c epson2-commands.h epson2-ops.c epson2-ops.h epson2-cct.c +libepson2_la_SOURCES = epson2.c epson2.h epson2_scsi.c epson2_scsi.h epson2_usb.c epson2_net.c epson2_net.h epson2-io.c epson2-io.h epson2-commands.c epson2-commands.h epson2-ops.c epson2-ops.h epson2-cct.c libepson2_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=epson2 nodist_libsane_epson2_la_SOURCES = epson2-s.c libsane_epson2_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=epson2 libsane_epson2_la_LDFLAGS = $(DIST_SANELIBS_LDFLAGS) libsane_epson2_la_LIBADD = $(COMMON_LIBS) libepson2.la ../sanei/sanei_init_debug.lo ../sanei/sanei_constrain_value.lo ../sanei/sanei_config.lo ../sanei/sanei_config2.lo sane_strstatus.lo ../sanei/sanei_usb.lo ../sanei/sanei_scsi.lo ../sanei/sanei_pio.lo ../sanei/sanei_tcp.lo ../sanei/sanei_udp.lo $(SCSI_LIBS) $(USB_LIBS) $(SOCKET_LIBS) $(MATH_LIB) $(RESMGR_LIBS) +libepsonds_la_SOURCES = epsonds.c epsonds.h epsonds-usb.c epsonds-usb.h epsonds-io.c epsonds-io.h \ + epsonds-cmd.c epsonds-cmd.h epsonds-ops.c epsonds-ops.h epsonds-jpeg.c epsonds-jpeg.h + +libepsonds_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=epsonds +nodist_libsane_epsonds_la_SOURCES = epsonds-s.c +libsane_epsonds_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=epsonds +libsane_epsonds_la_LDFLAGS = $(DIST_SANELIBS_LDFLAGS) +libsane_epsonds_la_LIBADD = $(COMMON_LIBS) libepsonds.la ../sanei/sanei_init_debug.lo ../sanei/sanei_constrain_value.lo \ + ../sanei/sanei_config.lo ../sanei/sanei_config2.lo sane_strstatus.lo \ + ../sanei/sanei_usb.lo ../sanei/sanei_scsi.lo \ + @SANEI_SANEI_JPEG_LO@ $(JPEG_LIBS) $(USB_LIBS) $(MATH_LIB) $(RESMGR_LIBS) + libfujitsu_la_SOURCES = fujitsu.c fujitsu.h fujitsu-scsi.h libfujitsu_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=fujitsu nodist_libsane_fujitsu_la_SOURCES = fujitsu-s.c @@ -2383,11 +2443,11 @@ libsane_ma1509_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=ma1509 libsane_ma1509_la_LDFLAGS = $(DIST_SANELIBS_LDFLAGS) libsane_ma1509_la_LIBADD = $(COMMON_LIBS) libma1509.la ../sanei/sanei_init_debug.lo ../sanei/sanei_constrain_value.lo ../sanei/sanei_config.lo sane_strstatus.lo ../sanei/sanei_usb.lo $(USB_LIBS) $(RESMGR_LIBS) libmagicolor_la_SOURCES = magicolor.c magicolor.h -libmagicolor_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=magicolor +libmagicolor_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=magicolor $(SNMP_CFLAGS) nodist_libsane_magicolor_la_SOURCES = magicolor-s.c libsane_magicolor_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=magicolor libsane_magicolor_la_LDFLAGS = $(DIST_SANELIBS_LDFLAGS) -libsane_magicolor_la_LIBADD = $(COMMON_LIBS) libmagicolor.la ../sanei/sanei_init_debug.lo ../sanei/sanei_constrain_value.lo ../sanei/sanei_config.lo ../sanei/sanei_config2.lo sane_strstatus.lo ../sanei/sanei_usb.lo ../sanei/sanei_scsi.lo ../sanei/sanei_tcp.lo ../sanei/sanei_udp.lo $(USB_LIBS) $(SOCKET_LIBS) $(MATH_LIB) $(RESMGR_LIBS) +libsane_magicolor_la_LIBADD = $(COMMON_LIBS) libmagicolor.la ../sanei/sanei_init_debug.lo ../sanei/sanei_constrain_value.lo ../sanei/sanei_config.lo ../sanei/sanei_config2.lo sane_strstatus.lo ../sanei/sanei_usb.lo ../sanei/sanei_scsi.lo ../sanei/sanei_tcp.lo ../sanei/sanei_udp.lo $(USB_LIBS) $(SOCKET_LIBS) $(MATH_LIB) $(RESMGR_LIBS) $(SNMP_LIBS) libmatsushita_la_SOURCES = matsushita.c matsushita.h libmatsushita_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=matsushita nodist_libsane_matsushita_la_SOURCES = matsushita-s.c @@ -2454,6 +2514,12 @@ nodist_libsane_pie_la_SOURCES = pie-s.c libsane_pie_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=pie libsane_pie_la_LDFLAGS = $(DIST_SANELIBS_LDFLAGS) libsane_pie_la_LIBADD = $(COMMON_LIBS) libpie.la ../sanei/sanei_init_debug.lo ../sanei/sanei_constrain_value.lo ../sanei/sanei_config.lo ../sanei/sanei_config2.lo sane_strstatus.lo ../sanei/sanei_scsi.lo ../sanei/sanei_thread.lo $(SCSI_LIBS) $(PTHREAD_LIBS) $(RESMGR_LIBS) +libpieusb_la_SOURCES = pieusb.h pieusb_buffer.c pieusb_buffer.h pieusb_scancmd.c pieusb_scancmd.h pieusb_specific.c pieusb_specific.h pieusb_usb.c pieusb_usb.h pieusb.c +libpieusb_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=pieusb +nodist_libsane_pieusb_la_SOURCES = pieusb-s.c +libsane_pieusb_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=pieusb +libsane_pieusb_la_LDFLAGS = $(DIST_SANELIBS_LDFLAGS) +libsane_pieusb_la_LIBADD = $(COMMON_LIBS) libpieusb.la ../sanei/sanei_init_debug.lo ../sanei/sanei_constrain_value.lo ../sanei/sanei_config.lo ../sanei/sanei_config2.lo sane_strstatus.lo ../sanei/sanei_scsi.lo ../sanei/sanei_thread.lo ../sanei/sanei_usb.lo ../sanei/sanei_ir.lo ../sanei/sanei_magic.lo $(PTHREAD_LIBS) $(RESMGR_LIBS) $(USB_LIBS) $(MATH_LIB) libp5_la_SOURCES = p5.c p5.h p5_device.h libp5_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=p5 nodist_libsane_p5_la_SOURCES = p5-s.c @@ -2848,6 +2914,9 @@ libepson.la: $(libepson_la_OBJECTS) $(libepson_la_DEPENDENCIES) $(EXTRA_libepson libepson2.la: $(libepson2_la_OBJECTS) $(libepson2_la_DEPENDENCIES) $(EXTRA_libepson2_la_DEPENDENCIES) $(AM_V_CCLD)$(LINK) $(libepson2_la_OBJECTS) $(libepson2_la_LIBADD) $(LIBS) +libepsonds.la: $(libepsonds_la_OBJECTS) $(libepsonds_la_DEPENDENCIES) $(EXTRA_libepsonds_la_DEPENDENCIES) + $(AM_V_CCLD)$(LINK) $(libepsonds_la_OBJECTS) $(libepsonds_la_LIBADD) $(LIBS) + libfujitsu.la: $(libfujitsu_la_OBJECTS) $(libfujitsu_la_DEPENDENCIES) $(EXTRA_libfujitsu_la_DEPENDENCIES) $(AM_V_CCLD)$(LINK) $(libfujitsu_la_OBJECTS) $(libfujitsu_la_LIBADD) $(LIBS) @@ -2953,6 +3022,9 @@ libp5.la: $(libp5_la_OBJECTS) $(libp5_la_DEPENDENCIES) $(EXTRA_libp5_la_DEPENDEN libpie.la: $(libpie_la_OBJECTS) $(libpie_la_DEPENDENCIES) $(EXTRA_libpie_la_DEPENDENCIES) $(AM_V_CCLD)$(LINK) $(libpie_la_OBJECTS) $(libpie_la_LIBADD) $(LIBS) +libpieusb.la: $(libpieusb_la_OBJECTS) $(libpieusb_la_DEPENDENCIES) $(EXTRA_libpieusb_la_DEPENDENCIES) + $(AM_V_CCLD)$(LINK) $(libpieusb_la_OBJECTS) $(libpieusb_la_LIBADD) $(LIBS) + libpint.la: $(libpint_la_OBJECTS) $(libpint_la_DEPENDENCIES) $(EXTRA_libpint_la_DEPENDENCIES) $(AM_V_CCLD)$(LINK) $(libpint_la_OBJECTS) $(libpint_la_LIBADD) $(LIBS) @@ -3055,6 +3127,9 @@ libsane-epson.la: $(libsane_epson_la_OBJECTS) $(libsane_epson_la_DEPENDENCIES) $ libsane-epson2.la: $(libsane_epson2_la_OBJECTS) $(libsane_epson2_la_DEPENDENCIES) $(EXTRA_libsane_epson2_la_DEPENDENCIES) $(AM_V_CCLD)$(libsane_epson2_la_LINK) $(libsane_epson2_la_OBJECTS) $(libsane_epson2_la_LIBADD) $(LIBS) +libsane-epsonds.la: $(libsane_epsonds_la_OBJECTS) $(libsane_epsonds_la_DEPENDENCIES) $(EXTRA_libsane_epsonds_la_DEPENDENCIES) + $(AM_V_CCLD)$(libsane_epsonds_la_LINK) $(libsane_epsonds_la_OBJECTS) $(libsane_epsonds_la_LIBADD) $(LIBS) + libsane-fujitsu.la: $(libsane_fujitsu_la_OBJECTS) $(libsane_fujitsu_la_DEPENDENCIES) $(EXTRA_libsane_fujitsu_la_DEPENDENCIES) $(AM_V_CCLD)$(libsane_fujitsu_la_LINK) $(libsane_fujitsu_la_OBJECTS) $(libsane_fujitsu_la_LIBADD) $(LIBS) @@ -3160,6 +3235,9 @@ libsane-p5.la: $(libsane_p5_la_OBJECTS) $(libsane_p5_la_DEPENDENCIES) $(EXTRA_li libsane-pie.la: $(libsane_pie_la_OBJECTS) $(libsane_pie_la_DEPENDENCIES) $(EXTRA_libsane_pie_la_DEPENDENCIES) $(AM_V_CCLD)$(libsane_pie_la_LINK) $(libsane_pie_la_OBJECTS) $(libsane_pie_la_LIBADD) $(LIBS) +libsane-pieusb.la: $(libsane_pieusb_la_OBJECTS) $(libsane_pieusb_la_DEPENDENCIES) $(EXTRA_libsane_pieusb_la_DEPENDENCIES) + $(AM_V_CCLD)$(libsane_pieusb_la_LINK) $(libsane_pieusb_la_OBJECTS) $(libsane_pieusb_la_LIBADD) $(LIBS) + libsane-pint.la: $(libsane_pint_la_OBJECTS) $(libsane_pint_la_DEPENDENCIES) $(EXTRA_libsane_pint_la_DEPENDENCIES) $(AM_V_CCLD)$(libsane_pint_la_LINK) $(libsane_pint_la_OBJECTS) $(libsane_pint_la_LIBADD) $(LIBS) @@ -3343,10 +3421,16 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libepson2_la-epson2.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libepson2_la-epson2_net.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libepson2_la-epson2_scsi.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libepson2_la-epson_usb.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libepson2_la-epson2_usb.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libepson_la-epson.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libepson_la-epson_scsi.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libepson_la-epson_usb.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libepsonds_la-epsonds-cmd.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libepsonds_la-epsonds-io.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libepsonds_la-epsonds-jpeg.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libepsonds_la-epsonds-ops.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libepsonds_la-epsonds-usb.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libepsonds_la-epsonds.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfujitsu_la-fujitsu.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgenesys_la-genesys.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgenesys_la-genesys_gl124.Plo@am__quote@ @@ -3403,6 +3487,11 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libniash_la-niash.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libp5_la-p5.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpie_la-pie.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpieusb_la-pieusb.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpieusb_la-pieusb_buffer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpieusb_la-pieusb_scancmd.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpieusb_la-pieusb_specific.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpieusb_la-pieusb_usb.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpint_la-pint.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpixma_la-pixma.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpixma_la-pixma_bjnp.Plo@am__quote@ @@ -3446,6 +3535,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsane_epjitsu_la-epjitsu-s.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsane_epson2_la-epson2-s.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsane_epson_la-epson-s.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsane_epsonds_la-epsonds-s.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsane_fujitsu_la-fujitsu-s.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsane_genesys_la-genesys-s.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsane_gphoto2_la-gphoto2-s.Plo@am__quote@ @@ -3482,6 +3572,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsane_niash_la-niash-s.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsane_p5_la-p5-s.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsane_pie_la-pie-s.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsane_pieusb_la-pieusb-s.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsane_pint_la-pint-s.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsane_pixma_la-pixma-s.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsane_plustek_la-plustek-s.Plo@am__quote@ @@ -3539,14 +3630,14 @@ distclean-compile: @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c $< +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< .c.obj: @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c `$(CYGPATH_W) '$<'` +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` .c.lo: @am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @@ -3772,12 +3863,12 @@ libepson2_la-epson2_scsi.lo: epson2_scsi.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libepson2_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libepson2_la-epson2_scsi.lo `test -f 'epson2_scsi.c' || echo '$(srcdir)/'`epson2_scsi.c -libepson2_la-epson_usb.lo: epson_usb.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libepson2_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libepson2_la-epson_usb.lo -MD -MP -MF $(DEPDIR)/libepson2_la-epson_usb.Tpo -c -o libepson2_la-epson_usb.lo `test -f 'epson_usb.c' || echo '$(srcdir)/'`epson_usb.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libepson2_la-epson_usb.Tpo $(DEPDIR)/libepson2_la-epson_usb.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='epson_usb.c' object='libepson2_la-epson_usb.lo' libtool=yes @AMDEPBACKSLASH@ +libepson2_la-epson2_usb.lo: epson2_usb.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libepson2_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libepson2_la-epson2_usb.lo -MD -MP -MF $(DEPDIR)/libepson2_la-epson2_usb.Tpo -c -o libepson2_la-epson2_usb.lo `test -f 'epson2_usb.c' || echo '$(srcdir)/'`epson2_usb.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libepson2_la-epson2_usb.Tpo $(DEPDIR)/libepson2_la-epson2_usb.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='epson2_usb.c' object='libepson2_la-epson2_usb.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libepson2_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libepson2_la-epson_usb.lo `test -f 'epson_usb.c' || echo '$(srcdir)/'`epson_usb.c +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libepson2_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libepson2_la-epson2_usb.lo `test -f 'epson2_usb.c' || echo '$(srcdir)/'`epson2_usb.c libepson2_la-epson2_net.lo: epson2_net.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libepson2_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libepson2_la-epson2_net.lo -MD -MP -MF $(DEPDIR)/libepson2_la-epson2_net.Tpo -c -o libepson2_la-epson2_net.lo `test -f 'epson2_net.c' || echo '$(srcdir)/'`epson2_net.c @@ -3814,6 +3905,48 @@ libepson2_la-epson2-cct.lo: epson2-cct.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libepson2_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libepson2_la-epson2-cct.lo `test -f 'epson2-cct.c' || echo '$(srcdir)/'`epson2-cct.c +libepsonds_la-epsonds.lo: epsonds.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libepsonds_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libepsonds_la-epsonds.lo -MD -MP -MF $(DEPDIR)/libepsonds_la-epsonds.Tpo -c -o libepsonds_la-epsonds.lo `test -f 'epsonds.c' || echo '$(srcdir)/'`epsonds.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libepsonds_la-epsonds.Tpo $(DEPDIR)/libepsonds_la-epsonds.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='epsonds.c' object='libepsonds_la-epsonds.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libepsonds_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libepsonds_la-epsonds.lo `test -f 'epsonds.c' || echo '$(srcdir)/'`epsonds.c + +libepsonds_la-epsonds-usb.lo: epsonds-usb.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libepsonds_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libepsonds_la-epsonds-usb.lo -MD -MP -MF $(DEPDIR)/libepsonds_la-epsonds-usb.Tpo -c -o libepsonds_la-epsonds-usb.lo `test -f 'epsonds-usb.c' || echo '$(srcdir)/'`epsonds-usb.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libepsonds_la-epsonds-usb.Tpo $(DEPDIR)/libepsonds_la-epsonds-usb.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='epsonds-usb.c' object='libepsonds_la-epsonds-usb.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libepsonds_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libepsonds_la-epsonds-usb.lo `test -f 'epsonds-usb.c' || echo '$(srcdir)/'`epsonds-usb.c + +libepsonds_la-epsonds-io.lo: epsonds-io.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libepsonds_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libepsonds_la-epsonds-io.lo -MD -MP -MF $(DEPDIR)/libepsonds_la-epsonds-io.Tpo -c -o libepsonds_la-epsonds-io.lo `test -f 'epsonds-io.c' || echo '$(srcdir)/'`epsonds-io.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libepsonds_la-epsonds-io.Tpo $(DEPDIR)/libepsonds_la-epsonds-io.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='epsonds-io.c' object='libepsonds_la-epsonds-io.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libepsonds_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libepsonds_la-epsonds-io.lo `test -f 'epsonds-io.c' || echo '$(srcdir)/'`epsonds-io.c + +libepsonds_la-epsonds-cmd.lo: epsonds-cmd.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libepsonds_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libepsonds_la-epsonds-cmd.lo -MD -MP -MF $(DEPDIR)/libepsonds_la-epsonds-cmd.Tpo -c -o libepsonds_la-epsonds-cmd.lo `test -f 'epsonds-cmd.c' || echo '$(srcdir)/'`epsonds-cmd.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libepsonds_la-epsonds-cmd.Tpo $(DEPDIR)/libepsonds_la-epsonds-cmd.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='epsonds-cmd.c' object='libepsonds_la-epsonds-cmd.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libepsonds_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libepsonds_la-epsonds-cmd.lo `test -f 'epsonds-cmd.c' || echo '$(srcdir)/'`epsonds-cmd.c + +libepsonds_la-epsonds-ops.lo: epsonds-ops.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libepsonds_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libepsonds_la-epsonds-ops.lo -MD -MP -MF $(DEPDIR)/libepsonds_la-epsonds-ops.Tpo -c -o libepsonds_la-epsonds-ops.lo `test -f 'epsonds-ops.c' || echo '$(srcdir)/'`epsonds-ops.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libepsonds_la-epsonds-ops.Tpo $(DEPDIR)/libepsonds_la-epsonds-ops.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='epsonds-ops.c' object='libepsonds_la-epsonds-ops.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libepsonds_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libepsonds_la-epsonds-ops.lo `test -f 'epsonds-ops.c' || echo '$(srcdir)/'`epsonds-ops.c + +libepsonds_la-epsonds-jpeg.lo: epsonds-jpeg.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libepsonds_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libepsonds_la-epsonds-jpeg.lo -MD -MP -MF $(DEPDIR)/libepsonds_la-epsonds-jpeg.Tpo -c -o libepsonds_la-epsonds-jpeg.lo `test -f 'epsonds-jpeg.c' || echo '$(srcdir)/'`epsonds-jpeg.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libepsonds_la-epsonds-jpeg.Tpo $(DEPDIR)/libepsonds_la-epsonds-jpeg.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='epsonds-jpeg.c' object='libepsonds_la-epsonds-jpeg.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libepsonds_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libepsonds_la-epsonds-jpeg.lo `test -f 'epsonds-jpeg.c' || echo '$(srcdir)/'`epsonds-jpeg.c + libfujitsu_la-fujitsu.lo: fujitsu.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libfujitsu_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libfujitsu_la-fujitsu.lo -MD -MP -MF $(DEPDIR)/libfujitsu_la-fujitsu.Tpo -c -o libfujitsu_la-fujitsu.lo `test -f 'fujitsu.c' || echo '$(srcdir)/'`fujitsu.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libfujitsu_la-fujitsu.Tpo $(DEPDIR)/libfujitsu_la-fujitsu.Plo @@ -4206,6 +4339,41 @@ libpie_la-pie.lo: pie.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpie_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libpie_la-pie.lo `test -f 'pie.c' || echo '$(srcdir)/'`pie.c +libpieusb_la-pieusb_buffer.lo: pieusb_buffer.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpieusb_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libpieusb_la-pieusb_buffer.lo -MD -MP -MF $(DEPDIR)/libpieusb_la-pieusb_buffer.Tpo -c -o libpieusb_la-pieusb_buffer.lo `test -f 'pieusb_buffer.c' || echo '$(srcdir)/'`pieusb_buffer.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libpieusb_la-pieusb_buffer.Tpo $(DEPDIR)/libpieusb_la-pieusb_buffer.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='pieusb_buffer.c' object='libpieusb_la-pieusb_buffer.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpieusb_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libpieusb_la-pieusb_buffer.lo `test -f 'pieusb_buffer.c' || echo '$(srcdir)/'`pieusb_buffer.c + +libpieusb_la-pieusb_scancmd.lo: pieusb_scancmd.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpieusb_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libpieusb_la-pieusb_scancmd.lo -MD -MP -MF $(DEPDIR)/libpieusb_la-pieusb_scancmd.Tpo -c -o libpieusb_la-pieusb_scancmd.lo `test -f 'pieusb_scancmd.c' || echo '$(srcdir)/'`pieusb_scancmd.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libpieusb_la-pieusb_scancmd.Tpo $(DEPDIR)/libpieusb_la-pieusb_scancmd.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='pieusb_scancmd.c' object='libpieusb_la-pieusb_scancmd.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpieusb_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libpieusb_la-pieusb_scancmd.lo `test -f 'pieusb_scancmd.c' || echo '$(srcdir)/'`pieusb_scancmd.c + +libpieusb_la-pieusb_specific.lo: pieusb_specific.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpieusb_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libpieusb_la-pieusb_specific.lo -MD -MP -MF $(DEPDIR)/libpieusb_la-pieusb_specific.Tpo -c -o libpieusb_la-pieusb_specific.lo `test -f 'pieusb_specific.c' || echo '$(srcdir)/'`pieusb_specific.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libpieusb_la-pieusb_specific.Tpo $(DEPDIR)/libpieusb_la-pieusb_specific.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='pieusb_specific.c' object='libpieusb_la-pieusb_specific.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpieusb_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libpieusb_la-pieusb_specific.lo `test -f 'pieusb_specific.c' || echo '$(srcdir)/'`pieusb_specific.c + +libpieusb_la-pieusb_usb.lo: pieusb_usb.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpieusb_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libpieusb_la-pieusb_usb.lo -MD -MP -MF $(DEPDIR)/libpieusb_la-pieusb_usb.Tpo -c -o libpieusb_la-pieusb_usb.lo `test -f 'pieusb_usb.c' || echo '$(srcdir)/'`pieusb_usb.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libpieusb_la-pieusb_usb.Tpo $(DEPDIR)/libpieusb_la-pieusb_usb.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='pieusb_usb.c' object='libpieusb_la-pieusb_usb.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpieusb_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libpieusb_la-pieusb_usb.lo `test -f 'pieusb_usb.c' || echo '$(srcdir)/'`pieusb_usb.c + +libpieusb_la-pieusb.lo: pieusb.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpieusb_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libpieusb_la-pieusb.lo -MD -MP -MF $(DEPDIR)/libpieusb_la-pieusb.Tpo -c -o libpieusb_la-pieusb.lo `test -f 'pieusb.c' || echo '$(srcdir)/'`pieusb.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libpieusb_la-pieusb.Tpo $(DEPDIR)/libpieusb_la-pieusb.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='pieusb.c' object='libpieusb_la-pieusb.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpieusb_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libpieusb_la-pieusb.lo `test -f 'pieusb.c' || echo '$(srcdir)/'`pieusb.c + libpint_la-pint.lo: pint.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpint_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libpint_la-pint.lo -MD -MP -MF $(DEPDIR)/libpint_la-pint.Tpo -c -o libpint_la-pint.lo `test -f 'pint.c' || echo '$(srcdir)/'`pint.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libpint_la-pint.Tpo $(DEPDIR)/libpint_la-pint.Plo @@ -4507,6 +4675,13 @@ libsane_epson2_la-epson2-s.lo: epson2-s.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsane_epson2_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libsane_epson2_la-epson2-s.lo `test -f 'epson2-s.c' || echo '$(srcdir)/'`epson2-s.c +libsane_epsonds_la-epsonds-s.lo: epsonds-s.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsane_epsonds_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libsane_epsonds_la-epsonds-s.lo -MD -MP -MF $(DEPDIR)/libsane_epsonds_la-epsonds-s.Tpo -c -o libsane_epsonds_la-epsonds-s.lo `test -f 'epsonds-s.c' || echo '$(srcdir)/'`epsonds-s.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libsane_epsonds_la-epsonds-s.Tpo $(DEPDIR)/libsane_epsonds_la-epsonds-s.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='epsonds-s.c' object='libsane_epsonds_la-epsonds-s.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsane_epsonds_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libsane_epsonds_la-epsonds-s.lo `test -f 'epsonds-s.c' || echo '$(srcdir)/'`epsonds-s.c + libsane_fujitsu_la-fujitsu-s.lo: fujitsu-s.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsane_fujitsu_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libsane_fujitsu_la-fujitsu-s.lo -MD -MP -MF $(DEPDIR)/libsane_fujitsu_la-fujitsu-s.Tpo -c -o libsane_fujitsu_la-fujitsu-s.lo `test -f 'fujitsu-s.c' || echo '$(srcdir)/'`fujitsu-s.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libsane_fujitsu_la-fujitsu-s.Tpo $(DEPDIR)/libsane_fujitsu_la-fujitsu-s.Plo @@ -4752,6 +4927,13 @@ libsane_pie_la-pie-s.lo: pie-s.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsane_pie_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libsane_pie_la-pie-s.lo `test -f 'pie-s.c' || echo '$(srcdir)/'`pie-s.c +libsane_pieusb_la-pieusb-s.lo: pieusb-s.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsane_pieusb_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libsane_pieusb_la-pieusb-s.lo -MD -MP -MF $(DEPDIR)/libsane_pieusb_la-pieusb-s.Tpo -c -o libsane_pieusb_la-pieusb-s.lo `test -f 'pieusb-s.c' || echo '$(srcdir)/'`pieusb-s.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libsane_pieusb_la-pieusb-s.Tpo $(DEPDIR)/libsane_pieusb_la-pieusb-s.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='pieusb-s.c' object='libsane_pieusb_la-pieusb-s.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsane_pieusb_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libsane_pieusb_la-pieusb-s.lo `test -f 'pieusb-s.c' || echo '$(srcdir)/'`pieusb-s.c + libsane_pint_la-pint-s.lo: pint-s.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsane_pint_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libsane_pint_la-pint-s.lo -MD -MP -MF $(DEPDIR)/libsane_pint_la-pint-s.Tpo -c -o libsane_pint_la-pint-s.lo `test -f 'pint-s.c' || echo '$(srcdir)/'`pint-s.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libsane_pint_la-pint-s.Tpo $(DEPDIR)/libsane_pint_la-pint-s.Plo diff --git a/backend/abaton.c b/backend/abaton.c index 10f5c21..4008c62 100644 --- a/backend/abaton.c +++ b/backend/abaton.c @@ -82,6 +82,7 @@ +static const SANE_Device **devlist = 0; static int num_devices; static Abaton_Device *first_dev; static Abaton_Scanner *first_handle; @@ -905,12 +906,14 @@ sane_exit (void) free ((void *) dev->sane.model); free (dev); } + + if (devlist) + free (devlist); } SANE_Status sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only) { - static const SANE_Device **devlist = 0; Abaton_Device *dev; int i; @@ -1455,7 +1458,7 @@ sane_cancel (SANE_Handle handle) if (s->AbortedByUser) { DBG (FLOW_CONTROL, "sane_cancel: Scan has not been initiated yet." - "we probably recieved a signal while writing data.\n"); + "we probably received a signal while writing data.\n"); s->AbortedByUser = SANE_FALSE; } else diff --git a/backend/agfafocus.c b/backend/agfafocus.c index bc21558..45d103f 100644 --- a/backend/agfafocus.c +++ b/backend/agfafocus.c @@ -51,6 +51,7 @@ #undef Byte #define Byte SANE_Byte +static const SANE_Device **devlist = 0; static int num_devices; static AgfaFocus_Device *agfafocus_devices; @@ -1323,12 +1324,14 @@ sane_exit (void) sane_close (dev->handle); free (dev); } + + if (devlist) + free (devlist); } SANE_Status sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only) { - static const SANE_Device **devlist = 0; AgfaFocus_Device *dev; int i; diff --git a/backend/apple.c b/backend/apple.c index c806983..a8e9979 100644 --- a/backend/apple.c +++ b/backend/apple.c @@ -136,6 +136,7 @@ #include "apple.h" +static const SANE_Device **devlist = 0; static int num_devices; static Apple_Device *first_dev; static Apple_Scanner *first_handle; @@ -1596,7 +1597,7 @@ init_options (Apple_Scanner * s) s->opt[OPT_WAIT].title = "Wait"; s->opt[OPT_WAIT].desc = "You may issue the scan command but the actual " "scan will not start unless you press the button in the front of the " - "scanner. It is usefull feature when you want to make a network scan (?) " + "scanner. It is a useful feature when you want to make a network scan (?) " "In the mean time you may halt your computer waiting for the SCSI bus " "to be free. If this happens just press the scanner button."; s->opt[OPT_WAIT].type = SANE_TYPE_BOOL; @@ -1921,12 +1922,13 @@ sane_exit (void) free ((void *) dev->sane.model); free (dev); } + if (devlist) + free (devlist); } SANE_Status sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only) { - static const SANE_Device **devlist = 0; Apple_Device *dev; int i; diff --git a/backend/artec.c b/backend/artec.c index 212de34..46aa8b6 100644 --- a/backend/artec.c +++ b/backend/artec.c @@ -607,7 +607,7 @@ sense_handler (int fd, u_char * sense, void *arg) return SANE_STATUS_IO_ERROR; } default: - DBG (2, "sense: Unkown Error Code Qualifier (%02x)\n", sense[0]); + DBG (2, "sense: Unknown Error Code Qualifier (%02x)\n", sense[0]); return SANE_STATUS_IO_ERROR; } @@ -1305,7 +1305,7 @@ artec_set_scan_window (SANE_Handle handle) { /* top left X value */ /* the select area is flipped across the page, so we have to do some */ - /* calculation here to get the the real starting X value */ + /* calculation here to get the real starting X value */ max_x = (int) ((SANE_UNFIX (s->hw->x_range.max) / MM_PER_INCH) * s->x_resolution); reversed_x = max_x - s->tl_x - s->params.pixels_per_line; diff --git a/backend/artec_eplus48u.c b/backend/artec_eplus48u.c index c26fbb0..bc3b2f8 100644 --- a/backend/artec_eplus48u.c +++ b/backend/artec_eplus48u.c @@ -67,7 +67,7 @@ Updates (C) 2001 by Henning Meier-Geinitz. whether to permit this exception to apply to your modifications. If you do not wish that, delete this exception notice. */ -#define BUILD 11 +#define BUILD 12 #include "../include/sane/config.h" @@ -3580,6 +3580,14 @@ load_calibration_data (Artec48U_Scanner * s) s->calibrated = SANE_FALSE; path[0] = 0; + + /* return SANE_STATUS_INVAL if HOME environment variable is not set */ + if (getenv ("HOME") == NULL) + { + XDBG ((1, "Environment variable HOME not set\n")); + return SANE_STATUS_INVAL; + } + if (strlen (getenv ("HOME")) < (PATH_MAX - 1)) strcat (path, getenv ("HOME")); else @@ -3690,6 +3698,14 @@ save_calibration_data (Artec48U_Scanner * s) mode_t mode = S_IRUSR | S_IWUSR; path[0] = 0; + + /* return SANE_STATUS_INVAL if HOME environment variable is not set */ + if (getenv ("HOME") == NULL) + { + XDBG ((1, "Environment variable HOME not set\n")); + return SANE_STATUS_INVAL; + } + if (strlen (getenv ("HOME")) < (PATH_MAX - 1)) strcat (path, getenv ("HOME")); else diff --git a/backend/avision.c b/backend/avision.c index 31b0a58..146125c 100644 --- a/backend/avision.c +++ b/backend/avision.c @@ -39,25 +39,22 @@ ***************************************************************************** - This backend is based upon the Tamarack backend and adapted to the Avision - scanners by René Rebe and Meino Cramer. - This file implements a SANE backend for the Avision SCSI Scanners (like the AV 630 / 620 (CS) ...) and some Avision (OEM) USB scanners (like the HP 53xx, 74xx, Minolta FS-V1 ...) or Fujitsu ScanPartner with the AVISION SCSI-2/3 - or USB command set. + or USB command set and written by René Rebe and Meino Cramer. + + Copyright 2002 - 2015 by + "Ren Rebe" <rene@exactcode.de> + Copyright 1999, 2000, 2001 by "René Rebe" <rene@exactcode.de> "Meino Christian Cramer" <mccramer@s.netic.de> Copyright 2002 by - "René Rebe" <rene@exactcode.de> "Jose Paulo Moitinho de Almeida" <moitinho@civil.ist.utl.pt> - Copyright 2003, 2004, 2005, 2006, 2007 by - "René Rebe" <rene@exactcode.de> - Copyright 2010, 2011 by "Mike Kelly" <mike@piratehaven.org> @@ -137,7 +134,7 @@ #include <math.h> #define BACKEND_NAME avision -#define BACKEND_BUILD 296 /* avision backend BUILD version */ +#define BACKEND_BUILD 297 /* avision backend BUILD version */ #include "../include/sane/sane.h" #include "../include/sane/sanei.h" @@ -167,444 +164,451 @@ static Avision_HWEntry Avision_Device_List [] = { "AVISION", "AV100CS", 0, 0, "Avision", "AV100CS", - 0,0}, + 0}, /* status="untested" */ { "AVISION", "AV100IIICS", 0, 0, "Avision", "AV100IIICS", - 0,0}, + 0}, /* status="untested" */ { "AVISION", "AV100S", 0, 0, "Avision", "AV100S", - 0,0}, + 0}, /* status="untested" */ { NULL, NULL, 0x0638, 0x0A27, "Avision", "AV120", - AV_INT_STATUS,0}, + AV_INT_STATUS}, /* comment="sheetfed scanner" */ /* status="complete" */ { NULL, NULL, 0x0638, 0x0A3C, "Avision", "AV121", - AV_INT_BUTTON | AV_DOES_KEEP_WINDOW | AV_DOES_KEEP_GAMMA,0}, + AV_INT_BUTTON | AV_DOES_KEEP_WINDOW | AV_DOES_KEEP_GAMMA}, /* comment="sheetfed scanner" */ /* status="good" */ { NULL, NULL, 0x0638, 0x0A33, "Avision", "AV122", - AV_INT_BUTTON | AV_2ND_LINE_INTERLACED | AV_NO_REAR | AV_SOFT_SCALE | AV_DOES_KEEP_WINDOW | AV_DOES_KEEP_GAMMA | AV_REAR_OFFSET,0}, + AV_INT_BUTTON | AV_2ND_LINE_INTERLACED | AV_NO_REAR | AV_SOFT_SCALE | AV_DOES_KEEP_WINDOW | AV_DOES_KEEP_GAMMA | AV_REAR_OFFSET}, /* comment="sheetfed duplex scanner" */ /* status="good" */ { NULL, NULL, 0x0638, 0x0A93, "Avision", "AV122 C2", - AV_INT_BUTTON | AV_2ND_LINE_INTERLACED | AV_NO_REAR | AV_SOFT_SCALE | AV_DOES_NOT_KEEP_WINDOW | AV_DOES_KEEP_GAMMA | AV_REAR_OFFSET,0}, + AV_INT_BUTTON | AV_2ND_LINE_INTERLACED | AV_NO_REAR | AV_SOFT_SCALE | AV_DOES_NOT_KEEP_WINDOW | AV_DOES_KEEP_GAMMA | AV_REAR_OFFSET}, /* comment="sheetfed duplex scanner" */ /* status="good" */ { NULL, NULL, 0x0638, 0x0A24, "Avision", "AV210", - AV_INT_BUTTON | AV_ACCEL_TABLE,0}, + AV_INT_BUTTON | AV_ACCEL_TABLE}, /* comment="sheetfed scanner" */ /* status="complete" */ { NULL, NULL, 0x0638, 0x0A25, "Avision", "AV210", - AV_INT_BUTTON | AV_ACCEL_TABLE | AV_NO_64BYTE_ALIGN,0}, + AV_INT_BUTTON | AV_ACCEL_TABLE | AV_NO_64BYTE_ALIGN}, /* comment="sheetfed scanner" */ /* status="complete" */ { NULL, NULL, 0x0638, 0x0A3A, "Avision", "AV210C2", - AV_INT_BUTTON | AV_GRAY_MODES,0}, + AV_INT_BUTTON | AV_GRAY_MODES}, /* comment="sheetfed scanner" */ /* status="complete" */ { NULL, NULL, 0x0638, 0x0A2F, "Avision", "AV210C2-G", - AV_INT_BUTTON | AV_GRAY_MODES,0}, + AV_INT_BUTTON | AV_GRAY_MODES}, /* comment="sheetfed scanner" */ /* status="complete" */ { NULL, NULL, 0x0638, 0x1A35, "Avision", "AV210D2+", - AV_INT_BUTTON, AV_USE_GRAY_FILTER}, + AV_INT_BUTTON | AV_USE_GRAY_FILTER}, /* comment="sheetfed scanner" */ /* status="complete" */ { NULL, NULL, 0x0638, 0x0A23, "Avision", "AV220", - AV_INT_BUTTON | AV_GRAY_MODES,0}, + AV_INT_BUTTON | AV_GRAY_MODES}, /* comment="duplex! sheetfed scanner" */ /* status="complete" */ { NULL, NULL, 0x0638, 0x0A2A, "Avision", "AV220C2", - AV_INT_BUTTON | AV_CANCEL_BUTTON,0}, + AV_INT_BUTTON | AV_CANCEL_BUTTON}, /* comment="duplex! sheetfed scanner" */ /* status="complete" */ { NULL, NULL, 0x0638, 0x0A2B, "Avision", "AV220D2", - AV_INT_BUTTON | AV_CANCEL_BUTTON,0}, + AV_INT_BUTTON | AV_CANCEL_BUTTON}, + /* comment="duplex! sheetfed scanner" */ + /* status="complete" */ + + { NULL, NULL, + 0x0638, 0x1A31, + "Avision", "AV220D2+", + AV_INT_BUTTON | AV_CANCEL_BUTTON | AV_USE_GRAY_FILTER}, /* comment="duplex! sheetfed scanner" */ /* status="complete" */ { NULL, NULL, 0x0638, 0x0A2C, "Avision", "AV220+", - AV_INT_BUTTON | AV_CANCEL_BUTTON,0}, + AV_INT_BUTTON | AV_CANCEL_BUTTON}, /* comment="duplex! sheetfed scanner" */ /* status="complete" */ { NULL, NULL, 0x0638, 0x0A2D, "Avision", "AV220C2-G", - AV_INT_BUTTON | AV_CANCEL_BUTTON,0}, + AV_INT_BUTTON | AV_CANCEL_BUTTON}, /* comment="duplex! sheetfed scanner" */ /* status="complete" */ { NULL, NULL, 0x0638, 0x0A2E, "Avision", "AV220C2-B", - AV_INT_BUTTON | AV_CANCEL_BUTTON,0}, + AV_INT_BUTTON | AV_CANCEL_BUTTON}, /* comment="duplex! sheetfed scanner" */ /* status="complete" */ { NULL, NULL, 0x0638, 0x0A94, "Avision", "AV220-G", - AV_INT_BUTTON | AV_2ND_LINE_INTERLACED, AV_FIRMWARE}, + AV_INT_BUTTON | AV_2ND_LINE_INTERLACED | AV_FIRMWARE}, /* comment="duplex! sheetfed scanner" */ /* status="complete" */ { "AVISION", "AV240SC", 0, 0, "Avision", "AV240SC", - 0,0}, + 0}, /* status="untested" */ { "AVISION", "AV260CS", 0, 0, "Avision", "AV260CS", - 0,0}, + 0}, /* status="untested" */ { "AVISION", "AV360CS", 0, 0, "Avision", "AV360CS", - 0,0}, + 0}, /* status="untested" */ { "AVISION", "AV363CS", 0, 0, "Avision", "AV363CS", - 0,0}, + 0}, /* status="untested" */ { "AVISION", "AV420CS", 0, 0, "Avision", "AV420CS", - 0,0}, + 0}, /* status="untested" */ { "AVISION", "AV6120", 0, 0, "Avision", "AV6120", - 0,0}, + 0}, /* status="untested" */ { NULL, "AV610", 0x0638, 0x0a18, "Avision", "AV610", - AV_GRAY_CALIB_BLUE | AV_ACCEL_TABLE | AV_NO_64BYTE_ALIGN | AV_INT_BUTTON, 0}, + AV_GRAY_CALIB_BLUE | AV_ACCEL_TABLE | AV_NO_64BYTE_ALIGN | AV_INT_BUTTON}, /* status="good" */ { NULL, NULL, 0x0638, 0x0a18, "Avision", "AV600U Plus", /* If this unit requires the AV_INT_STATUS flag, then we'll need to alter the code to deal with two different devices with the same USB id (AV610 above) */ - AV_GRAY_CALIB_BLUE | AV_ACCEL_TABLE | AV_NO_64BYTE_ALIGN | /* AV_INT_STATUS | */ AV_INT_BUTTON,0}, + AV_GRAY_CALIB_BLUE | AV_ACCEL_TABLE | AV_NO_64BYTE_ALIGN | /* AV_INT_STATUS | */ AV_INT_BUTTON}, /* status="good" */ { NULL, NULL, 0x0638, 0x0a5e, "Avision", "AV610C2", - AV_NO_BACKGROUND | AV_INT_BUTTON,0}, /* cancel button -> sense abort! */ + AV_NO_BACKGROUND | AV_INT_BUTTON}, /* cancel button -> sense abort! */ /* status="good" */ { NULL, NULL, 0x0638, 0x0a41, "Avision", "AM3000 Series", - 0,0}, + 0}, /* comment="MFD" */ /* status="basic" */ { NULL, NULL, 0x0638, 0x0a16, "Avision", "DS610CU Scancopier", - AV_INT_STATUS,0}, + AV_INT_STATUS}, /* comment="1 pass, 600 dpi, A4" */ /* status="good" */ { "AVISION", "AV620CS", 0, 0, "Avision", "AV620CS", - 0,0}, + 0}, /* comment="1 pass, 600 dpi" */ /* status="complete" */ { "AVISION", "AV620CS Plus", 0, 0, "Avision", "AV620CS Plus", - 0,0}, + 0}, /* comment="1 pass, 1200 dpi" */ /* status="complete" */ { "AVISION", "AV630CS", 0, 0, "Avision", "AV630CS", - 0,0}, + 0}, /* comment="1 pass, 1200 dpi" */ /* status="complete" */ { "AVISION", "AV630CSL", 0, 0, "Avision", "AV630CSL", - 0,0}, + 0}, /* comment="1 pass, 1200 dpi" */ /* status="untested" */ { "AVISION", "AV6240", 0, 0, "Avision", "AV6240", - 0,0}, + 0}, /* comment="1 pass, ??? dpi" */ /* status="complete" */ { NULL, NULL, 0x0638, 0x0A13, "Avision", "AV600U", - AV_MULTI_CALIB_CMD | AV_ADF_BGR_ORDER_INVERT | AV_SOFT_SCALE | AV_INT_STATUS | AV_NO_BUTTON,0}, + AV_MULTI_CALIB_CMD | AV_ADF_BGR_ORDER_INVERT | AV_SOFT_SCALE | AV_INT_STATUS | AV_NO_BUTTON}, /* comment="1 pass, 600 dpi" */ /* status="good" */ { "AVISION", "AV660S", 0, 0, "Avision", "AV660S", - 0,0}, + 0}, /* comment="1 pass, ??? dpi" */ /* status="untested" */ { "AVISION", "AV680S", 0, 0, "Avision", "AV680S", - 0,0}, + 0}, /* comment="1 pass, ??? dpi" */ /* status="untested" */ { "AVISION", "AV690U", 0, 0, "Avision", "AV690U", - 0,0}, + 0}, /* comment="1 pass, 2400 dpi" */ /* status="untested" */ { "AVISION", "AV800S", 0, 0, "Avision", "AV800S", - 0,0}, + 0}, /* comment="1 pass, ??? dpi" */ /* status="untested" */ { "AVISION", "AV810C", 0, 0, "Avision", "AV810C", - 0,0}, + 0}, /* comment="1 pass, ??? dpi" */ /* status="untested" */ { "AVISION", "AV820", 0, 0, "Avision", "AV820", - 0,0}, + 0}, /* comment="1 pass, ??? dpi" */ /* status="untested" */ { "AVISION", "AV820C", 0, 0, "Avision", "AV820C", - 0,0}, + 0}, /* comment="1 pass, ??? dpi" */ /* status="complete" */ { "AVISION", "AV820C Plus", 0, 0, "Avision", "AV820C Plus", - 0,0}, + 0}, /* comment="1 pass, ??? dpi" */ /* status="complete" */ { "AVISION", "AV830C", 0, 0, "Avision", "AV830C", - 0,0}, + 0}, /* comment="1 pass, ??? dpi" */ /* status="complete" */ { "AVISION", "AV830C Plus", 0, 0, "Avision", "AV830C Plus", - 0,0}, + 0}, /* comment="1 pass, ??? dpi" */ /* status="untested" */ { "AVISION", "AV880", 0, 0, "Avision", "AV880", - 0,0}, + 0}, /* comment="1 pass, ??? dpi" */ /* status="untested" */ { "AVISION", "AV880C", 0, 0, "Avision", "AV880C", - 0,0}, + 0}, /* comment="1 pass, ??? dpi" */ /* status="untested" */ { "AVISION", "AV3200C", 0, 0, "Avision", "AV3200C", - AV_NON_INTERLACED_DUPLEX_300 | AV_FASTER_WITH_FILTER,0}, + AV_NON_INTERLACED_DUPLEX_300 | AV_FASTER_WITH_FILTER}, /* comment="1 pass, ??? dpi" */ /* status="complete" */ { "AVISION", "AV3200SU", 0x0638, 0x0A4E, "Avision", "AV3200SU", - 0,0}, + 0}, /* comment="1 pass, ??? dpi" */ /* status="complete" */ { "AVISION", "AV3730SU", 0x0638, 0x0A4F, "Avision", "AV3730SU", - 0,0}, + 0}, /* comment="1 pass, ??? dpi" */ /* status="complete" */ { "AVISION", "AV3750SU", 0x0638, 0x0A65, "Avision", "AV3750SU", - 0,0}, + 0}, /* comment="1 pass, ??? dpi" */ /* status="complete" */ { "AVISION", "AV3800C", 0, 0, "Avision", "AV3800C", - 0,0}, + 0}, /* comment="1 pass, ??? dpi" */ /* status="complete" */ { "AVISION", "AV3850SU", 0x0638, 0x0a66, "Avision", "AV3850SU", - 0,0}, + 0}, /* comment="1 pass, ??? dpi" */ /* status="complete" */ { "AVISION", "FB6000E", 0, 0, "Avision", "FB6000E", - AV_NON_INTERLACED_DUPLEX_300,0}, + AV_NON_INTERLACED_DUPLEX_300}, /* comment="1 pass, 1200 dpi, A3 - duplex! - zero edge!" */ /* status="complete" */ { NULL, NULL, 0x0638, 0x0a82, "Avision", "FB6080E", - AV_NON_INTERLACED_DUPLEX_300,0}, + AV_NON_INTERLACED_DUPLEX_300}, /* comment="1 pass, 1200 dpi, A3 - duplex! - zero edge!" */ /* status="complete" */ { NULL, NULL, 0x0638, 0x0a84, "Avision", "FB2080E", - 0,0}, + 0}, /* comment="1 pass, 600 dpi, zero-edge" ASIC 7 */ /* status="basic" */ { "AVISION", "AV8000S", 0, 0, "Avision", "AV8000S", - AV_DOES_NOT_KEEP_WINDOW,0}, + AV_DOES_NOT_KEEP_WINDOW}, /* comment="1 pass, 1200 dpi, A3" */ /* status="complete" */ { NULL, NULL, 0x0638, 0x0a4d, "Avision", "AV8050U", - AV_NON_INTERLACED_DUPLEX_300 | AV_DOES_NOT_KEEP_GAMMA,0}, + AV_NON_INTERLACED_DUPLEX_300 | AV_DOES_NOT_KEEP_GAMMA}, /* comment="1 pass, 1200 dpi, A3 - duplex!" */ /* status="complete" */ { "AVISION", "AV8300", 0x0638, 0x0A40, "Avision", "AV8300", - AV_NON_INTERLACED_DUPLEX_300 | AV_DOES_NOT_KEEP_GAMMA,0}, + AV_NON_INTERLACED_DUPLEX_300 | AV_DOES_NOT_KEEP_GAMMA}, /* comment="1 pass, 1200 dpi, A3 - duplex!" */ /* status="complete" */ { "AVISION", "AV8350", 0x0638, 0x0A68, "Avision", "AV8350", - AV_NON_INTERLACED_DUPLEX_300 | AV_DOES_NOT_KEEP_GAMMA,0}, + AV_NON_INTERLACED_DUPLEX_300 | AV_DOES_NOT_KEEP_GAMMA}, /* comment="1 pass, 1200 dpi, A3 - duplex!" */ /* status="complete" */ { NULL, NULL, 0x0638, 0x0A61, "Avision", "IT8300", - AV_NON_INTERLACED_DUPLEX_300 | AV_ACCEL_TABLE,0}, + AV_NON_INTERLACED_DUPLEX_300 | AV_ACCEL_TABLE}, /* comment="1 pass, 1200 dpi, A3 - duplex!, LCD screen, paper sensors" */ /* status="good" */ { NULL, NULL, 0x0638, 0x0AA1, "Avision", "@V2500", - 0,0}, + 0}, /* comment="" */ /* status="untested" */ { NULL, NULL, 0x0638, 0x0A45, "Avision", "@V5100", - 0,0}, + 0}, /* comment="1 pass, 1200 dpi, A3 - duplex!, LCD screen, paper sensors" */ /* status="good" */ { "AVISION", "AVA3", 0, 0, "Avision", "AVA3", - AV_FORCE_A3,0}, + AV_FORCE_A3}, /* comment="1 pass, 600 dpi, A3" */ /* status="basic" */ @@ -613,21 +617,21 @@ static Avision_HWEntry Avision_Device_List [] = { "HP", "ScanJet 5300C", 0x03f0, 0x0701, "Hewlett-Packard", "ScanJet 5300C", - AV_INT_STATUS,0}, + AV_INT_STATUS}, /* comment="1 pass, 2400 dpi - some FW revisions have x-axis image scaling problems over 1200 dpi" */ /* status="complete" */ { "HP", "ScanJet 5370C", 0x03f0, 0x0701, "Hewlett-Packard", "ScanJet 5370C", - AV_MULTI_CALIB_CMD | AV_INT_STATUS, AV_FIRMWARE }, + AV_MULTI_CALIB_CMD | AV_INT_STATUS}, /* comment="1 pass, 2400 dpi - some FW revisions have x-axis image scaling problems over 1200 dpi" */ /* status="good" */ { "hp", "scanjet 7400c", 0x03f0, 0x0801, "Hewlett-Packard", "ScanJet 7400c", - AV_LIGHT_CHECK_BOGUS | AV_NO_64BYTE_ALIGN | AV_INT_STATUS,0}, + AV_LIGHT_CHECK_BOGUS | AV_NO_64BYTE_ALIGN | AV_INT_STATUS}, /* comment="1 pass, 2400 dpi - dual USB/SCSI interface" */ /* status="good" */ @@ -635,14 +639,14 @@ static Avision_HWEntry Avision_Device_List [] = { "hp", "scanjet 7450c", 0x03f0, 0x0801, "Hewlett-Packard", "ScanJet 7450c", - AV_NO_64BYTE_ALIGN | AV_INT_STATUS,0}, + AV_NO_64BYTE_ALIGN | AV_INT_STATUS}, /* comment="1 pass, 2400 dpi - dual USB/SCSI interface" */ /* status="good" */ { "hp", "scanjet 7490c", 0x03f0, 0x0801, "Hewlett-Packard", "ScanJet 7490c", - AV_NO_64BYTE_ALIGN | AV_INT_STATUS,0}, + AV_NO_64BYTE_ALIGN | AV_INT_STATUS}, /* comment="1 pass, 1200 dpi - dual USB/SCSI interface" */ /* status="good" */ @@ -650,7 +654,7 @@ static Avision_HWEntry Avision_Device_List [] = { "HP", "C9930A", 0x03f0, 0x0b01, "Hewlett-Packard", "ScanJet 8200", - 0, AV_ADF_FLIPPING_DUPLEX | AV_FIRMWARE }, + AV_ADF_FLIPPING_DUPLEX | AV_FIRMWARE}, /* comment="1 pass, 4800 (?) dpi - USB 2.0" */ /* status="good" */ @@ -658,7 +662,7 @@ static Avision_HWEntry Avision_Device_List [] = { "HP", "C9930A", 0x03f0, 0x0b01, "Hewlett-Packard", "ScanJet 8250", - 0, AV_ADF_FLIPPING_DUPLEX | AV_FIRMWARE }, + AV_ADF_FLIPPING_DUPLEX | AV_FIRMWARE}, /* comment="1 pass, 4800 (?) dpi - USB 2.0" */ /* status="good" */ #endif @@ -666,7 +670,7 @@ static Avision_HWEntry Avision_Device_List [] = { "HP", "C9930A", 0x03f0, 0x3905, "Hewlett-Packard", "ScanJet 8270", - 0, AV_ADF_FLIPPING_DUPLEX | AV_FIRMWARE }, + AV_ADF_FLIPPING_DUPLEX | AV_FIRMWARE}, /* comment="1 pass, 4800 (?) dpi - USB 2.0" */ /* status="good" */ @@ -674,7 +678,7 @@ static Avision_HWEntry Avision_Device_List [] = { "HP", "C9930A", 0x03f0, 0x0b01, "Hewlett-Packard", "ScanJet 8290", - 0, AV_ADF_FLIPPING_DUPLEX | AV_FIRMWARE }, + AV_ADF_FLIPPING_DUPLEX | AV_FIRMWARE}, /* comment="1 pass, 4800 (?) dpi - USB 2.0 and SCSI - only SCSI tested so far" */ /* status="good" */ @@ -682,7 +686,7 @@ static Avision_HWEntry Avision_Device_List [] = { "HP", "C9930A", 0x03f0, 0x3805, "Hewlett-Packard", "ScanJet 8300", - 0,0}, + 0}, /* comment="1 pass, 4800 (?) dpi - USB 2.0" */ /* status="good" */ @@ -690,14 +694,14 @@ static Avision_HWEntry Avision_Device_List [] = { "HP", "C9930A", 0x03f0, 0x3805, "Hewlett-Packard", "ScanJet 8350", - 0,0}, + 0}, /* comment="1 pass, 4800 (?) dpi - USB 2.0" */ /* status="good" */ { "HP", "C9930A", 0x03f0, 0x3805, "Hewlett-Packard", "ScanJet 8390", - 0,0}, + 0}, /* comment="1 pass, 4800 (?) dpi - USB 2.0" */ /* status="good" */ @@ -705,79 +709,79 @@ static Avision_HWEntry Avision_Device_List [] = { "Minolta", "#2882", 0, 0, "Minolta", "Dimage Scan Dual I", - AV_FORCE_FILM | AV_NO_START_SCAN,0}, /* not AV_FILMSCANNER (no frame control) */ + AV_FORCE_FILM | AV_NO_START_SCAN}, /* not AV_FILMSCANNER (no frame control) */ /* status="basic" */ { "Minolta", "#2887", 0, 0, "Minolta", "Scan Multi Pro", - AV_FORCE_FILM | AV_NO_START_SCAN,0}, /* AV_FILMSCANNER (frame control)? */ + AV_FORCE_FILM | AV_NO_START_SCAN}, /* AV_FILMSCANNER (frame control)? */ /* status="untested" */ { "MINOLTA", "FS-V1", 0x0638, 0x026a, "Minolta", "Dimage Scan Dual II", - AV_FILMSCANNER | AV_ONE_CALIB_CMD | AV_12_BIT_MODE,0}, + AV_FILMSCANNER | AV_ONE_CALIB_CMD | AV_12_BIT_MODE}, /* comment="1 pass, film-scanner" */ /* status="good" */ { "MINOLTA", "Elite II", 0x0686, 0x4004, "Minolta", "Elite II", - AV_FILMSCANNER | AV_ONE_CALIB_CMD,0}, + AV_FILMSCANNER | AV_ONE_CALIB_CMD}, /* comment="1 pass, film-scanner" */ /* status="untested" */ { "MINOLTA", "FS-V3", 0x0686, 0x400d, "Minolta", "Dimage Scan Dual III", - AV_FILMSCANNER | AV_ONE_CALIB_CMD | AV_ACCEL_TABLE ,0}, + AV_FILMSCANNER | AV_ONE_CALIB_CMD | AV_ACCEL_TABLE}, /* comment="1 pass, film-scanner" */ /* status="good" */ { "MINOLTA", "FS-V4", 0x0686, 0x400e, "Minolta", "Dimage Scan Elite 5400", - AV_FILMSCANNER | AV_ONE_CALIB_CMD | /*AV_ACCEL_TABLE |*/ AV_NO_START_SCAN,0}, + AV_FILMSCANNER | AV_ONE_CALIB_CMD | /*AV_ACCEL_TABLE |*/ AV_NO_START_SCAN}, /* comment="1 pass, film-scanner" */ /* status="good" */ { "QMS", "SC-110", 0x0638, 0x0a15, "Minolta-QMS", "SC-110", - 0,0}, + 0}, /* comment="" */ /* status="untested" */ { "QMS", "SC-215", 0x0638, 0x0a16, "Minolta-QMS", "SC-215", - 0,0}, + 0}, /* comment="" */ /* status="good" */ { "MITSBISH", "MCA-ADFC", 0, 0, "Mitsubishi", "MCA-ADFC", - 0,0}, + 0}, /* status="untested" */ { "MITSBISH", "MCA-S1200C", 0, 0, "Mitsubishi", "S1200C", - 0,0}, + 0}, /* status="untested" */ { "MITSBISH", "MCA-S600C", 0, 0, "Mitsubishi", "S600C", - 0,0}, + 0}, /* status="untested" */ { "MITSBISH", "SS600", 0, 0, "Mitsubishi", "SS600", - 0,0}, + 0}, /* status="good" */ /* The next are all untested ... */ @@ -785,209 +789,209 @@ static Avision_HWEntry Avision_Device_List [] = { "FCPA", "ScanPartner", 0, 0, "Fujitsu", "ScanPartner", - AV_FUJITSU,0}, + AV_FUJITSU}, /* status="untested" */ { "FCPA", "ScanPartner 10", 0, 0, "Fujitsu", "ScanPartner 10", - AV_FUJITSU,0}, + AV_FUJITSU}, /* status="untested" */ { "FCPA", "ScanPartner 10C", 0, 0, "Fujitsu", "ScanPartner 10C", - AV_FUJITSU,0}, + AV_FUJITSU}, /* status="untested" */ { "FCPA", "ScanPartner 15C", 0, 0, "Fujitsu", "ScanPartner 15C", - AV_FUJITSU,0}, + AV_FUJITSU}, /* status="untested" */ { "FCPA", "ScanPartner 300C", 0, 0, "Fujitsu", "ScanPartner 300C", - 0,0}, + 0}, /* status="untested" */ { "FCPA", "ScanPartner 600C", 0, 0, "Fujitsu", "ScanPartner 600C", - 0,0}, + 0}, /* status="untested" */ { "FCPA", "ScanPartner 620C", 0, 0, "Fujitsu", "ScanPartner 620C", - AV_LIGHT_CHECK_BOGUS,0}, + AV_LIGHT_CHECK_BOGUS}, /* status="good" */ { "FCPA", "ScanPartner Jr", 0, 0, "Fujitsu", "ScanPartner Jr", - 0,0}, + 0}, /* status="untested" */ { "FCPA", "ScanStation", 0, 0, "Fujitsu", "ScanStation", - 0,0}, + 0}, /* status="untested" */ { NULL, NULL, 0x04c5, 0x1029, "Fujitsu", "fi-4010CU", - 0,0}, + 0}, /* status="untested" */ { NULL, NULL, 0x04c5, 0x10ef, "Fujitsu", "fi-5015C", - 0,0}, + 0}, /* status="good" */ { NULL, NULL, 0x040a, 0x6001, "Kodak", "i30", - AV_INT_BUTTON | AV_GRAY_MODES,0}, + AV_INT_BUTTON | AV_GRAY_MODES}, /* status="untested" */ { NULL, NULL, 0x040a, 0x6002, "Kodak", "i40", - AV_INT_BUTTON | AV_GRAY_MODES,0}, + AV_INT_BUTTON | AV_GRAY_MODES}, /* status="basic" */ { NULL, NULL, 0x040a, 0x6003, "Kodak", "i50", - AV_INT_BUTTON,0}, + AV_INT_BUTTON}, /* status="untested" */ #ifdef FAKE_ENTRIES_FOR_DESC_GENERATION { NULL, NULL, 0x040a, 0x6003, "Kodak", "i55", - AV_INT_BUTTON,0}, + AV_INT_BUTTON}, /* status="untested" */ #endif { NULL, NULL, 0x040a, 0x6004, "Kodak", "i60", - AV_INT_BUTTON,0}, + AV_INT_BUTTON}, /* status="untested" */ #ifdef FAKE_ENTRIES_FOR_DESC_GENERATION { NULL, NULL, 0x040a, 0x6004, "Kodak", "i65", - AV_INT_BUTTON,0}, + AV_INT_BUTTON}, /* status="untested" */ #endif { NULL, NULL, 0x040a, 0x6005, "Kodak", "i80", - AV_INT_BUTTON,0}, + AV_INT_BUTTON}, /* status="good" */ { "iVina", "1200U", 0x0638, 0x0268, "iVina", "1200U", - 0,0}, + 0}, /* status="untested" */ { NULL, NULL, 0x04a7, 0x0424, "Visioneer", "Strobe XP 450", - AV_INT_BUTTON | AV_ACCEL_TABLE,0}, + AV_INT_BUTTON | AV_ACCEL_TABLE}, /* comment="sheetfed scanner" */ /* status="complete" */ { NULL, NULL, 0x04a7, 0x0491, "Visioneer", "Strobe XP 450-G", - AV_INT_BUTTON | AV_ACCEL_TABLE,0}, + AV_INT_BUTTON | AV_ACCEL_TABLE}, /* comment="sheetfed scanner" */ /* status="complete" */ { NULL, NULL, 0x04a7, 0x0479, "Visioneer", "Strobe XP 470", - AV_INT_BUTTON | AV_ACCEL_TABLE,0}, + AV_INT_BUTTON | AV_ACCEL_TABLE}, /* comment="sheetfed scanner" */ /* status="complete" */ { NULL, NULL, 0x04a7, 0x048F, "Visioneer", "Strobe XP 470-G", - AV_INT_BUTTON | AV_ACCEL_TABLE,0}, + AV_INT_BUTTON | AV_ACCEL_TABLE}, /* comment="sheetfed scanner" */ /* status="complete" */ { NULL, NULL, 0x04a7, 0x0420, "Visioneer", "9320", - 0,0}, + 0}, /* comment="sheetfed scanner" */ /* status="complete" */ { NULL, NULL, 0x04a7, 0x0421, "Visioneer", "9450", - AV_MULTI_CALIB_CMD | AV_ADF_BGR_ORDER_INVERT | AV_NO_BUTTON, AV_NO_TUNE_SCAN_LENGTH}, + AV_MULTI_CALIB_CMD | AV_ADF_BGR_ORDER_INVERT | AV_NO_BUTTON | AV_NO_TUNE_SCAN_LENGTH}, /* comment="sheetfed scanner" */ /* status="complete" */ { NULL, NULL, 0x04a7, 0x047A, "Visioneer", "9450-G", - 0,0}, + 0}, /* comment="sheetfed scanner" */ /* status="complete" */ { NULL, NULL, 0x04a7, 0x0422, "Visioneer", "9550", - 0,0}, + 0}, /* comment="sheetfed scanner" */ /* status="complete" */ { NULL, NULL, 0x04a7, 0x0390, "Visioneer", "9650", - 0,0}, + 0}, /* comment="sheetfed scanner" */ /* status="complete" */ { NULL, NULL, 0x04a7, 0x047B, "Visioneer", "9650-G", - 0,0}, + 0}, /* comment="sheetfed scanner" */ /* status="complete" */ { NULL, NULL, 0x04a7, 0x0423, "Visioneer", "9750", - AV_INT_BUTTON,0}, + AV_INT_BUTTON}, /* comment="sheetfed scanner" */ /* status="complete" */ { NULL, NULL, 0x04a7, 0x0493, "Visioneer", "9750-G", - AV_INT_BUTTON,0}, + AV_INT_BUTTON}, /* comment="sheetfed scanner" */ /* status="complete" */ { NULL, NULL, 0x04a7, 0x0497, "Visioneer", "Patriot 430", - AV_INT_BUTTON | AV_2ND_LINE_INTERLACED | AV_NO_REAR | AV_SOFT_SCALE | AV_DOES_KEEP_WINDOW | AV_DOES_KEEP_GAMMA | AV_REAR_OFFSET,0}, + AV_INT_BUTTON | AV_2ND_LINE_INTERLACED | AV_NO_REAR | AV_SOFT_SCALE | AV_DOES_KEEP_WINDOW | AV_DOES_KEEP_GAMMA | AV_REAR_OFFSET}, /* comment="sheetfed scanner" */ /* status="complete" */ @@ -995,7 +999,7 @@ static Avision_HWEntry Avision_Device_List [] = { NULL, NULL, 0x04a7, 0x048F, "Visioneer", "Patriot 470", - AV_INT_BUTTON,0}, + AV_INT_BUTTON}, /* comment="sheetfed scanner" */ /* status="complete" */ #endif @@ -1003,150 +1007,150 @@ static Avision_HWEntry Avision_Device_List [] = { NULL, NULL, 0x04a7, 0x0498, "Visioneer", "Patriot 680", - AV_INT_BUTTON,0}, + AV_INT_BUTTON}, /* comment="sheetfed scanner" */ /* status="complete" */ { NULL, NULL, 0x04a7, 0x0499, "Visioneer", "Patriot 780", - AV_INT_BUTTON,0}, + AV_INT_BUTTON}, /* comment="sheetfed scanner" */ /* status="complete" */ { NULL, NULL, 0x04a7, 0x049C, "Xerox", "DocuMate150", - AV_INT_BUTTON | AV_SOFT_SCALE | AV_DOES_KEEP_WINDOW | AV_DOES_KEEP_GAMMA | AV_BACKGROUND_QUIRK,0}, + AV_INT_BUTTON | AV_SOFT_SCALE | AV_DOES_KEEP_WINDOW | AV_DOES_KEEP_GAMMA | AV_BACKGROUND_QUIRK}, /* status="good" */ { NULL, NULL, 0x04a7, 0x0477, "Xerox", "DocuMate152", - AV_INT_BUTTON | AV_2ND_LINE_INTERLACED | AV_NO_REAR | AV_SOFT_SCALE | AV_DOES_KEEP_WINDOW | AV_DOES_KEEP_GAMMA | AV_REAR_OFFSET | AV_BACKGROUND_QUIRK,0}, + AV_INT_BUTTON | AV_2ND_LINE_INTERLACED | AV_NO_REAR | AV_SOFT_SCALE | AV_DOES_KEEP_WINDOW | AV_DOES_KEEP_GAMMA | AV_REAR_OFFSET | AV_BACKGROUND_QUIRK}, /* status="good" */ { NULL, NULL, 0x04a7, 0x049D, "Xerox", "DocuMate162", - AV_INT_BUTTON | AV_2ND_LINE_INTERLACED | AV_NO_REAR | AV_SOFT_SCALE | AV_DOES_KEEP_WINDOW | AV_DOES_KEEP_GAMMA | AV_REAR_OFFSET | AV_BACKGROUND_QUIRK,0}, + AV_INT_BUTTON | AV_2ND_LINE_INTERLACED | AV_NO_REAR | AV_SOFT_SCALE | AV_DOES_KEEP_WINDOW | AV_DOES_KEEP_GAMMA | AV_REAR_OFFSET | AV_BACKGROUND_QUIRK}, /* status="good" */ { NULL, NULL, 0x04a7, 0x0448, "Xerox", "DocuMate250", - AV_INT_BUTTON,0}, + AV_INT_BUTTON}, /* status="good" */ { NULL, NULL, 0x04a7, 0x0490, "Xerox", "DocuMate250-G", - AV_INT_BUTTON,0}, + AV_INT_BUTTON}, /* status="good" */ { NULL, NULL, 0x04a7, 0x0449, "Xerox", "DocuMate252", - AV_INT_BUTTON,0}, + AV_INT_BUTTON}, /* status="good" */ { NULL, NULL, 0x04a7, 0x048C, "Xerox", "DocuMate252-G", - AV_INT_BUTTON,0}, + AV_INT_BUTTON}, /* status="good" */ { NULL, NULL, 0x04a7, 0x0476, "Xerox", "DocuMate232", - AV_INT_BUTTON,0}, + AV_INT_BUTTON}, /* status="good" */ { NULL, NULL, 0x04a7, 0x044c, "Xerox", "DocuMate262", - AV_INT_BUTTON,0}, + AV_INT_BUTTON}, /* status="good" */ { NULL, NULL, 0x04a7, 0x048D, "Xerox", "DocuMate262-G", - AV_INT_BUTTON,0}, + AV_INT_BUTTON}, /* status="good" */ { NULL, NULL, 0x04a7, 0x04a7, "Xerox", "DocuMate262i", - AV_INT_BUTTON,0}, + AV_INT_BUTTON}, /* status="good" */ { NULL, NULL, 0x04a7, 0x0475, "Xerox", "DocuMate272", - AV_INT_BUTTON,0}, + AV_INT_BUTTON}, /* status="untested" */ { NULL, NULL, 0x04a7, 0x048E, "Xerox", "DocuMate272-G", - AV_INT_BUTTON,0}, + AV_INT_BUTTON}, /* status="untested" */ { NULL, NULL, 0x04a7, 0x0446, "Xerox", "DocuMate510", - AV_INT_BUTTON,0}, + AV_INT_BUTTON}, /* status="untested" */ { NULL, NULL, 0x04a7, 0x0495, "Xerox", "DocuMate512", - AV_INT_BUTTON,0}, + AV_INT_BUTTON}, /* status="untested" */ { NULL, NULL, 0x04a7, 0x047c, "Xerox", "DocuMate510-G", - AV_INT_BUTTON,0}, + AV_INT_BUTTON}, /* status="untested" */ { NULL, NULL, 0x04a7, 0x0447, "Xerox", "DocuMate520", - AV_INT_BUTTON,0}, + AV_INT_BUTTON}, /* status="untested" */ { NULL, NULL, 0x04a7, 0x0492, "Xerox", "DocuMate520-G", - AV_INT_BUTTON,0}, + AV_INT_BUTTON}, /* status="untested" */ #ifdef FAKE_ENTRIES_FOR_DESC_GENERATION { NULL, NULL, 0x04a7, 0x0498, "Xerox", "DocuMate632", - AV_INT_BUTTON,0}, + AV_INT_BUTTON}, /* status="untested" */ #endif { NULL, NULL, 0x04a7, 0x0478, "Xerox", "DocuMate752", - AV_INT_BUTTON,0}, + AV_INT_BUTTON}, /* status="untested" */ { NULL, NULL, 0x04a7, 0x049A, "Xerox", "DocuMate752", - AV_INT_BUTTON,0}, + AV_INT_BUTTON}, /* status="untested" */ #ifdef FAKE_ENTRIES_FOR_DESC_GENERATION { NULL, NULL, 0x0638, 0x0a16, "OKI", "S700 Scancopier", - 0,0}, + 0}, /* comment="1 pass, 600 dpi, A4" */ /* status="good" */ #endif @@ -1154,14 +1158,14 @@ static Avision_HWEntry Avision_Device_List [] = { "B+H", "2000F", 0, 0, "Bell+Howell", "2000F", - 0,0}, + 0}, /* comment="1 pass, ??? dpi, A4" */ /* status="basic" */ { NULL, NULL, 0x0482, 0x0335, "Kyocera", "FS-1016MFP", - 0,0}, + 0}, /* comment="1 pass, ??? dpi, A4" */ /* status="untested" */ @@ -1203,7 +1207,7 @@ Lexmark X4500 MFP { NULL, NULL, 0, 0, NULL, NULL, - 0,0} + 0} }; #if 0 @@ -3208,7 +3212,7 @@ get_accessories_info (Avision_Scanner* s) dev->inquiry_adf |= result [0]; - if (dev->hw->feature_type2 & AV_ADF_FLIPPING_DUPLEX) + if (dev->hw->feature_type & AV_ADF_FLIPPING_DUPLEX) { if (result[0] == 1) { @@ -3765,14 +3769,14 @@ attach (SANE_String_Const devname, Avision_ConnectionType con_type, if (!found) { DBG (0, "attach: \"%s\" - \"%s\" not yet in whitelist!\n", mfg, model); DBG (0, "attach: You might want to report this output.\n"); - DBG (0, "attach: To: mike@piratehaven.org (the Avision backend maintainer)\n"); + DBG (0, "attach: To: rene@exactcode.de (the Avision backend author)\n"); status = SANE_STATUS_INVAL; goto close_scanner_and_return; } /* second: maybe ask for the firmware status and flash ram info */ - if (Avision_Device_List [model_num].feature_type2 & AV_FIRMWARE) + if (Avision_Device_List [model_num].feature_type & AV_FIRMWARE) { DBG (3, "attach: reading firmware status\n"); status = get_firmware_status (&av_con); @@ -4211,7 +4215,7 @@ get_double ( &(result[48] ) )); } dev->inquiry_tune_scan_length = BIT(result[94],2); - if (Avision_Device_List [model_num].feature_type2 & AV_NO_TUNE_SCAN_LENGTH) + if (Avision_Device_List [model_num].feature_type & AV_NO_TUNE_SCAN_LENGTH) dev->inquiry_tune_scan_length = 0; dev->inquiry_background_raster = BIT(result[95],2); @@ -4278,7 +4282,9 @@ get_double ( &(result[48] ) )); else dev->scsi_buffer_size = sanei_scsi_max_request_size; - if (dev->inquiry_asic_type >= AV_ASIC_C5) + if (dev->inquiry_asic_type > AV_ASIC_C7 && dev->inquiry_asic_type < AV_ASIC_OA980) + dev->read_stripe_size = 16; + else if (dev->inquiry_asic_type >= AV_ASIC_C5) dev->read_stripe_size = 32; else /* tested on AV3200 with it's max of 300dpi @color */ dev->read_stripe_size = 8; /* maybe made dynamic on scan res ... */ @@ -5142,7 +5148,7 @@ send_gamma (Avision_Scanner* s) switch (dev->inquiry_asic_type) { case AV_ASIC_Cx: - case AV_ASIC_C1: /* from avision code */ + case AV_ASIC_C1: gamma_table_raw_size = 4096; gamma_table_size = 2048; break; @@ -5150,10 +5156,6 @@ send_gamma (Avision_Scanner* s) gamma_table_raw_size = 256; gamma_table_size = 256; break; - case AV_ASIC_C6: /* SPEC claims: 256 ... ? */ - case AV_ASIC_C7: - gamma_table_raw_size = 512; - gamma_table_size = 512; break; case AV_ASIC_OA980: gamma_table_raw_size = 4096; @@ -5164,7 +5166,8 @@ send_gamma (Avision_Scanner* s) gamma_table_size = 256; break; default: - gamma_table_raw_size = gamma_table_size = 4096; + gamma_table_raw_size = 512; /* SPEC claims: 256 ... ? */ + gamma_table_size = 512; } gamma_values = gamma_table_size / 256; @@ -5678,8 +5681,9 @@ set_window (Avision_Scanner* s) } } - if (s->val[OPT_PAPERLEN].w) + if (s->val[OPT_PAPERLEN].w != SANE_FALSE) { set_double (cmd.window.descriptor.paper_length, (int)((double)30.0*1200)); + } if ( !(dev->hw->feature_type & AV_FUJITSU) ) { @@ -5780,7 +5784,7 @@ set_window (Avision_Scanner* s) else { if (dev->hw->feature_type & AV_FASTER_WITH_FILTER) cmd.window.avision.bitset1 |= AVISION_FILTER_GREEN; - else if (dev->hw->feature_type2 & AV_USE_GRAY_FILTER) + else if (dev->hw->feature_type & AV_USE_GRAY_FILTER) cmd.window.avision.bitset1 |= AVISION_FILTER_GRAY; else cmd.window.avision.bitset1 |= AVISION_FILTER_NONE; @@ -6182,7 +6186,7 @@ do_eof (Avision_Scanner *s) /* we can now mark the rear data as valid */ if (s->avdimen.interlaced_duplex || - (s->hw->hw->feature_type2 & AV_ADF_FLIPPING_DUPLEX && s->source_mode == AV_ADF_DUPLEX)) { + (s->hw->hw->feature_type & AV_ADF_FLIPPING_DUPLEX && s->source_mode == AV_ADF_DUPLEX)) { DBG (3, "do_eof: toggling duplex rear data valid\n"); s->duplex_rear_valid = !s->duplex_rear_valid; DBG (3, "do_eof: duplex rear data valid: %x\n", @@ -6262,11 +6266,6 @@ init_options (Avision_Scanner* s) /* Init the SANE option from the scanner inquiry data */ - dev->x_range.max = SANE_FIX ( (int)dev->inquiry_x_ranges[s->source_mode_dim]); - dev->x_range.quant = 0; - dev->y_range.max = SANE_FIX ( (int)dev->inquiry_y_ranges[s->source_mode_dim]); - dev->y_range.quant = 0; - switch (dev->inquiry_asic_type) { case AV_ASIC_C2: dev->dpi_range.min = 100; @@ -6331,6 +6330,11 @@ init_options (Avision_Scanner* s) s->source_mode = match_source_mode (dev, s->val[OPT_SOURCE].s); s->source_mode_dim = match_source_mode_dim (s->source_mode); + dev->x_range.max = SANE_FIX ( (int)dev->inquiry_x_ranges[s->source_mode_dim]); + dev->x_range.quant = 0; + dev->y_range.max = SANE_FIX ( (int)dev->inquiry_y_ranges[s->source_mode_dim]); + dev->y_range.quant = 0; + /* resolution */ s->opt[OPT_RESOLUTION].name = SANE_NAME_SCAN_RESOLUTION; s->opt[OPT_RESOLUTION].title = SANE_TITLE_SCAN_RESOLUTION; @@ -6667,7 +6671,7 @@ init_options (Avision_Scanner* s) /* ADF page flipping */ s->opt[OPT_ADF_FLIP].cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_AUTOMATIC | SANE_CAP_ADVANCED; - if (!(s->hw->hw->feature_type2 & AV_ADF_FLIPPING_DUPLEX && s->source_mode == AV_ADF_DUPLEX)) + if (!(s->hw->hw->feature_type & AV_ADF_FLIPPING_DUPLEX && s->source_mode == AV_ADF_DUPLEX)) s->opt[OPT_ADF_FLIP].cap |= SANE_CAP_INACTIVE; s->opt[OPT_ADF_FLIP].name = "flip-page"; s->opt[OPT_ADF_FLIP].title = "Flip document after duplex scanning"; @@ -6782,7 +6786,7 @@ reader_process (void *data) return SANE_STATUS_NO_MEM; /* start scan ? */ - if ((deinterlace == NONE && !((dev->hw->feature_type2 & AV_ADF_FLIPPING_DUPLEX) && s->source_mode == AV_ADF_DUPLEX && s->duplex_rear_valid)) || + if ((deinterlace == NONE && !((dev->hw->feature_type & AV_ADF_FLIPPING_DUPLEX) && s->source_mode == AV_ADF_DUPLEX && s->duplex_rear_valid)) || (deinterlace != NONE && !s->duplex_rear_valid)) { /* reserve unit - in the past we did this in open - but the @@ -6820,7 +6824,7 @@ reader_process (void *data) /* setup file i/o for deinterlacing scans or if we are the back page with a flipping duplexer */ if (deinterlace != NONE || - (dev->hw->feature_type2 & AV_ADF_FLIPPING_DUPLEX && s->source_mode == AV_ADF_DUPLEX && !(s->page % 2))) + (dev->hw->feature_type & AV_ADF_FLIPPING_DUPLEX && s->source_mode == AV_ADF_DUPLEX && !(s->page % 2))) { if (!s->duplex_rear_valid) { /* create new file for writing */ DBG (3, "reader_process: opening duplex rear file for writing.\n"); @@ -6954,11 +6958,15 @@ reader_process (void *data) /* only EOF on the second stripe, as otherwise the rear page is shorter */ if (status == SANE_STATUS_EOF && deinterlace == STRIPE) { - static int already_eof = 0; - if (!already_eof) { - DBG (5, "reader_process: first EOF on stripe interlace: hiding.\n"); - status = SANE_STATUS_GOOD; - already_eof = 1; + if (dev->inquiry_asic_type > AV_ASIC_C7 && dev->inquiry_asic_type < AV_ASIC_OA980) { + this_read = 0; + } else { + static int already_eof = 0; + if (!already_eof) { + DBG (5, "reader_process: first EOF on stripe interlace: hiding.\n"); + status = SANE_STATUS_GOOD; + already_eof = 1; + } } } @@ -7047,7 +7055,7 @@ reader_process (void *data) DBG (9, "reader_process: after deinterlacing: useful_bytes: %d, stripe_fill: %d\n", useful_bytes, stripe_fill); } - if (dev->hw->feature_type2 & AV_ADF_FLIPPING_DUPLEX && s->source_mode == AV_ADF_DUPLEX && !(s->page % 2) && !s->duplex_rear_valid) { + 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; @@ -7454,7 +7462,7 @@ reader_process (void *data) /* Eject film holder and/or release_unit - but only for non-duplex-rear / non-virtual scans. */ if ((deinterlace != NONE && s->duplex_rear_valid) || - ((dev->hw->feature_type2 & AV_ADF_FLIPPING_DUPLEX) && s->source_mode == AV_ADF_DUPLEX && !(s->page % 2) && s->duplex_rear_valid)) + ((dev->hw->feature_type & AV_ADF_FLIPPING_DUPLEX) && s->source_mode == AV_ADF_DUPLEX && !(s->page % 2) && s->duplex_rear_valid)) { DBG (1, "reader_process: virtual duplex scan - no device cleanup!\n"); } @@ -7477,7 +7485,7 @@ reader_process (void *data) } } - if ((dev->hw->feature_type2 & AV_ADF_FLIPPING_DUPLEX) && s->source_mode == AV_ADF_DUPLEX && s->page % 2) { + if ((dev->hw->feature_type & AV_ADF_FLIPPING_DUPLEX) && s->source_mode == AV_ADF_DUPLEX && s->page % 2) { /* front page of flipping duplex */ if (exit_status == SANE_STATUS_EOF) { if (s->val[OPT_ADF_FLIP].w) { @@ -7891,7 +7899,7 @@ sane_open (SANE_String_Const devicename, SANE_Handle *handle) init_options (s); if (dev->inquiry_duplex_interlaced || dev->scanner_type == AV_FILM || - dev->hw->feature_type2 & AV_ADF_FLIPPING_DUPLEX) { + 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. */ strncpy(s->duplex_rear_fname, "/tmp/avision-rear-XXXXXX", PATH_MAX); @@ -8188,7 +8196,7 @@ sane_control_option (SANE_Handle handle, SANE_Int option, dev->y_range.max = SANE_FIX ( dev->inquiry_y_ranges[s->source_mode_dim]); - if (s->hw->hw->feature_type2 & AV_ADF_FLIPPING_DUPLEX && s->source_mode == AV_ADF_DUPLEX) { + if (s->hw->hw->feature_type & AV_ADF_FLIPPING_DUPLEX && s->source_mode == AV_ADF_DUPLEX) { s->opt[OPT_ADF_FLIP].cap &= ~SANE_CAP_INACTIVE; } else { s->opt[OPT_ADF_FLIP].cap |= SANE_CAP_INACTIVE; @@ -8284,16 +8292,9 @@ sane_get_parameters (SANE_Handle handle, SANE_Parameters* params) } if (params) { + *params = s->params; /* add background raster lines */ - s->params.lines += s->val[OPT_BACKGROUND].w; - - /* copy structure members */ - params->format = s->params.format; - params->last_frame = s->params.last_frame; - params->bytes_per_line = s->params.bytes_per_line; - params->pixels_per_line = s->params.pixels_per_line; - params->lines = s->params.lines; - params->depth = s->params.depth; + params->lines += s->val[OPT_BACKGROUND].w; } return SANE_STATUS_GOOD; diff --git a/backend/avision.h b/backend/avision.h index 14134e1..2122e09 100644 --- a/backend/avision.h +++ b/backend/avision.h @@ -93,123 +93,119 @@ typedef struct Avision_HWEntry { /* feature overwrites - as embedded CPUs have 16bit enums - this would need a change ... */ - enum { /* force no calibration */ - AV_NO_CALIB = (1<<0), + #define AV_NO_CALIB ((uint64_t)1<<0) /* force all in one command calibration */ - AV_ONE_CALIB_CMD = (1<<1), + #define AV_ONE_CALIB_CMD ((uint64_t)1<<1) /* no gamma table */ - AV_NO_GAMMA = (1<<2), + #define AV_NO_GAMMA ((uint64_t)1<<2) /* light check is bogus */ - AV_LIGHT_CHECK_BOGUS = (1<<3), + #define AV_LIGHT_CHECK_BOGUS ((uint64_t)1<<3) /* no button though the device advertise it */ - AV_NO_BUTTON = (1<<4), + #define AV_NO_BUTTON ((uint64_t)1<<4) /* if the scan area needs to be forced to A3 */ - AV_FORCE_A3 = (1<<5), + #define AV_FORCE_A3 ((uint64_t)1<<5) /* if the scan area and resolution needs to be forced for films */ - AV_FORCE_FILM = (1<<6), + #define AV_FORCE_FILM ((uint64_t)1<<6) /* does not suport, or very broken background (added for AV610C2) */ - AV_NO_BACKGROUND = (1<<7), + #define AV_NO_BACKGROUND ((uint64_t)1<<7) /* is film scanner - no detection yet */ - AV_FILMSCANNER = (1<<8), + #define AV_FILMSCANNER ((uint64_t)1<<8) /* fujitsu adaption */ - AV_FUJITSU = (1<<9), + #define AV_FUJITSU ((uint64_t)1<<9) /* gray calibration data has to be uploaded on the blue channel ... ? */ - AV_GRAY_CALIB_BLUE = (1<<10), + #define AV_GRAY_CALIB_BLUE ((uint64_t)1<<10) /* Interrupt endpoint button readout (so far AV220) */ - AV_INT_BUTTON = (1<<11), + #define AV_INT_BUTTON ((uint64_t)1<<11) /* send acceleration table ... */ - AV_ACCEL_TABLE = (1<<12), + #define AV_ACCEL_TABLE ((uint64_t)1<<12) /* non-interlaced scanns up to 300 dpi (AV32xx / AV83xx) */ - AV_NON_INTERLACED_DUPLEX_300 = (1<<13), + #define AV_NON_INTERLACED_DUPLEX_300 ((uint64_t)1<<13) /* do not read multiples of 64 bytes - stalls the USB chip */ - AV_NO_64BYTE_ALIGN = (1<<14), + #define AV_NO_64BYTE_ALIGN ((uint64_t)1<<14) /* force channel-by-channel calibration */ - AV_MULTI_CALIB_CMD = (1<<15), + #define AV_MULTI_CALIB_CMD ((uint64_t)1<<15) /* non color scans are faster with a filter applied (AV32xx) */ - AV_FASTER_WITH_FILTER = (1<<16), + #define AV_FASTER_WITH_FILTER ((uint64_t)1<<16) /* interlaced data with 1 line distance */ - AV_2ND_LINE_INTERLACED = (1<<17), + #define AV_2ND_LINE_INTERLACED ((uint64_t)1<<17) /* does not keep the window though it advertices so */ - AV_DOES_NOT_KEEP_WINDOW = (1<<18), + #define AV_DOES_NOT_KEEP_WINDOW ((uint64_t)1<<18) /* does not keep the gamma though it advertices so */ - AV_DOES_NOT_KEEP_GAMMA = (1<<19), + #define AV_DOES_NOT_KEEP_GAMMA ((uint64_t)1<<19) /* advertises ADF is BGR order, but isn't (or vice versa) */ - AV_ADF_BGR_ORDER_INVERT = (1<<20), + #define AV_ADF_BGR_ORDER_INVERT ((uint64_t)1<<20) /* allows 12bit mode, though not flagged */ - AV_12_BIT_MODE = (1<<21), + #define AV_12_BIT_MODE ((uint64_t)1<<21) /* very broken background raster */ - AV_BACKGROUND_QUIRK = (1<<22), + #define AV_BACKGROUND_QUIRK ((uint64_t)1<<22) /* though marked as GRAY only the scanner can do GRAY modes */ - AV_GRAY_MODES = (1<<23), + #define AV_GRAY_MODES ((uint64_t)1<<23) /* no seperate, single REAR scan (AV122, DM152, ...) */ - AV_NO_REAR = (1<<24), + #define AV_NO_REAR ((uint64_t)1<<24) /* only scan with some known good hardware resolutions, as the scanner fails to properly interpoloate in between (e.g. AV121, DM152 on duplex scans - but also the AV600), software scale and interpolate to all the others */ - AV_SOFT_SCALE = (1<<25), + #define AV_SOFT_SCALE ((uint64_t)1<<25) /* does keep window though it does not advertice it - the AV122/DM152 mess up image data if window is resend between ADF pages */ - AV_DOES_KEEP_WINDOW = (1<<26), + #define AV_DOES_KEEP_WINDOW ((uint64_t)1<<26) /* does keep gamma though it does not advertice it */ - AV_DOES_KEEP_GAMMA = (1<<27), + #define AV_DOES_KEEP_GAMMA ((uint64_t)1<<27) /* does the scanner contain a Cancel button? */ - AV_CANCEL_BUTTON = (1<<28), + #define AV_CANCEL_BUTTON ((uint64_t)1<<28) /* is the rear image offset? */ - AV_REAR_OFFSET = (1<<29), + #define AV_REAR_OFFSET ((uint64_t)1<<29) /* some devices do not need a START_SCAN, even hang with it */ - AV_NO_START_SCAN = (1<<30), - - AV_INT_STATUS = (1<<31) + #define AV_NO_START_SCAN ((uint64_t)1<<30) - /* maybe more ...*/ - } feature_type; - - /*second enum cause 32 bit int above is full*/ - enum { + #define AV_INT_STATUS ((uint64_t)1<<31) + /* force no calibration */ - AV_NO_TUNE_SCAN_LENGTH = (1<<0), + #define AV_NO_TUNE_SCAN_LENGTH ((uint64_t)1<<32) /* for gray scans, set grey filter */ - AV_USE_GRAY_FILTER = (1<<1), + #define AV_USE_GRAY_FILTER ((uint64_t)1<<33) /* For (HP) scanners with flipping duplexers */ - AV_ADF_FLIPPING_DUPLEX = (1<<2), + #define AV_ADF_FLIPPING_DUPLEX ((uint64_t)1<<34) /* For scanners which need to have their firmware read to properly function. */ - AV_FIRMWARE = (1<<3) - } feature_type2; + #define AV_FIRMWARE ((uint64_t)1<<35) + + /* maybe more ...*/ + uint64_t feature_type; } Avision_HWEntry; diff --git a/backend/bh.c b/backend/bh.c index 58c8caa..9424bd6 100644 --- a/backend/bh.c +++ b/backend/bh.c @@ -66,6 +66,7 @@ #define MIN(x,y) ((x)<(y) ? (x) : (y)) #define MAX(x,y) ((x)>(y) ? (x) : (y)) +static const SANE_Device **devlist = 0; static int num_devices = 0; static BH_Device *first_dev = NULL; static BH_Scanner *first_handle = NULL; @@ -1862,10 +1863,9 @@ start_scan (BH_Scanner *s) strncpy(s->barfname, "/tmp/bhXXXXXX", sizeof(s->barfname)); s->barfname[sizeof(s->barfname)-1] = '\0'; + fd = mkstemp(s->barfname); - if ((mktemp(s->barfname) == NULL) && - ((fd = open(s->barfname, O_CREAT | O_EXCL | O_WRONLY, 0600)) != -1) && - ((fp = fdopen(fd, "w")) != NULL)) + if (fd !=-1 && (fp = fdopen(fd, "w")) != NULL) { fprintf(fp, "<xml-stream>\n"); @@ -3231,7 +3231,6 @@ sane_init (SANE_Int *version_code, SANE_Auth_Callback authorize) SANE_Status sane_get_devices (const SANE_Device ***device_list, SANE_Bool local) { - static const SANE_Device **devlist = 0; BH_Device *dev; int i; DBG(3, "sane_get_devices called\n"); @@ -3879,5 +3878,8 @@ sane_exit (void) next = dev->next; free (dev); } + + if (devlist) + free (devlist); } diff --git a/backend/canon_dr-cmd.h b/backend/canon_dr-cmd.h index 64e6887..b969c3b 100644 --- a/backend/canon_dr-cmd.h +++ b/backend/canon_dr-cmd.h @@ -67,6 +67,10 @@ putnbyte (unsigned char *pnt, unsigned int value, unsigned int nbytes) } /* ==================================================================== */ +/* extended status packet */ +#define get_ES_length(b) getnbyte(b+0x04, 4) + +/* ==================================================================== */ /* SCSI commands */ #define set_SCSI_opcode(out, val) out[0]=val @@ -203,7 +207,9 @@ putnbyte (unsigned char *pnt, unsigned int value, unsigned int nbytes) /* READ/SEND page codes */ #define SR_datatype_image 0x00 #define SR_datatype_lut 0x03 +#define SR_datatype_pixelsize 0x80 /*DR-G1130*/ #define SR_datatype_panel 0x84 +#define SR_datatype_sensors 0x8b #define SR_datatype_counters 0x8c #define SR_datatype_endorser 0x90 #define SR_datatype_fineoffset 0x90 @@ -234,6 +240,11 @@ putnbyte (unsigned char *pnt, unsigned int value, unsigned int nbytes) #define get_R_PANEL_enable_led(in) getbitfield(in+2, 1, 0) #define get_R_PANEL_counter(in) getnbyte(in + 0x04, 4) +/*sensors*/ +#define R_SENSORS_len 0x01 +#define get_R_SENSORS_card(in) getbitfield(in, 1, 3) +#define get_R_SENSORS_adf(in) getbitfield(in, 1, 0) + /*counters*/ #define R_COUNTERS_len 0x80 #define get_R_COUNTERS_scans(in) getnbyte(in + 0x04, 4) @@ -334,6 +345,7 @@ putnbyte (unsigned char *pnt, unsigned int value, unsigned int nbytes) #define set_SSM_BUFF_async(sb, val) setbitfield(sb+0x0a, 1, 6, val) #define set_SSM_BUFF_ald(sb, val) setbitfield(sb+0x0a, 1, 5, val) #define set_SSM_BUFF_fb(sb, val) setbitfield(sb+0x0a, 1, 4, val) +#define set_SSM_BUFF_card(sb, val) setbitfield(sb+0x0a, 1, 3, val) /* for DO (0x36) page */ #define SSM_DO_none 0 @@ -415,18 +427,39 @@ putnbyte (unsigned char *pnt, unsigned int value, unsigned int nbytes) #define set_CC3_exp_b_b(sb, val) putnbyte(sb + 0x20, val, 2) /* ==================================================================== */ +/* Page codes used by GET/SET SCAN MODE 2 */ +#define SM2_pc_df 0x00 +#define SM2_pc_ultra 0x01 +#define SM2_pc_buffer 0x02 +#define SM2_pc_dropout 0x06 + +/* ==================================================================== */ /* SET SCAN MODE 2 */ #define SET_SCAN_MODE2_code 0xe5 -#define SET_SCAN_MODE2_len 10 +#define SET_SCAN_MODE2_len 12 #define set_SSM2_page_code(sb, val) sb[0x02] = val #define set_SSM2_pay_len(sb, val) sb[0x08] = val /* the payload */ #define SSM2_PAY_len 0x10 -#define set_SSM2_unk(sb, val) sb[0x02] = val -#define set_SSM2_unk2(sb, val) sb[0x03] = val -#define set_SSM2_unk3(sb, val) sb[0x04] = val + +/* for DF (0x00) page */ +#define set_SSM2_DF_thick(sb, val) setbitfield(sb+3, 1, 2, val) +#define set_SSM2_DF_len(sb, val) setbitfield(sb+3, 1, 0, val) + +/* for ULTRA (0x01) page */ +#define set_SSM2_ULTRA_top(sb, val) putnbyte(sb + 0x07, val, 2) +#define set_SSM2_ULTRA_bot(sb, val) putnbyte(sb + 0x09, val, 2) + +/* for BUFFER (0x02) page */ +#define set_SSM2_BUFF_unk(sb, val) sb[0x03] = val +#define set_SSM2_BUFF_unk2(sb, val) sb[0x06] = val +#define set_SSM2_BUFF_sync(sb, val) sb[0x09] = val + +/* for DROPOUT (0x06) page */ +#define set_SSM2_DO_do(sb, val) sb[0x09] = val +#define set_SSM2_DO_en(sb, val) sb[0x0a] = val /* ==================================================================== */ /* window descriptor macros for SET_WINDOW and GET_WINDOW */ diff --git a/backend/canon_dr.c b/backend/canon_dr.c index 594aab2..381cfd6 100644 --- a/backend/canon_dr.c +++ b/backend/canon_dr.c @@ -276,10 +276,46 @@ - DR-2580C pads the backside of duplex scans v40 2012-11-01, MAN - initial DR-9050C, DR-7550C, DR-6050C and DR-3010C support - v41 2013-07-31, MAN + v41 2013-07-31, MAN (SANE 1.0.24) - initial P-208 and P-215 support - bug fix for calibration of scanners with duplex_offset - allow duplex_offset to be controlled from config file + v42 2013-12-09, MAN + - initial DR-G1100 support + - add support for paper sensors (P-215 & P-208) + - add initial support for card reader (P-215) + - removed unused var from do_scsi_cmd() + v43 2014-03-13, MAN + - initial DR-M140 support + - add extra_status config and code + - split status code into do_usb_status + - fix copy_line margin offset + - add new color interlacing modes and code + - comment out ssm2 + - add timestamp to do_usb_cmd + v44 2014-03-26, MAN + - buffermode support for machines with ssm2 command + - DR-M140 needs always_op=0 + v45 2014-03-29, MAN + - dropout support for machines with ssm2 command + - doublefeed support for machines with ssm2 command + v46 2014-04-09, MAN + - split debug level 30 into two levels + - simplify jpeg ifdefs + - add support for DR-M160 + v47 2014-07-07, MAN + - initial DR-G1130 support + v48 2014-08-06, MAN + - set another unknown byte in buffermode for ssm2 + - add another gettimeofday call at end of do_usb_cmd + - don't print 0 length line in hexdump + v49 2015-03-18, MAN + - initial support for DR-C125 + v50 2015-08-23, MAN + - DR-C125 adds duplex padding on back side + - initial support for DR-C225 + v51 2015-08-25, MAN + - DR-C125 does not invert_tly, does need sw_lut SANE FLOW DIAGRAM @@ -317,6 +353,7 @@ #include <ctype.h> /*isspace*/ #include <math.h> /*tan*/ #include <unistd.h> /*usleep*/ +#include <sys/time.h> /*gettimeofday*/ #include "../include/sane/sanei_backend.h" #include "../include/sane/sanei_scsi.h" @@ -328,7 +365,7 @@ #include "canon_dr.h" #define DEBUG 1 -#define BUILD 41 +#define BUILD 51 /* values for SANE_DEBUG_CANON_DR env var: - errors 5 @@ -336,15 +373,25 @@ - function detail 15 - get/setopt cmds 20 - scsi/usb trace 25 - - scsi/usb detail 30 + - scsi/usb writes 30 + - scsi/usb reads 31 - useless noise 35 */ /* ------------------------------------------------------------------------- */ +/* if JPEG support is not enabled in sane.h, we setup our own defines */ +#ifndef SANE_FRAME_JPEG +#define SANE_FRAME_JPEG 0x0B +#define SANE_JPEG_DISABLED 1 +#endif +/* ------------------------------------------------------------------------- */ #define STRING_FLATBED SANE_I18N("Flatbed") #define STRING_ADFFRONT SANE_I18N("ADF Front") #define STRING_ADFBACK SANE_I18N("ADF Back") #define STRING_ADFDUPLEX SANE_I18N("ADF Duplex") +#define STRING_CARDFRONT SANE_I18N("Card Front") +#define STRING_CARDBACK SANE_I18N("Card Back") +#define STRING_CARDDUPLEX SANE_I18N("Card Duplex") #define STRING_LINEART SANE_VALUE_SCAN_MODE_LINEART #define STRING_HALFTONE SANE_VALUE_SCAN_MODE_HALFTONE @@ -366,6 +413,8 @@ static int global_buffer_size; static int global_buffer_size_default = 2 * 1024 * 1024; static int global_padded_read; static int global_padded_read_default = 0; +static int global_extra_status; +static int global_extra_status_default = 0; static int global_duplex_offset; static int global_duplex_offset_default = 0; static char global_vendor_name[9]; @@ -543,6 +592,32 @@ sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only) global_padded_read = buf; } + /* EXTRA STATUS: we clamp to 0 or 1 */ + else if (!strncmp (lp, "extra-status", 12) && isspace (lp[12])) { + + int buf; + lp += 12; + lp = sanei_config_skip_whitespace (lp); + buf = atoi (lp); + + if (buf < 0) { + DBG (5, "sane_get_devices: config option \"extra-status\" " + "(%d) is < 0, ignoring!\n", buf); + continue; + } + + if (buf > 1) { + DBG (5, "sane_get_devices: config option \"extra-status\" " + "(%d) is > 1, ignoring!\n", buf); + continue; + } + + DBG (15, "sane_get_devices: setting \"extra-status\" to %d\n", + buf); + + global_extra_status = buf; + } + /* DUPLEXOFFSET: < 1200 */ else if (!strncmp (lp, "duplex-offset", 13) && isspace (lp[13])) { @@ -733,6 +808,7 @@ attach_one (const char *device_name, int connType) /* config file settings */ s->buffer_size = global_buffer_size; s->padded_read = global_padded_read; + s->extra_status = global_extra_status; s->duplex_offset = global_duplex_offset; /* copy the device name */ @@ -1160,6 +1236,9 @@ init_model (struct scanner *s) s->reverse_by_mode[MODE_GRAYSCALE] = 0; s->reverse_by_mode[MODE_COLOR] = 0; + s->color_interlace[SIDE_FRONT] = COLOR_INTERLACE_RGB; + s->color_interlace[SIDE_BACK] = COLOR_INTERLACE_RGB; + s->always_op = 1; s->has_df = 1; s->has_btc = 1; @@ -1191,9 +1270,7 @@ init_model (struct scanner *s) /* specific settings missing from vpd */ if (strstr (s->model_name,"DR-9080") || strstr (s->model_name,"DR-7580")){ -#ifdef SANE_FRAME_JPEG s->has_comp_JPEG = 1; -#endif s->rgb_format = 2; } @@ -1203,7 +1280,10 @@ init_model (struct scanner *s) else if (strstr (s->model_name,"DR-9050") || strstr (s->model_name,"DR-7550") - || strstr (s->model_name,"DR-6050")){ + || strstr (s->model_name,"DR-6050") + || strstr (s->model_name,"DR-G1100") + || strstr (s->model_name,"DR-G1130") + ){ /*missing*/ s->std_res_x[DPI_100]=1; @@ -1367,6 +1447,7 @@ init_model (struct scanner *s) s->has_ssm_pay_head_len = 1; s->ppl_mod = 8; s->ccal_version = 3; + s->can_read_sensors = 1; } else if (strstr (s->model_name, "P-215")) { @@ -1382,6 +1463,150 @@ init_model (struct scanner *s) s->has_ssm_pay_head_len = 1; s->ppl_mod = 8; s->ccal_version = 3; + s->can_read_sensors = 1; + s->has_card = 1; + } + + else if (strstr (s->model_name,"DR-M160")){ + + /*missing*/ + s->std_res_x[DPI_100]=1; + s->std_res_y[DPI_100]=1; + s->std_res_x[DPI_150]=1; + s->std_res_y[DPI_150]=1; + s->std_res_x[DPI_200]=1; + s->std_res_y[DPI_200]=1; + s->std_res_x[DPI_300]=1; + s->std_res_y[DPI_300]=1; + s->std_res_x[DPI_400]=1; + s->std_res_y[DPI_400]=1; + s->std_res_x[DPI_600]=1; + s->std_res_y[DPI_600]=1; + + s->has_comp_JPEG = 1; + s->rgb_format = 1; + s->can_color = 1; + s->has_df_ultra = 1; + + s->color_inter_by_res[DPI_100] = COLOR_INTERLACE_GBR; + s->color_inter_by_res[DPI_150] = COLOR_INTERLACE_GBR; + s->color_inter_by_res[DPI_200] = COLOR_INTERLACE_BRG; + s->color_inter_by_res[DPI_400] = COLOR_INTERLACE_GBR; + + /*weirdness*/ + s->always_op = 0; + s->fixed_width = 1; + s->invert_tly = 1; + s->can_write_panel = 0; + s->has_ssm = 0; + s->has_ssm2 = 1; + s->duplex_interlace = DUPLEX_INTERLACE_FFBB; + s->duplex_offset_side = SIDE_FRONT; + + /*lies*/ + s->can_halftone=0; + s->can_monochrome=0; + } + + else if (strstr (s->model_name,"DR-M140")){ + + /*missing*/ + s->std_res_x[DPI_100]=1; + s->std_res_y[DPI_100]=1; + s->std_res_x[DPI_150]=1; + s->std_res_y[DPI_150]=1; + s->std_res_x[DPI_200]=1; + s->std_res_y[DPI_200]=1; + s->std_res_x[DPI_300]=1; + s->std_res_y[DPI_300]=1; + s->std_res_x[DPI_400]=1; + s->std_res_y[DPI_400]=1; + s->std_res_x[DPI_600]=1; + s->std_res_y[DPI_600]=1; + + s->has_comp_JPEG = 1; + s->rgb_format = 1; + s->can_color = 1; + s->has_df_ultra = 1; + + s->color_inter_by_res[DPI_100] = COLOR_INTERLACE_GBR; + s->color_inter_by_res[DPI_150] = COLOR_INTERLACE_GBR; + s->color_inter_by_res[DPI_200] = COLOR_INTERLACE_BRG; + s->color_inter_by_res[DPI_400] = COLOR_INTERLACE_GBR; + + /*weirdness*/ + s->always_op = 0; + s->fixed_width = 1; + s->invert_tly = 1; + s->can_write_panel = 0; + s->has_ssm = 0; + s->has_ssm2 = 1; + s->duplex_interlace = DUPLEX_INTERLACE_FFBB; + s->duplex_offset_side = SIDE_BACK; + + /*lies*/ + s->can_halftone=0; + s->can_monochrome=0; + } + + else if (strstr (s->model_name,"DR-C125")){ + + /*confirmed settings*/ + s->gray_interlace[SIDE_FRONT] = GRAY_INTERLACE_2510; + s->gray_interlace[SIDE_BACK] = GRAY_INTERLACE_2510; + s->color_interlace[SIDE_FRONT] = COLOR_INTERLACE_2510; + s->color_interlace[SIDE_BACK] = COLOR_INTERLACE_2510; + s->duplex_interlace = DUPLEX_INTERLACE_2510; + s->duplex_offset_side = SIDE_BACK; + s->unknown_byte2 = 0x88; + s->need_ccal = 1; + s->ccal_version = 3; + s->need_fcal = 1; + s->sw_lut = 1; + s->can_color = 1; + s->rgb_format = 1; + /*s->duplex_offset = 400; now set in config file*/ + + /*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->always_op = 0; + s->fixed_width = 1; + s->valid_x = 8.5 * 1200; + } + + else if (strstr (s->model_name,"DR-C225")){ + + s->color_interlace[SIDE_FRONT] = COLOR_INTERLACE_RRGGBB; + s->color_interlace[SIDE_BACK] = COLOR_INTERLACE_rRgGbB; + s->gray_interlace[SIDE_BACK] = GRAY_INTERLACE_gG; + s->duplex_interlace = DUPLEX_INTERLACE_FBFB; + + s->unknown_byte2 = 0x88; + s->need_ccal = 1; + s->ccal_version = 3; + s->need_fcal = 1; + s->invert_tly = 1; + s->can_color = 1; + s->rgb_format = 1; + /*s->duplex_offset = 400; now set in config file*/ + + /*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->always_op = 0; + s->fixed_width = 1; + s->valid_x = 8.5 * 1200; } DBG (10, "init_model: finish\n"); @@ -1435,6 +1660,8 @@ init_user (struct scanner *s) s->u.source = SOURCE_FLATBED; else if(s->has_adf) s->u.source = SOURCE_ADF_FRONT; + else if(s->has_card) + s->u.source = SOURCE_CARD_FRONT; /* scan mode */ if(s->can_monochrome) @@ -1628,6 +1855,16 @@ sane_get_option_descriptor (SANE_Handle handle, SANE_Int option) s->source_list[i++]=STRING_ADFDUPLEX; } } + if(s->has_card){ + s->source_list[i++]=STRING_CARDFRONT; + + if(s->has_back){ + s->source_list[i++]=STRING_CARDBACK; + } + if(s->has_duplex){ + s->source_list[i++]=STRING_CARDDUPLEX; + } + } s->source_list[i]=NULL; opt->name = SANE_NAME_SCAN_SOURCE; @@ -1841,7 +2078,7 @@ sane_get_option_descriptor (SANE_Handle handle, SANE_Int option) opt->constraint_type = SANE_CONSTRAINT_RANGE; opt->constraint.range = &s->paper_x_range; - if(s->has_adf){ + if(s->has_adf || s->has_card){ opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT; if(s->u.source == SOURCE_FLATBED){ opt->cap |= SANE_CAP_INACTIVE; @@ -1868,7 +2105,7 @@ sane_get_option_descriptor (SANE_Handle handle, SANE_Int option) opt->constraint_type = SANE_CONSTRAINT_RANGE; opt->constraint.range = &s->paper_y_range; - if(s->has_adf){ + if(s->has_adf || s->has_card){ opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT; if(s->u.source == SOURCE_FLATBED){ opt->cap |= SANE_CAP_INACTIVE; @@ -1985,7 +2222,9 @@ sane_get_option_descriptor (SANE_Handle handle, SANE_Int option) s->compress_list[i++]=STRING_NONE; if(s->has_comp_JPEG){ +#ifndef SANE_JPEG_DISABLED s->compress_list[i++]=STRING_JPEG; +#endif } s->compress_list[i]=NULL; @@ -2306,6 +2545,28 @@ sane_get_option_descriptor (SANE_Handle handle, SANE_Int option) opt->cap = SANE_CAP_INACTIVE; } + if(option==OPT_ADF_LOADED){ + opt->name = "adf-loaded"; + opt->title = "ADF Loaded"; + opt->desc = "Paper available in ADF input hopper"; + opt->type = SANE_TYPE_BOOL; + opt->unit = SANE_UNIT_NONE; + opt->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED; + if(!s->can_read_sensors) + opt->cap = SANE_CAP_INACTIVE; + } + + if(option==OPT_CARD_LOADED){ + opt->name = "card-loaded"; + opt->title = "Card Loaded"; + opt->desc = "Paper available in card reader"; + opt->type = SANE_TYPE_BOOL; + opt->unit = SANE_UNIT_NONE; + opt->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED; + if(!s->can_read_sensors || !s->has_card) + opt->cap = SANE_CAP_INACTIVE; + } + return opt; } @@ -2382,6 +2643,15 @@ sane_control_option (SANE_Handle handle, SANE_Int option, else if(s->u.source == SOURCE_ADF_DUPLEX){ strcpy (val, STRING_ADFDUPLEX); } + else if(s->u.source == SOURCE_CARD_FRONT){ + strcpy (val, STRING_CARDFRONT); + } + else if(s->u.source == SOURCE_CARD_BACK){ + strcpy (val, STRING_CARDBACK); + } + else if(s->u.source == SOURCE_CARD_DUPLEX){ + strcpy (val, STRING_CARDDUPLEX); + } return SANE_STATUS_GOOD; case OPT_MODE: @@ -2581,6 +2851,15 @@ sane_control_option (SANE_Handle handle, SANE_Int option, *val_p = s->panel_counter; return ret; + case OPT_ADF_LOADED: + ret = read_sensors(s,OPT_ADF_LOADED); + *val_p = s->sensor_adf_loaded; + return ret; + + case OPT_CARD_LOADED: + ret = read_sensors(s,OPT_CARD_LOADED); + *val_p = s->sensor_card_loaded; + return ret; } } else if (action == SANE_ACTION_SET_VALUE) { @@ -2629,6 +2908,15 @@ sane_control_option (SANE_Handle handle, SANE_Int option, else if (!strcmp (val, STRING_ADFDUPLEX)) { tmp = SOURCE_ADF_DUPLEX; } + else if (!strcmp (val, STRING_CARDFRONT)) { + tmp = SOURCE_CARD_FRONT; + } + else if (!strcmp (val, STRING_CARDBACK)) { + tmp = SOURCE_CARD_BACK; + } + else if (!strcmp (val, STRING_CARDDUPLEX)) { + tmp = SOURCE_CARD_DUPLEX; + } else{ tmp = SOURCE_FLATBED; } @@ -2837,54 +3125,85 @@ ssm_buffer (struct scanner *s) { SANE_Status ret = SANE_STATUS_GOOD; - unsigned char cmd[SET_SCAN_MODE_len]; - size_t cmdLen = SET_SCAN_MODE_len; - - unsigned char out[SSM_PAY_len]; - size_t outLen = SSM_PAY_len; - DBG (10, "ssm_buffer: start\n"); - if(!s->has_ssm){ - DBG (10, "ssm_buffer: unsupported\n"); - return ret; + if(s->has_ssm){ + + unsigned char cmd[SET_SCAN_MODE_len]; + size_t cmdLen = SET_SCAN_MODE_len; + + unsigned char out[SSM_PAY_len]; + size_t outLen = SSM_PAY_len; + + memset(cmd,0,cmdLen); + set_SCSI_opcode(cmd, SET_SCAN_MODE_code); + set_SSM_pf(cmd, 1); + set_SSM_pay_len(cmd, outLen); + + memset(out,0,outLen); + if(s->has_ssm_pay_head_len){ + set_SSM_pay_head_len(out, SSM_PAY_HEAD_len); + } + set_SSM_page_code(out, SM_pc_buffer); + set_SSM_page_len(out, SSM_PAGE_len); + + if(s->s.source == SOURCE_ADF_DUPLEX || s->s.source == SOURCE_CARD_DUPLEX){ + set_SSM_BUFF_duplex(out, 1); + } + if(s->s.source == SOURCE_FLATBED){ + set_SSM_BUFF_fb(out, 1); + } + else if(s->s.source >= SOURCE_CARD_FRONT){ + set_SSM_BUFF_card(out, 1); + } + if(s->buffermode){ + set_SSM_BUFF_async(out, 1); + } + if(0){ + set_SSM_BUFF_ald(out, 1); + } + if(0){ + set_SSM_BUFF_unk(out,1); + } + + ret = do_cmd ( + s, 1, 0, + cmd, cmdLen, + out, outLen, + NULL, NULL + ); } - memset(cmd,0,cmdLen); - set_SCSI_opcode(cmd, SET_SCAN_MODE_code); - set_SSM_pf(cmd, 1); - set_SSM_pay_len(cmd, outLen); + else if(s->has_ssm2){ - memset(out,0,outLen); - if(s->has_ssm_pay_head_len){ - set_SSM_pay_head_len(out, SSM_PAY_HEAD_len); + 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_buffer); + set_SSM2_pay_len(cmd, outLen); + + memset(out,0,outLen); + set_SSM2_BUFF_unk(out, !s->buffermode); + set_SSM2_BUFF_unk2(out, 0x40); + set_SSM2_BUFF_sync(out, !s->buffermode); + + ret = do_cmd ( + s, 1, 0, + cmd, cmdLen, + out, outLen, + NULL, NULL + ); } - set_SSM_page_code(out, SM_pc_buffer); - set_SSM_page_len(out, SSM_PAGE_len); - if(s->s.source == SOURCE_ADF_DUPLEX){ - set_SSM_BUFF_duplex(out, 1); - } - else if(s->s.source == SOURCE_FLATBED){ - set_SSM_BUFF_fb(out, 1); - } - if(s->buffermode){ - set_SSM_BUFF_async(out, 1); - } - if(0){ - set_SSM_BUFF_ald(out, 1); - } - if(0){ - set_SSM_BUFF_unk(out,1); + else{ + DBG (10, "ssm_buffer: unsupported\n"); } - ret = do_cmd ( - s, 1, 0, - cmd, cmdLen, - out, outLen, - NULL, NULL - ); - DBG (10, "ssm_buffer: finish\n"); return ret; @@ -2895,57 +3214,118 @@ ssm_df (struct scanner *s) { SANE_Status ret = SANE_STATUS_GOOD; - unsigned char cmd[SET_SCAN_MODE_len]; - size_t cmdLen = SET_SCAN_MODE_len; - - unsigned char out[SSM_PAY_len]; - size_t outLen = SSM_PAY_len; - DBG (10, "ssm_df: start\n"); - - if(!s->has_ssm || !s->has_df){ + + if(!s->has_df){ DBG (10, "ssm_df: unsupported, finishing\n"); return ret; } + + if(s->has_ssm){ - memset(cmd,0,cmdLen); - set_SCSI_opcode(cmd, SET_SCAN_MODE_code); - set_SSM_pf(cmd, 1); - set_SSM_pay_len(cmd, outLen); + unsigned char cmd[SET_SCAN_MODE_len]; + size_t cmdLen = SET_SCAN_MODE_len; + + unsigned char out[SSM_PAY_len]; + size_t outLen = SSM_PAY_len; + + memset(cmd,0,cmdLen); + set_SCSI_opcode(cmd, SET_SCAN_MODE_code); + set_SSM_pf(cmd, 1); + set_SSM_pay_len(cmd, outLen); + + memset(out,0,outLen); + if(s->has_ssm_pay_head_len){ + set_SSM_pay_head_len(out, SSM_PAY_HEAD_len); + } + set_SSM_page_code(out, SM_pc_df); + set_SSM_page_len(out, SSM_PAGE_len); + + /* deskew by roller */ + if(s->rollerdeskew){ + set_SSM_DF_deskew_roll(out, 1); + } + + /* staple detection */ + if(s->stapledetect){ + set_SSM_DF_staple(out, 1); + } + + /* thickness */ + if(s->df_thickness){ + set_SSM_DF_thick(out, 1); + } + + /* length */ + if(s->df_length){ + set_SSM_DF_len(out, 1); + } + + ret = do_cmd ( + s, 1, 0, + cmd, cmdLen, + out, outLen, + NULL, NULL + ); - memset(out,0,outLen); - if(s->has_ssm_pay_head_len){ - set_SSM_pay_head_len(out, SSM_PAY_HEAD_len); } - set_SSM_page_code(out, SM_pc_df); - set_SSM_page_len(out, SSM_PAGE_len); - /* deskew by roller */ - if(s->rollerdeskew){ - set_SSM_DF_deskew_roll(out, 1); - } + else if(s->has_ssm2){ + + unsigned char cmd[SET_SCAN_MODE2_len]; + size_t cmdLen = SET_SCAN_MODE2_len; - /* staple detection */ - if(s->stapledetect){ - set_SSM_DF_staple(out, 1); - } + unsigned char out[SSM2_PAY_len]; + size_t outLen = SSM2_PAY_len; + + /* send ultrasonic offsets first */ + if(s->df_thickness && s->has_df_ultra){ + memset(cmd,0,cmdLen); + set_SCSI_opcode(cmd, SET_SCAN_MODE2_code); + set_SSM2_page_code(cmd, SM2_pc_ultra); + set_SSM2_pay_len(cmd, outLen); + + memset(out,0,outLen); + set_SSM2_ULTRA_top(out, 0); + set_SSM2_ULTRA_bot(out, 0); + + ret = do_cmd ( + s, 1, 0, + cmd, cmdLen, + out, outLen, + NULL, NULL + ); + } - /* thickness */ - if(s->df_thickness){ - set_SSM_DF_thick(out, 1); - } + memset(cmd,0,cmdLen); + set_SCSI_opcode(cmd, SET_SCAN_MODE2_code); + set_SSM2_page_code(cmd, SM2_pc_df); + set_SSM2_pay_len(cmd, outLen); - /* length */ - if(s->df_length){ - set_SSM_DF_len(out, 1); + memset(out,0,outLen); + + /* thickness */ + if(s->df_thickness){ + set_SSM2_DF_thick(out, 1); + } + + /* length */ + if(s->df_length){ + set_SSM2_DF_len(out, 1); + } + + ret = do_cmd ( + s, 1, 0, + cmd, cmdLen, + out, outLen, + NULL, NULL + ); + } - ret = do_cmd ( - s, 1, 0, - cmd, cmdLen, - out, outLen, - NULL, NULL - ); + else{ + DBG (10, "ssm_df: unsupported\n"); + } DBG (10, "ssm_df: finish\n"); @@ -2957,140 +3337,203 @@ ssm_do (struct scanner *s) { SANE_Status ret = SANE_STATUS_GOOD; - unsigned char cmd[SET_SCAN_MODE_len]; - size_t cmdLen = SET_SCAN_MODE_len; + DBG (10, "ssm_do: start\n"); - unsigned char out[SSM_PAY_len]; - size_t outLen = SSM_PAY_len; + if(!s->can_color){ + DBG (10, "ssm_do: unsupported, finishing\n"); + return ret; + } + + if(s->has_ssm){ - DBG (10, "ssm_do: start\n"); + unsigned char cmd[SET_SCAN_MODE_len]; + size_t cmdLen = SET_SCAN_MODE_len; + + unsigned char out[SSM_PAY_len]; + size_t outLen = SSM_PAY_len; + + memset(cmd,0,cmdLen); + set_SCSI_opcode(cmd, SET_SCAN_MODE_code); + set_SSM_pf(cmd, 1); + set_SSM_pay_len(cmd, outLen); + + memset(out,0,outLen); + if(s->has_ssm_pay_head_len){ + set_SSM_pay_head_len(out, SSM_PAY_HEAD_len); + } + set_SSM_page_code(out, SM_pc_dropout); + set_SSM_page_len(out, SSM_PAGE_len); + + set_SSM_DO_unk1(out, 0x03); + + switch(s->dropout_color_f){ + case COLOR_RED: + set_SSM_DO_unk2(out, 0x05); + set_SSM_DO_f_do(out,SSM_DO_red); + break; + case COLOR_GREEN: + set_SSM_DO_unk2(out, 0x05); + set_SSM_DO_f_do(out,SSM_DO_green); + break; + case COLOR_BLUE: + set_SSM_DO_unk2(out, 0x05); + set_SSM_DO_f_do(out,SSM_DO_blue); + break; + case COLOR_EN_RED: + set_SSM_DO_unk2(out, 0x05); + set_SSM_DO_f_en(out,SSM_DO_red); + break; + case COLOR_EN_GREEN: + set_SSM_DO_unk2(out, 0x05); + set_SSM_DO_f_en(out,SSM_DO_green); + break; + case COLOR_EN_BLUE: + set_SSM_DO_unk2(out, 0x05); + set_SSM_DO_f_en(out,SSM_DO_blue); + break; + } + + switch(s->dropout_color_b){ + case COLOR_RED: + set_SSM_DO_unk2(out, 0x05); + set_SSM_DO_b_do(out,SSM_DO_red); + break; + case COLOR_GREEN: + set_SSM_DO_unk2(out, 0x05); + set_SSM_DO_b_do(out,SSM_DO_green); + break; + case COLOR_BLUE: + set_SSM_DO_unk2(out, 0x05); + set_SSM_DO_b_do(out,SSM_DO_blue); + break; + case COLOR_EN_RED: + set_SSM_DO_unk2(out, 0x05); + set_SSM_DO_b_en(out,SSM_DO_red); + break; + case COLOR_EN_GREEN: + set_SSM_DO_unk2(out, 0x05); + set_SSM_DO_b_en(out,SSM_DO_green); + break; + case COLOR_EN_BLUE: + set_SSM_DO_unk2(out, 0x05); + set_SSM_DO_b_en(out,SSM_DO_blue); + break; + } + + ret = do_cmd ( + s, 1, 0, + cmd, cmdLen, + out, outLen, + NULL, NULL + ); - if(!s->has_ssm || !s->can_color){ - DBG (10, "ssm_do: unsupported, finishing\n"); - return ret; } - memset(cmd,0,cmdLen); - set_SCSI_opcode(cmd, SET_SCAN_MODE_code); - set_SSM_pf(cmd, 1); - set_SSM_pay_len(cmd, outLen); + else if(s->has_ssm2){ - memset(out,0,outLen); - if(s->has_ssm_pay_head_len){ - set_SSM_pay_head_len(out, SSM_PAY_HEAD_len); - } - set_SSM_page_code(out, SM_pc_dropout); - set_SSM_page_len(out, SSM_PAGE_len); - - set_SSM_DO_unk1(out, 0x03); + 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_dropout); + set_SSM2_pay_len(cmd, outLen); + + memset(out,0,outLen); + + switch(s->dropout_color_f){ + case COLOR_RED: + set_SSM2_DO_do(out,SSM_DO_red); + break; + case COLOR_GREEN: + set_SSM2_DO_do(out,SSM_DO_green); + break; + case COLOR_BLUE: + set_SSM2_DO_do(out,SSM_DO_blue); + break; + case COLOR_EN_RED: + set_SSM2_DO_en(out,SSM_DO_red); + break; + case COLOR_EN_GREEN: + set_SSM2_DO_en(out,SSM_DO_green); + break; + case COLOR_EN_BLUE: + set_SSM2_DO_en(out,SSM_DO_blue); + break; + } - switch(s->dropout_color_f){ - case COLOR_RED: - set_SSM_DO_unk2(out, 0x05); - set_SSM_DO_f_do(out,SSM_DO_red); - break; - case COLOR_GREEN: - set_SSM_DO_unk2(out, 0x05); - set_SSM_DO_f_do(out,SSM_DO_green); - break; - case COLOR_BLUE: - set_SSM_DO_unk2(out, 0x05); - set_SSM_DO_f_do(out,SSM_DO_blue); - break; - case COLOR_EN_RED: - set_SSM_DO_unk2(out, 0x05); - set_SSM_DO_f_en(out,SSM_DO_red); - break; - case COLOR_EN_GREEN: - set_SSM_DO_unk2(out, 0x05); - set_SSM_DO_f_en(out,SSM_DO_green); - break; - case COLOR_EN_BLUE: - set_SSM_DO_unk2(out, 0x05); - set_SSM_DO_f_en(out,SSM_DO_blue); - break; + ret = do_cmd ( + s, 1, 0, + cmd, cmdLen, + out, outLen, + NULL, NULL + ); } - switch(s->dropout_color_b){ - case COLOR_RED: - set_SSM_DO_unk2(out, 0x05); - set_SSM_DO_b_do(out,SSM_DO_red); - break; - case COLOR_GREEN: - set_SSM_DO_unk2(out, 0x05); - set_SSM_DO_b_do(out,SSM_DO_green); - break; - case COLOR_BLUE: - set_SSM_DO_unk2(out, 0x05); - set_SSM_DO_b_do(out,SSM_DO_blue); - break; - case COLOR_EN_RED: - set_SSM_DO_unk2(out, 0x05); - set_SSM_DO_b_en(out,SSM_DO_red); - break; - case COLOR_EN_GREEN: - set_SSM_DO_unk2(out, 0x05); - set_SSM_DO_b_en(out,SSM_DO_green); - break; - case COLOR_EN_BLUE: - set_SSM_DO_unk2(out, 0x05); - set_SSM_DO_b_en(out,SSM_DO_blue); - break; + else{ + DBG (10, "ssm_do: unsupported\n"); } - ret = do_cmd ( - s, 1, 0, - cmd, cmdLen, - out, outLen, - NULL, NULL - ); - DBG (10, "ssm_do: finish\n"); return ret; } -/* used by recent scanners. meaning of payloads unknown */ static SANE_Status -ssm2 (struct scanner *s) +read_sensors(struct scanner *s,SANE_Int option) { - SANE_Status ret = SANE_STATUS_GOOD; - - unsigned char cmd[SET_SCAN_MODE2_len]; - size_t cmdLen = SET_SCAN_MODE2_len; + SANE_Status ret=SANE_STATUS_GOOD; - unsigned char out[SSM2_PAY_len]; - size_t outLen = SSM2_PAY_len; + unsigned char cmd[READ_len]; + size_t cmdLen = READ_len; - DBG (10, "ssm2:start\n"); + unsigned char in[R_SENSORS_len]; + size_t inLen = R_SENSORS_len; - if(!s->has_ssm2){ - DBG (10, "ssm2: unsupported, finishing\n"); + DBG (10, "read_sensors: start %d\n", option); + + if(!s->can_read_sensors){ + DBG (10, "read_sensors: unsupported, finishing\n"); return ret; } - memset(cmd,0,cmdLen); - set_SCSI_opcode(cmd, SET_SCAN_MODE2_code); - /*FIXME: set this correctly */ - set_SSM2_page_code(cmd, 0); - set_SSM2_pay_len(cmd, outLen); + /* only run this if frontend has already read the last time we got it */ + /* or if we don't care for such bookkeeping (private use) */ + if (!option || !s->sensors_read[option-OPT_ADF_LOADED]) { - /*FIXME: set these correctly */ - memset(out,0,outLen); - set_SSM2_unk(out, 0); - set_SSM2_unk2(out, 0); - set_SSM2_unk3(out, 0); + DBG (15, "read_sensors: running\n"); - /* - ret = do_cmd ( + memset(cmd,0,cmdLen); + set_SCSI_opcode(cmd, READ_code); + set_R_datatype_code (cmd, SR_datatype_sensors); + set_R_xfer_length (cmd, inLen); + + ret = do_cmd ( s, 1, 0, cmd, cmdLen, - out, outLen, - NULL, NULL - );*/ + NULL, 0, + in, &inLen + ); + + if (ret == SANE_STATUS_GOOD || ret == SANE_STATUS_EOF) { + /*set flags indicating there is data to read*/ + memset(s->sensors_read,1,sizeof(s->sensors_read)); - DBG (10, "ssm2: finish\n"); + s->sensor_adf_loaded = get_R_SENSORS_adf(in); + s->sensor_card_loaded = get_R_SENSORS_card(in); + ret = SANE_STATUS_GOOD; + } + } + + if(option) + s->sensors_read[option-OPT_ADF_LOADED] = 0; + + DBG (10, "read_sensors: finish\n"); + return ret; } @@ -3112,9 +3555,9 @@ read_panel(struct scanner *s,SANE_Int option) return ret; } - /* only run this if frontend has read previous value - * or if the caller does not want the data stored */ - if (!option || !s->hw_read[option-OPT_START]) { + /* only run this if frontend has already read the last time we got it */ + /* or if we don't care for such bookkeeping (private use) */ + if (!option || !s->panel_read[option-OPT_START]) { DBG (15, "read_panel: running\n"); @@ -3132,8 +3575,7 @@ read_panel(struct scanner *s,SANE_Int option) if (ret == SANE_STATUS_GOOD || ret == SANE_STATUS_EOF) { /*set flags indicating there is data to read*/ - if(option) - memset(s->hw_read,1,sizeof(s->hw_read)); + memset(s->panel_read,1,sizeof(s->panel_read)); s->panel_start = get_R_PANEL_start(in); s->panel_stop = get_R_PANEL_stop(in); @@ -3143,12 +3585,13 @@ read_panel(struct scanner *s,SANE_Int option) s->panel_bypass_mode = get_R_PANEL_bypass_mode(in); s->panel_enable_led = get_R_PANEL_enable_led(in); s->panel_counter = get_R_PANEL_counter(in); + ret = SANE_STATUS_GOOD; } } if(option) - s->hw_read[option-OPT_START] = 0; + s->panel_read[option-OPT_START] = 0; DBG (10, "read_panel: finish %d\n",s->panel_counter); @@ -3294,14 +3737,12 @@ update_params(struct scanner *s, int calib) /* round down to pixel boundary for some scanners */ s->u.width -= s->u.width % s->ppl_mod; -#ifdef SANE_FRAME_JPEG /* jpeg requires 8x8 squares */ if(s->compress == COMP_JPEG && s->u.mode >= MODE_GRAYSCALE){ s->u.format = SANE_FRAME_JPEG; s->u.width -= s->u.width % 8; s->u.height -= s->u.height % 8; } -#endif s->u.Bpl = s->u.width * s->u.bpp / 8; s->u.valid_Bpl = s->u.Bpl; @@ -3396,7 +3837,8 @@ update_params(struct scanner *s, int calib) } /* some scanners need longer scans because front/back is offset */ - if(s->u.source == SOURCE_ADF_DUPLEX && s->duplex_offset && !calib) + if((s->u.source == SOURCE_ADF_DUPLEX || s->u.source == SOURCE_CARD_DUPLEX) + && s->duplex_offset && !calib) s->s.height = (s->u.br_y-s->u.tl_y+s->duplex_offset) * s->u.dpi_y / 1200; /* round lines up to even number */ @@ -3421,7 +3863,7 @@ update_params(struct scanner *s, int calib) else{ memcpy(&s->i,&s->u,sizeof(struct img_params)); /*dumb scanners pad the top of front page in duplex*/ - if(s->i.source == SOURCE_ADF_DUPLEX) + if(s->i.source == SOURCE_ADF_DUPLEX || s->i.source == SOURCE_CARD_DUPLEX) s->i.skip_lines[s->duplex_offset_side] = s->duplex_offset * s->i.dpi_y / 1200; } @@ -3485,7 +3927,7 @@ sane_start (SANE_Handle handle) if(!s->started){ /* load side marker */ - if(s->u.source == SOURCE_ADF_BACK){ + if(s->u.source == SOURCE_ADF_BACK || s->u.source == SOURCE_CARD_BACK){ s->side = SIDE_BACK; } else{ @@ -3549,7 +3991,7 @@ sane_start (SANE_Handle handle) goto errors; } - /* buffer/duplex/ald command */ + /* buffer/duplex/ald/fb/card command */ ret = ssm_buffer(s); if (ret != SANE_STATUS_GOOD) { DBG (5, "sane_start: ERROR: cannot ssm buffer\n"); @@ -3591,18 +4033,21 @@ sane_start (SANE_Handle handle) goto errors; } - /* grab next page */ - ret = object_position (s, SANE_TRUE); - if (ret != SANE_STATUS_GOOD) { - DBG (5, "sane_start: ERROR: cannot load page\n"); - goto errors; - } - - /* wait for scanner to finish load */ - ret = wait_scanner (s); - if (ret != SANE_STATUS_GOOD) { - DBG (5, "sane_start: ERROR: cannot wait scanner\n"); - goto errors; + /* card reader dislikes op? */ + if(s->s.source < SOURCE_CARD_FRONT){ + /* grab next page */ + ret = object_position (s, SANE_TRUE); + if (ret != SANE_STATUS_GOOD) { + DBG (5, "sane_start: ERROR: cannot load page\n"); + goto errors; + } + + /* wait for scanner to finish load */ + ret = wait_scanner (s); + if (ret != SANE_STATUS_GOOD) { + DBG (5, "sane_start: ERROR: cannot wait scanner\n"); + goto errors; + } } /* start scanning */ @@ -3619,7 +4064,7 @@ sane_start (SANE_Handle handle) else{ /* duplex needs to switch sides */ - if(s->s.source == SOURCE_ADF_DUPLEX){ + if(s->s.source == SOURCE_ADF_DUPLEX || s->s.source == SOURCE_CARD_DUPLEX){ s->side = !s->side; } @@ -3635,7 +4080,7 @@ sane_start (SANE_Handle handle) /* otherwise buffered back page will be lost */ /* ingest paper with adf (no-op for fb) */ /* dont call object pos or scan on back side of duplex scan */ - if(s->side == SIDE_FRONT || s->s.source == SOURCE_ADF_BACK){ + if(s->side == SIDE_FRONT || s->s.source == SOURCE_ADF_BACK || s->s.source == SOURCE_CARD_BACK){ /* clean scan params for new scan */ ret = clean_params(s); @@ -3694,9 +4139,7 @@ sane_start (SANE_Handle handle) * API has no way to inform the frontend of this, * so we block and buffer. yuck */ if( (s->swdeskew || s->swdespeck || s->swcrop) -#ifdef SANE_FRAME_JPEG && s->s.format != SANE_FRAME_JPEG -#endif ){ /* get image */ @@ -3772,23 +4215,26 @@ clean_params (struct scanner *s) s->s.bytes_tot[1]=0; /* store the number of front bytes */ - if ( s->u.source != SOURCE_ADF_BACK ) + if ( s->u.source != SOURCE_ADF_BACK && s->u.source != SOURCE_CARD_BACK ) s->u.bytes_tot[SIDE_FRONT] = s->u.Bpl * s->u.height; - if ( s->i.source != SOURCE_ADF_BACK ) + if ( s->i.source != SOURCE_ADF_BACK && s->i.source != SOURCE_CARD_BACK ) s->i.bytes_tot[SIDE_FRONT] = s->i.Bpl * s->i.height; - if ( s->s.source != SOURCE_ADF_BACK ) + if ( s->s.source != SOURCE_ADF_BACK && s->s.source != SOURCE_CARD_BACK ) s->s.bytes_tot[SIDE_FRONT] = s->s.Bpl * s->s.height; /* store the number of back bytes */ - if ( s->u.source == SOURCE_ADF_DUPLEX || s->u.source == SOURCE_ADF_BACK ) + if ( s->u.source == SOURCE_ADF_DUPLEX || s->u.source == SOURCE_ADF_BACK + || s->u.source == SOURCE_CARD_DUPLEX || s->u.source == SOURCE_CARD_BACK ) s->u.bytes_tot[SIDE_BACK] = s->u.Bpl * s->u.height; - if ( s->i.source == SOURCE_ADF_DUPLEX || s->i.source == SOURCE_ADF_BACK ) + if ( s->i.source == SOURCE_ADF_DUPLEX || s->i.source == SOURCE_ADF_BACK + || s->i.source == SOURCE_CARD_DUPLEX || s->i.source == SOURCE_CARD_BACK ) s->i.bytes_tot[SIDE_BACK] = s->i.Bpl * s->i.height; - if ( s->s.source == SOURCE_ADF_DUPLEX || s->s.source == SOURCE_ADF_BACK ) + if ( s->s.source == SOURCE_ADF_DUPLEX || s->s.source == SOURCE_ADF_BACK + || s->s.source == SOURCE_CARD_DUPLEX || s->s.source == SOURCE_CARD_BACK ) s->s.bytes_tot[SIDE_BACK] = s->s.Bpl * s->s.height; DBG (10, "clean_params: finish\n"); @@ -3863,7 +4309,7 @@ set_window (struct scanner *s) set_WPDB_wdblen(header, SW_desc_len); /* init the window block */ - if (s->s.source == SOURCE_ADF_BACK) { + if (s->s.source == SOURCE_ADF_BACK || s->s.source == SOURCE_CARD_BACK) { set_WD_wid (desc1, WD_wid_back); } else{ @@ -3933,13 +4379,11 @@ set_window (struct scanner *s) set_WD_compress_type(desc1, COMP_NONE); set_WD_compress_arg(desc1, 0); -#ifdef SANE_FRAME_JPEG /* some scanners support jpeg image compression, for color/gs only */ if(s->s.format == SANE_FRAME_JPEG){ set_WD_compress_type(desc1, COMP_JPEG); set_WD_compress_arg(desc1, s->compress_arg); } -#endif /*build the command*/ memset(cmd,0,cmdLen); @@ -3953,7 +4397,7 @@ set_window (struct scanner *s) NULL, NULL ); - if (!ret && s->s.source == SOURCE_ADF_DUPLEX) { + if (!ret && (s->s.source == SOURCE_ADF_DUPLEX || s->s.source == SOURCE_CARD_DUPLEX)) { set_WD_wid (desc1, WD_wid_back); ret = do_cmd ( s, 1, 0, @@ -4037,9 +4481,9 @@ start_scan (struct scanner *s, int type) out[1] = type; } - if (s->s.source != SOURCE_ADF_DUPLEX) { + if (s->s.source != SOURCE_ADF_DUPLEX && s->s.source != SOURCE_CARD_DUPLEX) { outLen--; - if(s->s.source == SOURCE_ADF_BACK) { + if(s->s.source == SOURCE_ADF_BACK || s->s.source == SOURCE_CARD_BACK) { out[0] = WD_wid_back; } } @@ -4100,7 +4544,7 @@ sane_read (SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, SANE_Int * len s->reading = 1; /* double width pnm interlacing */ - if(s->s.source == SOURCE_ADF_DUPLEX + if((s->s.source == SOURCE_ADF_DUPLEX || s->s.source == SOURCE_CARD_DUPLEX) && s->s.format <= SANE_FRAME_RGB && s->duplex_interlace != DUPLEX_INTERLACE_NONE ){ @@ -4225,7 +4669,6 @@ read_from_scanner(struct scanner *s, int side, int exact) inLen = 0; } -#ifdef SANE_FRAME_JPEG /* this is jpeg data, we need to fix the missing image size */ if(s->s.format == SANE_FRAME_JPEG){ @@ -4275,7 +4718,6 @@ read_from_scanner(struct scanner *s, int side, int exact) } } } -#endif /*scanner may have sent more data than we asked for, chop it*/ if(inLen > remain){ @@ -4301,37 +4743,32 @@ read_from_scanner(struct scanner *s, int side, int exact) if(ret == SANE_STATUS_EOF){ - switch (s->s.format){ + /* this is jpeg data, we need to change the total size */ + if(s->s.format == SANE_FRAME_JPEG){ + s->s.bytes_tot[side] = s->s.bytes_sent[side]; + s->i.bytes_tot[side] = s->i.bytes_sent[side]; + s->u.bytes_tot[side] = s->i.bytes_sent[side]; + } -#ifdef SANE_FRAME_JPEG - /* this is jpeg data, we need to change the total size */ - case SANE_FRAME_JPEG: - s->s.bytes_tot[side] = s->s.bytes_sent[side]; - s->i.bytes_tot[side] = s->i.bytes_sent[side]; - s->u.bytes_tot[side] = s->i.bytes_sent[side]; - break; -#endif - - /* this is non-jpeg data, fill remainder, change rx'd size */ - default: + /* this is non-jpeg data, fill remainder, change rx'd size */ + else{ - DBG (15, "read_from_scanner: eof: %d %d\n", s->i.bytes_tot[side], s->i.bytes_sent[side]); + DBG (15, "read_from_scanner: eof: %d %d\n", s->i.bytes_tot[side], s->i.bytes_sent[side]); - /* clone the last line repeatedly until the end */ - while(s->i.bytes_tot[side] > s->i.bytes_sent[side]){ - memcpy( - s->buffers[side]+s->i.bytes_sent[side]-s->i.Bpl, - s->buffers[side]+s->i.bytes_sent[side], - s->i.Bpl - ); - s->i.bytes_sent[side] += s->i.Bpl; - } + /* clone the last line repeatedly until the end */ + while(s->i.bytes_tot[side] > s->i.bytes_sent[side]){ + memcpy( + s->buffers[side]+s->i.bytes_sent[side]-s->i.Bpl, + s->buffers[side]+s->i.bytes_sent[side], + s->i.Bpl + ); + s->i.bytes_sent[side] += s->i.Bpl; + } - DBG (15, "read_from_scanner: eof2: %d %d\n", s->i.bytes_tot[side], s->i.bytes_sent[side]); + DBG (15, "read_from_scanner: eof2: %d %d\n", s->i.bytes_tot[side], s->i.bytes_sent[side]); - /* pretend we got all the data from scanner */ - s->s.bytes_sent[side] = s->s.bytes_tot[side]; - break; + /* pretend we got all the data from scanner */ + s->s.bytes_sent[side] = s->s.bytes_tot[side]; } s->i.eof[side] = 1; @@ -4441,57 +4878,52 @@ read_from_scanner_duplex(struct scanner *s,int exact) if(ret == SANE_STATUS_EOF){ - switch (s->s.format){ - -#ifdef SANE_FRAME_JPEG - /* this is jpeg data, we need to change the total size */ - case SANE_FRAME_JPEG: - s->s.bytes_tot[SIDE_FRONT] = s->s.bytes_sent[SIDE_FRONT]; - s->s.bytes_tot[SIDE_BACK] = s->s.bytes_sent[SIDE_BACK]; - s->i.bytes_tot[SIDE_FRONT] = s->i.bytes_sent[SIDE_FRONT]; - s->i.bytes_tot[SIDE_BACK] = s->i.bytes_sent[SIDE_BACK]; - s->u.bytes_tot[SIDE_FRONT] = s->i.bytes_sent[SIDE_FRONT]; - s->u.bytes_tot[SIDE_BACK] = s->i.bytes_sent[SIDE_BACK]; - break; -#endif - - /* this is non-jpeg data, fill remainder, change rx'd size */ - default: + /* this is jpeg data, we need to change the total size */ + if(s->s.format == SANE_FRAME_JPEG){ + s->s.bytes_tot[SIDE_FRONT] = s->s.bytes_sent[SIDE_FRONT]; + s->s.bytes_tot[SIDE_BACK] = s->s.bytes_sent[SIDE_BACK]; + s->i.bytes_tot[SIDE_FRONT] = s->i.bytes_sent[SIDE_FRONT]; + s->i.bytes_tot[SIDE_BACK] = s->i.bytes_sent[SIDE_BACK]; + s->u.bytes_tot[SIDE_FRONT] = s->i.bytes_sent[SIDE_FRONT]; + s->u.bytes_tot[SIDE_BACK] = s->i.bytes_sent[SIDE_BACK]; + } - DBG (15, "read_from_scanner_duplex: eof: %d %d %d %d\n", - s->i.bytes_tot[SIDE_FRONT], s->i.bytes_sent[SIDE_FRONT], - s->i.bytes_tot[SIDE_BACK], s->i.bytes_sent[SIDE_BACK] - ); + /* this is non-jpeg data, fill remainder, change rx'd size */ + else{ - /* clone the last line repeatedly until the end */ - while(s->i.bytes_tot[SIDE_FRONT] > s->i.bytes_sent[SIDE_FRONT]){ - memcpy( - s->buffers[SIDE_FRONT]+s->i.bytes_sent[SIDE_FRONT]-s->i.Bpl, - s->buffers[SIDE_FRONT]+s->i.bytes_sent[SIDE_FRONT], - s->i.Bpl - ); - s->i.bytes_sent[SIDE_FRONT] += s->i.Bpl; - } + DBG (15, "read_from_scanner_duplex: eof: %d %d %d %d\n", + s->i.bytes_tot[SIDE_FRONT], s->i.bytes_sent[SIDE_FRONT], + s->i.bytes_tot[SIDE_BACK], s->i.bytes_sent[SIDE_BACK] + ); - /* clone the last line repeatedly until the end */ - while(s->i.bytes_tot[SIDE_BACK] > s->i.bytes_sent[SIDE_BACK]){ - memcpy( - s->buffers[SIDE_BACK]+s->i.bytes_sent[SIDE_BACK]-s->i.Bpl, - s->buffers[SIDE_BACK]+s->i.bytes_sent[SIDE_BACK], - s->i.Bpl - ); - s->i.bytes_sent[SIDE_BACK] += s->i.Bpl; - } + /* clone the last line repeatedly until the end */ + while(s->i.bytes_tot[SIDE_FRONT] > s->i.bytes_sent[SIDE_FRONT]){ + memcpy( + s->buffers[SIDE_FRONT]+s->i.bytes_sent[SIDE_FRONT]-s->i.Bpl, + s->buffers[SIDE_FRONT]+s->i.bytes_sent[SIDE_FRONT], + s->i.Bpl + ); + s->i.bytes_sent[SIDE_FRONT] += s->i.Bpl; + } - DBG (15, "read_from_scanner_duplex: eof2: %d %d %d %d\n", - s->i.bytes_tot[SIDE_FRONT], s->i.bytes_sent[SIDE_FRONT], - s->i.bytes_tot[SIDE_BACK], s->i.bytes_sent[SIDE_BACK] + /* clone the last line repeatedly until the end */ + while(s->i.bytes_tot[SIDE_BACK] > s->i.bytes_sent[SIDE_BACK]){ + memcpy( + s->buffers[SIDE_BACK]+s->i.bytes_sent[SIDE_BACK]-s->i.Bpl, + s->buffers[SIDE_BACK]+s->i.bytes_sent[SIDE_BACK], + s->i.Bpl ); + s->i.bytes_sent[SIDE_BACK] += s->i.Bpl; + } - /* pretend we got all the data from scanner */ - s->s.bytes_sent[SIDE_FRONT] = s->s.bytes_tot[SIDE_FRONT]; - s->s.bytes_sent[SIDE_BACK] = s->s.bytes_tot[SIDE_BACK]; - break; + DBG (15, "read_from_scanner_duplex: eof2: %d %d %d %d\n", + s->i.bytes_tot[SIDE_FRONT], s->i.bytes_sent[SIDE_FRONT], + s->i.bytes_tot[SIDE_BACK], s->i.bytes_sent[SIDE_BACK] + ); + + /* pretend we got all the data from scanner */ + s->s.bytes_sent[SIDE_FRONT] = s->s.bytes_tot[SIDE_FRONT]; + s->s.bytes_sent[SIDE_BACK] = s->s.bytes_tot[SIDE_BACK]; } s->i.eof[SIDE_FRONT] = 1; @@ -4522,6 +4954,7 @@ copy_simplex(struct scanner *s, unsigned char * buf, int len, int side) unsigned char * line = NULL; int line_next = 0; + int inter = get_color_inter(s,side,s->s.dpi_x); /* jpeg data should not pass thru this function, so copy and bail out */ if(s->s.format > SANE_FRAME_RGB){ @@ -4592,7 +5025,7 @@ copy_simplex(struct scanner *s, unsigned char * buf, int len, int side) else if (s->s.format == SANE_FRAME_RGB){ - switch (s->color_interlace[side]) { + switch (inter) { /* scanner returns color data as bgrbgr... */ case COLOR_INTERLACE_BGR: @@ -4604,6 +5037,26 @@ copy_simplex(struct scanner *s, unsigned char * buf, int len, int side) } break; + /* scanner returns color data as gbrgbr... */ + case COLOR_INTERLACE_GBR: + DBG (17, "copy_simplex: color, GBR\n"); + for (j=0; j<pwidth; j++){ + line[line_next++] = buf[i+j*3+2]; + line[line_next++] = buf[i+j*3]; + line[line_next++] = buf[i+j*3+1]; + } + break; + + /* scanner returns color data as brgbrg... */ + case COLOR_INTERLACE_BRG: + DBG (17, "copy_simplex: color, BRG\n"); + for (j=0; j<pwidth; j++){ + line[line_next++] = buf[i+j*3+1]; + line[line_next++] = buf[i+j*3+2]; + line[line_next++] = buf[i+j*3]; + } + break; + /* one line has the following format: RRR...rrrGGG...gggBBB...bbb */ case COLOR_INTERLACE_RRGGBB: DBG (17, "copy_simplex: color, RRGGBB\n"); @@ -4768,7 +5221,7 @@ copy_duplex(struct scanner *s, unsigned char * buf, int len) } } - /* no scanners use this? */ + /* full line of front, then full line of back */ else if(s->duplex_interlace == DUPLEX_INTERLACE_FFBB){ for(i=0; i<len; i+=dbwidth){ memcpy(front+flen,buf+i,bwidth); @@ -4877,7 +5330,7 @@ copy_line(struct scanner *s, unsigned char * buff, int side) /* scan is wider than user wanted, skip some pixels on left side */ if(s->i.width != s->s.width){ - offset = ((s->valid_x-s->i.page_x) / 2 + s->i.tl_x) * s->i.dpi_x/1200*3; + offset = ((s->valid_x-s->i.page_x) / 2 + s->i.tl_x) * s->i.dpi_x/1200; } /* change mode, store line in buffer */ @@ -4905,7 +5358,7 @@ copy_line(struct scanner *s, unsigned char * buff, int side) /*loop over output bits*/ for(j=0;j<8;j++){ - int source = (offset+i)*24 + j*3; + int source = offset*3 + i*24 + j*3; if( (line[source] + line[source+1] + line[source+2]) < thresh ){ curr |= 1 << (7-j); } @@ -5967,6 +6420,7 @@ default_globals(void) { global_buffer_size = global_buffer_size_default; global_padded_read = global_padded_read_default; + global_extra_status = global_extra_status_default; global_duplex_offset = global_duplex_offset_default; global_vendor_name[0] = 0; global_model_name[0] = 0; @@ -6252,7 +6706,6 @@ do_scsi_cmd(struct scanner *s, int runRS, int shortTime, ) { int ret; - size_t actLen = 0; /*shut up compiler*/ runRS=runRS; @@ -6270,7 +6723,6 @@ do_scsi_cmd(struct scanner *s, int runRS, int shortTime, if (inBuff && inLen){ DBG(25, "in: reading %d bytes\n", (int)*inLen); memset(inBuff,0,*inLen); - actLen = *inLen; } ret = sanei_scsi_cmd2(s->fd, cmdBuff, cmdLen, outBuff, outLen, inBuff, inLen); @@ -6285,7 +6737,7 @@ do_scsi_cmd(struct scanner *s, int runRS, int shortTime, DBG(25, "in: short read, remainder %lu bytes\n", (u_long)s->rs_info); *inLen -= s->rs_info; } - hexdump(30, "in: <<", inBuff, *inLen); + hexdump(31, "in: <<", inBuff, *inLen); DBG(25, "in: read %d bytes\n", (int)*inLen); } @@ -6319,16 +6771,15 @@ do_usb_cmd(struct scanner *s, int runRS, int shortTime, unsigned char * inBuffer = NULL; int inTimeout = 0; - size_t statOffset = 0; - size_t statLength = 0; - size_t statActual = 0; - unsigned char * statBuffer = NULL; - int statTimeout = 0; + size_t extraLength = 0; int ret = 0; int ret2 = 0; - DBG (10, "do_usb_cmd: start\n"); + struct timeval timer; + gettimeofday(&timer,NULL); + + DBG (10, "do_usb_cmd: start %lu %lu\n", (long unsigned int)timer.tv_sec, (long unsigned int)timer.tv_usec); /****************************************************************/ /* the command stage */ @@ -6376,6 +6827,20 @@ do_usb_cmd(struct scanner *s, int runRS, int shortTime, } /****************************************************************/ + /* the extra status stage, used by few scanners */ + /* this is like the regular status block, with an additional */ + /* length component at the end */ + if(s->extra_status){ + ret2 = do_usb_status(s,runRS,shortTime,&extraLength); + + /* bail out on bad RS status */ + if(ret2){ + DBG(5,"extra: bad RS status, %d\n", ret2); + return ret2; + } + } + + /****************************************************************/ /* the output stage */ if(outBuff && outLen){ @@ -6432,6 +6897,12 @@ do_usb_cmd(struct scanner *s, int runRS, int shortTime, inLength = inOffset+*inLen; inActual = inLength; + /* use the extra length to alter the amount of in we request */ + if(s->extra_status && extraLength && *inLen > extraLength){ + DBG(5,"in: adjust extra, %d %d\n", (int)*inLen, (int)extraLength); + inActual = inOffset+extraLength; + } + /*blast caller's copy in case we error out*/ *inLen = 0; @@ -6443,16 +6914,16 @@ do_usb_cmd(struct scanner *s, int runRS, int shortTime, sanei_usb_set_timeout(inTimeout); /* build inBuffer */ - inBuffer = calloc(inLength,1); + inBuffer = calloc(inActual,1); if(!inBuffer){ DBG(5,"in: no mem\n"); return SANE_STATUS_NO_MEM; } - DBG(25, "in: reading %d bytes, timeout %d\n", (int)inLength, inTimeout); + DBG(25, "in: reading %d bytes, timeout %d\n", (int)inActual, inTimeout); ret = sanei_usb_read_bulk(s->fd, inBuffer, &inActual); DBG(25, "in: read %d bytes, retval %d\n", (int)inActual, ret); - hexdump(30, "in: <<", inBuffer, inActual); + hexdump(31, "in: <<", inBuffer, inActual); if(!inActual){ DBG(5,"in: got no data, clearing\n"); @@ -6474,49 +6945,8 @@ do_usb_cmd(struct scanner *s, int runRS, int shortTime, } /****************************************************************/ - /* the status stage */ - statOffset = 0; - if(s->padded_read) - statOffset = USB_HEADER_LEN; - - statLength = statOffset+USB_STATUS_LEN; - statActual = statLength; - statTimeout = USB_STATUS_TIME; - - /* change timeout */ - if(shortTime) - statTimeout/=60; - sanei_usb_set_timeout(statTimeout); - - /* build statBuffer */ - statBuffer = calloc(statLength,1); - if(!statBuffer){ - DBG(5,"stat: no mem\n"); - if(inBuffer) free(inBuffer); - return SANE_STATUS_NO_MEM; - } - - DBG(25, "stat: reading %d bytes, timeout %d\n", (int)statLength, statTimeout); - ret2 = sanei_usb_read_bulk(s->fd, statBuffer, &statActual); - DBG(25, "stat: read %d bytes, retval %d\n", (int)statActual, ret2); - hexdump(30, "stat: <<", statBuffer, statActual); - - /*weird status*/ - if(ret2 != SANE_STATUS_GOOD){ - DBG(5,"stat: clearing error '%s'\n",sane_strstatus(ret2)); - ret2 = do_usb_clear(s,1,runRS); - } - /*short read*/ - else if(statLength != statActual){ - DBG(5,"stat: clearing short %d/%d\n",(int)statLength,(int)statActual); - ret2 = do_usb_clear(s,1,runRS); - } - /*inspect the last byte of the status response*/ - else if(statBuffer[statLength-1]){ - DBG(5,"stat: status %d\n",statBuffer[statLength-1]); - ret2 = do_usb_clear(s,0,runRS); - } - free(statBuffer); + /* the normal status stage */ + ret2 = do_usb_status(s,runRS,shortTime,&extraLength); /* if status said EOF, adjust input with remainder count */ if(ret2 == SANE_STATUS_EOF && inBuffer){ @@ -6524,11 +6954,11 @@ do_usb_cmd(struct scanner *s, int runRS, int shortTime, /* EOF is ok */ ret2 = SANE_STATUS_GOOD; - if(inActual <= inLength - s->rs_info){ - DBG(5,"in: we read <= RS, ignoring RS: %d <= %d (%d-%d)\n", + if(inActual < inLength - s->rs_info){ + DBG(5,"in: we read < RS, ignoring RS: %d < %d (%d-%d)\n", (int)inActual,(int)(inLength-s->rs_info),(int)inLength,(int)s->rs_info); } - else if(s->rs_info){ + else if(inActual > inLength - s->rs_info){ DBG(5,"in: we read > RS, using RS: %d to %d (%d-%d)\n", (int)inActual,(int)(inLength-s->rs_info),(int)inLength,(int)s->rs_info); inActual = inLength - s->rs_info; @@ -6556,7 +6986,80 @@ do_usb_cmd(struct scanner *s, int runRS, int shortTime, free(inBuffer); } - DBG (10, "do_usb_cmd: finish\n"); + gettimeofday(&timer,NULL); + + DBG (10, "do_usb_cmd: finish %lu %lu\n", (long unsigned int)timer.tv_sec, (long unsigned int)timer.tv_usec); + + return ret; +} + +static SANE_Status +do_usb_status(struct scanner *s, int runRS, int shortTime, size_t * extraLength) +{ + +#define EXTRA_READ_len 4 + + size_t statPadding = 0; + size_t statOffset = 0; + size_t statLength = 0; + size_t statActual = 0; + unsigned char * statBuffer = NULL; + int statTimeout = 0; + + int ret = 0; + + if(s->padded_read) + statPadding = USB_HEADER_LEN; + + statLength = statPadding+USB_STATUS_LEN; + statOffset = statLength-1; + + if(s->extra_status) + statLength += EXTRA_READ_len; + + statActual = statLength; + statTimeout = USB_STATUS_TIME; + + /* change timeout */ + if(shortTime) + statTimeout/=60; + sanei_usb_set_timeout(statTimeout); + + /* build statBuffer */ + statBuffer = calloc(statLength,1); + if(!statBuffer){ + DBG(5,"stat: no mem\n"); + return SANE_STATUS_NO_MEM; + } + + DBG(25, "stat: reading %d bytes, timeout %d\n", (int)statLength, statTimeout); + ret = sanei_usb_read_bulk(s->fd, statBuffer, &statActual); + DBG(25, "stat: read %d bytes, retval %d\n", (int)statActual, ret); + hexdump(30, "stat: <<", statBuffer, statActual); + + /*weird status*/ + if(ret != SANE_STATUS_GOOD){ + DBG(5,"stat: clearing error '%s'\n",sane_strstatus(ret)); + ret = do_usb_clear(s,1,runRS); + } + /*short read*/ + else if(statLength != statActual){ + DBG(5,"stat: clearing short %d/%d\n",(int)statLength,(int)statActual); + ret = do_usb_clear(s,1,runRS); + } + /*inspect the status byte of the response*/ + else if(statBuffer[statOffset]){ + DBG(5,"stat: status %d\n",statBuffer[statLength-1-4]); + ret = do_usb_clear(s,0,runRS); + } + + /*extract the extra length byte of the response*/ + if(s->extra_status){ + *extraLength = get_ES_length(statBuffer); + DBG(15,"stat: extra %d\n",(int)*extraLength); + } + + free(statBuffer); return ret; } @@ -6670,6 +7173,26 @@ wait_scanner(struct scanner *s) return ret; } +/* Some scanners have per-resolution + * color interlacing values, but most + * don't. This helper can tell the + * difference. + */ +static int +get_color_inter(struct scanner *s, int side, int res) +{ + int i; + for(i=0;i<DPI_1200;i++){ + if(res == dpi_list[i]) + break; + } + + if(s->color_inter_by_res[i]) + return s->color_inter_by_res[i]; + + return s->color_interlace[side]; +} + /* s->u.page_x stores the user setting * for the paper width in adf. sometimes, * we need a value that differs from this @@ -6789,7 +7312,8 @@ hexdump (int level, char *comment, unsigned char *p, int l) } /* print last (partial) line */ - DBG (level, "%s\n", line); + if (i) + DBG (level, "%s\n", line); } /** diff --git a/backend/canon_dr.conf.in b/backend/canon_dr.conf.in index ef1dfdf..453065b 100644 --- a/backend/canon_dr.conf.in +++ b/backend/canon_dr.conf.in @@ -15,8 +15,9 @@ ####################################################################### # Set data buffer size, in bytes. The value ranges from 4096 - infinity -# large values may cause timeouts, small causes slow scans. 4MB default -#option buffer-size 4194304 +# Large values may cause timeouts, or long pauses at the end of each +# page. Small values may cause slow scans. 2MB is the default. +#option buffer-size 2097152 ####################################################################### # Most scanners dont pad their reads @@ -138,9 +139,69 @@ usb 0x1083 0x1638 # CR-135i usb 0x1083 0x1639 +# DR-M160 +option extra-status 1 +option duplex-offset 400 +usb 0x1083 0x163e + +# DR-M140 +option extra-status 1 +option duplex-offset 400 +usb 0x1083 0x163f + +# DR-C125 +option duplex-offset 400 +usb 0x1083 0x1640 + +# DR-P215 +usb 0x1083 0x1641 + # P-215 usb 0x1083 0x1646 +# FSU-201 +usb 0x1083 0x1648 + +# DR-C130 +usb 0x1083 0x164a + +# DR-P208 +usb 0x1083 0x164b + # P-208 usb 0x1083 0x164c +# DR-G1130 +option buffer-size 8000000 +usb 0x1083 0x164f + +# DR-G1100 +option buffer-size 8000000 +usb 0x1083 0x1650 + +# DR-C120 +usb 0x1083 0x1651 + +# P-201 +usb 0x1083 0x1652 + +# DR-F120 +usb 0x1083 0x1654 + +# DR-M1060 +usb 0x1083 0x1657 + +# DR-C225 +usb 0x1083 0x1658 + +# DR-P215II +usb 0x1083 0x1659 + +# P-215II +usb 0x1083 0x165b + +# DR-P208II +usb 0x1083 0x165d + +# P-208II +usb 0x1083 0x165f diff --git a/backend/canon_dr.h b/backend/canon_dr.h index 1bf95a0..4a19f55 100644 --- a/backend/canon_dr.h +++ b/backend/canon_dr.h @@ -58,6 +58,8 @@ enum scanner_Option OPT_COUNTONLY, OPT_BYPASSMODE, OPT_COUNTER, + OPT_ADF_LOADED, + OPT_CARD_LOADED, /* must come last: */ NUM_OPTIONS @@ -174,13 +176,16 @@ struct scanner int has_flatbed; int has_duplex; int has_back; /* not all duplex scanners can do adf back side only */ + int has_card; /* P215 has a card reader instead of fb */ int has_comp_JPEG; int has_buffer; int has_df; + int has_df_ultra; int has_btc; int has_ssm; /* older scanners use this set scan mode command */ int has_ssm2; /* newer scanners user this similar command */ int has_ssm_pay_head_len; /* newer scanners put the length twice in ssm */ + int can_read_sensors; int can_read_panel; int can_write_panel; int rgb_format; /* meaning unknown */ @@ -190,11 +195,13 @@ struct scanner int invert_tly; /* weird bug in some smaller scanners */ int unknown_byte2; /* weird byte, required, meaning unknown */ int padded_read; /* some machines need extra 12 bytes on reads */ + int extra_status; /* some machines need extra status read after cmd */ int fixed_width; /* some machines always scan full width */ int even_Bpl; /* some machines require even bytes per line */ int gray_interlace[2]; /* different models interlace heads differently */ int color_interlace[2]; /* different models interlace colors differently */ + int color_inter_by_res[16]; /* and some even change by resolution */ int duplex_interlace; /* different models interlace sides differently */ int jpeg_interlace; /* different models interlace jpeg sides differently */ int duplex_offset; /* number of lines of padding added to front (1/1200)*/ @@ -224,7 +231,7 @@ struct scanner /*mode group*/ SANE_String_Const mode_list[7]; - SANE_String_Const source_list[5]; + SANE_String_Const source_list[8]; SANE_Int res_list[17]; SANE_Range res_range; @@ -334,9 +341,12 @@ struct scanner int panel_bypass_mode; int panel_enable_led; int panel_counter; + int sensor_adf_loaded; + int sensor_card_loaded; /* values which are used to track the frontend's access to sensors */ - char hw_read[NUM_OPTIONS-OPT_START]; + char panel_read[OPT_COUNTER - OPT_START + 1]; + char sensors_read[OPT_CARD_LOADED - OPT_ADF_LOADED + 1]; }; #define CONNECTION_SCSI 0 /* SCSI interface */ @@ -353,6 +363,9 @@ struct scanner #define SOURCE_ADF_FRONT 1 #define SOURCE_ADF_BACK 2 #define SOURCE_ADF_DUPLEX 3 +#define SOURCE_CARD_FRONT 4 +#define SOURCE_CARD_BACK 5 +#define SOURCE_CARD_DUPLEX 6 static const int dpi_list[] = { 60,75,100,120,150,160,180,200, @@ -406,11 +419,14 @@ enum { #define GRAY_INTERLACE_2510 1 #define GRAY_INTERLACE_gG 2 -#define COLOR_INTERLACE_RGB 0 -#define COLOR_INTERLACE_BGR 1 -#define COLOR_INTERLACE_RRGGBB 2 -#define COLOR_INTERLACE_rRgGbB 3 -#define COLOR_INTERLACE_2510 4 +#define COLOR_INTERLACE_UNK 0 +#define COLOR_INTERLACE_RGB 1 +#define COLOR_INTERLACE_BGR 2 +#define COLOR_INTERLACE_BRG 3 +#define COLOR_INTERLACE_GBR 4 +#define COLOR_INTERLACE_RRGGBB 5 +#define COLOR_INTERLACE_rRgGbB 6 +#define COLOR_INTERLACE_2510 7 #define DUPLEX_INTERLACE_NONE 0 #define DUPLEX_INTERLACE_FFBB 1 @@ -510,6 +526,9 @@ do_usb_cmd(struct scanner *s, int runRS, int shortTime, unsigned char * inBuff, size_t * inLen ); +static SANE_Status +do_usb_status(struct scanner *s, int runRS, int shortTime, size_t * extraLength); + static SANE_Status do_usb_clear(struct scanner *s, int clear, int runRS); static SANE_Status wait_scanner (struct scanner *s); @@ -520,6 +539,8 @@ static SANE_Status ssm_buffer (struct scanner *s); static SANE_Status ssm_do (struct scanner *s); static SANE_Status ssm_df (struct scanner *s); +static int get_color_inter(struct scanner *s, int side, int res); + static int get_page_width (struct scanner *s); static int get_page_height (struct scanner *s); @@ -528,6 +549,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_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); diff --git a/backend/coolscan.c b/backend/coolscan.c index 00a12e4..6828a16 100644 --- a/backend/coolscan.c +++ b/backend/coolscan.c @@ -179,7 +179,7 @@ request_sense_parse (unsigned char *sensed_data) case 0x2: if ((0x4 == asc) && (0x1 == ascq)) { - DBG (10, "\t%d/%d/%d: Logical unit is in process of becomming ready\n", + DBG (10, "\t%d/%d/%d: Logical unit is in process of becoming ready\n", sense, asc, ascq); ret = SANE_STATUS_DEVICE_BUSY; } @@ -1987,6 +1987,7 @@ static const SANE_Range shift_range = 0 }; +static const SANE_Device **devlist = 0; static int num_devices; static Coolscan_t *first_dev; @@ -3287,6 +3288,9 @@ sane_exit (void) free (dev->obuffer); free (dev); } + + if (devlist) + free (devlist); } /* ----------------------------- SANE GET DEVICES -------------------------- */ @@ -3294,8 +3298,6 @@ SANE_Status sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only) { - - static const SANE_Device **devlist = 0; Coolscan_t *dev; int i; diff --git a/backend/dll.c b/backend/dll.c index 619ee55..5264f11 100644 --- a/backend/dll.c +++ b/backend/dll.c @@ -430,7 +430,7 @@ load (struct backend *be) if (path) { - src_len = strlen (path) + strlen (STRINGIFY (LIBDIR)) + 1 + 1; + src_len = strlen (path) + strlen (LIBDIR) + 1 + 1; src = malloc (src_len); if (!src) { @@ -438,11 +438,11 @@ load (struct backend *be) return SANE_STATUS_NO_MEM; } orig_src = src; - snprintf (src, src_len, "%s:%s", path, STRINGIFY (LIBDIR)); + snprintf (src, src_len, "%s:%s", path, LIBDIR); } else { - src = STRINGIFY (LIBDIR); + src = LIBDIR; src = strdup (src); if (!src) { diff --git a/backend/dll.conf.in b/backend/dll.conf.in index a7e4b3e..ee6f2f1 100644 --- a/backend/dll.conf.in +++ b/backend/dll.conf.in @@ -24,6 +24,7 @@ dmc epjitsu #epson epson2 +epsonds fujitsu #gphoto2 genesys diff --git a/backend/dmc.c b/backend/dmc.c index 96f9186..7fc2ae9 100644 --- a/backend/dmc.c +++ b/backend/dmc.c @@ -75,6 +75,7 @@ static DMC_Device *FirstDevice = NULL; static DMC_Camera *FirstHandle = NULL; static int NumDevices = 0; +static SANE_Device const **devlist = NULL; static SANE_String_Const ValidModes[] = { "Full frame", "Viewfinder", "Raw", "Thumbnail", @@ -867,6 +868,9 @@ sane_exit(void) free(dev); dev = next; } + + if (devlist) + free (devlist); } /********************************************************************** @@ -882,7 +886,6 @@ sane_exit(void) SANE_Status sane_get_devices(SANE_Device const ***device_list, SANE_Bool local_only) { - static SANE_Device const **devlist = 0; DMC_Device *dev; int i = 0; diff --git a/backend/epjitsu-cmd.h b/backend/epjitsu-cmd.h index 2e914d9..77793df 100644 --- a/backend/epjitsu-cmd.h +++ b/backend/epjitsu-cmd.h @@ -38,31 +38,55 @@ static unsigned char coarseCalData_S300[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x2d, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x24, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; +static unsigned char coarseCalData_S1300i[] = { +0x00, 0x00, 0x00, 0x00, 0x00, 0x2d, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x24, 0x00, 0x28, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; +static unsigned char coarseCalData_S1100[] = { +0x00, 0x00, 0x00, 0x00, 0x00, 0x25, 0x00, 0x25, 0x00, 0x00, 0x00, 0x26, 0x00, 0x26, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; /*************** fi-60F 150dpi *************/ -/* 1b d1 (set window) before coarse cal (read 1 line of 0x____ bytes) */ +/* 1b d1 (set window) before coarse cal (read 1 line of 0x1c20 bytes) */ static unsigned char setWindowCoarseCal_FI60F_150[] = { -0 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x01, 0x2c, 0x01, 0x2c, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x60, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, +0x00, 0x05, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -/* 1b d1 (set window) before fine cal (read 16 lines of 0x____ bytes) */ +/* 1b d1 (set window) before fine cal (read 16 lines of 0x1c20 bytes) */ static unsigned char setWindowFineCal_FI60F_150[] = { -0 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x01, 0x2c, 0x03, 0x20, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x60, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, +0x00, 0x05, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x80, 0x80, 0x00, 0x10, 0x00, 0x08, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -/* 1b d1 (set window) before gain/offset tables (write 1 line of 0x____ bytes) */ +/* 1b d1 (set window) before gain/offset tables (write 1 line of 0x3840 bytes) */ static unsigned char setWindowSendCal_FI60F_150[] = { -0 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x01, 0x2c, 0x03, 0x20, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x60, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, +0x00, 0x05, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x08, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; /* 1b c3 (gain?) command header */ -static unsigned char sendCal1Header_FI60F_150[] = { -0 +static unsigned char sendCal1Header_FI60F_150[] = { /* plus 0x3840 data bytes */ +0x8c, 0x0f, 0x8c, 0x0f, 0x8c, 0x0f, 0x8c, 0x0f, 0x8c, 0x0f, 0x8c, 0x0f, 0x00, 0x04 }; /* 1b c4 (offset?) command header */ static unsigned char sendCal2Header_FI60F_150[] = { -0 +0x39, 0x3f, 0x39, 0x3f, 0x39, 0x3f, 0x07 }; /* 1b d1 (set window) before scan */ static unsigned char setWindowScan_FI60F_150[] = { -0 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x01, 0x2c, 0x00, 0x96, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x60, 0x00, 0x00, 0x03, 0x6b, 0x00, 0x00, +0x00, 0x05, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x80, 0x80, 0x01, 0x48, 0x00, 0x08, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; /*************** fi-60F 300dpi *************/ @@ -323,8 +347,8 @@ static unsigned char setWindowScan_S300_600[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -/*S300 can also use a USB power cable, but it requires a different set of params?*/ -/*************** S300 150dpi USB *************/ +/*S300/S1300/S1300i can also use a USB power cable, but it requires a different set of params?*/ +/*************** S300/S1300/S1300i 150dpi USB *************/ /* 1b d1 (set window) before coarse cal (read 1 line of 0x63c0 bytes) */ static unsigned char setWindowCoarseCal_S300_150_U[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x01, 0x2c, 0x01, 0x2c, 0x00, 0x00, @@ -338,7 +362,7 @@ static unsigned char setWindowFineCal_S300_150_U[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x01, 0x2c, 0x03, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x20, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x05, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x08, 0x80, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x96, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x80, 0x80, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x96, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; /* 1b d1 (set window) before gain/offset tables (write 1 line of 0xc780 bytes) */ @@ -368,7 +392,7 @@ static unsigned char setWindowScan_S300_150_U[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -/*************** S300 225dpi USB *************/ +/*************** S300/S1300/S1300i 225dpi USB *************/ /* 1b d1 (set window) before coarse cal (read 1 line of 0x63c0 bytes) */ static unsigned char setWindowCoarseCal_S300_225_U[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x01, 0x2c, 0x01, 0x2c, 0x00, 0x00, @@ -412,7 +436,8 @@ static unsigned char setWindowScan_S300_225_U[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -/*************** S300 300dpi USB *************/ +/*************** S300/S1300/S1300i 300dpi USB *************/ +/* 1b d1 (set window) before coarse cal (read 1 line of 0x63c0 bytes) */ /* 1b d1 (set window) before coarse cal (read 1 line of 0x63c0 bytes) */ static unsigned char setWindowCoarseCal_S300_300_U[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x01, 0x2c, 0x01, 0x2c, 0x00, 0x00, @@ -456,4 +481,229 @@ static unsigned char setWindowScan_S300_300_U[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -/*************** S300 600dpi USB is same as AC power *************/ +/*************** S300/S1300/S1300i USB is same as AC power *************/ + +/*************** S1300i 150dpi *************/ +/* 1b d1 (set window) before coarse cal (read 1 line of 0x5e24 bytes) */ +static unsigned char setWindowCoarseCal_S1300i_150[] = { +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x01, 0x2c, 0x01, 0x2c, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0xa0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, +0x00, 0x05, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x96, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; +/* 1b d1 (set window) before fine cal (read 16 lines of 0x5e24 bytes) */ +static unsigned char setWindowFineCal_S1300i_150[] = { +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x01, 0x2c, 0x03, 0x20, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0xa0, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, +0x00, 0x05, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x80, 0x80, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x96, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; +/* 1b d1 (set window) before gain/offset tables (write 1 line of 0xbc40 bytes) */ +static unsigned char setWindowSendCal_S1300i_150[] = { +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x01, 0x2c, 0x03, 0x20, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x60, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, +0x00, 0x05, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x96, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; +/* 1b c3 (gain?) command header */ +static unsigned char sendCal1Header_S1300i_150[] = { /* plus 0xc780 data bytes */ +0xc4, 0x06, 0xc4, 0x06, 0xc4, 0x06, 0xc4, 0x06, 0xc4, 0x06, 0xc4, 0x06, 0x00, 0x04 +}; +/* 1b c4 (offset?) command header */ +static unsigned char sendCal2Header_S1300i_150[] = { /* plus 0xc780 data bytes */ +0xd7, 0x3b, 0xd7, 0x3b, 0xd7, 0x3b, 0x07 +}; +/* 1b d1 (set window) before scan */ +static unsigned char setWindowScan_S1300i_150[] = { +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x96, 0x00, 0x96, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x50, 0x00, 0x00, 0x06, 0xe2, 0x00, 0x00, +0x00, 0x05, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x80, 0x80, 0x01, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +/*************** S1300i 225dpi *************/ +/* 1b d1 (set window) before coarse cal (read 1 line of 0x63c0 bytes) */ +static unsigned char setWindowCoarseCal_S1300i_225[] = { +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x01, 0x2c, 0x01, 0x2c, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0xc0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, +0x00, 0x05, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe1, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; +/* 1b d1 (set window) before fine cal (read 16 lines of 0x63c0 bytes) */ +static unsigned char setWindowFineCal_S1300i_225[] = { +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x01, 0x2c, 0x03, 0x20, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0xc0, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, +0x00, 0x05, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x80, 0x80, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe1, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; +/* 1b d1 (set window) before gain/offset tables (write 1 line of 0xc780 bytes) */ +static unsigned char setWindowSendCal_S1300i_225[] = { +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x01, 0x2c, 0x03, 0x20, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xa0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, +0x00, 0x05, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe1, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; +/* 1b c3 (gain?) command header */ +static unsigned char sendCal1Header_S1300i_225[] = { /* plus 0xc780 data bytes */ +0x2f, 0x07, 0x2f, 0x07, 0x2f, 0x07, 0x2f, 0x07, 0x2f, 0x07, 0x2f, 0x07, 0x00, 0x04 +}; +/* 1b c4 (offset?) command header */ +static unsigned char sendCal2Header_S1300i_225[] = { /* plus 0xc780 data bytes */ +0xa5, 0x3b, 0xa5, 0x3b, 0xa5, 0x3b, 0x07 +}; +/* 1b d1 (set window) before scan */ +static unsigned char setWindowScan_S1300i_225[] = { +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0xe1, 0x00, 0xc8, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x0c, 0x0c, 0x00, 0x00, +0x00, 0x05, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x80, 0x80, 0x01, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +/*************** S1300i 300dpi *************/ +/* 1b d1 (set window) before coarse cal (read 1 line of 0x5ee0 bytes) */ +static unsigned char setWindowCoarseCal_S1300i_300[] = { +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x01, 0x2c, 0x01, 0x2c, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0xc0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, +0x00, 0x05, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x01, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; +/* 1b d1 (set window) before fine cal (read 16 lines of 0x5ee0 bytes) */ +static unsigned char setWindowFineCal_S1300i_300[] = { +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x01, 0x2c, 0x03, 0x20, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0xc0, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, +0x00, 0x05, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x80, 0x80, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x01, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; +/* 1b d1 (set window) before gain/offset tables (write 1 line of 0xbdc0 bytes) */ +static unsigned char setWindowSendCal_S1300i_300[] = { +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x01, 0x2c, 0x03, 0x20, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xa0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, +0x00, 0x05, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x01, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; +/* 1b c3 (gain?) command header */ +static unsigned char sendCal1Header_S1300i_300[] = { /* plus 0xc000 data bytes */ +0xdd, 0x06, 0xdd, 0x06, 0xdd, 0x06, 0xdd, 0x06, 0xdd, 0x06, 0xdd, 0x06, 0x00, 0x04 +}; +/* 1b c4 (offset?) command header */ +static unsigned char sendCal2Header_S1300i_300[] = { /* plus 0xc000 data bytes */ +0x75, 0x3c, 0x75, 0x3c, 0x75, 0x3c, 0x07 +}; +/* 1b d1 (set window) before scan */ +static unsigned char setWindowScan_S1300i_300[] = { +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x01, 0x2c, 0x01, 0x2c, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0xc0, 0x00, 0x00, 0x0d, 0xc4, 0x00, 0x00, +0x00, 0x05, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x80, 0x80, 0x01, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +/*************** S1300i 600dpi AC power is same as S300 *************/ +/*************** except the calibration headers *************/ + +/* 1b c3 (gain?) command header */ +static unsigned char sendCal1Header_S1300i_USB[] = { +0x4d, 0x06, 0x4d, 0x06, 0x4d, 0x06, 0x4d, 0x06, 0x4d, 0x06, 0x4d, 0x06, 0x00, 0x04 +}; +/* 1b c4 (offset?) command header */ +static unsigned char sendCal2Header_S1300i_USB[] = { +0x8f, 0x40, 0x8f, 0x40, 0x8f, 0x40, 0x07 +}; + +/*************** S1300i all resolutions USB power is same as S300 *************/ + +/*************** S1100 300dpi USB *************/ +/* 1b d1 (set window) before coarse cal (read 1 line of 0x45a0 bytes) */ +static unsigned char setWindowCoarseCal_S1100_300_U[] = { +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x01, 0x2c, 0x01, 0x2c, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x58, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, +0x00, 0x05, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x01, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; +/* 1b d1 (set window) before fine cal (read 16 lines of 0x45a0 bytes) */ +static unsigned char setWindowFineCal_S1100_300_U[] = { +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x01, 0x2c, 0x03, 0x20, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x58, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, +0x00, 0x05, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x80, 0x80, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x01, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; +/* 1b d1 (set window) before gain/offset tables (write 1 line of 0x45a0 bytes) */ +static unsigned char setWindowSendCal_S1100_300_U[] = { +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x01, 0x2c, 0x01, 0x2c, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0xd0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, +0x00, 0x05, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x01, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; +/* 1b c3 (gain?) command header */ +static unsigned char sendCal1Header_S1100_300_U[] = { /* plus 0x45a0 data bytes */ +0x1e, 0x10, 0x1e, 0x10, 0x1e, 0x10, 0x1e, 0x10, 0x1e, 0x10, 0x1e, 0x10, 0x00, 0x03 +}; +/* 1b c4 (offset?) command header */ +static unsigned char sendCal2Header_S1100_300_U[] = { /* plus 0x45a0 data bytes */ +0x63, 0x86, 0x63, 0x86, 0x63, 0x86, 0x07 +}; +/* 1b d1 (set window) before scan */ +static unsigned char setWindowScan_S1100_300_U[] = { +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x01, 0x2c, 0x01, 0x2c, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x58, 0x00, 0x00, 0x1b, 0xe1, 0x00, 0x00, +0x00, 0x05, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x80, 0x80, 0x01, 0x3a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +/*************** S1100 600dpi USB *************/ +/* 1b d1 (set window) before coarse cal (read 1 line of 0x3e20 bytes) */ +static unsigned char setWindowCoarseCal_S1100_600_U[] = { +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x02, 0x58, 0x02, 0x58, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0xf0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, +0x00, 0x05, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x58, 0x02, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; +/* 1b d1 (set window) before fine cal (read 16 lines of 0x3e20 bytes) */ +static unsigned char setWindowFineCal_S1100_600_U[] = { +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x02, 0x58, 0x03, 0x20, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0xf0, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, +0x00, 0x05, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x80, 0x80, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x58, 0x02, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; +/* 1b d1 (set window) before gain/offset tables (write 1 line of 0x7c40 bytes) */ +static unsigned char setWindowSendCal_S1100_600_U[] = { +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x02, 0x58, 0x02, 0x58, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, +0x00, 0x05, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x58, 0x02, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; +/* 1b c3 (gain?) command header */ +static unsigned char sendCal1Header_S1100_600_U[] = { /* plus 0x7c40 data bytes */ +0xff, 0x11, 0xff, 0x11, 0xff, 0x11, 0xff, 0x11, 0xff, 0x11, 0xff, 0x11, 0x00, 0x03 +}; +/* 1b c4 (offset?) command header */ +static unsigned char sendCal2Header_S1100_600_U[] = { /* plus 0x7c40 data bytes */ +0x4b, 0x81, 0x4b, 0x81, 0x4b, 0x81, 0x07 +}; +/* 1b d1 (set window) before scan */ +static unsigned char setWindowScan_S1100_600_U[] = { +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x02, 0x58, 0x02, 0x58, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0xf0, 0x00, 0x00, 0x37, 0xbf, 0x00, 0x00, +0x00, 0x05, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x80, 0x80, 0x01, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + diff --git a/backend/epjitsu.c b/backend/epjitsu.c index 3e102da..7d987dc 100644 --- a/backend/epjitsu.c +++ b/backend/epjitsu.c @@ -123,9 +123,34 @@ - dont export private symbols v19 2009-08-31, RG - rewritten calibration routines - v20 2010-02-09, MAN (SANE 1.0.21 & 1.0.22) + v20 2010-02-09, MAN (SANE 1.0.21 to 1.0.24) - cleanup #include lines & copyright - add S1300 + v21 2011-04-15, MAN + - unreleased attempt at S1100 support + v22 2014-05-15, MAN/Hiroshi Miura + - port some S1100 changes from v21 + - add paper size support + v23 2014-05-20, MAN + - add S1300i support + - fix buffer overruns in read_from_scanner + - set default page width + - simplified the 225x200 resolution code + v24 2014-06-01, MAN + - enable fine calibration for S1300i 225 & 300 dpi, and S300 150 dpi + v25 2014-06-04, MAN + - initial support for fi-65F + - initial support for S1100 + v26 2014-06-28, MAN + - add resolution scaling + - fix 150 dpi settings for fi-60F and fi-65F + - make adf_height_padding variable + - make white_factor variable + v27 2015-01-24, MAN + - don't override br_x and br_y + - call change_params after changing page_width + v28 2015-03-23, MAN + - call get_hardware_status before starting scan SANE FLOW DIAGRAM @@ -174,7 +199,7 @@ #include "epjitsu-cmd.h" #define DEBUG 1 -#define BUILD 20 +#define BUILD 28 #ifndef MAX3 #define MAX3(a,b,c) ((a) > (b) ? ((a) > (c) ? a : c) : ((b) > (c) ? b : c)) @@ -197,7 +222,6 @@ unsigned char global_firmware_filename[PATH_MAX]; static int coarse_gain_min[3] = { 88, 88, 88 }; /* front, back, FI-60F 3rd plane */ static int coarse_gain_max[3] = { 92, 92, 92 }; static int fine_gain_target[3] = {185, 150, 170}; /* front, back, FI-60F is this ok? */ -static float white_factor[3] = {1.0, 0.93, 0.98}; /* Blue, Red, Green */ /* ------------------------------------------------------------------------- */ #define STRING_FLATBED SANE_I18N("Flatbed") @@ -458,7 +482,39 @@ attach_one (const char *name) DBG (15, "attach_one: Found %s scanner %s at %s\n", s->sane.vendor, s->sane.model, s->sane.name); - if (strstr (s->sane.model, "S300") || strstr (s->sane.model, "S1300")){ + if (strstr (s->sane.model, "S1300i")){ + unsigned char stat; + + DBG (15, "attach_one: Found S1300i\n"); + + stat = get_stat(s); + if(stat & 0x01){ + DBG (5, "attach_one: on USB power?\n"); + s->usb_power=1; + } + + s->model = MODEL_S1300i; + + s->has_adf = 1; + s->has_adf_duplex = 1; + s->min_res = 50; + s->max_res = 600; + s->adf_height_padding = 600; + /* Blue, Red, Green */ + s->white_factor[0] = 1.0; + s->white_factor[1] = 0.93; + s->white_factor[2] = 0.98; + + s->source = SOURCE_ADF_FRONT; + s->mode = MODE_LINEART; + s->resolution = 300; + s->page_height = 11.5 * 1200; + s->page_width = 8.5 * 1200; + + s->threshold = 120; + s->threshold_curve = 55; + } + else if (strstr (s->sane.model, "S300") || strstr (s->sane.model, "S1300")){ unsigned char stat; DBG (15, "attach_one: Found S300/S1300\n"); @@ -472,46 +528,93 @@ attach_one (const char *name) s->model = MODEL_S300; s->has_adf = 1; - s->x_res_150 = 1; - s->x_res_225 = 1; - s->x_res_300 = 1; - s->x_res_600 = 1; - s->y_res_150 = 1; - s->y_res_225 = 1; - s->y_res_300 = 1; - s->y_res_600 = 1; + s->has_adf_duplex = 1; + s->min_res = 50; + s->max_res = 600; + s->adf_height_padding = 600; + /* Blue, Red, Green */ + s->white_factor[0] = 1.0; + s->white_factor[1] = 0.93; + s->white_factor[2] = 0.98; s->source = SOURCE_ADF_FRONT; - s->mode = MODE_LINEART; - s->resolution_x = 300; + s->mode = MODE_LINEART; + s->resolution = 300; s->page_height = 11.5 * 1200; + s->page_width = 8.5 * 1200; s->threshold = 120; s->threshold_curve = 55; } + else if (strstr (s->sane.model, "S1100")){ + DBG (15, "attach_one: Found S1100\n"); + s->model = MODEL_S1100; + + s->usb_power = 1; + s->has_adf = 1; + s->has_adf_duplex = 0; + s->min_res = 50; + s->max_res = 600; + s->adf_height_padding = 450; + /* Blue, Red, Green */ + s->white_factor[0] = 0.95; + s->white_factor[1] = 1.0; + s->white_factor[2] = 1.0; + + s->source = SOURCE_ADF_FRONT; + s->mode = MODE_LINEART; + s->resolution = 300; + s->page_height = 11.5 * 1200; + s->page_width = 8.5 * 1200; + s->threshold = 120; + s->threshold_curve = 55; + } else if (strstr (s->sane.model, "fi-60F")){ DBG (15, "attach_one: Found fi-60F\n"); s->model = MODEL_FI60F; s->has_fb = 1; - s->x_res_150 = 0; - s->x_res_300 = 1; - s->x_res_600 = 1; - s->y_res_150 = 0; - s->y_res_300 = 1; - s->y_res_600 = 1; + s->min_res = 50; + s->max_res = 600; + /* Blue, Red, Green */ + s->white_factor[0] = 1.0; + s->white_factor[1] = 0.93; + s->white_factor[2] = 0.98; s->source = SOURCE_FLATBED; - s->mode = MODE_COLOR; - s->resolution_x = 300; + s->mode = MODE_COLOR; + s->resolution = 300; s->page_height = 5.83 * 1200; + s->page_width = 4.1 * 1200; s->threshold = 120; s->threshold_curve = 55; } + else if (strstr (s->sane.model, "fi-65F")){ + DBG (15, "attach_one: Found fi-65F\n"); + + s->model = MODEL_FI65F; + + s->has_fb = 1; + s->min_res = 50; + s->max_res = 600; + /* Blue, Red, Green */ + s->white_factor[0] = 1.0; + s->white_factor[1] = 0.93; + s->white_factor[2] = 0.98; + + s->source = SOURCE_FLATBED; + s->mode = MODE_COLOR; + s->resolution = 300; + s->page_height = 5.83 * 1200; + s->page_width = 4.1 * 1200; + + s->threshold = 120; + s->threshold_curve = 55; + } else{ DBG (15, "attach_one: Found other\n"); } @@ -615,6 +718,7 @@ load_fw (struct scanner *s) return SANE_STATUS_NO_DOCS; } + /* skip first 256 (=0x100) bytes */ if(lseek(file,0x100,SEEK_SET) != 0x100){ DBG (5, "load_fw: failed to lseek file %s\n",global_firmware_filename); close(file); @@ -761,7 +865,7 @@ load_fw (struct scanner *s) } /* - * try to load fw into scanner + * get status from scanner */ static unsigned char get_stat(struct scanner *s) @@ -795,6 +899,10 @@ get_stat(struct scanner *s) return stat[0]; } +/* + * get scanner identification + */ + static SANE_Status get_ident(struct scanner *s) { @@ -946,8 +1054,10 @@ sane_get_option_descriptor (SANE_Handle handle, SANE_Int option) } if(s->has_adf){ s->source_list[i++]=STRING_ADFFRONT; - s->source_list[i++]=STRING_ADFBACK; - s->source_list[i++]=STRING_ADFDUPLEX; + if(s->has_adf_duplex){ + s->source_list[i++]=STRING_ADFBACK; + s->source_list[i++]=STRING_ADFDUPLEX; + } } s->source_list[i]=NULL; @@ -983,33 +1093,19 @@ sane_get_option_descriptor (SANE_Handle handle, SANE_Int option) } } - else if(option==OPT_X_RES){ - i=0; - if(s->x_res_150){ - s->x_res_list[++i] = 150; - } - if(s->x_res_225){ - s->x_res_list[++i] = 225; - } - if(s->x_res_300){ - s->x_res_list[++i] = 300; - } - if(s->x_res_600){ - s->x_res_list[++i] = 600; - } - s->x_res_list[0] = i; - + else if(option==OPT_RES){ opt->name = SANE_NAME_SCAN_RESOLUTION; - opt->title = SANE_TITLE_SCAN_X_RESOLUTION; - opt->desc = SANE_DESC_SCAN_X_RESOLUTION; + opt->title = SANE_TITLE_SCAN_RESOLUTION; + opt->desc = SANE_DESC_SCAN_RESOLUTION; opt->type = SANE_TYPE_INT; opt->unit = SANE_UNIT_DPI; - if(i > 1){ - opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT; - } + opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT; - opt->constraint_type = SANE_CONSTRAINT_WORD_LIST; - opt->constraint.word_list = s->x_res_list; + s->res_range.min = s->min_res; + s->res_range.max = s->max_res; + s->res_range.quant = 1; + opt->constraint_type = SANE_CONSTRAINT_RANGE; + opt->constraint.range = &s->res_range; } /* "Geometry" group ---------------------------------------------------- */ @@ -1056,7 +1152,6 @@ sane_get_option_descriptor (SANE_Handle handle, SANE_Int option) opt->constraint_type = SANE_CONSTRAINT_RANGE; opt->constraint.range = &(s->tl_y_range); opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT; - opt->cap = SANE_CAP_INACTIVE; } /* bottom-right x */ @@ -1122,7 +1217,6 @@ sane_get_option_descriptor (SANE_Handle handle, SANE_Int option) else{ opt->cap = SANE_CAP_INACTIVE; } - opt->cap = SANE_CAP_INACTIVE; } /* page height */ @@ -1421,8 +1515,8 @@ sane_control_option (SANE_Handle handle, SANE_Int option, } return SANE_STATUS_GOOD; - case OPT_X_RES: - *val_p = s->resolution_x; + case OPT_RES: + *val_p = s->resolution; return SANE_STATUS_GOOD; case OPT_TL_X: @@ -1569,17 +1663,17 @@ sane_control_option (SANE_Handle handle, SANE_Int option, s->mode = tmp; *info |= SANE_INFO_RELOAD_PARAMS | SANE_INFO_RELOAD_OPTIONS; - return change_params(s); + return SANE_STATUS_GOOD; - case OPT_X_RES: + case OPT_RES: - if (s->resolution_x == val_c) + if (s->resolution == val_c) return SANE_STATUS_GOOD; - s->resolution_x = val_c; + s->resolution = val_c; *info |= SANE_INFO_RELOAD_PARAMS | SANE_INFO_RELOAD_OPTIONS; - return change_params(s); + return SANE_STATUS_GOOD; /* Geometry Group */ case OPT_TL_X: @@ -1598,7 +1692,7 @@ sane_control_option (SANE_Handle handle, SANE_Int option, s->tl_y = FIXED_MM_TO_SCANNER_UNIT(val_c); *info |= SANE_INFO_RELOAD_PARAMS | SANE_INFO_RELOAD_OPTIONS; - return SANE_STATUS_GOOD; + return change_params(s); case OPT_BR_X: if (s->br_x == FIXED_MM_TO_SCANNER_UNIT(val_c)) @@ -1623,8 +1717,8 @@ sane_control_option (SANE_Handle handle, SANE_Int option, return SANE_STATUS_GOOD; s->page_width = FIXED_MM_TO_SCANNER_UNIT(val_c); - *info |= SANE_INFO_RELOAD_OPTIONS; - return SANE_STATUS_GOOD; + *info |= SANE_INFO_RELOAD_PARAMS | SANE_INFO_RELOAD_OPTIONS; + return change_params(s); case OPT_PAGE_HEIGHT: if (s->page_height == FIXED_MM_TO_SCANNER_UNIT(val_c)) @@ -1685,16 +1779,15 @@ struct model_res { int max_y; int min_y; - int act_width; /* total data width output, in pixels per side (always 3 sides) */ - int req_width; /* stride in pixels per side between color planes (always 3 sides) */ - int head_width; - int pad_width; + int line_stride; /* byte width of 1 raw side, with padding */ + int plane_stride; /* byte width of 1 raw color plane, with padding */ + int plane_width; /* byte width of 1 raw color plane, without padding */ int block_height; - int cal_width; - int cal_headwidth; - int cal_reqwidth; + int cal_line_stride; + int cal_plane_stride; + int cal_plane_width; unsigned char * sw_coarsecal; unsigned char * sw_finecal; @@ -1709,67 +1802,141 @@ struct model_res { static struct model_res settings[] = { /*S300 AC*/ -/* model xres yres u mxx mnx mxy mny actw reqw hedw padw bh calw cal_hedw cal_reqw */ - { MODEL_S300, 150, 150, 0, 1296, 32, 2662, 32, 4256, 1480, 1296, 184, 41, 8512, 2592, 2960, +/* model xres yres u mxx mnx mxy mny lin_s pln_s pln_w bh cls cps cpw */ + { MODEL_S300, 150, 150, 0, 1296, 32, 2662, 32, 4256*3, 1480*3, 1296, 41, 8512*3, 2960*3, 2592, setWindowCoarseCal_S300_150, setWindowFineCal_S300_150, setWindowSendCal_S300_150, sendCal1Header_S300_150, sendCal2Header_S300_150, setWindowScan_S300_150 }, - { MODEL_S300, 225, 200, 0, 1944, 32, 3993, 32, 6144, 2100, 1944, 156, 28, 8192, 2592, 2800, + { MODEL_S300, 225, 200, 0, 1944, 32, 3993, 32, 6144*3, 2100*3, 1944, 28, 8192*3, 2800*3, 2592, setWindowCoarseCal_S300_225, setWindowFineCal_S300_225, setWindowSendCal_S300_225, sendCal1Header_S300_225, sendCal2Header_S300_225, setWindowScan_S300_225 }, - { MODEL_S300, 300, 300, 0, 2592, 32, 5324, 32, 8192, 2800, 2592, 208, 21, 8192, 2592, 2800, + { MODEL_S300, 300, 300, 0, 2592, 32, 5324, 32, 8192*3, 2800*3, 2592, 21, 8192*3, 2800*3, 2592, setWindowCoarseCal_S300_300, setWindowFineCal_S300_300, setWindowSendCal_S300_300, sendCal1Header_S300_300, sendCal2Header_S300_300, setWindowScan_S300_300 }, - { MODEL_S300, 600, 600, 0, 5184, 32, 10648, 32, 16064, 5440, 5184, 256, 10, 16064, 5184, 5440, + { MODEL_S300, 600, 600, 0, 5184, 32, 10648, 32, 16064*3, 5440*3, 5184, 10, 16064*3, 5440*3, 5184, setWindowCoarseCal_S300_600, setWindowFineCal_S300_600, setWindowSendCal_S300_600, sendCal1Header_S300_600, sendCal2Header_S300_600, setWindowScan_S300_600 }, /*S300 USB*/ -/* model xres yres u mxx mnx mxy mny actw reqw hedw padw bh calw cal_hedw cal_reqw */ - { MODEL_S300, 150, 150, 1, 1296, 32, 2662, 32, 7216, 2960, 1296, 1664, 24, 14432, 2592, 5920, +/* model xres yres u mxx mnx mxy mny lin_s pln_s pln_w bh cls cps cpw */ + { MODEL_S300, 150, 150, 1, 1296, 32, 2662, 32, 7216*3, 2960*3, 1296, 24, 14432*3, 5920*3, 2592, setWindowCoarseCal_S300_150_U, setWindowFineCal_S300_150_U, setWindowSendCal_S300_150_U, sendCal1Header_S300_150_U, sendCal2Header_S300_150_U, setWindowScan_S300_150_U }, - { MODEL_S300, 225, 200, 1, 1944, 32, 3993, 32, 10584, 4320, 1944, 2376, 16, 14112, 2592, 5760, + { MODEL_S300, 225, 200, 1, 1944, 32, 3993, 32, 10584*3, 4320*3, 1944, 16, 14112*3, 5760*3, 2592, setWindowCoarseCal_S300_225_U, setWindowFineCal_S300_225_U, setWindowSendCal_S300_225_U, sendCal1Header_S300_225_U, sendCal2Header_S300_225_U, setWindowScan_S300_225_U }, - { MODEL_S300, 300, 300, 1, 2592, 32, 5324, 32, 15872, 6640, 2592, 4048, 11, 15872, 2592, 6640, + { MODEL_S300, 300, 300, 1, 2592, 32, 5324, 32, 15872*3, 6640*3, 2592, 11, 15872*3, 6640*3, 2592, setWindowCoarseCal_S300_300_U, setWindowFineCal_S300_300_U, setWindowSendCal_S300_300_U, sendCal1Header_S300_300_U, sendCal2Header_S300_300_U, setWindowScan_S300_300_U }, - { MODEL_S300, 600, 600, 1, 5184, 32, 10648, 32, 16064, 5440, 5184, 256, 10, 16064, 5184, 5440, + { MODEL_S300, 600, 600, 1, 5184, 32, 10648, 32, 16064*3, 5440*3, 5184, 10, 16064*3, 5440*3, 5184, + setWindowCoarseCal_S300_600, setWindowFineCal_S300_600, + setWindowSendCal_S300_600, sendCal1Header_S300_600, + sendCal2Header_S300_600, setWindowScan_S300_600 }, + + /*S1300i AC*/ +/* model xres yres u mxx mnx mxy mny lin_s pln_s pln_w bh cls cps cpw */ + { MODEL_S1300i, 150, 150, 0, 1296, 32, 2662, 32, 4016*3, 1360*3, 1296, 43, 8032*3, 2720*3, 2592, + setWindowCoarseCal_S1300i_150, setWindowFineCal_S1300i_150, + setWindowSendCal_S1300i_150, sendCal1Header_S1300i_150, + sendCal2Header_S1300i_150, setWindowScan_S1300i_150 }, + + { MODEL_S1300i, 225, 200, 0, 1944, 32, 3993, 32, 6072*3, 2063*3, 1944, 28, 8096*3, 2752*3, 2592, + setWindowCoarseCal_S1300i_225, setWindowFineCal_S1300i_225, + setWindowSendCal_S1300i_225, sendCal1Header_S1300i_225, + sendCal2Header_S1300i_225, setWindowScan_S1300i_225 }, + + { MODEL_S1300i, 300, 300, 0, 2592, 32, 5324, 32, 8096*3, 2751*3, 2592, 21, 8096*3, 2752*3, 2592, + setWindowCoarseCal_S1300i_300, setWindowFineCal_S1300i_300, + setWindowSendCal_S1300i_300, sendCal1Header_S1300i_300, + sendCal2Header_S1300i_300, setWindowScan_S1300i_300 }, + + /*NOTE: S1300i uses S300 data blocks for remainder*/ + { MODEL_S1300i, 600, 600, 0, 5184, 32, 10648, 32, 16064*3, 5440*3, 5184, 10, 16064*3, 5440*3, 5184, setWindowCoarseCal_S300_600, setWindowFineCal_S300_600, setWindowSendCal_S300_600, sendCal1Header_S300_600, sendCal2Header_S300_600, setWindowScan_S300_600 }, + /*S1300i USB*/ +/* model xres yres u mxx mnx mxy mny lin_s pln_s pln_w bh cls cps cpw */ + { MODEL_S1300i, 150, 150, 1, 1296, 32, 2662, 32, 7216*3, 2960*3, 1296, 24, 14432*3, 5920*3, 2592, + setWindowCoarseCal_S300_150_U, setWindowFineCal_S300_150_U, + setWindowSendCal_S300_150_U, sendCal1Header_S1300i_USB, + sendCal2Header_S1300i_USB, setWindowScan_S300_150_U }, + + { MODEL_S1300i, 225, 200, 1, 1944, 32, 3993, 32, 10584*3, 4320*3, 1944, 16, 14112*3, 5760*3, 2592, + setWindowCoarseCal_S300_225_U, setWindowFineCal_S300_225_U, + setWindowSendCal_S300_225_U, sendCal1Header_S1300i_USB, + sendCal2Header_S1300i_USB, setWindowScan_S300_225_U }, + + { MODEL_S1300i, 300, 300, 1, 2592, 32, 5324, 32, 15872*3, 6640*3, 2592, 11, 15872*3, 6640*3, 2592, + setWindowCoarseCal_S300_300_U, setWindowFineCal_S300_300_U, + setWindowSendCal_S300_300_U, sendCal1Header_S1300i_USB, + sendCal2Header_S1300i_USB, setWindowScan_S300_300_U }, + + { MODEL_S1300i, 600, 600, 1, 5184, 32, 10648, 32, 16064*3, 5440*3, 5184, 10, 16064*3, 5440*3, 5184, + setWindowCoarseCal_S300_600, setWindowFineCal_S300_600, + setWindowSendCal_S300_600, sendCal1Header_S1300i_USB, + sendCal2Header_S1300i_USB, setWindowScan_S300_600 }, + /*fi-60F*/ -/* model xres yres u mxx mnx mxy mny actw reqw hedw padw bh calw cal_hedw cal_reqw */ - { MODEL_FI60F, 150, 150, 0, 648, 32, 875, 32, 1480, 632, 216, 416, 41, 1480, 216, 632, +/* model xres yres u mxx mnx mxy mny lin_s pln_s pln_w bh cls cps cpw */ + { MODEL_FI60F, 300, 150, 0, 1296, 32, 875, 32, 2400*3, 958*3, 432, 72, 2400*3, 958*3, 432, setWindowCoarseCal_FI60F_150, setWindowFineCal_FI60F_150, setWindowSendCal_FI60F_150, sendCal1Header_FI60F_150, sendCal2Header_FI60F_150, setWindowScan_FI60F_150 }, - { MODEL_FI60F, 300, 300, 0, 1296, 32, 1749, 32, 2400, 958, 432, 526, 72, 2400, 432, 958, + { MODEL_FI60F, 300, 300, 0, 1296, 32, 1749, 32, 2400*3, 958*3, 432, 72, 2400*3, 958*3, 432, setWindowCoarseCal_FI60F_300, setWindowFineCal_FI60F_300, setWindowSendCal_FI60F_300, sendCal1Header_FI60F_300, sendCal2Header_FI60F_300, setWindowScan_FI60F_300 }, - { MODEL_FI60F, 600, 600, 0, 2592, 32, 3498, 32, 2848, 978, 864, 114, 61, 2848, 864, 978, + { MODEL_FI60F, 600, 600, 0, 2592, 32, 3498, 32, 2848*3, 978*3, 864, 61, 2848*3, 978*3, 864, setWindowCoarseCal_FI60F_600, setWindowFineCal_FI60F_600, setWindowSendCal_FI60F_600, sendCal1Header_FI60F_600, sendCal2Header_FI60F_600, setWindowScan_FI60F_600 }, - { MODEL_NONE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + /*fi-65F*/ +/* model xres yres u mxx mnx mxy mny lin_s pln_s pln_w bh cls cps cpw */ + { MODEL_FI65F, 300, 150, 0, 1296, 32, 875, 32, 2400*3, 958*3, 432, 72, 2400*3, 958*3, 432, + setWindowCoarseCal_FI60F_150, setWindowFineCal_FI60F_150, + setWindowSendCal_FI60F_150, sendCal1Header_FI60F_150, + sendCal2Header_FI60F_150, setWindowScan_FI60F_150 }, + + { MODEL_FI65F, 300, 300, 0, 1296, 32, 1749, 32, 2400*3, 958*3, 432, 72, 2400*3, 958*3, 432, + setWindowCoarseCal_FI60F_300, setWindowFineCal_FI60F_300, + setWindowSendCal_FI60F_300, sendCal1Header_FI60F_300, + sendCal2Header_FI60F_300, setWindowScan_FI60F_300 }, + + { MODEL_FI65F, 600, 600, 0, 2592, 32, 3498, 32, 2848*3, 978*3, 864, 61, 2848*3, 978*3, 864, + setWindowCoarseCal_FI60F_600, setWindowFineCal_FI60F_600, + setWindowSendCal_FI60F_600, sendCal1Header_FI60F_600, + sendCal2Header_FI60F_600, setWindowScan_FI60F_600 }, + + /*S1100 USB*/ +/* model xres yres u mxx mnx mxy mny lin_s pln_s pln_w bh cls cps cpw */ + { MODEL_S1100, 300, 300, 1, 2592, 32, 5324, 32, 8912, 3160, 2592, 58, 8912, 3160, 2592, + setWindowCoarseCal_S1100_300_U, setWindowFineCal_S1100_300_U, + setWindowSendCal_S1100_300_U, sendCal1Header_S1100_300_U, + sendCal2Header_S1100_300_U, setWindowScan_S1100_300_U }, + + { MODEL_S1100, 600, 600, 1, 5184, 32, 10648, 32, 15904, 5360, 5184, 32, 15904, 5360, 5184, + setWindowCoarseCal_S1100_600_U, setWindowFineCal_S1100_600_U, + setWindowSendCal_S1100_600_U, sendCal1Header_S1100_600_U, + sendCal2Header_S1100_600_U, setWindowScan_S1100_600_U }, + + { MODEL_NONE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }, }; @@ -1789,86 +1956,126 @@ change_params(struct scanner *s) do { if(settings[i].model == s->model - && settings[i].x_res == s->resolution_x - && settings[i].usb_power == s->usb_power){ - - /*pull in closest y resolution*/ - s->resolution_y = settings[i].y_res; + && settings[i].x_res >= s->resolution + && settings[i].y_res >= s->resolution + && settings[i].usb_power == s->usb_power + ){ + break; + } + i++; + } while (settings[i].model); - /*1200 dpi*/ - s->max_x = settings[i].max_x * 1200/s->resolution_x; - s->min_x = settings[i].min_x * 1200/s->resolution_x; - s->max_y = settings[i].max_y * 1200/s->resolution_y; - s->min_y = settings[i].min_y * 1200/s->resolution_y; + if (!settings[i].model){ + return SANE_STATUS_INVAL; + } - s->page_width = s->max_x; - s->br_x = s->max_x; - s->br_y = s->max_y; + /*1200 dpi*/ + s->max_x = PIX_TO_SCANNER_UNIT( settings[i].max_x, settings[i].x_res ); + s->min_x = PIX_TO_SCANNER_UNIT( settings[i].min_x, settings[i].x_res ); + s->max_y = PIX_TO_SCANNER_UNIT( settings[i].max_y, settings[i].y_res ); + s->min_y = PIX_TO_SCANNER_UNIT( settings[i].min_y, settings[i].y_res ); - /*current dpi*/ - s->setWindowCoarseCal = settings[i].sw_coarsecal; - s->setWindowCoarseCalLen = SET_WINDOW_LEN; + /*current dpi*/ + s->setWindowCoarseCal = settings[i].sw_coarsecal; + s->setWindowCoarseCalLen = SET_WINDOW_LEN; - s->setWindowFineCal = settings[i].sw_finecal; - s->setWindowFineCalLen = SET_WINDOW_LEN; + s->setWindowFineCal = settings[i].sw_finecal; + s->setWindowFineCalLen = SET_WINDOW_LEN; - s->setWindowSendCal = settings[i].sw_sendcal; - s->setWindowSendCalLen = SET_WINDOW_LEN; + s->setWindowSendCal = settings[i].sw_sendcal; + s->setWindowSendCalLen = SET_WINDOW_LEN; - s->sendCal1Header = settings[i].head_cal1; - s->sendCal1HeaderLen = 14; + s->sendCal1Header = settings[i].head_cal1; + s->sendCal1HeaderLen = 14; - s->sendCal2Header = settings[i].head_cal2; - s->sendCal2HeaderLen = 7; + s->sendCal2Header = settings[i].head_cal2; + s->sendCal2HeaderLen = 7; - s->setWindowScan = settings[i].sw_scan; - s->setWindowScanLen = SET_WINDOW_LEN; + s->setWindowScan = settings[i].sw_scan; + s->setWindowScanLen = SET_WINDOW_LEN; - break; - } - i++; - } while (settings[i].model); - - if (!settings[i].model) - { - return SANE_STATUS_INVAL; - } - - if (s->model == MODEL_S300) + if (s->model == MODEL_S300 || s->model == MODEL_S1300i) { img_heads = 1; /* image width is the same as the plane width on the S300 */ img_pages = 2; } - else /* (s->model == MODEL_FI60F) */ + else if (s->model == MODEL_S1100) + { + img_heads = 1; /* image width is the same as the plane width on the S1000 */ + img_pages = 1; + } + else /* MODEL_FI60F or MODEL_FI65F */ { img_heads = 3; /* image width is 3* the plane width on the FI-60F */ img_pages = 1; } + + /* 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; + 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; + + if (s->page_height > 0) { + s->br_y = s->tl_y + s->page_height; + } + else { + s->br_y = s->max_y; + } + + /*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->tl_x = (s->max_x - s->page_width)/2; + s->br_x = (s->max_x + s->page_width)/2; - /* set up the transfer structs */ - s->cal_image.plane_width = settings[i].cal_headwidth; - s->cal_image.plane_stride = settings[i].cal_reqwidth * 3; - s->cal_image.line_stride = settings[i].cal_width * 3; + /*=============================================================*/ + /* set up the calibration structs */ + /* generally full width, short height, full resolution */ + s->cal_image.line_stride = settings[i].cal_line_stride; + s->cal_image.plane_stride = settings[i].cal_plane_stride; + s->cal_image.plane_width = settings[i].cal_plane_width; + s->cal_image.x_res = settings[i].x_res; + s->cal_image.y_res = settings[i].y_res; s->cal_image.raw_data = NULL; s->cal_image.image = NULL; - s->cal_data.plane_width = settings[i].cal_headwidth; /* width is the same, but there are 2 bytes per pixel component */ - s->cal_data.plane_stride = settings[i].cal_reqwidth * 6; - s->cal_data.line_stride = settings[i].cal_width * 6; + /* width is the same, but there are 2 bytes per pixel component */ + s->cal_data.line_stride = settings[i].cal_line_stride * 2; + s->cal_data.plane_stride = settings[i].cal_plane_stride * 2; + s->cal_data.plane_width = settings[i].cal_plane_width; + s->cal_data.x_res = settings[i].x_res; + s->cal_data.y_res = settings[i].y_res; s->cal_data.raw_data = NULL; s->cal_data.image = &s->sendcal; - s->block_xfr.plane_width = settings[i].head_width; - s->block_xfr.plane_stride = settings[i].req_width * 3; - s->block_xfr.line_stride = settings[i].act_width * 3; + /*=============================================================*/ + /* set up the input scan structs */ + s->block_xfr.line_stride = settings[i].line_stride; + s->block_xfr.plane_stride = settings[i].plane_stride; + s->block_xfr.plane_width = settings[i].plane_width; + s->block_xfr.x_res = settings[i].x_res; + s->block_xfr.y_res = settings[i].y_res; s->block_xfr.raw_data = NULL; s->block_xfr.image = &s->block_img; /* set up the block image used during scanning operation */ - width = s->block_xfr.plane_width * img_heads; + /* note that this is the same width/x_res as the final output image */ + /* but the height/y_res are the same as block_xfr */ + width = (s->block_xfr.plane_width*s->resolution/settings[i].x_res) * img_heads; s->block_img.width_pix = width; s->block_img.width_bytes = width * 3; s->block_img.height = settings[i].block_height; + s->block_img.x_res = s->resolution; + s->block_img.y_res = settings[i].y_res; s->block_img.pages = img_pages; s->block_img.buffer = NULL; @@ -1877,6 +2084,8 @@ change_params(struct scanner *s) s->coarsecal.width_pix = s->darkcal.width_pix = s->lightcal.width_pix = width; s->coarsecal.width_bytes = s->darkcal.width_bytes = s->lightcal.width_bytes = width * 3; s->coarsecal.height = 1; + s->coarsecal.x_res = s->darkcal.x_res = s->lightcal.x_res = settings[i].x_res; + s->coarsecal.y_res = s->darkcal.y_res = s->lightcal.y_res = settings[i].y_res; s->darkcal.height = s->lightcal.height = 16; s->coarsecal.pages = s->darkcal.pages = s->lightcal.pages = img_pages; s->coarsecal.buffer = s->darkcal.buffer = s->lightcal.buffer = NULL; @@ -1886,50 +2095,95 @@ change_params(struct scanner *s) s->sendcal.width_pix = width; s->sendcal.width_bytes = width * 6; /* 2 bytes of cal data per pixel component */ s->sendcal.height = 1; + s->sendcal.x_res = settings[i].x_res; + s->sendcal.y_res = settings[i].y_res; s->sendcal.pages = img_pages; s->sendcal.buffer = NULL; /* set up the fullscan parameters */ s->fullscan.width_bytes = s->block_xfr.line_stride; + s->fullscan.x_res = settings[i].x_res; + s->fullscan.y_res = settings[i].y_res; if(s->source == SOURCE_FLATBED || !s->page_height) { /* flatbed and adf in autodetect always ask for all*/ - s->fullscan.height = s->max_y * s->resolution_y / 1200; + s->fullscan.height = SCANNER_UNIT_TO_PIX(s->max_y, s->fullscan.y_res); } else { - /* adf with specified paper size requires padding (~1/2in) */ - s->fullscan.height = (s->page_height+600) * s->resolution_y / 1200; + /* adf with specified paper size requires padding on top of page_height (~1/2in) */ + s->fullscan.height = SCANNER_UNIT_TO_PIX((s->page_height + s->tl_y + s->adf_height_padding), s->fullscan.y_res); } - /* fill in front settings */ + /*=============================================================*/ + /* set up the output image structs */ + /* output image might be different from scan due to interpolation */ + s->front.x_res = s->resolution; + s->front.y_res = s->resolution; + if(s->source == SOURCE_FLATBED) + { + /* flatbed ignores the tly */ + s->front.height = SCANNER_UNIT_TO_PIX(s->max_y - s->tl_y, s->front.y_res); + } + else if(!s->page_height) + { + /* adf in autodetect always asks for all */ + s->front.height = SCANNER_UNIT_TO_PIX(s->max_y, s->front.y_res); + } + else + { + /* 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.x_start_offset = (s->block_xfr.image->width_pix - s->front.width_pix)/2; switch (s->mode) { case MODE_COLOR: s->front.width_bytes = s->front.width_pix*3; + s->front.x_offset_bytes = s->front.x_start_offset *3; break; case MODE_GRAYSCALE: s->front.width_bytes = s->front.width_pix; + s->front.x_offset_bytes = s->front.x_start_offset; break; default: /*binary*/ s->front.width_bytes = s->front.width_pix/8; + s->front.width_pix = s->front.width_bytes * 8; + /*s->page_width = PIX_TO_SCANNER_UNIT(s->front.width_pix, (img_heads * s->resolution_x));*/ + s->front.x_offset_bytes = s->front.x_start_offset/8; break; } - /*output image might be taller than scan due to interpolation*/ - s->front.height = s->fullscan.height * s->resolution_x / s->resolution_y; + + /* ADF front need to remove padding header */ + if (s->source != SOURCE_FLATBED) + { + s->front.y_skip_offset = SCANNER_UNIT_TO_PIX(s->tl_y+s->adf_height_padding, s->fullscan.y_res); + } + else + { + s->front.y_skip_offset = SCANNER_UNIT_TO_PIX(s->tl_y, s->fullscan.y_res); + } + s->front.pages = 1; s->front.buffer = NULL; /* back settings always same as front settings */ s->back.width_pix = s->front.width_pix; s->back.width_bytes = s->front.width_bytes; + s->back.x_res = s->front.x_res; + s->back.y_res = s->front.y_res; s->back.height = s->front.height; + s->back.x_start_offset = s->front.x_start_offset; + s->back.x_offset_bytes = s->front.x_offset_bytes; + s->back.y_skip_offset = SCANNER_UNIT_TO_PIX(s->tl_y, s->fullscan.y_res); s->back.pages = 1; s->back.buffer = NULL; /* dynamic threshold temp buffer, in gray */ s->dt.width_pix = s->front.width_pix; s->dt.width_bytes = s->front.width_pix; + s->dt.x_res = s->front.x_res; + s->dt.y_res = s->front.y_res; s->dt.height = 1; s->dt.pages = 1; s->dt.buffer = NULL; @@ -2117,10 +2371,13 @@ sane_start (SANE_Handle handle) s->side = !s->side; } + /* recent scanners need ghs called before scanning */ + ret = get_hardware_status(s); + /* ingest paper with adf */ if( s->source == SOURCE_ADF_BACK || s->source == SOURCE_ADF_FRONT || (s->source == SOURCE_ADF_DUPLEX && s->side == SIDE_FRONT) ){ - ret = ingest(s); + ret = object_position(s,EPJITSU_PAPER_INGEST); if (ret != SANE_STATUS_GOOD) { DBG (5, "sane_start: ERROR: failed to ingest\n"); sane_cancel((SANE_Handle)s); @@ -2222,6 +2479,9 @@ sane_start (SANE_Handle handle) s->pages[i].bytes_total = page_img->width_bytes * page_img->height; s->pages[i].bytes_scanned = 0; s->pages[i].bytes_read = 0; + s->pages[i].lines_rx = 0; + s->pages[i].lines_pass = 0; + s->pages[i].lines_tx = 0; s->pages[i].done = 0; } @@ -2343,43 +2603,123 @@ setup_buffers(struct scanner *s) */ static SANE_Status -coarsecal(struct scanner *s) +coarsecal_send_cal(struct scanner *s, unsigned char *pay) { SANE_Status ret = SANE_STATUS_GOOD; - - size_t cmdLen = 2; unsigned char cmd[2]; - - size_t statLen = 1; unsigned char stat[1]; + size_t cmdLen,statLen,payLen; + + DBG (5, "coarsecal_send_cal: start\n"); + /* send coarse cal (c6) */ + cmd[0] = 0x1b; + cmd[1] = 0xc6; + cmdLen = 2; + stat[0] = 0; + statLen = 1; + + ret = do_cmd( + s, 0, + cmd, cmdLen, + NULL, 0, + stat, &statLen + ); + if(ret){ + DBG (5, "coarsecal_send_cal: error sending c6 cmd\n"); + return ret; + } + if(stat[0] != 6){ + DBG (5, "coarsecal_send_cal: cmd bad c6 status?\n"); + return SANE_STATUS_IO_ERROR; + } + + /*send coarse cal payload*/ + stat[0] = 0; + statLen = 1; + payLen = 28; - size_t payLen = 28; - unsigned char pay[28]; + ret = do_cmd( + s, 0, + pay, payLen, + NULL, 0, + stat, &statLen + ); + if(ret){ + DBG (5, "coarsecal_send_cal: error sending c6 payload\n"); + return ret; + } + if(stat[0] != 6){ + DBG (5, "coarsecal_send_cal: c6 payload bad status?\n"); + return SANE_STATUS_IO_ERROR; + } - int try_count, cal_good[2], x, i, j; - int param[2], zcount[2], high_param[2], low_param[2], avg[2], maxval[2]; - int rgb_avg[2][3], rgb_hicount[2][3]; + DBG (5, "coarsecal_send_cal: finish\n"); + return ret; +} - DBG (10, "coarsecal: start\n"); +static SANE_Status +coarsecal_get_line(struct scanner *s, struct image *img) +{ + SANE_Status ret = SANE_STATUS_GOOD; + unsigned char cmd[2]; + unsigned char stat[1]; + size_t cmdLen,statLen; - if(s->model == MODEL_S300){ - memcpy(pay,coarseCalData_S300,payLen); - } - else{ - memcpy(pay,coarseCalData_FI60F,payLen); - } + DBG (5, "coarsecal_get_line: start\n"); - /* ask for 1 line */ - ret = set_window(s, WINDOW_COARSECAL); + /* send scan d2 command */ + cmd[0] = 0x1b; + cmd[1] = 0xd2; + cmdLen = 2; + stat[0] = 0; + statLen = 1; + + ret = do_cmd( + s, 0, + cmd, cmdLen, + NULL, 0, + stat, &statLen + ); if(ret){ - DBG (5, "coarsecal: error sending setwindow\n"); + DBG (5, "coarsecal_get_line: error sending d2 cmd\n"); return ret; } + if(stat[0] != 6){ + DBG (5, "coarsecal_get_line: cmd bad d2 status?\n"); + return SANE_STATUS_IO_ERROR; + } + + s->cal_image.image = img; + update_transfer_totals(&s->cal_image); + + while(!s->cal_image.done){ + ret = read_from_scanner(s,&s->cal_image); + if(ret){ + DBG (5, "coarsecal_get_line: cant read from scanner\n"); + return ret; + } + } + /* convert the raw data into normal packed pixel data */ + descramble_raw(s, &s->cal_image); + + DBG (5, "coarsecal_get_line: finish\n"); + return ret; +} + +static SANE_Status +coarsecal_dark(struct scanner *s, unsigned char *pay) +{ + SANE_Status ret = SANE_STATUS_GOOD; + + 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"); /* dark cal, lamp off */ ret = lamp(s,0); if(ret){ - DBG (5, "coarsecal: error lamp off\n"); + DBG (5, "coarsecal_dark: error lamp off\n"); return ret; } @@ -2394,93 +2734,23 @@ coarsecal(struct scanner *s) try_count--; /* update the coarsecal payload to use our new dark offset parameters */ - if (s->model == MODEL_S300) + if (s->model == MODEL_S300 || s->model == MODEL_S1300i) { pay[5] = param[0]; pay[7] = param[1]; } - else /* (s->model == MODEL_FI60F) */ + else /* MODEL_S1100 or MODEL_FI60F or MODEL_FI65F */ { pay[5] = param[0]; pay[7] = param[0]; pay[9] = param[0]; } - /* send coarse cal (c6) */ - cmd[0] = 0x1b; - cmd[1] = 0xc6; - stat[0] = 0; - statLen = 1; - - ret = do_cmd( - s, 0, - cmd, cmdLen, - NULL, 0, - stat, &statLen - ); - if(ret){ - DBG (5, "coarsecal: error sending c6 cmd\n"); - return ret; - } - if(stat[0] != 6){ - DBG (5, "coarsecal: cmd bad c6 status?\n"); - return SANE_STATUS_IO_ERROR; - } - - /*send coarse cal payload*/ - stat[0] = 0; - statLen = 1; - - ret = do_cmd( - s, 0, - pay, payLen, - NULL, 0, - stat, &statLen - ); - if(ret){ - DBG (5, "coarsecal: error sending c6 payload\n"); - return ret; - } - if(stat[0] != 6){ - DBG (5, "coarsecal: c6 payload bad status?\n"); - return SANE_STATUS_IO_ERROR; - } + ret = coarsecal_send_cal(s, pay); - DBG(15, "coarsecal offset: parameter front: %i back: %i\n", param[0], param[1]); + DBG(15, "coarsecal_dark offset: parameter front: %i back: %i\n", param[0], param[1]); - /* send scan d2 command */ - cmd[0] = 0x1b; - cmd[1] = 0xd2; - stat[0] = 0; - statLen = 1; - - ret = do_cmd( - s, 0, - cmd, cmdLen, - NULL, 0, - stat, &statLen - ); - if(ret){ - DBG (5, "coarsecal: error sending d2 cmd\n"); - return ret; - } - if(stat[0] != 6){ - DBG (5, "coarsecal: cmd bad d2 status?\n"); - return SANE_STATUS_IO_ERROR; - } - - s->cal_image.image = &s->coarsecal; - update_transfer_totals(&s->cal_image); - - while(!s->cal_image.done){ - ret = read_from_scanner(s,&s->cal_image); - if(ret){ - DBG (5, "coarsecal: cant read from scanner\n"); - return ret; - } - } - /* convert the raw data into normal packed pixel data */ - descramble_raw(s, &s->cal_image); + ret = coarsecal_get_line(s, &s->coarsecal); /* gather statistics: count the proportion of 0-valued pixels */ /* since the lamp is off, there's no point in looking at the green or blue data - they're all from the same sensor anyway */ @@ -2504,9 +2774,9 @@ coarsecal(struct scanner *s) avg[j] /= s->coarsecal.width_bytes; zcount[j] = zcount[j] * 1000 / s->coarsecal.width_bytes; } - DBG(15, "coarsecal offset: average pixel values front: %i back: %i\n", avg[0], avg[1]); - DBG(15, "coarsecal offset: maximum pixel values front: %i back: %i\n", maxval[0], maxval[1]); - DBG(15, "coarsecal offset: 0-valued pixel count front: %f%% back: %f%%\n", zcount[0] / 10.0f, zcount[1] / 10.0f); + DBG(15, "coarsecal_dark offset: average pixel values front: %i back: %i\n", avg[0], avg[1]); + DBG(15, "coarsecal_dark offset: maximum pixel values front: %i back: %i\n", maxval[0], maxval[1]); + DBG(15, "coarsecal_dark offset: 0-valued pixel count front: %f%% back: %f%%\n", zcount[0] / 10.0f, zcount[1] / 10.0f); /* check the values, adjust parameters if they are not within the target range */ for (j = 0; j < s->coarsecal.pages; j++) @@ -2530,10 +2800,25 @@ coarsecal(struct scanner *s) } /* continue looping for up to 8 tries */ + DBG (5, "coarsecal_dark: finish\n"); + return ret; +} + +static SANE_Status +coarsecal_light(struct scanner *s, unsigned char *pay) +{ + SANE_Status ret = SANE_STATUS_GOOD; + + int try_count, cal_good[2], x, i, j; + 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"); + /* light cal, lamp on */ ret = lamp(s,1); if(ret){ - DBG (5, "coarsecal: error lamp on\n"); + DBG (5, "coarsecal_light: error lamp on\n"); return ret; } @@ -2547,82 +2832,12 @@ coarsecal(struct scanner *s) while (try_count > 0){ try_count--; - /* send coarse cal (c6) */ - cmd[0] = 0x1b; - cmd[1] = 0xc6; - stat[0] = 0; - statLen = 1; - - ret = do_cmd( - s, 0, - cmd, cmdLen, - NULL, 0, - stat, &statLen - ); - if(ret){ - DBG (5, "coarsecal: error sending c6 cmd\n"); - return ret; - } - if(stat[0] != 6){ - DBG (5, "coarsecal: cmd bad c6 status?\n"); - return SANE_STATUS_IO_ERROR; - } - - /*send coarse cal payload*/ - stat[0] = 0; - statLen = 1; - - ret = do_cmd( - s, 0, - pay, payLen, - NULL, 0, - stat, &statLen - ); - if(ret){ - DBG (5, "coarsecal: error sending c6 payload\n"); - return ret; - } - if(stat[0] != 6){ - DBG (5, "coarsecal: c6 payload bad status?\n"); - return SANE_STATUS_IO_ERROR; - } - - DBG(15, "coarsecal gain: parameter front: %i back: %i\n", param[0], param[1]); + ret = coarsecal_send_cal(s, pay); - /* send scan d2 command */ - cmd[0] = 0x1b; - cmd[1] = 0xd2; - stat[0] = 0; - statLen = 1; - - ret = do_cmd( - s, 0, - cmd, cmdLen, - NULL, 0, - stat, &statLen - ); - if(ret){ - DBG (5, "coarsecal: error sending d2 cmd\n"); - return ret; - } - if(stat[0] != 6){ - DBG (5, "coarsecal: cmd bad d2 status?\n"); - return SANE_STATUS_IO_ERROR; - } + DBG(15, "coarsecal_light gain: parameter front: %i back: %i\n", param[0], param[1]); - s->cal_image.image = &s->coarsecal; - update_transfer_totals(&s->cal_image); + ret = coarsecal_get_line(s, &s->coarsecal); - while(!s->cal_image.done){ - ret = read_from_scanner(s,&s->cal_image); - if(ret){ - DBG (5, "coarsecal: cant read from scanner\n"); - return ret; - } - } - /* convert the raw data into normal packed pixel data */ - descramble_raw(s, &s->cal_image); - /* gather statistics: count the proportion of 255-valued pixels in each color channel */ /* count the average pixel value in each color channel */ for (i = 0; i < s->coarsecal.pages; i++) @@ -2645,7 +2860,7 @@ coarsecal(struct scanner *s) /* apply the color correction factors to the averages */ for (i = 0; i < s->coarsecal.pages; i++) for (j = 0; j < 3; j++) - rgb_avg[i][j] *= white_factor[j]; + rgb_avg[i][j] *= s->white_factor[j]; /* set the gain so that none of the color channels are clipping, ie take the highest channel values */ for (i = 0; i < s->coarsecal.pages; i++) { @@ -2662,9 +2877,9 @@ coarsecal(struct scanner *s) } zcount[i] = MAX3(rgb_hicount[i][0], rgb_hicount[i][1], rgb_hicount[i][2]); } - DBG(15, "coarsecal gain: average RGB values front: (%i,%i,%i) back: (%i,%i,%i)\n", + DBG(15, "coarsecal_light gain: average RGB values front: (%i,%i,%i) back: (%i,%i,%i)\n", rgb_avg[0][0], rgb_avg[0][1], rgb_avg[0][2], rgb_avg[1][0], rgb_avg[1][1], rgb_avg[1][2]); - DBG(15, "coarsecal gain: 255-valued pixel count front: (%g,%g,%g) back: (%g,%g,%g)\n", + DBG(15, "coarsecal_light gain: 255-valued pixel count front: (%g,%g,%g) back: (%g,%g,%g)\n", rgb_hicount[0][0]/10.0f, rgb_hicount[0][1]/10.0f, rgb_hicount[0][2]/10.0f, rgb_hicount[1][0]/10.0f, rgb_hicount[1][1]/10.0f, rgb_hicount[1][2]/10.0f); @@ -2689,12 +2904,12 @@ coarsecal(struct scanner *s) if (cal_good[0] + cal_good[1] == s->coarsecal.pages) break; /* update the coarsecal payload to use the new gain parameters */ - if (s->model == MODEL_S300) + if (s->model == MODEL_S300 || s->model == MODEL_S1300i) { pay[11] = param[0]; pay[13] = param[1]; } - else /* (s->model == MODEL_FI60F) */ + else /* MODEL_S1100 or MODEL_FI60F or MODEL_FI65F */ { pay[11] = param[0]; pay[13] = param[0]; @@ -2702,6 +2917,49 @@ coarsecal(struct scanner *s) } } + DBG (5, "coarsecal_light: finish\n"); + return ret; +} + +static SANE_Status +coarsecal(struct scanner *s) +{ + SANE_Status ret = SANE_STATUS_GOOD; + unsigned char pay[28]; + size_t payLen; + + DBG (10, "coarsecal: start\n"); + + payLen = sizeof(pay); + + if(s->model == MODEL_S300){ + memcpy(pay,coarseCalData_S300,payLen); + } + else if(s->model == MODEL_S1300i){ + memcpy(pay,coarseCalData_S1300i,payLen); + } + else if(s->model == MODEL_S1100){ + memcpy(pay,coarseCalData_S1100,payLen); + } + else{ + memcpy(pay,coarseCalData_FI60F,payLen); + } + + /* ask for 1 line */ + ret = set_window(s, WINDOW_COARSECAL); + if(ret){ + DBG (5, "coarsecal: error sending setwindow\n"); + return ret; + } + + if(s->model == MODEL_S1100){ + ret = coarsecal_send_cal(s, pay); + } + else{ + ret = coarsecal_dark(s, pay); + ret = coarsecal_light(s, pay); + } + DBG (10, "coarsecal: finish\n"); return ret; } @@ -2718,18 +2976,63 @@ finecal_send_cal(struct scanner *s) unsigned char stat[2]; int i, j, k; - unsigned short *p_out, *p_in = (unsigned short *) s->sendcal.buffer; - int planes = (s->model == MODEL_S300) ? 2 : 3; + unsigned char *p_out, *p_in = s->sendcal.buffer; + int planes; + + if(s->model == MODEL_FI60F || s->model == MODEL_FI65F) + planes = 3; + if(s->model == MODEL_S300 || s->model == MODEL_S1300i) + planes = 2; /* scramble the raster buffer data into scanner raw format */ + /* this is reverse of descramble_raw */ memset(s->cal_data.raw_data, 0, s->cal_data.line_stride); - for (i = 0; i < planes; i++) + + if(s->model == MODEL_S1100){ + planes = 1; + + for (k = 0; k < s->sendcal.width_pix; k++){ /* column (x) */ + + /* input is RrGgBb (capital is offset, small is gain) */ + /* output is Bb...BbRr...RrGg...Gg*/ + + /*red*/ + p_out = s->cal_data.raw_data + s->cal_data.plane_stride + k*2; + *p_out = *p_in; + p_out++; + p_in++; + *p_out = *p_in; + p_in++; + + /*green*/ + p_out = s->cal_data.raw_data + 2*s->cal_data.plane_stride + k*2; + *p_out = *p_in; + p_out++; + p_in++; + *p_out = *p_in; + p_in++; + + /*blue*/ + p_out = s->cal_data.raw_data + k*2; + *p_out = *p_in; + p_out++; + p_in++; + *p_out = *p_in; + p_in++; + } + } + + else{ + for (i = 0; i < planes; i++) for (j = 0; j < s->cal_data.plane_width; j++) for (k = 0; k < 3; k++) { - p_out = (unsigned short *) (s->cal_data.raw_data + k * s->cal_data.plane_stride + j * 6 + i * 2); - *p_out = *p_in++; /* dark offset, gain */ + p_out = (s->cal_data.raw_data + k * s->cal_data.plane_stride + j * 6 + i * 2); + *p_out = *p_in++; /* dark offset */ + p_out++; + *p_out = *p_in++; /* gain */ } + } ret = set_window(s, WINDOW_SENDCAL); if(ret){ @@ -2906,13 +3209,21 @@ finecal(struct scanner *s) { SANE_Status ret = SANE_STATUS_GOOD; - const int max_pages = (s->model == MODEL_S300 ? 2 : 1); + int max_pages; int gain_delta = 0xff - 0xbf; float *gain_slope, *last_error; int i, j, k, idx, try_count, cal_good; DBG (10, "finecal: start\n"); + if (s->model == MODEL_S300 || s->model == MODEL_S1300i) { /* S300, S1300 */ + max_pages = 2; + } + else /* fi-60f, S1100 */ + { + max_pages = 1; + } + /* set fine dark offset to 0 and fix all fine gains to lowest parameter (0xFF) */ for (i = 0; i < s->sendcal.width_bytes * s->sendcal.pages / 2; i++) { @@ -3008,7 +3319,7 @@ finecal(struct scanner *s) for (k = 0; k < 3; k++) { int pixvalue = s->lightcal.buffer[idx]; - float pixerror = (fine_gain_target[i] * white_factor[k] - pixvalue); + float pixerror = (fine_gain_target[i] * s->white_factor[k] - pixvalue); int oldgain = s->sendcal.buffer[idx * 2 + 1]; int newgain; /* if we overshot the last correction, reduce the gain_slope */ @@ -3084,6 +3395,9 @@ finecal(struct scanner *s) return ret; } +/* + * set scanner lamp brightness + */ static SANE_Status lamp(struct scanner *s, unsigned char set) { @@ -3247,16 +3561,36 @@ send_lut (struct scanner *s) size_t cmdLen = 2; unsigned char stat[1]; size_t statLen = 1; - unsigned char out[0x6000]; - size_t outLen = 0x6000; + unsigned char *out; + size_t outLen; int i, j; double b, slope, offset; - int width = outLen / 6; /* 3 colors, 2 bytes */ - int height = width; /* square table */ + int width; + int height; DBG (10, "send_lut: start\n"); + if (s->model == MODEL_S1100){ + outLen = 0x200; + width = outLen / 2; /* 1 color, 2 bytes */ + height = width; /* square table */ + } + else if (s->model == MODEL_FI65F){ + outLen = 0x600; + width = outLen / 6; /* 3 color, 2 bytes */ + height = width; /* square table */ + } + else { + outLen = 0x6000; + width = outLen / 6; /* 3 colors, 2 bytes */ + height = width; /* square table */ + } + out = ( unsigned char *)malloc(outLen*sizeof(unsigned char)); + if (out == NULL){ + return SANE_STATUS_NO_MEM; + } + /* contrast is converted to a slope [0,90] degrees: * first [-127,127] to [0,254] then to [0,1] * then multiply by PI/2 to convert to radians @@ -3287,18 +3621,38 @@ send_lut (struct scanner *s) if(j>(height-1)){ j=height-1; } - - /*first table, le order*/ - out[i*2] = j & 0xff; - out[i*2+1] = (j >> 8) & 0x0f; - /*second table, le order*/ - out[width*2 + i*2] = j & 0xff; - out[width*2 + i*2+1] = (j >> 8) & 0x0f; - - /*third table, le order*/ - out[width*4 + i*2] = j & 0xff; - out[width*4 + i*2+1] = (j >> 8) & 0x0f; + if (s->model == MODEL_S1100){ + /*only one table, be order*/ + out[i*2] = (j >> 8) & 0xff; + out[i*2+1] = j & 0xff; + } + else if (s->model == MODEL_FI65F){ + /*first table, be order*/ + out[i*2] = (j >> 8) & 0xff; + out[i*2+1] = j & 0xff; + + /*second table, be order*/ + out[width*2 + i*2] = (j >> 8) & 0xff; + out[width*2 + i*2+1] = j & 0xff; + + /*third table, be order*/ + out[width*4 + i*2] = (j >> 8) & 0xff; + out[width*4 + i*2+1] = j & 0xff; + } + else { + /*first table, le order*/ + out[i*2] = j & 0xff; + out[i*2+1] = (j >> 8) & 0x0f; + + /*second table, le order*/ + out[width*2 + i*2] = j & 0xff; + out[width*2 + i*2+1] = (j >> 8) & 0x0f; + + /*third table, le order*/ + out[width*4 + i*2] = j & 0xff; + out[width*4 + i*2+1] = (j >> 8) & 0x0f; + } } ret = do_cmd( @@ -3386,11 +3740,10 @@ get_hardware_status (struct scanner *s) } static SANE_Status -ingest(struct scanner *s) +object_position(struct scanner *s, int ingest) { SANE_Status ret = SANE_STATUS_GOOD; int i; - unsigned char cmd[2]; size_t cmdLen = sizeof(cmd); unsigned char stat[1]; @@ -3398,10 +3751,11 @@ ingest(struct scanner *s) unsigned char pay[2]; size_t payLen = sizeof(pay); - DBG (10, "ingest: start\n"); + DBG (10, "object_position: start\n"); - for(i=0;i<5;i++){ - + i = (ingest)?5:1; + + while(i--){ /*send paper load cmd*/ cmd[0] = 0x1b; cmd[1] = 0xd4; @@ -3414,18 +3768,18 @@ ingest(struct scanner *s) stat, &statLen ); if(ret){ - DBG (5, "ingest: error sending cmd\n"); + DBG (5, "object_position: error sending cmd\n"); return ret; } if(stat[0] != 6){ - DBG (5, "ingest: cmd bad status? %d\n",stat[0]); + DBG (5, "object_position: cmd bad status? %d\n",stat[0]); continue; } /*send payload*/ statLen = 1; payLen = 1; - pay[0] = 1; + pay[0] = ingest; ret = do_cmd( s, 0, @@ -3434,25 +3788,25 @@ ingest(struct scanner *s) stat, &statLen ); if(ret){ - DBG (5, "ingest: error sending payload\n"); + DBG (5, "object_position: error sending payload\n"); return ret; } if(stat[0] == 6){ - DBG (5, "ingest: found paper?\n"); + DBG (5, "object_position: found paper?\n"); break; } else if(stat[0] == 0x15 || stat[0] == 0){ - DBG (5, "ingest: no paper?\n"); + DBG (5, "object_position: no paper?\n"); ret=SANE_STATUS_NO_DOCS; continue; } else{ - DBG (5, "ingest: payload bad status?\n"); + DBG (5, "object_position: payload bad status?\n"); return SANE_STATUS_IO_ERROR; } } - DBG (10, "ingest: finish\n"); + DBG (10, "object_position: finish\n"); return ret; } @@ -3467,7 +3821,7 @@ scan(struct scanner *s) DBG (10, "scan: start\n"); - if(s->model == MODEL_S300){ + if(s->model == MODEL_S300 || s->model == MODEL_S1100 || s->model == MODEL_S1300i){ cmd[1] = 0xd6; } @@ -3525,9 +3879,29 @@ sane_read (SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, SANE_Int * len page = &s->pages[s->side]; /* have sent all of current buffer */ - if(page->done){ + if(s->fullscan.done && page->done){ DBG (10, "sane_read: returning eof\n"); - return SANE_STATUS_EOF; + + /*S1100 needs help to turn off button*/ + if(s->model == MODEL_S1100){ + usleep(15000); + + /* eject paper */ + ret = object_position(s,EPJITSU_PAPER_EJECT); + if (ret != SANE_STATUS_GOOD && ret != SANE_STATUS_NO_DOCS) { + DBG (5, "sane_read: ERROR: failed to eject\n"); + return ret; + } + + /* reset flashing button? */ + ret = six5(s); + if (ret != SANE_STATUS_GOOD) { + DBG (5, "sane_read: ERROR: failed to six5\n"); + return ret; + } + } + + return SANE_STATUS_EOF; } /* scan not finished, get more into block buffer */ @@ -3543,8 +3917,8 @@ sane_read (SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, SANE_Int * len DBG (15, "sane_read: shrinking block to %lu\n", (unsigned long)remainTotal); s->block_xfr.total_bytes = remainTotal; } - /* send d3 cmd for S300 */ - if(s->model == MODEL_S300) + /* send d3 cmd for S300, S1100, S1300 */ + if(s->model == MODEL_S300 || s->model == MODEL_S1100 || s->model == MODEL_S1300i) { unsigned char cmd[] = {0x1b, 0xd3}; size_t cmdLen = 2; @@ -3586,8 +3960,8 @@ sane_read (SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, SANE_Int * len s->block_xfr.done = 0; - /* get the 0x43 cmd for the S300 */ - if(s->model == MODEL_S300){ + /* get the 0x43 cmd for the S300, S1100, S1300 */ + if(s->model == MODEL_S300 || s->model == MODEL_S1100 || s->model == MODEL_S1300i){ unsigned char cmd[] = {0x1b, 0x43}; size_t cmdLen = 2; @@ -3672,7 +4046,7 @@ sane_read (SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, SANE_Int * len page->bytes_read += *len; /* sent it all, return eof on next read */ - if(s->fullscan.done && page->bytes_read == page->bytes_scanned){ + if(page->bytes_read == page->bytes_scanned && s->fullscan.done){ DBG (10, "sane_read: side done\n"); page->done = 1; } @@ -3683,36 +4057,180 @@ sane_read (SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, SANE_Int * len return ret; } +static SANE_Status +six5 (struct scanner *s) +{ + SANE_Status ret = SANE_STATUS_GOOD; + + unsigned char cmd[2]; + size_t cmdLen = sizeof(cmd); + unsigned char stat[1]; + size_t statLen = sizeof(stat); + + DBG (10, "six5: start\n"); + + cmd[0] = 0x1b; + cmd[1] = 0x65; + statLen = 1; + + ret = do_cmd( + s, 0, + cmd, cmdLen, + NULL, 0, + stat, &statLen + ); + if(ret){ + DBG (5, "six5: error sending cmd\n"); + return ret; + } + if(stat[0] != 6){ + DBG (5, "six5: cmd bad status? %d\n",stat[0]); + return SANE_STATUS_IO_ERROR; + } + + DBG (10, "six5: finish\n"); + + return ret; +} + /* de-scrambles the raw data from the scanner into the image buffer */ +/* the output image might be lower dpi than input image, so we scale horizontally */ static SANE_Status descramble_raw(struct scanner *s, struct transfer * tp) { SANE_Status ret = SANE_STATUS_GOOD; - unsigned char *p_in, *p_out = tp->image->buffer; + unsigned char *p_out = tp->image->buffer; int height = tp->total_bytes / tp->line_stride; - int i, j, k, l; + int i, j, k; - if (s->model == MODEL_S300) - { - for (i = 0; i < 2; i++) /* page, front/back */ - for (j = 0; j < height; j++) /* row (y)*/ - for (k = 0; k < tp->plane_width; k++) /* column (x) */ - for (l = 0; l < 3; l++) /* color component */ - { - p_in = (unsigned char *) tp->raw_data + (j * tp->line_stride) + (l * tp->plane_stride) + k * 3 + i; - *p_out++ = *p_in; - } + if (s->model == MODEL_S300 || s->model == MODEL_S1300i) { + for (i = 0; i < 2; i++){ /* page, front/back */ + for (j = 0; j < height; j++){ /* row (y)*/ + int curr_col = 0; + int r=0, g=0, b=0, ppc=0; + + for (k = 0; k <= tp->plane_width; k++){ /* column (x) */ + int this_col = k*tp->image->x_res/tp->x_res; + + /* going to change output pixel, dump rgb and reset */ + if(ppc && curr_col != this_col){ + *p_out = r/ppc; + p_out++; + + *p_out = g/ppc; + p_out++; + + *p_out = b/ppc; + p_out++; + + r = g = b = ppc = 0; + + curr_col = this_col; + } + + if(k == tp->plane_width || this_col >= tp->image->width_pix){ + break; + } + + /*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]; + + /*blue is third*/ + b += tp->raw_data[j*tp->line_stride + 2*tp->plane_stride + k*3 + i]; + + ppc++; + } + } + } } - else /* MODEL_FI60F */ - { - for (i = 0; i < height; i++) /* row (y)*/ - for (j = 0; j < 3; j++) /* read head */ - for (k = 0; k < tp->plane_width; k++) /* column within the read head */ - for (l = 0; l < 3; l++) /* color component */ - { - p_in = (unsigned char *) tp->raw_data + (i * tp->line_stride) + (l * tp->plane_stride) + k * 3 + j; - *p_out++ = *p_in; - } + else if (s->model == MODEL_S1100){ + for (j = 0; j < height; j++){ /* row (y)*/ + int curr_col = 0; + int r=0, g=0, b=0, ppc=0; + + for (k = 0; k <= tp->plane_width; k++){ /* column (x) */ + int this_col = k*tp->image->x_res/tp->x_res; + + /* going to change output pixel, dump rgb and reset */ + if(ppc && curr_col != this_col){ + *p_out = r/ppc; + p_out++; + + *p_out = g/ppc; + p_out++; + + *p_out = b/ppc; + p_out++; + + r = g = b = ppc = 0; + + curr_col = this_col; + } + + if(k == tp->plane_width || this_col >= tp->image->width_pix){ + break; + } + + /*red is second*/ + r += tp->raw_data[j*tp->line_stride + tp->plane_stride + k]; + + /*green is third*/ + g += tp->raw_data[j*tp->line_stride + 2*tp->plane_stride + k]; + + /*blue is first*/ + b += tp->raw_data[j*tp->line_stride + k]; + + ppc++; + } + } + } + else { /* MODEL_FI60F or MODEL_FI65F */ + + for (j = 0; j < height; j++){ /* row (y)*/ + int curr_col = 0; + + for (i = 0; i < 3; i++){ /* read head */ + int r=0, g=0, b=0, ppc=0; + + for (k = 0; k <= tp->plane_width; k++){ /* column (x) within the read head */ + int this_col = (k+i*tp->plane_width)*tp->image->x_res/tp->x_res; + + /* going to change output pixel, dump rgb and reset */ + if(ppc && curr_col != this_col){ + *p_out = r/ppc; + p_out++; + + *p_out = g/ppc; + p_out++; + + *p_out = b/ppc; + p_out++; + + r = g = b = ppc = 0; + + curr_col = this_col; + } + + if(k == tp->plane_width || this_col >= tp->image->width_pix){ + break; + } + + /*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]; + + /*blue is third*/ + b += tp->raw_data[j*tp->line_stride + 2*tp->plane_stride + k*3 + i]; + + ppc++; + } + } + } } return ret; @@ -3725,9 +4243,11 @@ read_from_scanner(struct scanner *s, struct transfer * tp) SANE_Status ret=SANE_STATUS_GOOD; size_t bytes = MAX_IMG_PASS; size_t remainBlock = tp->total_bytes - tp->rx_bytes + 8; - - /* determine amount to ask for */ - if(bytes > remainBlock){ + unsigned char * buf; + size_t bufLen; + + /* determine amount to ask for, S1300i wants big requests */ + if(bytes > remainBlock && s->model != MODEL_S1300i){ bytes = remainBlock; } @@ -3745,70 +4265,141 @@ read_from_scanner(struct scanner *s, struct transfer * tp) return SANE_STATUS_INVAL; } + bufLen = bytes; + buf = malloc(bufLen); + if(!buf){ + DBG (5, "read_from_scanner: failed to alloc mem\n"); + return SANE_STATUS_NO_MEM; + } + ret = do_cmd( s, 0, NULL, 0, NULL, 0, - tp->raw_data + tp->rx_bytes, &bytes + buf, &bytes ); - + /* full read or short read */ if (ret == SANE_STATUS_GOOD || (ret == SANE_STATUS_EOF && bytes) ) { DBG(15,"read_from_scanner: got GOOD/EOF (%lu)\n",(unsigned long)bytes); + if(bytes > remainBlock){ + DBG(15,"read_from_scanner: block too big?\n"); + bytes = remainBlock; + } + if(bytes == remainBlock){ DBG(15,"read_from_scanner: block done, ignoring trailer\n"); bytes -= 8; tp->done = 1; } - ret = SANE_STATUS_GOOD; + memcpy(tp->raw_data + tp->rx_bytes, buf, bytes); tp->rx_bytes += bytes; + + ret = SANE_STATUS_GOOD; } else { DBG(5, "read_from_scanner: error reading status = %d\n", ret); } - + + free(buf); + DBG (10, "read_from_scanner: finish rB:%lu len:%lu\n", - (unsigned long)(tp->total_bytes - tp->rx_bytes), (unsigned long)bytes); + (unsigned long)(tp->total_bytes - tp->rx_bytes + 8), (unsigned long)bytes); return ret; } /* copies block buffer into front or back image buffer */ /* converts pixel data from RGB Color to the output format */ +/* the output image might be lower dpi than input image, so we scale vertically */ static SANE_Status copy_block_to_page(struct scanner *s,int side) { SANE_Status ret = SANE_STATUS_GOOD; struct transfer * block = &s->block_xfr; struct page * page = &s->pages[side]; - int height = block->total_bytes / block->line_stride; - int width = block->image->width_pix; + int image_height = block->total_bytes / block->line_stride; + int page_height = SCANNER_UNIT_TO_PIX(s->page_height, s->resolution); + int page_width = page->image->width_pix; int block_page_stride = block->image->width_bytes * block->image->height; - int page_y_offset = page->bytes_scanned / page->image->width_bytes; - int line_reverse = (side == SIDE_BACK) || (s->model == MODEL_FI60F); - int i,j; + int line_reverse = (side == SIDE_BACK) || (s->model == MODEL_FI60F) || (s->model == MODEL_FI65F); + int i,j,k=0,l=0; + + int curr_in_row = s->fullscan.rx_bytes/s->fullscan.width_bytes; + int last_out_row = (page->bytes_scanned / page->image->width_bytes) - 1; DBG (10, "copy_block_to_page: start\n"); + /* skip padding and tl_y */ + if (s->fullscan.rx_bytes + s->block_xfr.rx_bytes < block->line_stride * page->image->y_skip_offset) + { + DBG (10, "copy_block_to_page: before the start? %d\n", side); + return ret; + } + else if (s->fullscan.rx_bytes < block->line_stride * page->image->y_skip_offset) + { + k = page->image->y_skip_offset - s->fullscan.rx_bytes / block->line_stride; + DBG (10, "copy_block_to_page: k start? %d\n", k); + } + + /* skip trailer */ + if (s->page_height) + { + DBG (10, "copy_block_to_page: ph %d\n", s->page_height); + if (s->fullscan.rx_bytes > block->line_stride * page->image->y_skip_offset + page_height * block->line_stride) + { + DBG (10, "copy_block_to_page: off the end? %d\n", side); + return ret; + } + else if (s->fullscan.rx_bytes + s->block_xfr.rx_bytes + > block->line_stride * page->image->y_skip_offset + page_height * block->line_stride) + { + l = (s->fullscan.rx_bytes + s->block_xfr.rx_bytes) / block->line_stride + - page_height - page->image->y_skip_offset; + } + } + /* loop over all the lines in the block */ - for (i = 0; i < height; i++) + for (i = k; i < image_height-l; i++) { - unsigned char * p_in = block->image->buffer + (side * block_page_stride) + (i * block->image->width_bytes); - unsigned char * p_out = page->image->buffer + ((i + page_y_offset) * page->image->width_bytes); + /* determine source and dest rows (dpi scaling) */ + int this_in_row = curr_in_row + i; + int this_out_row = (this_in_row - page->image->y_skip_offset) * page->image->y_res / s->fullscan.y_res; + DBG (15, "copy_block_to_page: in %d out %d lastout %d\n", this_in_row, this_out_row, last_out_row); + DBG (15, "copy_block_to_page: bs %d wb %d\n", page->bytes_scanned, page->image->width_bytes); + + /* don't walk off the end of the output buffer */ + if(this_out_row >= page->image->height || this_out_row < 0){ + DBG (10, "copy_block_to_page: out of space? %d\n", side); + DBG (10, "copy_block_to_page: rx:%d tx:%d tot:%d line:%d\n", + page->bytes_scanned, page->bytes_read, page->bytes_total,page->image->width_bytes); + return ret; + } + + /* ok, different output row, so we do the math */ + if(this_out_row > last_out_row){ + + unsigned char * p_in = block->image->buffer + (side * block_page_stride) + + (i * block->image->width_bytes) + page->image->x_start_offset * 3; + unsigned char * p_out = page->image->buffer + this_out_row * page->image->width_bytes; unsigned char * lineStart = p_out; + + last_out_row = this_out_row; + /* reverse order for back side or FI-60F scanner */ if (line_reverse) - p_in += (width - 1) * 3; + p_in += (page_width - 1) * 3; + /* convert all of the pixels in this row */ - for (j = 0; j < width; j++) + for (j = 0; j < page_width; j++) { unsigned char r, g, b; - if (s->model == MODEL_S300) + if (s->model == MODEL_S300 || s->model == MODEL_S1300i) { r = p_in[1]; g = p_in[2]; b = p_in[0]; } - else /* (s->model == MODEL_FI60F) */ + else /* MODEL_FI60F or MODEL_FI65F or MODEL_S1100 */ { r = p_in[0]; g = p_in[1]; b = p_in[2]; } if (s->mode == MODE_COLOR) { @@ -3822,28 +4413,28 @@ copy_block_to_page(struct scanner *s,int side) } else if (s->mode == MODE_LINEART) { - s->dt.buffer[j] = (r + g + b) / 3; + s->dt.buffer[j] = (r + g + b) / 3; /* stores dt temp image buffer and binarize afterword */ } if (line_reverse) p_in -= 3; else p_in += 3; } - /* for MODE_LINEART, binarize the gray line stored in the temp image buffer */ + + /* skip non-transfer pixels in block image buffer */ + if (line_reverse) + p_in -= page->image->x_offset_bytes; + else + p_in += page->image->x_offset_bytes; + + /* for MODE_LINEART, binarize the gray line stored in the temp image buffer(dt) */ + /* bacause dt.width = page_width, we pass page_width */ if (s->mode == MODE_LINEART) - binarize_line(s, lineStart, width); - /*add a periodic row because of non-square pixels*/ - /*FIXME: only works with 225x200*/ - if (s->resolution_x > s->resolution_y && (i + page_y_offset) % 9 == 8) - { - memcpy(lineStart + page->image->width_bytes, lineStart, page->image->width_bytes); - page_y_offset += 1; - page->bytes_scanned += page->image->width_bytes; - } - } + binarize_line(s, lineStart, page_width); - /* update the page counter of bytes scanned */ - page->bytes_scanned += page->image->width_bytes * height; + page->bytes_scanned += page->image->width_bytes; + } + } DBG (10, "copy_block_to_page: finish\n"); @@ -3858,7 +4449,7 @@ binarize_line(struct scanner *s, unsigned char *lineOut, int width) int j, windowX, sum = 0; /* ~1mm works best, but the window needs to have odd # of pixels */ - windowX = 6 * s->resolution_x / 150; + windowX = 6 * s->resolution / 150; if (!(windowX % 2)) windowX++; /*second, prefill the sliding sum*/ diff --git a/backend/epjitsu.conf.in b/backend/epjitsu.conf.in index cabe6b2..155befc 100644 --- a/backend/epjitsu.conf.in +++ b/backend/epjitsu.conf.in @@ -17,6 +17,35 @@ # find them. They should be ~65K, and have the scanner's name as part of the # file name. They are often inside a .cab file. +# To extract .nal files from cabinet files on Linux, use the following steps: +# (you need the "unshield" tool, which is - in Debian - in the unshield package) +# +# 1) Mount the ScanSnap installation DVD +# (mount point e.g. /media/dvd) +# +# 2) Extract the .nal files c$ from the cabinet files on the DVD +# using the following shell script: +# +# # loop over all cabinet files found on the DVD +# for cab in $(find /media/dvd/ -name \*.cab); do +# # search for .nal files in the cabinet files +# nalinfo=$(unshield l $cab | grep '\.nal$') +# +# # we found something +# if [ -n "$nalinfo" ]; then +# #echo -e "=== $cab ===\n$nalinfo" +# +# # loop over all fields in $nalinfo +# for nal in $nalinfo; do +# # if the element of $nalinfo is a .nal file name +# if echo "$nal" | grep -q '\.nal$' - 2>/dev/null; then +# # extract .nal file form the cabinet file +# unshield x "$cab" "${nal##*\\}" +# fi +# done +# fi +# done + # Copy the file someplace sane can reach it. Then update the line below. # NOTE: the firmware line must occur BEFORE the usb line for your scanner @@ -32,6 +61,14 @@ usb 0x04c5 0x1156 firmware @DATADIR@/sane/epjitsu/300M_0C00.nal usb 0x04c5 0x117f +# Fujitsu S1100 +firmware @DATADIR@/sane/epjitsu/1100_0B00.nal +usb 0x04c5 0x1200 + # Fujitsu S1300 firmware @DATADIR@/sane/epjitsu/1300_0C26.nal usb 0x04c5 0x11ed + +# Fujitsu S1300i +firmware @DATADIR@/sane/epjitsu/1300i_0D12.nal +usb 0x04c5 0x128d diff --git a/backend/epjitsu.h b/backend/epjitsu.h index ed63504..7bb1ccc 100644 --- a/backend/epjitsu.h +++ b/backend/epjitsu.h @@ -18,8 +18,7 @@ enum scanner_Option OPT_MODE_GROUP, OPT_SOURCE, /*adffront/adfback/adfduplex/fb*/ OPT_MODE, /*mono/gray/color*/ - OPT_X_RES, - OPT_Y_RES, + OPT_RES, OPT_GEOMETRY_GROUP, OPT_TL_X, @@ -56,7 +55,11 @@ struct image { int width_bytes; int height; int pages; - + int x_res; + int y_res; + int x_start_offset; + int x_offset_bytes; + int y_skip_offset; unsigned char * buffer; }; @@ -68,6 +71,8 @@ struct transfer { int total_bytes; int rx_bytes; int done; + int x_res; + int y_res; unsigned char * raw_data; struct image * image; @@ -77,6 +82,9 @@ struct page { int bytes_total; int bytes_scanned; int bytes_read; + int lines_rx; /* received from scanner */ + int lines_pass; /* passed thru from scanner to user (might be smaller than tx for 225dpi) */ + int lines_tx; /* transmitted to user */ int done; struct image *image; }; @@ -94,15 +102,13 @@ struct scanner int has_fb; int has_adf; - int x_res_150; - int x_res_225; - int x_res_300; - int x_res_600; + int has_adf_duplex; + + int min_res; + int max_res; - int y_res_150; - int y_res_225; - int y_res_300; - int y_res_600; + float white_factor[3]; + int adf_height_padding; /* the scan size in 1/1200th inches, NOT basic_units or sane units */ int max_x; @@ -127,8 +133,7 @@ struct scanner /*mode group, room for lineart, gray, color, null */ SANE_String_Const source_list[5]; SANE_String_Const mode_list[4]; - SANE_Int x_res_list[4]; - SANE_Int y_res_list[4]; + SANE_Range res_range; /*geometry group*/ SANE_Range tl_x_range; @@ -151,9 +156,7 @@ struct scanner /*mode group*/ int source; /* adf or fb */ int mode; /* color,lineart,etc */ - int res; /* from a limited list, x and y same */ - int resolution_x; /* unused dummy */ - int resolution_y; /* unused dummy */ + int resolution; /* dpi */ /*geometry group*/ /* The desired size of the scan, all in 1/1200 inch */ @@ -213,6 +216,8 @@ struct scanner /* the scan struct holds these larger numbers, but image buffer is unused */ struct { int done; + int x_res; + int y_res; int height; int rx_bytes; int width_bytes; @@ -257,6 +262,9 @@ struct scanner #define MODEL_NONE 0 #define MODEL_S300 1 #define MODEL_FI60F 2 +#define MODEL_S1100 3 +#define MODEL_S1300i 4 +#define MODEL_FI65F 5 #define USB_COMMAND_TIME 10000 #define USB_DATA_TIME 10000 @@ -278,6 +286,9 @@ struct scanner #define WINDOW_SENDCAL 2 #define WINDOW_SCAN 3 +#define EPJITSU_PAPER_INGEST 1 +#define EPJITSU_PAPER_EJECT 0 + /* ------------------------------------------------------------------------- */ #define MM_PER_UNIT_UNFIX SANE_UNFIX(SANE_FIX(MM_PER_INCH / 1200.0)) @@ -286,6 +297,9 @@ struct scanner #define SCANNER_UNIT_TO_FIXED_MM(number) SANE_FIX((number) * MM_PER_UNIT_UNFIX) #define FIXED_MM_TO_SCANNER_UNIT(number) SANE_UNFIX(number) / MM_PER_UNIT_UNFIX +#define PIX_TO_SCANNER_UNIT(number, dpi) SANE_UNFIX(SANE_FIX((number) * 1200 / dpi )) +#define SCANNER_UNIT_TO_PIX(number, dpi) SANE_UNFIX(SANE_FIX((number) * dpi / 1200 )) + #define CONFIG_FILE "epjitsu.conf" #ifndef PATH_MAX @@ -354,7 +368,8 @@ static SANE_Status destroy(struct scanner *s); static SANE_Status teardown_buffers(struct scanner *s); static SANE_Status setup_buffers(struct scanner *s); -static SANE_Status ingest(struct scanner *s); +static SANE_Status object_position(struct scanner *s, int ingest); +static SANE_Status six5 (struct scanner *s); static SANE_Status coarsecal(struct scanner *s); static SANE_Status finecal(struct scanner *s); static SANE_Status send_lut(struct scanner *s); diff --git a/backend/epson.c b/backend/epson.c index 2cae65a..6b111f2 100644 --- a/backend/epson.c +++ b/backend/epson.c @@ -818,6 +818,12 @@ typedef struct } EpsonIdentRec, *EpsonIdent; +typedef union +{ + EpsonHdrRec hdr; + EpsonIdentRec ident; +} EpsonHdrUnionRec, *EpsonHdrUnion; + typedef struct { @@ -843,7 +849,7 @@ typedef struct * */ -static EpsonHdr command (Epson_Scanner * s, u_char * cmd, size_t cmd_size, +static EpsonHdrUnion command (Epson_Scanner * s, u_char * cmd, size_t cmd_size, SANE_Status * status); static SANE_Status get_identity_information (SANE_Handle handle); static SANE_Status get_identity2_information (SANE_Handle handle); @@ -1844,21 +1850,24 @@ static Epson_Device *first_dev = NULL; /* first EPSON scanner in list */ static Epson_Scanner *first_handle = NULL; -static EpsonHdr +static EpsonHdrUnion command (Epson_Scanner * s, u_char * cmd, size_t cmd_size, SANE_Status * status) { + EpsonHdrUnion hdrunion, hdrunion_bak; EpsonHdr head; u_char *buf; int count; - if (NULL == (head = walloc (EpsonHdrRec))) + if (NULL == (hdrunion = walloc (EpsonHdrUnionRec))) { DBG (1, "out of memory (line %d)\n", __LINE__); *status = SANE_STATUS_NO_MEM; - return (EpsonHdr) 0; + return (EpsonHdrUnion) 0; } + head = &(hdrunion->hdr); + send (s, cmd, cmd_size, status); if (SANE_STATUS_GOOD != *status) @@ -1869,7 +1878,7 @@ command (Epson_Scanner * s, u_char * cmd, size_t cmd_size, *status = SANE_STATUS_GOOD; send (s, cmd, cmd_size, status); if (SANE_STATUS_GOOD != *status) - return (EpsonHdr) 0; + return (EpsonHdrUnion) 0; } buf = (u_char *) head; @@ -1892,7 +1901,7 @@ command (Epson_Scanner * s, u_char * cmd, size_t cmd_size, } if (SANE_STATUS_GOOD != *status) - return (EpsonHdr) 0; + return (EpsonHdrUnion) 0; DBG (4, "code %02x\n", (int) head->code); @@ -1921,25 +1930,30 @@ command (Epson_Scanner * s, u_char * cmd, size_t cmd_size, } if (SANE_STATUS_GOOD != *status) - return (EpsonHdr) 0; + return (EpsonHdrUnion) 0; DBG (4, "status %02x\n", (int) head->status); count = head->count2 * 255 + head->count1; DBG (4, "count %d\n", count); - if (NULL == (head = realloc (head, sizeof (EpsonHdrRec) + count))) + hdrunion_bak = hdrunion; + if (NULL == (hdrunion = realloc (hdrunion, + sizeof (EpsonHdrUnionRec) + count))) { + free(hdrunion_bak); DBG (1, "out of memory (line %d)\n", __LINE__); *status = SANE_STATUS_NO_MEM; - return (EpsonHdr) 0; + return (EpsonHdrUnion) 0; } + head = &(hdrunion->hdr); + buf = head->buf; receive (s, buf, count, status); if (SANE_STATUS_GOOD != *status) - return (EpsonHdr) 0; + return (EpsonHdrUnion) 0; break; @@ -1953,7 +1967,7 @@ command (Epson_Scanner * s, u_char * cmd, size_t cmd_size, break; } - return head; + return hdrunion; } @@ -2333,7 +2347,7 @@ attach (const char *dev_name, Epson_Device * *devp, int type) /* * Extended status flag request (ESC f). - * this also requests the scanner device name from the the scanner + * this also requests the scanner device name from the scanner */ /* * because we are also using the device name from this command, diff --git a/backend/epson2-commands.c b/backend/epson2-commands.c index a84630b..eccd4ba 100644 --- a/backend/epson2-commands.c +++ b/backend/epson2-commands.c @@ -333,7 +333,7 @@ esci_set_gamma_table(Epson_Scanner * s) /* Print the gamma tables before sending them to the scanner */ - if (DBG_LEVEL >= 10) { + if (DBG_LEVEL >= 16) { int c, i, j; for (c = 0; c < 3; c++) { @@ -347,7 +347,8 @@ esci_set_gamma_table(Epson_Scanner * s) s->gamma_table[c][i + j]); strcat(gammaValues, newValue); } - DBG(11, "gamma table[%d][%d] %s\n", c, i, + + DBG(16, "gamma table[%d][%d] %s\n", c, i, gammaValues); } } @@ -679,8 +680,10 @@ esci_set_scanning_parameter(SANE_Handle handle, unsigned char *buf) return status; status = e2_cmd_simple(s, buf, 64); - if (status != SANE_STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { + DBG(1, "%s: invalid scanning parameters\n", __func__); return status; + } return SANE_STATUS_GOOD; } diff --git a/backend/epson2-io.c b/backend/epson2-io.c index 13adef4..4477963 100644 --- a/backend/epson2-io.c +++ b/backend/epson2-io.c @@ -110,8 +110,8 @@ e2_send(Epson_Scanner * s, void *buf, size_t buf_size, size_t reply_len, } ssize_t -e2_recv(Epson_Scanner * s, void *buf, ssize_t buf_size, - SANE_Status * status) +e2_recv(Epson_Scanner *s, void *buf, ssize_t buf_size, + SANE_Status *status) { ssize_t n = 0; @@ -142,8 +142,9 @@ e2_recv(Epson_Scanner * s, void *buf, ssize_t buf_size, } if (n < buf_size) { - DBG(1, "%s: expected = %lu, got = %ld\n", __func__, - (u_long) buf_size, (long) n); + DBG(1, "%s: expected = %lu, got = %ld, canceling: %d\n", __func__, + (u_long) buf_size, (long) n, s->canceling); + *status = SANE_STATUS_IO_ERROR; } diff --git a/backend/epson2-ops.c b/backend/epson2-ops.c index df6958c..eac01b0 100644 --- a/backend/epson2-ops.c +++ b/backend/epson2-ops.c @@ -177,7 +177,7 @@ e2_dev_init(Epson_Device *dev, const char *devname, int conntype) SANE_Status e2_dev_post_init(struct Epson_Device *dev) { - int i; + int i, last; DBG(5, "%s\n", __func__); @@ -231,7 +231,7 @@ e2_dev_post_init(struct Epson_Device *dev) /* try to expand the resolution list where appropriate */ - int last = dev->res_list[dev->res_list_size - 1]; + last = dev->res_list[dev->res_list_size - 1]; DBG(1, "highest available resolution: %d\n", last); @@ -240,6 +240,21 @@ e2_dev_post_init(struct Epson_Device *dev) e2_add_resolution(dev, dev->optical_res); } + /* add missing resolutions for known scanners */ + + if (e2_dev_model(dev, "GT-X800") || e2_dev_model(dev, "GT-X700")) { + + DBG(1, "known scanner, integrating resolution list\n"); + e2_add_resolution(dev, 4800); + e2_add_resolution(dev, 6400); + e2_add_resolution(dev, 9600); + e2_add_resolution(dev, 12800); + + last = dev->res_list[dev->res_list_size - 1]; + } + + /* guess for the others */ + if (dev->dpi_range.max > last && dev->dpi_range.max != dev->optical_res) { int val = last + last; @@ -472,8 +487,10 @@ e2_set_tpu2_area(struct Epson_Scanner *s, int x, int y, int unit) } void -e2_add_depth(Epson_Device * dev, SANE_Word depth) +e2_add_depth(Epson_Device *dev, SANE_Int depth) { + DBG(10, "%s: add (bpp): %d\n", __func__, depth); + if (depth > dev->maxDepth) dev->maxDepth = depth; @@ -579,7 +596,7 @@ e2_discover_capabilities(Epson_Scanner *s) /* * Extended status flag request (ESC f). - * this also requests the scanner device name from the the scanner. + * this also requests the scanner device name from the scanner. * It seems unsupported on the network transport (CX11NF/LP-A500). */ @@ -700,6 +717,11 @@ e2_discover_capabilities(Epson_Scanner *s) *source_list_add++ = ADF_STR; dev->ADF = SANE_TRUE; } + + if (buf[44] & EXT_IDTY_CAP1_ADFS) { + dev->duplex = SANE_TRUE; + } + } /* TPU */ @@ -713,7 +735,7 @@ e2_discover_capabilities(Epson_Scanner *s) } /* TPU2 */ - if (e2_model(s, "GT-X800") || e2_model(s, "GT-X900")) { + if (e2_model(s, "GT-X800") || e2_model(s, "GT-X900") || e2_model(s, "GT-X980")) { if (le32atoh(&buf[68]) > 0 ) { e2_set_tpu2_area(s, le32atoh(&buf[68]), @@ -760,7 +782,7 @@ e2_discover_capabilities(Epson_Scanner *s) * Check for the max. supported color depth and assign * the values to the bitDepthList. */ - dev->depth_list = malloc(sizeof(SANE_Word) * 4); + dev->depth_list = malloc(sizeof(SANE_Int) * (4 + 1)); if (dev->depth_list == NULL) { DBG(1, "out of memory (line %d)\n", __LINE__); return SANE_STATUS_NO_MEM; @@ -771,9 +793,12 @@ e2_discover_capabilities(Epson_Scanner *s) /* maximum depth discovery */ DBG(3, "discovering max depth, NAKs are expected\n"); - if (dev->maxDepth >= 16 || dev->maxDepth == 0) { - if (esci_set_data_format(s, 16) == SANE_STATUS_GOOD) - e2_add_depth(dev, 16); + /* add default depth */ + e2_add_depth(dev, 8); + + if (dev->maxDepth >= 12 || dev->maxDepth == 0) { + if (esci_set_data_format(s, 12) == SANE_STATUS_GOOD) + e2_add_depth(dev, 12); } if (dev->maxDepth >= 14 || dev->maxDepth == 0) { @@ -781,14 +806,11 @@ e2_discover_capabilities(Epson_Scanner *s) e2_add_depth(dev, 14); } - if (dev->maxDepth >= 12 || dev->maxDepth == 0) { - if (esci_set_data_format(s, 12) == SANE_STATUS_GOOD) - e2_add_depth(dev, 12); + if (dev->maxDepth >= 16 || dev->maxDepth == 0) { + if (esci_set_data_format(s, 16) == SANE_STATUS_GOOD) + e2_add_depth(dev, 16); } - /* add default depth */ - e2_add_depth(dev, 8); - DBG(1, "maximum supported color depth: %d\n", dev->maxDepth); /* @@ -901,25 +923,28 @@ e2_set_extended_scanning_parameters(Epson_Scanner * s) char extensionCtrl; extensionCtrl = (s->hw->use_extension ? 1 : 0); - if (s->hw->use_extension && (s->val[OPT_ADF_MODE].w == 1)) + if (s->hw->use_extension && (s->val[OPT_ADF_MODE].w == 1)) { extensionCtrl = 2; + } /* Test for TPU2 * Epson Perfection 4990 Command Specifications * JZIS-0075 Rev. A, page 31 */ - if (s->hw->use_extension && s->hw->TPU2) + if (s->hw->use_extension && s->hw->TPU2) { extensionCtrl = 5; + } - if (s->val[OPT_MODE].w == MODE_INFRARED) + if (s->val[OPT_MODE].w == MODE_INFRARED) { /* only infrared in TPU mode (NOT in TPU2 or flatbeth) * XXX investigate this ... only tested on GT-X800 */ if (extensionCtrl == 1) /* test for TPU */ - extensionCtrl = 3; + extensionCtrl = 3; else - return SANE_STATUS_UNSUPPORTED; + return SANE_STATUS_UNSUPPORTED; + } /* ESC e */ buf[26] = extensionCtrl; @@ -1262,7 +1287,7 @@ e2_setup_block_mode(Epson_Scanner * s) DBG(1, "max req size: %d, line count: %d\n", maxreq, s->lcount); /* XXX investigate this */ - if (s->lcount < 3 && (e2_model(s, "GT-X800") || e2_model(s, "GT-X900"))) { + if (s->lcount < 3 && (e2_model(s, "GT-X800") || e2_model(s, "GT-X900") || e2_model(s, "GT-X980"))) { s->lcount = 21; DBG(17, "%s: set lcount = %i bigger than sanei_scsi_max_request_size\n", @@ -1689,10 +1714,6 @@ e2_scan_finish(Epson_Scanner * s) if (s->hw->ADF && s->hw->use_extension && s->val[OPT_AUTO_EJECT].w) if (e2_check_adf(s) == SANE_STATUS_NO_DOCS) esci_eject(s); - - /* XXX required? */ - if (s->hw->connection != SANE_EPSON_NET) - esci_reset(s); } void @@ -1738,6 +1759,8 @@ e2_ext_read(struct Epson_Scanner *s) SANE_Status status = SANE_STATUS_GOOD; ssize_t buf_len = 0, read; + DBG(18, "%s: begin\n", __func__); + /* did we passed everything we read to sane? */ if (s->ptr == s->end) { @@ -1761,10 +1784,12 @@ e2_ext_read(struct Epson_Scanner *s) /* receive image data + error code */ read = e2_recv(s, s->buf, buf_len + 1, &status); - DBG(18, "%s: read %lu bytes\n", __func__, (unsigned long) read); + DBG(18, "%s: read %lu bytes, status: %d\n", __func__, (unsigned long) read, status); - if (read != buf_len + 1) - return SANE_STATUS_IO_ERROR; + if (status != SANE_STATUS_GOOD) { + e2_cancel(s); + return status; + } if (e2_dev_model(dev, "GT-8200") || e2_dev_model(dev, "Perfection1650")) { /* See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=597922#127 */ @@ -2132,6 +2157,7 @@ e2_block_read(struct Epson_Scanner *s) * RGB then swap the colors. */ + /* never used, beta testers required */ needStrangeReorder = (strstr(s->hw->model, "GT-2200") || ((strstr(s->hw->model, "1640") diff --git a/backend/epson2-ops.h b/backend/epson2-ops.h index 9c36326..decbd4b 100644 --- a/backend/epson2-ops.h +++ b/backend/epson2-ops.h @@ -33,6 +33,7 @@ extern SANE_Status e2_add_resolution(Epson_Device *dev, int r); extern void e2_set_fbf_area(Epson_Scanner *s, int x, int y, int unit); extern void e2_set_adf_area(struct Epson_Scanner *s, int x, int y, int unit); extern void e2_set_tpu_area(struct Epson_Scanner *s, int x, int y, int unit); +extern void e2_set_tpu2_area(struct Epson_Scanner *s, int x, int y, int unit); extern void e2_add_depth(Epson_Device *dev, SANE_Word depth); extern SANE_Status e2_discover_capabilities(Epson_Scanner *s); extern SANE_Status e2_set_extended_scanning_parameters(Epson_Scanner *s); diff --git a/backend/epson2.c b/backend/epson2.c index 9f39c68..df84b1d 100644 --- a/backend/epson2.c +++ b/backend/epson2.c @@ -29,6 +29,7 @@ * 20 usb cmd counters * 18 sane_read * 17 setvalue, getvalue, control_option + * 16 gamma table * 15 e2_send, e2_recv calls * 13 e2_cmd_info_block * 12 epson_cmd_simple @@ -355,10 +356,12 @@ print_params(const SANE_Parameters params) static void close_scanner(Epson_Scanner *s) { + int i; + DBG(7, "%s: fd = %d\n", __func__, s->fd); if (s->fd == -1) - return; + goto free; /* send a request_status. This toggles w_cmd_count and r_cmd_count */ if (r_cmd_count % 2) @@ -380,6 +383,14 @@ close_scanner(Epson_Scanner *s) } s->fd = -1; + +free: + for (i = 0; i < LINES_SHUFFLE_MAX; i++) { + if (s->line_buffer[i] != NULL) + free(s->line_buffer[i]); + } + + free(s); } static void @@ -409,8 +420,8 @@ e2_network_discovery(void) FD_SET(fd, &rfds); sanei_udp_set_nonblock(fd, SANE_TRUE); - if (select(fd + 1, &rfds, NULL, NULL, &to) > 0) { - while ((len = sanei_udp_recvfrom(fd, buf, 76, &ip)) == 76) { + while (select(fd + 1, &rfds, NULL, NULL, &to) > 0) { + if ((len = sanei_udp_recvfrom(fd, buf, 76, &ip)) == 76) { DBG(5, " response from %s\n", ip); /* minimal check, protocol unknown */ @@ -576,12 +587,12 @@ static SANE_Status detect_scsi(struct Epson_Scanner *s) } static SANE_Status -detect_usb(struct Epson_Scanner *s) +detect_usb(struct Epson_Scanner *s, SANE_Bool assume_valid) { SANE_Status status; int vendor, product; int i, numIds; - SANE_Bool is_valid; + SANE_Bool is_valid = assume_valid; /* if the sanei_usb_get_vendor_product call is not supported, * then we just ignore this and rely on the user to config @@ -603,19 +614,20 @@ detect_usb(struct Epson_Scanner *s) } numIds = sanei_epson_getNumberOfUSBProductIds(); - is_valid = SANE_FALSE; i = 0; /* check all known product IDs to verify that we know about the device */ - while (i != numIds && !is_valid) { - if (product == sanei_epson_usb_product_ids[i]) + while (i != numIds) { + if (product == sanei_epson_usb_product_ids[i]) { is_valid = SANE_TRUE; + break; + } i++; } if (is_valid == SANE_FALSE) { - DBG(1, "the device at %s is not a supported (product id=0x%x)\n", + DBG(1, "the device at %s is not supported (product id=0x%x)\n", s->hw->sane.name, product); return SANE_STATUS_INVAL; } @@ -649,7 +661,7 @@ scanner_create(struct Epson_Device *dev, SANE_Status *status) } static struct Epson_Scanner * -device_detect(const char *name, int type, SANE_Status *status) +device_detect(const char *name, int type, SANE_Bool assume_valid, SANE_Status *status) { struct Epson_Scanner *s; struct Epson_Device *dev; @@ -702,7 +714,7 @@ device_detect(const char *name, int type, SANE_Status *status) } else if (dev->connection == SANE_EPSON_USB) { - *status = detect_usb(s); + *status = detect_usb(s, assume_valid); } if (*status != SANE_STATUS_GOOD) @@ -748,7 +760,6 @@ device_detect(const char *name, int type, SANE_Status *status) close: close_scanner(s); - free(s); return NULL; } @@ -761,12 +772,11 @@ attach(const char *name, int type) DBG(7, "%s: devname = %s, type = %d\n", __func__, name, type); - s = device_detect(name, type, &status); + s = device_detect(name, type, 0, &status); if(s == NULL) return status; close_scanner(s); - free(s); return status; } @@ -813,6 +823,7 @@ attach_one_config(SANEI_Config __sane_unused__ *config, const char *line) DBG(7, "%s: len = %d, line = %s\n", __func__, len, line); if (sscanf(line, "usb %i %i", &vendor, &product) == 2) { + /* add the vendor and product IDs to the list of known devices before we call the attach function */ @@ -976,10 +987,10 @@ init_options(Epson_Scanner *s) s->opt[OPT_MODE].size = max_string_size(mode_list); s->opt[OPT_MODE].constraint_type = SANE_CONSTRAINT_STRING_LIST; s->opt[OPT_MODE].constraint.string_list = mode_list; - s->val[OPT_MODE].w = 0; /* Binary */ + s->val[OPT_MODE].w = 0; /* Lineart */ /* disable infrared on unsupported scanners */ - if (!e2_model(s, "GT-X800") && !e2_model(s, "GT-X700") && !e2_model(s, "GT-X900")) + if (!e2_model(s, "GT-X800") && !e2_model(s, "GT-X700") && !e2_model(s, "GT-X900") && !e2_model(s, "GT-X980")) mode_list[MODE_INFRARED] = NULL; /* bit depth */ @@ -987,14 +998,13 @@ init_options(Epson_Scanner *s) s->opt[OPT_BIT_DEPTH].title = SANE_TITLE_BIT_DEPTH; s->opt[OPT_BIT_DEPTH].desc = SANE_DESC_BIT_DEPTH; s->opt[OPT_BIT_DEPTH].type = SANE_TYPE_INT; - s->opt[OPT_BIT_DEPTH].unit = SANE_UNIT_NONE; + s->opt[OPT_BIT_DEPTH].unit = SANE_UNIT_BIT; s->opt[OPT_BIT_DEPTH].constraint_type = SANE_CONSTRAINT_WORD_LIST; s->opt[OPT_BIT_DEPTH].constraint.word_list = s->hw->depth_list; - s->opt[OPT_BIT_DEPTH].cap |= SANE_CAP_INACTIVE; - s->val[OPT_BIT_DEPTH].w = s->hw->depth_list[1]; /* the first "real" element is the default */ + s->val[OPT_BIT_DEPTH].w = 8; /* default to 8 bit */ - if (s->hw->depth_list[0] == 1) /* only one element in the list -> hide the option */ - s->opt[OPT_BIT_DEPTH].cap |= SANE_CAP_INACTIVE; + /* default is Lineart, disable depth selection */ + s->opt[OPT_BIT_DEPTH].cap |= SANE_CAP_INACTIVE; /* halftone */ s->opt[OPT_HALFTONE].name = SANE_NAME_HALFTONE; @@ -1456,6 +1466,8 @@ sane_open(SANE_String_Const name, SANE_Handle *handle) DBG(7, "%s: name = %s\n", __func__, name); + *handle = NULL; + /* probe if empty device name provided */ if (l == 0) { @@ -1467,7 +1479,7 @@ sane_open(SANE_String_Const name, SANE_Handle *handle) } s = device_detect(first_dev->sane.name, first_dev->connection, - &status); + 0, &status); if (s == NULL) { DBG(1, "cannot open a perfectly valid device (%s)," " please report to the authors\n", name); @@ -1477,15 +1489,15 @@ sane_open(SANE_String_Const name, SANE_Handle *handle) } else { if (strncmp(name, "net:", 4) == 0) { - s = device_detect(name, SANE_EPSON_NET, &status); + s = device_detect(name, SANE_EPSON_NET, 0, &status); if (s == NULL) return status; } else if (strncmp(name, "libusb:", 7) == 0) { - s = device_detect(name, SANE_EPSON_USB, &status); + s = device_detect(name, SANE_EPSON_USB, 1, &status); if (s == NULL) return status; } else if (strncmp(name, "pio:", 4) == 0) { - s = device_detect(name, SANE_EPSON_PIO, &status); + s = device_detect(name, SANE_EPSON_PIO, 0, &status); if (s == NULL) return status; } else { @@ -1498,7 +1510,7 @@ sane_open(SANE_String_Const name, SANE_Handle *handle) if (first_dev == NULL) probe_devices(); - s = device_detect(name, SANE_EPSON_NODEV, &status); + s = device_detect(name, SANE_EPSON_NODEV, 0, &status); if (s == NULL) { DBG(1, "invalid device name: %s\n", name); return SANE_STATUS_INVAL; @@ -1513,8 +1525,6 @@ sane_open(SANE_String_Const name, SANE_Handle *handle) init_options(s); - *handle = (SANE_Handle) s; - status = open_scanner(s); if (status != SANE_STATUS_GOOD) { free(s); @@ -1522,18 +1532,23 @@ sane_open(SANE_String_Const name, SANE_Handle *handle) } status = esci_reset(s); - if (status != SANE_STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { close_scanner(s); + return status; + } + + *handle = (SANE_Handle)s; - return status; + return SANE_STATUS_GOOD; } void sane_close(SANE_Handle handle) { - int i; Epson_Scanner *s; + DBG(1, "* %s\n", __func__); + /* * XXX Test if there is still data pending from * the scanner. If so, then do a cancel @@ -1541,15 +1556,7 @@ sane_close(SANE_Handle handle) s = (Epson_Scanner *) handle; - if (s->fd != -1) - close_scanner(s); - - for (i = 0; i < LINES_SHUFFLE_MAX; i++) { - if (s->line_buffer[i] != NULL) - free(s->line_buffer[i]); - } - - free(s); + close_scanner(s); } const SANE_Option_Descriptor * @@ -1752,8 +1759,9 @@ change_source(Epson_Scanner *s, SANE_Int optindex, char *value) s->val[OPT_ADF_MODE].w = 0; } - DBG(1, "adf activated (%d %d)\n", s->hw->use_extension, - s->hw->duplex); + DBG(1, "adf activated (ext: %d, duplex: %d)\n", + s->hw->use_extension, + s->hw->duplex); } else if (strcmp(TPU_STR, value) == 0 || strcmp(TPU_STR2, value) == 0) { if (strcmp(TPU_STR, value) == 0) { @@ -1907,6 +1915,8 @@ setvalue(SANE_Handle handle, SANE_Int option, void *value, SANE_Int *info) sval->w = optindex; + DBG(17, "%s: setting mode to %d\n", __func__, optindex); + /* halftoning available only on bw scans */ if (s->hw->cmd->set_halftoning != 0) setOptionState(s, mode_params[optindex].depth == 1, @@ -1921,16 +1931,18 @@ setvalue(SANE_Handle handle, SANE_Int option, void *value, SANE_Int *info) /* if binary, then disable the bit depth selection */ if (optindex == 0) { + DBG(17, "%s: disabling bit depth selection\n", __func__); s->opt[OPT_BIT_DEPTH].cap |= SANE_CAP_INACTIVE; } else { - if (s->hw->depth_list[0] == 1) - s->opt[OPT_BIT_DEPTH].cap |= - SANE_CAP_INACTIVE; - else { - s->opt[OPT_BIT_DEPTH].cap &= - ~SANE_CAP_INACTIVE; - s->val[OPT_BIT_DEPTH].w = - mode_params[optindex].depth; + if (s->hw->depth_list[0] == 1) { + DBG(17, "%s: only one depth is available\n", __func__); + s->opt[OPT_BIT_DEPTH].cap |= SANE_CAP_INACTIVE; + } else { + + DBG(17, "%s: enabling bit depth selection\n", __func__); + + s->opt[OPT_BIT_DEPTH].cap &= ~SANE_CAP_INACTIVE; + s->val[OPT_BIT_DEPTH].w = mode_params[optindex].depth; } } @@ -2075,7 +2087,10 @@ sane_start(SANE_Handle handle) Epson_Device *dev = s->hw; SANE_Status status; - DBG(5, "%s\n", __func__); + DBG(5, "* %s\n", __func__); + + s->eof = SANE_FALSE; + s->canceling = SANE_FALSE; /* check if we just have finished working with the ADF */ status = e2_check_adf(s); @@ -2200,9 +2215,7 @@ sane_start(SANE_Handle handle) if (s->buf == NULL) return SANE_STATUS_NO_MEM; - s->eof = SANE_FALSE; s->ptr = s->end = s->buf; - s->canceling = SANE_FALSE; /* feed the first sheet in the ADF */ if (dev->ADF && dev->use_extension && dev->cmd->feed) { @@ -2273,8 +2286,14 @@ sane_read(SANE_Handle handle, SANE_Byte *data, SANE_Int max_length, SANE_Status status; Epson_Scanner *s = (Epson_Scanner *) handle; - if (s->buf == NULL || s->canceling) - return SANE_STATUS_CANCELLED; + DBG(18, "* %s: eof: %d, canceling: %d\n", + __func__, s->eof, s->canceling); + + /* sane_read called before sane_start? */ + if (s->buf == NULL) { + DBG(1, "%s: buffer is NULL", __func__); + return SANE_STATUS_INVAL; + } *length = 0; @@ -2283,9 +2302,12 @@ sane_read(SANE_Handle handle, SANE_Byte *data, SANE_Int max_length, else status = e2_block_read(s); - if (status == SANE_STATUS_CANCELLED) { + /* The scanning operation might be canceled by the scanner itself + * or the fronted program + */ + if (status == SANE_STATUS_CANCELLED || s->canceling) { e2_scan_finish(s); - return status; + return SANE_STATUS_CANCELLED; } /* XXX if FS G and STATUS_IOERR, use e2_check_extended_status */ @@ -2296,9 +2318,9 @@ sane_read(SANE_Handle handle, SANE_Byte *data, SANE_Int max_length, e2_copy_image_data(s, data, max_length, length); - DBG(18, "%d lines read, eof: %d, status: %d\n", + DBG(18, "%d lines read, eof: %d, canceling: %d, status: %d\n", *length / s->params.bytes_per_line, - s->eof, status); + s->canceling, s->eof, status); /* continue reading if appropriate */ if (status == SANE_STATUS_GOOD) @@ -2321,6 +2343,8 @@ sane_cancel(SANE_Handle handle) { Epson_Scanner *s = (Epson_Scanner *) handle; + DBG(1, "* %s\n", __func__); + s->canceling = SANE_TRUE; } diff --git a/backend/epson2.conf.in b/backend/epson2.conf.in index a996487..797df2d 100644 --- a/backend/epson2.conf.in +++ b/backend/epson2.conf.in @@ -16,7 +16,7 @@ scsi EPSON usb # For libusb support for unknown scanners use the following command -# usb <product ID> <device ID> +# usb <vendor ID> <product ID> # e.g.: # usb 0x4b8 0x110 diff --git a/backend/epson2.h b/backend/epson2.h index bb6c9e0..8650f01 100644 --- a/backend/epson2.h +++ b/backend/epson2.h @@ -346,7 +346,7 @@ struct Epson_Device SANE_Bool color_shuffle; /* does this scanner need color shuffling */ SANE_Int maxDepth; /* max. color depth */ - SANE_Word *depth_list; + SANE_Int *depth_list; SANE_Int optical_res; /* optical resolution */ SANE_Int max_line_distance; diff --git a/backend/epson2_net.c b/backend/epson2_net.c index c7b4873..911ce62 100644 --- a/backend/epson2_net.c +++ b/backend/epson2_net.c @@ -15,6 +15,10 @@ #include "sane/config.h" +#ifdef HAVE_SYS_SELECT_H +#include <sys/select.h> +#endif + #include "sane/sane.h" #include "sane/saneopts.h" #include "sane/sanei_tcp.h" @@ -28,25 +32,32 @@ #include "sane/sanei_debug.h" -int -sanei_epson_net_read_raw(Epson_Scanner *s, unsigned char *buf, size_t wanted, - SANE_Status * status) +static int +sanei_epson_net_read_raw(Epson_Scanner *s, unsigned char *buf, ssize_t wanted, + SANE_Status *status) { - size_t size, read = 0; + int ready, read = -1; + fd_set readable; + struct timeval tv; - *status = SANE_STATUS_GOOD; - - while (read < wanted) { - size = sanei_tcp_read(s->fd, buf + read, wanted - read); + tv.tv_sec = 10; + tv.tv_usec = 0; - if (size == 0) - break; + FD_ZERO(&readable); + FD_SET(s->fd, &readable); - read += size; + ready = select(s->fd + 1, &readable, NULL, NULL, &tv); + if (ready > 0) { + read = sanei_tcp_read(s->fd, buf, wanted); + } else { + DBG(15, "%s: select failed: %d\n", __func__, ready); } - if (read < wanted) + *status = SANE_STATUS_GOOD; + + if (read < wanted) { *status = SANE_STATUS_IO_ERROR; + } return read; } @@ -80,9 +91,8 @@ sanei_epson_net_read(Epson_Scanner *s, unsigned char *buf, ssize_t wanted, } /* receive net header */ - size = sanei_tcp_read(s->fd, header, 12); + size = sanei_epson_net_read_raw(s, header, 12, status); if (size != 12) { - *status = SANE_STATUS_IO_ERROR; return 0; } @@ -102,7 +112,8 @@ sanei_epson_net_read(Epson_Scanner *s, unsigned char *buf, ssize_t wanted, if (size == wanted) { DBG(15, "%s: full read\n", __func__); - read = sanei_tcp_read(s->fd, buf, size); + + read = sanei_epson_net_read_raw(s, buf, size, status); if (s->netbuf) { free(s->netbuf); @@ -111,7 +122,6 @@ sanei_epson_net_read(Epson_Scanner *s, unsigned char *buf, ssize_t wanted, } if (read < 0) { - *status = SANE_STATUS_IO_ERROR; return 0; } @@ -119,9 +129,8 @@ sanei_epson_net_read(Epson_Scanner *s, unsigned char *buf, ssize_t wanted, } else { DBG(23, "%s: partial read\n", __func__); - read = sanei_tcp_read(s->fd, s->netbuf, size); + read = sanei_epson_net_read_raw(s, s->netbuf, size, status); if (read != size) { - *status = SANE_STATUS_IO_ERROR; return 0; } diff --git a/backend/epson2_net.h b/backend/epson2_net.h index 6a6e8d8..6aef2b7 100644 --- a/backend/epson2_net.h +++ b/backend/epson2_net.h @@ -9,9 +9,6 @@ extern int sanei_epson_net_read(struct Epson_Scanner *s, unsigned char *buf, ssi extern int sanei_epson_net_write(struct Epson_Scanner *s, unsigned int cmd, const unsigned char *buf, size_t buf_size, size_t reply_len, SANE_Status *status); -extern int -sanei_epson_net_read_raw(Epson_Scanner *s, unsigned char *buf, size_t wanted, - SANE_Status * status); extern SANE_Status sanei_epson_net_lock(struct Epson_Scanner *s); extern SANE_Status sanei_epson_net_unlock(struct Epson_Scanner *s); diff --git a/backend/epson2_usb.c b/backend/epson2_usb.c new file mode 100644 index 0000000..8e29943 --- /dev/null +++ b/backend/epson2_usb.c @@ -0,0 +1,182 @@ +#include <sys/types.h> +#include "../include/sane/sanei_usb.h" +#include "epson_usb.h" + +/* generated with epson2usb.pl doc/descriptions/epson2.desc */ + +SANE_Word sanei_epson_usb_product_ids[] = { + 0x101, /* GT-7000U, Perfection 636U */ + 0x103, /* GT-6600U, Perfection 610 */ + 0x104, /* GT-7600U, GT-7600UF, Perfection 1200U, Perfection 1200U PHOTO */ + 0x105, /* Stylus Scan 2000 */ + 0x106, /* Stylus Scan 2500 */ + 0x107, /* ES-2000, Expression 1600 */ + 0x109, /* ES-8500, Expression 1640XL */ + 0x10a, /* GT-8700, GT-8700F, Perfection 1640SU, Perfection 1640SU PHOTO */ + 0x10b, /* GT-7700U, Perfection 1240U */ + 0x10c, /* GT-6700U, Perfection 640U */ + 0x10e, /* ES-2200, Expression 1680 */ + 0x110, /* GT-8200U, GT-8200UF, Perfection 1650, Perfection 1650 PHOTO */ + 0x112, /* GT-9700F, Perfection 2450 PHOTO */ + 0x11b, /* GT-9300UF, Perfection 2400 PHOTO */ + 0x11c, /* GT-9800F, Perfection 3200 PHOTO */ + 0x11e, /* GT-8300UF, Perfection 1660 PHOTO */ + 0x126, /* ES-7000H, GT-15000 */ + 0x128, /* GT-X700, Perfection 4870 PHOTO */ + 0x129, /* ES-10000G, Expression 10000XL */ + 0x12a, /* GT-X800, Perfection 4990 PHOTO */ + 0x12b, /* ES-H300, GT-2500 */ + 0x12c, /* GT-X900, Perfection V700 Photo, Perfection V750 Photo */ + 0x135, /* GT-X970 */ + 0x138, /* ES-H7200, GT-20000 */ + 0x14b, /* ES-G11000, Expression 11000XL */ + 0x151, /* GT-X980, Perfection V800 Photo, Perfection V850 Pro */ + 0x801, /* CC-600PX, Stylus CX5100, Stylus CX5200 */ + 0x802, /* CC-570L, Stylus CX3100, Stylus CX3200 */ + 0x805, /* Stylus CX6300, Stylus CX6400 */ + 0x806, /* PM-A850, Stylus Photo RX600 */ + 0x807, /* Stylus Photo RX500, Stylus Photo RX510 */ + 0x808, /* Stylus CX5300, Stylus CX5400 */ + 0x80d, /* Stylus CX4500, Stylus CX4600 */ + 0x80e, /* PX-A550, Stylus CX3500, Stylus CX3600, Stylus CX3650 */ + 0x80f, /* Stylus Photo RX420, Stylus Photo RX425, Stylus Photo RX430 */ + 0x810, /* PM-A900, Stylus Photo RX700 */ + 0x811, /* PM-A870, Stylus Photo RX620, Stylus Photo RX630 */ + 0x813, /* Stylus CX6500, Stylus CX6600 */ + 0x814, /* PM-A700 */ + 0x815, /* AcuLaser CX11, AcuLaser CX11NF, LP-A500 */ + 0x817, /* LP-M5500, LP-M5500F */ + 0x818, /* Stylus CX3700, Stylus CX3800, Stylus CX3810, Stylus DX3800 */ + 0x819, /* PX-A650, Stylus CX4700, Stylus CX4800, Stylus DX4800, Stylus DX4850 */ + 0x81a, /* PM-A750, Stylus Photo RX520, Stylus Photo RX530 */ + 0x81c, /* PM-A890, Stylus Photo RX640, Stylus Photo RX650 */ + 0x81d, /* PM-A950 */ + 0x81f, /* Stylus CX7700, Stylus CX7800 */ + 0x820, /* Stylus CX4100, Stylus CX4200, Stylus DX4200 */ + 0x827, /* PM-A820, Stylus Photo RX560, Stylus Photo RX580, Stylus Photo RX590 */ + 0x828, /* PM-A970 */ + 0x829, /* PM-T990 */ + 0x82a, /* PM-A920 */ + 0x82b, /* Stylus CX4900, Stylus CX5000, Stylus DX5000 */ + 0x82e, /* PX-A720, Stylus CX5900, Stylus CX6000, Stylus DX6000 */ + 0x82f, /* PX-A620, Stylus CX3900, Stylus DX4000 */ + 0x830, /* ME 200, Stylus CX2800, Stylus CX2900 */ + 0x833, /* LP-M5600 */ + 0x834, /* LP-M6000 */ + 0x835, /* AcuLaser CX21 */ + 0x836, /* PM-T960 */ + 0x837, /* PM-A940, Stylus Photo RX680, Stylus Photo RX685, Stylus Photo RX690 */ + 0x838, /* PX-A640, Stylus CX7300, Stylus CX7400, Stylus DX7400 */ + 0x839, /* PX-A740, Stylus CX8300, Stylus CX8400, Stylus DX8400 */ + 0x83a, /* PX-FA700, Stylus CX9300F, Stylus CX9400Fax, Stylus DX9400F */ + 0x83c, /* PM-A840, PM-A840S, Stylus Photo RX585, Stylus Photo RX595, Stylus Photo RX610 */ + 0x841, /* ME 300, PX-401A, Stylus NX100, Stylus SX100, Stylus TX100 */ + 0x843, /* LP-M5000 */ + 0x844, /* Artisan 800, EP-901A, EP-901F, Stylus Photo PX800FW, Stylus Photo TX800FW */ + 0x846, /* Artisan 700, EP-801A, Stylus Photo PX700W, Stylus Photo TX700W */ + 0x847, /* ME Office 700FW, PX-601F, Stylus Office BX600FW, Stylus Office TX600FW, Stylus SX600FW, WorkForce 600 */ + 0x848, /* ME Office 600F, Stylus Office BX300F, Stylus Office TX300F, Stylus NX300 Series */ + 0x849, /* Stylus NX200, Stylus SX200, Stylus SX205, Stylus TX200, Stylus TX203, Stylus TX209 */ + 0x84a, /* PX-501A, Stylus NX400, Stylus SX400, Stylus SX405, Stylus TX400 */ + 0x84c, /* WorkForce 500 */ + 0x84d, /* PX-402A, Stylus NX110 Series, Stylus SX110 Series, Stylus TX110 Series */ + 0x84f, /* ME OFFICE 510, Stylus NX210 Series, Stylus SX210 Series, Stylus TX210 Series */ + 0x850, /* EP-702A, Stylus Photo PX650 Series, Stylus Photo TX650 Series */ + 0x851, /* Stylus NX410 Series, Stylus SX410 Series, Stylus TX410 Series */ + 0x852, /* Artisan 710 Series, EP-802A, Stylus Photo PX710W Series, Stylus Photo TX710W Series */ + 0x853, /* Artisan 810 Series, EP-902A, Stylus Photo PX810FW Series */ + 0x854, /* ME OFFICE 650FN Series, Stylus Office BX310FN Series, Stylus Office TX510FN Series, WorkForce 310 Series */ + 0x855, /* PX-602F, Stylus Office BX610FW Series, Stylus Office TX610FW Series, Stylus SX610FW Series, WorkForce 610 Series */ + 0x856, /* PX-502A, Stylus NX510 Series, Stylus SX510W Series, Stylus TX550W Series */ + 0x85c, /* ME 320 Series, ME 330 Series, Stylus NX125, Stylus NX127, Stylus SX125, Stylus TX120 Series */ + 0x85d, /* ME OFFICE 960FWD Series, PX-603F, Stylus Office BX625FWD, Stylus Office TX620FWD Series, Stylus SX620FW Series, WorkForce 630 Series */ + 0x85e, /* ME OFFICE 900WD Series, PX-503A, Stylus Office BX525WD, Stylus NX625, Stylus SX525WD, Stylus TX560WD Series, WorkForce 625 */ + 0x85f, /* Stylus Office BX320FW Series, Stylus Office TX525FW, WorkForce 520 Series */ + 0x860, /* Artisan 835, EP-903A, EP-903F, Stylus Photo PX820FWD Series, Stylus Photo TX820FWD Series */ + 0x861, /* Artisan 725, EP-803A, EP-803AW, Stylus Photo PX720WD Series, Stylus Photo TX720WD Series */ + 0x862, /* EP-703A, Stylus Photo PX660 Series */ + 0x863, /* ME OFFICE 620F Series, Stylus Office BX305F, Stylus Office BX305FW, Stylus Office TX320F Series, WorkForce 320 Series */ + 0x864, /* ME OFFICE 560W Series, Stylus NX420 Series, Stylus SX420W Series, Stylus TX420W Series */ + 0x865, /* ME OFFICE 520 Series, Stylus NX220 Series, Stylus SX218, Stylus TX220 Series */ + 0x866, /* AcuLaser MX20DN, AcuLaser MX20DNF, AcuLaser MX21DNF */ + 0x869, /* PX-1600F, WF-7510 Series */ + 0x86a, /* PX-673F, Stylus Office BX925FWD, WorkForce 840 Series */ + 0x870, /* Stylus Office BX305FW Plus, WorkForce 435 */ + 0x871, /* K200 Series */ + 0x872, /* K300 Series, WorkForce K301 */ + 0x873, /* L200 Series */ + 0x878, /* Artisan 635, EP-704A */ + 0x879, /* Artisan 837, EP-904A, EP-904F, Stylus Photo PX830FWD Series */ + 0x87b, /* Artisan 730 Series, EP-804A, EP-804AR, EP-804AW, Stylus Photo PX730WD Series, Stylus Photo TX730WD Series */ + 0x87c, /* PX-1700F, WF-7520 Series */ + 0x87d, /* PX-B750F, WP-4511, WP-4515, WP-4521, WP-4525, WP-4530 Series, WP-4540 Series */ + 0x87e, /* WP-4590 Series */ + 0x87f, /* PX-403A */ + 0x880, /* ME OFFICE 570W Series, PX-434A, Stylus NX330 Series, Stylus SX430W Series, Stylus TX430W Series */ + 0x881, /* ME OFFICE 535, PX-404A, Stylus SX230 Series, Stylus TX235 */ + 0x883, /* ME 340 Series, Stylus NX130 Series, Stylus SX130 Series, Stylus TX130 Series */ + 0x884, /* Stylus NX430W Series, Stylus SX440W Series, Stylus TX435W */ + 0x885, /* Stylus NX230 Series, Stylus SX235W, Stylus TX230W Series */ + 0x88d, /* Epson ME 350 */ + 0x88f, /* Stylus Office BX635FWD, WorkForce 645 */ + 0x890, /* ME OFFICE 940FW Series, Stylus Office BX630FW Series, WorkForce 545 */ + 0x891, /* PX-504A, Stylus Office BX535WD, Stylus NX530 Series, Stylus NX635, Stylus SX535WD */ + 0x892, /* Stylus Office BX935FWD, WorkForce 845 */ + 0x893, /* EP-774A */ + 0x894, /* LP-M5300 Series */ + 0x895, /* PX-045A, XP-100 Series */ + 0x896, /* ME-301, XP-200 Series */ + 0x897, /* ME-303, PX-405A */ + 0x898, /* ME-401, PX-435A, XP-300 Series, XP-400 Series */ + 0x899, /* PX-605F, PX-675F, WF-3520 Series, WF-3530 Series, WF-3540 Series */ + 0x89a, /* EP-905F, XP-850 Series */ + 0x89b, /* EP-905A, XP-800 Series */ + 0x89c, /* EP-805A, EP-805AR, EP-805AW, XP-750 Series */ + 0x89d, /* XP-700 Series */ + 0x89e, /* EP-775A, EP-775AW, XP-600 Series */ + 0x89f, /* EP-705A */ + 0x8a0, /* ME-101 */ + 0x8a1, /* L210 Series, L350, L351 */ + 0x8a5, /* PX-505F, WF-2510 Series */ + 0x8a6, /* PX-535F, WF-2520 Series, WF-2530 Series, WF-2540 Series */ + 0x8a7, /* WP-M4525, WP-M4521, PX-K751F, WP-M4595 */ + 0x8a8, /* L355, L358 */ + 0x8a9, /* L550 Series */ + 0x8aa, /* M200 Series */ + 0x8ab, /* WF-M1560 Series */ + 0x8ac, /* AL-MX300DN Series, AL-MX300DNF Series */ + 0x8ad, /* LP-M8040, LP-M8040A, LP-M8040F */ + 0x8ae, /* PX-046A, XP-211, XP-212, XP-215 */ + 0x8af, /* PX-436A, XP-310 Series */ + 0x8b0, /* XP-410 Series */ + 0x8b3, /* EP-976A3, XP-950 Series */ + 0x8b4, /* EP-906F, XP-810 Series */ + 0x8b5, /* EP-806AB, EP-806AR, EP-806AW, XP-710 Series */ + 0x8b6, /* EP-776AB, EP-776AW, XP-610 Series */ + 0x8b7, /* EP-706A, XP-510 Series */ + 0x8b8, /* PX-M740F, PX-M741F, WF-3620 Series, WF-3640 Series */ + 0x8b9, /* PX-M5040F, PX-M5041F, WF-7610 Series, WF-7620 Series */ + 0x8bd, /* PX-M840F, WF-5620 Series, WF-5690 Series */ + 0x8be, /* WF-4630 Series, WF-4640 Series */ + 0x8bf, /* PX-437A, XP-320 Series */ + 0x8c0, /* PX-047A, XP-225 */ + 0x8c1, /* XP-420 Series */ + 0x8c3, /* PX-M650A, PX-M650F, WF-2650 Series, WF-2660 Series */ + 0x8c4, /* WF-2630 Series */ + 0x8c5, /* EP-977A3 */ + 0x8c6, /* EP-907F, XP-820 Series, XP-860 Series */ + 0x8c7, /* EP-807AB, EP-807AR, EP-807AW, XP-720 Series, XP-760 Series */ + 0x8c8, /* EP-777A, XP-520 Series, XP-620 Series */ + 0x8c9, /* EP-707A */ + 0x8ca, /* L850 Series */ + 0x8cd, /* WF-R4640 Series, WF-R5690 Series */ + 0x8d0, /* PX-M350F, WF-M5690 Series */ + 0 /* last entry - this is used for devices that are specified + in the config file as "usb <vendor> <product>" */ +}; + +int +sanei_epson_getNumberOfUSBProductIds (void) +{ + return sizeof (sanei_epson_usb_product_ids) / sizeof (SANE_Word); +} diff --git a/backend/epson_usb.c b/backend/epson_usb.c index 848ef63..520b49f 100644 --- a/backend/epson_usb.c +++ b/backend/epson_usb.c @@ -2,86 +2,45 @@ #include "../include/sane/sanei_usb.h" #include "epson_usb.h" -/* generated with epson2usb.pl doc/descriptions/epson2.desc */ +/* generated with epson2usb.pl doc/descriptions/epson.desc */ SANE_Word sanei_epson_usb_product_ids[] = { - 0x101, /* GT-7000U, Perfection 636U */ - 0x103, /* GT-6600U, Perfection 610 */ - 0x104, /* GT-7600U, GT-7600UF, Perfection 1200U, Perfection 1200U PHOTO */ - 0x105, /* Stylus Scan 2000 */ - 0x106, /* Stylus Scan 2500 */ - 0x107, /* ES-2000, Expression 1600 */ - 0x109, /* ES-8500, Expression 1640XL */ - 0x10a, /* GT-8700, GT-8700F, Perfection 1640SU, Perfection 1640SU PHOTO */ - 0x10b, /* GT-7700U, Perfection 1240U */ - 0x10c, /* GT-6700U, Perfection 640U */ - 0x10e, /* ES-2200, Expression 1680 */ - 0x110, /* GT-8200U, GT-8200UF, Perfection 1650, Perfection 1650 PHOTO */ - 0x112, /* GT-9700F, Perfection 2450 PHOTO */ - 0x11b, /* GT-9300UF, Perfection 2400 PHOTO */ - 0x11c, /* GT-9800F, Perfection 3200 PHOTO */ - 0x11e, /* GT-8300UF, Perfection 1660 PHOTO */ - 0x126, /* ES-7000H, GT-15000 */ - 0x128, /* GT-X700, Perfection 4870 PHOTO */ - 0x129, /* ES-10000G, Expression 10000XL */ - 0x12a, /* GT-X800, Perfection 4990 PHOTO */ - 0x12b, /* ES-H300, GT-2500 */ - 0x12c, /* GT-X900, Perfection V700 Photo, Perfection V750 Photo */ - 0x135, /* GT-X970 */ - 0x801, /* CC-600PX, Stylus CX5100, Stylus CX5200 */ - 0x802, /* CC-570L, Stylus CX3100, Stylus CX3200 */ - 0x805, /* Stylus CX6300, Stylus CX6400 */ - 0x806, /* PM-A850, Stylus Photo RX600 */ - 0x807, /* Stylus Photo RX500, Stylus Photo RX510 */ - 0x808, /* Stylus CX5300, Stylus CX5400 */ - 0x80d, /* Stylus CX4500, Stylus CX4600 */ - 0x80e, /* PX-A550, Stylus CX3500, Stylus CX3600, Stylus CX3650 */ - 0x80f, /* Stylus Photo RX420, Stylus Photo RX425, Stylus Photo RX430 */ - 0x810, /* PM-A900, Stylus Photo RX700 */ - 0x811, /* PM-A870, Stylus Photo RX620, Stylus Photo RX630 */ - 0x813, /* Stylus CX6500, Stylus CX6600 */ - 0x814, /* PM-A700 */ - 0x815, /* AcuLaser CX11, AcuLaser CX11NF, LP-A500 */ - 0x817, /* LP-M5500, LP-M5500F */ - 0x818, /* Stylus CX3700, Stylus CX3800, Stylus DX3800 */ - 0x819, /* PX-A650, Stylus CX4700, Stylus CX4800, Stylus DX4800, Stylus DX4850 */ - 0x81a, /* PM-A750, Stylus Photo RX520, Stylus Photo RX530 */ - 0x81c, /* PM-A890, Stylus Photo RX640, Stylus Photo RX650 */ - 0x81d, /* PM-A950 */ - 0x81f, /* Stylus CX7700, Stylus CX7800 */ - 0x820, /* Stylus CX4100, Stylus CX4200, Stylus DX4200 */ - 0x827, /* PM-A820, Stylus Photo RX560, Stylus Photo RX580, Stylus Photo RX590 */ - 0x828, /* PM-A970 */ - 0x829, /* PM-T990 */ - 0x82a, /* PM-A920 */ - 0x82b, /* Stylus CX4900, Stylus CX5000, Stylus DX5000 */ - 0x82e, /* PX-A720, Stylus CX5900, Stylus CX6000, Stylus DX6000 */ - 0x82f, /* PX-A620, Stylus CX3900, Stylus DX4000 */ - 0x830, /* ME 200, Stylus CX2800, Stylus CX2900 */ - 0x833, /* LP-M5600 */ - 0x834, /* LP-M6000 */ - 0x835, /* AcuLaser CX21 */ - 0x836, /* PM-T960 */ - 0x837, /* PM-A940, Stylus Photo RX680, Stylus Photo RX685, Stylus Photo RX690 */ - 0x838, /* PX-A640, Stylus CX7300, Stylus CX7400, Stylus DX7400 */ - 0x839, /* PX-A740, Stylus CX8300, Stylus CX8400, Stylus DX8400 */ - 0x83a, /* PX-FA700, Stylus CX9300F, Stylus CX9400Fax, Stylus DX9400F */ - 0x83c, /* PM-A840, PM-A840S, Stylus Photo RX585, Stylus Photo RX595, Stylus Photo RX610 */ - 0x841, /* ME 300, PX-401A, Stylus NX100, Stylus SX100, Stylus TX100 */ - 0x843, /* LP-M5000 */ - 0x844, /* Artisan 800, EP-901A, EP-901F, Stylus Photo PX800FW, Stylus Photo TX800FW */ - 0x846, /* Artisan 700, EP-801A, Stylus Photo PX700W, Stylus Photo TX700W */ - 0x847, /* ME Office 700FW, PX-601F, Stylus Office BX600FW, Stylus Office TX600FW, Stylus SX600FW, WorkForce 600 */ - 0x848, /* ME Office 600F, Stylus Office BX300F, Stylus Office TX300F, Stylus NX300 */ - 0x849, /* Stylus NX200, Stylus SX200, Stylus SX205, Stylus TX200, Stylus TX203, Stylus TX209 */ - 0x84a, /* PX-501A, Stylus NX400, Stylus SX400, Stylus SX405, Stylus TX400 */ - 0x84c, /* WorkForce 500 */ - 0x84d, /* PX-402A, Stylus NX110 Series, Stylus SX110 Series, Stylus TX110 Series */ - 0x84f, /* ME OFFICE 510, Stylus NX210 Series, Stylus SX210 Series, Stylus TX210 Series */ - 0x851, /* Stylus NX410 Series, Stylus SX410 Series, Stylus TX410 Series */ - 0x854, /* ME OFFICE 650FN Series, Stylus Office BX310FN Series, Stylus Office TX510FN Series, WorkForce 310 Series */ - 0x856, /* PX-502A, Stylus NX510 Series, Stylus SX510W Series, Stylus TX550W Series */ - 0x85c, /* Stylus SX125 */ + 0x101, /* Perfection 636U */ + 0x103, /* Perfection 610 */ + 0x104, /* Perfection 1200U, Perfection 1200Photo */ + 0x107, /* Expression 1600 */ + 0x10a, /* Perfection 1640 */ + 0x10b, /* Perfection 1240 */ + 0x10c, /* Perfection 640 */ + 0x10e, /* Expression 1680 */ + 0x110, /* Perfection 1650 */ + 0x112, /* Perfection 2450 */ + 0x11b, /* Perfection 2400 */ + 0x11c, /* Perfection 3200 */ + 0x11e, /* Perfection 1660 */ + 0x128, /* Perfection 4870 */ + 0x12a, /* Perfection 4990 */ + 0x12c, /* V700, V750 */ + 0x801, /* CX-5200, CX-5400 */ + 0x802, /* CX-3200 */ + 0x805, /* CX-6300, CX-6400 */ + 0x806, /* RX-600 */ + 0x807, /* RX-500 */ + 0x808, /* CX-5400 */ + 0x80d, /* CX-4600 */ + 0x80e, /* CX-3600, CX-3650 */ + 0x80f, /* RX-425 */ + 0x810, /* RX-700 */ + 0x811, /* RX-620 */ + 0x813, /* CX-6500, CX-6600 */ + 0x815, /* AcuLaser CX11, AcuLaser CX11NF */ + 0x818, /* DX-3850, CX-3700, CX-3800, DX-3800 */ + 0x819, /* CX-4800 */ + 0x820, /* CX-4200 */ + 0x82b, /* CX-5000, DX-5000, DX-5050 */ + 0x82e, /* DX-6000 */ + 0x82f, /* DX-4050 */ + 0x838, /* DX-7400 */ 0 /* last entry - this is used for devices that are specified in the config file as "usb <vendor> <product>" */ }; diff --git a/backend/epsonds-cmd.c b/backend/epsonds-cmd.c new file mode 100644 index 0000000..b91f3f1 --- /dev/null +++ b/backend/epsonds-cmd.c @@ -0,0 +1,908 @@ +/* + * epsonds-cmd.c - Epson ESC/I-2 routines. + * + * Copyright (C) 2015 Tower Technologies + * Author: Alessandro Zummo <a.zummo@towertech.it> + * + * This file is part of the SANE package. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, version 2. + */ + +#define DEBUG_DECLARE_ONLY + +#include "sane/config.h" +#include <ctype.h> +#include <unistd.h> /* sleep */ + +#include "epsonds.h" +#include "epsonds-io.h" +#include "epsonds-cmd.h" +#include "epsonds-ops.h" + +static SANE_Status +esci2_parse_block(char *buf, int len, void *userdata, SANE_Status (*cb)(void *userdata, char *token, int len)) +{ + SANE_Status status = SANE_STATUS_GOOD; + SANE_Status delayed_status = SANE_STATUS_GOOD; + + + char *start = buf; + char *end = (buf + len) - 1; + + /* 0 : # + * 1-3: param + * 4- : data + */ + + while (1) { + + char param[4]; + + while (*start != '#' && start < end) + start++; + + if (*start != '#') + break; + + param[0] = *++start; + param[1] = *++start; + param[2] = *++start; + param[3] = '\0'; + + if (strncmp("---", param, 3) == 0) + break; + + /* ugly hack to skip over GMT in RESA */ + if (strncmp("GMT", param, 3) == 0 && *(start + 5) == 'h') { + start = start + 4 + 0x100; + continue; + } + + /* find the end of the token */ + { + int tlen; + char *next = start; + + while (*next != '#' && *next != 0x00 && next < end) + next++; + + tlen = next - start - 1; + + if (cb) { + status = cb(userdata, start - 2, tlen); + if (status != SANE_STATUS_GOOD) { + delayed_status = status; + } + } + + start = next; + } + } + + if (delayed_status != SANE_STATUS_GOOD) + return delayed_status; + + return status; +} + +static SANE_Bool +esci2_check_header(const char *cmd, const char *buf, unsigned int *more) +{ + int err; + + *more = 0; + + if (strncmp(cmd, buf, 4) != 0) { + + if (strncmp("UNKN", buf, 4) == 0) { + DBG(1, "UNKN reply code received\n"); + } else if (strncmp("INVD", buf, 4) == 0) { + DBG(1, "INVD reply code received\n"); + } else { + DBG(1, "%c%c%c%c, unexpected reply code\n", buf[0], buf[1], buf[2], buf[3]); + } + + return 0; + } + + /* INFOx0000100#.... */ + + /* read the answer len */ + if (buf[4] != 'x') { + DBG(1, "unknown type in header: %c\n", buf[4]); + return 0; + } + + err = sscanf(&buf[5], "%x#", more); + if (err != 1) { + DBG(1, "cannot decode length from header\n"); + return 0; + } + + return 1; +} + +static SANE_Status esci2_cmd(epsonds_scanner* s, + char *cmd, size_t len, + char *payload, size_t plen, + void *userdata, SANE_Status (*cb)(void *userdata, char *token, int len)) +{ + SANE_Status status; + unsigned int more; + char rbuf[64]; + + DBG(8, "%s: %4s len %lu, payload len: %lu\n", __func__, cmd, len, plen); + + if (len < 12) { + DBG(1, "%s: command is too short (%lu)\n", __func__, len); + return SANE_STATUS_INVAL; + } + + /* merge the payload size and send the RequestBlock */ + if (payload && plen) { + + sprintf(rbuf, "%4.4sx%07x", cmd, (unsigned int)plen); + + DBG(8, " %s (%lu)\n", rbuf, plen); + + eds_send(s, rbuf, 12, &status); + + } else { + eds_send(s, cmd, len, &status); + } + + if (status != SANE_STATUS_GOOD) { + return status; + } + + /* send ParameterBlock */ + if (payload && plen) { + + eds_send(s, payload, plen, &status); + if (status != SANE_STATUS_GOOD) { + return status; + } + } + + /* receive DataHeaderBlock */ + memset(rbuf, 0x00, sizeof(rbuf)); + + eds_recv(s, rbuf, 64, &status); + if (status != SANE_STATUS_GOOD) { + return status; + } + + /* rxbuf holds the DataHeaderBlock, which should be + * parsed to know if we need to read more data + */ + if (!esci2_check_header(cmd, rbuf, &more)) { + return SANE_STATUS_IO_ERROR; + } + + /* parse the received header block */ + if (cb) { + status = esci2_parse_block(rbuf + 12, 64 - 12, userdata, cb); + if (status != SANE_STATUS_GOOD && status != SANE_STATUS_DEVICE_BUSY) { + DBG(1, "%s: %4s error while parsing received header\n", __func__, cmd); + } + } + + /* header valid, get the data block if present */ + if (more) { + + char *pbuf = malloc(more); + if (pbuf) { + + ssize_t read = eds_recv(s, pbuf, more, &status); + if (read != more) { + } + + /* parse the received data block */ + if (cb) { + status = esci2_parse_block(pbuf, more, userdata, cb); + if (status != SANE_STATUS_GOOD) { + DBG(1, "%s: %4s error while parsing received data block\n", __func__, cmd); + } + } + + free(pbuf); + + } else { + return SANE_STATUS_NO_MEM; + } + } + + return status; +} + +static SANE_Status esci2_cmd_simple(epsonds_scanner* s, char *cmd, SANE_Status (*cb)(void *userdata, char *token, int len)) +{ + return esci2_cmd(s, cmd, 12, NULL, 0, s, cb); +} + +SANE_Status esci2_fin(epsonds_scanner *s) +{ + SANE_Status status; + + DBG(5, "%s\n", __func__); + + status = esci2_cmd_simple(s, "FIN x0000000", NULL); + s->locked = 0; + return status; +} + +SANE_Status esci2_can(epsonds_scanner *s) +{ + return esci2_cmd_simple(s, "CAN x0000000", NULL); +} + +static int decode_value(char *buf, int len) +{ + char tmp[10]; + + memcpy(tmp, buf, len); + tmp[len] = '\0'; + + if (buf[0] == 'd' && len == 4) { + return strtol(buf + 1, NULL, 10); + } else if (buf[0] == 'i' && len == 8) { + return strtol(buf + 1, NULL, 10); + } else if (buf[0] == 'x' && len == 8) { + return strtol(buf + 1, NULL, 16); + } else if (buf[0] == 'h' && len == 4) { + return strtol(buf + 1, NULL, 16); + } + + return -1; +} + +/* h000 */ +static char *decode_binary(char *buf) +{ + char tmp[6]; + int hl; + + memcpy(tmp, buf, 4); + tmp[4] = '\0'; + + if (buf[0] != 'h') + return NULL; + + hl = strtol(tmp + 1, NULL, 16); + if (hl) { + + char *v = malloc(hl + 1); + memcpy(v, buf + 4, hl); + v[hl] = '\0'; + + return v; + } + + return NULL; +} + +static char *decode_string(char *buf) +{ + char *p, *s = decode_binary(buf); + if (s == NULL) + return NULL; + + /* trim white space at the end */ + p = s + strlen(s); + while (*--p == ' ') + *p = '\0'; + + return s; +} + +static void debug_token(int level, const char *func, char *token, int len) +{ + char *tdata = malloc(len + 1); + memcpy(tdata, token + 3, len); + tdata[len] = '\0'; + + DBG(level, "%s: %3.3s / %s / %d\n", func, token, tdata, len); + + free(tdata); +} + +static SANE_Status info_cb(void *userdata, char *token, int len) +{ + epsonds_scanner *s = (epsonds_scanner *)userdata; + char *value; + + if (DBG_LEVEL >= 11) { + debug_token(DBG_LEVEL, __func__, token, len); + } + + /* pointer to the token's value */ + value = token + 3; + + /* nrd / nrdBUSY */ + + if (strncmp("nrd", token, 3) == 0) { + if (strncmp("BUSY", value, 4) == 0) { + return SANE_STATUS_DEVICE_BUSY; + } + } + + if (strncmp("PRD", token, 3) == 0) { + free(s->hw->model); + s->hw->model = decode_string(value); + s->hw->sane.model = s->hw->model; + DBG(1, " product: %s\n", s->hw->model); + /* we will free the string later */ + } + + if (strncmp("VER", token, 3) == 0) { + char *v = decode_string(value); + DBG(1, " version: %s\n", v); + free(v); + } + + if (strncmp("S/N", token, 3) == 0) { + char *v = decode_string(value); + DBG(1, " serial: %s\n", v); + free(v); + } + + if (strncmp("ADF", token, 3) == 0) { + + s->hw->has_adf = 1; + + if (len == 8) { + + if (strncmp("TYPEPAGE", value, len) == 0) { + DBG(1, " ADF: page type\n"); + } + + if (strncmp("TYPEFEED", value, len) == 0) { + DBG(1, " ADF: sheet feed type\n"); + } + + if (strncmp("DPLX1SCN", value, len) == 0) { + DBG(1, " ADF: duplex single pass\n"); + s->hw->adf_singlepass = 1; + } + + if (strncmp("DPLX2SCN", value, len) == 0) { + DBG(1, " ADF: duplex double pass\n"); + s->hw->adf_singlepass = 0; + } + + if (strncmp("FORDPF1N", value, len) == 0) { + DBG(1, " ADF: order is 1 to N\n"); + } + + if (strncmp("FORDPFN1", value, len) == 0) { + DBG(1, " ADF: order is N to 1\n"); + } + + if (strncmp("ALGNLEFT", value, len) == 0) { + DBG(1, " ADF: left aligned\n"); + s->hw->adf_alignment = 0; + } + + if (strncmp("ALGNCNTR", value, len) == 0) { + DBG(1, " ADF: center aligned\n"); + s->hw->adf_alignment = 1; + } + + if (strncmp("ALGNRIGT", value, len) == 0) { + DBG(1, " ADF: right aligned (not supported!)\n"); + s->hw->adf_alignment = 2; + } + } + + if (len == 4) { + + if (strncmp("PREF", value, len) == 0) { + DBG(1, " ADF: auto pre-feed\n"); + } + + if (strncmp("ASCN", value, len) == 0) { + DBG(1, " ADF: auto scan\n"); + } + + if (strncmp("RCVR", value, len) == 0) { + DBG(1, " ADF: auto recovery\n"); + } + } + + if (len == 20) { + + /* ADFAREAi0000850i0001400 */ + + if (strncmp("AREA", value, 4) == 0) { + + int min = decode_value(value + 4, 8); + int max = decode_value(value + 4 + 8, 8); + + DBG(1, " ADF: area %dx%d @ 100dpi\n", min, max); + } + + if (strncmp("AMIN", value, 4) == 0) { + + int min = decode_value(value + 4, 8); + int max = decode_value(value + 4 + 8, 8); + + DBG(1, " ADF: min %dx%d @ 100dpi\n", min, max); + } + + if (strncmp("AMAX", value, 4) == 0) { + + int min = decode_value(value + 4, 8); + int max = decode_value(value + 4 + 8, 8); + + DBG(1, " ADF: max %dx%d @ 100dpi\n", min, max); + + eds_set_adf_area(s->hw, min, max, 100); + } + } + + if (len == 12) { + + /* RESOi0000600 */ + + if (strncmp("RESO", value, 4) == 0) { + + int res = decode_value(value + 4, 8); + + DBG(1, " ADF: basic resolution is %d dpi\n", res); + } + + /* OVSNd025d035 */ + + if (strncmp("OVSN", value, 4) == 0) { + + int x = decode_value(value + 4, 4); + int y = decode_value(value + 4 + 4, 4); + + DBG(1, " ADF: overscan %dx%d @ 100dpi\n", x, y); + } + } + } + + if (strncmp("FB ", token, 3) == 0) { + + s->hw->has_fb = 1; + + if (len == 20) { + + /* AREAi0000850i0001400 */ + if (strncmp("AREA", value, 4) == 0) { + + int min = decode_value(value + 4, 8); + int max = decode_value(value + 4 + 8, 8); + + DBG(1, " FB: area %dx%d @ 100dpi\n", min, max); + + eds_set_fbf_area(s->hw, min, max, 100); + } + } + + if (len == 8) { + + if (strncmp("ALGNLEFT", value, len) == 0) { + DBG(1, " FB: left aligned\n"); + s->hw->fbf_alignment = 0; + } + + if (strncmp("ALGNCNTR", value, len) == 0) { + DBG(1, " FB: center aligned\n"); + s->hw->fbf_alignment = 1; + } + + if (strncmp("ALGNRIGT", value, len) == 0) { + DBG(1, " FB: right aligned (not supported!)\n"); + s->hw->fbf_alignment = 2; + } + } + + if (len == 12) { + + /* RESOi0000600 */ + + if (strncmp("RESO", value, 4) == 0) { + + int res = decode_value(value + 4, 8); + + DBG(1, " FB: basic resolution is %d dpi\n", res); + } + + /* OVSNd025d035 */ + + if (strncmp("OVSN", value, 4) == 0) { + + int x = decode_value(value + 4, 4); + int y = decode_value(value + 4 + 4, 4); + + DBG(1, " FB: overscan %dx%d @ 100dpi\n", x, y); + } + } + + if (len == 4) { + + if (strncmp("DETX", value, len) == 0) { + DBG(1, " FB: paper width detection\n"); + } + + if (strncmp("DETY", value, len) == 0) { + DBG(1, " FB: paper height detection\n"); + } + } + } + + return SANE_STATUS_GOOD; +} + +SANE_Status esci2_info(epsonds_scanner *s) +{ + SANE_Status status; + int i = 4; + + DBG(1, "= gathering device information\n"); + + do { + status = esci2_cmd_simple(s, "INFOx0000000", &info_cb); + if (status == SANE_STATUS_DEVICE_BUSY) { + sleep(2); + } + + i--; + + } while (status == SANE_STATUS_DEVICE_BUSY && i); + + return status; +} + +/* CAPA */ + +static SANE_Status capa_cb(void *userdata, char *token, int len) +{ + epsonds_scanner *s = (epsonds_scanner *)userdata; + + char *value = token + 3; + + if (DBG_LEVEL >= 11) { + debug_token(DBG_LEVEL, __func__, token, len); + } + + if (len == 4) { + + if (strncmp("ADFDPLX", token, 3 + 4) == 0) { + DBG(1, " ADF: duplex\n"); + s->hw->adf_is_duplex = 1; + } + + if (strncmp("ADFSKEW", token, 3 + 4) == 0) { + DBG(1, " ADF: skew correction\n"); + s->hw->adf_has_skew = 1; + } + + if (strncmp("ADFOVSN", token, 3 + 4) == 0) { + DBG(1, " ADF: overscan\n"); + } + + if (strncmp("ADFPEDT", token, 3 + 4) == 0) { + DBG(1, " ADF: paper end detection\n"); + } + + if (strncmp("ADFLOAD", token, 3 + 4) == 0) { + DBG(1, " ADF: paper load\n"); + s->hw->adf_has_load = 1; + } + + if (strncmp("ADFEJCT", token, 3 + 4) == 0) { + DBG(1, " ADF: paper eject\n"); + s->hw->adf_has_eject = 1; + } + + if (strncmp("ADFCRP ", token, 3 + 4) == 0) { + DBG(1, " ADF: image cropping\n"); + } + + if (strncmp("ADFFAST", token, 3 + 4) == 0) { + DBG(1, " ADF: fast mode available\n"); + } + + if (strncmp("ADFDFL1", token, 3 + 4) == 0) { + DBG(1, " ADF: double feed detection\n"); + s->hw->adf_has_dfd = 1; + } + } + + if (len == 8 && strncmp("ADFDFL1DFL2", token, 3 + 4) == 0) { + DBG(1, " ADF: double feed detection (high sensitivity)\n"); + s->hw->adf_has_dfd = 2; + } + + if (strncmp("FMT", token, 3) == 0) { + + /* a bit ugly... */ + + if (len >= 8) { + if (strncmp("RAW ", value + 4, 4) == 0) { + s->hw->has_raw = 1; + } + } + + if (len >= 12) { + if (strncmp("RAW ", value + 8, 4) == 0) { + s->hw->has_raw = 1; + } + } + } + + /* RSMRANGi0000050i0000600 */ + + if (strncmp("RSMRANG", token, 3 + 4) == 0) { + + char *p = token + 3 + 4; + + if (p[0] == 'i') { + + int min = decode_value(p, 8); + int max = decode_value(p + 8, 8); + + eds_set_resolution_range(s->hw, min, max); + + DBG(1, "resolution min/max %d/%d\n", min, max); + } + } + + /* RSMLISTi0000300i0000600 */ + + if (strncmp("RSMLIST", token, 3 + 4) == 0) { + + char *p = token + 3 + 4; + + if (p[0] == 'i') { + + int i; + int count = (len - 4) / 8; + + for (i = 0; i < count; i++) { + + eds_add_resolution(s->hw, decode_value(p, 8)); + p += 8; + } + } + } + + return SANE_STATUS_GOOD; +} + +SANE_Status esci2_capa(epsonds_scanner *s) +{ + return esci2_cmd_simple(s, "CAPAx0000000", &capa_cb); +} + +/* STAT */ + +static SANE_Status stat_cb(void *userdata, char *token, int len) +{ +/* + epsonds_scanner *s = (epsonds_scanner *)userdata; + char *value = token + 3; +*/ + userdata = userdata; + + if (DBG_LEVEL >= 11) { + debug_token(DBG_LEVEL, __func__, token, len); + } + + return SANE_STATUS_GOOD; +} + +SANE_Status esci2_stat(epsonds_scanner *s) +{ + return esci2_cmd_simple(s, "STATx0000000", &stat_cb); +} + +/* RESA */ + +static SANE_Status resa_cb(void *userdata, char *token, int len) +{ + /* epsonds_scanner *s = (epsonds_scanner *)userdata; */ + + userdata = userdata; + + if (DBG_LEVEL >= 11) { + debug_token(DBG_LEVEL, __func__, token, len); + } + + return SANE_STATUS_GOOD; +} + +SANE_Status esci2_resa(epsonds_scanner *s) +{ + return esci2_cmd_simple(s, "RESAx0000000", &resa_cb); +} + +/* PARA */ + +static SANE_Status para_cb(void *userdata, char *token, int len) +{ + if (DBG_LEVEL >= 11) { + debug_token(DBG_LEVEL, __func__, token, len); + } + + userdata = userdata; + + if (strncmp("par", token, 3) == 0) { + if (strncmp("FAIL", token + 3, 4) == 0) { + DBG(1, "%s: parameter setting failed\n", __func__); + return SANE_STATUS_INVAL; + } + } + + return SANE_STATUS_GOOD; +} + +SANE_Status esci2_para(epsonds_scanner *s, char *parameters) +{ + DBG(8, "%s: %s\n", __func__, parameters); + return esci2_cmd(s, "PARAx0000000", 12, parameters, strlen(parameters), NULL, ¶_cb); +} + +SANE_Status esci2_mech(epsonds_scanner *s, char *parameters) +{ + DBG(8, "%s: %s\n", __func__, parameters); + return esci2_cmd(s, "MECHx0000000", 12, parameters, strlen(parameters), NULL, ¶_cb); +} + +SANE_Status esci2_trdt(epsonds_scanner *s) +{ + return esci2_cmd_simple(s, "TRDTx0000000", NULL); +} + + +static SANE_Status img_cb(void *userdata, char *token, int len) +{ + struct epsonds_scanner *s = userdata; + + if (DBG_LEVEL >= 11) { + debug_token(DBG_LEVEL, __func__, token, len); + } + + /* psti0000256i0000000i0000945 / 24 */ + + /* integer comparison first so it's faster */ + if (len == 24 && strncmp("pst", token, 3) == 0) { + + s->dummy = decode_value(token + 3 + 8, 8); + + DBG(10, "%s: pst width: %d, height: %d, dummy: %d\n", + __func__, + decode_value(token + 3, 8), + decode_value(token + 3 + 8 + 8, 8), + s->dummy); + + return SANE_STATUS_GOOD; + } + + if (len == 16 && strncmp("pen", token, 3) == 0) { + DBG(10, "%s: page end\n", __func__); + s->eof = 1; + return SANE_STATUS_EOF; + } + + /* typIMGA or typIMGB */ + if (len == 4 && strncmp("typ", token, 3) == 0) { + + if (token[6] == 'B') + s->backside = 1; + else + s->backside = 0; + + return SANE_STATUS_GOOD; + } + + if (strncmp("err", token, 3) == 0) { + + char *option = token + 3; /* ADF, TPU, FB */ + char *cause = token + 3 + 4; /* OPN, PJ, PE, ERR, LTF, LOCK, DFED, DTCL, AUT, PERM */ + + s->scanning = 0; + + DBG(1, "%s: error on option %3.3s, cause %4.4s\n", + __func__, option, cause); + + if (cause[0] == 'P' && cause[1] == 'J') + return SANE_STATUS_JAMMED; + + if (cause[0] == 'P' && cause[1] == 'E') + return SANE_STATUS_NO_DOCS; + + if (cause[0] == 'O' && cause[1] == 'P' && cause[2] == 'N') + return SANE_STATUS_COVER_OPEN; + + return SANE_STATUS_IO_ERROR; + } + + if (len == 4 && strncmp("atnCAN ", token, 3 + 4) == 0) { + DBG(1, "%s: cancel request\n", __func__); + s->canceling = 1; + s->scanning = 0; + return SANE_STATUS_CANCELLED; + } + + if (len == 4 && strncmp("lftd000", token, 3 + 4) == 0) { + s->scanning = 0; + } + + return SANE_STATUS_GOOD; +} + + +SANE_Status +esci2_img(struct epsonds_scanner *s, SANE_Int *length) +{ + SANE_Status status = SANE_STATUS_GOOD; + SANE_Status parse_status; + unsigned int more; + ssize_t read; + + *length = 0; + + if (s->canceling) + return SANE_STATUS_CANCELLED; + + /* request image data */ + eds_send(s, "IMG x0000000", 12, &status); + if (status != SANE_STATUS_GOOD) { + return status; + } + + /* receive DataHeaderBlock */ + memset(s->buf, 0x00, 64); + eds_recv(s, s->buf, 64, &status); + if (status != SANE_STATUS_GOOD) { + return status; + } + + /* check if we need to read any image data */ + more = 0; + if (!esci2_check_header("IMG ", (char *)s->buf, &more)) { + return SANE_STATUS_IO_ERROR; + } + + /* this handles eof and errors */ + parse_status = esci2_parse_block((char *)s->buf + 12, 64 - 12, s, &img_cb); + + /* no more data? return using the status of the esci2_parse_block + * call, which might hold other error conditions. + */ + if (!more) { + return parse_status; + } + + /* ALWAYS read image data */ + read = eds_recv(s, s->buf, more, &status); + if (status != SANE_STATUS_GOOD) { + return status; + } + + if (read != more) { + return SANE_STATUS_IO_ERROR; + } + + /* handle esci2_parse_block errors */ + if (parse_status != SANE_STATUS_GOOD) { + return parse_status; + } + + DBG(15, "%s: read %lu bytes, status: %d\n", __func__, (unsigned long) read, status); + + *length = read; + + if (s->canceling) { + return SANE_STATUS_CANCELLED; + } + + return SANE_STATUS_GOOD; +} diff --git a/backend/epsonds-cmd.h b/backend/epsonds-cmd.h new file mode 100644 index 0000000..923e811 --- /dev/null +++ b/backend/epsonds-cmd.h @@ -0,0 +1,29 @@ +/* + * epsonds-cmd.h - Epson ESC/I-2 routines. + * + * Copyright (C) 2015 Tower Technologies + * Author: Alessandro Zummo <a.zummo@towertech.it> + * + * This file is part of the SANE package. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, version 2. + */ + +#ifndef epsonds_cmd_h +#define epsonds_cmd_h + +SANE_Status esci2_info(epsonds_scanner *s); +SANE_Status esci2_fin(epsonds_scanner *s); +SANE_Status esci2_can(epsonds_scanner *s); +SANE_Status esci2_capa(epsonds_scanner *s); +SANE_Status esci2_resa(epsonds_scanner *s); +SANE_Status esci2_stat(epsonds_scanner *s); +SANE_Status esci2_para(epsonds_scanner *s, char *parameters); +SANE_Status esci2_mech(epsonds_scanner *s, char *parameters); +SANE_Status esci2_trdt(epsonds_scanner *s); +SANE_Status esci2_img(struct epsonds_scanner *s, SANE_Int *length) ; + +#endif + diff --git a/backend/epsonds-io.c b/backend/epsonds-io.c new file mode 100644 index 0000000..28bacfc --- /dev/null +++ b/backend/epsonds-io.c @@ -0,0 +1,177 @@ +/* + * epsonds-io.c - Epson ESC/I-2 driver, low level I/O. + * + * Copyright (C) 2015 Tower Technologies + * Author: Alessandro Zummo <a.zummo@towertech.it> + * + * This file is part of the SANE package. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, version 2. + */ + +#define DEBUG_DECLARE_ONLY + +#include "sane/config.h" +#include <ctype.h> +#include <unistd.h> /* sleep */ + +#include "epsonds.h" +#include "epsonds-io.h" + +size_t eds_send(epsonds_scanner *s, void *buf, size_t length, SANE_Status *status) +{ + DBG(32, "%s: size = %lu\n", __func__, (u_long) length); + + if (length == 2) { + + char *cmd = buf; + + switch (cmd[0]) { + case FS: + DBG(9, "%s: FS %c\n", __func__, cmd[1]); + break; + } + } + + if (s->hw->connection == SANE_EPSONDS_NET) { + /* XXX */ + } else if (s->hw->connection == SANE_EPSONDS_USB) { + + size_t n = length; + + *status = sanei_usb_write_bulk(s->fd, buf, &n); + + return n; + } + + /* never reached */ + + *status = SANE_STATUS_INVAL; + + return 0; +} + +size_t eds_recv(epsonds_scanner *s, void *buf, size_t length, SANE_Status *status) +{ + size_t n = 0; + + DBG(30, "%s: size = %ld, buf = %p\n", __func__, (long) length, buf); + + if (s->hw->connection == SANE_EPSONDS_NET) { + /* XXX */ + } else if (s->hw->connection == SANE_EPSONDS_USB) { + + /* !!! only report an error if we don't read anything */ + + n = length; + *status = sanei_usb_read_bulk(s->fd, (SANE_Byte *)buf, + (size_t *) &n); + if (n > 0) + *status = SANE_STATUS_GOOD; + } + + if (n < length) { + DBG(1, "%s: expected = %lu, got = %ld, canceling: %d\n", __func__, + (u_long)length, (long)n, s->canceling); + + *status = SANE_STATUS_IO_ERROR; + } + + return n; +} + +/* Simple function to exchange a fixed amount of data with the scanner */ + +SANE_Status eds_txrx(epsonds_scanner* s, char *txbuf, size_t txlen, + char *rxbuf, size_t rxlen) +{ + SANE_Status status; + size_t done; + + done = eds_send(s, txbuf, txlen, &status); + if (status != SANE_STATUS_GOOD) { + DBG(1, "%s: tx err, %s\n", __func__, sane_strstatus(status)); + return status; + } + + if (done != txlen) { + DBG(1, "%s: tx err, short write\n", __func__); + return SANE_STATUS_IO_ERROR; + } + + done = eds_recv(s, rxbuf, rxlen, &status); + if (status != SANE_STATUS_GOOD) { + DBG(1, "%s: rx err, %s\n", __func__, sane_strstatus(status)); + } + + return status; +} + +/* This function should be used to send codes that only requires the scanner + * to give back an ACK or a NAK, namely FS X or FS Y + */ + +SANE_Status eds_control(epsonds_scanner *s, void *buf, size_t buf_size) +{ + char result; + SANE_Status status; + + DBG(12, "%s: size = %lu\n", __func__, (u_long) buf_size); + + status = eds_txrx(s, buf, buf_size, &result, 1); + if (status != SANE_STATUS_GOOD) { + DBG(1, "%s: failed, %s\n", __func__, sane_strstatus(status)); + return status; + } + + if (result == ACK) + return SANE_STATUS_GOOD; + + if (result == NAK) { + DBG(3, "%s: NAK\n", __func__); + return SANE_STATUS_INVAL; + } + + DBG(1, "%s: result is neither ACK nor NAK but 0x%02x\n", + __func__, result); + + return SANE_STATUS_INVAL; +} + +SANE_Status eds_fsy(epsonds_scanner *s) +{ + return eds_control(s, "\x1CY", 2); +} + +SANE_Status eds_fsx(epsonds_scanner *s) +{ + SANE_Status status = eds_control(s, "\x1CX", 2); + if (status == SANE_STATUS_GOOD) { + s->locked = 1; + } + + return status; +} + +SANE_Status eds_lock(epsonds_scanner *s) +{ + SANE_Status status; + + DBG(5, "%s\n", __func__); + + if (s->hw->connection == SANE_EPSONDS_USB) { + sanei_usb_set_timeout(USB_SHORT_TIMEOUT); + } + + status = eds_fsx(s); + + if (s->hw->connection == SANE_EPSONDS_USB) { + sanei_usb_set_timeout(USB_TIMEOUT); + } + + return status; +} + + diff --git a/backend/epsonds-io.h b/backend/epsonds-io.h new file mode 100644 index 0000000..1a1b2b7 --- /dev/null +++ b/backend/epsonds-io.h @@ -0,0 +1,33 @@ +/* + * epsonds-io.h - Epson ESC/I-2 driver, low level I/O. + * + * Copyright (C) 2015 Tower Technologies + * Author: Alessandro Zummo <a.zummo@towertech.it> + * + * This file is part of the SANE package. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, version 2. + */ + +#ifndef epsonds_io_h +#define epsonds_io_h + +#define USB_TIMEOUT (6 * 1000) +#define USB_SHORT_TIMEOUT (1 * 800) + +size_t eds_send(epsonds_scanner *s, void *buf, size_t length, SANE_Status *status); +size_t eds_recv(epsonds_scanner *s, void *buf, size_t length, SANE_Status *status); + +SANE_Status eds_txrx(epsonds_scanner *s, char *txbuf, size_t txlen, + char *rxbuf, size_t rxlen); + +SANE_Status eds_control(epsonds_scanner *s, void *buf, size_t buf_size); + +SANE_Status eds_fsy(epsonds_scanner *s); +SANE_Status eds_fsx(epsonds_scanner *s); +SANE_Status eds_lock(epsonds_scanner *s); + +#endif + diff --git a/backend/epsonds-jpeg.c b/backend/epsonds-jpeg.c new file mode 100644 index 0000000..76a52cb --- /dev/null +++ b/backend/epsonds-jpeg.c @@ -0,0 +1,226 @@ +/* + * epsonds-jpeg.c - Epson ESC/I-2 driver, JPEG support. + * + * Copyright (C) 2015 Tower Technologies + * Author: Alessandro Zummo <a.zummo@towertech.it> + * + * This file is part of the SANE package. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, version 2. + */ + +#define DEBUG_DECLARE_ONLY + +#include <math.h> + +#include "epsonds.h" +#include "epsonds-jpeg.h" +#include "epsonds-ops.h" + +#define min(A,B) (((A)<(B)) ? (A) : (B)) + +typedef struct +{ + struct jpeg_source_mgr pub; + + epsonds_scanner *s; + JOCTET *buffer; + + SANE_Byte *linebuffer; + SANE_Int linebuffer_size; + SANE_Int linebuffer_index; +} +epsonds_src_mgr; + +METHODDEF(void) +jpeg_init_source(j_decompress_ptr UNUSEDARG cinfo) +{ +} + +METHODDEF(void) +jpeg_term_source(j_decompress_ptr UNUSEDARG cinfo) +{ +} + +METHODDEF(boolean) +jpeg_fill_input_buffer(j_decompress_ptr cinfo) +{ + epsonds_src_mgr *src = (epsonds_src_mgr *)cinfo->src; + int avail, size; + + /* read from the scanner or the ring buffer */ + + avail = eds_ring_avail(src->s->current); + if (avail == 0) { + return FALSE; + } + + /* read from scanner if no data? */ + size = min(1024, avail); + + eds_ring_read(src->s->current, src->buffer, size); + + src->pub.next_input_byte = src->buffer; + src->pub.bytes_in_buffer = size; + + return TRUE; +} + +METHODDEF (void) +jpeg_skip_input_data(j_decompress_ptr cinfo, long num_bytes) +{ + epsonds_src_mgr *src = (epsonds_src_mgr *)cinfo->src; + + if (num_bytes > 0) { + + while (num_bytes > (long)src->pub.bytes_in_buffer) { + num_bytes -= (long)src->pub.bytes_in_buffer; + jpeg_fill_input_buffer(cinfo); + } + + src->pub.next_input_byte += (size_t) num_bytes; + src->pub.bytes_in_buffer -= (size_t) num_bytes; + } +} + +SANE_Status +eds_jpeg_start(epsonds_scanner *s) +{ + epsonds_src_mgr *src; + + s->jpeg_cinfo.err = jpeg_std_error(&s->jpeg_err); + + jpeg_create_decompress(&s->jpeg_cinfo); + + s->jpeg_cinfo.src = (struct jpeg_source_mgr *)(*s->jpeg_cinfo.mem->alloc_small)((j_common_ptr)&s->jpeg_cinfo, + JPOOL_PERMANENT, sizeof(epsonds_src_mgr)); + + memset(s->jpeg_cinfo.src, 0x00, sizeof(epsonds_src_mgr)); + + src = (epsonds_src_mgr *)s->jpeg_cinfo.src; + src->s = s; + + src->buffer = (JOCTET *)(*s->jpeg_cinfo.mem->alloc_small)((j_common_ptr)&s->jpeg_cinfo, + JPOOL_PERMANENT, + 1024 * sizeof(JOCTET)); + + src->pub.init_source = jpeg_init_source; + src->pub.fill_input_buffer = jpeg_fill_input_buffer; + src->pub.skip_input_data = jpeg_skip_input_data; + src->pub.resync_to_restart = jpeg_resync_to_restart; + src->pub.term_source = jpeg_term_source; + src->pub.bytes_in_buffer = 0; + src->pub.next_input_byte = NULL; + + s->jpeg_header_seen = 0; + + return SANE_STATUS_GOOD; +} + +SANE_Status +eds_jpeg_read_header(epsonds_scanner *s) +{ + epsonds_src_mgr *src = (epsonds_src_mgr *)s->jpeg_cinfo.src; + + if (jpeg_read_header(&s->jpeg_cinfo, TRUE)) { + + s->jdst = sanei_jpeg_jinit_write_ppm(&s->jpeg_cinfo); + + if (jpeg_start_decompress(&s->jpeg_cinfo)) { + + int size; + + DBG(3, "%s: w: %d, h: %d, components: %d\n", + __func__, + s->jpeg_cinfo.output_width, s->jpeg_cinfo.output_height, + s->jpeg_cinfo.output_components); + + size = s->jpeg_cinfo.output_width * s->jpeg_cinfo.output_components * 1; + + src->linebuffer = (*s->jpeg_cinfo.mem->alloc_large)((j_common_ptr)&s->jpeg_cinfo, + JPOOL_PERMANENT, size); + + src->linebuffer_size = 0; + src->linebuffer_index = 0; + + s->jpeg_header_seen = 1; + + return SANE_STATUS_GOOD; + + } else { + DBG(0, "%s: decompression failed\n", __func__); + return SANE_STATUS_IO_ERROR; + } + } else { + DBG(0, "%s: cannot read JPEG header\n", __func__); + return SANE_STATUS_IO_ERROR; + } +} + +void +eds_jpeg_finish(epsonds_scanner *s) +{ + jpeg_destroy_decompress(&s->jpeg_cinfo); +} + +void +eds_jpeg_read(SANE_Handle handle, SANE_Byte *data, + SANE_Int max_length, SANE_Int *length) +{ + epsonds_scanner *s = handle; + + struct jpeg_decompress_struct cinfo = s->jpeg_cinfo; + epsonds_src_mgr *src = (epsonds_src_mgr *)s->jpeg_cinfo.src; + + int l; + + *length = 0; + + /* copy from line buffer if available */ + if (src->linebuffer_size && src->linebuffer_index < src->linebuffer_size) { + + *length = src->linebuffer_size - src->linebuffer_index; + + if (*length > max_length) + *length = max_length; + + memcpy(data, src->linebuffer + src->linebuffer_index, *length); + src->linebuffer_index += *length; + + return; + } + + if (cinfo.output_scanline >= cinfo.output_height) { + *length = 0; + return; + } + + /* scanlines of decompressed data will be in s->jdst->buffer + * only one line at time is supported + */ + + l = jpeg_read_scanlines(&cinfo, s->jdst->buffer, 1); + if (l == 0) { + return; + } + + /* from s->jdst->buffer to linebuffer + * linebuffer holds width * bytesperpixel + */ + + (*s->jdst->put_pixel_rows)(&cinfo, s->jdst, 1, (char *)src->linebuffer); + + *length = cinfo.output_width * cinfo.output_components * 1; + src->linebuffer_size = *length; + src->linebuffer_index = 0; + + if (*length > max_length) + *length = max_length; + + memcpy(data, src->linebuffer + src->linebuffer_index, *length); + src->linebuffer_index += *length; +} + + diff --git a/backend/epsonds-jpeg.h b/backend/epsonds-jpeg.h new file mode 100644 index 0000000..c54208e --- /dev/null +++ b/backend/epsonds-jpeg.h @@ -0,0 +1,19 @@ +/* + * epsonds.c - Epson ESC/I-2 driver, JPEG support. + * + * Copyright (C) 2015 Tower Technologies + * Author: Alessandro Zummo <a.zummo@towertech.it> + * + * This file is part of the SANE package. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, version 2. + */ + +#define UNUSEDARG __attribute__ ((unused)) + +SANE_Status eds_jpeg_start(epsonds_scanner *s); +void eds_jpeg_finish(epsonds_scanner *s); +SANE_Status eds_jpeg_read_header(epsonds_scanner *s); +void eds_jpeg_read(SANE_Handle handle, SANE_Byte *data, SANE_Int max_length, SANE_Int *length); diff --git a/backend/epsonds-ops.c b/backend/epsonds-ops.c new file mode 100644 index 0000000..403cd58 --- /dev/null +++ b/backend/epsonds-ops.c @@ -0,0 +1,481 @@ +/* + * epsonds-ops.c - Epson ESC/I-2 driver, support routines. + * + * Copyright (C) 2015 Tower Technologies + * Author: Alessandro Zummo <a.zummo@towertech.it> + * + * This file is part of the SANE package. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, version 2. + */ + +#define DEBUG_DECLARE_ONLY + +#include "sane/config.h" + +#include <unistd.h> /* sleep */ +#ifdef HAVE_SYS_SELECT_H +#include <sys/select.h> +#endif + +#include "epsonds.h" +#include "epsonds-io.h" +#include "epsonds-ops.h" +#include "epsonds-cmd.h" + +extern struct mode_param mode_params[]; + +/* Define the different scan sources */ + +#define FBF_STR SANE_I18N("Flatbed") +#define TPU_STR SANE_I18N("Transparency Unit") +#define ADF_STR SANE_I18N("Automatic Document Feeder") + +extern SANE_String_Const source_list[]; + +void +eds_dev_init(epsonds_device *dev) +{ + dev->res_list = malloc(sizeof(SANE_Word)); + dev->res_list[0] = 0; + + dev->depth_list = malloc(sizeof(SANE_Word)); + dev->depth_list[0] = 0; +} + +SANE_Status +eds_dev_post_init(struct epsonds_device *dev) +{ + SANE_String_Const *source_list_add = source_list; + + DBG(10, "%s\n", __func__); + + if (dev->has_fb) + *source_list_add++ = FBF_STR; + + if (dev->has_adf) + *source_list_add++ = ADF_STR; + + if (source_list[0] == 0 + || (dev->res_list[0] == 0 && dev->dpi_range.min == 0) + || dev->depth_list[0] == 0) { + + DBG(1, "something is wrong in the discovery process, aborting.\n"); + DBG(1, "sources: %ld, res: %d, depths: %d.\n", + source_list_add - source_list, dev->res_list[0], dev->depth_list[0]); + + return SANE_STATUS_INVAL; + } + + return SANE_STATUS_GOOD; +} + +SANE_Status +eds_add_resolution(epsonds_device *dev, int r) +{ + DBG(10, "%s: add (dpi): %d\n", __func__, r); + + /* first element is the list size */ + dev->res_list[0]++; + dev->res_list = realloc(dev->res_list, + (dev->res_list[0] + 1) * + sizeof(SANE_Word)); + if (dev->res_list == NULL) + return SANE_STATUS_NO_MEM; + + dev->res_list[dev->res_list[0]] = r; + + return SANE_STATUS_GOOD; +} + +SANE_Status +eds_set_resolution_range(epsonds_device *dev, int min, int max) +{ + DBG(10, "%s: set min/max (dpi): %d/%d\n", __func__, min, max); + + dev->dpi_range.min = min; + dev->dpi_range.max = max; + dev->dpi_range.quant = 1; + + return SANE_STATUS_GOOD; +} + +void +eds_set_fbf_area(epsonds_device *dev, int x, int y, int unit) +{ + if (x == 0 || y == 0) + return; + + dev->fbf_x_range.min = 0; + dev->fbf_x_range.max = SANE_FIX(x * MM_PER_INCH / unit); + dev->fbf_x_range.quant = 0; + + dev->fbf_y_range.min = 0; + dev->fbf_y_range.max = SANE_FIX(y * MM_PER_INCH / unit); + dev->fbf_y_range.quant = 0; + + DBG(5, "%s: %f,%f %f,%f %d [mm]\n", + __func__, + SANE_UNFIX(dev->fbf_x_range.min), + SANE_UNFIX(dev->fbf_y_range.min), + SANE_UNFIX(dev->fbf_x_range.max), + SANE_UNFIX(dev->fbf_y_range.max), unit); +} + +void +eds_set_adf_area(struct epsonds_device *dev, int x, int y, int unit) +{ + dev->adf_x_range.min = 0; + dev->adf_x_range.max = SANE_FIX(x * MM_PER_INCH / unit); + dev->adf_x_range.quant = 0; + + dev->adf_y_range.min = 0; + dev->adf_y_range.max = SANE_FIX(y * MM_PER_INCH / unit); + dev->adf_y_range.quant = 0; + + DBG(5, "%s: %f,%f %f,%f %d [mm]\n", + __func__, + SANE_UNFIX(dev->adf_x_range.min), + SANE_UNFIX(dev->adf_y_range.min), + SANE_UNFIX(dev->adf_x_range.max), + SANE_UNFIX(dev->adf_y_range.max), unit); +} + +void +eds_set_tpu_area(struct epsonds_device *dev, int x, int y, int unit) +{ + dev->tpu_x_range.min = 0; + dev->tpu_x_range.max = SANE_FIX(x * MM_PER_INCH / unit); + dev->tpu_x_range.quant = 0; + + dev->tpu_y_range.min = 0; + dev->tpu_y_range.max = SANE_FIX(y * MM_PER_INCH / unit); + dev->tpu_y_range.quant = 0; + + DBG(5, "%s: %f,%f %f,%f %d [mm]\n", + __func__, + SANE_UNFIX(dev->tpu_x_range.min), + SANE_UNFIX(dev->tpu_y_range.min), + SANE_UNFIX(dev->tpu_x_range.max), + SANE_UNFIX(dev->tpu_y_range.max), unit); +} + +SANE_Status +eds_add_depth(epsonds_device *dev, SANE_Word depth) +{ + DBG(5, "%s: add (bpp): %d\n", __func__, depth); + + /* > 8bpp not implemented yet */ + if (depth > 8) { + DBG(1, " not supported"); + return SANE_STATUS_GOOD; + } + + if (depth > dev->max_depth) + dev->max_depth = depth; + + /* first element is the list size */ + dev->depth_list[0]++; + dev->depth_list = realloc(dev->depth_list, + (dev->depth_list[0] + 1) * + sizeof(SANE_Word)); + + if (dev->depth_list == NULL) + return SANE_STATUS_NO_MEM; + + dev->depth_list[dev->depth_list[0]] = depth; + + return SANE_STATUS_GOOD; +} + +SANE_Status +eds_init_parameters(epsonds_scanner *s) +{ + int dpi, bytes_per_pixel; + + memset(&s->params, 0, sizeof(SANE_Parameters)); + + s->dummy = 0; + + dpi = s->val[OPT_RESOLUTION].w; + + if (SANE_UNFIX(s->val[OPT_BR_Y].w) == 0 || + SANE_UNFIX(s->val[OPT_BR_X].w) == 0) + return SANE_STATUS_INVAL; + + s->left = ((SANE_UNFIX(s->val[OPT_TL_X].w) / MM_PER_INCH) * + s->val[OPT_RESOLUTION].w) + 0.5; + + s->top = ((SANE_UNFIX(s->val[OPT_TL_Y].w) / MM_PER_INCH) * + s->val[OPT_RESOLUTION].w) + 0.5; + + s->params.pixels_per_line = + ((SANE_UNFIX(s->val[OPT_BR_X].w - + s->val[OPT_TL_X].w) / MM_PER_INCH) * dpi) + 0.5; + s->params.lines = + ((SANE_UNFIX(s->val[OPT_BR_Y].w - + s->val[OPT_TL_Y].w) / MM_PER_INCH) * dpi) + 0.5; + + DBG(5, "%s: tlx %f tly %f brx %f bry %f [mm]\n", + __func__, + SANE_UNFIX(s->val[OPT_TL_X].w), SANE_UNFIX(s->val[OPT_TL_Y].w), + SANE_UNFIX(s->val[OPT_BR_X].w), SANE_UNFIX(s->val[OPT_BR_Y].w)); + + DBG(5, "%s: tlx %d tly %d brx %d bry %d [dots @ %d dpi]\n", + __func__, s->left, s->top, + s->params.pixels_per_line, s->params.lines, dpi); + + /* center aligned? */ + if (s->hw->alignment == 1) { + + SANE_Int offset = ((SANE_UNFIX(s->hw->x_range->max) / MM_PER_INCH) * dpi) + 0.5; + + s->left += ((offset - s->params.pixels_per_line) / 2); + + DBG(5, "%s: centered to tlx %d tly %d brx %d bry %d [dots @ %d dpi]\n", + __func__, s->left, s->top, + s->params.pixels_per_line, s->params.lines, dpi); + } + + /* + * Calculate bytes_per_pixel and bytes_per_line for + * any color depths. + * + * The default color depth is stored in mode_params.depth: + */ + + if (mode_params[s->val[OPT_MODE].w].depth == 1) + s->params.depth = 1; + else + s->params.depth = s->val[OPT_DEPTH].w; + + /* this works because it can only be set to 1, 8 or 16 */ + bytes_per_pixel = s->params.depth / 8; + if (s->params.depth % 8) { /* just in case ... */ + bytes_per_pixel++; + } + + /* pixels_per_line is rounded to the next 8bit boundary */ + s->params.pixels_per_line = s->params.pixels_per_line & ~7; + + s->params.last_frame = SANE_TRUE; + + switch (s->val[OPT_MODE].w) { + case MODE_BINARY: + case MODE_GRAY: + s->params.format = SANE_FRAME_GRAY; + s->params.bytes_per_line = + s->params.pixels_per_line * s->params.depth / 8; + break; + case MODE_COLOR: + s->params.format = SANE_FRAME_RGB; + s->params.bytes_per_line = + 3 * s->params.pixels_per_line * bytes_per_pixel; + break; + } + + if (s->params.bytes_per_line == 0) { + DBG(1, "bytes_per_line is ZERO\n"); + return SANE_STATUS_INVAL; + } + + /* + * If (s->top + s->params.lines) is larger than the max scan area, reset + * the number of scan lines: + * XXX: precalculate the maximum scanning area elsewhere (use dev max_y) + */ + + if (SANE_UNFIX(s->val[OPT_BR_Y].w) / MM_PER_INCH * dpi < + (s->params.lines + s->top)) { + s->params.lines = + ((int) SANE_UNFIX(s->val[OPT_BR_Y].w) / MM_PER_INCH * + dpi + 0.5) - s->top; + } + + if (s->params.lines <= 0) { + DBG(1, "wrong number of lines: %d\n", s->params.lines); + return SANE_STATUS_INVAL; + } + + return SANE_STATUS_GOOD; +} + +void +eds_copy_image_from_ring(epsonds_scanner *s, SANE_Byte *data, SANE_Int max_length, + SANE_Int *length) +{ + int lines, available; + int hw_line_size = (s->params.bytes_per_line + s->dummy); + + /* trim max_length to a multiple of hw_line_size */ + max_length -= (max_length % hw_line_size); + + /* check available data */ + available = eds_ring_avail(s->current); + if (max_length > available) + max_length = available; + + lines = max_length / hw_line_size; + + DBG(18, "copying %d lines (%d, %d)\n", lines, s->params.bytes_per_line, s->dummy); + + /* need more data? */ + if (lines == 0) { + *length = 0; + return; + } + + *length = (lines * s->params.bytes_per_line); + + /* we need to copy one line at time, skipping + * dummy bytes at the end of each line + */ + + /* lineart */ + if (s->params.depth == 1) { + + while (lines--) { + + int i; + SANE_Byte *p; + + eds_ring_read(s->current, s->line_buffer, s->params.bytes_per_line); + eds_ring_skip(s->current, s->dummy); + + p = s->line_buffer; + + for (i = 0; i < s->params.bytes_per_line; i++) { + *data++ = ~*p++; + } + } + + } else { /* gray and color */ + + while (lines--) { + + eds_ring_read(s->current, data, s->params.bytes_per_line); + eds_ring_skip(s->current, s->dummy); + + data += s->params.bytes_per_line; + + } + } +} + +SANE_Status eds_ring_init(ring_buffer *ring, SANE_Int size) +{ + ring->ring = realloc(ring->ring, size); + if (!ring->ring) { + return SANE_STATUS_NO_MEM; + } + + ring->size = size; + ring->fill = 0; + ring->end = ring->ring + size; + ring->wp = ring->rp = ring->ring; + + return SANE_STATUS_GOOD; +} + +SANE_Status eds_ring_write(ring_buffer *ring, SANE_Byte *buf, SANE_Int size) +{ + SANE_Int tail; + + if (size > (ring->size - ring->fill)) { + DBG(1, "ring buffer full, requested: %d, available: %d\n", size, ring->size - ring->fill); + return SANE_STATUS_NO_MEM; + } + + tail = ring->end - ring->wp; + if (size < tail) { + + memcpy(ring->wp, buf, size); + + ring->wp += size; + ring->fill += size; + + } else { + + memcpy(ring->wp, buf, tail); + size -= tail; + + ring->wp = ring->ring; + memcpy(ring->wp, buf + tail, size); + + ring->wp += size; + ring->fill += (tail + size); + } + + return SANE_STATUS_GOOD; +} + +SANE_Int eds_ring_read(ring_buffer *ring, SANE_Byte *buf, SANE_Int size) +{ + SANE_Int tail; + + DBG(18, "reading from ring, %d bytes available\n", (int)ring->fill); + + /* limit read to available */ + if (size > ring->fill) { + DBG(1, "not enough data in the ring, shouldn't happen\n"); + size = ring->fill; + } + + tail = ring->end - ring->rp; + if (size < tail) { + + memcpy(buf, ring->rp, size); + + ring->rp += size; + ring->fill -= size; + + return size; + + } else { + + memcpy(buf, ring->rp, tail); + size -= tail; + + ring->rp = ring->ring; + memcpy(buf + tail, ring->rp, size); + + ring->rp += size; + ring->fill -= (size + tail); + + return size + tail; + } +} + +SANE_Int eds_ring_skip(ring_buffer *ring, SANE_Int size) +{ + SANE_Int tail; + /* limit skip to available */ + if (size > ring->fill) + size = ring->fill; + + tail = ring->end - ring->rp; + if (size < tail) { + ring->rp += size; + } else { + + ring->rp = ring->ring + (size - tail); + } + + ring->fill -= size; + + return size; +} + +SANE_Int eds_ring_avail(ring_buffer *ring) +{ + return ring->fill; +} + +void eds_ring_flush(ring_buffer *ring) +{ + eds_ring_skip(ring, ring->fill); +} + + diff --git a/backend/epsonds-ops.h b/backend/epsonds-ops.h new file mode 100644 index 0000000..3f45393 --- /dev/null +++ b/backend/epsonds-ops.h @@ -0,0 +1,41 @@ +/* + * epsonds-ops.h - Epson ESC/I-2 driver. + * + * Copyright (C) 2015 Tower Technologies + * Author: Alessandro Zummo <a.zummo@towertech.it> + * + * This file is part of the SANE package. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, version 2. + */ + +#define e2_model(s,m) e2_dev_model((s)->hw,(m)) + +extern void eds_dev_init(epsonds_device *dev); +extern SANE_Status eds_dev_post_init(struct epsonds_device *dev); + +extern SANE_Status eds_add_resolution(epsonds_device *dev, int r); +extern SANE_Status eds_set_resolution_range(epsonds_device *dev, int min, int max); +extern void eds_set_fbf_area(epsonds_device *dev, int x, int y, int unit); +extern void eds_set_adf_area(epsonds_device *dev, int x, int y, int unit); +extern void eds_set_tpu_area(epsonds_device *dev, int x, int y, int unit); + +extern SANE_Status eds_add_depth(epsonds_device *dev, SANE_Word depth); +extern SANE_Status eds_discover_capabilities(epsonds_scanner *s); +extern SANE_Status eds_set_extended_scanning_parameters(epsonds_scanner *s); +extern SANE_Status eds_set_scanning_parameters(epsonds_scanner *s); +extern void eds_setup_block_mode(epsonds_scanner *s); +extern SANE_Status eds_init_parameters(epsonds_scanner *s); + +extern void eds_copy_image_from_ring(epsonds_scanner *s, SANE_Byte *data, SANE_Int max_length, + SANE_Int *length); + +extern SANE_Status eds_ring_init(ring_buffer *ring, SANE_Int size); +extern SANE_Status eds_ring_write(ring_buffer *ring, SANE_Byte *buf, SANE_Int size); +extern SANE_Int eds_ring_read(ring_buffer *ring, SANE_Byte *buf, SANE_Int size); +extern SANE_Int eds_ring_skip(ring_buffer *ring, SANE_Int size); +extern SANE_Int eds_ring_avail(ring_buffer *ring); +extern void eds_ring_flush(ring_buffer *ring) ; + diff --git a/backend/epsonds-usb.c b/backend/epsonds-usb.c new file mode 100644 index 0000000..c7e514c --- /dev/null +++ b/backend/epsonds-usb.c @@ -0,0 +1,33 @@ +/* + * epsonds-usb.c - Epson ESC/I-2 driver, USB device list. + * + * Copyright (C) 2015 Tower Technologies + * Author: Alessandro Zummo <a.zummo@towertech.it> + * + * This file is part of the SANE package. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, version 2. + */ + +#include "epsonds-usb.h" + +SANE_Word epsonds_usb_product_ids[] = { + 0x0145, /* DS-5500, DS-6500, DS-7500 */ + 0x0146, /* DS-50000, DS-60000, DS-70000 */ + 0x014c, /* DS-510 */ + 0x014d, /* DS-560 */ + 0x0150, /* DS-40 */ + 0x0152, /* DS-760, DS-860 */ + 0x0154, /* DS-520 */ + 0x08bc, /* PX-M7050 Series, WF-8510/8590 Series */ + 0x08cc, /* PX-M7050FX Series, WF-R8590 Series */ + 0 /* last entry - this is used for devices that are specified + in the config file as "usb <vendor> <product>" */ +}; + +int epsonds_get_number_of_ids(void) +{ + return sizeof (epsonds_usb_product_ids) / sizeof (SANE_Word); +} diff --git a/backend/epsonds-usb.h b/backend/epsonds-usb.h new file mode 100644 index 0000000..96c77b5 --- /dev/null +++ b/backend/epsonds-usb.h @@ -0,0 +1,24 @@ +/* + * epsonds-usb.h - Epson ESC/I-2 driver, USB device list. + * + * Copyright (C) 2015 Tower Technologies + * Author: Alessandro Zummo <a.zummo@towertech.it> + * + * This file is part of the SANE package. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, version 2. + */ + +#include "sane/sane.h" + +#ifndef _EPSONDS_USB_H_ +#define _EPSONDS_USB_H_ + +#define SANE_EPSONDS_VENDOR_ID (0x4b8) + +extern SANE_Word epsonds_usb_product_ids[]; +extern int epsonds_get_number_of_ids(void); + +#endif diff --git a/backend/epsonds.c b/backend/epsonds.c new file mode 100644 index 0000000..2f85312 --- /dev/null +++ b/backend/epsonds.c @@ -0,0 +1,1364 @@ +/* + * epsonds.c - Epson ESC/I-2 driver. + * + * Copyright (C) 2015 Tower Technologies + * Author: Alessandro Zummo <a.zummo@towertech.it> + * + * This file is part of the SANE package. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, version 2. + */ + +#define EPSONDS_VERSION 1 +#define EPSONDS_REVISION 0 +#define EPSONDS_BUILD 35 + +/* debugging levels: + * + * 32 eds_send + * 30 eds_recv + * 20 sane_read and related + * 18 sane_read and related + * 17 setvalue, getvalue, control_option + * 16 + * 15 esci2_img + * 13 image_cb + * 12 eds_control + * 11 all received params + * 10 some received params + * 9 + * 8 esci2_xxx + * 7 open/close/attach + * 6 print_params + * 5 basic functions + * 3 JPEG decompressor + * 1 scanner info and capabilities + * 0 errors + */ + +#include "sane/config.h" + +#include <ctype.h> + +#include "sane/saneopts.h" +#include "sane/sanei_config.h" + +#include "epsonds.h" +#include "epsonds-usb.h" +#include "epsonds-io.h" +#include "epsonds-cmd.h" +#include "epsonds-ops.h" +#include "epsonds-jpeg.h" + +/* + * Definition of the mode_param struct, that is used to + * specify the valid parameters for the different scan modes. + * + * The depth variable gets updated when the bit depth is modified. + */ + +struct mode_param mode_params[] = { + {0, 0x00, 0x30, 1}, + {0, 0x00, 0x30, 8}, + {1, 0x02, 0x00, 8}, + {0, 0x00, 0x30, 1} +}; + +static SANE_String_Const mode_list[] = { + SANE_VALUE_SCAN_MODE_LINEART, + SANE_VALUE_SCAN_MODE_GRAY, + SANE_VALUE_SCAN_MODE_COLOR, + NULL +}; + +static const SANE_String_Const adf_mode_list[] = { + SANE_I18N("Simplex"), + SANE_I18N("Duplex"), + NULL +}; + +/* Define the different scan sources */ + +#define FBF_STR SANE_I18N("Flatbed") +#define ADF_STR SANE_I18N("Automatic Document Feeder") + +/* order will be fixed: fb, adf, tpu */ +SANE_String_Const source_list[] = { + NULL, + NULL, + NULL, + NULL +}; + +/* + * List of pointers to devices - will be dynamically allocated depending + * on the number of devices found. + */ +static const SANE_Device **devlist; + +/* Some utility functions */ + +static size_t +max_string_size(const SANE_String_Const strings[]) +{ + size_t size, max_size = 0; + int i; + + for (i = 0; strings[i]; i++) { + size = strlen(strings[i]) + 1; + if (size > max_size) + max_size = size; + } + return max_size; +} + +static SANE_Status attach_one_usb(SANE_String_Const devname); + +static void +print_params(const SANE_Parameters params) +{ + DBG(6, "params.format = %d\n", params.format); + DBG(6, "params.last_frame = %d\n", params.last_frame); + DBG(6, "params.bytes_per_line = %d\n", params.bytes_per_line); + DBG(6, "params.pixels_per_line = %d\n", params.pixels_per_line); + DBG(6, "params.lines = %d\n", params.lines); + DBG(6, "params.depth = %d\n", params.depth); +} + +static void +close_scanner(epsonds_scanner *s) +{ + DBG(7, "%s: fd = %d\n", __func__, s->fd); + + if (s->fd == -1) + goto free; + + if (s->locked) { + DBG(7, " unlocking scanner\n"); + esci2_fin(s); + } + + if (s->hw->connection == SANE_EPSONDS_USB) { + sanei_usb_close(s->fd); + } + +free: + + free(s->front.ring); + free(s->back.ring); + free(s->line_buffer); + free(s); + + DBG(7, "%s: ZZZ\n", __func__); +} + +static SANE_Status +open_scanner(epsonds_scanner *s) +{ + SANE_Status status = SANE_STATUS_INVAL; + + DBG(7, "%s: %s\n", __func__, s->hw->sane.name); + + if (s->fd != -1) { + DBG(5, "scanner is already open: fd = %d\n", s->fd); + return SANE_STATUS_GOOD; /* no need to open the scanner */ + } + + if (s->hw->connection == SANE_EPSONDS_USB) { + + status = sanei_usb_open(s->hw->sane.name, &s->fd); + sanei_usb_set_timeout(USB_TIMEOUT); + + } else { + DBG(1, "unknown connection type: %d\n", s->hw->connection); + } + + if (status == SANE_STATUS_ACCESS_DENIED) { + DBG(1, "please check that you have permissions on the device.\n"); + DBG(1, "if this is a multi-function device with a printer,\n"); + DBG(1, "disable any conflicting driver (like usblp).\n"); + } + + if (status != SANE_STATUS_GOOD) + DBG(1, "%s open failed: %s\n", + s->hw->sane.name, + sane_strstatus(status)); + else + DBG(5, " opened correctly\n"); + + return status; +} + +static int num_devices; /* number of scanners attached to backend */ +static epsonds_device *first_dev; /* first EPSON scanner in list */ + +static struct epsonds_scanner * +scanner_create(struct epsonds_device *dev, SANE_Status *status) +{ + struct epsonds_scanner *s; + + s = malloc(sizeof(struct epsonds_scanner)); + if (s == NULL) { + *status = SANE_STATUS_NO_MEM; + return NULL; + } + + /* clear verything */ + memset(s, 0x00, sizeof(struct epsonds_scanner)); + + s->fd = -1; + s->hw = dev; + + return s; +} + +static struct epsonds_scanner * +device_detect(const char *name, int type, SANE_Status *status) +{ + struct epsonds_scanner *s; + struct epsonds_device *dev; + + DBG(1, "%s\n", __func__); + + /* try to find the device in our list */ + for (dev = first_dev; dev; dev = dev->next) { + if (strcmp(dev->sane.name, name) == 0) { + DBG(1, " found cached device\n"); + return scanner_create(dev, status); + } + } + + /* not found, create new if valid */ + if (type == SANE_EPSONDS_NODEV) { + *status = SANE_STATUS_INVAL; + return NULL; + } + + /* alloc and clear our device structure */ + dev = malloc(sizeof(*dev)); + if (!dev) { + *status = SANE_STATUS_NO_MEM; + return NULL; + } + memset(dev, 0x00, sizeof(struct epsonds_device)); + + s = scanner_create(dev, status); + if (s == NULL) + return NULL; + + dev->connection = type; + dev->model = strdup("(undetermined)"); + + dev->sane.name = name; + dev->sane.vendor = "Epson"; + dev->sane.model = dev->model; + dev->sane.type = "ESC/I-2"; + + *status = open_scanner(s); + if (*status != SANE_STATUS_GOOD) { + free(s); + return NULL; + } + + eds_dev_init(dev); + + /* lock scanner */ + *status = eds_lock(s); + if (*status != SANE_STATUS_GOOD) { + goto close; + } + + /* discover capabilities */ + *status = esci2_info(s); + if (*status != SANE_STATUS_GOOD) + goto close; + + *status = esci2_capa(s); + if (*status != SANE_STATUS_GOOD) + goto close; + + *status = esci2_resa(s); + if (*status != SANE_STATUS_GOOD) + goto close; + + /* assume 1 and 8 bit are always supported */ + eds_add_depth(s->hw, 1); + eds_add_depth(s->hw, 8); + + /* setup area according to available options */ + if (s->hw->has_fb) { + + dev->x_range = &dev->fbf_x_range; + dev->y_range = &dev->fbf_y_range; + dev->alignment = dev->fbf_alignment; + + } else if (s->hw->has_adf) { + + dev->x_range = &dev->adf_x_range; + dev->y_range = &dev->adf_y_range; + dev->alignment = dev->adf_alignment; + + } else { + DBG(0, "unable to lay on the flatbed or feed the feeder. is that a scanner??\n"); + } + + *status = eds_dev_post_init(dev); + if (*status != SANE_STATUS_GOOD) + goto close; + + DBG(1, "scanner model: %s\n", dev->model); + + /* add this scanner to the device list */ + + num_devices++; + dev->next = first_dev; + first_dev = dev; + + return s; + +close: + DBG(1, " failed\n"); + + close_scanner(s); + return NULL; +} + + +static SANE_Status +attach(const char *name, int type) +{ + SANE_Status status; + epsonds_scanner * s; + + DBG(7, "%s: devname = %s, type = %d\n", __func__, name, type); + + s = device_detect(name, type, &status); + if (s == NULL) + return status; + + close_scanner(s); + return status; +} + +SANE_Status +attach_one_usb(const char *dev) +{ + DBG(7, "%s: dev = %s\n", __func__, dev); + return attach(dev, SANE_EPSONDS_USB); +} + +static SANE_Status +attach_one_config(SANEI_Config __sane_unused__ *config, const char *line) +{ + int vendor, product; + + int len = strlen(line); + + DBG(7, "%s: len = %d, line = %s\n", __func__, len, line); + + if (sscanf(line, "usb %i %i", &vendor, &product) == 2) { + + DBG(7, " user configured device\n"); + + if (vendor != SANE_EPSONDS_VENDOR_ID) + return SANE_STATUS_INVAL; /* this is not an Epson device */ + + sanei_usb_attach_matching_devices(line, attach_one_usb); + + } else if (strncmp(line, "usb", 3) == 0 && len == 3) { + + int i, numIds; + + DBG(7, " probing usb devices\n"); + + numIds = epsonds_get_number_of_ids(); + + for (i = 0; i < numIds; i++) { + sanei_usb_find_devices(SANE_EPSONDS_VENDOR_ID, + epsonds_usb_product_ids[i], attach_one_usb); + } + + } else { + DBG(0, "unable to parse config line: %s\n", line); + } + + return SANE_STATUS_GOOD; +} + +static void +free_devices(void) +{ + epsonds_device *dev, *next; + + for (dev = first_dev; dev; dev = next) { + next = dev->next; + free(dev->name); + free(dev->model); + free(dev); + } + + free(devlist); + first_dev = NULL; +} + +static void +probe_devices(void) +{ + DBG(5, "%s\n", __func__); + + free_devices(); + sanei_configure_attach(EPSONDS_CONFIG_FILE, NULL, attach_one_config); +} + +/**** SANE API ****/ + +SANE_Status +sane_init(SANE_Int *version_code, SANE_Auth_Callback __sane_unused__ authorize) +{ + DBG_INIT(); + DBG(2, "%s: " PACKAGE " " VERSION "\n", __func__); + + DBG(1, "epsonds backend, version %i.%i.%i\n", + EPSONDS_VERSION, EPSONDS_REVISION, EPSONDS_BUILD); + + if (version_code != NULL) + *version_code = SANE_VERSION_CODE(SANE_CURRENT_MAJOR, V_MINOR, + EPSONDS_BUILD); + + sanei_usb_init(); + + return SANE_STATUS_GOOD; +} + +void +sane_exit(void) +{ + DBG(5, "** %s\n", __func__); + free_devices(); +} + +SANE_Status +sane_get_devices(const SANE_Device ***device_list, SANE_Bool __sane_unused__ local_only) +{ + int i; + epsonds_device *dev; + + DBG(5, "** %s\n", __func__); + + probe_devices(); + + devlist = malloc((num_devices + 1) * sizeof(devlist[0])); + if (!devlist) { + DBG(1, "out of memory (line %d)\n", __LINE__); + return SANE_STATUS_NO_MEM; + } + + DBG(5, "%s - results:\n", __func__); + + for (i = 0, dev = first_dev; i < num_devices && dev; dev = dev->next, i++) { + DBG(1, " %d (%d): %s\n", i, dev->connection, dev->model); + devlist[i] = &dev->sane; + } + + devlist[i] = NULL; + + *device_list = devlist; + + return SANE_STATUS_GOOD; +} + +static SANE_Status +init_options(epsonds_scanner *s) +{ + int i; + + for (i = 0; i < NUM_OPTIONS; i++) { + s->opt[i].size = sizeof(SANE_Word); + s->opt[i].cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT; + } + + s->opt[OPT_NUM_OPTS].title = SANE_TITLE_NUM_OPTIONS; + s->opt[OPT_NUM_OPTS].desc = SANE_DESC_NUM_OPTIONS; + s->opt[OPT_NUM_OPTS].type = SANE_TYPE_INT; + s->opt[OPT_NUM_OPTS].cap = SANE_CAP_SOFT_DETECT; + s->val[OPT_NUM_OPTS].w = NUM_OPTIONS; + + /* "Scan Mode" group: */ + + s->opt[OPT_MODE_GROUP].title = SANE_I18N("Scan Mode"); + s->opt[OPT_MODE_GROUP].desc = ""; + s->opt[OPT_MODE_GROUP].type = SANE_TYPE_GROUP; + s->opt[OPT_MODE_GROUP].cap = 0; + + /* scan mode */ + s->opt[OPT_MODE].name = SANE_NAME_SCAN_MODE; + 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(mode_list); + s->opt[OPT_MODE].constraint_type = SANE_CONSTRAINT_STRING_LIST; + s->opt[OPT_MODE].constraint.string_list = mode_list; + s->val[OPT_MODE].w = 0; /* Lineart */ + + /* bit depth */ + s->opt[OPT_DEPTH].name = SANE_NAME_BIT_DEPTH; + s->opt[OPT_DEPTH].title = SANE_TITLE_BIT_DEPTH; + s->opt[OPT_DEPTH].desc = SANE_DESC_BIT_DEPTH; + s->opt[OPT_DEPTH].type = SANE_TYPE_INT; + s->opt[OPT_DEPTH].unit = SANE_UNIT_BIT; + s->opt[OPT_DEPTH].constraint_type = SANE_CONSTRAINT_WORD_LIST; + s->opt[OPT_DEPTH].constraint.word_list = s->hw->depth_list; + s->val[OPT_DEPTH].w = s->hw->depth_list[1]; /* the first "real" element is the default */ + + /* default is Lineart, disable depth selection */ + s->opt[OPT_DEPTH].cap |= SANE_CAP_INACTIVE; + + /* resolution */ + s->opt[OPT_RESOLUTION].name = SANE_NAME_SCAN_RESOLUTION; + s->opt[OPT_RESOLUTION].title = SANE_TITLE_SCAN_RESOLUTION; + s->opt[OPT_RESOLUTION].desc = SANE_DESC_SCAN_RESOLUTION; + + s->opt[OPT_RESOLUTION].type = SANE_TYPE_INT; + s->opt[OPT_RESOLUTION].unit = SANE_UNIT_DPI; + + /* range */ + if (s->hw->dpi_range.quant) { + s->opt[OPT_RESOLUTION].constraint_type = SANE_CONSTRAINT_RANGE; + s->opt[OPT_RESOLUTION].constraint.range = &s->hw->dpi_range; + s->val[OPT_RESOLUTION].w = s->hw->dpi_range.min; + } else { /* list */ + s->opt[OPT_RESOLUTION].constraint_type = SANE_CONSTRAINT_WORD_LIST; + s->opt[OPT_RESOLUTION].constraint.word_list = s->hw->res_list; + s->val[OPT_RESOLUTION].w = s->hw->res_list[1]; + } + + /* "Geometry" group: */ + s->opt[OPT_GEOMETRY_GROUP].title = SANE_I18N("Geometry"); + s->opt[OPT_GEOMETRY_GROUP].desc = ""; + s->opt[OPT_GEOMETRY_GROUP].type = SANE_TYPE_GROUP; + s->opt[OPT_GEOMETRY_GROUP].cap = SANE_CAP_ADVANCED; + + /* top-left x */ + s->opt[OPT_TL_X].name = SANE_NAME_SCAN_TL_X; + s->opt[OPT_TL_X].title = SANE_TITLE_SCAN_TL_X; + s->opt[OPT_TL_X].desc = SANE_DESC_SCAN_TL_X; + s->opt[OPT_TL_X].type = SANE_TYPE_FIXED; + s->opt[OPT_TL_X].unit = SANE_UNIT_MM; + s->opt[OPT_TL_X].constraint_type = SANE_CONSTRAINT_RANGE; + s->opt[OPT_TL_X].constraint.range = s->hw->x_range; + s->val[OPT_TL_X].w = 0; + + /* top-left y */ + s->opt[OPT_TL_Y].name = SANE_NAME_SCAN_TL_Y; + s->opt[OPT_TL_Y].title = SANE_TITLE_SCAN_TL_Y; + s->opt[OPT_TL_Y].desc = SANE_DESC_SCAN_TL_Y; + + s->opt[OPT_TL_Y].type = SANE_TYPE_FIXED; + s->opt[OPT_TL_Y].unit = SANE_UNIT_MM; + s->opt[OPT_TL_Y].constraint_type = SANE_CONSTRAINT_RANGE; + s->opt[OPT_TL_Y].constraint.range = s->hw->y_range; + s->val[OPT_TL_Y].w = 0; + + /* bottom-right x */ + s->opt[OPT_BR_X].name = SANE_NAME_SCAN_BR_X; + s->opt[OPT_BR_X].title = SANE_TITLE_SCAN_BR_X; + s->opt[OPT_BR_X].desc = SANE_DESC_SCAN_BR_X; + + s->opt[OPT_BR_X].type = SANE_TYPE_FIXED; + s->opt[OPT_BR_X].unit = SANE_UNIT_MM; + s->opt[OPT_BR_X].constraint_type = SANE_CONSTRAINT_RANGE; + s->opt[OPT_BR_X].constraint.range = s->hw->x_range; + s->val[OPT_BR_X].w = s->hw->x_range->max; + + /* bottom-right y */ + s->opt[OPT_BR_Y].name = SANE_NAME_SCAN_BR_Y; + s->opt[OPT_BR_Y].title = SANE_TITLE_SCAN_BR_Y; + s->opt[OPT_BR_Y].desc = SANE_DESC_SCAN_BR_Y; + + s->opt[OPT_BR_Y].type = SANE_TYPE_FIXED; + s->opt[OPT_BR_Y].unit = SANE_UNIT_MM; + s->opt[OPT_BR_Y].constraint_type = SANE_CONSTRAINT_RANGE; + s->opt[OPT_BR_Y].constraint.range = s->hw->y_range; + s->val[OPT_BR_Y].w = s->hw->y_range->max; + + /* "Optional equipment" group: */ + s->opt[OPT_EQU_GROUP].title = SANE_I18N("Optional equipment"); + s->opt[OPT_EQU_GROUP].desc = ""; + s->opt[OPT_EQU_GROUP].type = SANE_TYPE_GROUP; + s->opt[OPT_EQU_GROUP].cap = SANE_CAP_ADVANCED; + + /* source */ + s->opt[OPT_SOURCE].name = SANE_NAME_SCAN_SOURCE; + 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(source_list); + s->opt[OPT_SOURCE].constraint_type = SANE_CONSTRAINT_STRING_LIST; + s->opt[OPT_SOURCE].constraint.string_list = source_list; + s->val[OPT_SOURCE].w = 0; + + s->opt[OPT_EJECT].name = "eject"; + s->opt[OPT_EJECT].title = SANE_I18N("Eject"); + s->opt[OPT_EJECT].desc = SANE_I18N("Eject the sheet in the ADF"); + s->opt[OPT_EJECT].type = SANE_TYPE_BUTTON; + + if (!s->hw->adf_has_eject) + s->opt[OPT_EJECT].cap |= SANE_CAP_INACTIVE; + + s->opt[OPT_LOAD].name = "load"; + s->opt[OPT_LOAD].title = SANE_I18N("Load"); + s->opt[OPT_LOAD].desc = SANE_I18N("Load a sheet in the ADF"); + s->opt[OPT_LOAD].type = SANE_TYPE_BUTTON; + + if (!s->hw->adf_has_load) + s->opt[OPT_LOAD].cap |= SANE_CAP_INACTIVE; + + s->opt[OPT_ADF_MODE].name = "adf-mode"; + s->opt[OPT_ADF_MODE].title = SANE_I18N("ADF Mode"); + s->opt[OPT_ADF_MODE].desc = + SANE_I18N("Selects the ADF mode (simplex/duplex)"); + s->opt[OPT_ADF_MODE].type = SANE_TYPE_STRING; + s->opt[OPT_ADF_MODE].size = max_string_size(adf_mode_list); + s->opt[OPT_ADF_MODE].constraint_type = SANE_CONSTRAINT_STRING_LIST; + s->opt[OPT_ADF_MODE].constraint.string_list = adf_mode_list; + s->val[OPT_ADF_MODE].w = 0; /* simplex */ + + if (!s->hw->adf_is_duplex) + s->opt[OPT_ADF_MODE].cap |= SANE_CAP_INACTIVE; + + s->opt[OPT_ADF_SKEW].name = "adf-skew"; + s->opt[OPT_ADF_SKEW].title = SANE_I18N("ADF Skew Correction"); + s->opt[OPT_ADF_SKEW].desc = + SANE_I18N("Enables ADF skew correction"); + s->opt[OPT_ADF_SKEW].type = SANE_TYPE_BOOL; + s->val[OPT_ADF_SKEW].w = 0; + + if (!s->hw->adf_has_skew) + s->opt[OPT_ADF_SKEW].cap |= SANE_CAP_INACTIVE; + + return SANE_STATUS_GOOD; +} + +SANE_Status +sane_open(SANE_String_Const name, SANE_Handle *handle) +{ + SANE_Status status; + epsonds_scanner *s = NULL; + + DBG(7, "** %s: name = '%s'\n", __func__, name); + + /* probe if empty device name provided */ + if (name[0] == '\0') { + + probe_devices(); + + if (first_dev == NULL) { + DBG(1, "no devices detected\n"); + return SANE_STATUS_INVAL; + } + + s = device_detect(first_dev->sane.name, first_dev->connection, + &status); + if (s == NULL) { + DBG(1, "cannot open a perfectly valid device (%s)," + " please report to the authors\n", name); + return SANE_STATUS_INVAL; + } + + } else { + + if (strncmp(name, "libusb:", 7) == 0) { + s = device_detect(name, SANE_EPSONDS_USB, &status); + if (s == NULL) + return status; + } else { + DBG(1, "invalid device name: %s\n", name); + return SANE_STATUS_INVAL; + } + } + + /* s is always valid here */ + + DBG(5, "%s: handle obtained\n", __func__); + + init_options(s); + + *handle = (SANE_Handle)s; + + status = open_scanner(s); + if (status != SANE_STATUS_GOOD) { + free(s); + return status; + } + + /* lock scanner if required */ + if (!s->locked) { + status = eds_lock(s); + } + + return status; +} + +void +sane_close(SANE_Handle handle) +{ + epsonds_scanner *s = (epsonds_scanner *)handle; + + DBG(1, "** %s\n", __func__); + + close_scanner(s); +} + +const SANE_Option_Descriptor * +sane_get_option_descriptor(SANE_Handle handle, SANE_Int option) +{ + epsonds_scanner *s = (epsonds_scanner *) handle; + + if (option < 0 || option >= NUM_OPTIONS) + return NULL; + + return s->opt + option; +} + +static const SANE_String_Const * +search_string_list(const SANE_String_Const *list, SANE_String value) +{ + while (*list != NULL && strcmp(value, *list) != 0) + list++; + + return ((*list == NULL) ? NULL : list); +} + +static void +activateOption(epsonds_scanner *s, SANE_Int option, SANE_Bool *change) +{ + if (!SANE_OPTION_IS_ACTIVE(s->opt[option].cap)) { + s->opt[option].cap &= ~SANE_CAP_INACTIVE; + *change = SANE_TRUE; + } +} + +static void +deactivateOption(epsonds_scanner *s, SANE_Int option, SANE_Bool *change) +{ + if (SANE_OPTION_IS_ACTIVE(s->opt[option].cap)) { + s->opt[option].cap |= SANE_CAP_INACTIVE; + *change = SANE_TRUE; + } +} + +/* + * Handles setting the source (flatbed, transparency adapter (TPU), + * or auto document feeder (ADF)). + * + * For newer scanners it also sets the focus according to the + * glass / TPU settings. + */ + +static void +change_source(epsonds_scanner *s, SANE_Int optindex, char *value) +{ + int force_max = SANE_FALSE; + SANE_Bool dummy; + + DBG(1, "%s: optindex = %d, source = '%s'\n", __func__, optindex, + value); + + s->val[OPT_SOURCE].w = optindex; + + /* if current selected area is the maximum available, + * keep this setting on the new source. + */ + if (s->val[OPT_TL_X].w == s->hw->x_range->min + && s->val[OPT_TL_Y].w == s->hw->y_range->min + && s->val[OPT_BR_X].w == s->hw->x_range->max + && s->val[OPT_BR_Y].w == s->hw->y_range->max) { + force_max = SANE_TRUE; + } + + if (strcmp(ADF_STR, value) == 0) { + + s->hw->x_range = &s->hw->adf_x_range; + s->hw->y_range = &s->hw->adf_y_range; + s->hw->alignment = s->hw->adf_alignment; + + if (s->hw->adf_is_duplex) { + activateOption(s, OPT_ADF_MODE, &dummy); + } else { + deactivateOption(s, OPT_ADF_MODE, &dummy); + s->val[OPT_ADF_MODE].w = 0; + } + + } else if (strcmp(TPU_STR, value) == 0) { + + s->hw->x_range = &s->hw->tpu_x_range; + s->hw->y_range = &s->hw->tpu_y_range; + + deactivateOption(s, OPT_ADF_MODE, &dummy); + + } else { + + /* neither ADF nor TPU active, assume FB */ + s->hw->x_range = &s->hw->fbf_x_range; + s->hw->y_range = &s->hw->fbf_y_range; + s->hw->alignment = s->hw->fbf_alignment; + } + + s->opt[OPT_BR_X].constraint.range = s->hw->x_range; + s->opt[OPT_BR_Y].constraint.range = s->hw->y_range; + + if (s->val[OPT_TL_X].w < s->hw->x_range->min || force_max) + s->val[OPT_TL_X].w = s->hw->x_range->min; + + if (s->val[OPT_TL_Y].w < s->hw->y_range->min || force_max) + s->val[OPT_TL_Y].w = s->hw->y_range->min; + + if (s->val[OPT_BR_X].w > s->hw->x_range->max || force_max) + s->val[OPT_BR_X].w = s->hw->x_range->max; + + if (s->val[OPT_BR_Y].w > s->hw->y_range->max || force_max) + s->val[OPT_BR_Y].w = s->hw->y_range->max; +} + +static SANE_Status +getvalue(SANE_Handle handle, SANE_Int option, void *value) +{ + epsonds_scanner *s = (epsonds_scanner *)handle; + SANE_Option_Descriptor *sopt = &(s->opt[option]); + Option_Value *sval = &(s->val[option]); + + DBG(17, "%s: option = %d\n", __func__, option); + + switch (option) { + + case OPT_NUM_OPTS: + case OPT_RESOLUTION: + case OPT_TL_X: + case OPT_TL_Y: + case OPT_BR_X: + case OPT_BR_Y: + case OPT_DEPTH: + case OPT_ADF_SKEW: + *((SANE_Word *) value) = sval->w; + break; + + case OPT_MODE: + case OPT_ADF_MODE: + case OPT_SOURCE: + strcpy((char *) value, sopt->constraint.string_list[sval->w]); + break; + + default: + return SANE_STATUS_INVAL; + } + + return SANE_STATUS_GOOD; +} + +static SANE_Status +setvalue(SANE_Handle handle, SANE_Int option, void *value, SANE_Int *info) +{ + epsonds_scanner *s = (epsonds_scanner *) handle; + SANE_Option_Descriptor *sopt = &(s->opt[option]); + Option_Value *sval = &(s->val[option]); + + SANE_Status status; + const SANE_String_Const *optval = NULL; + int optindex = 0; + SANE_Bool reload = SANE_FALSE; + + DBG(17, "** %s: option = %d, value = %p\n", __func__, option, value); + + status = sanei_constrain_value(sopt, value, info); + if (status != SANE_STATUS_GOOD) + return status; + + if (info && value && (*info & SANE_INFO_INEXACT) + && sopt->type == SANE_TYPE_INT) + DBG(17, " constrained val = %d\n", *(SANE_Word *) value); + + if (sopt->constraint_type == SANE_CONSTRAINT_STRING_LIST) { + optval = search_string_list(sopt->constraint.string_list, + (char *) value); + if (optval == NULL) + return SANE_STATUS_INVAL; + optindex = optval - sopt->constraint.string_list; + } + + /* block faulty frontends */ + if (sopt->cap & SANE_CAP_INACTIVE) { + DBG(1, " tried to modify a disabled parameter"); + return SANE_STATUS_INVAL; + } + + switch (option) { + + case OPT_ADF_MODE: /* simple lists */ + sval->w = optindex; + break; + + case OPT_ADF_SKEW: + case OPT_RESOLUTION: + sval->w = *((SANE_Word *) value); + reload = SANE_TRUE; + break; + + case OPT_BR_X: + case OPT_BR_Y: + sval->w = *((SANE_Word *) value); + if (SANE_UNFIX(sval->w) == 0) { + DBG(17, " invalid br-x or br-y\n"); + return SANE_STATUS_INVAL; + } + /* passthru */ + case OPT_TL_X: + case OPT_TL_Y: + sval->w = *((SANE_Word *) value); + if (NULL != info) + *info |= SANE_INFO_RELOAD_PARAMS; + break; + + case OPT_SOURCE: + change_source(s, optindex, (char *) value); + reload = SANE_TRUE; + break; + + case OPT_MODE: + { + /* use JPEG mode if RAW is not available when bpp > 1 */ + if (optindex > 0 && !s->hw->has_raw) { + s->mode_jpeg = 1; + } else { + s->mode_jpeg = 0; + } + + sval->w = optindex; + + /* if binary, then disable the bit depth selection */ + if (optindex == 0) { + s->opt[OPT_DEPTH].cap |= SANE_CAP_INACTIVE; + } else { + if (s->hw->depth_list[0] == 1) + s->opt[OPT_DEPTH].cap |= SANE_CAP_INACTIVE; + else { + s->opt[OPT_DEPTH].cap &= ~SANE_CAP_INACTIVE; + s->val[OPT_DEPTH].w = + mode_params[optindex].depth; + } + } + + reload = SANE_TRUE; + break; + } + + case OPT_DEPTH: + sval->w = *((SANE_Word *) value); + mode_params[s->val[OPT_MODE].w].depth = sval->w; + reload = SANE_TRUE; + break; + + case OPT_LOAD: + esci2_mech(s, "#ADFLOAD"); + break; + + case OPT_EJECT: + esci2_mech(s, "#ADFEJCT"); + break; + + default: + return SANE_STATUS_INVAL; + } + + if (reload && info != NULL) + *info |= SANE_INFO_RELOAD_OPTIONS | SANE_INFO_RELOAD_PARAMS; + + return SANE_STATUS_GOOD; +} + +SANE_Status +sane_control_option(SANE_Handle handle, SANE_Int option, SANE_Action action, + void *value, SANE_Int *info) +{ + DBG(17, "** %s: action = %x, option = %d\n", __func__, action, option); + + if (option < 0 || option >= NUM_OPTIONS) + return SANE_STATUS_INVAL; + + if (info != NULL) + *info = 0; + + switch (action) { + case SANE_ACTION_GET_VALUE: + return getvalue(handle, option, value); + + case SANE_ACTION_SET_VALUE: + return setvalue(handle, option, value, info); + + default: + return SANE_STATUS_INVAL; + } + + return SANE_STATUS_INVAL; +} + +SANE_Status +sane_get_parameters(SANE_Handle handle, SANE_Parameters *params) +{ + epsonds_scanner *s = (epsonds_scanner *)handle; + + DBG(5, "** %s\n", __func__); + + if (params == NULL) + DBG(1, "%s: params is NULL\n", __func__); + + /* + * If sane_start was already called, then just retrieve the parameters + * from the scanner data structure + */ + if (s->scanning) { + DBG(5, "scan in progress, returning saved params structure\n"); + } else { + /* otherwise initialize the params structure */ + eds_init_parameters(s); + } + + if (params != NULL) + *params = s->params; + + print_params(s->params); + + return SANE_STATUS_GOOD; +} + +/* + * This function is part of the SANE API and gets called from the front end to + * start the scan process. + */ + +SANE_Status +sane_start(SANE_Handle handle) +{ + epsonds_scanner *s = (epsonds_scanner *)handle; + char buf[64]; + char cmd[100]; /* take care not to overflow */ + SANE_Status status = 0; + + s->pages++; + + DBG(5, "** %s, pages = %d, scanning = %d, backside = %d, front fill: %d, back fill: %d\n", + __func__, s->pages, s->scanning, s->backside, + eds_ring_avail(&s->front), + eds_ring_avail(&s->back)); + + s->eof = 0; + s->canceling = 0; + + if ((s->pages % 2) == 1) { + s->current = &s->front; + eds_ring_flush(s->current); + } else if (eds_ring_avail(&s->back)) { + DBG(5, "back side\n"); + s->current = &s->back; + } + + /* prepare the JPEG decompressor */ + if (s->mode_jpeg) { + status = eds_jpeg_start(s); + if (status != SANE_STATUS_GOOD) { + goto end; + } } + + /* scan already in progress? (one pass adf) */ + if (s->scanning) { + DBG(5, " scan in progress, returning early\n"); + return SANE_STATUS_GOOD; + } + + /* calc scanning parameters */ + status = eds_init_parameters(s); + if (status != SANE_STATUS_GOOD) { + DBG(1, " parameters initialization failed\n"); + return status; + } + + /* allocate line buffer */ + s->line_buffer = realloc(s->line_buffer, s->params.bytes_per_line); + if (s->line_buffer == NULL) + return SANE_STATUS_NO_MEM; + + /* ring buffer for front page, twice bsz */ + /* XXX read value from scanner */ + status = eds_ring_init(&s->front, (65536 * 4) * 2); + if (status != SANE_STATUS_GOOD) { + return status; + } + + /* transfer buffer, bsz */ + /* XXX read value from scanner */ + s->buf = realloc(s->buf, 65536 * 4); + if (s->buf == NULL) + return SANE_STATUS_NO_MEM; + + print_params(s->params); + + /* set scanning parameters */ + + /* document source */ + if (strcmp(source_list[s->val[OPT_SOURCE].w], ADF_STR) == 0) { + + sprintf(buf, "#ADF%s%s", + s->val[OPT_ADF_MODE].w ? "DPLX" : "", + s->val[OPT_ADF_SKEW].w ? "SKEW" : ""); + + if (s->hw->adf_has_dfd == 2) { + strcat(buf, "DFL2"); + } else if (s->hw->adf_has_dfd == 1) { + strcat(buf, "DFL1"); + } + + } else if (strcmp(source_list[s->val[OPT_SOURCE].w], FBF_STR) == 0) { + + strcpy(buf, "#FB "); + + } else { + /* XXX */ + } + + strcpy(cmd, buf); + + if (s->params.format == SANE_FRAME_GRAY) { + sprintf(buf, "#COLM%03d", s->params.depth); + } else if (s->params.format == SANE_FRAME_RGB) { + sprintf(buf, "#COLC%03d", s->params.depth * 3); + } + + strcat(cmd, buf); + + /* image transfer format */ + if (!s->mode_jpeg) { + if (s->params.depth > 1 || s->hw->has_raw) { + strcat(cmd, "#FMTRAW "); + } + } else { + strcat(cmd, "#FMTJPG #JPGd090"); + } + + /* resolution (RSMi not always supported) */ + + if (s->val[OPT_RESOLUTION].w > 999) { + sprintf(buf, "#RSMi%07d", s->val[OPT_RESOLUTION].w); + } else { + sprintf(buf, "#RSMd%03d", s->val[OPT_RESOLUTION].w); + } + + strcat(cmd, buf); + + /* scanning area */ + sprintf(buf, "#ACQi%07di%07di%07di%07d", + s->left, s->top, s->params.pixels_per_line, s->params.lines); + + strcat(cmd, buf); + + status = esci2_para(s, cmd); + if (status != SANE_STATUS_GOOD) { + goto end; + } + + /* start scanning */ + DBG(1, "%s: scanning...\n", __func__); + + /* switch to data state */ + status = esci2_trdt(s); + if (status != SANE_STATUS_GOOD) { + goto end; + } + + /* first page is page 1 */ + s->pages = 1; + s->scanning = 1; + +end: + if (status != SANE_STATUS_GOOD) { + DBG(1, "%s: start failed: %s\n", __func__, sane_strstatus(status)); + } + + return status; +} + +/* this moves data from our buffers to SANE */ + +SANE_Status +sane_read(SANE_Handle handle, SANE_Byte *data, SANE_Int max_length, + SANE_Int *length) +{ + SANE_Int read = 0, tries = 3; + SANE_Int available; + SANE_Status status = 0; + epsonds_scanner *s = (epsonds_scanner *)handle; + + *length = read = 0; + + DBG(20, "** %s: backside = %d\n", __func__, s->backside); + + /* sane_read called before sane_start? */ + if (s->current == NULL) { + DBG(0, "%s: buffer is NULL", __func__); + return SANE_STATUS_INVAL; + } + + /* anything in the buffer? pass it to the frontend */ + available = eds_ring_avail(s->current); + if (available) { + + DBG(18, "reading from ring buffer, %d left\n", available); + + if (s->mode_jpeg && !s->jpeg_header_seen) { + + status = eds_jpeg_read_header(s); + if (status != SANE_STATUS_GOOD && --tries) { + goto read_again; + } + } + + if (s->mode_jpeg) { + eds_jpeg_read(handle, data, max_length, &read); + } else { + eds_copy_image_from_ring(s, data, max_length, &read); + } + + if (read == 0) { + goto read_again; + } + + *length = read; + + return SANE_STATUS_GOOD; + + + } else if (s->current == &s->back) { + + /* finished reading the back page, next + * command should give us the EOF + */ + DBG(18, "back side ring buffer empty\n"); + } + + /* read until data or error */ + +read_again: + + status = esci2_img(s, &read); + if (status != SANE_STATUS_GOOD) { + DBG(20, "read: %d, eof: %d, backside: %d, status: %d\n", read, s->eof, s->backside, status); + } + + /* just got a back side page, alloc ring buffer if necessary + * we didn't before because dummy was not known + */ + if (s->backside) { + + int required = s->params.lines * (s->params.bytes_per_line + s->dummy); + + if (s->back.size < required) { + + DBG(20, "allocating buffer for the back side\n"); + + status = eds_ring_init(&s->back, required); + if (status != SANE_STATUS_GOOD) { + return status; + } + } + } + + /* abort scanning when appropriate */ + if (status == SANE_STATUS_CANCELLED) { + esci2_can(s); + return status; + } + + if (s->eof && s->backside) { + DBG(18, "back side scan finished\n"); + } + + /* read again if no error and no data */ + if (read == 0 && status == SANE_STATUS_GOOD) { + goto read_again; + } + + /* got something, write to ring */ + if (read) { + + DBG(20, " %d bytes read, %d lines, eof: %d, canceling: %d, status: %d, backside: %d\n", + read, read / (s->params.bytes_per_line + s->dummy), + s->canceling, s->eof, status, s->backside); + + /* move data to the appropriate ring */ + status = eds_ring_write(s->backside ? &s->back : &s->front, s->buf, read); + + if (0 && s->mode_jpeg && !s->jpeg_header_seen + && status == SANE_STATUS_GOOD) { + + status = eds_jpeg_read_header(s); + if (status != SANE_STATUS_GOOD && --tries) { + goto read_again; + } + } + } + + /* continue reading if appropriate */ + if (status == SANE_STATUS_GOOD) + return status; + + /* cleanup */ + DBG(5, "** %s: cleaning up\n", __func__); + + if (s->mode_jpeg) { + eds_jpeg_finish(s); + } + + eds_ring_flush(s->current); + + return status; +} + +/* + * void sane_cancel(SANE_Handle handle) + * + * Set the cancel flag to true. The next time the backend requests data + * from the scanner the CAN message will be sent. + */ + +void +sane_cancel(SANE_Handle handle) +{ + DBG(1, "** %s\n", __func__); + ((epsonds_scanner *)handle)->canceling = SANE_TRUE; +} + +/* + * SANE_Status sane_set_io_mode() + * + * not supported - for asynchronous I/O + */ + +SANE_Status +sane_set_io_mode(SANE_Handle __sane_unused__ handle, + SANE_Bool __sane_unused__ non_blocking) +{ + return SANE_STATUS_UNSUPPORTED; +} + +/* + * SANE_Status sane_get_select_fd() + * + * not supported - for asynchronous I/O + */ + +SANE_Status +sane_get_select_fd(SANE_Handle __sane_unused__ handle, + SANE_Int __sane_unused__ *fd) +{ + return SANE_STATUS_UNSUPPORTED; +} diff --git a/backend/epsonds.conf.in b/backend/epsonds.conf.in new file mode 100644 index 0000000..23dc461 --- /dev/null +++ b/backend/epsonds.conf.in @@ -0,0 +1,12 @@ +# epsonds.conf +# +# here are some examples for how to configure the epsonds backend + +# USB +usb + +# For libusb support for unknown scanners use the following command +# usb <vendor ID> <product ID> +# e.g.: +# usb 0x4b8 0x14c + diff --git a/backend/epsonds.h b/backend/epsonds.h new file mode 100644 index 0000000..024773b --- /dev/null +++ b/backend/epsonds.h @@ -0,0 +1,199 @@ +/* + * epsonds.c - Epson ESC/I-2 driver. + * + * Copyright (C) 2015 Tower Technologies + * Author: Alessandro Zummo <a.zummo@towertech.it> + * + * This file is part of the SANE package. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, version 2. + */ + +#ifndef epsonds_h +#define epsonds_h + +#undef BACKEND_NAME +#define BACKEND_NAME epsonds +#define DEBUG_NOT_STATIC + +#ifdef HAVE_SYS_IOCTL_H +#include <sys/ioctl.h> +#endif + +#ifdef HAVE_STDDEF_H +#include <stddef.h> +#endif + +#ifdef HAVE_STDLIB_H +#include <stdlib.h> +#endif + +#ifdef NEED_SYS_TYPES_H +#include <sys/types.h> +#endif + +#include <string.h> /* for memset and memcpy */ +#include <stdio.h> + +#include "sane/sane.h" +#include "sane/sanei_backend.h" +#include "sane/sanei_debug.h" +#include "sane/sanei_usb.h" +#include "sane/sanei_jpeg.h" + +#ifdef __GNUC__ +#define __func__ __FUNCTION__ +#else +#define __func__ "(undef)" +/* I cast my vote for C99... :) */ +#endif + +#define EPSONDS_CONFIG_FILE "epsonds.conf" + +#ifndef PATH_MAX +#define PATH_MAX (1024) +#endif + +#ifndef XtNumber +#define XtNumber(x) (sizeof(x) / sizeof(x[0])) +#define XtOffset(p_type, field) ((size_t)&(((p_type)NULL)->field)) +#define XtOffsetOf(s_type, field) XtOffset(s_type*, field) +#endif + +#define ACK 0x06 +#define NAK 0x15 +#define FS 0x1C + +#define FBF_STR SANE_I18N("Flatbed") +#define TPU_STR SANE_I18N("Transparency Unit") +#define ADF_STR SANE_I18N("Automatic Document Feeder") + +enum { + OPT_NUM_OPTS = 0, + OPT_MODE_GROUP, + OPT_MODE, + OPT_DEPTH, + OPT_RESOLUTION, + OPT_GEOMETRY_GROUP, + OPT_TL_X, + OPT_TL_Y, + OPT_BR_X, + OPT_BR_Y, + OPT_EQU_GROUP, + OPT_SOURCE, + OPT_EJECT, + OPT_LOAD, + OPT_ADF_MODE, + OPT_ADF_SKEW, + NUM_OPTIONS +}; + +typedef enum +{ /* hardware connection to the scanner */ + SANE_EPSONDS_NODEV, /* default, no HW specified yet */ + SANE_EPSONDS_USB, /* USB interface */ + SANE_EPSONDS_NET /* network interface (unsupported)*/ +} epsonds_conn_type; + +/* hardware description */ + +struct epsonds_device +{ + struct epsonds_device *next; + + epsonds_conn_type connection; + + char *name; + char *model; + + unsigned int model_id; + + SANE_Device sane; + SANE_Range *x_range; + SANE_Range *y_range; + SANE_Range dpi_range; + SANE_Byte alignment; + + + SANE_Int *res_list; /* list of resolutions */ + SANE_Int *depth_list; + SANE_Int max_depth; /* max. color depth */ + + SANE_Bool has_raw; /* supports RAW format */ + + SANE_Bool has_fb; /* flatbed */ + SANE_Range fbf_x_range; /* x range */ + SANE_Range fbf_y_range; /* y range */ + SANE_Byte fbf_alignment; /* left, center, right */ + SANE_Bool fbf_has_skew; /* supports skew correction */ + + SANE_Bool has_adf; /* adf */ + SANE_Range adf_x_range; /* x range */ + SANE_Range adf_y_range; /* y range */ + SANE_Bool adf_is_duplex; /* supports duplex mode */ + SANE_Bool adf_singlepass; /* supports single pass duplex */ + SANE_Bool adf_has_skew; /* supports skew correction */ + SANE_Bool adf_has_load; /* supports load command */ + SANE_Bool adf_has_eject; /* supports eject command */ + SANE_Byte adf_alignment; /* left, center, right */ + SANE_Byte adf_has_dfd; /* supports double feed detection */ + + SANE_Bool has_tpu; /* tpu */ + SANE_Range tpu_x_range; /* transparency unit x range */ + SANE_Range tpu_y_range; /* transparency unit y range */ +}; + +typedef struct epsonds_device epsonds_device; + +typedef struct ring_buffer +{ + SANE_Byte *ring, *wp, *rp, *end; + SANE_Int fill, size; + +} ring_buffer; + +/* an instance of a scanner */ + +struct epsonds_scanner +{ + struct epsonds_scanner *next; + struct epsonds_device *hw; + + int fd; + + SANE_Option_Descriptor opt[NUM_OPTIONS]; + Option_Value val[NUM_OPTIONS]; + SANE_Parameters params; + + SANE_Byte *buf, *line_buffer; + ring_buffer *current, front, back; + + SANE_Bool eof, scanning, canceling, locked, backside, mode_jpeg; + + SANE_Int left, top, pages, dummy; + + /* jpeg stuff */ + + djpeg_dest_ptr jdst; + struct jpeg_decompress_struct jpeg_cinfo; + struct jpeg_error_mgr jpeg_err; + SANE_Bool jpeg_header_seen; +}; + +typedef struct epsonds_scanner epsonds_scanner; + +struct mode_param +{ + int color; + int flags; + int dropout_mask; + int depth; +}; + +enum { + MODE_BINARY, MODE_GRAY, MODE_COLOR +}; + +#endif diff --git a/backend/fujitsu-scsi.h b/backend/fujitsu-scsi.h index 52ac7c6..de6652c 100644 --- a/backend/fujitsu-scsi.h +++ b/backend/fujitsu-scsi.h @@ -330,6 +330,7 @@ putnbyte (unsigned char *pnt, unsigned int value, unsigned int nbytes) #define get_IN_skew_check(in) getbitfield(in+0x6d, 1, 7) #define get_IN_new_fd_roll(in) getbitfield(in+0x6d, 1, 6) +#define get_IN_paper_prot_2(in) getbitfield(in+0x6d, 1, 1) #define get_IN_evpd_len(in) getnbyte(in + 0x6f, 1) @@ -364,8 +365,20 @@ putnbyte (unsigned char *pnt, unsigned int value, unsigned int nbytes) /*byte 75 is poorly documented*/ +#define get_IN_erp_lot6_supp(in) getbitfield(in+0x76, 1, 7) +#define get_IN_mode_change_jpeg(in) getbitfield(in+0x76, 1, 5) +#define get_IN_mode_change_irdc(in) getbitfield(in+0x76, 1, 4) +#define get_IN_mode_change_iomf(in) getbitfield(in+0x76, 1, 3) #define get_IN_sync_next_feed(in) getbitfield(in+0x76, 0x07, 0) +#define get_IN_imp_func3(in) getbitfield(in+0x77, 1, 7) + +#define get_IN_reset_ms(in) getbitfield(in+0x78, 1, 7) +#define get_IN_read_size(in) getbitfield(in+0x78, 1, 6) +#define get_IN_start_end_ms(in) getbitfield(in+0x78, 1, 5) + +#define get_IN_op_halt(in) getbitfield(in+0x7a, 1, 7) + /* some scanners need evpd inquiry data manipulated */ #define set_IN_page_length(in,val) in[0x04]=val @@ -429,6 +442,7 @@ putnbyte (unsigned char *pnt, unsigned int value, unsigned int nbytes) #define set_MSEL_df_paperprot(sb, val) setbitfield(sb + 3, 3, 6, val) #define set_MSEL_df_stapledet(sb, val) setbitfield(sb + 3, 3, 4, val) #define set_MSEL_df_recovery(sb, val) setbitfield(sb + 3, 3, 2, val) +#define set_MSEL_df_paperprot2(sb, val) setbitfield(sb + 5, 3, 6, val) #define set_MSEL_dropout_front(sb, val) setbitfield(sb + 0x02, 0x0f, 0, val) #define set_MSEL_dropout_back(sb, val) setbitfield(sb + 0x02, 0x0f, 4, val) @@ -548,6 +562,13 @@ putnbyte (unsigned char *pnt, unsigned int value, unsigned int nbytes) #define set_SD_preread_composition(sb, val) putnbyte(sb + 0x1c, val, 1) #define set_SD_preread_escan(sb, val) putnbyte(sb + 0x1d, val, 1) +#define SD_powoff_string "SET POWOFF TIME " +#define SD_powoff_stringlen 16 +#define SD_powoff_len 18 +#define set_SD_powoff_disable(in, val) setbitfield(in + 16, 1, 7, val) +#define set_SD_powoff_interval(in, val) setbitfield(in + 16, 0x7f, 0, val) +#define set_SD_powoff_notify(sb, val) putnbyte(sb + 0x17, val, 1) + /* ==================================================================== */ /* SET_WINDOW */ #define SET_WINDOW_code 0x24 @@ -675,9 +696,10 @@ putnbyte (unsigned char *pnt, unsigned int value, unsigned int nbytes) #define OBJECT_POSITION_code 0x31 #define OBJECT_POSITION_len 10 -#define set_OP_autofeed(b,val) setbitfield(b+0x01, 0x07, 0, val) +#define set_OP_action(b,val) setbitfield(b+0x01, 0x07, 0, val) #define OP_Discharge 0x00 #define OP_Feed 0x01 +#define OP_Halt 0x04 /* ==================================================================== */ /* SET_SUBWINDOW */ diff --git a/backend/fujitsu.c b/backend/fujitsu.c index 48d55dc..9fddb1c 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-2011 m. allan noah + Copyright (C) 2003-2014 m. allan noah JPEG output and low memory usage support funded by: Archivista GmbH, www.archivista.ch @@ -14,7 +14,7 @@ O A S Oilfield Accounting Service Ltd, www.oas.ca Automatic length detection support funded by: Martin G. Miller, mgmiller at optonline.net - Software image enhancement routines funded by: + Software image enhancement routines and recent scanner support funded by: Fujitsu Computer Products of America, Inc. www.fcpa.com -------------------------------------------------------------------------- @@ -533,11 +533,50 @@ v116 2013-03-23, MAN - call set_mode() in init_interlace - add swskip option - v117 2013-06-11, MAN + v117 2013-06-11, MAN (SANE 1.0.24) - default buffer-mode to off - improved error handling in sane_start - image width must be multiple of 8 when swcrop is used before binarization (iX500) - check hopper sensor before calling object_position(load) on iX500 + v118 2013-12-09, MAN + - support fi-7160, fi-7260, fi-7180 and fi-7280 + - remove unused var from do_scsi_cmd() + - added more request_sense options + - add adv_paper_protect option + - enable paper protection by default + - increase max_x_fb for fi-6240 and fi-6230 + v119 2013-12-18, MAN + - call get_pixelsize after start_scan, not before + - extend get_pixelsize to request backside data + - stop using backup/restore_params + - don't use extended get_pixelsize on M3091 or M3092 + - call software crop code on backside images too + v120 2014-01-29, MAN + - only call hopper_before_op code at batch start + - remove unused backup/restore_params + v121 2014-04-07, MAN + - add JFIF APP0 marker with resolution to jpeg images + - improve jpeg duplex parsing code + - simplify jpeg ifdefs + - add offtimer option for more recent scanners + - don't print 0 length line in hexdump + v122 2014-10-28, MAN + - add support for object_position halt + - call object_position halt in check_for_cancel when requested + v123 2014-11-06, MAN + - workaround Linux USB3 bugs by adding command counting code and + sending an even number of reads and writes during disconnect_fd + v124 2014-12-09, MAN + - support resolution controlled max page-height (fi-6/7xxx scanners) + - reorder scanner sections in init_model chronologically + v125 2014-12-16, MAN + - remove USB packet counting code from v123, fix sanei_usb instead + v126 2015-08-23, MAN + - initial support for iX100 + - add late_lut support for iX500/iX100 + v127 2015-08-25, MAN + - separate iX100 from iX500 settings + - iX100 has gray and lineart SANE FLOW DIAGRAM @@ -587,7 +626,7 @@ #include "fujitsu.h" #define DEBUG 1 -#define BUILD 117 +#define BUILD 127 /* values for SANE_DEBUG_FUJITSU env var: - errors 5 @@ -601,6 +640,12 @@ */ /* ------------------------------------------------------------------------- */ +/* if JPEG support is not enabled in sane.h, we setup our own defines */ +#ifndef SANE_FRAME_JPEG +#define SANE_FRAME_JPEG 0x0B +#define SANE_JPEG_DISABLED 1 +#endif +/* ------------------------------------------------------------------------- */ #define STRING_FLATBED SANE_I18N("Flatbed") #define STRING_ADFFRONT SANE_I18N("ADF Front") #define STRING_ADFBACK SANE_I18N("ADF Back") @@ -1577,9 +1622,8 @@ init_vpd (struct fujitsu *s) s->has_comp_JPG1 = get_IN_compression_JPG_BASE (in); DBG (15, " compression JPG1: %d\n", s->has_comp_JPG1); -#ifndef SANE_FRAME_JPEG +#ifdef SANE_JPEG_DISABLED DBG (15, " (Disabled)\n"); - s->has_comp_JPG1 = 0; #endif s->has_comp_JPG2 = get_IN_compression_JPG_EXT (in); @@ -1671,7 +1715,12 @@ init_vpd (struct fujitsu *s) DBG (15, " rgb lut: %d\n", get_IN_rgb_lut(in)); DBG (15, " num lut dl: %d\n", get_IN_num_lut_dl(in)); + s->has_off_mode = get_IN_erp_lot6_supp(in); + DBG (15, " ErP Lot6 (power off timer): %d\n", s->has_off_mode); DBG (15, " sync next feed: %d\n", get_IN_sync_next_feed(in)); + + s->has_op_halt = get_IN_op_halt(in); + DBG (15, " object postion halt: %d\n", s->has_op_halt); } ret = SANE_STATUS_GOOD; @@ -2012,6 +2061,10 @@ init_model (struct fujitsu *s) s->max_x = s->max_x_basic * 1200 / s->basic_x_res; s->max_y = s->max_y_basic * 1200 / s->basic_y_res; + /* setup the list with a single choice, in 1200dpi units, at max res */ + s->max_y_by_res[0].res = s->max_y_res; + s->max_y_by_res[0].len = s->max_y; + /* assume these are same as adf, override below */ s->max_x_fb = s->max_x; s->max_y_fb = s->max_y; @@ -2062,6 +2115,7 @@ init_model (struct fujitsu *s) s->has_vuid_3091 = 1; s->has_vuid_color = 0; s->has_vuid_mono = 0; + s->has_short_pixelsize = 1; s->color_interlace = COLOR_INTERLACE_3091; s->duplex_interlace = DUPLEX_INTERLACE_3091; @@ -2106,6 +2160,38 @@ init_model (struct fujitsu *s) s->max_y_fb = 14032; } + else if (strstr (s->model_name, "fi-4750") ) { + /* weirdness */ + s->broken_diag_serial = 1; + } + + /* some firmware versions use capital f? */ + else if (strstr (s->model_name, "Fi-4860") + || strstr (s->model_name, "fi-4860") ) { + + /* weirdness */ + s->broken_diag_serial = 1; + + s->ppl_mod_by_mode[MODE_LINEART] = 32; + s->ppl_mod_by_mode[MODE_HALFTONE] = 32; + s->ppl_mod_by_mode[MODE_GRAYSCALE] = 4; + s->ppl_mod_by_mode[MODE_COLOR] = 4; + } + + /* some firmware versions use capital f? */ + else if (strstr (s->model_name, "Fi-4990") + || strstr (s->model_name, "fi-4990") ) { + + /* weirdness */ + s->duplex_interlace = DUPLEX_INTERLACE_NONE; + s->color_interlace = COLOR_INTERLACE_RRGGBB; + + s->ppl_mod_by_mode[MODE_LINEART] = 32; + s->ppl_mod_by_mode[MODE_HALFTONE] = 32; + s->ppl_mod_by_mode[MODE_GRAYSCALE] = 4; + s->ppl_mod_by_mode[MODE_COLOR] = 4; + } + else if (strstr (s->model_name,"fi-5110C")){ /* missing from vpd */ @@ -2135,49 +2221,44 @@ init_model (struct fujitsu *s) s->adbits = 8; } - /* some firmware versions use capital f? */ - else if (strstr (s->model_name, "Fi-4990") - || strstr (s->model_name, "fi-4990") ) { - - /* weirdness */ - s->duplex_interlace = DUPLEX_INTERLACE_NONE; - s->color_interlace = COLOR_INTERLACE_RRGGBB; + else if (strstr (s->model_name,"S1500")){ - s->ppl_mod_by_mode[MODE_LINEART] = 32; - s->ppl_mod_by_mode[MODE_HALFTONE] = 32; - s->ppl_mod_by_mode[MODE_GRAYSCALE] = 4; - s->ppl_mod_by_mode[MODE_COLOR] = 4; - } - - else if (strstr (s->model_name, "fi-4750") ) { - /* weirdness */ - s->broken_diag_serial = 1; + /*lies*/ + s->has_MS_bg=0; + s->has_MS_prepick=0; } - /* some firmware versions use capital f? */ - else if (strstr (s->model_name, "Fi-4860") - || strstr (s->model_name, "fi-4860") ) { + /* also includes the 'Z' models */ + else if (strstr (s->model_name,"fi-6130") + || strstr (s->model_name,"fi-6140")){ /* weirdness */ - s->broken_diag_serial = 1; - - s->ppl_mod_by_mode[MODE_LINEART] = 32; - s->ppl_mod_by_mode[MODE_HALFTONE] = 32; - s->ppl_mod_by_mode[MODE_GRAYSCALE] = 4; - s->ppl_mod_by_mode[MODE_COLOR] = 4; + /* these machines have longer max paper at lower res */ + s->max_y_by_res[1].res = 200; + s->max_y_by_res[1].len = 151512; } /* also includes the 'Z' models */ else if (strstr (s->model_name,"fi-6230") || strstr (s->model_name,"fi-6240")){ + /* weirdness */ + /* these machines have longer max paper at lower res */ + s->max_y_by_res[1].res = 200; + s->max_y_by_res[1].len = 151512; + /* missing from vpd */ - s->max_x_fb = 10488; + s->max_x_fb = 10764; /* was previously 10488 */ s->max_y_fb = 14032; /* some scanners can be slightly more? */ } - else if (strstr (s->model_name,"S1500") - || strstr (s->model_name,"fi-6110")){ + else if (strstr (s->model_name,"fi-6110")){ + + /* weirdness */ + /* these machines have longer max paper at lower res */ + s->max_y_by_res[1].res = 200; + s->max_y_by_res[1].len = 151512; + /*lies*/ s->has_MS_bg=0; s->has_MS_prepick=0; @@ -2196,6 +2277,7 @@ init_model (struct fujitsu *s) /* weirdness */ s->need_q_table = 1; + s->late_lut = 1; s->need_diag_preread = 1; s->ppl_mod_by_mode[MODE_COLOR] = 2; s->hopper_before_op = 1; @@ -2212,6 +2294,62 @@ init_model (struct fujitsu *s) s->can_mode[MODE_HALFTONE] = 0; } + /*mostly copied from iX500*/ + else if (strstr (s->model_name,"iX100")){ + /* locks up scanner if we try to auto detect */ + s->has_MS_lamp = 0; + + /* weirdness */ + s->need_q_table = 1; + s->late_lut = 1; + s->need_diag_preread = 1; + s->ppl_mod_by_mode[MODE_COLOR] = 2; + s->hopper_before_op = 1; + s->no_wait_after_op = 1; + + /* lies */ + s->adbits = 8; + + /* dont bother with this one */ + s->can_mode[MODE_HALFTONE] = 0; + } + + else if (strstr (s->model_name,"fi-7180") + || strstr (s->model_name,"fi-7160")){ + + /* weirdness */ + /* these machines have longer max paper at lower res */ + s->max_y_by_res[1].res = 400; + s->max_y_by_res[1].len = 194268; + s->max_y_by_res[2].res = 300; + s->max_y_by_res[2].len = 260268; + s->max_y_by_res[3].res = 200; + s->max_y_by_res[3].len = 266268; + + /* missing from vpd */ + s->has_df_recovery=1; + s->has_adv_paper_prot=1; + } + + else if (strstr (s->model_name,"fi-7280") + || strstr (s->model_name,"fi-7260")){ + + /* weirdness */ + /* these machines have longer max paper at lower res */ + s->max_y_by_res[1].res = 400; + s->max_y_by_res[1].len = 194268; + s->max_y_by_res[2].res = 300; + s->max_y_by_res[2].len = 260268; + s->max_y_by_res[3].res = 200; + s->max_y_by_res[3].len = 266268; + + /* missing from vpd */ + s->has_df_recovery=1; + s->has_adv_paper_prot=1; + s->max_x_fb = 10764; + s->max_y_fb = 14032; /* some scanners can be slightly more? */ + } + DBG (10, "init_model: finish\n"); return SANE_STATUS_GOOD; @@ -2277,6 +2415,7 @@ init_user (struct fujitsu *s) /* page height US-Letter */ s->page_height = 11 * 1200; + set_max_y(s); if(s->page_height > s->max_y){ s->page_height = s->max_y; } @@ -2310,6 +2449,23 @@ init_user (struct fujitsu *s) * even when the user only wants one */ s->buff_mode = MSEL_OFF; + /* useful features of newer scanners which we turn on, + * even though the scanner defaults to off */ + if(s->has_paper_protect){ + s->paper_protect = MSEL_ON; + } + if(s->has_staple_detect){ + s->staple_detect = MSEL_ON; + } + if(s->has_df_recovery){ + s->df_recovery = MSEL_ON; + } + if(s->has_adv_paper_prot){ + s->adv_paper_prot = MSEL_ON; + } + + s->off_time = 240; + DBG (10, "init_user: finish\n"); return SANE_STATUS_GOOD; @@ -3377,7 +3533,9 @@ sane_get_option_descriptor (SANE_Handle handle, SANE_Int option) s->compress_list[i++]=STRING_NONE; if(s->has_comp_JPG1){ +#ifndef SANE_JPEG_DISABLED s->compress_list[i++]=STRING_JPEG; +#endif } s->compress_list[i]=NULL; @@ -3528,7 +3686,7 @@ sane_get_option_descriptor (SANE_Handle handle, SANE_Int option) opt->cap = SANE_CAP_INACTIVE; } - /*df recovery*/ + /*df_recovery*/ if(option==OPT_DF_RECOVERY){ s->df_recovery_list[0] = STRING_DEFAULT; s->df_recovery_list[1] = STRING_OFF; @@ -3548,7 +3706,7 @@ sane_get_option_descriptor (SANE_Handle handle, SANE_Int option) opt->cap = SANE_CAP_INACTIVE; } - /*paper protection*/ + /*paper_protect*/ if(option==OPT_PAPER_PROTECT){ s->paper_protect_list[0] = STRING_DEFAULT; s->paper_protect_list[1] = STRING_OFF; @@ -3568,6 +3726,26 @@ sane_get_option_descriptor (SANE_Handle handle, SANE_Int option) opt->cap = SANE_CAP_INACTIVE; } + /*adv_paper_prot*/ + if(option==OPT_ADV_PAPER_PROT){ + s->adv_paper_prot_list[0] = STRING_DEFAULT; + s->adv_paper_prot_list[1] = STRING_OFF; + s->adv_paper_prot_list[2] = STRING_ON; + s->adv_paper_prot_list[3] = NULL; + + opt->name = "adv-paper-protect"; + opt->title = "Advanced paper protection"; + opt->desc = "Request scanner to predict jams in the ADF using improved sensors"; + opt->type = SANE_TYPE_STRING; + opt->constraint_type = SANE_CONSTRAINT_STRING_LIST; + opt->constraint.string_list = s->adv_paper_prot_list; + opt->size = maxStringSize (opt->constraint.string_list); + if (s->has_MS_df && s->has_adv_paper_prot) + opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED; + else + opt->cap = SANE_CAP_INACTIVE; + } + /*staple detection*/ if(option==OPT_STAPLE_DETECT){ s->staple_detect_list[0] = STRING_DEFAULT; @@ -3693,7 +3871,7 @@ sane_get_option_descriptor (SANE_Handle handle, SANE_Int option) opt->cap = SANE_CAP_INACTIVE; } - /*sleep time*/ + /*sleep_time*/ if(option==OPT_SLEEP_TIME){ s->sleep_time_range.min = 0; s->sleep_time_range.max = 60; @@ -3712,6 +3890,25 @@ sane_get_option_descriptor (SANE_Handle handle, SANE_Int option) opt->cap = SANE_CAP_INACTIVE; } + /*off_time*/ + if(option==OPT_OFF_TIME){ + s->off_time_range.min = 0; + s->off_time_range.max = 960; + s->off_time_range.quant = 1; + + opt->name = "offtimer"; + opt->title = "Off timer"; + opt->desc = "Time in minutes until the internal power supply switches the scanner off. Will be rounded to nearest 15 minutes. Zero means never power off."; + opt->type = SANE_TYPE_INT; + opt->unit = SANE_UNIT_NONE; + opt->constraint_type = SANE_CONSTRAINT_RANGE; + opt->constraint.range=&s->off_time_range; + if(s->has_off_mode) + opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED; + else + opt->cap = SANE_CAP_INACTIVE; + } + /*duplex offset*/ if(option==OPT_DUPLEX_OFFSET){ s->duplex_offset_range.min = -16; @@ -3862,13 +4059,25 @@ sane_get_option_descriptor (SANE_Handle handle, SANE_Int option) opt->constraint_type = SANE_CONSTRAINT_RANGE; opt->constraint.range = &s->swskip_range; - s->swskip_range.quant=1; + s->swskip_range.quant=SANE_FIX(0.10001); s->swskip_range.min=SANE_FIX(0); s->swskip_range.max=SANE_FIX(100); opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT; } + /*halt scanner feeder when cancelling*/ + if(option==OPT_HALT_ON_CANCEL){ + opt->name = "halt-on-cancel"; + opt->title = "Halt on Cancel"; + opt->desc = "Request driver to halt the paper feed instead of eject during a cancel."; + opt->type = SANE_TYPE_BOOL; + if (s->has_op_halt) + opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED; + else + opt->cap = SANE_CAP_INACTIVE; + } + /* "Endorser" group ------------------------------------------------------ */ if(option==OPT_ENDORSER_GROUP){ opt->name = "endorser-options"; @@ -4689,6 +4898,20 @@ sane_control_option (SANE_Handle handle, SANE_Int option, } return SANE_STATUS_GOOD; + case OPT_ADV_PAPER_PROT: + switch (s->adv_paper_prot) { + case MSEL_DEFAULT: + strcpy (val, STRING_DEFAULT); + break; + case MSEL_ON: + strcpy (val, STRING_ON); + break; + case MSEL_OFF: + strcpy (val, STRING_OFF); + break; + } + return SANE_STATUS_GOOD; + case OPT_STAPLE_DETECT: switch (s->staple_detect) { case MSEL_DEFAULT: @@ -4780,6 +5003,10 @@ sane_control_option (SANE_Handle handle, SANE_Int option, *val_p = s->sleep_time; return SANE_STATUS_GOOD; + case OPT_OFF_TIME: + *val_p = s->off_time; + return SANE_STATUS_GOOD; + case OPT_DUPLEX_OFFSET: *val_p = s->duplex_offset; return SANE_STATUS_GOOD; @@ -4820,6 +5047,10 @@ sane_control_option (SANE_Handle handle, SANE_Int option, *val_p = SANE_FIX(s->swskip); return SANE_STATUS_GOOD; + case OPT_HALT_ON_CANCEL: + *val_p = s->halt_on_cancel; + return SANE_STATUS_GOOD; + /* Endorser Group */ case OPT_ENDORSER: *val_p = s->u_endorser; @@ -5080,6 +5311,7 @@ sane_control_option (SANE_Handle handle, SANE_Int option, s->resolution_x = val_c; s->resolution_y = val_c; + set_max_y(s); *info |= SANE_INFO_RELOAD_PARAMS | SANE_INFO_RELOAD_OPTIONS; return SANE_STATUS_GOOD; @@ -5341,6 +5573,15 @@ sane_control_option (SANE_Handle handle, SANE_Int option, s->paper_protect = MSEL_OFF; return SANE_STATUS_GOOD; + case OPT_ADV_PAPER_PROT: + if (!strcmp(val, STRING_DEFAULT)) + s->adv_paper_prot = MSEL_DEFAULT; + else if (!strcmp(val, STRING_ON)) + s->adv_paper_prot = MSEL_ON; + else if (!strcmp(val, STRING_OFF)) + s->adv_paper_prot = MSEL_OFF; + return SANE_STATUS_GOOD; + case OPT_STAPLE_DETECT: if (!strcmp(val, STRING_DEFAULT)) s->staple_detect = MSEL_DEFAULT; @@ -5403,6 +5644,14 @@ sane_control_option (SANE_Handle handle, SANE_Int option, s->sleep_time = val_c; return set_sleep_mode(s); + case OPT_OFF_TIME: + /* do our own constrain, because we want to round up */ + s->off_time = (val_c + 14)/15*15; + if(s->off_time != val_c){ + *info |= SANE_INFO_INEXACT; + } + return set_off_mode(s); + case OPT_DUPLEX_OFFSET: s->duplex_offset = val_c; return SANE_STATUS_GOOD; @@ -5439,6 +5688,10 @@ sane_control_option (SANE_Handle handle, SANE_Int option, s->swskip = SANE_UNFIX(val_c); return SANE_STATUS_GOOD; + case OPT_HALT_ON_CANCEL: + s->halt_on_cancel = val_c; + return SANE_STATUS_GOOD; + /* Endorser Group */ case OPT_ENDORSER: s->u_endorser = val_c; @@ -5550,6 +5803,50 @@ set_sleep_mode(struct fujitsu *s) } static SANE_Status +set_off_mode(struct fujitsu *s) +{ + SANE_Status ret = SANE_STATUS_GOOD; + + unsigned char cmd[SEND_DIAGNOSTIC_len]; /*also big enough for READ_DIAG*/ + size_t cmdLen = SEND_DIAGNOSTIC_len; + + unsigned char out[SD_powoff_len]; + size_t outLen = SD_powoff_len; + + DBG (10, "set_off_mode: start\n"); + + if (!s->has_cmd_sdiag || !s->has_cmd_rdiag || !s->has_off_mode){ + DBG (5, "set_off_mode: not supported, returning\n"); + return ret; + } + + memset(cmd,0,cmdLen); + set_SCSI_opcode(cmd, SEND_DIAGNOSTIC_code); + set_SD_slftst(cmd, 0); + set_SD_xferlen(cmd, outLen); + + memcpy(out,SD_powoff_string,SD_powoff_stringlen); + set_SD_powoff_disable(out,!s->off_time); + set_SD_powoff_interval(out,s->off_time/15); + + ret = do_cmd ( + s, 1, 0, + cmd, cmdLen, + out, outLen, + NULL, NULL + ); + + if (ret != SANE_STATUS_GOOD){ + DBG (5, "set_off_mode: send diag error: %d\n", ret); + return ret; + } + + DBG (10, "set_off_mode: finish\n"); + + return SANE_STATUS_GOOD; +} + +static SANE_Status get_hardware_status (struct fujitsu *s, SANE_Int option) { SANE_Status ret = SANE_STATUS_GOOD; @@ -6092,6 +6389,7 @@ mode_select_df (struct fujitsu *s) set_MSEL_df_paperprot(page,s->paper_protect); set_MSEL_df_stapledet(page,s->staple_detect); set_MSEL_df_recovery(page,s->df_recovery); + set_MSEL_df_paperprot2(page,s->adv_paper_prot); ret = do_cmd ( s, 1, 0, @@ -6408,7 +6706,6 @@ update_params (struct fujitsu * s) if (s->s_mode == MODE_COLOR) { params->depth = 8; -#ifdef SANE_FRAME_JPEG /* jpeg requires 8x8 squares */ if(s->compress == COMP_JPEG){ params->format = SANE_FRAME_JPEG; @@ -6416,20 +6713,16 @@ update_params (struct fujitsu * s) params->lines -= params->lines % 8; } else{ -#endif params->format = SANE_FRAME_RGB; params->pixels_per_line -= params->pixels_per_line % max(s->ppl_mod_by_mode[s->s_mode], s->ppl_mod_by_mode[s->u_mode]); -#ifdef SANE_FRAME_JPEG } -#endif params->bytes_per_line = params->pixels_per_line * 3; } else if (s->s_mode == MODE_GRAYSCALE) { params->depth = 8; -#ifdef SANE_FRAME_JPEG /* jpeg requires 8x8 squares */ if(s->compress == COMP_JPEG){ params->format = SANE_FRAME_JPEG; @@ -6437,13 +6730,10 @@ update_params (struct fujitsu * s) params->lines -= params->lines % 8; } else{ -#endif params->format = SANE_FRAME_GRAY; params->pixels_per_line -= params->pixels_per_line % max(s->ppl_mod_by_mode[s->s_mode], s->ppl_mod_by_mode[s->u_mode]); -#ifdef SANE_FRAME_JPEG } -#endif params->bytes_per_line = params->pixels_per_line; } @@ -6526,70 +6816,6 @@ update_u_params (struct fujitsu * s) return ret; } -/* make backup of param data, in case original is overwritten */ -SANE_Status -backup_params (struct fujitsu * s) -{ - SANE_Status ret = SANE_STATUS_GOOD; - SANE_Parameters * params = &(s->s_params); - SANE_Parameters * params_bk = &(s->s_params_bk); - - DBG (10, "backup_params: start\n"); - - params_bk->format = params->format; - params_bk->last_frame = params->last_frame; - params_bk->bytes_per_line = params->bytes_per_line; - params_bk->pixels_per_line = params->pixels_per_line; - params_bk->lines = params->lines; - params_bk->depth = params->depth; - - /* also have to save the user params */ - params = &(s->u_params); - params_bk = &(s->u_params_bk); - - params_bk->format = params->format; - params_bk->last_frame = params->last_frame; - params_bk->bytes_per_line = params->bytes_per_line; - params_bk->pixels_per_line = params->pixels_per_line; - params_bk->lines = params->lines; - params_bk->depth = params->depth; - - DBG (10, "backup_params: finish\n"); - return ret; -} - -/* restore backup of param data, in case original was overwritten */ -SANE_Status -restore_params (struct fujitsu * s) -{ - SANE_Status ret = SANE_STATUS_GOOD; - SANE_Parameters * params = &(s->s_params); - SANE_Parameters * params_bk = &(s->s_params_bk); - - DBG (10, "restore_params: start\n"); - - params->format = params_bk->format; - params->last_frame = params_bk->last_frame; - params->bytes_per_line = params_bk->bytes_per_line; - params->pixels_per_line = params_bk->pixels_per_line; - params->lines = params_bk->lines; - params->depth = params_bk->depth; - - /* also have to restore the user params */ - params = &(s->u_params); - params_bk = &(s->u_params_bk); - - params->format = params_bk->format; - params->last_frame = params_bk->last_frame; - params->bytes_per_line = params_bk->bytes_per_line; - params->pixels_per_line = params_bk->pixels_per_line; - params->lines = params_bk->lines; - params->depth = params_bk->depth; - - DBG (10, "restore_params: finish\n"); - return ret; -} - /* * Called by SANE when a page acquisition operation is to be started. * commands: scanner control (lampon), send (lut), send (dither), @@ -6700,6 +6926,13 @@ sane_start (SANE_Handle handle) if (ret != SANE_STATUS_GOOD) DBG (5, "sane_start: WARNING: cannot send_endorser %d\n", ret); + /* send lut if scanner has no hardware brightness/contrast */ + if (!s->late_lut && (!s->brightness_steps || !s->contrast_steps)){ + ret = send_lut(s); + if (ret != SANE_STATUS_GOOD) + DBG (5, "sane_start: WARNING: cannot early send_lut %d\n", ret); + } + /* set window command */ ret = set_window(s); if (ret != SANE_STATUS_GOOD) { @@ -6708,10 +6941,10 @@ sane_start (SANE_Handle handle) } /* send lut if scanner has no hardware brightness/contrast */ - if (!s->brightness_steps || !s->contrast_steps){ + if (s->late_lut && (!s->brightness_steps || !s->contrast_steps)){ ret = send_lut(s); if (ret != SANE_STATUS_GOOD) - DBG (5, "sane_start: WARNING: cannot send_lut %d\n", ret); + DBG (5, "sane_start: WARNING: cannot late send_lut %d\n", ret); } /* some scanners need the q table sent, even when not scanning jpeg */ @@ -6721,20 +6954,6 @@ sane_start (SANE_Handle handle) DBG (5, "sane_start: WARNING: cannot send_q_table %d\n", ret); } - /* try to read scan size from scanner */ - ret = get_pixelsize(s,0); - if (ret != SANE_STATUS_GOOD) { - DBG (5, "sane_start: ERROR: cannot get pixelsize\n"); - goto errors; - } - - /* make backup copy of params because later functions overwrite */ - ret = backup_params(s); - if (ret != SANE_STATUS_GOOD) { - DBG (5, "sane_start: ERROR: cannot backup params\n"); - goto errors; - } - /* start/stop endorser */ ret = endorser(s); if (ret != SANE_STATUS_GOOD) { @@ -6747,19 +6966,23 @@ sane_start (SANE_Handle handle) if (ret != SANE_STATUS_GOOD) { DBG (5, "sane_start: WARNING: cannot start lamp, ignoring\n"); } + + /* iX500 errors if op is called with no paper + * at the beginning of a batch, so we check */ + if(s->hopper_before_op && s->source != SOURCE_FLATBED){ + ret = get_hardware_status(s,0); + if(!s->hw_hopper){ + ret = SANE_STATUS_NO_DOCS; + DBG (5, "sane_start: ERROR: hopper empty\n"); + goto errors; + } + } } /* if already running, duplex needs to switch sides */ else if(s->source == SOURCE_ADF_DUPLEX){ s->side = !s->side; } - /* restore backup copy of params at the start of each image */ - ret = restore_params(s); - if (ret != SANE_STATUS_GOOD) { - DBG (5, "sane_start: ERROR: cannot restore params\n"); - goto errors; - } - /* set clean defaults with new sheet of paper */ /* dont reset the transfer vars on backside of duplex page */ /* otherwise buffered back page will be lost */ @@ -6788,11 +7011,30 @@ sane_start (SANE_Handle handle) s->buff_tx[1]=0; /* reset jpeg just in case... */ - s->jpeg_stage = JPEG_STAGE_HEAD; - s->jpeg_ff_offset = 0; + s->jpeg_stage = JPEG_STAGE_NONE; + s->jpeg_ff_offset = -1; s->jpeg_front_rst = 0; s->jpeg_back_rst = 0; + ret = object_position (s, OP_Feed); + if (ret != SANE_STATUS_GOOD) { + DBG (5, "sane_start: ERROR: cannot load page\n"); + goto errors; + } + + ret = start_scan (s); + if (ret != SANE_STATUS_GOOD) { + DBG (5, "sane_start: ERROR: cannot start_scan\n"); + goto errors; + } + + /* try to read scan size from scanner */ + ret = get_pixelsize(s,0); + if (ret != SANE_STATUS_GOOD) { + DBG (5, "sane_start: ERROR: cannot get pixelsize\n"); + goto errors; + } + /* store the number of front bytes */ if ( s->source != SOURCE_ADF_BACK ){ s->bytes_tot[SIDE_FRONT] = s->s_params.bytes_per_line * s->s_params.lines; @@ -6840,16 +7082,12 @@ sane_start (SANE_Handle handle) s->started=1; } - - ret = object_position (s, SANE_TRUE); - if (ret != SANE_STATUS_GOOD) { - DBG (5, "sane_start: ERROR: cannot load page\n"); - goto errors; - } - - ret = start_scan (s); + } + else{ + /* try to read scan size from scanner */ + ret = get_pixelsize(s,0); if (ret != SANE_STATUS_GOOD) { - DBG (5, "sane_start: ERROR: cannot start_scan\n"); + DBG (5, "sane_start: ERROR: cannot get pixelsize\n"); goto errors; } } @@ -7249,13 +7487,11 @@ set_window (struct fujitsu *s) set_WD_compress_type(desc1, COMP_NONE); set_WD_compress_arg(desc1, 0); -#ifdef SANE_FRAME_JPEG /* some scanners support jpeg image compression, for color/gs only */ if(s->s_params.format == SANE_FRAME_JPEG){ set_WD_compress_type(desc1, COMP_JPEG); set_WD_compress_arg(desc1, s->compress_arg); } -#endif /* the remainder of the block varies based on model and mode, * except for gamma and paper size, those are in the same place */ @@ -7435,7 +7671,8 @@ get_pixelsize(struct fujitsu *s, int actual) memset(cmd,0,cmdLen); set_SCSI_opcode(cmd, READ_code); set_R_datatype_code (cmd, R_datatype_pixelsize); - if(s->source == SOURCE_ADF_BACK){ + + if(s->side == SIDE_BACK){ set_R_window_id (cmd, WD_wid_back); } else{ @@ -7453,7 +7690,7 @@ get_pixelsize(struct fujitsu *s, int actual) /* when we are called post-scan, the scanner may give * more accurate data in other fields */ - if(actual && get_PSIZE_paper_w(in)){ + if(actual && !s->has_short_pixelsize && get_PSIZE_paper_w(in)){ s->s_params.pixels_per_line = get_PSIZE_paper_w(in); DBG(5,"get_pixelsize: Actual width\n"); } @@ -7469,7 +7706,7 @@ get_pixelsize(struct fujitsu *s, int actual) } /* when we are called post-scan, the scanner may give * more accurate data in other fields */ - else if(actual && get_PSIZE_paper_l(in)){ + else if(actual && !s->has_short_pixelsize && get_PSIZE_paper_l(in)){ s->s_params.lines = get_PSIZE_paper_l(in); DBG(5,"get_pixelsize: Actual length\n"); } @@ -7489,7 +7726,7 @@ get_pixelsize(struct fujitsu *s, int actual) } /* some scanners can request that the driver clean img */ - if(get_PSIZE_req_driv_valid(in)){ + if(!s->has_short_pixelsize && get_PSIZE_req_driv_valid(in)){ s->req_driv_crop = get_PSIZE_req_driv_crop(in); s->req_driv_lut = get_PSIZE_req_driv_lut(in); DBG(5,"get_pixelsize: scanner requests: crop=%d, lut=%d\n", @@ -7530,38 +7767,23 @@ get_pixelsize(struct fujitsu *s, int actual) * Issues the SCSI OBJECT POSITION command if an ADF is in use. */ static SANE_Status -object_position (struct fujitsu *s, int i_load) +object_position (struct fujitsu *s, int action) { SANE_Status ret = SANE_STATUS_GOOD; unsigned char cmd[OBJECT_POSITION_len]; size_t cmdLen = OBJECT_POSITION_len; - DBG (10, "object_position: start\n"); + DBG (10, "object_position: start %d\n", action); - if (s->source == SOURCE_FLATBED) { + if (s->source == SOURCE_FLATBED && action < OP_Halt) { DBG (10, "object_position: flatbed no-op\n"); return SANE_STATUS_GOOD; } - if(s->hopper_before_op && i_load){ - ret = get_hardware_status(s,0); - if(!s->hw_hopper){ - return SANE_STATUS_NO_DOCS; - } - } - memset(cmd,0,cmdLen); set_SCSI_opcode(cmd, OBJECT_POSITION_code); - - if (i_load) { - DBG (15, "object_position: load\n"); - set_OP_autofeed (cmd, OP_Feed); - } - else { - DBG (15, "object_position: eject\n"); - set_OP_autofeed (cmd, OP_Discharge); - } + set_OP_action (cmd, action); ret = do_cmd ( s, 1, 0, @@ -7630,22 +7852,30 @@ check_for_cancel(struct fujitsu *s) { SANE_Status ret=SANE_STATUS_GOOD; - DBG (10, "check_for_cancel: start\n"); + DBG (10, "check_for_cancel: start %d %d\n",s->started,s->cancelled); if(s->started && s->cancelled){ - DBG (15, "check_for_cancel: cancelling\n"); - /* cancel scan */ + /* halt scan */ + if(s->halt_on_cancel){ + DBG (15, "check_for_cancel: halting\n"); + ret = object_position (s, OP_Halt); + } + /* cancel scan */ + else{ + DBG (15, "check_for_cancel: cancelling\n"); ret = scanner_control(s, SC_function_cancel); - if (ret == SANE_STATUS_GOOD) { - ret = SANE_STATUS_CANCELLED; - } - else{ - DBG (5, "check_for_cancel: ERROR: cannot cancel\n"); - } + } + + if (ret == SANE_STATUS_GOOD || ret == SANE_STATUS_CANCELLED) { + ret = SANE_STATUS_CANCELLED; + } + else{ + DBG (5, "check_for_cancel: ERROR: cannot cancel\n"); + } - s->started = 0; - s->cancelled = 0; + s->started = 0; + s->cancelled = 0; } else if(s->cancelled){ DBG (15, "check_for_cancel: already cancelled\n"); @@ -7723,7 +7953,6 @@ sane_read (SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, SANE_Int * len } } /* end 3091 */ -#ifdef SANE_FRAME_JPEG /* alternating jpeg duplex interlacing */ else if(s->source == SOURCE_ADF_DUPLEX && s->s_params.format == SANE_FRAME_JPEG @@ -7735,11 +7964,10 @@ sane_read (SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, SANE_Int * len return ret; } } /* end alt jpeg */ -#endif /* alternating pnm duplex interlacing */ else if(s->source == SOURCE_ADF_DUPLEX - && s->s_params.format <= SANE_FRAME_RGB + && s->s_params.format != SANE_FRAME_JPEG && s->duplex_interlace == DUPLEX_INTERLACE_ALT ){ @@ -7808,7 +8036,33 @@ sane_read (SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, SANE_Int * len return ret; } -#ifdef SANE_FRAME_JPEG +/* bare jpeg images dont contain resolution, but JFIF APP0 does, so we add */ +static SANE_Status +inject_jfif_header(struct fujitsu *s, int side) +{ + SANE_Status ret=SANE_STATUS_GOOD; + + unsigned char out[] = { + 0xFF, 0xE0, 0x00, 0x10, 0x4A, 0x46, 0x49, 0x46, + 0x00, 0x01, 0x02, 0x01, 0x00, 0x48, 0x00, 0x48, + 0x00, 0x00 + }; + size_t outLen=JFIF_APP0_LENGTH; + + DBG (10, "inject_jfif_header: start %d\n", side); + + putnbyte(out + 12, s->resolution_x, 2); + putnbyte(out + 14, s->resolution_y, 2); + + memcpy(s->buffers[side]+s->buff_rx[side], out, outLen); + s->buff_rx[side] += outLen; + s->bytes_rx[side] += outLen; + + DBG (10, "inject_jfif_header: finish %d\n", ret); + + return ret; +} + static SANE_Status read_from_JPEGduplex(struct fujitsu *s) { @@ -7834,13 +8088,21 @@ read_from_JPEGduplex(struct fujitsu *s) * so we only get enough to fill whichever is smaller (and not yet done) */ if(!s->eof_rx[SIDE_FRONT]){ int avail = s->buff_tot[SIDE_FRONT] - s->buff_rx[SIDE_FRONT]; - if(bytes > avail) + if(bytes > avail){ bytes = avail; + /* leave space for JFIF header at start of image */ + if(s->bytes_rx[SIDE_FRONT] < 2) + bytes -= JFIF_APP0_LENGTH; + } } if(!s->eof_rx[SIDE_BACK]){ int avail = s->buff_tot[SIDE_BACK] - s->buff_rx[SIDE_BACK]; - if(bytes > avail) + if(bytes > avail){ bytes = avail; + /* leave space for JFIF header at start of image */ + if(s->bytes_rx[SIDE_BACK] < 2) + bytes -= JFIF_APP0_LENGTH; + } } DBG(15, "read_from_JPEGduplex: fto:%d frx:%d bto:%d brx:%d pa:%d\n", @@ -7901,7 +8163,7 @@ read_from_JPEGduplex(struct fujitsu *s) for(i=0;i<(int)inLen;i++){ /* about to change stage */ - if(in[i] == 0xff){ + if(in[i] == 0xff && s->jpeg_ff_offset != 0){ s->jpeg_ff_offset=0; continue; } @@ -7909,9 +8171,21 @@ read_from_JPEGduplex(struct fujitsu *s) /* last byte was an ff, this byte will change stage */ if(s->jpeg_ff_offset == 0){ - /* headers (SOI/HuffTab/QTab/DRI), in both sides */ - if(in[i] == 0xd8 || in[i] == 0xc4 - || in[i] == 0xdb || in[i] == 0xdd){ + /* first marker after SOI is not APP0, add one */ + if(s->jpeg_stage == JPEG_STAGE_SOI && in[i] != 0xe0){ + inject_jfif_header(s,SIDE_FRONT); + inject_jfif_header(s,SIDE_BACK); + s->jpeg_stage = JPEG_STAGE_HEAD; + } + + /* SOI header, in both sides */ + if(in[i] == 0xd8){ + s->jpeg_stage = JPEG_STAGE_SOI; + DBG(15, "read_from_JPEGduplex: stage SOI\n"); + } + + /* headers (HuffTab/QTab/DRI), in both sides */ + else if(in[i] == 0xc4 || in[i] == 0xdb || in[i] == 0xdd){ s->jpeg_stage = JPEG_STAGE_HEAD; DBG(15, "read_from_JPEGduplex: stage head\n"); } @@ -7972,6 +8246,11 @@ read_from_JPEGduplex(struct fujitsu *s) s->jpeg_stage = JPEG_STAGE_EOI; DBG(15, "read_from_JPEGduplex: stage eoi %d %d\n",(int)inLen,i); } + + /* unknown, warn */ + else if(in[i] != 0xff){ + DBG(15, "read_from_JPEGduplex: unknown %02x\n", in[i]); + } } s->jpeg_ff_offset++; @@ -8025,7 +8304,8 @@ read_from_JPEGduplex(struct fujitsu *s) } /* copy these stages to front */ - if(s->jpeg_stage == JPEG_STAGE_HEAD + if(s->jpeg_stage == JPEG_STAGE_SOI + || s->jpeg_stage == JPEG_STAGE_HEAD || s->jpeg_stage == JPEG_STAGE_SOF || s->jpeg_stage == JPEG_STAGE_SOS || s->jpeg_stage == JPEG_STAGE_EOI @@ -8043,7 +8323,8 @@ read_from_JPEGduplex(struct fujitsu *s) /* copy these stages to back */ if( s->jpeg_interlace == JPEG_INTERLACE_ALT && - ( s->jpeg_stage == JPEG_STAGE_HEAD + ( s->jpeg_stage == JPEG_STAGE_SOI + || s->jpeg_stage == JPEG_STAGE_HEAD || s->jpeg_stage == JPEG_STAGE_SOF || s->jpeg_stage == JPEG_STAGE_SOS || s->jpeg_stage == JPEG_STAGE_EOI @@ -8086,7 +8367,6 @@ read_from_JPEGduplex(struct fujitsu *s) return ret; } -#endif static SANE_Status read_from_3091duplex(struct fujitsu *s) @@ -8267,6 +8547,10 @@ read_from_scanner(struct fujitsu *s, int side) if(bytes % 2 && bytes < remain){ bytes -= s->s_params.bytes_per_line; } + + /* jpeg scans leave space for JFIF header at start of image */ + if(s->s_params.format == SANE_FRAME_JPEG && s->bytes_rx[side] < 2) + bytes -= JFIF_APP0_LENGTH; DBG(15, "read_from_scanner: si:%d re:%d bs:%d by:%d av:%d\n", side, remain, s->buffer_size, bytes, avail); @@ -8341,6 +8625,9 @@ read_from_scanner(struct fujitsu *s, int side) if(s->s_mode==MODE_COLOR && s->color_interlace == COLOR_INTERLACE_3091){ copy_3091 (s, in, inLen, side); } + else if(s->s_params.format == SANE_FRAME_JPEG){ + copy_JPEG (s, in, inLen, side); + } else{ copy_buffer (s, in, inLen, side); } @@ -8454,6 +8741,48 @@ copy_3091(struct fujitsu *s, unsigned char * buf, int len, int side) } static SANE_Status +copy_JPEG(struct fujitsu *s, unsigned char * buf, int len, int side) +{ + SANE_Status ret=SANE_STATUS_GOOD; + int i, seen = 0; + + DBG (10, "copy_JPEG: start\n"); + + /* A jpeg image starts with the SOI marker, FF D8. + * This is optionally followed by the JFIF APP0 + * marker, FF E0. If that marker is not present, + * we add it, so we can insert the resolution */ + + if(!s->bytes_rx[side] && len >= 4 + && buf[0] == 0xFF && buf[1] == 0xD8 + && buf[2] == 0xFF && buf[3] != 0xE0 + ){ + /* SOI marker */ + for (i=0; i<2; i++){ + s->buffers[side][s->buff_rx[side]++] = buf[i]; + s->bytes_rx[side]++; + seen++; + } + + /* JFIF header after SOI */ + inject_jfif_header(s,side); + } + + memcpy(s->buffers[side]+s->buff_rx[side],buf+seen,len-seen); + s->buff_rx[side] += len-seen; + s->bytes_rx[side] += len-seen; + + /* should never happen with jpeg */ + if(s->bytes_rx[side] == s->bytes_tot[side]){ + s->eof_rx[side] = 1; + } + + DBG (10, "copy_JPEG: finish\n"); + + return ret; +} + +static SANE_Status copy_buffer(struct fujitsu *s, unsigned char * buf, int len, int side) { SANE_Status ret=SANE_STATUS_GOOD; @@ -8465,7 +8794,7 @@ copy_buffer(struct fujitsu *s, unsigned char * buf, int len, int side) /* invert image if scanner needs it for this mode */ /* jpeg data does not use inverting */ - if(s->s_params.format <= SANE_FRAME_RGB && s->reverse_by_mode[s->s_mode]){ + if(s->s_params.format != SANE_FRAME_JPEG && s->reverse_by_mode[s->s_mode]){ for(i=0; i<len; i++){ buf[i] ^= 0xff; } @@ -8895,6 +9224,14 @@ sense_handler (int fd, unsigned char * sensed_data, void *arg) DBG (5, "Medium error: double feed\n"); return SANE_STATUS_JAMMED; } + if (0x08 == ascq) { + DBG (5, "Medium error: ADF setup error\n"); + return SANE_STATUS_JAMMED; + } + if (0x09 == ascq) { + DBG (5, "Medium error: Carrier sheet\n"); + return SANE_STATUS_JAMMED; + } if (0x10 == ascq) { DBG (5, "Medium error: no ink cartridge\n"); return SANE_STATUS_IO_ERROR; @@ -8907,12 +9244,36 @@ sense_handler (int fd, unsigned char * sensed_data, void *arg) DBG (5, "Medium error: endorser error\n"); return SANE_STATUS_IO_ERROR; } + if (0x20 == ascq) { + DBG (5, "Medium error: Stop button\n"); + return SANE_STATUS_NO_DOCS; + } + if (0x22 == ascq) { + DBG (5, "Medium error: scanning halted\n"); + return SANE_STATUS_CANCELLED; + } + if (0x30 == ascq) { + DBG (5, "Medium error: Not enough paper\n"); + return SANE_STATUS_NO_DOCS; + } + if (0x31 == ascq) { + DBG (5, "Medium error: scanning disabled\n"); + return SANE_STATUS_IO_ERROR; + } + if (0x32 == ascq) { + DBG (5, "Medium error: scanning paused\n"); + return SANE_STATUS_DEVICE_BUSY; + } + if (0x33 == ascq) { + DBG (5, "Medium error: WiFi control error\n"); + return SANE_STATUS_IO_ERROR; + } DBG (5, "Medium error: unknown ascq\n"); return SANE_STATUS_IO_ERROR; break; case 0x4: - if (0x80 != asc && 0x44 != asc && 0x47 != asc) { + if (0x80 != asc && 0x44 != asc) { DBG (5, "Hardware error: unknown asc\n"); return SANE_STATUS_IO_ERROR; } @@ -8928,6 +9289,10 @@ sense_handler (int fd, unsigned char * sensed_data, void *arg) DBG (5, "Hardware error: heater fuse\n"); return SANE_STATUS_IO_ERROR; } + if ((0x80 == asc) && (0x03 == ascq)) { + DBG (5, "Hardware error: lamp fuse\n"); + return SANE_STATUS_IO_ERROR; + } if ((0x80 == asc) && (0x04 == ascq)) { DBG (5, "Hardware error: ADF motor fuse\n"); return SANE_STATUS_IO_ERROR; @@ -8952,6 +9317,22 @@ sense_handler (int fd, unsigned char * sensed_data, void *arg) DBG (5, "Hardware error: endorser error\n"); return SANE_STATUS_IO_ERROR; } + if ((0x80 == asc) && (0x11 == ascq)) { + DBG (5, "Hardware error: endorser fuse\n"); + return SANE_STATUS_IO_ERROR; + } + if ((0x80 == asc) && (0x80 == ascq)) { + DBG (5, "Hardware error: interface board timeout\n"); + return SANE_STATUS_IO_ERROR; + } + if ((0x80 == asc) && (0x81 == ascq)) { + DBG (5, "Hardware error: interface board error 1\n"); + return SANE_STATUS_IO_ERROR; + } + if ((0x80 == asc) && (0x82 == ascq)) { + DBG (5, "Hardware error: interface board error 2\n"); + return SANE_STATUS_IO_ERROR; + } DBG (5, "Hardware error: unknown asc/ascq\n"); return SANE_STATUS_IO_ERROR; break; @@ -9098,7 +9479,6 @@ do_scsi_cmd(struct fujitsu *s, int runRS, int shortTime, ) { int ret; - size_t actLen = 0; /*shut up compiler*/ runRS=runRS; @@ -9116,7 +9496,6 @@ do_scsi_cmd(struct fujitsu *s, int runRS, int shortTime, if (inBuff && inLen){ DBG(25, "in: reading %d bytes\n", (int)*inLen); memset(inBuff,0,*inLen); - actLen = *inLen; } ret = sanei_scsi_cmd2(s->fd, cmdBuff, cmdLen, outBuff, outLen, inBuff, inLen); @@ -9408,9 +9787,7 @@ must_fully_buffer(struct fujitsu *s) if( (s->swdeskew || s->swdespeck || s->swcrop || s->swskip) -#ifdef SANE_FRAME_JPEG && s->s_params.format != SANE_FRAME_JPEG -#endif ){ return 1; } @@ -9424,9 +9801,7 @@ static int must_downsample(struct fujitsu *s) { if(s->s_mode != s->u_mode -#ifdef SANE_FRAME_JPEG && s->compress != COMP_JPEG -#endif ){ return 1; } @@ -9492,6 +9867,23 @@ get_page_height(struct fujitsu *s) return height; } +/* s->max_y gives the maximum height of paper which can be scanned + * this actually varies by resolution, so a helper to change it */ +static int +set_max_y(struct fujitsu *s) +{ + int i; + + for(i=0;i<4;i++){ + if(!s->max_y_by_res[i].res) + break; + if(s->resolution_x <= s->max_y_by_res[i].res){ + s->max_y = s->max_y_by_res[i].len; + } + } + + return s->max_y; +} /** * Convenience method to determine longest string size in a list. @@ -9561,7 +9953,8 @@ hexdump (int level, char *comment, unsigned char *p, int l) } /* print last (partial) line */ - DBG (level, "%s\n", line); + if (i) + DBG (level, "%s\n", line); } /** @@ -9654,37 +10047,23 @@ buffer_crop(struct fujitsu *s, int side) DBG (10, "buffer_crop: start\n"); - /*only find edges on first image from a page, or if first image had error */ - if(s->side == SIDE_FRONT || s->source == SOURCE_ADF_BACK || s->crop_stat){ - - s->crop_stat = sanei_magic_findEdges( - &s->s_params,s->buffers[side],s->resolution_x,s->resolution_y, - &s->crop_vals[0],&s->crop_vals[1],&s->crop_vals[2],&s->crop_vals[3]); - - if(s->crop_stat){ - DBG (5, "buffer_crop: bad edges, bailing\n"); - goto cleanup; - } - - DBG (15, "buffer_crop: t:%d b:%d l:%d r:%d\n", - s->crop_vals[0],s->crop_vals[1],s->crop_vals[2],s->crop_vals[3]); - - /* we dont listen to the 'top' value, since fujitsu does not pad the top */ - s->crop_vals[0] = 0; + ret = sanei_magic_findEdges( + &s->s_params,s->buffers[side],s->resolution_x,s->resolution_y, + &s->crop_vals[0],&s->crop_vals[1],&s->crop_vals[2],&s->crop_vals[3]); - /* if we will later binarize this image, make sure the width - * is a multiple of 8 pixels, by adjusting the right side */ - if ( must_downsample(s) && s->u_mode < MODE_GRAYSCALE ){ - s->crop_vals[3] -= (s->crop_vals[3]-s->crop_vals[2]) % 8; - } + if(ret){ + DBG (5, "buffer_crop: bad edges, bailing\n"); + ret = SANE_STATUS_GOOD; + goto cleanup; } - /* backside images can use a 'flipped' version of frontside data */ - else{ - int left = s->crop_vals[2]; - int right = s->crop_vals[3]; + + DBG (15, "buffer_crop: t:%d b:%d l:%d r:%d\n", + s->crop_vals[0],s->crop_vals[1],s->crop_vals[2],s->crop_vals[3]); - s->crop_vals[2] = s->s_params.pixels_per_line - right; - s->crop_vals[3] = s->s_params.pixels_per_line - left; + /* if we will later binarize this image, make sure the width + * is a multiple of 8 pixels, by adjusting the right side */ + if ( must_downsample(s) && s->u_mode < MODE_GRAYSCALE ){ + s->crop_vals[3] -= (s->crop_vals[3]-s->crop_vals[2]) % 8; } /* now crop the image */ diff --git a/backend/fujitsu.conf.in b/backend/fujitsu.conf.in index 8034f25..b3895ea 100644 --- a/backend/fujitsu.conf.in +++ b/backend/fujitsu.conf.in @@ -118,12 +118,6 @@ usb 0x04c5 0x119d #fi-6800-CGA usb 0x04c5 0x119e -#fi-6900 -usb 0x04c5 0x119f - -#fi-6900-CGA -usb 0x04c5 0x11a0 - #S1500 & S1500M usb 0x04c5 0x11a2 @@ -145,5 +139,24 @@ usb 0x04c5 0x11fc #fi-5950 usb 0x04c5 0x1213 +#ScanSnap SV600 +usb 0x04c5 0x128e + #ScanSnap iX500 usb 0x04c5 0x132b + +#fi-7180 +usb 0x04c5 0x132c + +#fi-7280 +usb 0x04c5 0x132d + +#fi-7160 +usb 0x04c5 0x132e + +#fi-7260 +usb 0x04c5 0x132f + +#ScanSnap iX100 +usb 0x04c5 0x13f4 + diff --git a/backend/fujitsu.h b/backend/fujitsu.h index 4c6804b..6ce1a56 100644 --- a/backend/fujitsu.h +++ b/backend/fujitsu.h @@ -72,6 +72,7 @@ enum fujitsu_Option OPT_DF_DIFF, OPT_DF_RECOVERY, OPT_PAPER_PROTECT, + OPT_ADV_PAPER_PROT, OPT_STAPLE_DETECT, OPT_BG_COLOR, OPT_DROPOUT_COLOR, @@ -79,6 +80,7 @@ enum fujitsu_Option OPT_PREPICK, OPT_OVERSCAN, OPT_SLEEP_TIME, + OPT_OFF_TIME, OPT_DUPLEX_OFFSET, OPT_GREEN_OFFSET, OPT_BLUE_OFFSET, @@ -89,6 +91,7 @@ enum fujitsu_Option OPT_SWDESPECK, OPT_SWCROP, OPT_SWSKIP, + OPT_HALT_ON_CANCEL, OPT_ENDORSER_GROUP, OPT_ENDORSER, @@ -127,6 +130,13 @@ enum fujitsu_Option NUM_OPTIONS }; +/* used to control the max page-height, which varies by resolution */ +struct y_size +{ + int res; + int len; +}; + struct fujitsu { /* --------------------------------------------------------------------- */ @@ -242,6 +252,7 @@ struct fujitsu int has_df_recovery; int has_paper_protect; + int has_adv_paper_prot; int has_staple_detect; int has_rif; @@ -257,6 +268,7 @@ struct fujitsu int has_ipc3; int has_rotation; int has_hybrid_crop_deskew; + int has_off_mode; int has_comp_MH; int has_comp_MR; @@ -265,6 +277,7 @@ struct fujitsu int has_comp_JPG1; int has_comp_JPG2; int has_comp_JPG3; + int has_op_halt; /*FIXME: more endorser data? */ int endorser_type_f; @@ -299,6 +312,7 @@ struct fujitsu /* the scan size in 1/1200th inches, NOT basic_units or sane units */ int max_x; int max_y; + struct y_size max_y_by_res[4]; int min_x; int min_y; int max_x_fb; @@ -313,10 +327,12 @@ struct fujitsu int window_gamma; int endorser_string_len; int has_pixelsize; + int has_short_pixelsize; /* m3091/2 put weird stuff at end, ignore it */ int broken_diag_serial; /* some scanners are just plain borked */ int need_q_table; /* some scanners wont work without these */ int need_diag_preread; + int late_lut; int hopper_before_op; /* some scanners dont like OP when hopper empty */ int no_wait_after_op; /* some scanners dont like TUR after OP */ @@ -382,6 +398,7 @@ struct fujitsu SANE_String_Const df_diff_list[5]; SANE_String_Const df_recovery_list[4]; SANE_String_Const paper_protect_list[4]; + SANE_String_Const adv_paper_prot_list[4]; SANE_String_Const staple_detect_list[4]; SANE_String_Const bg_color_list[4]; SANE_String_Const do_color_list[5]; @@ -390,6 +407,7 @@ struct fujitsu SANE_String_Const prepick_list[4]; SANE_String_Const overscan_list[4]; SANE_Range sleep_time_range; + SANE_Range off_time_range; SANE_Range duplex_offset_range; SANE_Range green_offset_range; SANE_Range blue_offset_range; @@ -467,6 +485,7 @@ struct fujitsu int df_diff; int df_recovery; int paper_protect; + int adv_paper_prot; int staple_detect; int bg_color; int dropout_color; @@ -475,6 +494,7 @@ struct fujitsu int overscan; int lamp_color; int sleep_time; + int off_time; int duplex_offset; int green_offset; int blue_offset; @@ -484,6 +504,7 @@ struct fujitsu int swdespeck; int swcrop; double swskip; + int halt_on_cancel; /*endorser group*/ int u_endorser; @@ -514,8 +535,10 @@ struct fujitsu SANE_Parameters s_params; /* also keep a backup copy, in case the software enhancement code overwrites*/ + /* SANE_Parameters u_params_bk; SANE_Parameters s_params_bk; + */ /* --------------------------------------------------------------------- */ /* values which are set by scanning functions to keep track of pages, etc */ @@ -556,7 +579,6 @@ struct fujitsu int deskew_vals[2]; double deskew_slope; - SANE_Status crop_stat; int crop_vals[4]; /* --------------------------------------------------------------------- */ @@ -622,12 +644,16 @@ struct fujitsu #define COMP_NONE WD_cmp_NONE #define COMP_JPEG WD_cmp_JPG1 -#define JPEG_STAGE_HEAD 0 -#define JPEG_STAGE_SOF 1 -#define JPEG_STAGE_SOS 2 -#define JPEG_STAGE_FRONT 3 -#define JPEG_STAGE_BACK 4 -#define JPEG_STAGE_EOI 5 +#define JPEG_STAGE_NONE 0 +#define JPEG_STAGE_SOI 1 +#define JPEG_STAGE_HEAD 2 +#define JPEG_STAGE_SOF 3 +#define JPEG_STAGE_SOS 4 +#define JPEG_STAGE_FRONT 5 +#define JPEG_STAGE_BACK 6 +#define JPEG_STAGE_EOI 7 + +#define JFIF_APP0_LENGTH 18 /* these are same as scsi data to make code easier */ #define MODE_LINEART WD_comp_LA @@ -771,7 +797,7 @@ do_usb_cmd(struct fujitsu *s, int runRS, int shortTime, static SANE_Status wait_scanner (struct fujitsu *s); -static SANE_Status object_position (struct fujitsu *s, int i_load); +static SANE_Status object_position (struct fujitsu *s, int action); static SANE_Status scanner_control (struct fujitsu *s, int function); static SANE_Status scanner_control_ric (struct fujitsu *s, int bytes, int side); @@ -789,11 +815,13 @@ static SANE_Status mode_select_prepick (struct fujitsu *s); static SANE_Status mode_select_auto (struct fujitsu *s); static SANE_Status set_sleep_mode(struct fujitsu *s); +static SANE_Status set_off_mode(struct fujitsu *s); static int must_downsample (struct fujitsu *s); static int must_fully_buffer (struct fujitsu *s); static int get_page_width (struct fujitsu *s); static int get_page_height (struct fujitsu *s); +static int set_max_y (struct fujitsu *s); static SANE_Status send_lut (struct fujitsu *s); static SANE_Status send_endorser (struct fujitsu *s); @@ -803,19 +831,17 @@ static SANE_Status get_pixelsize(struct fujitsu *s, int actual); static SANE_Status update_params (struct fujitsu *s); static SANE_Status update_u_params (struct fujitsu *s); -static SANE_Status backup_params (struct fujitsu *s); -static SANE_Status restore_params (struct fujitsu *s); + static SANE_Status start_scan (struct fujitsu *s); static SANE_Status check_for_cancel(struct fujitsu *s); -#ifdef SANE_FRAME_JPEG static SANE_Status read_from_JPEGduplex(struct fujitsu *s); -#endif static SANE_Status read_from_3091duplex(struct fujitsu *s); static SANE_Status read_from_scanner(struct fujitsu *s, int side); static SANE_Status copy_3091(struct fujitsu *s, unsigned char * buf, int len, int side); +static SANE_Status copy_JPEG(struct fujitsu *s, unsigned char * buf, int len, int side); static SANE_Status copy_buffer(struct fujitsu *s, unsigned char * buf, int len, int side); static SANE_Status read_from_buffer(struct fujitsu *s, SANE_Byte * buf, SANE_Int max_len, SANE_Int * len, int side); diff --git a/backend/genesys.c b/backend/genesys.c index 6e7caad..984cead 100644 --- a/backend/genesys.c +++ b/backend/genesys.c @@ -2,7 +2,7 @@ Copyright (C) 2003, 2004 Henning Meier-Geinitz <henning@meier-geinitz.de> Copyright (C) 2004, 2005 Gerhard Jaeger <gerhard@gjaeger.de> - Copyright (C) 2004-2013 Stphane Voltz <stef.dev@free.fr> + Copyright (C) 2004-2015 Stphane Voltz <stef.dev@free.fr> Copyright (C) 2005-2009 Pierre Willenbrock <pierre@pirsoft.dnsalias.org> Copyright (C) 2006 Laurent Charpentier <laurent_pubs@yahoo.com> Copyright (C) 2007 Luke <iceyfor@gmail.com> @@ -16,49 +16,49 @@ noah work in the fujitsu backend This file is part of the SANE package. - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - + As a special exception, the authors of SANE give permission for additional uses of the libraries contained in this release of SANE. - + The exception is that, if you link a SANE library with other files to produce an executable, this does not by itself cause the resulting executable to be covered by the GNU General Public License. Your use of that executable is in no way restricted on account of linking the SANE library code into it. - + This exception does not, however, invalidate any other reasons why the executable file might be covered by the GNU General Public License. - + If you submit changes to SANE to the maintainers to be included in a subsequent release, you agree by submitting the changes that those changes may be distributed with this exception intact. If you write modifications of your own for SANE, it is your choice whether to permit this exception to apply to your modifications. - If you do not wish that, delete this exception notice. + If you do not wish that, delete this exception notice. */ /* * SANE backend for Genesys Logic GL646/GL841/GL842/GL843/GL846/GL847/GL124 based scanners */ -#define BUILD 2411 +#define BUILD 2508 #define BACKEND_NAME genesys #include "genesys.h" @@ -157,6 +157,15 @@ static const SANE_Range enhance_range = { 1 /* quantization */ }; +/** + * range for expiration time + */ +static const SANE_Range expiration_range = { + -1, /* minimum */ + 30000, /* maximum */ + 1 /* quantization */ +}; + void sanei_genesys_init_structs (Genesys_Device * dev) { @@ -231,11 +240,11 @@ sanei_genesys_init_fe (Genesys_Device * dev) /* main function for slope creation */ /** - * This function generates a slope table using the given slope - * truncated at the given exposure time or step count, whichever comes first. + * This function generates a slope table using the given slope + * truncated at the given exposure time or step count, whichever comes first. * The reached step time is then stored in final_exposure and used for the rest * of the table. The summed time of the acceleration steps is returned, and the - * number of accerelation steps is put into used_steps. + * number of accerelation steps is put into used_steps. * * @param slope_table Table to write to * @param max_steps Size of slope_table in steps @@ -248,7 +257,7 @@ sanei_genesys_init_fe (Genesys_Device * dev) * @param used_steps Final number of steps is stored here * @param vfinal Final step time is stored here * @return Time for acceleration - * @note All times in pixel time. Correction for other motor timings is not + * @note All times in pixel time. Correction for other motor timings is not * done. */ SANE_Int @@ -339,10 +348,10 @@ sanei_genesys_generate_slope_table (uint16_t * slope_table, /* Generate slope table for motor movement */ /** * This function generates a slope table using the slope from the motor struct - * truncated at the given exposure time or step count, whichever comes first. + * truncated at the given exposure time or step count, whichever comes first. * The reached step time is then stored in final_exposure and used for the rest * of the table. The summed time of the acceleration steps is returned, and the - * number of accerelation steps is put into used_steps. + * number of accerelation steps is put into used_steps. * * @param dev Device struct * @param slope_table Table to write to @@ -412,7 +421,7 @@ sanei_genesys_create_slope_table3 (Genesys_Device * dev, if (final_exposure) *final_exposure = (vfinal * dev->motor.base_ydpi) / yres; - + DBG (DBG_proc, "sanei_genesys_create_slope_table: returns sum_time=%d, completed\n", sum_time); @@ -735,7 +744,7 @@ sanei_genesys_create_gamma_table (uint16_t * gamma_table, int size, if(gamma_table==NULL) { - DBG (DBG_proc, "sanei_genesys_create_gamma_table: gamma tbale is NULL\n"); + DBG (DBG_proc, "sanei_genesys_create_gamma_table: gamma table is NULL\n"); return; } DBG (DBG_proc, @@ -753,27 +762,26 @@ sanei_genesys_create_gamma_table (uint16_t * gamma_table, int size, } -/* computes the exposure_time on the basis of the given vertical dpi, +/* computes the exposure_time on the basis of the given vertical dpi, the number of pixels the ccd needs to send, the step_type and the corresponding maximum speed from the motor struct */ /* - Currently considers maximum motor speed at given step_type, minimum + Currently considers maximum motor speed at given step_type, minimum line exposure needed for conversion and led exposure time. TODO: Should also consider maximum transfer rate: ~6.5MB/s. - Note: The enhance option of the scanners does _not_ help. It only halves + Note: The enhance option of the scanners does _not_ help. It only halves the amount of pixels transfered. */ SANE_Int sanei_genesys_exposure_time2 (Genesys_Device * dev, float ydpi, int step_type, int endpixel, - int led_exposure, int power_mode) + int exposure_by_led, int power_mode) { int exposure_by_ccd = endpixel + 32; int exposure_by_motor = (dev->motor.slopes[power_mode][step_type].maximum_speed * dev->motor.base_ydpi) / ydpi; - int exposure_by_led = led_exposure; int exposure = exposure_by_ccd; @@ -783,6 +791,8 @@ sanei_genesys_exposure_time2 (Genesys_Device * dev, float ydpi, if (exposure < exposure_by_led && dev->model->is_cis) exposure = exposure_by_led; + DBG (DBG_info, "%s: ydpi=%d, step=%d, endpixel=%d led=%d, power=%d => exposure=%d\n", + __FUNCTION__, (int)ydpi, step_type, endpixel, exposure_by_led, power_mode, exposure); return exposure; } @@ -898,11 +908,11 @@ sanei_genesys_exposure_time (Genesys_Device * dev, Genesys_Register_Set * reg, -/* Sends a block of shading information to the scanner. - The data is placed at address 0x0000 for color mode, gray mode and +/* Sends a block of shading information to the scanner. + The data is placed at address 0x0000 for color mode, gray mode and unconditionally for the following CCD chips: HP2300, HP2400 and HP5345 - In the other cases (lineart, halftone on ccd chips not mentioned) the - addresses are 0x2a00 for dpihw==0, 0x5500 for dpihw==1 and 0xa800 for + In the other cases (lineart, halftone on ccd chips not mentioned) the + addresses are 0x2a00 for dpihw==0, 0x5500 for dpihw==1 and 0xa800 for dpihw==2. //Note: why this? The data needs to be of size "size", and in little endian byte order. @@ -918,10 +928,11 @@ genesys_send_offset_and_shading (Genesys_Device * dev, uint8_t * data, int start_address; SANE_Status status; - DBG (DBG_proc, "genesys_send_offset_and_shading (size = %d)\n", size); + DBG (DBG_proc, "%s: (size = %d)\n", __FUNCTION__, size); /* ASIC higher than gl843 doesn't have register 2A/2B, so we route to - * a per ASIC shading data loading function if available */ + * a per ASIC shading data loading function if available. + * It is also used for scanners using SHDAREA */ if(dev->model->cmd_set->send_shading_data!=NULL) { status=dev->model->cmd_set->send_shading_data(dev, data, size); @@ -932,7 +943,7 @@ genesys_send_offset_and_shading (Genesys_Device * dev, uint8_t * data, /* gl646, gl84[123] case */ dpihw = sanei_genesys_read_reg_from_set (dev->reg, 0x05) >> 6; - /* TODO invert the test so only the 2 models behaving like that are + /* TODO invert the test so only the 2 models behaving like that are * tested instead of adding all the others */ /* many scanners send coefficient for lineart/gray like in color mode */ if (dev->settings.scan_mode < 2 @@ -945,6 +956,7 @@ genesys_send_offset_and_shading (Genesys_Device * dev, uint8_t * data, && dev->model->ccd_type != CCD_XP300 && dev->model->ccd_type != CCD_DP665 && dev->model->ccd_type != CCD_DP685 + && dev->model->ccd_type != CIS_CANONLIDE80 && dev->model->ccd_type != CCD_ROADWARRIOR && dev->model->ccd_type != CCD_HP2300 && dev->model->ccd_type != CCD_HP2400 @@ -966,17 +978,15 @@ genesys_send_offset_and_shading (Genesys_Device * dev, uint8_t * data, status = sanei_genesys_set_buffer_address (dev, start_address); if (status != SANE_STATUS_GOOD) { - DBG (DBG_error, - "genesys_send_offset_and_shading: failed to set buffer address: %s\n", - sane_strstatus (status)); + DBG (DBG_error, "%s: failed to set buffer address: %s\n", __FUNCTION__, + sane_strstatus (status)); return status; } - + status = dev->model->cmd_set->bulk_write_data (dev, 0x3c, data, size); if (status != SANE_STATUS_GOOD) { - DBG (DBG_error, - "genesys_send_offset_and_shading: failed to send shading table: %s\n", + DBG (DBG_error, "%s: failed to send shading table: %s\n", __FUNCTION__, sane_strstatus (status)); return status; } @@ -1030,22 +1040,22 @@ sanei_genesys_init_shading_data (Genesys_Device * dev, int pixels_per_line) *shading_data_ptr++ = 0x40; /* white hi -> 0x4000 */ } - status = - genesys_send_offset_and_shading (dev, shading_data, - pixels_per_line * 4 * channels); - if (status != SANE_STATUS_GOOD) - DBG (DBG_error, - "sanei_genesys_init_shading_data: failed to send shading data: %s\n", - sane_strstatus (status)); - + status = genesys_send_offset_and_shading (dev, + shading_data, + pixels_per_line * 4 * channels); free (shading_data); + if (status != SANE_STATUS_GOOD) + { + DBG (DBG_error, "%s: failed to send shading data: %s\n", __FUNCTION__, + sane_strstatus (status)); + } DBGCOMPLETED; return status; } -/* Find the position of the reference point: +/* Find the position of the reference point: takes gray level 8 bits data and find first CCD usable pixel and top of scanning area */ SANE_Status @@ -1090,7 +1100,7 @@ sanei_genesys_search_reference_point (Genesys_Device * dev, uint8_t * data, if (DBG_LEVEL >= DBG_data) sanei_genesys_write_pnm_file ("laplace.pnm", image, 8, 1, width, height); - /* apply X direction sobel filter + /* apply X direction sobel filter -1 0 1 -2 0 2 -1 0 1 @@ -1144,7 +1154,7 @@ sanei_genesys_search_reference_point (Genesys_Device * dev, uint8_t * data, start_pixel + (left * dev->sensor.optical_res) / dpi; /* find top edge by detecting black strip */ - /* apply Y direction sobel filter + /* apply Y direction sobel filter -1 -2 -1 0 0 0 1 2 1 @@ -1913,7 +1923,7 @@ genesys_dark_shading_calibration (Genesys_Device * dev) /* * this function builds dummy dark calibration data so that we can * compute shading coefficient in a clean way - * todo: current values are hardcoded, we have to find if they + * todo: current values are hardcoded, we have to find if they * can be computed from previous calibration data (when doing offset * calibration ?) */ @@ -2114,7 +2124,7 @@ genesys_white_shading_calibration (Genesys_Device * dev) sanei_genesys_write_pnm_file ("white_shading.pnm", calibration_data, 16, channels, pixels_per_line, dev->calib_lines); - + genesys_average_data (dev->white_average_data, calibration_data, dev->calib_lines, pixels_per_line * channels); @@ -2138,7 +2148,7 @@ genesys_white_shading_calibration (Genesys_Device * dev) return status; } } - + if (dev->model->flags & GENESYS_FLAG_SHADING_REPARK) { status = dev->model->cmd_set->slow_back_home (dev, SANE_TRUE); @@ -2149,10 +2159,13 @@ genesys_white_shading_calibration (Genesys_Device * dev) return status; } -/* This calibration uses a scan over the calibration target, comprising a +/* This calibration uses a scan over the calibration target, comprising a * black and a white strip. (So the motor must be on.) */ -static SANE_Status +#ifndef UNIT_TESTING +static +#endif +SANE_Status genesys_dark_white_shading_calibration (Genesys_Device * dev) { SANE_Status status; @@ -2167,8 +2180,7 @@ genesys_dark_white_shading_calibration (Genesys_Device * dev) SANE_Bool motor; - DBG (DBG_proc, "genesys_black_white_shading_calibration (lines = %d)\n", - (unsigned int)dev->calib_lines); + DBG (DBG_proc, "%s: (lines = %d)\n", __FUNCTION__, (unsigned int)dev->calib_lines); pixels_per_line = dev->calib_pixels; channels = dev->calib_channels; @@ -2181,8 +2193,7 @@ genesys_dark_white_shading_calibration (Genesys_Device * dev) dev->white_average_data = malloc (dev->average_size); if (!dev->white_average_data) { - DBG (DBG_error, - "genesys_dark_white_shading_calibration: failed to allocate average memory\n"); + DBG (DBG_error, "%s: failed to allocate white average memory\n", __FUNCTION__); return SANE_STATUS_NO_MEM; } @@ -2192,8 +2203,7 @@ genesys_dark_white_shading_calibration (Genesys_Device * dev) dev->dark_average_data = malloc (channels * 2 * pixels_per_line); if (!dev->dark_average_data) { - DBG (DBG_error, - "genesys_dark_white_shading_shading_calibration: failed to allocate average memory\n"); + DBG (DBG_error, "%s: failed to allocate dark average memory\n", __FUNCTION__); return SANE_STATUS_NO_MEM; } @@ -2202,8 +2212,7 @@ genesys_dark_white_shading_calibration (Genesys_Device * dev) calibration_data = malloc (size); if (!calibration_data) { - DBG (DBG_error, - "genesys_dark_white_shading_calibration: failed to allocate calibration memory\n"); + DBG (DBG_error, "%s: failed to allocate calibration memory\n", __FUNCTION__); return SANE_STATUS_NO_MEM; } @@ -2224,9 +2233,8 @@ genesys_dark_white_shading_calibration (Genesys_Device * dev) if (status != SANE_STATUS_GOOD) { free (calibration_data); - DBG (DBG_error, - "genesys_dark_white_shading_calibration: failed to bulk write registers: %s\n", - sane_strstatus (status)); + DBG (DBG_error, "%s: failed to bulk write registers: %s\n", __FUNCTION__, + sane_strstatus (status)); return status; } @@ -2235,8 +2243,7 @@ genesys_dark_white_shading_calibration (Genesys_Device * dev) if (status != SANE_STATUS_GOOD) { free (calibration_data); - DBG (DBG_error, - "genesys_dark_white_shading_calibration: Failed to begin scan: %s\n", + DBG (DBG_error, "%s: failed to begin scan: %s\n", __FUNCTION__, sane_strstatus (status)); return status; } @@ -2245,8 +2252,7 @@ genesys_dark_white_shading_calibration (Genesys_Device * dev) if (status != SANE_STATUS_GOOD) { free (calibration_data); - DBG (DBG_error, - "genesys_dark_white_shading_calibration: Failed to read data: %s\n", + DBG (DBG_error, "%s: failed to read data: %s\n", __FUNCTION__, sane_strstatus (status)); return status; } @@ -2255,16 +2261,26 @@ genesys_dark_white_shading_calibration (Genesys_Device * dev) if (status != SANE_STATUS_GOOD) { free (calibration_data); - DBG (DBG_error, - "genesys_dark_white_shading_calibration: Failed to end scan: %s\n", + DBG (DBG_error, "%s: Failed to end scan: %s\n", __FUNCTION__, sane_strstatus (status)); return status; } if (DBG_LEVEL >= DBG_data) - sanei_genesys_write_pnm_file ("black_white_shading.pnm", calibration_data, - 16, channels, pixels_per_line, - dev->calib_lines); + { + if (dev->model->is_cis) + { + sanei_genesys_write_pnm_file ("black_white_shading.pnm", calibration_data, + 16, 1, pixels_per_line*channels, + dev->calib_lines); + } + else + { + sanei_genesys_write_pnm_file ("black_white_shading.pnm", calibration_data, + 16, channels, pixels_per_line, + dev->calib_lines); + } + } average_white = dev->white_average_data; @@ -2375,15 +2391,15 @@ compute_coefficient (unsigned int coeff, unsigned int target, unsigned int value * The dark/white shading is actually performed _after_ reducing * resolution via averaging. only dark/white shading data for what would be * first pixel at full resolution is used. - * + * * scanner raw input to output value calculation: * o=(i-off)*(gain/coeff) - * + * * from datasheet: * off=dark_average * gain=coeff*bright_target/(bright_average-dark_average) * works for dark_target==0 - * + * * what we want is these: * bright_target=(bright_average-off)*(gain/coeff) * dark_target=(dark_average-off)*(gain/coeff) @@ -2406,30 +2422,31 @@ static #endif void compute_averaged_planar (Genesys_Device * dev, - uint8_t * shading_data, - unsigned int pixels_per_line, - unsigned int words_per_color, - unsigned int channels, - unsigned int o, - unsigned int coeff, - unsigned int target_bright, - unsigned int target_dark) + uint8_t * shading_data, + unsigned int pixels_per_line, + unsigned int words_per_color, + unsigned int channels, + unsigned int o, + unsigned int coeff, + unsigned int target_bright, + unsigned int target_dark) { unsigned int x, i, j, br, dk, res, avgpixels, basepixels, val; + unsigned int fill,factor; + + DBG (DBG_info, "%s: pixels=%d, offset=%d\n", __FUNCTION__, pixels_per_line, o); - DBG (DBG_info, "%s: pixels=%d, offset=%d\n", __FUNCTION__, pixels_per_line, - o); /* initialize result */ memset (shading_data, 0xff, words_per_color * 3 * 2); - /* + /* strangely i can write 0x20000 bytes beginning at 0x00000 without overwriting slope tables - which begin at address 0x10000(for 1200dpi hw mode): memory is organized in words(2 bytes) instead of single bytes. explains quite some things */ /* - another one: the dark/white shading is actually performed _after_ reducing + another one: the dark/white shading is actually performed _after_ reducing resolution via averaging. only dark/white shading data for what would be first pixel at full resolution is used. */ @@ -2449,15 +2466,17 @@ compute_averaged_planar (Genesys_Device * dev, off = (dark_average*bright_target - bright_average*dark_target)/(bright_target - dark_target) gain = (bright_target - dark_target)/(bright_average - dark_average)*coeff */ - /* duplicate half-ccd logic */ res = dev->settings.xres; + + /* duplicate half-ccd logic */ if ((dev->model->flags & GENESYS_FLAG_HALF_CCD_MODE) && dev->settings.xres <= dev->sensor.optical_res / 2) - res *= 2; /* scanner is using half-ccd mode */ - /*this should be evenly dividable */ + res *= 2; + + /* this should be evenly dividable */ basepixels = dev->sensor.optical_res / res; -/* gl841 supports 1/1 1/2 1/3 1/4 1/5 1/6 1/8 1/10 1/12 1/15 averaging */ + /* gl841 supports 1/1 1/2 1/3 1/4 1/5 1/6 1/8 1/10 1/12 1/15 averaging */ if (basepixels < 1) avgpixels = 1; else if (basepixels < 6) @@ -2473,11 +2492,24 @@ compute_averaged_planar (Genesys_Device * dev, else avgpixels = 15; + /* LiDE80 packs shading data */ + if(dev->model->ccd_type != CIS_CANONLIDE80) + { + factor=1; + fill=avgpixels; + } + else + { + factor=avgpixels; + fill=1; + } + DBG (DBG_info, "%s: averaging over %d pixels\n", __FUNCTION__, avgpixels); + DBG (DBG_info, "%s: packing factor is %d\n", __FUNCTION__, factor); + DBG (DBG_info, "%s: fill length is %d\n", __FUNCTION__, fill); for (x = 0; x <= pixels_per_line - avgpixels; x += avgpixels) { - if ((x + o) * 2 * 2 + 3 > words_per_color * 2) break; @@ -2514,59 +2546,47 @@ compute_averaged_planar (Genesys_Device * dev, 65535 * (target_bright - target_dark)) val = 65535; else - val = - (dk * target_bright - br * target_dark) / (target_bright - - target_dark); + { + val = (dk * target_bright - br * target_dark) / (target_bright - target_dark); + } -/*fill all pixels, even if only the last one is relevant*/ - for (i = 0; i < avgpixels; i++) + /*fill all pixels, even if only the last one is relevant*/ + for (i = 0; i < fill; i++) { - shading_data[(x + o + i) * 2 * 2 + - words_per_color * 2 * j] = val & 0xff; - shading_data[(x + o + i) * 2 * 2 + - words_per_color * 2 * j + 1] = val >> 8; + shading_data[(x/factor + o + i) * 2 * 2 + words_per_color * 2 * j] = val & 0xff; + shading_data[(x/factor + o + i) * 2 * 2 + words_per_color * 2 * j + 1] = val >> 8; } val = br - dk; if (65535 * val > (target_bright - target_dark) * coeff) - val = (coeff * (target_bright - target_dark)) / val; + { + val = (coeff * (target_bright - target_dark)) / val; + } else - val = 65535; + { + val = 65535; + } -/*fill all pixels, even if only the last one is relevant*/ - for (i = 0; i < avgpixels; i++) + /*fill all pixels, even if only the last one is relevant*/ + for (i = 0; i < fill; i++) { - shading_data[(x + o + i) * 2 * 2 + - words_per_color * 2 * j + 2] = val & 0xff; - shading_data[(x + o + i) * 2 * 2 + - words_per_color * 2 * j + 3] = val >> 8; + shading_data[(x/factor + o + i) * 2 * 2 + words_per_color * 2 * j + 2] = val & 0xff; + shading_data[(x/factor + o + i) * 2 * 2 + words_per_color * 2 * j + 3] = val >> 8; } } -/*fill remaining channels*/ + /* fill remaining channels */ for (j = channels; j < 3; j++) { - for (i = 0; i < avgpixels; i++) + for (i = 0; i < fill; i++) { - shading_data[(x + o + i) * 2 * 2 + - words_per_color * 2 * j] = - shading_data[(x + o + i) * 2 * 2 + words_per_color * 0]; - shading_data[(x + o + i) * 2 * 2 + - words_per_color * 2 * j + 1] = - shading_data[(x + o + i) * 2 * 2 + - words_per_color * 2 * 0 + 1]; - shading_data[(x + o + i) * 2 * 2 + - words_per_color * 2 * j + 2] = - shading_data[(x + o + i) * 2 * 2 + - words_per_color * 2 * 0 + 2]; - shading_data[(x + o + i) * 2 * 2 + - words_per_color * 2 * j + 3] = - shading_data[(x + o + i) * 2 * 2 + - words_per_color * 2 * 0 + 3]; + shading_data[(x/factor + o + i) * 2 * 2 + words_per_color * 2 * j ] = shading_data[(x/factor + o + i) * 2 * 2 ]; + shading_data[(x/factor + o + i) * 2 * 2 + words_per_color * 2 * j + 1] = shading_data[(x/factor + o + i) * 2 * 2 + 1]; + shading_data[(x/factor + o + i) * 2 * 2 + words_per_color * 2 * j + 2] = shading_data[(x/factor + o + i) * 2 * 2 + 2]; + shading_data[(x/factor + o + i) * 2 * 2 + words_per_color * 2 * j + 3] = shading_data[(x/factor + o + i) * 2 * 2 + 3]; } } - } } @@ -2603,7 +2623,7 @@ compute_coefficients (Genesys_Device * dev, DBG (DBG_io, "compute_coefficients: pixels_per_line=%d, coeff=0x%04x\n", pixels_per_line, coeff); - + /* compute start & end values depending of the offset */ if (offset < 0) { @@ -2672,7 +2692,7 @@ compute_planar_coefficients (Genesys_Device * dev, unsigned int channels, unsigned int cmat[3], unsigned int offset, - unsigned int coeff, + unsigned int coeff, unsigned int target) { uint8_t *ptr; /* contains 16bit words in little endian */ @@ -2781,9 +2801,9 @@ compute_shifted_coefficients (Genesys_Device * dev, for (i = 0; i < avgpixels; i++) { for (j = 0; j < channels; j++) { - br_tmp[j] += (dev->white_average_data[((x + i) * channels + j) * 2] | + br_tmp[j] += (dev->white_average_data[((x + i) * channels + j) * 2] | (dev->white_average_data[((x + i) * channels + j) * 2 + 1] << 8)); - dk_tmp[i] += (dev->dark_average_data[((x + i) * channels + j) * 2] | + dk_tmp[i] += (dev->dark_average_data[((x + i) * channels + j) * 2] | (dev->dark_average_data[((x + i) * channels + j) * 2 + 1] << 8)); } } @@ -2826,7 +2846,7 @@ compute_shifted_coefficients (Genesys_Device * dev, } } -static SANE_Status +GENESYS_STATIC SANE_Status genesys_send_shading_coefficient (Genesys_Device * dev) { SANE_Status status; @@ -2869,19 +2889,27 @@ genesys_send_shading_coefficient (Genesys_Device * dev) break; } + /* special case, memory is aligned on 0x5400, this has yet to be explained */ + /* could be 0xa800 because sensor is truly 2400 dpi, then halved because + * we only set 1200 dpi */ + if(dev->model->ccd_type==CIS_CANONLIDE80) + { + words_per_color = 0x5400; + } + length = words_per_color * 3 * 2; + /* allocate computed size */ shading_data = malloc (length); if (!shading_data) { - DBG (DBG_error, - "genesys_send_shading_coefficient: failed to allocate memory\n"); + DBG (DBG_error, "%s: failed to allocate memory\n", __FUNCTION__); return SANE_STATUS_NO_MEM; } memset (shading_data, 0, length); /* TARGET/(Wn-Dn) = white gain -> ~1.xxx then it is multiplied by 0x2000 - or 0x4000 to give an integer + or 0x4000 to give an integer Wn = white average for column n Dn = dark average for column n */ @@ -2974,10 +3002,10 @@ genesys_send_shading_coefficient (Genesys_Device * dev) compute_coefficients (dev, shading_data, pixels_per_line, - 3, - cmat, - o, - coeff, + 3, + cmat, + o, + coeff, target_code); break; case CCD_HP3670: @@ -2999,10 +3027,10 @@ genesys_send_shading_coefficient (Genesys_Device * dev) compute_coefficients (dev, shading_data, pixels_per_line, - 3, - cmat, - o, - coeff, + 3, + cmat, + o, + coeff, target_code); break; case CCD_KVSS080: @@ -3015,21 +3043,25 @@ genesys_send_shading_coefficient (Genesys_Device * dev) compute_coefficients (dev, shading_data, pixels_per_line, - 3, - cmat, - o, - coeff, + 3, + cmat, + o, + coeff, target_code); break; case CIS_CANONLIDE700: case CIS_CANONLIDE100: case CIS_CANONLIDE200: case CIS_CANONLIDE110: + case CIS_CANONLIDE120: case CIS_CANONLIDE210: + case CIS_CANONLIDE220: /* TODO store this in a data struct so we avoid * growing this switch */ if(dev->model->ccd_type!=CIS_CANONLIDE110 - && dev->model->ccd_type!=CIS_CANONLIDE210) + && dev->model->ccd_type!=CIS_CANONLIDE210 + && dev->model->ccd_type!=CIS_CANONLIDE120 + && dev->model->ccd_type!=CIS_CANONLIDE220) target_code=0xdc00; else target_code=0xf000; @@ -3039,8 +3071,7 @@ genesys_send_shading_coefficient (Genesys_Device * dev) shading_data = malloc (length); if (!shading_data) { - DBG (DBG_error, - "genesys_send_shading_coefficient: failed to allocate memory\n"); + DBG (DBG_error, "%s: failed to allocate memory\n", __FUNCTION__); return SANE_STATUS_NO_MEM; } memset (shading_data, 0, length); @@ -3063,9 +3094,20 @@ genesys_send_shading_coefficient (Genesys_Device * dev) channels, 4, coeff, - 0xfa00, + 0xe000, 0x0a00); break; + case CIS_CANONLIDE80: + compute_averaged_planar (dev, + shading_data, + pixels_per_line, + words_per_color, + channels, + 0, + coeff, + 0xd000, + 0x0800); + break; case CCD_PLUSTEK_3600: compute_shifted_coefficients (dev, shading_data, @@ -3079,23 +3121,21 @@ genesys_send_shading_coefficient (Genesys_Device * dev) 256); /* patch_size: contigous extent */ break; default: - DBG (DBG_error, - "genesys_send_shading_coefficient: sensor %d not supported\n", - dev->model->ccd_type); + DBG (DBG_error, "%s: sensor %d not supported\n", __FUNCTION__, dev->model->ccd_type); return SANE_STATUS_UNSUPPORTED; break; } /* do the actual write of shading calibration data to the scanner */ status = genesys_send_offset_and_shading (dev, shading_data, length); + free (shading_data); if (status != SANE_STATUS_GOOD) - DBG (DBG_error, - "genesys_send_shading_coefficient: failed to send shading data: %s\n", - sane_strstatus (status)); + { + DBG (DBG_error, "%s: failed to send shading data: %s\n", __FUNCTION__, + sane_strstatus (status)); + } - free (shading_data); DBGCOMPLETED; - return SANE_STATUS_GOOD; } @@ -3125,7 +3165,7 @@ genesys_restore_calibration (Genesys_Device * dev) for (cache = dev->calibration_cache; cache; cache = cache->next) { status = dev->model->cmd_set->is_compatible_calibration (dev, cache, SANE_FALSE); - /* SANE_STATUS_GOOD, a matching cache has been found + /* SANE_STATUS_GOOD, a matching cache has been found * so we use it to populate calibration data */ if (status == SANE_STATUS_GOOD) @@ -3270,7 +3310,7 @@ genesys_save_calibration (Genesys_Device * dev) * @param dev device to calibrate * @return SANE_STATUS_GOOD if everything when all right, else the error code. */ -static SANE_Status +GENESYS_STATIC SANE_Status genesys_flatbed_calibration (Genesys_Device * dev) { SANE_Status status; @@ -3514,7 +3554,7 @@ genesys_sheetfed_calibration (Genesys_Device * dev) xres = dev->sensor.optical_res; dev->settings.xres = dev->sensor.optical_res; /* XP200 needs to calibrate a full and half sensor's resolution */ - if (dev->model->ccd_type == CIS_XP200 + if (dev->model->ccd_type == CIS_XP200 && dev->settings.xres <= dev->sensor.optical_res / 2) dev->settings.xres /= 2; @@ -3590,7 +3630,7 @@ genesys_sheetfed_calibration (Genesys_Device * dev) } } - /* search for a full width black strip and then do a 16 bit scan to + /* search for a full width black strip and then do a 16 bit scan to * gather black shading data */ if (dev->model->flags & GENESYS_FLAG_DARK_CALIBRATION) { @@ -3649,8 +3689,7 @@ genesys_sheetfed_calibration (Genesys_Device * dev) if (status != SANE_STATUS_GOOD) { dev->model->cmd_set->eject_document (dev); - DBG (DBG_error, - "genesys_sheetfed_calibration: failed eject target: %s\n", + DBG (DBG_error, "%s: failed eject target: %s\n", __FUNCTION__, sane_strstatus (status)); return status; } @@ -3851,7 +3890,7 @@ genesys_warmup_lamp (Genesys_Device * dev) { first_average /= pixel; second_average /= pixel; - difference = abs (first_average - second_average); + difference = fabs (first_average - second_average); DBG (DBG_info, "genesys_warmup_lamp: average = %.2f, diff = %.3f\n", 100 * ((second_average) / (256 * 256)), @@ -3878,7 +3917,7 @@ genesys_warmup_lamp (Genesys_Device * dev) } DBG (DBG_info, "genesys_warmup_lamp: average 1 = %.2f, average 2 = %.2f\n", first_average, second_average); /* if delta below 15/255 ~= 5.8%, lamp is considred warm enough */ - if (abs (first_average - second_average) < 15 + if (fabs (first_average - second_average) < 15 && second_average > 55) break; } @@ -3935,7 +3974,7 @@ genesys_start_scan (Genesys_Device * dev, SANE_Bool lamp_off) return status; } } - + /* disable power saving*/ status = dev->model->cmd_set->save_power (dev, SANE_FALSE); if (status != SANE_STATUS_GOOD) @@ -4077,7 +4116,7 @@ genesys_start_scan (Genesys_Device * dev, SANE_Bool lamp_off) status = sanei_genesys_load_lut(dev->lineart_lut, 8, 8, 50, 205, dev->settings.threshold_curve, dev->settings.threshold-127); - if (status != SANE_STATUS_GOOD) + if (status != SANE_STATUS_GOOD) { DBG (DBG_error, "genesys_start_scan: failed to build lut\n"); return status; @@ -4094,11 +4133,11 @@ genesys_start_scan (Genesys_Device * dev, SANE_Bool lamp_off) } /* no lamp during scan */ - if(lamp_off == SANE_TRUE) + if(lamp_off == SANE_TRUE) { dev->model->cmd_set->set_lamp_power (dev, dev->reg, SANE_FALSE); } - + /* GL124 is using SHDAREA, so we have to wait for scan to be set up before * sending shading data */ if( (dev->model->cmd_set->send_shading_data!=NULL) @@ -4140,7 +4179,7 @@ genesys_start_scan (Genesys_Device * dev, SANE_Bool lamp_off) /*do we really need this? the valid data check should be sufficent -- pierre*/ /* waits for head to reach scanning position */ expected = sanei_genesys_read_reg_from_set (dev->reg, 0x3d) * 65536 - + sanei_genesys_read_reg_from_set (dev->reg, 0x3e) * 256 + + sanei_genesys_read_reg_from_set (dev->reg, 0x3e) * 256 + sanei_genesys_read_reg_from_set (dev->reg, 0x3f); do { @@ -4157,7 +4196,7 @@ genesys_start_scan (Genesys_Device * dev, SANE_Bool lamp_off) } } while (steps < expected); - + /* wait for buffers to be filled */ do { @@ -4173,7 +4212,7 @@ genesys_start_scan (Genesys_Device * dev, SANE_Bool lamp_off) else usleep (500 * 1000); */ - /* then we wait for at least one word of valid scan data + /* then we wait for at least one word of valid scan data this is also done in sanei_genesys_read_data_from_scanner -- pierre */ if (dev->model->is_sheetfed == SANE_FALSE) @@ -4192,12 +4231,12 @@ genesys_start_scan (Genesys_Device * dev, SANE_Bool lamp_off) } while (steps < 1); } - + DBGCOMPLETED; return SANE_STATUS_GOOD; } -/* this is _not_ a ringbuffer. +/* this is _not_ a ringbuffer. if we need a block which does not fit at the end of our available data, we move the available data to the beginning. */ @@ -4294,7 +4333,7 @@ static SANE_Status accurate_line_read(Genesys_Device * dev, * must be read and bytes interleaved to get usable by the other stages * of the backend */ -static SANE_Status +static SANE_Status genesys_fill_line_interp_buffer (Genesys_Device * dev, uint8_t *work_buffer_dst, size_t size) { size_t count; @@ -4313,7 +4352,7 @@ genesys_fill_line_interp_buffer (Genesys_Device * dev, uint8_t *work_buffer_dst, } } - /* copy size bytes of data, copying from a line when line count matches */ + /* copy size bytes of data, copying from a line when line count matches */ count = 0; while (count < size) { @@ -4344,7 +4383,7 @@ genesys_fill_line_interp_buffer (Genesys_Device * dev, uint8_t *work_buffer_dst, if (status != SANE_STATUS_GOOD) { DBG (DBG_error, - "%s: failed to read %lu bytes (%s)\n", __FUNCTION__, + "%s: failed to read %lu bytes (%s)\n", __FUNCTION__, (u_long) dev->oe_buffer.size, sane_strstatus (status)); return SANE_STATUS_IO_ERROR; } @@ -4356,17 +4395,17 @@ genesys_fill_line_interp_buffer (Genesys_Device * dev, uint8_t *work_buffer_dst, /** @brief fill buffer for segmented sensors * This function fills a read buffer with scanned data from a sensor segmented - * in several parts (multi-lines sensors). Data of the same valid area is read + * in several parts (multi-lines sensors). Data of the same valid area is read * back to back and must be interleaved to get usable by the other stages * of the backend */ -static SANE_Status +static SANE_Status genesys_fill_segmented_buffer (Genesys_Device * dev, uint8_t *work_buffer_dst, size_t size) { size_t count; SANE_Status status; int depth,i,n,k; - + depth = dev->settings.depth; if (dev->settings.scan_mode == SCAN_MODE_LINEART && dev->settings.dynamic_lineart==SANE_FALSE) depth = 1; @@ -4397,12 +4436,12 @@ genesys_fill_segmented_buffer (Genesys_Device * dev, uint8_t *work_buffer_dst, s count++; dev->cur++; } - else + else { if(depth==1) { while (dev->cur < dev->len && count < size) - { + { for(n=0;n<dev->segnb;n++) { work_buffer_dst[count+n] = 0; @@ -4429,7 +4468,7 @@ genesys_fill_segmented_buffer (Genesys_Device * dev, uint8_t *work_buffer_dst, s if(depth==8) { while (dev->cur < dev->len && count < size) - { + { for(n=0;n<dev->segnb;n++) { work_buffer_dst[count+n] = dev->oe_buffer.buffer[dev->cur + dev->skip + dev->dist*dev->order[n] + dev->oe_buffer.pos]; @@ -4442,7 +4481,7 @@ genesys_fill_segmented_buffer (Genesys_Device * dev, uint8_t *work_buffer_dst, s if(depth==16) { while (dev->cur < dev->len && count < size) - { + { for(n=0;n<dev->segnb;n++) { work_buffer_dst[count+n*2] = dev->oe_buffer.buffer[dev->cur + dev->skip + dev->dist*dev->order[n] + dev->oe_buffer.pos]; @@ -4469,7 +4508,7 @@ genesys_fill_segmented_buffer (Genesys_Device * dev, uint8_t *work_buffer_dst, s if (status != SANE_STATUS_GOOD) { DBG (DBG_error, - "%s: failed to read %lu bytes (%s)\n", __FUNCTION__, + "%s: failed to read %lu bytes (%s)\n", __FUNCTION__, (u_long) dev->oe_buffer.size, sane_strstatus (status)); return SANE_STATUS_IO_ERROR; } @@ -4508,7 +4547,7 @@ genesys_fill_read_buffer (Genesys_Device * dev) size = space; - /* never read an odd number. exception: last read + /* never read an odd number. exception: last read the chip internal counter does not count half words. */ size &= ~1; /* Some setups need the reads to be multiples of 256 bytes */ @@ -4536,10 +4575,10 @@ genesys_fill_read_buffer (Genesys_Device * dev) * may have to be read from another intermediate buffer and then processed. * There are currently 3 intermediate stages: * - handling of odd/even sensors - * - handling of line interpolation for motors that can't have low + * - handling of line interpolation for motors that can't have low * enough dpi * - handling of multi-segments sensors - * + * * This is also the place where full duplex data will be handled. */ if (dev->line_interp>0) @@ -4576,8 +4615,8 @@ genesys_fill_read_buffer (Genesys_Device * dev) return SANE_STATUS_GOOD; } -/* this function does the effective data read in a manner that suits - the scanner. It does data reordering and resizing if need. +/* this function does the effective data read in a manner that suits + the scanner. It does data reordering and resizing if need. It also manages EOF and I/O errors, and line distance correction. */ static SANE_Status @@ -4736,14 +4775,14 @@ genesys_read_ordered_data (Genesys_Device * dev, SANE_Byte * destination, -------------- out_buffer ----------------------- 4. memcpy to destination (for lineart with bit reversal) */ -/*FIXME: for lineart we need sub byte addressing in buffers, or conversion to +/*FIXME: for lineart we need sub byte addressing in buffers, or conversion to bytes at 0. and back to bits at 4. Problems with the first approach: - its not clear how to check if we need to output an incomplete byte because it is the last one. */ -/*FIXME: add lineart support for gl646. in the meantime add logic to convert - from gray to lineart at the end? would suffer the above problem, +/*FIXME: add lineart support for gl646. in the meantime add logic to convert + from gray to lineart at the end? would suffer the above problem, total_bytes_to_read and total_bytes_read help in that case. */ @@ -5061,7 +5100,7 @@ Problems with the first approach: dev->total_bytes_read += *len; RIE (sanei_genesys_buffer_consume (src_buffer, bytes)); - + /* end scan if all needed data have been read */ if(dev->total_bytes_read >= dev->total_bytes_to_read) { @@ -5149,11 +5188,11 @@ calc_parameters (Genesys_Scanner * s) /* we need an even pixels number * TODO invert test logic or generalize behaviour across all ASICs */ if ((s->dev->model->flags & GENESYS_FLAG_SIS_SENSOR) - || s->dev->model->asic_type == GENESYS_GL847 - || s->dev->model->asic_type == GENESYS_GL124 - || s->dev->model->asic_type == GENESYS_GL845 - || s->dev->model->asic_type == GENESYS_GL846 - || s->dev->model->asic_type == GENESYS_GL843) + || s->dev->model->asic_type == GENESYS_GL847 + || s->dev->model->asic_type == GENESYS_GL124 + || s->dev->model->asic_type == GENESYS_GL845 + || s->dev->model->asic_type == GENESYS_GL846 + || s->dev->model->asic_type == GENESYS_GL843) { if (s->dev->settings.xres <= 1200) s->params.pixels_per_line = (s->params.pixels_per_line/4)*4; @@ -5164,7 +5203,7 @@ calc_parameters (Genesys_Scanner * s) /* corner case for true lineart for sensor with several segments * or when xres is doubled to match yres */ if (s->dev->settings.xres >= 1200 - && ( s->dev->model->asic_type == GENESYS_GL124 + && ( s->dev->model->asic_type == GENESYS_GL124 || s->dev->model->asic_type == GENESYS_GL847 || s->dev->current_setup.xres < s->dev->current_setup.yres ) @@ -5182,7 +5221,7 @@ calc_parameters (Genesys_Scanner * s) else if (s->params.depth == 1) { s->params.bytes_per_line /= 8; - /* round down pixel number + /* round down pixel number really? rounding down means loss of at most 7 pixels! -- pierre */ s->params.pixels_per_line = 8 * s->params.bytes_per_line; } @@ -5241,21 +5280,21 @@ calc_parameters (Genesys_Scanner * s) /* hardware lineart works only when we don't have interleave data * for GL847 scanners, ie up to 600 DPI, then we have to rely on * dynamic_lineart */ - if(s->dev->settings.xres > 600 + if(s->dev->settings.xres > 600 && s->dev->model->asic_type==GENESYS_GL847 && s->dev->settings.scan_mode == SCAN_MODE_LINEART) { s->dev->settings.dynamic_lineart = SANE_TRUE; } - + /* threshold curve for dynamic rasterization */ s->dev->settings.threshold_curve=s->val[OPT_THRESHOLD_CURVE].w; /* some digital processing requires the whole picture to be buffered */ /* no digital processing takes place when doing preview, or when bit depth is * higher than 8 bits */ - if ((s->val[OPT_SWDESPECK].b - || s->val[OPT_SWCROP].b + if ((s->val[OPT_SWDESPECK].b + || s->val[OPT_SWCROP].b || s->val[OPT_SWDESKEW].b || s->val[OPT_SWDEROTATE].b ||(SANE_UNFIX(s->val[OPT_SWSKIP].w)>0)) @@ -5281,6 +5320,9 @@ calc_parameters (Genesys_Scanner * s) s->dev->settings.brightness=0; } + /* cache expiration time */ + s->dev->settings.expiration_time=s->val[OPT_EXPIRATION_TIME].w; + return status; } @@ -5339,7 +5381,7 @@ init_gamma_vector_option (Genesys_Scanner * scanner, int option) scanner->val[option].wa = NULL; } -/** +/** * allocate a geometry range * @param size maximum size of the range * @return a pointer to a valid range or NULL @@ -5358,6 +5400,107 @@ SANE_Range *range=NULL; return range; } +/** @brief generate calibration cache file nam + * Generates the calibration cache file name to use. + * Tries to store the chache in $HOME/.sane or + * then fallbacks to $TMPDIR or TMP. The filename + * uses the model name if only one scanner is plugged + * else is uses the device name when several identical + * scanners are in use. + * @param currdev current scanner device + * @return an allocated string containing a file name + */ +GENESYS_STATIC char *calibration_filename(Genesys_Device *currdev) +{ + char *tmpstr; + char *ptr; + char filename[80]; + Genesys_Device *dev; + unsigned int count; + unsigned int i; + + /* allocate space for result */ + tmpstr=malloc(PATH_MAX); + if(tmpstr==NULL) + { + return NULL; + } + + /* first compute the DIR where we can store cache: + * 1 - home dir + * 2 - $TMPDIR + * 3 - $TMP + * 4 - tmp dir + * 5 - temp dir + * 6 - then resort to current dir + */ + ptr = getenv ("HOME"); + if(ptr==NULL) + { + ptr = getenv ("USERPROFILE"); + } + if(ptr==NULL) + { + ptr = getenv ("TMPDIR"); + } + if(ptr==NULL) + { + ptr = getenv ("TMP"); + } + + /* now choose filename: + * 1 - if only one scanner, name of the model + * 2 - if several scanners of the same model, use device name, + * replacing special chars + */ + count=0; + /* count models of the same names if several scanners attached */ + if(num_devices>1) + { + for (dev = first_dev; dev; dev = dev->next) + { + if(strcmp(dev->model->name,currdev->model->name)==0) + { + count++; + } + } + } + if(count>1) + { + snprintf(filename,sizeof(filename),"%s.cal",currdev->file_name); + for(i=0;i<strlen(filename);i++) + { + if(filename[i]==':'||filename[i]==PATH_SEP) + { + filename[i]='_'; + } + } + } + else + { + snprintf(filename,sizeof(filename),"%s.cal",currdev->model->name); + } + + /* build final final name : store dir + filename */ + if (NULL == ptr) + { + snprintf (tmpstr, PATH_MAX, "%s", filename); + } + else + { +#ifdef HAVE_MKDIR + /* make sure .sane directory exists in existing store dir */ + snprintf (tmpstr, PATH_MAX, "%s%c.sane", ptr, PATH_SEP); + mkdir(tmpstr,0700); +#endif + snprintf (tmpstr, PATH_MAX, "%s%c.sane%c%s", ptr, PATH_SEP, PATH_SEP, filename); + } + + DBG (DBG_info, "%s: calibration filename >%s<\n", __FUNCTION__, tmpstr); + + return tmpstr; +} + static SANE_Status init_options (Genesys_Scanner * s) @@ -5412,13 +5555,13 @@ init_options (Genesys_Scanner * s) s->opt[OPT_SOURCE].size = max_string_size (source_list); s->opt[OPT_SOURCE].constraint.string_list = source_list; s->val[OPT_SOURCE].s = strdup (FLATBED); - if (!(model->flags & GENESYS_FLAG_HAS_UTA)) + if (model->flags & GENESYS_FLAG_HAS_UTA) { - DISABLE (OPT_SOURCE); + ENABLE (OPT_SOURCE); } else { - ENABLE (OPT_SOURCE); + DISABLE (OPT_SOURCE); } /* preview */ @@ -5578,7 +5721,7 @@ init_options (Genesys_Scanner * s) DBG (DBG_info, "init_options: custom gamma disabled\n"); } - /* software base image enhancements, these are consuming as many + /* software base image enhancements, these are consuming as many * memory than used by the full scanned image and may fail at high * resolution */ @@ -5589,7 +5732,7 @@ init_options (Genesys_Scanner * s) s->opt[OPT_SWDESKEW].type = SANE_TYPE_BOOL; s->opt[OPT_SWDESKEW].cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED; s->val[OPT_SWDESKEW].b = SANE_FALSE; - + /* software deskew */ s->opt[OPT_SWDESPECK].name = "swdespeck"; s->opt[OPT_SWDESPECK].title = "Software despeck"; @@ -5606,7 +5749,7 @@ init_options (Genesys_Scanner * s) s->opt[OPT_DESPECK].unit = SANE_UNIT_NONE; s->opt[OPT_DESPECK].constraint_type = SANE_CONSTRAINT_RANGE; s->opt[OPT_DESPECK].constraint.range = &swdespeck_range; - s->opt[OPT_DESPECK].cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED; + s->opt[OPT_DESPECK].cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED | SANE_CAP_INACTIVE; s->val[OPT_DESPECK].w = 1; /* crop by software */ @@ -5680,7 +5823,7 @@ init_options (Genesys_Scanner * s) s->opt[OPT_THRESHOLD].constraint_type = SANE_CONSTRAINT_RANGE; s->opt[OPT_THRESHOLD].constraint.range = &percentage_range; s->val[OPT_THRESHOLD].w = SANE_FIX (50); - + /* BW threshold curve */ s->opt[OPT_THRESHOLD_CURVE].name = "threshold-curve"; s->opt[OPT_THRESHOLD_CURVE].title = SANE_I18N ("Threshold curve"); @@ -5690,7 +5833,7 @@ init_options (Genesys_Scanner * s) s->opt[OPT_THRESHOLD_CURVE].constraint_type = SANE_CONSTRAINT_RANGE; s->opt[OPT_THRESHOLD_CURVE].constraint.range = &threshold_curve_range; s->val[OPT_THRESHOLD_CURVE].w = 50; - + /* dynamic linart */ s->opt[OPT_DISABLE_DYNAMIC_LINEART].name = "disable-dynamic-lineart"; s->opt[OPT_DISABLE_DYNAMIC_LINEART].title = SANE_I18N ("Disable dynamic lineart"); @@ -5768,6 +5911,17 @@ init_options (Genesys_Scanner * s) } #endif + /* expiration time for calibration cache entries */ + s->opt[OPT_EXPIRATION_TIME].name = "expiration-time"; + s->opt[OPT_EXPIRATION_TIME].title = SANE_I18N ("Calibration cache expiration time"); + s->opt[OPT_EXPIRATION_TIME].desc = SANE_I18N ("Time (in minutes) before a cached calibration expires. " + "A value of 0 means cache is not used. A negative value means cache never expires."); + s->opt[OPT_EXPIRATION_TIME].type = SANE_TYPE_INT; + s->opt[OPT_EXPIRATION_TIME].unit = SANE_UNIT_NONE; + s->opt[OPT_EXPIRATION_TIME].constraint_type = SANE_CONSTRAINT_RANGE; + s->opt[OPT_EXPIRATION_TIME].constraint.range = &expiration_range; + s->val[OPT_EXPIRATION_TIME].w = 60; /* 60 minutes by default */ + /* Powersave time (turn lamp off) */ s->opt[OPT_LAMP_OFF_TIME].name = "lamp-off-time"; s->opt[OPT_LAMP_OFF_TIME].title = SANE_I18N ("Lamp off time"); @@ -5890,7 +6044,7 @@ init_options (Genesys_Scanner * s) s->opt[OPT_POWER_SW].cap = SANE_CAP_INACTIVE; s->val[OPT_POWER_SW].b = 0; s->last_val[OPT_POWER_SW].b = 0; - + /* extra button */ s->opt[OPT_EXTRA_SW].name = "extra"; s->opt[OPT_EXTRA_SW].title = SANE_I18N ("Extra button"); @@ -5971,13 +6125,24 @@ check_present (SANE_String_Const devname) return SANE_STATUS_GOOD; } +/** @brief add a scanner device + * Insert the given device into the backend list of devices. + * @param dev device to add + */ +GENESYS_STATIC void add_device(Genesys_Device *dev) +{ + ++num_devices; + dev->next = first_dev; + first_dev = dev; +} + static SANE_Status attach (SANE_String_Const devname, Genesys_Device ** devp, SANE_Bool may_wait) { Genesys_Device *dev = 0; SANE_Int dn, vendor, product; SANE_Status status; - int i; + unsigned int i; DBG (DBG_proc, "attach: start: devp %s NULL, may_wait = %d\n", @@ -6061,7 +6226,10 @@ attach (SANE_String_Const devname, Genesys_Device ** devp, SANE_Bool may_wait) dev->file_name = strdup (devname); if (!dev->file_name) - return SANE_STATUS_NO_MEM; + { + free(dev); + return SANE_STATUS_NO_MEM; + } dev->model = genesys_usb_device_list[i].model; dev->vendorId = genesys_usb_device_list[i].vendor; @@ -6070,9 +6238,7 @@ attach (SANE_String_Const devname, Genesys_Device ** devp, SANE_Bool may_wait) DBG (DBG_info, "attach: found %s flatbed scanner %s at %s\n", dev->model->vendor, dev->model->model, dev->file_name); - ++num_devices; - dev->next = first_dev; - first_dev = dev; + add_device(dev); if (devp) *devp = dev; @@ -6125,8 +6291,8 @@ attach_one_device (SANE_String_Const devname) static SANE_Status config_attach_genesys (SANEI_Config __sane_unused__ *config, const char *devname) { - /* the devname has been processed and is ready to be used - * directly. Since the backend is an USB only one, we can + /* the devname has been processed and is ready to be used + * directly. Since the backend is an USB only one, we can * call sanei_usb_attach_matching_devices straight */ sanei_usb_attach_matching_devices (devname, attach_one_device); @@ -6164,15 +6330,17 @@ probe_genesys_devices (void) free (new_dev); } + DBG(DBG_info, "%s: %d devices currently attached\n", __FUNCTION__, num_devices); + DBGCOMPLETED; return status; } /** - * This should be changed if one of the substructures of + * This should be changed if one of the substructures of Genesys_Calibration_Cache change, but it must be changed if there are - changes that don't change size -- at least for now, as we store most + changes that don't change size -- at least for now, as we store most of Genesys_Calibration_Cache as is. */ #define CALIBRATION_VERSION 1 @@ -6630,7 +6798,7 @@ sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only) first_dev = dev->next; num_devices--; free (dev); - dev = prev->next; + dev = first_dev; } } /* case 2 : removed device is not first_dev */ @@ -6661,8 +6829,7 @@ sane_open (SANE_String_Const devicename, SANE_Handle * handle) Genesys_Device *dev; SANE_Status status; Genesys_Scanner *s; - char tmp_str[PATH_MAX]; - char *ptr; + char *tmpstr; DBG (DBG_proc, "sane_open: start (devicename = `%s')\n", devicename); @@ -6768,37 +6935,16 @@ sane_open (SANE_String_Const devicename, SANE_Handle * handle) RIE (dev->model->cmd_set->init (dev)); - /* here is the place to fetch a stored calibration cache */ + /* some hardware capabilities are detected through sensors */ + RIE (s->dev->model->cmd_set->update_hardware_sensors (s)); - /* create calibration-filename - lifted from plustek-usb.c - */ - /* we should add a unique identifying feature to the file name - to support multiple scanners of the same model, but to my - knowledge, there is no such thing in these scanners. - (At least the usb serial is always "0".) - TODO add an storedir option to genesys.conf - */ - - ptr = getenv ("HOME"); - if (NULL == ptr) - { - sprintf (tmp_str, "/tmp/%s.cal", s->dev->model->name); - } - else - { -#ifdef HAVE_MKDIR - /* make sure .sane directory exists */ - sprintf (tmp_str, "%s/.sane", ptr); - mkdir(tmp_str,0700); -#endif - sprintf (tmp_str, "%s/.sane/%s.cal", ptr, s->dev->model->name); - } - - s->val[OPT_CALIBRATION_FILE].s = strdup (tmp_str); - s->dev->calib_file = strdup (tmp_str); - DBG (DBG_info, "Calibration filename set to:\n"); - DBG (DBG_info, ">%s<\n", s->dev->calib_file); + /* here is the place to fetch a stored calibration cache */ + tmpstr=calibration_filename(s->dev); + s->val[OPT_CALIBRATION_FILE].s = strdup (tmpstr); + s->dev->calib_file = strdup (tmpstr); + DBG (DBG_info, "%s: Calibration filename set to:\n", __FUNCTION__); + DBG (DBG_info, "%s: >%s<\n", __FUNCTION__, s->dev->calib_file); + free(tmpstr); /* now open file, fetch calibration records */ @@ -6860,7 +7006,7 @@ sane_close (SANE_Handle handle) "sane_close: failed to enable power saving mode: %s\n", sane_strstatus (status)); } - + /* here is the place to store calibration cache */ write_calibration (s->dev); @@ -6903,13 +7049,12 @@ sane_close (SANE_Handle handle) /* LAMP OFF : same register across all the ASICs */ sanei_genesys_write_register (s->dev, 0x03, 0x00); - /* we need this to avoid ASIC getting stuck + /* clear before closing */ + sanei_usb_clear_halt (s->dev->dn); + + /* we need this to avoid these ASIC getting stuck * in bulk writes */ - if(s->dev->model->asic_type==GENESYS_GL847 - ||s->dev->model->asic_type==GENESYS_GL845 - ||s->dev->model->asic_type==GENESYS_GL845 - ||s->dev->model->asic_type==GENESYS_GL843) - sanei_usb_reset (s->dev->dn); + sanei_usb_reset (s->dev->dn); sanei_usb_close (s->dev->dn); free (s); @@ -7075,37 +7220,35 @@ static SANE_Status set_calibration_value (Genesys_Scanner * s, int option, void { SANE_Status status=SANE_STATUS_GOOD; char *tmp; - Genesys_Calibration_Cache *cache; Genesys_Device *dev=s->dev; + DBGSTART; + /* try to load file */ tmp=dev->calib_file; dev->calib_file=val; status=sanei_genesys_read_calibration (dev); - - /* file exists but is invalid */ + + /* file exists but is invalid, so fall back to previous cache file + * an re-read it */ if (status!=SANE_STATUS_IO_ERROR && status!=SANE_STATUS_GOOD) { dev->calib_file=tmp; + status=sanei_genesys_read_calibration (dev); return status; } - /* we can set no file name value */ + /* now we can set file name value */ if (s->val[option].s) free (s->val[option].s); s->val[option].s = strdup (val); if (tmp) free (tmp); dev->calib_file = strdup (val); + DBG (DBG_info, "%s: Calibration filename set to:\n", __FUNCTION__); + DBG (DBG_info, "%s: >%s<\n", __FUNCTION__, s->dev->calib_file); - /* clear device calibration cache */ - while(dev->calibration_cache!=NULL) - { - cache=dev->calibration_cache; - dev->calibration_cache=dev->calibration_cache->next; - free(cache); - } - + DBGCOMPLETED; return SANE_STATUS_GOOD; } @@ -7300,6 +7443,7 @@ set_option_value (Genesys_Scanner * s, int option, void *val, RIE(set_calibration_value (s, option, val)); break; case OPT_LAMP_OFF_TIME: + case OPT_EXPIRATION_TIME: if (*(SANE_Word *) val != s->val[option].w) { s->val[option].w = *(SANE_Word *) val; @@ -7617,27 +7761,27 @@ sane_start (SANE_Handle handle) return status; } } - + /* deskew image if required */ if(s->val[OPT_SWDESKEW].b == SANE_TRUE) { RIE(genesys_deskew(s)); } - + /* despeck image if required */ if(s->val[OPT_SWDESPECK].b == SANE_TRUE) { RIE(genesys_despeck(s)); } - + /* crop image if required */ - if(s->val[OPT_SWCROP].b == SANE_TRUE) + if(s->val[OPT_SWCROP].b == SANE_TRUE) { RIE(genesys_crop(s)); } - + /* de-rotate image if required */ - if(s->val[OPT_SWDEROTATE].b == SANE_TRUE) + if(s->val[OPT_SWDEROTATE].b == SANE_TRUE) { RIE(genesys_derotate(s)); } @@ -7661,7 +7805,7 @@ sane_read (SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, DBG (DBG_error, "sane_read: handle is null!\n"); return SANE_STATUS_INVAL; } - + dev=s->dev; if (!dev) { @@ -7694,7 +7838,7 @@ sane_read (SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, DBG (DBG_io2, "sane_read: bytes_to_read=%lu, total_bytes_read=%lu\n", (u_long) dev->total_bytes_to_read, (u_long) dev->total_bytes_read); DBG (DBG_io2, "sane_read: physical bytes to read = %lu\n", (u_long) dev->read_bytes_left); - + if(dev->total_bytes_read>=dev->total_bytes_to_read) { DBG (DBG_proc, "sane_read: nothing more to scan: EOF\n"); @@ -7776,11 +7920,11 @@ sane_read (SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, *len = local_len; if(local_len>(size_t)max_len) { - fprintf (stderr, "[genesys] sane_read: returning incorrect length!!\n"); + fprintf (stderr, "[genesys] sane_read: returning incorrect length!!\n"); } DBG (DBG_proc, "sane_read: %d bytes returned\n", *len); return status; -} +} void sane_cancel (SANE_Handle handle) diff --git a/backend/genesys.conf.in b/backend/genesys.conf.in index 58cb351..7899455 100644 --- a/backend/genesys.conf.in +++ b/backend/genesys.conf.in @@ -36,6 +36,9 @@ usb 0x04a9 0x2213 # Canon LiDE 60 usb 0x04a9 0x221c +# Canon LiDE 80 +usb 0x04a9 0x2214 + # Canon 4400F usb 0x04a9 0x2228 @@ -57,6 +60,12 @@ usb 0x04a9 0x1907 # Canon LiDE 210 usb 0x04a9 0x190a +# Canon LiDE 120 +usb 0x04a9 0x190e + +# Canon LiDE 220 +usb 0x04a9 0x190f + # Canon 5600f usb 0x04a9 0x1906 diff --git a/backend/genesys.h b/backend/genesys.h index 4d5fd94..eab92bb 100644 --- a/backend/genesys.h +++ b/backend/genesys.h @@ -4,44 +4,44 @@ Copyright (C) 2005-2013 Stephane Voltz <stef.dev@free.fr> Copyright (C) 2006 Laurent Charpentier <laurent_pubs@yahoo.com> Copyright (C) 2009 Pierre Willenbrock <pierre@pirsoft.dnsalias.org> - + This file is part of the SANE package. - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - + As a special exception, the authors of SANE give permission for additional uses of the libraries contained in this release of SANE. - + The exception is that, if you link a SANE library with other files to produce an executable, this does not by itself cause the resulting executable to be covered by the GNU General Public License. Your use of that executable is in no way restricted on account of linking the SANE library code into it. - + This exception does not, however, invalidate any other reasons why the executable file might be covered by the GNU General Public License. - + If you submit changes to SANE to the maintainers to be included in a subsequent release, you agree by submitting the changes that those changes may be distributed with this exception intact. - + If you write modifications of your own for SANE, it is your choice whether to permit this exception to apply to your modifications. - If you do not wish that, delete this exception notice. + If you do not wish that, delete this exception notice. */ #ifndef GENESYS_H @@ -49,6 +49,16 @@ #include "genesys_low.h" +#ifndef PATH_MAX +# define PATH_MAX 1024 +#endif + +#if defined(_WIN32) || defined(HAVE_OS2_H) +# define PATH_SEP '\\' +#else +# define PATH_SEP '/' +#endif + #define ENABLE(OPTION) s->opt[OPTION].cap &= ~SANE_CAP_INACTIVE #define DISABLE(OPTION) s->opt[OPTION].cap |= SANE_CAP_INACTIVE @@ -110,6 +120,7 @@ enum Genesys_Option OPT_DISABLE_INTERPOLATION, OPT_COLOR_FILTER, OPT_CALIBRATION_FILE, + OPT_EXPIRATION_TIME, OPT_SENSOR_GROUP, OPT_SCAN_SW, @@ -146,4 +157,9 @@ typedef struct Genesys_Scanner SANE_Int bpp_list[5]; /**< */ } Genesys_Scanner; +#ifdef UNIT_TESTING +SANE_Status genesys_dark_white_shading_calibration (Genesys_Device * dev); +char *calibration_filename(Genesys_Device *currdev); +void add_device(Genesys_Device *dev); +#endif #endif /* not GENESYS_H */ diff --git a/backend/genesys_conv.c b/backend/genesys_conv.c index 61ac782..0346ad6 100644 --- a/backend/genesys_conv.c +++ b/backend/genesys_conv.c @@ -4,42 +4,42 @@ Copyright (C) 2010-2013 Stphane Voltz <stef.dev@free.fr> This file is part of the SANE package. - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - + As a special exception, the authors of SANE give permission for additional uses of the libraries contained in this release of SANE. - + The exception is that, if you link a SANE library with other files to produce an executable, this does not by itself cause the resulting executable to be covered by the GNU General Public License. Your use of that executable is in no way restricted on account of linking the SANE library code into it. - + This exception does not, however, invalidate any other reasons why the executable file might be covered by the GNU General Public License. - + If you submit changes to SANE to the maintainers to be included in a subsequent release, you agree by submitting the changes that those changes may be distributed with this exception intact. If you write modifications of your own for SANE, it is your choice whether to permit this exception to apply to your modifications. - If you do not wish that, delete this exception notice. + If you do not wish that, delete this exception notice. */ /* @@ -79,9 +79,9 @@ static SANE_Status genesys_reverse_bits( - uint8_t *src_data, - uint8_t *dst_data, - size_t bytes) + uint8_t *src_data, + uint8_t *dst_data, + size_t bytes) { size_t i; for(i = 0; i < bytes; i++) { @@ -105,7 +105,7 @@ binarize_line(Genesys_Device * dev, uint8_t *src, uint8_t *dst, int width) int thresh; int offset, addCol, dropCol; unsigned char mask; - + int x; uint8_t min, max; @@ -186,8 +186,8 @@ binarize_line(Genesys_Device * dev, uint8_t *src, uint8_t *dst, int width) static SANE_Status genesys_gray_lineart( Genesys_Device *dev, - uint8_t *src_data, - uint8_t *dst_data, + uint8_t *src_data, + uint8_t *dst_data, size_t pixels, size_t lines, uint8_t threshold) @@ -211,14 +211,14 @@ genesys_gray_lineart( * or grows it in case it is the opposite like when motor resolution is higher than * sensor's one. */ -static SANE_Status +static SANE_Status genesys_shrink_lines_1 ( - uint8_t *src_data, - uint8_t *dst_data, - unsigned int lines, + uint8_t *src_data, + uint8_t *dst_data, + unsigned int lines, unsigned int src_pixels, - unsigned int dst_pixels, - unsigned int channels) + unsigned int dst_pixels, + unsigned int channels) { unsigned int dst_x, src_x, y, c, cnt; unsigned int avg[3], val; @@ -383,7 +383,7 @@ genesys_deskew(Genesys_Scanner *s) double slope = 0; DBG (DBG_proc, "%s: start\n", __FUNCTION__); - + bg=0; if(s->params.format==SANE_FRAME_GRAY && s->params.depth == 1) { @@ -402,7 +402,7 @@ genesys_deskew(Genesys_Scanner *s) return SANE_STATUS_GOOD; } DBG(DBG_info, "%s: slope=%f => %f\n",__FUNCTION__,slope, (slope/M_PI_2)*90); - /* rotate image slope is in [-PI/2,PI/2] + /* rotate image slope is in [-PI/2,PI/2] * positive values rotate trigonometric direction wise */ status = sanei_magic_rotate (&s->params, dev->img_buffer, diff --git a/backend/genesys_conv_hlp.c b/backend/genesys_conv_hlp.c index cae4116..7663a87 100644 --- a/backend/genesys_conv_hlp.c +++ b/backend/genesys_conv_hlp.c @@ -3,54 +3,54 @@ Copyright (C) 2005 Pierre Willenbrock <pierre@pirsoft.dnsalias.org> This file is part of the SANE package. - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - + As a special exception, the authors of SANE give permission for additional uses of the libraries contained in this release of SANE. - + The exception is that, if you link a SANE library with other files to produce an executable, this does not by itself cause the resulting executable to be covered by the GNU General Public License. Your use of that executable is in no way restricted on account of linking the SANE library code into it. - + This exception does not, however, invalidate any other reasons why the executable file might be covered by the GNU General Public License. - + If you submit changes to SANE to the maintainers to be included in a subsequent release, you agree by submitting the changes that those changes may be distributed with this exception intact. If you write modifications of your own for SANE, it is your choice whether to permit this exception to apply to your modifications. - If you do not wish that, delete this exception notice. + If you do not wish that, delete this exception notice. */ /* * Conversion filters for genesys backend */ -static SANE_Status +static SANE_Status FUNC_NAME(genesys_reorder_components_cis) ( - uint8_t *src_data, - uint8_t *dst_data, - unsigned int lines, - unsigned int pixels) + uint8_t *src_data, + uint8_t *dst_data, + unsigned int lines, + unsigned int pixels) { unsigned int x, y; uint8_t *src[3]; @@ -97,12 +97,12 @@ FUNC_NAME(genesys_reorder_components_cis) ( return SANE_STATUS_GOOD; } -static SANE_Status +static SANE_Status FUNC_NAME(genesys_reorder_components_cis_bgr) ( - uint8_t *src_data, - uint8_t *dst_data, - unsigned int lines, - unsigned int pixels) + uint8_t *src_data, + uint8_t *dst_data, + unsigned int lines, + unsigned int pixels) { unsigned int x, y; uint8_t *src[3]; @@ -148,12 +148,12 @@ FUNC_NAME(genesys_reorder_components_cis_bgr) ( return SANE_STATUS_GOOD; } -static SANE_Status +static SANE_Status FUNC_NAME(genesys_reorder_components_bgr) ( - uint8_t *src_data, - uint8_t *dst_data, - unsigned int lines, - unsigned int pixels) + uint8_t *src_data, + uint8_t *dst_data, + unsigned int lines, + unsigned int pixels) { unsigned int c; uint8_t *src = src_data; @@ -190,13 +190,13 @@ FUNC_NAME(genesys_reorder_components_bgr) ( } #if defined(DOUBLE_BYTE) && defined(WORDS_BIGENDIAN) -static SANE_Status +static SANE_Status FUNC_NAME(genesys_reorder_components_endian) ( - uint8_t *src_data, - uint8_t *dst_data, - unsigned int lines, + uint8_t *src_data, + uint8_t *dst_data, + unsigned int lines, unsigned int pixels, - unsigned int channels) + unsigned int channels) { unsigned int c; uint8_t *src = src_data; @@ -212,14 +212,14 @@ return SANE_STATUS_GOOD; #endif /*defined(DOUBLE_BYTE) && defined(WORDS_BIGENDIAN)*/ -static SANE_Status +static SANE_Status FUNC_NAME(genesys_reverse_ccd) ( - uint8_t *src_data, - uint8_t *dst_data, - unsigned int lines, + uint8_t *src_data, + uint8_t *dst_data, + unsigned int lines, unsigned int components_per_line, unsigned int *ccd_shift, - unsigned int component_count) + unsigned int component_count) { unsigned int x, y, c; COMPONENT_TYPE *src = (COMPONENT_TYPE *)src_data; @@ -229,8 +229,8 @@ FUNC_NAME(genesys_reverse_ccd) ( unsigned int pitch = components_per_line; unsigned int ccd_shift_pitch[12]; unsigned int *csp; - - for (c = 0; c < component_count; c++) + + for (c = 0; c < component_count; c++) ccd_shift_pitch[c] = ccd_shift[c] * pitch; /* @@ -239,7 +239,7 @@ FUNC_NAME(genesys_reverse_ccd) ( into the cpu cache for maximum efficiency. our lines take maximum 252kb(3 channels, 16bit, 2400dpi, full gl841 shading range) * instruction efficiency: - the innermost loop runs long and consists of 3 adds, one compare, + the innermost loop runs long and consists of 3 adds, one compare, 2 derefences. */ /* @@ -258,7 +258,7 @@ FUNC_NAME(genesys_reverse_ccd) ( src += pitch; } */ -/* +/* * cache efficency: here only line_dist_pitch needs to stay in cache. 12*4 = 48 bytes * instruction efficiency: @@ -281,14 +281,14 @@ FUNC_NAME(genesys_reverse_ccd) ( return SANE_STATUS_GOOD; } -static SANE_Status +static SANE_Status FUNC_NAME(genesys_shrink_lines) ( - uint8_t *src_data, - uint8_t *dst_data, - unsigned int lines, + uint8_t *src_data, + uint8_t *dst_data, + unsigned int lines, unsigned int src_pixels, - unsigned int dst_pixels, - unsigned int channels) + unsigned int dst_pixels, + unsigned int channels) { unsigned int dst_x, src_x, y, c, cnt; unsigned int avg[3]; @@ -329,11 +329,11 @@ FUNC_NAME(genesys_shrink_lines) ( for (src_x = 0; src_x < src_pixels; src_x++) { for (c = 0; c < channels; c++) avg[c] = *src++; - while ((cnt < dst_pixels || src_x + 1 == src_pixels) && + while ((cnt < dst_pixels || src_x + 1 == src_pixels) && dst_x < dst_pixels) { cnt += src_pixels; - for (c = 0; c < channels; c++) + for (c = 0; c < channels; c++) *dst++ = avg[c]; dst_x++; } diff --git a/backend/genesys_devices.c b/backend/genesys_devices.c index fb3cd43..775ffb6 100644 --- a/backend/genesys_devices.c +++ b/backend/genesys_devices.c @@ -11,44 +11,44 @@ xerox travelscan device entry Copyright (C) 2010 Chris Berry <s0457957@sms.ed.ac.uk> and Michael Rickmann <mrickma@gwdg.de> for Plustek Opticbook 3600 support - + This file is part of the SANE package. - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - + As a special exception, the authors of SANE give permission for additional uses of the libraries contained in this release of SANE. - + The exception is that, if you link a SANE library with other files to produce an executable, this does not by itself cause the resulting executable to be covered by the GNU General Public License. Your use of that executable is in no way restricted on account of linking the SANE library code into it. - + This exception does not, however, invalidate any other reasons why the executable file might be covered by the GNU General Public License. - + If you submit changes to SANE to the maintainers to be included in a subsequent release, you agree by submitting the changes that those changes may be distributed with this exception intact. - + If you write modifications of your own for SANE, it is your choice whether to permit this exception to apply to your modifications. - If you do not wish that, delete this exception notice. + If you do not wish that, delete this exception notice. */ /* ------------------------------------------------------------------------ */ @@ -81,7 +81,7 @@ static Genesys_Frontend Wolfson[] = { , /* 2: ST24 */ {DAC_WOLFSON_5345,{0x00, 0x03, 0x05, 0x12} , {0x00, 0x00, 0x00} - , {0xb8, 0xb8, 0xb8} + , {0xb8, 0xb8, 0xb8} , {0x04, 0x04, 0x04} , {0x00, 0x00, 0x00} } @@ -114,10 +114,10 @@ static Genesys_Frontend Wolfson[] = { {0x58, 0x80, 0x00, 0x00} /* reg1=0x80 ? */ , {0x00, 0x00, 0x00} , {0x09, 0x09, 0x09} - , {0x09, 0x09, 0x09} + , {0x09, 0x09, 0x09} , {0x00, 0x00, 0x00} } - , + , {DAC_WOLFSON_XP300,{0x00, 0x35, 0x20, 0x14} /* 7: XP300 */ , {0x00, 0x00, 0x00} , {0xe1, 0xe1, 0xe1} @@ -125,7 +125,7 @@ static Genesys_Frontend Wolfson[] = { , {0x07, 0x00, 0x00} } , /* 8: HP3670 */ - {DAC_WOLFSON_HP3670, + {DAC_WOLFSON_HP3670, /* reg0 reg1 reg2 reg3 */ {0x00, 0x03, 0x05, 0x32} /* reg3=0x32 for 100-300 dpi, 0x12 at 1200 */ , {0x00, 0x00, 0x00} /* sign */ @@ -160,7 +160,7 @@ static Genesys_Frontend Wolfson[] = { {DAC_KVSS080, {0x00, 0x23, 0x24, 0x0f} , {0x00, 0x00, 0x00} - , {0x80, 0x80, 0x80} + , {0x80, 0x80, 0x80} , {0x4b, 0x4b, 0x4b} , {0x00,0x00,0x00} } @@ -211,12 +211,23 @@ static Genesys_Frontend Wolfson[] = { , {0x00, 0x00, 0x00} /* 0x20, 0x21, 0x22 */ , {0x00, 0x00, 0x00} /* 0x28, 0x29, 0x2a */ , {0x00, 0x00, 0x00} - } + }, + {DAC_CANONLIDE80, + /* reg0: control 74 data, 70 no data + * reg3: offset + * reg6: gain + * reg0 , reg3, reg6 */ + {0x70, 0x16, 0x60, 0x00} + , {0x00, 0x00, 0x00} + , {0x00, 0x00, 0x00} + , {0x00, 0x00, 0x00} + , {0x00, 0x00, 0x00} + } }; /** for setting up the sensor-specific settings: - * Optical Resolution, number of black pixels, number of dummy pixels, + * Optical Resolution, number of black pixels, number of dummy pixels, * CCD_start_xoffset, and overall number of sensor pixels * registers 0x08-0x0b, 0x10-0x1d and 0x52-0x5e */ @@ -294,13 +305,14 @@ static Genesys_Sensor Sensor[] = { } , /* CANOLIDE35 */ - {CCD_CANONLIDE35, 1200, - 87, /*(black) */ + {CCD_CANONLIDE35, + 1200, + 87, /* (black) */ 87, /* (dummy) */ 0, /* (startxoffset) */ - 10400, /*sensor_pixels */ - 210, - 200, + 10400, /* sensor_pixels */ + 0, + 0, {0x00, 0x00, 0x00, 0x00}, {0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x02, 0x00, 0x50, 0x00, 0x00, 0x00, 0x02 /* TODO(these do no harm, but may be neccessery for CCD) */ @@ -349,7 +361,7 @@ static Genesys_Sensor Sensor[] = { 200, {0x00, 0x00, 0x00, 0x00}, {0x11, 0x00, 0x11, 0x00, 0x11, 0x00, 0x00, 0x02, 0x04, 0x50, - 0x10, 0x00, 0x20, 0x02 + 0x10, 0x00, 0x20, 0x02 }, {0x04, 0x05, 0x00, 0x00, 0x00, 0x00, /*[GB](HI|LOW) not needed for cis */ @@ -372,7 +384,7 @@ static Genesys_Sensor Sensor[] = { 200, {0x00, 0x00, 0x00, 0x00}, {0x11, 0x00, 0x11, 0x00, 0x11, 0x00, 0x00, 0x02, 0x04, 0x50, - 0x10, 0x00, 0x20, 0x02 + 0x10, 0x00, 0x20, 0x02 }, {0x04, 0x05, 0x00, 0x00, 0x00, 0x00, /*[GB](HI|LOW) not needed for cis */ @@ -395,7 +407,7 @@ static Genesys_Sensor Sensor[] = { 200, {0x00, 0x00, 0x00, 0x00}, {0x15, 0x44, 0x15, 0x44, 0x15, 0x44, 0x00, 0x02, 0x04, 0x50, - 0x10, 0x00, 0x20, 0x02 + 0x10, 0x00, 0x20, 0x02 }, {0x04, 0x05, 0x00, 0x00, 0x00, 0x00, /*[GB](HI|LOW) not needed for cis */ @@ -418,7 +430,7 @@ static Genesys_Sensor Sensor[] = { 200, {0x00, 0x00, 0x00, 0x00}, {0x11, 0x00, 0x11, 0x00, 0x11, 0x00, 0x00, 0x02, 0x04, 0x50, - 0x10, 0x00, 0x20, 0x02 + 0x10, 0x00, 0x20, 0x02 }, {0x04, 0x05, 0x00, 0x00, 0x00, 0x00, /*[GB](HI|LOW) not needed for cis */ @@ -441,7 +453,7 @@ static Genesys_Sensor Sensor[] = { 200, {0x00, 0x00, 0x00, 0x00}, {0x11, 0x00, 0x11, 0x00, 0x11, 0x00, 0x00, 0x02, 0x04, 0x50, - 0x10, 0x00, 0x20, 0x02 + 0x10, 0x00, 0x20, 0x02 }, {0x04, 0x05, 0x00, 0x00, 0x00, 0x00, /*[GB](HI|LOW) not needed for cis */ @@ -471,9 +483,9 @@ static Genesys_Sensor Sensor[] = { {0x03, 0x07, 0x00, 0x00, 0x00, 0x00, 0x2a, 0xe1, - 0x55, - 0x00, 0x00, 0x00, - 0x41 + 0x55, + 0x00, 0x00, 0x00, + 0x41 } , {1.7, 1.7, 1.7}, @@ -497,9 +509,9 @@ static Genesys_Sensor Sensor[] = { {0x07, 0x03, 0x00, 0x00, 0x00, 0x00, 0x2a, 0xe1, - 0x55, - 0x00, 0x00, 0x00, - 0x41 + 0x55, + 0x00, 0x00, 0x00, + 0x41 } , {1.0, 1.0, 1.0}, @@ -524,9 +536,9 @@ static Genesys_Sensor Sensor[] = { {0x03, 0x07, 0x00, 0x00, 0x00, 0x00, 0x2a, 0xe1, - 0x55, - 0x00, 0x00, 0x00, - 0x41 + 0x55, + 0x00, 0x00, 0x00, + 0x41 } , {1.7, 1.7, 1.7}, @@ -648,6 +660,30 @@ static Genesys_Sensor Sensor[] = { {2.1, 2.1, 2.1}, {NULL, NULL, NULL}} , + + /* CANONLIDE120 */ + {CIS_CANONLIDE120, + 2400, /* optical resolution */ + 87, /* black pixels */ + 16, /* dummy pixels 16 */ + 303, /* 303 */ + 5168*4, /* total pixels */ + 210, + 200, + {0x00, 0x00, 0x00, 0x00}, + /* reg 0x10 - 0x15 : EXPR, EXPG and EXPB */ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + /* reg 0x16 - 0x1d */ + 0x10, 0x04, 0x00, 0x01, 0x30, 0x00, 0x02, 0x01 }, + /* reg 0x52 - 0x5e */ + { + 0x00, 0x02, 0x04, 0x06, 0x04, 0x04, 0x04, 0x04, + 0x1a, 0x00, 0xc0, 0x00, 0x00 + } + , + {2.1, 2.1, 2.1}, + {NULL, NULL, NULL}} + , /* CANON LIDE 210 sensor */ {CIS_CANONLIDE210, 2400, /* optical resolution */ @@ -671,6 +707,29 @@ static Genesys_Sensor Sensor[] = { {2.1, 2.1, 2.1}, {NULL, NULL, NULL}} , + /* CANON LIDE 220 sensor */ + {CIS_CANONLIDE220, + 2400, /* optical resolution */ + 87, /* black pixels */ + 16, /* dummy pixels 16 */ + 303, /* 303 */ + 5168*4, /* total pixels */ + 210, + 200, + {0x00, 0x00, 0x00, 0x00}, + /* reg 0x10 - 0x15 : EXPR, EXPG and EXPB */ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + /* reg 0x16 - 0x1d */ + 0x10, 0x04, 0x00, 0x01, 0x30, 0x00, 0x02, 0x01 }, + /* reg 0x52 - 0x5e */ + { + 0x00, 0x02, 0x04, 0x06, 0x04, 0x04, 0x04, 0x04, + 0x1a, 0x00, 0xc0, 0x00, 0x00 + } + , + {2.1, 2.1, 2.1}, + {NULL, NULL, NULL}} + , {CCD_PLUSTEK_3600, 1200, 87, /*(black) */ @@ -696,8 +755,8 @@ static Genesys_Sensor Sensor[] = { /* Canon Image formula 101 */ {CCD_IMG101, 1200, /* optical resolution */ - 31, - 31, + 31, + 31, 0, 10800, 210, @@ -711,9 +770,9 @@ static Genesys_Sensor Sensor[] = { {0x02, 0x04, 0x06, 0x08, 0x0a, 0x00, 0x59, 0x31, - 0x40, - 0x00, 0x00, 0x00, - 0x1f + 0x40, + 0x00, 0x00, 0x00, + 0x1f } , {1.7, 1.7, 1.7}, @@ -723,8 +782,8 @@ static Genesys_Sensor Sensor[] = { /* Plustek OpticBook 3800 */ {CCD_PLUSTEK3800, 1200, /* optical resolution */ - 31, - 31, + 31, + 31, 0, 10200, 210, @@ -738,14 +797,31 @@ static Genesys_Sensor Sensor[] = { {0x02, 0x04, 0x06, 0x08, 0x0a, 0x00, 0x59, 0x31, - 0x40, - 0x00, 0x00, 0x00, - 0x1f + 0x40, + 0x00, 0x00, 0x00, + 0x1f } , {1.7, 1.7, 1.7}, {NULL, NULL, NULL} - } + }, + /* CANOLIDE80 */ + {CIS_CANONLIDE80, + 1200, /* real hardware limit is 2400 */ + 20, /* black pixels */ + 6, /* expdummy 6 */ + /* tuned to give 3*8 multiple startx coordinate during shading calibration */ + 34, /* CCD_start_xoffset 14=>3, 20=>2 */ + 10240, /* 10400, too wide=>10288 in shading data 10240~, 10208 too short for shading, max shading data = 10240 pixels, endpix-startpix=10208 */ + 150, + 150, + {0x00, 0x05, 0x07, 0x09}, /* in fact ,maps to 0x70-0x73 for GL841 */ + /* [0x10-0x15] values are initial led exposure values */ + /* 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d*/ + {0x10, 0x00, 0x10, 0x00, 0x05, 0x00, 0x00, 0x01, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04}, + {0x03, 0x07, 0x00, 0x00, 0x00, 0x00, 0x29, 0x69, 0x55, 0x00, 0x00, 0x20, 0x41} , + {1.0, 1.0, 1.0}, + {NULL, NULL, NULL}} }; /** for General Purpose Output specific settings: @@ -804,7 +880,7 @@ static Genesys_Gpo Gpo[] = { , /* CANONLIDE35 */ {GPO_CANONLIDE35, - {0x12, 0x80} + {0x02, 0x80} , {0xef, 0x80} , @@ -909,6 +985,12 @@ static Genesys_Gpo Gpo[] = { {GPO_PLUSTEK3800, {0x41, 0xa4}, {0x13, 0xa7} + }, + /* Canon LiDE 80 */ + { + GPO_CANONLIDE80, + {0x28, 0x90}, /* 6c, 6d */ + {0x75, 0x80}, /* 6e, 6f */ } }; @@ -919,7 +1001,7 @@ static Genesys_Motor Motor[] = { 2400, /* maximum motor resolution */ 1, /* maximum step mode */ 1, /* number of power modes*/ - {{{ + {{{ 11000, /* maximum start speed */ 3000, /* maximum end speed */ 128, /* step count */ @@ -937,7 +1019,7 @@ static Genesys_Motor Motor[] = { 2400, 1, 1, - {{{ + {{{ 2000, 1375, 128, @@ -966,7 +1048,7 @@ static Genesys_Motor Motor[] = { 2100, 128, 0.3, - },},}, + },},}, }, {MOTOR_HP3670, /* HP 3670 */ 1200, @@ -1027,18 +1109,8 @@ static Genesys_Motor Motor[] = { 2400, 1, 1, - {{{ - 3500, - 1300, - 60, - 0.8, - }, - { - 3500, - 1400, - 60, - 0.8, - },},}, + {{{ 3500, 1300, 60, 0.8, }, + { 3500, 1400, 60, 0.8, },},}, }, {MOTOR_XP200, /* Strobe XP200 */ 600, @@ -1263,6 +1335,21 @@ static Genesys_Motor Motor[] = { { 3500, 3250, 60, 0.8 }, }, },}, + {MOTOR_CANONLIDE80, + 2400, /* 2400 ???? */ + 4800, /* 9600 ???? */ + 1, /* max step type */ + 1, /* power mode count */ + { + { /* start speed, max end speed, step number */ + /* maximum speed (second field) is used to compute exposure as seen by motor */ + /* exposure=max speed/ slope dpi * base dpi */ + /* 5144 = max pixels at 600 dpi */ + /* 1288=(5144+8)*ydpi(=300)/base_dpi(=1200) , where 5152 is exposure */ + /* 6440=9660/(1932/1288) */ + { 9560, 1912, 31, 0.8 }, + }, + },}, }; /* here we have the various device settings... @@ -1296,7 +1383,7 @@ static Genesys_Model umax_astra_4500_model = { SANE_FIX (0.0), /* Size of scan area after paper sensor stops sensing document in mm */ - SANE_FIX (0.0), /* Amount of feeding needed to eject document + SANE_FIX (0.0), /* Amount of feeding needed to eject document after finishing scanning in mm */ 0, 8, 16, /* RGB CCD Line-distance correction in pixel */ @@ -1323,8 +1410,8 @@ static Genesys_Model canon_lide_50_model = { GENESYS_GL841, NULL, - {1200, 600, 300, 150, 75, 0}, /* possible x-resolutions */ - {2400, 1200, 600, 300, 150, 75, 0}, /* possible y-resolutions */ + { 1200, 600, 400, 300, 240, 200, 150, 75, 0}, /* possible x-resolutions */ + {2400, 1200, 600, 400, 300, 240, 200, 150, 75, 0}, /* possible y-resolutions */ {16, 8, 0}, /* possible depths in gray mode */ {16, 8, 0}, /* possible depths in color mode */ @@ -1333,7 +1420,7 @@ static Genesys_Model canon_lide_50_model = { SANE_FIX (218.0), /* Size of scan area in mm (x) */ SANE_FIX (299.0), /* Size of scan area in mm (y) */ - SANE_FIX (3.0), /* Start of white strip in mm (y) */ + SANE_FIX (6.0), /* Start of white strip in mm (y) */ SANE_FIX (0.0), /* Start of black mark in mm (x) */ SANE_FIX (0.0), /* Start of scan area in TA mode in mm (x) */ @@ -1345,7 +1432,7 @@ static Genesys_Model canon_lide_50_model = { SANE_FIX (0.0), /* Size of scan area after paper sensor stops sensing document in mm */ - SANE_FIX (0.0), /* Amount of feeding needed to eject document + SANE_FIX (0.0), /* Amount of feeding needed to eject document after finishing scanning in mm */ 0, 0, 0, /* RGB CCD Line-distance correction in pixel */ @@ -1359,8 +1446,8 @@ static Genesys_Model canon_lide_50_model = { GPO_CANONLIDE35, MOTOR_CANONLIDE35, GENESYS_FLAG_LAZY_INIT | /* Which flags are needed for this scanner? */ - GENESYS_FLAG_SKIP_WARMUP | - GENESYS_FLAG_OFFSET_CALIBRATION | + GENESYS_FLAG_SKIP_WARMUP | + GENESYS_FLAG_OFFSET_CALIBRATION | GENESYS_FLAG_DARK_WHITE_CALIBRATION | GENESYS_FLAG_CUSTOM_GAMMA | GENESYS_FLAG_HALF_CCD_MODE, @@ -1401,7 +1488,7 @@ static Genesys_Model panasonic_kvss080_model = { SANE_FIX (0.0), /* Size of scan area after paper sensor stops sensing document in mm */ - SANE_FIX (0.0), /* Amount of feeding needed to eject document + SANE_FIX (0.0), /* Amount of feeding needed to eject document after finishing scanning in mm */ 0, 8, 16, /* RGB CCD Line-distance correction in pixel */ @@ -1452,7 +1539,7 @@ static Genesys_Model hp4850c_model = { SANE_FIX (0.0), /* Size of scan area after paper sensor stops sensing document in mm */ - SANE_FIX (0.0), /* Amount of feeding needed to eject document + SANE_FIX (0.0), /* Amount of feeding needed to eject document after finishing scanning in mm */ 0, 24, 48, /* RGB CCD Line-distance correction in line number */ @@ -1467,7 +1554,7 @@ static Genesys_Model hp4850c_model = { DAC_G4050, GPO_G4050, MOTOR_G4050, - GENESYS_FLAG_LAZY_INIT | + GENESYS_FLAG_LAZY_INIT | GENESYS_FLAG_OFFSET_CALIBRATION | GENESYS_FLAG_STAGGERED_LINE | GENESYS_FLAG_SKIP_WARMUP | @@ -1507,7 +1594,7 @@ static Genesys_Model hpg4010_model = { SANE_FIX (0.0), /* Size of scan area after paper sensor stops sensing document in mm */ - SANE_FIX (0.0), /* Amount of feeding needed to eject document + SANE_FIX (0.0), /* Amount of feeding needed to eject document after finishing scanning in mm */ 0, 24, 48, /* RGB CCD Line-distance correction in line number */ @@ -1522,7 +1609,7 @@ static Genesys_Model hpg4010_model = { DAC_G4050, GPO_G4050, MOTOR_G4050, - GENESYS_FLAG_LAZY_INIT | + GENESYS_FLAG_LAZY_INIT | GENESYS_FLAG_OFFSET_CALIBRATION | GENESYS_FLAG_STAGGERED_LINE | GENESYS_FLAG_SKIP_WARMUP | @@ -1562,7 +1649,7 @@ static Genesys_Model hpg4050_model = { SANE_FIX (0.0), /* Size of scan area after paper sensor stops sensing document in mm */ - SANE_FIX (0.0), /* Amount of feeding needed to eject document + SANE_FIX (0.0), /* Amount of feeding needed to eject document after finishing scanning in mm */ 0, 24, 48, /* RGB CCD Line-distance correction in line number */ @@ -1577,7 +1664,7 @@ static Genesys_Model hpg4050_model = { DAC_G4050, GPO_G4050, MOTOR_G4050, - GENESYS_FLAG_LAZY_INIT | + GENESYS_FLAG_LAZY_INIT | GENESYS_FLAG_OFFSET_CALIBRATION | GENESYS_FLAG_STAGGERED_LINE | GENESYS_FLAG_SKIP_WARMUP | @@ -1618,7 +1705,7 @@ static Genesys_Model canon_4400f_model = { SANE_FIX (0.0), /* Size of scan area after paper sensor stops sensing document in mm */ - SANE_FIX (0.0), /* Amount of feeding needed to eject document + SANE_FIX (0.0), /* Amount of feeding needed to eject document after finishing scanning in mm */ 0, 24, 48, /* RGB CCD Line-distance correction in line number */ @@ -1634,7 +1721,7 @@ static Genesys_Model canon_4400f_model = { GPO_CS4400F, MOTOR_G4050, GENESYS_FLAG_NO_CALIBRATION | - GENESYS_FLAG_LAZY_INIT | + GENESYS_FLAG_LAZY_INIT | GENESYS_FLAG_OFFSET_CALIBRATION | GENESYS_FLAG_STAGGERED_LINE | GENESYS_FLAG_SKIP_WARMUP | @@ -1677,7 +1764,7 @@ static Genesys_Model canon_8400f_model = { SANE_FIX (0.0), /* Size of scan area after paper sensor stops sensing document in mm */ - SANE_FIX (0.0), /* Amount of feeding needed to eject document + SANE_FIX (0.0), /* Amount of feeding needed to eject document after finishing scanning in mm */ 0, 24, 48, /* RGB CCD Line-distance correction in line number */ @@ -1693,7 +1780,7 @@ static Genesys_Model canon_8400f_model = { GPO_CS8400F, MOTOR_CS8400F, GENESYS_FLAG_NO_CALIBRATION | - GENESYS_FLAG_LAZY_INIT | + GENESYS_FLAG_LAZY_INIT | GENESYS_FLAG_OFFSET_CALIBRATION | GENESYS_FLAG_STAGGERED_LINE | GENESYS_FLAG_SKIP_WARMUP | @@ -1736,7 +1823,7 @@ static Genesys_Model canon_lide_100_model = { SANE_FIX (0.0), /* Size of scan area after paper sensor stops sensing document in mm */ - SANE_FIX (0.0), /* Amount of feeding needed to eject document + SANE_FIX (0.0), /* Amount of feeding needed to eject document after finishing scanning in mm */ 0, 0, 0, /* RGB CCD Line-distance correction in pixel */ @@ -1748,7 +1835,7 @@ static Genesys_Model canon_lide_100_model = { CIS_CANONLIDE100, DAC_CANONLIDE200, GPO_CANONLIDE200, - MOTOR_CANONLIDE100, + MOTOR_CANONLIDE100, /* Which flags are needed for this scanner? */ GENESYS_FLAG_SKIP_WARMUP | GENESYS_FLAG_SIS_SENSOR @@ -1790,7 +1877,7 @@ static Genesys_Model canon_lide_110_model = { SANE_FIX (0.0), /* Size of scan area after paper sensor stops sensing document in mm */ - SANE_FIX (0.0), /* Amount of feeding needed to eject document + SANE_FIX (0.0), /* Amount of feeding needed to eject document after finishing scanning in mm */ 0, 0, 0, /* RGB CCD Line-distance correction in pixel */ @@ -1802,7 +1889,60 @@ static Genesys_Model canon_lide_110_model = { CIS_CANONLIDE110, DAC_CANONLIDE110, GPO_CANONLIDE110, - MOTOR_CANONLIDE110, + MOTOR_CANONLIDE110, + GENESYS_FLAG_SKIP_WARMUP + | GENESYS_FLAG_OFFSET_CALIBRATION + | GENESYS_FLAG_DARK_CALIBRATION + | GENESYS_FLAG_HALF_CCD_MODE + | GENESYS_FLAG_SHADING_REPARK + | GENESYS_FLAG_CUSTOM_GAMMA, + GENESYS_HAS_SCAN_SW | GENESYS_HAS_COPY_SW | GENESYS_HAS_EMAIL_SW | GENESYS_HAS_FILE_SW, + 50, + 400 +}; + +static Genesys_Model canon_lide_120_model = { + "canon-lide-120", /* Name */ + "Canon", /* Device vendor string */ + "LiDE 120", /* Device model name */ + GENESYS_GL124, + NULL, + + {4800, 2400, 1200, 600, 300, 150, 100, 75, 0}, /* possible x-resolutions */ + {4800, 2400, 1200, 600, 300, 150, 100, 75, 0}, /* possible y-resolutions */ + {16, 8, 0}, /* possible depths in gray mode */ + {16, 8, 0}, /* possible depths in color mode */ + + SANE_FIX (2.2), /* Start of scan area in mm (x) */ + SANE_FIX (9.0), /* Start of scan area in mm (y) */ + SANE_FIX (216.70), /* Size of scan area in mm (x) */ + SANE_FIX (300.0), /* Size of scan area in mm (y) */ + + SANE_FIX (1.0), /* Start of white strip in mm (y) */ + SANE_FIX (0.0), /* Start of black mark in mm (x) */ + + SANE_FIX (0.0), /* Start of scan area in TA mode in mm (x) */ + SANE_FIX (0.0), /* Start of scan area in TA mode in mm (y) */ + SANE_FIX (100.0), /* Size of scan area in TA mode in mm (x) */ + SANE_FIX (100.0), /* Size of scan area in TA mode in mm (y) */ + + SANE_FIX (0.0), /* Start of white strip in TA mode in mm (y) */ + + SANE_FIX (0.0), /* Size of scan area after paper sensor stops + sensing document in mm */ + SANE_FIX (0.0), /* Amount of feeding needed to eject document + after finishing scanning in mm */ + + 0, 0, 0, /* RGB CCD Line-distance correction in pixel */ + + COLOR_ORDER_RGB, /* Order of the CCD/CIS colors */ + + SANE_TRUE, /* Is this a CIS scanner? */ + SANE_FALSE, /* Is this a sheetfed scanner? */ + CIS_CANONLIDE120, + DAC_CANONLIDE110, + GPO_CANONLIDE110, + MOTOR_CANONLIDE110, GENESYS_FLAG_SKIP_WARMUP | GENESYS_FLAG_OFFSET_CALIBRATION | GENESYS_FLAG_DARK_CALIBRATION @@ -1844,7 +1984,7 @@ static Genesys_Model canon_lide_210_model = { SANE_FIX (0.0), /* Size of scan area after paper sensor stops sensing document in mm */ - SANE_FIX (0.0), /* Amount of feeding needed to eject document + SANE_FIX (0.0), /* Amount of feeding needed to eject document after finishing scanning in mm */ 0, 0, 0, /* RGB CCD Line-distance correction in pixel */ @@ -1856,7 +1996,60 @@ static Genesys_Model canon_lide_210_model = { CIS_CANONLIDE210, DAC_CANONLIDE110, GPO_CANONLIDE210, - MOTOR_CANONLIDE210, + MOTOR_CANONLIDE210, + GENESYS_FLAG_SKIP_WARMUP + | GENESYS_FLAG_OFFSET_CALIBRATION + | GENESYS_FLAG_DARK_CALIBRATION + | GENESYS_FLAG_HALF_CCD_MODE + | GENESYS_FLAG_SHADING_REPARK + | GENESYS_FLAG_CUSTOM_GAMMA, + GENESYS_HAS_SCAN_SW | GENESYS_HAS_COPY_SW | GENESYS_HAS_EMAIL_SW | GENESYS_HAS_FILE_SW | GENESYS_HAS_EXTRA_SW, + 60, + 400 +}; + +static Genesys_Model canon_lide_220_model = { + "canon-lide-220", /* Name */ + "Canon", /* Device vendor string */ + "LiDE 220", /* Device model name */ + GENESYS_GL124, /* or a compatible one */ + NULL, + + {4800, 2400, 1200, 600, 300, 150, 100, 75, 0}, /* possible x-resolutions */ + {4800, 2400, 1200, 600, 300, 150, 100, 75, 0}, /* possible y-resolutions */ + {16, 8, 0}, /* possible depths in gray mode */ + {16, 8, 0}, /* possible depths in color mode */ + + SANE_FIX (2.2), /* Start of scan area in mm (x) */ + SANE_FIX (8.7), /* Start of scan area in mm (y) */ + SANE_FIX (216.70), /* Size of scan area in mm (x) */ + SANE_FIX (297.5), /* Size of scan area in mm (y) */ + + SANE_FIX (0.0), /* Start of white strip in mm (y) */ + SANE_FIX (0.0), /* Start of black mark in mm (x) */ + + SANE_FIX (0.0), /* Start of scan area in TA mode in mm (x) */ + SANE_FIX (0.0), /* Start of scan area in TA mode in mm (y) */ + SANE_FIX (100.0), /* Size of scan area in TA mode in mm (x) */ + SANE_FIX (100.0), /* Size of scan area in TA mode in mm (y) */ + + SANE_FIX (0.0), /* Start of white strip in TA mode in mm (y) */ + + SANE_FIX (0.0), /* Size of scan area after paper sensor stops + sensing document in mm */ + SANE_FIX (0.0), /* Amount of feeding needed to eject document + after finishing scanning in mm */ + + 0, 0, 0, /* RGB CCD Line-distance correction in pixel */ + + COLOR_ORDER_RGB, /* Order of the CCD/CIS colors */ + + SANE_TRUE, /* Is this a CIS scanner? */ + SANE_FALSE, /* Is this a sheetfed scanner? */ + CIS_CANONLIDE220, + DAC_CANONLIDE110, + GPO_CANONLIDE210, + MOTOR_CANONLIDE210, GENESYS_FLAG_SKIP_WARMUP | GENESYS_FLAG_OFFSET_CALIBRATION | GENESYS_FLAG_DARK_CALIBRATION @@ -1897,7 +2090,7 @@ static Genesys_Model canon_5600f_model = { SANE_FIX (0.0), /* Size of scan area after paper sensor stops sensing document in mm */ - SANE_FIX (0.0), /* Amount of feeding needed to eject document + SANE_FIX (0.0), /* Amount of feeding needed to eject document after finishing scanning in mm */ 0, 0, 0, /* RGB CCD Line-distance correction in pixel */ @@ -1950,7 +2143,7 @@ static Genesys_Model canon_lide_700f_model = { SANE_FIX (0.0), /* Size of scan area after paper sensor stops sensing document in mm */ - SANE_FIX (0.0), /* Amount of feeding needed to eject document + SANE_FIX (0.0), /* Amount of feeding needed to eject document after finishing scanning in mm */ 0, 0, 0, /* RGB CCD Line-distance correction in pixel */ @@ -2005,7 +2198,7 @@ static Genesys_Model canon_lide_200_model = { SANE_FIX (0.0), /* Size of scan area after paper sensor stops sensing document in mm */ - SANE_FIX (0.0), /* Amount of feeding needed to eject document + SANE_FIX (0.0), /* Amount of feeding needed to eject document after finishing scanning in mm */ 0, 0, 0, /* RGB CCD Line-distance correction in pixel */ @@ -2047,7 +2240,7 @@ static Genesys_Model canon_lide_60_model = { SANE_FIX (218.0), /* Size of scan area in mm (x) */ SANE_FIX (299.0), /* Size of scan area in mm (y) */ - SANE_FIX (3.0), /* Start of white strip in mm (y) */ + SANE_FIX (6.0), /* Start of white strip in mm (y) */ SANE_FIX (0.0), /* Start of black mark in mm (x) */ SANE_FIX (0.0), /* Start of scan area in TA mode in mm (x) */ @@ -2059,7 +2252,7 @@ static Genesys_Model canon_lide_60_model = { SANE_FIX (0.0), /* Size of scan area after paper sensor stops sensing document in mm */ - SANE_FIX (0.0), /* Amount of feeding needed to eject document + SANE_FIX (0.0), /* Amount of feeding needed to eject document after finishing scanning in mm */ 0, 0, 0, /* RGB CCD Line-distance correction in pixel */ @@ -2076,7 +2269,7 @@ static Genesys_Model canon_lide_60_model = { | GENESYS_FLAG_SKIP_WARMUP | GENESYS_FLAG_OFFSET_CALIBRATION | GENESYS_FLAG_DARK_WHITE_CALIBRATION - | GENESYS_FLAG_CUSTOM_GAMMA + | GENESYS_FLAG_CUSTOM_GAMMA | GENESYS_FLAG_HALF_CCD_MODE, GENESYS_HAS_NO_BUTTONS, /* no buttons supported */ @@ -2084,6 +2277,62 @@ static Genesys_Model canon_lide_60_model = { 400 }; /* this is completely untested -- hmg */ +static Genesys_Model canon_lide_80_model = { + "canon-lide-80", /* Name */ + "Canon", /* Device vendor string */ + "LiDE 80", /* Device model name */ + GENESYS_GL841, + NULL, + + { 1200, 600, 400, 300, 240, 150, 100, 75, 0}, /* possible x-resolutions */ + {2400, 1200, 600, 400, 300, 240, 150, 100, 75, 0}, /* possible y-resolutions */ + {16, 8, 0}, /* possible depths in gray mode */ + {16, 8, 0}, /* possible depths in color mode */ + SANE_FIX (0.42), /* Start of scan area in mm (x) 0.42 */ + SANE_FIX (7.90), /* Start of scan area in mm (y) 7.90 */ + SANE_FIX (216.07), /* Size of scan area in mm (x) 218.00 */ + SANE_FIX (299.0), /* Size of scan area in mm (y) */ + + SANE_FIX (4.5), /* Start of white strip in mm (y) */ + SANE_FIX (0.0), /* Start of black mark in mm (x) */ + + SANE_FIX (0.0), /* Start of scan area in TA mode in mm (x) */ + SANE_FIX (0.0), /* Start of scan area in TA mode in mm (y) */ + SANE_FIX (100.0), /* Size of scan area in TA mode in mm (x) */ + SANE_FIX (100.0), /* Size of scan area in TA mode in mm (y) */ + + SANE_FIX (0.0), /* Start of white strip in TA mode in mm (y) */ + + SANE_FIX (0.0), /* Size of scan area after paper sensor stops + sensing document in mm */ + SANE_FIX (0.0), /* Amount of feeding needed to eject document + after finishing scanning in mm */ + + 0, 0, 0, /* RGB CCD Line-distance correction in pixel */ + + COLOR_ORDER_RGB, /* Order of the CCD/CIS colors */ + + SANE_TRUE, /* Is this a CIS scanner? */ + SANE_FALSE, /* Is this a sheetfed scanner? */ + CIS_CANONLIDE80, + DAC_CANONLIDE80, + GPO_CANONLIDE80, + MOTOR_CANONLIDE80, + GENESYS_FLAG_LAZY_INIT | /* Which flags are needed for this scanner? */ + GENESYS_FLAG_SKIP_WARMUP | + GENESYS_FLAG_OFFSET_CALIBRATION | + GENESYS_FLAG_DARK_WHITE_CALIBRATION | + GENESYS_FLAG_CUSTOM_GAMMA | + GENESYS_FLAG_HALF_CCD_MODE, + GENESYS_HAS_SCAN_SW | + GENESYS_HAS_FILE_SW | + GENESYS_HAS_EMAIL_SW | + GENESYS_HAS_COPY_SW, + 160, /* 280 @2400 */ + 400 +}; + + static Genesys_Model hp2300c_model = { "hewlett-packard-scanjet-2300c", /* Name */ "Hewlett Packard", /* Device vendor string */ @@ -2113,7 +2362,7 @@ static Genesys_Model hp2300c_model = { SANE_FIX (0.0), /* Size of scan area after paper sensor stops sensing document in mm */ - SANE_FIX (0.0), /* Amount of feeding needed to eject document + SANE_FIX (0.0), /* Amount of feeding needed to eject document after finishing scanning in mm */ 16, 8, 0, /* RGB CCD Line-distance correction in pixel */ @@ -2139,7 +2388,7 @@ static Genesys_Model hp2300c_model = { 132 }; -static +static Genesys_Model hp2400c_model = { "hewlett-packard-scanjet-2400c", /* Name */ "Hewlett Packard", /* Device vendor string */ @@ -2169,7 +2418,7 @@ Genesys_Model hp2400c_model = { SANE_FIX (0.0), /* Size of scan area after paper sensor stops sensing document in mm */ - SANE_FIX (0.0), /* Amount of feeding needed to eject document + SANE_FIX (0.0), /* Amount of feeding needed to eject document after finishing scanning in mm */ 0, 24, 48, /* RGB CCD Line-distance correction in pixel */ @@ -2194,7 +2443,7 @@ Genesys_Model hp2400c_model = { 132 }; -static +static Genesys_Model visioneer_xp200_model = { "visioneer-strobe-xp200", /* Name */ "Visioneer", /* Device vendor string */ @@ -2224,7 +2473,7 @@ Genesys_Model visioneer_xp200_model = { SANE_FIX (0.0), /* Size of scan area after paper sensor stops sensing document in mm */ - SANE_FIX (0.0), /* Amount of feeding needed to eject document + SANE_FIX (0.0), /* Amount of feeding needed to eject document after finishing scanning in mm */ 0, 0, 0, /* RGB CCD Line-distance correction in pixel */ @@ -2277,7 +2526,7 @@ static Genesys_Model hp3670c_model = { SANE_FIX (0.0), /* Size of scan area after paper sensor stops sensing document in mm */ - SANE_FIX (0.0), /* Amount of feeding needed to eject document + SANE_FIX (0.0), /* Amount of feeding needed to eject document after finishing scanning in mm */ 0, 24, 48, /* RGB CCD Line-distance correction in pixel */ @@ -2331,7 +2580,7 @@ static Genesys_Model plustek_st12_model = { SANE_FIX (0.0), /* Size of scan area after paper sensor stops sensing document in mm */ - SANE_FIX (0.0), /* Amount of feeding needed to eject document + SANE_FIX (0.0), /* Amount of feeding needed to eject document after finishing scanning in mm */ 0, 8, 16, /* RGB CCD Line-distance correction in pixel */ @@ -2379,7 +2628,7 @@ static Genesys_Model plustek_st24_model = { SANE_FIX (0.0), /* Size of scan area after paper sensor stops sensing document in mm */ - SANE_FIX (0.0), /* Amount of feeding needed to eject document + SANE_FIX (0.0), /* Amount of feeding needed to eject document after finishing scanning in mm */ 0, 8, 16, /* RGB CCD Line-distance correction in pixel */ @@ -2395,7 +2644,7 @@ static Genesys_Model plustek_st24_model = { GENESYS_FLAG_UNTESTED | GENESYS_FLAG_14BIT_GAMMA | GENESYS_FLAG_LAZY_INIT - | GENESYS_FLAG_CUSTOM_GAMMA + | GENESYS_FLAG_CUSTOM_GAMMA | GENESYS_FLAG_SEARCH_START | GENESYS_FLAG_OFFSET_CALIBRATION, GENESYS_HAS_NO_BUTTONS, /* no buttons supported */ @@ -2432,7 +2681,7 @@ static Genesys_Model medion_md5345_model = { SANE_FIX (0.0), /* Size of scan area after paper sensor stops sensing document in mm */ - SANE_FIX (0.0), /* Amount of feeding needed to eject document + SANE_FIX (0.0), /* Amount of feeding needed to eject document after finishing scanning in mm */ 48, 24, 0, /* RGB CCD Line-distance correction in pixel */ @@ -2475,7 +2724,7 @@ static Genesys_Model visioneer_xp300_model = { SANE_FIX (435.0), /* Size of scan area in mm (x) */ SANE_FIX (511), /* Size of scan area in mm (y) */ - SANE_FIX (3.0), /* Start of white strip in mm (y) */ + SANE_FIX (0.0), /* Start of white strip in mm (y) */ SANE_FIX (0.0), /* Start of black mark in mm (x) */ SANE_FIX (0.0), /* Start of scan area in TA mode in mm (x) */ @@ -2487,9 +2736,9 @@ static Genesys_Model visioneer_xp300_model = { SANE_FIX (26.5), /* Size of scan area after paper sensor stops sensing document in mm */ - /* this is larger than needed -- accounts for second sensor head, which is a + /* this is larger than needed -- accounts for second sensor head, which is a calibration item */ - SANE_FIX (0.0), /* Amount of feeding needed to eject document + SANE_FIX (0.0), /* Amount of feeding needed to eject document after finishing scanning in mm */ 0, 0, 0, /* RGB CCD Line-distance correction in pixel */ @@ -2540,7 +2789,7 @@ static Genesys_Model syscan_docketport_665_model = { SANE_FIX (17.5), /* Size of scan area after paper sensor stops sensing document in mm */ - SANE_FIX (0.0), /* Amount of feeding needed to eject document + SANE_FIX (0.0), /* Amount of feeding needed to eject document after finishing scanning in mm */ 0, 0, 0, /* RGB CCD Line-distance correction in pixel */ @@ -2580,7 +2829,7 @@ static Genesys_Model visioneer_roadwarrior_model = { SANE_FIX (220.0), /* Size of scan area in mm (x) */ SANE_FIX (511), /* Size of scan area in mm (y) */ - SANE_FIX (3.0), /* Start of white strip in mm (y) */ + SANE_FIX (0.0), /* Start of white strip in mm (y) */ SANE_FIX (0.0), /* Start of black mark in mm (x) */ SANE_FIX (0.0), /* Start of scan area in TA mode in mm (x) */ @@ -2592,7 +2841,7 @@ static Genesys_Model visioneer_roadwarrior_model = { SANE_FIX (16.0), /* Size of scan area after paper sensor stops sensing document in mm */ - SANE_FIX (0.0), /* Amount of feeding needed to eject document + SANE_FIX (0.0), /* Amount of feeding needed to eject document after finishing scanning in mm */ 0, 0, 0, /* RGB CCD Line-distance correction in pixel */ @@ -2608,7 +2857,7 @@ static Genesys_Model visioneer_roadwarrior_model = { GENESYS_FLAG_LAZY_INIT /* Which flags are needed for this scanner? */ | GENESYS_FLAG_SKIP_WARMUP | GENESYS_FLAG_OFFSET_CALIBRATION - | GENESYS_FLAG_CUSTOM_GAMMA + | GENESYS_FLAG_CUSTOM_GAMMA | GENESYS_FLAG_DARK_CALIBRATION, GENESYS_HAS_SCAN_SW | GENESYS_HAS_PAGE_LOADED_SW | GENESYS_HAS_CALIBRATE, 100, @@ -2632,7 +2881,7 @@ static Genesys_Model syscan_docketport_465_model = { SANE_FIX (220.0), /* Size of scan area in mm (x) */ SANE_FIX (511), /* Size of scan area in mm (y) */ - SANE_FIX (3.0), /* Start of white strip in mm (y) */ + SANE_FIX (0.0), /* Start of white strip in mm (y) */ SANE_FIX (0.0), /* Start of black mark in mm (x) */ SANE_FIX (0.0), /* Start of scan area in TA mode in mm (x) */ @@ -2644,7 +2893,7 @@ static Genesys_Model syscan_docketport_465_model = { SANE_FIX (16.0), /* Size of scan area after paper sensor stops sensing document in mm */ - SANE_FIX (0.0), /* Amount of feeding needed to eject document + SANE_FIX (0.0), /* Amount of feeding needed to eject document after finishing scanning in mm */ 0, 0, 0, /* RGB CCD Line-distance correction in pixel */ @@ -2660,7 +2909,7 @@ static Genesys_Model syscan_docketport_465_model = { GENESYS_FLAG_LAZY_INIT /* Which flags are needed for this scanner? */ | GENESYS_FLAG_SKIP_WARMUP | GENESYS_FLAG_NO_CALIBRATION - | GENESYS_FLAG_CUSTOM_GAMMA + | GENESYS_FLAG_CUSTOM_GAMMA | GENESYS_FLAG_UNTESTED, GENESYS_HAS_SCAN_SW | GENESYS_HAS_PAGE_LOADED_SW, 300, @@ -2684,7 +2933,7 @@ static Genesys_Model visioneer_xp100_r3_model = { SANE_FIX (220.0), /* Size of scan area in mm (x) */ SANE_FIX (511), /* Size of scan area in mm (y) */ - SANE_FIX (3.0), /* Start of white strip in mm (y) */ + SANE_FIX (0.0), /* Start of white strip in mm (y) */ SANE_FIX (0.0), /* Start of black mark in mm (x) */ SANE_FIX (0.0), /* Start of scan area in TA mode in mm (x) */ @@ -2696,7 +2945,7 @@ static Genesys_Model visioneer_xp100_r3_model = { SANE_FIX (16.0), /* Size of scan area after paper sensor stops sensing document in mm */ - SANE_FIX (0.0), /* Amount of feeding needed to eject document + SANE_FIX (0.0), /* Amount of feeding needed to eject document after finishing scanning in mm */ 0, 0, 0, /* RGB CCD Line-distance correction in pixel */ @@ -2712,7 +2961,7 @@ static Genesys_Model visioneer_xp100_r3_model = { GENESYS_FLAG_LAZY_INIT /* Which flags are needed for this scanner? */ | GENESYS_FLAG_SKIP_WARMUP | GENESYS_FLAG_OFFSET_CALIBRATION - | GENESYS_FLAG_CUSTOM_GAMMA + | GENESYS_FLAG_CUSTOM_GAMMA | GENESYS_FLAG_DARK_CALIBRATION, GENESYS_HAS_SCAN_SW | GENESYS_HAS_PAGE_LOADED_SW | GENESYS_HAS_CALIBRATE, 100, @@ -2736,7 +2985,7 @@ static Genesys_Model pentax_dsmobile_600_model = { SANE_FIX (220.0), /* Size of scan area in mm (x) */ SANE_FIX (511), /* Size of scan area in mm (y) */ - SANE_FIX (3.0), /* Start of white strip in mm (y) */ + SANE_FIX (0.0), /* Start of white strip in mm (y) */ SANE_FIX (0.0), /* Start of black mark in mm (x) */ SANE_FIX (0.0), /* Start of scan area in TA mode in mm (x) */ @@ -2748,7 +2997,7 @@ static Genesys_Model pentax_dsmobile_600_model = { SANE_FIX (16.0), /* Size of scan area after paper sensor stops sensing document in mm */ - SANE_FIX (0.0), /* Amount of feeding needed to eject document + SANE_FIX (0.0), /* Amount of feeding needed to eject document after finishing scanning in mm */ 0, 0, 0, /* RGB CCD Line-distance correction in pixel */ @@ -2764,7 +3013,7 @@ static Genesys_Model pentax_dsmobile_600_model = { GENESYS_FLAG_LAZY_INIT /* Which flags are needed for this scanner? */ | GENESYS_FLAG_SKIP_WARMUP | GENESYS_FLAG_OFFSET_CALIBRATION - | GENESYS_FLAG_CUSTOM_GAMMA + | GENESYS_FLAG_CUSTOM_GAMMA | GENESYS_FLAG_DARK_CALIBRATION, GENESYS_HAS_SCAN_SW | GENESYS_HAS_PAGE_LOADED_SW | GENESYS_HAS_CALIBRATE, 100, @@ -2788,7 +3037,7 @@ static Genesys_Model syscan_docketport_467_model = { SANE_FIX (220.0), /* Size of scan area in mm (x) */ SANE_FIX (511), /* Size of scan area in mm (y) */ - SANE_FIX (3.0), /* Start of white strip in mm (y) */ + SANE_FIX (0.0), /* Start of white strip in mm (y) */ SANE_FIX (0.0), /* Start of black mark in mm (x) */ SANE_FIX (0.0), /* Start of scan area in TA mode in mm (x) */ @@ -2800,7 +3049,7 @@ static Genesys_Model syscan_docketport_467_model = { SANE_FIX (16.0), /* Size of scan area after paper sensor stops sensing document in mm */ - SANE_FIX (0.0), /* Amount of feeding needed to eject document + SANE_FIX (0.0), /* Amount of feeding needed to eject document after finishing scanning in mm */ 0, 0, 0, /* RGB CCD Line-distance correction in pixel */ @@ -2816,7 +3065,7 @@ static Genesys_Model syscan_docketport_467_model = { GENESYS_FLAG_LAZY_INIT /* Which flags are needed for this scanner? */ | GENESYS_FLAG_SKIP_WARMUP | GENESYS_FLAG_OFFSET_CALIBRATION - | GENESYS_FLAG_CUSTOM_GAMMA + | GENESYS_FLAG_CUSTOM_GAMMA | GENESYS_FLAG_DARK_CALIBRATION, GENESYS_HAS_SCAN_SW | GENESYS_HAS_PAGE_LOADED_SW | GENESYS_HAS_CALIBRATE, 100, @@ -2840,7 +3089,7 @@ static Genesys_Model syscan_docketport_685_model = { SANE_FIX (212.0), /* Size of scan area in mm (x) */ SANE_FIX (500), /* Size of scan area in mm (y) */ - SANE_FIX (3.0), /* Start of white strip in mm (y) */ + SANE_FIX (0.0), /* Start of white strip in mm (y) */ SANE_FIX (0.0), /* Start of black mark in mm (x) */ SANE_FIX (0.0), /* Start of scan area in TA mode in mm (x) */ @@ -2852,9 +3101,9 @@ static Genesys_Model syscan_docketport_685_model = { SANE_FIX (26.5), /* Size of scan area after paper sensor stops sensing document in mm */ - /* this is larger than needed -- accounts for second sensor head, which is a + /* this is larger than needed -- accounts for second sensor head, which is a calibration item */ - SANE_FIX (0.0), /* Amount of feeding needed to eject document + SANE_FIX (0.0), /* Amount of feeding needed to eject document after finishing scanning in mm */ 0, 0, 0, /* RGB CCD Line-distance correction in pixel */ @@ -2869,7 +3118,7 @@ static Genesys_Model syscan_docketport_685_model = { GENESYS_FLAG_LAZY_INIT /* Which flags are needed for this scanner? */ | GENESYS_FLAG_SKIP_WARMUP | GENESYS_FLAG_OFFSET_CALIBRATION - | GENESYS_FLAG_CUSTOM_GAMMA + | GENESYS_FLAG_CUSTOM_GAMMA | GENESYS_FLAG_DARK_CALIBRATION, GENESYS_HAS_SCAN_SW | GENESYS_HAS_PAGE_LOADED_SW | GENESYS_HAS_CALIBRATE, 100, @@ -2893,7 +3142,7 @@ static Genesys_Model syscan_docketport_485_model = { SANE_FIX (435.0), /* Size of scan area in mm (x) */ SANE_FIX (511), /* Size of scan area in mm (y) */ - SANE_FIX (3.0), /* Start of white strip in mm (y) */ + SANE_FIX (0.0), /* Start of white strip in mm (y) */ SANE_FIX (0.0), /* Start of black mark in mm (x) */ SANE_FIX (0.0), /* Start of scan area in TA mode in mm (x) */ @@ -2905,9 +3154,9 @@ static Genesys_Model syscan_docketport_485_model = { SANE_FIX (26.5), /* Size of scan area after paper sensor stops sensing document in mm */ - /* this is larger than needed -- accounts for second sensor head, which is a + /* this is larger than needed -- accounts for second sensor head, which is a calibration item */ - SANE_FIX (0.0), /* Amount of feeding needed to eject document + SANE_FIX (0.0), /* Amount of feeding needed to eject document after finishing scanning in mm */ 0, 0, 0, /* RGB CCD Line-distance correction in pixel */ @@ -2922,7 +3171,7 @@ static Genesys_Model syscan_docketport_485_model = { GENESYS_FLAG_LAZY_INIT /* Which flags are needed for this scanner? */ | GENESYS_FLAG_SKIP_WARMUP | GENESYS_FLAG_OFFSET_CALIBRATION - | GENESYS_FLAG_CUSTOM_GAMMA + | GENESYS_FLAG_CUSTOM_GAMMA | GENESYS_FLAG_DARK_CALIBRATION, GENESYS_HAS_SCAN_SW | GENESYS_HAS_PAGE_LOADED_SW | GENESYS_HAS_CALIBRATE, 100, @@ -2946,7 +3195,7 @@ static Genesys_Model dct_docketport_487_model = { SANE_FIX (435.0), /* Size of scan area in mm (x) */ SANE_FIX (511), /* Size of scan area in mm (y) */ - SANE_FIX (3.0), /* Start of white strip in mm (y) */ + SANE_FIX (0.0), /* Start of white strip in mm (y) */ SANE_FIX (0.0), /* Start of black mark in mm (x) */ SANE_FIX (0.0), /* Start of scan area in TA mode in mm (x) */ @@ -2958,9 +3207,9 @@ static Genesys_Model dct_docketport_487_model = { SANE_FIX (26.5), /* Size of scan area after paper sensor stops sensing document in mm */ - /* this is larger than needed -- accounts for second sensor head, which is a + /* this is larger than needed -- accounts for second sensor head, which is a calibration item */ - SANE_FIX (0.0), /* Amount of feeding needed to eject document + SANE_FIX (0.0), /* Amount of feeding needed to eject document after finishing scanning in mm */ 0, 0, 0, /* RGB CCD Line-distance correction in pixel */ @@ -2976,7 +3225,7 @@ static Genesys_Model dct_docketport_487_model = { | GENESYS_FLAG_SKIP_WARMUP | GENESYS_FLAG_OFFSET_CALIBRATION | GENESYS_FLAG_DARK_CALIBRATION - | GENESYS_FLAG_CUSTOM_GAMMA + | GENESYS_FLAG_CUSTOM_GAMMA | GENESYS_FLAG_UNTESTED, GENESYS_HAS_SCAN_SW | GENESYS_HAS_PAGE_LOADED_SW | GENESYS_HAS_CALIBRATE, 100, @@ -3012,7 +3261,7 @@ static Genesys_Model visioneer_7100_model = { SANE_FIX (0.0), /* Size of scan area after paper sensor stops sensing document in mm */ - SANE_FIX (0.0), /* Amount of feeding needed to eject document + SANE_FIX (0.0), /* Amount of feeding needed to eject document after finishing scanning in mm */ 48, 24, 0, /* RGB CCD Line-distance correction in pixel */ @@ -3067,7 +3316,7 @@ static Genesys_Model xerox_2400_model = { SANE_FIX (0.0), /* Size of scan area after paper sensor stops sensing document in mm */ - SANE_FIX (0.0), /* Amount of feeding needed to eject document + SANE_FIX (0.0), /* Amount of feeding needed to eject document after finishing scanning in mm */ 48, 24, 0, /* RGB CCD Line-distance correction in pixel */ @@ -3111,7 +3360,7 @@ static Genesys_Model xerox_travelscanner_model = { SANE_FIX (220.0), /* Size of scan area in mm (x) */ SANE_FIX (511), /* Size of scan area in mm (y) */ - SANE_FIX (3.0), /* Start of white strip in mm (y) */ + SANE_FIX (0.0), /* Start of white strip in mm (y) */ SANE_FIX (0.0), /* Start of black mark in mm (x) */ SANE_FIX (0.0), /* Start of scan area in TA mode in mm (x) */ @@ -3123,7 +3372,7 @@ static Genesys_Model xerox_travelscanner_model = { SANE_FIX (16.0), /* Size of scan area after paper sensor stops sensing document in mm */ - SANE_FIX (0.0), /* Amount of feeding needed to eject document + SANE_FIX (0.0), /* Amount of feeding needed to eject document after finishing scanning in mm */ 0, 0, 0, /* RGB CCD Line-distance correction in pixel */ @@ -3139,7 +3388,7 @@ static Genesys_Model xerox_travelscanner_model = { GENESYS_FLAG_LAZY_INIT /* Which flags are needed for this scanner? */ | GENESYS_FLAG_SKIP_WARMUP | GENESYS_FLAG_OFFSET_CALIBRATION - | GENESYS_FLAG_CUSTOM_GAMMA + | GENESYS_FLAG_CUSTOM_GAMMA | GENESYS_FLAG_DARK_CALIBRATION, GENESYS_HAS_SCAN_SW | GENESYS_HAS_PAGE_LOADED_SW | GENESYS_HAS_CALIBRATE, 100, @@ -3176,7 +3425,7 @@ static Genesys_Model plustek_3600_model = { sensing document in mm */ SANE_FIX (0.0), /* Amount of feeding needed to eject document after finishing scanning in mm */ - + 0, 24, 48, /* RGB CCD Line-distance correction in pixel */ COLOR_ORDER_RGB, /* Order of the CCD/CIS colors */ @@ -3199,7 +3448,7 @@ static Genesys_Model plustek_3600_model = { 7, 200 }; - + static Genesys_Model hpn6310_model = { "hewlett-packard-scanjet-N6310", /* Name */ "Hewlett Packard", /* Device vendor string */ @@ -3288,7 +3537,7 @@ static Genesys_Model plustek_3800_model = { SANE_FIX (0.0), /* Size of scan area after paper sensor stops sensing document in mm */ - SANE_FIX (0.0), /* Amount of feeding needed to eject document + SANE_FIX (0.0), /* Amount of feeding needed to eject document after finishing scanning in mm */ 0, 24, 48, /* RGB CCD Line-distance correction in pixel */ @@ -3340,7 +3589,7 @@ static Genesys_Model canon_formula101_model = { SANE_FIX (0.0), /* Size of scan area after paper sensor stops sensing document in mm */ - SANE_FIX (0.0), /* Amount of feeding needed to eject document + SANE_FIX (0.0), /* Amount of feeding needed to eject document after finishing scanning in mm */ 0, 24, 48, /* RGB CCD Line-distance correction in pixel */ @@ -3382,6 +3631,7 @@ static Genesys_USB_Device_Entry genesys_usb_device_list[] = { {0x04a7, 0x04ac, &xerox_travelscanner_model}, {0x04a9, 0x2213, &canon_lide_50_model}, {0x04a9, 0x221c, &canon_lide_60_model}, + {0x04a9, 0x2214, &canon_lide_80_model}, {0x07b3, 0x0900, &plustek_3600_model}, {0x0a17, 0x3210, &pentax_dsmobile_600_model}, {0x04f9, 0x2038, &pentax_dsmobile_600_model}, /* clone, only usb id is different */ @@ -3410,6 +3660,11 @@ static Genesys_USB_Device_Entry genesys_usb_device_list[] = { {0x03f0, 0x4705, &hpn6310_model}, /* GL124 devices */ {0x04a9, 0x1909, &canon_lide_110_model}, + {0x04a9, 0x190e, &canon_lide_120_model}, {0x04a9, 0x190a, &canon_lide_210_model}, + {0x04a9, 0x190f, &canon_lide_220_model}, {0, 0, NULL} }; + +#define MAX_SCANNERS (sizeof(genesys_usb_device_list) / \ + sizeof(genesys_usb_device_list[0])) diff --git a/backend/genesys_gl124.c b/backend/genesys_gl124.c index 9e2fb8a..eaac873 100644 --- a/backend/genesys_gl124.c +++ b/backend/genesys_gl124.c @@ -301,123 +301,6 @@ static Sensor_Profile *get_sensor_profile(int sensor_type, int dpi, int half_ccd return &(sensors[idx]); } -/** @brief motor profile - * search for the database of motor profiles and get the best one. Each - * profile is at full step and at a reference exposure. Use LiDE 110 table - * by default. - * @param motor_type motor id - * @param exposure exposure time - * @return a pointer to a Motor_Profile struct - */ -static Motor_Profile *get_motor_profile(int motor_type, int exposure) -{ - unsigned int i; - int idx; - - i=0; - idx=-1; - while(i<sizeof(motors)/sizeof(Motor_Profile)) - { - /* exact match */ - if(motors[i].motor_type==motor_type && motors[i].exposure==exposure) - { - return &(motors[i]); - } - - /* closest match */ - if(motors[i].motor_type==motor_type) - { - if(idx<0) - { - idx=i; - } - else - { - if(motors[i].exposure>=exposure - && motors[i].exposure<motors[idx].exposure) - { - idx=i; - } - } - } - i++; - } - - /* default fallback */ - if(idx<0) - { - DBG (DBG_warn,"%s: using default motor profile\n",__FUNCTION__); - idx=0; - } - - return &(motors[idx]); -} - -/** @brief generate slope table - * Generate the slope table to use for the scan using a reference slope - * table. - * @param slope pointer to the slope table to fill - * @param steps pointer to return used step number - * @param dpi desired motor resolution - * @param exposure exposure used - * @param base_dpi base resolution of the motor - * @param step_type step type used for scan - * @param factor shrink factor for the slope - * @param motor_type motor id - */ -static int gl124_slope_table(uint16_t *slope, - int *steps, - int dpi, - int exposure, - int base_dpi, - int step_type, - int factor, - int motor_type) -{ -int sum, i; -uint16_t target,current; -Motor_Profile *profile; - - /* required speed */ - target=((exposure * dpi) / base_dpi)>>step_type; - - /* fill result with target speed */ - for(i=0;i<SLOPE_TABLE_SIZE;i++) - slope[i]=target; - - profile=get_motor_profile(motor_type,exposure); - - /* use profile to build table */ - i=0; - sum=0; - - /* first step is used unmodified */ - current=profile->table[0]; - - /* loop on profile copying and apply step type */ - while(i<SLOPE_TABLE_SIZE && current>=target) - { - slope[i]=current; - sum+=slope[i]; - i++; - current=profile->table[i*factor]>>step_type; - } - if(i<3 && DBG_LEVEL >= DBG_warn) - { - DBG (DBG_warn,"%s: short slope table, failed to reach %d\n",__FUNCTION__,target); - } - - /* ensure minimal slope size */ - while(i<8) - { - sum+=slope[i]; - i++; - } - - /* return used steps and acceleration sum */ - *steps=i; - return sum; -} /* returns the max register bulk size */ static int @@ -732,7 +615,7 @@ gl124_init_registers (Genesys_Device * dev) * @param slope_table pointer to 16 bit values array of the slope table * @param steps number of elemnts in the slope table */ -static SANE_Status +GENESYS_STATIC SANE_Status gl124_send_slope_table (Genesys_Device * dev, int table_nr, uint16_t * slope_table, int steps) { @@ -922,24 +805,6 @@ static int gl124_compute_exposure(Genesys_Device *dev, int xres, int half_ccd) return sensor->exposure; } -/**@brief compute motor step type to use - * compute the step type (full, half, quarter, ...) to use based - * on target resolution - * @param dev device description - * @param exposure sensor exposure - * @return 0 for full step - * 1 for half step - * 2 for quarter step - * 3 for eighth step - */ -static int gl124_compute_step_type(Genesys_Device *dev, int exposure) -{ -Motor_Profile *profile; - - profile=get_motor_profile(dev->model->motor_type,exposure); - return profile->step_type; -} - static SANE_Status gl124_init_motor_regs_scan (Genesys_Device * dev, @@ -987,7 +852,7 @@ gl124_init_motor_regs_scan (Genesys_Device * dev, } else { - min_speed = 600; + min_speed = 900; if(dev->model->ccd_type==MOTOR_CANONLIDE110) { min_speed = 300; @@ -1033,14 +898,15 @@ gl124_init_motor_regs_scan (Genesys_Device * dev, sanei_genesys_set_double(reg,REG_SCANFED,4); /* scan and backtracking slope table */ - gl124_slope_table(scan_table, - &scan_steps, - yres, - scan_exposure_time, - dev->motor.base_ydpi, - scan_step_type, - factor, - dev->model->motor_type); + sanei_genesys_slope_table(scan_table, + &scan_steps, + yres, + scan_exposure_time, + dev->motor.base_ydpi, + scan_step_type, + factor, + dev->model->motor_type, + motors); RIE(gl124_send_slope_table (dev, SCAN_TABLE, scan_table, scan_steps)); RIE(gl124_send_slope_table (dev, BACKTRACK_TABLE, scan_table, scan_steps)); @@ -1049,18 +915,22 @@ gl124_init_motor_regs_scan (Genesys_Device * dev, /* fast table */ fast_dpi=yres; + + /* if (scan_mode != SCAN_MODE_COLOR) { fast_dpi*=3; } - gl124_slope_table(fast_table, - &fast_steps, - fast_dpi, - scan_exposure_time, - dev->motor.base_ydpi, - scan_step_type, - factor, - dev->model->motor_type); + */ + sanei_genesys_slope_table(fast_table, + &fast_steps, + fast_dpi, + scan_exposure_time, + dev->motor.base_ydpi, + scan_step_type, + factor, + dev->model->motor_type, + motors); RIE(gl124_send_slope_table (dev, STOP_TABLE, fast_table, fast_steps)); RIE(gl124_send_slope_table (dev, FAST_TABLE, fast_table, fast_steps)); @@ -1505,10 +1375,8 @@ gl124_init_optical_regs_scan (Genesys_Device * dev, * * this function sets up the scanner to scan in normal or single line mode */ -#ifndef UNIT_TESTING -static -#endif - SANE_Status +GENESYS_STATIC +SANE_Status gl124_init_scan_regs (Genesys_Device * dev, Genesys_Register_Set * reg, float xres, /*dpi */ @@ -1519,6 +1387,8 @@ gl124_init_scan_regs (Genesys_Device * dev, float lines, unsigned int depth, unsigned int channels, + __sane_unused__ int scan_method, + int scan_mode, int color_filter, unsigned int flags) { @@ -1619,7 +1489,7 @@ gl124_init_scan_regs (Genesys_Device * dev, else { exposure_time = gl124_compute_exposure (dev, used_res, half_ccd); - scan_step_type = gl124_compute_step_type(dev, exposure_time); + scan_step_type = sanei_genesys_compute_step_type(motors, dev->model->motor_type, exposure_time); } DBG (DBG_info, "gl124_init_scan_regs : exposure_time=%d pixels\n", exposure_time); @@ -1628,8 +1498,7 @@ gl124_init_scan_regs (Genesys_Device * dev, /*** optical parameters ***/ /* in case of dynamic lineart, we use an internal 8 bit gray scan * to generate 1 lineart data */ - if ((flags & SCAN_FLAG_DYNAMIC_LINEART) - && (dev->settings.scan_mode == SCAN_MODE_LINEART)) + if ((flags & SCAN_FLAG_DYNAMIC_LINEART) && (scan_mode == SCAN_MODE_LINEART)) { depth = 8; } @@ -1693,7 +1562,7 @@ gl124_init_scan_regs (Genesys_Device * dev, dev->model->is_cis ? lincnt * channels : lincnt, dummy, move, - dev->settings.scan_mode, + scan_mode, mflags); if (status != SANE_STATUS_GOOD) return status; @@ -2188,7 +2057,6 @@ gl124_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) uint8_t val; float resolution; int loop = 0; - int scan_mode; DBG (DBG_proc, "gl124_slow_back_home (wait_until_home = %d)\n", wait_until_home); @@ -2240,27 +2108,44 @@ gl124_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) return SANE_STATUS_GOOD; } + /* feed a little first */ + if (strcmp (dev->model->name, "canon-lide-210") == 0) + { + status = gl124_feed (dev, 20, SANE_TRUE); + if (status != SANE_STATUS_GOOD) + { + DBG (DBG_error, "%s: failed to do initial feed: %s\n", __FUNCTION__, sane_strstatus (status)); + return status; + } + } + memcpy (local_reg, dev->reg, GENESYS_GL124_MAX_REGS * sizeof (Genesys_Register_Set)); resolution=sanei_genesys_get_lowest_dpi(dev); - /* TODO add scan_mode to the API */ - scan_mode= dev->settings.scan_mode; - dev->settings.scan_mode=SCAN_MODE_GRAY; - gl124_init_scan_regs (dev, - local_reg, - resolution, - resolution, - 100, - 30000, - 100, - 100, - 8, - 1, - 0, - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA | - SCAN_FLAG_IGNORE_LINE_DISTANCE); - dev->settings.scan_mode=scan_mode; + status = gl124_init_scan_regs (dev, + local_reg, + resolution, + resolution, + 100, + 30000, + 100, + 100, + 8, + 1, + dev->settings.scan_method, + SCAN_MODE_GRAY, + 0, + SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA | + SCAN_FLAG_IGNORE_LINE_DISTANCE); + if (status != SANE_STATUS_GOOD) + { + DBG (DBG_error, + "gl124_slow_back_home: failed to set up registers: %s\n", + sane_strstatus (status)); + DBGCOMPLETED; + return status; + } /* clear scan and feed count */ RIE (sanei_genesys_write_register (dev, REG0D, REG0D_CLRLNCNT | REG0D_CLRMCNT)); @@ -2328,12 +2213,13 @@ gl124_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) /** @brief moves the slider to steps at motor base dpi * @param dev device to work on * @param steps number of steps to move + * @param reverse true is moving backward * */ #ifndef UNIT_TESTING static #endif SANE_Status -gl124_feed (Genesys_Device * dev, unsigned int steps) +gl124_feed (Genesys_Device * dev, unsigned int steps, int reverse) { Genesys_Register_Set local_reg[GENESYS_GL124_MAX_REGS]; SANE_Status status; @@ -2348,22 +2234,30 @@ gl124_feed (Genesys_Device * dev, unsigned int steps) memcpy (local_reg, dev->reg, GENESYS_GL124_MAX_REGS * sizeof (Genesys_Register_Set)); resolution=sanei_genesys_get_lowest_ydpi(dev); - gl124_init_scan_regs (dev, - local_reg, - resolution, - resolution, - 0, - steps, - 100, - 3, - 8, - 3, - dev->settings.color_filter, - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA | - SCAN_FLAG_FEEDING | - SCAN_FLAG_DISABLE_BUFFER_FULL_MOVE | - SCAN_FLAG_IGNORE_LINE_DISTANCE); + status = gl124_init_scan_regs (dev, + local_reg, + resolution, + resolution, + 0, + steps, + 100, + 3, + 8, + 3, + dev->settings.scan_method, + SCAN_MODE_COLOR, + dev->settings.color_filter, + SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA | + SCAN_FLAG_FEEDING | + SCAN_FLAG_DISABLE_BUFFER_FULL_MOVE | + SCAN_FLAG_IGNORE_LINE_DISTANCE); + if (status != SANE_STATUS_GOOD) + { + DBG (DBG_error, "%s: failed to set up registers: %s\n", __FUNCTION__, sane_strstatus (status)); + DBGCOMPLETED; + return status; + } /* set exposure to zero */ sanei_genesys_set_triple(local_reg,REG_EXPR,0); @@ -2378,6 +2272,13 @@ gl124_feed (Genesys_Device * dev, unsigned int steps) r = sanei_genesys_get_address (local_reg, REG01); r->value &= ~REG01_SCAN; + /* set up for reverse if needed */ + if(reverse) + { + r = sanei_genesys_get_address (local_reg, REG02); + r->value |= REG02_MTRREV; + } + /* send registers */ RIE (dev->model->cmd_set->bulk_write_register (dev, local_reg, GENESYS_GL124_MAX_REGS)); @@ -2422,7 +2323,7 @@ gl124_search_start_position (Genesys_Device * dev) int pixels = 600; int dpi = 300; - DBG (DBG_proc, "gl124_search_start_position\n"); + DBGSTART; memcpy (local_reg, dev->reg, GENESYS_GL124_MAX_REGS * sizeof (Genesys_Register_Set)); @@ -2430,8 +2331,19 @@ gl124_search_start_position (Genesys_Device * dev) /* sets for a 200 lines * 600 pixels */ /* normal scan with no shading */ - status = gl124_init_scan_regs (dev, local_reg, dpi, dpi, 0, 0, /*we should give a small offset here~60 steps */ - 600, dev->model->search_lines, 8, 1, 1, /*green */ + status = gl124_init_scan_regs (dev, + local_reg, + dpi, + dpi, + 0, + 0, /*we should give a small offset here~60 steps */ + 600, + dev->model->search_lines, + 8, + 1, + dev->settings.scan_method, + SCAN_MODE_GRAY, + 1, /*green */ SCAN_FLAG_DISABLE_SHADING | SCAN_FLAG_DISABLE_GAMMA | SCAN_FLAG_IGNORE_LINE_DISTANCE | @@ -2521,6 +2433,7 @@ gl124_search_start_position (Genesys_Device * dev) } free (data); + DBGCOMPLETED; return SANE_STATUS_GOOD; } @@ -2553,6 +2466,8 @@ gl124_init_regs_for_coarse_calibration (Genesys_Device * dev) 20, 16, channels, + dev->settings.scan_method, + dev->settings.scan_mode, dev->settings.color_filter, SCAN_FLAG_DISABLE_SHADING | SCAN_FLAG_DISABLE_GAMMA | @@ -2637,6 +2552,8 @@ gl124_init_regs_for_shading (Genesys_Device * dev) dev->calib_lines, 16, dev->calib_channels, + dev->settings.scan_method, + SCAN_MODE_COLOR, 0, SCAN_FLAG_DISABLE_SHADING | SCAN_FLAG_DISABLE_GAMMA | @@ -2753,7 +2670,7 @@ gl124_init_regs_for_scan (Genesys_Device * dev) if(channels*dev->settings.yres>=600 && move>700) { - status = gl124_feed (dev, move-500); + status = gl124_feed (dev, move-500, SANE_FALSE); if (status != SANE_STATUS_GOOD) { DBG (DBG_error, "%s: failed to move to scan area\n",__FUNCTION__); @@ -2791,6 +2708,8 @@ gl124_init_regs_for_scan (Genesys_Device * dev) dev->settings.lines, depth, channels, + dev->settings.scan_method, + dev->settings.scan_mode, dev->settings.color_filter, flags); @@ -2964,6 +2883,8 @@ move_to_calibration_area (Genesys_Device * dev) 1, 8, 3, + dev->settings.scan_method, + SCAN_MODE_COLOR, dev->settings.color_filter, SCAN_FLAG_DISABLE_SHADING | SCAN_FLAG_DISABLE_GAMMA | @@ -3062,6 +2983,8 @@ gl124_led_calibration (Genesys_Device * dev) 1, depth, channels, + dev->settings.scan_method, + SCAN_MODE_COLOR, dev->settings.color_filter, SCAN_FLAG_DISABLE_SHADING | SCAN_FLAG_DISABLE_GAMMA | @@ -3250,6 +3173,8 @@ gl124_offset_calibration (Genesys_Device * dev) lines, bpp, channels, + dev->settings.scan_method, + SCAN_MODE_COLOR, dev->settings.color_filter, SCAN_FLAG_DISABLE_SHADING | SCAN_FLAG_DISABLE_GAMMA | @@ -3429,6 +3354,8 @@ gl124_coarse_gain_calibration (Genesys_Device * dev, int dpi) lines, bpp, channels, + dev->settings.scan_method, + SCAN_MODE_COLOR, dev->settings.color_filter, SCAN_FLAG_DISABLE_SHADING | SCAN_FLAG_DISABLE_GAMMA | @@ -3558,6 +3485,8 @@ gl124_init_regs_for_warmup (Genesys_Device * dev, 1, 8, *channels, + dev->settings.scan_method, + SCAN_MODE_COLOR, dev->settings.color_filter, SCAN_FLAG_DISABLE_SHADING | SCAN_FLAG_DISABLE_GAMMA | @@ -3599,12 +3528,13 @@ gl124_init_gpio (Genesys_Device * dev) DBGSTART; /* per model GPIO layout */ - if (strcmp (dev->model->name, "canon-lide-110") == 0) + if ((strcmp (dev->model->name, "canon-lide-110") == 0) + ||(strcmp (dev->model->name, "canon-lide-120") == 0)) { idx = 0; } else - { /* canon LiDE 210 case */ + { /* canon LiDE 210 and 220 case */ idx = 1; } @@ -3632,12 +3562,13 @@ gl124_init_memory_layout (Genesys_Device * dev) DBGSTART; /* point to per model memory layout */ - if (strcmp (dev->model->name, "canon-lide-110") == 0) + if ((strcmp (dev->model->name, "canon-lide-110") == 0) + ||(strcmp (dev->model->name, "canon-lide-120") == 0)) { idx = 0; } else - { /* canon LiDE 210 case */ + { /* canon LiDE 210 and 220 case */ idx = 1; } @@ -3878,7 +3809,8 @@ static Genesys_Command_Set gl124_cmd_set = { NULL, gl124_send_shading_data, gl124_calculate_current_setup, - gl124_boot + gl124_boot, + gl124_init_scan_regs }; SANE_Status diff --git a/backend/genesys_gl124.h b/backend/genesys_gl124.h index 1b78af3..25f99c3 100644 --- a/backend/genesys_gl124.h +++ b/backend/genesys_gl124.h @@ -614,24 +614,40 @@ static size_t order_0213[]={0,2,1,3}; * database of sensor profiles */ static Sensor_Profile sensors[]={ - {CIS_CANONLIDE210, 600, 1, 2768, 0x1e, 0x9f, 0x55, 2584, 154, 101, 388, 574, 393, NULL , 0x00, 0x0c, 0x20, 0x21}, + /* LiDE 110 */ + {CIS_CANONLIDE110, 600, 1, 2768, 0x1e, 0x9f, 0x55, 2584, 154, 101, 388, 574, 393, NULL , 0x00, 0x0c, 0x20, 0x21}, {CIS_CANONLIDE110, 600, 0, 5360, 0x1e, 0x9f, 0x55, 5168, 163, 101, 388, 574, 393, NULL , 0x00, 0x0a, 0x20, 0x21}, {CIS_CANONLIDE110, 1200, 0, 10528, 0x1e, 0x9f, 0x55, 5168, 163, 101, 388, 574, 393, order_01 , 0x00, 0x08, 0x20, 0x22}, {CIS_CANONLIDE110, 2400, 0, 20864, 0x1e, 0x9f, 0x55, 5168, 163, 4679, 6839, 8401, 6859, order_0213, 0x00, 0x06, 0x20, 0x24}, + + /* LiDE 120 */ + {CIS_CANONLIDE120, 600, 1, 2768, 0x0f, 0x9f, 0x55, 2552, 112, 94, 388, 574, 393, NULL , 0x00, 0x02, 0x20, 0x21}, + {CIS_CANONLIDE120, 600, 0, 5360, 0x0f, 0x9f, 0x55, 5168, 163, 94, 388, 574, 393, NULL , 0x00, 0x0a, 0x20, 0x21}, + {CIS_CANONLIDE120, 1200, 0, 10528, 0x0f, 0x9f, 0x55, 5168, 163, 94, 388, 574, 393, order_01 , 0x00, 0x08, 0x20, 0x22}, + {CIS_CANONLIDE120, 2400, 0, 20864, 0x0f, 0x9f, 0x55, 5168, 163, 4679, 6839, 8401, 6859, order_0213, 0x00, 0x06, 0x20, 0x24}, + + /* LiDE 210 */ {CIS_CANONLIDE210, 600, 1, 2768, 0x1e, 0x9f, 0x55, 2584, 154, 101, 388, 574, 393, NULL , 0x00, 0x0c, 0x20, 0x21}, {CIS_CANONLIDE210, 600, 0, 5360, 0x1e, 0x9f, 0x55, 5168, 163, 101, 388, 574, 393, NULL , 0x00, 0x0a, 0x20, 0x21}, {CIS_CANONLIDE210, 1200, 0, 10528, 0x1e, 0x9f, 0x55, 5168, 163, 101, 388, 574, 393, order_01 , 0x00, 0x08, 0x20, 0x22}, {CIS_CANONLIDE210, 2400, 0, 20864, 0x1e, 0x9f, 0x55, 5168, 163, 4679, 6839, 8401, 6859, order_0213, 0x00, 0x06, 0x20, 0x24}, + + /* LiDE 220 */ + {CIS_CANONLIDE220, 600, 1, 2768, 0x0f, 0x9f, 0x55, 2584, 154, 101, 388, 574, 393, NULL , 0x00, 0x0c, 0x20, 0x21}, + {CIS_CANONLIDE220, 600, 0, 5360, 0x0f, 0x9f, 0x55, 5168, 163, 101, 388, 574, 393, NULL , 0x00, 0x0a, 0x20, 0x21}, + {CIS_CANONLIDE220, 1200, 0, 10528, 0x0f, 0x9f, 0x55, 5168, 163, 101, 388, 574, 393, order_01 , 0x00, 0x08, 0x20, 0x22}, + {CIS_CANONLIDE220, 2400, 0, 20864, 0x0f, 0x9f, 0x55, 5168, 163, 4679, 6839, 8401, 6859, order_0213, 0x00, 0x06, 0x20, 0x24}, }; #define MOVE_DPI 200 #define MOVE_EXPOSURE 2304 -static uint32_t lide210_max[] = { 62496, 31296, 0}; -static uint32_t lide210_slow[] = { 62496, 7896, 0}; static uint32_t lide210_fast[] = { 62496, 2343, 2343, 2343, 2343, 2343, 2343, 2343, 2343, 2051, 1432, 1372, 1323, 1280, 1246, 1216, 1188, 1163, 1142, 1121, 1101, 1084, 1068, 1051, 1036, 1020, 1007, 995, 983, 971, 959, 949, 938, 929, 917, 908, 900, 891, 882, 874, 866, 857, 849, 843, 835, 829, 821, 816, 808, 802, 795, 789, 784, 778, 773, 765, 760, 755, 749, 744, 739, 734, 731, 726, 721, 716, 711, 707, 702, 698, 693, 690, 685, 682, 677, 672, 669, 665, 662, 657, 654, 650, 647, 644, 639, 637, 632, 629, 626, 622, 619, 617, 614, 610, 607, 604, 601, 599, 595, 592, 589, 587, 584, 581, 579, 576, 572, 570, 567, 564, 562, 559, 557, 554, 552, 549, 547, 544, 542, 539, 538, 536, 533, 531, 529, 526, 524, 522, 519, 518, 516, 513, 511, 509, 506, 505, 503, 501, 498, 497, 495, 493, 491, 490, 487, 485, 483, 482, 480, 477, 476, 474, 472, 470, 469, 467, 465, 464, 462, 460, 458, 456, 455, 453, 451, 450, 448, 447, 445, 444, 442, 440, 439, 437, 436, 434, 433, 431, 430, 428, 427, 425, 423, 422, 420, 419, 417, 417, 415, 414, 413, 411, 410, 408, 407, 405, 404, 402, 401, 400, 399, 398, 396, 395, 393, 392, 391, 390, 389, 387, 386, 385, 383, 382, 381, 380, 379, 377, 376, 375, 374, 373, 371, 370, 369, 368, 367, 366, 364, 363, 363, 361, 360, 359, 358, 357, 356, 355, 353, 352, 352, 350, 349, 348, 347, 346, 345, 344, 343, 342, 341, 340, 339, 338, 335, 335, 0}; -static uint32_t lide210_ok[] = { 62496, 2343, 2343, 2343, 2343, 2343, 2343, 2343, 2343, 2051, 1961, 1901, 1852, 1809, 1775, 1745, 1717, 1692, 1671, 1650, 1630, 1613, 1597,1580,1565,1549,1536,1524,1512,1500,1488,1478,1467,1458,1446,1437,1429,1420,1411,1403,1395,1386,1378,1372,1364,1358,1350,1345,1337,1331,1324,1318,1313,1307,1302,1294,1289,1284,1278,1273,1268,1263,1260,1255,1250,1245,1240,1236,1231,1227,1222,1219,1214,1211,1206,1201,1198,1194,1191,1186,1183,1179,1176,1173,1168,1166,1161,1158,1155,1151,1148,1146,1143,1139,1136,1133,1130,1128,1124,1121,1118,1116,1113,1110,1108,1105,1101,1099,1096,1093,1091,1088,1086,1083,1081,1078,1076,1073,1071,1068,1067,1065,1062,1060,1058,1055,1053,1051,1048,1047,1045,1042,1040,1038,1035,1034,1032,1030,1027,1026,1024,1022,1020,1019,1016,1014,1012,1011,1009,1006,1005,1003,1001,999,998,996,994,993,991,989,987,985,984,982,980,979,977,976,974,973,971,969,968,966,965,963,962,960,959,957,956,954,952,951,949,948,946,946,944,943,942,940,939,937,936,934,933,931,930,929,928,927,925,924,922,921,920,919,918,916,915,914,912,911,910,909,908,906,905,904,903,902,900,899,898,897,896,895,893,892,892,890,889,888,887,886,885,884,882,881,881,879,878,877,876,875,874,873,872,871,870,869,868,867,864,864, 0}; +static uint32_t lide110_ok[] = { 62496, 2343, 2343, 2343, 2343, 2343, 2343, 2343, 2343, 2051, 1961, 1901, 1852, 1809, 1775, 1745, 1717, 1692, 1671, 1650, 1630, 1613, 1597,1580,1565,1549,1536,1524,1512,1500,1488,1478,1467,1458,1446,1437,1429,1420,1411,1403,1395,1386,1378,1372,1364,1358,1350,1345,1337,1331,1324,1318,1313,1307,1302,1294,1289,1284,1278,1273,1268,1263,1260,1255,1250,1245,1240,1236,1231,1227,1222,1219,1214,1211,1206,1201,1198,1194,1191,1186,1183,1179,1176,1173,1168,1166,1161,1158,1155,1151,1148,1146,1143,1139,1136,1133,1130,1128,1124,1121,1118,1116,1113,1110,1108,1105,1101,1099,1096,1093,1091,1088,1086,1083,1081,1078,1076,1073,1071,1068,1067,1065,1062,1060,1058,1055,1053,1051,1048,1047,1045,1042,1040,1038,1035,1034,1032,1030,1027,1026,1024,1022,1020,1019,1016,1014,1012,1011,1009,1006,1005,1003,1001,999,998,996,994,993,991,989,987,985,984,982,980,979,977,976,974,973,971,969,968,966,965,963,962,960,959,957,956,954,952,951,949,948,946,946,944,943,942,940,939,937,936,934,933,931,930,929,928,927,925,924,922,921,920,919,918,916,915,914,912,911,910,909,908,906,905,904,903,902,900,899,898,897,896,895,893,892,892,890,889,888,887,886,885,884,882,881,881,879,878,877,876,875,874,873,872,871,870,869,868,867,864,857, 849, 843, 835, 829, 821, 816, 808, 802, 795, 789, 784, 778, 773, 765, 760, 755, 749, 744, 739, 734, 731, 726, 721, 716, 711, 707, 702, 698, 693, 690, 685, 682, 677, 672, 669, 665, 662, 657, 654, 650, 647, 644, 639, 637, 632, 629, 626, 622, 619, 617, 614, 610, 607, 604, 601, 599, 595, 592, 589, 587, 584, 581, 579, 576, 572, 570, 567, 564, 562, 559, 557, 554, 552, 549, 547, 544, 542, 539, 538, 536, 533, 531, 529, 526, 524, 522, 519, 518, 516, 513, 511, 509, 506, 505, 503, 501, 498, 497, 495, 493, 491, 490, 487, 485, 483, 482, 480, 477, 476, 474, 472, 470, 469, 467, 465, 464, 462, 460, 458, 456, 455, 453, 451, 450, 448, 447, 445, 444, 442, 440, 439, 437, 436, 434, 433, 431, 430, 428, 427, 425, 423, 422, 420, 419, 417, 417, 415, 414, 413, 411, 410, 408, 407, 405, 404, 402, 401, 400, 399, 398, 396, 395, 393, 392, 391, 390, 389, 387, 386, 385, 383, 382, 381, 380, 379, 377, 376, 375, 374, 373, 371, 370, 369, 368, 367, 366, 364, 363, 363, 361, 360, 359, 358, 357, 356, 355, 353, 352, 352, 350, 349, 348, 347, 346, 345, 344, 343, 342, 341, 340, 339, 338, 335, 335, 0}; +static uint32_t lide110_slow[] = { 62496, 7896, 2632, 0}; +static uint32_t lide110_max[] = { 62496, 31296, 10432, 0}; +static uint32_t lide210_max[] = { 62496, 31296, 20864, 10432, 0}; /** * database of motor profiles @@ -641,31 +657,31 @@ static uint32_t lide210_ok[] = { 62496, 2343, 2343, 2343, 2343, 2343, 2343, 23 /* NEXT LPERIOD=PREVIOUS*2-192 */ static Motor_Profile motors[]={ {MOTOR_CANONLIDE110, 2768, 0, lide210_fast}, - {MOTOR_CANONLIDE110, 5360, 0, lide210_ok}, - {MOTOR_CANONLIDE110, 10528, 1, lide210_slow}, - {MOTOR_CANONLIDE110, 20864, 2, lide210_max}, + {MOTOR_CANONLIDE110, 5360, 0, lide110_ok}, + {MOTOR_CANONLIDE110, 10528, 1, lide110_slow}, + {MOTOR_CANONLIDE110, 20864, 2, lide110_max}, {MOTOR_CANONLIDE210, 2768, 0, lide210_fast}, - {MOTOR_CANONLIDE210, 5360, 0, lide210_ok}, - {MOTOR_CANONLIDE210, 10528, 1, lide210_slow}, + {MOTOR_CANONLIDE210, 5360, 0, lide110_ok}, + {MOTOR_CANONLIDE210, 10528, 1, lide110_slow}, {MOTOR_CANONLIDE210, 20864, 2, lide210_max}, {0, 0, 0, NULL}, }; /* *INDENT-ON* */ - -#ifndef UNIT_TESTING -static -#endif - SANE_Status gl124_init_scan_regs (Genesys_Device * dev, - Genesys_Register_Set * reg, - float xres, /*dpi */ - float yres, /*dpi */ - float startx, /*optical_res, from dummy_pixel+1 */ - float starty, /*base_ydpi, from home! */ - float pixels, - float lines, - unsigned int depth, - unsigned int channels, - int color_filter, unsigned int flags); +GENESYS_STATIC +SANE_Status gl124_init_scan_regs (Genesys_Device * dev, + Genesys_Register_Set * reg, + float xres, /*dpi */ + float yres, /*dpi */ + float startx, /*optical_res, from dummy_pixel+1 */ + float starty, /*base_ydpi, from home! */ + float pixels, + float lines, + unsigned int depth, + unsigned int channels, + int scan_method, + int scan_mode, + int color_filter, + unsigned int flags); #ifndef UNIT_TESTING static @@ -700,12 +716,13 @@ SANE_Status gl124_send_shading_data (Genesys_Device * dev, uint8_t * data, int s #ifndef UNIT_TESTING static #endif -SANE_Status gl124_feed (Genesys_Device * dev, unsigned int steps); +SANE_Status gl124_feed (Genesys_Device * dev, unsigned int steps, int reverse); -#ifndef UNIT_TESTING -static -#endif -SANE_Status +GENESYS_STATIC SANE_Status gl124_stop_action (Genesys_Device * dev); +GENESYS_STATIC SANE_Status +gl124_send_slope_table (Genesys_Device * dev, int table_nr, + uint16_t * slope_table, int steps); + /* vim: set sw=2 cino=>2se-1sn-1s{s^-1st0(0u0 smarttab expandtab: */ diff --git a/backend/genesys_gl646.c b/backend/genesys_gl646.c index c7fa175..19b4585 100644 --- a/backend/genesys_gl646.c +++ b/backend/genesys_gl646.c @@ -8,44 +8,44 @@ Copyright (C) 2007 Luke <iceyfor@gmail.com> Copyright (C) 2011 Alexey Osipov <simba@lerlan.ru> for HP2400 description and tuning - + This file is part of the SANE package. - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - + As a special exception, the authors of SANE give permission for additional uses of the libraries contained in this release of SANE. - + The exception is that, if you link a SANE library with other files to produce an executable, this does not by itself cause the resulting executable to be covered by the GNU General Public License. Your use of that executable is in no way restricted on account of linking the SANE library code into it. - + This exception does not, however, invalidate any other reasons why the executable file might be covered by the GNU General Public License. - + If you submit changes to SANE to the maintainers to be included in a subsequent release, you agree by submitting the changes that those changes may be distributed with this exception intact. - + If you write modifications of your own for SANE, it is your choice whether to permit this exception to apply to your modifications. - If you do not wish that, delete this exception notice. + If you do not wish that, delete this exception notice. */ #undef BACKEND_NAME @@ -682,7 +682,7 @@ get_cksel (int sensor, int required, SANE_Bool color) * the device. * @param dev pointer to a struct describing the device * @param regs register set to fill - * @param scan_settings scan's settings + * @param scan_settings scan's settings * @param slope_table1 first motor table to fill * @param slope_table2 second motor table to fill * @param resolution dpi of the scan @@ -985,10 +985,8 @@ gl646_setup_registers (Genesys_Device * dev, /* gamma enable for scans */ if (dev->model->flags & GENESYS_FLAG_14BIT_GAMMA) regs[reg_0x05].value |= REG05_GMM14BIT; - if (depth < 16) - regs[reg_0x05].value |= REG05_GMMENB; - else - regs[reg_0x05].value &= ~REG05_GMMENB; + + regs[reg_0x05].value &= ~REG05_GMMENB; /* true CIS gray if needed */ if (dev->model->is_cis == SANE_TRUE && color == SANE_FALSE @@ -1120,7 +1118,7 @@ gl646_setup_registers (Genesys_Device * dev, /* we assume all scans are done with 2 tables */ /* - feedl = feed_steps - fast_slope_steps*2 - + feedl = feed_steps - fast_slope_steps*2 - (slow_slope_steps >> scan_step_type); */ /* but head has moved due to shading calibration => dev->scanhead_position_in_steps */ if (feedl > 0) @@ -1299,7 +1297,7 @@ gl646_setup_registers (Genesys_Device * dev, dev->current_setup.stagger = stagger; dev->current_setup.max_shift = max_shift + stagger; - /* total_bytes_to_read is the number of byte to send to frontend + /* total_bytes_to_read is the number of byte to send to frontend * total_bytes_read is the number of bytes sent to frontend * read_bytes_left is the number of bytes to read from the scanner */ @@ -1354,7 +1352,7 @@ gl646_setup_sensor (Genesys_Device * dev, Genesys_Register_Set * regs) } -/** Test if the ASIC works +/** Test if the ASIC works */ static SANE_Status gl646_asic_test (Genesys_Device * dev) @@ -1415,7 +1413,7 @@ gl646_asic_test (Genesys_Device * dev) size = 0x40000; verify_size = size + 0x80; /* todo: looks like the read size must be a multiple of 128? - otherwise the read doesn't succeed the second time after the scanner has + otherwise the read doesn't succeed the second time after the scanner has been plugged in. Very strange. */ data = (uint8_t *) malloc (size); @@ -1699,7 +1697,7 @@ gl646_init_regs (Genesys_Device * dev) } -/* Send slope table for motor movement +/* Send slope table for motor movement slope_table in machine byte order */ static SANE_Status @@ -1834,7 +1832,7 @@ gl646_set_ad_fe (Genesys_Device * dev, uint8_t set) } } } - /* + /* if (set == AFE_POWER_SAVE) { status = @@ -1864,7 +1862,7 @@ gl646_wm_hp3670 (Genesys_Device * dev, uint8_t set, int dpi) SANE_Status status = SANE_STATUS_GOOD; int i; - DBG (DBG_proc, "gl646_wm_hp3670: start \n"); + DBGSTART; switch (set) { case AFE_INIT: @@ -1971,7 +1969,7 @@ gl646_wm_hp3670 (Genesys_Device * dev, uint8_t set, int dpi) } } - DBG (DBG_proc, "gl646_wm_hp3670: success \n"); + DBGCOMPLETED; return status; } @@ -2169,8 +2167,8 @@ gl646_set_fe (Genesys_Device * dev, uint8_t set, int dpi) return SANE_STATUS_GOOD; } -/** Set values of analog frontend - * this this the public interface, the gl646 as to use one more +/** Set values of analog frontend + * this this the public interface, the gl646 as to use one more * parameter to work effectively, hence the redirection * @param dev device to set * @param set action to execute @@ -2229,16 +2227,14 @@ gl646_set_lamp_power (Genesys_Device * dev, * limited to AFE for now. * @param dev scanner's device * @param enable SANE_TRUE to enable power saving, SANE_FALSE to leave it - * @return allways SANE_STATUS_GOOD + * @return allways SANE_STATUS_GOOD */ -#ifndef UNIT_TESTING -static -#endif - SANE_Status +GENESYS_STATIC +SANE_Status gl646_save_power (Genesys_Device * dev, SANE_Bool enable) { - DBG (DBG_proc, "gl646_save_power: start\n"); + DBGSTART; DBG (DBG_info, "gl646_save_power: enable = %d\n", enable); if (enable) @@ -2250,7 +2246,7 @@ gl646_save_power (Genesys_Device * dev, SANE_Bool enable) gl646_set_fe (dev, AFE_INIT, 0); } - DBG (DBG_proc, "gl646_save_power: end\n"); + DBGCOMPLETED; return SANE_STATUS_GOOD; } @@ -2558,8 +2554,8 @@ gl646_detect_document_end (Genesys_Device * dev) DBG (DBG_info, "gl646_detect_document_end: no more document\n"); dev->document = SANE_FALSE; - /* adjust number of bytes to read: - * total_bytes_to_read is the number of byte to send to frontend + /* adjust number of bytes to read: + * total_bytes_to_read is the number of byte to send to frontend * total_bytes_read is the number of bytes sent to frontend * read_bytes_left is the number of bytes to read from the scanner */ @@ -2972,10 +2968,8 @@ gl646_end_scan (Genesys_Device * dev, Genesys_Register_Set * reg, * @param dev scanner's device * @param wait_until_home true if the function waits until head parked */ -#ifndef UNIT_TESTING -static -#endif - SANE_Status +GENESYS_STATIC +SANE_Status gl646_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) { SANE_Status status; @@ -3068,11 +3062,11 @@ gl646_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) settings.exposure_time = 0; settings.dynamic_lineart = SANE_FALSE; - status = setup_for_scan (dev, settings, SANE_TRUE, SANE_TRUE, SANE_TRUE); + status = setup_for_scan (dev, dev->reg, settings, SANE_TRUE, SANE_TRUE, SANE_TRUE); if (status != SANE_STATUS_GOOD) { DBG (DBG_error, - "%s: failed to setup for scan: %s\n", __FUNCTION__, + "%s: failed to setup for scan: %s\n", __FUNCTION__, sane_strstatus (status)); DBGCOMPLETED; return status; @@ -3088,7 +3082,7 @@ gl646_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) if (status != SANE_STATUS_GOOD) { DBG (DBG_error, - "%s: failed to set frontend: %s\n", __FUNCTION__, + "%s: failed to set frontend: %s\n", __FUNCTION__, sane_strstatus (status)); DBGCOMPLETED; return status; @@ -3153,7 +3147,7 @@ gl646_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) DBG (DBG_info, "gl646_slow_back_home: scanhead is still moving\n"); - DBG (DBG_proc, "gl646_slow_back_home: end\n"); + DBGCOMPLETED; return SANE_STATUS_GOOD; } @@ -3331,7 +3325,7 @@ gl646_init_regs_for_shading (Genesys_Device * dev) /* we don't want top offset, but we need right margin to be the same * than the one for the final scan */ - status = setup_for_scan (dev, settings, SANE_TRUE, SANE_FALSE, SANE_FALSE); + status = setup_for_scan (dev, dev->reg, settings, SANE_TRUE, SANE_FALSE, SANE_FALSE); /* used when sending shading calibration data */ dev->calib_pixels = settings.pixels; @@ -3377,7 +3371,7 @@ gl646_init_regs_for_shading (Genesys_Device * dev) /** - * set up registers for the actual scan. The scan's parameters are given + * set up registers for the actual scan. The scan's parameters are given * through the device settings. It allocates the scan buffers. */ static SANE_Status @@ -3385,36 +3379,44 @@ gl646_init_regs_for_scan (Genesys_Device * dev) { SANE_Status status; + DBGSTART; + /* park head after calibration if needed */ if (dev->scanhead_position_in_steps > 0 && dev->settings.scan_method == SCAN_METHOD_FLATBED) { - status = gl646_slow_back_home (dev, SANE_TRUE); - if (status != SANE_STATUS_GOOD) - { - return status; - - } + RIE(gl646_slow_back_home (dev, SANE_TRUE)); dev->scanhead_position_in_steps = 0; } - return setup_for_scan (dev, dev->settings, SANE_FALSE, SANE_TRUE, - SANE_TRUE); + RIE(setup_for_scan (dev, dev->reg, dev->settings, SANE_FALSE, SANE_TRUE, SANE_TRUE)); + + /* gamma is only enabled at final scan time */ + if (dev->settings.depth < 16) + dev->reg[reg_0x05].value |= REG05_GMMENB; + + DBGCOMPLETED; + return status; } /** - * set up registers for the actual scan. The scan's parameters are given + * set up registers for the actual scan. The scan's parameters are given * through the device settings. It allocates the scan buffers. * @param dev scanner's device + * @param regs registers to set up * @param settings settings of scan * @param split SANE_TRUE if move to scan area is split from scan, SANE_FALSE is * scan first moves to area * @param xcorrection take x geometry correction into account (fixed and detected offsets) * @param ycorrection take y geometry correction into account */ -static SANE_Status -setup_for_scan (Genesys_Device * dev, Genesys_Settings settings, - SANE_Bool split, SANE_Bool xcorrection, SANE_Bool ycorrection) +GENESYS_STATIC SANE_Status +setup_for_scan (Genesys_Device * dev, + Genesys_Register_Set *regs, + Genesys_Settings settings, + SANE_Bool split, + SANE_Bool xcorrection, + SANE_Bool ycorrection) { SANE_Status status = SANE_STATUS_GOOD; SANE_Bool color; @@ -3423,10 +3425,11 @@ setup_for_scan (Genesys_Device * dev, Genesys_Settings settings, uint16_t startx = 0, endx, pixels; int move = 0; - DBG (DBG_proc, "setup_for_scan: start\n"); + DBGSTART; DBG (DBG_info, - "setup_for_scan settings:\nResolution: %ux%uDPI\n" + "%s settings:\nResolution: %ux%uDPI\n" "Lines : %u\nPixels : %u\nStartpos : %.3f/%.3f\nScan mode : %d\nScan method: %s\n\n", + __FUNCTION__, settings.xres, settings.yres, settings.lines, settings.pixels, settings.tl_x, settings.tl_y, settings.scan_mode, settings.scan_method == SCAN_METHOD_FLATBED ? "flatbed" : "XPA"); @@ -3441,7 +3444,7 @@ setup_for_scan (Genesys_Device * dev, Genesys_Settings settings, channels = 1; color = SANE_FALSE; } - + depth=settings.depth; if (settings.scan_mode == SCAN_MODE_LINEART) { @@ -3479,17 +3482,16 @@ setup_for_scan (Genesys_Device * dev, Genesys_Settings settings, move += (settings.tl_y * dev->motor.optical_ydpi) / MM_PER_INCH; } - DBG (DBG_info, "setup_for_scan: move=%d steps\n", move); + DBG (DBG_info, "%s: move=%d steps\n", __FUNCTION__, move); /* security check */ if (move < 0) { - DBG (DBG_error, - "setup_for_scan: overriding negative move value %d\n", move); + DBG (DBG_error, "%s: overriding negative move value %d\n", __FUNCTION__, move); move = 0; } } - DBG (DBG_info, "setup_for_scan: move=%d steps\n", move); + DBG (DBG_info, "%s: move=%d steps\n", __FUNCTION__, move); /* pixels are allways given at full CCD optical resolution */ /* use detected left margin and fixed value */ @@ -3537,7 +3539,7 @@ setup_for_scan (Genesys_Device * dev, Genesys_Settings settings, /* set up correct values for scan (gamma and shading enabled) */ status = gl646_setup_registers (dev, - dev->reg, + regs, settings, dev->slope_table0, dev->slope_table1, @@ -3548,31 +3550,29 @@ setup_for_scan (Genesys_Device * dev, Genesys_Settings settings, depth); if (status != SANE_STATUS_GOOD) { - DBG (DBG_error, - "setup_for_scan: failed setup registers: %s\n", - sane_strstatus (status)); + DBG (DBG_error, "%s: failed setup registers: %s\n", __FUNCTION__, sane_strstatus (status)); return status; } /* now post-process values for register and options fine tuning */ /* select color filter based on settings */ - dev->reg[reg_0x04].value &= ~REG04_FILTER; + regs[reg_0x04].value &= ~REG04_FILTER; if (channels == 1) { switch (settings.color_filter) { /* red */ case 0: - dev->reg[reg_0x04].value |= 0x04; + regs[reg_0x04].value |= 0x04; break; /* green */ case 1: - dev->reg[reg_0x04].value |= 0x08; + regs[reg_0x04].value |= 0x08; break; /* blue */ case 2: - dev->reg[reg_0x04].value |= 0x0c; + regs[reg_0x04].value |= 0x0c; break; default: break; @@ -3582,27 +3582,23 @@ setup_for_scan (Genesys_Device * dev, Genesys_Settings settings, /* send computed slope tables */ status = gl646_send_slope_table (dev, 0, dev->slope_table0, - sanei_genesys_read_reg_from_set (dev->reg, 0x21)); + sanei_genesys_read_reg_from_set (regs, 0x21)); if (status != SANE_STATUS_GOOD) { - DBG (DBG_error, - "setup_for_scan: failed to send slope table 0: %s\n", - sane_strstatus (status)); + DBG (DBG_error, "%s: failed to send slope table 0: %s\n", __FUNCTION__, sane_strstatus (status)); return status; } status = gl646_send_slope_table (dev, 1, dev->slope_table1, - sanei_genesys_read_reg_from_set (dev->reg, 0x6b)); + sanei_genesys_read_reg_from_set (regs, 0x6b)); if (status != SANE_STATUS_GOOD) { - DBG (DBG_error, - "setup_for_scan: failed to send slope table 1: %s\n", - sane_strstatus (status)); + DBG (DBG_error, "%s: failed to send slope table 1: %s\n", __FUNCTION__, sane_strstatus (status)); return status; } - DBG (DBG_proc, "setup_for_scan: end\n"); + DBGCOMPLETED; return status; } @@ -4234,7 +4230,7 @@ ad_fe_coarse_gain_calibration (Genesys_Device * dev, int dpi) Genesys_Settings settings; char title[32]; - DBG (DBG_proc, "ad_fe_coarse_gain_calibration: start\n"); + DBGSTART; /* setup for a RGB scan, one full sensor's width line */ /* resolution is the one from the final scan */ @@ -4317,12 +4313,12 @@ ad_fe_coarse_gain_calibration (Genesys_Device * dev, int dpi) DBG (DBG_info, "ad_fe_coarse_gain_calibration: gains=(%d,%d,%d)\n", dev->frontend.gain[0], dev->frontend.gain[1], dev->frontend.gain[2]); - DBG (DBG_proc, "ad_fe_coarse_gain_calibration: end\n"); + DBGCOMPLETED; return status; } /** - * Alternative coarse gain calibration + * Alternative coarse gain calibration * this on uses the settings from offset_calibration. First scan moves so * we can go to calibration area for XPA. * @param dev device for scan @@ -4343,7 +4339,7 @@ gl646_coarse_gain_calibration (Genesys_Device * dev, int dpi) { return ad_fe_coarse_gain_calibration (dev, dev->sensor.optical_res); } - DBG (DBG_proc, "gl646_coarse_gain_calibration: start\n"); + DBGSTART; /* setup for a RGB scan, one full sensor's width line */ /* resolution is the one from the final scan */ @@ -4352,9 +4348,7 @@ gl646_coarse_gain_calibration (Genesys_Device * dev, int dpi) /* we are searching a sensor resolution */ if (dpi > dev->sensor.optical_res) { - resolution = - get_closest_resolution (dev->model->ccd_type, dev->sensor.optical_res, - SANE_TRUE); + resolution = dev->sensor.optical_res; } else { @@ -4371,14 +4365,12 @@ gl646_coarse_gain_calibration (Genesys_Device * dev, int dpi) if (settings.scan_method == SCAN_METHOD_FLATBED) { settings.tl_x = 0; - settings.pixels = - (dev->sensor.sensor_pixels * resolution) / dev->sensor.optical_res; + settings.pixels = (dev->sensor.sensor_pixels * resolution) / dev->sensor.optical_res; } else { settings.tl_x = SANE_UNFIX (dev->model->x_offset_ta); - settings.pixels = - (SANE_UNFIX (dev->model->x_size_ta) * resolution) / MM_PER_INCH; + settings.pixels = (SANE_UNFIX (dev->model->x_size_ta) * resolution) / MM_PER_INCH; } settings.lines = CALIBRATION_LINES; settings.depth = 8; @@ -4422,8 +4414,7 @@ gl646_coarse_gain_calibration (Genesys_Device * dev, int dpi) if (status != SANE_STATUS_GOOD) { free(line); - DBG (DBG_error, - "gl646_coarse_gain_calibration: failed to scan first line\n"); + DBG (DBG_error, "%s: failed to scan first line\n", __FUNCTION__); return status; } @@ -4438,7 +4429,7 @@ gl646_coarse_gain_calibration (Genesys_Device * dev, int dpi) pass++; /* average high level for each channel and compute gain - to reach the target code + to reach the target code we only use the central half of the CCD data */ for (k = idx; k < idx + channels; k++) { @@ -4481,7 +4472,7 @@ gl646_coarse_gain_calibration (Genesys_Device * dev, int dpi) dev->frontend.gain[k]++; DBG (DBG_proc, - "gl646_coarse_gain_calibration: channel %d, average = %.2f, gain = %d\n", + "%s: channel %d, average = %.2f, gain = %d\n", __FUNCTION__, k, average[k], dev->frontend.gain[k]); } free (line); @@ -4493,9 +4484,9 @@ gl646_coarse_gain_calibration (Genesys_Device * dev, int dpi) dev->frontend.gain[2] = dev->frontend.gain[0]; } - DBG (DBG_info, "gl646_coarse_gain_calibration: gains=(%d,%d,%d)\n", + DBG (DBG_info, "%s: gains=(%d,%d,%d)\n", __FUNCTION__, dev->frontend.gain[0], dev->frontend.gain[1], dev->frontend.gain[2]); - DBG (DBG_proc, "gl646_coarse_gain_calibration: end\n"); + DBGCOMPLETED; return status; } @@ -4537,7 +4528,7 @@ gl646_init_regs_for_warmup (Genesys_Device * dev, settings.dynamic_lineart = SANE_FALSE; /* setup for scan */ - status = setup_for_scan (dev, settings, SANE_TRUE, SANE_FALSE, SANE_FALSE); + status = setup_for_scan (dev, dev->reg, settings, SANE_TRUE, SANE_FALSE, SANE_FALSE); if (status != SANE_STATUS_GOOD) { DBG (DBG_error, @@ -4551,9 +4542,7 @@ gl646_init_regs_for_warmup (Genesys_Device * dev, /* don't enable any correction for this scan */ dev->reg[reg_0x01].value &= ~REG01_DVDSET; - /* XXX STEF XXX - dev->reg[reg_0x05].value &= ~REG05_GMMENB; */ - + /* copy to local_reg */ memcpy (local_reg, dev->reg, (GENESYS_GL646_MAX_REGS + 1) * sizeof (Genesys_Register_Set)); @@ -4569,7 +4558,7 @@ gl646_init_regs_for_warmup (Genesys_Device * dev, RIE (gl646_set_fe (dev, AFE_SET, settings.xres)); RIE (gl646_bulk_write_register (dev, local_reg, GENESYS_GL646_MAX_REGS)); - DBG (DBG_proc, "gl646_init_regs_for_warmup: end\n"); + DBGCOMPLETED; return status; } @@ -4605,7 +4594,7 @@ gl646_repark_head (Genesys_Device * dev) settings.exposure_time = 0; settings.dynamic_lineart = SANE_FALSE; - status = setup_for_scan (dev, settings, SANE_FALSE, SANE_FALSE, SANE_FALSE); + status = setup_for_scan (dev, dev->reg, settings, SANE_FALSE, SANE_FALSE, SANE_FALSE); if (status != SANE_STATUS_GOOD) { DBG (DBG_error, @@ -4702,7 +4691,7 @@ gl646_init (Genesys_Device * dev) switch (dev->model->motor_type) { - /* set to 11111 to spot bugs, sanei_genesys_exposure_time should + /* set to 11111 to spot bugs, sanei_genesys_exposure_time should have obsoleted this field */ case MOTOR_5345: dev->settings.exposure_time = 11111; @@ -4924,15 +4913,13 @@ gl646_init (Genesys_Device * dev) return SANE_STATUS_GOOD; } -#ifndef UNIT_TESTING -static -#endif +GENESYS_STATIC SANE_Status gl646_move_to_ta (Genesys_Device * dev) { SANE_Status status = SANE_STATUS_GOOD; - DBG (DBG_proc, "gl646_move_to_ta: starting\n"); + DBGSTART; if (simple_move (dev, SANE_UNFIX (dev->model->y_offset_calib_ta)) != SANE_STATUS_GOOD) { @@ -4940,8 +4927,7 @@ gl646_move_to_ta (Genesys_Device * dev) "gl646_move_to_ta: failed to move to calibration area\n"); return status; } - DBG (DBG_proc, "gl646_move_to_ta: end\n"); - + DBGCOMPLETED; return status; } @@ -4957,10 +4943,7 @@ gl646_move_to_ta (Genesys_Device * dev) * @param shading SANE_TRUE to enable shading correction * @param data pointer for the data */ -#ifndef UNIT_TESTING -static -#endif - SANE_Status +GENESYS_STATIC SANE_Status simple_scan (Genesys_Device * dev, Genesys_Settings settings, SANE_Bool move, SANE_Bool forward, SANE_Bool shading, unsigned char **data) { @@ -4990,7 +4973,7 @@ simple_scan (Genesys_Device * dev, Genesys_Settings settings, SANE_Bool move, { split = SANE_TRUE; } - status = setup_for_scan (dev, settings, split, SANE_FALSE, SANE_FALSE); + status = setup_for_scan (dev, dev->reg, settings, split, SANE_FALSE, SANE_FALSE); if (status != SANE_STATUS_GOOD) { DBG (DBG_error, "simple_scan: setup_for_scan failed (%s)\n", @@ -5046,6 +5029,9 @@ simple_scan (Genesys_Device * dev, Genesys_Settings settings, SANE_Bool move, dev->reg[reg_0x01].value |= REG01_DVDSET; } + /* enable gamma table for the scan */ + dev->reg[reg_0x05].value |= REG05_GMMENB; + /* one table movement for simple scan */ dev->reg[reg_0x02].value &= ~REG02_FASTFED; @@ -5522,7 +5508,7 @@ gl646_is_compatible_calibration (Genesys_Device * dev, dev->current_setup.channels, dev->current_setup.xres, cache->used_setup.channels, cache->used_setup.xres); - /* a calibration cache is compatible if color mode and x dpi match the user + /* a calibration cache is compatible if color mode and x dpi match the user * requested scan. In the case of CIS scanners, dpi isn't a criteria */ if (dev->model->is_cis == SANE_FALSE) { @@ -5798,6 +5784,7 @@ static Genesys_Command_Set gl646_cmd_set = { gl646_move_to_ta, NULL, NULL, + NULL, NULL }; diff --git a/backend/genesys_gl646.h b/backend/genesys_gl646.h index e9124fd..9e328c5 100644 --- a/backend/genesys_gl646.h +++ b/backend/genesys_gl646.h @@ -6,42 +6,42 @@ Copyright (C) 2005-2009 Pierre Willenbrock <pierre@pirsoft.dnsalias.org> This file is part of the SANE package. - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - + As a special exception, the authors of SANE give permission for additional uses of the libraries contained in this release of SANE. - + The exception is that, if you link a SANE library with other files to produce an executable, this does not by itself cause the resulting executable to be covered by the GNU General Public License. Your use of that executable is in no way restricted on account of linking the SANE library code into it. - + This exception does not, however, invalidate any other reasons why the executable file might be covered by the GNU General Public License. - + If you submit changes to SANE to the maintainers to be included in a subsequent release, you agree by submitting the changes that those changes may be distributed with this exception intact. If you write modifications of your own for SANE, it is your choice whether to permit this exception to apply to your modifications. - If you do not wish that, delete this exception notice. + If you do not wish that, delete this exception notice. */ #include "genesys.h" @@ -261,20 +261,36 @@ static #endif SANE_Status gl646_public_set_fe (Genesys_Device * dev, uint8_t set); +GENESYS_STATIC +SANE_Status +gl646_save_power (Genesys_Device * dev, SANE_Bool enable); + +GENESYS_STATIC +SANE_Status +gl646_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home); + +GENESYS_STATIC +SANE_Status +gl646_move_to_ta (Genesys_Device * dev); + /** * sets up the scanner for a scan, registers, gamma tables, shading tables * and slope tables, based on the parameter struct. * @param device device to set up + * @param regs registers to set up * @param settings settings of the scan * @param split true if move before scan has to be done - * @param xcorrection true if scanner's X geometry must be taken into account to - * compute X, ie add left margins - * @param ycorrection true if scanner's Y geometry must be taken into account to - * compute Y, ie add top margins + * @param xcorrection true if scanner's X geometry must be taken into account to + * compute X, ie add left margins + * @param ycorrection true if scanner's Y geometry must be taken into account to + * compute Y, ie add top margins */ -static SANE_Status -setup_for_scan (Genesys_Device * device, Genesys_Settings settings, - SANE_Bool split, SANE_Bool xcorrection, +GENESYS_STATIC SANE_Status +setup_for_scan (Genesys_Device *device, + Genesys_Register_Set *regs, + Genesys_Settings settings, + SANE_Bool split, + SANE_Bool xcorrection, SANE_Bool ycorrection); /** @@ -305,7 +321,7 @@ gl646_setup_registers (Genesys_Device * dev, static #endif SANE_Status -simple_move (Genesys_Device * dev, SANE_Int distance); +simple_move (Genesys_Device * dev, SANE_Int distance); /** * Does a simple scan of the area given by the settings. Scanned data @@ -320,7 +336,7 @@ simple_move (Genesys_Device * dev, SANE_Int distance); * @param data pointer that will point to the scanned data */ #ifndef UNIT_TESTING -static +static #endif SANE_Status simple_scan (Genesys_Device * dev, Genesys_Settings settings, SANE_Bool move, SANE_Bool forward, @@ -344,7 +360,7 @@ static SANE_Status write_control (Genesys_Device * dev, int resolution); static void gl646_init_regs (Genesys_Device * dev); #ifndef UNIT_TESTING -static +static #endif SANE_Status gl646_load_document (Genesys_Device * dev); @@ -576,7 +592,7 @@ static Motor_Master motor_master[] = { {MOTOR_HP2300, 300, SANE_FALSE, 300, HALF_STEP, SANE_FALSE, SANE_TRUE , 63, 3, 2175, 1087, 120, 4905, 337, 0.3, 0.4, 16}, {MOTOR_HP2300, 600, SANE_FALSE, 600, HALF_STEP, SANE_FALSE, SANE_TRUE , 63, 3, 8700, 4350, 120, 4905, 337, 0.3, 0.4, 16}, {MOTOR_HP2300,1200, SANE_FALSE,1200, HALF_STEP, SANE_FALSE, SANE_TRUE , 63, 3, 17400, 8700, 120, 4905, 337, 0.3, 0.4, 16}, - /* non half ccd settings for 300 dpi + /* non half ccd settings for 300 dpi {MOTOR_HP2300, 300, SANE_TRUE, 300, HALF_STEP, SANE_FALSE, SANE_TRUE , 63, 44, 5386, 2175, 120, 4905, 337, 0.3, 0.4, 16}, {MOTOR_HP2300, 300, SANE_FALSE, 300, HALF_STEP, SANE_FALSE, SANE_TRUE , 63, 44, 5386, 2175, 120, 4905, 337, 0.3, 0.4, 16}, */ diff --git a/backend/genesys_gl841.c b/backend/genesys_gl841.c index 2b22d2c..2b16c67 100644 --- a/backend/genesys_gl841.c +++ b/backend/genesys_gl841.c @@ -9,45 +9,45 @@ Copyright (C) 2006 Laurent Charpentier <laurent_pubs@yahoo.com> Copyright (C) 2010 Chris Berry <s0457957@sms.ed.ac.uk> and Michael Rickmann <mrickma@gwdg.de> for Plustek Opticbook 3600 support - - + + This file is part of the SANE package. - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - + As a special exception, the authors of SANE give permission for additional uses of the libraries contained in this release of SANE. - + The exception is that, if you link a SANE library with other files to produce an executable, this does not by itself cause the resulting executable to be covered by the GNU General Public License. Your use of that executable is in no way restricted on account of linking the SANE library code into it. - + This exception does not, however, invalidate any other reasons why the executable file might be covered by the GNU General Public License. - + If you submit changes to SANE to the maintainers to be included in a subsequent release, you agree by submitting the changes that those changes may be distributed with this exception intact. - + If you write modifications of your own for SANE, it is your choice whether to permit this exception to apply to your modifications. - If you do not wish that, delete this exception notice. + If you do not wish that, delete this exception notice. */ #undef BACKEND_NAME @@ -64,7 +64,7 @@ /* ------------------------------------------------------------------------ */ /* Write to many registers */ -/* Note: There is no known bulk register write, +/* Note: There is no known bulk register write, this function is sending single registers instead */ static SANE_Status gl841_bulk_write_register (Genesys_Device * dev, @@ -88,7 +88,7 @@ gl841_bulk_write_register (Genesys_Device * dev, buffer[i * 2 + 0] = reg[i].address; buffer[i * 2 + 1] = reg[i].value; - + DBG (DBG_io2, "reg[0x%02x] = 0x%02x\n", buffer[i * 2 + 0], buffer[i * 2 + 1]); } @@ -214,13 +214,13 @@ gl841_bulk_read_data (Genesys_Device * dev, uint8_t addr, uint8_t * data, size_t len) { SANE_Status status; - size_t size; - uint8_t outdata[8]; + size_t size, target; + uint8_t outdata[8], *buffer; DBG (DBG_io, "gl841_bulk_read_data: requesting %lu bytes\n", (u_long) len); - if (len == 0) + if (len == 0) return SANE_STATUS_GOOD; status = @@ -254,12 +254,14 @@ gl841_bulk_read_data (Genesys_Device * dev, uint8_t addr, return status; } - while (len) + target = len; + buffer = data; + while (target) { - if (len > BULKIN_MAXSIZE) + if (target > BULKIN_MAXSIZE) size = BULKIN_MAXSIZE; else - size = len; + size = target; DBG (DBG_io2, "gl841_bulk_read_data: trying to read %lu bytes of data\n", @@ -277,14 +279,18 @@ gl841_bulk_read_data (Genesys_Device * dev, uint8_t addr, DBG (DBG_io2, "gl841_bulk_read_data read %lu bytes, %lu remaining\n", - (u_long) size, (u_long) (len - size)); + (u_long) size, (u_long) (target - size)); - len -= size; + target -= size; data += size; } - DBG (DBG_io, "gl841_bulk_read_data: completed\n"); + if (DBG_LEVEL >= DBG_data && dev->binary!=NULL) + { + fwrite(buffer, len, 1, dev->binary); + } + DBGCOMPLETED; return SANE_STATUS_GOOD; } @@ -324,7 +330,7 @@ gl841_set_buffer_address_gamma (Genesys_Device * dev, uint32_t addr) } /* Write bulk data (e.g. gamma) */ -static SANE_Status +GENESYS_STATIC SANE_Status gl841_bulk_write_data_gamma (Genesys_Device * dev, uint8_t addr, uint8_t * data, size_t len) { @@ -398,7 +404,7 @@ gl841_bulk_write_data_gamma (Genesys_Device * dev, uint8_t addr, /**************************************************************************** - Mid level functions + Mid level functions ****************************************************************************/ static SANE_Bool @@ -515,6 +521,7 @@ sanei_gl841_setup_sensor (Genesys_Device * dev, DBG (DBG_proc, "gl841_setup_sensor\n"); + /* that one is tricky at least ....*/ r = sanei_genesys_get_address (regs, 0x70); for (i = 0; i < 4; i++, r++) r->value = dev->sensor.regs_0x08_0x0b[i]; @@ -604,7 +611,7 @@ sanei_gl841_setup_sensor (Genesys_Device * dev, } } -/** Test if the ASIC works +/** Test if the ASIC works */ /*TODO: make this functional*/ static SANE_Status @@ -670,7 +677,7 @@ sanei_gl841_asic_test (Genesys_Device * dev) size = 0x40000; verify_size = size + 0x80; /* todo: looks like the read size must be a multiple of 128? - otherwise the read doesn't succeed the second time after the scanner has + otherwise the read doesn't succeed the second time after the scanner has been plugged in. Very strange. */ data = (uint8_t *) malloc (size); @@ -745,15 +752,15 @@ sanei_gl841_asic_test (Genesys_Device * dev) if (verify_data[i] != data[i]) { DBG (DBG_error, "sanei_gl841_asic_test: data verification error\n"); - DBG (DBG_info, "0x%.8x: got %.2x %.2x %.2x %.2x, expected %.2x %.2x %.2x %.2x\n", - i, - verify_data[i], - verify_data[i+1], - verify_data[i+2], - verify_data[i+3], - data[i], - data[i+1], - data[i+2], + DBG (DBG_info, "0x%.8x: got %.2x %.2x %.2x %.2x, expected %.2x %.2x %.2x %.2x\n", + i, + verify_data[i], + verify_data[i+1], + verify_data[i+2], + verify_data[i+3], + data[i], + data[i+1], + data[i+2], data[i+3]); free (data); free (verify_data); @@ -777,7 +784,168 @@ gl841_bulk_full_size (void) } /* - * Set all registers to default values + * Set all registers LiDE 80 to default values + * (function called only once at the beginning) + * we are doing a special case to ease development + */ +static void +gl841_init_lide80 (Genesys_Device * dev) +{ + uint8_t val; + int index=0; + + INITREG (0x01, 0x82); /* 0x02 = SHDAREA and no CISSET ! */ + INITREG (0x02, 0x10); + INITREG (0x03, 0x50); + INITREG (0x04, 0x02); + INITREG (0x05, 0x4c); /* 1200 DPI */ + INITREG (0x06, 0x38); /* 0x38 scanmod=1, pwrbit, GAIN4 */ + INITREG (0x07, 0x00); + INITREG (0x08, 0x00); + INITREG (0x09, 0x11); + INITREG (0x0a, 0x00); + + INITREG (0x10, 0x40); + INITREG (0x11, 0x00); + INITREG (0x12, 0x40); + INITREG (0x13, 0x00); + INITREG (0x14, 0x40); + INITREG (0x15, 0x00); + INITREG (0x16, 0x00); + INITREG (0x17, 0x01); + INITREG (0x18, 0x00); + INITREG (0x19, 0x06); + INITREG (0x1a, 0x00); + INITREG (0x1b, 0x00); + INITREG (0x1c, 0x00); + INITREG (0x1d, 0x04); + INITREG (0x1e, 0x10); + INITREG (0x1f, 0x04); + INITREG (0x20, 0x02); + INITREG (0x21, 0x10); + INITREG (0x22, 0x20); + INITREG (0x23, 0x20); + INITREG (0x24, 0x10); + INITREG (0x25, 0x00); + INITREG (0x26, 0x00); + INITREG (0x27, 0x00); + + INITREG (0x29, 0xff); + + INITREG (0x2c, dev->sensor.optical_res>>8); + INITREG (0x2d, dev->sensor.optical_res & 0xff); + INITREG (0x2e, 0x80); + INITREG (0x2f, 0x80); + INITREG (0x30, 0x00); + INITREG (0x31, 0x10); + INITREG (0x32, 0x15); + INITREG (0x33, 0x0e); + INITREG (0x34, 0x40); + INITREG (0x35, 0x00); + INITREG (0x36, 0x2a); + INITREG (0x37, 0x30); + INITREG (0x38, 0x2a); + INITREG (0x39, 0xf8); + + INITREG (0x3d, 0x00); + INITREG (0x3e, 0x00); + INITREG (0x3f, 0x00); + + INITREG (0x52, 0x03); + INITREG (0x53, 0x07); + INITREG (0x54, 0x00); + INITREG (0x55, 0x00); + INITREG (0x56, 0x00); + INITREG (0x57, 0x00); + INITREG (0x58, 0x29); + INITREG (0x59, 0x69); + INITREG (0x5a, 0x55); + + INITREG (0x5d, 0x20); + INITREG (0x5e, 0x41); + INITREG (0x5f, 0x40); + INITREG (0x60, 0x00); + INITREG (0x61, 0x00); + INITREG (0x62, 0x00); + INITREG (0x63, 0x00); + INITREG (0x64, 0x00); + INITREG (0x65, 0x00); + INITREG (0x66, 0x00); + INITREG (0x67, 0x40); + INITREG (0x68, 0x40); + INITREG (0x69, 0x20); + INITREG (0x6a, 0x20); + INITREG (0x6c, dev->gpo.value[0]); + INITREG (0x6d, dev->gpo.value[1]); + INITREG (0x6e, dev->gpo.enable[0]); + INITREG (0x6f, dev->gpo.enable[1]); + INITREG (0x70, 0x00); + INITREG (0x71, 0x05); + INITREG (0x72, 0x07); + INITREG (0x73, 0x09); + INITREG (0x74, 0x00); + INITREG (0x75, 0x01); + INITREG (0x76, 0xff); + INITREG (0x77, 0x00); + INITREG (0x78, 0x0f); + INITREG (0x79, 0xf0); + INITREG (0x7a, 0xf0); + INITREG (0x7b, 0x00); + INITREG (0x7c, 0x1e); + INITREG (0x7d, 0x11); + INITREG (0x7e, 0x00); + INITREG (0x7f, 0x50); + INITREG (0x80, 0x00); + INITREG (0x81, 0x00); + INITREG (0x82, 0x0f); + INITREG (0x83, 0x00); + INITREG (0x84, 0x0e); + INITREG (0x85, 0x00); + INITREG (0x86, 0x0d); + INITREG (0x87, 0x02); + INITREG (0x88, 0x00); + INITREG (0x89, 0x00); + + /* specific scanner settings, clock and gpio first */ + sanei_genesys_read_register (dev, REG6B, &val); + sanei_genesys_write_register (dev, REG6B, 0x0c); + sanei_genesys_write_register (dev, 0x06, 0x10); + sanei_genesys_write_register (dev, REG6E, 0x6d); + sanei_genesys_write_register (dev, REG6F, 0x80); + sanei_genesys_write_register (dev, REG6B, 0x0e); + sanei_genesys_read_register (dev, REG6C, &val); + sanei_genesys_write_register (dev, REG6C, 0x00); + sanei_genesys_read_register (dev, REG6D, &val); + sanei_genesys_write_register (dev, REG6D, 0x8f); + sanei_genesys_read_register (dev, REG6B, &val); + sanei_genesys_write_register (dev, REG6B, 0x0e); + sanei_genesys_read_register (dev, REG6B, &val); + sanei_genesys_write_register (dev, REG6B, 0x0e); + sanei_genesys_read_register (dev, REG6B, &val); + sanei_genesys_write_register (dev, REG6B, 0x0a); + sanei_genesys_read_register (dev, REG6B, &val); + sanei_genesys_write_register (dev, REG6B, 0x02); + sanei_genesys_read_register (dev, REG6B, &val); + sanei_genesys_write_register (dev, REG6B, 0x06); + + sanei_genesys_write_0x8c (dev, 0x10, 0x94); + sanei_genesys_write_register (dev, 0x09, 0x10); + + /* set up GPIO : no address, so no bulk write, doesn't written directly either ? */ + /* + dev->reg[reg_0x6c].value = dev->gpo.value[0]; + dev->reg[reg_0x6d].value = dev->gpo.value[1]; + dev->reg[reg_0x6e].value = dev->gpo.enable[0]; + dev->reg[reg_0x6f].value = dev->gpo.enable[1]; */ + + dev->reg[reg_0x6b].value |= REG6B_GPO18; + dev->reg[reg_0x6b].value &= ~REG6B_GPO17; + + sanei_gl841_setup_sensor (dev, dev->reg, 0, 0); +} + +/* + * Set all registers to default values * (function called only once at the beginning) */ static void @@ -789,6 +957,11 @@ gl841_init_registers (Genesys_Device * dev) nr = 0; memset (dev->reg, 0, GENESYS_MAX_REGS * sizeof (Genesys_Register_Set)); + if (strcmp (dev->model->name, "canon-lide-80") == 0) + { + gl841_init_lide80(dev); + return ; + } for (addr = 1; addr <= 0x0a; addr++) dev->reg[nr++].address = addr; @@ -814,12 +987,12 @@ gl841_init_registers (Genesys_Device * dev) { dev->reg[reg_0x01].value &= ~REG01_CISSET; } - + dev->reg[reg_0x02].value = 0x30 /*0x38 */ ; /* auto home, one-table-move, full step */ dev->reg[reg_0x02].value |= REG02_AGOHOME; dev->reg[reg_0x02].value |= REG02_MTRPWR; dev->reg[reg_0x02].value |= REG02_FASTFED; - + dev->reg[reg_0x03].value = 0x1f /*0x17 */ ; /* lamp on */ dev->reg[reg_0x03].value |= REG03_AVEENB; @@ -842,7 +1015,7 @@ gl841_init_registers (Genesys_Device * dev) else { dev->reg[reg_0x05].value |= REG05_DPIHW_2400; - DBG (DBG_warn, + DBG (DBG_warn, "gl841_init_registers: Cannot handle sensor pixel count %d\n", dev->sensor.sensor_pixels); } @@ -861,9 +1034,9 @@ gl841_init_registers (Genesys_Device * dev) else { dev->reg[reg_0x06].value |= 0x05 << REG06S_SCANMOD; /* 15 clocks/pixel */ - dev->reg[reg_0x09].value = 0; /* 24 MHz CLKSET */ + dev->reg[reg_0x09].value = 0; /* 24 MHz CLKSET */ } - + dev->reg[reg_0x1e].value = 0xf0; /* watch-dog time */ dev->reg[reg_0x17].value |= 1 << REG17S_TGW; @@ -879,7 +1052,7 @@ gl841_init_registers (Genesys_Device * dev) /*BUFSEL*/ dev->reg[reg_0x20].value = 0x20; - + /*LAMPPWM*/ dev->reg[reg_0x29].value = 0xff; @@ -905,7 +1078,7 @@ gl841_init_registers (Genesys_Device * dev) /*STOPTIM*/ dev->reg[reg_0x5e].value |= 0x2 << REG5ES_STOPTIM; - sanei_gl841_setup_sensor (dev, dev->reg, 0, 0); + sanei_gl841_setup_sensor (dev, dev->reg, 0, 0); /* set up GPIO */ dev->reg[reg_0x6c].value = dev->gpo.value[0]; @@ -913,18 +1086,24 @@ gl841_init_registers (Genesys_Device * dev) dev->reg[reg_0x6e].value = dev->gpo.enable[0]; dev->reg[reg_0x6f].value = dev->gpo.enable[1]; - if (dev->model->gpo_type == GPO_CANONLIDE35) + /* TODO there is a switch calling to be written here */ + if (dev->model->gpo_type == GPO_CANONLIDE35) + { + dev->reg[reg_0x6b].value |= REG6B_GPO18; + dev->reg[reg_0x6b].value &= ~REG6B_GPO17; + } + if (dev->model->gpo_type == GPO_CANONLIDE80) { dev->reg[reg_0x6b].value |= REG6B_GPO18; dev->reg[reg_0x6b].value &= ~REG6B_GPO17; } - if (dev->model->gpo_type == GPO_XP300) + if (dev->model->gpo_type == GPO_XP300) { dev->reg[reg_0x6b].value |= REG6B_GPO17; } - if (dev->model->gpo_type == GPO_DP685) + if (dev->model->gpo_type == GPO_DP685) { /* REG6B_GPO18 lights on green led */ dev->reg[reg_0x6b].value |= REG6B_GPO17|REG6B_GPO18; @@ -933,10 +1112,10 @@ gl841_init_registers (Genesys_Device * dev) DBG (DBG_proc, "gl841_init_registers complete\n"); } -/* Send slope table for motor movement +/* Send slope table for motor movement slope_table in machine byte order */ -static SANE_Status +GENESYS_STATIC SANE_Status gl841_send_slope_table (Genesys_Device * dev, int table_nr, uint16_t * slope_table, int steps) { @@ -944,6 +1123,7 @@ gl841_send_slope_table (Genesys_Device * dev, int table_nr, int start_address; SANE_Status status; uint8_t *table; + char msg[4000]; /*#ifdef WORDS_BIGENDIAN*/ int i; /*#endif*/ @@ -971,6 +1151,15 @@ gl841_send_slope_table (Genesys_Device * dev, int table_nr, /*#else table = (uint8_t*)slope_table; #endif*/ + if (DBG_LEVEL >= DBG_io) + { + sprintf (msg, "write slope %d (%d)=", table_nr, steps); + for (i = 0; i < steps; i++) + { + sprintf (msg+strlen(msg), ",%d", slope_table[i]); + } + DBG (DBG_io, "%s: %s\n", __FUNCTION__, msg); + } status = sanei_genesys_set_buffer_address (dev, start_address + table_nr * 0x200); @@ -1005,13 +1194,88 @@ gl841_send_slope_table (Genesys_Device * dev, int table_nr, DBG (DBG_proc, "gl841_send_slope_table: completed\n"); return status; } - + +static SANE_Status +gl841_set_lide80_fe (Genesys_Device * dev, uint8_t set) +{ + SANE_Status status = SANE_STATUS_GOOD; + + DBGSTART; + + if (set == AFE_INIT) + { + DBG (DBG_proc, "%s(): setting DAC %u\n", __FUNCTION__, + dev->model->dac_type); + + /* sets to default values */ + sanei_genesys_init_fe (dev); + + /* write them to analog frontend */ + status = sanei_genesys_fe_write_data (dev, 0x00, dev->frontend.reg[0]); + if (status != SANE_STATUS_GOOD) + { + DBG (DBG_error, "%s: writing reg 0x00 failed: %s\n", __FUNCTION__, + sane_strstatus (status)); + return status; + } + status = sanei_genesys_fe_write_data (dev, 0x03, dev->frontend.reg[1]); + if (status != SANE_STATUS_GOOD) + { + DBG (DBG_error, "%s: writing reg 0x03 failed: %s\n", __FUNCTION__, + sane_strstatus (status)); + return status; + } + status = sanei_genesys_fe_write_data (dev, 0x06, dev->frontend.reg[2]); + if (status != SANE_STATUS_GOOD) + { + DBG (DBG_error, "%s: writing reg 0x06 failed: %s\n", __FUNCTION__, + sane_strstatus (status)); + return status; + } + } + + if (set == AFE_SET) + { + status = sanei_genesys_fe_write_data (dev, 0x00, dev->frontend.reg[0]); + if (status != SANE_STATUS_GOOD) + { + DBG (DBG_error, "%s: writing reg 0x00 failed: %s\n", __FUNCTION__, + sane_strstatus (status)); + return status; + } + status = sanei_genesys_fe_write_data (dev, 0x06, dev->frontend.offset[0]); + if (status != SANE_STATUS_GOOD) + { + DBG (DBG_error, "%s: writing offset failed: %s\n", __FUNCTION__, + sane_strstatus (status)); + return status; + } + status = sanei_genesys_fe_write_data (dev, 0x03, dev->frontend.gain[0]); + if (status != SANE_STATUS_GOOD) + { + DBG (DBG_error, "%s: writing gain failed: %s\n", __FUNCTION__, + sane_strstatus (status)); + return status; + } + } + + return status; + DBGCOMPLETED; +} + /* Set values of Analog Device type frontend */ static SANE_Status gl841_set_ad_fe (Genesys_Device * dev, uint8_t set) { SANE_Status status = SANE_STATUS_GOOD; int i; + + /* special case for LiDE 80 analog frontend */ + if(dev->model->dac_type==DAC_CANONLIDE80) + { + return gl841_set_lide80_fe(dev, set); + } + DBG (DBG_proc, "gl841_set_ad_fe(): start\n"); if (set == AFE_INIT) { @@ -1309,7 +1573,7 @@ gl841_set_fe (Genesys_Device * dev, uint8_t set) */ static SANE_Status gl841_init_motor_regs_off(Genesys_Register_Set * reg, - unsigned int scan_lines) + unsigned int scan_lines) { unsigned int feedl; Genesys_Register_Set * r; @@ -1318,21 +1582,21 @@ gl841_init_motor_regs_off(Genesys_Register_Set * reg, scan_lines); feedl = 2; - + r = sanei_genesys_get_address (reg, 0x3d); r->value = (feedl >> 16) & 0xf; r = sanei_genesys_get_address (reg, 0x3e); r->value = (feedl >> 8) & 0xff; - r = sanei_genesys_get_address (reg, 0x3f); + r = sanei_genesys_get_address (reg, 0x3f); r->value = feedl & 0xff; - r = sanei_genesys_get_address (reg, 0x5e); + r = sanei_genesys_get_address (reg, 0x5e); r->value &= ~0xe0; r = sanei_genesys_get_address (reg, 0x25); r->value = (scan_lines >> 16) & 0xf; r = sanei_genesys_get_address (reg, 0x26); r->value = (scan_lines >> 8) & 0xff; - r = sanei_genesys_get_address (reg, 0x27); + r = sanei_genesys_get_address (reg, 0x27); r->value = scan_lines & 0xff; r = sanei_genesys_get_address (reg, 0x02); @@ -1349,43 +1613,95 @@ gl841_init_motor_regs_off(Genesys_Register_Set * reg, r->value &= ~0x40; - r = sanei_genesys_get_address (reg, 0x67); + r = sanei_genesys_get_address (reg, 0x67); r->value = 0x3f; r = sanei_genesys_get_address (reg, 0x68); r->value = 0x3f; - r = sanei_genesys_get_address (reg, 0x21); + r = sanei_genesys_get_address (reg, REG_STEPNO); r->value = 0; - - r = sanei_genesys_get_address (reg, 0x24); + + r = sanei_genesys_get_address (reg, REG_FASTNO); r->value = 0; - + r = sanei_genesys_get_address (reg, 0x69); r->value = 0; - + r = sanei_genesys_get_address (reg, 0x6a); r->value = 0; - + r = sanei_genesys_get_address (reg, 0x5f); r->value = 0; - DBG (DBG_proc, "gl841_init_motor_regs_off : completed. \n"); + DBGCOMPLETED; + return SANE_STATUS_GOOD; +} + +/** @brief write motor table frequency + * Write motor frequency data table. + * @param dev device to set up motor + * @param ydpi motor target resolution + * @return SANE_STATUS_GOOD on success + */ +GENESYS_STATIC SANE_Status gl841_write_freq(Genesys_Device *dev, unsigned int ydpi) +{ +SANE_Status status; +/**< 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}; - return SANE_STATUS_GOOD; +uint8_t *table; + + DBGSTART; + if(dev->model->motor_type == MOTOR_CANONLIDE80) + { + switch(ydpi) + { + case 3600: + case 1200: + table=t1200; + break; + case 900: + case 300: + table=t300; + break; + case 450: + case 150: + table=t150; + break; + default: + table=tdefault; + } + RIE(sanei_genesys_write_register(dev, 0x66, 0x00)); + RIE(sanei_genesys_write_register(dev, 0x5b, 0x0c)); + RIE(sanei_genesys_write_register(dev, 0x5c, 0x00)); + RIE(gl841_bulk_write_data_gamma (dev, 0x28, table, 128)); + RIE(sanei_genesys_write_register(dev, 0x5b, 0x00)); + RIE(sanei_genesys_write_register(dev, 0x5c, 0x00)); + } + DBGCOMPLETED; + return SANE_STATUS_GOOD; } -static SANE_Status + +#ifndef UNIT_TESTING +static +#endif +SANE_Status gl841_init_motor_regs(Genesys_Device * dev, Genesys_Register_Set * reg, unsigned int feed_steps,/*1/base_ydpi*/ /*maybe float for half/quarter step resolution?*/ unsigned int action, - unsigned int flags) + unsigned int flags) { SANE_Status status; unsigned int fast_exposure; + int scan_power_mode; int use_fast_fed = 0; uint16_t fast_slope_table[256]; unsigned int fast_slope_steps = 0; @@ -1399,49 +1715,48 @@ gl841_init_motor_regs(Genesys_Device * dev, flags); memset(fast_slope_table,0xff,512); - + gl841_send_slope_table (dev, 0, fast_slope_table, 256); gl841_send_slope_table (dev, 1, fast_slope_table, 256); gl841_send_slope_table (dev, 2, fast_slope_table, 256); gl841_send_slope_table (dev, 3, fast_slope_table, 256); gl841_send_slope_table (dev, 4, fast_slope_table, 256); + gl841_write_freq(dev, dev->motor.base_ydpi / 4); - if (action == MOTOR_ACTION_FEED || action == MOTOR_ACTION_GO_HOME) { -/* FEED and GO_HOME can use fastest slopes available */ - fast_slope_steps = 256; - fast_exposure = sanei_genesys_exposure_time2( - dev, - dev->motor.base_ydpi / 4, - 0,/*step_type*/ - 0,/*last used pixel*/ - 0, - 0); - - DBG (DBG_info, "gl841_init_motor_regs : fast_exposure=%d pixels\n", - fast_exposure); - } + fast_slope_steps = 256; + if (action == MOTOR_ACTION_FEED || action == MOTOR_ACTION_GO_HOME) + { + /* FEED and GO_HOME can use fastest slopes available */ + fast_exposure = gl841_exposure_time(dev, + dev->motor.base_ydpi / 4, + 0, + 0, + 0, + &scan_power_mode); + DBG (DBG_info, "%s : fast_exposure=%d pixels\n", __FUNCTION__, fast_exposure); + } if (action == MOTOR_ACTION_HOME_FREE) { /* HOME_FREE must be able to stop in one step, so do not try to get faster */ - fast_slope_steps = 256; fast_exposure = dev->motor.slopes[0][0].maximum_start_speed; } sanei_genesys_create_slope_table3 ( dev, - fast_slope_table, 256, + fast_slope_table, + 256, fast_slope_steps, - 0, + 0, fast_exposure, dev->motor.base_ydpi / 4, &fast_slope_steps, &fast_exposure, 0); - + feedl = feed_steps - fast_slope_steps*2; use_fast_fed = 1; - -/* all needed slopes available. we did even decide which mode to use. + +/* all needed slopes available. we did even decide which mode to use. what next? - transfer slopes SCAN: @@ -1475,16 +1790,16 @@ HOME_FREE: 3 r->value = (feedl >> 16) & 0xf; r = sanei_genesys_get_address (reg, 0x3e); r->value = (feedl >> 8) & 0xff; - r = sanei_genesys_get_address (reg, 0x3f); + r = sanei_genesys_get_address (reg, 0x3f); r->value = feedl & 0xff; - r = sanei_genesys_get_address (reg, 0x5e); + r = sanei_genesys_get_address (reg, 0x5e); r->value &= ~0xe0; r = sanei_genesys_get_address (reg, 0x25); r->value = 0; r = sanei_genesys_get_address (reg, 0x26); r->value = 0; - r = sanei_genesys_get_address (reg, 0x27); + r = sanei_genesys_get_address (reg, 0x27); r->value = 0; r = sanei_genesys_get_address (reg, 0x02); @@ -1493,7 +1808,7 @@ HOME_FREE: 3 r->value |= 0x10; - if (action == MOTOR_ACTION_GO_HOME) + if (action == MOTOR_ACTION_GO_HOME) r->value |= 0x06; else r->value &= ~0x06; @@ -1511,38 +1826,40 @@ HOME_FREE: 3 r->value &= ~0x40; status = gl841_send_slope_table (dev, 3, fast_slope_table, 256); - + if (status != SANE_STATUS_GOOD) return status; - - r = sanei_genesys_get_address (reg, 0x67); + + r = sanei_genesys_get_address (reg, 0x67); r->value = 0x3f; r = sanei_genesys_get_address (reg, 0x68); r->value = 0x3f; - r = sanei_genesys_get_address (reg, 0x21); + r = sanei_genesys_get_address (reg, REG_STEPNO); r->value = 0; - - r = sanei_genesys_get_address (reg, 0x24); + + r = sanei_genesys_get_address (reg, REG_FASTNO); r->value = 0; - + r = sanei_genesys_get_address (reg, 0x69); r->value = 0; - + r = sanei_genesys_get_address (reg, 0x6a); r->value = (fast_slope_steps >> 1) + (fast_slope_steps & 1); - + r = sanei_genesys_get_address (reg, 0x5f); r->value = (fast_slope_steps >> 1) + (fast_slope_steps & 1); - DBG (DBG_proc, "gl841_init_motor_regs : completed. \n"); - - return SANE_STATUS_GOOD; + DBGCOMPLETED; + return SANE_STATUS_GOOD; } -static SANE_Status +#ifndef UNIT_TESTING +static +#endif +SANE_Status gl841_init_motor_regs_scan(Genesys_Device * dev, Genesys_Register_Set * reg, unsigned int scan_exposure_time,/*pixel*/ @@ -1554,11 +1871,12 @@ gl841_init_motor_regs_scan(Genesys_Device * dev, unsigned int feed_steps,/*1/base_ydpi*/ /*maybe float for half/quarter step resolution?*/ int scan_power_mode, - unsigned int flags) + unsigned int flags) { SANE_Status status; unsigned int fast_exposure; int use_fast_fed = 0; + int dummy_power_mode; unsigned int fast_time; unsigned int slow_time; uint16_t slow_slope_table[256]; @@ -1586,26 +1904,25 @@ gl841_init_motor_regs_scan(Genesys_Device * dev, scan_power_mode, flags); - fast_exposure = sanei_genesys_exposure_time2( - dev, - dev->motor.base_ydpi / 4, - 0,/*step_type*/ - 0,/*last used pixel*/ - 0, - scan_power_mode); - - DBG (DBG_info, "gl841_init_motor_regs_scan : fast_exposure=%d pixels\n", - fast_exposure); + fast_exposure = gl841_exposure_time(dev, + dev->motor.base_ydpi / 4, + 0, + 0, + 0, + &dummy_power_mode); + DBG (DBG_info, "%s : fast_exposure=%d pixels\n", __FUNCTION__, fast_exposure); memset(slow_slope_table,0xff,512); - + gl841_send_slope_table (dev, 0, slow_slope_table, 256); gl841_send_slope_table (dev, 1, slow_slope_table, 256); gl841_send_slope_table (dev, 2, slow_slope_table, 256); gl841_send_slope_table (dev, 3, slow_slope_table, 256); gl841_send_slope_table (dev, 4, slow_slope_table, 256); + /* motor frequency table */ + gl841_write_freq(dev, scan_yres); /* we calculate both tables for SCAN. the fast slope step count depends on @@ -1616,53 +1933,55 @@ gl841_init_motor_regs_scan(Genesys_Device * dev, dev, slow_slope_table, 256, 256, - scan_step_type, + scan_step_type, scan_exposure_time, scan_yres, &slow_slope_steps, NULL, scan_power_mode); - + sanei_genesys_create_slope_table3 ( dev, back_slope_table, 256, 256, - scan_step_type, + scan_step_type, 0, scan_yres, &back_slope_steps, NULL, scan_power_mode); - + if (feed_steps < (slow_slope_steps >> scan_step_type)) { /*TODO: what should we do here?? go back to exposure calculation?*/ feed_steps = slow_slope_steps >> scan_step_type; } - - if (feed_steps > fast_slope_steps*2 - - (slow_slope_steps >> scan_step_type)) + + if (feed_steps > fast_slope_steps*2 - + (slow_slope_steps >> scan_step_type)) fast_slope_steps = 256; - else + else /* we need to shorten fast_slope_steps here. */ - fast_slope_steps = (feed_steps - + fast_slope_steps = (feed_steps - (slow_slope_steps >> scan_step_type))/2; - + DBG(DBG_info,"gl841_init_motor_regs_scan: Maximum allowed slope steps for fast slope: %d\n",fast_slope_steps); - + fast_slope_time = sanei_genesys_create_slope_table3 ( dev, fast_slope_table, 256, fast_slope_steps, - 0, + 0, fast_exposure, dev->motor.base_ydpi / 4, &fast_slope_steps, &fast_exposure, scan_power_mode); - - if (dev->model->gpo_type == GPO_XP300 || dev->model->gpo_type == GPO_DP685) + + /* fast fed special cases handling */ + if (dev->model->gpo_type == GPO_XP300 + || dev->model->gpo_type == GPO_DP685) { - /* quirk: looks like at least this scanner is unable to use + /* quirk: looks like at least this scanner is unable to use 2-feed mode */ use_fast_fed = 0; } @@ -1670,36 +1989,36 @@ gl841_init_motor_regs_scan(Genesys_Device * dev, use_fast_fed = 0; DBG(DBG_info,"gl841_init_motor_regs_scan: feed too short, slow move forced.\n"); } else { -/* for deciding whether we should use fast mode we need to check how long we - need for (fast)accelerating, moving, decelerating, (TODO: stopping?) - (slow)accelerating again versus (slow)accelerating and moving. we need +/* for deciding whether we should use fast mode we need to check how long we + need for (fast)accelerating, moving, decelerating, (TODO: stopping?) + (slow)accelerating again versus (slow)accelerating and moving. we need fast and slow tables here. */ /*NOTE: scan_exposure_time is per scan_yres*/ /*NOTE: fast_exposure is per base_ydpi/4*/ /*we use full steps as base unit here*/ - fast_time = + fast_time = fast_exposure / 4 * - (feed_steps - fast_slope_steps*2 - - (slow_slope_steps >> scan_step_type)) + (feed_steps - fast_slope_steps*2 - + (slow_slope_steps >> scan_step_type)) + fast_slope_time*2 + slow_slope_time; - slow_time = + slow_time = (scan_exposure_time * scan_yres) / dev->motor.base_ydpi * - (feed_steps - (slow_slope_steps >> scan_step_type)) + (feed_steps - (slow_slope_steps >> scan_step_type)) + slow_slope_time; DBG(DBG_info,"gl841_init_motor_regs_scan: Time for slow move: %d\n", slow_time); DBG(DBG_info,"gl841_init_motor_regs_scan: Time for fast move: %d\n", fast_time); - + use_fast_fed = fast_time < slow_time; } - - if (use_fast_fed) - feedl = feed_steps - fast_slope_steps*2 - + + if (use_fast_fed) + feedl = feed_steps - fast_slope_steps*2 - (slow_slope_steps >> scan_step_type); - else + else if ((feed_steps << scan_step_type) < slow_slope_steps) feedl = 0; else @@ -1707,7 +2026,7 @@ gl841_init_motor_regs_scan(Genesys_Device * dev, DBG(DBG_info,"gl841_init_motor_regs_scan: Decided to use %s mode\n", use_fast_fed?"fast feed":"slow feed"); -/* all needed slopes available. we did even decide which mode to use. +/* all needed slopes available. we did even decide which mode to use. what next? - transfer slopes SCAN: @@ -1741,16 +2060,16 @@ HOME_FREE: 3 r->value = (feedl >> 16) & 0xf; r = sanei_genesys_get_address (reg, 0x3e); r->value = (feedl >> 8) & 0xff; - r = sanei_genesys_get_address (reg, 0x3f); + r = sanei_genesys_get_address (reg, 0x3f); r->value = feedl & 0xff; - r = sanei_genesys_get_address (reg, 0x5e); + r = sanei_genesys_get_address (reg, 0x5e); r->value &= ~0xe0; r = sanei_genesys_get_address (reg, 0x25); r->value = (scan_lines >> 16) & 0xf; r = sanei_genesys_get_address (reg, 0x26); r->value = (scan_lines >> 8) & 0xff; - r = sanei_genesys_get_address (reg, 0x27); + r = sanei_genesys_get_address (reg, 0x27); r->value = scan_lines & 0xff; r = sanei_genesys_get_address (reg, 0x02); @@ -1776,35 +2095,35 @@ HOME_FREE: 3 r->value &= ~0x40; status = gl841_send_slope_table (dev, 0, slow_slope_table, 256); - + if (status != SANE_STATUS_GOOD) return status; - + status = gl841_send_slope_table (dev, 1, back_slope_table, 256); - + if (status != SANE_STATUS_GOOD) return status; - + status = gl841_send_slope_table (dev, 2, slow_slope_table, 256); - + if (status != SANE_STATUS_GOOD) return status; - + if (use_fast_fed) { status = gl841_send_slope_table (dev, 3, fast_slope_table, 256); - + if (status != SANE_STATUS_GOOD) return status; } - + if (flags & MOTOR_FLAG_AUTO_GO_HOME){ status = gl841_send_slope_table (dev, 4, fast_slope_table, 256); - + if (status != SANE_STATUS_GOOD) return status; } - - + + /* now reg 0x21 and 0x24 are available, we can calculate reg 0x22 and 0x23, reg 0x60-0x62 and reg 0x63-0x65 rule: @@ -1814,15 +2133,15 @@ HOME_FREE: 3 if (min_restep < slow_slope_steps*2+2) min_restep = slow_slope_steps*2+2; /* steps of table 1*/ - if (min_restep < back_slope_steps*2+2) + if (min_restep < back_slope_steps*2+2) min_restep = back_slope_steps*2+2; /* steps of table 0*/ - r = sanei_genesys_get_address (reg, 0x22); + r = sanei_genesys_get_address (reg, REG_FWDSTEP); r->value = min_restep - slow_slope_steps*2; /* steps of table 1*/ - r = sanei_genesys_get_address (reg, 0x23); + r = sanei_genesys_get_address (reg, REG_BWDSTEP); r->value = min_restep - back_slope_steps*2; - + /* for z1/z2: in dokumentation mentioned variables a-d: @@ -1830,16 +2149,16 @@ HOME_FREE: 3 b = time needed for reg 0x1f... wouldn't that be reg0x1f*exposure_time? c = time needed for acceleration, table 1 d = time needed for reg 0x22... wouldn't that be reg0x22*exposure_time? - z1 = (c+d-1) % exposure_time + z1 = (c+d-1) % exposure_time z2 = (a+b-1) % exposure_time */ -/* i don't see any effect of this. i can only guess that this will enhance +/* i don't see any effect of this. i can only guess that this will enhance sub-pixel accuracy z1 = (slope_0_time-1) % exposure_time; z2 = (slope_0_time-1) % exposure_time; */ z1 = z2 = 0; - + DBG (DBG_info, "gl841_init_motor_regs_scan: z1 = %d\n", z1); DBG (DBG_info, "gl841_init_motor_regs_scan: z2 = %d\n", z2); r = sanei_genesys_get_address (reg, 0x60); @@ -1854,40 +2173,39 @@ HOME_FREE: 3 r->value = ((z2 >> 8) & 0xff); r = sanei_genesys_get_address (reg, 0x65); r->value = (z2 & 0xff); - - r = sanei_genesys_get_address (reg, 0x1e); - r->value &= 0xf0; /* 0 dummy lines */ - r->value |= scan_dummy; /* dummy lines */ - r = sanei_genesys_get_address (reg, 0x67); + r = sanei_genesys_get_address (reg, REG1E); + r->value &= REG1E_WDTIME; + r->value |= scan_dummy; + + r = sanei_genesys_get_address (reg, 0x67); r->value = 0x3f | (scan_step_type << 6); r = sanei_genesys_get_address (reg, 0x68); r->value = 0x3f; - r = sanei_genesys_get_address (reg, 0x21); + r = sanei_genesys_get_address (reg, REG_STEPNO); r->value = (slow_slope_steps >> 1) + (slow_slope_steps & 1); - - r = sanei_genesys_get_address (reg, 0x24); + + r = sanei_genesys_get_address (reg, REG_FASTNO); r->value = (back_slope_steps >> 1) + (back_slope_steps & 1); - + r = sanei_genesys_get_address (reg, 0x69); r->value = (slow_slope_steps >> 1) + (slow_slope_steps & 1); - + r = sanei_genesys_get_address (reg, 0x6a); r->value = (fast_slope_steps >> 1) + (fast_slope_steps & 1); - + r = sanei_genesys_get_address (reg, 0x5f); r->value = (fast_slope_steps >> 1) + (fast_slope_steps & 1); - DBG (DBG_proc, "gl841_init_motor_regs_scan : completed. \n"); - - return SANE_STATUS_GOOD; + DBGCOMPLETED; + return SANE_STATUS_GOOD; } static int -gl841_get_dpihw(Genesys_Device * dev) +gl841_get_dpihw(Genesys_Device * dev) { Genesys_Register_Set * r; r = sanei_genesys_get_address (dev->reg, 0x05); @@ -1911,7 +2229,7 @@ gl841_init_optical_regs_off(Genesys_Register_Set * reg) r->value &= ~REG01_SCAN; DBGCOMPLETED; - return SANE_STATUS_GOOD; + return SANE_STATUS_GOOD; } static SANE_Status @@ -1919,7 +2237,7 @@ gl841_init_optical_regs_scan(Genesys_Device * dev, Genesys_Register_Set * reg, unsigned int exposure_time, unsigned int used_res, - unsigned int start, + unsigned int start, unsigned int pixels, int channels, int depth, @@ -1934,13 +2252,14 @@ gl841_init_optical_regs_scan(Genesys_Device * dev, unsigned int i; Genesys_Register_Set * r; SANE_Status status; + uint16_t expavg, expr, expb, expg; DBG (DBG_proc, "gl841_init_optical_regs_scan : exposure_time=%d, " "used_res=%d, start=%d, pixels=%d, channels=%d, depth=%d, " "half_ccd=%d, flags=%x\n", exposure_time, used_res, - start, + start, pixels, channels, depth, @@ -1948,7 +2267,7 @@ gl841_init_optical_regs_scan(Genesys_Device * dev, flags); end = start + pixels; - + status = gl841_set_fe (dev, AFE_SET); if (status != SANE_STATUS_GOOD) { @@ -1957,31 +2276,45 @@ gl841_init_optical_regs_scan(Genesys_Device * dev, sane_strstatus (status)); return status; } - + /* adjust used_res for chosen dpihw */ used_res = used_res * gl841_get_dpihw(dev) / dev->sensor.optical_res; /* - with half_ccd the optical resolution of the ccd is halfed. We don't apply this + with half_ccd the optical resolution of the ccd is halved. We don't apply this to dpihw, so we need to double dpiset. - + For the scanner only the ratio of dpiset and dpihw is of relevance to scale down properly. */ - if (half_ccd) + if (half_ccd) dpiset = used_res * 2; else dpiset = used_res; - - if (dev->model->gpo_type == GPO_CANONLIDE35) + + /* gpio part.*/ + if (dev->model->gpo_type == GPO_CANONLIDE35) { -/* gpio part.*/ r = sanei_genesys_get_address (reg, REG6C); if (half_ccd) r->value &= ~0x80; else r->value |= 0x80; } + if (dev->model->gpo_type == GPO_CANONLIDE80) + { + r = sanei_genesys_get_address (reg, REG6C); + if (half_ccd) + { + r->value &= ~0x40; + r->value |= 0x20; + } + else + { + r->value &= ~0x20; + r->value |= 0x40; + } + } /* enable shading */ r = sanei_genesys_get_address (reg, 0x01); @@ -1991,8 +2324,8 @@ gl841_init_optical_regs_scan(Genesys_Device * dev, r->value &= ~REG01_DVDSET; else r->value |= REG01_DVDSET; - - /* average looks better than deletion, and we are already set up to + + /* average looks better than deletion, and we are already set up to use one of the average enabled resolutions */ r = sanei_genesys_get_address (reg, 0x03); @@ -2001,7 +2334,7 @@ gl841_init_optical_regs_scan(Genesys_Device * dev, r->value &= ~REG03_LAMPPWR; else r->value |= REG03_LAMPPWR; - + /* exposure times */ r = sanei_genesys_get_address (reg, 0x10); for (i = 0; i < 6; i++, r++) { @@ -2044,84 +2377,94 @@ gl841_init_optical_regs_scan(Genesys_Device * dev, r->value |= REG04_BITSET; break; } - + + /* AFEMOD should depend on FESET, and we should set these + * bits separately */ r->value &= ~(REG04_FILTER | REG04_AFEMOD); - if (channels == 1) + if (flags & OPTICAL_FLAG_ENABLE_LEDADD) + { + r->value |= 0x10; /* no filter */ + } + else if (channels == 1) { switch (color_filter) - { - case 0: - r->value |= 0x14; /* red filter */ - break; - case 2: - r->value |= 0x1c; /* blue filter */ - break; - default: - r->value |= 0x18; /* green filter */ - break; - } - } - else - { + { + case 0: + r->value |= 0x14; /* red filter */ + break; + case 1: + r->value |= 0x18; /* green filter */ + break; + case 2: + r->value |= 0x1c; /* blue filter */ + break; + default: + r->value |= 0x10; /* no filter */ + break; + } + } + else + { if (dev->model->ccd_type == CCD_PLUSTEK_3600) { r->value |= 0x22; /* slow color pixel by pixel */ } - else + else { r->value |= 0x10; /* color pixel by pixel */ } - } + } /* CIS scanners can do true gray by setting LEDADD */ - if (dev->model->is_cis == SANE_TRUE) + r = sanei_genesys_get_address (reg, 0x87); + r->value &= ~REG87_LEDADD; + if (flags & OPTICAL_FLAG_ENABLE_LEDADD) { - r = sanei_genesys_get_address (reg, 0x87); - r->value &= ~REG87_LEDADD; - /* we set up LEDADD only when asked */ - if (channels==1 && (flags & OPTICAL_FLAG_ENABLE_LEDADD)) - { - r->value |= REG87_LEDADD; - } + r->value |= REG87_LEDADD; + sanei_genesys_get_double (reg, REG_EXPR, &expr); + sanei_genesys_get_double (reg, REG_EXPG, &expg); + sanei_genesys_get_double (reg, REG_EXPB, &expb); + + /* use minimal exposure for best image quality */ + expavg = expg; + if (expr < expg) + expavg = expr; + if (expb < expavg) + expavg = expb; + + sanei_genesys_set_double (dev->reg, REG_EXPR, expavg); + sanei_genesys_set_double (dev->reg, REG_EXPG, expavg); + sanei_genesys_set_double (dev->reg, REG_EXPB, expavg); } - + /* enable gamma tables */ r = sanei_genesys_get_address (reg, 0x05); if (flags & OPTICAL_FLAG_DISABLE_GAMMA) r->value &= ~REG05_GMMENB; else r->value |= REG05_GMMENB; - + /* sensor parameters */ sanei_gl841_setup_sensor (dev, dev->reg, 1, half_ccd); - + r = sanei_genesys_get_address (reg, 0x29); r->value = 255; /*<<<"magic" number, only suitable for cis*/ - - r = sanei_genesys_get_address (reg, 0x2c); - r->value = HIBYTE (dpiset); - r = sanei_genesys_get_address (reg, 0x2d); - r->value = LOBYTE (dpiset); - - r = sanei_genesys_get_address (reg, 0x30); - r->value = HIBYTE (start); - r = sanei_genesys_get_address (reg, 0x31); - r->value = LOBYTE (start); - r = sanei_genesys_get_address (reg, 0x32); - r->value = HIBYTE (end); - r = sanei_genesys_get_address (reg, 0x33); - r->value = LOBYTE (end); - -/* words(16bit) before gamma, conversion to 8 bit or lineart*/ - words_per_line = (pixels * dpiset) / gl841_get_dpihw(dev); - + + sanei_genesys_set_double(reg, REG_DPISET, dpiset); + sanei_genesys_set_double(reg, REG_STRPIXEL, start); + sanei_genesys_set_double(reg, REG_ENDPIXEL, end); + DBG( DBG_io2, "%s: STRPIXEL=%d, ENDPIXEL=%d\n",__FUNCTION__,start,end); + + /* words(16bit) before gamma, conversion to 8 bit or lineart*/ + words_per_line = (pixels * dpiset) / gl841_get_dpihw(dev); + words_per_line *= channels; if (depth == 1) words_per_line = (words_per_line >> 3) + ((words_per_line & 7)?1:0); else words_per_line *= depth / 8; - + dev->wpl = words_per_line; dev->bpl = words_per_line; @@ -2131,22 +2474,18 @@ gl841_init_optical_regs_scan(Genesys_Device * dev, r->value = HIBYTE (LOWORD (words_per_line)); r = sanei_genesys_get_address (reg, 0x37); r->value = LOBYTE (LOWORD (words_per_line)); - - r = sanei_genesys_get_address (reg, 0x38); - r->value = HIBYTE (exposure_time); - r = sanei_genesys_get_address (reg, 0x39); - r->value = LOBYTE (exposure_time); + + sanei_genesys_set_double(reg, REG_LPERIOD, exposure_time); r = sanei_genesys_get_address (reg, 0x34); r->value = dev->sensor.dummy_pixel; - DBG (DBG_proc, "gl841_init_optical_regs_scan : completed. \n"); - return SANE_STATUS_GOOD; + DBGCOMPLETED; + return SANE_STATUS_GOOD; } - -static int -gl841_get_led_exposure(Genesys_Device * dev) +static int +gl841_get_led_exposure(Genesys_Device * dev) { int d,r,g,b,m; if (!dev->model->is_cis) @@ -2161,17 +2500,94 @@ gl841_get_led_exposure(Genesys_Device * dev) m = g; if (m < b) m = b; - + return m + d; } +/** @brief compute exposure time + * Compute exposure time for the device and the given scan resolution, + * also compute scan_power_mode + */ +GENESYS_STATIC int +gl841_exposure_time(Genesys_Device *dev, + float slope_dpi, + int scan_step_type, + int start, + int used_pixels, + int *scan_power_mode) +{ +int exposure_time = 0; +int exposure_time2 = 0; +int led_exposure; + + *scan_power_mode=0; + led_exposure=gl841_get_led_exposure(dev); + exposure_time = sanei_genesys_exposure_time2( + dev, + slope_dpi, + scan_step_type, + start+used_pixels,/*+tgtime? currently done in sanei_genesys_exposure_time2 with tgtime = 32 pixel*/ + led_exposure, + *scan_power_mode); + + while(*scan_power_mode + 1 < dev->motor.power_mode_count) { + exposure_time2 = sanei_genesys_exposure_time2( + dev, + slope_dpi, + scan_step_type, + start+used_pixels,/*+tgtime? currently done in sanei_genesys_exposure_time2 with tgtime = 32 pixel*/ + led_exposure, + *scan_power_mode + 1); + if (exposure_time < exposure_time2) + break; + exposure_time = exposure_time2; + (*scan_power_mode)++; + } + + return exposure_time; +} + +/**@brief compute scan_step_type + * Try to do at least 4 steps per line. if that is impossible we will have to + * live with that. + * @param dev device + * @param yres motor resolution + */ +GENESYS_STATIC int +gl841_scan_step_type(Genesys_Device *dev, int yres) +{ +int scan_step_type=0; + + /* TODO : check if there is a bug around the use of max_step_type */ + /* should be <=1, need to chek all devices entry in genesys_devices */ + if (yres*4 < dev->motor.base_ydpi || dev->motor.max_step_type <= 0) + { + scan_step_type = 0; + } + else if (yres*4 < dev->motor.base_ydpi*2 || dev->motor.max_step_type <= 1) + { + scan_step_type = 1; + } + else + { + scan_step_type = 2; + } + + /* this motor behaves differently */ + if (dev->model->motor_type==MOTOR_CANONLIDE80) + { + /* driven by 'frequency' tables ? */ + scan_step_type = 0; + } + + return scan_step_type; +} + /* set up registers for an actual scan * * this function sets up the scanner to scan in normal or single line mode */ -#ifndef UNIT_TESTING -static -#endif +GENESYS_STATIC SANE_Status gl841_init_scan_regs (Genesys_Device * dev, Genesys_Register_Set * reg, @@ -2192,20 +2608,22 @@ gl841_init_scan_regs (Genesys_Device * dev, int bytes_per_line; int move; unsigned int lincnt; - int exposure_time, exposure_time2, led_exposure; + int exposure_time; + int scan_power_mode; int i; int stagger; + int avg; int slope_dpi = 0; int dummy = 0; int scan_step_type = 1; - int scan_power_mode = 0; int max_shift; size_t requested_buffer_size, read_buffer_size; SANE_Bool half_ccd; /* false: full CCD res is used, true, half max CCD res is used */ int optical_res; SANE_Status status; + unsigned int oflags; /**> optical flags */ DBG (DBG_info, "gl841_init_scan_regs settings:\n" @@ -2281,34 +2699,32 @@ independent of our calculated values: if (i < 2 || (flags & SCAN_FLAG_USE_OPTICAL_RES)) /* optical_res >= xres > optical_res/2 */ used_res = optical_res; else if (i < 3) /* optical_res/2 >= xres > optical_res/3 */ - used_res = optical_res/2; + used_res = optical_res/2; else if (i < 4) /* optical_res/3 >= xres > optical_res/4 */ - used_res = optical_res/3; + used_res = optical_res/3; else if (i < 5) /* optical_res/4 >= xres > optical_res/5 */ - used_res = optical_res/4; + used_res = optical_res/4; else if (i < 6) /* optical_res/5 >= xres > optical_res/6 */ - used_res = optical_res/5; + used_res = optical_res/5; else if (i < 8) /* optical_res/6 >= xres > optical_res/8 */ - used_res = optical_res/6; + used_res = optical_res/6; else if (i < 10) /* optical_res/8 >= xres > optical_res/10 */ - used_res = optical_res/8; + used_res = optical_res/8; else if (i < 12) /* optical_res/10 >= xres > optical_res/12 */ - used_res = optical_res/10; + used_res = optical_res/10; else if (i < 15) /* optical_res/12 >= xres > optical_res/15 */ - used_res = optical_res/12; + used_res = optical_res/12; else used_res = optical_res/15; /* compute scan parameters values */ /* pixels are allways given at half or full CCD optical resolution */ /* use detected left margin and fixed value */ -/* start */ + /* start */ /* add x coordinates */ - start = - ((dev->sensor.CCD_start_xoffset + startx) * used_res) / - dev->sensor.optical_res; + start = ((dev->sensor.CCD_start_xoffset + startx) * used_res) / dev->sensor.optical_res; -/* needs to be aligned for used_res */ + /* needs to be aligned for used_res */ start = (start * optical_res) / used_res; start += dev->sensor.dummy_pixel + 1; @@ -2316,10 +2732,19 @@ independent of our calculated values: if (stagger > 0) start |= 1; + /* in case of SHDAREA, we need to align start + * on pixel average factor, startx is different of + * 0 only when calling for function to setup for + * scan, where shading data needs to be align */ + if((dev->reg[reg_0x01].value & REG01_SHDAREA) != 0) + { + avg=optical_res/used_res; + start=(start/avg)*avg; + } + /* compute correct pixels number */ -/* pixels */ - used_pixels = - (pixels * optical_res) / xres; + /* pixels */ + used_pixels = (pixels * optical_res) / xres; /* round up pixels number if needed */ if (used_pixels * xres < pixels * optical_res) @@ -2327,8 +2752,8 @@ independent of our calculated values: /* dummy */ /* dummy lines: may not be usefull, for instance 250 dpi works with 0 or 1 - dummy line. Maybe the dummy line adds correctness since the motor runs - slower (higher dpi) + dummy line. Maybe the dummy line adds correctness since the motor runs + slower (higher dpi) */ /* for cis this creates better aligned color lines: dummy \ scanned lines @@ -2355,86 +2780,64 @@ dummy \ scanned lines /* slope_dpi */ /* cis color scan is effectively a gray scan with 3 gray lines per color line and a FILTER of 0 */ - if (dev->model->is_cis) + if (dev->model->is_cis) slope_dpi = yres*channels; else slope_dpi = yres; slope_dpi = slope_dpi * (1 + dummy); -/* scan_step_type */ -/* Try to do at least 4 steps per line. if that is impossible we will have to - live with that - */ - if (yres*4 < dev->motor.base_ydpi - || dev->motor.max_step_type <= 0) - scan_step_type = 0; - else if (yres*4 < dev->motor.base_ydpi*2 - || dev->motor.max_step_type <= 1) - scan_step_type = 1; - else - scan_step_type = 2; - -/* exposure_time */ - led_exposure = gl841_get_led_exposure(dev); - - exposure_time = sanei_genesys_exposure_time2( - dev, - slope_dpi, - scan_step_type, - start+used_pixels,/*+tgtime? currently done in sanei_genesys_exposure_time2 with tgtime = 32 pixel*/ - led_exposure, - scan_power_mode); - - while(scan_power_mode + 1 < dev->motor.power_mode_count) { - exposure_time2 = sanei_genesys_exposure_time2( - dev, - slope_dpi, - scan_step_type, - start+used_pixels,/*+tgtime? currently done in sanei_genesys_exposure_time2 with tgtime = 32 pixel*/ - led_exposure, - scan_power_mode + 1); - if (exposure_time < exposure_time2) - break; - exposure_time = exposure_time2; - scan_power_mode++; - } - - - DBG (DBG_info, "gl841_init_scan_regs : exposure_time=%d pixels\n", - exposure_time); + scan_step_type = gl841_scan_step_type(dev, yres); + exposure_time = gl841_exposure_time(dev, + slope_dpi, + scan_step_type, + start, + used_pixels, + &scan_power_mode); + DBG (DBG_info, "%s : exposure_time=%d pixels\n", __FUNCTION__, exposure_time); -/*** optical parameters ***/ + /*** optical parameters ***/ /* in case of dynamic lineart, we use an internal 8 bit gray scan * to generate 1 lineart data */ if(flags & SCAN_FLAG_DYNAMIC_LINEART) { depth=8; } - if (depth == 16) - flags |= SCAN_FLAG_DISABLE_GAMMA; - status = gl841_init_optical_regs_scan(dev, - reg, + oflags=0; + if (flags & SCAN_FLAG_DISABLE_SHADING) + { + oflags |= OPTICAL_FLAG_DISABLE_SHADING; + } + if ((flags & SCAN_FLAG_DISABLE_GAMMA) || (depth==16)) + { + oflags |= OPTICAL_FLAG_DISABLE_GAMMA; + } + if (flags & SCAN_FLAG_DISABLE_LAMP) + { + oflags |= OPTICAL_FLAG_DISABLE_LAMP; + } + if (flags & SCAN_FLAG_ENABLE_LEDADD) + { + oflags |= OPTICAL_FLAG_ENABLE_LEDADD; + } + + status = gl841_init_optical_regs_scan(dev, + reg, exposure_time, used_res, - start, + start, used_pixels, channels, depth, half_ccd, color_filter, - ((flags & SCAN_FLAG_DISABLE_SHADING)? - OPTICAL_FLAG_DISABLE_SHADING:0) | - ((flags & SCAN_FLAG_DISABLE_GAMMA)? - OPTICAL_FLAG_DISABLE_GAMMA:0) | - ((flags & SCAN_FLAG_DISABLE_LAMP)? - OPTICAL_FLAG_DISABLE_LAMP:0) - ); - + oflags); if (status != SANE_STATUS_GOOD) + { return status; - + } + /*** motor parameters ***/ /* scanned area must be enlarged by max color shift needed */ @@ -2482,7 +2885,7 @@ dummy \ scanned lines /*** prepares data reordering ***/ /* words_per_line */ - bytes_per_line = (used_pixels * used_res) / optical_res; + bytes_per_line = (used_pixels * used_res) / optical_res; bytes_per_line = (bytes_per_line * channels * depth) / 8; requested_buffer_size = 8 * bytes_per_line; @@ -2500,13 +2903,13 @@ dummy \ scanned lines RIE(sanei_genesys_buffer_free(&(dev->lines_buffer))); RIE(sanei_genesys_buffer_alloc(&(dev->lines_buffer), read_buffer_size)); - + RIE(sanei_genesys_buffer_free(&(dev->shrink_buffer))); - RIE(sanei_genesys_buffer_alloc(&(dev->shrink_buffer), + RIE(sanei_genesys_buffer_alloc(&(dev->shrink_buffer), requested_buffer_size)); - + RIE(sanei_genesys_buffer_free(&(dev->out_buffer))); - RIE(sanei_genesys_buffer_alloc(&(dev->out_buffer), + RIE(sanei_genesys_buffer_alloc(&(dev->out_buffer), (8 * dev->settings.pixels * channels * depth) / 8)); @@ -2534,12 +2937,12 @@ dummy \ scanned lines /* theory : target_size = (dev->settings.pixels * dev->settings.lines * channels * depth) / 8; - but it suffers from integer overflow so we do the following: + but it suffers from integer overflow so we do the following: - 1 bit color images store color data byte-wise, eg byte 0 contains - 8 bits of red data, byte 1 contains 8 bits of green, byte 2 contains + 1 bit color images store color data byte-wise, eg byte 0 contains + 8 bits of red data, byte 1 contains 8 bits of green, byte 2 contains 8 bits of blue. - This does not fix the overflow, though. + This does not fix the overflow, though. 644mp*16 = 10gp, leading to an overflow -- pierre */ @@ -2578,14 +2981,14 @@ gl841_calculate_current_setup (Genesys_Device * dev) int used_res; int used_pixels; unsigned int lincnt; - int exposure_time, exposure_time2, led_exposure; + int exposure_time; + int scan_power_mode; int i; int stagger; int slope_dpi = 0; int dummy = 0; int scan_step_type = 1; - int scan_power_mode = 0; int max_shift; SANE_Bool half_ccd; /* false: full CCD res is used, true, half max CCD res is used */ @@ -2669,21 +3072,21 @@ gl841_calculate_current_setup (Genesys_Device * dev) if (i < 2) /* optical_res >= xres > optical_res/2 */ used_res = optical_res; else if (i < 3) /* optical_res/2 >= xres > optical_res/3 */ - used_res = optical_res/2; + used_res = optical_res/2; else if (i < 4) /* optical_res/3 >= xres > optical_res/4 */ - used_res = optical_res/3; + used_res = optical_res/3; else if (i < 5) /* optical_res/4 >= xres > optical_res/5 */ - used_res = optical_res/4; + used_res = optical_res/4; else if (i < 6) /* optical_res/5 >= xres > optical_res/6 */ - used_res = optical_res/5; + used_res = optical_res/5; else if (i < 8) /* optical_res/6 >= xres > optical_res/8 */ - used_res = optical_res/6; + used_res = optical_res/6; else if (i < 10) /* optical_res/8 >= xres > optical_res/10 */ - used_res = optical_res/8; + used_res = optical_res/8; else if (i < 12) /* optical_res/10 >= xres > optical_res/12 */ - used_res = optical_res/10; + used_res = optical_res/10; else if (i < 15) /* optical_res/12 >= xres > optical_res/15 */ - used_res = optical_res/12; + used_res = optical_res/12; else used_res = optical_res/15; @@ -2692,7 +3095,7 @@ gl841_calculate_current_setup (Genesys_Device * dev) /* use detected left margin and fixed value */ /* start */ /* add x coordinates */ - start = + start = ((dev->sensor.CCD_start_xoffset + startx) * used_res) / dev->sensor.optical_res; @@ -2715,8 +3118,8 @@ gl841_calculate_current_setup (Genesys_Device * dev) /* dummy */ /* dummy lines: may not be usefull, for instance 250 dpi works with 0 or 1 - dummy line. Maybe the dummy line adds correctness since the motor runs - slower (higher dpi) + dummy line. Maybe the dummy line adds correctness since the motor runs + slower (higher dpi) */ /* for cis this creates better aligned color lines: dummy \ scanned lines @@ -2743,53 +3146,21 @@ dummy \ scanned lines /* slope_dpi */ /* cis color scan is effectively a gray scan with 3 gray lines per color line and a FILTER of 0 */ - if (dev->model->is_cis) + if (dev->model->is_cis) slope_dpi = yres*channels; else slope_dpi = yres; slope_dpi = slope_dpi * (1 + dummy); -/* scan_step_type */ -/* Try to do at least 4 steps per line. if that is impossible we will have to - live with that - */ - if (yres*4 < dev->motor.base_ydpi - || dev->motor.max_step_type <= 0) - scan_step_type = 0; - else if (yres*4 < dev->motor.base_ydpi*2 - || dev->motor.max_step_type <= 1) - scan_step_type = 1; - else - scan_step_type = 2; - - led_exposure = gl841_get_led_exposure(dev); - -/* exposure_time */ - exposure_time = sanei_genesys_exposure_time2( - dev, - slope_dpi, - scan_step_type, - start+used_pixels,/*+tgtime? currently done in sanei_genesys_exposure_time2 with tgtime = 32 pixel*/ - led_exposure, - scan_power_mode); - - while(scan_power_mode + 1 < dev->motor.power_mode_count) { - exposure_time2 = sanei_genesys_exposure_time2( - dev, - slope_dpi, - scan_step_type, - start+used_pixels,/*+tgtime? currently done in sanei_genesys_exposure_time2 with tgtime = 32 pixel*/ - led_exposure, - scan_power_mode + 1); - if (exposure_time < exposure_time2) - break; - exposure_time = exposure_time2; - scan_power_mode++; - } - - DBG (DBG_info, "gl841_calculate_current_setup : exposure_time=%d pixels\n", - exposure_time); + scan_step_type = gl841_scan_step_type(dev, yres); + exposure_time = gl841_exposure_time(dev, + slope_dpi, + scan_step_type, + start, + used_pixels, + &scan_power_mode); + DBG (DBG_info, "%s : exposure_time=%d pixels\n", __FUNCTION__, exposure_time); /* scanned area must be enlarged by max color shift needed */ max_shift=sanei_genesys_compute_max_shift(dev,channels,yres,0); @@ -2808,7 +3179,7 @@ dummy \ scanned lines dev->current_setup.stagger = stagger; dev->current_setup.max_shift = max_shift + stagger; - DBG (DBG_proc, "gl841_calculate_current_setup: completed\n"); + DBGCOMPLETED; return SANE_STATUS_GOOD; } @@ -2835,7 +3206,7 @@ gl841_set_motor_power (Genesys_Register_Set * regs, SANE_Bool set) } static void -gl841_set_lamp_power (Genesys_Device * dev, +gl841_set_lamp_power (Genesys_Device * dev, Genesys_Register_Set * regs, SANE_Bool set) { Genesys_Register_Set * r; @@ -2878,16 +3249,16 @@ gl841_set_lamp_power (Genesys_Device * dev, static SANE_Status gl841_save_power(Genesys_Device * dev, SANE_Bool enable) { uint8_t val; - + DBG(DBG_proc, "gl841_save_power: enable = %d\n", enable); if (enable) { - if (dev->model->gpo_type == GPO_CANONLIDE35) + if (dev->model->gpo_type == GPO_CANONLIDE35) { -/* expect GPIO17 to be enabled, and GPIO9 to be disabled, +/* expect GPIO17 to be enabled, and GPIO9 to be disabled, while GPIO8 is disabled*/ -/* final state: GPIO8 disabled, GPIO9 enabled, GPIO17 disabled, +/* final state: GPIO8 disabled, GPIO9 enabled, GPIO17 disabled, GPIO18 disabled*/ sanei_genesys_read_register(dev, REG6D, &val); @@ -2898,7 +3269,7 @@ gl841_save_power(Genesys_Device * dev, SANE_Bool enable) { /*enable GPIO9*/ sanei_genesys_read_register(dev, REG6C, &val); sanei_genesys_write_register(dev, REG6C, val | 0x01); - + /*disable GPO17*/ sanei_genesys_read_register(dev, REG6B, &val); sanei_genesys_write_register(dev, REG6B, val & ~REG6B_GPO17); @@ -2923,14 +3294,14 @@ gl841_save_power(Genesys_Device * dev, SANE_Bool enable) { gl841_set_fe (dev, AFE_POWER_SAVE); - } - else + } + else { - if (dev->model->gpo_type == GPO_CANONLIDE35) + if (dev->model->gpo_type == GPO_CANONLIDE35) { -/* expect GPIO17 to be enabled, and GPIO9 to be disabled, +/* expect GPIO17 to be enabled, and GPIO9 to be disabled, while GPIO8 is disabled*/ -/* final state: GPIO8 enabled, GPIO9 disabled, GPIO17 enabled, +/* final state: GPIO8 enabled, GPIO9 disabled, GPIO17 enabled, GPIO18 enabled*/ sanei_genesys_read_register(dev, REG6D, &val); @@ -2959,7 +3330,7 @@ gl841_save_power(Genesys_Device * dev, SANE_Bool enable) { dev->calib_reg[reg_0x6b].value |= REG6B_GPO18; } - if (dev->model->gpo_type == GPO_DP665 + if (dev->model->gpo_type == GPO_DP665 || dev->model->gpo_type == GPO_DP685) { sanei_genesys_read_register(dev, REG6B, &val); @@ -3049,7 +3420,7 @@ gl841_set_powersaving (Genesys_Device * dev, local_reg[5].value = exposure_time & 255; /* lowbyte */ status = - gl841_bulk_write_register (dev, local_reg, + gl841_bulk_write_register (dev, local_reg, sizeof (local_reg)/sizeof (local_reg[0])); if (status != SANE_STATUS_GOOD) DBG (DBG_error, @@ -3060,13 +3431,19 @@ gl841_set_powersaving (Genesys_Device * dev, return status; } -static SANE_Status +#ifndef UNIT_TESTING +static +#endif +SANE_Status gl841_start_action (Genesys_Device * dev) { return sanei_genesys_write_register (dev, 0x0f, 0x01); } -static SANE_Status +#ifndef UNIT_TESTING +static +#endif +SANE_Status gl841_stop_action (Genesys_Device * dev) { Genesys_Register_Set local_reg[GENESYS_GL841_MAX_REGS+1]; @@ -3113,12 +3490,12 @@ gl841_stop_action (Genesys_Device * dev) return status; } - /* looks like writing the right registers to zero is enough to get the chip - out of scan mode into command mode, actually triggering(writing to + /* looks like writing the right registers to zero is enough to get the chip + out of scan mode into command mode, actually triggering(writing to register 0x0f) seems to be unnecessary */ loop = 10; - while (loop > 0) + while (loop > 0) { status = sanei_genesys_read_register(dev, 0x40, &val40); if (DBG_LEVEL >= DBG_io) @@ -3133,7 +3510,7 @@ gl841_stop_action (Genesys_Device * dev) DBGCOMPLETED; return status; } - + /* if scanner is in command mode, we are done */ if (!(val40 & REG40_DATAENB) && !(val40 & REG40_MOTMFLG)) { @@ -3154,7 +3531,7 @@ gl841_get_paper_sensor(Genesys_Device * dev, SANE_Bool * paper_loaded) { SANE_Status status; uint8_t val; - + status = sanei_genesys_read_register(dev, REG6D, &val); if (status != SANE_STATUS_GOOD) { @@ -3186,7 +3563,7 @@ gl841_eject_document (Genesys_Device * dev) DBG (DBG_proc, "gl841_eject_document: finished\n"); return SANE_STATUS_GOOD; } - + memset (local_reg, 0, sizeof (local_reg)); val = 0; @@ -3275,7 +3652,7 @@ gl841_eject_document (Genesys_Device * dev) } feed_mm = SANE_UNFIX(dev->model->eject_feed); - if (dev->document) + if (dev->document) { feed_mm += SANE_UNFIX(dev->model->post_scan); } @@ -3288,13 +3665,13 @@ gl841_eject_document (Genesys_Device * dev) sane_strstatus (status)); return status; } - + /* now feed for extra <number> steps */ loop = 0; while (loop < 300) /* do not wait longer then 30 seconds */ { unsigned int steps; - + status = sanei_genesys_read_feed_steps(dev, &steps); if (status != SANE_STATUS_GOOD) { @@ -3341,9 +3718,9 @@ gl841_load_document (Genesys_Device * dev) DBG (DBG_proc, "gl841_load_document\n"); while (loop > 0) /* do not wait longer then 30 seconds */ { - + RIE(gl841_get_paper_sensor(dev, &paper_loaded)); - + if (paper_loaded) { DBG (DBG_info, @@ -3426,7 +3803,7 @@ gl841_detect_document_end (Genesys_Device * dev) /* the current scancnt is also the final one, so we use it to * compute total bytes to read. We also add the line count to eject document */ total_bytes_to_read=(scancnt+postcnt)*dev->wpl; - + DBG (DBG_io, "%s: old total_bytes_to_read=%u\n",__FUNCTION__,(unsigned int)dev->total_bytes_to_read); DBG (DBG_io, "%s: new total_bytes_to_read=%u\n",__FUNCTION__,(unsigned int)total_bytes_to_read); @@ -3453,9 +3830,17 @@ gl841_begin_scan (Genesys_Device * dev, Genesys_Register_Set * reg, { SANE_Status status; Genesys_Register_Set local_reg[4]; + uint8_t val; DBG (DBG_proc, "gl841_begin_scan\n"); + if (dev->model->gpo_type == GPO_CANONLIDE80) + { + RIE (sanei_genesys_read_register (dev, REG6B, &val)); + val = REG6B_GPO18; + RIE (sanei_genesys_write_register (dev, REG6B, val)); + } + local_reg[0].address = 0x03; if (dev->model->ccd_type != CCD_PLUSTEK_3600) { @@ -3479,7 +3864,7 @@ gl841_begin_scan (Genesys_Device * dev, Genesys_Register_Set * reg, local_reg[3].value = 0x00; /* do not start motor yet */ status = - gl841_bulk_write_register (dev, local_reg, + gl841_bulk_write_register (dev, local_reg, sizeof (local_reg)/sizeof (local_reg[0])); if (status != SANE_STATUS_GOOD) { @@ -3522,7 +3907,7 @@ gl841_end_scan (Genesys_Device * dev, Genesys_Register_Set __sane_unused__ * reg return status; } } - + DBG (DBG_proc, "gl841_end_scan: completed\n"); return status; @@ -3530,7 +3915,7 @@ gl841_end_scan (Genesys_Device * dev, Genesys_Register_Set __sane_unused__ * reg /* Moves the slider to steps */ #ifndef UNIT_TESTING -static +static #endif SANE_Status gl841_feed (Genesys_Device * dev, int steps) @@ -3540,15 +3925,12 @@ gl841_feed (Genesys_Device * dev, int steps) uint8_t val; int loop; - DBG (DBG_proc, "gl841_feed (steps = %d)\n", - steps); + DBG (DBG_proc, "gl841_feed (steps = %d)\n", steps); - status = - gl841_stop_action (dev); + status = gl841_stop_action (dev); if (status != SANE_STATUS_GOOD) { - DBG (DBG_error, - "gl841_feed: failed to stop action: %s\n", + DBG (DBG_error, "gl841_feed: failed to stop action: %s\n", sane_strstatus (status)); return status; } @@ -3557,12 +3939,9 @@ gl841_feed (Genesys_Device * dev, int steps) gl841_init_optical_regs_off(local_reg); - gl841_init_motor_regs(dev,local_reg, - steps,MOTOR_ACTION_FEED,0); + gl841_init_motor_regs(dev,local_reg, steps,MOTOR_ACTION_FEED,0); - status = - gl841_bulk_write_register (dev, local_reg, - GENESYS_GL841_MAX_REGS); + status = gl841_bulk_write_register (dev, local_reg, GENESYS_GL841_MAX_REGS); if (status != SANE_STATUS_GOOD) { DBG (DBG_error, @@ -3579,8 +3958,7 @@ gl841_feed (Genesys_Device * dev, int steps) sane_strstatus (status)); gl841_stop_action (dev); /* send original registers */ - gl841_bulk_write_register (dev, dev->reg, - GENESYS_GL841_MAX_REGS); + gl841_bulk_write_register (dev, dev->reg, GENESYS_GL841_MAX_REGS); return status; } @@ -3595,7 +3973,7 @@ gl841_feed (Genesys_Device * dev, int steps) sane_strstatus (status)); return status; } - + if (!(val & REG41_MOTORENB)) /* motor enabled */ { DBG (DBG_proc, "gl841_feed: finished\n"); @@ -3636,14 +4014,20 @@ gl841_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) DBG (DBG_proc, "gl841_slow_back_home: finished\n"); return SANE_STATUS_GOOD; } - - /* reset gpio pin */ + + /* reset gpio pin */ if (dev->model->gpo_type == GPO_CANONLIDE35) { RIE (sanei_genesys_read_register (dev, REG6C, &val)); val = dev->gpo.value[0]; RIE (sanei_genesys_write_register (dev, REG6C, val)); } + if (dev->model->gpo_type == GPO_CANONLIDE80) + { + RIE (sanei_genesys_read_register (dev, REG6B, &val)); + val = REG6B_GPO18 | REG6B_GPO17; + RIE (sanei_genesys_write_register (dev, REG6B, val)); + } gl841_save_power(dev, SANE_FALSE); /* first read gives HOME_SENSOR true */ @@ -3706,7 +4090,7 @@ gl841_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) memcpy (local_reg, dev->reg, (GENESYS_GL841_MAX_REGS+1) * sizeof (Genesys_Register_Set)); gl841_init_motor_regs(dev,local_reg, 65536,MOTOR_ACTION_GO_HOME,0); - + /* set up for reverse and no scan */ r = sanei_genesys_get_address (local_reg, REG02); r->value |= REG02_MTRREV; @@ -3800,7 +4184,7 @@ gl841_search_start_position (Genesys_Device * dev) SCAN_FLAG_DISABLE_BUFFER_FULL_MOVE); if(status!=SANE_STATUS_GOOD) { - DBG (DBG_error, "%s: failed to init scan registers: %s\n", __FUNCTION__, + DBG (DBG_error, "%s: failed to init scan registers: %s\n", __FUNCTION__, sane_strstatus (status)); return status; } @@ -3810,7 +4194,7 @@ gl841_search_start_position (Genesys_Device * dev) gl841_bulk_write_register (dev, local_reg, GENESYS_GL841_MAX_REGS); if (status != SANE_STATUS_GOOD) { - DBG (DBG_error, "%s: failed to bulk write registers: %s\n", __FUNCTION__, + DBG (DBG_error, "%s: failed to bulk write registers: %s\n", __FUNCTION__, sane_strstatus (status)); return status; } @@ -3868,7 +4252,7 @@ gl841_search_start_position (Genesys_Device * dev) /* update regs to copy ASIC internal state */ memcpy (dev->reg, local_reg, (GENESYS_GL841_MAX_REGS + 1) * sizeof (Genesys_Register_Set)); -/*TODO: find out where sanei_genesys_search_reference_point +/*TODO: find out where sanei_genesys_search_reference_point stores information, and use that correctly*/ status = sanei_genesys_search_reference_point (dev, data, 0, dpi, pixels, @@ -3886,7 +4270,7 @@ gl841_search_start_position (Genesys_Device * dev) return SANE_STATUS_GOOD; } -/* +/* * sets up register for coarse gain calibration * todo: check it for scanners using it */ static SANE_Status @@ -3896,8 +4280,7 @@ gl841_init_regs_for_coarse_calibration (Genesys_Device * dev) uint8_t channels; uint8_t cksel; - DBG (DBG_proc, "gl841_init_regs_for_coarse_calibration\n"); - + DBGSTART; cksel = (dev->calib_reg[reg_0x18].value & REG18_CKSEL) + 1; /* clock speed = 1..4 clocks */ @@ -3913,7 +4296,7 @@ gl841_init_regs_for_coarse_calibration (Genesys_Device * dev) dev->settings.yres, 0, 0, - dev->sensor.optical_res / cksel, + dev->sensor.optical_res / cksel, /* XXX STEF XXX !!! */ 20, 16, channels, @@ -3945,13 +4328,11 @@ gl841_init_regs_for_coarse_calibration (Genesys_Device * dev) return status; } - DBG (DBG_proc, - "gl841_init_register_for_coarse_calibration: completed\n"); /* if (DBG_LEVEL >= DBG_info) sanei_gl841_print_registers (dev->calib_reg);*/ - + DBGCOMPLETED; return SANE_STATUS_GOOD; } @@ -3962,14 +4343,25 @@ gl841_init_regs_for_shading (Genesys_Device * dev) { SANE_Status status; SANE_Int ydpi; + float starty=0; - DBG (DBG_proc, "gl841_init_regs_for_shading: lines = %d\n", (int)dev->calib_lines); + DBGSTART; + DBG (DBG_proc, "%s: lines = %d\n", __FUNCTION__, (int)(dev->calib_lines)); + + /* initial calibration reg values */ + memcpy (dev->calib_reg, dev->reg, GENESYS_GL841_MAX_REGS * sizeof (Genesys_Register_Set)); ydpi = dev->motor.base_ydpi; - if (dev->motor.motor_id == MOTOR_PLUSTEK_3600) /* TODO PLUSTEK_3600: 1200dpi not yet working, produces dark bar */ + if (dev->model->motor_type == MOTOR_PLUSTEK_3600) /* TODO PLUSTEK_3600: 1200dpi not yet working, produces dark bar */ { ydpi = 600; } + if (dev->model->motor_type == MOTOR_CANONLIDE80) + { + ydpi = gl841_get_dpihw(dev); + /* get over extra dark area for this model */ + starty = 140; + } dev->calib_channels = 3; dev->calib_lines = dev->model->shading_lines; @@ -3978,7 +4370,7 @@ gl841_init_regs_for_shading (Genesys_Device * dev) dev->settings.xres, ydpi, 0, - 0, + starty, (dev->sensor.sensor_pixels * dev->settings.xres) / dev->sensor.optical_res, dev->calib_lines, 16, @@ -3986,36 +4378,27 @@ gl841_init_regs_for_shading (Genesys_Device * dev) dev->settings.color_filter, SCAN_FLAG_DISABLE_SHADING | SCAN_FLAG_DISABLE_GAMMA | -/* we don't handle differing shading areas very well */ -/* SCAN_FLAG_DISABLE_BUFFER_FULL_MOVE |*/ - SCAN_FLAG_IGNORE_LINE_DISTANCE | - SCAN_FLAG_USE_OPTICAL_RES - ); - - dev->calib_pixels = dev->current_setup.pixels; - + SCAN_FLAG_USE_OPTICAL_RES | + /*SCAN_FLAG_DISABLE_BUFFER_FULL_MOVE |*/ + SCAN_FLAG_IGNORE_LINE_DISTANCE); if (status != SANE_STATUS_GOOD) { - DBG (DBG_error, - "gl841_init_registers_for_shading: failed to setup scan: %s\n", - sane_strstatus (status)); + DBG (DBG_error, "%s: failed to setup scan: %s\n", __FUNCTION__, sane_strstatus (status)); return status; } - dev->scanhead_position_in_steps += dev->calib_lines; + dev->calib_pixels = dev->current_setup.pixels; + dev->scanhead_position_in_steps += dev->calib_lines + starty; - status = - gl841_bulk_write_register (dev, dev->calib_reg, GENESYS_GL841_MAX_REGS); + status = gl841_bulk_write_register (dev, dev->calib_reg, GENESYS_GL841_MAX_REGS); if (status != SANE_STATUS_GOOD) { - DBG (DBG_error, - "gl841_init_registers_for_shading: failed to bulk write registers: %s\n", + DBG (DBG_error, "%s: failed to bulk write registers: %s\n", __FUNCTION__, sane_strstatus (status)); return status; } - DBG (DBG_proc, "gl841_init_regs_for_shading: completed\n"); - + DBGCOMPLETED; return SANE_STATUS_GOOD; } @@ -4063,9 +4446,9 @@ gl841_init_regs_for_scan (Genesys_Device * dev) assumption: steps are expressed at maximum motor resolution - we need: - SANE_Fixed y_offset; - SANE_Fixed y_size; + we need: + SANE_Fixed y_offset; + SANE_Fixed y_size; SANE_Fixed y_offset_calib; mm_to_steps()=motor dpi / 2.54 / 10=motor dpi / MM_PER_INCH */ @@ -4076,7 +4459,9 @@ gl841_init_regs_for_scan (Genesys_Device * dev) move = 0; if (dev->model->flags & GENESYS_FLAG_SEARCH_START) - move += SANE_UNFIX (dev->model->y_offset_calib); + { + move += SANE_UNFIX (dev->model->y_offset_calib); + } DBG (DBG_info, "gl841_init_regs_for_scan: move=%f steps\n", move); @@ -4097,18 +4482,21 @@ gl841_init_regs_for_scan (Genesys_Device * dev) flags=0; - /* we enable true gray for cis scanners only, and just when doing + /* we enable true gray for cis scanners only, and just when doing * scan since color calibration is OK for this mode */ flags = 0; - + + /* true gray (led add for cis scanners) */ if(dev->model->is_cis && dev->settings.true_gray - &&dev->model->ccd_type != CCD_CANONLIDE35) + && dev->settings.scan_mode != SCAN_MODE_COLOR) { - flags |= OPTICAL_FLAG_ENABLE_LEDADD; + DBG (DBG_io, "%s: activating LEDADD\n", __FUNCTION__); + flags |= SCAN_FLAG_ENABLE_LEDADD; } + /* enable emulated lineart from gray data */ - if(dev->settings.scan_mode == SCAN_MODE_LINEART + if(dev->settings.scan_mode == SCAN_MODE_LINEART && dev->settings.dynamic_lineart) { flags |= SCAN_FLAG_DYNAMIC_LINEART; @@ -4126,7 +4514,7 @@ gl841_init_regs_for_scan (Genesys_Device * dev) channels, dev->settings.color_filter, flags); - + if (status != SANE_STATUS_GOOD) return status; @@ -4192,7 +4580,7 @@ gl841_send_gamma_table (Genesys_Device * dev) -needs working coarse/gain */ -static SANE_Status +GENESYS_STATIC SANE_Status gl841_led_calibration (Genesys_Device * dev) { int num_pixels; @@ -4205,8 +4593,9 @@ gl841_led_calibration (Genesys_Device * dev) int avg[3], avga, avge; int turn; char fn[20]; - uint16_t expr, expg, expb; + uint16_t exp[3], target; Genesys_Register_Set *r; + int move; SANE_Bool acceptable = SANE_FALSE; @@ -4214,21 +4603,22 @@ gl841_led_calibration (Genesys_Device * dev) uint16_t min_exposure=500; uint16_t max_exposure; - DBG (DBG_proc, "gl841_led_calibration\n"); - + DBGSTART; - if (dev->model->gpo_type == GPO_CANONLIDE35) + /* feed to white strip if needed */ + if (dev->model->y_offset_calib>0) { - status = gl841_feed(dev, 280);/*feed to white strip. canon lide 35 only.*/ - + move = SANE_UNFIX (dev->model->y_offset_calib); + move = (move * (dev->motor.base_ydpi)) / MM_PER_INCH; + DBG (DBG_io, "%s: move=%d lines\n", __FUNCTION__, move); + status = gl841_feed(dev, move); if (status != SANE_STATUS_GOOD) { - DBG (DBG_error, - "gl841_led_calibration: failed to feed: %s\n", - sane_strstatus (status)); + DBG (DBG_error, "%s: failed to feed: %s\n", __FUNCTION__, + sane_strstatus (status)); return status; } - } + } /* offset calibration is always done in color mode */ channels = 3; @@ -4254,7 +4644,7 @@ gl841_led_calibration (Genesys_Device * dev) if (status != SANE_STATUS_GOOD) { DBG (DBG_error, - "gl841_led_calibration: failed to setup scan: %s\n", + "%s: failed to setup scan: %s\n", __FUNCTION__, sane_strstatus (status)); return status; } @@ -4269,7 +4659,7 @@ gl841_led_calibration (Genesys_Device * dev) if (!line) return SANE_STATUS_NO_MEM; -/* +/* we try to get equal bright leds here: loop: @@ -4277,23 +4667,24 @@ gl841_led_calibration (Genesys_Device * dev) adjust exposure times */ - expr = (dev->sensor.regs_0x10_0x1d[0] << 8) | dev->sensor.regs_0x10_0x1d[1]; - expg = (dev->sensor.regs_0x10_0x1d[2] << 8) | dev->sensor.regs_0x10_0x1d[3]; - expb = (dev->sensor.regs_0x10_0x1d[4] << 8) | dev->sensor.regs_0x10_0x1d[5]; + exp[0] = (dev->sensor.regs_0x10_0x1d[0] << 8) | dev->sensor.regs_0x10_0x1d[1]; + exp[1] = (dev->sensor.regs_0x10_0x1d[2] << 8) | dev->sensor.regs_0x10_0x1d[3]; + exp[2] = (dev->sensor.regs_0x10_0x1d[4] << 8) | dev->sensor.regs_0x10_0x1d[5]; turn = 0; /* max exposure is set to ~2 time initial average * exposure, or 2 time last calibration exposure */ - max_exposure=((expr+expg+expb)/3)*2; + max_exposure=((exp[0]+exp[1]+exp[2])/3)*2; + target=dev->sensor.gain_white_ref*256; do { - dev->sensor.regs_0x10_0x1d[0] = (expr >> 8) & 0xff; - dev->sensor.regs_0x10_0x1d[1] = expr & 0xff; - dev->sensor.regs_0x10_0x1d[2] = (expg >> 8) & 0xff; - dev->sensor.regs_0x10_0x1d[3] = expg & 0xff; - dev->sensor.regs_0x10_0x1d[4] = (expb >> 8) & 0xff; - dev->sensor.regs_0x10_0x1d[5] = expb & 0xff; + dev->sensor.regs_0x10_0x1d[0] = (exp[0] >> 8) & 0xff; + dev->sensor.regs_0x10_0x1d[1] = exp[0] & 0xff; + dev->sensor.regs_0x10_0x1d[2] = (exp[1] >> 8) & 0xff; + dev->sensor.regs_0x10_0x1d[3] = exp[1] & 0xff; + dev->sensor.regs_0x10_0x1d[4] = (exp[2] >> 8) & 0xff; + dev->sensor.regs_0x10_0x1d[5] = exp[2] & 0xff; r = &(dev->calib_reg[reg_0x10]); for (i = 0; i < 6; i++, r++) { @@ -4301,14 +4692,12 @@ gl841_led_calibration (Genesys_Device * dev) RIE (sanei_genesys_write_register (dev, 0x10+i, dev->sensor.regs_0x10_0x1d[i])); } - RIE (gl841_bulk_write_register - (dev, dev->calib_reg, GENESYS_GL841_MAX_REGS)); + RIE (gl841_bulk_write_register (dev, dev->calib_reg, GENESYS_GL841_MAX_REGS)); - DBG (DBG_info, - "gl841_led_calibration: starting first line reading\n"); + DBG (DBG_info, "%s: starting line reading\n", __FUNCTION__); RIE (gl841_begin_scan (dev, dev->calib_reg, SANE_TRUE)); RIE (sanei_genesys_read_data_from_scanner (dev, line, total_size)); - + if (DBG_LEVEL >= DBG_data) { snprintf(fn,20,"led_%d.pnm",turn); sanei_genesys_write_pnm_file (fn, @@ -4317,15 +4706,14 @@ gl841_led_calibration (Genesys_Device * dev) channels, num_pixels, 1); } - - acceptable = SANE_TRUE; - + + /* compute average */ for (j = 0; j < channels; j++) { avg[j] = 0; for (i = 0; i < num_pixels; i++) { - if (dev->model->is_cis) + if (dev->model->is_cis) val = line[i * 2 + j * 2 * num_pixels + 1] * 256 + line[i * 2 + j * 2 * num_pixels]; @@ -4339,82 +4727,212 @@ gl841_led_calibration (Genesys_Device * dev) avg[j] /= num_pixels; } - DBG(DBG_info,"gl841_led_calibration: average: " - "%d,%d,%d\n", - avg[0],avg[1],avg[2]); + DBG(DBG_info,"%s: average: %d,%d,%d\n", __FUNCTION__, avg[0], avg[1], avg[2]); acceptable = SANE_TRUE; - + + /* exposure is acceptable if each color is in the %5 range + * of other color channels */ if (avg[0] < avg[1] * 0.95 || avg[1] < avg[0] * 0.95 || avg[0] < avg[2] * 0.95 || avg[2] < avg[0] * 0.95 || avg[1] < avg[2] * 0.95 || avg[2] < avg[1] * 0.95) + { + acceptable = SANE_FALSE; + } + + /* led exposure is not acceptable if white level is too low + * ~80 hardcoded value for white level */ + if(avg[0]<20000 || avg[1]<20000 || avg[2]<20000) + { acceptable = SANE_FALSE; + } - if (!acceptable) { - avga = (avg[0]+avg[1]+avg[2])/3; - expr = (expr * avga) / avg[0]; - expg = (expg * avga) / avg[1]; - expb = (expb * avga) / avg[2]; -/* - keep the resulting exposures below this value. - too long exposure drives the ccd into saturation. - we may fix this by relying on the fact that - we get a striped scan without shading, by means of - statistical calculation -*/ - avge = (expr + expg + expb) / 3; + /* for scanners using target value */ + if(target>0) + { + acceptable = SANE_TRUE; + for(i=0;i<3;i++) + { + /* we accept +- 2% delta from target */ + if(abs(avg[i]-target)>target/50) + { + exp[i]=(exp[i]*target)/avg[i]; + acceptable = SANE_FALSE; + } + } + } + else + { + if (!acceptable) + { + avga = (avg[0]+avg[1]+avg[2])/3; + exp[0] = (exp[0] * avga) / avg[0]; + exp[1] = (exp[1] * avga) / avg[1]; + exp[2] = (exp[2] * avga) / avg[2]; + /* + keep the resulting exposures below this value. + too long exposure drives the ccd into saturation. + we may fix this by relying on the fact that + we get a striped scan without shading, by means of + statistical calculation + */ + avge = (exp[0] + exp[1] + exp[2]) / 3; + + if (avge > max_exposure) { + exp[0] = (exp[0] * max_exposure) / avge; + exp[1] = (exp[1] * max_exposure) / avge; + exp[2] = (exp[2] * max_exposure) / avge; + } + if (avge < min_exposure) { + exp[0] = (exp[0] * min_exposure) / avge; + exp[1] = (exp[1] * min_exposure) / avge; + exp[2] = (exp[2] * min_exposure) / avge; + } - if (avge > max_exposure) { - expr = (expr * max_exposure) / avge; - expg = (expg * max_exposure) / avge; - expb = (expb * max_exposure) / avge; - } - if (avge < min_exposure) { - expr = (expr * min_exposure) / avge; - expg = (expg * min_exposure) / avge; - expb = (expb * min_exposure) / avge; - } - - } + } + } RIE (gl841_stop_action (dev)); turn++; } while (!acceptable && turn < 100); - - DBG(DBG_info,"gl841_led_calibration: acceptable exposure: %d,%d,%d\n", - expr,expg,expb); + + DBG(DBG_info,"%s: acceptable exposure: %d,%d,%d\n", __FUNCTION__, exp[0],exp[1],exp[2]); /* cleanup before return */ free (line); gl841_slow_back_home(dev, SANE_TRUE); - DBG (DBG_proc, "gl841_led_calibration: completed\n"); + DBGCOMPLETED; return status; } /** @brief calibration for AD frontend devices - * experiments show that modifying offset is of little (if no) influence - * so we just return - * CHRIS: This was added from gl646.c as again offset seems to make no - * difference - * - * TODO PLUSTEK_3600 Michael Rickmann: - * offset calibration makes a lot of a difference but currently - * makes everything to dark + * offset calibration assumes that the scanning head is on a black area + * For LiDE80 analog frontend + * 0x0003 : is gain and belongs to [0..63] + * 0x0006 : is offset + * We scan a line with no gain until average offset reaches the target */ static SANE_Status ad_fe_offset_calibration (Genesys_Device * dev) { SANE_Status status = SANE_STATUS_GOOD; + int num_pixels; + int total_size; + uint8_t *line; + int i; + int average; + int turn; + char fn[20]; + int top; + int bottom; + int target; + + DBGSTART; - DBG (DBG_proc, "ad_fe_offset_calibration: start\n"); - DBG (DBG_info, "ad_fe_offset_calibration: offset=(%d,%d,%d)\n", - dev->frontend.offset[0], dev->frontend.offset[1], - dev->frontend.offset[2]); - DBG (DBG_proc, "ad_fe_offset_calibration: end\n"); + /* don't impact 3600 behavior since we can't test it */ + if (dev->model->ccd_type == CCD_PLUSTEK_3600) + { + DBGCOMPLETED; + return status; + } + + status = gl841_init_scan_regs (dev, + dev->calib_reg, + dev->settings.xres, + dev->settings.yres, + 0, + 0, + (dev->sensor.sensor_pixels*dev->settings.xres) / dev->sensor.optical_res, + 1, + 8, + 3, + dev->settings.color_filter, + SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA | + SCAN_FLAG_SINGLE_LINE | + SCAN_FLAG_IGNORE_LINE_DISTANCE | + SCAN_FLAG_USE_OPTICAL_RES); + + if (status != SANE_STATUS_GOOD) + { + DBG (DBG_error, + "gl841_offset_calibration: failed to setup scan: %s\n", + sane_strstatus (status)); + return status; + } + + num_pixels = dev->current_setup.pixels; + total_size = num_pixels * 3 * 2 * 1; + + line = malloc (total_size); + if (line==NULL) + { + DBGCOMPLETED; + return SANE_STATUS_NO_MEM; + } + + dev->frontend.gain[0] = 0x00; + dev->frontend.gain[1] = 0x00; + dev->frontend.gain[2] = 0x00; + + /* loop on scan until target offset is reached */ + turn=0; + target=24; + bottom=0; + top=255; + do { + /* set up offset mid range */ + dev->frontend.offset[0] = (top+bottom)/2; + dev->frontend.offset[1] = (top+bottom)/2; + dev->frontend.offset[2] = (top+bottom)/2; + + /* scan line */ + DBG (DBG_info, "%s: starting line reading\n",__FUNCTION__); + gl841_bulk_write_register (dev, dev->calib_reg, GENESYS_GL841_MAX_REGS); + gl841_set_fe(dev, AFE_SET); + gl841_begin_scan (dev, dev->calib_reg, SANE_TRUE); + sanei_genesys_read_data_from_scanner (dev, line, total_size); + gl841_stop_action (dev); + if (DBG_LEVEL >= DBG_data) { + snprintf(fn,20,"offset_%02d.pnm",turn); + sanei_genesys_write_pnm_file (fn, line, 8, 3, num_pixels, 1); + } + + /* search for minimal value */ + average=0; + for(i=0;i<total_size;i++) + { + average+=line[i]; + } + average/=total_size; + DBG (DBG_data, "%s: average=%d\n", __FUNCTION__, average); + + /* if min value is above target, the current value becomes the new top + * else it is the new bottom */ + if(average>target) + { + top=(top+bottom)/2; + } + else + { + bottom=(top+bottom)/2; + } + turn++; + } while ((top-bottom)>1 && turn < 100); + + dev->frontend.offset[0]=0; + dev->frontend.offset[1]=0; + dev->frontend.offset[2]=0; + free(line); + DBG (DBG_info, "%s: offset=(%d,%d,%d)\n", __FUNCTION__, + dev->frontend.offset[0], + dev->frontend.offset[1], + dev->frontend.offset[2]); + DBGCOMPLETED; return status; } @@ -4425,7 +4943,7 @@ ad_fe_offset_calibration (Genesys_Device * dev) this function expects the slider to be where? */ -static SANE_Status +GENESYS_STATIC SANE_Status gl841_offset_calibration (Genesys_Device * dev) { int num_pixels; @@ -4443,14 +4961,14 @@ gl841_offset_calibration (Genesys_Device * dev) SANE_Bool acceptable = SANE_FALSE; int mintgt = 0x400; + DBG (DBG_proc, "gl841_offset_calibration\n"); + /* Analog Device fronted have a different calibration */ - if (dev->model->dac_type == DAC_PLUSTEK_3600) + if ((dev->reg[reg_0x04].value & REG04_FESET) == 0x02) { return ad_fe_offset_calibration (dev); } - DBG (DBG_proc, "gl841_offset_calibration\n"); - /* offset calibration is always done in color mode */ channels = 3; @@ -4501,15 +5019,15 @@ gl841_offset_calibration (Genesys_Device * dev) /*okay. the sensor black level is now at -260mV. we only get 0 from AFE...*/ /* we should probably do real calibration here: * -detect acceptable offset with binary search - * -calculate offset from this last version + * -calculate offset from this last version * - * acceptable offset means + * acceptable offset means * - few completely black pixels(<10%?) * - few completely white pixels(<10%?) * - * final offset should map the minimum not completely black + * final offset should map the minimum not completely black * pixel to 0(16 bits) - * + * * this does account for dummy pixels at the end of ccd * this assumes slider is at black strip(which is not quite as black as "no * signal"). @@ -4534,8 +5052,8 @@ gl841_offset_calibration (Genesys_Device * dev) for (j=0; j < channels; j++) { off[j] = (offh[j]+offl[j])/2; dev->frontend.offset[j] = off[j]; - } - + } + status = gl841_set_fe(dev, AFE_SET); if (status != SANE_STATUS_GOOD) @@ -4551,7 +5069,7 @@ gl841_offset_calibration (Genesys_Device * dev) RIEF2 (gl841_begin_scan (dev, dev->calib_reg, SANE_TRUE), first_line, second_line); RIEF2 (sanei_genesys_read_data_from_scanner (dev, first_line, total_size), first_line, second_line); - + if (DBG_LEVEL >= DBG_data) { snprintf(fn,20,"offset1_%02d.pnm",turn); sanei_genesys_write_pnm_file (fn, @@ -4560,9 +5078,9 @@ gl841_offset_calibration (Genesys_Device * dev) channels, num_pixels, 1); } - + acceptable = SANE_TRUE; - + for (j = 0; j < channels; j++) { cmin[j] = 0; @@ -4570,7 +5088,7 @@ gl841_offset_calibration (Genesys_Device * dev) for (i = 0; i < num_pixels; i++) { - if (dev->model->is_cis) + if (dev->model->is_cis) val = first_line[i * 2 + j * 2 * num_pixels + 1] * 256 + first_line[i * 2 + j * 2 * num_pixels]; @@ -4595,7 +5113,7 @@ gl841_offset_calibration (Genesys_Device * dev) offl[0] = off[0]; else offl[j] = off[j]; - } + } if (cmax[j] > num_pixels/100) { acceptable = SANE_FALSE; if (dev->model->is_cis) @@ -4618,7 +5136,7 @@ gl841_offset_calibration (Genesys_Device * dev) turn++; } while (!acceptable && turn < 100); - + DBG(DBG_info,"gl841_offset_calibration: acceptable offsets: %d,%d,%d\n", off[0],off[1],off[2]); @@ -4626,12 +5144,12 @@ gl841_offset_calibration (Genesys_Device * dev) for (j = 0; j < channels; j++) { off1[j] = off[j]; - + min1[j] = 65536; - - for (i = 0; i < num_pixels; i++) + + for (i = 0; i < num_pixels; i++) { - if (dev->model->is_cis) + if (dev->model->is_cis) val = first_line[i * 2 + j * 2 * num_pixels + 1] * 256 + first_line[i * 2 + j * 2 * num_pixels]; @@ -4643,20 +5161,20 @@ gl841_offset_calibration (Genesys_Device * dev) min1[j] = val; } } - + offl[0] = off[0]; offl[1] = off[0]; offl[2] = off[0]; turn = 0; - + do { - + for (j=0; j < channels; j++) { off[j] = (offh[j]+offl[j])/2; dev->frontend.offset[j] = off[j]; - } - + } + status = gl841_set_fe(dev, AFE_SET); if (status != SANE_STATUS_GOOD) @@ -4668,25 +5186,25 @@ gl841_offset_calibration (Genesys_Device * dev) sane_strstatus (status)); return status; } - + DBG (DBG_info, "gl841_offset_calibration: starting second line reading\n"); RIEF2 (gl841_bulk_write_register (dev, dev->calib_reg, GENESYS_GL841_MAX_REGS), first_line, second_line); RIEF2 (gl841_begin_scan (dev, dev->calib_reg, SANE_TRUE), first_line, second_line); RIEF2 (sanei_genesys_read_data_from_scanner (dev, second_line, total_size), first_line, second_line); - + if (DBG_LEVEL >= DBG_data) { - snprintf(fn,20,"offset2_%d.pnm",turn); + snprintf(fn,20,"offset2_%02d.pnm",turn); sanei_genesys_write_pnm_file (fn, second_line, 16, channels, num_pixels, 1); } - + acceptable = SANE_TRUE; - + for (j = 0; j < channels; j++) { cmin[j] = 0; @@ -4694,7 +5212,7 @@ gl841_offset_calibration (Genesys_Device * dev) for (i = 0; i < num_pixels; i++) { - if (dev->model->is_cis) + if (dev->model->is_cis) val = second_line[i * 2 + j * 2 * num_pixels + 1] * 256 + second_line[i * 2 + j * 2 * num_pixels]; @@ -4714,7 +5232,7 @@ gl841_offset_calibration (Genesys_Device * dev) offl[0] = off[0]; else offl[j] = off[j]; - } + } if (cmax[j] > num_pixels/100) { acceptable = SANE_FALSE; if (dev->model->is_cis) @@ -4738,7 +5256,7 @@ gl841_offset_calibration (Genesys_Device * dev) turn++; } while (!acceptable && turn < 100); - + DBG(DBG_info,"gl841_offset_calibration: acceptable offsets: %d,%d,%d\n", off[0],off[1],off[2]); @@ -4746,12 +5264,12 @@ gl841_offset_calibration (Genesys_Device * dev) for (j = 0; j < channels; j++) { off2[j] = off[j]; - + min2[j] = 65536; - for (i = 0; i < num_pixels; i++) + for (i = 0; i < num_pixels; i++) { - if (dev->model->is_cis) + if (dev->model->is_cis) val = second_line[i * 2 + j * 2 * num_pixels + 1] * 256 + second_line[i * 2 + j * 2 * num_pixels]; @@ -4770,11 +5288,11 @@ gl841_offset_calibration (Genesys_Device * dev) DBG(DBG_info,"gl841_offset_calibration: second set: %d/%d,%d/%d,%d/%d\n", off2[0],min2[0],off2[1],min2[1],off2[2],min2[2]); -/* +/* calculate offset for each channel based on minimal pixel value min1 at offset off1 and minimal pixel value min2 at offset off2 - + to get min at off, values are linearly interpolated: min=real+off*fact min1=real+off1*fact @@ -4833,16 +5351,16 @@ gl841_offset_calibration (Genesys_Device * dev) } -/* alternative coarse gain calibration +/* alternative coarse gain calibration this on uses the settings from offset_calibration and uses only one scanline */ /* with offset and coarse calibration we only want to get our input range into - a reasonable shape. the fine calibration of the upper and lower bounds will + a reasonable shape. the fine calibration of the upper and lower bounds will be done with shading. */ -static SANE_Status +GENESYS_STATIC SANE_Status gl841_coarse_gain_calibration (Genesys_Device * dev, int dpi) { int num_pixels; @@ -4853,18 +5371,22 @@ gl841_coarse_gain_calibration (Genesys_Device * dev, int dpi) int max[3]; float gain[3]; int val; + int lines=1; + int move; - DBG (DBG_proc, "gl841_coarse_gain_calibration dpi=%d\n", dpi); + DBG (DBG_proc, "%s: dpi=%d\n", __FUNCTION__, dpi); - if (dev->model->gpo_type == GPO_CANONLIDE35) + /* feed to white strip if needed */ + if (dev->model->y_offset_calib>0) { - status = gl841_feed(dev, 280);/*feed to white strip. canon lide 35 only.*/ - + move = SANE_UNFIX (dev->model->y_offset_calib); + move = (move * (dev->motor.base_ydpi)) / MM_PER_INCH; + DBG (DBG_io, "%s: move=%d lines\n", __FUNCTION__, move); + status = gl841_feed(dev, move); if (status != SANE_STATUS_GOOD) { - DBG (DBG_error, - "gl841_coarse_gain_calibration: failed to feed: %s\n", - sane_strstatus (status)); + DBG (DBG_error, "%s: failed to feed: %s\n", __FUNCTION__, + sane_strstatus (status)); return status; } } @@ -4879,7 +5401,7 @@ gl841_coarse_gain_calibration (Genesys_Device * dev, int dpi) 0, 0, (dev->sensor.sensor_pixels*dev->settings.xres) / dev->sensor.optical_res, - 1, + lines, 16, channels, dev->settings.color_filter, @@ -4892,18 +5414,16 @@ gl841_coarse_gain_calibration (Genesys_Device * dev, int dpi) if (status != SANE_STATUS_GOOD) { - DBG (DBG_error, - "gl841_coarse_calibration: failed to setup scan: %s\n", + DBG (DBG_error, "%s: failed to setup scan: %s\n", __FUNCTION__, sane_strstatus (status)); return status; } - RIE (gl841_bulk_write_register - (dev, dev->calib_reg, GENESYS_GL841_MAX_REGS)); + RIE (gl841_bulk_write_register (dev, dev->calib_reg, GENESYS_GL841_MAX_REGS)); num_pixels = dev->current_setup.pixels; - total_size = num_pixels * channels * 2 * 1; /* colors * bytes_per_color * scan lines */ + total_size = num_pixels * channels * 2 * lines; /* colors * bytes_per_color * scan lines */ line = malloc (total_size); if (!line) @@ -4913,18 +5433,17 @@ gl841_coarse_gain_calibration (Genesys_Device * dev, int dpi) RIEF (sanei_genesys_read_data_from_scanner (dev, line, total_size), line); if (DBG_LEVEL >= DBG_data) - sanei_genesys_write_pnm_file ("coarse.pnm", line, 16, - channels, num_pixels, 1); + sanei_genesys_write_pnm_file ("coarse.pnm", line, 16, channels, num_pixels, lines); /* average high level for each channel and compute gain - to reach the target code + to reach the target code we only use the central half of the CCD data */ for (j = 0; j < channels; j++) { max[j] = 0; for (i = 0; i < num_pixels; i++) { - if (dev->model->is_cis) + if (dev->model->is_cis) val = line[i * 2 + j * 2 * num_pixels + 1] * 256 + line[i * 2 + j * 2 * num_pixels]; @@ -4941,24 +5460,28 @@ gl841_coarse_gain_calibration (Genesys_Device * dev, int dpi) if (dev->model->dac_type == DAC_CANONLIDE35 || dev->model->dac_type == DAC_WOLFSON_XP300 || - dev->model->dac_type == DAC_WOLFSON_DSM600) { + dev->model->dac_type == DAC_WOLFSON_DSM600) + { gain[j] *= 0.69;/*seems we don't get the real maximum. empirically derived*/ - if (283 - 208/gain[j] > 255) + if (283 - 208/gain[j] > 255) dev->frontend.gain[j] = 255; else if (283 - 208/gain[j] < 0) dev->frontend.gain[j] = 0; else dev->frontend.gain[j] = 283 - 208/gain[j]; - } + } + else if (dev->model->dac_type == DAC_CANONLIDE80) + { + dev->frontend.gain[j] = gain[j]*12; + } - DBG (DBG_proc, - "gl841_coarse_gain_calibration: channel %d, max=%d, gain = %f, setting:%d\n", + DBG (DBG_proc, "%s: channel %d, max=%d, gain = %f, setting:%d\n", __FUNCTION__, j, max[j], gain[j],dev->frontend.gain[j]); } for (j = 0; j < channels; j++) { - if(gain[j] > 10) + if(gain[j] > 10) { DBG (DBG_error0, "**********************************************\n"); DBG (DBG_error0, "**********************************************\n"); @@ -4975,7 +5498,7 @@ gl841_coarse_gain_calibration (Genesys_Device * dev, int dpi) return SANE_STATUS_JAMMED; #endif } - + } if (dev->model->is_cis) { @@ -4986,19 +5509,23 @@ gl841_coarse_gain_calibration (Genesys_Device * dev, int dpi) dev->frontend.gain[2] = dev->frontend.gain[1] = dev->frontend.gain[0]; } - if (channels == 1) + if (channels == 1) { dev->frontend.gain[0] = dev->frontend.gain[1]; dev->frontend.gain[2] = dev->frontend.gain[1]; } - + free (line); + DBG (DBG_info, "%s: gain=(%d,%d,%d)\n", __FUNCTION__, + dev->frontend.gain[0], + dev->frontend.gain[1], + dev->frontend.gain[2]); RIE (gl841_stop_action (dev)); gl841_slow_back_home(dev, SANE_TRUE); - DBG (DBG_proc, "gl841_coarse_gain_calibration: completed\n"); + DBGCOMPLETED; return status; } @@ -5069,7 +5596,7 @@ gl841_init_regs_for_warmup (Genesys_Device * dev, * as a by-product, also check for lock */ #ifndef UNIT_TESTING -static +static #endif SANE_Status sanei_gl841_repark_head (Genesys_Device * dev) @@ -5077,7 +5604,7 @@ sanei_gl841_repark_head (Genesys_Device * dev) SANE_Status status; DBG (DBG_proc, "sanei_gl841_repark_head\n"); - + status = gl841_feed(dev,232); if (status != SANE_STATUS_GOOD) @@ -5095,7 +5622,7 @@ sanei_gl841_repark_head (Genesys_Device * dev) } static SANE_Status -gl841_is_compatible_calibration (Genesys_Device * dev, +gl841_is_compatible_calibration (Genesys_Device * dev, Genesys_Calibration_Cache *cache, int for_overwrite) { @@ -5146,7 +5673,7 @@ gl841_is_compatible_calibration (Genesys_Device * dev, return SANE_STATUS_GOOD; } -/* +/* * initialize ASIC : registers, motor tables, and gamma tables * then ensure scanner's head is at home */ @@ -5181,16 +5708,15 @@ gl841_init (Genesys_Device * dev) dev->settings.color_filter = 0; - /* Set default values for registers */ - gl841_init_registers (dev); - /* ASIC reset */ RIE (sanei_genesys_write_register (dev, 0x0e, 0x01)); RIE (sanei_genesys_write_register (dev, 0x0e, 0x00)); + /* Set default values for registers */ + gl841_init_registers (dev); + /* Write initial registers */ - RIE (gl841_bulk_write_register - (dev, dev->reg, GENESYS_GL841_MAX_REGS)); + RIE (gl841_bulk_write_register (dev, dev->reg, GENESYS_GL841_MAX_REGS)); /* Test ASIC and RAM */ if (!(dev->model->flags & GENESYS_FLAG_LAZY_INIT)) @@ -5246,7 +5772,7 @@ gl841_init (Genesys_Device * dev) dev->sensor.gamma[i]); } } - + /* send gamma tables */ status = gl841_send_gamma_table (dev); if (status != SANE_STATUS_GOOD) @@ -5320,8 +5846,9 @@ gl841_update_hardware_sensors (Genesys_Scanner * s) */ SANE_Status status = SANE_STATUS_GOOD; uint8_t val; - - if (s->dev->model->gpo_type == GPO_CANONLIDE35) + + if (s->dev->model->gpo_type == GPO_CANONLIDE35 + || s->dev->model->gpo_type == GPO_CANONLIDE80) { RIE(sanei_genesys_read_register(s->dev, REG6D, &val)); @@ -5352,7 +5879,7 @@ gl841_update_hardware_sensors (Genesys_Scanner * s) /** @brief search for a full width black or white strip. * This function searches for a black or white stripe across the scanning area. - * When searching backward, the searched area must completely be of the desired + * When searching backward, the searched area must completely be of the desired * color since this area will be used for calibration which scans forward. * @param dev scanner device * @param forward SANE_TRUE if searching forward, SANE_FALSE if searching backward @@ -5665,6 +6192,127 @@ gl841_search_strip (Genesys_Device * dev, SANE_Bool forward, SANE_Bool black) return status; } +/** + * Send shading calibration data. The buffer is considered to always hold values + * for all the channels. + */ +GENESYS_STATIC +SANE_Status +gl841_send_shading_data (Genesys_Device * dev, uint8_t * data, int size) +{ + SANE_Status status = SANE_STATUS_GOOD; + uint32_t length, x, factor, pixels, i; + uint32_t half; + uint32_t lines, channels; + uint16_t dpiset, dpihw, strpixel ,endpixel, beginpixel; + uint8_t *buffer,*ptr,*src; + + DBGSTART; + DBG( DBG_io2, "%s: writing %d bytes of shading data\n",__FUNCTION__,size); + + /* old method if no SHDAREA */ + if((dev->reg[reg_0x01].value & REG01_SHDAREA) == 0) + { + /* start address */ + status = sanei_genesys_set_buffer_address (dev, 0x0000); + if (status != SANE_STATUS_GOOD) + { + DBG (DBG_error, "%s: failed to set buffer address: %s\n", __FUNCTION__, + sane_strstatus (status)); + return status; + } + + /* shading data whole line */ + status = dev->model->cmd_set->bulk_write_data (dev, 0x3c, data, size); + if (status != SANE_STATUS_GOOD) + { + DBG (DBG_error, "%s: failed to send shading table: %s\n", __FUNCTION__, + sane_strstatus (status)); + return status; + } + DBGCOMPLETED; + return status; + } + + /* data is whole line, we extract only the part for the scanned area */ + length = (uint32_t) (size / 3); + sanei_genesys_get_double(dev->reg,REG_STRPIXEL,&strpixel); + sanei_genesys_get_double(dev->reg,REG_ENDPIXEL,&endpixel); + DBG( DBG_io2, "%s: STRPIXEL=%d, ENDPIXEL=%d, PIXELS=%d\n",__FUNCTION__,strpixel,endpixel,endpixel-strpixel); + + /* compute deletion/average factor */ + sanei_genesys_get_double(dev->reg,REG_DPISET,&dpiset); + dpihw = gl841_get_dpihw(dev); + half=dev->current_setup.half_ccd+1; + factor=dpihw/dpiset; + DBG( DBG_io2, "%s: dpihw=%d, dpiset=%d, half_ccd=%d, factor=%d\n",__FUNCTION__,dpihw,dpiset,half-1,factor); + + /* binary data logging */ + if(DBG_LEVEL>=DBG_data) + { + dev->binary=fopen("binary.pnm","wb"); + sanei_genesys_get_triple(dev->reg, REG_LINCNT, &lines); + channels=dev->current_setup.channels; + if(dev->binary!=NULL) + { + fprintf(dev->binary,"P5\n%d %d\n%d\n",(endpixel-strpixel)/factor*channels,lines/channels,255); + } + } + + /* turn pixel value into bytes 2x16 bits words */ + strpixel*=2*2; /* 2 words of 2 bytes */ + endpixel*=2*2; + pixels=endpixel-strpixel; + + /* shading pixel begin is start pixel minus start pixel during shading + * calibration. Currently only cases handled are full and half ccd resolution. + */ + beginpixel = dev->sensor.CCD_start_xoffset / half; + beginpixel += dev->sensor.dummy_pixel + 1; + DBG(DBG_io2, "%s: ORIGIN PIXEL=%d\n", __FUNCTION__, beginpixel); + beginpixel = (strpixel-beginpixel*2*2)/factor; + DBG(DBG_io2, "%s: BEGIN PIXEL=%d\n",__FUNCTION__,beginpixel/4); + + DBG(DBG_io2, "%s: using chunks of %d bytes (%d shading data pixels)\n",__FUNCTION__,length, length/4); + buffer=(uint8_t *)malloc(pixels); + memset(buffer,0,pixels); + + /* write actual shading data contigously + * channel by channel, starting at addr 0x0000 + * */ + for(i=0;i<3;i++) + { + /* copy data to work buffer and process it */ + /* coefficent destination */ + ptr=buffer; + + /* 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; + ptr[0]=src[0]; + ptr[1]=src[1]; + ptr[2]=src[2]; + ptr[3]=src[3]; + + /* next shading coefficient */ + ptr+=4; + } + + /* 0x5400 alignment for LIDE80 internal memory */ + RIEF(sanei_genesys_set_buffer_address (dev, 0x5400*i), buffer); + RIEF(dev->model->cmd_set->bulk_write_data (dev, 0x3c, buffer, pixels), buffer); + } + + free(buffer); + DBGCOMPLETED; + + return status; +} + + /** the gl841 command set */ static Genesys_Command_Set gl841_cmd_set = { "gl841-generic", /* the name of this set */ @@ -5718,8 +6366,9 @@ static Genesys_Command_Set gl841_cmd_set = { gl841_is_compatible_calibration, NULL, - NULL, + gl841_send_shading_data, gl841_calculate_current_setup, + NULL, NULL }; diff --git a/backend/genesys_gl841.h b/backend/genesys_gl841.h index bbf2ee1..bbb79f1 100644 --- a/backend/genesys_gl841.h +++ b/backend/genesys_gl841.h @@ -3,42 +3,42 @@ Copyright (C) 2011-2013 Stphane Voltz <stef.dev@free.fr> This file is part of the SANE package. - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - + As a special exception, the authors of SANE give permission for additional uses of the libraries contained in this release of SANE. - + The exception is that, if you link a SANE library with other files to produce an executable, this does not by itself cause the resulting executable to be covered by the GNU General Public License. Your use of that executable is in no way restricted on account of linking the SANE library code into it. - + This exception does not, however, invalidate any other reasons why the executable file might be covered by the GNU General Public License. - + If you submit changes to SANE to the maintainers to be included in a subsequent release, you agree by submitting the changes that those changes may be distributed with this exception intact. If you write modifications of your own for SANE, it is your choice whether to permit this exception to apply to your modifications. - If you do not wish that, delete this exception notice. + If you do not wish that, delete this exception notice. */ #include "genesys.h" @@ -157,11 +157,25 @@ #define REG1DS_TGSHLD 0 +#define REG1E 0x1e #define REG1E_WDTIME 0xf0 #define REG1ES_WDTIME 4 #define REG1E_LINESEL 0x0f #define REG1ES_LINESEL 0 +#define REG_EXPR 0x10 +#define REG_EXPG 0x12 +#define REG_EXPB 0x14 +#define REG_STEPNO 0x21 +#define REG_FWDSTEP 0x22 +#define REG_BWDSTEP 0x23 +#define REG_FASTNO 0x24 +#define REG_LINCNT 0x25 +#define REG_DPISET 0x2c +#define REG_STRPIXEL 0x30 +#define REG_ENDPIXEL 0x32 +#define REG_LPERIOD 0x38 + #define REG40_HISPDFLG 0x04 #define REG40_MOTMFLG 0x02 #define REG40_DATAENB 0x01 @@ -231,8 +245,8 @@ #define REG6C_GPIOL 0xff #define REG6D 0x6d - #define REG6E 0x6e +#define REG6F 0x6f #define REG87_LEDADD 0x04 @@ -348,8 +362,13 @@ enum reg_0x85, reg_0x86, reg_0x87, + reg_0x88, + reg_0x89, GENESYS_GL841_MAX_REGS }; + +#define INITREG(adr,val) {dev->reg[index].address=adr;dev->reg[index].value=val;index++;} + /** * prototypes declaration in case of unit testing */ @@ -387,4 +406,51 @@ sanei_gl841_repark_head (Genesys_Device * dev); SANE_Status gl841_feed (Genesys_Device * dev, int steps); +SANE_Status +gl841_init_motor_regs_scan(Genesys_Device * dev, + Genesys_Register_Set * reg, + unsigned int scan_exposure_time, + float scan_yres, + int scan_step_type, + unsigned int scan_lines, + unsigned int scan_dummy, + unsigned int feed_steps, + int scan_power_mode, + unsigned int flags) ; + +SANE_Status +gl841_stop_action (Genesys_Device * dev); + +SANE_Status +gl841_start_action (Genesys_Device * dev); + +SANE_Status +gl841_init_motor_regs(Genesys_Device * dev, + Genesys_Register_Set * reg, + unsigned int feed_steps, + unsigned int action, + unsigned int flags); + +SANE_Status gl841_send_slope_table (Genesys_Device * dev, int table_nr, uint16_t * slope_table, int steps); + +SANE_Status gl841_bulk_write_data_gamma (Genesys_Device * dev, uint8_t addr, uint8_t * data, size_t len); + +SANE_Status gl841_offset_calibration (Genesys_Device * dev); + +SANE_Status gl841_coarse_gain_calibration (Genesys_Device * dev, int dpi); + +SANE_Status gl841_led_calibration (Genesys_Device * dev); + +SANE_Status gl841_send_shading_data (Genesys_Device * dev, uint8_t * data, int size); + +int gl841_scan_step_type(Genesys_Device *dev, int yres); +SANE_Status gl841_write_freq(Genesys_Device *dev, unsigned int ydpi); #endif + +GENESYS_STATIC +int gl841_exposure_time(Genesys_Device *dev, + float slope_dpi, + int scan_step_type, + int start, + int used_pixels, + int *scan_power_mode); diff --git a/backend/genesys_gl843.c b/backend/genesys_gl843.c index 3648d09..2b0d8fa 100644 --- a/backend/genesys_gl843.c +++ b/backend/genesys_gl843.c @@ -1,45 +1,45 @@ /* sane - Scanner Access Now Easy. Copyright (C) 2010-2013 Stphane Voltz <stef.dev@free.fr> - - + + This file is part of the SANE package. - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - + As a special exception, the authors of SANE give permission for additional uses of the libraries contained in this release of SANE. - + The exception is that, if you link a SANE library with other files to produce an executable, this does not by itself cause the resulting executable to be covered by the GNU General Public License. Your use of that executable is in no way restricted on account of linking the SANE library code into it. - + This exception does not, however, invalidate any other reasons why the executable file might be covered by the GNU General Public License. - + If you submit changes to SANE to the maintainers to be included in a subsequent release, you agree by submitting the changes that those changes may be distributed with this exception intact. - + If you write modifications of your own for SANE, it is your choice whether to permit this exception to apply to your modifications. - If you do not wish that, delete this exception notice. + If you do not wish that, delete this exception notice. */ #undef BACKEND_NAME @@ -294,7 +294,7 @@ gl843_bulk_read_data (Genesys_Device * dev, uint8_t addr, } /**************************************************************************** - Mid level functions + Mid level functions ****************************************************************************/ static SANE_Bool @@ -439,7 +439,7 @@ static Sensor_Profile *get_sensor_profile(int sensor_type, int dpi, int flags) } else { - if(sp[i].dpi>=dpi + if(sp[i].dpi>=dpi && sp[i].dpi<sp[idx].dpi) { idx=i; @@ -485,7 +485,7 @@ gl843_setup_sensor (Genesys_Device * dev, Genesys_Register_Set * regs, int dpi,i if (r) r->value = sensor->regs_0x52_0x5e[i]; } - + /* specific registers */ r = sanei_genesys_get_address (regs, 0x0c); if (r) @@ -664,7 +664,7 @@ gl843_init_registers (Genesys_Device * dev) SETREG (0x94, 0xff); SETREG (0xab, 0x50); } - + /* so many time burnt for this register ....*/ if (strcmp (dev->model->name, "canon-canoscan-4400f") != 0 &&strcmp (dev->model->name, "canon-canoscan-8400f") != 0) @@ -683,7 +683,7 @@ gl843_init_registers (Genesys_Device * dev) SETREG (0x06, 0xd8); /* SCANMOD=110, PWRBIT and GAIN4 */ SETREG (0x0a, 0x18); SETREG (0x0b, 0x69); - + /* CIS exposure is used for XPA lamp movement */ SETREG (0x10, 0x2c); SETREG (0x11, 0x09); @@ -698,7 +698,7 @@ gl843_init_registers (Genesys_Device * dev) SETREG (0x71, 0x02); SETREG (0x72, 0x00); SETREG (0x73, 0x00); - + SETREG (0x80, 0x50); SETREG (0x9d, 0x08); SETREG (0xab, 0x40); @@ -710,7 +710,7 @@ gl843_init_registers (Genesys_Device * dev) SETREG (0x9b, 0x80); SETREG (0xac, 0x00); } - + if (strcmp (dev->model->name, "canon-canoscan-4400f") == 0) { SETREG (0x06, 0xf0); /* SCANMOD=111, PWRBIT and no GAIN4 */ @@ -732,7 +732,7 @@ gl843_init_registers (Genesys_Device * dev) sanei_genesys_set_double(dev->reg,REG_EXPG,0x9c40); sanei_genesys_set_double(dev->reg,REG_EXPB,0x9c40); } - + if (strcmp (dev->model->name, "canon-canoscan-8400f") == 0) { SETREG (0x03, 0x1c); @@ -775,7 +775,7 @@ gl843_init_registers (Genesys_Device * dev) DBGCOMPLETED; } -/* Send slope table for motor movement +/* Send slope table for motor movement slope_table in machine byte order */ #ifndef UNIT_TESTING @@ -1032,7 +1032,7 @@ gl843_init_motor_regs_scan (Genesys_Device * dev, feedl<<=scan_step_type; dist = scan_steps; - if (use_fast_fed) + if (use_fast_fed) { dist += fast_steps*2; } @@ -1089,7 +1089,7 @@ gl843_init_motor_regs_scan (Genesys_Device * dev, { r->value = 0x50; coeff=dev->sensor.optical_res/sanei_genesys_compute_dpihw(dev, scan_yres); - if (dev->model->motor_type == MOTOR_KVSS080) + if (dev->model->motor_type == MOTOR_KVSS080) { if(coeff>=1) { @@ -1130,7 +1130,7 @@ static int gl843_compute_exposure(Genesys_Device *dev, int xres, int flags) /** @brief setup optical related registers * start and pixels are expressed in optical sensor resolution coordinate - * space. + * space. * @param dev device to use * @param reg registers to set up * @param exposure exposure time to use @@ -1190,7 +1190,7 @@ gl843_init_optical_regs_scan (Genesys_Device * dev, /* sensor parameters */ gl843_setup_sensor (dev, reg, dpihw, flags); - /* resolution is divided according to CKSEL which is known once sensor is set up */ + /* resolution is divided according to CKSEL which is known once sensor is set up */ r = sanei_genesys_get_address (reg, REG18); cksel= (r->value & REG18_CKSEL)+1; DBG (DBG_io2, "%s: cksel=%d\n", __FUNCTION__, cksel); @@ -1208,8 +1208,8 @@ gl843_init_optical_regs_scan (Genesys_Device * dev, used_pixels=endx-startx; /* in case of stagger we have to start at an odd coordinate */ - if ((flags & OPTICAL_FLAG_STAGGER) - &&((startx & 1)==0)) + if ((flags & OPTICAL_FLAG_STAGGER) + &&((startx & 1)==0)) { startx++; endx++; @@ -1218,7 +1218,7 @@ gl843_init_optical_regs_scan (Genesys_Device * dev, status = gl843_set_fe (dev, AFE_SET); if (status != SANE_STATUS_GOOD) { - DBG (DBG_error, "%s: failed to set frontend: %s\n", __FUNCTION__, + DBG (DBG_error, "%s: failed to set frontend: %s\n", __FUNCTION__, sane_strstatus (status)); return status; } @@ -1450,7 +1450,7 @@ gl843_init_scan_regs (Genesys_Device * dev, /* stagger starting at 2400, and not applied for calibration */ stagger = 0; - if ( (yres>1200) + if ( (yres>1200) && ((flags & SCAN_FLAG_IGNORE_LINE_DISTANCE)==0) && (dev->model->flags & GENESYS_FLAG_STAGGERED_LINE)) { @@ -1458,7 +1458,7 @@ gl843_init_scan_regs (Genesys_Device * dev, } DBG (DBG_info, "%s : stagger=%d lines\n", __FUNCTION__, stagger); - /* we enable true gray for cis scanners only, and just when doing + /* we enable true gray for cis scanners only, and just when doing * scan since color calibration is OK for this mode */ oflags = 0; @@ -1495,7 +1495,7 @@ gl843_init_scan_regs (Genesys_Device * dev, /* use detected left margin and fixed value */ /* start */ start = startx; - + /* compute correct pixels number */ used_pixels = (pixels * optical_res) / xres; DBG (DBG_info, "%s: used_pixels=%d\n", __FUNCTION__, used_pixels); @@ -1566,7 +1566,7 @@ gl843_init_scan_regs (Genesys_Device * dev, /*** motor parameters ***/ /* it seems base_dpi of the G4050 motor is changed above 600 dpi*/ - if (dev->model->motor_type == MOTOR_G4050 && yres>600) + if (dev->model->motor_type == MOTOR_G4050 && yres>600) { dev->ld_shift_r = (dev->model->ld_shift_r*3800)/dev->motor.base_ydpi; dev->ld_shift_g = (dev->model->ld_shift_g*3800)/dev->motor.base_ydpi; @@ -1797,7 +1797,7 @@ gl843_calculate_current_setup (Genesys_Device * dev) DBG (DBG_info, "%s : exposure=%d pixels\n", __FUNCTION__, exposure); /* it seems base_dpi of the G4050 motor is changed above 600 dpi*/ - if (dev->model->motor_type == MOTOR_G4050 && yres>600) + if (dev->model->motor_type == MOTOR_G4050 && yres>600) { dev->ld_shift_r = (dev->model->ld_shift_r*3800)/dev->motor.base_ydpi; dev->ld_shift_g = (dev->model->ld_shift_g*3800)/dev->motor.base_ydpi; @@ -1901,7 +1901,7 @@ gl843_save_power (Genesys_Device * dev, SANE_Bool enable) return SANE_STATUS_INVAL; /* switch KV-SS080 lamp off */ - if (dev->model->gpo_type == GPO_KVSS080) + if (dev->model->gpo_type == GPO_KVSS080) { RIE(sanei_genesys_read_register (dev, REG6C, &val)); if(enable) @@ -1978,7 +1978,7 @@ gl843_stop_action (Genesys_Device * dev) status = sanei_genesys_write_register (dev, REG01, val); if (status != SANE_STATUS_GOOD) { - DBG (DBG_error, "%s: failed to write register 01: %s\n", __FUNCTION__, + DBG (DBG_error, "%s: failed to write register 01: %s\n", __FUNCTION__, sane_strstatus (status)); return status; } @@ -2110,7 +2110,7 @@ gl843_detect_document_end (Genesys_Device * dev) flines); } - /* adjust number of bytes to read + /* adjust number of bytes to read * we need to read the final bytes which are word per line * number of last lines * to have doc leaving feeder */ lines = @@ -2149,7 +2149,7 @@ gl843_detect_document_end (Genesys_Device * dev) if (flines > lines) { /* change the value controlling communication with the frontend : - * total bytes to read is current value plus the number of remaining lines + * total bytes to read is current value plus the number of remaining lines * multiplied by bytes per line */ sublines = flines - lines; @@ -2419,13 +2419,13 @@ gl843_end_scan (Genesys_Device * dev, Genesys_Register_Set * reg, if (val & (REG03_XPASEL|REG03_LAMPPWR)) { sanei_genesys_read_register (dev, REGA6, &val); - + /* switch on regular lamp */ val |= 0x40; /* no XPA lamp power (2 bits for level: __11 ____) */ val &= ~0x30; - + RIE (sanei_genesys_write_register (dev, REGA6, val)); } @@ -2459,7 +2459,7 @@ static SANE_Status gl843_park_xpa_lamp (Genesys_Device * dev) Genesys_Register_Set *r; uint8_t val; int loop = 0; - + DBGSTART; /* copy scan settings */ @@ -2470,7 +2470,7 @@ static SANE_Status gl843_park_xpa_lamp (Genesys_Device * dev) /* clear scan and feed count */ RIE (sanei_genesys_write_register (dev, REG0D, REG0D_CLRLNCNT | REG0D_CLRMCNT)); - + /* set up for reverse and no scan */ r = sanei_genesys_get_address (local_reg, REG02); r->value |= REG02_MTRREV; @@ -2591,7 +2591,7 @@ gl843_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) memcpy (local_reg, dev->reg, GENESYS_GL843_MAX_REGS * sizeof (Genesys_Register_Set)); resolution=sanei_genesys_get_lowest_ydpi(dev); - gl843_init_scan_regs (dev, + status = gl843_init_scan_regs (dev, local_reg, resolution, resolution, @@ -2607,10 +2607,18 @@ gl843_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) SCAN_FLAG_DISABLE_GAMMA | SCAN_FLAG_DISABLE_BUFFER_FULL_MOVE | SCAN_FLAG_IGNORE_LINE_DISTANCE); + if (status != SANE_STATUS_GOOD) + { + DBG (DBG_error, + "gl843_slow_back_home: failed to set up registers: %s\n", + sane_strstatus (status)); + DBGCOMPLETED; + return status; + } /* clear scan and feed count */ RIE (sanei_genesys_write_register (dev, REG0D, REG0D_CLRLNCNT | REG0D_CLRMCNT)); - + /* set up for reverse and no scan */ r = sanei_genesys_get_address (local_reg, REG02); r->value |= REG02_MTRREV; @@ -2795,7 +2803,7 @@ gl843_search_start_position (Genesys_Device * dev) return SANE_STATUS_GOOD; } -/* +/* * sets up register for coarse gain calibration * todo: check it for scanners using it */ static SANE_Status @@ -2879,7 +2887,7 @@ gl843_feed (Genesys_Device * dev, unsigned int steps) memcpy (local_reg, dev->reg, GENESYS_GL843_MAX_REGS * sizeof (Genesys_Register_Set)); resolution=sanei_genesys_get_lowest_ydpi(dev); - gl843_init_scan_regs (dev, + status = gl843_init_scan_regs (dev, local_reg, resolution, resolution, @@ -2895,15 +2903,23 @@ gl843_feed (Genesys_Device * dev, unsigned int steps) SCAN_FLAG_DISABLE_GAMMA | SCAN_FLAG_FEEDING | SCAN_FLAG_IGNORE_LINE_DISTANCE); + if (status != SANE_STATUS_GOOD) + { + DBG (DBG_error, + "gl843_feed: failed to set up registers: %s\n", + sane_strstatus (status)); + DBGCOMPLETED; + return status; + } /* clear scan and feed count */ RIE (sanei_genesys_write_register (dev, REG0D, REG0D_CLRLNCNT)); RIE (sanei_genesys_write_register (dev, REG0D, REG0D_CLRMCNT)); - + /* set up for no scan */ r = sanei_genesys_get_address (local_reg, REG01); r->value &= ~REG01_SCAN; - + /* send registers */ RIE (dev->model->cmd_set->bulk_write_register (dev, local_reg, GENESYS_GL843_MAX_REGS)); @@ -2925,7 +2941,7 @@ gl843_feed (Genesys_Device * dev, unsigned int steps) status = sanei_genesys_get_status (dev, &val); } while (status == SANE_STATUS_GOOD && !(val & FEEDFSH)); - + DBGCOMPLETED; return SANE_STATUS_GOOD; } @@ -2941,7 +2957,7 @@ gl843_init_regs_for_shading (Genesys_Device * dev) uint16_t strpixel; DBGSTART; - + /* initial calibration reg values */ memcpy (dev->calib_reg, dev->reg, GENESYS_GL843_MAX_REGS * sizeof (Genesys_Register_Set)); @@ -3053,7 +3069,7 @@ gl843_init_regs_for_scan (Genesys_Device * dev) flags = 0; /* enable emulated lineart from gray data */ - if(dev->settings.scan_mode == SCAN_MODE_LINEART + if(dev->settings.scan_mode == SCAN_MODE_LINEART && dev->settings.dynamic_lineart) { flags |= SCAN_FLAG_DYNAMIC_LINEART; @@ -3080,7 +3096,7 @@ gl843_init_regs_for_scan (Genesys_Device * dev) return SANE_STATUS_GOOD; } -/** +/** * This function sends gamma tables to ASIC */ static SANE_Status @@ -3210,7 +3226,7 @@ gl843_led_calibration (Genesys_Device * dev) if (!line) return SANE_STATUS_NO_MEM; -/* +/* we try to get equal bright leds here: loop: @@ -3294,9 +3310,9 @@ gl843_led_calibration (Genesys_Device * dev) /* keep the resulting exposures below this value. too long exposure drives the ccd into saturation. - we may fix this by relying on the fact that + we may fix this by relying on the fact that we get a striped scan without shading, by means of - statistical calculation + statistical calculation */ avge = (expr + expg + expb) / 3; @@ -3561,13 +3577,13 @@ gl843_offset_calibration (Genesys_Device * dev) } -/* alternative coarse gain calibration +/* alternative coarse gain calibration this on uses the settings from offset_calibration and uses only one scanline */ /* with offset and coarse calibration we only want to get our input range into - a reasonable shape. the fine calibration of the upper and lower bounds will + a reasonable shape. the fine calibration of the upper and lower bounds will be done with shading. */ static SANE_Status @@ -3781,7 +3797,7 @@ gl843_init_regs_for_warmup (Genesys_Device * dev, return SANE_STATUS_GOOD; } -/** +/** * set up GPIO/GPOE for idle state WRITE GPIO[17-21]= GPIO19 WRITE GPOE[17-21]= GPOE21 GPOE20 GPOE19 GPOE18 @@ -3842,7 +3858,7 @@ gl843_boot (Genesys_Device * dev, SANE_Bool cold) RIE (sanei_genesys_write_register (dev, 0x0e, 0x01)); RIE (sanei_genesys_write_register (dev, 0x0e, 0x00)); } - + if(dev->usb_mode == 1) { val = 0x14; @@ -3898,7 +3914,7 @@ gl843_boot (Genesys_Device * dev, SANE_Bool cold) /* setup gpio */ RIE (gl843_init_gpio (dev)); - + gl843_feed (dev, 300); usleep (100000); @@ -3993,7 +4009,7 @@ SANE_Status gl843_move_to_ta (Genesys_Device * dev) /** @brief search for a full width black or white strip. * This function searches for a black or white stripe across the scanning area. - * When searching backward, the searched area must completely be of the desired + * When searching backward, the searched area must completely be of the desired * color since this area will be used for calibration which scans forward. * @param dev scanner device * @param forward SANE_TRUE if searching forward, SANE_FALSE if searching backward @@ -4310,7 +4326,7 @@ gl843_send_shading_data (Genesys_Device * dev, uint8_t * data, int size) uint16_t dpiset, strpixel, endpixel, startx, factor; DBGSTART; - + offset=0; length=size; r = sanei_genesys_get_address (dev->reg, REG01); @@ -4337,7 +4353,7 @@ gl843_send_shading_data (Genesys_Device * dev, uint8_t * data, int size) sanei_genesys_get_double(dev->reg,REG_ENDPIXEL,&endpixel); strpixel*=tgtime; endpixel*=tgtime; - + /* 16 bit words, 2 words per color, 3 color channels */ offset=(strpixel-startx)*2*2*3; length=(endpixel-strpixel)*2*2*3; @@ -4378,13 +4394,13 @@ gl843_send_shading_data (Genesys_Device * dev, uint8_t * data, int size) free(final_data); return status; } - + status = dev->model->cmd_set->bulk_write_data (dev, 0x3c, final_data, count); if (status != SANE_STATUS_GOOD) { DBG (DBG_error, "%s: failed to send shading table: %s\n", __FUNCTION__, sane_strstatus (status)); } - + free(final_data); DBGCOMPLETED; return status; @@ -4446,7 +4462,8 @@ static Genesys_Command_Set gl843_cmd_set = { gl843_move_to_ta, gl843_send_shading_data, gl843_calculate_current_setup, - gl843_boot + gl843_boot, + NULL }; SANE_Status diff --git a/backend/genesys_gl843.h b/backend/genesys_gl843.h index 241a2ed..f31f0ee 100644 --- a/backend/genesys_gl843.h +++ b/backend/genesys_gl843.h @@ -3,42 +3,42 @@ Copyright (C) 2010-2013 Stphane Voltz <stef.dev@free.fr> This file is part of the SANE package. - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - + As a special exception, the authors of SANE give permission for additional uses of the libraries contained in this release of SANE. - + The exception is that, if you link a SANE library with other files to produce an executable, this does not by itself cause the resulting executable to be covered by the GNU General Public License. Your use of that executable is in no way restricted on account of linking the SANE library code into it. - + This exception does not, however, invalidate any other reasons why the executable file might be covered by the GNU General Public License. - + If you submit changes to SANE to the maintainers to be included in a subsequent release, you agree by submitting the changes that those changes may be distributed with this exception intact. If you write modifications of your own for SANE, it is your choice whether to permit this exception to apply to your modifications. - If you do not wish that, delete this exception notice. + If you do not wish that, delete this exception notice. */ #include "genesys.h" diff --git a/backend/genesys_gl846.c b/backend/genesys_gl846.c index 5e1f0f4..3991693 100644 --- a/backend/genesys_gl846.c +++ b/backend/genesys_gl846.c @@ -1,45 +1,45 @@ /* sane - Scanner Access Now Easy. Copyright (C) 2012-2013 Stphane Voltz <stef.dev@free.fr> - - + + This file is part of the SANE package. - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - + As a special exception, the authors of SANE give permission for additional uses of the libraries contained in this release of SANE. - + The exception is that, if you link a SANE library with other files to produce an executable, this does not by itself cause the resulting executable to be covered by the GNU General Public License. Your use of that executable is in no way restricted on account of linking the SANE library code into it. - + This exception does not, however, invalidate any other reasons why the executable file might be covered by the GNU General Public License. - + If you submit changes to SANE to the maintainers to be included in a subsequent release, you agree by submitting the changes that those changes may be distributed with this exception intact. - + If you write modifications of your own for SANE, it is your choice whether to permit this exception to apply to your modifications. - If you do not wish that, delete this exception notice. + If you do not wish that, delete this exception notice. */ /** @file @@ -62,7 +62,7 @@ /** @brief read scanned data * Read in 0xeff0 maximum sized blocks. This read is done in 2 - * parts if not multple of 512. First read is rounded to a multiple of 512 bytes, last read fetches the + * parts if not multple of 512. First read is rounded to a multiple of 512 bytes, last read fetches the * remainder. Read addr is always 0x10000000 with the memory layout setup. * @param dev device to read data from * @param addr address within ASIC memory space, unused but kept for API @@ -128,7 +128,7 @@ gl846_bulk_read_data (Genesys_Device * dev, uint8_t addr, read /= 512; read *= 512; } - + DBG (DBG_io2, "gl846_bulk_read_data: trying to read %lu bytes of data\n", (u_long) read); @@ -180,7 +180,7 @@ gl846_bulk_read_data (Genesys_Device * dev, uint8_t addr, } /**************************************************************************** - Mid level functions + Mid level functions ****************************************************************************/ static SANE_Bool @@ -304,7 +304,7 @@ static Sensor_Profile *get_sensor_profile(int sensor_type, int dpi) } else { - if(sensors[i].dpi>=dpi + if(sensors[i].dpi>=dpi && sensors[i].dpi<sensors[idx].dpi) { idx=i; @@ -560,7 +560,7 @@ gl846_init_registers (Genesys_Device * dev) DBGCOMPLETED; } -/**@brief send slope table for motor movement +/**@brief send slope table for motor movement * Send slope_table in machine byte order * @param dev device to send slope table * @param table_nr index of the slope table in ASIC memory @@ -633,7 +633,7 @@ gl846_set_adi_fe (Genesys_Device * dev, uint8_t set) /* wait for FE to be ready */ status = sanei_genesys_get_status (dev, &val8); - while (val8 & REG41_FEBUSY); + while (val8 & REG41_FEBUSY) { usleep (10000); status = sanei_genesys_get_status (dev, &val8); @@ -776,7 +776,7 @@ gl846_init_motor_regs_scan (Genesys_Device * dev, use_fast_fed=0; /* no fast fed since feed works well */ - if(dev->settings.yres==4444 && feed_steps>100 + if(dev->settings.yres==4444 && feed_steps>100 && ((flags & MOTOR_FLAG_FEED)==0)) { use_fast_fed=1; @@ -845,7 +845,7 @@ gl846_init_motor_regs_scan (Genesys_Device * dev, /* correct move distance by acceleration and deceleration amounts */ feedl=feed_steps; - if (use_fast_fed) + if (use_fast_fed) { feedl<<=fast_step_type; dist=(scan_steps+2*fast_steps)*factor; @@ -887,7 +887,7 @@ gl846_init_motor_regs_scan (Genesys_Device * dev, */ /* if quarter step, bipolar Vref2 */ - /* XXX STEF XXX GPIO + /* XXX STEF XXX GPIO if (scan_step_type > 1) { if (scan_step_type < 3) @@ -1021,11 +1021,11 @@ gl846_init_optical_regs_scan (Genesys_Device * dev, "half_ccd=%d, flags=%x\n", exposure_time, used_res, start, pixels, channels, depth, half_ccd, flags); - /* resolution is divided according to CKSEL */ + /* resolution is divided according to CKSEL */ r = sanei_genesys_get_address (reg, REG18); cksel= (r->value & REG18_CKSEL)+1; DBG (DBG_io2, "%s: cksel=%d\n", __FUNCTION__, cksel); - + /* to manage high resolution device while keeping good * low resolution scanning speed, we make hardware dpi vary */ dpihw=sanei_genesys_compute_dpihw(dev, used_res * cksel); @@ -1040,7 +1040,7 @@ gl846_init_optical_regs_scan (Genesys_Device * dev, /* start and end coordinate in optical dpi coordinates */ startx = start/cksel+dev->sensor.CCD_start_xoffset; used_pixels=pixels/cksel; - + /* end of sensor window */ endx = startx + used_pixels; @@ -1184,7 +1184,7 @@ gl846_init_optical_regs_scan (Genesys_Device * dev, { r->value |= REG87_LEDADD; } - /* RGB weighting + /* RGB weighting r = sanei_genesys_get_address (reg, 0x01); r->value &= ~REG01_TRUEGRAY; if (channels == 1 && (flags & OPTICAL_FLAG_ENABLE_LEDADD)) @@ -1229,7 +1229,7 @@ gl846_init_optical_regs_scan (Genesys_Device * dev, DBG (DBG_io2, "%s: dev->len =%lu\n", __FUNCTION__, (unsigned long)dev->len); DBG (DBG_io2, "%s: dev->dist =%lu\n", __FUNCTION__, (unsigned long)dev->dist); DBG (DBG_io2, "%s: dev->segnb =%lu\n", __FUNCTION__, (unsigned long)dev->segnb); - + words_per_line *= channels; dev->wpl = words_per_line; @@ -1248,7 +1248,7 @@ gl846_init_optical_regs_scan (Genesys_Device * dev, r = sanei_genesys_get_address (reg, 0x34); r->value = dev->sensor.dummy_pixel; - + DBGCOMPLETED; return SANE_STATUS_GOOD; } @@ -1383,7 +1383,7 @@ gl846_init_scan_regs (Genesys_Device * dev, depth = 8; } - /* we enable true gray for cis scanners only, and just when doing + /* we enable true gray for cis scanners only, and just when doing * scan since color calibration is OK for this mode */ oflags = 0; @@ -1393,7 +1393,7 @@ gl846_init_scan_regs (Genesys_Device * dev, oflags |= OPTICAL_FLAG_DISABLE_GAMMA; if(flags & SCAN_FLAG_DISABLE_LAMP) oflags |= OPTICAL_FLAG_DISABLE_LAMP; - + if (dev->model->is_cis && dev->settings.true_gray) { oflags |= OPTICAL_FLAG_ENABLE_LEDADD; @@ -1504,12 +1504,12 @@ gl846_init_scan_regs (Genesys_Device * dev, /* theory : target_size = (dev->settings.pixels * dev->settings.lines * channels * depth) / 8; - but it suffers from integer overflow so we do the following: + but it suffers from integer overflow so we do the following: - 1 bit color images store color data byte-wise, eg byte 0 contains - 8 bits of red data, byte 1 contains 8 bits of green, byte 2 contains + 1 bit color images store color data byte-wise, eg byte 0 contains + 8 bits of red data, byte 1 contains 8 bits of green, byte 2 contains 8 bits of blue. - This does not fix the overflow, though. + This does not fix the overflow, though. 644mp*16 = 10gp, leading to an overflow -- pierre */ @@ -1969,13 +1969,13 @@ gl846_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) } memcpy (local_reg, dev->reg, GENESYS_GL846_MAX_REGS * sizeof (Genesys_Register_Set)); - + resolution=sanei_genesys_get_lowest_ydpi(dev); - + /* TODO add scan_mode to the API */ scan_mode= dev->settings.scan_mode; dev->settings.scan_mode=SCAN_MODE_LINEART; - gl846_init_scan_regs (dev, + status = gl846_init_scan_regs (dev, local_reg, resolution, resolution, @@ -1989,11 +1989,19 @@ gl846_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) SCAN_FLAG_DISABLE_SHADING | SCAN_FLAG_DISABLE_GAMMA | SCAN_FLAG_IGNORE_LINE_DISTANCE); + if (status != SANE_STATUS_GOOD) + { + DBG (DBG_error, + "gl846_slow_back_home: failed to set up registers: %s\n", + sane_strstatus (status)); + DBGCOMPLETED; + return status; + } dev->settings.scan_mode=scan_mode; /* clear scan and feed count */ RIE (sanei_genesys_write_register (dev, REG0D, REG0D_CLRLNCNT | REG0D_CLRMCNT)); - + /* set up for reverse */ r = sanei_genesys_get_address (local_reg, REG02); r->value |= REG02_MTRREV; @@ -2153,7 +2161,7 @@ gl846_search_start_position (Genesys_Device * dev) memcpy (dev->reg, local_reg, GENESYS_GL846_MAX_REGS * sizeof (Genesys_Register_Set)); -/*TODO: find out where sanei_genesys_search_reference_point +/*TODO: find out where sanei_genesys_search_reference_point stores information, and use that correctly*/ status = sanei_genesys_search_reference_point (dev, data, 0, dpi, pixels, @@ -2171,7 +2179,7 @@ gl846_search_start_position (Genesys_Device * dev) return SANE_STATUS_GOOD; } -/* +/* * sets up register for coarse gain calibration * todo: check it for scanners using it */ static SANE_Status @@ -2255,7 +2263,7 @@ gl846_feed (Genesys_Device * dev, unsigned int steps) memcpy (local_reg, dev->reg, GENESYS_GL846_MAX_REGS * sizeof (Genesys_Register_Set)); resolution=sanei_genesys_get_lowest_ydpi(dev); - gl846_init_scan_regs (dev, + status = gl846_init_scan_regs (dev, local_reg, resolution, resolution, @@ -2270,6 +2278,14 @@ gl846_feed (Genesys_Device * dev, unsigned int steps) SCAN_FLAG_DISABLE_GAMMA | SCAN_FLAG_FEEDING | SCAN_FLAG_IGNORE_LINE_DISTANCE); + if (status != SANE_STATUS_GOOD) + { + DBG (DBG_error, + "gl846_feed: failed to set up registers: %s\n", + sane_strstatus (status)); + DBGCOMPLETED; + return status; + } /* set exposure to zero */ sanei_genesys_set_triple(local_reg,REG_EXPR,0); @@ -2279,11 +2295,11 @@ gl846_feed (Genesys_Device * dev, unsigned int steps) /* clear scan and feed count */ RIE (sanei_genesys_write_register (dev, REG0D, REG0D_CLRLNCNT)); RIE (sanei_genesys_write_register (dev, REG0D, REG0D_CLRMCNT)); - + /* set up for no scan */ r = sanei_genesys_get_address (local_reg, REG01); r->value &= ~REG01_SCAN; - + /* send registers */ RIE (dev->model->cmd_set->bulk_write_register (dev, local_reg, GENESYS_GL846_MAX_REGS)); @@ -2308,7 +2324,7 @@ gl846_feed (Genesys_Device * dev, unsigned int steps) /* then stop scanning */ RIE(gl846_stop_action (dev)); - + DBGCOMPLETED; return SANE_STATUS_GOOD; } @@ -2335,7 +2351,7 @@ gl846_init_regs_for_shading (Genesys_Device * dev) DBG (DBG_io, "%s: calib_lines = %d\n", __FUNCTION__, (unsigned int)dev->calib_lines); DBG (DBG_io, "%s: calib_pixels = %d\n", __FUNCTION__, (unsigned int)dev->calib_pixels); - /* this is aworkaround insufficent distance for slope + /* this is aworkaround insufficent distance for slope * motor acceleration TODO special motor slope for shading */ move=1; if(dev->calib_resolution<1200) @@ -2364,7 +2380,7 @@ gl846_init_regs_for_shading (Genesys_Device * dev) DBG (DBG_error, "%s: failed to setup scan: %s\n", __FUNCTION__, sane_strstatus (status)); return status; } - + status = dev->model->cmd_set->bulk_write_register (dev, dev->calib_reg, GENESYS_GL846_MAX_REGS); if (status != SANE_STATUS_GOOD) { @@ -2421,9 +2437,9 @@ gl846_init_regs_for_scan (Genesys_Device * dev) assumption: steps are expressed at maximum motor resolution - we need: - SANE_Fixed y_offset; - SANE_Fixed y_size; + we need: + SANE_Fixed y_offset; + SANE_Fixed y_size; SANE_Fixed y_offset_calib; mm_to_steps()=motor dpi / 2.54 / 10=motor dpi / MM_PER_INCH */ @@ -2453,7 +2469,7 @@ gl846_init_regs_for_scan (Genesys_Device * dev) } move=500; } - + DBG (DBG_info, "gl846_init_regs_for_scan: move=%f steps\n", move); DBG (DBG_info, "%s: move=%f steps\n", __FUNCTION__, move); @@ -2465,7 +2481,7 @@ gl846_init_regs_for_scan (Genesys_Device * dev) flags = 0; /* emulated lineart from gray data is required for now */ - if(dev->settings.scan_mode == SCAN_MODE_LINEART + if(dev->settings.scan_mode == SCAN_MODE_LINEART && dev->settings.dynamic_lineart) { flags |= SCAN_FLAG_DYNAMIC_LINEART; @@ -2489,7 +2505,7 @@ gl846_init_regs_for_scan (Genesys_Device * dev) if (status != SANE_STATUS_GOOD) return status; - + DBGCOMPLETED; return SANE_STATUS_GOOD; } @@ -2512,7 +2528,7 @@ gl846_send_shading_data (Genesys_Device * dev, uint8_t * data, int size) DBGSTART; DBG( DBG_io2, "%s: writing %d bytes of shading data\n",__FUNCTION__,size); - /* shading data is plit in 3 (up to 5 with IR) areas + /* shading data is plit in 3 (up to 5 with IR) areas write(0x10014000,0x00000dd8) URB 23429 bulk_out len 3544 wrote 0x33 0x10 0x.... write(0x1003e000,0x00000dd8) @@ -2542,14 +2558,14 @@ gl846_send_shading_data (Genesys_Device * dev, uint8_t * data, int size) fprintf(dev->binary,"P5\n%d %d\n%d\n",(endpixel-strpixel)/factor*channels,lines/channels,255); } } - + pixels=endpixel-strpixel; /* since we're using SHDAREA, substract startx coordinate from shading */ strpixel-=((dev->sensor.CCD_start_xoffset*600)/dev->sensor.optical_res); - + /* turn pixel value into bytes 2x16 bits words */ - strpixel*=2*2; + strpixel*=2*2; pixels*=2*2; /* allocate temporary buffer */ @@ -2578,18 +2594,19 @@ gl846_send_shading_data (Genesys_Device * dev, uint8_t * data, int size) ptr[1]=src[1]; ptr[2]=src[2]; ptr[3]=src[3]; - + /* next shading coefficient */ ptr+=4; } - RIE (sanei_genesys_read_register (dev, 0xd0+i, &val)); + RIEF (sanei_genesys_read_register (dev, 0xd0+i, &val), buffer); addr = val * 8192 + 0x10000000; status = sanei_genesys_write_ahb (dev->dn, dev->usb_mode, addr, pixels, buffer); if (status != SANE_STATUS_GOOD) { DBG (DBG_error, "gl846_send_shading_data; write to AHB failed (%s)\n", sane_strstatus (status)); + free(buffer); return status; } } @@ -2640,7 +2657,7 @@ gl846_led_calibration (Genesys_Device * dev) used_res=sanei_genesys_compute_dpihw(dev,dev->settings.xres); sensor=get_sensor_profile(dev->model->ccd_type, used_res); num_pixels = (dev->sensor.sensor_pixels*used_res)/dev->sensor.optical_res; - + /* initial calibration reg values */ memcpy (dev->calib_reg, dev->reg, GENESYS_GL846_MAX_REGS * sizeof (Genesys_Register_Set)); @@ -2770,18 +2787,18 @@ gl846_led_calibration (Genesys_Device * dev) /* cleanup before return */ free (line); - + /* go back home */ if(move>20) { status=gl846_slow_back_home (dev, SANE_TRUE); } - + DBGCOMPLETED; return status; } -/** +/** * set up GPIO/GPOE for idle state */ static SANE_Status @@ -2805,7 +2822,7 @@ gl846_init_gpio (Genesys_Device * dev) RIE (sanei_genesys_write_register (dev, REGA7, gpios[idx].ra7)); RIE (sanei_genesys_write_register (dev, REGA6, gpios[idx].ra6)); - + RIE (sanei_genesys_write_register (dev, REG6B, gpios[idx].r6b)); RIE (sanei_genesys_write_register (dev, REG6C, gpios[idx].r6c)); RIE (sanei_genesys_write_register (dev, REG6D, gpios[idx].r6d)); @@ -2819,7 +2836,7 @@ gl846_init_gpio (Genesys_Device * dev) return status; } -/** +/** * set memory layout by filling values in dedicated registers */ static SANE_Status @@ -2867,7 +2884,7 @@ gl846_init_memory_layout (Genesys_Device * dev) */ #ifndef UNIT_TESTING static -#endif +#endif SANE_Status gl846_boot (Genesys_Device * dev, SANE_Bool cold) { @@ -2882,7 +2899,7 @@ gl846_boot (Genesys_Device * dev, SANE_Bool cold) RIE (sanei_genesys_write_register (dev, 0x0e, 0x01)); RIE (sanei_genesys_write_register (dev, 0x0e, 0x00)); } - + if(dev->usb_mode == 1) { val = 0x14; @@ -2950,7 +2967,7 @@ SANE_Status gl846_init (Genesys_Device * dev) DBG_INIT (); DBGSTART; - + status=sanei_genesys_asic_init(dev, GENESYS_GL846_MAX_REGS); DBGCOMPLETED; @@ -2990,7 +3007,7 @@ gl846_update_hardware_sensors (Genesys_Scanner * s) /** @brief search for a full width black or white strip. * This function searches for a black or white stripe across the scanning area. - * When searching backward, the searched area must completely be of the desired + * When searching backward, the searched area must completely be of the desired * color since this area will be used for calibration which scans forward. * @param dev scanner device * @param forward SANE_TRUE if searching forward, SANE_FALSE if searching backward @@ -3013,7 +3030,15 @@ gl846_search_strip (Genesys_Device * dev, SANE_Bool forward, SANE_Bool black) DBG (DBG_proc, "gl846_search_strip %s %s\n", black ? "black" : "white", forward ? "forward" : "reverse"); - gl846_set_fe (dev, AFE_SET); + status = gl846_set_fe (dev, AFE_SET); + if (status != SANE_STATUS_GOOD) + { + DBG (DBG_error, + "gl846_search_strip: gl846_set_fe() failed: %s\n", + sane_strstatus(status)); + return status; + } + status = gl846_stop_action (dev); if (status != SANE_STATUS_GOOD) { @@ -3415,7 +3440,7 @@ gl846_offset_calibration (Genesys_Device * dev) snprintf(title,20,"offset%03d.pnm",bottom); sanei_genesys_write_pnm_file (title, first_line, bpp, channels, pixels, lines); } - + bottomavg = dark_average (first_line, pixels, lines, channels, black_pixels); DBG (DBG_io2, "gl846_offset_calibration: bottom avg=%d\n", bottomavg); @@ -3429,7 +3454,7 @@ gl846_offset_calibration (Genesys_Device * dev) DBG (DBG_info, "gl846_offset_calibration: starting second line reading\n"); RIEF2 (gl846_begin_scan (dev, dev->calib_reg, SANE_TRUE), first_line, second_line); RIEF2 (sanei_genesys_read_data_from_scanner (dev, second_line, total_size), first_line, second_line); - + topavg = dark_average (second_line, pixels, lines, channels, black_pixels); DBG (DBG_io2, "gl846_offset_calibration: top avg=%d\n", topavg); @@ -3572,24 +3597,10 @@ gl846_coarse_gain_calibration (Genesys_Device * dev, int dpi) max[j] = 0; for (i = pixels/4; i < (pixels*3/4); i++) { - if(bpp==16) - { - if (dev->model->is_cis) - val = - line[i * 2 + j * 2 * pixels + 1] * 256 + - line[i * 2 + j * 2 * pixels]; - else - val = - line[i * 2 * channels + 2 * j + 1] * 256 + - line[i * 2 * channels + 2 * j]; - } - else - { if (dev->model->is_cis) val = line[i + j * pixels]; else val = line[i * channels + j]; - } max[j] += val; } @@ -3619,12 +3630,6 @@ gl846_coarse_gain_calibration (Genesys_Device * dev, int dpi) dev->frontend.gain[2] = dev->frontend.gain[1] = dev->frontend.gain[0]; } - if (channels == 1) - { - dev->frontend.gain[0] = dev->frontend.gain[1]; - dev->frontend.gain[2] = dev->frontend.gain[1]; - } - free (line); RIE (gl846_stop_action (dev)); @@ -3691,7 +3696,8 @@ static Genesys_Command_Set gl846_cmd_set = { NULL, gl846_send_shading_data, gl846_calculate_current_setup, - gl846_boot + gl846_boot, + NULL }; SANE_Status diff --git a/backend/genesys_gl846.h b/backend/genesys_gl846.h index 58e9702..d57f149 100644 --- a/backend/genesys_gl846.h +++ b/backend/genesys_gl846.h @@ -3,42 +3,42 @@ Copyright (C) 2012-2013 Stphane Voltz <stef.dev@free.fr> This file is part of the SANE package. - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - + As a special exception, the authors of SANE give permission for additional uses of the libraries contained in this release of SANE. - + The exception is that, if you link a SANE library with other files to produce an executable, this does not by itself cause the resulting executable to be covered by the GNU General Public License. Your use of that executable is in no way restricted on account of linking the SANE library code into it. - + This exception does not, however, invalidate any other reasons why the executable file might be covered by the GNU General Public License. - + If you submit changes to SANE to the maintainers to be included in a subsequent release, you agree by submitting the changes that those changes may be distributed with this exception intact. If you write modifications of your own for SANE, it is your choice whether to permit this exception to apply to your modifications. - If you do not wish that, delete this exception notice. + If you do not wish that, delete this exception notice. */ #include "genesys.h" @@ -566,7 +566,7 @@ gl846_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home); #ifndef UNIT_TESTING static -#endif +#endif SANE_Status gl846_boot (Genesys_Device * dev, SANE_Bool cold); @@ -696,7 +696,7 @@ static Motor_Profile gl846_motors[]={ /* Image Formula 101 */ {MOTOR_IMG101, 11000, HALF_STEP , img101_high}, {MOTOR_PLUSTEK3800, 11000, HALF_STEP , img101_high}, - + /* end of database entry */ {0, 0, 0, NULL}, }; diff --git a/backend/genesys_gl847.c b/backend/genesys_gl847.c index 7c6a3c3..7c4d19c 100644 --- a/backend/genesys_gl847.c +++ b/backend/genesys_gl847.c @@ -1,45 +1,45 @@ /* sane - Scanner Access Now Easy. Copyright (C) 2010-2013 Stphane Voltz <stef.dev@free.fr> - - + + This file is part of the SANE package. - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - + As a special exception, the authors of SANE give permission for additional uses of the libraries contained in this release of SANE. - + The exception is that, if you link a SANE library with other files to produce an executable, this does not by itself cause the resulting executable to be covered by the GNU General Public License. Your use of that executable is in no way restricted on account of linking the SANE library code into it. - + This exception does not, however, invalidate any other reasons why the executable file might be covered by the GNU General Public License. - + If you submit changes to SANE to the maintainers to be included in a subsequent release, you agree by submitting the changes that those changes may be distributed with this exception intact. - + If you write modifications of your own for SANE, it is your choice whether to permit this exception to apply to your modifications. - If you do not wish that, delete this exception notice. + If you do not wish that, delete this exception notice. */ #undef BACKEND_NAME @@ -58,7 +58,7 @@ /** @brief read scanned data * Read in 0xeff0 maximum sized blocks. This read is done in 2 - * parts if not multple of 512. First read is rounded to a multiple of 512 bytes, last read fetches the + * parts if not multple of 512. First read is rounded to a multiple of 512 bytes, last read fetches the * remainder. Read addr is always 0x10000000 with the memory layout setup. * @param dev device to read data from * @param addr address within ASIC memory space, unused but kept for API @@ -124,7 +124,7 @@ gl847_bulk_read_data (Genesys_Device * dev, uint8_t addr, read /= 512; read *= 512; } - + DBG (DBG_io2, "gl847_bulk_read_data: trying to read %lu bytes of data\n", (u_long) read); @@ -176,7 +176,7 @@ gl847_bulk_read_data (Genesys_Device * dev, uint8_t addr, } /**************************************************************************** - Mid level functions + Mid level functions ****************************************************************************/ static SANE_Bool @@ -300,7 +300,7 @@ static Sensor_Profile *get_sensor_profile(int sensor_type, int dpi) } else { - if(sensors[i].dpi>=dpi + if(sensors[i].dpi>=dpi && sensors[i].dpi<sensors[idx].dpi) { idx=i; @@ -583,7 +583,7 @@ gl847_init_registers (Genesys_Device * dev) DBGCOMPLETED; } -/**@brief send slope table for motor movement +/**@brief send slope table for motor movement * Send slope_table in machine byte order * @param dev device to send slope table * @param table_nr index of the slope table in ASIC memory @@ -759,7 +759,7 @@ gl847_set_fe (Genesys_Device * dev, uint8_t set) DBG (DBG_proc, "gl847_set_fe (%s)\n", set == AFE_INIT ? "init" : set == AFE_SET ? "set" : set == AFE_POWER_SAVE ? "powersave" : "huh?"); - + RIE (sanei_genesys_read_register (dev, REG04, &val)); /* route to AD devices */ @@ -819,7 +819,7 @@ gl847_init_motor_regs_scan (Genesys_Device * dev, use_fast_fed=0; /* no fast fed since feed works well */ - if(dev->settings.yres==4444 && feed_steps>100 + if(dev->settings.yres==4444 && feed_steps>100 && ((flags & MOTOR_FLAG_FEED)==0)) { use_fast_fed=1; @@ -888,7 +888,7 @@ gl847_init_motor_regs_scan (Genesys_Device * dev, /* correct move distance by acceleration and deceleration amounts */ feedl=feed_steps; - if (use_fast_fed) + if (use_fast_fed) { feedl<<=fast_step_type; dist=(scan_steps+2*fast_steps)*factor; @@ -1045,11 +1045,11 @@ gl847_init_optical_regs_scan (Genesys_Device * dev, "half_ccd=%d, flags=%x\n", exposure_time, used_res, start, pixels, channels, depth, half_ccd, flags); - /* resolution is divided according to CKSEL */ + /* resolution is divided according to CKSEL */ r = sanei_genesys_get_address (reg, REG18); cksel= (r->value & REG18_CKSEL)+1; DBG (DBG_io2, "%s: cksel=%d\n", __FUNCTION__, cksel); - + /* to manage high resolution device while keeping good * low resolution scanning speed, we make hardware dpi vary */ dpihw=sanei_genesys_compute_dpihw(dev, used_res * cksel); @@ -1064,7 +1064,7 @@ gl847_init_optical_regs_scan (Genesys_Device * dev, /* start and end coordinate in optical dpi coordinates */ startx = start/cksel+dev->sensor.CCD_start_xoffset; used_pixels=pixels/cksel; - + /* end of sensor window */ endx = startx + used_pixels; @@ -1208,7 +1208,7 @@ gl847_init_optical_regs_scan (Genesys_Device * dev, { r->value |= REG87_LEDADD; } - /* RGB weighting + /* RGB weighting r = sanei_genesys_get_address (reg, 0x01); r->value &= ~REG01_TRUEGRAY; if (channels == 1 && (flags & OPTICAL_FLAG_ENABLE_LEDADD)) @@ -1253,7 +1253,7 @@ gl847_init_optical_regs_scan (Genesys_Device * dev, DBG (DBG_io2, "%s: dev->len =%lu\n", __FUNCTION__, (unsigned long)dev->len); DBG (DBG_io2, "%s: dev->dist =%lu\n", __FUNCTION__, (unsigned long)dev->dist); DBG (DBG_io2, "%s: dev->segnb =%lu\n", __FUNCTION__, (unsigned long)dev->segnb); - + words_per_line *= channels; dev->wpl = words_per_line; @@ -1272,7 +1272,7 @@ gl847_init_optical_regs_scan (Genesys_Device * dev, r = sanei_genesys_get_address (reg, 0x34); r->value = dev->sensor.dummy_pixel; - + DBGCOMPLETED; return SANE_STATUS_GOOD; } @@ -1407,7 +1407,7 @@ gl847_init_scan_regs (Genesys_Device * dev, depth = 8; } - /* we enable true gray for cis scanners only, and just when doing + /* we enable true gray for cis scanners only, and just when doing * scan since color calibration is OK for this mode */ oflags = 0; @@ -1417,7 +1417,7 @@ gl847_init_scan_regs (Genesys_Device * dev, oflags |= OPTICAL_FLAG_DISABLE_GAMMA; if(flags & SCAN_FLAG_DISABLE_LAMP) oflags |= OPTICAL_FLAG_DISABLE_LAMP; - + if (dev->model->is_cis && dev->settings.true_gray) { oflags |= OPTICAL_FLAG_ENABLE_LEDADD; @@ -1528,12 +1528,12 @@ gl847_init_scan_regs (Genesys_Device * dev, /* theory : target_size = (dev->settings.pixels * dev->settings.lines * channels * depth) / 8; - but it suffers from integer overflow so we do the following: + but it suffers from integer overflow so we do the following: - 1 bit color images store color data byte-wise, eg byte 0 contains - 8 bits of red data, byte 1 contains 8 bits of green, byte 2 contains + 1 bit color images store color data byte-wise, eg byte 0 contains + 8 bits of red data, byte 1 contains 8 bits of green, byte 2 contains 8 bits of blue. - This does not fix the overflow, though. + This does not fix the overflow, though. 644mp*16 = 10gp, leading to an overflow -- pierre */ @@ -1989,13 +1989,13 @@ gl847_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) } memcpy (local_reg, dev->reg, GENESYS_GL847_MAX_REGS * sizeof (Genesys_Register_Set)); - + resolution=sanei_genesys_get_lowest_ydpi(dev); - + /* TODO add scan_mode to the API */ scan_mode= dev->settings.scan_mode; dev->settings.scan_mode=SCAN_MODE_LINEART; - gl847_init_scan_regs (dev, + status = gl847_init_scan_regs (dev, local_reg, resolution, resolution, @@ -2009,11 +2009,20 @@ gl847_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) SCAN_FLAG_DISABLE_SHADING | SCAN_FLAG_DISABLE_GAMMA | SCAN_FLAG_IGNORE_LINE_DISTANCE); + if (status != SANE_STATUS_GOOD) + { + DBG (DBG_error, + "gl847_slow_back_home: failed to set up registers: %s\n", + sane_strstatus (status)); + DBGCOMPLETED; + return status; + } + dev->settings.scan_mode=scan_mode; /* clear scan and feed count */ RIE (sanei_genesys_write_register (dev, REG0D, REG0D_CLRLNCNT | REG0D_CLRMCNT)); - + /* set up for reverse */ r = sanei_genesys_get_address (local_reg, REG02); r->value |= REG02_MTRREV; @@ -2173,7 +2182,7 @@ gl847_search_start_position (Genesys_Device * dev) memcpy (dev->reg, local_reg, GENESYS_GL847_MAX_REGS * sizeof (Genesys_Register_Set)); -/*TODO: find out where sanei_genesys_search_reference_point +/*TODO: find out where sanei_genesys_search_reference_point stores information, and use that correctly*/ status = sanei_genesys_search_reference_point (dev, data, 0, dpi, pixels, @@ -2191,7 +2200,7 @@ gl847_search_start_position (Genesys_Device * dev) return SANE_STATUS_GOOD; } -/* +/* * sets up register for coarse gain calibration * todo: check it for scanners using it */ static SANE_Status @@ -2276,7 +2285,7 @@ gl847_feed (Genesys_Device * dev, unsigned int steps) memcpy (local_reg, dev->reg, GENESYS_GL847_MAX_REGS * sizeof (Genesys_Register_Set)); resolution=sanei_genesys_get_lowest_ydpi(dev); - gl847_init_scan_regs (dev, + status = gl847_init_scan_regs (dev, local_reg, resolution, resolution, @@ -2291,6 +2300,14 @@ gl847_feed (Genesys_Device * dev, unsigned int steps) SCAN_FLAG_DISABLE_GAMMA | SCAN_FLAG_FEEDING | SCAN_FLAG_IGNORE_LINE_DISTANCE); + if (status != SANE_STATUS_GOOD) + { + DBG (DBG_error, + "gl847_feed: failed to set up registers: %s\n", + sane_strstatus (status)); + DBGCOMPLETED; + return status; + } /* set exposure to zero */ sanei_genesys_set_triple(local_reg,REG_EXPR,0); @@ -2300,11 +2317,11 @@ gl847_feed (Genesys_Device * dev, unsigned int steps) /* clear scan and feed count */ RIE (sanei_genesys_write_register (dev, REG0D, REG0D_CLRLNCNT)); RIE (sanei_genesys_write_register (dev, REG0D, REG0D_CLRMCNT)); - + /* set up for no scan */ r = sanei_genesys_get_address (local_reg, REG01); r->value &= ~REG01_SCAN; - + /* send registers */ RIE (dev->model->cmd_set->bulk_write_register (dev, local_reg, GENESYS_GL847_MAX_REGS)); @@ -2329,7 +2346,7 @@ gl847_feed (Genesys_Device * dev, unsigned int steps) /* then stop scanning */ RIE(gl847_stop_action (dev)); - + DBGCOMPLETED; return SANE_STATUS_GOOD; } @@ -2356,7 +2373,7 @@ gl847_init_regs_for_shading (Genesys_Device * dev) DBG (DBG_io, "%s: calib_lines = %d\n", __FUNCTION__, (int)dev->calib_lines); DBG (DBG_io, "%s: calib_pixels = %d\n", __FUNCTION__, (int)dev->calib_pixels); - /* this is aworkaround insufficent distance for slope + /* this is aworkaround insufficent distance for slope * motor acceleration TODO special motor slope for shading */ move=1; if(dev->calib_resolution<1200) @@ -2385,7 +2402,7 @@ gl847_init_regs_for_shading (Genesys_Device * dev) DBG (DBG_error, "%s: failed to setup scan: %s\n", __FUNCTION__, sane_strstatus (status)); return status; } - + status = dev->model->cmd_set->bulk_write_register (dev, dev->calib_reg, GENESYS_GL847_MAX_REGS); if (status != SANE_STATUS_GOOD) { @@ -2442,9 +2459,9 @@ gl847_init_regs_for_scan (Genesys_Device * dev) assumption: steps are expressed at maximum motor resolution - we need: - SANE_Fixed y_offset; - SANE_Fixed y_size; + we need: + SANE_Fixed y_offset; + SANE_Fixed y_size; SANE_Fixed y_offset_calib; mm_to_steps()=motor dpi / 2.54 / 10=motor dpi / MM_PER_INCH */ @@ -2474,7 +2491,7 @@ gl847_init_regs_for_scan (Genesys_Device * dev) } move=500; } - + DBG (DBG_info, "gl124_init_regs_for_scan: move=%f steps\n", move); DBG (DBG_info, "%s: move=%f steps\n", __FUNCTION__, move); @@ -2486,7 +2503,7 @@ gl847_init_regs_for_scan (Genesys_Device * dev) flags = 0; /* emulated lineart from gray data is required for now */ - if(dev->settings.scan_mode == SCAN_MODE_LINEART + if(dev->settings.scan_mode == SCAN_MODE_LINEART && dev->settings.dynamic_lineart) { flags |= SCAN_FLAG_DYNAMIC_LINEART; @@ -2510,7 +2527,7 @@ gl847_init_regs_for_scan (Genesys_Device * dev) if (status != SANE_STATUS_GOOD) return status; - + DBGCOMPLETED; return SANE_STATUS_GOOD; } @@ -2533,7 +2550,7 @@ gl847_send_shading_data (Genesys_Device * dev, uint8_t * data, int size) DBGSTART; DBG( DBG_io2, "%s: writing %d bytes of shading data\n",__FUNCTION__,size); - /* shading data is plit in 3 (up to 5 with IR) areas + /* shading data is plit in 3 (up to 5 with IR) areas write(0x10014000,0x00000dd8) URB 23429 bulk_out len 3544 wrote 0x33 0x10 0x.... write(0x1003e000,0x00000dd8) @@ -2563,14 +2580,14 @@ gl847_send_shading_data (Genesys_Device * dev, uint8_t * data, int size) fprintf(dev->binary,"P5\n%d %d\n%d\n",(endpixel-strpixel)/factor*channels,lines/channels,255); } } - + pixels=endpixel-strpixel; /* since we're using SHDAREA, substract startx coordinate from shading */ strpixel-=((dev->sensor.CCD_start_xoffset*600)/dev->sensor.optical_res); - + /* turn pixel value into bytes 2x16 bits words */ - strpixel*=2*2; + strpixel*=2*2; pixels*=2*2; /* allocate temporary buffer */ @@ -2599,7 +2616,7 @@ gl847_send_shading_data (Genesys_Device * dev, uint8_t * data, int size) ptr[1]=src[1]; ptr[2]=src[2]; ptr[3]=src[3]; - + /* next shading coefficient */ ptr+=4; } @@ -2661,7 +2678,7 @@ gl847_led_calibration (Genesys_Device * dev) used_res=sanei_genesys_compute_dpihw(dev,dev->settings.xres); sensor=get_sensor_profile(dev->model->ccd_type, used_res); num_pixels = (dev->sensor.sensor_pixels*used_res)/dev->sensor.optical_res; - + /* initial calibration reg values */ memcpy (dev->calib_reg, dev->reg, GENESYS_GL847_MAX_REGS * sizeof (Genesys_Register_Set)); @@ -2791,18 +2808,18 @@ gl847_led_calibration (Genesys_Device * dev) /* cleanup before return */ free (line); - + /* go back home */ if(move>20) { status=gl847_slow_back_home (dev, SANE_TRUE); } - + DBGCOMPLETED; return status; } -/** +/** * set up GPIO/GPOE for idle state */ static SANE_Status @@ -2826,10 +2843,10 @@ gl847_init_gpio (Genesys_Device * dev) RIE (sanei_genesys_write_register (dev, REGA7, gpios[idx].ra7)); RIE (sanei_genesys_write_register (dev, REGA6, gpios[idx].ra6)); - + RIE (sanei_genesys_write_register (dev, REG6E, gpios[idx].r6e)); RIE (sanei_genesys_write_register (dev, REG6C, 0x00)); - + RIE (sanei_genesys_write_register (dev, REG6B, gpios[idx].r6b)); RIE (sanei_genesys_write_register (dev, REG6C, gpios[idx].r6c)); RIE (sanei_genesys_write_register (dev, REG6D, gpios[idx].r6d)); @@ -2843,7 +2860,7 @@ gl847_init_gpio (Genesys_Device * dev) return status; } -/** +/** * set memory layout by filling values in dedicated registers */ static SANE_Status @@ -3004,7 +3021,7 @@ SANE_Status gl847_init (Genesys_Device * dev) DBG_INIT (); DBGSTART; - + status=sanei_genesys_asic_init(dev, GENESYS_GL847_MAX_REGS); DBGCOMPLETED; @@ -3050,7 +3067,7 @@ gl847_update_hardware_sensors (Genesys_Scanner * s) /** @brief search for a full width black or white strip. * This function searches for a black or white stripe across the scanning area. - * When searching backward, the searched area must completely be of the desired + * When searching backward, the searched area must completely be of the desired * color since this area will be used for calibration which scans forward. * @param dev scanner device * @param forward SANE_TRUE if searching forward, SANE_FALSE if searching backward @@ -3476,7 +3493,7 @@ gl847_offset_calibration (Genesys_Device * dev) snprintf(title,20,"offset%03d.pnm",bottom); sanei_genesys_write_pnm_file (title, first_line, bpp, channels, pixels, lines); } - + bottomavg = dark_average (first_line, pixels, lines, channels, black_pixels); DBG (DBG_io2, "gl847_offset_calibration: bottom avg=%d\n", bottomavg); @@ -3490,7 +3507,7 @@ gl847_offset_calibration (Genesys_Device * dev) DBG (DBG_info, "gl847_offset_calibration: starting second line reading\n"); RIEF2 (gl847_begin_scan (dev, dev->calib_reg, SANE_TRUE),first_line, second_line); RIEF2 (sanei_genesys_read_data_from_scanner (dev, second_line, total_size),first_line, second_line); - + topavg = dark_average (second_line, pixels, lines, channels, black_pixels); DBG (DBG_io2, "gl847_offset_calibration: top avg=%d\n", topavg); @@ -3752,7 +3769,8 @@ static Genesys_Command_Set gl847_cmd_set = { NULL, gl847_send_shading_data, gl847_calculate_current_setup, - gl847_boot + gl847_boot, + NULL }; SANE_Status diff --git a/backend/genesys_gl847.h b/backend/genesys_gl847.h index d787f43..9901e23 100644 --- a/backend/genesys_gl847.h +++ b/backend/genesys_gl847.h @@ -3,42 +3,42 @@ Copyright (C) 2010-2013 Stphane Voltz <stef.dev@free.fr> This file is part of the SANE package. - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - + As a special exception, the authors of SANE give permission for additional uses of the libraries contained in this release of SANE. - + The exception is that, if you link a SANE library with other files to produce an executable, this does not by itself cause the resulting executable to be covered by the GNU General Public License. Your use of that executable is in no way restricted on account of linking the SANE library code into it. - + This exception does not, however, invalidate any other reasons why the executable file might be covered by the GNU General Public License. - + If you submit changes to SANE to the maintainers to be included in a subsequent release, you agree by submitting the changes that those changes may be distributed with this exception intact. If you write modifications of your own for SANE, it is your choice whether to permit this exception to apply to your modifications. - If you do not wish that, delete this exception notice. + If you do not wish that, delete this exception notice. */ #include "genesys.h" @@ -653,7 +653,7 @@ static uint32_t lide200_high[] = { 31680, 31680, 31680, 31680, 31680, 31680, 316 static uint32_t lide700_medium[] = { 46876,2342,2342,2342,2342,2342,2342,2342,2342,2302,2286,2274,2266,2258,2252,2244,2240,2234,2228,2224,2218,2216,2210,2208,2202,2200,2194,2192,2190,2186,2182,2180,2176,2174,2172,2170,2166,2162,2160,2156,2154,2152,2150,2150,2146,2144,2142,2140,2136,2134,2132,2130,2130,2128,2124,2122,2120,2120,2118,2116,2112,2112,2110,2108,2106,2106,2104,2102,2102,2098,2096,2094,2094,2092,2090,2090,2086,2084,2084,2082,2082,2080,2078,2078,2076,2074,2074,2070,2070,2068,2066,2066,2064,2064,2062,2062,2060,2058,2058,2054,2054,2052,2052,2050,2050,2048,2048,2046,2046,2044,2042,2042,2040,2040,2038,2038,2034,2034,2032,2032,2030,2030,2028,2028,2026,2026,2022,2022}; static uint32_t lide700_high[] = { 46876,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864,15864}; /* 5190 trop - * 5186 pas assez + * 5186 pas assez */ /* static uint32_t lide200_max[] = { 124992, 124992, 124992, 124992, 124992, 124992, 124992, 124992, 124992, 124992, 124992, 124992, 124992, 124992, 124992, 124992, 124992, 2219,2212,2205,2198,2190,2183,2176,2168,2161,2154,2146,2139,2132,2125,2117,2110,2103,2095,2088,2081,2073,2066,2059,2052,2044,2037,2030,2022,2015,2008,2001,1993,1986,1979,1971,1964,1957,1949,1942,1935,1928,1920,1913,1906,1898,1891,1884,1876,1869,1862,1855,1847,1840,1833,1825,1818,1811,1803,1796,1789,1782,1774,1767,1760,1752,1745,1738,1731,1723,1716,1709,1701,1694,1687,1679,1672,1665,1658,1650,1643,1636,1628,1621,1614,1606,1599,1592,1585,1577,1570,1563,1555,1548,1541,1533,1526,1519,1512,1504,1497,1490,1482,1475,1468,1461,1453,1446,1439,1431,1424,1417,1409,1402,1395,1388,1380,1373,1366,1358,1351,1344,1336,1329,1322,1315,1307,1300,1293,1285,1278,1271,1263,1256,1249,1242,1234,1227,1220,1212,1205,1198,1191,1183,1176,1169,1161,1154,1147,1139,1132,1125,1118,1110,1103,1096,1088,1081,1074,1066,1059,1052,1045,1037,1030,1023,1015,1008,1001,993,986,979,972,964,957,950,942,935,928,921,913,906,899,891,884,877,869,862,855,848,840,833,826,818,811,804,796,789,782,775,767,760,753,745,738,731,723,716,709,702,694,687,680,672,665,658,651,643,636,629,621,614,607,599,592,585,578,570,563,556,534,534, 0}; @@ -671,7 +671,7 @@ static Motor_Profile gl847_motors[]={ {MOTOR_CANONLIDE100, 1432, HALF_STEP , lide200_base}, {MOTOR_CANONLIDE100, 2712, QUARTER_STEP, lide200_medium}, {MOTOR_CANONLIDE100, 5280, EIGHTH_STEP , lide200_high}, - + /* LiDE 200 */ {MOTOR_CANONLIDE200, 2848, HALF_STEP , lide200_base}, {MOTOR_CANONLIDE200, 1424, HALF_STEP , lide200_base}, diff --git a/backend/genesys_low.c b/backend/genesys_low.c index 62563ae..f28b72c 100644 --- a/backend/genesys_low.c +++ b/backend/genesys_low.c @@ -1,45 +1,45 @@ /* sane - Scanner Access Now Easy. Copyright (C) 2010-2013 Stphane Voltz <stef.dev@free.fr> - - + + This file is part of the SANE package. - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - + As a special exception, the authors of SANE give permission for additional uses of the libraries contained in this release of SANE. - + The exception is that, if you link a SANE library with other files to produce an executable, this does not by itself cause the resulting executable to be covered by the GNU General Public License. Your use of that executable is in no way restricted on account of linking the SANE library code into it. - + This exception does not, however, invalidate any other reasons why the executable file might be covered by the GNU General Public License. - + If you submit changes to SANE to the maintainers to be included in a subsequent release, you agree by submitting the changes that those changes may be distributed with this exception intact. - + If you write modifications of your own for SANE, it is your choice whether to permit this exception to apply to your modifications. - If you do not wish that, delete this exception notice. + If you do not wish that, delete this exception notice. */ #undef BACKEND_NAME #define BACKEND_NAME genesys_low @@ -261,7 +261,7 @@ sanei_genesys_read_hregister (Genesys_Device * dev, uint16_t reg, uint8_t * val) /** * Write to one GL847 ASIC register -URB 10 control 0x40 0x04 0x83 0x00 len 2 wrote 0xa6 0x04 +URB 10 control 0x40 0x04 0x83 0x00 len 2 wrote 0xa6 0x04 */ static SANE_Status sanei_genesys_write_gl847_register (Genesys_Device * dev, uint8_t reg, uint8_t val) @@ -310,8 +310,8 @@ sanei_genesys_write_register (Genesys_Device * dev, uint16_t reg, uint8_t val) /* route to gl847 function if needed */ if(dev->model->asic_type==GENESYS_GL847 - || dev->model->asic_type==GENESYS_GL845 - || dev->model->asic_type==GENESYS_GL846 + || dev->model->asic_type==GENESYS_GL845 + || dev->model->asic_type==GENESYS_GL846 || dev->model->asic_type==GENESYS_GL124) { return sanei_genesys_write_gl847_register(dev, reg, val); @@ -346,7 +346,7 @@ sanei_genesys_write_register (Genesys_Device * dev, uint16_t reg, uint8_t val) return status; } -/** +/** * @brief write command to 0x8c endpoint * Write a value to 0x8c end point (end access), for USB firmware related operations * Known values are 0x0f, 0x11 for USB 2.0 data transfer and 0x0f,0x14 for USB1.1 @@ -475,10 +475,10 @@ SANE_Status sanei_genesys_set_buffer_address (Genesys_Device * dev, uint32_t addr) { SANE_Status status; - + if(dev->model->asic_type==GENESYS_GL847 - || dev->model->asic_type==GENESYS_GL845 - || dev->model->asic_type==GENESYS_GL846 + || dev->model->asic_type==GENESYS_GL845 + || dev->model->asic_type==GENESYS_GL846 || dev->model->asic_type==GENESYS_GL124) { DBG (DBG_warn, @@ -943,13 +943,18 @@ sanei_genesys_get_triple(Genesys_Register_Set *regs, uint16_t addr, uint32_t *va return SANE_STATUS_GOOD; } -/* Checks if the scan buffer is empty */ +/** @brief Check if the scanner's internal data buffer is empty + * @param *dev device to test for data + * @param *empty return value + * @return empty will be set to SANE_TRUE if there is no scanned data. + **/ SANE_Status sanei_genesys_test_buffer_empty (Genesys_Device * dev, SANE_Bool * empty) { uint8_t val = 0; SANE_Status status; + usleep(1000); status = sanei_genesys_get_status (dev, &val); if (status != SANE_STATUS_GOOD) { @@ -961,6 +966,10 @@ sanei_genesys_test_buffer_empty (Genesys_Device * dev, SANE_Bool * empty) if (dev->model->cmd_set->test_buffer_empty_bit (val)) { + /* fix timing issue on USB3 (or just may be too fast) hardware + * spotted by John S. Weber <jweber53@gmail.com> + */ + usleep(1000); DBG (DBG_io2, "sanei_genesys_test_buffer_empty: buffer is empty\n"); *empty = SANE_TRUE; return SANE_STATUS_GOOD; @@ -1210,7 +1219,7 @@ SANE_Status sanei_genesys_generate_gamma_buffer(Genesys_Device * dev, max, dev->settings.contrast, dev->settings.brightness); - for (i = 0; i < size-1; i++) + for (i = 0; i < size; i++) { value=dev->sensor.gamma_table[GENESYS_RED][i]; value=lut[value]; @@ -1230,7 +1239,7 @@ SANE_Status sanei_genesys_generate_gamma_buffer(Genesys_Device * dev, } else { - for (i = 0; i < size-1; i++) + for (i = 0; i < size; i++) { value=dev->sensor.gamma_table[GENESYS_RED][i]; gamma[i * 2 + size * 0 + 0] = value & 0xff; @@ -1258,7 +1267,7 @@ SANE_Status sanei_genesys_generate_gamma_buffer(Genesys_Device * dev, /** @brief send gamma table to scanner * This function sends generic gamma table (ie ones built with - * provided gamma) or the user defined one if provided by + * provided gamma) or the user defined one if provided by * fontend. Used by gl846+ ASICs * @param dev device to write to */ @@ -1317,10 +1326,14 @@ sanei_genesys_send_gamma_table (Genesys_Device * dev) } /** @brief initialize device - * initialize backend and ASIC : registers, motor tables, and gamma tables - * then ensure scanner's head is at home. Designed for gl846+ ASICs + * Initialize backend and ASIC : registers, motor tables, and gamma tables + * then ensure scanner's head is at home. Designed for gl846+ ASICs. + * Detects cold boot (ie first boot since device plugged) in this case + * an extensice setup up is done at hardware level. + * * @param dev device to initialize * @param max_regs umber of maximum used registers + * @return SANE_STATUS_GOOD in case of success */ SANE_Status sanei_genesys_asic_init (Genesys_Device * dev, int max_regs) @@ -1328,7 +1341,8 @@ sanei_genesys_asic_init (Genesys_Device * dev, int max_regs) SANE_Status status; uint8_t val; SANE_Bool cold = SANE_TRUE; - int size, i; + int size; /**< size of the device's gamma table */ + int i; DBGSTART; @@ -1354,7 +1368,26 @@ sanei_genesys_asic_init (Genesys_Device * dev, int max_regs) } } - /* check if the device has already been initialized and powered up + /* setup gamma tables */ + size = 256; + for(i=0;i<3;i++) + { + FREE_IFNOT_NULL (dev->sensor.gamma_table[i]); + dev->sensor.gamma_table[i] = (uint16_t *) malloc (2 * size); + if (dev->sensor.gamma_table[i] == NULL) + { + DBG (DBG_error, "%s: could not allocate memory for gamma table %d\n", + __FUNCTION__, i); + return SANE_STATUS_NO_MEM; + } + sanei_genesys_create_gamma_table (dev->sensor.gamma_table[i], + size, + 65535, + 65535, + dev->sensor.gamma[i]); + } + + /* check if the device has already been initialized and powered up * we read register 6 and check PWRBIT, if reset scanner has been * freshly powered up. This bit will be set to later so that following * reads can detect power down/up cycle*/ @@ -1380,9 +1413,6 @@ sanei_genesys_asic_init (Genesys_Device * dev, int max_regs) /* now hardware part is OK, set up device struct */ FREE_IFNOT_NULL (dev->white_average_data); FREE_IFNOT_NULL (dev->dark_average_data); - FREE_IFNOT_NULL (dev->sensor.gamma_table[0]); - FREE_IFNOT_NULL (dev->sensor.gamma_table[1]); - FREE_IFNOT_NULL (dev->sensor.gamma_table[2]); dev->settings.color_filter = 0; @@ -1392,28 +1422,6 @@ sanei_genesys_asic_init (Genesys_Device * dev, int max_regs) /* Set analog frontend */ RIE (dev->model->cmd_set->set_fe (dev, AFE_INIT)); - /* init gamma tables */ - size = 256; - - for(i=0;i<3;i++) - { - if (dev->sensor.gamma_table[i] == NULL) - { - dev->sensor.gamma_table[i] = (uint16_t *) malloc (2 * size); - if (dev->sensor.gamma_table[i] == NULL) - { - DBG (DBG_error, "%s: could not allocate memory for gamma table %d\n", - __FUNCTION__, i); - return SANE_STATUS_NO_MEM; - } - sanei_genesys_create_gamma_table (dev->sensor.gamma_table[i], - size, - 65535, - 65535, - dev->sensor.gamma[i]); - } - } - dev->oe_buffer.buffer = NULL; dev->already_initialized = SANE_TRUE; @@ -1429,7 +1437,7 @@ sanei_genesys_asic_init (Genesys_Device * dev, int max_regs) } /** - * Wait for the scanning head to park + * Wait for the scanning head to park */ SANE_Status sanei_genesys_wait_for_home (Genesys_Device * dev) @@ -1437,6 +1445,7 @@ sanei_genesys_wait_for_home (Genesys_Device * dev) SANE_Status status; uint8_t val; int loop; + int max=300; DBGSTART; @@ -1492,7 +1501,14 @@ sanei_genesys_wait_for_home (Genesys_Device * dev) } ++loop; } - while (loop < 300 && !(val & HOMESNR) && status == SANE_STATUS_GOOD); + while (loop < max && !(val & HOMESNR) && status == SANE_STATUS_GOOD); + + /* if after the timeout, head is still not parked, error out */ + if(loop >= max && !(val & HOMESNR) && status == SANE_STATUS_GOOD) + { + DBG (DBG_error, "%s: failed to reach park position %ds\n", __FUNCTION__, max/10); + return SANE_STATUS_IO_ERROR; + } DBGCOMPLETED; return status; @@ -1638,8 +1654,8 @@ Motor_Profile *profile; /* required speed */ target=((exposure * dpi) / base_dpi)>>step_type; - DBG (DBG_io2, "%s: target=%d\n", __FUNCTION__, target); - + DBG (DBG_io2, "%s: exposure=%d, dpi=%d, target=%d\n", __FUNCTION__, exposure, dpi, target); + /* fill result with target speed */ for(i=0;i<SLOPE_TABLE_SIZE;i++) slope[i]=target; @@ -1650,7 +1666,7 @@ Motor_Profile *profile; i=0; sum=0; - /* first step is used unmodified */ + /* first step is always used unmodified */ current=profile->table[0]; /* loop on profile copying and apply step type */ @@ -1662,6 +1678,14 @@ Motor_Profile *profile; current=profile->table[i]>>step_type; } + /* ensure last step is required speed in case profile doesn't contain it */ + if(current!=0 && current<target) + { + slope[i]=target; + sum+=slope[i]; + i++; + } + /* range checking */ if(profile->table[i]==0 && DBG_LEVEL >= DBG_warn && current>target) { @@ -1747,7 +1771,11 @@ int sanei_genesys_get_lowest_dpi(Genesys_Device *dev) /** @brief check is a cache entry may be used * Compares current settings with the cache entry and return * SANE_TRUE if they are compatible. - */ + * A calibration cache is compatible if color mode and x dpi match the user + * requested scan. In the case of CIS scanners, dpi isn't a criteria. + * flatbed cache entries are considred too old and then expires if they + * are older than the expiration time option, forcing calibration at least once + * then given time. */ SANE_Status sanei_genesys_is_compatible_calibration (Genesys_Device * dev, Genesys_Calibration_Cache * cache, @@ -1760,27 +1788,25 @@ sanei_genesys_is_compatible_calibration (Genesys_Device * dev, SANE_Status status; DBGSTART; - + if(dev->model->cmd_set->calculate_current_setup==NULL) { - DBG (DBG_proc, - "sanei_genesys_is_compatible_calibration: no calculate_setup, non compatible cache\n"); + DBG (DBG_proc, "%s: no calculate_setup, non compatible cache\n", __FUNCTION__); return SANE_STATUS_UNSUPPORTED; } status = dev->model->cmd_set->calculate_current_setup (dev); if (status != SANE_STATUS_GOOD) { - DBG (DBG_error, - "sanei_genesys_is_compatible_calibration: failed to calculate current setup: %s\n", + DBG (DBG_error, "%s: failed to calculate current setup: %s\n", __FUNCTION__, sane_strstatus (status)); return status; } dev->current_setup.scan_method = dev->settings.scan_method; - DBG (DBG_proc, "sanei_genesys_is_compatible_calibration: checking\n"); - - /* a calibration cache is compatible if color mode and x dpi match the user + DBG (DBG_proc, "%s: checking\n", __FUNCTION__); + + /* a calibration cache is compatible if color mode and x dpi match the user * requested scan. In the case of CIS scanners, dpi isn't a criteria */ if (dev->model->is_cis == SANE_FALSE) { @@ -1796,39 +1822,36 @@ sanei_genesys_is_compatible_calibration (Genesys_Device * dev, resolution=sanei_genesys_compute_dpihw(dev,dev->settings.xres); compatible = (resolution == ((int) sanei_genesys_compute_dpihw(dev,cache->used_setup.xres))); } + DBG (DBG_io, "%s: after resolution check current compatible=%d\n", __FUNCTION__, compatible); if (dev->current_setup.half_ccd != cache->used_setup.half_ccd) { - DBG (DBG_io, - "sanei_genesys_is_compatible_calibration: half_ccd=%d, used=%d\n", + DBG (DBG_io, "%s: half_ccd=%d, used=%d\n", __FUNCTION__, dev->current_setup.half_ccd, cache->used_setup.half_ccd); compatible = 0; } if (dev->current_setup.scan_method != cache->used_setup.scan_method) { - DBG (DBG_io, - "sanei_genesys_is_compatible_calibration: current method=%d, used=%d\n", + DBG (DBG_io, "%s: current method=%d, used=%d\n", __FUNCTION__, dev->current_setup.scan_method, cache->used_setup.scan_method); compatible = 0; } if (!compatible) { - DBG (DBG_proc, - "sanei_genesys_is_compatible_calibration: completed, non compatible cache\n"); + DBG (DBG_proc, "%s: completed, non compatible cache\n", __FUNCTION__); return SANE_STATUS_UNSUPPORTED; } - /* a cache entry expires after 60 minutes for non sheetfed scanners */ + /* a cache entry expires after afetr expiration time for non sheetfed scanners */ /* this is not taken into account when overwriting cache entries */ #ifdef HAVE_SYS_TIME_H - if(for_overwrite == SANE_FALSE) + if(for_overwrite == SANE_FALSE && dev->settings.expiration_time >=0) { gettimeofday (&time, NULL); - if ((time.tv_sec - cache->last_calibration > 60 * 60) + if ((time.tv_sec - cache->last_calibration > dev->settings.expiration_time*60) && (dev->model->is_sheetfed == SANE_FALSE) && (dev->settings.scan_method == SCAN_METHOD_FLATBED)) { - DBG (DBG_proc, - "sanei_genesys_is_compatible_calibration: expired entry, non compatible cache\n"); + DBG (DBG_proc, "%s: expired entry, non compatible cache\n", __FUNCTION__); return SANE_STATUS_UNSUPPORTED; } } diff --git a/backend/genesys_low.h b/backend/genesys_low.h index 1d5ef22..b5a0a8f 100644 --- a/backend/genesys_low.h +++ b/backend/genesys_low.h @@ -8,44 +8,44 @@ Copyright (C) 2006 Laurent Charpentier <laurent_pubs@yahoo.com> Parts of the structs have been taken from the gt68xx backend by Sergey Vlasov <vsu@altlinux.ru> et al. - + This file is part of the SANE package. - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - + As a special exception, the authors of SANE give permission for additional uses of the libraries contained in this release of SANE. - + The exception is that, if you link a SANE library with other files to produce an executable, this does not by itself cause the resulting executable to be covered by the GNU General Public License. Your use of that executable is in no way restricted on account of linking the SANE library code into it. - + This exception does not, however, invalidate any other reasons why the executable file might be covered by the GNU General Public License. - + If you submit changes to SANE to the maintainers to be included in a subsequent release, you agree by submitting the changes that those changes may be distributed with this exception intact. - + If you write modifications of your own for SANE, it is your choice whether to permit this exception to apply to your modifications. - If you do not wish that, delete this exception notice. + If you do not wish that, delete this exception notice. */ #ifndef GENESYS_LOW_H @@ -67,7 +67,7 @@ #ifdef HAVE_SYS_TYPES_H #include <sys/types.h> #endif -#ifdef HAVE_MKDIR +#ifdef HAVE_MKDIR #include <sys/stat.h> #include <sys/types.h> #endif @@ -81,6 +81,12 @@ #include "../include/_stdint.h" +#ifndef UNIT_TESTING +#define GENESYS_STATIC static +#else +#define GENESYS_STATIC +#endif + #define DBG_error0 0 /* errors/warnings printed even with devuglevel 0 */ #define DBG_error 1 /* fatal errors */ #define DBG_init 2 /* initialization and scanning time messages */ @@ -140,11 +146,11 @@ #define GENESYS_FLAG_SKIP_WARMUP (1 << 4) /**< skip genesys_warmup() */ /** @brief offset calibration flag * signals that the scanner does offset calibration. In this case off_calibration() and - * coarse_gain_calibration() functions must be implemented + * coarse_gain_calibration() functions must be implemented */ #define GENESYS_FLAG_OFFSET_CALIBRATION (1 << 5) #define GENESYS_FLAG_SEARCH_START (1 << 6) /**< do start search before scanning */ -#define GENESYS_FLAG_REPARK (1 << 7) /**< repark head (and check for lock) by +#define GENESYS_FLAG_REPARK (1 << 7) /**< repark head (and check for lock) by moving without scanning */ #define GENESYS_FLAG_DARK_CALIBRATION (1 << 8) /**< do dark calibration */ #define GENESYS_FLAG_STAGGERED_LINE (1 << 9) /**< pixel columns are shifted vertically for hi-res modes */ @@ -286,8 +292,8 @@ typedef struct SANE_Int maximum_speed; /* maximum speed allowed. Unit: pixeltime/step */ SANE_Int minimum_steps; /* number of steps used for default curve */ float g; /* power for non-linear acceleration curves. */ -/* vs*(1-i^g)+ve*(i^g) where - vs = start speed, ve = end speed, +/* vs*(1-i^g)+ve*(i^g) where + vs = start speed, ve = end speed, i = 0.0 for first entry and i = 1.0 for last entry in default table*/ } Genesys_Motor_Slope; @@ -310,7 +316,6 @@ typedef enum Genesys_Color_Order Genesys_Color_Order; -#define MAX_SCANNERS 50 #define MAX_RESOLUTIONS 13 #define MAX_DPI 4 @@ -346,6 +351,7 @@ Genesys_Color_Order; #define DAC_CS8400F 17 #define DAC_IMG101 18 #define DAC_PLUSTEK3800 19 +#define DAC_CANONLIDE80 20 #define CCD_UMAX 0 #define CCD_ST12 1 /* SONY ILX548: 5340 Pixel ??? */ @@ -375,6 +381,9 @@ Genesys_Color_Order; #define CCD_IMG101 25 #define CCD_PLUSTEK3800 26 #define CIS_CANONLIDE210 27 +#define CIS_CANONLIDE80 28 +#define CIS_CANONLIDE220 29 +#define CIS_CANONLIDE120 30 #define GPO_UMAX 0 #define GPO_ST12 1 @@ -400,6 +409,7 @@ Genesys_Color_Order; #define GPO_CS8400F 21 #define GPO_IMG101 22 #define GPO_PLUSTEK3800 23 +#define GPO_CANONLIDE80 24 #define MOTOR_UMAX 0 #define MOTOR_5345 1 @@ -424,6 +434,7 @@ Genesys_Color_Order; #define MOTOR_IMG101 21 #define MOTOR_PLUSTEK3800 22 #define MOTOR_CANONLIDE210 23 +#define MOTOR_CANONLIDE80 24 /* Forward typedefs */ @@ -474,8 +485,8 @@ typedef struct Genesys_Command_Set SANE_Status (*save_power) (Genesys_Device * dev, SANE_Bool enable); void (*set_motor_power) (Genesys_Register_Set * regs, SANE_Bool set); - void (*set_lamp_power) (Genesys_Device * dev, - Genesys_Register_Set * regs, + void (*set_lamp_power) (Genesys_Device * dev, + Genesys_Register_Set * regs, SANE_Bool set); SANE_Status (*begin_scan) (Genesys_Device * dev, @@ -499,9 +510,9 @@ typedef struct Genesys_Command_Set SANE_Bool wait_until_home); SANE_Status (*bulk_write_register) (Genesys_Device * dev, - Genesys_Register_Set * reg, + Genesys_Register_Set * reg, size_t elems); - SANE_Status (*bulk_write_data) (Genesys_Device * dev, uint8_t addr, + SANE_Status (*bulk_write_data) (Genesys_Device * dev, uint8_t addr, uint8_t * data, size_t len); SANE_Status (*bulk_read_data) (Genesys_Device * dev, uint8_t addr, @@ -511,7 +522,7 @@ typedef struct Genesys_Command_Set If possible, just get information for given option. The sensor state in Genesys_Scanner.val[] should be merged with the new sensor state, using the information that was last read by the frontend - in Genesys_Scanner.last_val[], in such a way that a button up/down + in Genesys_Scanner.last_val[], in such a way that a button up/down relative to Genesys_Scanner.last_val[] is not lost. */ SANE_Status (*update_hardware_sensors) (struct Genesys_Scanner * s); @@ -532,7 +543,7 @@ typedef struct Genesys_Command_Set */ SANE_Status (*eject_document) (Genesys_Device * dev); /** - * search for an black or white area in forward or reverse + * search for an black or white area in forward or reverse * direction */ SANE_Status (*search_strip) (Genesys_Device * dev, SANE_Bool forward, SANE_Bool black); @@ -562,6 +573,24 @@ typedef struct Genesys_Command_Set */ SANE_Status (*asic_boot) (Genesys_Device * dev, SANE_Bool cold); + /** + * Scan register setting interface + */ + SANE_Status (*init_scan_regs) (Genesys_Device * dev, + Genesys_Register_Set * reg, + float xres, + float yres, + float startx, + float starty, + float pixels, + float lines, + unsigned int depth, + unsigned int channels, + int scan_method, + int scan_mode, + int color_filter, + unsigned int flags); + } Genesys_Command_Set; /** @brief structure to describe a scanner model @@ -583,7 +612,7 @@ typedef struct Genesys_Model SANE_Int bpp_color_values[MAX_DPI]; /* possible depths in color mode */ SANE_Fixed x_offset; /* Start of scan area in mm */ - SANE_Fixed y_offset; /* Start of scan area in mm (Amount of + SANE_Fixed y_offset; /* Start of scan area in mm (Amount of feeding needed to get to the medium) */ SANE_Fixed x_size; /* Size of scan area in mm */ SANE_Fixed y_size; /* Size of scan area in mm */ @@ -600,7 +629,7 @@ typedef struct Genesys_Model SANE_Fixed post_scan; /* Size of scan area after paper sensor stops sensing document in mm */ - SANE_Fixed eject_feed; /* Amount of feeding needed to eject document + SANE_Fixed eject_feed; /* Amount of feeding needed to eject document after finishing scanning in mm */ /* Line-distance correction (in pixel at optical_ydpi) for CCD scanners */ @@ -654,7 +683,7 @@ typedef struct unsigned int color_filter; /**< true if scan is true gray, false if monochrome scan */ - int true_gray; + int true_gray; /**< lineart threshold */ int threshold; @@ -678,6 +707,9 @@ typedef struct /**< value for brightness enhancement in the [-100..100] range */ int brightness; + + /**< cahe entries expiration time */ + int expiration_time; } Genesys_Settings; typedef struct Genesys_Current_Setup @@ -691,7 +723,7 @@ typedef struct Genesys_Current_Setup float xres; /* used xres */ float yres; /* used yres*/ SANE_Bool half_ccd; /* half ccd mode */ - SANE_Int stagger; + SANE_Int stagger; SANE_Int max_shift; /* max shift of any ccd component, including staggered pixels*/ } Genesys_Current_Setup; @@ -780,7 +812,7 @@ struct Genesys_Device size_t wpl; /**< asic's word per line */ Genesys_Current_Setup current_setup; /* contains the real used values */ - + /**< look up table used in dynamic rasterization */ unsigned char lineart_lut[256]; @@ -850,7 +882,7 @@ typedef struct { #define SCAN_FLAG_CALIBRATION 0x100 #define SCAN_FLAG_FEEDING 0x200 #define SCAN_FLAG_USE_XPA 0x400 - +#define SCAN_FLAG_ENABLE_LEDADD 0x800 #define MOTOR_FLAG_AUTO_GO_HOME 0x01 #define MOTOR_FLAG_DISABLE_BUFFER_FULL_MOVE 0x02 #define MOTOR_FLAG_FEED 0x04 @@ -995,7 +1027,7 @@ extern void sanei_genesys_create_gamma_table (uint16_t * gamma_table, int size, float maximum, float gamma_max, float gamma); - + extern SANE_Status sanei_genesys_send_gamma_table (Genesys_Device * dev); extern SANE_Status sanei_genesys_start_motor (Genesys_Device * dev); @@ -1054,7 +1086,7 @@ sanei_genesys_wait_for_home(Genesys_Device *dev); extern SANE_Status sanei_genesys_asic_init(Genesys_Device *dev, SANE_Bool cold); -extern +extern int sanei_genesys_compute_dpihw(Genesys_Device *dev, int xres); extern @@ -1173,7 +1205,7 @@ compute_planar_coefficients (Genesys_Device * dev, unsigned int channels, unsigned int cmat[3], unsigned int offset, - unsigned int coeff, + unsigned int coeff, unsigned int target); void @@ -1190,6 +1222,10 @@ compute_shifted_coefficients (Genesys_Device * dev, SANE_Status probe_genesys_devices (void); + +SANE_Status genesys_flatbed_calibration (Genesys_Device *dev); + +SANE_Status genesys_send_shading_coefficient (Genesys_Device *dev); #endif diff --git a/backend/hp3900_debug.c b/backend/hp3900_debug.c index 18f6136..eb7d45c 100644 --- a/backend/hp3900_debug.c +++ b/backend/hp3900_debug.c @@ -597,7 +597,7 @@ dbg_tiff_save (char *sFile, SANE_Int width, SANE_Int height, SANE_Int depth, } else DBG (DBG_ERR, - "- dbg_tiff_save: Enviroment HOME variable does not exist\n"); + "- dbg_tiff_save: Environment HOME variable does not exist\n"); } #else /* silent gcc */ diff --git a/backend/hp3900_sane.c b/backend/hp3900_sane.c index a1c381c..b815572 100644 --- a/backend/hp3900_sane.c +++ b/backend/hp3900_sane.c @@ -1405,7 +1405,7 @@ options_init (TScanner * scanner) pDesc->title = SANE_I18N ("Scanner model"); pDesc->desc = SANE_I18N - ("Allows to test device behaviour with other supported models"); + ("Allows one to test device behaviour with other supported models"); pDesc->type = SANE_TYPE_STRING; pDesc->size = max_string_size (scanner->list_models); pDesc->constraint_type = SANE_CONSTRAINT_STRING_LIST; diff --git a/backend/hp5590.c b/backend/hp5590.c index 8db3d5e..7b1cd60 100644 --- a/backend/hp5590.c +++ b/backend/hp5590.c @@ -1239,6 +1239,14 @@ convert_to_rgb (struct hp5590_scanner *scanner, SANE_Byte *data, SANE_Int size) buf[i*6+5] = ptr[2*i+bytes_per_color*2]; } } + + /* Invert pixels in case of TMA Negatives source has been selected */ + if (scanner->source == SOURCE_TMA_NEGATIVES) + { + for (i = 0; i < bytes_per_line; i++) + buf[i] ^= 0xff; + } + memcpy (ptr, buf, bytes_per_line); } free (buf); diff --git a/backend/hs2p-scsi.c b/backend/hs2p-scsi.c index 82640e9..a14e6cb 100644 --- a/backend/hs2p-scsi.c +++ b/backend/hs2p-scsi.c @@ -1283,9 +1283,9 @@ hs2p_send_gamma (HS2P_Scanner * s) _lto3b (len, &out.cmd.len[0]); /* 19 bytes max */ out.gamma[0] = 0x08; /* Gamma ID for Download table */ out.gamma[1] = 0x08; /* The Number of gray scale (M) = 8 */ - for (i = 2; i < 2 + GAMMA_LENGTH; i++) + for (i = 0; i < GAMMA_LENGTH; i++) { - out.gamma[i] = s->gamma_table[i]; + out.gamma[i + 2] = s->gamma_table[i]; } status = sanei_scsi_cmd (s->fd, &out, sizeof (out), NULL, NULL); diff --git a/backend/ibm.c b/backend/ibm.c index 729c140..3ab7890 100644 --- a/backend/ibm.c +++ b/backend/ibm.c @@ -248,11 +248,13 @@ attach (const char *devnam, Ibm_Device ** devp) dev->sane.name = strdup (devnam); dev->sane.vendor = "IBM"; - str = malloc (16 + 1); - memset (str, 0, sizeof (str)); - strncpy (str, (char *)ibuf.product, sizeof(ibuf.product)); - strncpy (str + sizeof(ibuf.revision), (char *)ibuf.revision, sizeof(ibuf.revision)); - str[sizeof(ibuf.product) + sizeof(ibuf.revision)] = '\0'; + str = malloc (sizeof(ibuf.product) + sizeof(ibuf.revision) + 1); + if (str) + { + str[0] = '\0'; + strncat (str, (char *)ibuf.product, sizeof(ibuf.product)); + strncat (str, (char *)ibuf.revision, sizeof(ibuf.revision)); + } dev->sane.model = str; dev->sane.type = "flatbed scanner"; diff --git a/backend/kodakaio.c b/backend/kodakaio.c index 8c4583a..42b59a5 100644 --- a/backend/kodakaio.c +++ b/backend/kodakaio.c @@ -1,7 +1,7 @@ /* * kodakaio.c - SANE library for Kodak ESP Aio scanners. * - * Copyright (C) 2011-2013 Paul Newall + * Copyright (C) 2011-2015 Paul Newall * * Based on the Magicolor sane backend: * Based on the epson2 sane backend: @@ -14,19 +14,32 @@ * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, version 2. - * Using avahi now 25/11/12 for net autodiscovery. Use configure option --enable-avahi + * Modified 30/12/14 to fix bug where network connection was broken after 30s of idle time. + * The connection is now made in sane_start and ended in sane_cancel. * 01/01/13 Now with adf, the scan can be padded to make up the full page length, * or the page can terminate at the end of the paper. This is a selectable option. + * 25/11/12 Using avahi now for net autodiscovery. Use configure option --enable-avahi */ -/* convenient lines to paste -export SANE_DEBUG_KODAKAIO=10 +/* +Packages to add to a clean ubuntu install +libavahi-common-dev +libusb-dev +libsnmp-dev + +convenient lines to paste +export SANE_DEBUG_KODAKAIO=20 for ubuntu prior to 12.10 -./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --enable-avahi --disable-latex BACKENDS=kodakaio +./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --enable-avahi --disable-latex BACKENDS="kodakaio test" for ubuntu 12.10 -./configure --prefix=/usr --libdir=/usr/lib/i386-linux-gnu --sysconfdir=/etc --localstatedir=/var --enable-avahi --disable-latex BACKENDS=kodakaio +./configure --prefix=/usr --libdir=/usr/lib/i386-linux-gnu --sysconfdir=/etc --localstatedir=/var --enable-avahi --disable-latex BACKENDS="kodakaio test" + +for ubuntu 14.10 +./configure --prefix=/usr --libdir=/usr/lib/x86_64-linux-gnu --sysconfdir=/etc --localstatedir=/var --enable-avahi --disable-latex BACKENDS="kodakaio test" + +If you want to use the test backend, for example with sane-troubleshoot, you should enable it in /etc/sane.d/dll.conf */ @@ -50,20 +63,14 @@ for ubuntu 12.10 */ /* FUNCTION-TREE sane_init - sane_start - k_init_parametersta - k_lock_scanner - k_set_scanning_parameters - print_params - k_start_scan - cmd_start_scan - print_status - k_send - kodakaio_txrxack sane_open device_detect + k_dev_init + open_scanner + close_scanner sane_get_devices init_options + (open_scanner - moved to sane_start 27/12/14 ) sane_control_option getvalue setvalue @@ -71,6 +78,18 @@ for ubuntu 12.10 change_source activateOption deactivateOption + sane_start + open_scanner + k_init_parametersta + k_lock_scanner + k_hello + k_set_scanning_parameters + print_params + k_start_scan + cmd_start_scan + print_status + k_send + kodakaio_txrxack sane_get_parameters print_params sane_read @@ -78,6 +97,11 @@ for ubuntu 12.10 cmd_read_data (reads one block) k_recv cmp_array + sane_cancel + cmd_cancel_scan + close_scanner + sane_close + (close_scanner - moved to sane_cancel 27/12/14) sane_exit free_devices k_recv @@ -89,7 +113,9 @@ for ubuntu 12.10 open_scanner sanei_kodakaio_net_open close_scanner - sanei_kodakaio_net_close + k_scan_finish + cmd_cancel_scan + sanei_kodakaio_net_close or sanei_usb_close detect_usb kodakaio_getNumberOfUSBProductIds attach_one_config - (Passed to sanei_configure_attach) @@ -126,8 +152,8 @@ for ubuntu 12.10 #define KODAKAIO_VERSION 02 -#define KODAKAIO_REVISION 4 -#define KODAKAIO_BUILD 6 +#define KODAKAIO_REVISION 7 +#define KODAKAIO_BUILD 2 /* for usb (but also used for net though it's not required). */ #define MAX_BLOCK_SIZE 32768 @@ -214,10 +240,12 @@ static int K_SNMP_Timeout = 3000; /* used for any auto detection method */ static int K_Scan_Data_Timeout = 10000; static int K_Request_Timeout = 5000; +/* static int bitposn=0; was used to pack bits into bytes in lineart mode */ + /* This file is used to store directly the raster returned by the scanner for debugging If RawScanPath has no length it will not be created */ FILE *RawScan = NULL; -/* example: unsigned char RawScanPath[] = "TestRawScan.pgm"; */ +/* example: char RawScanPath[] = "TestRawScan.pgm"; */ char RawScanPath[] = ""; /* empty path means no raw scan file is made */ /* @@ -566,16 +594,17 @@ commandtype, max depth, pointer to depth list * The depth variable gets updated when the bit depth is modified. */ +/* could be affecting what data sane delivers */ static struct mode_param mode_params[] = { - /* {0x00, 1, 1}, // Lineart, 1 color, 1 bit */ + {0x03, 3, 24}, /* Color, 3 colors, 24 bit */ {0x02, 1, 8}, /* Grayscale, 1 color, 8 bit */ - {0x03, 3, 24} /* Color, 3 colors, 24 bit */ + {0x00, 1, 1} /* Lineart, 1 color, 8 bit (was 8 bit) */ }; static SANE_String_Const mode_list[] = { - /* SANE_VALUE_SCAN_MODE_LINEART, */ - SANE_VALUE_SCAN_MODE_GRAY, SANE_VALUE_SCAN_MODE_COLOR, + SANE_VALUE_SCAN_MODE_GRAY, + SANE_VALUE_SCAN_MODE_LINEART, NULL }; @@ -602,6 +631,9 @@ static SANE_String_Const source_list[] = { NULL }; +static const SANE_Range percent_range_fixed = {SANE_FIX(0.0), SANE_FIX(100.0), SANE_FIX(1.0)}; +/*static const SANE_Range percent_range_int = {0, 100, 1};*/ + /* prototypes */ static SANE_Status attach_one_usb(SANE_String_Const devname); static SANE_Status attach_one_net(SANE_String_Const devname, unsigned int device); @@ -659,11 +691,12 @@ print_status(KodakAio_Scanner *s,int level) /**************************************************************************** * Low-level Network communication functions ****************************************************************************/ -/* We don't have a packet wrapper, which holds packet size etc., so we - don't have to use a *read_raw and a *_read function... */ static int kodakaio_net_read(struct KodakAio_Scanner *s, unsigned char *buf, size_t wanted, SANE_Status * status) +/* there seems to be a condition where this returns no error and no data without detecting a timeout +That is probably if the scanner disconnected the network connection +*/ { size_t size, read = 0; struct pollfd fds[1]; @@ -676,7 +709,7 @@ kodakaio_net_read(struct KodakAio_Scanner *s, unsigned char *buf, size_t wanted, fds[0].events = POLLIN; fds[0].revents = 0; if ((pollreply = poll (fds, 1, K_Request_Timeout)) <= 0) { - if (pollreply ==0) + if (pollreply == 0) DBG(1, "net poll timeout\n"); else /* pollreply is -ve */ @@ -684,21 +717,22 @@ kodakaio_net_read(struct KodakAio_Scanner *s, unsigned char *buf, size_t wanted, *status = SANE_STATUS_IO_ERROR; return read; } - else if(fds[0].revents & POLLIN) { + else if((fds[0].revents & POLLIN) && !(fds[0].revents & (POLLERR | POLLHUP | POLLNVAL))) { while (read < wanted) { + DBG(50, "reading: read %lu, wanted %lu\n",read, wanted); size = sanei_tcp_read(s->fd, buf + read, wanted - read); - - if (size == 0) - break; - + if (size == 0) { + DBG(1, "No data read. Scanner may have disconnected\n"); + break; + } read += size; } -/* this error removed 28/12/12 because adf scans end with less data than wanted - if (read < wanted) + if (read == 0) *status = SANE_STATUS_IO_ERROR; - */ + DBG(32, "net read %d bytes:%x,%x,%x,%x,%x,%x,%x,%x\n",read,buf[0],buf[1],buf[2],buf[3],buf[4],buf[5],buf[6],buf[7]); + return read; } else @@ -706,7 +740,7 @@ kodakaio_net_read(struct KodakAio_Scanner *s, unsigned char *buf, size_t wanted, return read; } -/* kodak does not pad commands like magicolor, so there's only a write_raw function */ + static int sanei_kodakaio_net_write_raw(struct KodakAio_Scanner *s, const unsigned char *buf, size_t buf_size, @@ -832,6 +866,7 @@ k_recv(KodakAio_Scanner * s, void *buf, ssize_t buf_size, this function called by a number of others In USB mode, this function will wait until data is available for a maximum of SCANNER_READ_TIMEOUT seconds. +In NET mode the timeout is in kodakaio_net_read */ ssize_t n = 0; char fmt_buf[25]; @@ -847,6 +882,10 @@ In USB mode, this function will wait until data is available for a maximum of SC DBG(min(16,DBG_READ), "[%ld] %s: net req size = %ld ", (long) time_start, __func__, (long) buf_size); n = kodakaio_net_read(s, buf, buf_size, status); DBG(min(16,DBG_READ), "returned %d\n", n); + if (*status != SANE_STATUS_GOOD) { + DBG(1, "%s: err returned from kodakaio_net_read, %s\n", __func__, sane_strstatus(*status)); + } + } else if (s->hw->connection == SANE_KODAKAIO_USB) { /* Start the clock for USB timeout */ @@ -922,17 +961,30 @@ kodakaio_txrx(KodakAio_Scanner *s, unsigned char *txbuf, unsigned char *rxbuf) /* Sends 8 byte data to scanner and returns reply and appropriate status. */ { SANE_Status status; + ssize_t n = 0; k_send(s, txbuf, 8, &status); if (status != SANE_STATUS_GOOD) { DBG(1, "%s: tx err, %s\n", __func__, sane_strstatus(status)); return status; } - k_recv(s, rxbuf, 8, &status); + n = k_recv(s, rxbuf, 8, &status); if (status != SANE_STATUS_GOOD) { DBG(1, "%s: %s gave rx err, %s\n", __func__, "txvalue", sane_strstatus(status)); return status; } + if (n == 0) { + DBG(1, "%s: try 1 k_recv returned 0 bytes with status %s\n", __func__, sane_strstatus(status)); + n = k_recv(s, rxbuf, 8, &status); + if (status != SANE_STATUS_GOOD) { + DBG(1, "%s: %s gave rx err, %s\n", __func__, "txvalue", sane_strstatus(status)); + return status; + } + if (n == 0) { + DBG(1, "%s: try 2 k_recv returned 0 bytes with status %s\n", __func__, sane_strstatus(status)); + return status; + } + } return status; } @@ -962,7 +1014,8 @@ and returns appropriate status s->adf_loaded = SANE_TRUE; DBG(5, "%s: News - docs in ADF\n", __func__); } - else if (rxbuf[4] != 0x01 && s->adf_loaded == SANE_TRUE) { + else if (rxbuf[4] != +0x01 && s->adf_loaded == SANE_TRUE) { s->adf_loaded = SANE_FALSE; DBG(5, "%s: News - ADF is empty\n", __func__); } @@ -976,6 +1029,27 @@ and returns appropriate status return status; } +/* unused function +static ssize_t +kodakaio_rxflush(KodakAio_Scanner *s) + +Tries to get 64 byte reply +and returns number of bytes read + +{ + SANE_Status status; + unsigned char rxbuf[64]; + ssize_t n = 0; + + n = k_recv(s, rxbuf, 64, &status); + if (status != SANE_STATUS_GOOD) { + DBG(1, "%s: %s gave rx err, %s\n", __func__, "status", sane_strstatus(status)); + } + DBG(5, "%s: flushed, %d bytes\n", __func__, (int)n); + return n; +} +*/ + /* * high-level communication commands */ @@ -988,6 +1062,13 @@ k_hello (KodakAio_Scanner * s) char fmt_buf[25]; DBG(5, "%s\n", __func__); + +/* check that there is nothing already in the input buffer before starting +kodakaio_rxflush(s); +*/ +/* preset the reply, so I can see if it gets changed */ +reply[0] = 0; reply[1] = 1; reply[2] = 2; reply[3] = 3; reply[4] = 4; reply[5] = 5; reply[6] = 6; reply[7] = 7; + if((status = kodakaio_txrx(s, KodakEsp_V, reply))!= SANE_STATUS_GOOD) { DBG(1, "%s: KodakEsp_V failure, %s\n", __func__, sane_strstatus(status)); return SANE_STATUS_IO_ERROR; @@ -998,6 +1079,8 @@ k_hello (KodakAio_Scanner * s) DBG(1, "%s: KodakEsp_v err, got %s\n", __func__, fmt_buf); return SANE_STATUS_IO_ERROR; } + + DBG(5, "%s: OK %s\n", __func__, sane_strstatus(status)); return status; } @@ -1045,12 +1128,24 @@ cmd_cancel_scan (SANE_Handle handle) unsigned char reply[8]; /* adf added 20/2/12 should it be adf? or adf with paper in? */ if (strcmp(source_list[s->val[OPT_SOURCE].w], ADF_STR) == 0) { /* adf */ - if (kodakaio_txrxack(s, KodakEsp_F, reply)!= SANE_STATUS_GOOD) return SANE_STATUS_IO_ERROR; - if (kodakaio_txrxack(s, KodakEsp_UnLock, reply)!= SANE_STATUS_GOOD) return SANE_STATUS_IO_ERROR; + if (kodakaio_txrxack(s, KodakEsp_F, reply)!= SANE_STATUS_GOOD) + { + DBG(1, "%s: KodakEsp_F command failed\n", __func__); + return SANE_STATUS_IO_ERROR; + } + if (kodakaio_txrxack(s, KodakEsp_UnLock, reply)!= SANE_STATUS_GOOD) + { + DBG(1, "%s: KodakEsp_UnLock command failed\n", __func__); + return SANE_STATUS_IO_ERROR; + } DBG(5, "%s unlocked the scanner with adf F U\n", __func__); } else { /* no adf */ - if (kodakaio_txrxack(s, KodakEsp_UnLock, reply)!= SANE_STATUS_GOOD) return SANE_STATUS_IO_ERROR; + if (kodakaio_txrxack(s, KodakEsp_UnLock, reply)!= SANE_STATUS_GOOD) + { + DBG(1, "%s: KodakEsp_UnLock command failed\n", __func__); + return SANE_STATUS_IO_ERROR; + } DBG(5, "%s unlocked the scanner U\n", __func__); } s->scanning = SANE_FALSE; @@ -1084,6 +1179,7 @@ Old mc cmd read this stuff from the scanner. I don't think kodak can do that eas return status; } +/* Set color curve command, low level, sends commands to the scanner*/ static SANE_Status cmd_set_color_curve(SANE_Handle handle, unsigned char col) { @@ -1093,11 +1189,12 @@ cmd_set_color_curve(SANE_Handle handle, unsigned char col) unsigned char tx_col[8]; unsigned char rx[8]; unsigned char tx_curve[256]; - unsigned char i; + int i; /* 7/9/14 was unsigned char and that stopped the loop that made the linear curve from going to 255 */ DBG(32, "%s: start\n", __func__); tx_col[0]=0x1b; tx_col[1]='S'; tx_col[2]='K'; tx_col[3]=col; tx_col[4]=0; tx_col[5]=0; tx_col[6]=0; tx_col[7]=0; /* linear curve now but could send tailor made curves in future */ - for(i=0;i<255;++i) tx_curve[i]=i; + for(i=0;i<=255;++i) tx_curve[i]=i; /* 7/9/14 was i<255 the missing elements caused speckles */ + k_send(s, tx_col, 8, &status); if (status != SANE_STATUS_GOOD) { DBG(1, "%s: tx err, %s\n", __func__, "curve command"); @@ -1113,7 +1210,7 @@ cmd_set_color_curve(SANE_Handle handle, unsigned char col) return status; } -/* Set scanning parameters command low level */ +/* Set scanning parameters command, low level, sends commands to the scanner*/ static SANE_Status cmd_set_scanning_parameters(SANE_Handle handle, int resolution, @@ -1210,8 +1307,6 @@ unsigned int i; return 0; } - - static SANE_Status cmd_read_data (SANE_Handle handle, unsigned char *buf, size_t *len) { @@ -1283,11 +1378,11 @@ But it seems that the scanner takes care of that, and gives you the ack as a sep } } else { - DBG(min(1,DBG_READ), "%s: tiny read, got %d bytes of %d\n", __func__, bytecount, *len); + DBG(min(1,DBG_READ), "%s: tiny read, got %d bytes of %d\n", __func__, (int) bytecount, *len); return SANE_STATUS_IO_ERROR; } if (*len > s->params.bytes_per_line) { - /* store average colour as background. That's not the ideal method but it's easy to implement. */ + /* store average colour as background. That's not the ideal method but it's easy to implement. What's it used for? */ lines = *len / s->params.bytes_per_line; s->background[0] = 0; s->background[1] = 0; @@ -1545,11 +1640,11 @@ k_set_scanning_parameters(KodakAio_Scanner * s) s->params.bytes_per_line *= 3; /* Calculate how many bytes per line will be returned by the scanner. - magicolor needed this because it uses padding. Scan bytes per line != image bytes per line + magicolor needed this because it uses padding so scan bytes per line != image bytes per line. * The values needed for this are returned by get_scanning_parameters */ - s->scan_bytes_per_line = 3 * ceil (scan_pixels_per_line * s->params.depth / 8.0); + s->scan_bytes_per_line = 3 * ceil (scan_pixels_per_line); /* we always scan in colour 8 bit */ s->data_len = s->scan_bytes_per_line * floor (s->height * dpi / optres + 0.5); /* NB this is the length for a full scan */ - DBG (1, "Check: scan_bytes_per_line = %d s->params.bytes_per_line = %d \n", s->scan_bytes_per_line, s->params.bytes_per_line); + DBG (5, "Check: scan_bytes_per_line = %d s->params.bytes_per_line = %d \n", s->scan_bytes_per_line, s->params.bytes_per_line); /* k_setup_block_mode at the start of each page for adf to work */ status = k_setup_block_mode (s); @@ -1604,10 +1699,14 @@ k_copy_image_data(KodakAio_Scanner * s, SANE_Byte * data, SANE_Int max_length, uncompressed data is RRRR...GGGG...BBBB per line */ { SANE_Int bytes_available; + SANE_Int threshold; DBG (min(18,DBG_READ), "%s: bytes_read in line: %d\n", __func__, s->bytes_read_in_line); *length = 0; + threshold = 255 - (int) (SANE_UNFIX(s->val[OPT_THRESHOLD].w) * 255.0 / 100.0 + 0.5); /* 255 - for the grey scale version */ + DBG (20, "%s: threshold: %d\n", __func__, threshold); + while ((max_length >= s->params.bytes_per_line) && (s->ptr < s->end)) { SANE_Int bytes_to_copy = s->scan_bytes_per_line - s->bytes_read_in_line; /* First, fill the line buffer for the current line: */ @@ -1635,23 +1734,36 @@ uncompressed data is RRRR...GGGG...BBBB per line */ *length += s->params.bytes_per_line; for (i=0; i< s->params.pixels_per_line; ++i) { + /* different behaviour for each mode */ if (s->val[OPT_MODE].w == MODE_COLOR){ - /*interlace */ - *data++ = 255-line[0]; /*red */ - *data++ = 255-line[s->params.pixels_per_line]; /*green */ - *data++ = 255-line[2 * s->params.pixels_per_line]; /*blue */ + /*interlace was subtracting from 255 until 6/9/14 */ + *data++ = 255-line[0]; /*red */ + *data++ = 255-line[s->params.pixels_per_line]; /*green */ + *data++ = 255-line[2 * s->params.pixels_per_line]; /*blue */ + } + else if (s->val[OPT_MODE].w == MODE_LINEART) { /* gives 1 bit output */ + /*output image location*/ + int offset = i % 8; + unsigned char mask = 0x80 >> offset; + /*set if any colour is over the threshold */ + if (line[0] < threshold || line[s->params.pixels_per_line] < threshold || line[2 * s->params.pixels_per_line] < threshold) + *data &= ~mask; /* white clear the bit in mask */ + else + *data |= mask; /* black set the bit in mask */ + + if (offset == 7 || i == s->params.pixels_per_line-1) + data++; /* move on a byte if the byte is full or the line is complete */ } - else { /* grey */ - /*Average*/ - *data++ = (255-line[0] + else { /* greyscale - Average the 3 colours */ + *data++ = (255-line[0] +255-line[s->params.pixels_per_line] +255-line[2 * s->params.pixels_per_line]) / 3; } - line++; + line++; } /*debug file The same for color or grey because the scan is colour */ if (RawScan != NULL) { @@ -1716,21 +1828,22 @@ k_init_parametersta(KodakAio_Scanner * s) SANE_UNFIX(s->val[OPT_BR_X].w), SANE_UNFIX(s->val[OPT_BR_Y].w)); /* - * The default color depth is stored in mode_params.depth: + * The default color depth is stored in mode_params.depth: */ if (mode_params[s->val[OPT_MODE].w].depth == 1) s->params.depth = 1; else { - DBG(20, "%s: setting depth = s->val[OPT_BIT_DEPTH].w = %d\n", __func__,s->val[OPT_BIT_DEPTH].w); s->params.depth = s->val[OPT_BIT_DEPTH].w; } + DBG(20, "%s: bit depth = s->params.depth = %d\n", __func__,s->params.depth); s->params.last_frame = SANE_TRUE; s->params.bytes_per_line = 3 * ceil (s->params.depth * s->params.pixels_per_line / 8.0); -/* kodak only scans in color and conversion to grey is done in the driver +/* kodak only scans in color and conversion to grey or lineart is done in the driver s->params.format = SANE_FRAME_RGB; */ - DBG(20, "%s: s->val[OPT_MODE].w = %d (color is %d)\n", __func__,s->val[OPT_MODE].w, MODE_COLOR); + DBG(20, "%s: s->val[OPT_MODE].w = %d (color is %d)\n", __func__,s->val[OPT_MODE].w, MODE_COLOR); if (s->val[OPT_MODE].w == MODE_COLOR) s->params.format = SANE_FRAME_RGB; + else if (s->val[OPT_MODE].w == MODE_LINEART) s->params.format = SANE_FRAME_GRAY; else s->params.format = SANE_FRAME_GRAY; DBG(20, "%s: format=%d, bytes_per_line=%d, lines=%d\n", __func__, s->params.format, s->params.bytes_per_line, s->params.lines); @@ -1761,19 +1874,16 @@ you don't know how many blocks there will be in advance because their size may b SANE_Status status = SANE_STATUS_GOOD; size_t buf_len = 0; - /* did we passed everything we read to sane? */ + /* have we passed everything we read to sane? */ if (s->ptr == s->end) { - if (s->eof) return SANE_STATUS_EOF; s->counter++; - if (s->bytes_unread >= s->block_len) buf_len = s->block_len; else buf_len = s->bytes_unread; - DBG(min(20,DBG_READ), "%s: block %d, size %lu\n", __func__, s->counter, (unsigned long) buf_len); @@ -1810,9 +1920,7 @@ you don't know how many blocks there will be in advance because their size may b return SANE_STATUS_IO_ERROR; } } - } - s->end = s->buf + buf_len; s->ptr = s->buf; } @@ -1858,7 +1966,6 @@ get_device_from_identification (const char *ident, const char *vid, const char * return NULL; } - /* * close_scanner() * @@ -2184,6 +2291,7 @@ static void resolve_callback( AvahiLookupResultFlags flags, AVAHI_GCC_UNUSED void* userdata) { + AvahiStringList *vid_pair_list = NULL, *pid_pair_list = NULL; char *pidkey, *pidvalue; char *vidkey, *vidvalue; size_t valuesize; @@ -2204,20 +2312,40 @@ static void resolve_callback( avahi_address_snprint(a, sizeof(a), address); /* Output short for Kodak ESP */ - DBG(min(10,DBG_AUTO), "%s:%u %s ", a,port,host_name); - avahi_string_list_get_pair(avahi_string_list_find(txt, "vid"), - &vidkey, &vidvalue, &valuesize); - DBG(min(10,DBG_AUTO), "%s=%s ", vidkey, vidvalue); - avahi_string_list_get_pair(avahi_string_list_find(txt, "pid"), - &pidkey, &pidvalue, &valuesize); - DBG(min(10,DBG_AUTO), "%s=%s\n", pidkey, pidvalue); + DBG(min(10,DBG_AUTO), "%s:%u %s\n", a,port,host_name); + + vid_pair_list = avahi_string_list_find(txt, "vid"); + if(vid_pair_list != NULL) { + avahi_string_list_get_pair(vid_pair_list, &vidkey, &vidvalue, &valuesize); + DBG(min(10,DBG_AUTO), "%s=%s ", vidkey, vidvalue); + } + else DBG(min(10,DBG_AUTO), "failed to find key vid\n"); + pid_pair_list = avahi_string_list_find(txt, "pid"); + if(pid_pair_list != NULL) { + avahi_string_list_get_pair(pid_pair_list, &pidkey, &pidvalue, &valuesize); + DBG(min(10,DBG_AUTO), "%s=%s\n", pidkey, pidvalue); + } + else DBG(min(10,DBG_AUTO), "failed to find key pid\n"); + + if(pid_pair_list != NULL && vid_pair_list != NULL) { ProcessAvahiDevice(name, vidvalue, pidvalue, a); - avahi_free(vidkey); avahi_free(vidvalue); - avahi_free(pidkey); avahi_free(pidvalue); + } + else DBG(min(10,DBG_AUTO), "didn't call ProcessAvahiDevice\n"); + + if(vid_pair_list != NULL) { + avahi_free(vidkey); + avahi_free(vidvalue); + DBG(min(15,DBG_AUTO), "vidkey and vidvalue freed\n"); + } + if(pid_pair_list != NULL) { + avahi_free(pidkey); + avahi_free(pidvalue); + DBG(min(15,DBG_AUTO), "pidkey and pidvalue freed\n"); + } } } - + DBG(min(10,DBG_AUTO), "ending resolve_callback\n"); avahi_service_resolver_free(r); } @@ -2619,8 +2747,32 @@ init_options(KodakAio_Scanner *s) s->opt[OPT_MODE].size = max_string_size(mode_list); s->opt[OPT_MODE].constraint_type = SANE_CONSTRAINT_STRING_LIST; s->opt[OPT_MODE].constraint.string_list = mode_list; - s->val[OPT_MODE].w = 0; /* Binary */ - DBG(20, "%s: mode_list has first entry %s\n", __func__, mode_list[0]); + s->val[OPT_MODE].w = MODE_COLOR; /* default */ + DBG(20, "%s: mode_list has first entry %s, default mode is %s\n", __func__, mode_list[0],mode_list[s->val[OPT_MODE].w]); + + /* theshold the sane std says should be SANE_TYPE_FIXED 0..100 but all other backends seem to use INT 0..255 */ + s->opt[OPT_THRESHOLD].name = SANE_NAME_THRESHOLD; + s->opt[OPT_THRESHOLD].title = SANE_TITLE_THRESHOLD; + s->opt[OPT_THRESHOLD].desc = SANE_DESC_THRESHOLD; + s->opt[OPT_THRESHOLD].type = SANE_TYPE_FIXED; + s->opt[OPT_THRESHOLD].unit = SANE_UNIT_PERCENT; + s->opt[OPT_THRESHOLD].size = sizeof(SANE_Word); + s->opt[OPT_THRESHOLD].constraint_type = SANE_CONSTRAINT_RANGE; + s->opt[OPT_THRESHOLD].constraint.range = &percent_range_fixed; + s->val[OPT_THRESHOLD].w = SANE_FIX(50.0); + DBG(20, "%s: threshold initialised to fixed %f\n", __func__, SANE_UNFIX(s->val[OPT_THRESHOLD].w)); + + /* theshold the sane std says should be SANE_TYPE_FIXED 0..100 but all other backends seem to use INT 0..255 + s->opt[OPT_THRESHOLD].name = SANE_NAME_THRESHOLD; + s->opt[OPT_THRESHOLD].title = SANE_TITLE_THRESHOLD; + s->opt[OPT_THRESHOLD].desc = SANE_DESC_THRESHOLD; + s->opt[OPT_THRESHOLD].type = SANE_TYPE_INT; + s->opt[OPT_THRESHOLD].unit = SANE_UNIT_PERCENT; + s->opt[OPT_THRESHOLD].size = sizeof(SANE_Word); + s->opt[OPT_THRESHOLD].constraint_type = SANE_CONSTRAINT_RANGE; + s->opt[OPT_THRESHOLD].constraint.range = &percent_range_int; + s->val[OPT_THRESHOLD].w = 51; + DBG(20, "%s: threshold initialised to int %d\n", __func__, s->val[OPT_THRESHOLD].w); */ /* bit depth */ s->opt[OPT_BIT_DEPTH].name = SANE_NAME_BIT_DEPTH; @@ -2656,6 +2808,17 @@ init_options(KodakAio_Scanner *s) s->val[OPT_RESOLUTION].w = s->hw->cap->dpi_range.min; + /* trial option for debugging + s->opt[OPT_TRIALOPT].name = "trialoption"; + s->opt[OPT_TRIALOPT].title = "trialoption"; + s->opt[OPT_TRIALOPT].desc = "trialoption"; + s->opt[OPT_TRIALOPT].type = SANE_TYPE_INT; + s->opt[OPT_TRIALOPT].unit = SANE_UNIT_NONE; + s->opt[OPT_TRIALOPT].size = sizeof(SANE_Word); + s->opt[OPT_TRIALOPT].constraint_type = SANE_CONSTRAINT_RANGE; + s->opt[OPT_TRIALOPT].constraint.range = &percent_range_int; + s->val[OPT_TRIALOPT].w = 1; */ + /* preview */ s->opt[OPT_PREVIEW].name = SANE_NAME_PREVIEW; s->opt[OPT_PREVIEW].title = SANE_TITLE_PREVIEW; @@ -2831,12 +2994,13 @@ maybe we should only be rebuilding the source list here? */ *handle = (SANE_Handle) s; +/* moving the open scanner section below to sane_start 27/12/14 status = open_scanner(s); if (status != SANE_STATUS_GOOD) { free(s); return status; } - +*/ return status; } @@ -2853,8 +3017,11 @@ sane_close(SANE_Handle handle) s = (KodakAio_Scanner *) handle; DBG(2, "%s: called\n", __func__); +/* moving the close scanner section below to sane_cancel 27/12/14 */ if (s->fd != -1) close_scanner(s); +/* end of section */ + if(RawScan != NULL) fclose(RawScan); RawScan = NULL; @@ -2867,7 +3034,7 @@ sane_get_option_descriptor(SANE_Handle handle, SANE_Int option) /* this may be a sane call, but it happens way too often to have DBG level 2 */ KodakAio_Scanner *s = (KodakAio_Scanner *) handle; - DBG(20, "%s: called for option %d\n", __func__, option); + DBG(30, "%s: called for option %d\n", __func__, option); if (option < 0 || option >= NUM_OPTIONS) return NULL; @@ -2922,7 +3089,7 @@ getvalue(SANE_Handle handle, SANE_Int option, void *value) case OPT_NUM_OPTS: case OPT_BIT_DEPTH: -/* case OPT_BRIGHTNESS: */ + /* case OPT_TRIALOPT: */ case OPT_RESOLUTION: case OPT_PREVIEW: case OPT_TL_X: @@ -2930,6 +3097,13 @@ getvalue(SANE_Handle handle, SANE_Int option, void *value) case OPT_BR_X: case OPT_BR_Y: *((SANE_Word *) value) = sval->w; + DBG(20, "%s: got option %d as %d\n", __func__, option, *((SANE_Word *) value)); + break; + + case OPT_THRESHOLD: + *((SANE_Word *) value) = sval->w; + DBG(20, "%s: got option %d as %f\n", __func__, option, SANE_UNFIX(*((SANE_Word *) value))); + /*DBG(20, "%s: got option %d as %d\n", __func__, option, *((SANE_Word *) value));*/ break; case OPT_MODE: @@ -2942,9 +3116,11 @@ getvalue(SANE_Handle handle, SANE_Int option, void *value) break; default: + DBG(20, "%s: returning inval\n", __func__); return SANE_STATUS_INVAL; } + DBG(20, "%s: returning good\n", __func__); return SANE_STATUS_GOOD; } @@ -3050,18 +3226,23 @@ setvalue(SANE_Handle handle, SANE_Int option, void *value, SANE_Int *info) case OPT_MODE: { sval->w = optindex; - /* if binary, then disable the bit depth selection */ - if (optindex == 0) { + /* if binary, then disable the bit depth selection and enable threshold */ + if (optindex == MODE_LINEART) { + DBG(17, "%s: binary mode setting depth to 1\n", __func__); + s->val[OPT_BIT_DEPTH].w = 1; s->opt[OPT_BIT_DEPTH].cap |= SANE_CAP_INACTIVE; + s->opt[OPT_THRESHOLD].cap &= ~SANE_CAP_INACTIVE; } else { - if (s->hw->cap->depth_list[0] == 1) - s->opt[OPT_BIT_DEPTH].cap |= - SANE_CAP_INACTIVE; - else { - s->opt[OPT_BIT_DEPTH].cap &= - ~SANE_CAP_INACTIVE; - s->val[OPT_BIT_DEPTH].w = - mode_params[optindex].depth; + if (s->hw->cap->depth_list[0] == 1) { /* only one entry in the list ? */ + DBG(17, "%s: non-binary mode but only one depth available\n", __func__); + s->val[OPT_BIT_DEPTH].w = s->hw->cap->depth_list[1]; + s->opt[OPT_BIT_DEPTH].cap |= SANE_CAP_INACTIVE; + s->opt[OPT_THRESHOLD].cap |= SANE_CAP_INACTIVE; + } else { /* there is a list to choose from ? */ + DBG(17, "%s: non-binary mode and depth list available\n", __func__); + s->opt[OPT_BIT_DEPTH].cap &= ~SANE_CAP_INACTIVE; + s->val[OPT_BIT_DEPTH].w = mode_params[optindex].depth; + s->opt[OPT_THRESHOLD].cap |= SANE_CAP_INACTIVE; /* does not work in xsane ? */ } } reload = SANE_TRUE; @@ -3074,6 +3255,13 @@ setvalue(SANE_Handle handle, SANE_Int option, void *value, SANE_Int *info) reload = SANE_TRUE; break; + case OPT_THRESHOLD: + sval->w = *((SANE_Word *) value); + DBG(17, "setting threshold to %f\n", SANE_UNFIX(sval->w)); + /*DBG(17, "setting threshold to %d\n", sval->w);*/ + /*reload = SANE_TRUE; what does this do?*/ + break; + case OPT_RESOLUTION: sval->w = *((SANE_Word *) value); DBG(17, "setting resolution to %d\n", sval->w); @@ -3109,7 +3297,7 @@ setvalue(SANE_Handle handle, SANE_Int option, void *value, SANE_Int *info) sval->w = *((SANE_Word *) value); break; -/* case OPT_BRIGHTNESS: */ + /* case OPT_TRIALOPT: */ case OPT_PREVIEW: /* needed? */ sval->w = *((SANE_Word *) value); break; @@ -3131,14 +3319,14 @@ sane_control_option(SANE_Handle handle, SANE_Int option, SANE_Action action, void *value, SANE_Int *info) { KodakAio_Scanner *s = (KodakAio_Scanner *) handle; - DBG(2, "%s: action = %x, option = %d %s\n", __func__, action, option, s->opt[option].name); - if (option < 0 || option >= NUM_OPTIONS) { - DBG(1, "%s: option num = %d (%s) out of range\n", __func__, option, s->opt[option].name); + DBG(1, "%s: option num = %d out of range (0..%d)\n", __func__, option, NUM_OPTIONS - 1); return SANE_STATUS_INVAL; } + DBG(5, "%s: action = %x, option = %d %s\n", __func__, action, option, s->opt[option].name); + if (info != NULL) *info = 0; @@ -3209,6 +3397,16 @@ sane_start(SANE_Handle handle) * them to s->params Only set scanning params the first time, or after a cancel try change 22/2/12 take lock scanner out of k_set_scanning_parameters */ + +/* moved open_scanner here 27/12/14 from sane_open */ + status = open_scanner(s); + if (status != SANE_STATUS_GOOD) { + free(s); + return status; + } +/* end of open scanner section */ + + status = k_lock_scanner(s); if (status != SANE_STATUS_GOOD) { DBG(1, "could not lock scanner\n"); @@ -3299,24 +3497,24 @@ sane_read(SANE_Handle handle, SANE_Byte *data, SANE_Int max_length, return status; } -/* - * void sane_cancel(SANE_Handle handle) - * - * Set the cancel flag to true. The next time the backend requests data - * from the scanner the CAN message will be sent. - */ void sane_cancel(SANE_Handle handle) { + SANE_Status status; KodakAio_Scanner *s = (KodakAio_Scanner *) handle; DBG(2, "%s: called\n", __func__); -/* used to set cancelling flag to tell sane_read to cancel -changed 20/2/12 - s->canceling = SANE_TRUE; -*/ - cmd_cancel_scan(s); + status = cmd_cancel_scan(s); + if (status != SANE_STATUS_GOOD) + DBG(1, "%s: cmd_cancel_scan failed: %s\n", __func__, + sane_strstatus(status)); + +/* moved from close scanner section 27/12/14 */ + if (s->fd != -1) + close_scanner(s); +/* end of section */ + } /* diff --git a/backend/kodakaio.h b/backend/kodakaio.h index f2265f5..6804e3b 100644 --- a/backend/kodakaio.h +++ b/backend/kodakaio.h @@ -97,8 +97,10 @@ enum { OPT_NUM_OPTS = 0, OPT_MODE_GROUP, OPT_MODE, + OPT_THRESHOLD, OPT_BIT_DEPTH, OPT_RESOLUTION, + OPT_TRIALOPT, /* for debuggging */ OPT_PREVIEW, OPT_SOURCE, OPT_ADF_MODE, @@ -163,6 +165,7 @@ struct KodakAio_Scanner SANE_Int left, top; /* in optres units? */ SANE_Int width, height; /* in optres units? */ + /* SANE_Int threshold; 0..255 for lineart*/ /* image block data */ SANE_Int data_len; @@ -192,7 +195,7 @@ struct mode_param }; enum { - MODE_GRAY, MODE_COLOR + MODE_COLOR, MODE_GRAY, MODE_LINEART }; #endif diff --git a/backend/lexmark_low.c b/backend/lexmark_low.c index ae0db2c..821b621 100644 --- a/backend/lexmark_low.c +++ b/backend/lexmark_low.c @@ -1965,7 +1965,7 @@ sanei_lexmark_low_search_home_bwd (Lexmark_Device * dev) available. The number of lines (or number of buffers in our buffer space) is calculated from the size of the data available from the scanner. The number of buffers is calculated as the space required to hold 1.5 times - the the size of the data available from the scanner. + the size of the data available from the scanner. After data is read from the scanner each line is checked if it is on the home dot. Lines are continued to be read until we are no longer on the home diff --git a/backend/magicolor.c b/backend/magicolor.c index e3cd80d..660f517 100644 --- a/backend/magicolor.c +++ b/backend/magicolor.c @@ -103,7 +103,8 @@ * | | | | | | | | | | | | | | | */ static struct MagicolorCmd magicolor_cmd[] = { - {"mc1690mf", CMD, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x12, NET, 0x00, 0x01, 0x02, 0x03} + {"mc1690mf", CMD, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x12, NET, 0x00, 0x01, 0x02, 0x03}, + {"mc4690mf", CMD, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x12, NET, 0x00, 0x01, 0x02, 0x03}, }; static SANE_Int magicolor_default_resolutions[] = {150, 300, 600}; @@ -121,7 +122,20 @@ static struct MagicolorCap magicolor_cap[] = { {0, SANE_FIX(0x13f8 * MM_PER_INCH / 600), 0}, {0, SANE_FIX(0x1b9c * MM_PER_INCH / 600), 0}, /* FBF x/y ranges (TODO!) */ SANE_TRUE, SANE_FALSE, /* non-duplex ADF, x/y ranges (TODO!) */ {0, SANE_FIX(0x1390 * MM_PER_INCH / 600), 0}, {0, SANE_FIX(0x20dc * MM_PER_INCH / 600), 0}, - } + }, + + /* KONICA MINOLTA magicolor 4690MF, USB ID 0x132b:2079 */ + { + 0x2079, "mc4690mf", "KONICA MINOLTA magicolor 4690MF", + "FIXME", /* FIXME: fill in the correct OID! */ + 0x03, 0x85, + 600, {150, 600, 0}, magicolor_default_resolutions, 3, /* 600 dpi max, 3 resolutions */ + 8, magicolor_default_depths, /* color depth 8 default, 1 and 8 possible */ + {1, 9, 0}, /* brightness ranges (TODO!) */ + {0, SANE_FIX(0x13f8 * MM_PER_INCH / 600), 0}, {0, SANE_FIX(0x1b9c * MM_PER_INCH / 600), 0}, /* FBF x/y ranges (TODO!) */ + SANE_TRUE, SANE_TRUE, /* duplex ADF, x/y ranges (TODO!) */ + {0, SANE_FIX(0x1390 * MM_PER_INCH / 600), 0}, {0, SANE_FIX(0x20dc * MM_PER_INCH / 600), 0}, + }, }; @@ -373,6 +387,7 @@ sanei_magicolor_net_close(struct Magicolor_Scanner *s) SANE_Word sanei_magicolor_usb_product_ids[] = { 0x2089, /* magicolor 1690MF */ + 0x2079, /* magicolor 4690MF */ 0 /* last entry - this is used for devices that are specified in the config file as "usb <vendor> <product>" */ }; @@ -1176,7 +1191,12 @@ mc_set_scanning_parameters(Magicolor_Scanner * s) /* ADF used? */ if (strcmp(source_list[s->val[OPT_SOURCE].w], ADF_STR) == 0) { /* Use ADF */ - source = 0x01; + if (s->val[OPT_ADF_MODE].w == 0) { + source = 0x01; + } else { + /* Use duplex */ + source = 0x02; + } } else { source = 0x00; } @@ -1670,6 +1690,7 @@ detect_usb(struct Magicolor_Scanner *s) DBG(2, "found valid Magicolor scanner: 0x%x/0x%x (vendorID/productID)\n", vendor, product); + mc_set_device(s, product); return SANE_STATUS_GOOD; } diff --git a/backend/microtek2.c b/backend/microtek2.c index d56e568..8fdf497 100644 --- a/backend/microtek2.c +++ b/backend/microtek2.c @@ -4013,7 +4013,7 @@ get_scan_mode_and_depth(Microtek2_Scanner *ms, /* This function translates the strings for the possible modes and */ /* bitdepth into a more conveniant format as needed for SET WINDOW. */ /* bits_per_pixel is the number of bits per color one pixel needs */ - /* when transferred from the the scanner, bits_perpixel_out is the */ + /* when transferred from the scanner, bits_perpixel_out is the */ /* number of bits per color one pixel uses when transferred to the */ /* frontend. These may be different. For example, with a depth of 4 */ /* two pixels per byte are transferred from the scanner, but only one */ @@ -7453,7 +7453,7 @@ segreg_proc_data(Microtek2_Scanner *ms) save_current_src = ms->buf.current_src; if ( ms->buf.free_lines < ms->src_max_lines ) { - ms->buf.current_src = ++ms->buf.current_src % 2; + ms->buf.current_src = !ms->buf.current_src; ms->buf.src_buf = ms->buf.src_buffer[ms->buf.current_src]; ms->buf.free_lines = ms->buf.free_max_lines; } diff --git a/backend/mustek_pp_ccd300.c b/backend/mustek_pp_ccd300.c index c5351a4..41ad0ec 100644 --- a/backend/mustek_pp_ccd300.c +++ b/backend/mustek_pp_ccd300.c @@ -940,10 +940,10 @@ get_color_line_101x (Mustek_pp_Handle * dev, SANE_Byte * buf) wait_bank_change (dev, priv->bank_count, 1); reset_bank_count (dev); if (priv->ccd_line >= (priv->line_step >> SANE_FIXED_SCALE_SHIFT)) - priv->redline = ++priv->redline % priv->green_offs; + priv->redline = (priv->redline + 1) % priv->green_offs; if (priv->ccd_line >= priv->blue_offs + (priv->line_step >> SANE_FIXED_SCALE_SHIFT)) - priv->blueline = ++priv->blueline % priv->blue_offs; + priv->blueline = (priv->blueline + 1) % priv->blue_offs; continue; } @@ -979,7 +979,7 @@ get_color_line_101x (Mustek_pp_Handle * dev, SANE_Byte * buf) } - priv->redline = ++priv->redline % priv->green_offs; + priv->redline = (priv->redline + 1) % priv->green_offs; if (priv->ccd_line >= priv->green_offs && gogreen) { @@ -1013,7 +1013,7 @@ get_color_line_101x (Mustek_pp_Handle * dev, SANE_Byte * buf) if (priv->ccd_line >= priv->blue_offs + (priv->line_step >> SANE_FIXED_SCALE_SHIFT)) - priv->blueline = ++priv->blueline % priv->blue_offs; + priv->blueline = (priv->blueline + 1) % priv->blue_offs; if (gogreen) { @@ -1660,7 +1660,7 @@ ccd300_open (SANE_String port, SANE_Int caps, SANE_Int * fd) if (caps & ~(CAP_NOTHING | CAP_INVERT | CAP_LAMP_OFF)) { - DBG (1, "ccd300_open: called with unknonw capabilities (%#02x)\n", + DBG (1, "ccd300_open: called with unknown capabilities (%#02x)\n", caps); return SANE_STATUS_INVAL; } @@ -1816,7 +1816,7 @@ ccd300_config (SANE_Handle handle, SANE_String_Const optname, } else { - DBG (1, "ccd300_config: unkown option ``%s''", optname); + DBG (1, "ccd300_config: unknown option ``%s''", optname); return SANE_STATUS_INVAL; } diff --git a/backend/mustek_pp_cis.c b/backend/mustek_pp_cis.c index 026734f..d5ef86d 100644 --- a/backend/mustek_pp_cis.c +++ b/backend/mustek_pp_cis.c @@ -2086,7 +2086,7 @@ cis_calibrate (Mustek_PP_CIS_dev * dev) * It seems that the width of the black border is being measured at * this stage, possibly multiple times till it stabilizes. * I assume that the buffer is read 100 times to allow the lamp to - * warm up and that the the width of the black border is then being + * warm up and that the width of the black border is then being * measured till it stabilizes. That would explain the minimum number * of 102 iterations that I've seen. * diff --git a/backend/net.c b/backend/net.c index 16fba2f..4beb45d 100644 --- a/backend/net.c +++ b/backend/net.c @@ -140,7 +140,7 @@ static int hang_over; client/server have different endianness. A value of -1 means, that there's no left over; otherwise the value has to be casted to SANE_Byte. left_over means, that there is a remaining byte from a previous call to sane_read, - which already is in the the correct byte order, but could not be returned, + which already is in the correct byte order, but could not be returned, e.g. because the frontend requested only one byte per call. */ static int left_over; @@ -1044,9 +1044,14 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize) continue; } - +#ifdef WITH_AVAHI + avahi_threaded_poll_lock (avahi_thread); +#endif /* WITH_AVAHI */ DBG (2, "sane_init: trying to add %s\n", device_name); add_device (device_name, 0); +#ifdef WITH_AVAHI + avahi_threaded_poll_unlock (avahi_thread); +#endif /* WITH_AVAHI */ } fclose (fp); @@ -1090,8 +1095,14 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize) if (host[0] == '\0') continue; #endif /* ENABLE_IPV6 */ +#ifdef WITH_AVAHI + avahi_threaded_poll_lock (avahi_thread); +#endif /* WITH_AVAHI */ DBG (2, "sane_init: trying to add %s\n", host); add_device (host, 0); +#ifdef WITH_AVAHI + avahi_threaded_poll_unlock (avahi_thread); +#endif /* WITH_AVAHI */ } free (copy); } @@ -1507,7 +1518,13 @@ sane_open (SANE_String_Const full_name, SANE_Handle * meta_handle) DBG (1, "sane_open: device %s not found, trying to register it anyway\n", nd_name); +#ifdef WITH_AVAHI + avahi_threaded_poll_lock (avahi_thread); +#endif /* WITH_AVAHI */ status = add_device (nd_name, &dev); +#ifdef WITH_AVAHI + avahi_threaded_poll_unlock (avahi_thread); +#endif /* WITH_AVAHI */ if (status != SANE_STATUS_GOOD) { DBG (1, "sane_open: could not open device\n"); diff --git a/backend/niash.c b/backend/niash.c index 7bc8a25..950df21 100644 --- a/backend/niash.c +++ b/backend/niash.c @@ -81,15 +81,14 @@ typedef enum optGroupEnhancement, optThreshold, - - optLast, -/* put temporarily disabled options here after optLast */ - +#ifdef EXPERIMENTAL optGroupMisc, optLamp, optCalibrate, - optGamma /* analog gamma = single number */ + optGamma, /* analog gamma = single number */ +#endif + optLast } EOptionIndex; @@ -150,10 +149,12 @@ static const SANE_Range rangeGammaTable = { 0, 255, 1 }; /* available scanner resolutions */ static const SANE_Int setResolutions[] = { 4, 75, 150, 300, 600 }; +#ifdef EXPERIMENTAL /* range of an analog gamma */ static const SANE_Range rangeGamma = { SANE_FIX (0.25), SANE_FIX (4.0), SANE_FIX (0.0) }; +#endif /* interpolate a sane gamma table to a hardware appropriate one just in case the sane gamma table would be smaller */ @@ -260,18 +261,15 @@ _bytesPerLineColor (int pixelsPerLine) /* dummy*/ static void -_rgb2rgb (unsigned char *buffer, int pixels, int threshold) +_rgb2rgb (unsigned char __sane_unused__ *buffer, int __sane_unused__ pixels, int __sane_unused__ threshold) { /* make the compiler content */ - buffer = buffer; - pixels = pixels; - threshold = threshold; } /* convert 24bit RGB to 8bit GRAY */ static void -_rgb2gray (unsigned char *buffer, int pixels, int threshold) +_rgb2gray (unsigned char *buffer, int pixels, int __sane_unused__ threshold) { #define WEIGHT_R 27 #define WEIGHT_G 54 @@ -283,9 +281,6 @@ _rgb2gray (unsigned char *buffer, int pixels, int threshold) int acc = 0; int x; - /* make the compiler content */ - threshold = threshold; - for (x = 0; x < nbyte; ++x) { acc += aWeight[x % BYTES_PER_PIXEL_COLOR] * buffer[x]; @@ -685,6 +680,7 @@ _InitOptions (TScanner * s) pDesc->size = 0; break; +#ifdef EXPERIMENTAL case optGamma: pDesc->name = SANE_NAME_ANALOG_GAMMA; pDesc->title = SANE_TITLE_ANALOG_GAMMA; @@ -695,6 +691,7 @@ _InitOptions (TScanner * s) pDesc->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT; pVal->w = startUpGamma; break; +#endif case optGammaTable: pDesc->name = SANE_NAME_GAMMA_VECTOR; @@ -707,6 +704,7 @@ _InitOptions (TScanner * s) pVal->wa = s->aGammaTable; break; +#ifdef EXPERIMENTAL case optGroupMisc: pDesc->title = SANE_I18N ("Miscellaneous"); pDesc->type = SANE_TYPE_GROUP; @@ -731,7 +729,7 @@ _InitOptions (TScanner * s) pDesc->cap = SANE_CAP_SOFT_SELECT; pDesc->size = 0; break; - +#endif case optGroupMode: pDesc->title = SANE_I18N ("Scan Mode"); pDesc->desc = ""; @@ -824,11 +822,8 @@ _ReportDevice (TScannerModel * pModel, const char *pszDeviceName) /*****************************************************************************/ SANE_Status -sane_init (SANE_Int * piVersion, SANE_Auth_Callback pfnAuth) +sane_init (SANE_Int * piVersion, SANE_Auth_Callback __sane_unused__ pfnAuth) { - /* prevent compiler from complaing about unused parameters */ - pfnAuth = pfnAuth; - DBG_INIT (); DBG (DBG_MSG, "sane_init\n"); @@ -869,15 +864,13 @@ sane_exit (void) SANE_Status -sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only) +sane_get_devices (const SANE_Device *** device_list, SANE_Bool __sane_unused__ local_only) { TDevListEntry *pDev; int i; DBG (DBG_MSG, "sane_get_devices\n"); - local_only = local_only; - if (_pSaneDevList) { free (_pSaneDevList); @@ -984,17 +977,32 @@ sane_control_option (SANE_Handle h, SANE_Int n, SANE_Action Action, void *pVal, SANE_Int * pInfo) { TScanner *s; - SANE_Bool fVal; static char szTable[100]; int *pi; int i; SANE_Int info; - SANE_Bool fLampIsOn; SANE_Status status; +#ifdef EXPERIMENTAL + SANE_Bool fLampIsOn; + SANE_Bool fVal; SANE_Bool fSame; +#endif DBG (DBG_MSG, "sane_control_option: option %d, action %d\n", n, Action); + if ((n < optCount) || (n >= optLast)) + { + return SANE_STATUS_UNSUPPORTED; + } + + if (Action == SANE_ACTION_GET_VALUE || Action == SANE_ACTION_SET_VALUE) + { + if (pVal == NULL) + { + return SANE_STATUS_INVAL; + } + } + s = (TScanner *) h; info = 0; @@ -1007,7 +1015,9 @@ sane_control_option (SANE_Handle h, SANE_Int n, SANE_Action Action, /* Get options of type SANE_Word */ case optCount: case optDPI: +#ifdef EXPERIMENTAL case optGamma: +#endif case optTLX: case optTLY: case optBRX: @@ -1031,6 +1041,7 @@ sane_control_option (SANE_Handle h, SANE_Int n, SANE_Action Action, strcpy ((char *) pVal, modeList[s->aValues[optMode].w]); break; +#ifdef EXPERIMENTAL /* Get options of type SANE_Bool */ case optLamp: GetLamp (&s->HWParams, &fLampIsOn); @@ -1041,6 +1052,7 @@ sane_control_option (SANE_Handle h, SANE_Int n, SANE_Action Action, /* although this option has nothing to read, it's added here to avoid a warning when running scanimage --help */ break; +#endif default: DBG (DBG_MSG, "SANE_ACTION_GET_VALUE: Invalid option (%d)\n", n); @@ -1061,7 +1073,9 @@ sane_control_option (SANE_Handle h, SANE_Int n, SANE_Action Action, case optCount: return SANE_STATUS_INVAL; +#ifdef EXPERIMENTAL case optGamma: +#endif case optThreshold: case optDPI: @@ -1081,14 +1095,17 @@ sane_control_option (SANE_Handle h, SANE_Int n, SANE_Action Action, return status; } +#ifdef EXPERIMENTAL /* check values if they are equal */ fSame = s->aValues[n].w == *(SANE_Word *) pVal; +#endif /* set the values */ s->aValues[n].w = *(SANE_Word *) pVal; DBG (DBG_MSG, "sane_control_option: SANE_ACTION_SET_VALUE %d = %d\n", n, (int) s->aValues[n].w); +#ifdef EXPERIMENTAL if (n == optGamma) { if (!fSame && optLast > optGammaTable) @@ -1097,6 +1114,7 @@ sane_control_option (SANE_Handle h, SANE_Int n, SANE_Action Action, } _SetScalarGamma (s->aGammaTable, s->aValues[n].w); } +#endif break; case optGammaTable: @@ -1159,6 +1177,7 @@ sane_control_option (SANE_Handle h, SANE_Int n, SANE_Action Action, +#ifdef EXPERIMENTAL case optLamp: fVal = *(SANE_Bool *) pVal; DBG (DBG_MSG, "lamp %s\n", fVal ? "on" : "off"); @@ -1171,6 +1190,7 @@ sane_control_option (SANE_Handle h, SANE_Int n, SANE_Action Action, case optCalibrate: /* SimpleCalib(&s->HWParams); */ break; +#endif default: DBG (DBG_ERR, "SANE_ACTION_SET_VALUE: Invalid option (%d)\n", n); @@ -1458,13 +1478,10 @@ sane_cancel (SANE_Handle h) SANE_Status -sane_set_io_mode (SANE_Handle h, SANE_Bool m) +sane_set_io_mode (SANE_Handle __sane_unused__ h, SANE_Bool m) { DBG (DBG_MSG, "sane_set_io_mode %s\n", m ? "non-blocking" : "blocking"); - /* prevent compiler from complaining about unused parameters */ - h = h; - if (m) { return SANE_STATUS_UNSUPPORTED; @@ -1474,13 +1491,8 @@ sane_set_io_mode (SANE_Handle h, SANE_Bool m) SANE_Status -sane_get_select_fd (SANE_Handle h, SANE_Int * fd) +sane_get_select_fd (SANE_Handle __sane_unused__ h, SANE_Int * __sane_unused__ fd) { DBG (DBG_MSG, "sane_select_fd\n"); - - /* prevent compiler from complaining about unused parameters */ - h = h; - fd = fd; - return SANE_STATUS_UNSUPPORTED; } diff --git a/backend/pieusb.c b/backend/pieusb.c new file mode 100644 index 0000000..4b07304 --- /dev/null +++ b/backend/pieusb.c @@ -0,0 +1,1422 @@ +/* sane - Scanner Access Now Easy. + + pieusb.c + + Copyright (C) 2012-2015 Jan Vleeshouwers, Michael Rickmann, Klaus Kaempf + + This file is part of the SANE package. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA. + + As a special exception, the authors of SANE give permission for + additional uses of the libraries contained in this release of SANE. + + The exception is that, if you link a SANE library with other files + to produce an executable, this does not by itself cause the + resulting executable to be covered by the GNU General Public + License. Your use of that executable is in no way restricted on + account of linking the SANE library code into it. + + This exception does not, however, invalidate any other reasons why + the executable file might be covered by the GNU General Public + License. + + If you submit changes to SANE to the maintainers to be included in + a subsequent release, you agree by submitting the changes that + those changes may be distributed with this exception intact. + + If you write modifications of your own for SANE, it is your choice + whether to permit this exception to apply to your modifications. + If you do not wish that, delete this exception notice. */ + +/* ========================================================================= + * + * SANE interface to three Reflecta USB scanners with USB-id 0x05e3/0x0145: + * - Reflecta CrystalScan 7200 (model id 0x30) + * - Reflecta ProScan 7200 (model id 0x36) + * - Reflecta 6000 Multiple Slide Scanner (model id 0x3A) + * + * ========================================================================= */ + +#define DEBUG_NOT_STATIC +/* -------------------------------------------------------------------------- + * + * INCLUDES + * + * --------------------------------------------------------------------------*/ + +#include "../include/sane/config.h" +/* Standard includes for various utiliy functions */ +#include <stdio.h> /* for FILE */ +#include <string.h> /* for strlen */ +#include <stdlib.h> /* for NULL */ +#include <stdint.h> +#include <math.h> + +/* Configuration defines */ +#include "../include/sane/config.h" + +/* SANE includes */ +#include "../include/sane/sane.h" +#include "../include/sane/saneopts.h" +#include "../include/sane/sanei_usb.h" +#include "../include/sane/sanei_config.h" + +/* Backend includes */ +#define BACKEND_NAME pieusb +#include "../include/sane/sanei_backend.h" +#include "pieusb.h" +#include "pieusb_specific.h" + +#define CAN_DO_4_CHANNEL_TIFF + +#ifdef CAN_DO_4_CHANNEL_TIFF +extern void write_tiff_rgbi_header (FILE *fptr, int width, int height, int depth, int resolution, const char *icc_profile); +#endif + +/* -------------------------------------------------------------------------- + * + * DEFINES + * + * --------------------------------------------------------------------------*/ + +/* Build number of this backend */ +#define BUILD 1 + +/* Configuration filename */ +#define PIEUSB_CONFIG_FILE "pieusb.conf" + +/* Debug error levels */ +#define DBG_error 1 /* errors */ +#define DBG_warning 3 /* warnings */ +#define DBG_info 5 /* information */ +#define DBG_info_sane 7 /* information sane interface level */ +#define DBG_inquiry 8 /* inquiry data */ +#define DBG_info_proc 9 /* information pieusb backend functions */ +#define DBG_info_scan 11 /* information scanner commands */ +#define DBG_info_usb 13 /* information usb level functions */ + +/* -------------------------------------------------------------------------- + * + * SUPPORTED DEVICES SPECIFICS + * + * --------------------------------------------------------------------------*/ + +struct Pieusb_USB_Device_Entry* pieusb_supported_usb_device_list = NULL; +struct Pieusb_USB_Device_Entry pieusb_supported_usb_device; /* for searching */ + +/* -------------------------------------------------------------------------- + * + * LISTS OF ACTIVE DEVICE DEFINITIONS AND SCANNERS + * + * --------------------------------------------------------------------------*/ + +Pieusb_Device_Definition *pieusb_definition_list_head = NULL; +static Pieusb_Scanner *first_handle = NULL; +static const SANE_Device **devlist = NULL; + +/* -------------------------------------------------------------------------- + * + * SANE INTERFACE + * + * --------------------------------------------------------------------------*/ + +/** + * Initializes the debugging system, the USB system, the version code and + * 'attaches' available scanners, i.e. creates device definitions for all + * scanner devices found. + * + * @param version_code + * @param authorize + * @return SANE_STATUS_GOOD + */ +SANE_Status +sane_init (SANE_Int * version_code, SANE_Auth_Callback __sane_unused__ authorize) +{ + FILE *fp; + char config_line[PATH_MAX]; + SANE_Word vendor_id; + SANE_Word product_id; + SANE_Word model_number; + SANE_Status status; + int i; + + /* Initialize debug logging */ + DBG_INIT (); + + DBG (DBG_info_sane, "sane_init() build %d\n", BUILD); + + /* Set version code to current major, minor and build number */ + /* TODO: use V_MINOR instead or SANE_CURRENT_MINOR? If so, why? */ + if (version_code) + *version_code = SANE_VERSION_CODE (SANE_CURRENT_MAJOR, SANE_CURRENT_MINOR, BUILD); + + /* Initialize usb */ + sanei_usb_init (); + sanei_usb_set_timeout (30 * 1000); /* 30 sec timeout */ + + /* There are currently 3 scanners hardcoded into this backend, see below. + * The config file may add other scanners using a line like + * usb 0x1234 0x5678 0x9A + * where the first two hex numbers are vendor and product id, and the last + * number is the model number. Unfortunately, this is not according to the + * config file standard. Anyone any suggestions? */ + + /* Create default list */ + pieusb_supported_usb_device_list = calloc (4, sizeof(struct Pieusb_USB_Device_Entry)); + if (pieusb_supported_usb_device_list == NULL) + return SANE_STATUS_NO_MEM; + /* Reflecta CrystalScan 7200, model number 0x30 */ + pieusb_supported_usb_device_list[0].vendor = 0x05e3; + pieusb_supported_usb_device_list[0].product = 0x0145; + pieusb_supported_usb_device_list[0].model = 0x30; + /* Reflecta ProScan 7200, model number 0x36 */ + pieusb_supported_usb_device_list[1].vendor = 0x05e3; + pieusb_supported_usb_device_list[1].product = 0x0145; + pieusb_supported_usb_device_list[1].model = 0x36; + /* Reflecta 6000 Multiple Slide Scanner */ + pieusb_supported_usb_device_list[2].vendor = 0x05e3; + pieusb_supported_usb_device_list[2].product = 0x0142; + pieusb_supported_usb_device_list[2].model = 0x3a; + /* end of list */ + pieusb_supported_usb_device_list[3].vendor = 0; + pieusb_supported_usb_device_list[3].product = 0; + pieusb_supported_usb_device_list[3].model = 0; + + /* Add entries from config file */ + fp = sanei_config_open (PIEUSB_CONFIG_FILE); + if (!fp) { + DBG (DBG_info_sane, "sane_init() did not find a config file, using default list of supported devices\n"); + } else { + while (sanei_config_read (config_line, sizeof (config_line), fp)) { + /* Ignore line comments and empty lines */ + if (config_line[0] == '#') continue; + if (strlen (config_line) == 0) continue; + /* Ignore lines which do not begin with 'usb ' */ + if (strncmp (config_line, "usb ", 4) != 0) continue; + /* Parse vendor-id, product-id and model number and add to list */ + DBG (DBG_info_sane, "sane_init() config file parsing %s\n", config_line); + status = sanei_pieusb_parse_config_line(config_line, &vendor_id, &product_id, &model_number); + if (status == SANE_STATUS_GOOD) { + DBG (DBG_info_sane, "sane_init() config file lists device %04x %04x %02x\n",vendor_id, product_id, model_number); + if (!sanei_pieusb_supported_device_list_contains(vendor_id, product_id, model_number)) { + DBG (DBG_info_sane, "sane_init() adding device %04x %04x %02x\n",vendor_id, product_id, model_number); + sanei_pieusb_supported_device_list_add(vendor_id, product_id, model_number); + } else { + DBG (DBG_info_sane, "sane_init() list already contains %04x %04x %02x\n", vendor_id, product_id, model_number); + } + } else { + DBG (DBG_info_sane, "sane_init() config file parsing %s: error\n", config_line); + } + } + fclose (fp); + } + + /* Loop through supported device list */ + i = 0; + while (pieusb_supported_usb_device_list[i].vendor != 0) { + /* Check if the supported device is present. If so, create a device + * definition structure for it. + * The variable pieusb_supported_usb_device is set to current values, + * which are used in the callback. */ + pieusb_supported_usb_device.vendor = pieusb_supported_usb_device_list[i].vendor; + pieusb_supported_usb_device.product = pieusb_supported_usb_device_list[i].product; + pieusb_supported_usb_device.model = pieusb_supported_usb_device_list[i].model; + pieusb_supported_usb_device.device_number = -1; /* No device number (yet) */ + DBG( DBG_info_sane, "sane_init() looking for Reflecta scanner %04x %04x model %02x\n", pieusb_supported_usb_device.vendor, pieusb_supported_usb_device.product, pieusb_supported_usb_device.model); + sanei_usb_find_devices (pieusb_supported_usb_device.vendor, pieusb_supported_usb_device.product, sanei_pieusb_find_device_callback); + i++; + } + return SANE_STATUS_GOOD; +} + +/** + * Backend exit. + * Clean up allocated memory. + */ +void +sane_exit (void) +{ + Pieusb_Device_Definition *dev, *next; + + DBG (DBG_info_sane, "sane_exit()\n"); + + for (dev = pieusb_definition_list_head; dev; dev = next) { + next = dev->next; + free((void *)dev->sane.name); + free((void *)dev->sane.vendor); + free((void *)dev->sane.model); + free (dev->version); + free (dev); + } + pieusb_definition_list_head = NULL; + + if (devlist) { + free (devlist); + devlist = NULL; + } +} + +/** + * Create a SANE device list from the device list generated by sane_init(). + * + * @param device_list List of SANE_Device elements + * @param local_only If true, disregard network scanners. Not applicable for USB scanners. + * @return SANE_STATUS_GOOD, or SANE_STATUS_NO_MEM if the list cannot be allocated + */ +SANE_Status +sane_get_devices (const SANE_Device *** device_list, SANE_Bool __sane_unused__ local_only) +{ + Pieusb_Device_Definition *dev; + int i; + + DBG (DBG_info_sane, "sane_get_devices\n"); + + /* Create SANE_DEVICE list from device list created in sane_init() */ + i = 0; + for (dev = pieusb_definition_list_head; dev; dev = dev->next) { + i++; + } + if (devlist) { + free (devlist); + } + devlist = malloc ((i + 1) * sizeof (devlist[0])); + if (!devlist) { + return SANE_STATUS_NO_MEM; + } + i = 0; + for (dev = pieusb_definition_list_head; dev; dev = dev->next) { + devlist[i++] = &dev->sane; + } + devlist[i] = NULL; + *device_list = devlist; + return SANE_STATUS_GOOD; +} + +/** + * Open the scanner with the given devicename and return a handle to it, which + * is a pointer to a Pieusb_Scanner struct. The handle will be an input to + * a couple of other functions of the SANE interface. + * + * @param devicename Name of the device, corresponds to SANE_Device.name + * @param handle handle to scanner (pointer to a Pieusb_Scanner struct) + * @return SANE_STATUS_GOOD if the device has been opened + */ +SANE_Status +sane_open (SANE_String_Const devicename, SANE_Handle * handle) +{ + Pieusb_Device_Definition *dev; + SANE_Status status; + Pieusb_Scanner *scanner, *s; + + DBG (DBG_info_sane, "sane_open(%s)\n", devicename); + + /* Search for devicename */ + if (devicename[0]) { + for (dev = pieusb_definition_list_head; dev; dev = dev->next) { + if (strcmp (dev->sane.name, devicename) == 0) { + break; + } + } + if (!dev) { + /* Is it a valid USB device? */ + SANE_Word vendor; + SANE_Word product; + int i = 0; + + status = sanei_usb_get_vendor_product_byname (devicename, &vendor, &product); + if (status != SANE_STATUS_GOOD) { + DBG (DBG_error, "sane_open: sanei_usb_get_vendor_product_byname failed %s\n", devicename); + return status; + } + /* Get vendor-product-model & verify that is is supported */ + /* Loop through supported device list */ + while (pieusb_supported_usb_device_list[i].vendor != 0) { + /* Check if vendor and product match */ + if (pieusb_supported_usb_device_list[i].vendor == vendor + && pieusb_supported_usb_device_list[i].product == product) { + /* Check if a supported device is present + * If so, create a device definition structure for it. */ + /* Set pieusb_supported_usb_device to current values: these are used in callback */ + pieusb_supported_usb_device.vendor = vendor; + pieusb_supported_usb_device.product = product; + pieusb_supported_usb_device.model = pieusb_supported_usb_device_list[i].model; + pieusb_supported_usb_device.device_number = -1; + sanei_usb_find_devices (vendor, product, sanei_pieusb_find_device_callback); + if (pieusb_supported_usb_device.device_number == -1) { + /* Did not succeed in opening the USB device, which is an error. + * This error is not caught by sanei_usb_find_devices(), so handle + * it here. */ + DBG (DBG_error, "sane_open: sanei_usb_find_devices did not open device %s\n", devicename); + return SANE_STATUS_INVAL; + } + } + i++; + } + /* Now rescan the device list to see if it is present */ + for (dev = pieusb_definition_list_head; dev; dev = dev->next) { + if (strcmp (dev->sane.name, devicename) == 0) { + break; + } + } + } + } else { + /* empty devicename -> use first device */ + dev = pieusb_definition_list_head; + } + /* If no device found, return error */ + if (!dev) { + return SANE_STATUS_INVAL; + } + + /* Now create a scanner structure to return */ + + /* Check if we are not opening the same scanner again. */ + for (s = first_handle; s; s = s->next) { + if (s->device->sane.name == devicename) { + *handle = s; + return SANE_STATUS_GOOD; + } + } + + /* Create a new scanner instance */ + scanner = malloc (sizeof (*scanner)); + if (!scanner) { + return SANE_STATUS_NO_MEM; + } + memset (scanner, 0, sizeof (*scanner)); + scanner->device = dev; + sanei_usb_open (dev->sane.name, &scanner->device_number); + scanner->cancel_request = 0; + scanner->shading_data_present = SANE_FALSE; + /* Options and buffers */ + (void)sanei_pieusb_init_options (scanner); + + /* wait for warmup */ + status = sanei_pieusb_wait_ready (scanner, 0); + if (status != SANE_STATUS_GOOD) { + sanei_usb_close(scanner->device_number); + free (scanner); + DBG (DBG_error, "sane_open: scanner not ready\n"); + return status; + } + + /* First time settings */ + /* ? */ + /* Insert newly opened handle into list of open handles: */ + scanner->next = first_handle; + first_handle = scanner; + + *handle = scanner; + return SANE_STATUS_GOOD; +} + +/** + * Close the scanner and remove the scanner from the list of active scanners. + * + * @param handle Scanner handle + */ +void +sane_close (SANE_Handle handle) +{ + Pieusb_Scanner *prev, *scanner; + SANE_Int k; + + DBG (DBG_info_sane, "sane_close()\n"); + + /* Find handle in list of open handles: */ + prev = 0; + for (scanner = first_handle; scanner; scanner = scanner->next) { + if (scanner == handle) { + break; + } + prev = scanner; + } + /* Not a handle we know about. This may happen since all different backend + * scanner instances are all cast to SANE_Handle (a void pointer) */ + if (!scanner) { + DBG (DBG_error, "sane_close(): invalid handle %p\n", handle); + return; + } + + /* Stop scan if still scanning */ + if (scanner->scanning) { + sanei_pieusb_on_cancel(scanner); + } + + /* USB scanners may be still open here */ + if (scanner->device_number >= 0) { + sanei_usb_reset (scanner->device_number); + sanei_usb_close (scanner->device_number); + } + /* Remove handle from list */ + if (prev) { + prev->next = scanner->next; + } else { + first_handle = scanner->next; + } + + /* Free scanner related allocated memory and the scanner itself */ + /*TODO: check if complete */ + if (scanner->buffer.data) sanei_pieusb_buffer_delete(&scanner->buffer); + free (scanner->ccd_mask); + for (k=0; k<4; k++) free (scanner->shading_ref[k]); + free (scanner->val[OPT_MODE].s); + free (scanner->val[OPT_HALFTONE_PATTERN].s); + free (scanner); +} + +/** + * Get option descriptor. Return the option descriptor with the given index + * + * @param handle Scanner handle + * @param option Index of option descriptor to return + * @return The option descriptor + */ +const SANE_Option_Descriptor * +sane_get_option_descriptor (SANE_Handle handle, SANE_Int option) +{ + Pieusb_Scanner *scanner = handle; + + DBG (DBG_info_proc, "sane_get_option_descriptor() option=%d\n", option); + + if ((unsigned) option >= NUM_OPTIONS) + { + return 0; + } + + return scanner->opt + option; +} + +/** + * Set or inquire the current value of option number 'option' of the device + * represented by the given handle. + * + * @param handle Scanner handle + * @param option Index of option to set or get + * @param action Determines if the option value is read or set + * @param val Pointer to value to set or get + * @param info About set result. May be NULL. + * @return SANE_STATUS_GOOD, or SANE_STATUS_INVAL if a parameter cannot be set + */ +SANE_Status +sane_control_option (SANE_Handle handle, SANE_Int option, SANE_Action action, + void *val, SANE_Int * info) +{ + Pieusb_Scanner *scanner = handle; + SANE_Status status; + SANE_Word cap; + SANE_String_Const name; + + DBG(DBG_info_sane,"sane_control_option()\n"); + if (info) { + *info = 0; + } + + /* Don't set or get options while the scanner is busy */ + if (scanner->scanning) { + DBG(DBG_error,"Device busy scanning, no option returned\n"); + return SANE_STATUS_DEVICE_BUSY; + } + + /* Check if option index is between bounds */ + if ((unsigned) option >= NUM_OPTIONS) { + DBG(DBG_error,"Index too large, no option returned\n"); + return SANE_STATUS_INVAL; + } + + /* Check if option is switched on */ + cap = scanner->opt[option].cap; + if (!SANE_OPTION_IS_ACTIVE (cap)) + { + DBG(DBG_error,"Option inactive (%s)\n", scanner->opt[option].name); + return SANE_STATUS_INVAL; + } + + /* Get name of option */ + name = scanner->opt[option].name; + if (!name) + { + name = "(no name)"; + } + + /* */ + switch (action) { + case SANE_ACTION_GET_VALUE: + + DBG (DBG_info_sane, "get %s [#%d]\n", name, option); + + switch (option) { + + /* word options: */ + case OPT_NUM_OPTS: + case OPT_BIT_DEPTH: + case OPT_RESOLUTION: + case OPT_TL_X: + case OPT_TL_Y: + case OPT_BR_X: + case OPT_BR_Y: + case OPT_THRESHOLD: + case OPT_SHARPEN: + case OPT_SHADING_ANALYSIS: + case OPT_FAST_INFRARED: + case OPT_ADVANCE_SLIDE: + case OPT_CORRECT_SHADING: + case OPT_CORRECT_INFRARED: + case OPT_CLEAN_IMAGE: + case OPT_SMOOTH_IMAGE: + case OPT_TRANSFORM_TO_SRGB: + case OPT_INVERT_IMAGE: + case OPT_PREVIEW: + case OPT_SAVE_SHADINGDATA: + case OPT_SAVE_CCDMASK: + case OPT_LIGHT: + case OPT_DOUBLE_TIMES: + case OPT_SET_EXPOSURE_R: + case OPT_SET_EXPOSURE_G: + case OPT_SET_EXPOSURE_B: + case OPT_SET_EXPOSURE_I: + case OPT_SET_GAIN_R: + case OPT_SET_GAIN_G: + case OPT_SET_GAIN_B: + case OPT_SET_GAIN_I: + case OPT_SET_OFFSET_R: + case OPT_SET_OFFSET_G: + case OPT_SET_OFFSET_B: + case OPT_SET_OFFSET_I: + *(SANE_Word *) val = scanner->val[option].w; + DBG (DBG_info_sane, "get %s [#%d] val=%d\n", name, option,scanner->val[option].w); + return SANE_STATUS_GOOD; + + /* word-array options: => for exposure gain offset? */ + case OPT_CROP_IMAGE: + memcpy (val, scanner->val[option].wa, scanner->opt[option].size); + return SANE_STATUS_GOOD; + + /* string options */ + case OPT_MODE: + case OPT_CALIBRATION_MODE: + case OPT_GAIN_ADJUST: + case OPT_HALFTONE_PATTERN: + strcpy (val, scanner->val[option].s); + DBG (DBG_info_sane, "get %s [#%d] val=%s\n", name, option,scanner->val[option].s); + return SANE_STATUS_GOOD; + } + break; + + case SANE_ACTION_SET_VALUE: + + switch (scanner->opt[option].type) { + case SANE_TYPE_INT: + DBG (DBG_info_sane, "set %s [#%d] to %d, size=%d\n", name, option, *(SANE_Word *) val, scanner->opt[option].size); + break; + case SANE_TYPE_FIXED: + DBG (DBG_info_sane, "set %s [#%d] to %f\n", name, option, SANE_UNFIX (*(SANE_Word *) val)); + break; + case SANE_TYPE_STRING: + DBG (DBG_info_sane, "set %s [#%d] to %s\n", name, option, (char *) val); + break; + case SANE_TYPE_BOOL: + DBG (DBG_info_sane, "set %s [#%d] to %d\n", name, option, *(SANE_Word *) val); + break; + default: + DBG (DBG_info_sane, "set %s [#%d]\n", name, option); + } + /* Check if option can be set */ + if (!SANE_OPTION_IS_SETTABLE (cap)) { + return SANE_STATUS_INVAL; + } + /* Check if new value within bounds */ + status = sanei_constrain_value (scanner->opt + option, val, info); + if (status != SANE_STATUS_GOOD) { + return status; + } + /* Set option and handle info return */ + switch (option) + { + /* (mostly) side-effect-free word options: */ + case OPT_BIT_DEPTH: + case OPT_RESOLUTION: + case OPT_TL_X: + case OPT_TL_Y: + case OPT_BR_X: + case OPT_BR_Y: + case OPT_SHARPEN: + case OPT_SHADING_ANALYSIS: + case OPT_FAST_INFRARED: + if (info) { + *info |= SANE_INFO_RELOAD_PARAMS; + } + /* fall through */ + case OPT_NUM_OPTS: + case OPT_PREVIEW: + case OPT_ADVANCE_SLIDE: + case OPT_CORRECT_SHADING: + case OPT_CORRECT_INFRARED: + case OPT_CLEAN_IMAGE: + case OPT_SMOOTH_IMAGE: + case OPT_TRANSFORM_TO_SRGB: + case OPT_INVERT_IMAGE: + case OPT_SAVE_SHADINGDATA: + case OPT_SAVE_CCDMASK: + case OPT_THRESHOLD: + case OPT_LIGHT: + case OPT_DOUBLE_TIMES: + case OPT_SET_GAIN_R: + case OPT_SET_GAIN_G: + case OPT_SET_GAIN_B: + case OPT_SET_GAIN_I: + case OPT_SET_OFFSET_R: + case OPT_SET_OFFSET_G: + case OPT_SET_OFFSET_B: + case OPT_SET_OFFSET_I: + case OPT_SET_EXPOSURE_R: + case OPT_SET_EXPOSURE_G: + case OPT_SET_EXPOSURE_B: + case OPT_SET_EXPOSURE_I: + scanner->val[option].w = *(SANE_Word *) val; + break; + + /* side-effect-free word-array options: */ + case OPT_CROP_IMAGE: + memcpy (scanner->val[option].wa, val, scanner->opt[option].size); + break; + + /* options with side-effects: */ + case OPT_MODE: + { + /* Free current setting */ + if (scanner->val[option].s) { + free (scanner->val[option].s); + } + /* New setting */ + scanner->val[option].s = (SANE_Char *) strdup (val); + /* Info */ + if (info) { + *info |= SANE_INFO_RELOAD_OPTIONS | SANE_INFO_RELOAD_PARAMS; + } + break; + } + + case OPT_CALIBRATION_MODE: + case OPT_GAIN_ADJUST: + case OPT_HALFTONE_PATTERN: + { + /* Free current setting */ + if (scanner->val[option].s) { + free (scanner->val[option].s); + } + /* New setting */ + scanner->val[option].s = (SANE_Char *) strdup (val); + break; + } + + } + + /* Check the whole set */ + if (sanei_pieusb_analyse_options(scanner)) { + return SANE_STATUS_GOOD; + } else { + return SANE_STATUS_INVAL; + } + + break; + default: + return SANE_STATUS_INVAL; + break; + } + return SANE_STATUS_INVAL; +} + +/** + * Obtain the current scan parameters. The returned parameters are guaranteed + * to be accurate between the time a scan has been started (sane start() has + * been called) and the completion of that request. Outside of that window, the + * returned values are best-effort estimates of what the parameters will be when + * sane start() gets invoked. - says the SANE standard. + * + * @param handle Scanner handle + * @param params Scan parameters + * @return SANE_STATUS_GOOD + */ +SANE_Status +sane_get_parameters (SANE_Handle handle, SANE_Parameters * params) +{ + Pieusb_Scanner *scanner = handle; + const char *mode; + double resolution, width, height; + SANE_Int colors; + + DBG (DBG_info_sane, "sane_get_parameters\n"); + + if (params) { + + if (scanner->scanning) { + /* sane_start() initialized a SANE_Parameters struct in the scanner */ + DBG (DBG_info_sane, "sane_get_parameters from scanner values\n"); + params->bytes_per_line = scanner->scan_parameters.bytes_per_line; + params->depth = scanner->scan_parameters.depth; + params->format = scanner->scan_parameters.format; + params->last_frame = scanner->scan_parameters.last_frame; + params->lines = scanner->scan_parameters.lines; + params->pixels_per_line = scanner->scan_parameters.pixels_per_line; + } else { + /* Calculate appropriate values from option settings */ + DBG (DBG_info_sane, "sane_get_parameters from option values\n"); + if (scanner->val[OPT_PREVIEW].b) { + resolution = scanner->device->fast_preview_resolution; + } else { + resolution = SANE_UNFIX(scanner->val[OPT_RESOLUTION].w); + } + DBG (DBG_info_sane, " resolution %f\n", resolution); + width = SANE_UNFIX(scanner->val[OPT_BR_X].w)-SANE_UNFIX(scanner->val[OPT_TL_X].w); + height = SANE_UNFIX(scanner->val[OPT_BR_Y].w)-SANE_UNFIX(scanner->val[OPT_TL_Y].w); + DBG (DBG_info_sane, " width x height: %f x %f\n", width, height); + params->lines = height / MM_PER_INCH * resolution; + params->pixels_per_line = width / MM_PER_INCH * resolution; + mode = scanner->val[OPT_MODE].s; + if (strcmp(mode, SANE_VALUE_SCAN_MODE_LINEART) == 0) { + params->format = SANE_FRAME_GRAY; + params->depth = 1; + colors = 1; + } else if(strcmp(mode, SANE_VALUE_SCAN_MODE_HALFTONE) == 0) { + params->format = SANE_FRAME_GRAY; + params->depth = 1; + colors = 1; + } else if(strcmp(mode, SANE_VALUE_SCAN_MODE_GRAY) == 0) { + params->format = SANE_FRAME_GRAY; + params->depth = scanner->val[OPT_BIT_DEPTH].w; + colors = 1; + } else if(strcmp(mode, SANE_VALUE_SCAN_MODE_RGBI) == 0) { + params->format = SANE_FRAME_RGB; /* was: SANE_FRAME_RGBI */ + params->depth = scanner->val[OPT_BIT_DEPTH].w; + colors = 4; + } else { /* SANE_VALUE_SCAN_MODE_COLOR */ + params->format = SANE_FRAME_RGB; + params->depth = scanner->val[OPT_BIT_DEPTH].w; + colors = 3; + } + DBG (DBG_info_sane, " colors: %d\n", colors); + if (params->depth == 1) { + params->bytes_per_line = colors * (params->pixels_per_line + 7)/8; + } else if (params->depth <= 8) { + params->bytes_per_line = colors * params->pixels_per_line; + } else if (params->depth <= 16) { + params->bytes_per_line = 2 * colors * params->pixels_per_line; + } + params->last_frame = SANE_TRUE; + } + + DBG(DBG_info_sane,"sane_get_parameters(): SANE parameters\n"); + DBG(DBG_info_sane," format = %d\n",params->format); + DBG(DBG_info_sane," last_frame = %d\n",params->last_frame); + DBG(DBG_info_sane," bytes_per_line = %d\n",params->bytes_per_line); + DBG(DBG_info_sane," pixels_per_line = %d\n",params->pixels_per_line); + DBG(DBG_info_sane," lines = %d\n",params->lines); + DBG(DBG_info_sane," depth = %d\n",params->depth); + + } else { + + DBG(DBG_info_sane," no params argument, no values returned\n"); + + } + + return SANE_STATUS_GOOD; +} + +/** + * Initiates aquisition of an image from the scanner. + * SCAN Phase 1: initialization and calibration + * (SCAN Phase 2: line-by-line scan & read is not implemented) + * SCAN Phase 3: get CCD-mask + * SCAN phase 4: scan slide and save data in scanner buffer + + * @param handle Scanner handle + * @return + */ +SANE_Status +sane_start (SANE_Handle handle) +{ + struct Pieusb_Scanner *scanner = handle; + struct Pieusb_Command_Status status; + SANE_Byte colors; + const char *mode; + SANE_Bool shading_correction_relevant; + SANE_Bool infrared_post_processing_relevant; + SANE_Status st; + SANE_Int bytes_per_line; + + SANE_Int shading_width; + SANE_Int shading_idx; + + struct Pieusb_Exposure_Time exptime = { + 0x93, /* code 0x93 */ + 3 * 2 * sizeof(SANE_Int), /* number of bytes in rest of structure */ + { { 0x02, 100 }, { 0x04, 100 }, { 0x08, 100 } } + }; + + struct Pieusb_Highlight_Shadow shadow = { + 0x94, /* code 0x94 */ + 3 * 2 * sizeof(SANE_Int), /* number of bytes in rest of structure */ + { { 0x02, 100 }, { 0x04, 100 }, { 0x08, 100 } } + }; + + DBG (DBG_info_sane, "sane_start()\n"); + + /* ---------------------------------------------------------------------- + * + * Exit if currently scanning + * + * ---------------------------------------------------------------------- */ + if (scanner->scanning) { + DBG (DBG_error, "sane_start(): scanner is already scanning, exiting\n"); + return SANE_STATUS_DEVICE_BUSY; + } + + /* ---------------------------------------------------------------------- + * + * Exit with pause if not warmed up + * + * ---------------------------------------------------------------------- */ + + sanei_pieusb_cmd_read_state (scanner->device_number, &(scanner->state), &status); + if (status.pieusb_status != PIEUSB_STATUS_GOOD) { + if (status.pieusb_status == PIEUSB_STATUS_DEVICE_BUSY) + return SANE_STATUS_DEVICE_BUSY; /* was: SANE_STATUS_WARMING_UP */ + DBG (DBG_error, "sane_start(): warmed up check returns status: %s\n", sane_strstatus (sanei_pieusb_convert_status(status.pieusb_status))); + return SANE_STATUS_IO_ERROR; + } + if (scanner->state.warmingUp) { + DBG (DBG_error, "sane_start(): warming up, exiting\n"); + /* Seen SANE_STATUS_WARMING_UP in scanimage => enabled */ + sleep (10); /* scanimage does not pause, so do it here */ + return SANE_STATUS_DEVICE_BUSY; /* was: SANE_STATUS_WARMING_UP */ + } + + /* ---------------------------------------------------------------------- + * set exposure time + * ---------------------------------------------------------------------- */ + + sanei_pieusb_cmd_set_exposure_time (scanner->device_number, &exptime, &status); + if (status.pieusb_status != PIEUSB_STATUS_GOOD) { + DBG (DBG_error, "sane_start(): sanei_pieusb_cmd_set_exposure_time failed: %d\n", status.pieusb_status); + return SANE_STATUS_IO_ERROR; + } + + /* ---------------------------------------------------------------------- + * set highlight shadow + * ---------------------------------------------------------------------- */ + + sanei_pieusb_cmd_set_highlight_shadow (scanner->device_number, &shadow, &status); + if (status.pieusb_status != PIEUSB_STATUS_GOOD) { + DBG (DBG_error, "sane_start(): sanei_pieusb_cmd_set_highlight_shadow failed: %d\n", status.pieusb_status); + return SANE_STATUS_IO_ERROR; + } + + /* ---------------------------------------------------------------------- + * get calibration info + * ---------------------------------------------------------------------- */ + + sanei_pieusb_cmd_get_shading_parms (scanner->device_number, scanner->device->shading_parameters, &status); + if (status.pieusb_status != PIEUSB_STATUS_GOOD) { + DBG (DBG_error, "sane_scan: sanei_pieusb_cmd_get_shading_parms failed: %d\n", status.pieusb_status); + return SANE_STATUS_INVAL; + } + shading_width = scanner->device->shading_parameters[0].pixelsPerLine; + DBG (DBG_info, "shading_width %d\n", shading_width); + for (shading_idx = 0; shading_idx < SHADING_PARAMETERS_INFO_COUNT; shading_idx++) { + scanner->shading_ref[shading_idx] = + realloc(scanner->shading_ref[shading_idx], 2 * shading_width * sizeof(SANE_Int)); + if (scanner->shading_ref[shading_idx] == NULL) { + return SANE_STATUS_NO_MEM; + } + } + scanner->ccd_mask = realloc (scanner->ccd_mask, shading_width); + scanner->ccd_mask_size = shading_width; + if (scanner->ccd_mask == NULL) { + return SANE_STATUS_NO_MEM; + } + + /* ---------------------------------------------------------------------- + * + * Standard run does; + * - set exposure time 0x0A/0x13 + * - set highlight shadow 0x0A/0x14 + * - read shading parameters 0x0A/0x95/0x08 + * - set scan frame 0x0A/0x12 + * "12 00 0a00 80 00 0300 0000 b829 e31a" + * => 0:12 1:0 2:10 4:80 5:0 6:3 8:0 10:10680 12:6883 + * - read gain offset 0xD7 + * - set gain offset 0xDC + * - set mode 0x15 + * "00 0f 2c01 80 04 04 00 01 0a 00 00 00 80 10 00" + * size res pass dpt frm ord bitmap ptn thr + * 15 300 RGB 8 inx intel 1=sharpen 0 128 + * 3=skipshad + * + * ---------------------------------------------------------------------- */ + + /* ---------------------------------------------------------------------- + * + * Show and check options + * + * ---------------------------------------------------------------------- */ + sanei_pieusb_print_options (scanner); + if (!sanei_pieusb_analyse_options (scanner)) { + return SANE_STATUS_IO_ERROR; + } + + /* ---------------------------------------------------------------------- + * + * Set scan frame + * + * ---------------------------------------------------------------------- */ + if (sanei_pieusb_set_frame_from_options (scanner) != SANE_STATUS_GOOD) { + return SANE_STATUS_IO_ERROR; + } + + /* ---------------------------------------------------------------------- + * + * Function 17 + * + * ---------------------------------------------------------------------- */ + + sanei_pieusb_cmd_17 (scanner->device_number, 1, &status); + if (status.pieusb_status != PIEUSB_STATUS_GOOD) { + DBG (DBG_error, "sane_start(): sanei_pieusb_cmd_17 failed: %d\n", status.pieusb_status); + return SANE_STATUS_IO_ERROR; + } + st = sanei_pieusb_wait_ready (scanner, 0); + if (st != SANE_STATUS_GOOD) { + DBG (DBG_error, "sane_start(): scanner not ready after sanei_pieusb_cmd_17: %d\n", st); + return st; + } + + /* ---------------------------------------------------------------------- + * + * Get & set initial gains and offsets + * + * There does not seem to be much reason to set exposure/gain/offset + * now, but it does make a large difference in speed, because it + * creates a small BADF-table. This is probably because without SET GAIN + * OFFSET, extraEntries has a random value (it is not initialised). + * + * TODO: test if this may be done just once, in sane_open(). + * + * ---------------------------------------------------------------------- */ + + if (sanei_pieusb_set_gain_offset (scanner, scanner->val[OPT_CALIBRATION_MODE].s) != SANE_STATUS_GOOD) { + return SANE_STATUS_IO_ERROR; + } + + st = sanei_pieusb_wait_ready (scanner, 0); + if (st != SANE_STATUS_GOOD) { + DBG (DBG_error, "sane_start: scanner not ready %d\n", st); + return st; + } + + /* ---------------------------------------------------------------------- + * + * Set mode + * + * ---------------------------------------------------------------------- */ + if (sanei_pieusb_set_mode_from_options (scanner) != SANE_STATUS_GOOD) { + return SANE_STATUS_IO_ERROR; + } + + /* ---------------------------------------------------------------------- + * + * Lamp on + * + * ---------------------------------------------------------------------- */ + sanei_pieusb_cmd_slide (scanner->device_number, SLIDE_LAMP_ON, &status); + if (status.pieusb_status != PIEUSB_STATUS_GOOD) { + DBG (DBG_error, "sane_start(): sanei_pieusb_cmd_slide failed: %d\n", status.pieusb_status); + return SANE_STATUS_IO_ERROR; + } + st = sanei_pieusb_wait_ready (scanner, 0); + if (st != SANE_STATUS_GOOD) { + DBG (DBG_error, "sane_start: scanner not ready %d\n", st); + return st; + } + + /* Enter SCAN phase 1 */ + DBG (DBG_info_sane, "sane_start(): scan phase 1\n"); + + /* ---------------------------------------------------------------------- + * + * Start scan & wait until device ready + * + * ---------------------------------------------------------------------- */ + scanner->scanning = SANE_TRUE; + scanner->cancel_request = SANE_FALSE; + for (;;) { + sanei_pieusb_cmd_start_scan (scanner->device_number, &status); + if (status.pieusb_status != PIEUSB_STATUS_WARMING_UP) + break; + sleep(5); + } + sanei_pieusb_wait_ready (scanner, 0); + if ((status.pieusb_status == PIEUSB_STATUS_MUST_CALIBRATE) + || (scanner->val[OPT_SHADING_ANALYSIS].b != 0)) { + + /* Overriding skip calibration */ + DBG (DBG_info_sane, "sane_start(): process shading data\n"); + + /* ------------------------------------------------------------------ + * + * Get and set gain and offset + * Get settings from scanner, from preview data, from options, + * or use defaults. + * + * ------------------------------------------------------------------ */ + if (sanei_pieusb_set_gain_offset (scanner, scanner->val[OPT_CALIBRATION_MODE].s) != SANE_STATUS_GOOD) { + sanei_pieusb_cmd_stop_scan (scanner->device_number, &status); + scanner->scanning = SANE_FALSE; + return SANE_STATUS_IO_ERROR; + } + /* ------------------------------------------------------------------ + * + * Obtain shading data + * Get parameters from scanner->device->shading_parameters[0] although + * it's 45 lines, scanner->ccd_mask_size pixels, 16 bit depth in all cases. + * + * ------------------------------------------------------------------ */ + if (sanei_pieusb_get_shading_data (scanner) != SANE_STATUS_GOOD) { + sanei_pieusb_cmd_stop_scan (scanner->device_number, &status); + scanner->scanning = SANE_FALSE; + return SANE_STATUS_IO_ERROR; + } + } + + /* Enter SCAN phase 2 */ + DBG (DBG_info_sane, "sane_start(): scan phase 2\n"); + + /* SCAN phase 2 (line-by-line scan) not implemented */ + + st = sanei_pieusb_wait_ready (scanner, 0); + if (st != SANE_STATUS_GOOD) { + DBG (DBG_error, "sane_start: scanner not ready %d\n", st); + return st; + } + + /* Enter SCAN phase 3 */ + + DBG (DBG_info_sane, "sane_start(): scan phase 3\n"); + + /* Handle cancel request */ + if (scanner->cancel_request) { + return sanei_pieusb_on_cancel (scanner); + } + + /* ---------------------------------------------------------------------- + * + * Get CCD mask + * + * ---------------------------------------------------------------------- */ + + if (sanei_pieusb_get_ccd_mask (scanner) != SANE_STATUS_GOOD) { + sanei_pieusb_cmd_stop_scan (scanner->device_number, &status); + scanner->scanning = SANE_FALSE; + return SANE_STATUS_IO_ERROR; + } + + /* Enter SCAN phase 4 */ + + /* ---------------------------------------------------------------------- + * + * Read scan parameters & wait until ready for reading + * + * ---------------------------------------------------------------------- */ + if (sanei_pieusb_get_parameters (scanner, &bytes_per_line) != SANE_STATUS_GOOD) { + sanei_pieusb_cmd_stop_scan (scanner->device_number, &status); + scanner->scanning = SANE_FALSE; + return SANE_STATUS_IO_ERROR; + } + + st = sanei_pieusb_wait_ready (scanner, 0); + if (st != SANE_STATUS_GOOD) { + DBG (DBG_error, "sane_start: scanner not ready %d\n", st); + return st; + } + + /* ---------------------------------------------------------------------- + * + * Prepare read buffer + * Currently this buffer is always a memory mapped buffer + * Might be faster to use RAM buffers for small images (such as preview) + * + * ---------------------------------------------------------------------- */ + colors = 0x00; + switch (scanner->mode.passes) { + case SCAN_FILTER_RED: colors = 0x01; break; + case SCAN_FILTER_GREEN: colors = 0x02; break; + case SCAN_FILTER_BLUE: colors = 0x04; break; + case SCAN_FILTER_INFRARED: colors = 0x08; break; + case SCAN_ONE_PASS_COLOR: colors = 0x07; break; + case SCAN_ONE_PASS_RGBI: colors = 0x0F; break; + } + if (scanner->buffer.data) sanei_pieusb_buffer_delete(&scanner->buffer); /* free resources from previous invocation */ + st = sanei_pieusb_buffer_create (&(scanner->buffer), scanner->scan_parameters.pixels_per_line, + scanner->scan_parameters.lines, colors, + scanner->scan_parameters.depth); + if (st != SANE_STATUS_GOOD) { + scanner->scanning = SANE_FALSE; + return st; + } + + /* ---------------------------------------------------------------------- + * + * Read all image data into the buffer + * + * ---------------------------------------------------------------------- */ + if (sanei_pieusb_get_scan_data (scanner, bytes_per_line) != SANE_STATUS_GOOD) { + scanner->scanning = SANE_FALSE; + return SANE_STATUS_IO_ERROR; + } + sleep(2); + st = sanei_pieusb_wait_ready (scanner, 0); + if (st != SANE_STATUS_GOOD) { + DBG (DBG_error, "sane_start(): scanner not ready after sanei_pieusb_get_scan_data: %d\n", st); + scanner->scanning = SANE_FALSE; + return st; + } + + /* ---------------------------------------------------------------------- + * + * Advance to next slide (except for preview) + * + * ---------------------------------------------------------------------- */ + if (scanner->val[OPT_ADVANCE_SLIDE].b && !scanner->val[OPT_PREVIEW].b) { + sanei_pieusb_cmd_slide (scanner->device_number, SLIDE_NEXT, &status); + if (status.pieusb_status != PIEUSB_STATUS_GOOD) { + DBG (DBG_error, "sane_start(): sanei_pieusb_cmd_slide failed: %d\n", status.pieusb_status); + + } + } + + /* ---------------------------------------------------------------------- + * + * Post processing: + * 1. Correct for shading + * 2. Remove R-component from IR data + * 3. Remove dust + * + * ---------------------------------------------------------------------- */ + + mode = scanner->val[OPT_MODE].s; + if (strcmp(mode, SANE_VALUE_SCAN_MODE_LINEART) == 0) { + shading_correction_relevant = SANE_FALSE; /* Shading correction irrelavant at bit depth 1 */ + infrared_post_processing_relevant = SANE_FALSE; /* No infrared, no postprocessing */ + } else if (strcmp(mode, SANE_VALUE_SCAN_MODE_HALFTONE) == 0) { + shading_correction_relevant = SANE_FALSE; /* Shading correction irrelavant at bit depth 1 */ + infrared_post_processing_relevant = SANE_FALSE; /* No infrared, no postprocessing */ + } else if (strcmp(mode, SANE_VALUE_SCAN_MODE_GRAY) == 0) { + shading_correction_relevant = SANE_TRUE; + infrared_post_processing_relevant = SANE_FALSE; /* No infrared, no postprocessing */ + } else if (scanner->val[OPT_PREVIEW].b) { + /* Catch preview here, otherwise next ifs get complicated */ + shading_correction_relevant = SANE_TRUE; + infrared_post_processing_relevant = SANE_FALSE; + } else if (strcmp(mode, SANE_VALUE_SCAN_MODE_RGBI) == 0) { + shading_correction_relevant = SANE_TRUE; + infrared_post_processing_relevant = SANE_TRUE; + } else if (strcmp(mode, SANE_VALUE_SCAN_MODE_COLOR) == 0 && scanner->val[OPT_CLEAN_IMAGE].b) { + shading_correction_relevant = SANE_TRUE; + infrared_post_processing_relevant = SANE_TRUE; + } else { /* SANE_VALUE_SCAN_MODE_COLOR */ + shading_correction_relevant = SANE_TRUE; + infrared_post_processing_relevant = SANE_TRUE; + } + if (scanner->val[OPT_CORRECT_SHADING].b && shading_correction_relevant) { + if (scanner->shading_data_present) { + sanei_pieusb_correct_shading (scanner, &scanner->buffer); + } else { + DBG(DBG_warning, "sane_start(): unable to correct for shading, no shading data available\n"); + } + } + if ((scanner->val[OPT_CORRECT_INFRARED].b || scanner->val[OPT_CLEAN_IMAGE].b) && !scanner->val[OPT_PREVIEW].b && infrared_post_processing_relevant) { + /* Create array of pointers to color planes R, G, B, I */ + SANE_Uint *planes[PLANES]; + SANE_Int N; + N = scanner->buffer.width * scanner->buffer.height; + planes[0] = scanner->buffer.data; + planes[1] = scanner->buffer.data + N; + planes[2] = scanner->buffer.data + 2 * N; + planes[3] = scanner->buffer.data + 3 * N; + sanei_ir_init (); + sanei_pieusb_post (scanner, planes, scanner->buffer.colors); + } + + /* Save preview data. Preview data only used once to set gain and offset. */ + if (scanner->val[OPT_PREVIEW].b) { + sanei_pieusb_analyze_preview(scanner); + } else { + scanner->preview_done = SANE_FALSE; + } + + /* Modify buffer in case the buffer has infrared, but no infrared should be returned */ + if (scanner->buffer.colors == PLANES && (strcmp(mode,SANE_VALUE_SCAN_MODE_COLOR) == 0 && scanner->val[OPT_CLEAN_IMAGE].b)) { + DBG(DBG_info_sane, "sane_start(): modifying buffer to ignore I\n"); + /* Base buffer parameters */ + scanner->buffer.colors = 3; + /* Derived quantities */ + scanner->buffer.image_size_bytes = scanner->buffer.colors * scanner->buffer.height * scanner->buffer.line_size_bytes; + scanner->buffer.color_index_infrared = -1; + scanner->buffer.bytes_unread = scanner->buffer.bytes_unread * 3 / 4; + scanner->buffer.bytes_written = scanner->buffer.bytes_written * 3 / 4; + } + + return SANE_STATUS_GOOD; + +} + +/** + * Read image data from the scanner buffer. + * + * @param handle + * @param buf + * @param max_len + * @param len + * @return + */ +SANE_Status +sane_read (SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, SANE_Int * len) +{ + + struct Pieusb_Scanner *scanner = handle; + SANE_Int return_size; + + DBG(DBG_info_sane, "sane_read(): requested %d bytes\n", max_len); + + /* No reading if not scanning */ + if (!scanner->scanning) { + *len = 0; + return SANE_STATUS_IO_ERROR; /* SANE standard does not allow a SANE_STATUS_INVAL return */ + } + + /* Handle cancel request */ + if (scanner->cancel_request) { + return sanei_pieusb_on_cancel(scanner); + } +#if 0 + /* Return image data, just read from scanner buffer */ + DBG(DBG_info_sane, "sane_read():\n"); + DBG(DBG_info_sane, " image size %d\n", scanner->buffer.image_size_bytes); + DBG(DBG_info_sane, " unread %d\n", scanner->buffer.bytes_unread); + DBG(DBG_info_sane, " read %d\n", scanner->buffer.bytes_read); + DBG(DBG_info_sane, " max_len %d\n", max_len); +#endif + if (scanner->buffer.bytes_read > scanner->buffer.image_size_bytes) { + /* Test if not reading past buffer boundaries */ + DBG(DBG_error, "sane_read(): reading past buffer boundaries (contains %d, read %d)\n", scanner->buffer.image_size_bytes, scanner->buffer.bytes_read); + *len = 0; + sanei_pieusb_on_cancel(scanner); + return SANE_STATUS_EOF; + } else if (scanner->buffer.bytes_read == scanner->buffer.image_size_bytes) { + /* Return EOF since all data of this frame has already been read. */ + *len = 0; + scanner->scanning = SANE_FALSE; + return SANE_STATUS_EOF; + } else if (scanner->buffer.bytes_unread >= max_len) { + /* Already enough data to return, do not read */ + DBG(DBG_info_sane, "sane_read(): buffer suffices (contains %d, requested %d)\n", scanner->buffer.bytes_unread, max_len); + return_size = max_len; + } else if (scanner->buffer.bytes_read + scanner->buffer.bytes_unread == scanner->buffer.image_size_bytes) { + /* All the remaining data is in the buffer, do not read */ + DBG(DBG_info_sane, "sane_read(): buffer suffices (contains %d, requested %d, last batch though)\n", scanner->buffer.bytes_unread, max_len); + return_size = scanner->buffer.bytes_unread; + } else { + /* Should not happen in this implementation - all data read by sane_start() */ + DBG(DBG_error, "sane_read(): shouldn't be here...\n"); + return SANE_STATUS_IO_ERROR; + } + + /* Check */ + if (return_size == 0 && scanner->buffer.bytes_read < scanner->buffer.image_size_bytes) { + DBG(DBG_error, "sane_read(): unable to service read request, %d bytes in frame, %d read\n", scanner->buffer.image_size_bytes, scanner->buffer.bytes_read); + } + + /* Return the available data: Output return_size bytes from buffer */ + sanei_pieusb_buffer_get(&scanner->buffer, buf, max_len, len); +#if 0 + DBG(DBG_info_sane, "sane_read(): currently read %.2f lines of %d\n", + (double)scanner->buffer.bytes_written/(scanner->buffer.line_size_bytes*scanner->buffer.colors), + scanner->buffer.height); + DBG(DBG_info_sane, "sane_read(): returning %d bytes (requested %d), returned %d of %d \n", + *len, max_len,scanner->buffer.bytes_read, scanner->buffer.image_size_bytes); +#endif + return SANE_STATUS_GOOD; + +} + +/** + * Request cancellation of current scanning process. + * + * @param handle Scanner handle + */ +void +sane_cancel (SANE_Handle handle) +{ + struct Pieusb_Scanner *scanner = handle; + + DBG (DBG_info_sane, "sane_cancel\n"); + + if (scanner->scanning) { + scanner->cancel_request = 1; + } +} + +/** + * Set the I/O mode of handle h. The I/O mode can be either blocking or + * non-blocking, but for USB devices, only blocking mode is supported. + * + * @param handle Scanner handle + * @param non_blocking + * @return SANE_STATUS_UNSUPPORTED; + */ +SANE_Status +sane_set_io_mode (SANE_Handle handle, SANE_Bool non_blocking) +{ + /* Pieusb_Scanner *scanner = handle; */ + + DBG (DBG_info_sane, "sane_set_io_mode: handle = %p, non_blocking = %s\n", handle, non_blocking == SANE_TRUE ? "true" : "false"); + + if (non_blocking) { + return SANE_STATUS_UNSUPPORTED; + } + + return SANE_STATUS_GOOD; +} + +/** + * Obtain a file-descriptor for the scanner that is readable if image data is + * available. The select file-descriptor is returned in *fd. + * The function has not been implemented since USB-device only operate in + * blocking mode. + * + * @param handle Scanner handle + * @param fd File descriptor with imae data + * @return SANE_STATUS_INVAL + */ +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; + return SANE_STATUS_UNSUPPORTED; +} diff --git a/backend/pieusb.conf.in b/backend/pieusb.conf.in new file mode 100644 index 0000000..ec5ba7e --- /dev/null +++ b/backend/pieusb.conf.in @@ -0,0 +1,9 @@ +# pieusb.conf: Configuration file for PIE/Reflecta USB scanner +# Read man sane-pieusb for documentation + +# Autodetect +# Reflecta 6000 Multiple Slide Scanner +usb 0x05e3 0x0142 +# Reflecta CrystalScan 7200 +# Reflecta ProScan 7200 +usb 0x05e3 0x0145 diff --git a/backend/pieusb.h b/backend/pieusb.h new file mode 100644 index 0000000..10ce106 --- /dev/null +++ b/backend/pieusb.h @@ -0,0 +1,105 @@ +/* sane - Scanner Access Now Easy. + + pieusb.h + + Copyright (C) 2012-2015 Jan Vleeshouwers, Michael Rickmann, Klaus Kaempf + + This file is part of the SANE package. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA. + + As a special exception, the authors of SANE give permission for + additional uses of the libraries contained in this release of SANE. + + The exception is that, if you link a SANE library with other files + to produce an executable, this does not by itself cause the + resulting executable to be covered by the GNU General Public + License. Your use of that executable is in no way restricted on + account of linking the SANE library code into it. + + This exception does not, however, invalidate any other reasons why + the executable file might be covered by the GNU General Public + License. + + If you submit changes to SANE to the maintainers to be included in + a subsequent release, you agree by submitting the changes that + those changes may be distributed with this exception intact. + + If you write modifications of your own for SANE, it is your choice + whether to permit this exception to apply to your modifications. + If you do not wish that, delete this exception notice. */ + +#ifndef PIEUSB_H +#define PIEUSB_H + +#include "../include/sane/config.h" +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#ifdef HAVE_UNISTD_H +#include <unistd.h> +#endif + +#define BACKEND_NAME pieusb + +#include "../include/sane/sane.h" +#include "../include/sane/sanei_usb.h" +#include "../include/sane/sanei_debug.h" + + +#include "pieusb_scancmd.h" +#include "pieusb_usb.h" + + +/* -------------------------------------------------------------------------- + * + * SUPPORTED DEVICES SPECIFICS + * + * --------------------------------------------------------------------------*/ + +/* List of default supported scanners by vendor-id, product-id and model number. + * A default list will be created in sane_init(), and entries in the config file + * will be added to it. */ + +struct Pieusb_USB_Device_Entry +{ + SANE_Word vendor; /* USB vendor identifier */ + SANE_Word product; /* USB product identifier */ + SANE_Word model; /* USB model number */ + SANE_Int device_number; /* USB device number if the device is present */ +}; + +extern struct Pieusb_USB_Device_Entry* pieusb_supported_usb_device_list; +extern struct Pieusb_USB_Device_Entry pieusb_supported_usb_device; /* for searching */ + +struct Pieusb_Device_Definition; +extern struct Pieusb_Device_Definition *pieusb_definition_list_head; + +/* Debug error levels */ +#define DBG_error 1 /* errors */ +#define DBG_warning 3 /* warnings */ +#define DBG_info 5 /* information */ +#define DBG_info_sane 7 /* information sane interface level */ +#define DBG_inquiry 8 /* inquiry data */ +#define DBG_info_proc 9 /* information pieusb backend functions */ +#define DBG_info_scan 11 /* information scanner commands */ +#define DBG_info_usb 13 /* information usb level functions */ +#define DBG_info_buffer 15 /* information buffer functions */ + +/* R G B I */ +#define PLANES 4 + +#endif /* PIEUSB_H */ diff --git a/backend/pieusb_buffer.c b/backend/pieusb_buffer.c new file mode 100644 index 0000000..53bd867 --- /dev/null +++ b/backend/pieusb_buffer.c @@ -0,0 +1,644 @@ +/* sane - Scanner Access Now Easy. + + pieusb_buffer.c + + Copyright (C) 2012-2015 Jan Vleeshouwers, Michael Rickmann, Klaus Kaempf + + This file is part of the SANE package. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA. + + As a special exception, the authors of SANE give permission for + additional uses of the libraries contained in this release of SANE. + + The exception is that, if you link a SANE library with other files + to produce an executable, this does not by itself cause the + resulting executable to be covered by the GNU General Public + License. Your use of that executable is in no way restricted on + account of linking the SANE library code into it. + + This exception does not, however, invalidate any other reasons why + the executable file might be covered by the GNU General Public + License. + + If you submit changes to SANE to the maintainers to be included in + a subsequent release, you agree by submitting the changes that + those changes may be distributed with this exception intact. + + If you write modifications of your own for SANE, it is your choice + whether to permit this exception to apply to your modifications. + If you do not wish that, delete this exception notice. */ + +/* ========================================================================= + * + * Read buffer + * + * Data obtained from the scanner cannot be presented to the frontend immediately. + * The scanner returns data in the 'index' or 'line' color format, which means it + * returns data in batches which contain a single color of a scan line. + * + * These must finally be converted into the SANE data format (data for a single + * pixel in consecutive bytes). Apart from that, sane_read() must be able to + * return any amount of data bytes. + * + * In between, data processing may be necessary, usually requiring the whole + * image to be available. + * + * To accommodate all this, the buffer stores all samples as 16-bit values, even + * if the original values are 8-bit or even 1 bit. This is a waste of space, but + * makes processing much easier, and it is only temporary. + * + * The read buffer is constructed by a call to buffer_create(), which initializes + * the buffer based on width, height, number of colors and depth. The buffer + * contains data organized in color planes, with each plane consisting of lines, + * each line of a fixed number of (single color) pixels, and each pixel of a fixed + * number of bits (or bytes). + * + * The buffer maintains read and write pointers. + * + * Multi-color data with a bit depth of 1 are packed in single color bytes, so + * the data obtained from the scanner does not need conversion. + * + * ========================================================================= */ + +#define DEBUG_DECLARE_ONLY + +/* Configuration defines */ +#include "../include/sane/config.h" + +/* SANE includes */ +#include "../include/sane/sane.h" +#include "../include/sane/saneopts.h" +#include "../include/sane/sanei_usb.h" +#include "../include/sane/sanei_config.h" + +/* Backend includes */ +#define BACKEND_NAME pieusb +#include "../include/sane/sanei_backend.h" +#include "pieusb.h" + +#include "pieusb_specific.h" +#include "pieusb_buffer.h" + +#ifdef HAVE_ALLOCA_H +#include <alloca.h> +#endif + +#include <stdio.h> +#include <fcntl.h> +#include <sys/mman.h> +#include <endian.h> + +/* When creating the release backend, make complains about unresolved external + * le16toh, although it finds the include <endian.h> */ +#if __BYTE_ORDER == __LITTLE_ENDIAN + #define le16toh(x) (x) +#else + #define le16toh(x) __bswap_16 (x) +#endif + +static void buffer_update_read_index(struct Pieusb_Read_Buffer* buffer, int increment); + +/* READER */ + +/** + * Initialize the buffer. + * A scanner has a Pieusb_Read_Buffer struct as one of its members. + * + * @param buffer the buffer to initialize + * @param width number of pixels on a line (row) + * @param height number of lines in the buffer (pixels in a column) + * @param colors bitmap specifying the colors in the scanned data (bitmap: 0000 IBGR) + * @param depth number of bits of a color + * @param bigendian how to store multi-byte values: bigendian if true + * @param maximum_size maximum size of buffer (-1 = size of image) + */ + +SANE_Status +sanei_pieusb_buffer_create(struct Pieusb_Read_Buffer* buffer, SANE_Int width, SANE_Int height, SANE_Byte color_spec, SANE_Byte depth) +{ + int k, result; + unsigned int buffer_size_bytes; + unsigned char g; + + /* Base parameters */ + buffer->width = width; + buffer->height = height; + buffer->colors = 0; + if (color_spec & 0x01) { buffer->color_index_red = 0; buffer->colors++; } else { buffer->color_index_red = -1; } + if (color_spec & 0x02) { buffer->color_index_green = 1; buffer->colors++; } else { buffer->color_index_green = -1; } + if (color_spec & 0x04) { buffer->color_index_blue = 2; buffer->colors++; } else { buffer->color_index_blue = -1; } + if (color_spec & 0x08) { buffer->color_index_infrared = 3; buffer->colors++; } else { buffer->color_index_infrared = -1; } + if (buffer->colors == 0) { + DBG(DBG_error, "sanei_pieusb_buffer_create(): no colors specified\n"); + return SANE_STATUS_INVAL; + } + buffer->depth = depth; + if (depth < 1 || depth > 16) { + DBG(DBG_error, "sanei_pieusb_buffer_create(): unsupported depth %d\n", depth); + return SANE_STATUS_INVAL; + } + buffer->packing_density = (depth == 1) ? 8 : 1; /* These are all the situations we have */ + + /* Derived*/ + buffer->packet_size_bytes = (buffer->depth * buffer->packing_density + 7) / 8; + buffer->line_size_packets = (buffer->width + buffer->packing_density -1) / buffer->packing_density; + buffer->line_size_bytes = buffer->line_size_packets * buffer->packet_size_bytes; + buffer->image_size_bytes = buffer->colors * buffer->height * buffer->line_size_bytes; + + /* Create empty file */ + snprintf(buffer->buffer_name, L_tmpnam, "/tmp/sane.XXXXXX"); + if (buffer->data_file != 0) /* might still be open from previous invocation */ + close(buffer->data_file); + buffer->data_file = mkostemp(buffer->buffer_name, O_RDWR | O_CREAT | O_EXCL | O_TRUNC); + if (buffer->data_file == -1) { + buffer->data_file = 0; + buffer->data = NULL; + perror("sanei_pieusb_buffer_create(): error opening image buffer file"); + return SANE_STATUS_IO_ERROR; + } + /* Stretch the file size */ + buffer_size_bytes = buffer->width * buffer->height * buffer->colors * sizeof(SANE_Uint); + if (buffer_size_bytes == 0) { + close(buffer->data_file); + buffer->data_file = 0; + DBG(DBG_error, "sanei_pieusb_buffer_create(): buffer_size is zero: width %d, height %d, colors %d\n", buffer->width, buffer->height, buffer->colors); + return SANE_STATUS_INVAL; + } + result = lseek(buffer->data_file, buffer_size_bytes-1, SEEK_SET); + if (result == -1) { + close(buffer->data_file); + buffer->data_file = 0; + buffer->data = NULL; + DBG(DBG_error, "sanei_pieusb_buffer_create(): error calling lseek() to 'stretch' the file to %d bytes\n", buffer_size_bytes-1); + perror("sanei_pieusb_buffer_create(): error calling lseek()"); + return SANE_STATUS_INVAL; + } + /* Write one byte at the end */ + g = 0x00; + result = write(buffer->data_file, &g, 1); + if (result < 0) { + close(buffer->data_file); + buffer->data_file = 0; + buffer->data = NULL; + perror("sanei_pieusb_buffer_create(): error writing a byte at the end of the file"); + return SANE_STATUS_IO_ERROR; + } +#ifdef HAVE_MMAP + /* Create memory map */ + buffer->data = mmap(NULL, buffer_size_bytes, PROT_WRITE | PROT_READ, MAP_SHARED, buffer->data_file, 0); + if (buffer->data == MAP_FAILED) { + close(buffer->data_file); + buffer->data = NULL; + perror("sanei_pieusb_buffer_create(): error mapping file"); + return SANE_STATUS_INVAL; + } +#else +#error mmap(2) not available, aborting +#endif + buffer->data_size = buffer_size_bytes; + /* Reading and writing */ + buffer->p_read = calloc(buffer->colors, sizeof(SANE_Uint*)); + if (buffer->p_read == NULL) + return SANE_STATUS_NO_MEM; + buffer->p_write = calloc(buffer->colors, sizeof(SANE_Uint*)); + if (buffer->p_write == NULL) + return SANE_STATUS_NO_MEM; + for (k = 0; k < buffer->colors; k++) { + buffer->p_write[k] = buffer->data + k * buffer->height * buffer->width; + buffer->p_read[k] = buffer->p_write[k]; + } + buffer->read_index[0] = 0; + buffer->read_index[1] = 0; + buffer->read_index[2] = 0; + buffer->read_index[3] = 0; + + /* Statistics */ + buffer->bytes_read = 0; + buffer->bytes_written = 0; + buffer->bytes_unread = 0; + + DBG(DBG_info,"pieusb: Read buffer created: w=%d h=%d ncol=%d depth=%d in file %s\n", + buffer->width, buffer->height, buffer->colors, buffer->depth, buffer->buffer_name); + return SANE_STATUS_GOOD; +} + +/** + * Delete buffer and free its resources + * + * @param buffer + */ +void +sanei_pieusb_buffer_delete(struct Pieusb_Read_Buffer* buffer) +{ +#ifdef HAVE_MMAP + munmap(buffer->data, buffer->data_size); +#else +#error mmap(2) not available, aborting +#endif + /* ftruncate(buffer->data_file,0); Can we delete given a file-descriptor? */ + close(buffer->data_file); + /* remove fs entry */ + unlink(buffer->buffer_name); + buffer->data_file = 0; + buffer->data_size = 0; + free(buffer->p_read); + free(buffer->p_write); + buffer->data = 0; + buffer->width = 0; + buffer->height = 0; + buffer->depth = 0; + buffer->colors = 0; + buffer->packing_density = 0; + + DBG(DBG_info,"pieusb: Read buffer deleted\n"); +} + +/** + * Add a line to the reader buffer, for the given color. + * The buffer checks and decides how to interpret the data. + * + * @param buffer + * @param color Color code for line + * @param line + * @param size Number of bytes in line + * @return 1 if successful, 0 if not + */ +SANE_Int +sanei_pieusb_buffer_put_single_color_line(struct Pieusb_Read_Buffer* buffer, SANE_Byte color, void* line, SANE_Int size) +{ + + SANE_Int c, k, m, n; + + /* Check index code */ + c = -1; + switch (color) { + case 'R': + c = buffer->color_index_red; + break; + case 'G': + c = buffer->color_index_green; + break; + case 'B': + c = buffer->color_index_blue; + break; + case 'I': + c = buffer->color_index_infrared; + break; + } + if (c == -1) { + DBG(DBG_error, "sanei_pieusb_buffer_put_single_color_line(): color '%c' not specified when buffer was created\n", color); + return 0; + } + DBG(DBG_info_buffer, "sanei_pieusb_buffer_put_single_color_line() line color = %d (0=R, 1=G, 2=B, 3=I)\n",c); + + /* Check line size (for a line with a single color) */ + if (buffer->line_size_bytes != size) { + DBG(DBG_error, "sanei_pieusb_buffer_put_single_color_line(): incorrect line size, expecting %d, got %d\n", buffer->line_size_bytes, size); + return 0; + } + + /* The general approach for all densities and packet sizes + * - process packet_size_bytes at a time + * - use packing_density to decode the full packet into separate values + * - now save these values as neighbouring pixels on the current line + * Use custom code for the 1-byte and 2-byte single sample cases, + * because the general approach is a bit overkill for them. + */ + + if (buffer->packet_size_bytes == 1 && buffer->packing_density == 1) { + uint8_t* p_packet = (uint8_t*)line; + n = 0; + while (n < size) { + /* Get next packet data & store in buffer */ + *buffer->p_write[c]++ = *p_packet++; + n++; + } + } else if (buffer->packet_size_bytes == 2 && buffer->packing_density == 1) { + uint16_t* p_packet = (uint16_t*)line; + n = 0; + while (n < size) { + /* Get next packet data & store in buffer */ + *buffer->p_write[c]++ = le16toh (*p_packet++); + n += 2; + } + } else { + uint8_t* p_packet = (uint8_t*)line; + uint8_t *packet = (uint8_t *)alloca(buffer->packet_size_bytes * sizeof(uint8_t)); + SANE_Uint val; + uint8_t mask = ~(0xFF >> buffer->depth); /* byte with depth most significant bits set */ + n = 0; + while (n < size) { + /* Get next packet data */ + for (k = 0; k < buffer->packet_size_bytes; k++) packet[k] = *p_packet++; + /* Unpack packing_density samples from packet. Of course, + * buffer->depth * packing_density <= # bits in packet. + * That is checked at buffer creation. */ + for (k = 0; k < buffer->packing_density; k++) { + /* Take 1st depth bits and store in val */ + val = (packet[0] & mask) >> (8-buffer->depth); + /* Now shift packet bytes depth bits left */ + for (m = 0; m < buffer->packet_size_bytes; m++) { + /* Shift left one sample */ + packet[m] <<= buffer->depth; + if (m < buffer->packet_size_bytes-1) { + /* If there are more bytes, insert 1st depth bits of next byte */ + packet[m] |= (packet[m+1] >> (8-buffer->depth)); + } + } + /* Store in buffer */ + *buffer->p_write[c]++ = val; + } + n += buffer->packet_size_bytes; + } + } + + /* Update state & statistics */ + buffer->bytes_written += size; + buffer->bytes_unread += size; + + /* Output current buffer state */ + /* buffer_output_state(buffer); */ + + return 1; +} + +/** + * Write line of full color pixels to the buffer. + * + * @param buffer Read buffer + * @param pixel array of full color pixel data + * @param size Number of bytes in the line + * @return 1 if successful, 0 if not + */ +/** + * + */ +SANE_Int +sanei_pieusb_buffer_put_full_color_line(struct Pieusb_Read_Buffer* buffer, void* line, int size) +{ + int k, c, m, n; + + DBG(DBG_info_buffer, "sanei_pieusb_buffer_put_full_color_line() entered\n"); + + /* Check line size */ + if (buffer->line_size_bytes * buffer->colors != size) { + DBG(DBG_error, "sanei_pieusb_buffer_put_full_color_line(): incorrect line size, expecting %d, got %d\n", buffer->line_size_bytes * buffer->colors, size); + return 0; + } + + /* The general approach for all densities and packet sizes + * - process packet_size_bytes at a time + * - use packing_density to decode the full packet into separate values + * - now save these values as neighbouring pixels on the current line + * Use custom code for the 1-byte and 2-byte single sample cases, + * because the general approach is a bit overkill for them. + */ + + if (buffer->packet_size_bytes == 1 && buffer->packing_density == 1) { + uint8_t* p_packet = (uint8_t*)line; + n = 0; + while (n < size) { + /* Get next packet data & store in buffer */ + for (c = 0; c < buffer->colors; c++) { + *buffer->p_write[c]++ = *p_packet++; + n++; + } + } + } else if (buffer->packet_size_bytes == 2 && buffer->packing_density == 1) { + uint16_t* p_packet = (uint16_t*)line; + n = 0; + while (n < size) { + /* Get next packet data & store in buffer */ + for (c = 0; c < buffer->colors; c++) { + *buffer->p_write[c]++ = le16toh (*p_packet++); + n += 2; + } + } + } else { + uint8_t* p_packet = (uint8_t*)line; + uint8_t *packet = (uint8_t *)alloca(buffer->packet_size_bytes * sizeof(uint8_t)); + SANE_Uint val; + uint8_t mask = ~(0xFF >> buffer->depth); /* byte with depth most significant bits set */ + /* DBG(DBG_info,"buffer_put_full_color_line(): mask %02x\n",mask); */ + n = 0; + while (n < size) { + /* Get next packet data */ + for (c = 0; c < buffer->colors; c++) { + for (k = 0; k < buffer->packet_size_bytes; k++) { + packet[k] = *p_packet++; + /* DBG(DBG_info,"buffer_put_full_color_line(): packet[%d] = %02x\n",k,packet[k]); */ + } + /* Unpack packing_density samples from packet. Of course, + * buffer->depth * packing_density <= # bits in packet. + * That is checked at buffer creation. */ + for (k = 0; k < buffer->packing_density; k++) { + /* Take 1st depth bits and store in val */ + val = (packet[0] & mask) >> (8-buffer->depth); + /* DBG(DBG_info,"buffer_put_full_color_line(): val[%d] = %02x\n",k,val); */ + /* Now shift packet bytes depth bits left */ + for (m = 0; m < buffer->packet_size_bytes; m++) { + /* Shift left one sample */ + packet[m] <<= buffer->depth; + /* DBG(DBG_info,"buffer_put_full_color_line(): shift packet[%d] = %02x\n",m,packet[m]); */ + if (m < buffer->packet_size_bytes-1) { + /* If there are more bytes, insert 1st depth bits of next byte */ + packet[m] |= (packet[m+1] >> (8-buffer->depth)); + /* DBG(DBG_info,"buffer_put_full_color_line(): shift packet[%d] = %02x\n",m,packet[m]); */ + } + } + /* Store in buffer */ + *buffer->p_write[c]++ = val; + } + n += buffer->packet_size_bytes; + } + } + } + + /* Update state & statistics */ + buffer->bytes_written += size; + buffer->bytes_unread += size; + + /* Output current buffer state */ + /* buffer_output_state(buffer); */ + + return 1; +} + +/** + * Return bytes from the buffer. Do not mind pixel boundaries. + * Since the image data is organized in color planes, return bytes from the + * planes in the defined order. Take care to return multi-byte values after + * each other. Pack unpacked values. + * + * @param buffer Buffer to return bytes from. + * @param data Byte array to return bytes in + * @param max_len Maximum number of bytes returned + * @param len Actual number of bytes returned + */ +void +sanei_pieusb_buffer_get(struct Pieusb_Read_Buffer* buffer, SANE_Byte* data, SANE_Int max_len, SANE_Int* len) +{ + SANE_Byte *pdata; + SANE_Int n, i, n_bits, N; + + DBG(DBG_info_buffer, "sanei_pieusb_buffer_get() entered\n"); + + /* Read from the p_read locations */ + pdata = data; + n = 0; + N = buffer->width * buffer->height; + /* Determine bytes to return */ + if (buffer->packet_size_bytes == 1 && buffer->packing_density == 1) { + /* Single byte values in buffer */ + while (n < max_len && buffer->bytes_read < buffer->image_size_bytes) { + /* Return byte*/ + *pdata++ = *(buffer->data + N*buffer->read_index[0] + buffer->width*buffer->read_index[1] + buffer->read_index[2]) & 0xFF; + /* Update read indices */ + buffer_update_read_index(buffer,1); + /* Update number of bytes read */ + buffer->bytes_read++; + n++; + } + } else if (buffer->packet_size_bytes == 1 && buffer->packing_density == 8) { + /* Unpacked bits in buffer: repack */ + while (n < max_len && buffer->bytes_read < buffer->image_size_bytes) { + uint8_t val = 0; + /* How many bits to pack? At the end of a line it may be less than 8 */ + n_bits = 8; + if (buffer->width - buffer->read_index[2] < 8) { + n_bits = buffer->width - buffer->read_index[2]; + } + /* Pack n_bits samples from same color plane */ + for (i = 0; i < n_bits; i++) { + if (*(buffer->data + N*buffer->read_index[0] + buffer->width*buffer->read_index[1] + buffer->read_index[2] + i) > 0) { + val |= (0x80 >> i); + } + } + /* Return byte */ + *pdata++ = val; + /* Update read indices */ + buffer_update_read_index(buffer,n_bits); + /* Update number of bytes read */ + buffer->bytes_read++; + n++; + } + } else if (buffer->packet_size_bytes == 2) { + /* Two-byte values in buffer */ + while (n < max_len && buffer->bytes_read < buffer->image_size_bytes) { + /* Pointer to byte to return */ + SANE_Uint val = *(buffer->data + N*buffer->read_index[0] + buffer->width*buffer->read_index[1] + buffer->read_index[2]); + /* Return byte */ + if (buffer->read_index[3] == 0) { + *pdata++ = *((SANE_Byte*)(&val)); + } else { + *pdata++ = *((SANE_Byte*)(&val)+1); + } + /* Update read indices */ + buffer_update_read_index(buffer,1); + /* Update number of bytes read */ + buffer->bytes_read++; + n++; + } + } else { + /* not implemented */ + DBG(DBG_error, "buffer_put(): paccket size & density of %d/%d not implementd\n", buffer->packet_size_bytes, buffer->packing_density); + return; + } + *len = n; + + /* Update statistics */ + buffer->bytes_unread -= n; + + /* Output current buffer state */ + /* buffer_output_state(buffer); */ +} + +/** + * Update read index to point a given number of bytes past the current position. + * + * @param buffer the buffer to initialize + * @param increment the amount of bytes to move the index + */ +static void buffer_update_read_index(struct Pieusb_Read_Buffer* buffer, int increment) +{ + /* Update read indices + * [3] = byte-index in 2-byte value: increased first, if we have 2-byte data + * [2] = index of pixel on line: increased after color plane + * [1] = index of line: increased after line is complete + * [0] = color index: increased first since SANE requires full color pixels */ + if (buffer->read_index[3] == 0 && buffer->packet_size_bytes == 2) { + buffer->read_index[3] = 1; + } else { + buffer->read_index[3] = 0; + buffer->read_index[0]++; + if (buffer->read_index[0] == buffer->colors) { + buffer->read_index[0] = 0; + buffer->read_index[2] += increment; + if (buffer->read_index[2] >= buffer->width) { + buffer->read_index[2] = 0; + buffer->read_index[1]++; + } + } + } +} + +#if 0 +/** + * Display the buffer state. + * + * @param buffer the buffer to initialize + */ + +static void buffer_output_state(struct Pieusb_Read_Buffer* buffer) +{ + SANE_Int line_size; + SANE_Int N, k, loc[4]; + + line_size = buffer->line_size_bytes * buffer->colors; /* Full line size in bytes */ + + DBG(DBG_info_buffer, "Buffer data\n"); + DBG(DBG_info_buffer," width/height/colors/depth = %d %d %d %d (buffer size %d)\n", + buffer->width, buffer->height, buffer->colors, buffer->depth, buffer->image_size_bytes); + + /* Summary */ + N = buffer->width * buffer->height; + for (k = 0; k < buffer->colors; k++) { + loc[k] = buffer->p_read[k] - buffer->data - k*N; + } + for (k = buffer->colors; k < 4; k++) { + loc[k] = 0; + } + DBG(DBG_info_buffer, " reading at: lines = %d:%d:%d:%d\n", loc[0], loc[1], loc[2], loc[3]); + for (k = 0; k < buffer->colors; k++) { + loc[k] = buffer->p_write[k] - buffer->data - k*N; + } + for (k = buffer->colors; k < 4; k++) { + loc[k] = 0; + } + DBG(DBG_info_buffer, " writing at: lines = %d:%d:%d:%d\n", loc[0], loc[1], loc[2], loc[3]); + + /* Progress */ + double fdata = (double)buffer->bytes_unread/buffer->image_size_bytes*100; + double fread = (double)buffer->bytes_read/buffer->image_size_bytes*100; + double fwritten = (double)buffer->bytes_written/buffer->image_size_bytes*100; + DBG(DBG_info_buffer, " byte counts: image = %d, data = %d (%.0f%%), read = %d (%.0f%%), written = %d (%.0f%%)\n", + buffer->image_size_bytes, buffer->bytes_unread, fdata, buffer->bytes_read, fread, buffer->bytes_written, fwritten); + DBG(DBG_info_buffer, " line counts: image = %.1f, data = %.1f, read = %.1f, written = %.1f\n", + (double)buffer->image_size_bytes/line_size, (double)buffer->bytes_unread/line_size, (double)buffer->bytes_read/line_size, (double)buffer->bytes_written/line_size); + +} +#endif diff --git a/backend/pieusb_buffer.h b/backend/pieusb_buffer.h new file mode 100644 index 0000000..3724a40 --- /dev/null +++ b/backend/pieusb_buffer.h @@ -0,0 +1,93 @@ +/* sane - Scanner Access Now Easy. + + pieusb_buffer.h + + Copyright (C) 2012-2015 Jan Vleeshouwers, Michael Rickmann, Klaus Kaempf + + This file is part of the SANE package. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA. + + As a special exception, the authors of SANE give permission for + additional uses of the libraries contained in this release of SANE. + + The exception is that, if you link a SANE library with other files + to produce an executable, this does not by itself cause the + resulting executable to be covered by the GNU General Public + License. Your use of that executable is in no way restricted on + account of linking the SANE library code into it. + + This exception does not, however, invalidate any other reasons why + the executable file might be covered by the GNU General Public + License. + + If you submit changes to SANE to the maintainers to be included in + a subsequent release, you agree by submitting the changes that + those changes may be distributed with this exception intact. + + If you write modifications of your own for SANE, it is your choice + whether to permit this exception to apply to your modifications. + If you do not wish that, delete this exception notice. */ + +#ifndef PIEUSB_BUFFER_H +#define PIEUSB_BUFFER_H + +#include "pieusb.h" +#include "../include/sane/sanei_ir.h" + +struct Pieusb_Read_Buffer +{ + SANE_Uint* data; /* image data - always store as 16 bit values; mmap'ed */ + unsigned int data_size; /* size of mmap region */ + SANE_Int data_file; /* associated file if memory mapped */ + char buffer_name[L_tmpnam]; + + /* Buffer parameters */ + SANE_Int width; /* number of pixels on a line */ + SANE_Int height; /* number of lines in buffer */ + SANE_Int colors; /* number of colors in a pixel */ + SANE_Int depth; /* number of bits of a color */ + SANE_Int packing_density; /* number of single color samples packed together */ + + /* Derived quantities + * All derived quantities pertain to the image, not to the buffer */ + SANE_Int packet_size_bytes; /* number of bytes of a packet of samples = round_up(depth*packing_density/8) */ + SANE_Int line_size_packets; /* number of packets on a single color line = round-down((width+packing_density-1)/packing_density) */ + SANE_Int line_size_bytes; /* number of bytes on a single color line = line_size_packets*packet_size_bytes */ + SANE_Int image_size_bytes; /* total number of bytes in the buffer (= colors * height * line_size_packets* packet_size_bytes) */ + SANE_Int color_index_red; /* color index of the red color plane (-1 if not used) */ + SANE_Int color_index_green; /* color index of the green color plane (-1 if not used) */ + SANE_Int color_index_blue; /* color index of the blue color plane (-1 if not used) */ + SANE_Int color_index_infrared; /* color index of the infrared color plane (-1 if not used) */ + + /* Reading - byte oriented */ + SANE_Uint** p_read; /* array of pointers to next sample to read for each color plane */ + SANE_Int read_index[4]; /* location where to read next (color-index, height-index, width-index, byte-index) */ + SANE_Int bytes_read; /* number of bytes read from the buffer */ + SANE_Int bytes_unread; /* number of bytes not yet read from the buffer */ + SANE_Int bytes_written; /* number of bytes written to the buffer */ + + /* Writing */ + SANE_Uint** p_write; /* array of pointers to next byte to write for each color plane */ +}; + +void sanei_pieusb_buffer_get(struct Pieusb_Read_Buffer* buffer, SANE_Byte* data, SANE_Int max_len, SANE_Int* len); +SANE_Status sanei_pieusb_buffer_create(struct Pieusb_Read_Buffer* buffer, SANE_Int width, SANE_Int height, SANE_Byte colors, SANE_Byte depth); +void sanei_pieusb_buffer_delete(struct Pieusb_Read_Buffer* buffer); +SANE_Int sanei_pieusb_buffer_put_full_color_line(struct Pieusb_Read_Buffer* buffer, void* line, int size); +SANE_Int sanei_pieusb_buffer_put_single_color_line(struct Pieusb_Read_Buffer* buffer, SANE_Byte color, void* line, SANE_Int size); + +#endif /* PIEUSB_BUFFER_H */ diff --git a/backend/pieusb_scancmd.c b/backend/pieusb_scancmd.c new file mode 100644 index 0000000..a86f8fe --- /dev/null +++ b/backend/pieusb_scancmd.c @@ -0,0 +1,1329 @@ +/* sane - Scanner Access Now Easy. + + pieusb_scancmd.c + + Copyright (C) 2012-2015 Jan Vleeshouwers, Michael Rickmann, Klaus Kaempf + + This file is part of the SANE package. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA. + + As a special exception, the authors of SANE give permission for + additional uses of the libraries contained in this release of SANE. + + The exception is that, if you link a SANE library with other files + to produce an executable, this does not by itself cause the + resulting executable to be covered by the GNU General Public + License. Your use of that executable is in no way restricted on + account of linking the SANE library code into it. + + This exception does not, however, invalidate any other reasons why + the executable file might be covered by the GNU General Public + License. + + If you submit changes to SANE to the maintainers to be included in + a subsequent release, you agree by submitting the changes that + those changes may be distributed with this exception intact. + + If you write modifications of your own for SANE, it is your choice + whether to permit this exception to apply to your modifications. + If you do not wish that, delete this exception notice. */ + +/* ========================================================================= + * + * Pieusb scanner commands + * + * Each scanner command has its own function. + * See the sort description preceeding each function. + * + * ========================================================================= */ + +#define DEBUG_DECLARE_ONLY + +#include "pieusb.h" +#include "pieusb_scancmd.h" +#include "pieusb_usb.h" + +#ifdef HAVE_ALLOCA_H +#include <alloca.h> +#endif + +#include <time.h> /* for time() */ + +static void _prep_scsi_cmd(SANE_Byte* command_bytes, SANE_Byte command, SANE_Word size); + +/* ========================================================================= + * + * Pieusb utility functions + * + * ========================================================================= */ + +/* + * Get the unsigned char value in the array at given offset + */ +static SANE_Byte +_get_byte(SANE_Byte* array, SANE_Byte offset) { + return *(array+offset); +} + +/* + * Set the array at given offset to the given unsigned char value + */ +static void +_set_byte(SANE_Byte val, SANE_Byte* array, SANE_Byte offset) { + *(array+offset) = val; +} + + +/* + * Get the unsigned short value in the array at given offset. + * All data in structures is little-endian, so the LSB comes first + * SANE_Int is 4 bytes, but that is not a problem. + */ +static SANE_Int +_get_short(SANE_Byte* array, SANE_Byte offset) { + SANE_Int i = *(array+offset+1); + i <<= 8; + i += *(array+offset); + return i; +} + + +/* + * Put the bytes of a short int value into an unsigned char array + * All data in structures is little-endian, so start with LSB + */ +static void +_set_short(SANE_Word val, SANE_Byte* array, SANE_Byte offset) { + *(array+offset) = val & 0xFF; + *(array+offset+1) = (val>>8) & 0xFF; +} + + +/* + * Get the signed int value in the array at given offset. + * All data in structures is little-endian, so the LSB comes first + */ +static SANE_Int +_get_int(SANE_Byte* array, SANE_Byte offset) { + SANE_Int i = *(array+offset+3); + i <<= 8; + i += *(array+offset+2); + i <<= 8; + i += *(array+offset+1); + i <<= 8; + i += *(array+offset); + return i; +} + +#if 0 /* unused */ +/* + * Put the bytes of a signed int value into an unsigned char array + * All data in structures is little-endian, so start with LSB + */ +static void +_set_int(SANE_Word val, SANE_Byte* array, SANE_Byte offset) { + *(array+offset) = val & 0xFF; + *(array+offset+1) = (val>>8) & 0xFF; + *(array+offset+2) = (val>>16) & 0xFF; + *(array+offset+3) = (val>>24) & 0xFF; +} +#endif + +/* + * Copy count unsigned char values from src to dst + */ +static void +_copy_bytes(SANE_Byte* dst, SANE_Byte* src, SANE_Byte count) { + SANE_Byte k; + for (k=0; k<count; k++) { + *dst++ = *src++; + } +} + + +/* + * Get count unsigned short values in the array at given offset. + * All data in structures is little-endian, so the MSB comes first. + * SANE_Word is 4 bytes, but that is not a problem. + */ +static void +_get_shorts(SANE_Word* dst, SANE_Byte* src, SANE_Byte count) { + SANE_Byte k; + for (k=0; k<count; k++) { + *dst = *(src+2*k+1); + *dst <<= 8; + *dst++ += *(src+2*k); + } +} + +/* + * Copy an unsigned short array of given size + * All data in structures is little-endian, so start with MSB of each short. + * SANE_Word is 4 bytes, but that is not a problem. All MSB 2 bytes are ignored. + */ +static void +_set_shorts(SANE_Word* src, SANE_Byte* dst, SANE_Byte count) { + SANE_Byte k; + for (k=0; k<count; k++) { + *(dst+2*k) = *src & 0xFF; + *(dst+2*k+1) = ((*src++)>>8) & 0xFF; + } +} + + +/** + * Perform a TEST UNIT READY (SCSI command code 0x00) + * Returns status->pieusb_status: + * - PIEUSB_STATUS_GOOD if device is ready + * - PIEUSB_STATUS_DEVICE_BUSY if device is still busy after timeout + * - other SANE status code if TEST UNIT READY failed or if it returned + * CHECK CONDITION and REQUEST SENSE failed + * + * @param device_number Device number + * @return Pieusb_Command_Status SANE_STATUS_GOOD if ready, SANE_STATUS_DEVICE_BUSY if not + */ +void +sanei_pieusb_cmd_test_unit_ready(SANE_Int device_number, struct Pieusb_Command_Status *status) +{ + SANE_Byte command[SCSI_COMMAND_LEN]; + + DBG (DBG_info_scan, "sanei_pieusb_cmd_test_unit_ready()\n"); + + _prep_scsi_cmd (command, SCSI_TEST_UNIT_READY, 0); + + 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)); +} + +/** + * slide action + * @param action SLIDE_NEXT, SLIDE_PREV, SLIDE_LAMP_ON, SLIDE_RELOAD + * @return Pieusb_Command_Status + */ + +void +sanei_pieusb_cmd_slide(SANE_Int device_number, slide_action action, struct Pieusb_Command_Status *status) +{ + SANE_Byte command[SCSI_COMMAND_LEN]; +#define SLIDE_DATA_SIZE 4 + SANE_Byte data[SLIDE_DATA_SIZE]; + + DBG (DBG_info_scan, "sanei_pieusb_cmd_slide(0x%02x)\n", action); + + _prep_scsi_cmd(command, SCSI_SLIDE, SLIDE_DATA_SIZE); + memset(data, '\0', SLIDE_DATA_SIZE); + data[0] = action; + data[1] = 0x01; + + status->pieusb_status = sanei_pieusb_command(device_number, command, data, SLIDE_DATA_SIZE); +#undef SLIDE_DATA_SIZE +} + +/** + * Perform a REQUEST SENSE (SCSI command code 0x03) + * Returns status->pieusb_status: + * - PIEUSB_STATUS_GOOD is the command executes OK + * - other SANE status code if REQUEST SENSE fails + * The sense fields in status are always 0. A REQUEST SENSE is not repeated if + * the device returns PIEUSB_STATUS_DEVICE_BUSY. + * + * @param device_number Device number + * @param sense Sense data + * @param status Command result status + * @see struc Pieusb_Sense + */ +void +sanei_pieusb_cmd_get_sense(SANE_Int device_number, struct Pieusb_Sense* sense, struct Pieusb_Command_Status *status, PIEUSB_Status *ret) +{ + SANE_Byte command[SCSI_COMMAND_LEN]; +#define DATA_SIZE 14 + SANE_Int size = DATA_SIZE; + SANE_Byte data[DATA_SIZE]; + PIEUSB_Status st; + SANE_Char* sd; + + DBG (DBG_info_scan, "sanei_pieusb_cmd_get_sense()\n"); + + _prep_scsi_cmd(command, SCSI_REQUEST_SENSE, size); + + memset(data, '\0', size); + st = sanei_pieusb_command(device_number, command, data, size); + if (st != PIEUSB_STATUS_GOOD) { + status->pieusb_status = st; + /*FIXME*/ + return; + } + + /* Decode data recieved */ + sense->errorCode = _get_byte (data, 0); + sense->segment = _get_byte (data, 1); + sense->senseKey = _get_byte (data, 2); + _copy_bytes (sense->info, data+3, 4); + sense->addLength = _get_byte (data, 7); + _copy_bytes (sense->cmdInfo, data+8, 4); + sense->senseCode = _get_byte (data, 12); + sense->senseQualifier = _get_byte (data, 13); + status->pieusb_status = PIEUSB_STATUS_GOOD; +#undef DATA_SIZE + DBG (DBG_info_scan, "\tsense details:\n"); + DBG (DBG_info_scan, "\t\terror......... : 0x%02x\n", sense->errorCode); + DBG (DBG_info_scan, "\t\tsegment....... : %d\n", sense->segment); + DBG (DBG_info_scan, "\t\tsenseKey...... : 0x%02x\n", sense->senseKey); + DBG (DBG_info_scan, "\t\tinfo.......... : %02x %02x %02x %02x\n", sense->info[0], sense->info[1], sense->info[2], sense->info[3]); + DBG (DBG_info_scan, "\t\taddLength..... : %d\n", sense->addLength); + DBG (DBG_info_scan, "\t\tcmdInfo....... : %02x %02x %02x %02x\n", sense->cmdInfo[0], sense->cmdInfo[1], sense->cmdInfo[2], sense->cmdInfo[3]); + DBG (DBG_info_scan, "\t\tsenseCode..... : 0x%02x\n", sense->senseCode); + DBG (DBG_info_scan, "\t\tsenseQualifier : 0x%02x\n", sense->senseQualifier); + sd = sanei_pieusb_decode_sense (sense, ret?ret:&st); + DBG (DBG_info_scan, "\tsense: %s\n", sd); + free(sd); +} + +/** + * Read the halftone pattern with the specified index. This requires two + * commands, one to ask the device to prepare the pattern, and one to read it. + * + * @param device_number Device number + * @param index index of halftone pattern + * @param pattern Halftone pattern (not implemented) + * @return Pieusb_Command_Status + * @see Pieusb_Halftone_Pattern + */ +void +sanei_pieusb_cmd_get_halftone_pattern(SANE_Int device_number, SANE_Int index, struct Pieusb_Halftone_Pattern* pattern, struct Pieusb_Command_Status *status) +{ + SANE_Byte command[SCSI_COMMAND_LEN]; +#define PATTERN_SIZE 256 /* Assumed maximum pattern size */ + SANE_Int size = PATTERN_SIZE; + SANE_Byte data[PATTERN_SIZE]; + int psize; + SANE_Char* desc; + PIEUSB_Status st; + + DBG (DBG_info_scan, "sanei_pieusb_cmd_get_halftone_pattern()\n"); + + /* Ask scanner to prepare the pattern with the given index. Only SCSI_COMMAND_LEN bytes of data. */ + _prep_scsi_cmd(command, SCSI_WRITE, SCSI_COMMAND_LEN); + memset(data, '\0', SCSI_COMMAND_LEN); + data[0] = SCSI_HALFTONE_PATTERN | 0x80; /* set bit 7 means prepare read */ + data[4] = index; + + st = sanei_pieusb_command(device_number, command, data, SCSI_COMMAND_LEN); + if (st != PIEUSB_STATUS_GOOD) { + status->pieusb_status = st; + /* FIXME */ + return; + } + + /* Read pattern */ + _prep_scsi_cmd(command, SCSI_READ, size); + + memset(data, '\0', size); + status->pieusb_status = sanei_pieusb_command (device_number, command, data, size); + + /*FIXME: analyse */ + fprintf(stderr, "Halftone pattern %d:\n", index); + psize = (data[3]<<8) + data[2]; + desc = (SANE_Char*)(data + 4 + psize); + data[4 + psize + 16] = '\0'; + fprintf(stderr,"Descr. offset from byte 4 = %d, %16s, index = %d, size = %dx%d\n", psize, desc, data[4]&0x7F, data[6], data[7]); +#undef PATTERN_SIZE +} + +/** + * Read the scan frame with the specified index. This requires two + * commands, one to ask the device to prepare the pattern, and one to read it. + * + * @param device_number Device number + * @param frame Scan frame + * @return Pieusb_Command_Status + * @see Pieusb_Scan_Frame + */ +void +sanei_pieusb_cmd_get_scan_frame(SANE_Int device_number, SANE_Int index, struct Pieusb_Scan_Frame* frame, struct Pieusb_Command_Status *status) +{ + SANE_Byte command[SCSI_COMMAND_LEN]; +#define FRAME_SIZE 256 /* Assumed maximum frame size */ + SANE_Int size = FRAME_SIZE; + SANE_Byte data[FRAME_SIZE]; + PIEUSB_Status st; + + DBG (DBG_info_scan, "sanei_pieusb_cmd_get_scan_frame()\n"); + + /* Ask scanner to prepare the scan frame with the given index. Only SCSI_COMMAND_LEN bytes of data. */ + _prep_scsi_cmd (command, SCSI_WRITE, SCSI_COMMAND_LEN); + memset (data, '\0', SCSI_COMMAND_LEN); + data[0] = SCSI_SCAN_FRAME | 0x80; /* set bit 7 means prepare read */ + data[4] = index; + + st = sanei_pieusb_command (device_number, command, data, SCSI_COMMAND_LEN); + if (st != PIEUSB_STATUS_GOOD) { + status->pieusb_status = st; + /* FIXME */ + return; + } + + /* Read scan frame */ + _prep_scsi_cmd (command, SCSI_READ, size); + + memset(data, '\0', size); + status->pieusb_status = sanei_pieusb_command (device_number, command, data, size); + + /* Decode data */ + frame->index = _get_byte (data, 4); + frame->x0 = _get_short (data, 6); + frame->y0 = _get_short (data, 8); + frame->x1 = _get_short (data, 10); + frame->y1 = _get_short (data, 12); + + DBG (DBG_info_scan, "sanei_pieusb_cmd_get_scan_frame() set:\n"); + DBG (DBG_info_scan, " x0,y0 = %d,%d\n", frame->x0, frame->y0); + DBG (DBG_info_scan, " x1,y1 = %d,%d\n", frame->x1, frame->y1); + DBG (DBG_info_scan, " index = %d\n", frame->index); +#undef FRAME_SIZE +} + +/** + * command 17 - unknown + */ + +void +sanei_pieusb_cmd_17(SANE_Int device_number, SANE_Int value, struct Pieusb_Command_Status *status) +{ + SANE_Byte command[SCSI_COMMAND_LEN]; +#define CMD_17_SIZE 6 + SANE_Byte data[CMD_17_SIZE]; + + DBG (DBG_info_scan, "sanei_pieusb_cmd_17(%d)\n", value); + + _prep_scsi_cmd (command, SCSI_WRITE, CMD_17_SIZE); + memset (data, '\0', CMD_17_SIZE); + _set_short (SCSI_CMD_17, data, 0); + _set_short (2, data, 2); + _set_short (value, data, 4); + + status->pieusb_status = sanei_pieusb_command (device_number, command, data, CMD_17_SIZE); +#undef CMD_17_SIZE + if (status->pieusb_status != PIEUSB_STATUS_GOOD) { + DBG (DBG_info_scan, "sanei_pieusb_cmd_17 failed: 0x%02x\n", status->pieusb_status); + return; + } +} + +/** + * Read the relative exposure time for the specified colorbits. This requires two + * commands, one to ask the device to prepare the value, and one to read it. + * + * @param device_number Device number + * @param time Relative exposure time(s) + * @return Pieusb_Command_Status + * @see Pieusb_Exposure_Time + */ +void +sanei_pieusb_cmd_get_exposure_time(SANE_Int device_number, SANE_Int colorbits, struct Pieusb_Exposure_Time* time, struct Pieusb_Command_Status *status) +{ + DBG (DBG_info_scan, "sanei_pieusb_cmd_get_exposure_time(): not implemented\n"); + status->pieusb_status = PIEUSB_STATUS_INVAL; +} + +/** + * Read the highlight and shadow levels with the specified colorbits. This requires two + * commands, one to ask the device to prepare the value, and one to read it. + * + * @param device_number Device number + * @param hgltshdw Highlight and shadow level(s) + * @return Pieusb_Command_Status + * @see Pieusb_Highlight_Shadow + */ +void +sanei_pieusb_cmd_get_highlight_shadow(SANE_Int device_number, SANE_Int colorbits, struct Pieusb_Highlight_Shadow* hgltshdw, struct Pieusb_Command_Status *status) +{ + DBG (DBG_info_scan, "sanei_pieusb_cmd_get_highlight_shadow(): not implemented\n"); + status->pieusb_status = PIEUSB_STATUS_INVAL; +} + +/** + * Read the shading data parameters. This requires two + * commands, one to ask the device to prepare the value, and one to read it. + * + * @param device_number Device number + * @param shading Shading data parameters + * @return Pieusb_Command_Status + * @see Pieusb_Shading_Parameters + */ +void +sanei_pieusb_cmd_get_shading_parms(SANE_Int device_number, struct Pieusb_Shading_Parameters_Info* shading, struct Pieusb_Command_Status *status) +{ + SANE_Byte command[SCSI_COMMAND_LEN]; +#define SHADING_SIZE 32 +#define PREP_READ_SIZE 6 + SANE_Int size = SHADING_SIZE; + SANE_Byte data[SHADING_SIZE]; + int k; + + DBG (DBG_info_scan, "sanei_pieusb_cmd_get_shading_parms()\n"); + + /* Ask scanner to prepare the scan frame with the given index. Only SCSI_COMMAND_LEN bytes of data. */ + _prep_scsi_cmd (command, SCSI_WRITE, SCSI_COMMAND_LEN); + memset (data, '\0', PREP_READ_SIZE); + data[0] = SCSI_CALIBRATION_INFO | 0x80; /* set bit 7 means prepare read */ + + status->pieusb_status = sanei_pieusb_command (device_number, command, data, PREP_READ_SIZE); + if (status->pieusb_status != PIEUSB_STATUS_GOOD) { + return; + } + + /* Read shading parameters */ + _prep_scsi_cmd(command, SCSI_READ, size); + + memset (data, '\0', size); + status->pieusb_status = sanei_pieusb_command (device_number, command, data, size); + if (status->pieusb_status != PIEUSB_STATUS_GOOD) { + return; + } + + /* Decode data [32 bytes] + 0: 95 00 type + 2: 1c 00 payload len + 4: 04 entries + 5: 06 entry size + 6: 04 00 ? + 8: 00 10 10 14 1a 1d type send recv nlines pixPerLine(2bytes) + 14: 08 10 10 14 1a 1d + 20: 10 10 10 14 1a 1d + 26: 20 10 10 14 1a 1d + */ + for (k = 0; k < data[4]; k++) { + shading[k].type = _get_byte (data, 8 + data[5]*k); + shading[k].sendBits = _get_byte (data, 9 + data[5]*k); + shading[k].recieveBits = _get_byte (data, 10 + data[5]*k); + shading[k].nLines = _get_byte (data, 11 + data[5]*k); + shading[k].pixelsPerLine = _get_short (data, 12 + data[5]*k); + } +#undef PREP_READ_SIZE +#undef SHADING_SIZE +} + +/** + * Read scanned data from the scanner memory into a byte array. The lines + * argument specifies how many lines will be read, the size argument specifies + * the total amount of bytes in these lines. Use sanei_pieusb_cmd_get_parameters() to + * determine the current line size and the number of available lines.\n + * If there is scanned data available, it should be read. Waiting too long + * causes the scan to stop, probably because a buffer is filled to its limits + * (if so, it is approximately 2Mb in size). I haven't tried what happens if you + * start reading after a stop. Reading to fast causes the scanner to return + * a busy status, which is not a problem. + * This is a SCSI READ command (code 0x08). It is distinguished from the other + * READ commands by the context in which it is issued: see sanei_pieusb_cmd_start_scan(). + * + * @param device_number + * @param data + * @param lines + * @param size + * @return Pieusb_Command_Status + */ +void +sanei_pieusb_cmd_get_scanned_lines(SANE_Int device_number, SANE_Byte* data, SANE_Int lines, SANE_Int size, struct Pieusb_Command_Status *status) +{ + SANE_Byte command[SCSI_COMMAND_LEN]; + + DBG (DBG_info_scan, "sanei_pieusb_cmd_get_scanned_lines(): %d lines (%d bytes)\n", lines, size); + + _prep_scsi_cmd (command, SCSI_READ, lines); + memset (data, '\0', size); + + status->pieusb_status = sanei_pieusb_command (device_number, command, data, size); +} + +/** + * Set the halftone pattern with the given index to the specified pattern. The + * command is a SCSI WRITE command (code 0x0A, write code 0x11). + * + * @param device_number Device number + * @param index Pattern index (0-7) + * @param pattern Halftone pattern (not implemented) + * @return Pieusb_Command_Status + * @see Pieusb_Halftone_Pattern + */ +void +sanei_pieusb_cmd_set_halftone_pattern(SANE_Int device_number, SANE_Int index, struct Pieusb_Halftone_Pattern* pattern, struct Pieusb_Command_Status *status) +{ + DBG (DBG_info_scan, "sanei_pieusb_cmd_set_halftone_pattern(): not implemented\n"); + status->pieusb_status = PIEUSB_STATUS_INVAL; +} + +/** + * Set the scan frame with the given index to the frame. The command is a SCSI + * WRITE command (code SCSI_WRITE, write code SCSI_SCAN_FRAME). + * + * @param device_number Device number + * @param index Frame index (0-7) + * @param frame Scan frame + * @return Pieusb_Command_Status + * @see Pieusb_Scan_Frame + */ +void +sanei_pieusb_cmd_set_scan_frame(SANE_Int device_number, SANE_Int index, struct Pieusb_Scan_Frame* frame, struct Pieusb_Command_Status *status) +{ + SANE_Byte command[SCSI_COMMAND_LEN]; +#define FRAME_SIZE 14 + SANE_Int size = FRAME_SIZE; + SANE_Byte data[FRAME_SIZE]; + + DBG (DBG_info_scan, "sanei_pieusb_cmd_set_scan_frame()\n"); + + _prep_scsi_cmd(command, SCSI_WRITE, size); + + DBG (DBG_info_scan, " x0,y0 = %d,%d\n", frame->x0, frame->y0); + DBG (DBG_info_scan, " x1,y1 = %d,%d\n", frame->x1, frame->y1); + DBG (DBG_info_scan, " index = %d\n", index); + + /* Code data */ + memset (data, '\0', size); + _set_short (SCSI_SCAN_FRAME, data, 0); + _set_short (size-4, data, 2); /* size: one frame, 5 shorts */ + _set_short (index, data, 4); + _set_short (frame->x0, data, 6); + _set_short (frame->y0, data, 8); + _set_short (frame->x1, data, 10); + _set_short (frame->y1, data, 12); + + status->pieusb_status = sanei_pieusb_command (device_number, command, data, size); +#undef FRAME_SIZE +} + +/** + * Set the relative exposure time to the given values. Only the first + * Pieusb_Exposure_Time_Color is used. The command is a SCSI + * WRITE command (code SCSI_WRITE, write code SCSI_EXPOSURE). + * + * @param device_number Device number + * @param time Relative exposure time + * @return Pieusb_Command_Status + * @see Pieusb_Exposure_Time + */ +void +sanei_pieusb_cmd_set_exposure_time(SANE_Int device_number, struct Pieusb_Exposure_Time* time, struct Pieusb_Command_Status *status) +{ + SANE_Byte command[SCSI_COMMAND_LEN]; +#define EXPOSURE_DATA_SIZE 8 + SANE_Byte data[EXPOSURE_DATA_SIZE]; + struct Pieusb_Exposure_Time_Color *exptime; + int i; + + DBG (DBG_info_scan, "sanei_pieusb_cmd_set_exposure_time()\n"); + + for (i = 0; i < 3; ++i) { /* R, G, B */ + _prep_scsi_cmd (command, SCSI_WRITE, EXPOSURE_DATA_SIZE); + memset (data, '\0', EXPOSURE_DATA_SIZE); + exptime = &(time->color[i]); + _set_short (SCSI_EXPOSURE, data, 0); + _set_short (EXPOSURE_DATA_SIZE-4, data, 2); /* short: RGB, short: value */ + _set_short (exptime->filter, data, 4); /* 1: neutral, 2: R, 4: G, 8: B */ + _set_short (exptime->value, data, 6); + status->pieusb_status = sanei_pieusb_command (device_number, command, data, EXPOSURE_DATA_SIZE); + if (status->pieusb_status != PIEUSB_STATUS_GOOD) + break; + } + +#undef EXPOSURE_DATA_SIZE +} + +/** + * Set the highlight and shadow levels to the given values. Only the first + * Pieusb_Highlight_Shadow_Color is used. The command is a SCSI + * WRITE command (code SCSI_WRITE, write code SCSI_HIGHLIGHT_SHADOW). + * + * @param device_number Device number + * @param hgltshdw highlight and shadow level + * @return Pieusb_Command_Status + * @see Pieusb_Highlight_Shadow + */ +void +sanei_pieusb_cmd_set_highlight_shadow(SANE_Int device_number, struct Pieusb_Highlight_Shadow* hgltshdw, struct Pieusb_Command_Status *status) +{ + SANE_Byte command[SCSI_COMMAND_LEN]; +#define HIGHLIGHT_SHADOW_SIZE 8 + SANE_Byte data[HIGHLIGHT_SHADOW_SIZE]; + struct Pieusb_Highlight_Shadow_Color *color; + int i; + + DBG (DBG_info_scan, "sanei_pieusb_cmd_set_highlight_shadow()\n"); + + for (i = 0; i < 3; ++i) { /* R, G, B */ + _prep_scsi_cmd (command, SCSI_WRITE, HIGHLIGHT_SHADOW_SIZE); + memset (data, '\0', HIGHLIGHT_SHADOW_SIZE); + color = &(hgltshdw->color[i]); + _set_short (SCSI_HIGHLIGHT_SHADOW, data, 0); + _set_short (HIGHLIGHT_SHADOW_SIZE-4, data, 2); /* short: RGB, short: value */ + _set_short (color->filter, data, 4); /* 1: neutral, 2: R, 4: G, 8: B */ + _set_short (color->value, data, 6); + status->pieusb_status = sanei_pieusb_command (device_number, command, data, HIGHLIGHT_SHADOW_SIZE); + if (status->pieusb_status != PIEUSB_STATUS_GOOD) + break; + } + +#undef HIGHLIGHT_SHADOW_SIZE +} + +/** + * Set the CCD-mask for the colors set in the given color bit mask. The mask + * array must contain mask_size. The command is a SCSI WRITE command + * (code 0x0A, write code 0x16). + * (The command is able to handle more masks at once, but that is not implemented.) + * + * @param device_number Device number + * @param colorbits 0000RGB0 color bit mask; at least one color bit must be set + * @param mask CCD mask to use + * @return Pieusb_Command_Status + */ +void +sanei_pieusb_cmd_set_ccd_mask(SANE_Int device_number, SANE_Byte colorbits, SANE_Byte* mask, SANE_Int mask_size, struct Pieusb_Command_Status *status) +{ + DBG (DBG_info_scan, "sanei_pieusb_cmd_set_ccd_mask(): not implemented\n"); + status->pieusb_status = PIEUSB_STATUS_INVAL; +} + +/* SCSI PARAM, code 0x0F */ +/** + * Get the parameters of an executed scan, such as width, lines and bytes, which + * are needed to calculate the parameters of the READ-commands which read the + * actual scan data. + * + * @param device_number Device number + * @param parameters Scan parameters + * @return Pieusb_Command_Status + * @see Pieusb_Scan_Parameters + */ +void +sanei_pieusb_cmd_get_parameters(SANE_Int device_number, struct Pieusb_Scan_Parameters* parameters, struct Pieusb_Command_Status *status) +{ + SANE_Byte command[SCSI_COMMAND_LEN]; +#define PARAMETER_SIZE 18 + SANE_Int size = PARAMETER_SIZE; + SANE_Byte data[PARAMETER_SIZE]; + + DBG (DBG_info_scan, "sanei_pieusb_cmd_get_parameters()\n"); + + _prep_scsi_cmd (command, SCSI_PARAM, size); + memset (data, '\0', size); + + status->pieusb_status = sanei_pieusb_command(device_number, command, data, size); + if (status->pieusb_status != PIEUSB_STATUS_GOOD) { + return; + } + + /* cyberview: + * 0: e6 02 width 0x2e6 - 742 + * 2: e0 02 lines 0x2e0 - 736 + * 4: e6 02 bytes 0x2e6 - 742 + * 6: 08 filterOffeset1 8 + * 7: 08 filterOffset2 8 + * 8: c9 1c 00 00 period 7369 + * c: 00 00 scsi transfer rate + * e: d7 00 available lines 215 + * 10:00 00 + */ + /* Decode data recieved */ + parameters->width = _get_short(data, 0); + parameters->lines = _get_short(data, 2); + parameters->bytes = _get_short(data, 4); + parameters->filterOffset1 = _get_byte(data, 6); + parameters->filterOffset2 = _get_byte(data, 7); + parameters->period = _get_int(data, 8); /* unused */ + parameters->scsiTransferRate = _get_short(data, 12); /* unused */ + parameters->availableLines = _get_short(data, 14); + + DBG (DBG_info_scan, "sanei_pieusb_cmd_get_parameters() read:\n"); + DBG (DBG_info_scan, " width = %d\n", parameters->width); + DBG (DBG_info_scan, " lines = %d\n", parameters->lines); + DBG (DBG_info_scan, " bytes = %d\n", parameters->bytes); + DBG (DBG_info_scan, " offset1 = %d\n", parameters->filterOffset1); + DBG (DBG_info_scan, " offset2 = %d\n", parameters->filterOffset2); + DBG (DBG_info_scan, " available lines = %d\n", parameters->availableLines); +#undef PARAMETER_SIZE +} + +/** + * Read INQUIRY block from device (SCSI command code 0x12). This block contains + * information about the properties of the scanner. + * Returns status->pieusb_status: + * - PIEUSB_STATUS_GOOD if the INQUIRY command succeeded + * - PIEUSB_STATUS_DEVICE_BUSY if device is busy after repeat retries + * - other SANE status code if INQUIRY failed or if it returned CHECK CONDITION + * and REQUEST SENSE failed + * + * @param device_number Device number + * @param data Input or output data buffer + * @param size Size of the data buffer + * @return Pieusb_Command_Status + * @see Pieusb_Scanner_Properties + */ +void +sanei_pieusb_cmd_inquiry(SANE_Int device_number, struct Pieusb_Scanner_Properties* inq, SANE_Byte size, struct Pieusb_Command_Status *status) +{ + SANE_Byte command[SCSI_COMMAND_LEN]; +#define INQUIRY_SIZE 256 + SANE_Byte data[INQUIRY_SIZE]; + int k; + + DBG (DBG_info_scan, "sanei_pieusb_cmd_inquiry()\n"); + + _prep_scsi_cmd (command, SCSI_INQUIRY, size); + memset (data, '\0', INQUIRY_SIZE); /* size may be less than INQUIRY_SIZE, so prevent returning noise */ + + status->pieusb_status = sanei_pieusb_command (device_number, command, data, size); + if (status->pieusb_status != PIEUSB_STATUS_GOOD) { + return; + } + + /* Decode data recieved */ + inq->deviceType = _get_byte(data, 0); + inq->additionalLength = _get_byte(data, 4); + _copy_bytes((SANE_Byte*)(inq->vendor), data+8, 8); /* Note: not 0-terminated */ + _copy_bytes((SANE_Byte*)(inq->product), data+16, 16); /* Note: not 0-terminated */ + _copy_bytes((SANE_Byte*)(inq->productRevision), data+32, 4); /* Note: not 0-terminated */ + /* 1st Vendor-specific block, 20 bytes, see pie_get_inquiry_values(), partially: */ + inq->maxResolutionX = _get_short(data, 36); + inq->maxResolutionY = _get_short(data, 38); + inq->maxScanWidth = _get_short(data, 40); + inq->maxScanHeight = _get_short(data, 42); + inq->filters = _get_byte(data, 44); + inq->colorDepths = _get_byte(data, 45); + inq->colorFormat = _get_byte(data, 46); + inq->imageFormat = _get_byte(data, 48); + inq->scanCapability = _get_byte(data, 49); + inq->optionalDevices = _get_byte(data, 50); + inq->enhancements = _get_byte(data, 51); + inq->gammaBits = _get_byte(data, 52); + inq->lastFilter = _get_byte(data, 53); + inq->previewScanResolution = _get_short(data, 54); + /* 2nd vendor specific block (36 bytes at offset 96) */ + _copy_bytes((SANE_Byte*)(inq->firmwareVersion), data+96, 4); inq->firmwareVersion[4]=0x00; + inq->halftones = _get_byte(data, 100); + inq->minumumHighlight = _get_byte(data, 101); + inq->maximumShadow = _get_byte(data, 102); + inq->calibrationEquation = _get_byte(data, 103); + inq->maximumExposure = _get_short(data ,104); + inq->minimumExposure = _get_short(data ,106); + inq->x0 = _get_short(data, 108); + inq->y0 = _get_short(data, 110); + inq->x1 = _get_short(data, 112); + inq->y1 = _get_short(data, 114); + inq->model = _get_short(data, 116); + _copy_bytes((SANE_Byte*)(inq->production), data+120, 4); + _copy_bytes((SANE_Byte*)(inq->timestamp), data+124, 20); + _copy_bytes((SANE_Byte*)(inq->signature), data+144, 40); + /* remove newline in signature */ + for (k=0; k<40; k++) if (inq->signature[k]==0x0a || inq->signature[k]==0x0d) inq->signature[k]=' '; +#undef INQUIRY_SIZE +} + +/** + * Set scan mode parameters, such as resolution, colors to scan, color depth, + * color format, and a couple of scan quality settings (sharpen, skip + * calibration, fast infrared). It performs the SCSI-command MODE SELECT, + * code 0x15. + * + * @param device_number Device number + * @param mode Mode parameters + * @return Pieusb_Command_Status + * @see Pieusb_Mode + */ +void +sanei_pieusb_cmd_set_mode(SANE_Int device_number, struct Pieusb_Mode* mode, struct Pieusb_Command_Status *status) +{ + SANE_Byte command[SCSI_COMMAND_LEN]; +#define MODE_SIZE 16 + SANE_Int size = MODE_SIZE; + SANE_Byte data[MODE_SIZE]; + SANE_Byte quality; + + DBG (DBG_info_scan, "sanei_pieusb_cmd_set_mode()\n"); + + _prep_scsi_cmd(command, SCSI_MODE_SELECT, size); + + DBG (DBG_info_scan, "sanei_pieusb_cmd_set_mode() set:\n"); + DBG (DBG_info_scan, " resolution = %d\n", mode->resolution); + DBG (DBG_info_scan, " passes = %02x\n", mode->passes); + DBG (DBG_info_scan, " depth = %02x\n", mode->colorDepth); + DBG (DBG_info_scan, " color format = %02x\n", mode->colorFormat); + DBG (DBG_info_scan, " sharpen = %d\n", mode->sharpen); + DBG (DBG_info_scan, " skip calibration = %d\n", mode->skipShadingAnalysis); + DBG (DBG_info_scan, " fast infrared = %d\n", mode->fastInfrared); + DBG (DBG_info_scan, " halftone pattern = %d\n", mode->halftonePattern); + DBG (DBG_info_scan, " line threshold = %d\n", mode->lineThreshold); + + /* Code data */ + /* cyberview + * 00 0f entries + * f4 01 resolution 500 + * 80 RGB (90: RGBI) + * 04 color depth (4: 8 bit, 20: 16 bit) + * 04 color format + * 00 + * 01 byte order + * 08 quality bitmask: 80=fast infrared, 08=skip shading analysis, 02=sharpen + * 00 00 + * 00 halftone pattern + * 80 line threshold + * 10 00 + * + * pieusb + * 0: 00 0f + * 2: e8 03 resolution 1000 + * 4: 80 passes + * 5: 04 color depth + * 6: 04 color format + * 7: 00 + * 8: 01 byte order + * 9: 02 quality bitmask: sharpen + * a: 00 00 + * c: 00 halftone pattern + * d: 7f line threshold + * e: 00 00 + */ + memset (data, '\0', size); + _set_byte (size-1, data, 1); + _set_short (mode->resolution, data, 2); + _set_byte (mode->passes, data, 4); + _set_byte (mode->colorDepth, data, 5); + _set_byte (mode->colorFormat, data, 6); + _set_byte (mode->byteOrder, data, 8); + quality = 0x00; + if (mode->sharpen) quality |= 0x02; + if (mode->skipShadingAnalysis) quality |= 0x08; + if (mode->fastInfrared) quality |= 0x80; + _set_byte (quality, data, 9); + _set_byte (mode->halftonePattern, data, 12); + _set_byte (mode->lineThreshold, data, 13); + _set_byte (0x10, data, 14); /* ? */ + + status->pieusb_status = sanei_pieusb_command (device_number, command, data, size); +#undef MODE_SIZE +} + +/* SCSI COPY, code 0x18 */ +/** + * Get the currently used CCD-mask, which defines which pixels have been used in + * the scan, and which allows to relate scan data to shading data. A mask is a + * 5340 byte array which consists only contains the values 0x00 and 0x70. A + * value of 0x00 indicates the pixel is used, a value of 0x70 that it is not.\n + * The number of 0x00 bytes equals the number of pixels on a line.\n + * The mask begins with a number of 0x70 bytes equal to the scan frame x0-value + * divided by 2.\n + * The SCSI-command COPY (code 0x18) is used for function. + * + * @param device_number Device number + * @param mask + * @return Pieusb_Command_Status + */ +void +sanei_pieusb_cmd_get_ccd_mask(SANE_Int device_number, SANE_Byte* mask, SANE_Int mask_size, struct Pieusb_Command_Status *status) +{ + SANE_Byte command[SCSI_COMMAND_LEN]; + + DBG (DBG_info_scan, "sanei_pieusb_cmd_get_ccd_mask()\n"); + + _prep_scsi_cmd (command, SCSI_COPY, mask_size); + + memset (mask, '\0', mask_size); + status->pieusb_status = sanei_pieusb_command (device_number, command, mask, mask_size); +} + +/** + * Get scan mode parameters, such as resolution, colors to scan, color depth, + * color format, and a couple of scan quality settings (sharpen, skip + * calibration, fast infrared). It performs the SCSI-command MODE SELECT, + * code 0x1A. + * + * @param device_number Device number + * @param mode Mode parameters + * @return Pieusb_Command_Status + * @see Pieusb_Mode + */ +void +sanei_pieusb_cmd_get_mode(SANE_Int device_number, struct Pieusb_Mode* mode, struct Pieusb_Command_Status *status) +{ + SANE_Byte command[SCSI_COMMAND_LEN]; +#define MODE_SIZE 16 + SANE_Int size = MODE_SIZE; + SANE_Byte data[MODE_SIZE]; + SANE_Byte quality; + + DBG (DBG_info_scan, "sanei_pieusb_cmd_get_mode()\n"); + + _prep_scsi_cmd (command, SCSI_MODE_SENSE, size); + memset (data, '\0', size); + + status->pieusb_status = sanei_pieusb_command(device_number, command, data, size); + if (status->pieusb_status != PIEUSB_STATUS_GOOD) { + return; + } + + /* Decode data recieved */ + mode->resolution = _get_short (data, 2); + mode->passes = _get_byte (data, 4); + mode->colorDepth = _get_byte (data, 5); + mode->colorFormat = _get_byte (data, 6); + mode->byteOrder = _get_byte (data, 8); + quality = _get_byte (data, 9); + mode->sharpen = (quality |= 0x02) ? SANE_TRUE : SANE_FALSE; + mode->skipShadingAnalysis = (quality |= 0x08) ? SANE_TRUE : SANE_FALSE; + mode->fastInfrared = (quality |= 0x80) ? SANE_TRUE : SANE_FALSE; + mode->halftonePattern = _get_byte (data, 12); + mode->lineThreshold = _get_byte (data, 13); + + DBG (DBG_info_scan, "cmdGetMode():\n"); + DBG (DBG_info_scan, " resolution = %d\n", mode->resolution); + DBG (DBG_info_scan, " passes = %02x\n", mode->passes); + DBG (DBG_info_scan, " depth = %02x\n", mode->colorDepth); + DBG (DBG_info_scan, " color format = %02x\n", mode->colorFormat); + DBG (DBG_info_scan, " sharpen = %d\n", mode->sharpen); + DBG (DBG_info_scan, " skip calibration = %d\n", mode->skipShadingAnalysis); + DBG (DBG_info_scan, " fast infrared = %d\n", mode->fastInfrared); + DBG (DBG_info_scan, " halftone pattern = %d\n", mode->halftonePattern); + DBG (DBG_info_scan, " line threshold = %d\n", mode->lineThreshold); +#undef MODE_SIZE +} + +/** + * Start a scan (SCSI SCAN command, code 0x1B, size byte = 0x01).\n + * There are four phases in a scan process. During each phase a limited number of + * commands is available. The phases are:\n + * 1. Calibration phase: make previously collected shading correction data available\n + * 2. Line-by-line scan & read phase\n + * 3. Output CCD-mask phase\n + * 4. Scan and output scan data phase\n + * + * The calibration phase is skipped if Pieusb_Mode.skipCalibration is set. If + * the scanner determines a calibration is necessary, a CHECK CONDIDITION response + * is returned. Available command during this phase:\n + * 1. sanei_pieusb_cmd_test_unit_ready()\n + * 2. sanei_pieusb_cmd_get_scanned_lines(): read shading correction lines\n + * 3. sanei_pieusb_cmd_stop_scan: abort scanning process\n + * 4. sanei_pieusb_cmd_get_gain_offset() : the settings are generated during the initialisation of this phase, so they are current\n + * 5. cmdSetSettings(): settings take effect in the next scan phase\n\n + * The line-by-line phase is only entered if Pieusb_Mode.div_10[0] bit 5 is + * set. It is not implemented.\n\n + * In the CCD-mask output phase the CCD-mask is read. Available command during this phase:\n + * 1. sanei_pieusb_cmd_test_unit_ready()\n + * 2. sanei_pieusb_cmd_get_ccd_mask()\n + * 3. sanei_pieusb_cmd_stop_scan: abort scanning process\n\n + * In the 'scan and output scan data' phase, the slide is scanned while data is + * read in the mean time. Available command during this phase:\n + * 1. sanei_pieusb_cmd_test_unit_ready()\n + * 2. sanei_pieusb_cmd_get_scanned_lines()\n + * 2. sanei_pieusb_cmd_get_parameters()\n + * 4. sanei_pieusb_cmd_stop_scan: abort scanning process\n + * + * @param device_number Device number + * @return Pieusb_Command_Status + */ +void +sanei_pieusb_cmd_start_scan(SANE_Int device_number, struct Pieusb_Command_Status *status) +{ + SANE_Byte command[SCSI_COMMAND_LEN]; + + DBG (DBG_info_scan, "sanei_pieusb_cmd_start_scan()\n"); + + _prep_scsi_cmd (command, SCSI_SCAN, 1); + + status->pieusb_status = sanei_pieusb_command (device_number, command, NULL, 0); +} + +/** + * Stop a scan started with sanei_pieusb_cmd_start_scan(). It issues a SCSI SCAN command, + * code 0x1B, with size byte = 0x00. + * + * @param device_number Device number + * @return Pieusb_Command_Status + */ +void +sanei_pieusb_cmd_stop_scan(SANE_Int device_number, struct Pieusb_Command_Status *status) +{ + SANE_Byte command[SCSI_COMMAND_LEN]; + + DBG (DBG_info_scan, "sanei_pieusb_cmd_stop_scan()\n"); + + _prep_scsi_cmd (command, SCSI_SCAN, 0); + + status->pieusb_status = sanei_pieusb_command (device_number, command, NULL, 0); +} + +/** + * Set scan head to a specific position, depending on the value for mode:\n + * mode = 1: Returns the scan head to the resting position, after a short move + * forward. If this command is left out between two scans, the second scan is + * up-down-mirrored, and scanning starts where the proevious scan stopped.\n + * mode = 2: Resets the scan head an then moves it forward depending on 'size', + * but it is a bit unpredictable to what position. The scanner may attempt to + * move the head past its physical end position. The mode is not implemented.\n + * mode = 3: This command positions the scan head to the start of the slide.\n + * mode = 4 or 5: The command forwards (4) or retreats (5) the scan head the + * given amount of steps (in size).\n + * The SCSI code is 0xD2, there is no related command name. + * + * @param device_number Device number + * @param mode + * @param size + * @return Pieusb_Command_Status + */ +void +sanei_pieusb_cmd_set_scan_head(SANE_Int device_number, SANE_Int mode, SANE_Int steps, struct Pieusb_Command_Status *status) +{ + SANE_Byte command[SCSI_COMMAND_LEN]; +#define SCAN_HEAD_SIZE 4 + SANE_Int size = SCAN_HEAD_SIZE; + SANE_Byte data[SCAN_HEAD_SIZE]; + + DBG (DBG_info_scan, "sanei_pieusb_cmd_set_scan_head()\n"); + + _prep_scsi_cmd (command, SCSI_SET_SCAN_HEAD, size); + + /* Code data */ + memset (data, '\0', size); + switch (mode) { + case 1: + data[0] = 2; + break; + case 2: + DBG (DBG_error, "sanei_pieusb_cmd_set_scan_head() mode 2 unreliable, possibly dangerous\n"); + status->pieusb_status = PIEUSB_STATUS_INVAL; + return; + case 3: + data[0] = 8; + break; + case 4: + data[0] = 0; /* forward */ + data[2] = (steps>>8) & 0xFF; + data[3] = steps & 0xFF; + break; + case 5: + data[0] = 1; /* backward */ + data[2] = (steps>>8) & 0xFF; + data[3] = steps & 0xFF; + break; + } + + status->pieusb_status = sanei_pieusb_command(device_number, command, data, size); +#undef SCAN_HEAD_SIZE +} + +/** + * Get internal scanner settings which have resulted from an auto-calibration + * procedure. This procedure only runs when calibrating (Scan phase 1), so the + * data returned are relatively static.\n + * The SCSI code is 0xD7, there is no related command name. + * + * @param device_number Device number + * @param settings Settings for gain and offset for the four colors RGBI + * @return Pieusb_Command_Status + * @see Pieusb_Settings + */ +void +sanei_pieusb_cmd_get_gain_offset(SANE_Int device_number, struct Pieusb_Settings* settings, struct Pieusb_Command_Status *status) +{ + SANE_Byte command[SCSI_COMMAND_LEN]; +#define GAIN_OFFSET_SIZE 103 + SANE_Int size = GAIN_OFFSET_SIZE; + SANE_Byte data[GAIN_OFFSET_SIZE]; + int k; + SANE_Byte val[3]; + + DBG (DBG_info_scan, "sanei_pieusb_cmd_get_gain_offset()\n"); + + _prep_scsi_cmd (command, SCSI_READ_GAIN_OFFSET, size); + + memset (data, '\0', size); + status->pieusb_status = sanei_pieusb_command(device_number, command, data, size); + if (status->pieusb_status != PIEUSB_STATUS_GOOD) { + return; + } + + /* Decode data received */ + _get_shorts (settings->saturationLevel, data+54, 3); + _get_shorts (settings->exposureTime, data+60, 3); + _copy_bytes (val, data+66, 3); + for (k = 0; k < 3; k++) settings->offset[k] = val[k]; + _copy_bytes (val, data+72, 3); + for (k = 0; k < 3; k++) settings->gain[k] = val[k]; + settings->light = _get_byte (data, 75); + settings->exposureTime[3] = _get_short (data, 98); + settings->offset[3] = _get_byte (data, 100); + settings->gain[3] = _get_byte (data, 102); + + DBG (DBG_info, "sanei_pieusb_cmd_get_gain_offset() set:\n"); + DBG (DBG_info, " saturationlevels = %d-%d-%d\n", settings->saturationLevel[0], settings->saturationLevel[1], settings->saturationLevel[2]); + DBG (DBG_info, " ---\n"); + DBG (DBG_info, " exposure times = %d-%d-%d-%d\n", settings->exposureTime[0], settings->exposureTime[1], settings->exposureTime[2], settings->exposureTime[3]); + DBG (DBG_info, " gain = %d-%d-%d-%d\n", settings->gain[0], settings->gain[1], settings->gain[2], settings->gain[3]); + DBG (DBG_info, " offset = %d-%d-%d-%d\n", settings->offset[0], settings->offset[1], settings->offset[2], settings->offset[3]); + DBG (DBG_info, " light = %02x\n", settings->light); + DBG (DBG_info, " double times = %02x\n", settings->doubleTimes); + DBG (DBG_info, " extra entries = %02x\n", settings->extraEntries); +#undef GAIN_OFFSET_SIZE +} + + +/** + * Set internal scanner settings such as gain and offset.\n + * There are two effective moments for this command:\n + * 1. For a scan without calibration phase: before the sanei_pieusb_cmd_start_scan() command; + * 2. For a sccan with calibration phase: before (or during) reading the shading reference data. + * The SCSI code is 0xDC, there is no related command name. + * + * @param device_number Device number + * @param settings Settings for gain and offset for the four colors RGBI + * @return Pieusb_Command_Status + * @see Pieusb_Settings + */ +void +sanei_pieusb_cmd_set_gain_offset(SANE_Int device_number, struct Pieusb_Settings* settings, struct Pieusb_Command_Status *status) +{ + SANE_Byte command[SCSI_COMMAND_LEN]; +#define GAIN_OFFSET_SIZE 29 + SANE_Int size = GAIN_OFFSET_SIZE; + SANE_Byte data[GAIN_OFFSET_SIZE]; + int k; + SANE_Byte val[3]; + + DBG (DBG_info_scan, "sanei_pieusb_cmd_set_gain_offset()\n"); + + _prep_scsi_cmd (command, SCSI_WRITE_GAIN_OFFSET, size); + + DBG (DBG_info, "sanei_pieusb_cmd_set_gain_offset() set:\n"); + DBG (DBG_info, " exposure times = %d-%d-%d-%d\n", settings->exposureTime[0], settings->exposureTime[1], settings->exposureTime[2], settings->exposureTime[3]); + DBG (DBG_info, " gain = %d-%d-%d-%d\n", settings->gain[0], settings->gain[1], settings->gain[2], settings->gain[3]); + DBG (DBG_info, " offset = %d-%d-%d-%d\n", settings->offset[0], settings->offset[1], settings->offset[2], settings->offset[3]); + DBG (DBG_info, " light = %02x\n", settings->light); + DBG (DBG_info, " double times = %02x\n", settings->doubleTimes); + DBG (DBG_info, " extra entries = %02x\n", settings->extraEntries); + + /* Code data */ + memset (data, '\0', size); + _set_shorts (settings->exposureTime, data, 3); + for (k = 0; k < 3; k++) { + val[k] = settings->offset[k]; + } + _copy_bytes (data + 6, val, 3); + for (k = 0; k < 3; k++) { + val[k] = settings->gain[k]; + } + _copy_bytes (data + 12, val, 3); + _set_byte (settings->light, data, 15); + _set_byte (settings->extraEntries, data, 16); + _set_byte (settings->doubleTimes, data, 17); + _set_short (settings->exposureTime[3], data, 18); + _set_byte (settings->offset[3], data, 20); + _set_byte (settings->gain[3], data, 22); + /* + * pieusb-get_gain_offset: + * 00000000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + * 00000010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + * 00000020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + * 00000030: a9 00 88 00 b1 00 00 00 00 00 00 00 04 10 04 10 )...1........... + * 00000040: 04 10 53 4f 6e 00 00 00 2e 21 21 05 04 10 df 2d ..SOn....!!..._- + * 00000050: a3 5c e7 f2 a1 2c b3 c4 42 df 32 42 eb 82 8e e0 #\gr!,3DB_2Bk..` + * 00000060: 87 be 04 10 4f 00 2c .>..O., + * + * cyberview: + * 00000000: 65 22 57 18 19 19 - exposure time RGB + * 00000006: 51 4e 6a - offset RGB + * 00000009: 00 00 00 + * 0000000c: 21 21 21 - gain RGB + * 0000000f: 05 - light + * 00000010: 01 - extra entries + * 00000011: 00 - double times + * 00000012: 04 10 - exposure time I + * 00000014: 4e 00 - offset I + * 00000016: 2a - gain I + * 00000017: 00 00 00 00 00 00 + * + * pieusb: + * 00000000: 04 10 04 10 04 10 - exposure time RGB + * 00000006: 53 4f 6e - offset RGB + * 00000009: 00 00 00 + * 0000000c: 2e 21 21 - gain RGB + * 0000000f: 05 - light + * 00000010: 00 - extra entries + * 00000011: 00 - double times + * 00000012: 04 10 - exposure time I + * 00000014: 4f 00 - offset I + * 00000016: 2c - gain I + * 00000017: 00 00 00 00 00 00 + */ + + status->pieusb_status = sanei_pieusb_command(device_number, command, data, size); +#undef GAIN_OFFSET_SIZE +} + +/** + * Get scanner state information: button pushed, + * warming up, scanning. + * + * @param device_number Device number + * @param state State information + * @return Pieusb_Command_Status + */ +void +sanei_pieusb_cmd_read_state(SANE_Int device_number, struct Pieusb_Scanner_State* state, struct Pieusb_Command_Status *status) +{ + SANE_Byte command[SCSI_COMMAND_LEN]; +#define GET_STATE_SIZE 12 + SANE_Byte data[GET_STATE_SIZE]; + SANE_Int size = GET_STATE_SIZE; + + /* Execute READ STATUS command */ + DBG (DBG_info_scan, "sanei_pieusb_cmd_read_state()\n"); + + _prep_scsi_cmd (command, SCSI_READ_STATE, size); + + memset (data, '\0', size); + status->pieusb_status = sanei_pieusb_command (device_number, command, data, size); + + if (status->pieusb_status == PIEUSB_STATUS_WARMING_UP + || status->pieusb_status == PIEUSB_STATUS_DEVICE_BUSY) { + data[5] = 1; + status->pieusb_status = PIEUSB_STATUS_GOOD; + } + /* Decode data recieved */ + state->buttonPushed = _get_byte(data, 0); + state->warmingUp = _get_byte(data, 5); + state->scanning = _get_byte(data, 6); +/* state->busy = _get_byte(data, 8); */ + DBG (DBG_info_scan, "sanei_pieusb_cmd_read_state(): button %d, warmingUp %d, scanning %d, busy? %d\n", state->buttonPushed, state->warmingUp, state->scanning, _get_byte(data, 8)); +#undef GET_STATE_SIZE +} + +/** + * Prepare SCSI_COMMAND_LEN-byte command array with command code and size value + * + * @param command + * @param code + * @param size + */ +static void +_prep_scsi_cmd(SANE_Byte* command, SANE_Byte code, SANE_Word size) +{ + memset(command, '\0', SCSI_COMMAND_LEN); + command[0] = code; + command[3] = (size>>8) & 0xFF; /* lsb first */ + command[4] = size & 0xFF; +} diff --git a/backend/pieusb_scancmd.h b/backend/pieusb_scancmd.h new file mode 100644 index 0000000..0dee646 --- /dev/null +++ b/backend/pieusb_scancmd.h @@ -0,0 +1,378 @@ +/* sane - Scanner Access Now Easy. + + pieusb_scancmd.h + + Copyright (C) 2012-2015 Jan Vleeshouwers, Michael Rickmann, Klaus Kaempf + + This file is part of the SANE package. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA. + + As a special exception, the authors of SANE give permission for + additional uses of the libraries contained in this release of SANE. + + The exception is that, if you link a SANE library with other files + to produce an executable, this does not by itself cause the + resulting executable to be covered by the GNU General Public + License. Your use of that executable is in no way restricted on + account of linking the SANE library code into it. + + This exception does not, however, invalidate any other reasons why + the executable file might be covered by the GNU General Public + License. + + If you submit changes to SANE to the maintainers to be included in + a subsequent release, you agree by submitting the changes that + those changes may be distributed with this exception intact. + + If you write modifications of your own for SANE, it is your choice + whether to permit this exception to apply to your modifications. + If you do not wish that, delete this exception notice. */ + +#ifndef PIEUSB_SCANCMD_H +#define PIEUSB_SCANCMD_H + +#include "../include/sane/sane.h" + +/* ========================================================================= + * + * Data-structures used by scanner commands + * + * For SENSE descriptions, see SCSI-2 p158, table 67 (p469 ASC/Q alphabetically) + * For the INQUIRY command, see SCSI-2 p141 table 45, 46, 47 + * + * 2-byte short ints are represented by 4-byte SANE_Int types + * + * ========================================================================= */ + +struct Pieusb_Scanner_Properties { + SANE_Byte deviceType; /* 0x06 = scanner */ + SANE_Byte additionalLength; /* including this byte: 0xb4 = 180, so total structure 184 bytes */ + SANE_Char vendor[9]; /* actually 8 bytes, not null-terminated ...PIE ... */ + SANE_Char product[17]; /* actually 16 bytes, null-terminated ...SF Scanner... */ + SANE_Char productRevision[5]; /* actually 4 bytes, not null-terminated ...1.70... */ + /* 1st Vendor-specific block, 20 bytes, see pie_get_inquiry_values(), partially: */ + SANE_Int maxResolutionX; /* 7200 maximum scan resolution in x direction */ + SANE_Int maxResolutionY; /* 7200 maximum scan resolution in y direction */ + SANE_Int maxScanWidth; /* 10680 flatbed_max_scan_width (& calibration block size) */ + SANE_Int maxScanHeight; /* 6888 flatbed_max_scan_height */ + SANE_Byte filters; /* 0x9e = 10011110 ?-0-0-OnePassColor-B-G-R-N => additional infrared? */ + SANE_Byte colorDepths; /* 0x35 = 00110101 0-0-16-12-10-8-4-1 */ + SANE_Byte colorFormat; /* 0x07 = 00000111 0-0-0-0-0-Index-Line-Pixel */ + SANE_Byte imageFormat; /* 0x09 = 00001001 0-0-0-0-OKLine-BlkOne-Motorola-Intel */ + SANE_Byte scanCapability; + /* 0x4b = 01001011 PowerSave-ExtCal-0-FastPreview-DisableCal-[CalSpeeds=3] + * PowerSave: no + * ExtCal: yes => + * FastPreview: no + * DisableCal: yes => can calibration be disabled? + * CalSpeeds: 3 => 1 line, 13 lines, 31 lines */ + SANE_Byte optionalDevices; + /* 0x61 = 01100001 MultiPageLoad-?-?-0-0-TransModule1-TransModule-AutoDocFeeder => additional? + * MultiPageLoad: no + * ?: yes + * ?: yes + * TransModule1: no + * TransModule: no + * AutoDocFeeder: yes */ + SANE_Byte enhancements; /* 0x02 = no info in pie.c */ + SANE_Byte gammaBits; /* 0x0c = 00001100 = 12 ? used when downloading gamma table ... does not happen */ + SANE_Byte lastFilter; /* 0x00 = ? no info in pie.c, not used */ + SANE_Int previewScanResolution; /* 0x2c01 = 300 fast preview scan resolution */ + /* Reserved (56-95) */ + /* SANE_Byte div_56[40]; */ + /* 2nd vendor specific block (36 bytes at offset 96) */ + SANE_Char firmwareVersion[5]; /* actually 4 bytes, not null terminated "1.05" */ + SANE_Byte halftones; /* 0x08 = halftones (4 LSbits) = 00001000 ? */ + SANE_Byte minumumHighlight; /* 0x64 = 100 */ + SANE_Byte maximumShadow; /* 0x64 = 100 */ + SANE_Byte calibrationEquation; /* 0x01 ? see pie_perform_cal() */ + SANE_Int maximumExposure; /* 0xc409 = 2500 (units?) */ + SANE_Int minimumExposure; /* 0x6400 = 100 (units?) */ + SANE_Int x0; /* 0xd002 = 720 transparency top left x */ + SANE_Int y0; /* 0x8604 = 1158 transparency top left y */ + SANE_Int x1; /* 0xbc10 = 4284 transparency bottom right x */ + SANE_Int y1; /* 0xc015 = 5568 transparency bottom right y */ + SANE_Int model; /* 0x3000 => model number */ + /* SANE_Int div_118; 0x0000 meaning? */ + SANE_Char production[4]; /* null terminated */ + SANE_Char timestamp[20]; /* null terminated */ + SANE_Byte signature[40]; /* null terminated */ +}; + +struct Pieusb_Sense { + /* 14 bytes according to SCSI-2 p158, table 67 (p469 ASC/Q alphabetically) */ + SANE_Byte errorCode; /* 0x70 or 0x71 */ + SANE_Byte segment; + SANE_Byte senseKey; /* sense key is actually this value & 0x0F - table 69 */ + SANE_Byte info[4]; + SANE_Byte addLength; /* should be 0x07 (remaining struct length including this byte) */ + SANE_Byte cmdInfo[4]; /* command specific information */ + SANE_Byte senseCode; /* abbreviated ASC - table 71 */ + SANE_Byte senseQualifier; /* abbreviated ASCQ - table 71 */ +}; + +struct Pieusb_Scanner_State { + SANE_Byte buttonPushed; /* 0x01 if pushed */ + SANE_Byte warmingUp; /* 0x01 if warming up, 0x00 if not */ + SANE_Byte scanning; /* bit 6 set if SCAN active, bit 7 motor direction inverted (not analysed in detail) */ +}; + +struct Pieusb_Scan_Parameters { + SANE_Int width; /* Number of pixels on a scan line */ + SANE_Int lines; /* Number of lines in the scan. Value depends on color format, see Pieusb_Mode. */ + SANE_Int bytes; /* Number of bytes on a scan line. Value depends on color format. */ + SANE_Byte filterOffset1; /* 0x08 in the logs, but may also be set to 0x16, they seem to be used in “line”-format only. */ + SANE_Byte filterOffset2; /* 0x08 in the logs, but may also be set to 0x16, they seem to be used in “line”-format only. */ + SANE_Int period; /* Seems to be unused */ + SANE_Int scsiTransferRate; /* Don't use, values cannot be trusted */ + SANE_Int availableLines; /* The number of currently available scanned lines. Value depends on color format. Returns a value >0 if PARAM is called while scanning is in progress */ + SANE_Byte motor; /* Motor direction in bit 0 */ +}; + +struct Pieusb_Mode { + /* SANE_Byte size; of remaining data, not useful */ + SANE_Int resolution; /* in dpi */ + SANE_Byte passes; + /* 0x80 = One pass color; 0x90 = One pass RGBI; + * bit 7 : one-pass-color bit (equivalent to RGB all set?) + * bit 6 & 5: unused + * bit 4 : Infrared + * bit 3 : Blue + * bit 2 : Green + * bit 1 : Red + * bit 0: Neutral (not supported, ignored) */ + SANE_Byte colorDepth; + /* 0x04 = 8, 0x20 = 16 bit + * bit 7 & 6 : 0 (unused) + * bit 5 : 16 bit + * bit 4 : 12 bit + * bit 3 : 10 bit + * bit 2 : 8 bit + * bit 1 : 4 bit + * bit 0 : 1 bit */ + SANE_Byte colorFormat; + /* 0x04 = index, cf. INQUIRY + * bit 7-3 : 0 (unused) + * bit 2 : Index = scanned data are lines preceeded by a two-byte index, 'RR', 'GG', 'BB', or 'II' + * bit 1 : Line = scanned data are (probably) lines in RGBI order (needs testing) + * bit 0 : Pixel = scanned data are always RGB-pixels, i.e. 3x2 bytes at depth = 16 bits, 3 bytes + * at depth = 8 bits, and 3 packed bytes at depth = 1. This is also the case in + * a single color or gray scale scan; in these cases only the first pixel contains + * valid data. */ + SANE_Byte byteOrder; /* 0x01 = Intel; only bit 0 used */ + SANE_Bool sharpen; /* byte 9 bit 1 */ + SANE_Bool skipShadingAnalysis; /* byte 9 bit 3 */ + SANE_Bool fastInfrared; /* byte 9 bit 7 */ + /* bit 7 : “fast infrared” flag + * bit 6,5,4 : 0 (unused) + * bit 3 : “skip calibration” flag (skip collecting shading information) + * bit 2 : 0 (unused) + * bit 1 : “sharpen” flag (only effective with fastInfrared off, one-pass-color and no extra BADF-entries) + * bit 0 : 0 (unused) */ + SANE_Byte halftonePattern; /* 0x00 = no halftone pattern */ + SANE_Byte lineThreshold; /* 0xFF = 100% */ +}; + +struct Pieusb_Settings { + SANE_Int saturationLevel[3]; + /* The average pixel values for the three colors Red, Green and Blue, + * which are the result of optimizing the Timer 1 counts so that Red and + * Blue values are least 90% of full scale (58981) and the Green value is + * at least 80% (52428). These levels are only determined during warming up. */ + SANE_Int exposureTime[4]; + /* Optimized exposure times for Red, Green and Blue. The exposure times are + * Timer 1 counts which define when Timer 1 interrupts. These values are + * only determined at startup. + * Exposure time for Infrared. The value is optimized and set at startup + * with the other exposure times. Quite often, it is subsequently reset to + * a default value (0x0B79). */ + SANE_Word offset[4]; + /* Optimized offsets for Red, Green and Blue. See above. These values are + * also updated before outputting the CCD-mask. + * Element 4 is offset for Infrared. */ + SANE_Word gain[4]; + /* Optimized gains for Red, Green and Blue. See the remark for + * exposureTime above. Element 4 is gain for Infrared. */ + SANE_Byte light; + /* Current light level. The stability of the light source is tested during + * warming up. The check starts with a light value 7 or 6, and decrements + * it when the light warms up. At a light value of 4, the scanner produces + * stable scans (i.e. successive “white” scan values don't differ more + * than 0x200). */ + SANE_Int minimumExposureTime; + /* Fixed value: 0x0b79 (2937) */ + SANE_Byte extraEntries; + SANE_Byte doubleTimes; + /* Originally 20 unused bytes (uninitialized memory) + * To complete the mapping to the Pieusb_Settings_Condensed struct, + * the last two bytes are given an explicit meaning. */ + /* SANE_Int exposureTimeIR; */ + /* SANE_Byte offsetIR; */ + /* SANE_Byte gainIR; */ +}; + +/* Not used, Pieusb_Settings contains the same fields (after a bit of juggling) */ +struct Pieusb_Settings_Condensed { + SANE_Int exposureTime[4]; /* => Pieusb_Settings.exposureTime */ + SANE_Byte offset[4]; /* => Pieusb_Settings.offset */ + SANE_Byte gain[4]; /* => Pieusb_Settings.gain */ + SANE_Byte light; /* => Pieusb_Settings.light */ + SANE_Byte extraEntries; /* => Pieusb_Settings.extraEntries */ + SANE_Byte doubleTimes; /* => Pieusb_Settings.doubleTimes */ +}; + +struct Pieusb_Halftone_Pattern { + SANE_Int code; /* 0x91 */ + /*TODO */ +}; + +struct Pieusb_Scan_Frame { + SANE_Int index; /* scan frame index (0-7) */ + SANE_Int x0; /* top left, is origin */ + SANE_Int y0; + SANE_Int x1; /* bottom right */ + SANE_Int y1; +}; + +struct Pieusb_Exposure_Time_Color { + SANE_Int filter; /* color mask 0x02, 0x04 or 0x08 for R, G, B */ + SANE_Int value; /* relative exposure time 0 - 100 */ +}; + +struct Pieusb_Exposure_Time { + SANE_Int code; /* 0x93 */ + SANE_Int size; /* number of bytes in rest of structure */ + struct Pieusb_Exposure_Time_Color color[3]; /* not all elements may actually be used */ +}; + +struct Pieusb_Highlight_Shadow_Color { + SANE_Int filter; /* color mask 0x02, 0x04 or 0x08 for R, G, B */ + SANE_Int value; /* 0-100 */ +}; + +struct Pieusb_Highlight_Shadow { + SANE_Int code; /* 0x94 */ + SANE_Int size; /* number of bytes in rest of structure */ + struct Pieusb_Highlight_Shadow_Color color[3]; +}; + +struct Pieusb_Shading_Parameters_Info { + SANE_Byte type; /* 0x00, 0x08, 0x10, 0x20; RGBI(?) */ + SANE_Byte sendBits; /* 0x10 = 16 */ + SANE_Byte recieveBits; /* 0x10 = 16 */ + SANE_Byte nLines; /* 0x2D = 45 */ + SANE_Int pixelsPerLine; /* 0x14dc = 5340 */ +}; + +#define SHADING_PARAMETERS_INFO_COUNT 4 +struct Pieusb_Shading_Parameters { + SANE_Byte code; /* 0x95 */ + SANE_Int size; /* number of bytes in rest of structure (0x1c=28) */ + SANE_Byte calInfoCount; /* number of individual info structures (=0x04) */ + SANE_Byte calInfoSize; /* size of individual info structure (=0x06) */ + SANE_Int div_6; /* 0x0004, meaning not clear */ + struct Pieusb_Shading_Parameters_Info cal[SHADING_PARAMETERS_INFO_COUNT]; +}; + +typedef enum { + PIEUSB_STATUS_GOOD = 0, /* 0 everything A-OK */ + PIEUSB_STATUS_UNSUPPORTED, /* 1 operation is not supported */ + PIEUSB_STATUS_CANCELLED, /* 2 operation was cancelled */ + PIEUSB_STATUS_DEVICE_BUSY, /* 3 device is busy; try again later */ + PIEUSB_STATUS_INVAL, /* 4 data is invalid (includes no dev at open) */ + PIEUSB_STATUS_EOF, /* 5 no more data available (end-of-file) */ + PIEUSB_STATUS_JAMMED, /* 6 document feeder jammed */ + PIEUSB_STATUS_NO_DOCS, /* 7 document feeder out of documents */ + PIEUSB_STATUS_COVER_OPEN, /* 8 scanner cover is open */ + PIEUSB_STATUS_IO_ERROR, /* 9 error during device I/O */ + PIEUSB_STATUS_NO_MEM, /* 10 out of memory */ + PIEUSB_STATUS_ACCESS_DENIED, /* 11 access to resource has been denied */ + PIEUSB_STATUS_WARMING_UP, /* 12 lamp not ready, please retry */ + PIEUSB_STATUS_HW_LOCKED, /* 13 scanner mechanism locked for transport */ + PIEUSB_STATUS_MUST_CALIBRATE /* 14 */ +} PIEUSB_Status; + +/* Structures used by the USB functions */ + +struct Pieusb_Command_Status { + PIEUSB_Status pieusb_status; + SANE_Byte senseKey; /* sense key: see Pieusb_Sense */ + SANE_Byte senseCode; /* sense code */ + SANE_Byte senseQualifier; /* sense code qualifier */ +}; + +typedef struct Pieusb_Scanner_Properties Pieusb_Scanner_Properties; + +typedef enum { + SLIDE_NEXT = 0x04, SLIDE_PREV = 0x05, SLIDE_LAMP_ON = 0x10, SLIDE_RELOAD = 0x40 +} slide_action; + +void sanei_pieusb_cmd_slide(SANE_Int device_number, slide_action action, struct Pieusb_Command_Status *status); + +/* Scanner commands */ + +void sanei_pieusb_cmd_test_unit_ready(SANE_Int device_number, struct Pieusb_Command_Status *status); + +void sanei_pieusb_cmd_get_sense(SANE_Int device_number, struct Pieusb_Sense* sense, struct Pieusb_Command_Status *status, PIEUSB_Status *ret); + +void sanei_pieusb_cmd_get_halftone_pattern(SANE_Int device_number, SANE_Int index, struct Pieusb_Halftone_Pattern* pattern, struct Pieusb_Command_Status *status); +void sanei_pieusb_cmd_set_halftone_pattern(SANE_Int device_number, SANE_Int index, struct Pieusb_Halftone_Pattern* pattern, struct Pieusb_Command_Status *status); + +void sanei_pieusb_cmd_get_scan_frame(SANE_Int device_number, SANE_Int index, struct Pieusb_Scan_Frame* frame, struct Pieusb_Command_Status *status); +void sanei_pieusb_cmd_set_scan_frame(SANE_Int device_number, SANE_Int index, struct Pieusb_Scan_Frame* frame, struct Pieusb_Command_Status *status); + +void sanei_pieusb_cmd_17(SANE_Int device_number, SANE_Int value, struct Pieusb_Command_Status *status); + +void sanei_pieusb_cmd_get_exposure_time(SANE_Int device_number, SANE_Int colorbits, struct Pieusb_Exposure_Time* time, struct Pieusb_Command_Status *status); +void sanei_pieusb_cmd_set_exposure_time(SANE_Int device_number, struct Pieusb_Exposure_Time* time, struct Pieusb_Command_Status *status); + +void sanei_pieusb_cmd_get_highlight_shadow(SANE_Int device_number, SANE_Int colorbits, struct Pieusb_Highlight_Shadow* hgltshdw, struct Pieusb_Command_Status *status); +void sanei_pieusb_cmd_set_highlight_shadow(SANE_Int device_number, struct Pieusb_Highlight_Shadow* hgltshdw, struct Pieusb_Command_Status *status); + +void sanei_pieusb_cmd_get_shading_parms(SANE_Int device_number, struct Pieusb_Shading_Parameters_Info* shading, struct Pieusb_Command_Status *status); +void sanei_pieusb_cmd_get_scanned_lines(SANE_Int device_number, SANE_Byte* data, SANE_Int lines, SANE_Int size, struct Pieusb_Command_Status *status); + +void sanei_pieusb_cmd_get_ccd_mask(SANE_Int device_number, SANE_Byte* mask, SANE_Int mask_size, struct Pieusb_Command_Status *status); +void sanei_pieusb_cmd_set_ccd_mask(SANE_Int device_number, SANE_Byte colorbits, SANE_Byte* mask, SANE_Int mask_size, struct Pieusb_Command_Status *status); + +/* +void cmdPrepareHalftonePattern(SANE_Int device_number, SANE_Int index, struct Pieusb_Command_Status *status); +void cmdPrepareScanFrame(SANE_Int device_number, SANE_Int index, struct Pieusb_Command_Status *status); +void cmdPrepareRelativeExposureTime(SANE_Int device_number, SANE_Int colorbits, struct Pieusb_Command_Status *status); +void cmdPrepareHighlightShadow(SANE_Int device_number, SANE_Int colorbits, struct Pieusb_Command_Status *status); +void cmdPrepareShadingParameters(SANE_Int device_number, struct Pieusb_Command_Status *status); +*/ + +void sanei_pieusb_cmd_get_parameters(SANE_Int device_number, struct Pieusb_Scan_Parameters* parameters, struct Pieusb_Command_Status *status); + +void sanei_pieusb_cmd_inquiry(SANE_Int device_number, struct Pieusb_Scanner_Properties* inq, SANE_Byte size, struct Pieusb_Command_Status *status); + +void sanei_pieusb_cmd_get_mode(SANE_Int device_number, struct Pieusb_Mode* mode, struct Pieusb_Command_Status *status); +void sanei_pieusb_cmd_set_mode(SANE_Int device_number, struct Pieusb_Mode* mode, struct Pieusb_Command_Status *status); + +void sanei_pieusb_cmd_start_scan(SANE_Int device_number, struct Pieusb_Command_Status *status); +void sanei_pieusb_cmd_stop_scan(SANE_Int device_number, struct Pieusb_Command_Status *status); + +void sanei_pieusb_cmd_set_scan_head(SANE_Int device_number, SANE_Int mode, SANE_Int steps, struct Pieusb_Command_Status *status); + +void sanei_pieusb_cmd_get_gain_offset(SANE_Int device_number, struct Pieusb_Settings* settings, struct Pieusb_Command_Status *status); + +void sanei_pieusb_cmd_set_gain_offset(SANE_Int device_number, struct Pieusb_Settings* settings, struct Pieusb_Command_Status *status); + +void sanei_pieusb_cmd_read_state(SANE_Int device_number, struct Pieusb_Scanner_State* state, struct Pieusb_Command_Status *status); + +#endif /* PIEUSB_SCANCMD_H */ diff --git a/backend/pieusb_specific.c b/backend/pieusb_specific.c new file mode 100644 index 0000000..8231075 --- /dev/null +++ b/backend/pieusb_specific.c @@ -0,0 +1,2509 @@ +/* sane - Scanner Access Now Easy. + + pieusb_specific.c + + Copyright (C) 2012-2015 Jan Vleeshouwers, Michael Rickmann, Klaus Kaempf + + This file is part of the SANE package. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA. + + As a special exception, the authors of SANE give permission for + additional uses of the libraries contained in this release of SANE. + + The exception is that, if you link a SANE library with other files + to produce an executable, this does not by itself cause the + resulting executable to be covered by the GNU General Public + License. Your use of that executable is in no way restricted on + account of linking the SANE library code into it. + + This exception does not, however, invalidate any other reasons why + the executable file might be covered by the GNU General Public + License. + + If you submit changes to SANE to the maintainers to be included in + a subsequent release, you agree by submitting the changes that + those changes may be distributed with this exception intact. + + If you write modifications of your own for SANE, it is your choice + whether to permit this exception to apply to your modifications. + If you do not wish that, delete this exception notice. */ + +/* ========================================================================= + * + * Various Pieusb backend specific functions + * + * Option handling, configuration file handling, post-processing + * + * ========================================================================= */ + +#define DEBUG_DECLARE_ONLY +#include "pieusb.h" + +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include "../include/sane/sane.h" +#include "../include/sane/saneopts.h" +#include "../include/sane/sanei_config.h" + +#include <errno.h> +#include <math.h> +#include <time.h> + +#include "pieusb_usb.h" +#include "pieusb_scancmd.h" +#include "pieusb_buffer.h" +#include "pieusb_specific.h" + +/* Pieusb specific */ + +/* sub to sanei_pieusb_find_device_callback() */ +static SANE_Status pieusb_initialize_device_definition (Pieusb_Device_Definition* dev, Pieusb_Scanner_Properties* inq, const char* devicename, SANE_Word vendor_id, SANE_Word product_id); +static void pieusb_print_inquiry (Pieusb_Device_Definition * dev); + +/* sub to sane_start() */ +static void pieusb_calculate_shading(struct Pieusb_Scanner *scanner, SANE_Byte* buffer); + +/* MR */ +/* sub to sanei_pieusb_post() */ +static SANE_Status pieusb_write_pnm_file (char *filename, uint16_t *data, int depth, int channels, int pixels_per_line, int lines); + +/* Auxilary */ +static size_t max_string_size (SANE_String_Const const strings[]); +static double getGain(int gain); +static int getGainSetting(double gain); +/* +static void updateGain(Pieusb_Scanner *scanner, int color_index); +*/ +static void updateGain2(Pieusb_Scanner *scanner, int color_index, double gain_increase); + +/* -------------------------------------------------------------------------- + * + * SPECIFIC PIEUSB + * + * --------------------------------------------------------------------------*/ + +/* Settings for byte order */ +#define SCAN_IMG_FMT_OKLINE 0x08 +#define SCAN_IMG_FMT_BLK_ONE 0x04 +#define SCAN_IMG_FMT_MOTOROLA 0x02 +#define SCAN_IMG_FMT_INTEL 0x01 + +/* Settings for scanner capabilities */ +#define SCAN_CAP_PWRSAV 0x80 +#define SCAN_CAP_EXT_CAL 0x40 +#define SCAN_CAP_FAST_PREVIEW 0x10 +#define SCAN_CAP_DISABLE_CAL 0x08 +#define SCAN_CAP_SPEEDS 0x07 + +/* Available scanner options */ +#define SCAN_OPT_DEV_MPCL 0x80 +#define SCAN_OPT_DEV_TP1 0x04 +#define SCAN_OPT_DEV_TP 0x02 +#define SCAN_OPT_DEV_ADF 0x01 + +/* Options */ +#define SANE_NAME_EXPOSURE_R "exposure-time-r" +#define SANE_TITLE_EXPOSURE_R "Exposure time red" +#define SANE_DESC_EXPOSURE_R "The time the red color filter of the CCD is exposed" +#define SANE_NAME_EXPOSURE_G "exposure-time-g" +#define SANE_TITLE_EXPOSURE_G "Exposure time green" +#define SANE_DESC_EXPOSURE_G "The time the green color filter of the CCD is exposed" +#define SANE_NAME_EXPOSURE_B "exposure-time-b" +#define SANE_TITLE_EXPOSURE_B "Exposure time blue" +#define SANE_DESC_EXPOSURE_B "The time the blue color filter of the CCD is exposed" +#define SANE_NAME_EXPOSURE_I "exposure-time-i" +#define SANE_TITLE_EXPOSURE_I "Exposure time infrared" +#define SANE_DESC_EXPOSURE_I "The time the infrared color filter of the CCD is exposed" +#define SANE_EXPOSURE_DEFAULT DEFAULT_EXPOSURE +#if 1 +#define SANE_NAME_GAIN_R "gain-r" +#define SANE_TITLE_GAIN_R "Gain red" +#define SANE_DESC_GAIN_R "The gain of the signal processor for red" +#define SANE_NAME_GAIN_G "gain-g" +#define SANE_TITLE_GAIN_G "Gain green" +#define SANE_DESC_GAIN_G "The gain of the signal processor for green" +#define SANE_NAME_GAIN_B "gain-b" +#define SANE_TITLE_GAIN_B "Gain blue" +#define SANE_DESC_GAIN_B "The gain of the signal processor for blue" +#define SANE_NAME_GAIN_I "gain-i" +#define SANE_TITLE_GAIN_I "Gain infrared" +#define SANE_DESC_GAIN_I "The gain of the signal processor for infrared" +#define SANE_GAIN_DEFAULT DEFAULT_GAIN + +#define SANE_NAME_OFFSET_R "offset-r" +#define SANE_TITLE_OFFSET_R "Offset red" +#define SANE_DESC_OFFSET_R "The offset of the signal processor for red" +#define SANE_NAME_OFFSET_G "offset-g" +#define SANE_TITLE_OFFSET_G "Offset greed" +#define SANE_DESC_OFFSET_G "The offset of the signal processor for green" +#define SANE_NAME_OFFSET_B "offset-b" +#define SANE_TITLE_OFFSET_B "Offset blue" +#define SANE_DESC_OFFSET_B "The offset of the signal processor for blue" +#define SANE_NAME_OFFSET_I "offset-i" +#define SANE_TITLE_OFFSET_I "Offset infrared" +#define SANE_DESC_OFFSET_I "The offset of the signal processor for infrared" +#define SANE_OFFSET_DEFAULT DEFAULT_OFFSET +#else +#define SANE_NAME_GAIN "gain" +#define SANE_TITLE_GAIN "Gain" +#define SANE_DESC_GAIN "The gain of the signal processor for the 4 CCD color filters (R,G,B,I)" +#define SANE_GAIN_DEFAULT 0x13 + +#define SANE_NAME_OFFSET "offset" +#define SANE_TITLE_OFFSET "Offset" +#define SANE_DESC_OFFSET "The offset of the signal processor for the 4 CCD color filters (R,G,B,I)" +#define SANE_OFFSET_DEFAULT 0 +#endif +#define min(a,b) (((a)<(b))?(a):(b)) +#define max(a,b) (((a)>(b))?(a):(b)) + +static const SANE_Range percentage_range_100 = { + 0 << SANE_FIXED_SCALE_SHIFT, /* minimum */ + 100 << SANE_FIXED_SCALE_SHIFT, /* maximum */ + 0 << SANE_FIXED_SCALE_SHIFT /* quantization */ +}; + +/* From the firmware disassembly */ +static const SANE_Range gain_range = { + 0, /* minimum */ + 63, /* maximum */ + 0 /* quantization */ +}; + +/* From the firmware disassembly */ +static const SANE_Range offset_range = { + 0, /* minimum */ + 255, /* maximum */ + 0 /* quantization */ +}; + +static const double gains[] = { +1.000, 1.075, 1.154, 1.251, 1.362, 1.491, 1.653, /* 0, 5, 10, 15, 20, 25, 30 */ +1.858, 2.115, 2.458, 2.935, 3.638, 4.627 /* 35, 40, 45, 50, 55, 60 */ +}; + +/** + * Callback called whenever a connected USB device reports a supported vendor + * and product id combination. + * Used by sane_init() and by sane_open(). + * + * @param name Device name which has required vendor and product id + * @return SANE_STATUS_GOOD + */ +SANE_Status +sanei_pieusb_find_device_callback (const char *devicename) +{ + struct Pieusb_Command_Status status; + SANE_Status r; + Pieusb_Device_Definition *dev; + int device_number; /* index in usb devices list maintained by sani_usb */ + Pieusb_Scanner_Properties inq; + int retry; + + DBG (DBG_info_proc, "sanei_pieusb_find_device_callback: %s\n", devicename); + + /* Check if device is present in the Pieusb device list */ + for (dev = pieusb_definition_list_head; dev; dev = dev->next) { + if (strcmp (dev->sane.name, devicename) == 0) { + return SANE_STATUS_GOOD; + } + } + + /* If not, create a new device struct */ + dev = malloc (sizeof (*dev)); + if (!dev) { + return SANE_STATUS_NO_MEM; + } + + /* Get device number: index of the device in the sanei_usb devices list */ + r = sanei_usb_open (devicename, &device_number); + if (r != SANE_STATUS_GOOD) { + free (dev); + DBG (DBG_error, "sanei_pieusb_find_device_callback: sanei_usb_open failed for device %s: %s\n",devicename,sane_strstatus(r)); + return r; + } + + /* Get device properties */ + + retry = 2; + while (retry > 0) { + retry--; + /* get inquiry data length */ + sanei_pieusb_cmd_inquiry (device_number, &inq, 5, &status); + if (status.pieusb_status == PIEUSB_STATUS_GOOD) { + break; + } + else if (status.pieusb_status == PIEUSB_STATUS_IO_ERROR) { + if (retry > 0) { + DBG (DBG_info_proc, "inquiry failed, resetting usb\n"); + if (sanei_pieusb_usb_reset(device_number) == SANE_STATUS_GOOD) { + continue; /* retry after IEEE1284 reset */ + } + if (sanei_usb_reset(device_number) == SANE_STATUS_GOOD) { + continue; /* retry after USB reset */ + } + } + } + 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; + } + /* get full inquiry data */ + sanei_pieusb_cmd_inquiry(device_number, &inq, inq.additionalLength+4, &status); + if (status.pieusb_status != PIEUSB_STATUS_GOOD) { + free (dev); + DBG (DBG_error, "sanei_pieusb_find_device_callback: get scanner properties failed\n"); + sanei_usb_close (device_number); + return status.pieusb_status; + } + + /* Close the device again */ + sanei_usb_close(device_number); + + /* Initialize device definition */ + r = pieusb_initialize_device_definition(dev, &inq, devicename, pieusb_supported_usb_device.vendor, pieusb_supported_usb_device.product); + if (r != SANE_STATUS_GOOD) { + return r; + } + + /* Output */ + pieusb_print_inquiry (dev); + + /* Check model number */ + if (inq.model != pieusb_supported_usb_device.model) { + free (dev); + DBG (DBG_error, "sanei_pieusb_find_device_callback: wrong model number %d\n", inq.model); + return SANE_STATUS_INVAL; + } + + /* Found a supported scanner, put it in the definitions list*/ + DBG (DBG_info_proc, "sanei_pieusb_find_device_callback: success\n"); + dev->next = pieusb_definition_list_head; + pieusb_definition_list_head = dev; + return SANE_STATUS_GOOD; +} + +/** + * Full initialization of a Pieusb_Device structure from INQUIRY data. + * The function is used in find_device_callback(), so when sane_init() or + * sane_open() is called. + * + * @param dev + */ +static SANE_Status +pieusb_initialize_device_definition (Pieusb_Device_Definition* dev, Pieusb_Scanner_Properties* inq, const char* devicename, + SANE_Word vendor_id, SANE_Word product_id) +{ + char *pp, *buf; + + /* Initialize device definition */ + dev->next = NULL; + dev->sane.name = strdup(devicename); + + /* Create 0-terminated string without trailing spaces for vendor */ + buf = malloc(9); + if (buf == NULL) + return SANE_STATUS_NO_MEM; + strncpy(buf, inq->vendor, 8); + pp = buf + 8; + *pp-- = '\0'; + while (*pp == ' ') *pp-- = '\0'; + dev->sane.vendor = buf; + + /* Create 0-terminated string without trailing spaces for model */ + buf = malloc(17); + if (buf == NULL) + return SANE_STATUS_NO_MEM; + strncpy(buf, inq->product, 16); + pp = buf + 16; + *pp-- = '\0'; + while (*pp == ' ') *pp-- = '\0'; + dev->sane.model = buf; + + dev->sane.type = "film scanner"; + dev->vendorId = vendor_id; + dev->productId = product_id; + + /* Create 0-terminated strings without trailing spaces for revision */ + buf = malloc(5); + if (buf == NULL) + return SANE_STATUS_NO_MEM; + strncpy(buf, inq->productRevision, 4); + pp = buf + 4; + *pp-- = '\0'; + while (*pp == ' ') *pp-- = '\0'; + dev->version = buf; + + dev->model = inq->model; + + /* Maximum resolution values */ + dev->maximum_resolution_x = inq->maxResolutionX; + dev->maximum_resolution_y = inq->maxResolutionY; + if (dev->maximum_resolution_y < 256) { + /* y res is a multiplier */ + dev->maximum_resolution = dev->maximum_resolution_x; + dev->maximum_resolution_x *= dev->maximum_resolution_y; + dev->maximum_resolution_y = dev->maximum_resolution_x; + } else { + /* y res really is resolution */ + dev->maximum_resolution = min (dev->maximum_resolution_x, dev->maximum_resolution_y); + } + + /* Geometry */ + dev->scan_bed_width = (double) inq->maxScanWidth / dev->maximum_resolution; + dev->scan_bed_height = (double) inq->maxScanHeight / dev->maximum_resolution; + dev->slide_top_left_x = inq->x0; + dev->slide_top_left_y = inq->y0; + dev->slide_width = (double) (inq->x1 - inq->x0) / dev->maximum_resolution; + dev->slide_height = (double) (inq->y1 - inq->y0) / dev->maximum_resolution; + + /* Integer and bit-encoded properties */ + dev->halftone_patterns = inq->halftones & 0x0f; + dev->color_filters = inq->filters; + dev->color_depths = inq->colorDepths; + dev->color_formats = inq->colorFormat; + dev->image_formats = inq->imageFormat; + dev->scan_capabilities = inq->scanCapability; + dev->optional_devices = inq->optionalDevices; + dev->enhancements = inq->enhancements; + dev->gamma_bits = inq->gammaBits; + dev->fast_preview_resolution = inq->previewScanResolution; + dev->minimum_highlight = inq->minumumHighlight; + dev->maximum_shadow = inq->maximumShadow; + dev->calibration_equation = inq->calibrationEquation; + dev->minimum_exposure = inq->minimumExposure; + dev->maximum_exposure = inq->maximumExposure*4; /* *4 to solve the strange situation that the default value is out of range */ + + dev->x0 = inq->x0; + dev->y0 = inq->y0; + dev->x1 = inq->x1; + dev->y1 = inq->y1; + dev->production = strndup(inq->production, 4); + dev->timestamp = strndup(inq->timestamp, 20); + dev->signature = (char *)strndup((char *)inq->signature, 40); + + /* Ranges for various quantities */ + dev->x_range.min = SANE_FIX (0); + dev->x_range.quant = SANE_FIX (0); + dev->x_range.max = SANE_FIX (dev->scan_bed_width * MM_PER_INCH); + + dev->y_range.min = SANE_FIX (0); + dev->y_range.quant = SANE_FIX (0); + dev->y_range.max = SANE_FIX (dev->scan_bed_height * MM_PER_INCH); + + dev->dpi_range.min = SANE_FIX (25); + dev->dpi_range.quant = SANE_FIX (1); + dev->dpi_range.max = SANE_FIX (max (dev->maximum_resolution_x, dev->maximum_resolution_y)); + + dev->shadow_range.min = SANE_FIX (0); + dev->shadow_range.quant = SANE_FIX (1); + dev->shadow_range.max = SANE_FIX (dev->maximum_shadow); + + dev->highlight_range.min = SANE_FIX (dev->minimum_highlight); + dev->highlight_range.quant = SANE_FIX (1); + dev->highlight_range.max = SANE_FIX (100); + + dev->exposure_range.min = dev->minimum_exposure; + dev->exposure_range.quant = 1; + dev->exposure_range.max = dev->maximum_exposure; + + dev->dust_range.min = 0; + dev->dust_range.quant = 1; + dev->dust_range.max = 100; + + /* Enumerated ranges vor various quantities */ + /*TODO: create from inq->filters */ + dev->scan_mode_list[0] = SANE_VALUE_SCAN_MODE_LINEART; + dev->scan_mode_list[1] = SANE_VALUE_SCAN_MODE_HALFTONE; + dev->scan_mode_list[2] = SANE_VALUE_SCAN_MODE_GRAY; + dev->scan_mode_list[3] = SANE_VALUE_SCAN_MODE_COLOR; + dev->scan_mode_list[4] = SANE_VALUE_SCAN_MODE_RGBI; + dev->scan_mode_list[5] = 0; + + dev->calibration_mode_list[0] = SCAN_CALIBRATION_DEFAULT; + dev->calibration_mode_list[1] = SCAN_CALIBRATION_AUTO; + dev->calibration_mode_list[2] = SCAN_CALIBRATION_PREVIEW; + dev->calibration_mode_list[3] = SCAN_CALIBRATION_OPTIONS; + dev->calibration_mode_list[4] = 0; + + dev->gain_adjust_list[0] = SCAN_GAIN_ADJUST_03; + dev->gain_adjust_list[1] = SCAN_GAIN_ADJUST_05; + dev->gain_adjust_list[2] = SCAN_GAIN_ADJUST_08; + dev->gain_adjust_list[3] = SCAN_GAIN_ADJUST_10; + dev->gain_adjust_list[4] = SCAN_GAIN_ADJUST_12; + dev->gain_adjust_list[5] = SCAN_GAIN_ADJUST_16; + dev->gain_adjust_list[6] = SCAN_GAIN_ADJUST_19; + dev->gain_adjust_list[7] = SCAN_GAIN_ADJUST_24; + dev->gain_adjust_list[8] = SCAN_GAIN_ADJUST_30; + dev->gain_adjust_list[9] = 0; + + /*TODO: create from inq->colorDepths? Maybe not: didn't experiment with + * 4 and 12 bit depths. Don;t know how they behave. */ + dev->bpp_list[0] = 3; /* count */ + dev->bpp_list[1] = 1; + dev->bpp_list[2] = 8; + dev->bpp_list[3] = 16; + + /* Infrared */ + dev->ir_sw_list[0] = "None"; + dev->ir_sw_list[1] = "Reduce red overlap"; + dev->ir_sw_list[2] = "Remove dirt"; + dev->ir_sw_list[3] = 0; + + dev->grain_sw_list[0] = 4; + dev->grain_sw_list[1] = 0; + dev->grain_sw_list[2] = 1; + dev->grain_sw_list[3] = 2; + dev->grain_sw_list[4] = 3; + dev->grain_sw_list[5] = 0; + + dev->crop_sw_list[0] = "None"; + dev->crop_sw_list[1] = "Outside"; + dev->crop_sw_list[2] = "Inside"; + dev->crop_sw_list[3] = 0; + + /* halftone_list */ + dev->halftone_list[0] = "53lpi 45d ROUND"; /* 8x8 pattern */ + dev->halftone_list[1] = "70lpi 45d ROUND"; /* 6x6 pattern */ + dev->halftone_list[2] = "75lpi Hori. Line"; /* 4x4 pattern */ + dev->halftone_list[3] = "4X4 BAYER"; /* 4x4 pattern */ + dev->halftone_list[4] = "4X4 SCROLL"; /* 4x4 pattern */ + dev->halftone_list[5] = "5x5 26 Levels"; /* 5x5 pattern */ + dev->halftone_list[6] = "4x4 SQUARE"; /* 4x4 pattern */ + dev->halftone_list[7] = "5x5 TILE"; /* 5x5 pattern */ + dev->halftone_list[8] = 0; + + return SANE_STATUS_GOOD; +} + +/** + * Output device definition. + * The function is used in find_device_callback(), so when sane_init() or + * sane_open() is called. + * + * @param dev Device to output + */ +static void +pieusb_print_inquiry (Pieusb_Device_Definition * dev) +{ + DBG (DBG_inquiry, "INQUIRY:\n"); + DBG (DBG_inquiry, "========\n"); + DBG (DBG_inquiry, "\n"); + DBG (DBG_inquiry, "vendor........................: '%s'\n", dev->sane.vendor); + DBG (DBG_inquiry, "product.......................: '%s'\n", dev->sane.model); + DBG (DBG_inquiry, "model .......................: 0x%04x\n", dev->model); + DBG (DBG_inquiry, "version.......................: '%s'\n", dev->version); + + DBG (DBG_inquiry, "X resolution..................: %d dpi\n", + dev->maximum_resolution_x); + DBG (DBG_inquiry, "Y resolution..................: %d dpi\n", + dev->maximum_resolution_y); + DBG (DBG_inquiry, "pixel resolution..............: %d dpi\n", + dev->maximum_resolution); + DBG (DBG_inquiry, "fb width......................: %f in\n", + dev->scan_bed_width); + DBG (DBG_inquiry, "fb length.....................: %f in\n", + dev->scan_bed_height); + + DBG (DBG_inquiry, "transparency width............: %f in\n", + dev->slide_width); + DBG (DBG_inquiry, "transparency length...........: %f in\n", + dev->slide_height); + DBG (DBG_inquiry, "transparency offset...........: %d,%d\n", + dev->slide_top_left_x, dev->slide_top_left_y); + + DBG (DBG_inquiry, "# of halftones................: %d\n", + dev->halftone_patterns); + + DBG (DBG_inquiry, "One pass color................: %s\n", + dev->color_filters & SCAN_ONE_PASS_COLOR ? "yes" : "no"); + + DBG (DBG_inquiry, "Filters.......................: %s%s%s%s%s (%02x)\n", + dev->color_filters & SCAN_FILTER_INFRARED ? "Infrared " : "", + dev->color_filters & SCAN_FILTER_RED ? "Red " : "", + dev->color_filters & SCAN_FILTER_GREEN ? "Green " : "", + dev->color_filters & SCAN_FILTER_BLUE ? "Blue " : "", + dev->color_filters & SCAN_FILTER_NEUTRAL ? "Neutral " : "", + dev->color_filters); + + DBG (DBG_inquiry, "Color depths..................: %s%s%s%s%s%s (%02x)\n", + dev->color_depths & SCAN_COLOR_DEPTH_16 ? "16 bit " : "", + dev->color_depths & SCAN_COLOR_DEPTH_12 ? "12 bit " : "", + dev->color_depths & SCAN_COLOR_DEPTH_10 ? "10 bit " : "", + dev->color_depths & SCAN_COLOR_DEPTH_8 ? "8 bit " : "", + dev->color_depths & SCAN_COLOR_DEPTH_4 ? "4 bit " : "", + dev->color_depths & SCAN_COLOR_DEPTH_1 ? "1 bit " : "", + dev->color_depths); + + DBG (DBG_inquiry, "Color Format..................: %s%s%s (%02x)\n", + dev->color_formats & SCAN_COLOR_FORMAT_INDEX ? "Indexed " : "", + dev->color_formats & SCAN_COLOR_FORMAT_LINE ? "Line " : "", + dev->color_formats & SCAN_COLOR_FORMAT_PIXEL ? "Pixel " : "", + dev->color_formats); + + DBG (DBG_inquiry, "Image Format..................: %s%s%s%s (%02x)\n", + dev->image_formats & SCAN_IMG_FMT_OKLINE ? "OKLine " : "", + dev->image_formats & SCAN_IMG_FMT_BLK_ONE ? "BlackOne " : "", + dev->image_formats & SCAN_IMG_FMT_MOTOROLA ? "Motorola " : "", + dev->image_formats & SCAN_IMG_FMT_INTEL ? "Intel" : "", + dev->image_formats); + + DBG (DBG_inquiry, + "Scan Capability...............: %s%s%s%s%d speeds (%02x)\n", + dev->scan_capabilities & SCAN_CAP_PWRSAV ? "PowerSave " : "", + dev->scan_capabilities & SCAN_CAP_EXT_CAL ? "ExtCal " : "", + dev->scan_capabilities & SCAN_CAP_FAST_PREVIEW ? "FastPreview" : + "", + dev->scan_capabilities & SCAN_CAP_DISABLE_CAL ? "DisCal " : "", + dev->scan_capabilities & SCAN_CAP_SPEEDS, + dev->scan_capabilities); + + DBG (DBG_inquiry, "Optional Devices..............: %s%s%s%s (%02x)\n", + dev->optional_devices & SCAN_OPT_DEV_MPCL ? "MultiPageLoad " : + "", + dev->optional_devices & SCAN_OPT_DEV_TP1 ? "TransModule1 " : "", + dev->optional_devices & SCAN_OPT_DEV_TP ? "TransModule " : "", + dev->optional_devices & SCAN_OPT_DEV_ADF ? "ADF " : "", + dev->optional_devices); + + DBG (DBG_inquiry, "Enhancement...................: %02x\n", + dev->enhancements); + DBG (DBG_inquiry, "Gamma bits....................: %d\n", + dev->gamma_bits); + + DBG (DBG_inquiry, "Fast Preview Resolution.......: %d\n", + dev->fast_preview_resolution); + DBG (DBG_inquiry, "Min Highlight.................: %d\n", + dev->minimum_highlight); + DBG (DBG_inquiry, "Max Shadow....................: %d\n", + dev->maximum_shadow); + DBG (DBG_inquiry, "Cal Eqn.......................: %d\n", + dev->calibration_equation); + DBG (DBG_inquiry, "Min Exposure..................: %d\n", + dev->minimum_exposure); + DBG (DBG_inquiry, "Max Exposure..................: %d\n", + dev->maximum_exposure); + + DBG (DBG_inquiry, "x0,y0 x1,y1...................: %d,%d %d,%d\n", + dev->x0, dev->y0, dev->x1, dev->y1); + DBG (DBG_inquiry, "production....................: '%s'\n", + dev->production); + DBG (DBG_inquiry, "timestamp.....................: '%s'\n", + dev->timestamp); + DBG (DBG_inquiry, "signature.....................: '%s'\n", + dev->signature); + +} + +/** + * Initiaize scanner options from the device definition and from exposure, + * gain and offset defaults. The function is called by sane_open(), when no + * optimized settings are available yet. The scanner object is fully + * initialized in sane_start(). + * + * @param scanner Scanner to initialize + * @return SANE_STATUS_GOOD + */ +SANE_Status +sanei_pieusb_init_options (Pieusb_Scanner* scanner) +{ + int i; + + DBG (DBG_info_proc, "sanei_pieusb_init_options\n"); + + memset (scanner->opt, 0, sizeof (scanner->opt)); + memset (scanner->val, 0, sizeof (scanner->val)); + + for (i = 0; i < NUM_OPTIONS; ++i) { + scanner->opt[i].size = sizeof (SANE_Word); + scanner->opt[i].cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT; + } + + /* Number of options (a pseudo-option) */ + scanner->opt[OPT_NUM_OPTS].name = SANE_NAME_NUM_OPTIONS; + scanner->opt[OPT_NUM_OPTS].title = SANE_TITLE_NUM_OPTIONS; + scanner->opt[OPT_NUM_OPTS].desc = SANE_DESC_NUM_OPTIONS; + scanner->opt[OPT_NUM_OPTS].type = SANE_TYPE_INT; + scanner->opt[OPT_NUM_OPTS].cap = SANE_CAP_SOFT_DETECT; + scanner->val[OPT_NUM_OPTS].w = NUM_OPTIONS; + + /* "Mode" group: */ + scanner->opt[OPT_MODE_GROUP].title = "Scan Mode"; + scanner->opt[OPT_MODE_GROUP].desc = ""; + scanner->opt[OPT_MODE_GROUP].type = SANE_TYPE_GROUP; + scanner->opt[OPT_MODE_GROUP].cap = 0; + scanner->opt[OPT_MODE_GROUP].constraint_type = SANE_CONSTRAINT_NONE; + + /* scan mode */ + scanner->opt[OPT_MODE].name = SANE_NAME_SCAN_MODE; + scanner->opt[OPT_MODE].title = SANE_TITLE_SCAN_MODE; + scanner->opt[OPT_MODE].desc = SANE_DESC_SCAN_MODE; + scanner->opt[OPT_MODE].type = SANE_TYPE_STRING; + scanner->opt[OPT_MODE].size = max_string_size ((SANE_String_Const const *) scanner->device->scan_mode_list); + scanner->opt[OPT_MODE].constraint_type = SANE_CONSTRAINT_STRING_LIST; + scanner->opt[OPT_MODE].constraint.string_list = (SANE_String_Const const *) scanner->device->scan_mode_list; + scanner->val[OPT_MODE].s = (SANE_Char *) strdup (scanner->device->scan_mode_list[3]); /* default RGB */ + + /* bit depth */ + scanner->opt[OPT_BIT_DEPTH].name = SANE_NAME_BIT_DEPTH; + scanner->opt[OPT_BIT_DEPTH].title = SANE_TITLE_BIT_DEPTH; + scanner->opt[OPT_BIT_DEPTH].desc = SANE_DESC_BIT_DEPTH; + scanner->opt[OPT_BIT_DEPTH].type = SANE_TYPE_INT; + scanner->opt[OPT_BIT_DEPTH].constraint_type = SANE_CONSTRAINT_WORD_LIST; + scanner->opt[OPT_BIT_DEPTH].size = sizeof (SANE_Word); + scanner->opt[OPT_BIT_DEPTH].constraint.word_list = scanner->device->bpp_list; + scanner->val[OPT_BIT_DEPTH].w = scanner->device->bpp_list[2]; + + /* resolution */ + scanner->opt[OPT_RESOLUTION].name = SANE_NAME_SCAN_RESOLUTION; + scanner->opt[OPT_RESOLUTION].title = SANE_TITLE_SCAN_RESOLUTION; + scanner->opt[OPT_RESOLUTION].desc = SANE_DESC_SCAN_RESOLUTION; + scanner->opt[OPT_RESOLUTION].type = SANE_TYPE_FIXED; + scanner->opt[OPT_RESOLUTION].unit = SANE_UNIT_DPI; + scanner->opt[OPT_RESOLUTION].constraint_type = SANE_CONSTRAINT_RANGE; + scanner->opt[OPT_RESOLUTION].constraint.range = &scanner->device->dpi_range; + scanner->val[OPT_RESOLUTION].w = scanner->device->fast_preview_resolution << SANE_FIXED_SCALE_SHIFT; + + /* halftone pattern */ + scanner->opt[OPT_HALFTONE_PATTERN].name = SANE_NAME_HALFTONE_PATTERN; + scanner->opt[OPT_HALFTONE_PATTERN].title = SANE_TITLE_HALFTONE_PATTERN; + scanner->opt[OPT_HALFTONE_PATTERN].desc = SANE_DESC_HALFTONE_PATTERN; + scanner->opt[OPT_HALFTONE_PATTERN].type = SANE_TYPE_STRING; + scanner->opt[OPT_HALFTONE_PATTERN].size = max_string_size ((SANE_String_Const const *) scanner->device->halftone_list); + scanner->opt[OPT_HALFTONE_PATTERN].constraint_type = SANE_CONSTRAINT_STRING_LIST; + scanner->opt[OPT_HALFTONE_PATTERN].constraint.string_list = (SANE_String_Const const *) scanner->device->halftone_list; + scanner->val[OPT_HALFTONE_PATTERN].s = (SANE_Char *) strdup (scanner->device->halftone_list[6]); + scanner->opt[OPT_HALFTONE_PATTERN].cap |= SANE_CAP_INACTIVE; /* Not implemented, and only meaningful at depth 1 */ + + /* lineart threshold */ + scanner->opt[OPT_THRESHOLD].name = SANE_NAME_THRESHOLD; + scanner->opt[OPT_THRESHOLD].title = SANE_TITLE_THRESHOLD; + scanner->opt[OPT_THRESHOLD].desc = SANE_DESC_THRESHOLD; + scanner->opt[OPT_THRESHOLD].type = SANE_TYPE_FIXED; + scanner->opt[OPT_THRESHOLD].unit = SANE_UNIT_PERCENT; + scanner->opt[OPT_THRESHOLD].constraint_type = SANE_CONSTRAINT_RANGE; + scanner->opt[OPT_THRESHOLD].constraint.range = &percentage_range_100; + scanner->val[OPT_THRESHOLD].w = SANE_FIX (50); + /* scanner->opt[OPT_THRESHOLD].cap |= SANE_CAP_INACTIVE; Not implemented, and only meaningful at depth 1 */ + + /* create a sharper scan at the cost of scan time */ + scanner->opt[OPT_SHARPEN].name = "sharpen"; + scanner->opt[OPT_SHARPEN].title = "Sharpen scan"; + scanner->opt[OPT_SHARPEN].desc = "Sharpen scan by taking more time to discharge the CCD."; + scanner->opt[OPT_SHARPEN].type = SANE_TYPE_BOOL; + scanner->opt[OPT_SHARPEN].unit = SANE_UNIT_NONE; + scanner->opt[OPT_SHARPEN].constraint_type = SANE_CONSTRAINT_NONE; + scanner->val[OPT_SHARPEN].b = SANE_FALSE; + scanner->opt[OPT_SHARPEN].cap |= SANE_CAP_SOFT_SELECT; + + /* skip the auto-calibration phase before the scan */ + scanner->opt[OPT_SHADING_ANALYSIS].name = "shading-analysis"; + scanner->opt[OPT_SHADING_ANALYSIS].title = "Perform shading analysis"; + scanner->opt[OPT_SHADING_ANALYSIS].desc = "Collect shading reference data before scanning the image. If set to 'no', this option may be overridden by the scanner."; + scanner->opt[OPT_SHADING_ANALYSIS].type = SANE_TYPE_BOOL; + scanner->opt[OPT_SHADING_ANALYSIS].unit = SANE_UNIT_NONE; + scanner->opt[OPT_SHADING_ANALYSIS].constraint_type = SANE_CONSTRAINT_NONE; + scanner->val[OPT_SHADING_ANALYSIS].b = SANE_FALSE; + scanner->opt[OPT_SHADING_ANALYSIS].cap |= SANE_CAP_SOFT_SELECT; + + /* use auto-calibration settings for scan */ + scanner->opt[OPT_CALIBRATION_MODE].name = "calibration"; + scanner->opt[OPT_CALIBRATION_MODE].title = "Calibration mode"; + scanner->opt[OPT_CALIBRATION_MODE].desc = "How to calibrate the scanner."; + scanner->opt[OPT_CALIBRATION_MODE].type = SANE_TYPE_STRING; + scanner->opt[OPT_CALIBRATION_MODE].size = max_string_size ((SANE_String_Const const *) scanner->device->calibration_mode_list); + scanner->opt[OPT_CALIBRATION_MODE].constraint_type = SANE_CONSTRAINT_STRING_LIST; + scanner->opt[OPT_CALIBRATION_MODE].constraint.string_list = (SANE_String_Const const *) scanner->device->calibration_mode_list; + scanner->val[OPT_CALIBRATION_MODE].s = (SANE_Char *) strdup (scanner->device->calibration_mode_list[1]); /* default auto */ + + /* OPT_GAIN_ADJUST */ + scanner->opt[OPT_GAIN_ADJUST].name = "gain-adjust"; + scanner->opt[OPT_GAIN_ADJUST].title = "Adjust gain"; + scanner->opt[OPT_GAIN_ADJUST].desc = "Adjust gain determined by calibration procedure."; + scanner->opt[OPT_GAIN_ADJUST].type = SANE_TYPE_STRING; + scanner->opt[OPT_GAIN_ADJUST].size = max_string_size ((SANE_String_Const const *) scanner->device->gain_adjust_list); + scanner->opt[OPT_GAIN_ADJUST].constraint_type = SANE_CONSTRAINT_STRING_LIST; + scanner->opt[OPT_GAIN_ADJUST].constraint.string_list = (SANE_String_Const const *) scanner->device->gain_adjust_list; + scanner->val[OPT_GAIN_ADJUST].s = (SANE_Char *) strdup (scanner->device->gain_adjust_list[2]); /* x 1.0 (no change) */ + + /* scan infrared channel faster but less accurate */ + scanner->opt[OPT_FAST_INFRARED].name = "fast-infrared"; + scanner->opt[OPT_FAST_INFRARED].title = "Fast infrared scan"; + scanner->opt[OPT_FAST_INFRARED].desc = "Do not reposition scan head before scanning infrared line. Results in an infrared offset which may deteriorate IR dust and scratch removal."; + scanner->opt[OPT_FAST_INFRARED].type = SANE_TYPE_BOOL; + scanner->opt[OPT_FAST_INFRARED].unit = SANE_UNIT_NONE; + scanner->opt[OPT_FAST_INFRARED].constraint_type = SANE_CONSTRAINT_NONE; + scanner->val[OPT_FAST_INFRARED].b = SANE_FALSE; + scanner->opt[OPT_FAST_INFRARED].cap |= SANE_CAP_SOFT_SELECT; + + /* automatically advance to next slide after scan */ + scanner->opt[OPT_ADVANCE_SLIDE].name = "advcane"; + scanner->opt[OPT_ADVANCE_SLIDE].title = "Advance slide"; + scanner->opt[OPT_ADVANCE_SLIDE].desc = "Automatically advance to next slide after scan"; + scanner->opt[OPT_ADVANCE_SLIDE].type = SANE_TYPE_BOOL; + scanner->opt[OPT_ADVANCE_SLIDE].unit = SANE_UNIT_NONE; + scanner->opt[OPT_ADVANCE_SLIDE].constraint_type = SANE_CONSTRAINT_NONE; + scanner->val[OPT_ADVANCE_SLIDE].w = SANE_TRUE; + scanner->opt[OPT_ADVANCE_SLIDE].cap |= SANE_CAP_SOFT_SELECT; + + /* "Geometry" group: */ + scanner->opt[OPT_GEOMETRY_GROUP].title = "Geometry"; + scanner->opt[OPT_GEOMETRY_GROUP].desc = ""; + scanner->opt[OPT_GEOMETRY_GROUP].type = SANE_TYPE_GROUP; + scanner->opt[OPT_GEOMETRY_GROUP].cap = SANE_CAP_ADVANCED; + scanner->opt[OPT_GEOMETRY_GROUP].constraint_type = SANE_CONSTRAINT_NONE; + + /* top-left x */ + scanner->opt[OPT_TL_X].name = SANE_NAME_SCAN_TL_X; + scanner->opt[OPT_TL_X].title = SANE_TITLE_SCAN_TL_X; + scanner->opt[OPT_TL_X].desc = SANE_DESC_SCAN_TL_X; + scanner->opt[OPT_TL_X].type = SANE_TYPE_FIXED; + scanner->opt[OPT_TL_X].unit = SANE_UNIT_MM; + scanner->opt[OPT_TL_X].constraint_type = SANE_CONSTRAINT_RANGE; + scanner->opt[OPT_TL_X].constraint.range = &(scanner->device->x_range); + scanner->val[OPT_TL_X].w = 0; + + /* top-left y */ + scanner->opt[OPT_TL_Y].name = SANE_NAME_SCAN_TL_Y; + scanner->opt[OPT_TL_Y].title = SANE_TITLE_SCAN_TL_Y; + scanner->opt[OPT_TL_Y].desc = SANE_DESC_SCAN_TL_Y; + scanner->opt[OPT_TL_Y].type = SANE_TYPE_FIXED; + scanner->opt[OPT_TL_Y].unit = SANE_UNIT_MM; + scanner->opt[OPT_TL_Y].constraint_type = SANE_CONSTRAINT_RANGE; + scanner->opt[OPT_TL_Y].constraint.range = &(scanner->device->y_range); + scanner->val[OPT_TL_Y].w = 0; + + /* bottom-right x */ + scanner->opt[OPT_BR_X].name = SANE_NAME_SCAN_BR_X; + scanner->opt[OPT_BR_X].title = SANE_TITLE_SCAN_BR_X; + scanner->opt[OPT_BR_X].desc = SANE_DESC_SCAN_BR_X; + scanner->opt[OPT_BR_X].type = SANE_TYPE_FIXED; + scanner->opt[OPT_BR_X].unit = SANE_UNIT_MM; + scanner->opt[OPT_BR_X].constraint_type = SANE_CONSTRAINT_RANGE; + scanner->opt[OPT_BR_X].constraint.range = &(scanner->device->x_range); + scanner->val[OPT_BR_X].w = scanner->device->x_range.max; + + /* bottom-right y */ + scanner->opt[OPT_BR_Y].name = SANE_NAME_SCAN_BR_Y; + scanner->opt[OPT_BR_Y].title = SANE_TITLE_SCAN_BR_Y; + scanner->opt[OPT_BR_Y].desc = SANE_DESC_SCAN_BR_Y; + scanner->opt[OPT_BR_Y].type = SANE_TYPE_FIXED; + scanner->opt[OPT_BR_Y].unit = SANE_UNIT_MM; + scanner->opt[OPT_BR_Y].constraint_type = SANE_CONSTRAINT_RANGE; + scanner->opt[OPT_BR_Y].constraint.range = &(scanner->device->y_range); + scanner->val[OPT_BR_Y].w = scanner->device->y_range.max; + + /* "Enhancement" group: */ + scanner->opt[OPT_ENHANCEMENT_GROUP].title = "Enhancement"; + scanner->opt[OPT_ENHANCEMENT_GROUP].desc = ""; + scanner->opt[OPT_ENHANCEMENT_GROUP].type = SANE_TYPE_GROUP; + scanner->opt[OPT_ENHANCEMENT_GROUP].cap = 0; + scanner->opt[OPT_ENHANCEMENT_GROUP].constraint_type = SANE_CONSTRAINT_NONE; + + /* correct data for lamp variations (shading) */ + scanner->opt[OPT_CORRECT_SHADING].name = "correct-shading"; + scanner->opt[OPT_CORRECT_SHADING].title = "Correct shading"; + scanner->opt[OPT_CORRECT_SHADING].desc = "Correct data for lamp variations (shading)"; + scanner->opt[OPT_CORRECT_SHADING].type = SANE_TYPE_BOOL; + scanner->opt[OPT_CORRECT_SHADING].unit = SANE_UNIT_NONE; + scanner->val[OPT_CORRECT_SHADING].w = SANE_TRUE; + + /* correct infrared for red crosstalk */ + scanner->opt[OPT_CORRECT_INFRARED].name = "correct-infrared"; + scanner->opt[OPT_CORRECT_INFRARED].title = "Correct infrared"; + scanner->opt[OPT_CORRECT_INFRARED].desc = "Correct infrared for red crosstalk"; + scanner->opt[OPT_CORRECT_INFRARED].type = SANE_TYPE_BOOL; + scanner->opt[OPT_CORRECT_INFRARED].unit = SANE_UNIT_NONE; + scanner->val[OPT_CORRECT_INFRARED].w = SANE_FALSE; + + /* detect and remove dust and scratch artifacts */ + scanner->opt[OPT_CLEAN_IMAGE].name = "clean-image"; + scanner->opt[OPT_CLEAN_IMAGE].title = "Clean image"; + scanner->opt[OPT_CLEAN_IMAGE].desc = "Detect and remove dust and scratch artifacts"; + scanner->opt[OPT_CLEAN_IMAGE].type = SANE_TYPE_BOOL; + scanner->opt[OPT_CLEAN_IMAGE].unit = SANE_UNIT_NONE; + scanner->val[OPT_CLEAN_IMAGE].w = SANE_FALSE; + + /* strength of grain filtering */ + scanner->opt[OPT_SMOOTH_IMAGE].name = "smooth"; + scanner->opt[OPT_SMOOTH_IMAGE].title = "Attenuate film grain"; + scanner->opt[OPT_SMOOTH_IMAGE].desc = "Amount of smoothening"; + scanner->opt[OPT_SMOOTH_IMAGE].type = SANE_TYPE_INT; + scanner->opt[OPT_SMOOTH_IMAGE].constraint_type = SANE_CONSTRAINT_WORD_LIST; + scanner->opt[OPT_SMOOTH_IMAGE].size = sizeof (SANE_Word); + scanner->opt[OPT_SMOOTH_IMAGE].constraint.word_list = scanner->device->grain_sw_list; + scanner->val[OPT_SMOOTH_IMAGE].w = scanner->device->grain_sw_list[1]; + if (scanner->opt[OPT_SMOOTH_IMAGE].constraint.word_list[0] < 2) { + scanner->opt[OPT_SMOOTH_IMAGE].cap |= SANE_CAP_INACTIVE; + } + + /* gamma correction, to make image sRGB like */ + scanner->opt[OPT_TRANSFORM_TO_SRGB].name = "srgb"; + scanner->opt[OPT_TRANSFORM_TO_SRGB].title = "sRGB colors"; + scanner->opt[OPT_TRANSFORM_TO_SRGB].desc = "Transform image to approximate sRGB color space"; + scanner->opt[OPT_TRANSFORM_TO_SRGB].type = SANE_TYPE_BOOL; + scanner->opt[OPT_TRANSFORM_TO_SRGB].unit = SANE_UNIT_NONE; + scanner->val[OPT_TRANSFORM_TO_SRGB].w = SANE_FALSE; + scanner->opt[OPT_TRANSFORM_TO_SRGB].cap |= SANE_CAP_INACTIVE; + + /* color correction for generic negative film */ + scanner->opt[OPT_INVERT_IMAGE].name = "invert"; + scanner->opt[OPT_INVERT_IMAGE].title = "Invert colors"; + scanner->opt[OPT_INVERT_IMAGE].desc = "Correct for generic negative film"; + scanner->opt[OPT_INVERT_IMAGE].type = SANE_TYPE_BOOL; + scanner->opt[OPT_INVERT_IMAGE].unit = SANE_UNIT_NONE; + scanner->val[OPT_INVERT_IMAGE].w = SANE_FALSE; + scanner->opt[OPT_INVERT_IMAGE].cap |= SANE_CAP_INACTIVE; + + /* crop image */ + scanner->opt[OPT_CROP_IMAGE].name = "crop"; + scanner->opt[OPT_CROP_IMAGE].title = "Cropping"; + scanner->opt[OPT_CROP_IMAGE].desc = "How to crop the image"; + scanner->opt[OPT_CROP_IMAGE].type = SANE_TYPE_STRING; + scanner->opt[OPT_CROP_IMAGE].size = max_string_size ((SANE_String_Const const *)(void*) scanner->device->crop_sw_list); + scanner->opt[OPT_CROP_IMAGE].constraint_type = SANE_CONSTRAINT_STRING_LIST; + scanner->opt[OPT_CROP_IMAGE].constraint.string_list = (SANE_String_Const const *)(void*) scanner->device->crop_sw_list; + scanner->val[OPT_CROP_IMAGE].s = (SANE_Char *) strdup (scanner->device->crop_sw_list[2]); + + /* "Advanced" group: */ + scanner->opt[OPT_ADVANCED_GROUP].title = "Advanced"; + scanner->opt[OPT_ADVANCED_GROUP].desc = ""; + scanner->opt[OPT_ADVANCED_GROUP].type = SANE_TYPE_GROUP; + scanner->opt[OPT_ADVANCED_GROUP].cap = SANE_CAP_ADVANCED; + scanner->opt[OPT_ADVANCED_GROUP].constraint_type = SANE_CONSTRAINT_NONE; + + /* preview */ + scanner->opt[OPT_PREVIEW].name = SANE_NAME_PREVIEW; + scanner->opt[OPT_PREVIEW].title = SANE_TITLE_PREVIEW; + scanner->opt[OPT_PREVIEW].desc = SANE_DESC_PREVIEW; + scanner->opt[OPT_PREVIEW].type = SANE_TYPE_BOOL; + scanner->val[OPT_PREVIEW].w = SANE_FALSE; + + /* save shading data */ + scanner->opt[OPT_SAVE_SHADINGDATA].name = "save-shading-data"; + scanner->opt[OPT_SAVE_SHADINGDATA].title = "Save shading data"; + scanner->opt[OPT_SAVE_SHADINGDATA].desc = "Save shading data in 'pieusb.shading'"; + scanner->opt[OPT_SAVE_SHADINGDATA].type = SANE_TYPE_BOOL; + scanner->val[OPT_SAVE_SHADINGDATA].w = SANE_FALSE; + + /* save CCD mask */ + scanner->opt[OPT_SAVE_CCDMASK].name = "save-ccdmask"; + scanner->opt[OPT_SAVE_CCDMASK].title = "Save CCD mask"; + scanner->opt[OPT_SAVE_CCDMASK].desc = "Save CCD mask 'pieusb.ccd'"; + scanner->opt[OPT_SAVE_CCDMASK].type = SANE_TYPE_BOOL; + scanner->val[OPT_SAVE_CCDMASK].w = SANE_FALSE; + + scanner->opt[OPT_LIGHT].name = "light"; + scanner->opt[OPT_LIGHT].title = "Light"; + scanner->opt[OPT_LIGHT].desc = "Light"; + scanner->opt[OPT_LIGHT].type = SANE_TYPE_INT; + scanner->opt[OPT_LIGHT].unit = SANE_UNIT_MICROSECOND; + scanner->opt[OPT_LIGHT].cap |= SANE_CAP_SOFT_SELECT; + scanner->opt[OPT_LIGHT].size = sizeof(SANE_Word); + scanner->val[OPT_LIGHT].w = DEFAULT_LIGHT; + + scanner->opt[OPT_DOUBLE_TIMES].name = "double-times"; + scanner->opt[OPT_DOUBLE_TIMES].title = "Double times"; + scanner->opt[OPT_DOUBLE_TIMES].desc = "Double times"; + scanner->opt[OPT_DOUBLE_TIMES].type = SANE_TYPE_INT; + scanner->opt[OPT_DOUBLE_TIMES].unit = SANE_UNIT_MICROSECOND; + scanner->opt[OPT_DOUBLE_TIMES].cap |= SANE_CAP_SOFT_SELECT; + scanner->opt[OPT_DOUBLE_TIMES].size = sizeof(SANE_Word); + scanner->val[OPT_DOUBLE_TIMES].w = DEFAULT_DOUBLE_TIMES; + + /* exposure times for R, G, B and I */ + scanner->opt[OPT_SET_EXPOSURE_R].name = SANE_NAME_EXPOSURE_R; + scanner->opt[OPT_SET_EXPOSURE_R].title = SANE_TITLE_EXPOSURE_R; + scanner->opt[OPT_SET_EXPOSURE_R].desc = SANE_DESC_EXPOSURE_R; + scanner->opt[OPT_SET_EXPOSURE_G].name = SANE_NAME_EXPOSURE_G; + scanner->opt[OPT_SET_EXPOSURE_G].title = SANE_TITLE_EXPOSURE_G; + scanner->opt[OPT_SET_EXPOSURE_G].desc = SANE_DESC_EXPOSURE_G; + scanner->opt[OPT_SET_EXPOSURE_B].name = SANE_NAME_EXPOSURE_B; + scanner->opt[OPT_SET_EXPOSURE_B].title = SANE_TITLE_EXPOSURE_B; + scanner->opt[OPT_SET_EXPOSURE_B].desc = SANE_DESC_EXPOSURE_B; + scanner->opt[OPT_SET_EXPOSURE_I].name = SANE_NAME_EXPOSURE_I; + scanner->opt[OPT_SET_EXPOSURE_I].title = SANE_TITLE_EXPOSURE_I; + scanner->opt[OPT_SET_EXPOSURE_I].desc = SANE_DESC_EXPOSURE_I; + for (i = OPT_SET_EXPOSURE_R; i <= OPT_SET_EXPOSURE_I; ++i) { + scanner->opt[i].type = SANE_TYPE_INT; + scanner->opt[i].unit = SANE_UNIT_MICROSECOND; + scanner->opt[i].cap |= SANE_CAP_SOFT_SELECT; + scanner->opt[i].constraint_type = SANE_CONSTRAINT_RANGE; + scanner->opt[i].constraint.range = &(scanner->device->exposure_range); + scanner->opt[i].size = sizeof(SANE_Word); + scanner->val[i].w = SANE_EXPOSURE_DEFAULT; + } + + /* gain for R, G, B and I */ + scanner->opt[OPT_SET_GAIN_R].name = SANE_NAME_GAIN_R; + scanner->opt[OPT_SET_GAIN_R].title = SANE_TITLE_GAIN_R; + scanner->opt[OPT_SET_GAIN_R].desc = SANE_DESC_GAIN_R; + scanner->opt[OPT_SET_GAIN_G].name = SANE_NAME_GAIN_G; + scanner->opt[OPT_SET_GAIN_G].title = SANE_TITLE_GAIN_G; + scanner->opt[OPT_SET_GAIN_G].desc = SANE_DESC_GAIN_G; + scanner->opt[OPT_SET_GAIN_B].name = SANE_NAME_GAIN_B; + scanner->opt[OPT_SET_GAIN_B].title = SANE_TITLE_GAIN_B; + scanner->opt[OPT_SET_GAIN_B].desc = SANE_DESC_GAIN_B; + scanner->opt[OPT_SET_GAIN_I].name = SANE_NAME_GAIN_I; + scanner->opt[OPT_SET_GAIN_I].title = SANE_TITLE_GAIN_I; + scanner->opt[OPT_SET_GAIN_I].desc = SANE_DESC_GAIN_I; + for (i = OPT_SET_GAIN_R; i <= OPT_SET_GAIN_I; ++i) { + scanner->opt[i].type = SANE_TYPE_INT; + scanner->opt[i].unit = SANE_UNIT_NONE; + scanner->opt[i].constraint_type = SANE_CONSTRAINT_RANGE; + scanner->opt[i].constraint.range = &gain_range; + scanner->opt[i].size = sizeof(SANE_Word); + scanner->val[i].w = SANE_GAIN_DEFAULT; + } + /* offsets for R, G, B and I */ + scanner->opt[OPT_SET_OFFSET_R].name = SANE_NAME_OFFSET_R; + scanner->opt[OPT_SET_OFFSET_R].title = SANE_TITLE_OFFSET_R; + scanner->opt[OPT_SET_OFFSET_R].desc = SANE_DESC_OFFSET_R; + scanner->opt[OPT_SET_OFFSET_G].name = SANE_NAME_OFFSET_G; + scanner->opt[OPT_SET_OFFSET_G].title = SANE_TITLE_OFFSET_G; + scanner->opt[OPT_SET_OFFSET_G].desc = SANE_DESC_OFFSET_G; + scanner->opt[OPT_SET_OFFSET_B].name = SANE_NAME_OFFSET_B; + scanner->opt[OPT_SET_OFFSET_B].title = SANE_TITLE_OFFSET_B; + scanner->opt[OPT_SET_OFFSET_B].desc = SANE_DESC_OFFSET_B; + scanner->opt[OPT_SET_OFFSET_I].name = SANE_NAME_OFFSET_I; + scanner->opt[OPT_SET_OFFSET_I].title = SANE_TITLE_OFFSET_I; + scanner->opt[OPT_SET_OFFSET_I].desc = SANE_DESC_OFFSET_I; + for (i = OPT_SET_OFFSET_R; i <= OPT_SET_OFFSET_I; ++i) { + scanner->opt[i].type = SANE_TYPE_INT; + scanner->opt[i].unit = SANE_UNIT_NONE; + scanner->opt[i].constraint_type = SANE_CONSTRAINT_RANGE; + scanner->opt[i].constraint.range = &offset_range; + scanner->opt[i].size = sizeof(SANE_Word); + scanner->val[i].w = SANE_OFFSET_DEFAULT; + } + return SANE_STATUS_GOOD; +} + +/** + * Parse line from config file into a vendor id, product id and a model number + * + * @param config_line Text to parse + * @param vendor_id + * @param product_id + * @param model_number + * @return SANE_STATUS_GOOD, or SANE_STATUS_INVAL in case of a parse error + */ +SANE_Status +sanei_pieusb_parse_config_line(const char* config_line, SANE_Word* vendor_id, SANE_Word* product_id, SANE_Word* model_number) +{ + char *vendor_id_string, *product_id_string, *model_number_string; + + if (strncmp (config_line, "usb ", 4) != 0) { + return SANE_STATUS_INVAL; + } + /* Detect vendor-id */ + config_line += 4; + config_line = sanei_config_skip_whitespace (config_line); + if (*config_line) { + config_line = sanei_config_get_string (config_line, &vendor_id_string); + if (vendor_id_string) { + *vendor_id = strtol (vendor_id_string, 0, 0); + free (vendor_id_string); + } else { + return SANE_STATUS_INVAL; + } + config_line = sanei_config_skip_whitespace (config_line); + } else { + return SANE_STATUS_INVAL; + } + /* Detect product-id */ + config_line = sanei_config_skip_whitespace (config_line); + if (*config_line) { + config_line = sanei_config_get_string (config_line, &product_id_string); + if (product_id_string) { + *product_id = strtol (product_id_string, 0, 0); + free (product_id_string); + } else { + return SANE_STATUS_INVAL; + } + config_line = sanei_config_skip_whitespace (config_line); + } else { + return SANE_STATUS_INVAL; + } + /* Detect product-id */ + config_line = sanei_config_skip_whitespace (config_line); + if (*config_line) { + config_line = sanei_config_get_string (config_line, &model_number_string); + if (model_number_string) { + *model_number = strtol (model_number_string, 0, 0); + free (model_number_string); + } else { + return SANE_STATUS_INVAL; + } + config_line = sanei_config_skip_whitespace (config_line); + } else { + return SANE_STATUS_INVAL; + } + return SANE_STATUS_GOOD; +} + +/** + * Check if current list of supported devices contains the given specifications. + * + * @param vendor_id + * @param product_id + * @param model_number + * @return + */ +SANE_Bool +sanei_pieusb_supported_device_list_contains(SANE_Word vendor_id, SANE_Word product_id, SANE_Word model_number) +{ + int i = 0; + while (pieusb_supported_usb_device_list[i].vendor != 0) { + if (pieusb_supported_usb_device_list[i].vendor == vendor_id + && pieusb_supported_usb_device_list[i].product == product_id + && pieusb_supported_usb_device_list[i].model == model_number) { + return SANE_TRUE; + } + i++; + } + return SANE_FALSE; +} + +/** + * Add the given specifications to the current list of supported devices + * @param vendor_id + * @param product_id + * @param model_number + * @return + */ +SANE_Status +sanei_pieusb_supported_device_list_add(SANE_Word vendor_id, SANE_Word product_id, SANE_Word model_number) +{ + int i = 0, k; + struct Pieusb_USB_Device_Entry* dl; + + while (pieusb_supported_usb_device_list[i].vendor != 0) { + i++; + } + /* i is index of last entry */ + for (k=0; k<=i; k++) { + DBG(DBG_info_proc,"sanei_pieusb_supported_device_list_add(): current %03d: %04x %04x %02x\n", i, + pieusb_supported_usb_device_list[k].vendor, + pieusb_supported_usb_device_list[k].product, + pieusb_supported_usb_device_list[k].model); + } + + dl = realloc(pieusb_supported_usb_device_list,(i+2)*sizeof(struct Pieusb_USB_Device_Entry)); /* Add one entry to list */ + if (dl == NULL) { + return SANE_STATUS_INVAL; + } + /* Copy values */ + pieusb_supported_usb_device_list = dl; + pieusb_supported_usb_device_list[i].vendor = vendor_id; + pieusb_supported_usb_device_list[i].product = product_id; + pieusb_supported_usb_device_list[i].model = model_number; + pieusb_supported_usb_device_list[i+1].vendor = 0; + pieusb_supported_usb_device_list[i+1].product = 0; + pieusb_supported_usb_device_list[i+1].model = 0; + for (k=0; k<=i+1; k++) { + DBG(DBG_info_proc,"sanei_pieusb_supported_device_list_add() add: %03d: %04x %04x %02x\n", i, + pieusb_supported_usb_device_list[k].vendor, + pieusb_supported_usb_device_list[k].product, + pieusb_supported_usb_device_list[k].model); + } + return SANE_STATUS_GOOD; +} + +/** + * Actions to perform when a cancel request has been received. + * + * @param scanner scanner to stop scanning + * @return SANE_STATUS_CANCELLED + */ +SANE_Status +sanei_pieusb_on_cancel (Pieusb_Scanner * scanner) +{ + struct Pieusb_Command_Status status; + + DBG (DBG_info_proc, "sanei_pieusb_on_cancel()\n"); + + sanei_pieusb_cmd_stop_scan (scanner->device_number, &status); + sanei_pieusb_cmd_set_scan_head (scanner->device_number, 1, 0, &status); + sanei_pieusb_buffer_delete (&scanner->buffer); + scanner->scanning = SANE_FALSE; + return SANE_STATUS_CANCELLED; +} + +/** + * Determine maximum lengt of a set of strings. + * + * @param strings Set of strings + * @return maximum length + */ +static size_t +max_string_size (SANE_String_Const const strings[]) +{ + size_t size, max_size = 0; + int i; + + for (i = 0; strings[i]; ++i) { + size = strlen (strings[i]) + 1; + if (size > max_size) { + max_size = size; + } + } + + return max_size; +} + +/* From MR's pie.c */ + +/* ------------------------- PIEUSB_CORRECT_SHADING -------------------------- */ + +/** + * Correct the given buffer for shading using shading data in scanner. + * If the loop order is width->color->height, a 7200 dpi scan correction takes + * 45 minutes. If the loop order is color->height->width, this is less than 3 + * minutes. So it is worthwhile to find the used pixels first (array width_to_loc). + * + * @param scanner Scanner + * @param buffer Buffer to correct + */ +void +sanei_pieusb_correct_shading(struct Pieusb_Scanner *scanner, struct Pieusb_Read_Buffer *buffer) +{ + + int i, j, c, k; + SANE_Uint val, val_org, *p; + int *width_to_loc; + + DBG (DBG_info_proc, "sanei_pieusb_correct_shading()\n"); + + /* Loop through CCD-mask to find used pixels */ + width_to_loc = calloc(buffer->width,sizeof(int)); + j = 0; + for (i = 0; i < scanner->ccd_mask_size; i++) { + if (scanner->ccd_mask[i] == 0) { + width_to_loc[j++] = i; + } + } + /* Correct complete image */ + for (c = 0; c < buffer->colors; c++) { + DBG(DBG_info,"sanei_pieusb_correct_shading() correct color %d\n",c); + for (k = 0; k < buffer->height; k++) { + /* DBG(DBG_info,"Correct line %d\n",k); */ + p = buffer->data + c * buffer->width * buffer->height + k * buffer->width; + for (j = 0; j < buffer->width; j++) { + val_org = *p; + val = lround((double)scanner->shading_mean[c] / scanner->shading_ref[c][width_to_loc[j]] * val_org); + /* DBG(DBG_info,"Correct [%d,%d,%d] %d -> %d\n",k,j,c,val_org,val); */ + *p++ = val; + } + } + } + /* Free memory */ + free(width_to_loc); +} + +/* === functions copied from MR's code === */ + +/** + * + * @param scanner + * @param in_img + * @param planes + * @param out_planes + * @return + */ +SANE_Status +sanei_pieusb_post (Pieusb_Scanner *scanner, uint16_t **in_img, int planes) +{ + uint16_t *cplane[PLANES]; /* R, G, B, I gray scale planes */ + SANE_Parameters parameters; /* describes the image */ + int winsize_smooth; /* for adapting replaced pixels */ + char filename[64]; + SANE_Status status; + int smooth, i; + + memcpy (¶meters, &scanner->scan_parameters, sizeof (SANE_Parameters)); + parameters.format = SANE_FRAME_GRAY; + parameters.bytes_per_line = parameters.pixels_per_line; + if (parameters.depth > 8) + parameters.bytes_per_line *= 2; + parameters.last_frame = 0; + + DBG (DBG_info, "pie_usb_post: %d ppl, %d lines, %d bits, %d planes, %d dpi\n", + parameters.pixels_per_line, parameters.lines, + parameters.depth, planes, scanner->mode.resolution); + + if (planes > PLANES) { + DBG (DBG_error, "pie_usb_post: too many planes: %d (max %d)\n", planes, PLANES); + return SANE_STATUS_INVAL; + } + + for (i = 0; i < planes; i++) + cplane[i] = in_img[i]; + + /* dirt is rather resolution invariant, so + * setup resolution dependent parameters + */ + /* film grain reduction */ + smooth = scanner->val[OPT_SMOOTH_IMAGE].w; + winsize_smooth = (scanner->mode.resolution / 540) | 1; + /* smoothen whole image or only replaced pixels */ + if (smooth) + { + winsize_smooth += 2 * (smooth - 3); /* even */ + if (winsize_smooth < 3) + smooth = 0; + } + if (winsize_smooth < 3) + winsize_smooth = 3; + DBG (DBG_info, "pie_usb_sw_post: winsize_smooth %d\n", winsize_smooth); + + /* RGBI post-processing if selected: + * 1) remove spectral overlay from ired plane, + * 2) remove dirt, smoothen if, crop if */ + if (scanner->val[OPT_CORRECT_INFRARED].b) /* (scanner->processing & POST_SW_IRED_MASK) */ + { + /* remove spectral overlay from ired plane */ + status = sanei_ir_spectral_clean (¶meters, scanner->ln_lut, cplane[0], cplane[3]); + if (status != SANE_STATUS_GOOD) + return status; + if (DBG_LEVEL >= 15) + { + snprintf (filename, 63, "/tmp/ir-spectral.pnm"); + pieusb_write_pnm_file (filename, cplane[3], + parameters.depth, 1, + parameters.pixels_per_line, parameters.lines); + } + if (scanner->cancel_request) /* asynchronous cancel ? */ + return SANE_STATUS_CANCELLED; + } /* scanner-> processing & POST_SW_IRED_MASK */ + + /* remove dirt, smoothen if, crop if */ + if (scanner->val[OPT_CLEAN_IMAGE].b) /* (scanner->processing & POST_SW_DIRT) */ + { + double *norm_histo; + uint16_t *thresh_data; + int static_thresh, too_thresh; /* static thresholds */ + int winsize_filter; /* primary size of filtering window */ + int size_dilate; /* the dirt mask */ + + /* size of filter detecting dirt */ + winsize_filter = (int) (5.0 * (double) scanner->mode.resolution / 300.0) | 1; + if (winsize_filter < 3) + winsize_filter = 3; + /* dirt usually has smooth edges which also need correction */ + size_dilate = scanner->mode.resolution / 1000 + 1; + + /* first detect large dirt by a static threshold */ + status = sanei_ir_create_norm_histogram (¶meters, cplane[3], &norm_histo); + if (status != SANE_STATUS_GOOD) + { + DBG (DBG_error, "pie_usb_sw_post: no buffer\n"); + return SANE_STATUS_NO_MEM; + } + /* generate a "bimodal" static threshold */ + status = sanei_ir_threshold_yen (¶meters, norm_histo, &static_thresh); + if (status != SANE_STATUS_GOOD) + return status; + /* generate traditional static threshold */ + status = sanei_ir_threshold_otsu (¶meters, norm_histo, &too_thresh); + if (status != SANE_STATUS_GOOD) + return status; + /* choose lower one */ + if (too_thresh < static_thresh) + static_thresh = too_thresh; + free (norm_histo); + + /* then generate dirt mask with adaptive thresholding filter + * and add the dirt from the static threshold */ + /* last two parameters: 10, 50 detects more, 20, 75 less */ + status = sanei_ir_filter_madmean (¶meters, cplane[3], &thresh_data, winsize_filter, 20, 100); + if (status != SANE_STATUS_GOOD) { + free (thresh_data); + return status; + } + sanei_ir_add_threshold (¶meters, cplane[3], thresh_data, static_thresh); + if (DBG_LEVEL >= 15) + { + snprintf (filename, 63, "/tmp/ir-threshold.pnm"); + pieusb_write_pnm_file (filename, thresh_data, + 8, 1, parameters.pixels_per_line, + parameters.lines); + } + if (scanner->cancel_request) { /* asynchronous cancel ? */ + free (thresh_data); + return SANE_STATUS_CANCELLED; + } + /* replace the dirt and smoothen film grain and crop if possible */ + status = sanei_ir_dilate_mean (¶meters, cplane, thresh_data, + 500, size_dilate, winsize_smooth, smooth, + 0, NULL); + if (status != SANE_STATUS_GOOD) { + free (thresh_data); + return status; + } + smooth = 0; + free (thresh_data); + } + + if (DBG_LEVEL >= 15) + { + pieusb_write_pnm_file ("/tmp/RGBi-img.pnm", scanner->buffer.data, + scanner->scan_parameters.depth, 3, scanner->scan_parameters.pixels_per_line, + scanner->scan_parameters.lines); + } + + return status; +} + +/* ------------------------------ PIE_USB_WRITE_PNM_FILE ------------------------------- */ +static SANE_Status +pieusb_write_pnm_file (char *filename, SANE_Uint *data, int depth, + int channels, int pixels_per_line, int lines) +{ + FILE *out; + int r, c, ch; + SANE_Uint val; + uint8_t b = 0; + + DBG (DBG_info_proc, + "pie_usb_write_pnm_file: depth=%d, channels=%d, ppl=%d, lines=%d\n", + depth, channels, pixels_per_line, lines); + + out = fopen (filename, "w"); + if (!out) + { + DBG (DBG_error, + "pie_usb_write_pnm_file: could not open %s for writing: %s\n", + filename, strerror (errno)); + return SANE_STATUS_INVAL; + } + + switch (depth) { + case 1: + fprintf (out, "P4\n%d\n%d\n", pixels_per_line, lines); + for (r = 0; r < lines; r++) { + int i; + i = 0; + b = 0; + for (c = 0; c < pixels_per_line; c++) { + val = *(data + r * pixels_per_line + c); + if (val > 0) b |= (0x80 >> i); + i++; + if (i == 7) { + fputc(b, out); + i = 0; + b = 0; + } + } + if (i != 0) { + fputc(b, out); + } + } + break; + case 8: + fprintf (out, "P%c\n%d\n%d\n%d\n", channels == 1 ? '5' : '6', pixels_per_line, lines, 255); + for (r = 0; r < lines; r++) { + for (c = 0; c < pixels_per_line; c++) { + for (ch = 0; ch < channels; ch++) { + val = *(data + ch * lines * pixels_per_line + r * pixels_per_line + c); + b = val & 0xFF; + fputc(b, out); + } + } + } + break; + case 16: + fprintf (out, "P%c\n%d\n%d\n%d\n", channels == 1 ? '5' : '6', pixels_per_line, lines, 65535); + for (r = 0; r < lines; r++) { + for (c = 0; c < pixels_per_line; c++) { + for (ch = 0; ch < channels; ch++) { + val = *(data + ch * lines * pixels_per_line + r * pixels_per_line + c); + b = (val >> 8) & 0xFF; + fputc(b, out); + b = val & 0xFF; + fputc(b, out); + } + } + } + break; + default: + DBG (DBG_error, "pie_usb_write_pnm_file: depth %d not implemented\n", depth); + } + fclose (out); + + DBG (DBG_info, "pie_usb_write_pnm_file: finished\n"); + return SANE_STATUS_GOOD; +} + +/** + * Check option inconsistencies. + * In most cases an inconsistency can be solved by ignoring an option setting. + * Message these situations and return 1 to indicate we can work with the + * current set op options. If the settings are really inconsistent, return 0. + */ +int +sanei_pieusb_analyse_options(struct Pieusb_Scanner *scanner) +{ + /* Checks*/ + if (scanner->val[OPT_TL_X].w > scanner->val[OPT_BR_X].w) { + DBG (DBG_error, "sane_start: %s (%.1f mm) is bigger than %s (%.1f mm) -- aborting\n", + scanner->opt[OPT_TL_X].title, + SANE_UNFIX (scanner->val[OPT_TL_X].w), + scanner->opt[OPT_BR_X].title, + SANE_UNFIX (scanner->val[OPT_BR_X].w)); + return 0; + } + if (scanner->val[OPT_TL_Y].w > scanner->val[OPT_BR_Y].w) { + DBG (DBG_error, "sane_start: %s (%.1f mm) is bigger than %s (%.1f mm) -- aborting\n", + scanner->opt[OPT_TL_Y].title, + SANE_UNFIX (scanner->val[OPT_TL_Y].w), + scanner->opt[OPT_BR_Y].title, + SANE_UNFIX (scanner->val[OPT_BR_Y].w)); + return 0; + } + /* Modes sometimes limit other choices */ + if (scanner->val[OPT_PREVIEW].b) { + /* Preview uses its own specific settings */ + if (scanner->val[OPT_RESOLUTION].w != (scanner->device->fast_preview_resolution << SANE_FIXED_SCALE_SHIFT)) { + DBG (DBG_info_sane, "Option %s = %f ignored during preview\n", scanner->opt[OPT_RESOLUTION].name, SANE_UNFIX(scanner->val[OPT_RESOLUTION].w)); + } + if (scanner->val[OPT_SHARPEN].b) { + DBG (DBG_info_sane, "Option %s = %d ignored during preview\n", scanner->opt[OPT_SHARPEN].name, scanner->val[OPT_SHARPEN].b); + } + if (!scanner->val[OPT_FAST_INFRARED].b) { + DBG (DBG_info_sane, "Option %s = %d ignored during preview\n", scanner->opt[OPT_FAST_INFRARED].name, scanner->val[OPT_FAST_INFRARED].b); + } + if (scanner->val[OPT_CORRECT_INFRARED].b) { + DBG (DBG_info_sane, "Option %s = %d ignored during preview\n", scanner->opt[OPT_CORRECT_INFRARED].name, scanner->val[OPT_CORRECT_INFRARED].b); + } + if (scanner->val[OPT_CLEAN_IMAGE].b) { + DBG (DBG_info_sane, "Option %s = %d ignored during preview\n", scanner->opt[OPT_CLEAN_IMAGE].name, scanner->val[OPT_CLEAN_IMAGE].b); + } + if (scanner->val[OPT_SMOOTH_IMAGE].w != 0) { + DBG (DBG_info_sane, "Option %s = %d ignored during preview\n", scanner->opt[OPT_SMOOTH_IMAGE].name, scanner->val[OPT_SMOOTH_IMAGE].w); + } + if (strcmp(scanner->val[OPT_CROP_IMAGE].s, scanner->device->crop_sw_list[0]) != 0) { + DBG (DBG_info_sane, "Option %s = %s ignored during preview\n", scanner->opt[OPT_CROP_IMAGE].name, scanner->val[OPT_CROP_IMAGE].s); + } + if (scanner->val[OPT_TRANSFORM_TO_SRGB].b) { + DBG (DBG_info_sane, "Option %s = %d ignored during preview\n", scanner->opt[OPT_TRANSFORM_TO_SRGB].name, scanner->val[OPT_TRANSFORM_TO_SRGB].w); + } + if (scanner->val[OPT_INVERT_IMAGE].w) { + DBG (DBG_info_sane, "Option %s = %d ignored during preview\n", scanner->opt[OPT_INVERT_IMAGE].name, scanner->val[OPT_INVERT_IMAGE].w); + } + } else if (strcmp(scanner->val[OPT_MODE].s,SANE_VALUE_SCAN_MODE_LINEART)==0) { + /* Can we do any post processing in lineart? Needs testing to see what's possible */ + if (scanner->val[OPT_BIT_DEPTH].w != 1) { + DBG (DBG_info_sane, "Option %s = %d ignored in lineart mode (will use 1)\n", scanner->opt[OPT_BIT_DEPTH].name, scanner->val[OPT_BIT_DEPTH].w); + } + if (!scanner->val[OPT_FAST_INFRARED].b) { + DBG (DBG_info_sane, "Option %s = %d ignored in lineart mode (irrelevant)\n", scanner->opt[OPT_FAST_INFRARED].name, scanner->val[OPT_FAST_INFRARED].b); + } + if (!scanner->val[OPT_CORRECT_SHADING].b) { + DBG (DBG_info_sane, "Option %s = %d ignored in lineart mode (irrelevant)\n", scanner->opt[OPT_CORRECT_SHADING].name, scanner->val[OPT_CORRECT_SHADING].b); + } + if (!scanner->val[OPT_CORRECT_INFRARED].b) { + DBG (DBG_info_sane, "Option %s = %d ignored in lineart mode (irrelevant)\n", scanner->opt[OPT_CORRECT_INFRARED].name, scanner->val[OPT_CORRECT_INFRARED].b); + } + if (scanner->val[OPT_CLEAN_IMAGE].b) { + DBG (DBG_info_sane, "Option %s = %d ignored in lineart mode (irrelevant)\n", scanner->opt[OPT_CLEAN_IMAGE].name, scanner->val[OPT_CLEAN_IMAGE].b); + } + if (scanner->val[OPT_SMOOTH_IMAGE].w != 0) { + DBG (DBG_info_sane, "Option %s = %d ignored in lineart mode (irrelevant)\n", scanner->opt[OPT_SMOOTH_IMAGE].name, scanner->val[OPT_SMOOTH_IMAGE].w); + } + if (strcmp(scanner->val[OPT_CROP_IMAGE].s, scanner->device->crop_sw_list[0]) != 0) { + DBG (DBG_info_sane, "Option %s = %s ignored in lineart mode (irrelevant)\n", scanner->opt[OPT_CROP_IMAGE].name, scanner->val[OPT_CROP_IMAGE].s); + } + if (scanner->val[OPT_TRANSFORM_TO_SRGB].b) { + DBG (DBG_info_sane, "Option %s = %d ignored in lineart mode (irrelevant)\n", scanner->opt[OPT_TRANSFORM_TO_SRGB].name, scanner->val[OPT_TRANSFORM_TO_SRGB].w); + } + } else if (strcmp(scanner->val[OPT_MODE].s,SANE_VALUE_SCAN_MODE_HALFTONE)==0) { + /* Can we do any post processing in halftone? Needs testing to see what's possible */ + if (scanner->val[OPT_BIT_DEPTH].w != 1) { + DBG (DBG_info_sane, "Option %s = %d ignored in halftone mode (will use 1)\n", scanner->opt[OPT_BIT_DEPTH].name, scanner->val[OPT_BIT_DEPTH].w); + } + if (!scanner->val[OPT_FAST_INFRARED].b) { + DBG (DBG_info_sane, "Option %s = %d ignored in halftone mode (irrelevant)\n", scanner->opt[OPT_FAST_INFRARED].name, scanner->val[OPT_FAST_INFRARED].b); + } + if (!scanner->val[OPT_CORRECT_SHADING].b) { + DBG (DBG_info_sane, "Option %s = %d ignored in halftone mode (irrelevant)\n", scanner->opt[OPT_CORRECT_SHADING].name, scanner->val[OPT_CORRECT_SHADING].b); + } + if (!scanner->val[OPT_CORRECT_INFRARED].b) { + DBG (DBG_info_sane, "Option %s = %d ignored in halftone mode (irrelevant)\n", scanner->opt[OPT_CORRECT_INFRARED].name, scanner->val[OPT_CORRECT_INFRARED].b); + } + if (scanner->val[OPT_CLEAN_IMAGE].b) { + DBG (DBG_info_sane, "Option %s = %d ignored in halftone mode (irrelevant)\n", scanner->opt[OPT_CLEAN_IMAGE].name, scanner->val[OPT_CLEAN_IMAGE].b); + } + if (scanner->val[OPT_SMOOTH_IMAGE].w != 0) { + DBG (DBG_info_sane, "Option %s = %d ignored in halftone mode (irrelevant)\n", scanner->opt[OPT_SMOOTH_IMAGE].name, scanner->val[OPT_SMOOTH_IMAGE].w); + } + if (strcmp(scanner->val[OPT_CROP_IMAGE].s, scanner->device->crop_sw_list[0]) != 0) { + DBG (DBG_info_sane, "Option %s = %s ignored in halftone mode (irrelevant)\n", scanner->opt[OPT_CROP_IMAGE].name, scanner->val[OPT_CROP_IMAGE].s); + } + if (scanner->val[OPT_TRANSFORM_TO_SRGB].b) { + DBG (DBG_info_sane, "Option %s = %d ignored in halftone mode (irrelevant)\n", scanner->opt[OPT_TRANSFORM_TO_SRGB].name, scanner->val[OPT_TRANSFORM_TO_SRGB].w); + } + } else if (strcmp(scanner->val[OPT_MODE].s,SANE_VALUE_SCAN_MODE_GRAY)==0) { + /* Can we do any post processing in gray mode? */ + /* Can we obtain a single color channel in this mode? How? */ + /* Is this just RGB with luminance trasformation? */ + /* Needs testing to see what's possible */ + /* Only do 8 or 16 bit scans */ + if (scanner->val[OPT_BIT_DEPTH].w == 1) { + DBG (DBG_info_sane, "Option %s = %d ignored in gray mode (will use 8)\n", scanner->opt[OPT_BIT_DEPTH].name, scanner->val[OPT_BIT_DEPTH].w); + } + if (!scanner->val[OPT_FAST_INFRARED].b) { + DBG (DBG_info_sane, "Option %s = %d ignored in gray mode (irrelevant)\n", scanner->opt[OPT_FAST_INFRARED].name, scanner->val[OPT_FAST_INFRARED].b); + } + if (!scanner->val[OPT_CORRECT_INFRARED].b) { + DBG (DBG_info_sane, "Option %s = %d ignored in gray mode (irrelevant)\n", scanner->opt[OPT_CORRECT_INFRARED].name, scanner->val[OPT_CORRECT_INFRARED].b); + } + if (scanner->val[OPT_CLEAN_IMAGE].b) { + DBG (DBG_info_sane, "Option %s = %d ignored in gray mode (irrelevant)\n", scanner->opt[OPT_CLEAN_IMAGE].name, scanner->val[OPT_CLEAN_IMAGE].b); + } + if (scanner->val[OPT_TRANSFORM_TO_SRGB].b) { + DBG (DBG_info_sane, "Option %s = %d ignored in gray mode (irrelevant)\n", scanner->opt[OPT_TRANSFORM_TO_SRGB].name, scanner->val[OPT_TRANSFORM_TO_SRGB].w); + } + } else if (strcmp(scanner->val[OPT_MODE].s,SANE_VALUE_SCAN_MODE_COLOR)==0) { + /* Some options require infrared data to be obtained, so all infrared options are relevant */ + /* Only do 8 or 16 bit scans */ + if (scanner->val[OPT_BIT_DEPTH].w == 1) { + DBG (DBG_info_sane, "Option %s = %d ignored in color mode (will use 8)\n", scanner->opt[OPT_BIT_DEPTH].name, scanner->val[OPT_BIT_DEPTH].w); + } + } else if (strcmp(scanner->val[OPT_MODE].s,SANE_VALUE_SCAN_MODE_RGBI)==0) { + /* Only do 8 or 16 bit scans */ + if (scanner->val[OPT_BIT_DEPTH].w == 1) { + DBG (DBG_info_sane, "Option %s = %d ignored in color mode (will use 8)\n", scanner->opt[OPT_BIT_DEPTH].name, scanner->val[OPT_BIT_DEPTH].w); + } + } + + return 1; +} + +/** + * Print options + * + * @param scanner + */ +void +sanei_pieusb_print_options(struct Pieusb_Scanner *scanner) +{ + int k; + /* List current options and values */ + DBG (DBG_info, "Num options = %d\n", scanner->val[OPT_NUM_OPTS].w); + for (k = 1; k < scanner->val[OPT_NUM_OPTS].w; k++) { + switch (scanner->opt[k].type) { + case SANE_TYPE_BOOL: + DBG(DBG_info," Option %d: %s = %d\n", k, scanner->opt[k].name, scanner->val[k].b); + break; + case SANE_TYPE_INT: + DBG(DBG_info," Option %d: %s = %d\n", k, scanner->opt[k].name, scanner->val[k].w); + break; + case SANE_TYPE_FIXED: + DBG(DBG_info," Option %d: %s = %f\n", k, scanner->opt[k].name, SANE_UNFIX (scanner->val[k].w)); + break; + case SANE_TYPE_STRING: + DBG(DBG_info," Option %d: %s = %s\n", k, scanner->opt[k].name, scanner->val[k].s); + break; + case SANE_TYPE_GROUP: + DBG(DBG_info," Option %d: %s = %s\n", k, scanner->opt[k].title, scanner->val[k].s); + break; + default: + DBG(DBG_info," Option %d: %s unknown type %d\n", k, scanner->opt[k].name, scanner->opt[k].type); + break; + } + } +} + +/** + * Calculate reference values for each pixel, line means and line maxima. + * We have got 45 lines for all four colors and for each CCD pixel. + * The reference value for each pixel is the 45-line average for that + * pixel, for each color separately. + * + * @param scanner + * @param buffer + */ +static void pieusb_calculate_shading(struct Pieusb_Scanner *scanner, SANE_Byte* buffer) +{ + int k, m; + SANE_Byte* p; + SANE_Int ci, val; + SANE_Int shading_width = scanner->device->shading_parameters[0].pixelsPerLine; + SANE_Int shading_height = scanner->device->shading_parameters[0].nLines; + + /* Initialze all to 0 */ + for (k = 0; k < SHADING_PARAMETERS_INFO_COUNT; k++) { + scanner->shading_max[k] = 0; + scanner->shading_mean[k] = 0; + memset(scanner->shading_ref[k], 0, shading_width * sizeof (SANE_Int)); + } + /* Process data from buffer */ + p = buffer; + switch (scanner->mode.colorFormat) { + case 0x01: /* Pixel */ + /* Process pixel by pixel */ + for (k = 0; k < shading_height; k++) { + for (m = 0; m < shading_width; m++) { + for (ci = 0; ci < SHADING_PARAMETERS_INFO_COUNT; ci++) { + val = *(p) + *(p+1) * 256; + scanner->shading_ref[ci][m] += val; + scanner->shading_max[ci] = scanner->shading_max[ci] < val ? val : scanner->shading_max[ci]; + p += 2; + } + } + } + break; + case 0x04: /* Indexed */ + /* Process each line in the sequence found in the buffer */ + for (k = 0; k < shading_height*4; k++) { + /* Save at right color */ + switch (*p) { + case 'R': ci = 0; break; + case 'G': ci = 1; break; + case 'B': ci = 2; break; + case 'I': ci = 3; break; + default: ci = -1; break; /* ignore line */ + } + /* Add scanned data to reference line and keep track of maximum */ + if (ci != -1) { + for (m = 0; m < shading_width; m++) { + val = *(p+2+2*m) + *(p+2+2*m+1) * 256; + scanner->shading_ref[ci][m] += val; + scanner->shading_max[ci] = scanner->shading_max[ci] < val ? val : scanner->shading_max[ci]; + /* DBG(DBG_error,"%02d Shading_ref[%d][%d] = %d\n",k,ci,m,scanner->shading_ref[ci][m]); */ + } + } + /* Next line */ + p += 2*shading_width+2; + } + break; + default: + DBG (DBG_error,"sane_start(): color format %d not implemented\n",scanner->mode.colorFormat); + return; + } + /* Mean reference value needs division */ + for (k = 0; k < SHADING_PARAMETERS_INFO_COUNT; k++) { + for (m = 0; m < shading_width; m++) { + scanner->shading_ref[k][m] = lround((double)scanner->shading_ref[k][m]/shading_height); + /* DBG(DBG_error,"Shading_ref[%d][%d] = %d\n",k,m,scanner->shading_ref[k][m]); */ + } + } + /* Overall means */ + for (k = 0; k < SHADING_PARAMETERS_INFO_COUNT; k++) { + for (m=0; m<shading_width; m++) { + scanner->shading_mean[k] += scanner->shading_ref[k][m]; + } + scanner->shading_mean[k] = lround((double)scanner->shading_mean[k]/shading_width); + DBG (DBG_error,"Shading_mean[%d] = %d\n",k,scanner->shading_mean[k]); + } + + /* Set shading data present */ + scanner->shading_data_present = SANE_TRUE; + + /* Export shading data as TIFF */ +#ifdef CAN_DO_4_CHANNEL_TIFF + if (scanner->val[OPT_SAVE_SHADINGDATA].b) { + struct Pieusb_Read_Buffer shading; + SANE_Byte* lboff = buffer; + SANE_Int bpl = shading_width*2; + SANE_Int n; + buffer_create(&shading, shading_width, shading_height, 0x0F, 16); + for (n=0; n<4*shading_height; n++) { + if (buffer_put_single_color_line(&shading, *lboff, lboff+2, bpl) == 0) { + break; + } + lboff += (bpl + 2); + } + FILE* fs = fopen("pieusb.shading", "w"); + /* write_tiff_rgbi_header (fs, shading_width, shading_height, 16, 3600, NULL); */ + fwrite(shading.data, 1, shading.image_size_bytes, fs); + fclose(fs); + buffer_delete(&shading); + } +#endif + +} + +/* + * Set frame (from scanner options) + */ + +SANE_Status +sanei_pieusb_set_frame_from_options(Pieusb_Scanner * scanner) +{ + double dpmm; + struct Pieusb_Command_Status status; + + dpmm = (double) scanner->device->maximum_resolution / MM_PER_INCH; + scanner->frame.x0 = SANE_UNFIX(scanner->val[OPT_TL_X].w) * dpmm; + scanner->frame.y0 = SANE_UNFIX(scanner->val[OPT_TL_Y].w) * dpmm; + scanner->frame.x1 = SANE_UNFIX(scanner->val[OPT_BR_X].w) * dpmm; + scanner->frame.y1 = SANE_UNFIX(scanner->val[OPT_BR_Y].w) * dpmm; + 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; +} + +/* + * Set mode (from scanner options) + */ + +SANE_Status +sanei_pieusb_set_mode_from_options(Pieusb_Scanner * scanner) +{ + struct Pieusb_Command_Status status; + const char *mode; + SANE_Status res; + + mode = scanner->val[OPT_MODE].s; + if (strcmp (mode, SANE_VALUE_SCAN_MODE_LINEART) == 0) { + scanner->mode.passes = SCAN_FILTER_GREEN; /* G */ + scanner->mode.colorFormat = SCAN_COLOR_FORMAT_PIXEL; + } else if(strcmp (mode, SANE_VALUE_SCAN_MODE_HALFTONE) == 0) { + scanner->mode.passes = SCAN_FILTER_GREEN; /* G */ + scanner->mode.colorFormat = SCAN_COLOR_FORMAT_PIXEL; + } else if(strcmp (mode, SANE_VALUE_SCAN_MODE_GRAY) == 0) { + scanner->mode.passes = SCAN_FILTER_GREEN; /* G=gray; unable to get R & B & I to work */ + scanner->mode.colorFormat = SCAN_COLOR_FORMAT_PIXEL; + } else if(scanner->val[OPT_PREVIEW].b) { + /* Catch preview here, otherwise next ifs get complicated */ + scanner->mode.passes = SCAN_ONE_PASS_COLOR; + scanner->mode.colorFormat = SCAN_COLOR_FORMAT_INDEX; /* pixel format might be an alternative */ + } else if(strcmp (mode, SANE_VALUE_SCAN_MODE_RGBI) == 0) { + scanner->mode.passes = SCAN_ONE_PASS_RGBI; + scanner->mode.colorFormat = SCAN_COLOR_FORMAT_INDEX; + } else if(strcmp (mode, SANE_VALUE_SCAN_MODE_COLOR) == 0 && scanner->val[OPT_CLEAN_IMAGE].b) { + scanner->mode.passes = SCAN_ONE_PASS_RGBI; /* Need infrared for cleaning */ + scanner->mode.colorFormat = SCAN_COLOR_FORMAT_INDEX; + } else { /* SANE_VALUE_SCAN_MODE_COLOR */ + scanner->mode.passes = SCAN_ONE_PASS_COLOR; + scanner->mode.colorFormat = SCAN_COLOR_FORMAT_INDEX; /* pixel format might be an alternative */ + } + /* Resolution */ + if (scanner->val[OPT_PREVIEW].b) { + scanner->mode.resolution = scanner->device->fast_preview_resolution; + DBG (DBG_info_sane, "sanei_pieusb_set_mode_from_options(): resolution fast preview (%d)\n", scanner->mode.resolution); + } else { + scanner->mode.resolution = SANE_UNFIX (scanner->val[OPT_RESOLUTION].w); + DBG (DBG_info_sane, "sanei_pieusb_set_mode_from_options(): resolution from option setting (%d)\n", scanner->mode.resolution); + } + /* Bit depth: exit on untested values */ + switch (scanner->val[OPT_BIT_DEPTH].w) { + case 1: scanner->mode.colorDepth = SCAN_COLOR_DEPTH_1; break; + case 8: scanner->mode.colorDepth = SCAN_COLOR_DEPTH_8; break; + case 16: scanner->mode.colorDepth = SCAN_COLOR_DEPTH_16; break; + default: /* 4, 10 & 12 */ + DBG (DBG_error, "sanei_pieusb_set_mode_from_options(): sanei_pieusb_cmd_set_scan_frame untested bit depth %d\n", scanner->val[OPT_BIT_DEPTH].w); + return SANE_STATUS_INVAL; + } + scanner->mode.byteOrder = 0x01; /* 0x01 = Intel; only bit 0 used */ + scanner->mode.sharpen = scanner->val[OPT_SHARPEN].b && !scanner->val[OPT_PREVIEW].b; + scanner->mode.skipShadingAnalysis = !scanner->val[OPT_SHADING_ANALYSIS].b; + scanner->mode.fastInfrared = scanner->val[OPT_FAST_INFRARED].b && !scanner->val[OPT_PREVIEW].b; + if (strcmp (scanner->val[OPT_HALFTONE_PATTERN].s, "53lpi 45d ROUND") == 0) { + scanner->mode.halftonePattern = 0; + } else { /*TODO: the others */ + scanner->mode.halftonePattern = 0; + } + scanner->mode.lineThreshold = SANE_UNFIX (scanner->val[OPT_THRESHOLD].w) / 100 * 0xFF; /* 0xFF = 100% */ + sanei_pieusb_cmd_set_mode (scanner->device_number, &(scanner->mode), &status); + res = sanei_pieusb_convert_status(status.pieusb_status); + if (res == SANE_STATUS_GOOD) { + res = sanei_pieusb_wait_ready (scanner, 0); + } + DBG (DBG_info_sane, "sanei_pieusb_set_mode_from_options(): sanei_pieusb_cmd_set_mode status %s\n", sane_strstatus(res)); + return res; +} + +/** + * Set gains, exposure and offset, to: + * - values default (pieusb_set_default_gain_offset) + * - values set by options + * - values set by auto-calibration procedure + * - values determined from preceeding preview + * + * @param scanner + * @return + */ +SANE_Status +sanei_pieusb_set_gain_offset(Pieusb_Scanner * scanner, const char *calibration_mode) +{ + struct Pieusb_Command_Status status; + SANE_Status ret; + double gain; + + DBG (DBG_info,"sanei_pieusb_set_gain_offset(): mode = %s\n", calibration_mode); + + if (strcmp (calibration_mode, SCAN_CALIBRATION_DEFAULT) == 0) { + /* Default values */ + DBG(DBG_info_sane,"sanei_pieusb_set_gain_offset(): get calibration data from defaults\n"); + scanner->settings.exposureTime[0] = DEFAULT_EXPOSURE; + scanner->settings.exposureTime[1] = DEFAULT_EXPOSURE; + scanner->settings.exposureTime[2] = DEFAULT_EXPOSURE; + scanner->settings.exposureTime[3] = DEFAULT_EXPOSURE; + scanner->settings.offset[0] = DEFAULT_OFFSET; + scanner->settings.offset[1] = DEFAULT_OFFSET; + scanner->settings.offset[2] = DEFAULT_OFFSET; + scanner->settings.offset[3] = DEFAULT_OFFSET; + scanner->settings.gain[0] = DEFAULT_GAIN; + scanner->settings.gain[1] = DEFAULT_GAIN; + scanner->settings.gain[2] = DEFAULT_GAIN; + scanner->settings.gain[3] = DEFAULT_GAIN; + scanner->settings.light = DEFAULT_LIGHT; + scanner->settings.extraEntries = DEFAULT_ADDITIONAL_ENTRIES; + scanner->settings.doubleTimes = DEFAULT_DOUBLE_TIMES; + status.pieusb_status = PIEUSB_STATUS_GOOD; + } else if ((strcmp(calibration_mode, SCAN_CALIBRATION_PREVIEW) == 0) + && scanner->preview_done) { + /* If no preview data availble, do the auto-calibration. */ + double dg, dgi; + DBG (DBG_info, "sanei_pieusb_set_gain_offset(): get calibration data from preview. scanner->mode.passes %d\n", scanner->mode.passes); + switch (scanner->mode.passes) { + case SCAN_ONE_PASS_RGBI: + dg = 3.00; + dgi = ((double)scanner->settings.saturationLevel[0] / 65536) / ((double)scanner->preview_upper_bound[0] / HISTOGRAM_SIZE); + if (dgi < dg) dg = dgi; + dgi = ((double)scanner->settings.saturationLevel[1] / 65536) / ((double)scanner->preview_upper_bound[1] / HISTOGRAM_SIZE); + if (dgi < dg) dg = dgi; + dgi = ((double)scanner->settings.saturationLevel[2] / 65536) / ((double)scanner->preview_upper_bound[2] / HISTOGRAM_SIZE); + if (dgi < dg) dg = dgi; + updateGain2(scanner, 0, dg); + updateGain2(scanner, 1, dg); + updateGain2(scanner, 2, dg); + break; + case SCAN_ONE_PASS_COLOR: + dg = 3.00; + dgi = ((double)scanner->settings.saturationLevel[0] / 65536) / ((double)scanner->preview_upper_bound[0] / HISTOGRAM_SIZE); + if (dgi < dg) dg = dgi; + dgi = ((double)scanner->settings.saturationLevel[1] / 65536) / ((double)scanner->preview_upper_bound[1] / HISTOGRAM_SIZE); + if (dgi < dg) dg = dgi; + dgi = ((double)scanner->settings.saturationLevel[2] / 65536) / ((double)scanner->preview_upper_bound[2] / HISTOGRAM_SIZE); + if (dgi < dg) dg = dgi; + updateGain2(scanner, 0, dg); + updateGain2(scanner, 1, dg); + updateGain2(scanner, 2, dg); + break; + case SCAN_FILTER_BLUE: + dg = 3.00; + dgi = ((double)scanner->settings.saturationLevel[2] / 65536) / ((double)scanner->preview_upper_bound[2] / HISTOGRAM_SIZE); + if (dgi < dg) dg = dgi; + updateGain2(scanner, 2, dg); + break; + case SCAN_FILTER_GREEN: + dg = 3.00; + dgi = ((double)scanner->settings.saturationLevel[1] / 65536) / ((double)scanner->preview_upper_bound[1] / HISTOGRAM_SIZE); + if (dgi < dg) dg = dgi; + updateGain2(scanner, 1, dg); + break; + case SCAN_FILTER_RED: + dg = 3.00; + dgi = ((double)scanner->settings.saturationLevel[0] / 65536) / ((double)scanner->preview_upper_bound[0] / HISTOGRAM_SIZE); + if (dgi < dg) dg = dgi; + updateGain2(scanner, 0, dg); + break; + case SCAN_FILTER_NEUTRAL: + break; + } + status.pieusb_status = PIEUSB_STATUS_GOOD; + } else if (strcmp (calibration_mode, SCAN_CALIBRATION_OPTIONS) == 0) { + DBG (DBG_info_sane, "sanei_pieusb_set_gain_offset(): get calibration data from options\n"); + /* Exposure times */ + scanner->settings.exposureTime[0] = scanner->val[OPT_SET_EXPOSURE_R].w; + scanner->settings.exposureTime[1] = scanner->val[OPT_SET_EXPOSURE_G].w; + scanner->settings.exposureTime[2] = scanner->val[OPT_SET_EXPOSURE_B].w; + scanner->settings.exposureTime[3] = scanner->val[OPT_SET_EXPOSURE_I].w; /* Infrared */ + /* Offsets */ + scanner->settings.offset[0] = scanner->val[OPT_SET_OFFSET_R].w; + scanner->settings.offset[1] = scanner->val[OPT_SET_OFFSET_G].w; + scanner->settings.offset[2] = scanner->val[OPT_SET_OFFSET_B].w; + scanner->settings.offset[3] = scanner->val[OPT_SET_OFFSET_I].w; /* Infrared */ + /* Gains */ + scanner->settings.gain[0] = scanner->val[OPT_SET_GAIN_R].w; + scanner->settings.gain[1] = scanner->val[OPT_SET_GAIN_G].w; + scanner->settings.gain[2] = scanner->val[OPT_SET_GAIN_B].w; + scanner->settings.gain[3] = scanner->val[OPT_SET_GAIN_I].w; /* Infrared */ + /* Light, extra entries and doubling */ + scanner->settings.light = scanner->val[OPT_LIGHT].w; + scanner->settings.extraEntries = DEFAULT_ADDITIONAL_ENTRIES; + scanner->settings.doubleTimes = scanner->val[OPT_DOUBLE_TIMES].w; + status.pieusb_status = PIEUSB_STATUS_GOOD; + } else { /* SCAN_CALIBRATION_AUTO */ + DBG (DBG_info_sane, "sanei_pieusb_set_gain_offset(): get calibration data from scanner\n"); + sanei_pieusb_cmd_get_gain_offset (scanner->device_number, &scanner->settings, &status); + } + /* Check status */ + if (status.pieusb_status == PIEUSB_STATUS_DEVICE_BUSY) { + ret = sanei_pieusb_wait_ready (scanner, 0); + if (ret != SANE_STATUS_GOOD) { + DBG (DBG_error,"sanei_pieusb_set_gain_offset(): not ready after sanei_pieusb_cmd_get_gain_offset(): %d\n", ret); + return ret; + } + } + else if (status.pieusb_status != PIEUSB_STATUS_GOOD) { + return SANE_STATUS_INVAL; + } + /* Adjust gain */ + gain = 1.0; + if (strcmp (scanner->val[OPT_GAIN_ADJUST].s, SCAN_GAIN_ADJUST_03) == 0) { + gain = 0.3; + } else if (strcmp (scanner->val[OPT_GAIN_ADJUST].s, SCAN_GAIN_ADJUST_05) == 0) { + gain = 0.5; + } else if (strcmp (scanner->val[OPT_GAIN_ADJUST].s, SCAN_GAIN_ADJUST_08) == 0) { + gain = 0.8; + } else if (strcmp (scanner->val[OPT_GAIN_ADJUST].s, SCAN_GAIN_ADJUST_10) == 0) { + gain = 1.0; + } else if (strcmp (scanner->val[OPT_GAIN_ADJUST].s, SCAN_GAIN_ADJUST_12) == 0) { + gain = 1.2; + } else if (strcmp (scanner->val[OPT_GAIN_ADJUST].s, SCAN_GAIN_ADJUST_16) == 0) { + gain = 1.6; + } else if (strcmp (scanner->val[OPT_GAIN_ADJUST].s, SCAN_GAIN_ADJUST_19) == 0) { + gain = 1.9; + } else if (strcmp (scanner->val[OPT_GAIN_ADJUST].s, SCAN_GAIN_ADJUST_24) == 0) { + gain = 2.4; + } else if (strcmp (scanner->val[OPT_GAIN_ADJUST].s, SCAN_GAIN_ADJUST_30) == 0) { + gain = 3.0; + } + switch (scanner->mode.passes) { + case SCAN_ONE_PASS_RGBI: + case SCAN_ONE_PASS_COLOR: + updateGain2 (scanner, 0, gain); + updateGain2 (scanner, 1, gain); + updateGain2 (scanner, 2, gain); + /* Don't correct IR, hampers cleaning process... */ + break; + case SCAN_FILTER_INFRARED: + updateGain2 (scanner, 3, gain); + break; + case SCAN_FILTER_BLUE: + updateGain2 (scanner, 2, gain); + break; + case SCAN_FILTER_GREEN: + updateGain2 (scanner, 1, gain); + break; + case SCAN_FILTER_RED: + updateGain2 (scanner, 0, gain); + break; + case SCAN_FILTER_NEUTRAL: + break; + } + /* Now set values for gain, offset and exposure */ + sanei_pieusb_cmd_set_gain_offset (scanner->device_number, &(scanner->settings), &status); + ret = sanei_pieusb_convert_status (status.pieusb_status); + DBG (DBG_info_sane, "sanei_pieusb_set_gain_offset(): status %s\n", sane_strstatus (ret)); + return ret; +} + +/* + * get shading data + * must be called immediately after sanei_pieusb_set_gain_offset + */ + +SANE_Status +sanei_pieusb_get_shading_data(Pieusb_Scanner * scanner) +{ + struct Pieusb_Command_Status status; + SANE_Int shading_width; + SANE_Int shading_height; + SANE_Byte* buffer; + SANE_Int lines; + SANE_Int cols; + SANE_Int size; + SANE_Status res = SANE_STATUS_GOOD; + + DBG (DBG_info_sane, "sanei_pieusb_get_shading_data()\n"); + shading_width = scanner->device->shading_parameters[0].pixelsPerLine; + shading_height = scanner->device->shading_parameters[0].nLines; + if (shading_height < 1) { + DBG (DBG_error, "shading_height < 1\n"); + return SANE_STATUS_INVAL; + } + switch (scanner->mode.colorFormat) { + case SCAN_COLOR_FORMAT_PIXEL: /* Pixel */ + lines = shading_height * 4; + cols = 2 * shading_width; + break; + case SCAN_COLOR_FORMAT_INDEX: /* Indexed */ + lines = shading_height * 4; + cols = (2 * shading_width + 2); + break; + default: + DBG (DBG_error, "sanei_pieusb_get_shading_data(): color format %d not implemented\n", scanner->mode.colorFormat); + return SANE_STATUS_INVAL; + } + + size = cols * lines; + buffer = malloc (size); + if (buffer == NULL) { + return SANE_STATUS_NO_MEM; + } + sanei_pieusb_cmd_get_scanned_lines (scanner->device_number, buffer, 4, cols * 4, &status); + if (status.pieusb_status == PIEUSB_STATUS_GOOD) { + res = sanei_pieusb_wait_ready (scanner, 0); + if (res == SANE_STATUS_GOOD) { + sanei_pieusb_cmd_get_scanned_lines (scanner->device_number, buffer + cols*4, lines - 4, (lines - 4) * cols, &status); + if (status.pieusb_status == PIEUSB_STATUS_GOOD) { + pieusb_calculate_shading (scanner, buffer); + } + res = sanei_pieusb_convert_status (status.pieusb_status); + } + } + else { + res = sanei_pieusb_convert_status (status.pieusb_status); + } + free (buffer); + return res; +} + +/* + * + */ + +SANE_Status +sanei_pieusb_get_ccd_mask(Pieusb_Scanner * scanner) +{ + struct Pieusb_Command_Status status; + + DBG(DBG_info_proc, "sanei_pieusb_get_ccd_mask()\n"); + + sanei_pieusb_cmd_get_ccd_mask(scanner->device_number, scanner->ccd_mask, scanner->ccd_mask_size, &status); + if (status.pieusb_status == PIEUSB_STATUS_GOOD) { + /* Save CCD mask */ + if (scanner->val[OPT_SAVE_CCDMASK].b) { + FILE* fs = fopen ("pieusb.ccd", "w"); + fwrite (scanner->ccd_mask, 1, scanner->ccd_mask_size, fs); + fclose (fs); + } + } + return sanei_pieusb_convert_status(status.pieusb_status); + +} + +/** + * Read parameters from scanner + * and initialize SANE parameters + * + * @param scanner + * @return parameter_bytes for use in get_scan_data() + */ +SANE_Status +sanei_pieusb_get_parameters(Pieusb_Scanner * scanner, SANE_Int *parameter_bytes) +{ + struct Pieusb_Command_Status status; + struct Pieusb_Scan_Parameters parameters; + const char *mode; + + DBG (DBG_info_proc, "sanei_pieusb_get_parameters()\n"); + + sanei_pieusb_cmd_get_parameters (scanner->device_number, ¶meters, &status); + if (status.pieusb_status != PIEUSB_STATUS_GOOD) { + return sanei_pieusb_convert_status (status.pieusb_status); + } + *parameter_bytes = parameters.bytes; + /* Use response from sanei_pieusb_cmd_get_parameters() for initialization of SANE parameters. + * Note the weird values of the bytes-field: this is because of the colorFormat + * setting in sanei_pieusb_cmd_set_mode(). The single-color modes all use the pixel format, + * which makes sanei_pieusb_cmd_get_parameters() return a full color line although just + * one color actually contains data. For the index format, the bytes field + * gives the size of a single color line. */ + mode = scanner->val[OPT_MODE].s; + if (strcmp (mode, SANE_VALUE_SCAN_MODE_LINEART) == 0) { + scanner->scan_parameters.format = SANE_FRAME_GRAY; + scanner->scan_parameters.depth = 1; + scanner->scan_parameters.bytes_per_line = parameters.bytes/3; + } else if (strcmp (mode, SANE_VALUE_SCAN_MODE_HALFTONE) == 0) { + scanner->scan_parameters.format = SANE_FRAME_GRAY; + scanner->scan_parameters.depth = 1; + scanner->scan_parameters.bytes_per_line = parameters.bytes/3; + } else if (strcmp (mode, SANE_VALUE_SCAN_MODE_GRAY) == 0) { + scanner->scan_parameters.format = SANE_FRAME_GRAY; + scanner->scan_parameters.depth = scanner->val[OPT_BIT_DEPTH].w; + scanner->scan_parameters.bytes_per_line = parameters.bytes/3; + } else if (strcmp (mode, SANE_VALUE_SCAN_MODE_RGBI) == 0) { + scanner->scan_parameters.format = SANE_FRAME_RGB; /* was: SANE_FRAME_RGBI */ + scanner->scan_parameters.depth = scanner->val[OPT_BIT_DEPTH].w; + scanner->scan_parameters.bytes_per_line = 4*parameters.bytes; + } else { /* SANE_VALUE_SCAN_MODE_COLOR, with and without option clean image set */ + scanner->scan_parameters.format = SANE_FRAME_RGB; + scanner->scan_parameters.depth = scanner->val[OPT_BIT_DEPTH].w; + scanner->scan_parameters.bytes_per_line = 3*parameters.bytes; + } + scanner->scan_parameters.lines = parameters.lines; + scanner->scan_parameters.pixels_per_line = parameters.width; + scanner->scan_parameters.last_frame = SANE_TRUE; + + DBG (DBG_info_sane,"sanei_pieusb_get_parameters(): mode '%s'\n", mode); + DBG (DBG_info_sane," format = %d\n", scanner->scan_parameters.format); + DBG (DBG_info_sane," depth = %d\n", scanner->scan_parameters.depth); + DBG (DBG_info_sane," bytes_per_line = %d\n", scanner->scan_parameters.bytes_per_line); + DBG (DBG_info_sane," lines = %d\n", scanner->scan_parameters.lines); + DBG (DBG_info_sane," pixels_per_line = %d\n", scanner->scan_parameters.pixels_per_line); + DBG (DBG_info_sane," last_frame = %d\n", scanner->scan_parameters.last_frame); + + return SANE_STATUS_GOOD; +} + +SANE_Status +sanei_pieusb_get_scan_data(Pieusb_Scanner * scanner, SANE_Int parameter_bytes) +{ + struct Pieusb_Command_Status status; + SANE_Parameters *parameters = &scanner->scan_parameters; + SANE_Int lines_to_read, lines_remaining; + SANE_Int ppl, bpl; + SANE_Byte *linebuf, *lboff; + SANE_Bool compress; + int n, k, i; + + switch (scanner->mode.colorFormat) { + case SCAN_COLOR_FORMAT_PIXEL: /* Pixel */ + lines_to_read = scanner->buffer.height; + break; + case SCAN_COLOR_FORMAT_INDEX: /* Indexed */ + lines_to_read = scanner->buffer.colors * scanner->buffer.height; + break; + default: + DBG(DBG_error, "sanei_pieusb_get_scan_data(): color format %d not implemented\n",scanner->mode.colorFormat); + return SANE_STATUS_INVAL; + } + lines_remaining = lines_to_read; + DBG (DBG_info_proc, "sanei_pieusb_get_scan_data(colorFormat %d), lines_to_read %d, bytes %d\n", scanner->mode.colorFormat, lines_to_read, parameter_bytes); + + /* + fdraw = open("/tmp/pieusb.raw", O_WRONLY | O_CREAT | O_TRUNC, (mode_t)0600); + if (fdraw == -1) { + perror("error opening raw image buffer file"); + } +*/ + while (lines_remaining > 0) { + SANE_Int lines; + /* Read lines */ + /* The amount of bytes_per_line varies with color format setting; only 'pixel' and 'index' implemented */ + ppl = parameters->pixels_per_line; + switch (scanner->mode.colorFormat) { + case SCAN_COLOR_FORMAT_PIXEL: /* Pixel */ + bpl = parameter_bytes; + break; + case SCAN_COLOR_FORMAT_INDEX: /* Indexed */ + bpl = parameter_bytes + 2; /* Index bytes! */ + break; + default: + DBG(DBG_error, "sanei_pieusb_get_scan_data(): color format %d not implemented\n", scanner->mode.colorFormat); + return SANE_STATUS_INVAL; + } + lines = (lines_remaining < 256) ? lines_remaining : 255; + DBG(DBG_info_sane, "sanei_pieusb_get_scan_data(): reading lines: now %d, bytes per line = %d\n", lines, bpl); + linebuf = malloc(lines * bpl); + sanei_pieusb_cmd_get_scanned_lines(scanner->device_number, linebuf, lines, lines * bpl, &status); + if (status.pieusb_status != PIEUSB_STATUS_GOOD ) { + /* Error, return */ + free(linebuf); + return SANE_STATUS_INVAL; + } + /* Save raw data */ +/* + if (fdraw != -1) { + wcnt = write(fdraw,linebuf,parameters.lines*bpl); + DBG(DBG_info_sane,"Raw written %d\n",wcnt); + } +*/ + /* Copy into official buffer + * Sometimes the scanner returns too many lines. Take care not to + * overflow the buffer. */ + lboff = linebuf; + switch (scanner->mode.colorFormat) { + case SCAN_COLOR_FORMAT_PIXEL: + /* The scanner may return lines with 3 colors even though only + * one color is actually scanned. Detect this situation and + * eliminate the excess samples from the line buffer before + * handing it to buffer_put_full_color_line(). */ + compress = SANE_FALSE; + if (scanner->buffer.colors == 1 + && (bpl * scanner->buffer.packing_density / ppl) == (3 * scanner->buffer.packet_size_bytes)) { + compress = SANE_TRUE; + } + for (n = 0; n < lines; n++) { + if (compress) { + /* Move samples to fill up all unused locations */ + int ps = scanner->buffer.packet_size_bytes; + for (k = 0; k < scanner->buffer.line_size_packets; k++) { + for (i = 0; i < ps; i++) { + lboff[ps*k+i] = lboff[3*ps*k+i]; + } + } + } + if (sanei_pieusb_buffer_put_full_color_line(&scanner->buffer, lboff, bpl/3) == 0) { + /* Error, return */ + return SANE_STATUS_INVAL; + } + lboff += bpl; + } + break; + case SCAN_COLOR_FORMAT_INDEX: + /* Indexed data */ + for (n = 0; n < lines; n++) { + if (sanei_pieusb_buffer_put_single_color_line(&scanner->buffer, *lboff, lboff+2, bpl-2) == 0) { + /* Error, return */ + return SANE_STATUS_INVAL; + } + lboff += bpl; + } + break; + default: + DBG(DBG_error, "sanei_pieusb_get_scan_data(): store color format %d not implemented\n", scanner->mode.colorFormat); + free(linebuf); + return SANE_STATUS_INVAL; + } + free(linebuf); + lines_remaining -= lines; /* Note: excess discarded */ + DBG(DBG_info_sane, "sanei_pieusb_get_scan_data(): reading lines: remaining %d\n", lines_remaining); + } +/* + if (fdraw != -1) close(fdraw); +*/ + return SANE_STATUS_GOOD; +} + +/** + * Wait for scanner to get ready + * + * loop of test_ready/read_state + * + * @param scanner + * @param device_number, used if scanner == NULL + * @return SANE_Status + */ + +SANE_Status +sanei_pieusb_wait_ready(Pieusb_Scanner * scanner, SANE_Int device_number) +{ + struct Pieusb_Command_Status status; + struct Pieusb_Scanner_State state; + time_t start, elapsed; + + DBG (DBG_info_proc, "sanei_pieusb_wait_ready()\n"); + start = time(NULL); + if (scanner) + device_number = scanner->device_number; + + for(;;) { + sanei_pieusb_cmd_test_unit_ready(device_number, &status); + DBG (DBG_info_proc, "-> sanei_pieusb_cmd_test_unit_ready: %d\n", status.pieusb_status); + if (status.pieusb_status == PIEUSB_STATUS_GOOD) + break; + if (status.pieusb_status == PIEUSB_STATUS_IO_ERROR) + break; + sanei_pieusb_cmd_read_state(device_number, &state, &status); + DBG (DBG_info_proc, "-> sanei_pieusb_cmd_read_state: %d\n", status.pieusb_status); + if (status.pieusb_status != PIEUSB_STATUS_DEVICE_BUSY) + break; + sleep(2); + elapsed = time(NULL) - start; + if (elapsed > 120) { /* 2 minute overall timeout */ + DBG (DBG_error, "scanner not ready after 2 minutes\n"); + break; + } + if (elapsed % 2) { + DBG (DBG_info, "still waiting for scanner to get ready\n"); + } + } + return sanei_pieusb_convert_status(status.pieusb_status); +} + + +SANE_Status sanei_pieusb_analyze_preview(Pieusb_Scanner * scanner) +{ + int k, n; + SANE_Parameters params; + SANE_Int N; + double *norm_histo; + double level; + + DBG(DBG_info, "sanei_pieusb_analyze_preview(): saving preview data\n"); + + /* Settings */ + scanner->preview_done = SANE_TRUE; + for (k = 0; k < 4; k++) { + scanner->preview_exposure[k] = scanner->settings.exposureTime[k]; + scanner->preview_gain[k] = scanner->settings.gain[k]; + scanner->preview_offset[k] = scanner->settings.offset[k]; + } + /* Analyze color planes */ + N = scanner->buffer.width * scanner->buffer.height; + params.format = SANE_FRAME_GRAY; + params.depth = scanner->buffer.depth; + params.pixels_per_line = scanner->buffer.width; + params.lines = scanner->buffer.height; + for (k = 0; k < scanner->buffer.colors; k++) { + /* Create histogram for color k */ + sanei_ir_create_norm_histogram (¶ms, scanner->buffer.data + k * N, &norm_histo); + /* Find 1% and 99% limits */ + level = 0; + for (n =0; n < HISTOGRAM_SIZE; n++) { + + level += norm_histo[n]; + if (level < 0.01) { + scanner->preview_lower_bound[k] = n; + } + if (level < 0.99) { + scanner->preview_upper_bound[k] = n; + } + } + DBG(DBG_info,"sanei_pieusb_analyze_preview(): 1%%-99%% levels for color %d: %d - %d\n", k, scanner->preview_lower_bound[k], scanner->preview_upper_bound[k]); + } + /* Disable remaining color planes */ + for (k = scanner->buffer.colors; k < 4; k++) { + scanner->preview_lower_bound[k] = 0; + scanner->preview_upper_bound[k] = 0; + } + return SANE_STATUS_GOOD; +} + + +/** + * Return actual gain at given gain setting + * + * @param gain Gain setting (0 - 63) + * @return + */ +static double getGain(int gain) +{ + int k; + + /* Actually an error, but don't be picky */ + if (gain <= 0) { + return gains[0]; + } + /* A gain > 63 is also an error, but don't be picky */ + if (gain >= 60) { + return (gain-55)*(gains[12]-gains[11])/5 + gains[11]; + } + /* Interpolate other values */ + k = gain/5; /* index of array value just below given gain */ + return (gain-5*k)*(gains[k+1]-gains[k])/5 + gains[k]; +} + +static int getGainSetting(double gain) +{ + int k, m; + + /* Out of bounds */ + if (gain < 1.0) { + return 0; + } + if (gain >= gains[12]) { + m = 60 + lround((gain-gains[11])/(gains[12]-gains[11])*5); + if (m > 63) m = 63; + return m; + } + /* Interpolate the rest */ + m = 0; + for (k = 0; k <= 11; k++) { + if (gains[k] <= gain && gain < gains[k+1]) { + m = 5*k + lround((gain-gains[k])/(gains[k+1]-gains[k])*5); + } + } + return m; +} + +/** + * Modify gain and exposure times in order to make maximal use of the scan depth. + * Each color treated separately, infrared excluded. + * + * This may be too aggressive => leads to a noisy whitish border instead of the orange. + * In a couuple of tries, gain was set to values of 60 and above, which introduces + * the noise? + * The whitish border is logical since the brightest parts of the negative, the + * unexposed borders, are amplified to values near CCD saturation, which is white. + * Maybe a uniform gain increase for each color is more appropriate? Somewhere + * between 2.5 and 3 seems worthwhile trying, see updateGain2(). + * + switch (scanner->mode.passes) { + case SCAN_ONE_PASS_RGBI: + updateGain(scanner,0); + updateGain(scanner,1); + updateGain(scanner,2); + updateGain(scanner,3); + break; + case SCAN_ONE_PASS_COLOR: + updateGain(scanner,0); + updateGain(scanner,1); + updateGain(scanner,2); + break; + case SCAN_FILTER_INFRARED: + updateGain(scanner,3); + break; + case SCAN_FILTER_BLUE: + updateGain(scanner,2); + break; + case SCAN_FILTER_GREEN: + updateGain(scanner,1); + break; + case SCAN_FILTER_RED: + updateGain(scanner,0); + break; + case SCAN_FILTER_NEUTRAL: + break; + } + * @param scanner + */ +/* +static void updateGain(Pieusb_Scanner *scanner, int color_index) +{ + double g, dg; + + DBG(DBG_info_sane,"updateGain(): color %d preview used G=%d Exp=%d\n", color_index, scanner->preview_gain[color_index], scanner->preview_exposure[color_index]); + // Additional gain to obtain + dg = ((double)scanner->settings.saturationLevel[color_index] / 65536) / ((double)scanner->preview_upper_bound[color_index] / HISTOGRAM_SIZE); + DBG(DBG_info_sane,"updateGain(): additional gain %f\n", dg); + // Achieve this by modifying gain and exposure + // Gain used for preview + g = getGain(scanner->preview_gain[color_index]); + DBG(DBG_info_sane,"updateGain(): preview had gain %d => %f\n",scanner->preview_gain[color_index],g); + // Look up new gain setting g*sqrt(dg) + DBG(DBG_info_sane,"updateGain(): optimized gain * %f = %f\n",sqrt(dg),sqrt(dg)*g); + scanner->settings.gain[color_index] = getGainSetting(g*sqrt(dg)); + DBG(DBG_info_sane,"updateGain(): optimized gain setting %d => %f\n",scanner->settings.gain[color_index],getGain(scanner->settings.gain[color_index])); + // Exposure change is straightforward + DBG(DBG_info_sane,"updateGain(): remains for exposure %f\n",dg/(getGain(scanner->settings.gain[color_index])/g)); + scanner->settings.exposureTime[color_index] = lround( g / getGain(scanner->settings.gain[color_index]) * dg * scanner->preview_exposure[color_index] ); + DBG(DBG_info_sane,"updateGain(): new setting G=%d Exp=%d\n", scanner->settings.gain[color_index], scanner->settings.exposureTime[color_index]); +} +*/ + +static void updateGain2(Pieusb_Scanner *scanner, int color_index, double gain_increase) +{ + double g; + + DBG(DBG_info,"updateGain2(): color %d preview used G=%d Exp=%d\n", color_index, scanner->settings.gain[color_index], scanner->settings.exposureTime[color_index]); + /* Additional gain to obtain */ + DBG(DBG_info,"updateGain2(): additional gain %f\n", gain_increase); + /* Achieve this by modifying gain and exposure */ + /* Gain used for preview */ + g = getGain(scanner->settings.gain[color_index]); + DBG(DBG_info,"updateGain2(): preview had gain %d => %f\n", scanner->settings.gain[color_index], g); + /* Look up new gain setting g*sqrt(dg) */ + DBG(DBG_info,"updateGain2(): optimized gain * %f = %f\n", sqrt(gain_increase), sqrt(gain_increase) * g); + scanner->settings.gain[color_index] = getGainSetting(g * sqrt(gain_increase)); + DBG(DBG_info,"updateGain2(): optimized gain setting %d => %f\n", scanner->settings.gain[color_index], getGain(scanner->settings.gain[color_index])); + /* Exposure change is straightforward */ + DBG(DBG_info,"updateGain2(): remains for exposure %f\n", gain_increase / (getGain(scanner->settings.gain[color_index]) / g)); + scanner->settings.exposureTime[color_index] = lround( g / getGain(scanner->settings.gain[color_index]) * gain_increase * scanner->settings.exposureTime[color_index] ); + DBG(DBG_info,"updateGain2(): new setting G=%d Exp=%d\n", scanner->settings.gain[color_index], scanner->settings.exposureTime[color_index]); +} diff --git a/backend/pieusb_specific.h b/backend/pieusb_specific.h new file mode 100644 index 0000000..3928adf --- /dev/null +++ b/backend/pieusb_specific.h @@ -0,0 +1,346 @@ +/* sane - Scanner Access Now Easy. + + pieusb_specific.h + + Copyright (C) 2012-2015 Jan Vleeshouwers, Michael Rickmann, Klaus Kaempf + + This file is part of the SANE package. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA. + + As a special exception, the authors of SANE give permission for + additional uses of the libraries contained in this release of SANE. + + The exception is that, if you link a SANE library with other files + to produce an executable, this does not by itself cause the + resulting executable to be covered by the GNU General Public + License. Your use of that executable is in no way restricted on + account of linking the SANE library code into it. + + This exception does not, however, invalidate any other reasons why + the executable file might be covered by the GNU General Public + License. + + If you submit changes to SANE to the maintainers to be included in + a subsequent release, you agree by submitting the changes that + those changes may be distributed with this exception intact. + + If you write modifications of your own for SANE, it is your choice + whether to permit this exception to apply to your modifications. + If you do not wish that, delete this exception notice. */ + +#ifndef PIEUSB_SPECIFIC_H +#define PIEUSB_SPECIFIC_H + +#include "../include/sane/sanei_ir.h" +#include "../include/sane/sanei_backend.h" +#include "pieusb_scancmd.h" +#include "pieusb_buffer.h" + +/* Settings for scan modes available to SANE */ +/* In addition to those defined in sane.h */ +#define SANE_VALUE_SCAN_MODE_RGBI "RGBI" + +/* Scanner settings for colors to scan */ +#define SCAN_ONE_PASS_RGBI 0x90 +#define SCAN_ONE_PASS_COLOR 0x80 +#define SCAN_FILTER_INFRARED 0x10 +#define SCAN_FILTER_BLUE 0x08 +#define SCAN_FILTER_GREEN 0x04 +#define SCAN_FILTER_RED 0x02 +#define SCAN_FILTER_NEUTRAL 0x01 + +/* Settings for color depth of scan */ +#define SCAN_COLOR_DEPTH_16 0x20 +#define SCAN_COLOR_DEPTH_12 0x10 +#define SCAN_COLOR_DEPTH_10 0x08 +#define SCAN_COLOR_DEPTH_8 0x04 +#define SCAN_COLOR_DEPTH_4 0x02 +#define SCAN_COLOR_DEPTH_1 0x01 + +/* Settings for format of the scanned data */ +#define SCAN_COLOR_FORMAT_INDEX 0x04 +#define SCAN_COLOR_FORMAT_LINE 0x02 +#define SCAN_COLOR_FORMAT_PIXEL 0x01 + +/* Settings for calibration mode */ +#define SCAN_CALIBRATION_DEFAULT "default values" +#define SCAN_CALIBRATION_AUTO "from internal test" +#define SCAN_CALIBRATION_PREVIEW "from preview" +#define SCAN_CALIBRATION_OPTIONS "from options" + +/* Settings for additional gain */ +#define SCAN_GAIN_ADJUST_03 "* 0.3" +#define SCAN_GAIN_ADJUST_05 "* 0.5" +#define SCAN_GAIN_ADJUST_08 "* 0.8" +#define SCAN_GAIN_ADJUST_10 "* 1.0" +#define SCAN_GAIN_ADJUST_12 "* 1.2" +#define SCAN_GAIN_ADJUST_16 "* 1.6" +#define SCAN_GAIN_ADJUST_19 "* 1.9" +#define SCAN_GAIN_ADJUST_24 "* 2.4" +#define SCAN_GAIN_ADJUST_30 "* 3.0" + +/* Post-processing */ +#define POST_SW_COLORS (1 << 0) /* gain, negatives, ..., can be done at any time */ +#define POST_SW_IRED (1 << 1) /* remove spectral overlap, needs complete scan */ +#define POST_SW_DIRT (1 << 2) /* our digital lavabo, needs complete scan */ +#define POST_SW_GRAIN (1 << 3) /* smoothen a bit */ +#define POST_SW_CROP (1 << 4) /* trim whole image in sane_start + before sane_get_parameters() is answered */ +#define POST_SW_IRED_MASK (POST_SW_IRED | POST_SW_DIRT) +#define POST_SW_ACCUM_MASK (POST_SW_IRED_MASK | POST_SW_GRAIN | POST_SW_CROP) + +#define DEFAULT_GAIN 19 /* 0x13 */ +#define DEFAULT_EXPOSURE 2937 /* 0xb79 minimum value, see Pieusb_Settings */ +#define DEFAULT_OFFSET 0 +#define DEFAULT_LIGHT 4 +#define DEFAULT_ADDITIONAL_ENTRIES 1 +#define DEFAULT_DOUBLE_TIMES 0 + +/* -------------------------------------------------------------------------- + * + * DEVICE DEFINITION STRUCTURES + * + * --------------------------------------------------------------------------*/ + +/* Options supported by the scanner */ + +enum Pieusb_Option +{ + OPT_NUM_OPTS = 0, + /* ------------------------------------------- */ + OPT_MODE_GROUP, + OPT_MODE, /* scan mode */ + OPT_BIT_DEPTH, /* number of bits to encode a color */ + OPT_RESOLUTION, /* number of pixels per inch */ + OPT_HALFTONE_PATTERN, /* halftone pattern to use (see halftone_list) */ + OPT_THRESHOLD, /* halftone threshold */ + OPT_SHARPEN, /* create a sharper scan at the cost of scan time */ + OPT_SHADING_ANALYSIS, /* do shading analysis before the scan */ + OPT_FAST_INFRARED, /* scan infrared channel faster but less accurate */ + OPT_ADVANCE_SLIDE, /* auto-advance slide after scan */ + OPT_CALIBRATION_MODE, /* use auto-calibarion settings for scan */ + /* ------------------------------------------- */ + OPT_GEOMETRY_GROUP, + OPT_TL_X, /* top-left x */ + OPT_TL_Y, /* top-left y */ + OPT_BR_X, /* bottom-right x */ + OPT_BR_Y, /* bottom-right y */ + /* ------------------------------------------- */ + OPT_ENHANCEMENT_GROUP, + OPT_CORRECT_SHADING, /* correct scanned data for lamp variations (shading) */ + OPT_CORRECT_INFRARED, /* correct infrared for red crosstalk */ + OPT_CLEAN_IMAGE, /* detect and remove dust and scratch artifacts */ + OPT_GAIN_ADJUST, /* adjust gain (a simpler option than setting gain, exposure and offset directly) */ + OPT_CROP_IMAGE, /* automatically crop image */ + OPT_SMOOTH_IMAGE, /* smoothen image */ + OPT_TRANSFORM_TO_SRGB, /* transform to approximate sRGB data */ + OPT_INVERT_IMAGE, /* transform negative to positive */ + /* ------------------------------------------- */ + OPT_ADVANCED_GROUP, + OPT_PREVIEW, /* scan a preview before the actual scan */ + OPT_SAVE_SHADINGDATA, /* output shading data */ + OPT_SAVE_CCDMASK, /* output CCD mask */ + OPT_LIGHT, + OPT_DOUBLE_TIMES, + OPT_SET_EXPOSURE_R, /* exposure times for R */ + OPT_SET_EXPOSURE_G, /* exposure times for G */ + OPT_SET_EXPOSURE_B, /* exposure times for B */ + OPT_SET_EXPOSURE_I, /* exposure times for I */ + OPT_SET_GAIN_R, /* gain for R */ + OPT_SET_GAIN_G, /* gain for G */ + OPT_SET_GAIN_B, /* gain for B */ + OPT_SET_GAIN_I, /* gain for I */ + OPT_SET_OFFSET_R, /* offset for R */ + OPT_SET_OFFSET_G, /* offset for G */ + OPT_SET_OFFSET_B, /* offset for B */ + OPT_SET_OFFSET_I, /* offset for I */ + /* must come last: */ + NUM_OPTIONS +}; + +/* Forward declaration (see pieusb_scancmd.h) */ +struct Pieusb_Shading_Parameters; + +/* Device characteristics of a Pieusb USB scanner */ +struct Pieusb_Device_Definition +{ + struct Pieusb_Device_Definition *next; + + SANE_Device sane; + /* name = string like "libusb:001:006" == NO! this should be "CrystalScan 7200" or "ProScan 7200"... + * vendor = "PIE/Pieusb" + * model = "CrystalScan 7200" or "ProScan 7200" + * type = "film scanner" */ + /* char *devicename; => sane->name */ + /* char *vendor; => sane->vendor */ + /* char *product; => sane->model */ + SANE_Word vendorId; + SANE_Word productId; + /* USB id's like 0x05e3 0x0145, see pieusb.conf */ + SANE_String version; /* INQUIRY productRevision */ + SANE_Byte model; /* INQUIRY model */ + + /* Ranges for various quantities */ + SANE_Range dpi_range; + SANE_Range x_range; + SANE_Range y_range; + SANE_Range exposure_range; /* Unit is a 8051 machine cycle, which is approximately 1 us. (Exactly: 12 cycles at 11.059 Mhz = 1.085 us.) */ + SANE_Range dust_range; + + SANE_Range shadow_range; + SANE_Range highlight_range; + + /* Enumerated ranges vor various quantities */ + SANE_String scan_mode_list[7]; /* names of scan modes (see saneopts.h) */ + SANE_String calibration_mode_list[6]; /* names of calibration modes */ + SANE_String gain_adjust_list[10]; /* gain adjustment values */ + SANE_Word bpp_list[5]; /* bit depths */ + SANE_String halftone_list[17]; /* names of the halftone patterns from the scanner */ + SANE_String speed_list[9]; /* names of available speeds */ + SANE_String ir_sw_list[4]; + SANE_String crop_sw_list[4]; + SANE_Word grain_sw_list[6]; + + /* Maximum resolution values */ + int maximum_resolution_x; /* maximum x-resolution */ + int maximum_resolution_y; /* maximum y-resolution */ + int maximum_resolution; + + /* Geometry */ + double scan_bed_width; /* flatbed width in inches (horizontal) */ + double scan_bed_height; /* flatbed height in inches (vertical) */ + int slide_top_left_x; /* top-left location of slide w.r.t. scan bed */ + int slide_top_left_y; /* top-left location of slide w.r.t. scan bed */ + double slide_width; /* transparency width in inches */ + double slide_height; /* transparency length in inches */ + + /* Integer and bit-encoded properties */ + int halftone_patterns; /* number of halftones supported */ + int color_filters; /* available colour filters: Infrared-0-0-OnePassColor-B-G-R-N */ + int color_depths; /* available colour depths: 0-0-16-12-10-8-4-1 */ + int color_formats; /* colour data format: 0-0-0-0-0-Index-Line-Pixel */ + int image_formats; /* image data format: 0-0-0-0-OKLine-BlkOne-Motorola-Intel */ + int scan_capabilities; /* additional scanner features, number of speeds: PowerSave-ExtCal-0-FastPreview-DisableCal-[CalSpeeds=3] */ + int optional_devices; /* optional devices: MultiPageLoad-?-?-0-0-TransModule1-TransModule-AutoDocFeeder */ + int enhancements; /* enhancements: unknown coding */ + int gamma_bits; /* no of bits used for gamma table */ + int fast_preview_resolution; /* fast preview resolution */ + int minimum_highlight; /* min highlight % that can be used */ + int maximum_shadow; /* max shadow % that can be used */ + int calibration_equation; /* which calibration equation to use */ + int minimum_exposure; /* min exposure */ + int maximum_exposure; /* max exposure */ + + struct Pieusb_Shading_Parameters_Info shading_parameters[4]; /* array with shading data parameters */ + + int x0, y0, x1, y1; + SANE_String production; + SANE_String timestamp; + SANE_String signature; +}; + +typedef struct Pieusb_Device_Definition Pieusb_Device_Definition; + +/* -------------------------------------------------------------------------- + * + * CURRENTLY ACTIVE DEVICES + * + * --------------------------------------------------------------------------*/ + +/* This structure holds information about an instance of an active scanner */ + +struct Pieusb_Scanner +{ + struct Pieusb_Scanner *next; + struct Pieusb_Device_Definition *device; /* pointer to device definition */ + + int device_number; /* scanner device number (as determined by USB) */ + + /* SANE option descriptions and settings for this scanner instance */ + SANE_Option_Descriptor opt[NUM_OPTIONS]; + Option_Value val[NUM_OPTIONS]; + + /* Scan state */ + struct Pieusb_Scanner_State state; + SANE_Int scanning; /* true if busy scanning */ + SANE_Int cancel_request; /* if true, scanner should terminate a scan */ + + /* Scan settings */ + struct Pieusb_Mode mode; + struct Pieusb_Settings settings; + struct Pieusb_Scan_Frame frame; + SANE_Parameters scan_parameters; + + /* Shading data and CCD-mask */ +#define PIEUSB_CCD_MASK_SIZE 0x1a1d /* pieusb 5340; */ /* cyberview: 6685 0x1a1d */ + SANE_Byte *ccd_mask; /* malloc'ed in sane_open */ + SANE_Int ccd_mask_size; + SANE_Bool shading_data_present; /* don't correct shading if not present */ + SANE_Int shading_mean[SHADING_PARAMETERS_INFO_COUNT]; /* mean shading value for each color (average all 45 lines) */ + SANE_Int shading_max[SHADING_PARAMETERS_INFO_COUNT]; /* maximum shading value for each color (for all 45 lines) */ + SANE_Int* shading_ref[SHADING_PARAMETERS_INFO_COUNT]; /* 4 arrays of shading references for each pixel on a line and for each color */ + + /* Calibration using preview */ + + SANE_Bool preview_done; + SANE_Int preview_exposure[4]; /* exposure values used in preview */ + SANE_Int preview_gain[4]; /* gain values used in preview */ + SANE_Int preview_offset[4]; /* offset values used in preview */ + SANE_Int preview_lower_bound[4]; /* lowest RGBI values in preview */ + SANE_Int preview_upper_bound[4]; /* highest RGBI values in preview */ + + /* Post processing options */ +/* + SANE_Int processing; +*/ + double *ln_lut; /* logarithmic lookup table */ + + /* Reading buffer */ + struct Pieusb_Read_Buffer buffer; +}; + +typedef struct Pieusb_Scanner Pieusb_Scanner; + +SANE_Status sanei_pieusb_parse_config_line(const char* config_line, SANE_Word* vendor_id, SANE_Word* product_id, SANE_Word* model_number); +/* sub to sane_start() */ +SANE_Status sanei_pieusb_post (Pieusb_Scanner *scanner, uint16_t **in_img, int planes); +void sanei_pieusb_correct_shading(struct Pieusb_Scanner *scanner, struct Pieusb_Read_Buffer *buffer); +SANE_Status sanei_pieusb_get_scan_data(Pieusb_Scanner * scanner, SANE_Int parameter_bytes); +SANE_Status sanei_pieusb_get_parameters(Pieusb_Scanner * scanner, SANE_Int *parameter_bytes); +SANE_Status sanei_pieusb_get_ccd_mask(Pieusb_Scanner * scanner); +SANE_Status sanei_pieusb_get_shading_data(Pieusb_Scanner * scanner); +SANE_Status sanei_pieusb_set_mode_from_options(Pieusb_Scanner * scanner); +SANE_Status sanei_pieusb_set_gain_offset(Pieusb_Scanner * scanner, const char* calibration_mode); +SANE_Status sanei_pieusb_set_frame_from_options(Pieusb_Scanner * scanner); +void sanei_pieusb_print_options(struct Pieusb_Scanner *scanner); +/* sub to sane_control_option() and sane_start() */ +int sanei_pieusb_analyse_options(struct Pieusb_Scanner *scanner); +SANE_Bool sanei_pieusb_supported_device_list_contains(SANE_Word vendor_id, SANE_Word product_id, SANE_Word model_number); +SANE_Status sanei_pieusb_supported_device_list_add(SANE_Word vendor_id, SANE_Word product_id, SANE_Word model_number); +/* sub to sane_init() and sane_open() */ +SANE_Status sanei_pieusb_find_device_callback (const char *devicename); +/* sub to sane_open() */ +SANE_Status sanei_pieusb_init_options (Pieusb_Scanner * scanner); +/* sub to sane_start(), sane_read() and sane_close() */ +SANE_Status sanei_pieusb_on_cancel (Pieusb_Scanner * scanner); + +SANE_Status sanei_pieusb_wait_ready(Pieusb_Scanner *scanner, SANE_Int device_number); +SANE_Status sanei_pieusb_analyze_preview(Pieusb_Scanner * scanner); + + + +#endif /* PIEUSB_SPECIFIC_H */ diff --git a/backend/pieusb_usb.c b/backend/pieusb_usb.c new file mode 100644 index 0000000..71b6bcf --- /dev/null +++ b/backend/pieusb_usb.c @@ -0,0 +1,679 @@ +/* sane - Scanner Access Now Easy. + + pieusb_usb.c + + Copyright (C) 2012-2015 Jan Vleeshouwers, Michael Rickmann, Klaus Kaempf + + This file is part of the SANE package. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA. + + As a special exception, the authors of SANE give permission for + additional uses of the libraries contained in this release of SANE. + + The exception is that, if you link a SANE library with other files + to produce an executable, this does not by itself cause the + resulting executable to be covered by the GNU General Public + License. Your use of that executable is in no way restricted on + account of linking the SANE library code into it. + + This exception does not, however, invalidate any other reasons why + the executable file might be covered by the GNU General Public + License. + + If you submit changes to SANE to the maintainers to be included in + a subsequent release, you agree by submitting the changes that + those changes may be distributed with this exception intact. + + If you write modifications of your own for SANE, it is your choice + whether to permit this exception to apply to your modifications. + If you do not wish that, delete this exception notice. */ + +#define DEBUG_DECLARE_ONLY +#include "pieusb.h" +#include "pieusb_scancmd.h" +#include "pieusb_usb.h" + +#include "../include/sane/sanei_usb.h" +#include <unistd.h> /* usleep */ +#include <time.h> /* time */ + +/* USB functions */ + +static SANE_Status _ctrl_out_byte(SANE_Int device_number, SANE_Int port, SANE_Byte b); +static SANE_Status _bulk_size(SANE_Int device_number, unsigned int size); +static SANE_Status _ctrl_in_byte(SANE_Int device_number, SANE_Byte* b); +static SANE_Status _bulk_in(SANE_Int device_number, SANE_Byte* data, size_t *size); +static SANE_Status _ieee_command(SANE_Int device_number, SANE_Byte command); + +/* Defines for use in USB functions */ + +#define REQUEST_TYPE_IN (USB_TYPE_VENDOR | USB_DIR_IN) +#define REQUEST_TYPE_OUT (USB_TYPE_VENDOR | USB_DIR_OUT) +#define REQUEST_REGISTER 0x0c +#define REQUEST_BUFFER 0x04 +#define ANYINDEX 0x00 /* wIndex value for USB control transfer - value is irrelevant */ + +/* from libieee1284 */ +#define C1284_NSTROBE 0x01 +#define C1284_NINIT 0x04 + +/* usb via ieee1284 */ +#define IEEE1284_ADDR 0x00 +#define IEEE1284_RESET 0x30 +#define IEEE1284_SCSI 0xe0 + +#define PORT_SCSI_SIZE 0x0082 +#define PORT_SCSI_STATUS 0x0084 +#define PORT_SCSI_CMD 0x0085 +#define PORT_PAR_CTRL 0x0087 /* IEEE1284 parallel control */ +#define PORT_PAR_DATA 0x0088 /* IEEE1284 parallel data */ + +/* see also: SCSI Status Codes http://www.t10.org/lists/2status.htm */ +typedef enum { + USB_STATUS_OK = 0x00, /* ok */ + USB_STATUS_READ = 0x01, /* read: send expected length, then read data */ + USB_STATUS_CHECK = 0x02, /* check condition */ + USB_STATUS_BUSY = 0x03, /* wait on usb */ + USB_STATUS_AGAIN = 0x08, /* re-send scsi cmd */ + USB_STATUS_FAIL = 0x88, /* ??? */ + USB_STATUS_ERROR = 0xff /* usb i/o error */ +} PIEUSB_USB_Status; + +static PIEUSB_USB_Status _pieusb_scsi_command(SANE_Int device_number, SANE_Byte command[], SANE_Byte data[], SANE_Int size); + +#define SENSE_CODE_WARMING_UP 4 + +/* Standard SCSI Sense codes*/ +#define SCSI_NO_ADDITIONAL_SENSE_INFORMATION 0x00 + +struct code_text_t { int code; char *text; }; +static struct code_text_t usb_code_text[] = { + { 0x00, "Ok" }, + { 0x01, "Read" }, + { 0x02, "Check" }, + { 0x03, "Busy" }, + { 0x08, "Again" }, + { 0xff, "Error" }, + { -1, NULL } +}; + +static struct code_text_t scsi_code_text[] = { + { 0x00, "Test Unit Ready" } + ,{ 0x01, "Calibrate" } + ,{ 0x03, "Request Sense" } + ,{ 0x04, "Format" } + ,{ 0x08, "Read" } + ,{ 0x0a, "Write" } + ,{ 0x0f, "Get Param" } + ,{ 0x10, "Mark" } + ,{ 0x11, "Space" } + ,{ 0x12, "Inquiry" } + ,{ 0x15, "Mode Select" } + ,{ 0x16, "Reserve Unit" } + ,{ 0x18, "Copy" } + ,{ 0x1a, "Mode Sense" } + ,{ 0x1b, "Scan" } + ,{ 0x1d, "Diagnose" } + ,{ 0xa8, "Read Extended" } + ,{ 0xd1, "Slide" } + ,{ 0xd2, "Set Scan Head" } + ,{ 0xd7, "Read Gain Offset" } + ,{ 0xdc, "Write Gain Offset" } + ,{ 0xdd, "Read State" } + ,{ -1, NULL } +}; + +static char * +code_to_text(struct code_text_t *list, int code) +{ + while (list && list->text) { + if (list->code == code) + return list->text; + list++; + } + return "**unknown**"; +} + +/** + * Convert PIEUSB_Status to SANE_Status + */ +SANE_Status +sanei_pieusb_convert_status(PIEUSB_Status status) +{ + return (SANE_Status)status; +} + + +/** + * hex dump 'size' bytes starting at 'ptr' + */ +static void +_hexdump(char *msg, unsigned char *ptr, int size) +{ + unsigned char *lptr = ptr; + int count = 0; + long start = 0; + long clipped = 0; + + if (DBG_info_proc > DBG_LEVEL) + return; + + if (size > 127) { + clipped = size; + size = 128; + } + while (size-- > 0) + { + if ((count % 16) == 0) + fprintf (stderr, "%s\t%08lx:", msg?msg:"", start); + msg = NULL; + fprintf (stderr, " %02x", *ptr++); + count++; + start++; + if (size == 0) + { + while ((count % 16) != 0) + { + fprintf (stderr, " "); + count++; + } + } + if ((count % 16) == 0) + { + fprintf (stderr, " "); + while (lptr < ptr) + { + unsigned char c = *lptr & 0x7f; + fprintf (stderr, "%c", ((c < 0x20)||(c == 0x7f)) ? '.' : c); + lptr++; + } + fprintf (stderr, "\n"); + } + } + if ((count % 16) != 0) + fprintf (stderr, "\n"); + if (clipped > 0) + fprintf (stderr, "\t%08lx bytes clipped\n", clipped); + + fflush(stderr); + return; +} + + +/* ========================================================================= + * + * USB functions + * + * ========================================================================= */ + +/** + * Send a command to the device, retry 10 times if device is busy + * and return SENSE data in the sense fields of status if there is a CHECK + * CONDITION response from the command. + * If the REQUEST SENSE command fails, the SANE status code is unequal to + * PIEUSB_STATUS_GOOD and the sense fields are empty. + * + * @param device_number Device number + * @param command Command array + * @param data Input or output data buffer + * @param size Size of the data buffer + * @param status Pieusb_Command_Status + */ + +PIEUSB_Status +sanei_pieusb_command(SANE_Int device_number, SANE_Byte command[], SANE_Byte data[], SANE_Int size) +{ +#define MAXTIME 60 /* max 60 seconds */ + time_t start; + SANE_Status sane_status; + PIEUSB_Status ret = PIEUSB_STATUS_DEVICE_BUSY; + SANE_Byte usbstat; + PIEUSB_USB_Status usb_status = USB_STATUS_AGAIN; + + DBG (DBG_info_usb, "*** sanei_pieusb_command(%02x:%s): size 0x%02x\n", command[0], code_to_text (scsi_code_text, command[0]), size); + + start = time(NULL); + while ((time(NULL)-start) < MAXTIME) { + DBG (DBG_info_usb, "\tsanei_pieusb_command loop, status %d:%s\n", usb_status, code_to_text (usb_code_text, usb_status)); + if (usb_status == USB_STATUS_AGAIN) { + usb_status = _pieusb_scsi_command (device_number, command, data, size); + DBG (DBG_info_usb, "\t_pieusb_scsi_command returned %d:%s\n", usb_status, code_to_text (usb_code_text, usb_status)); + continue; + } + if (usb_status == USB_STATUS_OK) { + ret = PIEUSB_STATUS_GOOD; + break; + } + if (usb_status == USB_STATUS_READ) { + DBG (DBG_error, "\tsanei_pieusb_command() 2nd STATUS_READ ?!\n"); + ret = PIEUSB_STATUS_IO_ERROR; + break; + } + if (usb_status == USB_STATUS_CHECK) { + /* check condition */ + struct Pieusb_Sense sense; + struct Pieusb_Command_Status senseStatus; + +#define SCSI_REQUEST_SENSE 0x03 + + if (command[0] == SCSI_REQUEST_SENSE) { + DBG (DBG_error, "\tsanei_pieusb_command() recursive SCSI_REQUEST_SENSE\n"); + ret = PIEUSB_STATUS_INVAL; + break; + } + + /* A check sense may be a busy state in disguise + * It is also practical to execute a request sense command by + * default. The calling function should interpret + * PIEUSB_STATUS_CHECK_SENSE as 'sense data available'. */ + + sanei_pieusb_cmd_get_sense (device_number, &sense, &senseStatus, &ret); + if (senseStatus.pieusb_status != PIEUSB_STATUS_GOOD) { + DBG (DBG_error, "\tsanei_pieusb_command(): CHECK CONDITION, but REQUEST SENSE fails\n"); + ret = senseStatus.pieusb_status; + } + break; + } + if (usb_status == USB_STATUS_BUSY) { + /* wait on usb */ + sane_status = _ctrl_in_byte (device_number, &usbstat); + if (sane_status != SANE_STATUS_GOOD) { + DBG (DBG_error, "\tpieusb_scsi_command() fails status in: %d\n", sane_status); + ret = PIEUSB_STATUS_IO_ERROR; + break; + } + usb_status = usbstat; + if (usb_status == USB_STATUS_AGAIN) { + sleep(1); + } + continue; + } + if (usb_status == USB_STATUS_AGAIN) { + /* re-send scsi cmd */ + continue; + } + if (usb_status == USB_STATUS_FAIL) { + DBG (DBG_error, "\tsanei_pieusb_command() usb status again2\n"); + usb_status = USB_STATUS_ERROR; + sanei_pieusb_usb_reset(device_number); + ret = PIEUSB_STATUS_IO_ERROR; + break; + } + if (usb_status == USB_STATUS_ERROR) { + sanei_pieusb_usb_reset(device_number); + ret = PIEUSB_STATUS_IO_ERROR; + break; + } + + DBG (DBG_error, "\tsanei_pieusb_command() unhandled usb status 0x%02x\n", usb_status); + ret = PIEUSB_STATUS_IO_ERROR; + break; + } + if ((time(NULL)-start) > MAXTIME) { + DBG (DBG_info_usb, "\tsanei_pieusb_command() timeout !\n"); + } + + DBG (DBG_info_usb, "\tsanei_pieusb_command() finished with state %d\n", ret); + return ret; +} + +/** + * Reset IEEE1284 interface + * + * @param device_number Device number + * @returns SANE_Status + */ + +SANE_Status +sanei_pieusb_usb_reset(SANE_Int device_number) +{ + DBG (DBG_info_sane, "\tsanei_pieusb_usb_reset()\n"); + return _ieee_command (device_number, IEEE1284_RESET); +} + +/* http://www.t10.org/lists/2sensekey.htm */ +static struct code_text_t sense_code_text[] = { + { SCSI_SENSE_NO_SENSE, "No Sense" }, + { SCSI_SENSE_RECOVERED_ERROR, "Recovered Error" }, + { SCSI_SENSE_NOT_READY, "Not Ready" }, + { SCSI_SENSE_MEDIUM_ERROR, "Medium Error" }, + { SCSI_SENSE_HARDWARE_ERROR, "Hardware Error" }, + { SCSI_SENSE_ILLEGAL_REQUEST, "Illegal Request" }, + { SCSI_SENSE_UNIT_ATTENTION, "Unit Attention" }, + { SCSI_SENSE_DATA_PROTECT, "Data Protect" }, + { SCSI_SENSE_BLANK_CHECK, "Blank Check" }, + { SCSI_SENSE_VENDOR_SPECIFIC, "Vendor Specific" }, + { SCSI_SENSE_COPY_ABORTED, "Copy Aborted" }, + { SCSI_SENSE_ABORTED_COMMAND, "Aborted Command" }, + { SCSI_SENSE_EQUAL, "Equal" }, + { SCSI_SENSE_VOLUME_OVERFLOW, "Volume Overflow" }, + { SCSI_SENSE_MISCOMPARE, "Miscompare" }, + { SCSI_SENSE_COMPLETED, "Completed" }, + { -1, NULL } +}; + + +/** + * Return a textual description of the given sense code. + * + * See http://www.t10.org/lists/asc-num.txt + * + * @param sense + * @return description + */ + +SANE_String +sanei_pieusb_decode_sense(struct Pieusb_Sense* sense, PIEUSB_Status *status) +{ + SANE_Char* desc = malloc(200); + SANE_Char* ptr; + strcpy (desc, code_to_text (sense_code_text, sense->senseKey)); + ptr = desc + strlen(desc); + + switch (sense->senseKey) { + case SCSI_SENSE_NOT_READY: + if (sense->senseCode == SENSE_CODE_WARMING_UP && sense->senseQualifier == 1) { + strcpy (ptr, ": Logical unit is in the process of becoming ready"); + *status = PIEUSB_STATUS_WARMING_UP; + } + else { + sprintf (ptr, ": senseCode 0x%02x, senseQualifier 0x%02x", sense->senseCode, sense->senseQualifier); + *status = PIEUSB_STATUS_INVAL; + } + break; + case SCSI_SENSE_UNIT_ATTENTION: + if (sense->senseCode == 0x1a && sense->senseQualifier == 0) { + strcpy (ptr, ": Invalid field in parameter list"); + *status = PIEUSB_STATUS_INVAL; + break; + } else if (sense->senseCode == 0x20 && sense->senseQualifier == 0) { + strcpy (ptr, ": Invalid command operation code"); + *status = PIEUSB_STATUS_INVAL; + break; + } else if (sense->senseCode == 0x82 && sense->senseQualifier == 0) { + strcpy (ptr, ": Calibration disable not granted"); + *status = PIEUSB_STATUS_MUST_CALIBRATE; + break; + } else if (sense->senseCode == 0x00 && sense->senseQualifier == 6) { + strcpy (ptr, ": I/O process terminated"); + *status = PIEUSB_STATUS_IO_ERROR; + break; + } else if (sense->senseCode == 0x26 && sense->senseQualifier == 0x82) { + strcpy (ptr, ": MODE SELECT value invalid: resolution too high (vs)"); + *status = PIEUSB_STATUS_INVAL; + break; + } else if (sense->senseCode == 0x26 && sense->senseQualifier == 0x83) { + strcpy (ptr, ": MODE SELECT value invalid: select only one color (vs)"); + *status = PIEUSB_STATUS_INVAL; + break; + } else if (sense->senseCode == 0x26 && sense->senseQualifier == 0x83) { + strcpy (ptr, ": MODE SELECT value invalid: unsupported bit depth (vs)"); + *status = PIEUSB_STATUS_INVAL; + break; + } + /*fallthru*/ + case SCSI_SENSE_NO_SENSE: + case SCSI_SENSE_RECOVERED_ERROR: + case SCSI_SENSE_MEDIUM_ERROR: + case SCSI_SENSE_HARDWARE_ERROR: + case SCSI_SENSE_ILLEGAL_REQUEST: + case SCSI_SENSE_DATA_PROTECT: + case SCSI_SENSE_BLANK_CHECK: + case SCSI_SENSE_VENDOR_SPECIFIC: + case SCSI_SENSE_COPY_ABORTED: + case SCSI_SENSE_ABORTED_COMMAND: + case SCSI_SENSE_EQUAL: + case SCSI_SENSE_VOLUME_OVERFLOW: + case SCSI_SENSE_MISCOMPARE: + case SCSI_SENSE_COMPLETED: + default: + sprintf (ptr, ": senseCode 0x%02x, senseQualifier 0x%02x", sense->senseCode, sense->senseQualifier); + *status = PIEUSB_STATUS_INVAL; + } + return desc; +} + +/** + * Prepare IEEE1284 interface + * Issue one of IEEE1284_ADDR, IEEE1284_RESET, or IEEE1284_SCSI + * + * @param device_number Device number + * @param command - IEEE1284 command + * @returns SANE_Status + */ + +static SANE_Status +_ieee_command(SANE_Int device_number, SANE_Byte command) +{ + SANE_Status st; + static int sequence[] = { 0xff, 0xaa, 0x55, 0x00, 0xff, 0x87, 0x78 }; +#define SEQUENCE_LEN 7 + unsigned int i; + /* 2 x 4 + 3 bytes preceding command, then SCSI_COMMAND_LEN bytes command */ + /* IEEE1284 command, see hpsj5s.c:cpp_daisy() */ + for (i = 0; i < SEQUENCE_LEN; ++i) { + st = _ctrl_out_byte (device_number, PORT_PAR_DATA, sequence[i]); + if (st != SANE_STATUS_GOOD) { + DBG (DBG_error, "\t\t_ieee_command fails after %d bytes\n", i); + return st; + } + } + st = _ctrl_out_byte (device_number, PORT_PAR_DATA, command); + if (st == SANE_STATUS_GOOD) { + usleep(3000); /* 3.000 usec -> 3 msec */ + st = _ctrl_out_byte (device_number, PORT_PAR_CTRL, C1284_NINIT|C1284_NSTROBE); /* CTRL_VAL_FINAL */ + if (st == SANE_STATUS_GOOD) { + st = _ctrl_out_byte (device_number, PORT_PAR_CTRL, C1284_NINIT); + if (st == SANE_STATUS_GOOD) { + st = _ctrl_out_byte (device_number, PORT_PAR_DATA, 0xff); + if (st != SANE_STATUS_GOOD) { + DBG (DBG_error, "\t\t_ieee_command fails to write final data\n"); + } + } + else { + DBG (DBG_error, "\t\t_ieee_command fails to reset strobe\n"); + } + } + else { + DBG (DBG_error, "\t\t_ieee_command fails to set strobe\n"); + } + } + + return st; +#undef SEQUENCE_LEN +} + +/** + * Send a command to the device. + * The command is a SCSI_COMMAND_LEN-byte array. The data-array is used for input and output. + * The sense-fields of Pieusb_Command_Status are cleared. + * + * @param device_number Device number + * @param command Command array + * @param data Input or output data buffer + * @param size Size of the data buffer + * @returns PIEUSB_SCSI_Status + */ +static PIEUSB_USB_Status +_pieusb_scsi_command(SANE_Int device_number, SANE_Byte command[], SANE_Byte data[], SANE_Int size) +{ + SANE_Status st; + SANE_Byte usbstat; + int i; + + DBG (DBG_info_usb, "\t\t_pieusb_scsi_command(): %02x:%s\n", command[0], code_to_text (scsi_code_text, command[0])); + + st = _ieee_command (device_number, IEEE1284_SCSI); + if (st != SANE_STATUS_GOOD) { + DBG (DBG_error, "\t\t_pieusb_scsi_command can't prep scsi cmd: %d\n", st); + return USB_STATUS_ERROR; + } + + /* output command */ + for (i = 0; i < SCSI_COMMAND_LEN; ++i) { + SANE_Status st; + st = _ctrl_out_byte (device_number, PORT_SCSI_CMD, command[i]); + if (st != SANE_STATUS_GOOD) { + DBG (DBG_error, "\t\t_pieusb_scsi_command fails command out, after %d bytes: %d\n", i, st); + return USB_STATUS_ERROR; + } + } + _hexdump ("Cmd", command, SCSI_COMMAND_LEN); + + /* Verify this sequence */ + st = _ctrl_in_byte (device_number, &usbstat); + if (st != SANE_STATUS_GOOD) { + DBG (DBG_error, "\t\t_pieusb_scsi_command fails status after command out: %d\n", st); + return USB_STATUS_ERROR; + } + /* Process rest of the data, if present; either input or output, possibly bulk */ + DBG (DBG_info_usb, "\t\t_pieusb_scsi_command usbstat 0x%02x\n", usbstat); + if (usbstat == USB_STATUS_OK && size > 0) { + /* + * send additional data to usb + */ + _hexdump ("Out", data, size); + for (i = 0; i < size; ++i) { + st = _ctrl_out_byte (device_number, PORT_SCSI_CMD, data[i]); + if (st != SANE_STATUS_GOOD) { + DBG (DBG_error, "\t\t_pieusb_scsi_command fails data out after %d bytes: %d\n", i, st); + return USB_STATUS_ERROR; + } + } + /* Verify data out */ + st = _ctrl_in_byte (device_number, &usbstat); + if (st != SANE_STATUS_GOOD) { + DBG (DBG_error, "\t\t_pieusb_scsi_command fails status after data out: %d\n", st); + return USB_STATUS_ERROR; + } + } + else if (usbstat == USB_STATUS_READ) { + /* Intermediate status OK, device has made data available for reading */ + /* Read data */ + size_t remsize; + size_t partsize; + + remsize = (size_t)size; + + DBG (DBG_info_usb, "\t\t_pieusb_scsi_command data in\n"); + while (remsize > 0) { + partsize = remsize > 0x1000000 ? 0x1000000 : remsize; /* 0xc000 must be multiples of 0x4000, see _bulk_in() */ + /* send expected length */ + st = _bulk_size (device_number, partsize); + if (st != SANE_STATUS_GOOD) { + DBG (DBG_error, "\t\t_pieusb_scsi_command prepare read data failed for size %u: %d\n", (unsigned int)partsize, st); + return USB_STATUS_ERROR; + } + /* read expected length bytes */ + st = _bulk_in (device_number, data + size - remsize, &partsize); + if (st != SANE_STATUS_GOOD) { + DBG (DBG_error, "\t\t_pieusb_scsi_command read data failed for size %u: %d\n", (unsigned int)partsize, st); + return USB_STATUS_ERROR; + } + remsize -= partsize; +/* DBG (DBG_info, "\t\t_pieusb_scsi_command partsize %08x, remsize %08x\n", (unsigned int)partsize, (unsigned int)remsize); */ + } + /* Verify data in */ + st = _ctrl_in_byte (device_number, &usbstat); + if (st != SANE_STATUS_GOOD) { + DBG (DBG_error, "\t\t_pieusb_scsi_command fails status after data in: %d\n", st); + return USB_STATUS_ERROR; + } + _hexdump ("In", data, size); + } + + return usbstat; +} + + +/** + * Simplified control transfer: one byte to given port + * + * @param device_number device number + * @param b byte to send to device + * @return SANE status + */ +static SANE_Status _ctrl_out_byte(SANE_Int device_number, SANE_Int port, SANE_Byte b) { + /* int r = libusb_control_transfer(scannerHandle, CTRL_OUT, 0x0C, 0x0088, ANYINDEX, &b, 1, TIMEOUT); */ + return sanei_usb_control_msg(device_number, REQUEST_TYPE_OUT, REQUEST_REGISTER, port, ANYINDEX, 1, &b); +} + + +/** + * Simplified control transfer for port/wValue = 0x82 - prepare bulk + * + * @param device_number device number + * @param size Size of bulk transfer which follows (number of bytes) + * @return SANE status + */ +static SANE_Status _bulk_size(SANE_Int device_number, unsigned int size) { + SANE_Byte bulksize[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + bulksize[4] = size & 0xff; + bulksize[5] = (size >> 8) & 0xff; + bulksize[6] = (size >> 16) & 0xff; + bulksize[7] = (size >> 24) & 0xff; + return sanei_usb_control_msg(device_number, REQUEST_TYPE_OUT, REQUEST_BUFFER, PORT_SCSI_SIZE, ANYINDEX, 8, bulksize); +} + + +/* + * Ctrl inbound, single byte + */ +/** + * Inbound control transfer + * + * @param device_number device number + * @param b byte received from device + * @return SANE status + */ +static SANE_Status _ctrl_in_byte(SANE_Int device_number, SANE_Byte* b) { + /* int r = libusb_control_transfer(scannerHandle, CTRL_IN, 0x0C, 0x0084, ANYINDEX, &b, 1, TIMEOUT); */ + /* int r = libusb_control_transfer(scannerHandle, CTRL_IN, 0x0C, 0x0084, ANYINDEX, &b, 1, TIMEOUT); */ + return sanei_usb_control_msg(device_number, REQUEST_TYPE_IN, REQUEST_REGISTER, PORT_SCSI_STATUS, ANYINDEX, 1, b); +} + + +/** + * Bulk in transfer for data, in parts of 0x4000 bytes max + * + * @param device_number device number + * @param data array holding or receiving data (must be preallocated) + * @param size ptr to size of the data array / actual size on output + * @return SANE status + */ +static SANE_Status +_bulk_in(SANE_Int device_number, SANE_Byte *data, size_t *size) { + size_t remaining = 0; + SANE_Status r = SANE_STATUS_GOOD; + size_t part; + + remaining = *size; + while (remaining > 0) { + /* Determine bulk size */ + part = (remaining >= 0x4000) ? 0x4000 : remaining; /* max 16k per chunk */ +/* DBG (DBG_info, "\t\t_bulk_in: %08x @ %p, %08x rem\n", (unsigned int)part, data, (unsigned int)remaining); */ + r = sanei_usb_read_bulk(device_number, data, &part); + if (r != SANE_STATUS_GOOD) { + break; + } +/* DBG (DBG_info, "\t\t_bulk_in: -> %d : %08x\n", r, (unsigned int)part);*/ + remaining -= part; + data += part; + } + *size -= remaining; + return r; +} diff --git a/backend/pieusb_usb.h b/backend/pieusb_usb.h new file mode 100644 index 0000000..dee3212 --- /dev/null +++ b/backend/pieusb_usb.h @@ -0,0 +1,114 @@ +/* sane - Scanner Access Now Easy. + + pieusb_usb.h + + Copyright (C) 2012-2015 Jan Vleeshouwers, Michael Rickmann, Klaus Kaempf + + This file is part of the SANE package. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA. + + As a special exception, the authors of SANE give permission for + additional uses of the libraries contained in this release of SANE. + + The exception is that, if you link a SANE library with other files + to produce an executable, this does not by itself cause the + resulting executable to be covered by the GNU General Public + License. Your use of that executable is in no way restricted on + account of linking the SANE library code into it. + + This exception does not, however, invalidate any other reasons why + the executable file might be covered by the GNU General Public + License. + + If you submit changes to SANE to the maintainers to be included in + a subsequent release, you agree by submitting the changes that + those changes may be distributed with this exception intact. + + If you write modifications of your own for SANE, it is your choice + whether to permit this exception to apply to your modifications. + If you do not wish that, delete this exception notice. */ + +#ifndef PIEUSB_USB_H +#define PIEUSB_USB_H + +#define PIEUSB_WAIT_BUSY 1 /* seconds to wait on busy condition */ + +#define SCSI_COMMAND_LEN 6 + +SANE_Status sanei_pieusb_usb_reset(SANE_Int device_number); + +SANE_Status sanei_pieusb_convert_status(PIEUSB_Status status); + +SANE_String sanei_pieusb_decode_sense(struct Pieusb_Sense* sense, PIEUSB_Status *status); + +PIEUSB_Status sanei_pieusb_command(SANE_Int device_number, SANE_Byte command[], SANE_Byte data[], SANE_Int size); + +/* ========================================================================= + * + * Pieusb scanner commands + * + * ========================================================================= */ + +/* Standard SCSI command codes */ +#define SCSI_TEST_UNIT_READY 0x00 +#define SCSI_REQUEST_SENSE 0x03 +#define SCSI_READ 0x08 +#define SCSI_WRITE 0x0A +#define SCSI_PARAM 0x0F +#define SCSI_INQUIRY 0x12 +#define SCSI_MODE_SELECT 0x15 +#define SCSI_COPY 0x18 +#define SCSI_MODE_SENSE 0x1A +#define SCSI_SCAN 0x1B + +/* Non-standard SCSI command codes */ +#define SCSI_SLIDE 0xD1 +#define SCSI_SET_SCAN_HEAD 0xD2 +#define SCSI_READ_GAIN_OFFSET 0xD7 +#define SCSI_WRITE_GAIN_OFFSET 0xDC +#define SCSI_READ_STATE 0xDD + +/* Additional SCSI READ/WRITE codes, |0x80 for Read */ +#define SCSI_POWER_SAVE_CONTROL 0x01 +#define SCSI_GAMMA_TABLE 0x10 +#define SCSI_HALFTONE_PATTERN 0x11 +#define SCSI_SCAN_FRAME 0x12 +#define SCSI_EXPOSURE 0x13 +#define SCSI_HIGHLIGHT_SHADOW 0x14 +#define SCSI_CALIBRATION_INFO 0x15 +#define SCSI_CAL_DATA 0x16 +#define SCSI_CMD_17 0x17 /* used by CyberView */ + +/* Standard SCSI Sense keys, see http://www.t10.org/lists/2sensekey.htm */ +#define SCSI_SENSE_NO_SENSE 0x00 +#define SCSI_SENSE_RECOVERED_ERROR 0x01 +#define SCSI_SENSE_NOT_READY 0x02 +#define SCSI_SENSE_MEDIUM_ERROR 0x03 +#define SCSI_SENSE_HARDWARE_ERROR 0x04 +#define SCSI_SENSE_ILLEGAL_REQUEST 0x05 +#define SCSI_SENSE_UNIT_ATTENTION 0x06 +#define SCSI_SENSE_DATA_PROTECT 0x07 +#define SCSI_SENSE_BLANK_CHECK 0x08 +#define SCSI_SENSE_VENDOR_SPECIFIC 0x09 +#define SCSI_SENSE_COPY_ABORTED 0x0A +#define SCSI_SENSE_ABORTED_COMMAND 0x0B +#define SCSI_SENSE_EQUAL 0x0C +#define SCSI_SENSE_VOLUME_OVERFLOW 0x0D +#define SCSI_SENSE_MISCOMPARE 0x0E +#define SCSI_SENSE_COMPLETED 0x0F + +#endif /* PIEUSB_USB_H */ diff --git a/backend/pixma.c b/backend/pixma.c index 6a2492e..3396155 100644 --- a/backend/pixma.c +++ b/backend/pixma.c @@ -1,8 +1,8 @@ /* SANE - Scanner Access Now Easy. + Copyright (C) 2011-2015 Rolf Bensch <rolf at bensch hyphen online dot de> Copyright (C) 2007-2008 Nicolas Martin, <nicols-guest at alioth dot debian dot org> Copyright (C) 2006-2007 Wittawat Yamwong <wittawat@web.de> - Copyright (C) 2011-2013 Rolf Bensch <rolf at bensch hyphen online dot de> This file is part of the SANE package. diff --git a/backend/pixma.h b/backend/pixma.h index 56bd14d..620f038 100644 --- a/backend/pixma.h +++ b/backend/pixma.h @@ -1,8 +1,8 @@ /* SANE - Scanner Access Now Easy. + Copyright (C) 2011-2015 Rolf Bensch <rolf at bensch hyphen online dot de> Copyright (C) 2007-2008 Nicolas Martin, <nicols-guest at alioth dot debian dot org> Copyright (C) 2006-2007 Wittawat Yamwong <wittawat@web.de> - Copyright (C) 2011-2013 Rolf Bensch <rolf at bensch hyphen online dot de> This file is part of the SANE package. @@ -114,7 +114,7 @@ typedef uint32_t uint32_t; /**@{*/ #define PIXMA_VERSION_MAJOR 0 #define PIXMA_VERSION_MINOR 17 -#define PIXMA_VERSION_BUILD 4 +#define PIXMA_VERSION_BUILD 23 /**@}*/ /** \name Error codes */ diff --git a/backend/pixma_bjnp.c b/backend/pixma_bjnp.c index 3046e9d..7d2d541 100644 --- a/backend/pixma_bjnp.c +++ b/backend/pixma_bjnp.c @@ -65,6 +65,9 @@ #ifdef HAVE_SYS_TIME_H #include <sys/time.h> #endif +#ifdef HAVE_LIMITS_H +#include <limits.h> +#endif /* * networking stuff @@ -99,6 +102,9 @@ #include "pixma.h" #include "pixma_common.h" +#ifndef SSIZE_MAX +# define SSIZE_MAX LONG_MAX +#endif /* static data */ static bjnp_device_t device[BJNP_NO_DEVICES]; @@ -130,11 +136,11 @@ static void u32tohex (uint32_t x, char *str) { uint8_t uint8[4]; - uint8[0]= (uint8_t) x >> 24; - uint8[1] = (uint8_t)x >> 16; - uint8[2] = (uint8_t)x >> 8; - uint8[3] = (uint8_t)x ; - u8tohex(str, uint8, 4); + uint8[0] = (uint8_t)(x >> 24); + uint8[1] = (uint8_t)(x >> 16); + uint8[2] = (uint8_t)(x >> 8); + uint8[3] = (uint8_t)x ; + u8tohex(str, uint8, 4); } static void @@ -284,7 +290,8 @@ parse_IEEE1284_to_model (char *scanner_id, char *model) char s[BJNP_IEEE1284_MAX]; char *tok; - strcpy (s, scanner_id); + strncpy (s, scanner_id, BJNP_IEEE1284_MAX); + s[BJNP_IEEE1284_MAX - 1] = '\0'; model[0] = '\0'; tok = strtok (s, ";"); @@ -294,7 +301,8 @@ parse_IEEE1284_to_model (char *scanner_id, char *model) if (strncmp (tok, "MDL:", 4) == 0) { - strcpy (model, tok + 4); + strncpy (model, tok + 4, BJNP_IEEE1284_MAX); + model[BJNP_IEEE1284_MAX -1] = '\0'; return 1; } tok = strtok (NULL, ";"); @@ -334,6 +342,34 @@ charTo2byte (char *d, const char *s, int len) return copied; } +static bjnp_protocol_defs_t *get_protocol_by_method( char *method) +{ + int i = 0; + while ( bjnp_protocol_defs[i].method_string != NULL) + { + if (strcmp(method, bjnp_protocol_defs[i].method_string) == 0) + { + return &bjnp_protocol_defs[i]; + } + i++; + } + return NULL; +} + +static bjnp_protocol_defs_t *get_protocol_by_proto_string( char *proto_string) +{ + int i = 0; + while ( bjnp_protocol_defs[i].proto_string != NULL) + { + if (strncmp(proto_string, bjnp_protocol_defs[i].proto_string, 4) == 0) + { + return &bjnp_protocol_defs[i]; + } + i++; + } + return NULL; +} + static char * getusername (void) { @@ -364,11 +400,13 @@ determine_scanner_serial (const char *hostname, const char * mac_address, char * /* if this is a FQDN, not an ip-address, remove domain part of the name */ if ((dot = strchr (copy, '.')) != NULL) { - *dot = '\0'; + *dot = '\0'; } else - strcpy(copy, mac_address); - break; + { + strcpy(copy, mac_address); + break; + } } strcpy( serial, copy ); return serial; @@ -389,7 +427,7 @@ bjnp_open_tcp (int devno) if ((sock = socket (get_protocol_family( addr ) , SOCK_STREAM, 0)) < 0) { - PDBG (bjnp_dbg (LOG_CRIT, "bjnp_open_tcp: Can not create socket: %s\n", + PDBG (bjnp_dbg (LOG_CRIT, "bjnp_open_tcp: ERROR - Can not create socket: %s\n", strerror (errno))); return -1; } @@ -422,7 +460,7 @@ bjnp_open_tcp (int devno) (sock, &(addr->addr), sa_size(device[devno].addr) )!= 0) { PDBG (bjnp_dbg - (LOG_CRIT, "bjnp_open_tcp: Can not connect to scanner: %s\n", + (LOG_CRIT, "bjnp_open_tcp: ERROR - Can not connect to scanner: %s\n", strerror (errno))); return -1; } @@ -439,7 +477,8 @@ split_uri (const char *devname, char *method, char *host, char *port, char next; int i; - strcpy (copy, devname); + strncpy (copy, devname, 1024); + copy[1023] = '\0'; start = copy; /* @@ -453,7 +492,7 @@ split_uri (const char *devname, char *method, char *host, char *port, if (((strncmp (start + i, "://", 3) != 0)) || (i > BJNP_METHOD_MAX -1 )) { - PDBG (bjnp_dbg (LOG_NOTICE, "Can not find method in %s (offset %d)\n", + PDBG (bjnp_dbg (LOG_NOTICE, "split_uri: ERROR - Can not find method in %s (offset %d)\n", devname, i)); return -1; } @@ -476,7 +515,7 @@ split_uri (const char *devname, char *method, char *host, char *port, ( (end_of_address[1] != ':') && (end_of_address[1] != '/' ) && (end_of_address[1] != '\0' )) || ( (end_of_address - start) >= BJNP_HOST_MAX ) ) { - PDBG (bjnp_dbg (LOG_NOTICE, "Can not find hostname or address in %s\n", devname)); + PDBG (bjnp_dbg (LOG_NOTICE, "split_uri: ERROR - Can not find hostname or address in %s\n", devname)); return -1; } next = end_of_address[1]; @@ -495,7 +534,7 @@ split_uri (const char *devname, char *method, char *host, char *port, start[i] = '\0'; if ((i == 0) || (i >= BJNP_HOST_MAX ) ) { - PDBG (bjnp_dbg (LOG_NOTICE, "Can not find hostname or address in %s\n", devname)); + PDBG (bjnp_dbg (LOG_NOTICE, "split_uri: ERROR - Can not find hostname or address in %s\n", devname)); return -1; } strcpy (host, start); @@ -523,7 +562,7 @@ split_uri (const char *devname, char *method, char *host, char *port, } if ((strlen(start) == 0) || (strlen(start) >= BJNP_PORT_MAX ) ) { - PDBG (bjnp_dbg (LOG_NOTICE, "Can not find port in %s (have \"%s\")\n", devname, start)); + PDBG (bjnp_dbg (LOG_NOTICE, "split_uri: ERROR - Can not find port in %s (have \"%s\")\n", devname, start)); return -1; } strcpy(port, start); @@ -538,7 +577,7 @@ split_uri (const char *devname, char *method, char *host, char *port, i = strlen(start); if ( i >= BJNP_ARGS_MAX) { - PDBG (bjnp_dbg (LOG_NOTICE, "Argument string too long in %s\n", devname)); + PDBG (bjnp_dbg (LOG_NOTICE, "split_uri: ERROR - Argument string too long in %s\n", devname)); } strcpy (args, start); } @@ -550,28 +589,40 @@ split_uri (const char *devname, char *method, char *host, char *port, static void -set_cmd (int devno, struct BJNP_command *cmd, char cmd_code, int payload_len) +set_cmd_from_string (char* protocol_string, struct BJNP_command *cmd, char cmd_code, int payload_len) { /* - * Set command buffer with command code, session_id and lenght of payload + * Set command buffer with command code, session_id and length of payload * Returns: sequence number of command */ - strncpy (cmd->BJNP_id, BJNP_STRING, sizeof (cmd->BJNP_id)); + + strncpy (cmd->BJNP_id, protocol_string, sizeof (cmd->BJNP_id)); cmd->dev_type = BJNP_CMD_SCAN; cmd->cmd_code = cmd_code; cmd->unknown1 = htons (0); - if (devno == -1) - { - /* device not yet opened, use 0 for serial and session) */ - cmd->seq_no = htons (0); - cmd->session_id = htons (0); - } - else - { - cmd->seq_no = htons (++(device[devno].serial)); - cmd->session_id = (cmd_code == CMD_UDP_POLL ) ? 0 : htons (device[devno].session_id); - device[devno].last_cmd = cmd_code; - } + + /* device not yet opened, use 0 for serial and session) */ + cmd->seq_no = htons (0); + cmd->session_id = htons (0); + cmd->payload_len = htonl (payload_len); +} + +static void +set_cmd_for_dev (int devno, struct BJNP_command *cmd, char cmd_code, int payload_len) +{ + /* + * Set command buffer with command code, session_id and length of payload + * Returns: sequence number of command + * If devno < 0, then use devno as negativ index into bjnp_protocol_defs + */ + + strncpy (cmd->BJNP_id, device[devno].protocol_string, sizeof (cmd->BJNP_id)); + cmd->dev_type = BJNP_CMD_SCAN; + cmd->cmd_code = cmd_code; + cmd->unknown1 = htons (0); + cmd->seq_no = htons (++(device[devno].serial)); + cmd->session_id = (cmd_code == CMD_UDP_POLL ) ? 0 : htons (device[devno].session_id); + device[devno].last_cmd = cmd_code; cmd->payload_len = htonl (payload_len); } @@ -596,7 +647,7 @@ bjnp_setup_udp_socket ( const int dev_no ) if ((sockfd = socket (get_protocol_family( addr ), SOCK_DGRAM, IPPROTO_UDP)) == -1) { PDBG (bjnp_dbg - (LOG_CRIT, "setup_udp_socket: can not open socket - %s\n", + (LOG_CRIT, "setup_udp_socket: ERROR - can not open socket - %s\n", strerror (errno))); return -1; } @@ -605,7 +656,7 @@ bjnp_setup_udp_socket ( const int dev_no ) (sockfd, &(device[dev_no].addr->addr), sa_size(device[dev_no].addr) )!= 0) { PDBG (bjnp_dbg - (LOG_CRIT, "setup_udp_socket: connect failed- %s\n", + (LOG_CRIT, "setup_udp_socket: ERROR - connect failed- %s\n", strerror (errno))); close(sockfd); return -1; @@ -632,7 +683,7 @@ udp_command (const int dev_no, char *command, int cmd_len, char *response, if ( (sockfd = bjnp_setup_udp_socket(dev_no) ) == -1 ) { - PDBG (bjnp_dbg( LOG_CRIT, "udp_command: Can not setup socket\n") ); + PDBG (bjnp_dbg( LOG_CRIT, "udp_command: ERROR - Can not setup socket\n") ); return -1; } @@ -641,7 +692,7 @@ udp_command (const int dev_no, char *command, int cmd_len, char *response, if ((numbytes = send (sockfd, command, cmd_len, 0)) != cmd_len) { PDBG (bjnp_dbg - (LOG_NOTICE, "udp_command: Sent %d bytes, expected %d\n", + (LOG_NOTICE, "udp_command: ERROR - Sent %d bytes, expected %d\n", numbytes, cmd_len)); continue; } @@ -666,7 +717,7 @@ udp_command (const int dev_no, char *command, int cmd_len, char *response, if (result <= 0) { PDBG (bjnp_dbg - (LOG_NOTICE, "udp_command: select failed: %s\n", + (LOG_NOTICE, "udp_command: ERROR - select failed: %s\n", result == 0 ? "timed out" : strerror (errno))); continue; } @@ -674,7 +725,7 @@ udp_command (const int dev_no, char *command, int cmd_len, char *response, if ((numbytes = recv (sockfd, response, resp_len, 0)) == -1) { PDBG (bjnp_dbg - (LOG_NOTICE, "udp_command: recv failed: %s", + (LOG_NOTICE, "udp_command: ERROR - recv failed: %s", strerror (errno))); continue; } @@ -686,7 +737,7 @@ udp_command (const int dev_no, char *command, int cmd_len, char *response, close(sockfd); PDBG (bjnp_dbg - (LOG_CRIT, "udp_command: no data received\n" ) ); + (LOG_CRIT, "udp_command: ERROR - no data received\n" ) ); return -1; } @@ -710,36 +761,43 @@ get_scanner_id (const int dev_no, char *model) strcpy (model, "Unidentified scanner"); - set_cmd (dev_no, &cmd, CMD_UDP_GET_ID, 0); + set_cmd_for_dev (dev_no, &cmd, CMD_UDP_GET_ID, 0); - PDBG (bjnp_dbg (LOG_DEBUG2, "Get scanner identity\n")); + PDBG (bjnp_dbg (LOG_DEBUG2, "get_scanner_id: Get scanner identity\n")); PDBG (bjnp_hexdump (LOG_DEBUG2, (char *) &cmd, sizeof (struct BJNP_command))); if ( ( resp_len = udp_command (dev_no, (char *) &cmd, sizeof (struct BJNP_command), resp_buf, BJNP_RESP_MAX) ) < (int)sizeof(struct BJNP_command) ) { - PDBG (bjnp_dbg (LOG_DEBUG, "Failed to retrieve scanner identity:\n")); + PDBG (bjnp_dbg (LOG_DEBUG, "get_scanner_id: ERROR - Failed to retrieve scanner identity:\n")); return -1; } - PDBG (bjnp_dbg (LOG_DEBUG2, "scanner identity:\n")); + PDBG (bjnp_dbg (LOG_DEBUG2, "get_scanner_id: scanner identity:\n")); PDBG (bjnp_hexdump (LOG_DEBUG2, resp_buf, resp_len)); id = (struct IDENTITY *) resp_buf; - /* truncate string to be safe */ - id_len = htons( id-> id_len ) - sizeof(id->id_len); - id->id[id_len] = '\0'; - strcpy (scanner_id, id->id); - - PDBG (bjnp_dbg (LOG_INFO, "Scanner identity string = %s - lenght = %d\n", scanner_id, id_len)); + if (device[dev_no].protocol == PROTOCOL_BJNP) + { + id_len = MIN(ntohl( id-> cmd.payload_len ) - sizeof(id-> payload.bjnp.id_len), BJNP_IEEE1284_MAX); + strncpy(scanner_id, id->payload.bjnp.id, id_len); + scanner_id[id_len] = '\0'; + } + else + { + id_len = MIN(ntohl( id-> cmd.payload_len ), BJNP_IEEE1284_MAX); + strncpy(scanner_id, id->payload.mfnp.id, id_len); + scanner_id[id_len] = '\0'; + } + PDBG (bjnp_dbg (LOG_INFO, "get_scanner_id: Scanner identity string = %s - length = %d\n", scanner_id, id_len)); /* get make&model from IEEE1284 id */ if (model != NULL) { parse_IEEE1284_to_model (scanner_id, model); - PDBG (bjnp_dbg (LOG_INFO, "Scanner model = %s\n", model)); + PDBG (bjnp_dbg (LOG_INFO, "get_scanner_id: Scanner model = %s\n", model)); } return 0; } @@ -776,7 +834,7 @@ get_scanner_name(const bjnp_sockaddr_t *scanner_sa, char *host) if( (error = getnameinfo( &(scanner_sa -> addr) , sa_size( scanner_sa), host, BJNP_HOST_MAX , NULL, 0, NI_NAMEREQD) ) != 0 ) { - PDBG (bjnp_dbg(LOG_INFO, "Name for %s not found : %s\n", + PDBG (bjnp_dbg(LOG_INFO, "get_scanner_name: Name for %s not found : %s\n", ip_address, gai_strerror(error) ) ); strcpy(host, ip_address); return level; @@ -797,7 +855,7 @@ get_scanner_name(const bjnp_sockaddr_t *scanner_sa, char *host) { /* found match, good */ PDBG (bjnp_dbg (LOG_INFO, - "Forward lookup for %s succeeded, using as hostname\n", host)); + "get_scanner_name: Forward lookup for %s succeeded, using as hostname\n", host)); match = 1; level = BJNP_ADDRESS_HAS_FQDN; break; @@ -809,7 +867,7 @@ get_scanner_name(const bjnp_sockaddr_t *scanner_sa, char *host) if (match != 1) { PDBG (bjnp_dbg (LOG_INFO, - "Forward lookup for %s succeeded, IP-address does not match, using IP-address %s instead\n", + "get_scanner_name: Forward lookup for %s succeeded, IP-address does not match, using IP-address %s instead\n", host, ip_address)); strcpy (host, ip_address); } @@ -817,13 +875,30 @@ get_scanner_name(const bjnp_sockaddr_t *scanner_sa, char *host) else { /* forward lookup failed, use ip-address */ - PDBG ( bjnp_dbg (LOG_INFO, "Forward lookup of %s failed, using IP-address", ip_address)); + PDBG ( bjnp_dbg (LOG_INFO, "get_scanner_name: Forward lookup of %s failed, using IP-address", ip_address)); strcpy (host, ip_address); } } return level; } +static int +get_port_from_sa(const bjnp_sockaddr_t scanner_sa) +{ +#ifdef ENABLE_IPV6 + if ( scanner_sa.addr.sa_family == AF_INET6 ) + { + return ntohs(scanner_sa.ipv6.sin6_port); + } + else +#endif + if ( scanner_sa.addr.sa_family == AF_INET ) + { + return ntohs(scanner_sa.ipv4.sin_port); + } + return -1; +} + static int create_broadcast_socket( const bjnp_sockaddr_t * local_addr ) { int sockfd = -1; @@ -834,7 +909,7 @@ static int create_broadcast_socket( const bjnp_sockaddr_t * local_addr ) if ((sockfd = socket (local_addr-> addr.sa_family, SOCK_DGRAM, 0)) == -1) { PDBG (bjnp_dbg - (LOG_CRIT, "create_broadcast_socket: can not open socket - %s", + (LOG_CRIT, "create_broadcast_socket: ERROR - can not open socket - %s", strerror (errno))); return -1; } @@ -847,7 +922,7 @@ static int create_broadcast_socket( const bjnp_sockaddr_t * local_addr ) { PDBG (bjnp_dbg (LOG_CRIT, - "create_broadcast_socket: setting socket option SO_BROADCAST failed - %s", + "create_broadcast_socket: ERROR - setting socket option SO_BROADCAST failed - %s", strerror (errno))); close (sockfd); return -1; @@ -860,7 +935,7 @@ static int create_broadcast_socket( const bjnp_sockaddr_t * local_addr ) { PDBG (bjnp_dbg (LOG_CRIT, - "create_broadcast_socket: setting socket option IPV6_V6ONLY failed - %s", + "create_broadcast_socket: ERROR - setting socket option IPV6_V6ONLY failed - %s", strerror (errno))); close (sockfd); return -1; @@ -872,7 +947,7 @@ static int create_broadcast_socket( const bjnp_sockaddr_t * local_addr ) { PDBG (bjnp_dbg (LOG_CRIT, - "create_broadcast_socket: bind socket to local address failed - %s\n", + "create_broadcast_socket: ERROR - bind socket to local address failed - %s\n", strerror (errno))); close (sockfd); return -1; @@ -900,7 +975,7 @@ prepare_socket(const char *if_name, const bjnp_sockaddr_t *local_sa, if ( local_sa == NULL ) { PDBG (bjnp_dbg (LOG_DEBUG, - "%s is not a valid IPv4 interface, skipping...\n", + "prepare_socket: %s is not a valid IPv4 interface, skipping...\n", if_name)); return -1; } @@ -919,7 +994,7 @@ prepare_socket(const char *if_name, const bjnp_sockaddr_t *local_sa, /* not a valid interface */ PDBG (bjnp_dbg (LOG_DEBUG, - "%s is not a valid IPv4 interface, skipping...\n", + "prepare_socket: %s is not a valid IPv4 interface, skipping...\n", if_name)); return -1; } @@ -928,15 +1003,18 @@ 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) ); - dest_sa -> ipv4.sin_port = htons(BJNP_PORT_SCAN); + + /* we fill port when we send the broadcast */ + dest_sa -> ipv4.sin_port = htons(0); + if ( (socket = create_broadcast_socket( &local_sa_copy) ) != -1) { - PDBG (bjnp_dbg (LOG_INFO, "%s is IPv4 capable, sending broadcast, socket = %d\n", + PDBG (bjnp_dbg (LOG_INFO, "prepare_socket: %s is IPv4 capable, sending broadcast, socket = %d\n", if_name, socket)); } else { - PDBG (bjnp_dbg (LOG_INFO, "%s is IPv4 capable, but failed to create a socket.\n", + PDBG (bjnp_dbg (LOG_INFO, "prepare_socket: ERROR - %s is IPv4 capable, but failed to create a socket.\n", if_name)); return -1; } @@ -952,23 +1030,26 @@ prepare_socket(const char *if_name, const bjnp_sockaddr_t *local_sa, /* not a valid interface */ PDBG (bjnp_dbg (LOG_DEBUG, - "%s is not a valid IPv6 interface, skipping...\n", + "prepare_socket: %s is not a valid IPv6 interface, skipping...\n", if_name)); return -1; } else { dest_sa -> ipv6.sin6_family = AF_INET6; - dest_sa -> ipv6.sin6_port = htons(BJNP_PORT_SCAN); + + /* We fill port when we send the broadcast */ + dest_sa -> ipv6.sin6_port = htons(0); + inet_pton(AF_INET6, "ff02::1", dest_sa -> ipv6.sin6_addr.s6_addr); if ( (socket = create_broadcast_socket( &local_sa_copy ) ) != -1) { - PDBG (bjnp_dbg (LOG_INFO, "%s is IPv6 capable, sending broadcast, socket = %d\n", + PDBG (bjnp_dbg (LOG_INFO, "prepare_socket: %s is IPv6 capable, sending broadcast, socket = %d\n", if_name, socket)); } else { - PDBG (bjnp_dbg (LOG_INFO, "%s is IPv6 capable, but failed to create a socket.\n", + PDBG (bjnp_dbg (LOG_INFO, "prepare_socket: ERROR - %s is IPv6 capable, but failed to create a socket.\n", if_name)); return -1; } @@ -984,20 +1065,33 @@ prepare_socket(const char *if_name, const bjnp_sockaddr_t *local_sa, } static int -bjnp_send_broadcast (int sockfd, const bjnp_sockaddr_t * broadcast_addr, +bjnp_send_broadcast (int sockfd, const bjnp_sockaddr_t * broadcast_addr, int port, struct BJNP_command cmd, int size) { int num_bytes; + bjnp_sockaddr_t dest_addr; - /* set address to send packet to */ - /* usebroadcast address of interface */ + /* set address to send packet to broadcast address of interface, */ + /* with port set to the destination port */ + + memcpy(&dest_addr, broadcast_addr, sizeof(dest_addr)); + if( dest_addr.addr.sa_family == AF_INET) + { + dest_addr.ipv4.sin_port = htons(port); + } +#ifdef ENABLE_IPV6 + if( dest_addr.addr.sa_family == AF_INET6) + { + dest_addr.ipv6.sin6_port = htons(port); + } +#endif if ((num_bytes = sendto (sockfd, &cmd, size, 0, - &(broadcast_addr->addr), + &(dest_addr.addr), sa_size( broadcast_addr)) ) != size) { PDBG (bjnp_dbg (LOG_INFO, - "bjnp_send_broadcast: Socket: %d: sent only %x = %d bytes of packet, error = %s\n", + "bjnp_send_broadcast: Socket: %d: ERROR - sent only %x = %d bytes of packet, error = %s\n", sockfd, num_bytes, num_bytes, strerror (errno))); /* not allowed, skip this interface */ @@ -1017,9 +1111,9 @@ bjnp_finish_job (int devno) int resp_len; struct BJNP_command cmd; - set_cmd (devno, &cmd, CMD_UDP_CLOSE, 0); + set_cmd_for_dev (devno, &cmd, CMD_UDP_CLOSE, 0); - PDBG (bjnp_dbg (LOG_DEBUG2, "Finish scanjob\n")); + PDBG (bjnp_dbg (LOG_DEBUG2, "bjnp_finish_job: Finish scanjob\n")); PDBG (bjnp_hexdump (LOG_DEBUG2, (char *) &cmd, sizeof (struct BJNP_command))); resp_len = @@ -1030,11 +1124,11 @@ bjnp_finish_job (int devno) { PDBG (bjnp_dbg (LOG_INFO, - "Received %d characters on close scanjob command, expected %d\n", + "bjnp_finish_job: ERROR - Received %d characters on close scanjob command, expected %d\n", resp_len, (int) sizeof (struct BJNP_command))); return; } - PDBG (bjnp_dbg (LOG_DEBUG2, "Finish scanjob response\n")); + PDBG (bjnp_dbg (LOG_DEBUG2, "bjnp_finish_job: Finish scanjob response\n")); PDBG (bjnp_hexdump (LOG_DEBUG2, resp_buf, resp_len)); } @@ -1101,11 +1195,11 @@ bjnp_poll_scanner (int devno, char type,char *hostname, char *user, SANE_Byte *s return -1; }; /* we can only now set the header as we now know the length of the payload */ - set_cmd (devno, (struct BJNP_command *) cmd_buf, CMD_UDP_POLL, + set_cmd_for_dev (devno, (struct BJNP_command *) cmd_buf, CMD_UDP_POLL, len); buf_len = len + sizeof(struct BJNP_command); - PDBG (bjnp_dbg (LOG_DEBUG2, "Poll details (type %d)\n", type)); + PDBG (bjnp_dbg (LOG_DEBUG2, "bjnp_poll_scanner: Poll details (type %d)\n", type)); PDBG (bjnp_hexdump (LOG_DEBUG2, cmd_buf, buf_len)); @@ -1113,7 +1207,7 @@ bjnp_poll_scanner (int devno, char type,char *hostname, char *user, SANE_Byte *s if (resp_len > 0) { - PDBG (bjnp_dbg (LOG_DEBUG2, "Poll details response:\n")); + PDBG (bjnp_dbg (LOG_DEBUG2, "bjnp_poll_scanner: Poll details response:\n")); PDBG (bjnp_hexdump (LOG_DEBUG2, resp_buf, resp_len)); response = (struct POLL_RESPONSE *) resp_buf; @@ -1126,7 +1220,7 @@ bjnp_poll_scanner (int devno, char type,char *hostname, char *user, SANE_Byte *s if ( (response -> result[2] & 0x80) != 0) { memcpy( status, response->status, size); - PDBG( bjnp_dbg(LOG_INFO, "received button status!\n")); + PDBG( bjnp_dbg(LOG_INFO, "bjnp_poll_scanner: received button status!\n")); PDBG (bjnp_hexdump( LOG_DEBUG2, status, size )); device[devno].status_key = ntohl( response -> key ); return size; @@ -1151,7 +1245,7 @@ bjnp_send_job_details (int devno, char *hostname, char *user, char *title) /* send job details command */ - set_cmd (devno, (struct BJNP_command *) cmd_buf, CMD_UDP_JOB_DETAILS, + set_cmd_for_dev (devno, (struct BJNP_command *) cmd_buf, CMD_UDP_JOB_DETAILS, sizeof (*job) - sizeof (struct BJNP_command)); /* create payload */ @@ -1162,7 +1256,7 @@ bjnp_send_job_details (int devno, char *hostname, char *user, char *title) charTo2byte (job->username, user, sizeof (job->username)); charTo2byte (job->jobtitle, title, sizeof (job->jobtitle)); - PDBG (bjnp_dbg (LOG_DEBUG2, "Job details\n")); + PDBG (bjnp_dbg (LOG_DEBUG2, "bjnp_send_job_details: Job details\n")); PDBG (bjnp_hexdump (LOG_DEBUG2, cmd_buf, (sizeof (struct BJNP_command) + sizeof (*job)))); @@ -1172,7 +1266,7 @@ bjnp_send_job_details (int devno, char *hostname, char *user, char *title) if (resp_len > 0) { - PDBG (bjnp_dbg (LOG_DEBUG2, "Job details response:\n")); + PDBG (bjnp_dbg (LOG_DEBUG2, "bjnp_send_job_details: Job details response:\n")); PDBG (bjnp_hexdump (LOG_DEBUG2, resp_buf, resp_len)); resp = (struct BJNP_command *) resp_buf; device[devno].session_id = ntohs (resp->session_id); @@ -1193,14 +1287,14 @@ bjnp_get_scanner_mac_address ( int devno, char *mac_address ) /* send job details command */ - set_cmd (devno, (struct BJNP_command *) cmd_buf, CMD_UDP_DISCOVER, 0); + set_cmd_for_dev (devno, (struct BJNP_command *) cmd_buf, CMD_UDP_DISCOVER, 0); resp_len = udp_command (devno, cmd_buf, sizeof (struct BJNP_command), resp_buf, BJNP_RESP_MAX); if (resp_len > 0) { - PDBG (bjnp_dbg (LOG_DEBUG2, "Discover response:\n")); + PDBG (bjnp_dbg (LOG_DEBUG2, "bjnp_get_scanner_mac_address: Discover response:\n")); PDBG (bjnp_hexdump (LOG_DEBUG2, resp_buf, resp_len)); u8tohex( mac_address, resp -> mac_addr, sizeof( resp -> mac_addr ) ); return 0; @@ -1212,7 +1306,7 @@ static int bjnp_write (int devno, const SANE_Byte * buf, size_t count) { /* - * This function writes scandata to the scanner. + * This function writes TCP data to the scanner. * Returns: number of bytes written to the scanner */ int sent_bytes; @@ -1220,14 +1314,15 @@ bjnp_write (int devno, const SANE_Byte * buf, size_t count) struct SCAN_BUF bjnp_buf; if (device[devno].scanner_data_left) - PDBG (bjnp_dbg - (LOG_CRIT, "bjnp_write: ERROR: scanner data left = 0x%lx = %ld\n", - (unsigned long) device[devno].scanner_data_left, - (unsigned long) device[devno].scanner_data_left)); - + { + PDBG (bjnp_dbg + (LOG_CRIT, "bjnp_write: ERROR - scanner data left = 0x%lx = %ld\n", + (unsigned long) device[devno].scanner_data_left, + (unsigned long) device[devno].scanner_data_left)); + } /* set BJNP command header */ - set_cmd (devno, (struct BJNP_command *) &bjnp_buf, CMD_TCP_SEND, count); + set_cmd_for_dev (devno, (struct BJNP_command *) &bjnp_buf, CMD_TCP_SEND, count); memcpy (bjnp_buf.scan_data, buf, count); PDBG (bjnp_dbg (LOG_DEBUG, "bjnp_write: sending 0x%lx = %ld bytes\n", (unsigned long) count, (unsigned long) count); @@ -1241,7 +1336,7 @@ bjnp_write (int devno, const SANE_Byte * buf, size_t count) { /* return result from write */ terrno = errno; - PDBG (bjnp_dbg (LOG_CRIT, "bjnp_write: Could not send data!\n")); + PDBG (bjnp_dbg (LOG_CRIT, "bjnp_write: ERROR - Could not send data!\n")); errno = terrno; return sent_bytes; } @@ -1270,13 +1365,13 @@ bjnp_send_read_request (int devno) if (device[devno].scanner_data_left) PDBG (bjnp_dbg (LOG_CRIT, - "bjnp_send_read_request: ERROR scanner data left = 0x%lx = %ld\n", + "bjnp_send_read_request: ERROR - scanner data left = 0x%lx = %ld\n", (unsigned long) device[devno].scanner_data_left, (unsigned long) device[devno].scanner_data_left)); /* set BJNP command header */ - set_cmd (devno, (struct BJNP_command *) &bjnp_buf, CMD_TCP_REQ, 0); + set_cmd_for_dev (devno, (struct BJNP_command *) &bjnp_buf, CMD_TCP_REQ, 0); PDBG (bjnp_dbg (LOG_DEBUG, "bjnp_send_read_req sending command\n")); PDBG (bjnp_hexdump (LOG_DEBUG2, (char *) &bjnp_buf, @@ -1289,7 +1384,7 @@ bjnp_send_read_request (int devno) /* return result from write */ terrno = errno; PDBG (bjnp_dbg - (LOG_CRIT, "bjnp_send_read_request: Could not send data!\n")); + (LOG_CRIT, "bjnp_send_read_request: ERROR - Could not send data!\n")); errno = terrno; return -1; } @@ -1338,7 +1433,7 @@ bjnp_recv_header (int devno, size_t *payload_size ) { terrno = errno; PDBG (bjnp_dbg (LOG_CRIT, - "bjnp_recv_header: could not read response header (select): %s!\n", + "bjnp_recv_header: ERROR - could not read response header (select): %s!\n", strerror (terrno))); errno = terrno; return SANE_STATUS_IO_ERROR; @@ -1347,7 +1442,7 @@ bjnp_recv_header (int devno, size_t *payload_size ) { terrno = errno; PDBG (bjnp_dbg (LOG_CRIT, - "bjnp_recv_header: could not read response header (select timed out)!\n" ) ); + "bjnp_recv_header: ERROR - could not read response header (select timed out)!\n" ) ); errno = terrno; return SANE_STATUS_IO_ERROR; } @@ -1360,12 +1455,18 @@ bjnp_recv_header (int devno, size_t *payload_size ) 0)) != sizeof (struct BJNP_command)) { terrno = errno; - PDBG (bjnp_dbg (LOG_CRIT, - "bjnp_recv_header: (recv) could not read response header, received %d bytes!\n", + if (recv_bytes == 0) + { + PDBG (bjnp_dbg (LOG_CRIT, + "bjnp_recv_header: ERROR - (recv) Scanner closed the TCP-connection!\n")); + } else { + PDBG (bjnp_dbg (LOG_CRIT, + "bjnp_recv_header: ERROR - (recv) could not read response header, received %d bytes!\n", recv_bytes)); - PDBG (bjnp_dbg - (LOG_CRIT, "bjnp_recv_header: (recv) error: %s!\n", - strerror (terrno))); + PDBG (bjnp_dbg + (LOG_CRIT, "bjnp_recv_header: ERROR - (recv) error: %s!\n", + strerror (terrno))); + } errno = terrno; return SANE_STATUS_IO_ERROR; } @@ -1374,7 +1475,7 @@ bjnp_recv_header (int devno, size_t *payload_size ) { PDBG (bjnp_dbg (LOG_CRIT, - "bjnp_recv_header:ERROR, Received response has cmd code %d, expected %d\n", + "bjnp_recv_header: ERROR - Received response has cmd code %d, expected %d\n", resp_buf.cmd_code, device[devno].last_cmd)); return SANE_STATUS_IO_ERROR; } @@ -1383,17 +1484,17 @@ bjnp_recv_header (int devno, size_t *payload_size ) { PDBG (bjnp_dbg (LOG_CRIT, - "bjnp_recv_header:ERROR, Received response has serial %d, expected %d\n", + "bjnp_recv_header: ERROR - Received response has serial %d, expected %d\n", (int) ntohs (resp_buf.seq_no), (int) device[devno].serial)); return SANE_STATUS_IO_ERROR; } - /* got response header back, retrieve length of scanner data */ + /* got response header back, retrieve length of payload */ *payload_size = ntohl (resp_buf.payload_len); PDBG (bjnp_dbg - (LOG_DEBUG, "TCP response header(scanner data = %ld bytes):\n", + (LOG_DEBUG, "bjnp_recv_header: TCP response header(payload data = %ld bytes):\n", *payload_size) ); PDBG (bjnp_hexdump (LOG_DEBUG2, (char *) &resp_buf, sizeof (struct BJNP_command))); @@ -1401,7 +1502,7 @@ bjnp_recv_header (int devno, size_t *payload_size ) } static int -bjnp_init_device_structure(int dn, bjnp_sockaddr_t *sa ) +bjnp_init_device_structure(int dn, bjnp_sockaddr_t *sa, bjnp_protocol_defs_t *protocol_defs) { /* initialize device structure */ @@ -1413,6 +1514,8 @@ bjnp_init_device_structure(int dn, bjnp_sockaddr_t *sa ) device[dn].dialog = 0; device[dn].status_key = 0; #endif + device[dn].protocol = protocol_defs->protocol_version; + device[dn].protocol_string = protocol_defs->proto_string; device[dn].tcp_socket = -1; device[dn].addr = (bjnp_sockaddr_t *) malloc(sizeof ( bjnp_sockaddr_t) ); @@ -1424,14 +1527,14 @@ bjnp_init_device_structure(int dn, bjnp_sockaddr_t *sa ) device[dn].bjnp_timeout = 0; device[dn].scanner_data_left = 0; device[dn].last_cmd = 0; - device[dn].blocksize = 2048; /* safe assumption, we start low */ + device[dn].blocksize = BJNP_BLOCKSIZE_START; device[dn].last_block = 0; /* fill mac_address */ if (bjnp_get_scanner_mac_address(dn, device[dn].mac_address) != 0 ) { PDBG (bjnp_dbg - (LOG_CRIT, "Cannot read mac address, skipping this scanner\n" ) ); + (LOG_CRIT, "bjnp_init_device_structure: Cannot read mac address, skipping this scanner\n" ) ); return -1; } return 0; @@ -1449,11 +1552,12 @@ bjnp_free_device_structure( int dn) } static SANE_Status -bjnp_recv_data (int devno, SANE_Byte * buffer, size_t * len) +bjnp_recv_data (int devno, SANE_Byte * buffer, size_t start_pos, size_t * len) { /* - * This function receives the responses to the write commands. + * This function receives the payload data. * NOTE: len may not exceed SSIZE_MAX (as that is max for recv) + * len will be restricted to SSIZE_MAX to be sure * Returns: number of bytes of payload received from device */ @@ -1465,13 +1569,28 @@ bjnp_recv_data (int devno, SANE_Byte * buffer, size_t * len) int fd; int attempt; - PDBG (bjnp_dbg (LOG_DEBUG, "bjnp_recv_data: receiving response data\n")); - fd = device[devno].tcp_socket; - PDBG (bjnp_dbg - (LOG_DEBUG, "bjnp_recv_data: read response payload (%ld bytes max)\n", - (unsigned long) *len)); + (LOG_DEBUG, "bjnp_recv_data: read response payload (0x%lx bytes max), buffer: 0x%lx, start_pos: 0x%lx\n", + (long) *len, (long) buffer, (long) start_pos)); + + if (*len == 0) + { + /* nothing to do */ + PDBG (bjnp_dbg + (LOG_DEBUG, "bjnp_recv_data: Nothing to do (%ld bytes requested)\n", + (long) *len)); + return SANE_STATUS_GOOD; + } + else if ( *len > SSIZE_MAX ) + { + PDBG (bjnp_dbg + (LOG_DEBUG, "bjnp_recv_data: WARNING - requested block size (%ld) exceeds maximum, setting to maximum %ld\n", + (long)*len, SSIZE_MAX)); + *len = SSIZE_MAX; + } + + fd = device[devno].tcp_socket; attempt = 0; do { @@ -1488,7 +1607,7 @@ bjnp_recv_data (int devno, SANE_Byte * buffer, size_t * len) { terrno = errno; PDBG (bjnp_dbg (LOG_CRIT, - "bjnp_recv_data: could not read response payload (select): %s!\n", + "bjnp_recv_data: ERROR - could not read response payload (select failed): %s!\n", strerror (errno))); errno = terrno; *len = 0; @@ -1498,24 +1617,23 @@ bjnp_recv_data (int devno, SANE_Byte * buffer, size_t * len) { terrno = errno; PDBG (bjnp_dbg (LOG_CRIT, - "bjnp_recv_data: could not read response payload (select timed out): %s!\n", - strerror (terrno))); + "bjnp_recv_data: ERROR - could not read response payload (select timed out)!\n") ); errno = terrno; *len = 0; return SANE_STATUS_IO_ERROR; } - if ((recv_bytes = recv (fd, buffer, *len, 0)) < 0) + if ((recv_bytes = recv (fd, buffer + start_pos, *len, 0)) < 0) { terrno = errno; PDBG (bjnp_dbg (LOG_CRIT, - "bjnp_recv_data: could not read response payload (recv): %s!\n", - strerror (errno))); + "bjnp_recv_data: ERROR - could not read response payload (%ld + %ld = %ld) (recv): %s!\n", + (long) buffer, (long) start_pos, (long) buffer + start_pos, strerror (errno))); errno = terrno; *len = 0; return SANE_STATUS_IO_ERROR; } - PDBG (bjnp_dbg (LOG_DEBUG2, "Received TCP response payload (%ld bytes):\n", + PDBG (bjnp_dbg (LOG_DEBUG2, "bjnp_recv_data: Received TCP response payload (%ld bytes):\n", (unsigned long) recv_bytes)); PDBG (bjnp_hexdump (LOG_DEBUG2, buffer, recv_bytes)); @@ -1531,6 +1649,7 @@ bjnp_allocate_device (SANE_String_Const devname, char host[BJNP_HOST_MAX]; char port[BJNP_PORT_MAX] = ""; char args[BJNP_ARGS_MAX]; + bjnp_protocol_defs_t *protocol_defs; struct addrinfo *res, *cur; struct addrinfo hints; int result; @@ -1547,22 +1666,22 @@ bjnp_allocate_device (SANE_String_Const devname, { PDBG (bjnp_dbg (LOG_CRIT, - "URI may not contain userid, password or aguments: %s\n", + "bjnp_allocate_device: ERROR - URI may not contain userid, password or aguments: %s\n", devname)); return BJNP_STATUS_INVAL; } - if (strcmp (method, BJNP_METHOD) != 0) + if ( (protocol_defs = get_protocol_by_method(method)) == NULL) { PDBG (bjnp_dbg - (LOG_CRIT, "URI %s contains invalid method: %s\n", devname, + (LOG_CRIT, "bjnp_allocate_device: ERROR - URI %s contains invalid method: %s\n", devname, method)); return BJNP_STATUS_INVAL; } if (strlen(port) == 0) { - sprintf( port, "%d", BJNP_PORT_SCAN ); + sprintf( port, "%d", protocol_defs->default_port ); } hints.ai_flags = 0; @@ -1581,7 +1700,7 @@ bjnp_allocate_device (SANE_String_Const devname, result = getaddrinfo (host, port, &hints, &res ); if (result != 0 ) { - PDBG (bjnp_dbg (LOG_CRIT, "Cannot resolve host: %s port %s\n", host, port)); + PDBG (bjnp_dbg (LOG_CRIT, "bjnp_allocate_device: ERROR - Cannot resolve host: %s port %s\n", host, port)); return SANE_STATUS_INVAL; } @@ -1596,12 +1715,13 @@ bjnp_allocate_device (SANE_String_Const devname, { PDBG (bjnp_dbg (LOG_CRIT, - "Too many devices, ran out of device structures, can not add %s\n", + "bjnp_allocate_device: WARNING - Too many devices, ran out of device structures, can not add %s\n", devname)); freeaddrinfo(res); return BJNP_STATUS_INVAL; } - if (bjnp_init_device_structure( bjnp_no_devices, (bjnp_sockaddr_t *)cur -> ai_addr) != 0) + if (bjnp_init_device_structure( bjnp_no_devices, (bjnp_sockaddr_t *)cur -> ai_addr, + protocol_defs) != 0) { /* giving up on this address, try next one if any */ break; @@ -1632,7 +1752,7 @@ bjnp_allocate_device (SANE_String_Const devname, } freeaddrinfo(res); - PDBG (bjnp_dbg (LOG_INFO, "Scanner not yet in our list, added it: %s:%s\n", host, port)); + PDBG (bjnp_dbg (LOG_INFO, "bjnp_allocate_device: Scanner not yet in our list, added it: %s:%s\n", host, port)); /* return hostname if required */ @@ -1670,7 +1790,7 @@ static void add_scanner(SANE_Int *dev_no, case BJNP_STATUS_GOOD: if (get_scanner_id (*dev_no, makemodel) != 0) { - PDBG (bjnp_dbg (LOG_CRIT, "Cannot read scanner make & model: %s\n", + PDBG (bjnp_dbg (LOG_CRIT, "add_scanner: ERROR - Cannot read scanner make & model: %s\n", uri)); } else @@ -1682,15 +1802,17 @@ static void add_scanner(SANE_Int *dev_no, determine_scanner_serial (scanner_host, device[*dev_no].mac_address, serial); attach_bjnp (uri, makemodel, serial, pixma_devices); + PDBG (bjnp_dbg (LOG_NOTICE, "add_scanner: New scanner at %s added!\n", + uri)); } break; case BJNP_STATUS_ALREADY_ALLOCATED: - PDBG (bjnp_dbg (LOG_NOTICE, "Scanner at %s was added before, good!\n", + PDBG (bjnp_dbg (LOG_NOTICE, "add_scanner: Scanner at %s was added before, good!\n", uri)); break; case BJNP_STATUS_INVAL: - PDBG (bjnp_dbg (LOG_NOTICE, "Scanner at %s can not be added\n", + PDBG (bjnp_dbg (LOG_NOTICE, "add_scanner: Scanner at %s can not be added\n", uri)); break; } @@ -1738,6 +1860,7 @@ sanei_bjnp_find_devices (const char **conf_devices, int socket_fd[BJNP_SOCK_MAX]; int no_sockets; int i; + int j; int attempt; int last_socketfd = 0; fd_set fdset; @@ -1746,13 +1869,16 @@ sanei_bjnp_find_devices (const char **conf_devices, char scanner_host[256]; char uri[256]; int dev_no; + int port; bjnp_sockaddr_t broadcast_addr[BJNP_SOCK_MAX]; bjnp_sockaddr_t scanner_sa; socklen_t socklen; + bjnp_protocol_defs_t *protocol_defs; memset( broadcast_addr, 0, sizeof( broadcast_addr) ); memset( &scanner_sa, 0 ,sizeof( scanner_sa ) ); - PDBG (bjnp_dbg (LOG_INFO, "sanei_bjnp_find_devices:\n")); + PDBG (bjnp_dbg (LOG_INFO, "sanei_bjnp_find_devices, pixma backend version: %d.%d.%d\n", + PIXMA_VERSION_MAJOR, PIXMA_VERSION_MINOR, PIXMA_VERSION_BUILD)); bjnp_no_devices = 0; for (i=0; i < BJNP_SOCK_MAX; i++) @@ -1762,24 +1888,23 @@ sanei_bjnp_find_devices (const char **conf_devices, /* First add devices from config file */ if (conf_devices[0] == NULL) - PDBG (bjnp_dbg( LOG_DEBUG, "No devices specified in configuration file.\n" ) ); + PDBG (bjnp_dbg( LOG_DEBUG, "sanei_bjnp_find_devices: No devices specified in configuration file.\n" ) ); for (i = 0; conf_devices[i] != NULL; i++) { PDBG (bjnp_dbg - (LOG_DEBUG, "Adding scanner from pixma.conf: %s\n", conf_devices[i])); + (LOG_DEBUG, "sanei_bjnp_find_devices: Adding scanner from pixma.conf: %s\n", conf_devices[i])); add_scanner(&dev_no, conf_devices[i], attach_bjnp, pixma_devices); } PDBG (bjnp_dbg (LOG_DEBUG, - "Added all configured scanners, now do auto detection...\n")); + "sanei_bjnp_find_devices: Added all configured scanners, now do auto detection...\n")); /* * Send UDP DISCOVER to discover scanners and return the list of scanners found */ FD_ZERO (&fdset); - set_cmd (-1, &cmd, CMD_UDP_DISCOVER, 0); no_sockets = 0; #ifdef HAVE_IFADDRS_H @@ -1824,7 +1949,7 @@ sanei_bjnp_find_devices (const char **conf_devices, local.ipv4.sin_addr.s_addr = htonl (INADDR_ANY); bc_addr.ipv4.sin_family = AF_INET; - bc_addr.ipv4.sin_port = htons(BJNP_PORT_SCAN); + bc_addr.ipv4.sin_port = htons(0); bc_addr.ipv4.sin_addr.s_addr = htonl (INADDR_BROADCAST); socket_fd[no_sockets] = prepare_socket( "any_interface", @@ -1866,7 +1991,14 @@ sanei_bjnp_find_devices (const char **conf_devices, { for ( i=0; i < no_sockets; i++) { - bjnp_send_broadcast ( socket_fd[i], &broadcast_addr[i], cmd, sizeof (cmd)); + j = 0; + while(bjnp_protocol_defs[j].protocol_version != PROTOCOL_NONE) + { + set_cmd_from_string (bjnp_protocol_defs[j].proto_string, &cmd, CMD_UDP_DISCOVER, 0); + bjnp_send_broadcast ( socket_fd[i], &broadcast_addr[i], + bjnp_protocol_defs[j].default_port, cmd, sizeof (cmd)); + j++; + } } /* wait for some time between broadcast packets */ usleep (BJNP_BROADCAST_INTERVAL * BJNP_USLEEP_MS); @@ -1882,7 +2014,7 @@ sanei_bjnp_find_devices (const char **conf_devices, while (select (last_socketfd + 1, &active_fdset, NULL, NULL, &timeout) > 0) { - PDBG (bjnp_dbg (LOG_DEBUG, "Select returned, time left %d.%d....\n", + PDBG (bjnp_dbg (LOG_DEBUG, "sanei_bjnp_find_devices: Select returned, time left %d.%d....\n", (int) timeout.tv_sec, (int) timeout.tv_usec)); for (i = 0; i < no_sockets; i++) { @@ -1894,17 +2026,18 @@ sanei_bjnp_find_devices (const char **conf_devices, &(scanner_sa.addr), &socklen ) ) == -1) { PDBG (bjnp_dbg - (LOG_INFO, "find_devices: no data received")); + (LOG_INFO, "sanei_find_devices: no data received")); break; } else { - PDBG (bjnp_dbg (LOG_DEBUG2, "Discover response:\n")); + PDBG (bjnp_dbg (LOG_DEBUG2, "sanei_find_devices: Discover response:\n")); PDBG (bjnp_hexdump (LOG_DEBUG2, &resp_buf, numbytes)); /* check if something sensible is returned */ + protocol_defs = get_protocol_by_proto_string(disc_resp-> response.BJNP_id); if ( (numbytes < (int)sizeof (struct BJNP_command)) || - (strncmp ("BJNP", disc_resp-> response.BJNP_id, 4) != 0)) + (protocol_defs == NULL)) { /* not a valid response, assume not a scanner */ @@ -1912,11 +2045,11 @@ sanei_bjnp_find_devices (const char **conf_devices, strncpy(bjnp_id, disc_resp-> response.BJNP_id, 4); bjnp_id[4] = '\0'; PDBG (bjnp_dbg (LOG_INFO, - "Invalid discover response! Length = %d, Id = %s\n", + "sanei_find_devices: Invalid discover response! Length = %d, Id = %s\n", numbytes, bjnp_id ) ); break; } - if ( ! ((disc_resp -> response.dev_type) & 0x80) ) + if ( !(disc_resp -> response.dev_type & 0x80) ) { /* not a response, a command from somebody else or */ /* a discover command that we generated */ @@ -1924,12 +2057,13 @@ sanei_bjnp_find_devices (const char **conf_devices, } }; + port = get_port_from_sa(scanner_sa); /* scanner found, get IP-address or hostname */ get_scanner_name( &scanner_sa, scanner_host); /* construct URI */ - sprintf (uri, "%s://%s:%d", BJNP_METHOD, scanner_host, - BJNP_PORT_SCAN); + sprintf (uri, "%s://%s:%d", protocol_defs->method_string, scanner_host, + port); add_scanner( &dev_no, uri, attach_bjnp, pixma_devices); @@ -1939,7 +2073,7 @@ sanei_bjnp_find_devices (const char **conf_devices, timeout.tv_sec = 0; timeout.tv_usec = BJNP_BC_RESPONSE_TIMEOUT * BJNP_USLEEP_MS; } - PDBG (bjnp_dbg (LOG_DEBUG, "scanner discovery finished...\n")); + PDBG (bjnp_dbg (LOG_DEBUG, "sanei_find_devices: scanner discovery finished...\n")); for (i = 0; i < no_sockets; i++) close (socket_fd[i]); @@ -1977,10 +2111,10 @@ sanei_bjnp_open (SANE_String_Const devname, SANE_Int * dn) PDBG (bjnp_dbg (LOG_INFO, "sanei_bjnp_open(%s, %d):\n", devname, *dn)); result = bjnp_allocate_device (devname, dn, NULL); - if ( (result != BJNP_STATUS_GOOD) && (result != BJNP_STATUS_ALREADY_ALLOCATED ) ) + if ( (result != BJNP_STATUS_GOOD) && (result != BJNP_STATUS_ALREADY_ALLOCATED ) ) { return SANE_STATUS_INVAL; - - return sanei_bjnp_activate( *dn);; + } + return SANE_STATUS_GOOD; } /** Close a BJNP device. @@ -1992,8 +2126,9 @@ void sanei_bjnp_close (SANE_Int dn) { PDBG (bjnp_dbg (LOG_INFO, "sanei_bjnp_close(%d):\n", dn)); - sanei_bjnp_deactivate(dn); + device[dn].open = 0; + sanei_bjnp_deactivate(dn); } /** Activate BJNP device connection @@ -2008,7 +2143,6 @@ sanei_bjnp_activate (SANE_Int dn) char pid_str[64]; PDBG (bjnp_dbg (LOG_INFO, "sanei_bjnp_activate (%d)\n", dn)); - gethostname (hostname, 256); hostname[255] = '\0'; sprintf (pid_str, "Process ID = %d", getpid ()); @@ -2032,11 +2166,9 @@ SANE_Status sanei_bjnp_deactivate (SANE_Int dn) { PDBG (bjnp_dbg (LOG_INFO, "sanei_bjnp_deactivate (%d)\n", dn)); - - bjnp_finish_job (dn); - if ( device[dn].tcp_socket != -1) { + bjnp_finish_job (dn); close (device[dn].tcp_socket); device[dn].tcp_socket = -1; } @@ -2079,12 +2211,13 @@ sanei_bjnp_read_bulk (SANE_Int dn, SANE_Byte * buffer, size_t * size) SANE_Status result; SANE_Status error; size_t recvd; - size_t more; + size_t read_size; + size_t read_size_max; size_t requested; PDBG (bjnp_dbg - (LOG_INFO, "bjnp_read_bulk(%d, bufferptr, 0x%lx = %ld)\n", dn, - (unsigned long) *size, (unsigned long) *size)); + (LOG_INFO, "bjnp_read_bulk(dn=%d, bufferptr=%lx, 0x%lx = %ld)\n", dn, + (long) buffer, (unsigned long) *size, (unsigned long) *size)); recvd = 0; requested = *size; @@ -2095,20 +2228,21 @@ sanei_bjnp_read_bulk (SANE_Int dn, SANE_Byte * buffer, size_t * size) (unsigned long) device[dn].scanner_data_left ) ); while ( (recvd < requested) && !( device[dn].last_block && (device[dn].scanner_data_left == 0)) ) - { PDBG (bjnp_dbg (LOG_DEBUG, - "Received 0x%lx = %ld bytes, backend requested 0x%lx = %ld bytes\n", + "bjnp_read_bulk: Already received 0x%lx = %ld bytes, backend requested 0x%lx = %ld bytes\n", (unsigned long) recvd, (unsigned long) recvd, (unsigned long) requested, (unsigned long)requested )); + /* Check first if there is data in flight from the scanner */ + if (device[dn].scanner_data_left == 0) { - /* send new read request */ + /* There is no data in flight from the scanner, send new read request */ PDBG (bjnp_dbg (LOG_DEBUG, - "No (more) scanner data available, requesting more( blocksize = %ld =%lx\n", + "bjnp_read_bulk: No (more) scanner data available, requesting more( blocksize = %ld = %lx\n", (long int) device[dn].blocksize, (long int) device[dn].blocksize )); if ((error = bjnp_send_read_request (dn)) != SANE_STATUS_GOOD) @@ -2133,43 +2267,40 @@ sanei_bjnp_read_bulk (SANE_Int dn, SANE_Byte * buffer, size_t * size) device[dn].last_block = 1; } - if ( device[dn].scanner_data_left == 0 ) - { - break; - } } - PDBG (bjnp_dbg (LOG_DEBUG, "Scanner reports 0x%lx = %ld bytes available\n", + PDBG (bjnp_dbg (LOG_DEBUG, "bjnp_read_bulk: In flight: 0x%lx = %ld bytes available\n", (unsigned long) device[dn].scanner_data_left, (unsigned long) device[dn].scanner_data_left)); - /* read as many bytes as needed and available */ + /* read as many bytes as needed and available */ - more = MIN( device[dn].scanner_data_left, (requested - recvd) ); + read_size_max = MIN( device[dn].scanner_data_left, (requested - recvd) ); + read_size = read_size_max; PDBG (bjnp_dbg (LOG_DEBUG, - "reading 0x%lx = %ld (of max 0x%lx = %ld) bytes\n", - (unsigned long) more, - (unsigned long) more, + "bjnp_read_bulk: Try to read 0x%lx = %ld (of max 0x%lx = %ld) bytes\n", + (unsigned long) read_size_max, + (unsigned long) read_size_max, (unsigned long) device[dn].scanner_data_left, (unsigned long) device[dn].scanner_data_left) ); - result = bjnp_recv_data (dn, buffer + recvd, &more); + result = bjnp_recv_data (dn, buffer , recvd, &read_size); if (result != SANE_STATUS_GOOD) { *size = recvd; return SANE_STATUS_IO_ERROR; } - PDBG (bjnp_dbg (LOG_DEBUG, "Requested %ld bytes, received: %ld\n", - MIN( device[dn].scanner_data_left, (requested - recvd) ), more) ); + PDBG (bjnp_dbg (LOG_DEBUG, "bjnp_read_bulk: Expected at most %ld bytes, received this time: %ld\n", + read_size_max, read_size) ); - device[dn].scanner_data_left = device[dn].scanner_data_left - more; - recvd = recvd + more; + device[dn].scanner_data_left = device[dn].scanner_data_left - read_size; + recvd = recvd + read_size; } - PDBG (bjnp_dbg (LOG_DEBUG, "returning %ld bytes, backend expexts %ld\n", - recvd, *size ) ); + PDBG (bjnp_dbg (LOG_DEBUG, "bjnp_read_bulk: %s: Returning %ld bytes, backend expexts %ld\n", + (recvd == *size)? "OK": "NOTICE",recvd, *size ) ); *size = recvd; if ( *size == 0 ) return SANE_STATUS_EOF; @@ -2199,51 +2330,50 @@ sanei_bjnp_write_bulk (SANE_Int dn, const SANE_Byte * buffer, size_t * size) uint32_t buf; size_t payload_size; - PDBG (bjnp_dbg - (LOG_INFO, "bjnp_write_bulk(%d, bufferptr, 0x%lx = %ld)\n", dn, - (unsigned long) *size, (unsigned long) *size)); + /* Write received data to scanner */ + sent = bjnp_write (dn, buffer, *size); if (sent < 0) return SANE_STATUS_IO_ERROR; if (sent != (int) *size) { PDBG (bjnp_dbg - (LOG_CRIT, "Sent only %ld bytes to scanner, expected %ld!!\n", + (LOG_CRIT, "sanei_bjnp_write_bulk: ERROR - Sent only %ld bytes to scanner, expected %ld!!\n", (unsigned long) sent, (unsigned long) *size)); return SANE_STATUS_IO_ERROR; } if (bjnp_recv_header (dn, &payload_size) != SANE_STATUS_GOOD) { - PDBG (bjnp_dbg (LOG_CRIT, "Could not read response to command!\n")); + PDBG (bjnp_dbg (LOG_CRIT, "sanei_bjnp_write_bulk: ERROR - Could not read response to command!\n")); return SANE_STATUS_IO_ERROR; } if (payload_size != 4) { PDBG (bjnp_dbg (LOG_CRIT, - "Scanner length of write confirmation = 0x%lx bytes = %ld, expected %d!!\n", + "sanei_bjnp_write_bulk: ERROR - Scanner length of write confirmation = 0x%lx bytes = %ld, expected %d!!\n", (unsigned long) payload_size, (unsigned long) payload_size, 4)); return SANE_STATUS_IO_ERROR; } recvd = payload_size; - if ((bjnp_recv_data (dn, (unsigned char *) &buf, &recvd) != + if ((bjnp_recv_data (dn, (unsigned char *) &buf, 0, &recvd) != SANE_STATUS_GOOD) || (recvd != payload_size)) { PDBG (bjnp_dbg (LOG_CRIT, - "Could not read length of data confirmed by device\n")); + "sanei_bjnp_write_bulk: ERROR - Could not read length of data confirmed by device\n")); return SANE_STATUS_IO_ERROR; } recvd = ntohl (buf); if (recvd != *size) { PDBG (bjnp_dbg - (LOG_CRIT, "Scanner confirmed %ld bytes, expected %ld!!\n", + (LOG_CRIT, "sanei_bjnp_write_bulk: ERROR - Scanner confirmed %ld bytes, expected %ld!!\n", (unsigned long) recvd, (unsigned long) *size)); return SANE_STATUS_IO_ERROR; } - /* we can expect data from the scanner again */ + /* we can expect data from the scanner */ device[dn].last_block = 0; @@ -2304,13 +2434,15 @@ sanei_bjnp_read_int (SANE_Int dn, SANE_Byte * buffer, size_t * size) if ( (bjnp_poll_scanner (dn, 0, hostname, getusername (), buffer, *size ) != 0) || (bjnp_poll_scanner (dn, 1, hostname, getusername (), buffer, *size ) != 0) ) { - PDBG (bjnp_dbg (LOG_NOTICE, "Failed to setup read_intr dialog with device!\n")); + PDBG (bjnp_dbg (LOG_NOTICE, "bjnp_read_int: WARNING - Failed to setup read_intr dialog with device!\n")); device[dn].dialog = 0; device[dn].status_key = 0; return SANE_STATUS_IO_ERROR; } device[dn].polling_status = BJNP_POLL_STARTED; + /* fall through to BJNP_POLL_STARTED */ + case BJNP_POLL_STARTED: /* we use only seonds accuracy between poll attempts */ timeout = device[dn].bjnp_timeout /1000; @@ -2319,7 +2451,7 @@ sanei_bjnp_read_int (SANE_Int dn, SANE_Byte * buffer, size_t * size) { if ( (resp_len = bjnp_poll_scanner (dn, 2, hostname, getusername (), buffer, *size ) ) < 0 ) { - PDBG (bjnp_dbg (LOG_NOTICE, "Restarting polling dialog!\n")); + PDBG (bjnp_dbg (LOG_NOTICE, "bjnp_read_int: Restarting polling dialog!\n")); device[dn].polling_status = BJNP_POLL_STOPPED; *size = 0; return SANE_STATUS_EOF; @@ -2332,8 +2464,11 @@ sanei_bjnp_read_int (SANE_Int dn, SANE_Byte * buffer, size_t * size) /* this is a bit of a hack, but the scanner does not like */ /* us to continue using the existing tcp socket */ + /* No longer required? Does not work anymore now we moved code from sanei_bjnp_activate/sanei_bjnp_deactivate + to the isanei_bjnp_open and sanei_bjnp_close sanei_bjnp_deactivate(dn); sanei_bjnp_activate(dn); + */ return SANE_STATUS_GOOD; } @@ -2345,7 +2480,7 @@ sanei_bjnp_read_int (SANE_Int dn, SANE_Byte * buffer, size_t * size) case BJNP_POLL_STATUS_RECEIVED: if ( (resp_len = bjnp_poll_scanner (dn, 5, hostname, getusername (), buffer, *size ) ) < 0 ) { - PDBG (bjnp_dbg (LOG_NOTICE, "Restarting polling dialog!\n")); + PDBG (bjnp_dbg (LOG_NOTICE, "bjnp_read_int: Restarting polling dialog!\n")); device[dn].polling_status = BJNP_POLL_STOPPED; *size = 0; break; diff --git a/backend/pixma_bjnp.h b/backend/pixma_bjnp.h index e2939d7..3770bfd 100644 --- a/backend/pixma_bjnp.h +++ b/backend/pixma_bjnp.h @@ -96,7 +96,7 @@ sanei_bjnp_find_devices (const char **conf_devices, * Where: * method = bjnp * hostname = resolvable name or IP-address - * port = 8612 for a scanner + * port = 8612 for a bjnp scanner, 8610 for a mfnp device * An example could look like this: bjnp://host.domain:8612 * * @param devname name of the device to open diff --git a/backend/pixma_bjnp_private.h b/backend/pixma_bjnp_private.h index 859baa5..1902c7a 100644 --- a/backend/pixma_bjnp_private.h +++ b/backend/pixma_bjnp_private.h @@ -75,6 +75,7 @@ #define BJNP_SERIAL_MAX 16 /* maximum length of serial number */ #define BJNP_NO_DEVICES 16 /* max number of open devices */ #define BJNP_SCAN_BUF_MAX 65536 /* size of scanner data intermediate buffer */ +#define BJNP_BLOCKSIZE_START 512 /* startsize for last block detection */ /* timers */ #define BJNP_BROADCAST_INTERVAL 10 /* ms between broadcasts */ @@ -109,15 +110,34 @@ /* port numbers */ typedef enum bjnp_port_e { - BJNP_PORT_BROADCAST_BASE = 8610, + MFNP_PORT_SCAN = 8610, BJNP_PORT_PRINT = 8611, BJNP_PORT_SCAN = 8612, BJNP_PORT_3 = 8613, BJNP_PORT_4 = 8614 } bjnp_port_t; -#define BJNP_METHOD "bjnp" -#define BJNP_STRING "BJNP" +typedef enum +{ + PROTOCOL_BJNP = 0, + PROTOCOL_MFNP = 1, + PROTOCOL_NONE =2 +} bjnp_protocol_t; + +typedef struct +{ + bjnp_protocol_t protocol_version; + int default_port; + char * proto_string; + char * method_string; +} bjnp_protocol_defs_t; + +bjnp_protocol_defs_t bjnp_protocol_defs[] = +{ + {PROTOCOL_BJNP, BJNP_PORT_SCAN,"BJNP", "bjnp"}, + {PROTOCOL_MFNP, MFNP_PORT_SCAN,"MFNP", "mfnp"}, + {PROTOCOL_NONE, -1, NULL, NULL} +}; /* commands */ typedef enum bjnp_cmd_e @@ -168,7 +188,7 @@ struct __attribute__ ((__packed__)) DISCOVER_RESPONSE struct BJNP_command response; /* reponse header */ char unknown1[4]; /* 00 01 08 00 */ char mac_len; /* length of mac address */ - char addr_len; /* length od address field */ + char addr_len; /* length of address field */ unsigned char mac_addr[6]; /* printers mac address */ union { struct __attribute__ ((__packed__)) { @@ -251,8 +271,18 @@ struct __attribute__ ((__packed__)) POLL_RESPONSE struct __attribute__ ((__packed__)) IDENTITY { struct BJNP_command cmd; - uint16_t id_len; /* length of identity */ - char id[BJNP_IEEE1284_MAX]; /* identity */ + union __attribute__ ((__packed__)) + { + struct __attribute__ ((__packed__)) payload_s + { + uint16_t id_len; /* length of identity */ + char id[BJNP_IEEE1284_MAX]; /* identity */ + } bjnp; + struct __attribute__ ((__packed__)) mfnp + { + char id[BJNP_IEEE1284_MAX]; + } mfnp; + } payload; }; @@ -314,6 +344,10 @@ typedef enum typedef struct device_s { int open; /* connection to scanner is opened */ + + /* protocol version */ + int protocol; + char *protocol_string; /* sockets */ diff --git a/backend/pixma_common.c b/backend/pixma_common.c index b417d07..9d41f7a 100644 --- a/backend/pixma_common.c +++ b/backend/pixma_common.c @@ -1,8 +1,8 @@ /* SANE - Scanner Access Now Easy. + Copyright (C) 2011-2015 Rolf Bensch <rolf at bensch hyphen online dot de> Copyright (C) 2007-2008 Nicolas Martin, <nicols-guest at alioth dot debian dot org> Copyright (C) 2006-2007 Wittawat Yamwong <wittawat@web.de> - Copyright (C) 2011-2013 Rolf Bensch <rolf at bensch hyphen online dot de> This file is part of the SANE package. @@ -318,7 +318,7 @@ pixma_get_time (time_t * sec, uint32_t * usec) uint8_t * pixma_r_to_ir (uint8_t * gptr, uint8_t * sptr, unsigned w, unsigned c) { - unsigned i, j, g; + unsigned i; /* PDBG (pixma_dbg (4, "*pixma_rgb_to_ir*****\n")); */ @@ -383,7 +383,7 @@ pixma_binarize_line(pixma_scan_param_t * sp, uint8_t * dst, uint8_t * src, unsig unsigned char mask; uint8_t min, max; - /* PDBG (pixma_dbg (4, "*pixma_binarize_line***** src = %u, dst = %u, width = %u, c = %u, threshold = %u, thershold_curve = %u *****\n", + /* PDBG (pixma_dbg (4, "*pixma_binarize_line***** src = %u, dst = %u, width = %u, c = %u, threshold = %u, threshold_curve = %u *****\n", src, dst, width, c, sp->threshold, sp->threshold_curve)); */ /* 16 bit grayscale not supported */ @@ -655,7 +655,10 @@ pixma_cmd_transaction (pixma_t * s, const void *cmd, unsigned cmdlen, { error = pixma_read (s->io, data, expected_len); if (error == PIXMA_ETIMEDOUT) + { PDBG (pixma_dbg (2, "No response yet. Timed out in %d sec.\n", tmo)); + pixma_sleep (1000000); /* 1s timeout */ + } } while (error == PIXMA_ETIMEDOUT && --tmo != 0); if (error < 0) @@ -1048,9 +1051,11 @@ pixma_check_scan_param (pixma_t * s, pixma_scan_param_t * sp) if (s->ops->check_param (s, sp) < 0) return PIXMA_EINVAL; - /* FIXME: I assume the same minimum width and height for every model. */ - CLAMP2 (sp->x, sp->w, 13, s->cfg->width, sp->xdpi); - CLAMP2 (sp->y, sp->h, 8, s->cfg->height, sp->ydpi); + /* FIXME: I assume the same minimum width and height for every model. + * new scanners need minimum 16 px height + * minimum image size: 16 px x 16 px */ + CLAMP2 (sp->x, sp->w, 16, s->cfg->width, sp->xdpi); + CLAMP2 (sp->y, sp->h, 16, s->cfg->height, sp->ydpi); switch (sp->source) { diff --git a/backend/pixma_common.h b/backend/pixma_common.h index 86d459f..dbaa23f 100644 --- a/backend/pixma_common.h +++ b/backend/pixma_common.h @@ -1,7 +1,7 @@ /* SANE - Scanner Access Now Easy. + Copyright (C) 2011-2015 Rolf Bensch <rolf at bensch hyphen online dot de> Copyright (C) 2006-2007 Wittawat Yamwong <wittawat@web.de> - Copyright (C) 2011-2013 Rolf Bensch <rolf at bensch hyphen online dot de> This file is part of the SANE package. @@ -147,7 +147,7 @@ struct pixma_scan_ops_t * -# Fill the buffer pointed by ib->wptr directly and leave * ib->rptr and ib->rend untouched. The length of the buffer is * ib->wend - ib->wptr. It must update ib->wptr accordingly. - * -# Update ib->rptr and ib->rend to point to the the beginning and + * -# Update ib->rptr and ib->rend to point to the beginning and * the end of the internal buffer resp. The length of the buffer * is ib->rend - ib->rptr. This function is called again if * and only if pixma_read_image() has copied the whole buffer. diff --git a/backend/pixma_imageclass.c b/backend/pixma_imageclass.c index c0287a3..b2d45ee 100644 --- a/backend/pixma_imageclass.c +++ b/backend/pixma_imageclass.c @@ -1,8 +1,8 @@ /* SANE - Scanner Access Now Easy. + Copyright (C) 2011-2015 Rolf Bensch <rolf at bensch hyphen online dot de> Copyright (C) 2007-2009 Nicolas Martin, <nicols-guest at alioth dot debian dot org> Copyright (C) 2008 Dennis Lou, dlou 99 at yahoo dot com - Copyright (C) 2011-2013 Rolf Bensch <rolf at bensch hyphen online dot de> This file is part of the SANE package. @@ -64,24 +64,30 @@ # define UNUSED(v) #endif -#define IMAGE_BLOCK_SIZE (0xffff) +#define IMAGE_BLOCK_SIZE (0x80000) #define MAX_CHUNK_SIZE (0x1000) #define MIN_CHUNK_SIZE (0x0200) #define CMDBUF_SIZE 512 -#define MF4200_PID 0x26b5 #define MF4100_PID 0x26a3 #define MF4600_PID 0x26b0 #define MF4010_PID 0x26b4 +#define MF4200_PID 0x26b5 #define MF4360_PID 0x26ec #define D480_PID 0x26ed #define MF4320_PID 0x26ee #define D420_PID 0x26ef #define MF3200_PID 0x2684 #define MF6500_PID 0x2686 +/* generation 2 scanners (>=0x2707) */ +#define MF8300_PID 0x2708 +#define MF4500_PID 0x2736 #define MF4410_PID 0x2737 #define MF3010_PID 0x2759 -#define MF4770_PID 0x2774 +#define MF4570_PID 0x275a +#define MF4800_PID 0x2773 +#define MF4700_PID 0x2774 +#define MF8200_PID 0x2779 /* the following are all untested */ #define MF5630_PID 0x264e #define MF5650_PID 0x264f @@ -89,9 +95,14 @@ #define MF5880_PID 0x26f9 #define MF6680_PID 0x26fa #define MF8030_PID 0x2707 -#define MF4550_PID 0x2736 -#define MF4570_PID 0x275a #define IR1133_PID 0x2742 +#define MF5900_PID 0x2743 +#define D530_PID 0x2775 +#define MF8500_PID 0x277a +#define MF6100_PID 0x278e +#define MF820_PID 0x27a6 +#define MF220_PID 0x27a8 +#define MF210_PID 0x27a9 enum iclass_state_t @@ -198,6 +209,7 @@ activate (pixma_t * s, uint8_t x) case D420_PID: case MF4360_PID: case MF4100_PID: + case MF8300_PID: return iclass_exec (s, &mf->cb, 1); break; default: @@ -229,6 +241,7 @@ select_source (pixma_t * s) case D420_PID: case MF4360_PID: case MF4100_PID: + case MF8300_PID: return iclass_exec (s, &mf->cb, 0); break; default: @@ -263,6 +276,7 @@ send_scan_param (pixma_t * s) case D420_PID: case MF4360_PID: case MF4100_PID: + case MF8300_PID: return iclass_exec (s, &mf->cb, 0); break; default: @@ -280,16 +294,10 @@ request_image_block (pixma_t * s, unsigned flag, uint8_t * info, const int hlen = 2 + 6; memset (mf->cb.buf, 0, 11); - pixma_set_be16 (((s->cfg->pid == MF3010_PID || - s->cfg->pid == MF4410_PID || - s->cfg->pid == MF4770_PID || - s->cfg->pid == MF4550_PID) ? cmd_read_image2 : cmd_read_image), mf->cb.buf); + pixma_set_be16 (((mf->generation >= 2) ? cmd_read_image2 : cmd_read_image), mf->cb.buf); mf->cb.buf[8] = flag; mf->cb.buf[10] = 0x06; - expected_len = (s->cfg->pid == MF3010_PID || - s->cfg->pid == MF4410_PID || - s->cfg->pid == MF4770_PID || - s->cfg->pid == MF4550_PID || + expected_len = (mf->generation >= 2 || s->cfg->pid == MF4600_PID || s->cfg->pid == MF6500_PID || s->cfg->pid == MF8030_PID) ? 512 : hlen; @@ -300,10 +308,7 @@ request_image_block (pixma_t * s, unsigned flag, uint8_t * info, *size = pixma_get_be16 (mf->cb.buf + 6); /* 16bit size */ error = 0; - if (s->cfg->pid == MF3010_PID || - s->cfg->pid == MF4410_PID || - s->cfg->pid == MF4770_PID || - s->cfg->pid == MF4550_PID || + if (mf->generation >= 2 || s->cfg->pid == MF4600_PID || s->cfg->pid == MF6500_PID || s->cfg->pid == MF8030_PID) @@ -312,6 +317,7 @@ request_image_block (pixma_t * s, unsigned flag, uint8_t * info, *size = (*datalen + hlen == 512) ? pixma_get_be32 (mf->cb.buf + 4) - *datalen : 0; memcpy (data, mf->cb.buf + hlen, *datalen); } + PDBG (pixma_dbg (11, "*request_image_block***** size = %u *****\n", *size)); } else { @@ -323,13 +329,11 @@ request_image_block (pixma_t * s, unsigned flag, uint8_t * info, static int read_image_block (pixma_t * s, uint8_t * data, unsigned size) { + iclass_t *mf = (iclass_t *) s->subdriver; int error; unsigned maxchunksize, chunksize, count = 0; - maxchunksize = MAX_CHUNK_SIZE * ((s->cfg->pid == MF3010_PID || - s->cfg->pid == MF4410_PID || - s->cfg->pid == MF4770_PID || - s->cfg->pid == MF4550_PID || + maxchunksize = MAX_CHUNK_SIZE * ((mf->generation >= 2 || s->cfg->pid == MF4600_PID || s->cfg->pid == MF6500_PID || s->cfg->pid == MF8030_PID) ? 4 : 1); @@ -369,6 +373,7 @@ read_error_info (pixma_t * s, void *buf, unsigned size) case D420_PID: case MF4360_PID: case MF4100_PID: + case MF8300_PID: error = iclass_exec (s, &mf->cb, 0); break; default: @@ -513,8 +518,8 @@ iclass_check_param (pixma_t * s, pixma_scan_param_t * sp) /* Some exceptions here for particular devices */ /* Those devices can scan up to Legal 14" with ADF, but A4 11.7" in flatbed */ - if (sp->source == PIXMA_SOURCE_FLATBED - && ( s->cfg->pid == MF4770_PID )) + /* PIXMA_CAP_ADF also works for PIXMA_CAP_ADFDUP */ + if ((s->cfg->cap & PIXMA_CAP_ADF) && sp->source == PIXMA_SOURCE_FLATBED) sp->h = MIN (sp->h, 877 * sp->xdpi / 75); return 0; @@ -651,10 +656,7 @@ iclass_fill_buffer (pixma_t * s, pixma_imagebuf_t * ib) if (n != 0) { if (s->param->channels != 1 && - s->cfg->pid != MF3010_PID && - s->cfg->pid != MF4410_PID && - s->cfg->pid != MF4770_PID && - s->cfg->pid != MF4550_PID && + mf->generation == 1 && s->cfg->pid != MF4600_PID && s->cfg->pid != MF6500_PID && s->cfg->pid != MF8030_PID) @@ -706,10 +708,15 @@ iclass_finish_scan (pixma_t * s) activate (s, 0); query_status (s); } - /* 0x38 = last block and ADF empty - * 0x28 = last block and Paper in ADF */ - if (mf->last_block==0x38 /* ADF empty */ - || (mf->generation == 1 && mf->last_block == 0x28)) /* generation 1 scanner or Paper in ADF */ + /* generation = 1: + * 0x28 = last block (no multi page scan) + * generation >= 2: + * 0x38 = last block and ADF empty (generation >= 2) + * 0x28 = last block and Paper in ADF (multi page scan) + * some generation 2 scanners don't use 0x38 for ADF empty => check status */ + if (mf->last_block==0x38 /* generation 2 scanner ADF empty */ + || (mf->generation == 1 && mf->last_block == 0x28) /* generation 1 scanner last block */ + || (mf->generation >= 2 && !has_paper(s))) /* check status: no paper in ADF */ { PDBG (pixma_dbg (3, "*iclass_finish_scan***** abort session *****\n")); abort_session (s); @@ -759,41 +766,52 @@ static const pixma_scan_ops_t pixma_iclass_ops = { iclass_get_status }; -#define DEV(name, model, pid, dpi, w, h, cap) { \ +#define DEV(name, model, pid, dpi, adftpu_max_dpi, w, h, cap) { \ name, /* name */ \ model, /* model */ \ 0x04a9, pid, /* vid pid */ \ 1, /* iface */ \ &pixma_iclass_ops, /* ops */ \ dpi, dpi, /* xdpi, ydpi */ \ - 0, 0, /* adftpu_min_dpi & adftpu_max_dpi not used in this subdriver */ \ + 0, /* adftpu_min_dpi not used in this subdriver */ \ + adftpu_max_dpi, /* adftpu_max_dpi */ \ 0, 0, /* tpuir_min_dpi & tpuir_max_dpi not used in this subdriver */ \ w, h, /* width, height */ \ PIXMA_CAP_GRAY|PIXMA_CAP_EVENTS|cap \ } const pixma_config_t pixma_iclass_devices[] = { - DEV ("Canon imageCLASS MF4270", "MF4270", MF4200_PID, 600, 640, 877, PIXMA_CAP_ADF), - DEV ("Canon imageCLASS MF4150", "MF4100", MF4100_PID, 600, 640, 877, PIXMA_CAP_ADF), - DEV ("Canon imageCLASS MF4690", "MF4690", MF4600_PID, 600, 640, 877, PIXMA_CAP_ADF), - DEV ("Canon imageCLASS D420", "D420", D420_PID, 600, 640, 877, PIXMA_CAP_ADFDUP), - DEV ("Canon imageCLASS D480", "D480", D480_PID, 600, 640, 877, PIXMA_CAP_ADFDUP), - DEV ("Canon imageCLASS MF4360", "MF4360", MF4360_PID, 600, 640, 877, PIXMA_CAP_ADFDUP), - DEV ("Canon imageCLASS MF4320", "MF4320", MF4320_PID, 600, 640, 877, PIXMA_CAP_ADF), - DEV ("Canon imageCLASS MF4010", "MF4010", MF4010_PID, 600, 640, 877, 0), - DEV ("Canon imageCLASS MF3240", "MF3240", MF3200_PID, 600, 640, 877, 0), - DEV ("Canon imageClass MF6500", "MF6500", MF6500_PID, 600, 640, 877, PIXMA_CAP_ADF), - DEV ("Canon imageCLASS MF4410", "MF4410", MF4410_PID, 600, 640, 877, PIXMA_CAP_ADF), - DEV ("Canon i-SENSYS MF4550d", "MF4550", MF4550_PID, 600, 640, 877, PIXMA_CAP_ADF), - DEV ("Canon i-SENSYS MF3010", "MF3010", MF3010_PID, 600, 640, 877, 0), - DEV ("Canon imageCLASS MF4770n", "MF4770", MF4770_PID, 600, 640, 1050, PIXMA_CAP_ADF), + DEV ("Canon imageCLASS MF4270", "MF4270", MF4200_PID, 600, 0, 640, 877, PIXMA_CAP_ADF), + DEV ("Canon imageCLASS MF4150", "MF4100", MF4100_PID, 600, 0, 640, 877, PIXMA_CAP_ADF), + DEV ("Canon imageCLASS MF4690", "MF4690", MF4600_PID, 600, 0, 640, 877, PIXMA_CAP_ADF), + DEV ("Canon imageCLASS D420", "D420", D420_PID, 600, 0, 640, 877, PIXMA_CAP_ADFDUP), + DEV ("Canon imageCLASS D480", "D480", D480_PID, 600, 0, 640, 877, PIXMA_CAP_ADFDUP), + DEV ("Canon imageCLASS MF4360", "MF4360", MF4360_PID, 600, 0, 640, 877, PIXMA_CAP_ADFDUP), + DEV ("Canon imageCLASS MF4320", "MF4320", MF4320_PID, 600, 0, 640, 877, PIXMA_CAP_ADF), + DEV ("Canon imageCLASS MF4010", "MF4010", MF4010_PID, 600, 0, 640, 877, 0), + DEV ("Canon imageCLASS MF3240", "MF3240", MF3200_PID, 600, 0, 640, 877, 0), + DEV ("Canon imageClass MF6500", "MF6500", MF6500_PID, 600, 0, 640, 877, PIXMA_CAP_ADF), + DEV ("Canon imageCLASS MF4410", "MF4410", MF4410_PID, 600, 0, 640, 877, PIXMA_CAP_ADF), + DEV ("Canon i-SENSYS MF4500 Series", "MF4500", MF4500_PID, 600, 0, 640, 877, PIXMA_CAP_ADF), + DEV ("Canon i-SENSYS MF3010", "MF3010", MF3010_PID, 600, 0, 640, 877, 0), + DEV ("Canon i-SENSYS MF4700 Series", "MF4700", MF4700_PID, 600, 0, 640, 1050, PIXMA_CAP_ADF), + DEV ("Canon i-SENSYS MF4800 Series", "MF4800", MF4800_PID, 600, 0, 640, 1050, PIXMA_CAP_ADF), + DEV ("Canon imageCLASS MF4570dw", "MF4570dw", MF4570_PID, 600, 0, 640, 877, 0), + 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), /* FIXME: the following capabilities all need updating/verifying */ - DEV ("Canon imageCLASS MF5630", "MF5630", MF5630_PID, 600, 640, 877, PIXMA_CAP_ADF), - DEV ("Canon laserBase MF5650", "MF5650", MF5650_PID, 600, 640, 877, PIXMA_CAP_ADF), - DEV ("Canon imageCLASS MF8170c", "MF8170c", MF8100_PID, 600, 640, 877, PIXMA_CAP_ADF), - DEV ("Canon imageClass MF8030", "MF8030", MF8030_PID, 600, 640, 877, PIXMA_CAP_ADF), - DEV ("Canon i-SENSYS MF5880dn", "MF5880", MF5880_PID, 600, 640, 877, PIXMA_CAP_ADFDUP), - DEV ("Canon i-SENSYS MF6680dn", "MF6680", MF6680_PID, 600, 640, 877, PIXMA_CAP_ADFDUP), - DEV ("Canon imageCLASS MF4570dw", "MF4570dw", MF4570_PID, 600, 640, 877, 0), - DEV ("Canon imageRUNNER 1133", "iR1133", IR1133_PID, 600, 637, 877, PIXMA_CAP_ADFDUP), - DEV (NULL, NULL, 0, 0, 0, 0, 0) + 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), + 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, 0, 640, 1050, PIXMA_CAP_ADFDUP), + DEV ("Canon imageClass MF810/820", "MF810/820", MF820_PID, 600, 0, 640, 1050, PIXMA_CAP_ADFDUP), + DEV ("Canon i-SENSYS MF220 Series", "MF220", MF220_PID, 600, 0, 640, 1050, PIXMA_CAP_ADFDUP), + DEV ("Canon i-SENSYS MF210 Series", "MF210", MF210_PID, 600, 0, 640, 1050, PIXMA_CAP_ADF), + DEV (NULL, NULL, 0, 0, 0, 0, 0, 0) }; diff --git a/backend/pixma_io_sanei.c b/backend/pixma_io_sanei.c index b25c7eb..9e4a2fa 100644 --- a/backend/pixma_io_sanei.c +++ b/backend/pixma_io_sanei.c @@ -1,8 +1,8 @@ /* SANE - Scanner Access Now Easy. * For limitations, see function sanei_usb_get_vendor_product(). + Copyright (C) 2011-2015 Rolf Bensch <rolf at bensch hyphen online dot de> Copyright (C) 2006-2007 Wittawat Yamwong <wittawat@web.de> - Copyright (C) 2011-2013 Rolf Bensch <rolf at bensch hyphen online dot de> This file is part of the SANE package. @@ -575,7 +575,8 @@ pixma_wait_interrupt (pixma_io_t * io, void *buf, unsigned size, int timeout) #endif error = map_error (sanei_usb_read_int (io->dev, buf, &count)); } - if (error == PIXMA_EIO || error == PIXMA_EOF) + if (error == PIXMA_EIO || + (io->interface == INT_BJNP && error == PIXMA_EOF)) /* EOF is a bjnp timeout error! */ error = PIXMA_ETIMEDOUT; /* FIXME: SANE doesn't have ETIMEDOUT!! */ if (error == 0) error = count; diff --git a/backend/pixma_mp150.c b/backend/pixma_mp150.c index e29dccd..4f8b232 100644 --- a/backend/pixma_mp150.c +++ b/backend/pixma_mp150.c @@ -1,8 +1,8 @@ /* SANE - Scanner Access Now Easy. + Copyright (C) 2011-2015 Rolf Bensch <rolf at bensch hyphen online dot de> Copyright (C) 2007-2009 Nicolas Martin, <nicols-guest at alioth dot debian dot org> Copyright (C) 2006-2007 Wittawat Yamwong <wittawat@web.de> - Copyright (C) 2011-2013 Rolf Bensch <rolf at bensch hyphen online dot de> This file is part of the SANE package. @@ -209,6 +209,26 @@ #define MG5500_PID 0x1771 #define MG7100_PID 0x1772 +/* 2014 new devices (untested) */ +#define MX470_PID 0x1774 +#define MX530_PID 0x1775 +#define MB5000_PID 0x1776 +#define MB5300_PID 0x1777 +#define MB2000_PID 0x1778 +#define MB2300_PID 0x1779 +#define E400_PID 0x177a +#define E560_PID 0x177b +#define MG7500_PID 0x177c +#define MG6600_PID 0x177e +#define MG5600_PID 0x177f +#define MG2900_PID 0x1780 +#define E460_PID 0x1788 + +/* 2015 new devices (untested) */ +#define MX490_PID 0x1787 +#define E480_PID 0x1789 +#define MG3600_PID 0x178a + /* Generation 4 XML messages that encapsulates the Pixma protocol messages */ #define XML_START_1 \ @@ -284,6 +304,7 @@ typedef struct mp150_t unsigned stripe_shift; uint8_t tpu_datalen; uint8_t tpu_data[0x40]; + uint8_t adf_state; /* handle adf scanning */ } mp150_t; /* @@ -420,7 +441,7 @@ is_calibrated (pixma_t * s) mp150_t *mp = (mp150_t *) s->subdriver; if (mp->generation >= 3) { - return ((mp->current_status[0] & 0x01) == 1); + return ((mp->current_status[0] & 0x01) == 1 || (mp->current_status[0] & 0x02) == 2); } if (mp->generation == 1) { @@ -454,6 +475,7 @@ static int abort_session (pixma_t * s) { mp150_t *mp = (mp150_t *) s->subdriver; + mp->adf_state = state_idle; /* reset adf scanning */ return pixma_exec_short_cmd (s, &mp->cb, cmd_abort_session); } @@ -630,10 +652,14 @@ calc_shifting (pixma_t * s) /* If stripes shift needed (CCD devices), how many pixels shift */ mp->stripe_shift = 0; + /* If color plane shift (CCD devices), how many pixels shift */ + mp->color_shift = mp->shift[0] = mp->shift[1] = mp->shift[2] = 0; + switch (s->cfg->pid) { case MP800_PID: case MP800R_PID: + case MP830_PID: if (s->param->xdpi == 2400) { if (is_scanning_from_tpu(s)) @@ -641,35 +667,15 @@ calc_shifting (pixma_t * s) else mp->stripe_shift = 3; } - break; - - case MP830_PID: - if (s->param->xdpi == 2400) + if (s->param->ydpi > 75) { - if (is_scanning_from_tpu(s)) - mp->stripe_shift = 6; - else - mp->stripe_shift = 3; - } - break; - - default: /* Default, and all CIS devices */ - break; - } - /* If color plane shift (CCD devices), how many pixels shift */ - mp->color_shift = mp->shift[0] = mp->shift[1] = mp->shift[2] = 0; - if (s->param->ydpi > 75) - { - switch (s->cfg->pid) - { - case MP800_PID: - case MP800R_PID: - case MP830_PID: mp->color_shift = s->param->ydpi / ((s->param->ydpi < 1200) ? 150 : 75); if (is_scanning_from_tpu (s)) mp->color_shift = s->param->ydpi / 75; + /* If you're trying to decipher this color-shifting code, + the following line is where the magic is revealed. */ mp->shift[1] = mp->color_shift * get_cis_ccd_line_size (s); if (is_scanning_from_adf (s)) { /* ADF */ @@ -681,11 +687,11 @@ calc_shifting (pixma_t * s) mp->shift[0] = 2 * mp->shift[1]; mp->shift[2] = 0; } - break; + } + break; - default: - break; - } + default: /* Default, and all CIS devices */ + break; } return (2 * mp->color_shift + mp->stripe_shift); } @@ -940,7 +946,10 @@ handle_interrupt (pixma_t * s, int timeout) * rr: scan resolution * poll event with 'scanimage -A' */ if (s->cfg->pid == MG6200_PID - || s->cfg->pid == MG6300_PID) + || s->cfg->pid == MG6300_PID + || s->cfg->pid == MX520_PID + || s->cfg->pid == MX720_PID + || s->cfg->pid == MX920_PID) /* button no. in buf[7] * size in buf[10] 01=A4; 02=Letter; 08=10x15; 09=13x18; 0b=auto * format in buf[11] 01=JPEG; 02=TIFF; 03=PDF; 04=Kompakt-PDF @@ -1000,7 +1009,7 @@ static int wait_until_ready (pixma_t * s) { mp150_t *mp = (mp150_t *) s->subdriver; - int error, tmo = 60; + int error, tmo = 120; /* some scanners need a long timeout */ RET_IF_ERR ((mp->generation >= 3) ? query_status_3 (s) : query_status (s)); @@ -1135,11 +1144,19 @@ post_process_image_data (pixma_t * s, pixma_imagebuf_t * ib) && s->cfg->pid != MP220_PID && s->cfg->pid != MX360_PID && s->cfg->pid != MX370_PID + && s->cfg->pid != MX530_PID && s->cfg->pid != MX890_PID + && s->cfg->pid != MX720_PID + && s->cfg->pid != MX920_PID && s->cfg->pid != MG3100_PID + && s->cfg->pid != MG3500_PID && s->cfg->pid != MG2100_PID && s->cfg->pid != MG5300_PID - && s->cfg->pid != MG6300_PID) + && s->cfg->pid != MG5500_PID + && s->cfg->pid != MG6300_PID + && s->cfg->pid != MG6400_PID + && s->cfg->pid != MG7100_PID + && s->cfg->pid != MG7500_PID) reorder_pixels (mp->linebuf, sptr, c, n, m, s->param->wx, line_size); /* Crop line to selected borders */ @@ -1201,9 +1218,14 @@ mp150_open (pixma_t * s) if (s->cfg->pid == MP140_PID) mp->generation = 2; + PDBG (pixma_dbg (3, "*mp150_open***** This is a generation %d scanner. *****\n", mp->generation)); + /* TPU info data setup */ mp->tpu_datalen = 0; + /* adf scanning */ + mp->adf_state = state_idle; + if (mp->generation < 4) { query_status (s); @@ -1281,21 +1303,9 @@ mp150_check_param (pixma_t * s, pixma_scan_param_t * sp) /*PDBG (pixma_dbg (4, "*mp150_check_param***** Final scan width and line-size: %i, %i *****\n", sp->wx, sp->line_size));*/ /* Some exceptions here for particular devices */ - /* Those devices can scan up to 14" with ADF, but A4 11.7" in flatbed */ - if (( s->cfg->pid == MX850_PID || - s->cfg->pid == MX860_PID || - s->cfg->pid == MX870_PID || - s->cfg->pid == MX880_PID || - s->cfg->pid == MX320_PID || - s->cfg->pid == MX330_PID || - s->cfg->pid == MX340_PID || - s->cfg->pid == MX350_PID || - s->cfg->pid == MX360_PID || - s->cfg->pid == MX410_PID || - s->cfg->pid == MX420_PID || - s->cfg->pid == MX7600_PID ) - && - sp->source == PIXMA_SOURCE_FLATBED) + /* Those devices can scan up to legal 14" with ADF, but A4 11.7" in flatbed */ + /* PIXMA_CAP_ADF also works for PIXMA_CAP_ADFDUP */ + if ((s->cfg->cap & PIXMA_CAP_ADF) && sp->source == PIXMA_SOURCE_FLATBED) sp->h = MIN (sp->h, 877 * sp->xdpi / 75); if (sp->source == PIXMA_SOURCE_TPU) @@ -1349,7 +1359,8 @@ mp150_scan (pixma_t * s) return PIXMA_EBUSY; /* Generation 4: send XML dialog */ - if (mp->generation == 4 && s->param->adf_pageid == 0) + /* adf: first page or idle */ + if (mp->generation == 4 && mp->adf_state == state_idle) { if (!send_xml_dialog (s, XML_START_1)) return PIXMA_EPROTO; @@ -1367,15 +1378,38 @@ mp150_scan (pixma_t * s) { if ((error = query_status (s)) < 0) return error; + + /* wait for inserted paper + * timeout: 10 sec */ tmo = 10; while (!has_paper (s) && --tmo >= 0) { + if ((error = query_status (s)) < 0) + return error; WAIT_INTERRUPT (1000); PDBG (pixma_dbg (2, "No paper in ADF. Timed out in %d sec.\n", tmo)); } + + /* no paper inserted + * => abort session */ if (!has_paper (s)) + { + PDBG (pixma_dbg (4, "*mp150_scan***** no paper in ADF *****\n")); + error = abort_session (s); + if (error < 0) + return error; + + /* Generation 4: send XML dialog */ + /* adf: first page or idle */ + if (mp->generation == 4 && mp->adf_state == state_idle) + { + if (!send_xml_dialog (s, XML_END)) + return PIXMA_EPROTO; + } + return PIXMA_ENO_PAPER; + } } if (has_ccd_sensor (s) && (mp->generation <= 2)) @@ -1406,8 +1440,10 @@ mp150_scan (pixma_t * s) } tmo = 10; - if (s->param->adf_pageid == 0 || mp->generation <= 2) - { + /* adf: first page or idle */ + if (mp->generation <= 2 || mp->adf_state == state_idle) + { /* single sheet or first sheet from ADF */ + PDBG (pixma_dbg (4, "*mp150_scan***** start scanning *****\n")); error = start_session (s); while (error == PIXMA_EBUSY && --tmo >= 0) { @@ -1448,7 +1484,11 @@ mp150_scan (pixma_t * s) error = send_set_tpu_info (s); } else /* ADF pageid != 0 and gen3 or above */ + { /* next sheet from ADF */ + PDBG (pixma_dbg (4, "*mp150_scan***** scan next sheet from ADF *****\n")); pixma_sleep (1000000); + } + if ((error >= 0) || (mp->generation >= 3)) mp->state = state_warmup; @@ -1462,6 +1502,10 @@ mp150_scan (pixma_t * s) mp150_finish_scan (s); return error; } + + /* ADF scanning active */ + if (is_scanning_from_adf (s)) + mp->adf_state = state_scanning; return 0; } @@ -1495,9 +1539,13 @@ mp150_fill_buffer (pixma_t * s, pixma_imagebuf_t * ib) do { if (s->cancel) + { + PDBG (pixma_dbg (4, "*mp150_fill_buffer***** s->cancel *****\n")); return PIXMA_ECANCELED; + } if ((mp->last_block & 0x28) == 0x28) - { /* end of image */ + { /* end of image */ + PDBG (pixma_dbg (4, "*mp150_fill_buffer***** end of image *****\n")); mp->state = state_finished; return 0; } @@ -1506,6 +1554,8 @@ mp150_fill_buffer (pixma_t * s, pixma_imagebuf_t * ib) error = read_image_block (s, header, mp->imgbuf + mp->data_left_len); if (error < 0) { + PDBG (pixma_dbg (4, "*mp150_fill_buffer***** scanner error (%d): end scan *****\n", error)); + mp->last_block = 0x38; /* end scan in mp150_finish_scan() */ if (error == PIXMA_ECANCELED) { /* NOTE: I see this in traffic logs but I don't know its meaning. */ @@ -1569,6 +1619,7 @@ mp150_finish_scan (pixma_t * s) * abort_session and start_session between pages (last_block=0x28) */ if (mp->generation <= 2 || !is_scanning_from_adf (s) || mp->last_block == 0x38) { + PDBG (pixma_dbg (4, "*mp150_finish_scan***** abort session *****\n")); error = abort_session (s); /* FIXME: it probably doesn't work in duplex mode! */ if (error < 0) PDBG (pixma_dbg (1, "WARNING:abort_session() failed %d\n", error)); @@ -1580,6 +1631,9 @@ mp150_finish_scan (pixma_t * s) PDBG (pixma_dbg (1, "WARNING:XML_END dialog failed \n")); } } + else + PDBG (pixma_dbg (4, "*mp150_finish_scan***** wait for next page from ADF *****\n")); + mp->state = state_idle; /* fall through */ case state_idle: @@ -1669,8 +1723,8 @@ const pixma_config_t pixma_mp150_devices[] = { DEVICE ("Canon PIXMA MP610", "MP610", MP610_PID, 4800, 0, 0, 638, 877, PIXMA_CAP_CIS), DEVICE ("Canon PIXMA MX300", "MX300", MX300_PID, 600, 0, 0, 638, 877, PIXMA_CAP_CIS), - DEVICE ("Canon PIXMA MX310", "MX310", MX310_PID, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF), - DEVICE ("Canon PIXMA MX700", "MX700", MX700_PID, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF), + DEVICE ("Canon PIXMA MX310", "MX310", MX310_PID, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF), + DEVICE ("Canon PIXMA MX700", "MX700", MX700_PID, 2400, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF), DEVICE ("Canon PIXMA MX850", "MX850", MX850_PID, 2400, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADFDUP), DEVICE ("Canon PIXMA MX7600", "MX7600", MX7600_PID, 4800, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADFDUP), @@ -1699,7 +1753,7 @@ const pixma_config_t pixma_mp150_devices[] = { DEVICE ("Canon PIXMA MX360", "MX360", MX360_PID, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF), DEVICE ("Canon PIXMA MX410", "MX410", MX410_PID, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF), DEVICE ("Canon PIXMA MX420", "MX420", MX420_PID, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF), - DEVICE ("Canon PIXMA MX880 Series", "MX880", MX880_PID, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADFDUP), + DEVICE ("Canon PIXMA MX880 Series", "MX880", MX880_PID, 2400, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADFDUP), /* Generation 4: CIS */ DEVICE ("Canon PIXMA MP640", "MP640", MP640_PID, 4800, 0, 0, 638, 877, PIXMA_CAP_CIS), @@ -1726,27 +1780,27 @@ const pixma_config_t pixma_mp150_devices[] = { DEVICE ("Canon PIXMA E500", "E500", E500_PID, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), /* Latest devices (2012) Generation 4 CIS */ - DEVICE ("Canon PIXMA MX370 Series", "MX370", MX370_PID, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF), - DEVICE ("Canon PIXMA MX430 Series", "MX430", MX430_PID, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF), - DEVICE ("Canon PIXMA MX510 Series", "MX510", MX510_PID, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF), - DEVICE ("Canon PIXMA MX710 Series", "MX710", MX710_PID, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADFDUP), - DEVICE ("Canon PIXMA MX890 Series", "MX890", MX890_PID, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADFDUP), - DEVICE ("Canon PIXMA E600 Series", "E600", E600_PID, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF), + DEVICE ("Canon PIXMA MX370 Series", "MX370", MX370_PID, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF), + DEVICE ("Canon PIXMA MX430 Series", "MX430", MX430_PID, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF), + DEVICE ("Canon PIXMA MX510 Series", "MX510", MX510_PID, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF), + DEVICE ("Canon PIXMA MX710 Series", "MX710", MX710_PID, 2400, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADFDUP), + DEVICE ("Canon PIXMA MX890 Series", "MX890", MX890_PID, 2400, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADFDUP), + DEVICE ("Canon PIXMA E600 Series", "E600", E600_PID, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF), DEVICE ("Canon PIXMA MG4200", "MG4200", MG4200_PID, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), /* Latest devices (2013) Generation 4 CIS */ DEVICE ("Canon PIXMA E510", "E510", E510_PID, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), - DEVICE ("Canon PIXMA E610", "E610", E610_PID, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF), + DEVICE ("Canon PIXMA E610", "E610", E610_PID, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF), DEVICE ("Canon PIXMA MP230", "MP230", MP230_PID, 600, 0, 0, 638, 877, PIXMA_CAP_CIS), DEVICE ("Canon PIXMA MG2200 Series", "MG2200", MG2200_PID, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), DEVICE ("Canon PIXMA MG3200 Series", "MG3200", MG3200_PID, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), DEVICE ("Canon PIXMA MG5400 Series", "MG5400", MG5400_PID, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS), DEVICE ("Canon PIXMA MG6300 Series", "MG6300", MG6300_PID, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS), - DEVICE ("Canon PIXMA MX390 Series", "MX390", MX390_PID, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF), - DEVICE ("Canon PIXMA MX450 Series", "MX450", MX450_PID, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF), - DEVICE ("Canon PIXMA MX520 Series", "MX520", MX520_PID, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF), - DEVICE ("Canon PIXMA MX720 Series", "MX720", MX720_PID, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF), - DEVICE ("Canon PIXMA MX920 Series", "MX920", MX920_PID, 2400, 0, 600, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADFDUP), + DEVICE ("Canon PIXMA MX390 Series", "MX390", MX390_PID, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF), + DEVICE ("Canon PIXMA MX450 Series", "MX450", MX450_PID, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF), + DEVICE ("Canon PIXMA MX520 Series", "MX520", MX520_PID, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF), + DEVICE ("Canon PIXMA MX720 Series", "MX720", MX720_PID, 2400, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADFDUP), + DEVICE ("Canon PIXMA MX920 Series", "MX920", MX920_PID, 2400, 0, 600, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADFDUP), DEVICE ("Canon PIXMA MG2400 Series", "MG2400", MG2400_PID, 600, 0, 0, 638, 877, PIXMA_CAP_CIS), DEVICE ("Canon PIXMA MG2500 Series", "MG2500", MG2500_PID, 600, 0, 0, 638, 877, PIXMA_CAP_CIS), DEVICE ("Canon PIXMA MG3500 Series", "MG3500", MG3500_PID, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), @@ -1755,5 +1809,25 @@ const pixma_config_t pixma_mp150_devices[] = { DEVICE ("Canon PIXMA MG6500 Series", "MG6500", MG6500_PID, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS), DEVICE ("Canon PIXMA MG7100 Series", "MG7100", MG7100_PID, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS), + /* Latest devices (2014) Generation 4 CIS */ + DEVICE ("Canon PIXMA MX470 Series", "MX470", MX470_PID, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF), + DEVICE ("Canon PIXMA MX530 Series", "MX530", MX530_PID, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF), + DEVICE ("Canon MAXIFY MB5000 Series", "MB5000", MB5000_PID, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADFDUP), + DEVICE ("Canon MAXIFY MB5300 Series", "MB5300", MB5300_PID, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADFDUP), + DEVICE ("Canon MAXIFY MB2000 Series", "MB2000", MB2000_PID, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADFDUP), + DEVICE ("Canon MAXIFY MB2300 Series", "MB2300", MB2300_PID, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADFDUP), + DEVICE ("Canon PIXMA E400", "E400", E400_PID, 600, 0, 0, 638, 877, PIXMA_CAP_CIS), + DEVICE ("Canon PIXMA E560", "E560", E560_PID, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), + DEVICE ("Canon PIXMA MG7500 Series", "MG7500", MG7500_PID, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS), + DEVICE ("Canon PIXMA MG6600 Series", "MG6600", MG6600_PID, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), + DEVICE ("Canon PIXMA MG5600 Series", "MG5600", MG5600_PID, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), + DEVICE ("Canon PIXMA MG2900 Series", "MG2900", MG2900_PID, 600, 0, 0, 638, 877, PIXMA_CAP_CIS), + DEVICE ("Canon PIXMA E460 Series", "E460", E460_PID, 600, 0, 0, 638, 877, PIXMA_CAP_CIS), + + /* Latest devices (2015) Generation 4 CIS */ + DEVICE ("Canon PIXMA MX490 Series", "MX490", MX490_PID, 600, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF), + DEVICE ("Canon PIXMA E480 Series", "E480", E480_PID, 600, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADF), + DEVICE ("Canon PIXMA MG3600 Series", "MG3600", MG3600_PID, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), + END_OF_DEVICE_LIST }; diff --git a/backend/pixma_mp730.c b/backend/pixma_mp730.c index 1980fcc..2184ff7 100644 --- a/backend/pixma_mp730.c +++ b/backend/pixma_mp730.c @@ -1,8 +1,8 @@ /* SANE - Scanner Access Now Easy. + Copyright (C) 2011-2015 Rolf Bensch <rolf at bensch hyphen online dot de> Copyright (C) 2007-2008 Nicolas Martin, <nicols-guest at alioth dot debian dot org> Copyright (C) 2006-2007 Wittawat Yamwong <wittawat@web.de> - Copyright (C) 2011-2013 Rolf Bensch <rolf at bensch hyphen online dot de> This file is part of the SANE package. diff --git a/backend/pixma_mp750.c b/backend/pixma_mp750.c index ea35851..8d2d94c 100644 --- a/backend/pixma_mp750.c +++ b/backend/pixma_mp750.c @@ -1,7 +1,7 @@ /* SANE - Scanner Access Now Easy. + Copyright (C) 2011-2015 Rolf Bensch <rolf at bensch hyphen online dot de> Copyright (C) 2006-2007 Wittawat Yamwong <wittawat@web.de> - Copyright (C) 2011-2013 Rolf Bensch <rolf at bensch hyphen online dot de> This file is part of the SANE package. diff --git a/backend/pixma_mp810.c b/backend/pixma_mp810.c index 5b6cdfe..5f9043e 100644 --- a/backend/pixma_mp810.c +++ b/backend/pixma_mp810.c @@ -1,8 +1,8 @@ /* SANE - Scanner Access Now Easy. + Copyright (C) 2011-2015 Rolf Bensch <rolf at bensch hyphen online dot de> Copyright (C) 2007-2009 Nicolas Martin, <nicols-guest at alioth dot debian dot org> Copyright (C) 2006-2007 Wittawat Yamwong <wittawat@web.de> - Copyright (C) 2011-2013 Rolf Bensch <rolf at bensch hyphen online dot de> This file is part of the SANE package. @@ -657,6 +657,23 @@ static unsigned calc_shifting (pixma_t * s) } break; + case MP990_PID: + if (s->param->xdpi == 4800) + { + if (is_scanning_from_tpu (s)) + { + mp->stripe_shift = 6; + mp->stripe_shift2 = 6; + } + else + { + mp->stripe_shift = 3; + mp->stripe_shift2 = 3; + } + mp->jumplines = 34; /* better than 32 or 34 : applies to flatbed & TPU */ + } + break; + default: /* Default, and all CIS devices */ break; } @@ -850,7 +867,7 @@ static int send_scan_param (pixma_t * s) * 0x24 | 1 | all | 0x01 * -----+-------+---------+--------------------------- * 0x25 | 1 | default | 0x00; cs8800f: 0x01 - * | | tpu | 0x00; cs9000f, mg8200: 0x01 + * | | tpu | 0x00; cs9000f, mg8200, mp990: 0x01 * | | tpuir | cs9000f: 0x00 * -----+-------+---------+--------------------------- * ... | 1 | all | 0x00 @@ -908,8 +925,8 @@ static int send_scan_param (pixma_t * s) data[0x23] = 0x02; data[0x24] = 0x01; - /* MG8200 addition */ - if (s->cfg->pid == MG8200_PID) + /* MG8200 & MP990 addition */ + if (s->cfg->pid == MG8200_PID || s->cfg->pid == MP990_PID) { if (is_scanning_from_tpu (s)) { @@ -1691,7 +1708,8 @@ static unsigned post_process_image_data (pixma_t * s, pixma_imagebuf_t * ib) /* comment: MP970, CS8800F, CS9000F specific reordering for 4800 dpi */ if ((s->cfg->pid == MP970_PID || s->cfg->pid == CS8800F_PID - || s->cfg->pid == CS9000F_PID || s->cfg->pid == CS9000F_MII_PID) && (s->param->xdpi == 4800)) + || s->cfg->pid == CS9000F_PID || s->cfg->pid == CS9000F_MII_PID + || s->cfg->pid == MP990_PID) && (s->param->xdpi == 4800)) { /*PDBG (pixma_dbg (4, "*post_process_image_data***** mp970_reordering pixels n = %i *****\n", n)); */ mp970_reorder_pixels (mp->linebuf, sptr, c, s->param->wx, line_size); diff --git a/backend/plustek-pp_dac.c b/backend/plustek-pp_dac.c index dd35ce7..f89d814 100644 --- a/backend/plustek-pp_dac.c +++ b/backend/plustek-pp_dac.c @@ -338,7 +338,7 @@ static void dacP98SetInitialGainRegister( pScanData ps ) dacP98FillGainInitialRestRegister( ps );/* Model Control2, LED, Correct.*/ } -/** Find the the most ideal intensity for each color (RGB) +/** Find the most ideal intensity for each color (RGB) */ static void dacP98SetRGBGainRegister( pScanData ps ) { @@ -451,7 +451,7 @@ static void dacP98SetInitialGainRAM( pScanData ps ) dacP98DownloadMapTable( ps, ps->pScanBuffer1 ); } -/** Find the the most ideal intensity for each color (RGB) +/** Find the most ideal intensity for each color (RGB) */ static void dacP98AdjustRGBGain( pScanData ps ) { diff --git a/backend/plustek-pp_scan.h b/backend/plustek-pp_scan.h index 3b977bf..5a8f9d7 100644 --- a/backend/plustek-pp_scan.h +++ b/backend/plustek-pp_scan.h @@ -152,7 +152,7 @@ /* * WARNING - never use the _SECOND define with the _DODELAY macro !! - * they are for use the the MiscStartTimer function and the _DO_UDELAY macro + * they are for use the MiscStartTimer function and the _DO_UDELAY macro */ #ifndef __KERNEL__ typedef double TimerDef, *pTimerDef; diff --git a/backend/plustek-usbcalfile.c b/backend/plustek-usbcalfile.c index 5638b2e..afea3f9 100644 --- a/backend/plustek-usbcalfile.c +++ b/backend/plustek-usbcalfile.c @@ -89,7 +89,7 @@ typedef struct { static u_short a_wWhiteShading[_SHADING_BUF] = {0}; static u_short a_wDarkShading[_SHADING_BUF] = {0}; -/* the version the the calibration files */ +/* the version the calibration files */ #define _PT_CF_VERSION 0x0002 /** function to read a text file and returns the string which starts which diff --git a/backend/pnm.c b/backend/pnm.c index 88b6e4a..b8d3192 100644 --- a/backend/pnm.c +++ b/backend/pnm.c @@ -267,7 +267,7 @@ static SANE_Option_Descriptor sod[] = { SANE_I18N ("Hand-Scanner Simulation"), SANE_I18N ("Simulate a hand-scanner. Hand-scanners often do not know the " "image height a priori. Instead, they return a height of -1. " - "Setting this option allows to test whether a frontend can " + "Setting this option allows one to test whether a frontend can " "handle this correctly."), SANE_TYPE_BOOL, SANE_UNIT_NONE, diff --git a/backend/ricoh.c b/backend/ricoh.c index a349179..88f33d1 100644 --- a/backend/ricoh.c +++ b/backend/ricoh.c @@ -73,6 +73,7 @@ #define MAX(a,b) ((a) > (b) ? (a) : (b)) +static const SANE_Device **devlist = NULL; static int num_devices = 0; static Ricoh_Device *first_dev = NULL; static Ricoh_Scanner *first_handle = NULL; @@ -221,11 +222,13 @@ attach (const char *devnam, Ricoh_Device ** devp) dev->sane.name = strdup (devnam); dev->sane.vendor = "RICOH"; - str = malloc (16 + 1); - memset (str, 0, sizeof (str)); - strncpy (str, (char *)ibuf.product, sizeof(ibuf.product)); - strncpy (str + sizeof(ibuf.revision), (char *)ibuf.revision, sizeof(ibuf.revision)); - str[sizeof(ibuf.product) + sizeof(ibuf.revision)] = '\0'; + str = malloc (sizeof(ibuf.product) + sizeof(ibuf.revision) + 1); + if (str) + { + str[0] = '\0'; + strncat (str, (char *)ibuf.product, sizeof(ibuf.product)); + strncat (str, (char *)ibuf.revision, sizeof(ibuf.revision)); + } dev->sane.model = str; dev->sane.type = "flatbed scanner"; @@ -535,6 +538,9 @@ sane_exit (void) free ((void *) dev->sane.model); free (dev); } + + if (devlist) + free (devlist); DBG (11, "<< sane_exit\n"); } @@ -542,7 +548,6 @@ sane_exit (void) SANE_Status sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only) { - static const SANE_Device **devlist = 0; Ricoh_Device *dev; int i; diff --git a/backend/rts8891.c b/backend/rts8891.c index d86347b..bdb4011 100644 --- a/backend/rts8891.c +++ b/backend/rts8891.c @@ -2212,7 +2212,13 @@ sane_close (SANE_Handle handle) /* switch off lamp and close usb */ if (dev->conf.allowsharing == SANE_TRUE) { - sanei_usb_claim_interface (dev->devnum, 0); + SANE_Status status = sanei_usb_claim_interface (dev->devnum, 0); + if (status != SANE_STATUS_GOOD) + { + DBG (DBG_warn, "sane_close: cannot claim usb interface: %s\n", + sane_strstatus(status)); + DBG (DBG_warn, "sane_close: continuing anyway\n"); + } } set_lamp_state (session, 0); sanei_usb_close (dev->devnum); @@ -3197,14 +3203,6 @@ find_origin (struct Rts8891_Device *dev, SANE_Bool * changed) return status; } - if (status != SANE_STATUS_GOOD) - { - free(image); - free(data); - DBG (DBG_error, "find_origin: failed to wait for data\n"); - return status; - } - if (DBG_LEVEL > DBG_io2) { write_gray_data (data, "find_origin.pnm", width, height); diff --git a/backend/s9036.c b/backend/s9036.c index 9313622..1b97f80 100644 --- a/backend/s9036.c +++ b/backend/s9036.c @@ -45,6 +45,7 @@ #undef Byte #define Byte SANE_Byte +static const SANE_Device **devlist = NULL; static int num_devices; static S9036_Device *s9036_devices; @@ -870,12 +871,14 @@ sane_exit (void) sane_close (dev->handle); free (dev); } + + if (devlist) + free (devlist); } SANE_Status sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only) { - static const SANE_Device **devlist = 0; S9036_Device *dev; int i; diff --git a/backend/snapscan-options.c b/backend/snapscan-options.c index 15f3a4a..52fee81 100644 --- a/backend/snapscan-options.c +++ b/backend/snapscan-options.c @@ -44,7 +44,7 @@ If you do not wish that, delete this exception notice. This file is a component of the implementation of a backend for many - of the the AGFA SnapScan and Acer Vuego/Prisa flatbed scanners. */ + of the AGFA SnapScan and Acer Vuego/Prisa flatbed scanners. */ /* $Id$ SANE SnapScan backend */ diff --git a/backend/snapscan-scsi.c b/backend/snapscan-scsi.c index ac0efea..861ff32 100644 --- a/backend/snapscan-scsi.c +++ b/backend/snapscan-scsi.c @@ -44,7 +44,7 @@ If you do not wish that, delete this exception notice. This file is a component of the implementation of a backend for many - of the the AGFA SnapScan and Acer Vuego/Prisa flatbed scanners. */ + of the AGFA SnapScan and Acer Vuego/Prisa flatbed scanners. */ /* $Id$ diff --git a/backend/snapscan-sources.c b/backend/snapscan-sources.c index d91060e..63eadb2 100644 --- a/backend/snapscan-sources.c +++ b/backend/snapscan-sources.c @@ -44,7 +44,7 @@ If you do not wish that, delete this exception notice. This file is a component of the implementation of a backend for many - of the the AGFA SnapScan and Acer Vuego/Prisa flatbed scanners. */ + of the AGFA SnapScan and Acer Vuego/Prisa flatbed scanners. */ /* $Id$ diff --git a/backend/snapscan-sources.h b/backend/snapscan-sources.h index 53b705b..a5ed3df 100644 --- a/backend/snapscan-sources.h +++ b/backend/snapscan-sources.h @@ -44,7 +44,7 @@ If you do not wish that, delete this exception notice. This file is a component of the implementation of a backend for many - of the the AGFA SnapScan and Acer Vuego/Prisa flatbed scanners. */ + of the AGFA SnapScan and Acer Vuego/Prisa flatbed scanners. */ /* $Id$ diff --git a/backend/snapscan.c b/backend/snapscan.c index 44b757b..3c0fb81 100644 --- a/backend/snapscan.c +++ b/backend/snapscan.c @@ -45,7 +45,7 @@ If you do not wish that, delete this exception notice. This file is a component of the implementation of a backend for many - of the the AGFA SnapScan and Acer Vuego/Prisa flatbed scanners. */ + of the AGFA SnapScan and Acer Vuego/Prisa flatbed scanners. */ /* $Id$ diff --git a/backend/snapscan.h b/backend/snapscan.h index 2795d88..19a9fb5 100644 --- a/backend/snapscan.h +++ b/backend/snapscan.h @@ -44,7 +44,7 @@ If you do not wish that, delete this exception notice. This file is a component of the implementation of a backend for many - of the the AGFA SnapScan and Acer Vuego/Prisa flatbed scanners. */ + of the AGFA SnapScan and Acer Vuego/Prisa flatbed scanners. */ /* $Id$ SANE SnapScan backend */ diff --git a/backend/sp15c.c b/backend/sp15c.c index 7a3808e..3937a30 100644 --- a/backend/sp15c.c +++ b/backend/sp15c.c @@ -311,7 +311,6 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize) SANE_Status sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only) { - static const SANE_Device **devlist = 0; struct sp15c *dev; int i; @@ -990,6 +989,9 @@ sane_exit (void) free (dev->buffer); free (dev); } + + if (devlist) + free (devlist); } /* sane_exit */ /* }################ internal (support) routines ################{ */ diff --git a/backend/sp15c.h b/backend/sp15c.h index 52535e0..e078316 100644 --- a/backend/sp15c.h +++ b/backend/sp15c.h @@ -97,6 +97,7 @@ static const char RCSid_h[] = "$Header$"; * */ +static const SANE_Device **devlist = NULL; static int num_devices; static struct sp15c *first_dev; diff --git a/backend/tamarack.c b/backend/tamarack.c index 9baec51..e7073af 100644 --- a/backend/tamarack.c +++ b/backend/tamarack.c @@ -77,6 +77,7 @@ #define TAMARACK_CONFIG_FILE "tamarack.conf" +static const SANE_Device **devlist = NULL; static int num_devices; static Tamarack_Device *first_dev; static Tamarack_Scanner *first_handle; @@ -950,12 +951,14 @@ sane_exit (void) free ((void *) dev->sane.model); free (dev); } + + if (devlist) + free (devlist); } SANE_Status sane_get_devices (const SANE_Device ***device_list, SANE_Bool local_only) { - static const SANE_Device **devlist = 0; Tamarack_Device *dev; int i; diff --git a/backend/test.c b/backend/test.c index 8f8851a..d5b7365 100644 --- a/backend/test.c +++ b/backend/test.c @@ -348,7 +348,7 @@ init_options (Test_Device * test_device) od->title = SANE_I18N ("Hand-scanner simulation"); od->desc = SANE_I18N ("Simulate a hand-scanner. Hand-scanners do not " "know the image height a priori. Instead, they " - "return a height of -1. Setting this option allows " + "return a height of -1. Setting this option allows one " "to test whether a frontend can handle this " "correctly. This option also enables a fixed width " "of 11 cm."); @@ -1120,7 +1120,10 @@ read_option (SANE_String line, SANE_String option_string, return SANE_STATUS_INVAL; if (strcmp (word, option_string) != 0) - return SANE_STATUS_INVAL; + { + free(word); + return SANE_STATUS_INVAL; + } free (word); word = 0; @@ -1240,7 +1243,6 @@ read_option (SANE_String line, SANE_String option_string, if (word) free (word); - word = 0; return SANE_STATUS_GOOD; } @@ -1453,7 +1455,7 @@ sane_init (SANE_Int * __sane_unused__ version_code, SANE_Auth_Callback __sane_un { FILE *fp; SANE_Int linenumber; - SANE_Char line[PATH_MAX], *word; + SANE_Char line[PATH_MAX], *word = NULL; SANE_String_Const cp; SANE_Device *sane_device; Test_Device *test_device, *previous_device; @@ -1481,7 +1483,9 @@ sane_init (SANE_Int * __sane_unused__ version_code, SANE_Auth_Callback __sane_un DBG (4, "sane_init: reading config file `%s'\n", TEST_CONFIG_FILE); while (sanei_config_read (line, sizeof (line), fp)) { - word = 0; + if (word) + free (word); + word = NULL; linenumber++; cp = sanei_config_get_string (line, &word); @@ -1490,8 +1494,6 @@ sane_init (SANE_Int * __sane_unused__ version_code, SANE_Auth_Callback __sane_un DBG (5, "sane_init: config file line %3d: ignoring empty line\n", linenumber); - if (word) - free (word); continue; } if (word[0] == '#') @@ -1499,7 +1501,6 @@ sane_init (SANE_Int * __sane_unused__ version_code, SANE_Auth_Callback __sane_un DBG (5, "sane_init: config file line %3d: ignoring comment line\n", linenumber); - free (word); continue; } @@ -1599,6 +1600,8 @@ sane_init (SANE_Int * __sane_unused__ version_code, SANE_Auth_Callback __sane_un DBG (3, "sane-init: I don't know how to handle option `%s'\n", word); } /* while */ + if (word) + free (word); fclose (fp); } /* if */ else diff --git a/backend/umax-uc630.c b/backend/umax-uc630.c index 26c6831..0fbc59f 100644 --- a/backend/umax-uc630.c +++ b/backend/umax-uc630.c @@ -76,14 +76,14 @@ static unsigned char UC630_INQUIRY[] = /* 60 -62 scanner capability */ 0xfd, - 0x8c, /* 0xbc ? */ + 0x80, 0x03, /* 63 reserved */ 0x00, /* 64 gamma */ - 0xa1, + 0x00, /* 65 reserved */ 0x00, @@ -113,13 +113,13 @@ static unsigned char UC630_INQUIRY[] = 0x00, /* 73 max optical res in 100 dpi */ - 0x04, + 0x03, /* 74 max x_res in 100 dpi */ - 0x04, + 0x03, /* 75 max y_res in 100 dpi */ - 0x04, + 0x06, /* 76-77 fb max scan width in 0.01 inch */ 0x03, 0x52, @@ -167,7 +167,7 @@ static unsigned char UC630_INQUIRY[] = 0x00, /* 92-93 window descriptor block length */ - 0x00, 0x30, + 0x00, 0x31, /* 94 optical resolution residue (1dpi) */ 0x00, diff --git a/backend/umax.c b/backend/umax.c index b2ceb00..0d8ddba 100644 --- a/backend/umax.c +++ b/backend/umax.c @@ -1035,7 +1035,7 @@ static SANE_Status sense_handler(int scsi_fd, unsigned char *result, void *arg) if (asc == 0x00) { - DBG(DBG_sense, "-> button protocoll\n"); + DBG(DBG_sense, "-> button protocol\n"); if (ascq & 1) { dev->button0_pressed = 1; diff --git a/backend/umax_pp_low.c b/backend/umax_pp_low.c index ef10bd7..c5f58a7 100644 --- a/backend/umax_pp_low.c +++ b/backend/umax_pp_low.c @@ -10898,7 +10898,7 @@ sanei_umax_pp_scan (int x, int y, int width, int height, int dpi, int color, /* scan time are high enough to forget about usec */ elapsed = tf.tv_sec - td.tv_sec; - DBG (8, "%ld bytes transfered in %f seconds ( %.2f Kb/s)\n", somme, + DBG (8, "%ld bytes transferred in %f seconds ( %.2f Kb/s)\n", somme, elapsed, (somme / elapsed) / 1024.0); #endif diff --git a/backend/v4l.c b/backend/v4l.c index 38595ed..519bf01 100644 --- a/backend/v4l.c +++ b/backend/v4l.c @@ -290,6 +290,13 @@ init_options (V4L_Scanner * s) s->val[OPT_MODE].s = strdup (mode_list[0]); if (!s->val[OPT_MODE].s) return SANE_STATUS_NO_MEM; + s->opt[OPT_MODE].size = 1; /* '\0' */ + for (i = 0; mode_list[i] != 0; ++i) + { + int len = strlen(mode_list[i]) + 1; + if (s->opt[OPT_MODE].size < len) + s->opt[OPT_MODE].size = len; + } /* channel */ s->opt[OPT_CHANNEL].name = "channel"; @@ -305,6 +312,13 @@ init_options (V4L_Scanner * s) return SANE_STATUS_NO_MEM; if (s->channel[0] == 0 || s->channel[1] == 0) s->opt[OPT_CHANNEL].cap |= SANE_CAP_INACTIVE; + s->opt[OPT_CHANNEL].size = 1; /* '\0' */ + for (i = 0; s->channel[i] != 0; ++i) + { + int len = strlen(s->channel[i]) + 1; + if (s->opt[OPT_CHANNEL].size < len) + s->opt[OPT_CHANNEL].size = len; + } /* "Geometry" group: */ s->opt[OPT_GEOMETRY_GROUP].title = "Geometry"; |