0018-Allow-non-JPEG-scanning-on-the-HP-DeskJet-3520-All-i.patch 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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
  4. similar devices
  5. LP: #1245578
  6. ---
  7. scan/sane/bb_ledm.c | 47 +++++++++++++++++++++++++++++++++++++++++------
  8. scan/sane/ledm.c | 12 +++++++-----
  9. 2 files changed, 48 insertions(+), 11 deletions(-)
  10. diff --git a/scan/sane/bb_ledm.c b/scan/sane/bb_ledm.c
  11. index 4b18af8..168a6ab 100644
  12. --- a/scan/sane/bb_ledm.c
  13. +++ b/scan/sane/bb_ledm.c
  14. @@ -189,7 +189,7 @@ Keep-Alive: 20\r\nProxy-Connection: keep-alive\r\nCookie: AccessCounter=new\r\n0
  15. <YStart>%d</YStart>\
  16. <Height>%d</Height>\
  17. <Format>%s</Format>\
  18. -<CompressionQFactor>15</CompressionQFactor>\
  19. +<CompressionQFactor>0</CompressionQFactor>\
  20. <ColorSpace>%s</ColorSpace>\
  21. <BitDepth>%d</BitDepth>\
  22. <InputSource>%s</InputSource>\
  23. @@ -234,6 +234,38 @@ Keep-Alive: 300\r\nProxy-Connection: keep-alive\r\nCookie: AccessCounter=new\r\n
  24. # define JOBSTATE_COMPLETED "<j:JobState>Completed</j:JobState>"
  25. # define PRESCANPAGE "<PreScanPage>"
  26. +static int parse_status_elements(const char *payload, int size, struct wscn_create_scan_job_response *resp)
  27. +{
  28. + char tag[512];
  29. + char value[128];
  30. + char *tail=(char *)payload;
  31. +
  32. + while (1)
  33. + {
  34. + get_tag(tail, size-(tail-payload), tag, sizeof(tag), &tail);
  35. +
  36. + if (!tag[0])
  37. + break;
  38. +
  39. + if (strncmp(tag, "ImageWidth", 10) == 0)
  40. + {
  41. + get_element(tail, size-(tail-payload), value, sizeof(value), &tail);
  42. + resp->pixels_per_line = strtol(value, NULL, 10);
  43. + }
  44. + else if (strncmp(tag, "ImageHeight", 11) == 0)
  45. + {
  46. + get_element(tail, size-(tail-payload), value, sizeof(value), &tail);
  47. + resp->lines = strtol(value, NULL, 10);
  48. + }
  49. + else if (strncmp(tag, "BytesPerLine", 12) == 0)
  50. + {
  51. + get_element(tail, size-(tail-payload), value, sizeof(value), &tail);
  52. + resp->bytes_per_line = strtol(value, NULL, 10);
  53. + }
  54. + }
  55. + return 0;
  56. +}
  57. +
  58. static int parse_scan_elements(const char *payload, int size, struct wscn_scan_elements *elements)
  59. {
  60. char tag[512];
  61. @@ -764,8 +796,7 @@ int bb_get_parameters(struct ledm_session *ps, SANE_Parameters *pp, int option)
  62. if (ps->currentCompression == SF_RAW && ps->currentScanMode != CE_GRAY8)
  63. {
  64. /* Set scan parameters based on scan job response values */
  65. - //pp->lines = pbb->job.lines;
  66. - pp->lines = (int)(SANE_UNFIX(ps->effectiveBry - ps->effectiveTly)/MM_PER_INCH*ps->currentResolution);
  67. + pp->lines = pbb->job.lines;
  68. pp->pixels_per_line = pbb->job.pixels_per_line;
  69. pp->bytes_per_line = pbb->job.bytes_per_line;
  70. }
  71. @@ -786,8 +817,8 @@ int bb_get_parameters(struct ledm_session *ps, SANE_Parameters *pp, int option)
  72. break;
  73. case SPO_BEST_GUESS: /* called by xsane & sane_start */
  74. /* Set scan parameters based on best guess. */
  75. - pp->lines = (int)round(SANE_UNFIX(ps->effectiveBry - ps->effectiveTly)/MM_PER_INCH*ps->currentResolution);
  76. - pp->pixels_per_line = (int)round(SANE_UNFIX(ps->effectiveBrx -ps->effectiveTlx)/MM_PER_INCH*ps->currentResolution);
  77. + pp->lines = (int)(SANE_UNFIX(ps->effectiveBry - ps->effectiveTly)/MM_PER_INCH*ps->currentResolution);
  78. + pp->pixels_per_line = ps->image_traits.iPixelsPerRow;
  79. pp->bytes_per_line = BYTES_PER_LINE(pp->pixels_per_line, pp->depth * factor);
  80. break;
  81. default:
  82. @@ -896,7 +927,7 @@ SANE_Status bb_start_scan(struct ledm_session *ps)
  83. (int) ((ps->currentBrx / 5548.7133) - (ps->currentTlx / 5548.7133)),//<Width>
  84. (int) (ps->currentTly / 5548.7133),//<YStart>
  85. (int) ((ps->currentBry / 5548.7133) - (ps->currentTly / 5548.7133)),//<Height>
  86. - "Jpeg",//<Format>
  87. + (ps->currentCompression == SF_RAW) ? "Raw" : "Jpeg", //<Format>
  88. (! strcmp(ce_element[ps->currentScanMode], "Color8")) ? "Color" : (! strcmp(ce_element[ps->currentScanMode], "Gray8")) ? "Gray" : "Gray",//<ColorSpace>
  89. ((! strcmp(ce_element[ps->currentScanMode], "Color8")) || (! strcmp(ce_element[ps->currentScanMode], "Gray8"))) ? 8: 8,//<BitDepth>
  90. ps->currentInputSource == IS_PLATEN ? is_element[1] : is_element[2],//<InputSource>
  91. @@ -994,6 +1025,7 @@ SANE_Status bb_start_scan(struct ledm_session *ps)
  92. _DBG("bb_start_scan() read_http_payload FAILED len=%d buf=%s\n", len, buf);
  93. break;
  94. }
  95. +
  96. //For a new scan, buf must contain <PreScanPage>.
  97. if (NULL == strstr(buf,PRESCANPAGE))
  98. { //i.e Paper is not present in Scanner
  99. @@ -1012,6 +1044,9 @@ SANE_Status bb_start_scan(struct ledm_session *ps)
  100. stat = SANE_STATUS_GOOD;
  101. goto bugout;
  102. }
  103. + // Parse buf here
  104. + parse_status_elements(buf, len, &pbb->job);
  105. +
  106. usleep(500000);//0.5 sec delay
  107. }//end while()
  108. diff --git a/scan/sane/ledm.c b/scan/sane/ledm.c
  109. index ac9d604..a56f534 100644
  110. --- a/scan/sane/ledm.c
  111. +++ b/scan/sane/ledm.c
  112. @@ -170,11 +170,11 @@ static int set_scan_mode_side_effects(struct ledm_session *ps, enum COLOR_ENTRY
  113. case CE_GRAY8:
  114. case CE_COLOR8:
  115. default:
  116. -// ps->compressionList[j] = STR_COMPRESSION_NONE;
  117. -// ps->compressionMap[j++] = SF_RAW;
  118. + ps->compressionList[j] = STR_COMPRESSION_NONE;
  119. + ps->compressionMap[j++] = SF_RAW;
  120. ps->compressionList[j] = STR_COMPRESSION_JPEG;
  121. ps->compressionMap[j++] = SF_JPEG;
  122. - ps->currentCompression = SF_JPEG;
  123. + ps->currentCompression = SF_RAW;
  124. ps->option[LEDM_OPTION_JPEG_QUALITY].cap |= SANE_CAP_SOFT_SELECT; /* enable jpeg quality */
  125. break;
  126. }
  127. @@ -690,7 +690,7 @@ SANE_Status ledm_control_option(SANE_Handle handle, SANE_Int option, SANE_Action
  128. }
  129. else
  130. { /* Set default. */
  131. - ps->currentCompression = SF_JPEG;
  132. + ps->currentCompression = SF_RAW;
  133. stat = SANE_STATUS_GOOD;
  134. }
  135. break;
  136. @@ -995,7 +995,9 @@ SANE_Status ledm_start(SANE_Handle handle)
  137. }
  138. }
  139. else
  140. - ipGetImageTraits(ps->ip_handle, NULL, &ps->image_traits); /* get valid image traits */
  141. + {
  142. + ipGetOutputTraits(ps->ip_handle, &ps->image_traits); /* get valid image traits */
  143. + }
  144. stat = SANE_STATUS_GOOD;