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

« back to all changes in this revision

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