Fix for 687139, fuzzy.c wrongly handles CMYK
Alex Cherepanov <[email protected]>
| Newsgroups | gmane.comp.printing.ghostscript.patches |
|---|---|
| Organization | Coscript Software |
| Message-ID | <[email protected]> |
Add support to pnm images with max_pixel_value < (1<<depth)-1 CMYK is still not supported because none of the supported image formats include CMYK support. To do CMYK we need to change the data format to TIFF (for instance) and use libTiff library. _______________________________________________ gs-code-review mailing list [email protected] http://www.ghostscript.com/mailman/listinfo/gs-code-review
fuzzy.c.diff
(text/plain, 2.6 KB)
Index: gs/toolbin/tests/fuzzy.c
===================================================================
RCS file: /cvs/ghostscript/gs/toolbin/tests/fuzzy.c,v
retrieving revision 1.12
diff -b -u -r1.12 fuzzy.c
--- gs/toolbin/tests/fuzzy.c 9 Oct 2003 19:19:14 -0000 1.12
+++ gs/toolbin/tests/fuzzy.c 27 Nov 2003 14:23:25 -0000
@@ -28,6 +28,7 @@
int (*seek) (Image *self, int y);
int width;
int height;
+ int maxval;
int n_chan;
int raster;
int bpp; /* bits per pixel */
@@ -252,8 +253,15 @@
ImagePnm *pnm = (ImagePnm *)self;
int n_bytes = self->raster;
int code;
+ int bppval = (1 << self->bpp) -1;
+ int maxval = self->maxval;
code = fread (buf, 1, n_bytes, pnm->f);
+ if (maxval < bppval) {
+ int i;
+ for(i = 0; i<n_bytes; i++)
+ buf[i] = buf[i] * bppval / maxval;
+ }
return (code < n_bytes) ? -1 : 0;
}
@@ -262,6 +270,7 @@
{
FILE *f = fopen (fn, "rb");
int width, height;
+ int maxval = 0;
int n_chan, bpp;
char linebuf[256];
ImagePnm *image;
@@ -273,15 +282,13 @@
image->f = f;
if (fgets (linebuf, sizeof(linebuf), f) == NULL ||
linebuf[0] != 'P' || linebuf[1] < '4' || linebuf[1] > '6')
- {
- fclose (f);
- return NULL;
- }
+ goto punt;
switch (linebuf[1])
{
case '4':
n_chan = 1;
bpp = 1;
+ maxval = 1;
break;
case '5':
n_chan = 1;
@@ -292,44 +299,38 @@
bpp = 8;
break;
default:
- fclose (f);
- return NULL;
+ goto punt;
}
do
{
if (fgets (linebuf, sizeof(linebuf), f) == NULL)
- {
- fclose (f);
- return NULL;
- }
+ goto punt;
}
while (linebuf[0] == '#');
if (sscanf (linebuf, "%d %d", &width, &height) != 2)
- {
- fclose (f);
- return NULL;
- }
- if (bpp == 8)
- {
- do
+ goto punt;
+ while (!maxval)
{
if (fgets (linebuf, sizeof(linebuf), f) == NULL)
- {
- fclose (f);
- return NULL;
- }
- }
- while (linebuf[0] == '#');
+ goto punt;
+ if (linebuf[0] == '#')
+ continue;
+ if (sscanf(linebuf, "%d", &maxval) != 1 || maxval <= 0 || maxval > 255)
+ goto punt;
}
image->super.close = image_pnm_close;
image->super.get_scan_line = image_pnm_get_scan_line;
image->super.seek = no_seek;
image->super.width = width;
image->super.height = height;
+ image->super.maxval = maxval;
image->super.raster = n_chan * ((width * bpp + 7) >> 3);
image->super.n_chan = n_chan;
image->super.bpp = bpp;
return &image->super;
+punt:;
+ fclose (f);
+ return NULL;
}
Image *