Menu ▾ ▴

#446 Wrong page resolution when backend has inactive x-resolution/y-resolution options (300 dpi scan saved as A6)

v1.0_(example)
closed-fixed
nobody
None
5
4 days ago
4 days ago
No

Version: gscan2pdf 2.13.5 (Ubuntu package 2.13.5-3), SANE 1.4.0, backend epsonscan2 (Epson ET-2710). The code below is unchanged on current master (0088b63).

Steps:

Scan an A4 page at 600 dpi, save as PDF → correct (7015×4960 px image, A4 page).
Change resolution to 300 dpi, scan another A4 page, save as PDF.
Expected: A4 page (842×595 pt) with the image at 300 ppi.

Actual: the image has 3507×2480 px (300 dpi worth of A4 pixels) but is embedded at 600 ppi, so the page is 421×298 pt (A6):

$ pdfimages -list scan.pdf
page num type width height color comp bpc enc interp object ID x-ppi y-ppi
1 0 image 3507 2480 gray 1 8 image no 13 0 600 600
$ pdfinfo scan.pdf | grep "Page size"
Page size: 420.84 x 297.6 pts (A6)
In the scan dialog, "Resolution" was 300, and the backend's separate "X Resolution" / "Y Resolution" options were inactive (greyed out), showing 50.

Cause: get_xy_resolution in Gscan2pdf/Dialog/Scan.pm treats the x-resolution and y-resolution options as present even when they are inactive. epsonscan2 always exposes them as inactive, so instead of returning the live resolution value the function takes the "resolution plus x/y" branch and reads the value from current-scan-options. That value can be stale (here, the previous scan's 600). Elsewhere in the code, inactive options are skipped via SANE_CAP_INACTIVE.

Suggested fix: ignore inactive x/y options, so that with only resolution active its live value is used:

--- a/lib/Gscan2pdf/Dialog/Scan.pm
+++ b/lib/Gscan2pdf/Dialog/Scan.pm
@@ sub get_xy_resolution {
my $resolution = $options->by_name(SANE_NAME_SCAN_RESOLUTION);
my $x = $options->by_name('x-resolution');
my $y = $options->by_name('y-resolution');
if ( defined $resolution ) { $resolution = $resolution->{val} }

  • if ( defined $x ) { $x = $x->{val} }
  • if ( defined $y ) { $y = $y->{val} }
  • $x = defined $x && !( $x->{cap} & SANE_CAP_INACTIVE ) ? $x->{val} : undef;
  • $y = defined $y && !( $y->{cap} & SANE_CAP_INACTIVE ) ? $y->{val} : undef;

Discussion

  • Jeffrey Ratcliffe

    I am about to deprecate gscan2pdf as scantpaper is stable. Please test: https://github.com/carygravel/scantpaper

     
  • nuncaeslupus

    nuncaeslupus - 4 days ago

    D'Oh!

    Thank you! I'll try it! :-)

     
  • nuncaeslupus

    nuncaeslupus - 4 days ago

    I tried scantpaper 3.0.24 from the PPA on Ubuntu 26.04 with an Epson ET-2710 (epsonscan2): scanning fails with “scan_pages: Invalid argument”. It looks like the snap() issue your Fedora/openSUSE packages patch in python3-sane (python-pillow/Sane PR 109), but the PPA uses Ubuntu’s unpatched python3-sane 2.9.2. Could the PPA ship the patched python3-sane too?

    Claude fixed it for me, so this clearly works. Thanks again, great tool!

     
  • Jeffrey Ratcliffe

    Thanks for the feedback. I can certainly ship the patch in the PPA. I would prefer to upstream it, though, but the python3-sane maintainers seem to be ghosting me. If you can add your voice to the bug report and pull request, perhaps you can help change that.

     
  • Jeffrey Ratcliffe

    • status: open --> closed-fixed
     

Log in to post a comment.