2 - cdj850 and cdj1600 were broken, because of terminating *b command
3 (by 'Y' or 'V' instead of 'y' or 'v'); now *b is terminated only
5 - do_gcr replaced whole black component by CMY (so everything was
6 printed using colour ink!); do_gcr with NOBLACK looks strange,
7 like somebody didn't know what he's doing... (see the "XXX" comments);
8 now old, actual DOGCR is used, but NOBLACK can be enabled by -dUseBlack=0
11 Jakub Bogusz <qboosh@pld-linux.org>
12 --- ghostscript-9.52/contrib/gdevcd8.c.orig 2020-03-19 09:21:42.000000000 +0100
13 +++ ghostscript-9.52/contrib/gdevcd8.c 2020-03-25 20:10:39.745178961 +0100
15 StartRasterMode start_raster_mode; /* output function to start raster mode */
16 PrintNonBlankLines print_non_blank_lines; /* output function to print a non blank line */
17 TerminatePage terminate_page; /* page termination output function */
18 + int useblack; /* use K compound */
25 print_non_blank_line,\
30 #define cdj_1600_device(procs, dev_name, x_dpi, y_dpi, bpp, print_page, correction, quality, papertype, intensities,ptype,compression,mastergamma,gammavalc,gammavalm,gammavaly,gammavalk,blackcorrect,start_raster_mode,print_non_blank_line,terminate_page)\
34 print_non_blank_line,\
39 /* HP2200 and DNJ500 is a RGB printer */
43 print_non_blank_line,\
48 #define cmyk_colour_procs(proc_colour_open, proc_get_params, proc_put_params, \
51 (code = param_write_int(plist, "Quality", &cdj850->quality)) < 0 ||
52 (code = param_write_int(plist, "Papertype", &cdj850->papertype)) < 0 ||
53 + (code = param_write_int(plist, "UseBlack", &cdj850->useblack)) < 0 ||
54 (code = param_write_float(plist, "MasterGamma", &cdj850->gammavalc))
56 (code = param_write_float(plist, "GammaValC", &cdj850->gammavalc)) <
59 int quality = cdj850->quality;
60 int papertype = cdj850->papertype;
61 + int useblack = cdj850->useblack;
62 float mastergamma = cdj850->mastergamma;
63 float gammavalc = cdj850->gammavalc;
64 float gammavalm = cdj850->gammavalm;
66 code = cdj_put_param_int(plist, "BitsPerPixel", &bpp, 1, 32, code);
67 code = cdj_put_param_int(plist, "Quality", &quality, 0, 2, code);
68 code = cdj_put_param_int(plist, "Papertype", &papertype, 0, 4, code);
69 + code = cdj_put_param_int(plist, "UseBlack", &useblack, 0, 1, code);
70 code = cdj_put_param_float(plist, "MasterGamma", &mastergamma, 0.1f, 9.0f, code);
71 code = cdj_put_param_float(plist, "GammaValC", &gammavalc, 0.0f, 9.0f, code);
72 code = cdj_put_param_float(plist, "GammaValM", &gammavalm, 0.0f, 9.0f, code);
75 cdj850->quality = quality;
76 cdj850->papertype = papertype;
77 + cdj850->useblack = useblack;
78 cdj850->mastergamma = mastergamma;
79 cdj850->gammavalc = gammavalc;
80 cdj850->gammavalm = gammavalm;
81 @@ -1160,7 +1165,13 @@
82 gx_device_printer * pdev,
83 struct error_val_field *error_values);
85 - do_gcr(int bytecount, byte * inbyte, const byte * kvalues,
86 + do_gcr_noblack(int bytecount, byte * inbyte, const byte * kvalues,
87 + const byte * cvalues, const byte * mvalues,
88 + const byte * yvalues, const int *kcorrect,
92 + do_gcr_gcr(int bytecount, byte * inbyte, const byte * kvalues,
93 const byte * cvalues, const byte * mvalues,
94 const byte * yvalues, const int *kcorrect,
96 @@ -2025,7 +2036,10 @@
98 /* Skip blank lines if any */
99 if (num_blank_lines > 0) {
100 + if(cdj850->ptype == DJ880C)
101 gp_fprintf(prn_stream, "\033*b%dY", num_blank_lines / (cdj850->yscal + 1));
102 + else /* still in *b if not dj880 */
103 + fprintf(prn_stream, "%dy", num_blank_lines / (cdj850->yscal + 1));
104 memset(data_ptrs->plane_data[0][0], 0,
105 (misc_vars->plane_size * 2 * misc_vars->num_comps));
106 memset(data_ptrs->plane_data_c[0][0], 0,
107 @@ -2035,7 +2049,10 @@
108 /* all blank lines printed, now for the non-blank lines */
109 if (cdj850->yscal && odd(lnum)) {
110 /* output a blank black plane for odd lines */
111 + if(cdj850->ptype == DJ880C)
112 gp_fprintf(prn_stream, "\033*b0V");
113 + else /* still in *b if not dj880 */
114 + putc('v', prn_stream);
116 /* now output all non blank lines */
117 while (lnum < lend && llen != 0) {
118 @@ -2061,9 +2078,11 @@
119 int out_count = gdev_pcl_mode9compress(plane_size, curr, prev, out_data);
121 /* and output the data */
122 - gp_fprintf(prn_stream, "%d%c", out_count, plane_code);
124 + gp_fprintf(prn_stream, "%d%c", out_count, plane_code);
125 gp_fwrite(out_data, sizeof(byte), out_count, prn_stream);
126 + } else { /* single plane_code is sufficient for cdj850 */
127 + putc(plane_code, prn_stream);
131 @@ -2122,15 +2141,22 @@
132 byte *dp = data_ptrs->data[misc_vars->scan + 2];
133 int *ep = data_ptrs->errors[misc_vars->scan];
135 - /* we need cmyk color separation befor all the rest, since
136 + /* we need cmyk color separation before all the rest, since
137 black may be contained in the color fields. This needs to
138 be done on all pixel-rows, since even unused color-bytes
139 might generate black */
141 + if(cdj850->useblack) {
142 misc_vars->is_color_data =
143 - do_gcr(misc_vars->databuff_size, data_ptrs->data[misc_vars->scan],
144 + do_gcr_gcr(misc_vars->databuff_size, data_ptrs->data[misc_vars->scan],
145 gamma->k, gamma->c, gamma->m, gamma->y, gamma->correct,
146 (word *) data_ptrs->data[misc_vars->scan]);
148 + misc_vars->is_color_data =
149 + do_gcr_noblack(misc_vars->databuff_size, data_ptrs->data[misc_vars->scan],
150 + gamma->k, gamma->c, gamma->m, gamma->y, gamma->correct,
151 + (word *) data_ptrs->data[misc_vars->scan]);
154 /* dithering the black-plane */
155 FSDlinebw(misc_vars->scan, misc_vars->plane_size,
156 @@ -2200,15 +2226,22 @@
157 byte *dp = data_ptrs->data[misc_vars->scan + 2];
158 int *ep = data_ptrs->errors[misc_vars->scan];
160 - /* we need cmyk color separation befor all the rest, since
161 + /* we need cmyk color separation before all the rest, since
162 black may be contained in the color fields. This needs to
163 be done on all pixel-rows, since even unused color-bytes
164 might generate black */
166 + if(cdj850->useblack) {
167 + misc_vars->is_color_data =
168 + do_gcr_gcr(misc_vars->databuff_size, data_ptrs->data[misc_vars->scan],
169 + gamma->k, gamma->c, gamma->m, gamma->y, gamma->correct,
170 + (word *) data_ptrs->data[misc_vars->scan]);
172 misc_vars->is_color_data =
173 - do_gcr(misc_vars->databuff_size, data_ptrs->data[misc_vars->scan],
174 + do_gcr_noblack(misc_vars->databuff_size, data_ptrs->data[misc_vars->scan],
175 gamma->k, gamma->c, gamma->m, gamma->y, gamma->correct,
176 (word *) data_ptrs->data[misc_vars->scan]);
179 /* dithering the black-plane */
180 FSDlinebw(misc_vars->scan, misc_vars->plane_size,
181 @@ -2411,7 +2444,7 @@
182 do real color separation, here we try a real grey component
185 -do_gcr(int bytecount, byte * inbyte, const byte kvalues[256],
186 +do_gcr_noblack(int bytecount, byte * inbyte, const byte kvalues[256],
187 const byte cvalues[256], const byte mvalues[256],
188 const byte yvalues[256], const int kcorrect[256],
190 @@ -2421,7 +2454,7 @@
191 word last_color_value = 0;
194 - /* initialise *last_color with a dummmy value */
195 + /* initialise *last_color with a dummy value */
196 last_color = &last_color_value;
197 /* Grey component replacement */
198 for (i = 0; i < bytecount; i += 4) {
199 @@ -2451,11 +2484,12 @@
200 /* Test whether we 've already computet the value */
201 if (*inword == last_color_value) {
202 /* save a copy of the current color before it will be modified */
203 - last_color_value = *inword;
204 + last_color_value = *inword; /* NOP --q */
205 /* debug_print_string("\n", 1);*/
206 /* copy the result of the old value onto the new position */
207 *inword = *last_color;
209 + /* ??? ALL these NOBLACKs will be NOPs after the first NOBLACK! what are they for??? --q */
210 /* save a copy of the current color before it will be modified */
211 last_color_value = *inword;
212 NOBLACK(cyan, magenta, yellow, black);
213 @@ -2493,6 +2527,7 @@
214 debug_print_string(output, strlen(output));
217 + /* XXX: how byte could be >255??? --q */
218 if ( *cyan > 255) *cyan = 255;
219 if (*magenta > 255) *magenta = 255;
220 if ( *yellow > 255) *yellow = 255;
221 @@ -2500,6 +2535,96 @@
222 *cyan = *(cvalues + *cyan);
223 *magenta = *(mvalues + *magenta);
224 *yellow = *(yvalues + *yellow);
225 + last_color = inword; /* save pointer */
226 + }/* end current_color */
227 + } /* end of if c+m+y > 0 */
228 + *black = *(kvalues + *black);
229 + inword = inword + 1;
230 + } /* end of for bytecount */
235 +do_gcr_gcr(int bytecount, byte * inbyte, const byte kvalues[256],
236 + const byte cvalues[256], const byte mvalues[256],
237 + const byte yvalues[256], const int kcorrect[256],
240 + int i, ucr, kadd, is_color = 0;
242 + byte *black, *cyan, *magenta, *yellow;
243 + word last_color_value = 0;
246 + /* initialise *last_color with a dummy value */
247 + last_color = &last_color_value;
248 + /* Grey component replacement */
249 + for (i = 0; i < bytecount; i += 4) {
251 + /* Assign to black the current address of inbyte */
254 + magenta = inbyte++;
257 + if (*magenta + *yellow + *cyan > 0) { /* if any color at all */
260 + if ((*cyan > 0) && (*magenta > 0) && (*yellow > 0))
263 + gs_sprintf(output, "%3d %3d %3d %3d - ", *cyan, *magenta, *yellow, *black);
264 + debug_print_string(output, strlen(output));
270 + /* Test whether we 've already computet the value */
271 + if (*inword == last_color_value) {
272 +/* debug_print_string("\n", 1);*/
273 + /* copy the result of the old value onto the new position */
274 + *inword = *last_color;
276 + /* save a copy of the current color before it will be modified */
277 + last_color_value = *inword;
278 + if ((*cyan >= *magenta)
279 + && (*magenta >= *yellow)
280 + && (*yellow > 0)) { /* if any grey component */
281 + DOGCR(cyan, magenta, yellow, black);
282 + } else if ((*cyan >= *yellow)
283 + && (*yellow >= *magenta)
284 + && (*magenta > 0)) {
285 + DOGCR(cyan, yellow, magenta, black);
286 + } else if ((*yellow >= *magenta)
287 + && (*magenta >= *cyan)
289 + DOGCR(yellow, magenta, cyan, black);
290 + } else if ((*yellow >= *cyan)
291 + && (*cyan >= *magenta)
292 + && (*magenta > 0)) {
293 + DOGCR(yellow, cyan, magenta, black);
294 + } else if ((*magenta >= *yellow)
295 + && (*yellow >= *cyan)
297 + DOGCR(magenta, yellow, cyan, black);
298 + } else if ((*magenta >= *cyan)
299 + && (*cyan >= *yellow)
300 + && (*yellow > 0)) {
301 + DOGCR(magenta, cyan, yellow, black);
302 + } else { /* do gamma only if no black */
308 + gs_sprintf(output, "%3d %3d %3d %3d - %5d\n", *cyan, *magenta, *yellow, *black, ucr);
309 + debug_print_string(output, strlen(output));
312 + *cyan = *(cvalues + *cyan);
313 + *magenta = *(mvalues + *magenta);
314 + *yellow = *(yvalues + *yellow);
315 last_color = inword; /* save pointer */
316 }/* end current_color */
317 } /* end of if c+m+y > 0 */