[contains fix] With no output filename given, output format of scans ignores -x / --compression option and is solely determined by -m / --mode where -m color produces JPGs and -m gray produces PNGs

Bug #1779307 reported by luke
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
HPLIP
In Progress
Undecided
Unassigned

Bug Description

I have tried this with 3.17.11 which I've been running until now and have installed (latest) 3.18.6 today where the issue persists.

When no output file is specified (-o), the output file format isn't picked according to the compression chosen but according to the mode (color or gray).

----------------------------------------

$ hp-scan -m gray -x jpeg
will produce a PNG file.

Output:

Mode: gray
Compression: JPEG
...
Setting output format to PNG for greyscale mode.

----------------------------------------

$ hp-scan -m gray
will produce a PNG file.

Output:

Mode: gray
Compression: JPEG
...
Setting output format to PNG for greyscale mode.

----------------------------------------

$ hp-scan -m color -x raw
will produce a JPEG file.

Output:

Mode: color
Compression: None
...
Setting output format to JPEG for color/lineart mode.

----------------------------------------

$ hp-scan -m color
will produce a JPEG file.

Mode: color
Compression: JPEG
...
Setting output format to JPEG for color/lineart mode.

----------------------------------------

This is confusing.

I went over to `/usr/share/hplip/scan.py` and the mistake seems to be here:

----------------------------------------

        if 'file' in dest and not output:
            log.warn("File destination enabled with no output file specified.")

            if adf:
               log.info("Setting output format to PDF for ADF mode.")
               output = utils.createSequencedFilename("hpscan", ".pdf")
               output_type = 'pdf'
            else:
               if scan_mode == 'gray':
                  log.info("Setting output format to PNG for greyscale mode.")
                  output = utils.createSequencedFilename("hpscan", ".png")
                  output_type = 'png'
               else:
                  log.info("Setting output format to JPEG for color/lineart mode.")
                  output = utils.createSequencedFilename("hpscan", ".jpg")
                  output_type = 'jpeg'

            log.warn("Defaulting to '%s'." % output)

        else:
            try:
               output_type = os.path.splitext(output)[1].lower()[1:]
               if output_type == 'jpg':
                  output_type = 'jpeg'
            except IndexError:
               output_type = ''

----------------------------------------

To get PNG files in colour mode I *have to* specify an output filename with .png extension manually.

The -x/--compression option has virtually no effect, because the output filename solely relies on either the -o option or the -m option.

In the above code this:

----------------------------------------

               if scan_mode == 'gray':
                  log.info("Setting output format to PNG for greyscale mode.")
                  output = utils.createSequencedFilename("hpscan", ".png")
                  output_type = 'png'
               else:
                  log.info("Setting output format to JPEG for color/lineart mode.")
                  output = utils.createSequencedFilename("hpscan", ".jpg")
                  output_type = 'jpeg'

----------------------------------------

should be changed so something like this

----------------------------------------

               if scanner_compression == 'jpeg':
                  log.info("Setting output format to JPEG.")
                  output = utils.createSequencedFilename("hpscan", ".jpg")
                  output_type = 'jpeg'
               else:
                  log.info("Setting output format to PNG.")
                  output = utils.createSequencedFilename("hpscan", ".png")
                  output_type = 'png'

----------------------------------------

Which I have tested and works.

Revision history for this message
luke (jlw) wrote :
Revision history for this message
srinivas (srinivas5) wrote :

Hi Luke,

Thanks for your analysis. we will try to incorporate your suggestions on the compression(-x) in our future releases.
Yes currently we should specify the hp-scan command in the below way to get respective output file formats.
hp-scan --adf --mode=color/gray --filetype=png/jpg/pdf

Thanks,
Srinivas Teja.

srinivas (srinivas5)
Changed in hplip:
status: New → In Progress
Revision history for this message
Bill Yikes (yik3s) wrote :

Just wanted to say I was stung by this bug despite a patch submission 6 years ago. I’m running version 3.22.10 and it’s still a disaster. It behaves just as Luke described.

The docs are also still inconsistent with the behaviour, man page as well as this web doc:

https://developers.hp.com/hp-linux-imaging-and-printing/tech_docs/man_pages/scan?language=zh-hans

In the very least there should be a loud “KNOWN BUGS” section added to the docs until it gets fixed so other people don’t waste too much time in frustration.

Revision history for this message
luke (jlw) wrote :

It's been a while since I posted this. Unfortunate that this is still in there.

From what I remember what I posted completely fixes it as well. It's a really minor thing. Just needs to be changed in the code. Would be good if someone with the permissions could actually do that now.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.