--- ray/src/px/x11image.c 1997/04/16 20:28:47 2.46 +++ ray/src/px/x11image.c 1997/04/24 17:29:53 2.49 @@ -178,11 +178,11 @@ char *argv[]; break; case 'e': /* exposure comp. */ i++; - if (!strcmp(argv[i], "auto")) { + if (argv[i][0] == 'a') { tmflags = TM_F_CAMERA; break; } - if (!strcmp(argv[i], "human")) { + if (argv[i][0] == 'h') { tmflags = TM_F_HUMAN; break; } @@ -944,45 +944,48 @@ COLOR clr; make_tonemap() /* initialize tone mapping */ { - int y; + int flags, y; if (tmflags != -1 && fname == NULL) { fprintf(stderr, "%s: cannot adjust tone of standard input\n", progname); tmflags = -1; } - if (tmflags == -1) { + if (tmflags == -1) { /* linear with clamping */ setcolrcor(pow, 1.0/gamcor); return; } - if (greyscale) - tmflags |= TM_F_BW; - /* initialize tm library */ - if (tmInit(tmflags, stdprims, gamcor) == NULL) - goto memerr; - if (tmSetSpace(stdprims, WHTEFFICACY/exposure)) - goto tmerr; - /* allocate encoding buffers */ - if ((lscan = (TMbright *)malloc(xmax*sizeof(TMbright))) == NULL) - goto memerr; - if (tmflags & TM_F_BW) { - cscan = TM_NOCHROM; - if ((pscan = (BYTE *)malloc(sizeof(BYTE)*xmax)) == NULL) + flags = tmflags; /* histogram adjustment */ + if (greyscale) flags |= TM_F_BW; + if (tmTop != NULL) { /* reuse old histogram if one */ + tmTop->flags = flags; + } else { /* else initialize */ + if ((lscan = (TMbright *)malloc(xmax*sizeof(TMbright))) == NULL) goto memerr; - } else if ((pscan=cscan = (BYTE *)malloc(3*sizeof(BYTE)*xmax)) == NULL) - goto memerr; - /* compute picture histogram */ - for (y = 0; y < ymax; y++) { - getscan(y); - if (tmCvColrs(lscan, TM_NOCHROM, scanline, xmax)) + if (greyscale) { + cscan = TM_NOCHROM; + if ((pscan = (BYTE *)malloc(sizeof(BYTE)*xmax)) == NULL) + goto memerr; + } else if ((pscan=cscan = (BYTE *)malloc(3*sizeof(BYTE)*xmax)) + == NULL) + goto memerr; + /* initialize tm library */ + if (tmInit(flags, stdprims, gamcor) == NULL) + goto memerr; + if (tmSetSpace(stdprims, WHTEFFICACY/exposure)) goto tmerr; - if (tmAddHisto(lscan, xmax, 1)) - goto tmerr; + /* compute picture histogram */ + for (y = 0; y < ymax; y++) { + getscan(y); + if (tmCvColrs(lscan, TM_NOCHROM, scanline, xmax)) + goto tmerr; + if (tmAddHisto(lscan, xmax, 1)) + goto tmerr; + } } - /* compute tone mapping */ + /* (re)compute tone mapping */ if (tmComputeMapping(gamcor, 0., 0.)) goto tmerr; - free((char *)lscan); return; memerr: quiterr("out of memory in make_tonemap"); @@ -1010,7 +1013,7 @@ int len; if (tmMapPixels(pscan, lscan, cscan, len)) goto tmerr; ps = pscan; - if (tmflags & TM_F_BW) + if (greyscale) while (len--) { scn[0][RED] = scn[0][GRN] = scn[0][BLU] = *ps++; scn[0][EXP] = COLXS; @@ -1030,16 +1033,6 @@ tmerr: } -done_tonemap() /* clean up after tone mapping is done */ -{ - if (tmflags == -1 || tmTop == NULL) - return; - tmDone(tmTop); /* clear old mapping */ - free((char *)lscan); /* free memory */ - free((char *)pscan); -} - - getmono() /* get monochrome data */ { register unsigned char *dp; @@ -1148,7 +1141,6 @@ getfull() /* get full (24-bit) data */ (unsigned int4)scanline[x][GRN] << 8 | (unsigned int4)scanline[x][BLU] << 16 ; } - done_tonemap(); } @@ -1176,7 +1168,6 @@ getgrey() /* get greyscale data */ for (x = 0; x < maxcolors; x++) clrtab[x][RED] = clrtab[x][GRN] = clrtab[x][BLU] = ((int4)x*256 + 128)/maxcolors; - done_tonemap(); } @@ -1209,7 +1200,6 @@ getmapped() /* get color-mapped data */ else map_colrs(ourdata+y*xmax, scanline, xmax); } - done_tonemap(); }