Skip to content

Commit 2fdad60

Browse files
committed
Ghostscript (gstoraster): Introduce cupsHalftoneType dithering algorithms
Add new dithering (halftone) algorithms in addition to the default Ghostscript one. Controlled either with `halftone-type` job option or `cupsHalftoneType` PPD option. - Stochastic algotirhm is implemented in `stocht.ps` Ghostscript library, just include it if cupsHalftoneType is set to yes/true/on/stochastic. - Foo2zjs algorithm is a PostScript code taken from foo2zjs-pstops file (don't know the name of the algorithm)
1 parent 7509668 commit 2fdad60

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

cupsfilters/ghostscript.c

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ typedef enum gs_doc_e
4444

4545
typedef cups_page_header_t gs_page_header;
4646

47+
typedef enum cups_halftone_type_e
48+
{
49+
HALFTONE_DEFAULT,
50+
HALFTONE_STOCHASTIC,
51+
HALFTONE_FOO2ZJS
52+
} cups_halftone_type_t;
53+
4754
static gs_doc_t
4855
parse_doc_type(FILE *fp)
4956
{
@@ -805,6 +812,7 @@ cfFilterGhostscript(int inputfd, // I - File descriptor input
805812
struct sigaction sa;
806813
cf_cm_calibration_t cm_calibrate;
807814
int pxlcolor = 0; // 1 if printer is color printer otherwise 0.
815+
cups_halftone_type_t halftonetype = HALFTONE_DEFAULT;
808816
ipp_attribute_t *ipp_attr;
809817
cf_logfunc_t log = data->logfunc;
810818
void *ld = data->logdata;
@@ -1606,6 +1614,31 @@ cfFilterGhostscript(int inputfd, // I - File descriptor input
16061614
else if (!cm_disabled)
16071615
cupsArrayAdd(gs_args, strdup("-sOutputICCProfile=srgb.icc"));
16081616

1617+
if ((t = cupsGetOption("cupsHalftoneType", num_options, options)) != NULL ||
1618+
(t = cupsGetOption("halftone-type", num_options, options)) != NULL)
1619+
{
1620+
if (!strcasecmp(t, "true") || !strcasecmp(t, "on") ||
1621+
!strcasecmp(t, "yes") || !strcasecmp(t, "stochastic"))
1622+
{
1623+
halftonetype = HALFTONE_STOCHASTIC;
1624+
}
1625+
else if (!strcasecmp(t, "foo2zjs"))
1626+
{
1627+
halftonetype = HALFTONE_FOO2ZJS;
1628+
}
1629+
}
1630+
1631+
//
1632+
// Use Stochastic Halftone dithering found in GhostScript stocht.ps library file.
1633+
// It is activated automatically.
1634+
//
1635+
if (halftonetype == HALFTONE_STOCHASTIC)
1636+
{
1637+
if (log) log(ld, CF_LOGLEVEL_DEBUG,
1638+
"cfFilterGhostscript: Ghostscript using Stochastic Halftone dithering.");
1639+
cupsArrayAdd(gs_args, strdup("stocht.ps"));
1640+
}
1641+
16091642
// Switch to taking PostScript commands on the Ghostscript command line
16101643
cupsArrayAdd(gs_args, strdup("-c"));
16111644

@@ -1662,6 +1695,54 @@ cfFilterGhostscript(int inputfd, // I - File descriptor input
16621695
"cfFilterGhostscript: Ghostscript using Any-Part-of-Pixel method to "
16631696
"fill paths.");
16641697

1698+
//
1699+
// Use halftone dithering algorithm found in foo2zjs-pstops file
1700+
//
1701+
if (halftonetype == HALFTONE_FOO2ZJS)
1702+
{
1703+
if (log) log(ld, CF_LOGLEVEL_DEBUG,
1704+
"cfFilterGhostscript: Ghostscript using foo2zjs Halftone dithering.");
1705+
cupsArrayAdd(gs_args, strdup("/SpotDot { 180 mul cos exch 180 mul cos add 2 div } def\
1706+
<<\
1707+
/HalftoneType 5\
1708+
/Cyan <<\
1709+
/HalftoneType 1\
1710+
/AccurateScreens true\
1711+
/Frequency 150\
1712+
/Angle 105\
1713+
/SpotFunction /SpotDot load\
1714+
>>\
1715+
/Magenta <<\
1716+
/HalftoneType 1\
1717+
/AccurateScreens true\
1718+
/Frequency 150\
1719+
/Angle 165\
1720+
/SpotFunction /SpotDot load\
1721+
>>\
1722+
/Yellow <<\
1723+
/HalftoneType 1\
1724+
/AccurateScreens true\
1725+
/Frequency 150\
1726+
/Angle 30\
1727+
/SpotFunction /SpotDot load\
1728+
>>\
1729+
/Black <<\
1730+
/HalftoneType 1\
1731+
/AccurateScreens true\
1732+
/Frequency 150\
1733+
/Angle 45\
1734+
/SpotFunction /SpotDot load\
1735+
>>\
1736+
/Default <<\
1737+
/HalftoneType 1\
1738+
/AccurateScreens true\
1739+
/Frequency 150\
1740+
/Angle 37\
1741+
/SpotFunction /SpotDot load\
1742+
>>\
1743+
>> /Default exch /Halftone defineresource sethalftone"));
1744+
}
1745+
16651746
// Mark the end of PostScript commands supplied on the Ghostscript command
16661747
// line (with the "-c" option), so that we can supply the input file name
16671748
cupsArrayAdd(gs_args, strdup("-f"));

0 commit comments

Comments
 (0)