1
1
/* Copyright (C) 1999 Aladdin Enterprises. All rights reserved.
3
3
This software is provided AS-IS with no warranty, either express or
6
6
This software is distributed under license and may not be copied,
7
7
modified or distributed except as expressly authorized under the terms
8
8
of the license contained in the file LICENSE in this distribution.
10
10
For more information about licensing, please refer to
11
11
http://www.ghostscript.com/licensing/. For information on
12
12
commercial licensing, go to http://www.artifex.com/licensing/ or
82
82
const gx_device_imdi gs_imdi_device =
84
84
prn_device_body(gx_device_imdi, imdi_procs, "imdi",
85
DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
87
0, 0, 0, 0, /* Margins */
88
3, 24, 255, 255, 256, 256, imdi_print_page)
85
DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
87
0, 0, 0, 0, /* Margins */
88
3, 24, 255, 255, 256, 256, imdi_print_page)
91
91
static double incurve(void *ctx, int ch, double val)
112
112
/* Open and read profile */
114
idev->icc_link_profile = gsicc_get_profile_handle_file(LINK_ICC_NAME,
114
idev->icc_link_profile = gsicc_get_profile_handle_file(LINK_ICC_NAME,
115
115
strlen(LINK_ICC_NAME), dev->memory);
117
117
if (idev->icc_link_profile == NULL)
118
118
return gs_throw(-1, "Could not create link profile for imdi device");
120
120
if (idev->icc_link_profile->num_comps != 3)
121
return gs_throw1(-1, "profile must have 3 input channels. got %d.",
121
return gs_throw1(-1, "profile must have 3 input channels. got %d.",
122
122
idev->icc_link_profile->num_comps);
123
123
if (idev->icc_link_profile->num_comps_out != 4)
124
return gs_throw1(-1, "profile must have 4 output channels. got %d.",
124
return gs_throw1(-1, "profile must have 4 output channels. got %d.",
125
125
idev->icc_link_profile->num_comps_out);
128
127
rendering_params.black_point_comp = false;
129
rendering_params.object_type = GS_DEVICE_DOESNT_SUPPORT_TAGS; /* Already rendered */
128
rendering_params.graphics_type_tag = GS_UNKNOWN_TAG; /* Already rendered */
130
129
rendering_params.rendering_intent = gsPERCEPTUAL;
132
idev->icc_link = gscms_get_link(idev->icc_link_profile,
131
idev->icc_link = gscms_get_link(idev->icc_link_profile,
133
132
NULL, &rendering_params);
135
134
if (!idev->icc_link)
136
return gs_throw(-1, "could not create ICC link handle");
135
return gs_throw(-1, "could not create ICC link handle");
138
137
return gdev_prn_open(dev);
144
142
* Close device and clean up ICC structures.
194
191
for (k = 0; k < 4; k++)
198
sprintf(name, "%s.%c.pgm", pdev->fname, "cmyk"[k]);
200
dprintf1("output file: %s\n", name);
202
fp[k] = fopen(name, "wb");
205
code = gs_throw2(-1, "could not open file: %s (%s)", name, strerror(errno));
209
fprintf(fp[k], "P5\n%d %d\n255\n", pdev->width, pdev->height);
195
sprintf(name, "%s.%c.pgm", pdev->fname, "cmyk"[k]);
197
dprintf1("output file: %s\n", name);
199
fp[k] = gp_fopen(name, "wb");
202
code = gs_throw2(-1, "could not open file: %s (%s)", name, strerror(errno));
206
fprintf(fp[k], "P5\n%d %d\n255\n", pdev->width, pdev->height);
238
235
for (y = 0; y < pdev->height; y++)
240
gdev_prn_get_bits(pdev, y, srcbuffer, &srcdata);
237
gdev_prn_get_bits(pdev, y, srcbuffer, &srcdata);
242
/* write rgb to original output file */
243
fwrite(srcdata, 1, srcstride, prn_stream);
239
/* write rgb to original output file */
240
fwrite(srcdata, 1, srcstride, prn_stream);
245
242
#if 1 /* Collect runlengths */
257
inp[0] = srcdata + sx * 3;
258
outp[0] = dstbuffer + sx * 4;
261
srcdata[ex * 3 + 0] == srcdata[sx * 3 + 0] &&
262
srcdata[ex * 3 + 1] == srcdata[sx * 3 + 1] &&
263
srcdata[ex * 3 + 2] == srcdata[sx * 3 + 2])
271
nsame ++; lsame += ex - sx;
254
inp[0] = srcdata + sx * 3;
255
outp[0] = dstbuffer + sx * 4;
258
srcdata[ex * 3 + 0] == srcdata[sx * 3 + 0] &&
259
srcdata[ex * 3 + 1] == srcdata[sx * 3 + 1] &&
260
srcdata[ex * 3 + 2] == srcdata[sx * 3 + 2])
268
nsame ++; lsame += ex - sx;
273
270
/* Transform the color */
274
271
gscms_transform_color(idev->icc_link, inp,
277
for (x = sx + 1; x < ex; x++)
279
dstbuffer[x * 4 + 0] = dstbuffer[sx * 4 + 0];
280
dstbuffer[x * 4 + 1] = dstbuffer[sx * 4 + 1];
281
dstbuffer[x * 4 + 2] = dstbuffer[sx * 4 + 2];
282
dstbuffer[x * 4 + 3] = dstbuffer[sx * 4 + 3];
292
srcdata[ex * 3 + 0] != srcdata[ex * 3 - 3] &&
293
srcdata[ex * 3 + 1] != srcdata[ex * 3 - 2] &&
294
srcdata[ex * 3 + 2] != srcdata[ex * 3 - 1])
274
for (x = sx + 1; x < ex; x++)
276
dstbuffer[x * 4 + 0] = dstbuffer[sx * 4 + 0];
277
dstbuffer[x * 4 + 1] = dstbuffer[sx * 4 + 1];
278
dstbuffer[x * 4 + 2] = dstbuffer[sx * 4 + 2];
279
dstbuffer[x * 4 + 3] = dstbuffer[sx * 4 + 3];
289
srcdata[ex * 3 + 0] != srcdata[ex * 3 - 3] &&
290
srcdata[ex * 3 + 1] != srcdata[ex * 3 - 2] &&
291
srcdata[ex * 3 + 2] != srcdata[ex * 3 - 1])
301
298
/* This needs to be done more efficiently */
311
308
gscms_transform_color_buffer(idev->icc_link, &input_buff_desc,
312
309
&output_buff_desc, inp, outp);
322
319
#if 0 /* Call IMDI for entire scanline */
329
326
gsicc_init_buffer(&input_buff_desc, 3, 1,
330
327
false, false, false, 0, width*3,
337
334
gscms_transform_color_buffer(idev->icc_link, &input_buff_desc,
338
335
&output_buff_desc, inp, outp);
343
/* output planar data to auxiliary output files */
344
for (x = 0; x < pdev->width; x++)
345
for (k = 0; k < 4; k++)
346
putc(dstbuffer[x * 4 + k], fp[k]);
338
/* output planar data to auxiliary output files */
339
for (x = 0; x < pdev->width; x++)
340
for (k = 0; k < 4; k++)
341
putc(dstbuffer[x * 4 + k], fp[k]);
350
345
#if 0 /* Call IMDI for every pixel */
351
for (x = 0; x < pdev->width; x++)
346
for (x = 0; x < pdev->width; x++)
356
inp[0] = srcdata + x * 3;
357
outp[0] = dstbuffer + x * 4;
351
inp[0] = srcdata + x * 3;
352
outp[0] = dstbuffer + x * 4;
359
354
/* Transform the color */
360
355
gscms_transform_color(idev->icc_link, inp,
364
/* output planar data to auxiliary output files */
365
for (k = 0; k < 4; k++)
366
putc(dstbuffer[x * 4 + k], fp[k]);
358
/* output planar data to auxiliary output files */
359
for (k = 0; k < 4; k++)
360
putc(dstbuffer[x * 4 + k], fp[k]);
370
364
#if 0 /* Slow but accurate every pixel */
372
for (x = 0; x < pdev->width; x++)
374
srcpixel[0] = srcdata[x * 3 + 0] / 255.0;
375
srcpixel[1] = srcdata[x * 3 + 1] / 255.0;
376
srcpixel[2] = srcdata[x * 3 + 2] / 255.0;
378
code = idev->luo->lookup(idev->luo, dstpixel, srcpixel);
381
code = gs_throw1(-1, "icc lookup failed: %s", idev->icco->err);
385
dstbuffer[x * 4 + 0] = dstpixel[0] * 255 + 0.5;
386
dstbuffer[x * 4 + 1] = dstpixel[1] * 255 + 0.5;
387
dstbuffer[x * 4 + 2] = dstpixel[2] * 255 + 0.5;
388
dstbuffer[x * 4 + 3] = dstpixel[3] * 255 + 0.5;
390
/* output planar data to auxiliary output files */
391
for (k = 0; k < 4; k++)
392
putc(dstbuffer[x * 4 + k], fp[k]);
366
for (x = 0; x < pdev->width; x++)
368
srcpixel[0] = srcdata[x * 3 + 0] / 255.0;
369
srcpixel[1] = srcdata[x * 3 + 1] / 255.0;
370
srcpixel[2] = srcdata[x * 3 + 2] / 255.0;
372
code = idev->luo->lookup(idev->luo, dstpixel, srcpixel);
375
code = gs_throw1(-1, "icc lookup failed: %s", idev->icco->err);
379
dstbuffer[x * 4 + 0] = dstpixel[0] * 255 + 0.5;
380
dstbuffer[x * 4 + 1] = dstpixel[1] * 255 + 0.5;
381
dstbuffer[x * 4 + 2] = dstpixel[2] * 255 + 0.5;
382
dstbuffer[x * 4 + 3] = dstpixel[3] * 255 + 0.5;
384
/* output planar data to auxiliary output files */
385
for (k = 0; k < 4; k++)
386
putc(dstbuffer[x * 4 + k], fp[k]);
397
391
dprintf4("same=%d/%d diff=%d/%d\n", lsame, nsame, ldiff, ndiff);
401
394
* Cleanup memory and files.
406
399
for (k = 0; k < 4; k++)
411
gs_free(pdev->memory, dstbuffer, dststride, 1, "imdi_print_page(dstbuffer)");
404
gs_free(pdev->memory, dstbuffer, dststride, 1, "imdi_print_page(dstbuffer)");
414
gs_free(pdev->memory, srcbuffer, srcstride, 1, "imdi_print_page(srcbuffer)");
407
gs_free(pdev->memory, srcbuffer, srcstride, 1, "imdi_print_page(srcbuffer)");