]> git.pld-linux.org Git - packages/ghostscript.git/blob - ghostscript-gdevcd8-fixes.patch
- unconditional noarch subpackages
[packages/ghostscript.git] / ghostscript-gdevcd8-fixes.patch
1 Fixes:
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
4    for cdj880
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
9    though
10
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
14 @@ -604,6 +604,7 @@
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 */
19  } gx_device_cdj850;
20  
21  typedef struct {
22 @@ -659,7 +660,7 @@
23      blackcorrect,\
24      start_raster_mode,\
25      print_non_blank_line,\
26 -    terminate_page\
27 +    terminate_page, 1\
28  }
29  
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)\
31 @@ -678,7 +679,7 @@
32      blackcorrect,\
33      start_raster_mode,\
34      print_non_blank_line,\
35 -    terminate_page\
36 +    terminate_page, 1\
37  }
38  
39  /* HP2200 and DNJ500 is a RGB printer */
40 @@ -698,7 +699,7 @@
41      blackcorrect,\
42      start_raster_mode,\
43      print_non_blank_line,\
44 -    terminate_page\
45 +    terminate_page, 1\
46  }
47  
48  #define cmyk_colour_procs(proc_colour_open, proc_get_params, proc_put_params, \
49 @@ -1057,6 +1058,7 @@
50      if (code < 0 ||
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))
55          < 0 ||
56          (code = param_write_float(plist, "GammaValC", &cdj850->gammavalc)) <
57 @@ -1080,6 +1082,7 @@
58  {
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;
65 @@ -1092,6 +1095,7 @@
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);
73 @@ -1108,6 +1112,7 @@
74  
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);
84  static int
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,
89 +           word * inword);
90 +
91 +static int
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,
95             word * inword);
96 @@ -2025,7 +2036,10 @@
97          }
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);
115          }
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);
120  
121      /* and output the data */
122 -        gp_fprintf(prn_stream, "%d%c", out_count, plane_code);
123      if (out_count > 0) {
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);
128      }
129  }
130  
131 @@ -2122,15 +2141,22 @@
132      byte *dp = data_ptrs->data[misc_vars->scan + 2];
133      int *ep = data_ptrs->errors[misc_vars->scan];
134  
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 */
140  
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]);
147 +  } else {
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]);
152 +  }
153  
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];
159  
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 */
165  
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]);
171 +  } else {
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]);
177 +  }
178  
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
183     replacement */
184  static int
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],
189         word * inword)
190 @@ -2421,7 +2454,7 @@
191    word last_color_value = 0;
192    word *last_color;
193  
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;
208        } else {
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));
215          }
216  #endif /* 0 */
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 */
231 +  return is_color;
232 +}
233 +
234 +static int
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],
238 +       word * inword)
239 +{
240 +  int i, ucr, kadd, is_color = 0;
241 +  float uca_fac;
242 +  byte *black, *cyan, *magenta, *yellow;
243 +  word last_color_value = 0;
244 +  word *last_color;
245 +
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) {
250 +
251 +    /* Assign to black the current address of  inbyte */
252 +    black = inbyte++;
253 +    cyan = inbyte++;
254 +    magenta = inbyte++;
255 +    yellow = inbyte++;
256 +
257 +    if (*magenta + *yellow + *cyan > 0) {      /* if any color at all */
258 +
259 +#if 0
260 +      if ((*cyan > 0) && (*magenta > 0) && (*yellow > 0))
261 +      {
262 +        char output[255];
263 +        gs_sprintf(output, "%3d %3d %3d %3d - ", *cyan, *magenta, *yellow, *black);
264 +        debug_print_string(output, strlen(output));
265 +      }
266 +#endif /* 0 */
267 +
268 +      is_color = 1;
269 +
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;
275 +      } else {
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)
288 +                   && (*cyan > 0)) {
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)
296 +                   && (*cyan > 0)) {
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 */
303 +        }
304 +#if 0
305 +        if (ucr > 0)
306 +        {
307 +          char output[255];
308 +          gs_sprintf(output, "%3d %3d %3d %3d - %5d\n", *cyan, *magenta, *yellow, *black, ucr);
309 +          debug_print_string(output, strlen(output));
310 +        }
311 +#endif /* 0 */
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 */
This page took 0.114715 seconds and 3 git commands to generate.