#include #include "pnm.h" static int pam_transform(FILE *in_fp, FILE *out_fp, const struct pnm *in_pnm, cmsHTRANSFORM *hTransform); int main(int argc, char **argv) { int c, i, nProf = 0; char *in_prof = NULL, *out_prof = NULL; double gamma = 0.0, bright = 0.0, contrast = 1.0, hue = 0.0; double saturation = 0.0; int tempSrc = 5000, tempDst = 5000; cmsHTRANSFORM hTransform; cmsHPROFILE profiles[3]; struct pnm in_pnm; while ((c = getopt(argc, argv, "i:o:g:b:c:h:s:S:D:")) != EOF) { switch (c) { case 'i': in_prof = optarg; break; case 'o': out_prof = optarg; break; case 'g': gamma = atof(optarg); break; case 'b': bright = atof(optarg); break; case 'c': contrast = atof(optarg); break; case 'h': hue = atof(optarg); break; case 's': saturation = atof(optarg); break; case 'S': tempSrc = atoi(optarg); break; case 'D': tempDst = atoi(optarg); break; default: break; } } if (in_prof) { profiles[nProf++] = cmsOpenProfileFromFile(in_prof, "r"); } else { profiles[nProf++] = cmsCreate_sRGBProfile(); } if (gamma) { LPGAMMATABLE gTable[3]; gTable[0] = cmsBuildGamma(256, gamma); gTable[1] = gTable[2] = cmsBuildGamma(256, 1.0); profiles[nProf++] = cmsCreateLinearizationDeviceLink( icSigLabData, gTable); } profiles[nProf++] = cmsCreateBCHSWabstractProfile( 10, bright, contrast, hue, saturation, tempSrc, tempDst); if (out_prof) { profiles[nProf++] = cmsOpenProfileFromFile(out_prof, "r"); } else { profiles[nProf++] = cmsCreate_sRGBProfile(); } hTransform = cmsCreateMultiprofileTransform( profiles, nProf, TYPE_RGB_16_SE, TYPE_RGB_16_SE, INTENT_PERCEPTUAL, 0); if (readPnmHeader(stdin, &in_pnm) != 0) { exit(1); } writePnmHeader(stdout, &in_pnm); pam_transform(stdin, stdout, &in_pnm, &hTransform); cmsDeleteTransform(hTransform); for (i = 0; i < nProf; i++) { // cmsCloseProfile(profiles[i]); } return 0; } static int 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); for (row = 0; row < in_pnm->height; row++) { fread(in_buf, in_pnm->width, 2 * 3, in_fp); cmsDoTransform(*hTransform, in_buf, out_buf, in_pnm->width); fwrite(out_buf, in_pnm->width, 2 * 3, out_fp); } free(in_buf); free(out_buf); return 0; }