From 874c41537ac1702a4d020d4a5d6c8fc9302fae45 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Fri, 5 Oct 2007 21:54:00 +0200 Subject: support 8bit pnm files --- src/pnmlcms.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/pnmlcms.c b/src/pnmlcms.c index 66c1905..f139b0f 100644 --- a/src/pnmlcms.c +++ b/src/pnmlcms.c @@ -15,6 +15,7 @@ main(int argc, char **argv) { int tempSrc = 5000, tempDst = 5000; cmsHTRANSFORM hTransform; cmsHPROFILE profiles[3]; + DWORD type; struct pnm in_pnm; while ((c = getopt(argc, argv, "i:o:g:b:c:h:s:S:D:")) != EOF) { @@ -84,19 +85,27 @@ main(int argc, char **argv) { profiles[nProf++] = cmsCreate_sRGBProfile(); } + if (readPnmHeader(stdin, &in_pnm) != 0) { + exit(1); + } + + if (in_pnm.maxval == 255) { + type = TYPE_RGB_8; + } else if (in_pnm.maxval == 65535) { + type = TYPE_RGB_16_SE; + } else { + fprintf(stderr, "unsupported PNM maxval %d\n", in_pnm.maxval); + exit(1); + } + hTransform = cmsCreateMultiprofileTransform( profiles, nProf, - TYPE_RGB_16_SE, - TYPE_RGB_16_SE, + type, + type, INTENT_PERCEPTUAL, - 0); + cmsFLAGS_BLACKPOINTCOMPENSATION); - - if (readPnmHeader(stdin, &in_pnm) != 0) { - exit(1); - } - writePnmHeader(stdout, &in_pnm); pam_transform(stdin, stdout, &in_pnm, &hTransform); @@ -115,15 +124,16 @@ pam_transform(FILE *in_fp, FILE *out_fp, const struct pnm *in_pnm, cmsHTRANSFORM *hTransform) { int row, col; - char *in_buf = malloc(in_pnm->width * 2 * 3); - char *out_buf = malloc(in_pnm->width * 2 * 3); + int nbytes = in_pnm->maxval == 65535?2:1; + char *in_buf = malloc(in_pnm->width * nbytes * 3); + char *out_buf = malloc(in_pnm->width * nbytes * 3); for (row = 0; row < in_pnm->height; row++) { - fread(in_buf, in_pnm->width, 2 * 3, in_fp); + fread(in_buf, in_pnm->width, nbytes * 3, in_fp); cmsDoTransform(*hTransform, in_buf, out_buf, in_pnm->width); - fwrite(out_buf, in_pnm->width, 2 * 3, out_fp); + fwrite(out_buf, in_pnm->width, nbytes * 3, out_fp); } free(in_buf); -- cgit v1.2.3