Skip to content

Commit 71742d2

Browse files
committed
Ghostscript (gstoraster): add bi-level threshold support
Similar to pdftoraster implementation.
1 parent 7a979f5 commit 71742d2

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

cupsfilters/ghostscript.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ typedef enum cups_halftone_type_e
4848
{
4949
HALFTONE_DEFAULT,
5050
HALFTONE_STOCHASTIC,
51-
HALFTONE_FOO2ZJS
51+
HALFTONE_FOO2ZJS,
52+
HALFTONE_BI_LEVEL
5253
} cups_halftone_type_t;
5354

5455
static gs_doc_t
@@ -1622,8 +1623,18 @@ cfFilterGhostscript(int inputfd, // I - File descriptor input
16221623
halftonetype = HALFTONE_STOCHASTIC;
16231624
else if (!strcasecmp(t, "foo2zjs"))
16241625
halftonetype = HALFTONE_FOO2ZJS;
1626+
else if (!strcasecmp(t, "bi-level"))
1627+
halftonetype = HALFTONE_BI_LEVEL;
16251628
}
16261629

1630+
//
1631+
// For bi-level type, also check print-color-mode, the way it is
1632+
// handled by Poppler pwgtoraster/pdftoraster/pclmtoraster utilities.
1633+
//
1634+
if ((t = cupsGetOption("print-color-mode", num_options, options)) != NULL &&
1635+
!strcasecmp(t, "bi-level"))
1636+
halftonetype = HALFTONE_BI_LEVEL;
1637+
16271638
//
16281639
// Use Stochastic Halftone dithering found in GhostScript stocht.ps library file.
16291640
// It is activated automatically.
@@ -1739,6 +1750,16 @@ cfFilterGhostscript(int inputfd, // I - File descriptor input
17391750
>> /Default exch /Halftone defineresource sethalftone"));
17401751
}
17411752

1753+
//
1754+
// Use simple threshold (bi-level) halftone algorithm
1755+
//
1756+
if (halftonetype == HALFTONE_BI_LEVEL)
1757+
{
1758+
if (log) log(ld, CF_LOGLEVEL_DEBUG,
1759+
"cfFilterGhostscript: Ghostscript using Bi-Level Halftone dithering.");
1760+
cupsArrayAdd(gs_args, strdup("{ .5 gt { 1 } { 0 } ifelse} settransfer"));
1761+
}
1762+
17421763
// Mark the end of PostScript commands supplied on the Ghostscript command
17431764
// line (with the "-c" option), so that we can supply the input file name
17441765
cupsArrayAdd(gs_args, strdup("-f"));

0 commit comments

Comments
 (0)