1 From: =?utf-8?b?THVib8WhIERvbGXFvmVs?= <lubos@dolezel.info>
2 Date: Fri, 22 Jul 2016 09:33:05 +0200
3 Subject: Allow non-JPEG scanning on the HP DeskJet 3520 All-in-One and
8 scan/sane/bb_ledm.c | 47 +++++++++++++++++++++++++++++++++++++++++------
9 scan/sane/ledm.c | 12 +++++++-----
10 2 files changed, 48 insertions(+), 11 deletions(-)
12 diff --git a/scan/sane/bb_ledm.c b/scan/sane/bb_ledm.c
13 index 4b18af8..168a6ab 100644
14 --- a/scan/sane/bb_ledm.c
15 +++ b/scan/sane/bb_ledm.c
16 @@ -189,7 +189,7 @@ Keep-Alive: 20\r\nProxy-Connection: keep-alive\r\nCookie: AccessCounter=new\r\n0
20 -<CompressionQFactor>15</CompressionQFactor>\
21 +<CompressionQFactor>0</CompressionQFactor>\
22 <ColorSpace>%s</ColorSpace>\
23 <BitDepth>%d</BitDepth>\
24 <InputSource>%s</InputSource>\
25 @@ -234,6 +234,38 @@ Keep-Alive: 300\r\nProxy-Connection: keep-alive\r\nCookie: AccessCounter=new\r\n
26 # define JOBSTATE_COMPLETED "<j:JobState>Completed</j:JobState>"
27 # define PRESCANPAGE "<PreScanPage>"
29 +static int parse_status_elements(const char *payload, int size, struct wscn_create_scan_job_response *resp)
33 + char *tail=(char *)payload;
37 + get_tag(tail, size-(tail-payload), tag, sizeof(tag), &tail);
42 + if (strncmp(tag, "ImageWidth", 10) == 0)
44 + get_element(tail, size-(tail-payload), value, sizeof(value), &tail);
45 + resp->pixels_per_line = strtol(value, NULL, 10);
47 + else if (strncmp(tag, "ImageHeight", 11) == 0)
49 + get_element(tail, size-(tail-payload), value, sizeof(value), &tail);
50 + resp->lines = strtol(value, NULL, 10);
52 + else if (strncmp(tag, "BytesPerLine", 12) == 0)
54 + get_element(tail, size-(tail-payload), value, sizeof(value), &tail);
55 + resp->bytes_per_line = strtol(value, NULL, 10);
61 static int parse_scan_elements(const char *payload, int size, struct wscn_scan_elements *elements)
64 @@ -764,8 +796,7 @@ int bb_get_parameters(struct ledm_session *ps, SANE_Parameters *pp, int option)
65 if (ps->currentCompression == SF_RAW && ps->currentScanMode != CE_GRAY8)
67 /* Set scan parameters based on scan job response values */
68 - //pp->lines = pbb->job.lines;
69 - pp->lines = (int)(SANE_UNFIX(ps->effectiveBry - ps->effectiveTly)/MM_PER_INCH*ps->currentResolution);
70 + pp->lines = pbb->job.lines;
71 pp->pixels_per_line = pbb->job.pixels_per_line;
72 pp->bytes_per_line = pbb->job.bytes_per_line;
74 @@ -786,8 +817,8 @@ int bb_get_parameters(struct ledm_session *ps, SANE_Parameters *pp, int option)
76 case SPO_BEST_GUESS: /* called by xsane & sane_start */
77 /* Set scan parameters based on best guess. */
78 - pp->lines = (int)round(SANE_UNFIX(ps->effectiveBry - ps->effectiveTly)/MM_PER_INCH*ps->currentResolution);
79 - pp->pixels_per_line = (int)round(SANE_UNFIX(ps->effectiveBrx -ps->effectiveTlx)/MM_PER_INCH*ps->currentResolution);
80 + pp->lines = (int)(SANE_UNFIX(ps->effectiveBry - ps->effectiveTly)/MM_PER_INCH*ps->currentResolution);
81 + pp->pixels_per_line = ps->image_traits.iPixelsPerRow;
82 pp->bytes_per_line = BYTES_PER_LINE(pp->pixels_per_line, pp->depth * factor);
85 @@ -896,7 +927,7 @@ SANE_Status bb_start_scan(struct ledm_session *ps)
86 (int) ((ps->currentBrx / 5548.7133) - (ps->currentTlx / 5548.7133)),//<Width>
87 (int) (ps->currentTly / 5548.7133),//<YStart>
88 (int) ((ps->currentBry / 5548.7133) - (ps->currentTly / 5548.7133)),//<Height>
90 + (ps->currentCompression == SF_RAW) ? "Raw" : "Jpeg", //<Format>
91 (! strcmp(ce_element[ps->currentScanMode], "Color8")) ? "Color" : (! strcmp(ce_element[ps->currentScanMode], "Gray8")) ? "Gray" : "Gray",//<ColorSpace>
92 ((! strcmp(ce_element[ps->currentScanMode], "Color8")) || (! strcmp(ce_element[ps->currentScanMode], "Gray8"))) ? 8: 8,//<BitDepth>
93 ps->currentInputSource == IS_PLATEN ? is_element[1] : is_element[2],//<InputSource>
94 @@ -994,6 +1025,7 @@ SANE_Status bb_start_scan(struct ledm_session *ps)
95 _DBG("bb_start_scan() read_http_payload FAILED len=%d buf=%s\n", len, buf);
99 //For a new scan, buf must contain <PreScanPage>.
100 if (NULL == strstr(buf,PRESCANPAGE))
101 { //i.e Paper is not present in Scanner
102 @@ -1012,6 +1044,9 @@ SANE_Status bb_start_scan(struct ledm_session *ps)
103 stat = SANE_STATUS_GOOD;
107 + parse_status_elements(buf, len, &pbb->job);
109 usleep(500000);//0.5 sec delay
112 diff --git a/scan/sane/ledm.c b/scan/sane/ledm.c
113 index ac9d604..a56f534 100644
114 --- a/scan/sane/ledm.c
115 +++ b/scan/sane/ledm.c
116 @@ -170,11 +170,11 @@ static int set_scan_mode_side_effects(struct ledm_session *ps, enum COLOR_ENTRY
120 -// ps->compressionList[j] = STR_COMPRESSION_NONE;
121 -// ps->compressionMap[j++] = SF_RAW;
122 + ps->compressionList[j] = STR_COMPRESSION_NONE;
123 + ps->compressionMap[j++] = SF_RAW;
124 ps->compressionList[j] = STR_COMPRESSION_JPEG;
125 ps->compressionMap[j++] = SF_JPEG;
126 - ps->currentCompression = SF_JPEG;
127 + ps->currentCompression = SF_RAW;
128 ps->option[LEDM_OPTION_JPEG_QUALITY].cap |= SANE_CAP_SOFT_SELECT; /* enable jpeg quality */
131 @@ -690,7 +690,7 @@ SANE_Status ledm_control_option(SANE_Handle handle, SANE_Int option, SANE_Action
135 - ps->currentCompression = SF_JPEG;
136 + ps->currentCompression = SF_RAW;
137 stat = SANE_STATUS_GOOD;
140 @@ -995,7 +995,9 @@ SANE_Status ledm_start(SANE_Handle handle)
144 - ipGetImageTraits(ps->ip_handle, NULL, &ps->image_traits); /* get valid image traits */
146 + ipGetOutputTraits(ps->ip_handle, &ps->image_traits); /* get valid image traits */
149 stat = SANE_STATUS_GOOD;