summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2007-10-05 21:54:00 +0200
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2007-10-05 21:54:00 +0200
commit874c41537ac1702a4d020d4a5d6c8fc9302fae45 (patch)
treec6cc06aae78a95b17b26eb4cf22922e9eac43d7b /src
parent0ceeafe90dc5055ff999c0e2d7530748bb32fed5 (diff)
support 8bit pnm files
Diffstat (limited to 'src')
-rw-r--r--src/pnmlcms.c34
1 files 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);