Skip to content

Fix SANE custom page size scan failure and improve invalid parameter …#842

Open
kovacsbv wants to merge 1 commit into
cyanfish:masterfrom
kovacsbv:master
Open

Fix SANE custom page size scan failure and improve invalid parameter …#842
kovacsbv wants to merge 1 commit into
cyanfish:masterfrom
kovacsbv:master

Conversation

@kovacsbv

Copy link
Copy Markdown

…error message

  • Fix PageAlign switch in SaneScanDriver.SetOptions where HorizontalAlign.Left and HorizontalAlign.Right cases were swapped, causing non-zero offsetX values for Left-aligned profiles that pushed the scan area to the right edge of the bed. For small custom page sizes (e.g. 3x5 cards) this produced a tl-x value outside the valid range for the configured page-width, causing sane_start to return SaneStatus.Invalid and NAPS2 to report 'scanner is offline'.

  • Replace the TODO at SaneScanDriver line 318 with DeviceInvalidParameterException. SaneStatus.Invalid at that point originates from sane_start (SaneOptionController .TrySet handles its own exceptions internally and never propagates them), so it indicates rejected scan parameters rather than a connectivity failure. This also prevents ScanController's device re-query logic from firing unnecessarily on parameter errors.

  • Add DeviceInvalidParameterException to DeviceException.cs with a user-facing message directing users to check page size, alignment, and resolution settings.

  • Add geometry debug log in SetOptions after SetArea is called, recording tl-x, tl-y, br-x, br-y, width, and height values for diagnostic purposes.

Note: SdkResources.Designer.cs was manually updated as ResGen is not available on Linux. The new DeviceInvalidParameter string should be added to translate.naps2.com for localization.

…error message

- Fix PageAlign switch in SaneScanDriver.SetOptions where HorizontalAlign.Left
  and HorizontalAlign.Right cases were swapped, causing non-zero offsetX values
  for Left-aligned profiles that pushed the scan area to the right edge of the
  bed. For small custom page sizes (e.g. 3x5 cards) this produced a tl-x value
  outside the valid range for the configured page-width, causing sane_start to
  return SaneStatus.Invalid and NAPS2 to report 'scanner is offline'.

- Replace the TODO at SaneScanDriver line 318 with DeviceInvalidParameterException.
  SaneStatus.Invalid at that point originates from sane_start (SaneOptionController
  .TrySet handles its own exceptions internally and never propagates them), so it
  indicates rejected scan parameters rather than a connectivity failure. This also
  prevents ScanController's device re-query logic from firing unnecessarily on
  parameter errors.

- Add DeviceInvalidParameterException to DeviceException.cs with a user-facing
  message directing users to check page size, alignment, and resolution settings.

- Add geometry debug log in SetOptions after SetArea is called, recording tl-x,
  tl-y, br-x, br-y, width, and height values for diagnostic purposes.

Note: SdkResources.Designer.cs was manually updated as ResGen is not available
on Linux. The new DeviceInvalidParameter string should be added to
translate.naps2.com for localization.
@cyanfish

Copy link
Copy Markdown
Owner

If this fixes your issue then you should just be able to switch "Horizontal Align" to "Right" in your profile (which is the default) to fix the problem.

The left v right delineation is arguably weird, but it depends what perspective you're looking at it from (e.g. for a flatbed scanner, are you looking top down, or from the perspective of the paper). In any case it's been this way for 13 years and it can't be changed without breaking/confusing everyone else.

@kovacsbv

Copy link
Copy Markdown
Author

Perhaps the best way would be to have a new setting such as "reverse alignment" that defaults to the old way, but allows everyone else to do what makes sense. I put in 3"x5" left-aligned and get "printer disconnected"? Something still has to change.

@kovacsbv

kovacsbv commented Jul 1, 2026

Copy link
Copy Markdown
Author

Closes #838

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants