Bug 701880

Summary: Unwanted dots in halftone screen (on high resolution?)
Product: Ghostscript Reporter: Martin Schulze <martin.schulze>
Component: ColorAssignee: Ray Johnston <ray.johnston>
Status: RESOLVED FIXED    
Severity: normal CC: diuming_wen
Priority: P4    
Version: 9.50   
Hardware: PC   
OS: Linux   
Customer: Word Size: ---
Attachments: Magenta channel with 600DPI at ditherPPI=20
Fixed magenta channel

Description Martin Schulze 2019-11-08 08:46:45 UTC
Created attachment 18498 [details]
Magenta channel with 600DPI at ditherPPI=20

When using custom angles and frequencies for RIP I noticed unwanted dots in white (zero tone value; blue circle in the attachment) areas and within the "glades"* in non-white (non zero tone value; red circle in the attachment) areas. At first I thought this only happens with custom screensets and high resolution but now I found a reproducer that exhibits (part of) this earlier:


```
<< /PageSize [20 10] >> setpagedevice
% draw two filled rects that contrast different tone values per CMYK channel
0.75 0.5 0 0 setcmykcolor
newpath 0 0 moveto 10 0 lineto 10 10 lineto 0 10 lineto closepath fill 
0.5 0 0.75 0.5 setcmykcolor
newpath 10 0 moveto 20 0 lineto 20 10 lineto 10 10 lineto closepath fill 
showpage
quit
```

Running this with

`gs -r600 -dDITHERPPI=20 -sOutputFile=test%d.tif -sDEVICE=tiffsep1 -f test.gs` 

gives black dots in "white" areas (where the channel has value 0) and I get black dots in the middle of the white "glades" of the screen in non zero channels. Both is unintended. 

With -r300 the zeros stay clean but the unwanted dots in the nonzero channels are still there. When looking closely you can see, that the dots in zero channels are located in the same grid as the wanted dots in the non zero channels, so I am not sure if they stem from the same problem.

I lowered the ditherDPI to better separate the unwanted dots from the rest. With default ditherPPI the unwanted dots in the zeros are gone but the other unwanted dots remain.

* I lack knowledge of the exact terminology for this. What I mean is the white area that is encroached by increasing amounts of black when the tone value increases until it vanishes.
Comment 1 Ken Sharp 2019-11-11 11:31:38 UTC
*** Bug 701814 has been marked as a duplicate of this bug. ***
Comment 2 Ray Johnston 2019-12-27 17:19:08 UTC
This bug is particular to the tiffsep1 device which uses its own function to
create threshold arrays from the ht_order. Changing tiffsep1 to use the gsht.c
function gx_ht_construct_threshold that Michael developed fixes this problem.

Taking this bug, and will commit the fix shortly.
Comment 3 Ray Johnston 2019-12-28 02:44:12 UTC
Fixed in commit bf689ee0bff720f202ebc98f301c765f34e2c1fa

For patterns with > 256 dots, threshold_from_order would put in 0 value
cells which would then always be imaged. Change this device to (finally)
use the gx_ht_construct_threshold used by the fast_ht thresholding code
so that it should match the other devices, such as pbmraw.

Also vertically invert the use of the threshold array to match the dots
of the other devices.

The commit also adds missing dependencies for gdevtsep.c in devs.mak
Comment 4 Martin Schulze 2020-01-02 10:52:55 UTC
Thanks for your fine work. I tried current master and the artifacts are gone. 

However, I noticed that the output from my test above now looks different: The angles seem to work in the opposite direction now as you can see the attached new magenta image. The orientation seems to be from lower left to upper right now, instead of upper left to lower right as in the old image.
Comment 5 Martin Schulze 2020-01-02 10:54:26 UTC
Created attachment 18749 [details]
Fixed magenta channel
Comment 6 Ray Johnston 2020-01-05 14:13:30 UTC
I was able to see the angle change -- it was due to an invalid attempt to get
the halftone phase to match the output from other halftone methods (such as
that used by pbmraw).

The phase and angle can be made to match by the latest patch:
commit d1aa5fdfdbea4c55445ee1bdbe08b822a1bd7a8c

As noted in the comment for that patch, the pattern is slightly darker, but
that might be a result of the gx_ht_construct_threshold.
Comment 7 Martin Schulze 2020-01-08 11:30:40 UTC
It looks good now. Thanks again for your work on this.