Can we please get Floyd-Steinberg dithering available in the tiffg3, tiffg32d, and tiffg4 drivers? This dithering is available already in, for example, the lj4dither and stcolor drivers. Support for -sDithering="fsmono" would be especially nice for transformations originating with 24/16/8-bit color or greyscale image data.
Marking this as bountiable, and setting Severity to 'enhancement'.
As an alternative to FS or other relatively slow error diffusion, a threshold array based stochastic mask can be used to provide similar results. In testing this, I discovered that the 'ht_ccsto.ps' threshold arrays included with Ghostscript were of the wrong polarity. I am attaching sample output and a ht_ccsto.ps with the correct polarity used to generate the sample tiffg4 output. Replace the lib/ht_ccsto.ps with the attached and test using: gs -sDEVICE=tiffg4 -o stocht_tiger.tif stocht.ps examples/tiger.eps Note that in general, you probably need to set HalftoneMode to 1 as in the comment at the end of lib/stocht.ps: << /HalftoneMode 1 >> setuserparams This prevents PS (or PDF) files from setting their own halftone/screening. This can be done from the command line: gs -sDEVICE=tiffg4 -o stocht_tiger.tif stocht.ps -c "<< /HalftoneMode 1 >> setuserparams" examples/tiger.eps
Created attachment 3664 [details] ht_ccsto.ps Stochastic Threshold array with corrected polarity.
Created attachment 3665 [details] stocht_tiger.tif Sample output
A final note on the Stochastic Threshold array -- this has the advantage that it can be used with ANY monochrome or color device without needing modifications to the device.
Thank you for your attention. Take your favorite JPEG file as "original.jpg". I happened to be testing with this one: http://www.webcamshots.nl/galleries/Kate%20Beckinsale/TN_Kate%20Beckinsale%2011.JPG I do not see much of a difference (if there is any) between this: $ jpeg2ps -r 200 -q original.jpg | \ gs -q -sDEVICE=tiffg3 -dNOPAUSE -dBATCH -r204x196 -sOutputFile=final.tif - and this: $ jpeg2ps -r 200 -q original.jpg | \ gs -q -sDEVICE=tiff24nc -dNOPAUSE -dBATCH -r204x196 \ -sOutputFile=final.tif ht_ccsto.ps -c "<< /HalftoneMode 1 >> setuserparams" - Whereas this (using libtiff utilities to perform the monochrome dithering) turns out significantly better: $ jpeg2ps -r 200 -q original.jpg | \ gs -q -sDEVICE=tiff24nc -dNOPAUSE -dBATCH -r204x196 -sOutputFile=step1.tif - $ tiff2bw step1.tif step2.tif $ tiffdither -c g3 step2.tif final.tif
Comment #6 has an incorrect invocation: jpeg2ps -r 200 -q original.jpg | \ gs -q -sDEVICE=tiff24nc -dNOPAUSE -dBATCH -r204x196 \ -sOutputFile=final.tif ht_ccsto.ps -c "<< /HalftoneMode 1 >> setuserparams" - uses the DEVICE=tiff24NC, which is 24-bit RGB, thus Ghostscript performs no dithering. Please look at the output from Ghostscript directly converting to tiffg3 using: jpeg2ps -r 200 -q original.jpg | \ gs -q -sDEVICE=tiffg3 -dNOPAUSE -dBATCH -r204x196 \ -sOutputFile=final.tif ht_ccsto.ps -c "<< /HalftoneMode 1 >> setuserparams" - No post-conversion using: tiff2bw step1.tif step2.tif; tiffdither -c g3 step2.tif final.tif should be performed since the output will already be dithered B&W.
I'm sorry, the misplaced tiff24nc was mere cut-n-paste typo on my part. Yes this: jpeg2ps -r 200 -q original.jpg | \ gs -q -sDEVICE=tiffg3 -dNOPAUSE -dBATCH -r204x196 \ -sOutputFile=final.tif ht_ccsto.ps -c "<< /HalftoneMode 1 >> setuserparams" - Looks nearly the same (if not exactly the same) as this: jpeg2ps -r 200 -q original.jpg | \ gs -q -sDEVICE=tiffg3 -dNOPAUSE -dBATCH -r204x196 \ -sOutputFile=final.tif - And significantly worse than the dithering performed by libtiff's tools.
Now I must apologize for seeing the one mistake and missing the other. The ht_ccsto.ps is a replacement for the (too dark) one in the lib/ directory, but when you invoke Ghostscript, you need to use 'stocht.ps' which loads the ht_stocht.ps halftone resource and defines it as the DefaultHalftone. The 'ht_ccsto.ps' file only defines a Halftone Resource 'StochasticDefault' which stocht.ps uses. Please try: jpeg2ps -r 200 -q original.jpg | \ gs -q -sDEVICE=tiffg3 -dNOPAUSE -dBATCH -r204x196 \ -sOutputFile=final.tif stocht.ps -c "<< /HalftoneMode 1 >> setuserparams" -
Okay, thank you again. YES! That looks very, very good. Thank you. Will the corrected ht_ccsto.ps be in the next Ghostscript release? (8.62?)
The fixed ht_ccsto.ps is committed in rev 8469, so will be in the next GS.