b1ada74
From 9b13d4c18b2424eaed02b72a928e9607921ec265 Mon Sep 17 00:00:00 2001
b1ada74
From: Bernard Cafarelli <bernard.cafarelli@gmail.com>
b1ada74
Date: Tue, 17 Apr 2018 22:43:15 +0200
b1ada74
Subject: [PATCH] Revert "Color scanning for Samsung models, which support JPEG
b1ada74
 Lossy compression."
b1ada74
b1ada74
This reverts commit 926bfade544de4a4fd5f1a8082b85a97e2443770, leaving
b1ada74
the new IDs in.
b1ada74
As tracked in #315876, this breaks scanning with multiple Samsung scanners
b1ada74
b1ada74
Conflicts:
b1ada74
	backend/xerox_mfp.c
b1ada74
	backend/xerox_mfp.h
b1ada74
	doc/descriptions/xerox_mfp.desc
b1ada74
---
b1ada74
 backend/Makefile.am             |   2 +-
b1ada74
 backend/Makefile.in             |   7 +-
b1ada74
 backend/xerox_mfp.c             | 193 +-------------------------------
b1ada74
 backend/xerox_mfp.h             |   5 -
b1ada74
 doc/descriptions/xerox_mfp.desc |  10 +-
b1ada74
 5 files changed, 14 insertions(+), 203 deletions(-)
b1ada74
b1ada74
diff --git a/backend/Makefile.am b/backend/Makefile.am
b1ada74
index 18695a4a..3225b133 100644
b1ada74
--- a/backend/Makefile.am
b1ada74
+++ b/backend/Makefile.am
b1ada74
@@ -1086,7 +1086,7 @@ libxerox_mfp_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=xerox_mfp
b1ada74
 nodist_libsane_xerox_mfp_la_SOURCES = xerox_mfp-s.c
b1ada74
 libsane_xerox_mfp_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=xerox_mfp
b1ada74
 libsane_xerox_mfp_la_LDFLAGS = $(DIST_SANELIBS_LDFLAGS)
b1ada74
-libsane_xerox_mfp_la_LIBADD = $(COMMON_LIBS) libxerox_mfp.la ../sanei/sanei_init_debug.lo ../sanei/sanei_constrain_value.lo ../sanei/sanei_config.lo  sane_strstatus.lo @SANEI_SANEI_JPEG_LO@ $(JPEG_LIBS) ../sanei/sanei_usb.lo ../sanei/sanei_tcp.lo $(MATH_LIB) $(SOCKET_LIBS) $(USB_LIBS) $(RESMGR_LIBS)
b1ada74
+libsane_xerox_mfp_la_LIBADD = $(COMMON_LIBS) libxerox_mfp.la ../sanei/sanei_init_debug.lo ../sanei/sanei_constrain_value.lo ../sanei/sanei_config.lo  sane_strstatus.lo ../sanei/sanei_usb.lo ../sanei/sanei_tcp.lo $(MATH_LIB) $(SOCKET_LIBS) $(USB_LIBS) $(RESMGR_LIBS)
b1ada74
 EXTRA_DIST += xerox_mfp.conf.in
b1ada74
 
b1ada74
 libdll_preload_la_SOURCES =  dll.c
b1ada74
diff --git a/backend/Makefile.in b/backend/Makefile.in
b1ada74
index d1dca4a2..2643bb77 100644
b1ada74
--- a/backend/Makefile.in
b1ada74
+++ b/backend/Makefile.in
b1ada74
@@ -1430,10 +1430,9 @@ libsane_v4l_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
b1ada74
 libsane_xerox_mfp_la_DEPENDENCIES = $(COMMON_LIBS) libxerox_mfp.la \
b1ada74
 	../sanei/sanei_init_debug.lo ../sanei/sanei_constrain_value.lo \
b1ada74
 	../sanei/sanei_config.lo sane_strstatus.lo \
b1ada74
-	$(am__DEPENDENCIES_1) ../sanei/sanei_usb.lo \
b1ada74
-	../sanei/sanei_tcp.lo $(am__DEPENDENCIES_1) \
b1ada74
+	../sanei/sanei_usb.lo ../sanei/sanei_tcp.lo \
b1ada74
 	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
b1ada74
-	$(am__DEPENDENCIES_1)
b1ada74
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
b1ada74
 nodist_libsane_xerox_mfp_la_OBJECTS =  \
b1ada74
 	libsane_xerox_mfp_la-xerox_mfp-s.lo
b1ada74
 libsane_xerox_mfp_la_OBJECTS = $(nodist_libsane_xerox_mfp_la_OBJECTS)
b1ada74
@@ -2754,7 +2753,7 @@ libxerox_mfp_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=xerox_mfp
b1ada74
 nodist_libsane_xerox_mfp_la_SOURCES = xerox_mfp-s.c
b1ada74
 libsane_xerox_mfp_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=xerox_mfp
b1ada74
 libsane_xerox_mfp_la_LDFLAGS = $(DIST_SANELIBS_LDFLAGS)
b1ada74
-libsane_xerox_mfp_la_LIBADD = $(COMMON_LIBS) libxerox_mfp.la ../sanei/sanei_init_debug.lo ../sanei/sanei_constrain_value.lo ../sanei/sanei_config.lo  sane_strstatus.lo @SANEI_SANEI_JPEG_LO@ $(JPEG_LIBS) ../sanei/sanei_usb.lo ../sanei/sanei_tcp.lo $(MATH_LIB) $(SOCKET_LIBS) $(USB_LIBS) $(RESMGR_LIBS)
b1ada74
+libsane_xerox_mfp_la_LIBADD = $(COMMON_LIBS) libxerox_mfp.la ../sanei/sanei_init_debug.lo ../sanei/sanei_constrain_value.lo ../sanei/sanei_config.lo  sane_strstatus.lo ../sanei/sanei_usb.lo ../sanei/sanei_tcp.lo $(MATH_LIB) $(SOCKET_LIBS) $(USB_LIBS) $(RESMGR_LIBS)
b1ada74
 libdll_preload_la_SOURCES = dll.c
b1ada74
 libdll_preload_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=dll -DENABLE_PRELOAD
b1ada74
 libdll_la_SOURCES = dll.c
b1ada74
diff --git a/backend/xerox_mfp.c b/backend/xerox_mfp.c
b1ada74
index 8b8c8956..d37a6237 100644
b1ada74
--- a/backend/xerox_mfp.c
b1ada74
+++ b/backend/xerox_mfp.c
b1ada74
@@ -33,9 +33,6 @@
b1ada74
 #include "../include/sane/sanei_usb.h"
b1ada74
 #include "../include/sane/sanei_config.h"
b1ada74
 #include "../include/sane/sanei_backend.h"
b1ada74
-#ifdef HAVE_LIBJPEG
b1ada74
-#include <jpeglib.h>
b1ada74
-#endif
b1ada74
 #include "xerox_mfp.h"
b1ada74
 
b1ada74
 #define BACKEND_BUILD 13
b1ada74
@@ -93,128 +90,6 @@ static char *str_cmd(int cmd)
b1ada74
 }
b1ada74
 
b1ada74
 #define MAX_DUMP 70
b1ada74
-const char *encTmpFileName = "/tmp/stmp_enc.tmp";
b1ada74
-
b1ada74
-static int decompress(struct device __sane_unused__ *dev,
b1ada74
-                      const char __sane_unused__ *infilename)
b1ada74
-{
b1ada74
-#ifdef HAVE_LIBJPEG
b1ada74
-    int rc;
b1ada74
-    int row_stride, width, height, pixel_size;
b1ada74
-    struct jpeg_decompress_struct cinfo;
b1ada74
-    struct jpeg_error_mgr jerr;
b1ada74
-    unsigned long bmp_size = 0;
b1ada74
-    FILE *pInfile = NULL;
b1ada74
-    JSAMPARRAY buffer;
b1ada74
-
b1ada74
-    if ((pInfile = fopen(infilename, "rb")) == NULL) {
b1ada74
-        fprintf(stderr, "can't open %s\n", infilename);
b1ada74
-        return -1;
b1ada74
-    }
b1ada74
-
b1ada74
-    cinfo.err = jpeg_std_error(&jerr);
b1ada74
-
b1ada74
-    jpeg_create_decompress(&cinfo);
b1ada74
-
b1ada74
-    jpeg_stdio_src(&cinfo, pInfile);
b1ada74
-
b1ada74
-    rc = jpeg_read_header(&cinfo, TRUE);
b1ada74
-    if (rc != 1) {
b1ada74
-        jpeg_destroy_decompress(&cinfo);
b1ada74
-        fclose(pInfile);
b1ada74
-        return -1;
b1ada74
-    }
b1ada74
-
b1ada74
-    jpeg_start_decompress(&cinfo);
b1ada74
-
b1ada74
-    width = cinfo.output_width;
b1ada74
-    height = cinfo.output_height;
b1ada74
-    pixel_size = cinfo.output_components;
b1ada74
-    bmp_size = width * height * pixel_size;
b1ada74
-    dev->decDataSize = bmp_size;
b1ada74
-
b1ada74
-    row_stride = width * pixel_size;
b1ada74
-
b1ada74
-    buffer = (*cinfo.mem->alloc_sarray)
b1ada74
-             ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
b1ada74
-
b1ada74
-    while (cinfo.output_scanline < cinfo.output_height) {
b1ada74
-        buffer[0] = dev->decData + \
b1ada74
-                    (cinfo.output_scanline) * row_stride;
b1ada74
-        jpeg_read_scanlines(&cinfo, buffer, 1);
b1ada74
-    }
b1ada74
-    jpeg_finish_decompress(&cinfo);
b1ada74
-    jpeg_destroy_decompress(&cinfo);
b1ada74
-    fclose(pInfile);
b1ada74
-    return 0;
b1ada74
-#else
b1ada74
-    return -1;
b1ada74
-#endif
b1ada74
-}
b1ada74
-
b1ada74
-static int copy_decompress_data(struct device *dev, unsigned char *pDest, int maxlen, int *destLen)
b1ada74
-{
b1ada74
-    int data_size = 0;
b1ada74
-    size_t result = 0, retVal = 0;
b1ada74
-
b1ada74
-
b1ada74
-    if (0 == dev->decDataSize) {
b1ada74
-        *destLen = 0;
b1ada74
-        return retVal;
b1ada74
-    }
b1ada74
-    data_size = dev->decDataSize - dev->currentDecDataIndex;
b1ada74
-    if (data_size > maxlen) {
b1ada74
-        data_size = maxlen;
b1ada74
-    }
b1ada74
-    memcpy(pDest, dev->decData+dev->currentDecDataIndex, data_size);
b1ada74
-    result = data_size;
b1ada74
-    *destLen = result;
b1ada74
-    dev->currentDecDataIndex += result;
b1ada74
-    retVal = result;
b1ada74
-
b1ada74
-    if (dev->decDataSize == dev->currentDecDataIndex) {
b1ada74
-        dev->currentDecDataIndex = 0;
b1ada74
-        dev->decDataSize = 0;
b1ada74
-    }
b1ada74
-
b1ada74
-    return retVal;
b1ada74
-}
b1ada74
-
b1ada74
-static int decompress_tempfile(struct device *dev)
b1ada74
-{
b1ada74
-    decompress(dev, encTmpFileName);
b1ada74
-    remove(encTmpFileName);
b1ada74
-    return 0;
b1ada74
-}
b1ada74
-
b1ada74
-static int dump_to_tmp_file(struct device *dev)
b1ada74
-{
b1ada74
-    unsigned char *pSrc = dev->data;
b1ada74
-    int srcLen = dev->datalen;
b1ada74
-    FILE *pInfile;
b1ada74
-    if ((pInfile = fopen(encTmpFileName, "a")) == NULL) {
b1ada74
-        fprintf(stderr, "can't open %s\n", encTmpFileName);
b1ada74
-        return 0;
b1ada74
-    }
b1ada74
-
b1ada74
-    fwrite(pSrc, 1, srcLen, pInfile);
b1ada74
-    fclose(pInfile);
b1ada74
-    return srcLen;
b1ada74
-}
b1ada74
-
b1ada74
-static int isSupportedDevice(struct device __sane_unused__ *dev)
b1ada74
-{
b1ada74
-#ifdef HAVE_LIBJPEG
b1ada74
-    /* Checking device which supports JPEG Lossy compression for color scanning*/
b1ada74
-    if (dev->compressionTypes & (1 << 6))
b1ada74
-        return 1;
b1ada74
-    else
b1ada74
-        return 0;
b1ada74
-#else
b1ada74
-    return 0;
b1ada74
-#endif
b1ada74
-}
b1ada74
-
b1ada74
 static void dbg_dump(struct device *dev)
b1ada74
 {
b1ada74
     int i;
b1ada74
@@ -639,11 +514,9 @@ static void set_parameters(struct device *dev)
b1ada74
     dev->para.pixels_per_line = dev->win_width / px_to_len;
b1ada74
     dev->para.bytes_per_line = dev->para.pixels_per_line;
b1ada74
 
b1ada74
-    if (!isSupportedDevice(dev)) {
b1ada74
 #if BETTER_BASEDPI
b1ada74
-        px_to_len = 1213.9 / dev->val[OPT_RESOLUTION].w;
b1ada74
+	px_to_len = 1213.9 / dev->val[OPT_RESOLUTION].w;
b1ada74
 #endif
b1ada74
-    }
b1ada74
     dev->para.lines = dev->win_len / px_to_len;
b1ada74
     if (dev->composition == MODE_LINEART ||
b1ada74
         dev->composition == MODE_HALFTONE) {
b1ada74
@@ -765,13 +638,6 @@ static int dev_set_window(struct device *dev)
b1ada74
     cmd[0x11] = (SANE_Byte)floor(dev->win_off_y);
b1ada74
     cmd[0x12] = (SANE_Byte)((dev->win_off_y - floor(dev->win_off_y)) * 100);
b1ada74
     cmd[0x13] = dev->composition;
b1ada74
-    /* Set to JPEG Lossy Compression, if mode is color (only for supported model)...
b1ada74
-     * else go with Uncompressed (For backard compatibility with old models )*/
b1ada74
-    if (dev->composition == MODE_RGB24) {
b1ada74
-        if (isSupportedDevice(dev)) {
b1ada74
-            cmd[0x14] = 0x6;
b1ada74
-        }
b1ada74
-    }
b1ada74
     cmd[0x16] = dev->threshold;
b1ada74
     cmd[0x17] = dev->doc_source;
b1ada74
 
b1ada74
@@ -843,7 +709,6 @@ dev_inquiry(struct device *dev)
b1ada74
                       dev->res[0x3e] << 8 |
b1ada74
                       dev->res[0x3f];
b1ada74
     dev->line_order = dev->res[0x31];
b1ada74
-    dev->compressionTypes = dev->res[0x32];
b1ada74
     dev->doc_loaded = (dev->res[0x35] == 0x02) &&
b1ada74
                       (dev->res[0x26] & 0x03);
b1ada74
 
b1ada74
@@ -942,10 +807,6 @@ dev_free(struct device *dev)
b1ada74
         free(UNCONST(dev->sane.type));
b1ada74
     if (dev->data)
b1ada74
         free(dev->data);
b1ada74
-    if (dev->decData) {
b1ada74
-        free(dev->decData);
b1ada74
-        dev->decData = NULL;
b1ada74
-    }
b1ada74
     memset(dev, 0, sizeof(*dev));
b1ada74
     free(dev);
b1ada74
 }
b1ada74
@@ -1283,19 +1144,6 @@ sane_read(SANE_Handle h, SANE_Byte *buf, SANE_Int maxlen, SANE_Int *lenp)
b1ada74
     /* if there is no data to read or output from buffer */
b1ada74
     if (!dev->blocklen && dev->datalen <= PADDING_SIZE) {
b1ada74
 
b1ada74
-        /* copying uncompressed data */
b1ada74
-        if (dev->composition == MODE_RGB24 &&
b1ada74
-            isSupportedDevice(dev) &&
b1ada74
-            dev->decDataSize > 0) {
b1ada74
-            int diff = dev->total_img_size - dev->total_out_size;
b1ada74
-            int bufLen = (diff < maxlen) ? diff : maxlen;
b1ada74
-            if (0 < diff &&
b1ada74
-                0 < copy_decompress_data(dev, buf, bufLen, lenp)) {
b1ada74
-                dev->total_out_size += *lenp;
b1ada74
-                return SANE_STATUS_GOOD;
b1ada74
-            }
b1ada74
-        }
b1ada74
-
b1ada74
         /* and we don't need to acquire next block */
b1ada74
         if (dev->final_block) {
b1ada74
             int slack = dev->total_img_size - dev->total_out_size;
b1ada74
@@ -1311,10 +1159,7 @@ sane_read(SANE_Handle h, SANE_Byte *buf, SANE_Int maxlen, SANE_Int *lenp)
b1ada74
                 /* this will never happen */
b1ada74
                 DBG(1, "image overflow %d bytes\n", dev->total_img_size - dev->total_out_size);
b1ada74
             }
b1ada74
-            if (isSupportedDevice(dev) &&
b1ada74
-                dev->composition == MODE_RGB24) {
b1ada74
-                remove(encTmpFileName);
b1ada74
-            }
b1ada74
+
b1ada74
             /* that's all */
b1ada74
             dev_stop(dev);
b1ada74
             return SANE_STATUS_EOF;
b1ada74
@@ -1365,18 +1210,9 @@ sane_read(SANE_Handle h, SANE_Byte *buf, SANE_Int maxlen, SANE_Int *lenp)
b1ada74
 
b1ada74
         if (buf && lenp) { /* read mode */
b1ada74
             /* copy will do minimal of valid data */
b1ada74
-            if (dev->para.format == SANE_FRAME_RGB && dev->line_order) {
b1ada74
-                if (isSupportedDevice(dev)) {
b1ada74
-                    clrlen = dump_to_tmp_file(dev);
b1ada74
-                    /* decompress after reading entire block data*/
b1ada74
-                    if (0 == dev->blocklen) {
b1ada74
-                        decompress_tempfile(dev);
b1ada74
-                    }
b1ada74
-                    copy_decompress_data(dev, buf, maxlen, &olen);
b1ada74
-                } else {
b1ada74
-                    clrlen = copy_mix_bands_trim(dev, buf, maxlen, &olen);
b1ada74
-                }
b1ada74
-            } else
b1ada74
+            if (dev->para.format == SANE_FRAME_RGB && dev->line_order)
b1ada74
+				clrlen = copy_mix_bands_trim(dev, buf, maxlen, &olen);
b1ada74
+            else
b1ada74
                 clrlen = copy_plain_trim(dev, buf, maxlen, &olen);
b1ada74
 
b1ada74
             dev->datalen -= clrlen;
b1ada74
@@ -1455,9 +1291,6 @@ sane_start(SANE_Handle h)
b1ada74
     if (!dev->data && !(dev->data = malloc(DATASIZE)))
b1ada74
         return ret_cancel(dev, SANE_STATUS_NO_MEM);
b1ada74
 
b1ada74
-    if (!dev->decData && !(dev->decData = malloc(POST_DATASIZE)))
b1ada74
-        return ret_cancel(dev, SANE_STATUS_NO_MEM);
b1ada74
-
b1ada74
     if (!dev_acquire(dev))
b1ada74
         return dev->state;
b1ada74
 
b1ada74
@@ -1479,22 +1312,6 @@ sane_start(SANE_Handle h)
b1ada74
 
b1ada74
     dev->total_img_size = dev->para.bytes_per_line * dev->para.lines;
b1ada74
 
b1ada74
-    if (isSupportedDevice(dev) &&
b1ada74
-        dev->composition == MODE_RGB24) {
b1ada74
-	int fd;
b1ada74
-        remove(encTmpFileName);
b1ada74
-
b1ada74
-	/* Precreate temporary file in exclusive mode. */
b1ada74
-	fd = open(encTmpFileName, O_CREAT|O_EXCL, 0600);
b1ada74
-	if (fd == -1) {
b1ada74
-	    DBG(3, "%s: %p, can't create temporary file %s: %s\n", __func__,
b1ada74
-		(void *)dev, encTmpFileName, strerror(errno));
b1ada74
-	    return ret_cancel(dev, SANE_STATUS_ACCESS_DENIED);
b1ada74
-	}
b1ada74
-	close(fd);
b1ada74
-    }
b1ada74
-    dev->currentDecDataIndex = 0;
b1ada74
-
b1ada74
     return SANE_STATUS_GOOD;
b1ada74
 }
b1ada74
 
b1ada74
diff --git a/backend/xerox_mfp.h b/backend/xerox_mfp.h
b1ada74
index 3d93f06d..ea89dda2 100644
b1ada74
--- a/backend/xerox_mfp.h
b1ada74
+++ b/backend/xerox_mfp.h
b1ada74
@@ -74,10 +74,6 @@ struct device {
b1ada74
 #define DATATAIL(dev) ((dev->dataoff + dev->datalen) & DATAMASK)
b1ada74
 #define DATAROOM(dev) dataroom(dev)
b1ada74
 
b1ada74
-#define POST_DATASIZE 0xFFFFFF
b1ada74
-    SANE_Byte *decData;
b1ada74
-    int decDataSize;
b1ada74
-    int currentDecDataIndex;
b1ada74
     /* data from CMD_INQUIRY: */
b1ada74
     int resolutions;		/* supported resolution bitmask */
b1ada74
     int compositions;		/* supported image compositions bitmask */
b1ada74
@@ -102,7 +98,6 @@ struct device {
b1ada74
     int composition;		/* MODE_ */
b1ada74
     int doc_source;		/* document source */
b1ada74
     int threshold;		/* brightness */
b1ada74
-    int compressionTypes;
b1ada74
 
b1ada74
     /* CMD_READ data. It is per block only, image could be in many blocks */
b1ada74
     int blocklen;			/* image data block len (padding incl.) */
b1ada74
diff --git a/doc/descriptions/xerox_mfp.desc b/doc/descriptions/xerox_mfp.desc
b1ada74
index d21a6be6..67253b38 100644
b1ada74
--- a/doc/descriptions/xerox_mfp.desc
b1ada74
+++ b/doc/descriptions/xerox_mfp.desc
b1ada74
@@ -320,7 +320,7 @@
b1ada74
 
b1ada74
 :model "SCX-3405W"
b1ada74
 :interface "Ethernet"
b1ada74
-:status :good
b1ada74
+:status :basic
b1ada74
 
b1ada74
 :model "SCX-3400"
b1ada74
 :interface "USB"
b1ada74
@@ -335,17 +335,17 @@
b1ada74
 :model "SCX-4729FD"
b1ada74
 :interface "USB"
b1ada74
 :usbid "0x04e8" "0x3453"
b1ada74
-:status :good
b1ada74
+:status :basic
b1ada74
 
b1ada74
 :model "CLX-6260"
b1ada74
 :interface "USB"
b1ada74
 :usbid "0x04e8" "0x3455"
b1ada74
-:status :good
b1ada74
+:status :minimal
b1ada74
 
b1ada74
 :model "CLX-3300 Series"
b1ada74
 :interface "USB"
b1ada74
 :usbid "0x04e8" "0x3456"
b1ada74
-:status :good
b1ada74
+:status :basic
b1ada74
 
b1ada74
 :model "SCX-470x"
b1ada74
 :interface "USB"
b1ada74
@@ -355,7 +355,7 @@
b1ada74
 :model "CLX-4190"
b1ada74
 :interface "USB"
b1ada74
 :usbid "0x04e8" "0x345a"
b1ada74
-:status :good
b1ada74
+:status :minimal
b1ada74
 
b1ada74
 :model "SCX-4650 4x21S Series"
b1ada74
 :interface "USB"
b1ada74
-- 
b1ada74
2.17.0
b1ada74