philpem / printer-driver-ptouch

P-Touch PT-series and QL-series printer driver for Linux (under CUPS)
GNU General Public License v2.0
97 stars 24 forks source link

Add internal halftone filters (Error Diffusion, Nonlinear Laplacian) #40

Open vintagepc opened 1 year ago

vintagepc commented 1 year ago

Per the discussion in #39 - this adds an actual half-tone filter to the driver.

It may also add some value to #37 to improve the output.

The source for these filters was sourced from the driver for a Dymo LabelWriterPnP linux package and is GPL-v2.

Generally, my experience has been that Error Diffusion provides better results for greyscale text, and NLL will work better for images and non hard-edged graphics

It is currently in draft stage for the following reasons:

My compile command line looks like this:

g++ rastertoptch.c halftoning//ErrorDiffusionHalftoning.cpp halftoning/Halftoning.cpp halftoning/NonLinearLaplacianHalftoning.cpp -I . -lcups -lcupsimage
*OpenUI *Halftone/Halftoning: PickOne
*OrderDependency: 20 AnySetup *Halftoning
*DefaulHalftone: ErrorDiffusion
*Halftone Default/Default: "<</cupsColorOrder 0/cupsColorSpace 3/cupsBitsPerColor 1/cupsBitsPerPixel 1>>setpagedevice"
*Halftone ErrorDiffusion/Error Diffusion: "<</cupsColorOrder 0/cupsColorSpace 1/cupsBitsPerColor 8>>setpagedevice"
*Halftone NLL/Nonlinear Dithering: "<</cupsColorOrder 0/cupsColorSpace 1/cupsBitsPerColor 8>>setpagedevice"
*CloseUI: *Halftone

and the following parameters must be passed to rastertoptch depending on the selected value:

Default: Halftone=-1
ErrorDiffusion: Halftone=0
NLL: Halftone=1

There may also be value in allowing the user to select the threshold value for the Laplacian filter, but that would require detailed analysis with a lot of images - not really what tape label printers are meant for but it may have value for e.g. the QL series?

Some examples for a simple black-to-white gradient:

Input: gradient Default: gradient1 Error Diffusion: gradient21 NLL: grad64-31