Blame SOURCES/sane-backends-revert-samsung-patch.patch

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