--- ray/src/common/tmapcolrs.c 2003/02/22 02:07:22 3.10 +++ ray/src/common/tmapcolrs.c 2005/01/07 20:33:02 3.17 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: tmapcolrs.c,v 3.10 2003/02/22 02:07:22 greg Exp $"; +static const char RCSid[] = "$Id: tmapcolrs.c,v 3.17 2005/01/07 20:33:02 greg Exp $"; #endif /* * Routines for tone mapping on Radiance RGBE and XYZE pictures. @@ -7,69 +7,16 @@ static const char RCSid[] = "$Id: tmapcolrs.c,v 3.10 2 * Externals declared in tonemap.h */ -/* ==================================================================== - * The Radiance Software License, Version 1.0 - * - * Copyright (c) 1990 - 2002 The Regents of the University of California, - * through Lawrence Berkeley National Laboratory. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes Radiance software - * (http://radsite.lbl.gov/) - * developed by the Lawrence Berkeley National Laboratory - * (http://www.lbl.gov/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Radiance," "Lawrence Berkeley National Laboratory" - * and "The Regents of the University of California" must - * not be used to endorse or promote products derived from this - * software without prior written permission. For written - * permission, please contact radiance@radsite.lbl.gov. - * - * 5. Products derived from this software may not be called "Radiance", - * nor may "Radiance" appear in their name, without prior written - * permission of Lawrence Berkeley National Laboratory. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of Lawrence Berkeley National Laboratory. For more - * information on Lawrence Berkeley National Laboratory, please see - * . - */ +#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) */ @@ -83,13 +30,10 @@ typedef struct { TMbright inpsfb; /* encoded tm->inpsf */ } COLRDATA; -#ifdef NOPROTO -static MEM_PTR colrInit(); -static void colrNewSpace(); -#else -static MEM_PTR colrInit(struct tmStruct *); -static void colrNewSpace(struct tmStruct *); -#endif +static MEM_PTR colrInit(TMstruct *); +static void colrNewSpace(TMstruct *); +static gethfunc headline; + static struct tmPackage colrPkg = { /* our package functions */ colrInit, colrNewSpace, free }; @@ -100,25 +44,27 @@ static TMbright logi[LOGISZ]; int -tmCvColrs(ls, cs, scan, len) /* convert RGBE/XYZE colors */ -TMbright *ls; -BYTE *cs; -COLR *scan; -int len; +tmCvColrs( /* convert RGBE/XYZE colors */ +TMstruct *tms, +TMbright *ls, +BYTE *cs, +COLR *scan, +int len +) { static char funcName[] = "tmCvColrs"; COLR cmon; register COLRDATA *cd; register int i, bi, li; - if (tmTop == NULL) + if (tms == 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 */ + if (tmNeedMatrix(tms)) { /* need floating point */ #else - if (tmTop->inppri == TM_XYZPRIM) { /* no way around this */ + if (tms->inppri == TM_XYZPRIM) { /* no way around this */ #endif register COLOR *newscan; newscan = (COLOR *)tempbuffer(len*sizeof(COLOR)); @@ -126,7 +72,7 @@ int len; returnErr(TM_E_NOMEM); for (i = len; i--; ) colr_color(newscan[i], scan[i]); - return(tmCvColors(ls, cs, newscan, len)); + return(tmCvColors(tms, ls, cs, newscan, len)); } if (colrReg < 0) { /* build tables if necessary */ colrReg = tmRegPkg(&colrPkg); @@ -138,7 +84,7 @@ int len; logi[i] = 0; tmMkMesofact(); } - if ((cd = (COLRDATA *)tmPkgData(tmTop,colrReg)) == NULL) + if ((cd = (COLRDATA *)tmPkgData(tms,colrReg)) == NULL) returnErr(TM_E_NOMEM); for (i = len; i--; ) { copycolr(cmon, scan[i]); @@ -156,12 +102,12 @@ int len; 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) { register int pf, sli = normscot(cmon); if (bi < BMESLOWER) cmon[RED] = cmon[GRN] = cmon[BLU] = sli; else { - if (tmTop->flags & TM_F_BW) + if (tms->flags & TM_F_BW) cmon[RED] = cmon[GRN] = cmon[BLU] = li; pf = tmMesofact[bi-BMESLOWER]; sli *= 256 - pf; @@ -169,14 +115,14 @@ int len; cmon[GRN] = ( sli + pf*cmon[GRN] ) >> 8; cmon[BLU] = ( sli + pf*cmon[BLU] ) >> 8; } - } else if (tmTop->flags & TM_F_BW) { + } else if (tms->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; @@ -197,11 +143,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)) @@ -226,12 +174,15 @@ register struct radhead *rh; int -tmLoadPicture(lpp, cpp, xp, yp, fname, fp) /* convert Radiance picture */ -TMbright **lpp; -BYTE **cpp; -int *xp, *yp; -char *fname; -FILE *fp; +tmLoadPicture( /* convert Radiance picture */ +TMstruct *tms, +TMbright **lpp, +BYTE **cpp, +int *xp, +int *yp, +char *fname, +FILE *fp +) { char *funcName = fname==NULL ? "tmLoadPicture" : fname; FILE *inpf; @@ -240,10 +191,10 @@ FILE *fp; COLR *scanin = NULL; int i; /* check arguments */ - if (tmTop == NULL) + if (tms == 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) @@ -251,8 +202,8 @@ FILE *fp; *lpp = NULL; if (cpp != TM_NOCHROMP) *cpp = NULL; info = rhdefault; /* get our header */ - getheader(inpf, headline, (char *)&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; } @@ -263,7 +214,7 @@ FILE *fp; else if (info.format == FMTCIE) info.primp = TM_XYZPRIM; /* prepare library */ - if ((err = tmSetSpace(info.primp, 1./info.expos)) != TM_E_OK) + if ((err = tmSetSpace(tms, info.primp, 1./info.expos)) != TM_E_OK) goto done; err = TM_E_NOMEM; /* allocate arrays */ *lpp = (TMbright *)malloc(sizeof(TMbright) * *xp * *yp); @@ -282,7 +233,7 @@ FILE *fp; if (freadcolrs(scanin, *xp, inpf) < 0) { err = TM_E_BADFILE; break; } - err = tmCvColrs(*lpp + (i * *xp), + err = tmCvColrs(tms, *lpp + (i * *xp), cpp==TM_NOCHROMP ? TM_NOCHROM : *cpp + (i * 3 * *xp), scanin, *xp); if (err != TM_E_OK) @@ -305,7 +256,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; @@ -315,6 +266,7 @@ double gamval, Lddyn, Ldmax; char *fname; { char *funcName = fname; + TMstruct *tms = NULL; char cmdbuf[1024]; FILE *infp; register COLR *scan; @@ -360,7 +312,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); } @@ -402,12 +354,13 @@ char *fname; FILE *fp; { char *funcName = fname==NULL ? "tmMapPicture" : fname; + TMstruct *tms; BYTE *cp; 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; @@ -421,13 +374,13 @@ FILE *fp; monpri, gamval, Lddyn, Ldmax, fname) ); #endif /* initialize tone mapping */ - if (tmInit(flags, monpri, gamval) == NULL) + if ((tms = tmInit(flags, monpri, gamval)) == NULL) returnErr(TM_E_NOMEM); /* load & convert picture */ - err = tmLoadPicture(&lp, (flags&TM_F_BW) ? TM_NOCHROMP : &cp, + err = tmLoadPicture(tms, &lp, (flags&TM_F_BW) ? TM_NOCHROMP : &cp, xp, yp, fname, fp); if (err != TM_E_OK) { - tmDone(NULL); + tmDone(tms); return(err); } /* allocate space for result */ @@ -435,25 +388,25 @@ FILE *fp; *psp = (BYTE *)malloc(sizeof(BYTE) * *xp * *yp); if (*psp == NULL) { free((MEM_PTR)lp); - tmDone(NULL); + tmDone(tms); returnErr(TM_E_NOMEM); } cp = TM_NOCHROM; } else *psp = cp; /* compute color mapping */ - err = tmAddHisto(lp, *xp * *yp, 1); + err = tmAddHisto(tms, lp, *xp * *yp, 1); if (err != TM_E_OK) goto done; - err = tmComputeMapping(gamval, Lddyn, Ldmax); + err = tmComputeMapping(tms, gamval, Lddyn, Ldmax); if (err != TM_E_OK) goto done; /* map colors */ - err = tmMapPixels(*psp, lp, cp, *xp * *yp); + err = tmMapPixels(tms, *psp, lp, cp, *xp * *yp); done: /* clean up */ free((MEM_PTR)lp); - tmDone(NULL); + tmDone(tms); if (err != TM_E_OK) { /* free memory on error */ free((MEM_PTR)*psp); *psp = NULL; @@ -465,7 +418,7 @@ done: /* clean up */ static void colrNewSpace(tms) /* color space changed for tone mapping */ -register struct tmStruct *tms; +register TMstruct *tms; { register COLRDATA *cd; double d; @@ -482,7 +435,7 @@ register struct tmStruct *tms; static MEM_PTR colrInit(tms) /* initialize private data for tone mapping */ -register struct tmStruct *tms; +register TMstruct *tms; { register COLRDATA *cd; register int i;