Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Black and white scan uses JPEG image (on Brother scanner) #48

Open
cbertelli opened this issue Jan 14, 2025 · 8 comments
Open

Black and white scan uses JPEG image (on Brother scanner) #48

cbertelli opened this issue Jan 14, 2025 · 8 comments

Comments

@cbertelli
Copy link

Scanning in black and white (using -mono) with my Brother MFC produces very big files. If I extract images with pdfimages, I see these are JPEG images.
When scanning with -tiff the size is small even if converted to pdf.
Is this a bug? Is it specific to my printer-scanner? Can I use this tiff image to output pdf files instead of piping them to an external program?

@klep
Copy link
Owner

klep commented Jan 14, 2025

Interesting. How big are we talking? Are you saying that the file size with -mono is larger than the file size without the option?

On my Brother MFC scanner, scanning a business card with scanline -flatbed -mono yields a 74k PDF. It's about the same without -mono.

Have you tried specifying -resolution as well? The default is 150, but maybe that's higher than what you need?

@cbertelli
Copy link
Author

How big are we talking? Are you saying that the file size with -mono is larger than the file size without the option?

Yes, the standard pdf output is 660KB, while the tiff -> pdf size is around 57KB (an A4 page with a big white space).
I used -resolution 200, a little more than you. I used an MFC-7460N.

@klep
Copy link
Owner

klep commented Jan 14, 2025

660kb for a single page? What's the size without -mono?

@cbertelli
Copy link
Author

Sorry for the long delay, I was out of office. I tried, the size was 469 KB (at 200 dpi). 24 bit images compress better than 8 bit images in JPEG. I think this is due to a wrong strategy inside the Brother MFC. Can you interfere with it?

@klep
Copy link
Owner

klep commented Jan 21, 2025

By "wrong strategy", do you mean that when the scanner is instructed to scan in mono, it's also scanning at the wrong pixel depth? FWIW, I'm attempting to specify both in ScannerController.swift:

        if configuration.config[ScanlineConfigOptionMono] != nil {
            functionalUnit.pixelDataType = .BW
            functionalUnit.bitDepth = .depth1Bit
        } else {
            functionalUnit.pixelDataType = .RGB
            functionalUnit.bitDepth = .depth8Bits
        }

I can potentially get more info if you can send me the output of scanline -verbose -mono, but looking at the output from my MFC-L3770CDW, I'm noticing that I don't output the actual content of the list of supported resolutions and bit depths:

didSelectFunctionalUnit: ICScannerFunctionalUnitFlatbed <0x600000ce28e0>:
  pixelDataType                            : ICScannerPixelDataTypeBW
  supportedBitDepths                       : <NSMutableIndexSet: 0x600000ce28c0>[number of indexes: 2 (in 2 ranges), indexes: (1 8)]
  bitDepth                                 : 1
  supportedDocumentTypes                   : <NSMutableIndexSet: 0x600000ce2960>[number of indexes: 49 (in 11 ranges), indexes: (1-3 5 7-8 10 13 15-16 22-25 29-33 39-43 48-65 72-78)]
  documentType                             : 3
  physicalSize                             : [width = 8.50 inches, height = 11.69 inches]
  measurementUnit                          : 0
  supportedResolutions                     : <NSMutableIndexSet: 0x600000ce2920>[number of indexes: 4 (in 4 ranges), indexes: (100 200 300 600)]
  preferredResolutions                     : <NSMutableIndexSet: 0x600000ce2920>[number of indexes: 4 (in 4 ranges), indexes: (100 200 300 600)]
  resolution                               : 200
  overviewResolution                       : 200
  supportedScaleFactors                    : <NSMutableIndexSet: 0x600000ce29a0>[number of indexes: 1 (in 1 ranges), indexes: (100)]
  preferredScaleFactors                    : <NSMutableIndexSet: 0x600000ce29a0>[number of indexes: 1 (in 1 ranges), indexes: (100)]
  scaleFactor                              : 100
  acceptsThresholdForBlackAndWhiteScanning : NO
  usesThresholdForBlackAndWhiteScanning    : NO
  thresholdForBlackAndWhiteScanning        : 0
  templates                                : (null)
  vendorFeatures                           : (
)

@cbertelli
Copy link
Author

Sorry, I didn't notice your message. Here is the log:

$ scanline -verbose -mono skn
Browsing for scanners.
Waiting up to 10.0 seconds to find scanners
Added device: {
    UUIDString = "C7C45161-C7C4-5161-C7C4-5161C7C45161";
    autolaunchApplicationPath = "";
    class = ICScannerDevice;
    connectionID = 0x00000000;
    delegate = "<0x0>";
    deviceID = 0x00000000;
    deviceRef = 0x10000166;
    iconPath = "(null)";
    locationDescription = "Brother MFC-7460DN";
    moduleExecutableArchitecture = 0;
    modulePath = "/Library/Image Capture/Devices/Brother Scanner.app";
    moduleVersion = "1.0";
    name = "Brother MFC-7460DN";
    persistentIDString = "C7C45161-C7C4-5161-C7C4-5161C7C45161";
    shared = NO;
    softwareInstallPercentDone = "0.000000";
    transportType = ICTransportTypeTCPIP;
    type = 0x00000402;
}  availableFunctionalUnitTypes  : 
  selectedFunctionalUnit        : (null) <0x0>
  transferMode                  : ICScannerTransferModeFileBased
  downloadsDirectory            : file:///Users/carlo/Pictures/
  documentName                  : Scan
  documentUTI                   : public.tiff

Done searching for scanners
Found scanner: Brother MFC-7460DN
Opening session with scanner
Added device: {
    UUIDString = "53395659-0323-3080-0000-000000000000";
    autolaunchApplicationPath = "";
    class = ICScannerDevice;
    connectionID = 0x00000000;
    delegate = "<0x0>";
    deviceID = 0x00000000;
    deviceRef = 0x10000168;
    iconPath = "(null)";
    locationDescription = "EPSON WF-7620 Series";
    moduleExecutableArchitecture = 0;
    modulePath = "/Library/Image Capture/Devices/EPSON Scanner.app";
    moduleVersion = "1.0";
    name = "EPSON WF-7620 Series";
    persistentIDString = "53395659-0323-3080-0000-000000000000";
    shared = NO;
    softwareInstallPercentDone = "0.000000";
    transportType = ICTransportTypeTCPIP;
    type = 0x00000402;
}  availableFunctionalUnitTypes  : 
  selectedFunctionalUnit        : (null) <0x0>
  transferMode                  : ICScannerTransferModeFileBased
  downloadsDirectory            : file:///Users/carlo/Pictures/
  documentName                  : Scan
  documentUTI                   : public.tiff

didOpenSessionWithError: [no error]
deviceDidBecomeReady
didSelectFunctionalUnit:  error: [no error]
didSelectFunctionalUnit: ICScannerFunctionalUnitDocumentFeeder <0x600001ef6ca0>:
  supportedBitDepths      : <NSMutableIndexSet: 0x600001ef7180>[number of indexes: 2 (in 2 ranges), indexes: (1 8)]
  bitDepth                : 8
  supportedDocumentTypes  : <NSMutableIndexSet: 0x600001ef6e40>[number of indexes: 6 (in 2 ranges), indexes: (1-5 10)]
  documentType            : 1
  measurementUnit         : 1
  supportedResolutions    : <NSMutableIndexSet: 0x600001ef7060>[number of indexes: 6 (in 6 ranges), indexes: (100 150 200 300 400 600)]
  preferredResolutions    : <NSMutableIndexSet: 0x600001ef7060>[number of indexes: 6 (in 6 ranges), indexes: (100 150 200 300 400 600)]
  resolution              : 150
  supportedScaleFactors   : <NSMutableIndexSet: 0x600001ef6d60>[number of indexes: 1 (in 1 ranges), indexes: (100)]
  preferredScaleFactors   : <NSMutableIndexSet: 0x600001ef6d60>[number of indexes: 1 (in 1 ranges), indexes: (100)]
  scaleFactor             : 100
  supportsDuplexScanning  : NO
  duplexScanningEnabled   : NO
  vendorFeatures          : (null)
  state                   : 0x00000001
 error: [no error]
Configuring scanner
Configuring Document Feeder
Starting scan...
didScanTo file:///var/folders/bs/jy_ww7jn0gdd778nw96_pynr0000gn/T/Scan%202.jpeg
didCompleteScanWithError [no error]
Output path: /Users/carlo/Documents/Archive/skn/2025
About to copy file:///var/folders/bs/jy_ww7jn0gdd778nw96_pynr0000gn/T//scan.pdf to /Users/carlo/Documents/Archive/skn/2025/scan_085556.pdf
Done

The wrong strategy is inside the scanner software, as it scans black and white in JPEG. Don't you think so?

@cbertelli
Copy link
Author

It's maybe useful to say that the output (PDF containing a monochrome JPEG) is 253248 bytes, the corresponding G3 compressed TIFF is 37088 bytes (via pdfimages -all and imagemagick) while the resulting PDF (via tiff2pdf) is 21613 bytes. The visual comparison at 400% enlargement shows no difference.

@cbertelli
Copy link
Author

I see scanline uses /Library/Image Capture/Devices/Brother Scanner.app and I see the internal option (via GUI) "mono" is not black and white, while the true black and white is called "text". Is it relevant?

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

No branches or pull requests

2 participants