~ubuntu-branches/ubuntu/gutsy/hplip/gutsy-security

« back to all changes in this revision

Viewing changes to prnt/hpijs/gdevijs-krgb-1.3-gs8.54.patch

  • Committer: Bazaar Package Importer
  • Author(s): Till Kamppeter
  • Date: 2006-09-15 18:00:07 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20060915180007-96mez3nck3oy5wij
Tags: 1.6.7-2ubuntu1
* Merge from debian unstable.
* Removed patches 50_ui-supportform-cleanups.dpatch and
  55_ui-supportform-debian.dpatch, there is no support window in the HP
  toolbox any more.
* HPLIP (file io/hpiod/usbext.h) includes linux/compiler.h which is not
  part of Ubuntu Linux and not needed. Removed the include with patch
  80_no-compiler.h.dpatch.
* debian/control: Let the "Conflicts:" of hpijs-ppds be only a "Breaks:"
  to facilitate an update from the previous version when both hpijs and
  hpijs-ppds are installed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
diff -uNr old/gdevijs.c new/gdevijs.c
 
2
--- old/gdevijs.c       2006-06-02 16:42:01.829749000 -0700
 
3
+++ new/gdevijs.c       2006-06-02 16:42:37.562316824 -0700
 
4
@@ -23,15 +23,50 @@
 
5
  * which is a security risk, since any program can be run.
 
6
  * You should use -dSAFER which sets .LockSafetyParams to true 
 
7
  * before opening this device.
 
8
+ *
 
9
+ * 11/26/03 David Suffield (gdevijs-krgb-1.0.patch)
 
10
+ * (c) 2003-2004 Copyright Hewlett-Packard Development Company, LP
 
11
+ *
 
12
+ * 1. Removed hpijs 1.0-1.0.2 workarounds, use hpijs 1.0.3 or higher.
 
13
+ * 2. Added krgb support.
 
14
+ *
 
15
+ * 02/21/05 David Suffield (gdevijs-krgb-1.1.patch)
 
16
+ * 1. Fixed segfault issue with 1-bit color space.
 
17
+ * 2. Fixed z-order issue with colored text on black rectangle.
 
18
+ *
 
19
+ * 02/22/06 David Suffield (gdevijs-krgb-1.2.patch)
 
20
+ * 1. Fixed krgb buffer overflow issue with out-of-band data in fill_rectangle and copy_mono. 
 
21
+ *    This buffer overflow condition occurred with fullbleed print jobs that had k-band images.
 
22
+ * 2. Added Dan Coby (artifex) fix for gsijs_read_string_malloc gs_free *str memory leak.
 
23
+ *
 
24
+ * 06/02/06 David Suffield (gdevijs-krgb-1.3.patch)
 
25
+ * 1. Revisited the krgb buffer overflow issue with out-of-band data in fill_rectangle and 
 
26
+ *    copy_mono. Changed the fill_rectangle and copy_mono to an inner loop buffer check 
 
27
+ *    instead of a outer loop x/y extent check.
 
28
+ * 2. As requested by Ralph Giles, added K 1-bit and 8-bit support for krgb, but only 1-bit is 
 
29
+ *    implemented for now.
 
30
+ *
 
31
+ *    KRGB definition:
 
32
+ *    1. K=1-bit or 8-bit black plane, RGB=24 bit color raster.
 
33
+ *    2. K-plane will only contain objects that are black text and black line drawings.
 
34
+ *    3. RGB raster will not contain K-plane objects.
 
35
+ *    4. K resolution and RGB resolution will be equal.
 
36
+ *    5. K-plane will be byte aligned.
 
37
+ *    6. K-plane 1-bit definition; 1=black, 0=nothing (KRGB).
 
38
+ *    7. K-plane 8-bit definition; 255=black, 0=nothing (KxRGB).
 
39
+ *
 
40
  */
 
41
 
 
42
 #include "unistd_.h"   /* for dup() */
 
43
 #include <stdlib.h>
 
44
+#include <fcntl.h>
 
45
 #include "gdevprn.h"
 
46
 #include "gp.h"
 
47
 #include "ijs.h"
 
48
 #include "ijs_client.h"
 
49
 
 
50
+//#define KRGB_DEBUG
 
51
+
 
52
 /* This should go into gdevprn.h, or, better yet, gdevprn should
 
53
    acquire an API for changing resolution. */
 
54
 int gdev_prn_maybe_realloc_memory(gx_device_printer *pdev,
 
55
@@ -49,6 +84,14 @@
 
56
 private dev_proc_put_params(gsijs_put_params);
 
57
 private dev_proc_finish_copydevice(gsijs_finish_copydevice);
 
58
 
 
59
+/* Following definitions are for krgb support. */
 
60
+private dev_proc_create_buf_device(gsijs_create_buf_device);
 
61
+private dev_proc_fill_rectangle(gsijs_fill_rectangle);
 
62
+private dev_proc_copy_mono(gsijs_copy_mono);
 
63
+private dev_proc_fill_mask(gsijs_fill_mask);
 
64
+private dev_proc_fill_path(gsijs_fill_path);
 
65
+private dev_proc_stroke_path(gsijs_stroke_path);
 
66
+
 
67
 private const gx_device_procs gsijs_procs = {
 
68
        gsijs_open,
 
69
        NULL,   /* get_initial_matrix */
 
70
@@ -123,6 +166,15 @@
 
71
 
 
72
     IjsClientCtx *ctx;
 
73
     int ijs_version;
 
74
+
 
75
+    /* Additional parameters for krgb support. */
 
76
+    int krgb_mode;     /* 0=false, 1=true */
 
77
+    int k_bits;        /* number of bits in k plane, 1 or 8 */
 
78
+    int k_path;        /* k plane path, 0=false, 1=true */
 
79
+    int k_width;       /* k plane width in pixels */
 
80
+    int k_band_size;   /* k plane buffer size in bytes, byte aligned */
 
81
+    unsigned char *k_band;  /* k plane buffer */
 
82
+    gx_device_procs prn_procs;  /* banding playback procedures */
 
83
 };
 
84
 
 
85
 #define DEFAULT_DPI 74   /* See gsijs_set_resolution() below. */
 
86
@@ -150,7 +202,13 @@
 
87
     FALSE,     /* Tumble_set */
 
88
 
 
89
     NULL,      /* IjsClient *ctx */
 
90
-    0          /* ijs_version */
 
91
+    0,         /* ijs_version */
 
92
+    0,          /* krgb_mode */
 
93
+    0,          /* k_bits */
 
94
+    0,          /* k_path */
 
95
+    0,          /* k_width */
 
96
+    0,          /* k_band_size */
 
97
+    NULL        /* k_band buffer */
 
98
 };
 
99
 
 
100
 
 
101
@@ -166,12 +224,299 @@
 
102
 
 
103
 /**************************************************************************/
 
104
 
 
105
-/* ------ Private definitions ------ */
 
106
+/* ---------------- Low-level graphic procedures ---------------- */
 
107
+
 
108
+static unsigned char xmask[] =
 
109
+{
 
110
+   0x80,    /* x=0 */
 
111
+   0x40,    /* 1 */
 
112
+   0x20,    /* 2 */
 
113
+   0x10,    /* 3 */
 
114
+   0x08,    /* 4 */
 
115
+   0x04,    /* 5 */
 
116
+   0x02,    /* 6 */
 
117
+   0x01     /* 7 */
 
118
+};
 
119
+
 
120
+private int gsijs_fill_rectangle(gx_device * dev, int x, int y, int w, int h,
 
121
+           gx_color_index color)
 
122
+{
 
123
+   gx_device_ijs *ijsdev = (gx_device_ijs *)((gx_device_forward *)dev)->target;
 
124
+
 
125
+   if (ijsdev->krgb_mode && ijsdev->k_path && y >= 0 && x >= 0) 
 
126
+   {
 
127
+      int raster = (ijsdev->k_width+7) >> 3;
 
128
+      register unsigned char *dest;
 
129
+      int dest_start_bit;
 
130
+      int band_height = ijsdev->k_band_size/raster;
 
131
+      int i,j;
 
132
+      unsigned char *beg = ijsdev->k_band;
 
133
+      unsigned char *end = ijsdev->k_band+ijsdev->k_band_size;
 
134
+      unsigned char *p;
 
135
+
 
136
+      if (h <= 0 || w <= 0)
 
137
+         return 0;
 
138
+
 
139
+      /* Check for out-of-band graphic. */
 
140
+      if (x >= ijsdev->k_width || y >= band_height)
 
141
+         return 0;  /* out-of-band */
 
142
+
 
143
+      dest_start_bit = x & 7;
 
144
+      dest=ijsdev->k_band+(raster*y)+(x >> 3);
 
145
+
 
146
+      /* Note x,y orgin 0,0 is stored first byte 0 left to right. */
 
147
+
 
148
+      if (color==0x0)
 
149
+      { 
 
150
+         /* Color is black, store in k plane band instead of regular band. */
 
151
+         for (j=0; j<h; j++)
 
152
+         {
 
153
+            for (i=0; i<w; i++)
 
154
+            {
 
155
+               p = &dest[(dest_start_bit+i)>>3];
 
156
+               if (p >= beg && p <= end)
 
157
+                  *p |= xmask[(dest_start_bit+i)&7];
 
158
+            }
 
159
+            dest+=raster;    
 
160
+         }
 
161
+         return 0;
 
162
+      }
 
163
+      else
 
164
+      {
 
165
+         /* Color is not black, remove any k plane bits for z-order dependencies, store in regular band. */
 
166
+         for (j=0; j<h; j++)
 
167
+         {
 
168
+            for (i=0; i<w; i++)
 
169
+            {
 
170
+               p = &dest[(dest_start_bit+i)>>3];
 
171
+               if (p >= beg && p <= end)
 
172
+                  *p &= ~xmask[(dest_start_bit+i)&7];
 
173
+            }
 
174
+            dest+=raster;    
 
175
+         }
 
176
+      }
 
177
+   }
 
178
+
 
179
+   return (*ijsdev->prn_procs.fill_rectangle)(dev, x, y, w, h, color);
 
180
+}
 
181
+
 
182
+private int gsijs_copy_mono(gx_device * dev, const byte * data,
 
183
+      int dx, int draster, gx_bitmap_id id,
 
184
+      int x, int y, int w, int height, gx_color_index zero, gx_color_index one)
 
185
+{
 
186
+   gx_device_ijs *ijsdev = (gx_device_ijs *)((gx_device_forward *)dev)->target;
 
187
+
 
188
+   //   if (ijsdev->krgb_mode && ijsdev->k_path && one==0x0) 
 
189
+   if (ijsdev->krgb_mode && ijsdev->k_path) 
 
190
+   {
 
191
+      /* Store in k plane band instead of regular band. */
 
192
+      int raster = (ijsdev->k_width+7) >> 3;       /* raster width in bytes, byte aligned */
 
193
+      register unsigned char *dest;
 
194
+      register const unsigned char *scan;
 
195
+      int dest_start_bit;
 
196
+      int scan_start_bit;
 
197
+      int band_height = ijsdev->k_band_size/raster;
 
198
+      int i,h=height;
 
199
+      unsigned char *beg = ijsdev->k_band;
 
200
+      unsigned char *end = ijsdev->k_band+ijsdev->k_band_size;
 
201
+      unsigned char *p;
 
202
+      
 
203
+      if (h <= 0 || w <= 0)
 
204
+         return 0;
 
205
+
 
206
+      /* Check for out-of-band graphic. */
 
207
+      if (x >= ijsdev->k_width || y >= band_height)
 
208
+         return 0;  /* out-of-band */
 
209
+
 
210
+      scan=data+(dx >> 3);
 
211
+      dest_start_bit = x & 7;
 
212
+      scan_start_bit = dx & 7;
 
213
+      dest=ijsdev->k_band+(raster*y)+(x >> 3);
 
214
+
 
215
+      if (one==0x0)
 
216
+      {
 
217
+         /* Color is black, store in k plane band instead of regular band. */
 
218
+         while (h-- > 0)
 
219
+         {
 
220
+            for (i=0; i<w; i++)
 
221
+            {
 
222
+               if (scan[(scan_start_bit+i)>>3] & xmask[(scan_start_bit+i)&7])
 
223
+               {
 
224
+                  p = &dest[(dest_start_bit+i)>>3];
 
225
+                  if (p >= beg && p <= end)
 
226
+                     *p |= xmask[(dest_start_bit+i)&7];
 
227
+               }
 
228
+            }
 
229
+            scan+=draster;
 
230
+            dest+=raster;
 
231
+         }
 
232
+         return 0;
 
233
+      }
 
234
+      else
 
235
+      {
 
236
+         /* Color is not black, remove any k plane bits for z-order dependencies, store in regular band. */
 
237
+         while (h-- > 0)
 
238
+         {
 
239
+            for (i=0; i<w; i++)
 
240
+            {
 
241
+               if (scan[(scan_start_bit+i)>>3] & xmask[(scan_start_bit+i)&7])
 
242
+               {
 
243
+                  p = &dest[(dest_start_bit+i)>>3];
 
244
+                  if (p >= beg && p <= end)
 
245
+                     *p &= ~xmask[(dest_start_bit+i)&7];
 
246
+               }
 
247
+            }
 
248
+            scan+=draster;
 
249
+            dest+=raster;
 
250
+         }
 
251
+      }   
 
252
+   }
 
253
+
 
254
+   return (*ijsdev->prn_procs.copy_mono)(dev, data, dx, draster, id, x, y, w, height, zero, one);
 
255
+}
 
256
+
 
257
+/* ---------------- High-level graphic procedures ---------------- */
 
258
+
 
259
+private int gsijs_fill_mask(gx_device * dev,
 
260
+      const byte * data, int dx, int raster, gx_bitmap_id id,
 
261
+      int x, int y, int w, int h,
 
262
+      const gx_drawing_color * pdcolor, int depth,
 
263
+      gs_logical_operation_t lop, const gx_clip_path * pcpath)
 
264
+{
 
265
+   gx_device_ijs *ijsdev = (gx_device_ijs *)((gx_device_forward *)dev)->target;
 
266
+   int code;
 
267
+
 
268
+   ijsdev->k_path = 1;
 
269
+
 
270
+   code = (*ijsdev->prn_procs.fill_mask)(dev, data, dx, raster, id, x, y, w, h, pdcolor, depth, lop, pcpath);
 
271
 
 
272
-/* Versions 1.0 through 1.0.2 of hpijs report IJS version 0.29, and
 
273
-   require some workarounds. When more up-to-date hpijs versions
 
274
-   become ubiquitous, all these workarounds should be removed. */
 
275
-#define HPIJS_1_0_VERSION 29
 
276
+   ijsdev->k_path = 0;
 
277
+
 
278
+   return code;
 
279
+}
 
280
+
 
281
+private int gsijs_fill_path(gx_device * dev, const gs_imager_state * pis,
 
282
+      gx_path * ppath, const gx_fill_params * params,
 
283
+      const gx_drawing_color * pdcolor,
 
284
+      const gx_clip_path * pcpath)
 
285
+{
 
286
+   gx_device_ijs *ijsdev = (gx_device_ijs *)((gx_device_forward *)dev)->target;
 
287
+   int code;
 
288
+
 
289
+   ijsdev->k_path = 1;
 
290
+
 
291
+   code = (*ijsdev->prn_procs.fill_path)(dev, pis, ppath, params, pdcolor, pcpath);
 
292
+
 
293
+   ijsdev->k_path = 0;
 
294
+
 
295
+   return 0;
 
296
+}
 
297
+
 
298
+private int gsijs_stroke_path(gx_device * dev, const gs_imager_state * pis,
 
299
+        gx_path * ppath, const gx_stroke_params * params,
 
300
+        const gx_drawing_color * pdcolor,
 
301
+        const gx_clip_path * pcpath)
 
302
+{
 
303
+   gx_device_ijs *ijsdev = (gx_device_ijs *)((gx_device_forward *)dev)->target;
 
304
+   int code;
 
305
+
 
306
+   ijsdev->k_path = 1;
 
307
+
 
308
+   code = (*ijsdev->prn_procs.stroke_path)(dev, pis, ppath, params, pdcolor, pcpath);
 
309
+
 
310
+   ijsdev->k_path = 0;
 
311
+
 
312
+   return code;
 
313
+}
 
314
+
 
315
+/* ---------------- krgb banding playback procedures ---------------- */
 
316
+
 
317
+private int gsijs_get_bits(gx_device_printer * pdev, int y, byte * str, byte ** actual_data)
 
318
+{
 
319
+   gx_device_ijs *ijsdev = (gx_device_ijs *)pdev;
 
320
+   gx_device_clist_common *cdev = (gx_device_clist_common *)pdev;
 
321
+   int band_height = cdev->page_info.band_params.BandHeight;
 
322
+   int band_number = y/band_height;
 
323
+   int raster = (ijsdev->k_width+7) >> 3;       /* raster width in bytes, byte aligned */
 
324
+   int y1=raster*(y-(band_height*band_number));
 
325
 
326
+   if (y1 == 0)
 
327
+   {
 
328
+      /* First raster for band, clear k_band. Banding playback occurs on first raster. */
 
329
+      memset(ijsdev->k_band, 0, ijsdev->k_band_size); 
 
330
+   }
 
331
+
 
332
+   return gdev_prn_get_bits(pdev, y, str, actual_data);  /* get raster from regular band */
 
333
+}
 
334
+
 
335
+private int gsijs_k_get_bits(gx_device_printer * pdev, int y, byte ** actual_data)
 
336
+{
 
337
+   gx_device_ijs *ijsdev = (gx_device_ijs *)pdev;
 
338
+   gx_device_clist_common *cdev = (gx_device_clist_common *)pdev;
 
339
+   int band_height = cdev->page_info.band_params.BandHeight;
 
340
+   int band_number = y/band_height;
 
341
+   int raster = (ijsdev->k_width+7) >> 3;       /* raster width in bytes, byte aligned */
 
342
+   int y1=raster*(y-(band_height*band_number));
 
343
 
344
+   *actual_data = ijsdev->k_band+y1;
 
345
+
 
346
+   return 0;
 
347
+}
 
348
+
 
349
+private int gsijs_create_buf_device(gx_device **pbdev, gx_device *target,
 
350
+            const gx_render_plane_t *render_plane, gs_memory_t *mem, bool for_band)
 
351
+{
 
352
+   gx_device_ijs *ijsdev = (gx_device_ijs *)target;
 
353
+   int n_chan = ijsdev->color_info.num_components;
 
354
+   int code = gx_default_create_buf_device(pbdev, target, render_plane, mem, for_band);
 
355
+   if (code < 0 || n_chan != 3)
 
356
+      return code;
 
357
+
 
358
+   /* Save buffer (vector) procedures so that we can hook them during banding playback. */
 
359
+   ijsdev->prn_procs = (*pbdev)->procs;
 
360
+
 
361
+   /* Replace buffer procedures with krgb procedures. */
 
362
+   set_dev_proc(*pbdev, fill_rectangle, gsijs_fill_rectangle);
 
363
+   set_dev_proc(*pbdev, copy_mono, gsijs_copy_mono);
 
364
+   set_dev_proc(*pbdev, fill_mask, gsijs_fill_mask);
 
365
+   set_dev_proc(*pbdev, fill_path, gsijs_fill_path);
 
366
+   set_dev_proc(*pbdev, stroke_path, gsijs_stroke_path);
 
367
+
 
368
+   return code;
 
369
+}
 
370
+
 
371
+/* See if IJS server supports krgb. */
 
372
+private int
 
373
+gsijs_set_krgb_mode(gx_device_ijs *ijsdev)
 
374
+{
 
375
+    char buf[256];
 
376
+    int n_chan = ijsdev->color_info.num_components;
 
377
+    int code;
 
378
+
 
379
+    ijsdev->krgb_mode = 0;  /* default is no krgb */
 
380
+
 
381
+    if (n_chan != 3)
 
382
+        return 0;    /* no krgb support, not RGB colorspace */
 
383
+
 
384
+    buf[0] = 0;
 
385
+    code = ijs_client_enum_param(ijsdev->ctx, 0, "ColorSpace", buf, sizeof(buf)-1);
 
386
+    if (code >= 0)
 
387
+        buf[code] = 0;
 
388
+    if (strstr(buf, "KRGB") != NULL)
 
389
+    {
 
390
+        ijsdev->krgb_mode = 1;     /* yes KRGB is supported */
 
391
+        ijsdev->k_bits = 1;        /* KRGB = 1x8x8x8 */ 
 
392
+    }
 
393
+    else if (strstr(buf, "KxRGB") != NULL)
 
394
+    {
 
395
+        ijsdev->krgb_mode = 1;    /* yes KRGB is supported */
 
396
+        ijsdev->k_bits = 8;       /* KRGB = 8x8x8x8 */
 
397
+    }
 
398
+
 
399
+    return 0; 
 
400
+}
 
401
+
 
402
+/* ------ Private definitions ------ */
 
403
 
 
404
 private int
 
405
 gsijs_parse_wxh (const char *val, int size, double *pw, double *ph)
 
406
@@ -209,34 +554,6 @@
 
407
 }
 
408
 
 
409
 /**
 
410
- * gsijs_set_generic_params_hpijs: Set generic IJS parameters.
 
411
- *
 
412
- * This version is specialized for hpijs 1.0 through 1.0.2, and
 
413
- * accommodates a number of quirks.
 
414
- **/
 
415
-private int
 
416
-gsijs_set_generic_params_hpijs(gx_device_ijs *ijsdev)
 
417
-{
 
418
-    char buf[256];
 
419
-    int code = 0;
 
420
-
 
421
-    /* IjsParams, Duplex, and Tumble get set at this point because
 
422
-       they may affect margins. */
 
423
-    if (ijsdev->IjsParams) {
 
424
-       code = gsijs_client_set_param(ijsdev, "IjsParams", ijsdev->IjsParams);
 
425
-    }
 
426
-
 
427
-    if (code == 0 && ijsdev->Duplex_set) {
 
428
-       int duplex_val;
 
429
-       
 
430
-       duplex_val = ijsdev->Duplex ? (ijsdev->IjsTumble ? 1 : 2) : 0;
 
431
-       sprintf (buf, "%d", duplex_val);
 
432
-       code = gsijs_client_set_param(ijsdev, "Duplex", buf);
 
433
-    }
 
434
-    return code;
 
435
-}
 
436
-
 
437
-/**
 
438
  * gsijs_set_generic_params: Set generic IJS parameters.
 
439
  **/
 
440
 private int
 
441
@@ -247,9 +564,6 @@
 
442
     int i, j;
 
443
     char *value;
 
444
 
 
445
-    if (ijsdev->ijs_version == HPIJS_1_0_VERSION)
 
446
-       return gsijs_set_generic_params_hpijs(ijsdev);
 
447
-
 
448
     /* Split IjsParams into separate parameters and send to ijs server */
 
449
     value = NULL;
 
450
     for (i=0, j=0; (j < ijsdev->IjsParams_size) && (i < sizeof(buf)-1); j++) {
 
451
@@ -290,68 +604,6 @@
 
452
 }
 
453
 
 
454
 /**
 
455
- * gsijs_set_margin_params_hpijs: Do margin negotiation with IJS server.
 
456
- *
 
457
- * This version is specialized for hpijs 1.0 through 1.0.2, and
 
458
- * accommodates a number of quirks.
 
459
- **/
 
460
-private int
 
461
-gsijs_set_margin_params_hpijs(gx_device_ijs *ijsdev)
 
462
-{
 
463
-    char buf[256];
 
464
-    int code = 0;
 
465
-
 
466
-    if (code == 0) {
 
467
-       sprintf(buf, "%d", ijsdev->width);
 
468
-       code = gsijs_client_set_param(ijsdev, "Width", buf);
 
469
-    }
 
470
-    if (code == 0) {
 
471
-       sprintf(buf, "%d", ijsdev->height);
 
472
-       code = gsijs_client_set_param(ijsdev, "Height", buf);
 
473
-    }
 
474
-
 
475
-    if (code == 0) {
 
476
-       double printable_width, printable_height;
 
477
-       double printable_left, printable_top;
 
478
-       float m[4];
 
479
-
 
480
-       code = ijs_client_get_param(ijsdev->ctx, 0, "PrintableArea",
 
481
-                                  buf, sizeof(buf));
 
482
-       if (code == IJS_EUNKPARAM)
 
483
-           /* IJS server doesn't support margin negotiations.
 
484
-              That's ok. */
 
485
-           return 0;
 
486
-       else if (code >= 0) {
 
487
-           code = gsijs_parse_wxh(buf, code,
 
488
-                                   &printable_width, &printable_height);
 
489
-       }
 
490
-
 
491
-       if (code == 0) {
 
492
-           code = ijs_client_get_param(ijsdev->ctx, 0, "PrintableTopLeft",
 
493
-                                       buf, sizeof(buf));
 
494
-           if (code == IJS_EUNKPARAM)
 
495
-               return 0;
 
496
-           else if (code >= 0) {
 
497
-               code = gsijs_parse_wxh(buf, code,
 
498
-                                       &printable_left, &printable_top);
 
499
-           }
 
500
-       }
 
501
-
 
502
-       if (code == 0) {
 
503
-           m[0] = printable_left;
 
504
-           m[1] = ijsdev->MediaSize[1] * (1.0 / 72) -
 
505
-             printable_top - printable_height;
 
506
-           m[2] = ijsdev->MediaSize[0] * (1.0 / 72) -
 
507
-             printable_left - printable_width;
 
508
-           m[3] = printable_top;
 
509
-           gx_device_set_margins((gx_device *)ijsdev, m, true);
 
510
-       }
 
511
-    }
 
512
-
 
513
-    return code;
 
514
-}
 
515
-
 
516
-/**
 
517
  * gsijs_set_margin_params: Do margin negotiation with IJS server.
 
518
  **/
 
519
 private int
 
520
@@ -362,9 +614,6 @@
 
521
     int i, j;
 
522
     char *value;
 
523
 
 
524
-    if (ijsdev->ijs_version == HPIJS_1_0_VERSION)
 
525
-       return gsijs_set_margin_params_hpijs(ijsdev);
 
526
-
 
527
     /* Split IjsParams into separate parameters and send to ijs server */
 
528
     value = NULL;
 
529
     for (i=0, j=0; (j < ijsdev->IjsParams_size) && (i < sizeof(buf)-1); j++) {
 
530
@@ -531,12 +780,18 @@
 
531
     char buf[256];
 
532
     bool use_outputfd;
 
533
     int fd = -1;
 
534
+    long max_bitmap = ijsdev->space_params.MaxBitmap;
 
535
 
 
536
     if (strlen(ijsdev->IjsServer) == 0) {
 
537
        eprintf("ijs server not specified\n");
 
538
        return gs_note_error(gs_error_ioerror);
 
539
     }
 
540
 
 
541
+    ijsdev->space_params.MaxBitmap = 0;        /* force banding */
 
542
+
 
543
+    /* Set create_buf_device in printer device, so that we can hook the banding playback procedures. */
 
544
+    ijsdev->printer_procs.buf_procs.create_buf_device = gsijs_create_buf_device;
 
545
+
 
546
     /* Decide whether to use OutputFile or OutputFD. Note: how to
 
547
        determine this is a tricky question, so we just allow the
 
548
        user to set it.
 
549
@@ -551,6 +806,8 @@
 
550
     if (code < 0)
 
551
        return code;
 
552
 
 
553
+    ijsdev->space_params.MaxBitmap = max_bitmap;
 
554
+    
 
555
     if (use_outputfd) {
 
556
        /* Note: dup() may not be portable to all interesting IJS
 
557
           platforms. In that case, this branch should be #ifdef'ed out.
 
558
@@ -610,6 +867,9 @@
 
559
     if (code >= 0)
 
560
        code = gsijs_set_margin_params(ijsdev);
 
561
 
 
562
+    if (code >= 0)
 
563
+        code = gsijs_set_krgb_mode(ijsdev);
 
564
+
 
565
     return code;
 
566
 }
 
567
 
 
568
@@ -690,21 +950,6 @@
 
569
     return min(width, end);
 
570
 }
 
571
 
 
572
-private int ijs_all_white(unsigned char *data, int size)
 
573
-{
 
574
-   int clean = 1;
 
575
-   int i;
 
576
-   for (i = 0; i < size; i++)
 
577
-   {
 
578
-     if (data[i] != 0xFF)
 
579
-     {
 
580
-        clean = 0;
 
581
-        break;
 
582
-     }
 
583
-   }
 
584
-   return clean;
 
585
-}
 
586
-
 
587
 /* Print a page.  Don't use normal printer gdev_prn_output_page 
 
588
  * because it opens the output file.
 
589
  */
 
590
@@ -715,8 +960,10 @@
 
591
     gx_device_printer *pdev = (gx_device_printer *)dev;
 
592
     int raster = gdev_prn_raster(pdev);
 
593
     int ijs_width, ijs_height;
 
594
-    int row_bytes;
 
595
+    int row_bytes, k_row_bytes=0;
 
596
     int n_chan = pdev->color_info.num_components;
 
597
+    int krgb_mode = ijsdev->krgb_mode;
 
598
+    int k_bits = ijsdev->k_bits;
 
599
     unsigned char *data;
 
600
     char buf[256];
 
601
     double xres = pdev->HWResolution[0];
 
602
@@ -732,13 +979,23 @@
 
603
 
 
604
     /* Determine bitmap width and height */
 
605
     ijs_height = gdev_prn_print_scan_lines(dev);
 
606
-    if (ijsdev->ijs_version == HPIJS_1_0_VERSION) {
 
607
-       ijs_width = pdev->width;
 
608
-    } else {
 
609
        ijs_width = gsijs_raster_width(dev);
 
610
-    }
 
611
+
 
612
     row_bytes = (ijs_width * pdev->color_info.depth + 7) >> 3;
 
613
 
 
614
+    if (krgb_mode)
 
615
+    {
 
616
+        gx_device_clist_common *cdev = (gx_device_clist_common *)dev;
 
617
+        int band_height = cdev->page_info.band_params.BandHeight;
 
618
+        k_row_bytes = (ijs_width + 7) >> 3;
 
619
+
 
620
+        /* Create banding buffer for k plane. */
 
621
+        ijsdev->k_width = ijs_width;
 
622
+        ijsdev->k_band_size = band_height * k_row_bytes;   
 
623
+        if ((ijsdev->k_band = gs_malloc(pdev->memory, ijsdev->k_band_size, 1, "gsijs_output_page")) == (unsigned char *)NULL)
 
624
+           return gs_note_error(gs_error_VMerror);
 
625
+    }
 
626
+
 
627
     /* Required page parameters */
 
628
     sprintf(buf, "%d", n_chan);
 
629
     gsijs_client_set_param(ijsdev, "NumChan", buf);
 
630
@@ -747,44 +1004,71 @@
 
631
 
 
632
     /* This needs to become more sophisticated for DeviceN. */
 
633
     strcpy(buf, (n_chan == 4) ? "DeviceCMYK" : 
 
634
-       ((n_chan == 3) ? "DeviceRGB" : "DeviceGray"));
 
635
+       ((n_chan == 3) ? (krgb_mode ? ((k_bits == 1) ? "KRGB" : "KxRGB") : "DeviceRGB") : "DeviceGray"));
 
636
     gsijs_client_set_param(ijsdev, "ColorSpace", buf);
 
637
 
 
638
-    /* If hpijs 1.0, don't set width and height here, because it
 
639
-       expects them to be the paper size. */
 
640
-    if (ijsdev->ijs_version != HPIJS_1_0_VERSION) {
 
641
-       sprintf(buf, "%d", ijs_width);
 
642
-       gsijs_client_set_param(ijsdev, "Width", buf);
 
643
-       sprintf(buf, "%d", ijs_height);
 
644
-       gsijs_client_set_param(ijsdev, "Height", buf);
 
645
-    }
 
646
+    sprintf(buf, "%d", ijs_width);
 
647
+    gsijs_client_set_param(ijsdev, "Width", buf);
 
648
+    sprintf(buf, "%d", ijs_height);
 
649
+    gsijs_client_set_param(ijsdev, "Height", buf);
 
650
 
 
651
     sprintf(buf, "%gx%g", xres, yres);
 
652
     gsijs_client_set_param(ijsdev, "Dpi", buf);
 
653
 
 
654
+#ifdef KRGB_DEBUG
 
655
+    int kfd, rgbfd;
 
656
+    char sz[128];
 
657
+    kfd = open("/tmp/k.pbm", O_CREAT | O_TRUNC | O_RDWR, 0644);
 
658
+    rgbfd = open("/tmp/rgb.ppm", O_CREAT | O_TRUNC | O_RDWR, 0644);
 
659
+    snprintf(sz, sizeof(sz), "P4\n#gdevijs test\n%d\n%d\n", ijs_width, ijs_height);
 
660
+    write(kfd, sz, strlen(sz));
 
661
+    snprintf(sz, sizeof(sz), "P6\n#gdevijs test\n%d\n%d\n255\n", ijs_width, ijs_height);
 
662
+    write(rgbfd, sz, strlen(sz));
 
663
+#endif
 
664
+
 
665
     for (i=0; i<num_copies; i++) {
 
666
        unsigned char *actual_data;
 
667
        ijs_client_begin_cmd (ijsdev->ctx, IJS_CMD_BEGIN_PAGE);
 
668
        status = ijs_client_send_cmd_wait(ijsdev->ctx);
 
669
 
 
670
        for (y = 0; y < ijs_height; y++) {
 
671
-           code = gdev_prn_get_bits(pdev, y, data, &actual_data);
 
672
-           if (code < 0)
 
673
-               break;
 
674
+            if (krgb_mode)
 
675
+                code = gsijs_get_bits(pdev, y, data, &actual_data);
 
676
+            else
 
677
+                code = gdev_prn_get_bits(pdev, y, data, &actual_data);
 
678
+            if (code < 0)
 
679
+                break;
 
680
+#ifdef KRGB_DEBUG
 
681
+            write(rgbfd, actual_data, row_bytes);
 
682
+#endif
 
683
+            status = ijs_client_send_data_wait(ijsdev->ctx, 0, (char *)actual_data, row_bytes);
 
684
+            if (status)
 
685
+                break;
 
686
 
 
687
-           if (ijsdev->ijs_version == HPIJS_1_0_VERSION &&
 
688
-               ijs_all_white(actual_data, row_bytes))
 
689
-               status = ijs_client_send_data_wait(ijsdev->ctx, 0, NULL, 0);
 
690
-           else
 
691
-               status = ijs_client_send_data_wait(ijsdev->ctx, 0,
 
692
-                   (char *)actual_data, row_bytes);
 
693
-           if (status)
 
694
-               break;
 
695
+            if (krgb_mode) {
 
696
+                code = gsijs_k_get_bits(pdev, y, &actual_data);
 
697
+                if (code < 0)
 
698
+                    break;
 
699
+#ifdef KRGB_DEBUG
 
700
+                write(kfd, actual_data, k_row_bytes);
 
701
+#endif
 
702
+                status = ijs_client_send_data_wait(ijsdev->ctx, 0, (char *)actual_data, k_row_bytes);
 
703
+                if (status)
 
704
+                    break;
 
705
+           }
 
706
        }
 
707
        ijs_client_begin_cmd(ijsdev->ctx, IJS_CMD_END_PAGE);
 
708
        status = ijs_client_send_cmd_wait(ijsdev->ctx);
 
709
     }
 
710
 
 
711
+#ifdef KRGB_DEBUG
 
712
+    close(kfd);
 
713
+    close(rgbfd);
 
714
+#endif
 
715
+
 
716
+    if(krgb_mode)
 
717
+        gs_free(pdev->memory, ijsdev->k_band, ijsdev->k_band_size, 1, "gsijs_output_page");
 
718
+
 
719
     gs_free_object(pdev->memory, data, "gsijs_output_page");
 
720
 
 
721
     endcode = (pdev->buffer_space && !pdev->is_async_renderer ?
 
722
@@ -1090,7 +1374,6 @@
 
723
        dprintf2("ijs: Can't set parameter %s=%s\n", key, value);
 
724
     return code;
 
725
 }
 
726
 
727
 
 
728
 private int
 
729
 gsijs_set_color_format(gx_device_ijs *ijsdev)