--- ray/src/common/tmap16bit.c 2003/07/27 22:12:01 1.4 +++ ray/src/common/tmap16bit.c 2005/01/07 20:33:02 1.5 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: tmap16bit.c,v 1.4 2003/07/27 22:12:01 schorsch Exp $"; +static const char RCSid[] = "$Id: tmap16bit.c,v 1.5 2005/01/07 20:33:02 greg Exp $"; #endif /* * Routines for tone-mapping 16-bit/primary pixels @@ -59,15 +59,15 @@ mkGamTable(double gv) /* Fill our monitor gamma table */ static void -mkMonGamTable() +mkMonGamTable(TMstruct *tms) { int i; - if (tmTop->mongam == cur_mongam) + if (tms->mongam == cur_mongam) return; for (i = MONGAMTSZ; i--; ) - mongamtab[i] = 256.*pow((i+.5)*(1./MONGAMTSZ), 1./tmTop->mongam); - cur_mongam = tmTop->mongam; + mongamtab[i] = 256.*pow((i+.5)*(1./MONGAMTSZ), 1./tms->mongam); + cur_mongam = tms->mongam; } @@ -131,7 +131,7 @@ rgb48_color(COLOR col, uint16 clr48[3], double gv) /* Convert 16-bit gray scanline to encoded luminance */ int -tmCvGray16(TMbright *ls, uint16 *scan, int len, double gv) +tmCvGray16(TMstruct *tms, TMbright *ls, uint16 *scan, int len, double gv) { static char funcName[] = "tmCvGray16"; static double cur_inpsf = 1.; @@ -139,7 +139,7 @@ tmCvGray16(TMbright *ls, uint16 *scan, int len, double int nshft; double d; - if (tmTop == NULL) + if (tms == NULL) returnErr(TM_E_TMINVAL); if ((ls == NULL) | (scan == NULL) | (len < 0)) returnErr(TM_E_ILLEGAL); @@ -148,8 +148,8 @@ tmCvGray16(TMbright *ls, uint16 *scan, int len, double /* initialize log table */ if (logtab[0] == 0.f) mkLogTable(); - if (cur_inpsf != tmTop->inpsf) - log_inpsf = log(cur_inpsf = tmTop->inpsf); + if (cur_inpsf != tms->inpsf) + log_inpsf = log(cur_inpsf = tms->inpsf); /* convert 16-bit grays */ while (len--) { nshft = normShift16(*scan); @@ -170,14 +170,15 @@ tmCvGray16(TMbright *ls, uint16 *scan, int len, double /* Convert a 48-bit RGB scanline to encoded luminance/chrominance */ int -tmCvRGB48(TMbright *ls, BYTE *cs, uint16 (*scan)[3], int len, double gv) +tmCvRGB48(TMstruct *tms, TMbright *ls, BYTE *cs, + uint16 (*scan)[3], int len, double gv) { static char funcName[] = "tmCvRGB48"; static double cur_inpsf = 1.; static double log_inpsf = 0.; int i; - if (tmTop == NULL) + if (tms == NULL) returnErr(TM_E_TMINVAL); if ((ls == NULL) | (scan == NULL) | (len < 0)) returnErr(TM_E_ILLEGAL); @@ -186,24 +187,24 @@ tmCvRGB48(TMbright *ls, BYTE *cs, uint16 (*scan)[3], i /* sync input gamma table */ if ((gv != 1.) & (gv != cur_gam)) mkGamTable(gv); - if (tmNeedMatrix(tmTop)) { /* need floating point */ + if (tmNeedMatrix(tms)) { /* need floating point */ COLOR *newscan; newscan = (COLOR *)tempbuffer(len*sizeof(COLOR)); if (newscan == NULL) returnErr(TM_E_NOMEM); for (i = len; i--; ) rgb48_color(newscan[i], scan[i], gv); - return(tmCvColors(ls, cs, newscan, len)); + return(tmCvColors(tms, ls, cs, newscan, len)); } /* sync monitor gamma table */ - if (cs != TM_NOCHROM && tmTop->mongam != cur_mongam) - mkMonGamTable(); + if (cs != TM_NOCHROM && tms->mongam != cur_mongam) + mkMonGamTable(tms); /* initialize log table */ if (logtab[0] == 0.f) mkLogTable(); - if (cur_inpsf != tmTop->inpsf) - log_inpsf = log(cur_inpsf = tmTop->inpsf); - if (tmTop->flags & TM_F_MESOPIC) + if (cur_inpsf != tms->inpsf) + log_inpsf = log(cur_inpsf = tms->inpsf); + if (tms->flags & TM_F_MESOPIC) tmMkMesofact(); /* convert scanline */ for (i = len; i--; ) { @@ -223,9 +224,9 @@ tmCvRGB48(TMbright *ls, BYTE *cs, uint16 (*scan)[3], i setcolor(cmon, gamtab[imultpow2(scan[i][0],j)], gamtab[imultpow2(scan[i][1],j)], gamtab[imultpow2(scan[i][2],j)] ); - lum = tmTop->clf[RED]*cmon[RED]; - lum += tmTop->clf[GRN]*cmon[GRN]; - lum += tmTop->clf[BLU]*cmon[BLU]; + lum = tms->clf[RED]*cmon[RED]; + lum += tms->clf[GRN]*cmon[GRN]; + lum += tms->clf[BLU]*cmon[BLU]; /* convert to log Y */ j = lum * (double)(1L<<16); nshft2 = normShift16(j); @@ -240,28 +241,28 @@ tmCvRGB48(TMbright *ls, BYTE *cs, uint16 (*scan)[3], i if (cs == TM_NOCHROM) /* no color? */ continue; /* mesopic adj. */ - if (tmTop->flags & TM_F_MESOPIC && bi < BMESUPPER) { + if (tms->flags & TM_F_MESOPIC && bi < BMESUPPER) { double slum = scotlum(cmon); if (bi < BMESLOWER) setcolor(cmon, slum, slum, slum); else { double pf; pf = (1./256.)*tmMesofact[bi-BMESLOWER]; - if (tmTop->flags & TM_F_BW) + if (tms->flags & TM_F_BW) cmon[RED] = cmon[GRN] = cmon[BLU] = lum; slum *= 1. - pf; cmon[RED] = slum + pf*cmon[RED]; cmon[GRN] = slum + pf*cmon[GRN]; cmon[BLU] = slum + pf*cmon[BLU]; } - } else if (tmTop->flags & TM_F_BW) { + } else if (tms->flags & TM_F_BW) { cmon[RED] = cmon[GRN] = cmon[BLU] = lum; } - bi = (double)MONGAMTSZ*tmTop->clf[RED]*cmon[RED]/lum; + bi = (double)MONGAMTSZ*tms->clf[RED]*cmon[RED]/lum; cs[3*i ] = bi>=MONGAMTSZ ? 255 : mongamtab[bi]; - bi = (double)MONGAMTSZ*tmTop->clf[GRN]*cmon[GRN]/lum; + bi = (double)MONGAMTSZ*tms->clf[GRN]*cmon[GRN]/lum; cs[3*i+1] = bi>=MONGAMTSZ ? 255 : mongamtab[bi]; - bi = (double)MONGAMTSZ*tmTop->clf[BLU]*cmon[BLU]/lum; + bi = (double)MONGAMTSZ*tms->clf[BLU]*cmon[BLU]/lum; cs[3*i+2] = bi>=MONGAMTSZ ? 255 : mongamtab[bi]; } returnOK;