SimulPiscator / AirSane

Publish SANE scanners to MacOS, Android, and Windows via Apple AirScan.
GNU General Public License v3.0
247 stars 26 forks source link

different scan behaviour in AIC (simple vs advanced options) #40

Closed meiser79 closed 3 years ago

meiser79 commented 3 years ago

Hi,

I see a different behaviour in AIC if I scan with simple options or advanced options. There is a part missing at the top of the page. I own a Brother DCP-1510 which uses the brother4 SANE driver (deb package version 0.4.9-1), running on Ubuntu 20.04.

Looking at the debug output, [tl-y] = 64.994mm is set when using the advanced options, this is not the case in "simple mode".

airsaned-log.txt Scan AIC simple options.png Scan AIC advanced options.pdf

Here are the AIC advanced options settings: Scan AIC settings.pdf

BTW, everything works fine when scanning via the web interface or the Android Mopria app.

Thanks in advance for having a look. Best regards, meiser

SimulPiscator commented 3 years ago

This is really strange behavior. If you know how to use wireshark, could you check the scan ticket that Image Capture sends? Does it contain a non-zero YOffset setting?

Regards, Simul

meiser79 commented 3 years ago

You're right, Image Capture sends YOffset = 762 when using advanced options, but YOffset = 0 for simple options.

BTW, I'm on macOS 10.15.7 with AIC 8.0 (1106).

SimulPiscator commented 3 years ago

I'm using the same OS version and I'm not experiencing the behavior you describe (using a Canon LiDE60 as scanner). What happens if you set the scan rectangle to "manual", do a scan an then switch back to "auto/A4"?

meiser79 commented 3 years ago

Doesn't help, there's always a YOffset. Does the brother4 SANE driver maybe report something which AIC uses for offset calculation?

meiser79 commented 3 years ago

My temporary solution is to modify "top = settings.getNumber("YOffset") - 762," in server/scanjob.cpp to remove the YOffset. With this change I can scan full pages and manual selections in AIC, but it breaks other applications.

meiser79 commented 3 years ago

My temporary solution is not okay as it breaks too much. Do you have an idea why this happens? Where could I start to investigate the issue?

SimulPiscator commented 3 years ago

You might check the ScannerCapabilities document that AirSane sends to AIC when opening the scanner. There, dimensions and minimum values for top and left position are communicated. AirSane uses the SANE minimum values for tr_x and tr_y for this. Maybe those minimum values are not filled in correctly by the brother backend?

meiser79 commented 3 years ago

These are the ScannerCapabilities sent by AirSane:

<?xml version='1.0' encoding='UTF-8'?>
<scan:ScannerCapabilities xmlns:pwg='http://www.pwg.org/schemas/2010/12/sm' xmlns:scan='http://schemas.hp.com/imaging/escl/2011/05/03'>
<pwg:Version>2.0</pwg:Version>
<pwg:MakeAndModel>Brother DCP-1510</pwg:MakeAndModel>
<scan:UUID>9b75a7c2-3c20-5450-8422-ff0c3ca0adca</scan:UUID>
<scan:AdminURI>http://server.local:8090/eSCL</scan:AdminURI>
<scan:IconURI>http://server.local:8090/eSCL/ScannerIcon</scan:IconURI>
<scan:Platen>
<scan:PlatenInputCaps>
<scan:MinWidth>0</scan:MinWidth>
<scan:MinHeight>0</scan:MinHeight>
<scan:MaxWidth>2503</scan:MaxWidth>
<scan:MaxHeight>4200</scan:MaxHeight>
<scan:MaxPhysicalWidth>2503</scan:MaxPhysicalWidth>
<scan:MaxPhysicalHeight>4200</scan:MaxPhysicalHeight>
<scan:MaxScanRegions>1</scan:MaxScanRegions>
<scan:SettingProfiles>
<scan:SettingProfile name='0'>
<scan:ColorModes>
<scan:ColorMode>Grayscale8</scan:ColorMode>
<scan:ColorMode>RGB24</scan:ColorMode>
</scan:ColorModes>
<scan:ColorSpaces>
<scan:ColorSpace>RGB</scan:ColorSpace>
</scan:ColorSpaces>
<scan:SupportedResolutions>
<scan:DiscreteResolutions>
<scan:DiscreteResolution>
<scan:XResolution>100</scan:XResolution>
<scan:YResolution>100</scan:YResolution>
</scan:DiscreteResolution>
<scan:DiscreteResolution>
<scan:XResolution>150</scan:XResolution>
<scan:YResolution>150</scan:YResolution>
</scan:DiscreteResolution>
<scan:DiscreteResolution>
<scan:XResolution>200</scan:XResolution>
<scan:YResolution>200</scan:YResolution>
</scan:DiscreteResolution>
<scan:DiscreteResolution>
<scan:XResolution>300</scan:XResolution>
<scan:YResolution>300</scan:YResolution>
</scan:DiscreteResolution>
<scan:DiscreteResolution>
<scan:XResolution>400</scan:XResolution>
<scan:YResolution>400</scan:YResolution>
</scan:DiscreteResolution>
<scan:DiscreteResolution>
<scan:XResolution>600</scan:XResolution>
<scan:YResolution>600</scan:YResolution>
</scan:DiscreteResolution>
<scan:DiscreteResolution>
<scan:XResolution>1200</scan:XResolution>
<scan:YResolution>1200</scan:YResolution>
</scan:DiscreteResolution>
<scan:DiscreteResolution>
<scan:XResolution>2400</scan:XResolution>
<scan:YResolution>2400</scan:YResolution>
</scan:DiscreteResolution>
<scan:DiscreteResolution>
<scan:XResolution>4800</scan:XResolution>
<scan:YResolution>4800</scan:YResolution>
</scan:DiscreteResolution>
<scan:DiscreteResolution>
<scan:XResolution>9600</scan:XResolution>
<scan:YResolution>9600</scan:YResolution>
</scan:DiscreteResolution>
</scan:DiscreteResolutions>
</scan:SupportedResolutions>
<scan:DocumentFormats>
<pwg:DocumentFormat>application/pdf</pwg:DocumentFormat>
<pwg:DocumentFormat>image/jpeg</pwg:DocumentFormat>
<pwg:DocumentFormat>image/png</pwg:DocumentFormat>
</scan:DocumentFormats>
</scan:SettingProfile>
</scan:SettingProfiles>
<scan:SupportedIntents>
<scan:SupportedIntent>Preview</scan:SupportedIntent>
<scan:SupportedIntent>TextAndGraphic</scan:SupportedIntent>
<scan:SupportedIntent>Photo</scan:SupportedIntent>
</scan:SupportedIntents>
</scan:PlatenInputCaps>
</scan:Platen>
</scan:ScannerCapabilities>

And AIC sends in the ScanJobs POST:

<?xml version="1.0" encoding="UTF-8"?><scan:ScanSettings xmlns:scan="http://schemas.hp.com/imaging/escl/2011/05/03" xmlns:pwg="http://www.pwg.org/schemas/2010/12/sm"><pwg:Version>2.0</pwg:Version><scan:Intent>TextAndGraphic</scan:Intent><pwg:ScanRegions pwg:MustHonor="true"><pwg:ScanRegion><pwg:ContentRegionUnits>escl:ThreeHundredthsOfInches</pwg:ContentRegionUnits><pwg:Width>2448</pwg:Width><pwg:Height>3436</pwg:Height><pwg:XOffset>0</pwg:XOffset><pwg:YOffset>764</pwg:YOffset></pwg:ScanRegion></pwg:ScanRegions><pwg:DocumentFormat>image/jpeg</pwg:DocumentFormat><pwg:InputSource>Platen</pwg:InputSource><scan:ColorMode>RGB24</scan:ColorMode><scan:XResolution>150</scan:XResolution><scan:YResolution>150</scan:YResolution></scan:ScanSettings>

SimulPiscator commented 3 years ago

There is nothing suspicious about these ScannerCapabilities. I have absolutely no idea why AIC is scanning with an offset as you describe.

Have you tried deleting AIC preferences?

Library/Preferences/com.apple.AirScanScanner.plist
Library/Preferences/com.apple.ImageCapture2.plist
Library/Preferences/com.apple.ImageCaptureApp.plist
Library/Preferences/com.apple.Image_Capture.plist

Also, if you create a persistent scanner object using "Printers and Scanners", and then use the Preview App's "Import from Scanner", do you get the same behavior?

meiser79 commented 3 years ago

Deleting the settings doesn't change the behaviour. And Preview behaves exactly the same as AIC. No offset with simple options, offset with advanced options.

meiser79 commented 3 years ago

Just to verify if my macOS installation is broken, I tried the same in a macOS virtual machine (VMware Fusion). I see the exact same behaviour.

SimulPiscator commented 3 years ago

I've never observed this behavior with the SANE test backend, or the genesys backend. Sorry to say, I have no further idea what might be the reason for your problem.

meiser79 commented 3 years ago

I guess, I found the "bug".

server:~$ scanimage -d "brother4:bus1;dev2" -A
Output format is not set, using pnm as a default.
scanimage: rounded value of br-x from 211.9 to 211.881
scanimage: rounded value of br-y from 355.6 to 355.567

All options specific to device `brother4:bus1;dev2':
  Mode:
    --mode Black & White|Gray[Error Diffusion]|True Gray|24bit Color|24bit Color[Fast] [24bit Color[Fast]]
        Select the scan mode
    --resolution 100|150|200|300|400|600|1200|2400|4800|9600dpi [200]
        Sets the resolution of the scanned image.
    --source FlatBed [FlatBed]
        Selects the scan source (such as a document-feeder).
    --brightness -50..50% (in steps of 1) [inactive]
        Controls the brightness of the acquired image.
    --contrast -50..50% (in steps of 1) [inactive]
        Controls the contrast of the acquired image.
  Geometry:
    -l 0..211.9mm (in steps of 0.0999908) [0]
        Top-left x position of scan area.
    -t 0..355.6mm (in steps of 0.0999908) [0]
        Top-left y position of scan area.
    -x 0..211.9mm (in steps of 0.0999908) [211.881]
        Width of scan-area.
    -y 0..355.6mm (in steps of 0.0999908) [355.567]
        Height of scan-area.

The brother4 backend shows 211.881x355.567 mm for maxWidth and maxHeight. But it should be 210x297 mm for A4.

That's why AirSane sends 2503x4200 px in the ScannerCapabilities instead of 2480x3508 px.

So AIC somehow thinks that it has to reduce the height by 64.994mm.

Would it be possible to add parameters for the options.conf to specify maxWidth and maxHeight manuelly?

meiser79 commented 3 years ago

Even if I change br_x.max() and br_y.max() to 210 and 297, AIC sets tl_y to 6 mm. Why???

sane_open(brother4:bus1;dev2) -> 0x7f4528013cb0
[mode] := "24bit Color" -> reload options
[source] := "FlatBed"
[resolution] := 100dpi
[tl-x] := 0mm
[tl-y] := 6mm
[br-x] := 207mm
[br-y] := 297mm
sane_start(0x7f4528013cb0) with options:
[br-x] = 206.981mm
[br-y] = 296.973mm
[mode] = "24bit Color"
[resolution] = 100dpi
[source] = "FlatBed"
[tl-x] = 0mm
[tl-y] = 5.99945mm