diff options
author | Marcos H. Woehrmann <marcos.woehrmann@artifex.com> | 2011-12-10 16:41:06 -0800 |
---|---|---|
committer | Marcos H. Woehrmann <marcos.woehrmann@artifex.com> | 2011-12-10 16:51:32 -0800 |
commit | 70b1623bf91ea2a75da69f40caefb7efa56f49d9 (patch) | |
tree | 440deb7c3a1cb49b173973c03677c2667b554ec0 | |
parent | 9a2555a91fbc2fa73a6e2f8f4035b58b4ff5ae57 (diff) |
Add ink coverage device: inkconv. Resolves Bug 692665.
Add the inkcov device, written by sebastian.kapfer@physik.uni-erlangen.de.
This dummy device produce output listing the percentage of pixels
containing c, m, y, and k ink.
No cluster differences expected since this device isn't tested by the
cluster.
-rw-r--r-- | gs/base/configure.ac | 2 | ||||
-rw-r--r-- | gs/base/gdevicov.c | 113 | ||||
-rw-r--r-- | gs/base/lib.mak | 8 | ||||
-rw-r--r-- | gs/base/macos-mcp.mak | 2 | ||||
-rw-r--r-- | gs/base/macosx.mak | 2 | ||||
-rw-r--r-- | gs/base/openvms.mak | 2 | ||||
-rw-r--r-- | gs/base/unix-gcc.mak | 2 | ||||
-rw-r--r-- | gs/base/unixansi.mak | 2 | ||||
-rw-r--r-- | gs/ghostscript.vcproj | 6 |
9 files changed, 132 insertions, 7 deletions
diff --git a/gs/base/configure.ac b/gs/base/configure.ac index 0ea0b80ac..ac9c34849 100644 --- a/gs/base/configure.ac +++ b/gs/base/configure.ac @@ -1333,7 +1333,7 @@ JPEG_DEVS='jpeg jpeggray jpegcmyk' TIFF_DEVS='tiffs tiff12nc tiff24nc tiff48nc tiff32nc tiff64nc tiffcrle tifflzw tiffpack tiffgray tiffsep tiffsep1 tiffscaled tiffscaled8 tiffscaled24' PCX_DEVS='pcxmono pcxgray pcx16 pcx256 pcx24b pcxcmyk pcx2up' PBM_DEVS='pbm pbmraw pgm pgmraw pgnm pgnmraw pnm pnmraw ppm ppmraw pkm pkmraw pksm pksmraw pam pamcmyk4 pamcmyk32 plan plang planm planc plank' -PS_DEVS='psdf psdcmyk psdrgb pdfwrite pswrite ps2write epswrite psgray psmono psrgb bbox txtwrite' +PS_DEVS='psdf psdcmyk psdrgb pdfwrite pswrite ps2write epswrite psgray psmono psrgb bbox txtwrite inkcov' MISC_FDEVS='ccr cif inferno mag16 mag256 mgr4 mgr8 mgrgray2 mgrgray4 mgrgray8 mgrmono miff24 plan9bm sgirgb sunhmono bit bitrgb bitrgbtags bitcmyk devicen spotcmyk xcf' SVGDEV='svgwrite' diff --git a/gs/base/gdevicov.c b/gs/base/gdevicov.c new file mode 100644 index 000000000..e934ee09e --- /dev/null +++ b/gs/base/gdevicov.c @@ -0,0 +1,113 @@ +/* Copyright (C) 2011 Artifex Software, Inc. + 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 that + license. Refer to licensing information at http://www.artifex.com/ + or contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134, + San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further information. +*/ + +/* $Id$ */ + +/* inkcov: compute ink coverage of the document being rendered. + * originally copyright 2011 Sebastian Kapfer <sebastian.kapfer@physik.uni-erlangen.de> + * but assigned to Artifex Software, Inc. (see http://bugs.ghostscript.com/show_bug.cgi?id=692665) + * + * output is plain text; one line per page. + * columns 1 through 4 give the fraction of pixels containing + * c, m, y and black ink. + * column 5 is the string 'CMYK'. + * column 6 is 'OK' if everything went fine, 'ERROR' if there + * was a problem. + * + * the resolution defaults to 75 dpi (which gives good-enough estimates) + * but can be changed via the -r flag to Ghostscript. + */ + +#include "stdint_.h" +#include "stdio_.h" +#include "gdevprn.h" + +static int +cov_write_page(gx_device_printer *pdev, FILE *file) +{ + int code = 0; + int raster = gdev_prn_raster(pdev); + int height = pdev->height; + byte *line = gs_alloc_bytes(pdev->memory, raster, "ink coverage plugin buffer"); + int y; + uint64_t c_pix = 0, m_pix = 0, y_pix = 0, k_pix = 0, total_pix = 0; + + for (y = 0; y < height; y++) { + byte *row, *end; + + code = gdev_prn_get_bits(pdev, y, line, &row); + if (code < 0) + break; + end = row + raster; + + for (; row < end; row += 4) { + c_pix += !!row[0]; + m_pix += !!row[1]; + y_pix += !!row[2]; + k_pix += !!row[3]; + ++total_pix; + } + } + + if (pdev->width * height != total_pix) + code = 1; + + gs_free_object(pdev->memory, line, "ink coverage plugin buffer"); + + { + double c = -1., m = -1., y = -1., k = -1.; + if (code == 0) { + c = (double)c_pix / total_pix; + m = (double)m_pix / total_pix; + y = (double)y_pix / total_pix; + k = (double)k_pix / total_pix; + } + + fprintf (file, "%8.5f %8.5f %8.5f %8.5f CMYK %s\n", + c, m, y, k, code ? "ERROR" : "OK"); + } + + return 0; +} + +static const gx_device_procs cov_procs = +{ + gdev_prn_open, + NULL, /* get_initial_matrix */ + NULL, /* sync_output */ + gdev_prn_output_page, + gdev_prn_close, + NULL, /* map_rgb_color */ + cmyk_8bit_map_color_rgb, + NULL, /* fill_rectangle */ + NULL, /* tile_rectangle */ + NULL, /* copy_mono */ + NULL, /* copy_color */ + NULL, /* draw_line */ + NULL, /* get_bits */ + gdev_prn_get_params, + gdev_prn_put_params, + cmyk_8bit_map_cmyk_color, + NULL, /* get_xfont_procs */ + NULL, /* get_xfont_device */ + NULL, /* map_rgb_alpha_color */ + gx_page_device_get_page_device +}; + +const gx_device_printer gs_inkcov_device = prn_device( + cov_procs, "inkcov", + DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS, + 75, 75, /* dpi */ + 0, 0, 0, 0, /* margins */ + 32, cov_write_page); + diff --git a/gs/base/lib.mak b/gs/base/lib.mak index 8213eb960..3833cdb5f 100644 --- a/gs/base/lib.mak +++ b/gs/base/lib.mak @@ -1122,6 +1122,14 @@ $(GLOBJ)gdevhit.$(OBJ) : $(GLSRC)gdevhit.c $(AK) $(std_h)\ $(MAKEDIRS) $(GLCC) $(GLO_)gdevhit.$(OBJ) $(C_) $(GLSRC)gdevhit.c +# ink coverage device -- a device that records the ink coverage +# on each page, and discards the page. +$(GLD)inkcov.dev : $(ECHOGS_XE) $(LIB_MAK) $(GLOBJ)gdevicov.$(OBJ) + $(SETDEV2) $(GLD)inkcov $(GLOBJ)gdevicov.$(OBJ) + +$(GLOBJ)gdevicov.$(OBJ) : $(GLSRC)gdevicov.c $(AK) $(MAKEDIRS) + $(GLCC) $(GLO_)gdevicov.$(OBJ) $(C_) $(GLSRC)gdevicov.c + # A device that stores its data using run-length encoding. $(GLOBJ)gdevmrun.$(OBJ) : $(GLSRC)gdevmrun.c $(AK) $(gx_h)\ diff --git a/gs/base/macos-mcp.mak b/gs/base/macos-mcp.mak index 34effe84b..d4393c911 100644 --- a/gs/base/macos-mcp.mak +++ b/gs/base/macos-mcp.mak @@ -235,7 +235,7 @@ DEVICE_DEVS13=$(DD)pngmono.dev $(DD)pngmonod.dev $(DD)pnggray.dev $(DD)png16.dev DEVICE_DEVS14=$(DD)jpeg.dev $(DD)jpeggray.dev $(DD)jpegcmyk.dev DEVICE_DEVS15=$(DD)pdfwrite.dev $(DD)pswrite.dev $(DD)ps2write.dev $(DD)epswrite.dev $(DD)txtwrite.dev $(DD)pxlmono.dev $(DD)pxlcolor.dev -DEVICE_DEVS16=$(DD)bbox.dev +DEVICE_DEVS16=$(DD)bbox.dev $(DD)inkcov.dev DEVICE_DEVS17= DEVICE_DEVS18= DEVICE_DEVS19= diff --git a/gs/base/macosx.mak b/gs/base/macosx.mak index 4a2a15979..f273e13cc 100644 --- a/gs/base/macosx.mak +++ b/gs/base/macosx.mak @@ -372,7 +372,7 @@ DEVICE_DEVS12= DEVICE_DEVS13=$(DD)png16.dev $(DD)png256.dev $(DD)pngalpha.dev DEVICE_DEVS14=$(DD)jpeg.dev $(DD)jpeggray.dev $(DD)jpegcmyk.dev DEVICE_DEVS15=$(DD)pdfwrite.dev $(DD)pswrite.dev $(DD)ps2write.dev $(DD)epswrite.dev $(DD)txtwrite.dev $(DD)pxlmono.dev $(DD)pxlcolor.dev -DEVICE_DEVS16=$(DD)bbox.dev +DEVICE_DEVS16=$(DD)bbox.dev $(DD)inkcov.dev DEVICE_DEVS17= DEVICE_DEVS18= DEVICE_DEVS19= diff --git a/gs/base/openvms.mak b/gs/base/openvms.mak index 7626a35d3..c4c43044f 100644 --- a/gs/base/openvms.mak +++ b/gs/base/openvms.mak @@ -234,7 +234,7 @@ DEVICE_DEVS12=$(DD)psmono.dev $(DD)psgray.dev $(DD)psrgb.dev $(DD)bit.dev $(DD)b DEVICE_DEVS13=$(DD)pngmono.dev $(DD)pngmonod.dev $(DD)pnggray.dev $(DD)png16.dev $(DD)png256.dev $(DD)png16m.dev $(DD)pngalpha.dev DEVICE_DEVS14=$(DD)jpeg.dev $(DD)jpeggray.dev $(DD)jpegcmyk.dev DEVICE_DEVS15=$(DD)pdfwrite.dev $(DD)pswrite.dev $(DD)ps2write.dev $(DD)epswrite.dev $(DD)txtwrite.dev $(DD)pxlmono.dev $(DD)pxlcolor.dev -DEVICE_DEVS16=$(DD)bbox.dev +DEVICE_DEVS16=$(DD)bbox.dev $(DD)inkcov.dev # Overflow from DEVS9 DEVICE_DEVS17=$(DD)pnm.dev $(DD)pnmraw.dev $(DD)ppm.dev $(DD)ppmraw.dev $(DD)pkm.dev $(DD)pkmraw.dev $(DD)pksm.dev $(DD)pksmraw.dev $(DD)pamcmyk32.dev DEVICE_DEVS18= diff --git a/gs/base/unix-gcc.mak b/gs/base/unix-gcc.mak index a70cb9869..d49583117 100644 --- a/gs/base/unix-gcc.mak +++ b/gs/base/unix-gcc.mak @@ -409,7 +409,7 @@ DEVICE_DEVS12=$(DD)psmono.dev $(DD)psgray.dev $(DD)psrgb.dev $(DD)bit.dev $(DD)b DEVICE_DEVS13=$(DD)pngmono.dev $(DD)pngmonod.dev $(DD)pnggray.dev $(DD)png16.dev $(DD)png256.dev $(DD)png16m.dev $(DD)pngalpha.dev DEVICE_DEVS14=$(DD)jpeg.dev $(DD)jpeggray.dev $(DD)jpegcmyk.dev DEVICE_DEVS15=$(DD)pdfwrite.dev $(DD)pswrite.dev $(DD)ps2write.dev $(DD)epswrite.dev $(DD)txtwrite.dev $(DD)pxlmono.dev $(DD)pxlcolor.dev -DEVICE_DEVS16=$(DD)bbox.dev +DEVICE_DEVS16=$(DD)bbox.dev $(DD)inkcov.dev DEVICE_DEVS17=$(DD)plan.dev $(DD)planm.dev $(DD)plang.dev $(DD)planc.dev $(DD)plank.dev diff --git a/gs/base/unixansi.mak b/gs/base/unixansi.mak index d8d720ae1..ec79f49de 100644 --- a/gs/base/unixansi.mak +++ b/gs/base/unixansi.mak @@ -356,7 +356,7 @@ DEVICE_DEVS12=$(DD)psmono.dev $(DD)psgray.dev $(DD)psrgb.dev $(DD)bit.dev $(DD)b DEVICE_DEVS13=$(DD)pngmono.dev $(DD)pngmonod.dev $(DD)pnggray.dev $(DD)png16.dev $(DD)png256.dev $(DD)png16m.dev $(DD)pngalpha.dev DEVICE_DEVS14=$(DD)jpeg.dev $(DD)jpeggray.dev $(DD)jpegcmyk.dev DEVICE_DEVS15=$(DD)pdfwrite.dev $(DD)pswrite.dev $(DD)ps2write.dev $(DD)epswrite.dev $(DD)txtwrite.dev $(DD)pxlmono.dev $(DD)pxlcolor.dev -DEVICE_DEVS16=$(DD)bbox.dev +DEVICE_DEVS16=$(DD)bbox.dev $(DD)inkcov.dev # Overflow from DEVS9 DEVICE_DEVS17=$(DD)pnm.dev $(DD)pnmraw.dev $(DD)ppm.dev $(DD)ppmraw.dev $(DD)pkm.dev $(DD)pkmraw.dev $(DD)pksm.dev $(DD)pksmraw.dev $(DD)pamcmyk32.dev DEVICE_DEVS18= diff --git a/gs/ghostscript.vcproj b/gs/ghostscript.vcproj index dc949097a..c1bfa1b13 100644 --- a/gs/ghostscript.vcproj +++ b/gs/ghostscript.vcproj @@ -1238,6 +1238,10 @@ > </File> <File + RelativePath="base\gdevicov.c" + > + </File> + <File RelativePath="base\gdevbit.c" > </File> @@ -9297,4 +9301,4 @@ </Files> <Globals> </Globals> -</VisualStudioProject>
\ No newline at end of file +</VisualStudioProject> |