1 |
– |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ SGI"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Routines for tone mapping on Radiance RGBE and XYZE pictures. |
6 |
< |
* See tonemap.h for detailed function descriptions. |
6 |
> |
* |
7 |
> |
* Externals declared in tonemap.h |
8 |
|
*/ |
9 |
|
|
10 |
+ |
/* ==================================================================== |
11 |
+ |
* The Radiance Software License, Version 1.0 |
12 |
+ |
* |
13 |
+ |
* Copyright (c) 1990 - 2002 The Regents of the University of California, |
14 |
+ |
* through Lawrence Berkeley National Laboratory. All rights reserved. |
15 |
+ |
* |
16 |
+ |
* Redistribution and use in source and binary forms, with or without |
17 |
+ |
* modification, are permitted provided that the following conditions |
18 |
+ |
* are met: |
19 |
+ |
* |
20 |
+ |
* 1. Redistributions of source code must retain the above copyright |
21 |
+ |
* notice, this list of conditions and the following disclaimer. |
22 |
+ |
* |
23 |
+ |
* 2. Redistributions in binary form must reproduce the above copyright |
24 |
+ |
* notice, this list of conditions and the following disclaimer in |
25 |
+ |
* the documentation and/or other materials provided with the |
26 |
+ |
* distribution. |
27 |
+ |
* |
28 |
+ |
* 3. The end-user documentation included with the redistribution, |
29 |
+ |
* if any, must include the following acknowledgment: |
30 |
+ |
* "This product includes Radiance software |
31 |
+ |
* (http://radsite.lbl.gov/) |
32 |
+ |
* developed by the Lawrence Berkeley National Laboratory |
33 |
+ |
* (http://www.lbl.gov/)." |
34 |
+ |
* Alternately, this acknowledgment may appear in the software itself, |
35 |
+ |
* if and wherever such third-party acknowledgments normally appear. |
36 |
+ |
* |
37 |
+ |
* 4. The names "Radiance," "Lawrence Berkeley National Laboratory" |
38 |
+ |
* and "The Regents of the University of California" must |
39 |
+ |
* not be used to endorse or promote products derived from this |
40 |
+ |
* software without prior written permission. For written |
41 |
+ |
* permission, please contact [email protected]. |
42 |
+ |
* |
43 |
+ |
* 5. Products derived from this software may not be called "Radiance", |
44 |
+ |
* nor may "Radiance" appear in their name, without prior written |
45 |
+ |
* permission of Lawrence Berkeley National Laboratory. |
46 |
+ |
* |
47 |
+ |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED |
48 |
+ |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
49 |
+ |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
50 |
+ |
* DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR |
51 |
+ |
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
52 |
+ |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
53 |
+ |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
54 |
+ |
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
55 |
+ |
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
56 |
+ |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
57 |
+ |
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
58 |
+ |
* SUCH DAMAGE. |
59 |
+ |
* ==================================================================== |
60 |
+ |
* |
61 |
+ |
* This software consists of voluntary contributions made by many |
62 |
+ |
* individuals on behalf of Lawrence Berkeley National Laboratory. For more |
63 |
+ |
* information on Lawrence Berkeley National Laboratory, please see |
64 |
+ |
* <http://www.lbl.gov/>. |
65 |
+ |
*/ |
66 |
+ |
|
67 |
|
#include <stdio.h> |
68 |
+ |
#include <string.h> |
69 |
|
#include <math.h> |
70 |
+ |
#include <time.h> |
71 |
|
#include "tmprivat.h" |
72 |
|
#include "resolu.h" |
73 |
|
|
74 |
+ |
#ifndef TM_PIC_CTRANS |
75 |
+ |
#define TM_PIC_CTRANS 1 /* transform colors? (expensive) */ |
76 |
+ |
#endif |
77 |
|
|
18 |
– |
extern char *tempbuffer(); |
19 |
– |
|
78 |
|
#define GAMTSZ 1024 |
79 |
|
|
80 |
|
typedef struct { |
83 |
|
TMbright inpsfb; /* encoded tm->inpsf */ |
84 |
|
} COLRDATA; |
85 |
|
|
86 |
+ |
#ifdef NOPROTO |
87 |
|
static MEM_PTR colrInit(); |
88 |
|
static void colrNewSpace(); |
89 |
< |
extern void free(); |
89 |
> |
#else |
90 |
> |
static MEM_PTR colrInit(struct tmStruct *); |
91 |
> |
static void colrNewSpace(struct tmStruct *); |
92 |
> |
#endif |
93 |
|
static struct tmPackage colrPkg = { /* our package functions */ |
94 |
|
colrInit, colrNewSpace, free |
95 |
|
}; |
97 |
|
|
98 |
|
#define LOGISZ 260 |
99 |
|
static TMbright logi[LOGISZ]; |
38 |
– |
static BYTE photofact[BMESUPPER-BMESLOWER]; |
100 |
|
|
101 |
|
|
102 |
|
int |
115 |
|
returnErr(TM_E_TMINVAL); |
116 |
|
if (ls == NULL | scan == NULL | len < 0) |
117 |
|
returnErr(TM_E_ILLEGAL); |
118 |
+ |
#if TM_PIC_CTRANS |
119 |
|
if (tmNeedMatrix(tmTop)) { /* need floating point */ |
120 |
+ |
#else |
121 |
+ |
if (tmTop->inppri == TM_XYZPRIM) { /* no way around this */ |
122 |
+ |
#endif |
123 |
|
register COLOR *newscan; |
124 |
|
newscan = (COLOR *)tempbuffer(len*sizeof(COLOR)); |
125 |
|
if (newscan == NULL) |
135 |
|
for (i = 256; i--; ) |
136 |
|
logi[i] = TM_BRTSCALE*log((i+.5)/256.) - .5; |
137 |
|
for (i = 256; i < LOGISZ; i++) |
138 |
< |
logi[i] = logi[255]; |
139 |
< |
for (i = BMESLOWER; i < BMESUPPER; i++) |
75 |
< |
photofact[i-BMESLOWER] = 256. * |
76 |
< |
(tmLuminance(i) - LMESLOWER) / |
77 |
< |
(LMESUPPER - LMESLOWER); |
138 |
> |
logi[i] = 0; |
139 |
> |
tmMkMesofact(); |
140 |
|
} |
141 |
|
if ((cd = (COLRDATA *)tmPkgData(tmTop,colrReg)) == NULL) |
142 |
|
returnErr(TM_E_NOMEM); |
146 |
|
li = ( cd->clfb[RED]*cmon[RED] + |
147 |
|
cd->clfb[GRN]*cmon[GRN] + |
148 |
|
cd->clfb[BLU]*cmon[BLU] ) >> 8; |
149 |
< |
bi = BRT2SCALE*(cmon[EXP]-COLXS) + |
149 |
> |
bi = BRT2SCALE(cmon[EXP]-COLXS) + |
150 |
|
logi[li] + cd->inpsfb; |
151 |
< |
if (bi < MINBRT) { |
152 |
< |
bi = MINBRT-1; /* bogus value */ |
153 |
< |
li++; /* avoid li==0 */ |
151 |
> |
if (li <= 0) { |
152 |
> |
bi = TM_NOBRT; /* bogus value */ |
153 |
> |
li = 1; /* avoid li==0 */ |
154 |
|
} |
155 |
|
ls[i] = bi; |
156 |
|
if (cs == TM_NOCHROM) /* no color? */ |
163 |
|
else { |
164 |
|
if (tmTop->flags & TM_F_BW) |
165 |
|
cmon[RED] = cmon[GRN] = cmon[BLU] = li; |
166 |
< |
pf = photofact[bi-BMESLOWER]; |
166 |
> |
pf = tmMesofact[bi-BMESLOWER]; |
167 |
|
sli *= 256 - pf; |
168 |
|
cmon[RED] = ( sli + pf*cmon[RED] ) >> 8; |
169 |
|
cmon[GRN] = ( sli + pf*cmon[GRN] ) >> 8; |
251 |
|
*lpp = NULL; |
252 |
|
if (cpp != TM_NOCHROMP) *cpp = NULL; |
253 |
|
info = rhdefault; /* get our header */ |
254 |
< |
getheader(inpf, headline, (MEM_PTR)&info); |
254 |
> |
getheader(inpf, headline, (char *)&info); |
255 |
|
if (info.format == FMTBAD | info.expos <= 0. || |
256 |
|
fgetresolu(xp, yp, inpf) < 0) { |
257 |
|
err = TM_E_BADFILE; goto done; |
315 |
|
char *fname; |
316 |
|
{ |
317 |
|
char *funcName = fname; |
318 |
< |
char cmdbuf[512]; |
318 |
> |
char cmdbuf[1024]; |
319 |
|
FILE *infp; |
320 |
|
register COLR *scan; |
321 |
|
register BYTE *rp; |