OpenPrinting / cups-filters

filters, backends, driverless utility, ... - Everything which CUPS 2.x needs to be used on non-Mac systems
Apache License 2.0
155 stars 125 forks source link

rastertolabel uncontrollably dithering.... #221

Open snarke opened 4 years ago

snarke commented 4 years ago

IMG_2839 It seems likely that the rastertolabel filter is often involved in printing bar codes. Many shipping labels these days are being generated in the cloud/web/remotely, and are arriving as pdf-encapsulated raster images. A very common problem with people using Zebra printers is having the bar codes seriously corrupted, and printing all "fuzzy." I believe this is caused when a 300dpi or 150dpi raster bar code is scaled to the 203dpi native resolution of some (many?) Zebra printers. This results in gray-scale intermediate pixels which then get dithered. Dithered! Aiiieee! I'm almost certain it's not the printer itself that's dithering, so it's happening somewhere else in the CUPS chain, and all of us trying to print bar codes desperately need to make it stop doing that! Yes, even if the image gets posterized, or threshold dithered, or whatever you want to call it, the resulting bar code might still be out of spec and difficult to scan. Nevertheless, it's likely to be better than the fuzzy mess we see now. I've dug through all kinds of CUPS documentation; I have no idea where the dithering is getting done, or how to stop it, but it seems like it ought to be fairly easy for somebody who understands CUPS to fix/amend?

zdohnal commented 4 years ago

Hi Dave,

the rastertolabel filter is part of original CUPS project, not cups-filters. Please file the issue at https://github.com/apple/cups/issues .

tillkamppeter commented 4 years ago

Could you attach a sample PDF file for tests? Thanks.

tillkamppeter commented 4 years ago

@michaelrsweet, is there a way to let label printers with their CUPS drivers (and the filters of cups-filters) print in a dither-free black-and-white mode? Dither-free means that we take a 1-bit-monochrome destination color space and for each pixel we let the pixwl get black if the input luminance value (or simply input grayscale value) is darker than a certain threshold and white when it is lighter than this threshold. A dark blue or dark gray bar code will come out as deep black, a light gray background will not turn into white with a grid of dots but completely white.

michaelrsweet commented 4 years ago

@tillkamppeter That functionality is offered by LPrint. It could also be supported by rastertolabel - it just needs to ask for grayscale and then do a threshold dither - but I never bothered implementing it there.

For cups-filters, if you support the print-color-mode option with the value 'bi-level', then that can trigger a threshold dithering mode for 1-bit raster output.

tillkamppeter commented 4 years ago

Thanks, @michaelrsweet. @snarke, the drivers you are using are deprecated and replaced by @michaelrsweet's LPrint. Lprint supports printing jobs in said dither-free mode, called bi-level. You need to use the option "-o print-color-mode=bi-level". See LPrint's documentation.

tillkamppeter commented 4 years ago

@michaelrsweet, is there a CUPS color space (CUPSCSPACE... in /usr/include/cups/raster.h) reserved for bi-level?

michaelrsweet commented 4 years ago

@tillkamppeter No, 'bi-level' is not a color space, it is a color mode.

frazhome commented 3 years ago

@snarke which version of cups are you using? Did you have seen https://github.com/apple/cups/issues/5092

snarke commented 3 years ago

I hadn't seen it. I can't tell if there's an actual solution in that discussion or not, aside from michaelrsweet's statement about how it maybe needs to be solved outside of CUPS, which I'm guessing is where LPrint came from. I see LPrint still uses CUPS, and wants 2.2.0 or higher. To answer your question, I'm currently running MacOS 10.11, which uses CUPS 2.1.0. Of course. (sigh)

OTOH, a label I printed this week from stamps.com came out perfect. Now I need to figure out if it's something specific to stamps.com, or if something updated in my system somewhere . . . .

arthare commented 3 years ago

@snarke Check the bit depth of the image. I was fighting this issue today and eventually discovered that 1-bit BMPs from MSPaint printed quite nicely, but 8-bit-per-channel PNGs got the dithering and were unreadable. Likely CUPs is internally saying "sending an 8-bit image to your B&W thermal printer? I'll help you out by dithering it". By sending 1-bit, it avoids the dither.

Since I'm authoring my own image pipeline to build my barcodes, it was easy for me to save to 1-bit BMPs and send those to the zebra. It's possible stamps.com is authoring 1-bit images?

davids74 commented 1 year ago

I found a workaround. Believe it or not but the barcodes in labels are indeed blurry. Try and zoom it, you will see that text is crisp and barcode has grey shades around bars. I am talking about Royal Mail labels here. I have been bashing my head about this issue for ages to the level where I had Windows XP in VirtualBox just for label printing.

Soo, what is the workaround. My desktop motherboard got fried and I am stuck now with this old Intel NUC with OSX El Capitan on it. Installed cups drivers and started to have the problem with dithering obviously.

Soo what can you do about it is open the Click and Drop label in Preview, export it as PNG at 203dpi or whatever your printer does (mine is GK420d) open it in Preview again and go to Tools > Adjust Colour and max out the first four sliders and set the fifth to zero.

It is so cool, I am so happy. Surely this can be automated.

Screen Shot 2023-06-30 at 11 31 56

zougloub commented 7 months ago

With label printers having different resolutions (8 dots/mm aka 203 dpi mostly or 300 dpi) there's no way to properly align a barcode so it is optimal for everyone ; having large bar code modules is a reasonable solution. I have seen North American shipping labels (USPS, UPS, FedEx, Purolator, Canada Post) and shipping labels and e-stamps from France's La Poste, and they were pretty much all readable from 203 or 300 dpi prints.

Of course things would look prettier if different dpi versions of e-stamps / labels were offered by transporters.

If you're a maniac like me you can post-process your shipping labels to adjust the barcode locations and scales so they're pixel-perfect, and try various half-toning algorithms...

michaelrsweet commented 7 months ago

@zougloub The latest release of LPrint (the replacement for this driver) has an improved dithering algorithm that produces clean bar codes.