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

Update label printer drivers to use threshold dithering #5092

Closed
gqbgqb opened this issue Aug 23, 2017 · 23 comments
Closed

Update label printer drivers to use threshold dithering #5092

gqbgqb opened this issue Aug 23, 2017 · 23 comments
Assignees
Labels
enhancement New feature or request

Comments

@gqbgqb
Copy link

gqbgqb commented Aug 23, 2017

We currently have an issue printing PDF (with or without scaling) where the output is fuzzy/not good of quality (refer to attached files). We don't have this issue in Ubuntu (CUPS 1.7.2/ver 14.04/64-bit and CUPS 2.2.2/ver 17.04/32-bit) using the same PDF, printer and drivers.

I also couldn't find anything in the logs which might relate to this. I hope someone could advice me where to look. I can't figure if its Apple or CUPS issue.

Environment/Setup: Mac OS X Sierra/CUPS 2.2.1/SATO CUPS driver/SATO WS408 printer

barcode

Thanks in advance.

@mwibeck
Copy link

mwibeck commented Aug 24, 2017

Hi.
I have some additional information. I work at the same company as gqbgqb and have also been investigating the issue.
The issue is that gcpdftoraster (and pdftoraster) adds noise to the image parts of the pdf that is very visible on a low resolution monochrome device, such as a label printer.

Attached are files showing the issue

  • testprint.pdf, original PDF.
  • rasterview_ppd.txt, ppd to be used with maketestfiles.sh from the test-directory of https://github.com/michaelrsweet/rasterview
  • cgpdftoraster-K-1-Banded.ras, result of rendering the testprint.pdf via cgpdftoraster (MacOS Sierra 10.12.6)
  • pdftoraster-K-1-Banded.ras, result of rendering the testprint.pdf via pdftoraster
  • gstoraster-K-1-Banded.ras, result of rendering the testprint.pdf via gstoraster

pdftoraster and gstoraster were used on a Ubuntu 14.04, package info:
cups - 1.7.2-0ubuntu1.8
cups-filters - 1.0.52-0ubuntu1.7

*.ras files can be viewed with Rasterview (http://michaelrsweet.github.io/rasterview/)

If this is a cups-filters, CUPS, or Apple macOS issue I am not sure.
I find it a bit confusing to find out where different filters come from.

If anyone could figure out a workaround on macOS, that would be great..

Regards,
/Magnus Wibeck

testprint.pdf
result.zip
rasterview_ppd.txt

@michaelrsweet
Copy link
Collaborator

OK, so there are two issues:

  1. The driver is relying on the RIP to produce a B&W image, but asking for 1-bit K data produces dithered data. The driver should ask for 8-bit and use its own thresholding/dithering algorithm for consistent results.

  2. The embedded barcode image has interpolation enabled (or is grayscale with blurry edges), which tells cgpdftoraster (and more specifically CoreGraphics) that the image needs to effectively be blurred instead of kept B&W. Ghostscript also honors the interpolation hint in the PDF file.

So the fix here is to fix the PDF file and/or the driver.

@michaelrsweet michaelrsweet added the third-party This issue is in a third-party component label Aug 25, 2017
@isadon
Copy link

isadon commented Apr 3, 2018

I am also having this issue with a thermal printer on OS X High Sierra 10.13.4. Its great that you guys have identified the issue but what fix can we all implement to fix this problem?

@michaelrsweet
Copy link
Collaborator

@Donileo If the source barcode is embedded as a bitmap or uses a font, the fuzziness issues will not be present.

@isadon
Copy link

isadon commented Apr 3, 2018

@michaelrsweet Unfortunately I am not controlling the original output of the pdf's that I am trying to print. They are being generated in this example from a shipping courier service called Shippingeasy.com. But this same problem exists for shipping label pdfs generated by ebay, amazon essentially all the major selling platforms. They definitely are not using a font for the pdf and look to be images (though I can't tell if bitmap or JPEG or what format). When I open my pdfs and zoom to around 800-1000x the text definitely looks blurry so the entire pdf is an image not just the bar code section.
I am wondering if turning off interpolation on the pdf via some CLI or some property of the file itself may resolve the issue.

@michaelrsweet
Copy link
Collaborator

@Donileo Interpolation is turned off on macOS when ripping PDFs; if you can file a new issue and attach a sample PDF perhaps we can better determine a cross-platform fix for you...

@isadon
Copy link

isadon commented Apr 3, 2018

Hmm since I am unsure whether the issue is the interpolation here is my sample pdf that I send to print. I think my issue still applies to this topic, if not I'll move it to another issue.

sample-shipping.pdf

The output I get is essentially the same as in this issue except it applies to the entire print.

@isadon
Copy link

isadon commented Apr 3, 2018

I think this issue is also very pertinent: #4820

@michaelrsweet
Copy link
Collaborator

Ghostscript is the producer of this PDF, and they didn't set the proper rendering options so the barcode images are both interpolated and JPEG'd. Garbage-in, garbage-out... :/

Not sure what we can possibly do to improve things here...

@isadon
Copy link

isadon commented Apr 3, 2018

@michaelrsweet Can you explain how I can view the rendering options and the interpolation flag myself for future pdfs?

In regards to the pdf file being bad, on Windows with these drivers.
https://www.seagullscientific.com/drivers/printer-driver-features/?m=zebra+zp+450+ctp

Here are sample images of the printout on mac vs windows:
img_6566

Mac on the left, Windows on the right (using seagull drivers and no dithering). Particularly pay attention to how bad the barcode is on the mac side.

Though I agree the pdf file can be better. Why is Windows simply printing this same file better? I don't think the issue simply comes down to just the file not being the greatest output.

@mwibeck
Copy link

mwibeck commented Apr 4, 2018

What we ended up doing at SATO, since we cannot control user input, is that we added an 8-bit option to our drivers and let the filter have a threshold option, so that the image ends up 1-bit, but without dithering, just a simple threshold cutoff.
That will work for most labels with barcodes and text.

@isadon
Copy link

isadon commented Apr 4, 2018

@mwibeck Can you post how this would be done exactly? Not sure exactly how to do what you are saying.

@mwibeck
Copy link

mwibeck commented Apr 4, 2018

Unless you can rewrite the filter it is not possible afaik.
We added 8 bit grayscale as an option in the ppd, and then the filter looks at the options passed. If it is 8 bit, we generate a b&w image based on a threshold.

You're most welcome buying SATO printers instead... :-)

@michaelrsweet
Copy link
Collaborator

We could certainly update the rastertolabel driver to ask for 8-bit grayscale and then threshold dither the output; I'll see if I can prototype something with my Zebra printer...

@michaelrsweet michaelrsweet reopened this Apr 4, 2018
@michaelrsweet michaelrsweet self-assigned this Apr 4, 2018
@michaelrsweet michaelrsweet added enhancement New feature or request and removed third-party This issue is in a third-party component labels Apr 4, 2018
@michaelrsweet michaelrsweet added this to the CUPS 2.3.x milestone Apr 4, 2018
@michaelrsweet michaelrsweet changed the title Fuzzy printout in Mac OS X Update label printer drivers to use threshold dithering Apr 4, 2018
@isadon
Copy link

isadon commented Apr 4, 2018

@michaelrsweet Sounds great! Considering I can't just upgrade CUPS on OS X due to SIP I'm assuming I can just replace the rastertolabel filter and my Zebra ppd file and hopefully implement your changes?

Will these changes someday make it to OS X when Apple upgrades to the 2.3.x release?

@michaelrsweet
Copy link
Collaborator

@Donileo Filters and backends in /usr/libexec/cups aren't covered by SIP and can be updated.

As for what goes into future macOS releases, that's not something I can talk about or predict... :)

@isadon
Copy link

isadon commented Apr 8, 2018

@mwibeck Is there a way to communicate with you outside the scope of this issue? I acquired a SATO WS408DT printer but its just refusing to print anything but its own self calibrated output.

@irfkhan
Copy link

irfkhan commented Aug 15, 2018

I m not trying to piggyback on existing thread ,but also want to determine if this issue is related to what we are facing.

Attached PDF printed from old cups and new cups, notice the decimal point, its almost invisible.

I went through individual printers and when it goes through gstoraster is where things become so light and dithering comes in.

Scan_Doc0013.pdf
Scan_Doc0012.pdf
CCOAPRD Conc Req 799649710-Document-1.pdf

Unfortunately for end users the visibility of the quantity without decimal can be chaotic

I have also attached rasterized file

it was done using the command below

/usr/sbin/cupsfilter -p /etc/cups/ppd/NICK-T420-TEST-ZPL.ppd -m application/vnd.cups-raster /dbstage/dba/tmp2/799649710.pdf > irf.ras 2>log

@irfkhan
Copy link

irfkhan commented Aug 15, 2018

Notable part is quantity , there is a decimal in one scan and not in other

its definitely after raster filter

@michaelrsweet michaelrsweet modified the milestones: Future, CUPS 2.3.x Nov 8, 2018
@michaelrsweet
Copy link
Collaborator

OK, after much deliberation we have decided not to address this in CUPS. A subsequent revision of the ippserver sample code will include compatible "drivers" that offer this functionality to demonstrate the whole "printer application" approach.

@michaelrsweet michaelrsweet removed this from the CUPS 2.3.x milestone Dec 6, 2018
@turntable
Copy link

I have this same issue with the barcode clarity as mentioned in this thread. I'm using a Zebra printer and the Zebra ZPL driver on macOS 10.14.6, CUPS 2.2.9. Since a fix was not included in 2.3 CUPS is there a further explanation on how I can resolve?

@dreamcat4
Copy link

dreamcat4 commented Jan 17, 2020

[edited]
Here on ubuntu 19.10 linux. Got a brand new thermal printer. And it's all the exact same issue in regards to the dithering being all wrong. This specific device happens to be an xprinter xp-460b. Which I found that it will print using the driver downloaded from TSC website. However the printout quality is all screwed up. All as per the other problem reports here. Without any question we are all talking about the same thing.

The cups driver name is called TSC TDP-247 (grayscale). With CUPS version 2.2.12.

Sorry I don't fully understand the path to fixing this here so maybe some of you people can elaborate about the filter. And why this cannot be fixed in a single central place for all of the printers.

Does this mean that I need to contact TCL company and inform them there is an error in their driver? Because I definitely didn't buy my printer from those guys. Despite it being the same OEM device underneath. These guys were the other rebrand / reseller the company known as xprinter, only offers a windows driver package and nothing for the linux support.

Perhaps... can I work on adding this myself ?

Well here is the TSC linux drivers package downloads page https://www.tscprinters.com/EN/support/Support_Download/TDP-244#

And here is the PPD file https://gist.github.com/dreamcat4/8a74f6b5151a321fcac076c68dd6aed7

It seems that the driver package installs an executable file named rastertobarcodetspl as in Raster To Barcode TSPL whereby the printer language is also indicated in the PPD file as being TSPL2.

The most interesting thing happens when I run that program. Because it says:

$ ./rastertobarcodetspl 
DEBUG: ### Start rastertobarcodetspl ###
ERROR: rastertoepson job-id user title copies options [file]

So why does this raster program output debugging lines claiming that it's name is actually rastertoepson (as in: Raster To Epson)? Does that mean that it is potentially derived (modified) from an older Epson printer driver source code? I am end up questioning the closed source nature of this printer driver. And what the true origin of it actually is. Has this raster code been taken from another company or was it legitimately permitted and used under agreement and license from Epson company?

Is there actually any change that we can modify it in order to fix this dithering problem? Or alternatively would it be worth asking the EFF to look into this matter further as to determine the open or closed source nature of this specific driver by examining the binary?

The other thing I found in this archive was a GUI program called thermalprinterui. Which also has a corresponding linux .desktop opener file which makes the application appear to the system and open with the name "Barcode Printer Setting". The main reason why I bring this up is because when I run it there is seemingly a graphic option in there. However it's all only option to set to is 'automatic`. There are no other available options in the drop down menu.

thermalprinterui Graphics options

There is also this other tab which allows the insertion of "Control characters" so can that be another different way to set the dithering mode? Perhaps not?

thermalprinterui User commands

These all seem to be precompiled binary executables. There is no accompanying source code. Therefore I cannot modify them.

[edited] Ah i see now you have made an entirely new seperate project for these types of label printers called lprint. Excellent and thank you for doing this as an alternative way forwards. I have now opened a new issue over there asking about my specific type of printer model.

@ddavidebor
Copy link

Hello Everyone,
If you're looking for a workaround, I have setup this on a raspberry pi https://github.com/AnotherDaniel/airprint-relay
Now it prints like a dream, clear and crisp barcodes including from Royal Mail, where they used to be horribly dithered.
Added benefit, your Zebra printer will become compatible with iPhones/iPads as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

8 participants