diff options
Diffstat (limited to 'gs/base/gdevimdi.c')
-rw-r--r-- | gs/base/gdevimdi.c | 252 |
1 files changed, 122 insertions, 130 deletions
diff --git a/gs/base/gdevimdi.c b/gs/base/gdevimdi.c index 0a6522c5b..97587706f 100644 --- a/gs/base/gdevimdi.c +++ b/gs/base/gdevimdi.c @@ -1,12 +1,12 @@ /* Copyright (C) 1999 Aladdin Enterprises. All rights reserved. - + This software is provided AS-IS with no warranty, either express or implied. - + This software is distributed under license and may not be copied, modified or distributed except as expressly authorized under the terms of the license contained in the file LICENSE in this distribution. - + For more information about licensing, please refer to http://www.ghostscript.com/licensing/. For information on commercial licensing, go to http://www.artifex.com/licensing/ or @@ -82,10 +82,10 @@ static const gx_device_procs imdi_procs = const gx_device_imdi gs_imdi_device = { prn_device_body(gx_device_imdi, imdi_procs, "imdi", - DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS, - X_DPI, Y_DPI, - 0, 0, 0, 0, /* Margins */ - 3, 24, 255, 255, 256, 256, imdi_print_page) + DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS, + X_DPI, Y_DPI, + 0, 0, 0, 0, /* Margins */ + 3, 24, 255, 255, 256, 256, imdi_print_page) }; static double incurve(void *ctx, int ch, double val) @@ -111,35 +111,33 @@ imdi_open_device(gx_device *dev) /* Open and read profile */ - idev->icc_link_profile = gsicc_get_profile_handle_file(LINK_ICC_NAME, + idev->icc_link_profile = gsicc_get_profile_handle_file(LINK_ICC_NAME, strlen(LINK_ICC_NAME), dev->memory); if (idev->icc_link_profile == NULL) return gs_throw(-1, "Could not create link profile for imdi device"); if (idev->icc_link_profile->num_comps != 3) - return gs_throw1(-1, "profile must have 3 input channels. got %d.", + return gs_throw1(-1, "profile must have 3 input channels. got %d.", idev->icc_link_profile->num_comps); if (idev->icc_link_profile->num_comps_out != 4) - return gs_throw1(-1, "profile must have 4 output channels. got %d.", + return gs_throw1(-1, "profile must have 4 output channels. got %d.", idev->icc_link_profile->num_comps_out); - rendering_params.black_point_comp = false; rendering_params.object_type = GS_DEVICE_DOESNT_SUPPORT_TAGS; /* Already rendered */ rendering_params.rendering_intent = gsPERCEPTUAL; - - idev->icc_link = gscms_get_link(idev->icc_link_profile, + + idev->icc_link = gscms_get_link(idev->icc_link_profile, NULL, &rendering_params); if (!idev->icc_link) - return gs_throw(-1, "could not create ICC link handle"); + return gs_throw(-1, "could not create ICC link handle"); return gdev_prn_open(dev); } - /* * Close device and clean up ICC structures. */ @@ -155,7 +153,6 @@ imdi_close_device(gx_device *dev) return gdev_prn_close(dev); } - /* * Output the page raster. */ @@ -193,20 +190,20 @@ imdi_print_page(gx_device_printer *pdev, FILE *prn_stream) for (k = 0; k < 4; k++) { - char name[256]; + char name[256]; - sprintf(name, "%s.%c.pgm", pdev->fname, "cmyk"[k]); + sprintf(name, "%s.%c.pgm", pdev->fname, "cmyk"[k]); - dprintf1("output file: %s\n", name); + dprintf1("output file: %s\n", name); - fp[k] = fopen(name, "wb"); - if (!fp[k]) - { - code = gs_throw2(-1, "could not open file: %s (%s)", name, strerror(errno)); - goto cleanup; - } + fp[k] = fopen(name, "wb"); + if (!fp[k]) + { + code = gs_throw2(-1, "could not open file: %s (%s)", name, strerror(errno)); + goto cleanup; + } - fprintf(fp[k], "P5\n%d %d\n255\n", pdev->width, pdev->height); + fprintf(fp[k], "P5\n%d %d\n255\n", pdev->width, pdev->height); } /* @@ -218,8 +215,8 @@ imdi_print_page(gx_device_printer *pdev, FILE *prn_stream) srcbuffer = gs_malloc(pdev->memory, srcstride, 1, "imdi_print_page(srcbuffer)"); if (!srcbuffer) { - code = gs_throw1(-1, "outofmem: src buffer %d", srcstride); - goto cleanup; + code = gs_throw1(-1, "outofmem: src buffer %d", srcstride); + goto cleanup; } dstplanes = 4; @@ -227,8 +224,8 @@ imdi_print_page(gx_device_printer *pdev, FILE *prn_stream) dstbuffer = gs_malloc(pdev->memory, dststride, 1, "imdi_print_page(dstbuffer)"); if (!dstbuffer) { - code = gs_throw1(-1, "outofmem: dst buffer %d", dststride); - goto cleanup; + code = gs_throw1(-1, "outofmem: dst buffer %d", dststride); + goto cleanup; } /* @@ -237,66 +234,66 @@ imdi_print_page(gx_device_printer *pdev, FILE *prn_stream) for (y = 0; y < pdev->height; y++) { - gdev_prn_get_bits(pdev, y, srcbuffer, &srcdata); + gdev_prn_get_bits(pdev, y, srcbuffer, &srcdata); - /* write rgb to original output file */ - fwrite(srcdata, 1, srcstride, prn_stream); + /* write rgb to original output file */ + fwrite(srcdata, 1, srcstride, prn_stream); #if 1 /* Collect runlengths */ - { - void *inp[1]; - void *outp[1]; - int sx, ex; - int w = pdev->width; + { + void *inp[1]; + void *outp[1]; + int sx, ex; + int w = pdev->width; - sx = ex = 0; + sx = ex = 0; - while (sx < w) - { - inp[0] = srcdata + sx * 3; - outp[0] = dstbuffer + sx * 4; + while (sx < w) + { + inp[0] = srcdata + sx * 3; + outp[0] = dstbuffer + sx * 4; - while (ex < w && - srcdata[ex * 3 + 0] == srcdata[sx * 3 + 0] && - srcdata[ex * 3 + 1] == srcdata[sx * 3 + 1] && - srcdata[ex * 3 + 2] == srcdata[sx * 3 + 2]) - { - ex ++; - } + while (ex < w && + srcdata[ex * 3 + 0] == srcdata[sx * 3 + 0] && + srcdata[ex * 3 + 1] == srcdata[sx * 3 + 1] && + srcdata[ex * 3 + 2] == srcdata[sx * 3 + 2]) + { + ex ++; + } - /* same-run */ - if (ex - sx > 1) - { - nsame ++; lsame += ex - sx; + /* same-run */ + if (ex - sx > 1) + { + nsame ++; lsame += ex - sx; /* Transform the color */ gscms_transform_color(idev->icc_link, inp, outp, 1, NULL); - for (x = sx + 1; x < ex; x++) - { - dstbuffer[x * 4 + 0] = dstbuffer[sx * 4 + 0]; - dstbuffer[x * 4 + 1] = dstbuffer[sx * 4 + 1]; - dstbuffer[x * 4 + 2] = dstbuffer[sx * 4 + 2]; - dstbuffer[x * 4 + 3] = dstbuffer[sx * 4 + 3]; - } - } - - /* diff-run */ - else - { - ndiff ++; - - while (ex < w && - srcdata[ex * 3 + 0] != srcdata[ex * 3 - 3] && - srcdata[ex * 3 + 1] != srcdata[ex * 3 - 2] && - srcdata[ex * 3 + 2] != srcdata[ex * 3 - 1]) - { - ex ++; - } - - ldiff += ex - sx; + for (x = sx + 1; x < ex; x++) + { + dstbuffer[x * 4 + 0] = dstbuffer[sx * 4 + 0]; + dstbuffer[x * 4 + 1] = dstbuffer[sx * 4 + 1]; + dstbuffer[x * 4 + 2] = dstbuffer[sx * 4 + 2]; + dstbuffer[x * 4 + 3] = dstbuffer[sx * 4 + 3]; + } + } + + /* diff-run */ + else + { + ndiff ++; + + while (ex < w && + srcdata[ex * 3 + 0] != srcdata[ex * 3 - 3] && + srcdata[ex * 3 + 1] != srcdata[ex * 3 - 2] && + srcdata[ex * 3 + 2] != srcdata[ex * 3 - 1]) + { + ex ++; + } + + ldiff += ex - sx; /* This needs to be done more efficiently */ @@ -311,20 +308,20 @@ imdi_print_page(gx_device_printer *pdev, FILE *prn_stream) gscms_transform_color_buffer(idev->icc_link, &input_buff_desc, &output_buff_desc, inp, outp); - } + } - sx = ex; - } - } + sx = ex; + } + } #endif #if 0 /* Call IMDI for entire scanline */ - void *inp[1]; - void *outp[1]; + void *inp[1]; + void *outp[1]; - inp[0] = srcdata; - outp[0] = dstbuffer; + inp[0] = srcdata; + outp[0] = dstbuffer; gsicc_init_buffer(&input_buff_desc, 3, 1, false, false, false, 0, width*3, @@ -337,66 +334,62 @@ imdi_print_page(gx_device_printer *pdev, FILE *prn_stream) gscms_transform_color_buffer(idev->icc_link, &input_buff_desc, &output_buff_desc, inp, outp); - - #if 0 - /* output planar data to auxiliary output files */ - for (x = 0; x < pdev->width; x++) - for (k = 0; k < 4; k++) - putc(dstbuffer[x * 4 + k], fp[k]); + /* output planar data to auxiliary output files */ + for (x = 0; x < pdev->width; x++) + for (k = 0; k < 4; k++) + putc(dstbuffer[x * 4 + k], fp[k]); #endif #endif #if 0 /* Call IMDI for every pixel */ - for (x = 0; x < pdev->width; x++) - { - void *inp[1]; - void *outp[1]; + for (x = 0; x < pdev->width; x++) + { + void *inp[1]; + void *outp[1]; - inp[0] = srcdata + x * 3; - outp[0] = dstbuffer + x * 4; + inp[0] = srcdata + x * 3; + outp[0] = dstbuffer + x * 4; /* Transform the color */ gscms_transform_color(idev->icc_link, inp, outp, 1, NULL); - - /* output planar data to auxiliary output files */ - for (k = 0; k < 4; k++) - putc(dstbuffer[x * 4 + k], fp[k]); - } + /* output planar data to auxiliary output files */ + for (k = 0; k < 4; k++) + putc(dstbuffer[x * 4 + k], fp[k]); + } #endif #if 0 /* Slow but accurate every pixel */ - for (x = 0; x < pdev->width; x++) - { - srcpixel[0] = srcdata[x * 3 + 0] / 255.0; - srcpixel[1] = srcdata[x * 3 + 1] / 255.0; - srcpixel[2] = srcdata[x * 3 + 2] / 255.0; - - code = idev->luo->lookup(idev->luo, dstpixel, srcpixel); - if (code > 1) - { - code = gs_throw1(-1, "icc lookup failed: %s", idev->icco->err); - goto cleanup; - } - - dstbuffer[x * 4 + 0] = dstpixel[0] * 255 + 0.5; - dstbuffer[x * 4 + 1] = dstpixel[1] * 255 + 0.5; - dstbuffer[x * 4 + 2] = dstpixel[2] * 255 + 0.5; - dstbuffer[x * 4 + 3] = dstpixel[3] * 255 + 0.5; - - /* output planar data to auxiliary output files */ - for (k = 0; k < 4; k++) - putc(dstbuffer[x * 4 + k], fp[k]); - } + for (x = 0; x < pdev->width; x++) + { + srcpixel[0] = srcdata[x * 3 + 0] / 255.0; + srcpixel[1] = srcdata[x * 3 + 1] / 255.0; + srcpixel[2] = srcdata[x * 3 + 2] / 255.0; + + code = idev->luo->lookup(idev->luo, dstpixel, srcpixel); + if (code > 1) + { + code = gs_throw1(-1, "icc lookup failed: %s", idev->icco->err); + goto cleanup; + } + + dstbuffer[x * 4 + 0] = dstpixel[0] * 255 + 0.5; + dstbuffer[x * 4 + 1] = dstpixel[1] * 255 + 0.5; + dstbuffer[x * 4 + 2] = dstpixel[2] * 255 + 0.5; + dstbuffer[x * 4 + 3] = dstpixel[3] * 255 + 0.5; + + /* output planar data to auxiliary output files */ + for (k = 0; k < 4; k++) + putc(dstbuffer[x * 4 + k], fp[k]); + } #endif } dprintf4("same=%d/%d diff=%d/%d\n", lsame, nsame, ldiff, ndiff); - /* * Cleanup memory and files. */ @@ -404,15 +397,14 @@ imdi_print_page(gx_device_printer *pdev, FILE *prn_stream) cleanup: for (k = 0; k < 4; k++) - if (fp[k]) - fclose(fp[k]); + if (fp[k]) + fclose(fp[k]); if (dstbuffer) - gs_free(pdev->memory, dstbuffer, dststride, 1, "imdi_print_page(dstbuffer)"); + gs_free(pdev->memory, dstbuffer, dststride, 1, "imdi_print_page(dstbuffer)"); if (srcbuffer) - gs_free(pdev->memory, srcbuffer, srcstride, 1, "imdi_print_page(srcbuffer)"); + gs_free(pdev->memory, srcbuffer, srcstride, 1, "imdi_print_page(srcbuffer)"); return code; } - |