--- ray/src/common/tmapcolrs.c 1998/10/28 09:26:03 3.9 +++ ray/src/common/tmapcolrs.c 2004/10/23 18:55:52 3.16 @@ -1,22 +1,27 @@ -/* Copyright (c) 1998 Silicon Graphics, Inc. */ - #ifndef lint -static char SCCSid[] = "$SunId$ SGI"; +static const char RCSid[] = "$Id: tmapcolrs.c,v 3.16 2004/10/23 18:55:52 schorsch Exp $"; #endif - /* * Routines for tone mapping on Radiance RGBE and XYZE pictures. - * See tonemap.h for detailed function descriptions. + * + * Externals declared in tonemap.h */ +#include "copyright.h" + #include +#include #include +#include + #include "tmprivat.h" #include "resolu.h" +#include "rtprocess.h" +#ifndef TM_PIC_CTRANS +#define TM_PIC_CTRANS 1 /* transform colors? (expensive) */ +#endif -extern char *tempbuffer(); - #define GAMTSZ 1024 typedef struct { @@ -25,9 +30,10 @@ typedef struct { TMbright inpsfb; /* encoded tm->inpsf */ } COLRDATA; -static MEM_PTR colrInit(); -static void colrNewSpace(); -extern void free(); +static MEM_PTR colrInit(struct tmStruct *); +static void colrNewSpace(struct tmStruct *); +static gethfunc headline; + static struct tmPackage colrPkg = { /* our package functions */ colrInit, colrNewSpace, free }; @@ -35,7 +41,6 @@ static int colrReg = -1; /* our package registration #define LOGISZ 260 static TMbright logi[LOGISZ]; -static BYTE photofact[BMESUPPER-BMESLOWER]; int @@ -52,9 +57,13 @@ int len; if (tmTop == NULL) returnErr(TM_E_TMINVAL); - if (ls == NULL | scan == NULL | len < 0) + if ((ls == NULL) | (scan == NULL) | (len < 0)) returnErr(TM_E_ILLEGAL); +#if TM_PIC_CTRANS if (tmNeedMatrix(tmTop)) { /* need floating point */ +#else + if (tmTop->inppri == TM_XYZPRIM) { /* no way around this */ +#endif register COLOR *newscan; newscan = (COLOR *)tempbuffer(len*sizeof(COLOR)); if (newscan == NULL) @@ -70,11 +79,8 @@ int len; for (i = 256; i--; ) logi[i] = TM_BRTSCALE*log((i+.5)/256.) - .5; for (i = 256; i < LOGISZ; i++) - logi[i] = logi[255]; - for (i = BMESLOWER; i < BMESUPPER; i++) - photofact[i-BMESLOWER] = 256. * - (tmLuminance(i) - LMESLOWER) / - (LMESUPPER - LMESLOWER); + logi[i] = 0; + tmMkMesofact(); } if ((cd = (COLRDATA *)tmPkgData(tmTop,colrReg)) == NULL) returnErr(TM_E_NOMEM); @@ -84,11 +90,11 @@ int len; li = ( cd->clfb[RED]*cmon[RED] + cd->clfb[GRN]*cmon[GRN] + cd->clfb[BLU]*cmon[BLU] ) >> 8; - bi = BRT2SCALE*(cmon[EXP]-COLXS) + + bi = BRT2SCALE(cmon[EXP]-COLXS) + logi[li] + cd->inpsfb; - if (bi < MINBRT) { - bi = MINBRT-1; /* bogus value */ - li++; /* avoid li==0 */ + if (li <= 0) { + bi = TM_NOBRT; /* bogus value */ + li = 1; /* avoid li==0 */ } ls[i] = bi; if (cs == TM_NOCHROM) /* no color? */ @@ -101,7 +107,7 @@ int len; else { if (tmTop->flags & TM_F_BW) cmon[RED] = cmon[GRN] = cmon[BLU] = li; - pf = photofact[bi-BMESLOWER]; + pf = tmMesofact[bi-BMESLOWER]; sli *= 256 - pf; cmon[RED] = ( sli + pf*cmon[RED] ) >> 8; cmon[GRN] = ( sli + pf*cmon[GRN] ) >> 8; @@ -110,11 +116,11 @@ int len; } else if (tmTop->flags & TM_F_BW) { cmon[RED] = cmon[GRN] = cmon[BLU] = li; } - bi = ( (int4)GAMTSZ*cd->clfb[RED]*cmon[RED]/li ) >> 8; + bi = ( (int32)GAMTSZ*cd->clfb[RED]*cmon[RED]/li ) >> 8; cs[3*i ] = bi>=GAMTSZ ? 255 : cd->gamb[bi]; - bi = ( (int4)GAMTSZ*cd->clfb[GRN]*cmon[GRN]/li ) >> 8; + bi = ( (int32)GAMTSZ*cd->clfb[GRN]*cmon[GRN]/li ) >> 8; cs[3*i+1] = bi>=GAMTSZ ? 255 : cd->gamb[bi]; - bi = ( (int4)GAMTSZ*cd->clfb[BLU]*cmon[BLU]/li ) >> 8; + bi = ( (int32)GAMTSZ*cd->clfb[BLU]*cmon[BLU]/li ) >> 8; cs[3*i+2] = bi>=GAMTSZ ? 255 : cd->gamb[bi]; } returnOK; @@ -135,11 +141,13 @@ static struct radhead { static int -headline(s, rh) /* grok a header line */ -register char *s; -register struct radhead *rh; +headline( /* grok a header line */ + register char *s, + void *vrh +) { char fmt[32]; + register struct radhead *rh = vrh; if (formatval(fmt, s)) { if (!strcmp(fmt, COLRFMT)) @@ -180,8 +188,8 @@ FILE *fp; /* check arguments */ if (tmTop == NULL) returnErr(TM_E_TMINVAL); - if (lpp == NULL | xp == NULL | yp == NULL | - (fname == NULL & fp == TM_GETFILE)) + if ((lpp == NULL) | (xp == NULL) | (yp == NULL) | + ((fname == NULL) & (fp == TM_GETFILE))) returnErr(TM_E_ILLEGAL); *xp = *yp = 0; /* error precaution */ if ((inpf = fp) == TM_GETFILE && (inpf = fopen(fname, "r")) == NULL) @@ -189,8 +197,8 @@ FILE *fp; *lpp = NULL; if (cpp != TM_NOCHROMP) *cpp = NULL; info = rhdefault; /* get our header */ - getheader(inpf, headline, (MEM_PTR)&info); - if (info.format == FMTBAD | info.expos <= 0. || + getheader(inpf, headline, &info); + if ((info.format == FMTBAD) | (info.expos <= 0.) || fgetresolu(xp, yp, inpf) < 0) { err = TM_E_BADFILE; goto done; } @@ -243,7 +251,7 @@ done: /* clean up */ #ifdef PCOND -int /* run pcond to map picture */ +static int /* run pcond to map picture */ dopcond(psp, xp, yp, flags, monpri, gamval, Lddyn, Ldmax, fname) BYTE **psp; int *xp, *yp; @@ -253,7 +261,7 @@ double gamval, Lddyn, Ldmax; char *fname; { char *funcName = fname; - char cmdbuf[512]; + char cmdbuf[1024]; FILE *infp; register COLR *scan; register BYTE *rp; @@ -298,7 +306,7 @@ char *fname; rp = (BYTE *)malloc(sizeof(BYTE) * *xp * *yp); else rp = (BYTE *)malloc(3*sizeof(BYTE) * *xp * *yp); - if ((*psp = rp) == NULL | scan == NULL) { + if (((*psp = rp) == NULL) | (scan == NULL)) { pclose(infp); returnErr(TM_E_NOMEM); } @@ -344,8 +352,8 @@ FILE *fp; TMbright *lp; int err; /* check arguments */ - if (psp == NULL | xp == NULL | yp == NULL | monpri == NULL | - (fname == NULL & fp == TM_GETFILE)) + if ((psp == NULL) | (xp == NULL) | (yp == NULL) | (monpri == NULL) | + ((fname == NULL) & (fp == TM_GETFILE))) returnErr(TM_E_ILLEGAL); /* set defaults */ if (gamval < MINGAM) gamval = DEFGAM;