7 |
|
* Externals declared in tmaptiff.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 |
< |
*/ |
10 |
> |
#include "copyright.h" |
11 |
|
|
12 |
|
#define LOGLUV_PUBLIC 1 |
13 |
|
|
18 |
|
#include "tmprivat.h" |
19 |
|
#include "tmaptiff.h" |
20 |
|
|
76 |
– |
#ifndef BSD |
77 |
– |
#define bzero(d,n) (void)memset(d,0,n) |
78 |
– |
#endif |
21 |
|
#define uvflgop(p,uv,op) ((p)->rgbflg[(uv)>>5] op (1L<<((uv)&0x1f))) |
22 |
|
#define isuvset(p,uv) uvflgop(p,uv,&) |
23 |
|
#define setuv(p,uv) uvflgop(p,uv,|=) |
24 |
|
#define clruv(p,uv) uvflgop(p,uv,&=~) |
25 |
< |
#define clruvall(p) bzero((MEM_PTR)(p)->rgbflg,sizeof((p)->rgbflg)) |
25 |
> |
#define clruvall(p) memset((MEM_PTR)(p)->rgbflg,'\0',sizeof((p)->rgbflg)) |
26 |
|
|
27 |
|
#ifdef NOPROTO |
28 |
|
static MEM_PTR luv32Init(); |
30 |
|
static MEM_PTR luv24Init(); |
31 |
|
static void luv24NewSpace(); |
32 |
|
#else |
33 |
< |
static MEM_PTR luv32Init(struct tmStruct *); |
34 |
< |
static void luv32NewSpace(struct tmStruct *); |
35 |
< |
static MEM_PTR luv24Init(struct tmStruct *); |
36 |
< |
static void luv24NewSpace(struct tmStruct *); |
33 |
> |
static MEM_PTR luv32Init(TMstruct *); |
34 |
> |
static void luv32NewSpace(TMstruct *); |
35 |
> |
static MEM_PTR luv24Init(TMstruct *); |
36 |
> |
static void luv24NewSpace(TMstruct *); |
37 |
|
#endif |
38 |
|
|
39 |
|
typedef struct { |
65 |
|
|
66 |
|
|
67 |
|
static void |
68 |
< |
uv2rgb(rgb, tm, uvp) /* compute RGB from uv coordinate */ |
68 |
> |
uv2rgb(rgb, tms, uvp) /* compute RGB from uv coordinate */ |
69 |
|
BYTE rgb[3]; |
70 |
< |
register struct tmStruct *tm; |
70 |
> |
register TMstruct *tms; |
71 |
|
double uvp[2]; |
72 |
< |
{ /* Should check that tm->inppri==TM_XYZPRIM beforehand... */ |
72 |
> |
{ /* Should check that tms->inppri==TM_XYZPRIM beforehand... */ |
73 |
|
double d, x, y; |
74 |
|
COLOR XYZ, RGB; |
75 |
|
/* convert to XYZ */ |
76 |
|
d = 1./(6.*uvp[0] - 16.*uvp[1] + 12.); |
77 |
|
x = 9.*uvp[0] * d; |
78 |
|
y = 4.*uvp[1] * d; |
79 |
< |
XYZ[CIEY] = 1./tm->inpsf; |
79 |
> |
XYZ[CIEY] = 1./tms->inpsf; |
80 |
|
XYZ[CIEX] = x/y * XYZ[CIEY]; |
81 |
|
XYZ[CIEZ] = (1.-x-y)/y * XYZ[CIEY]; |
82 |
|
/* convert to RGB and clip */ |
83 |
< |
colortrans(RGB, tm->cmat, XYZ); |
83 |
> |
colortrans(RGB, tms->cmat, XYZ); |
84 |
|
clipgamut(RGB, 1., CGAMUT_LOWER, cblack, cwhite); |
85 |
|
/* perform final scaling & gamma */ |
86 |
< |
d = tm->clf[RED] * RGB[RED]; |
87 |
< |
rgb[RED] = d>=.999 ? 255 : (int)(256.*pow(d, 1./tm->mongam)); |
88 |
< |
d = tm->clf[GRN] * RGB[GRN]; |
89 |
< |
rgb[GRN] = d>=.999 ? 255 : (int)(256.*pow(d, 1./tm->mongam)); |
90 |
< |
d = tm->clf[BLU] * RGB[BLU]; |
91 |
< |
rgb[BLU] = d>=.999 ? 255 : (int)(256.*pow(d, 1./tm->mongam)); |
86 |
> |
d = tms->clf[RED] * RGB[RED]; |
87 |
> |
rgb[RED] = d>=.999 ? 255 : (int)(256.*pow(d, 1./tms->mongam)); |
88 |
> |
d = tms->clf[GRN] * RGB[GRN]; |
89 |
> |
rgb[GRN] = d>=.999 ? 255 : (int)(256.*pow(d, 1./tms->mongam)); |
90 |
> |
d = tms->clf[BLU] * RGB[BLU]; |
91 |
> |
rgb[BLU] = d>=.999 ? 255 : (int)(256.*pow(d, 1./tms->mongam)); |
92 |
|
} |
93 |
|
|
94 |
|
|
123 |
|
|
124 |
|
|
125 |
|
int |
126 |
< |
tmCvLuv32(ls, cs, luvs, len) /* convert raw 32-bit LogLuv values */ |
127 |
< |
TMbright *ls; |
128 |
< |
BYTE *cs; |
129 |
< |
uint32 *luvs; |
130 |
< |
int len; |
126 |
> |
tmCvLuv32( /* convert raw 32-bit LogLuv values */ |
127 |
> |
TMstruct *tms, |
128 |
> |
TMbright *ls, |
129 |
> |
BYTE *cs, |
130 |
> |
uint32 *luvs, |
131 |
> |
int len |
132 |
> |
) |
133 |
|
{ |
134 |
< |
static char funcName[] = "tmCvLuv32"; |
134 |
> |
static const char funcName[] = "tmCvLuv32"; |
135 |
|
double uvp[2]; |
136 |
|
register LUV32DATA *ld; |
137 |
|
register int i, j; |
138 |
|
/* check arguments */ |
139 |
< |
if (tmTop == NULL) |
139 |
> |
if (tms == NULL) |
140 |
|
returnErr(TM_E_TMINVAL); |
141 |
< |
if (ls == NULL | luvs == NULL | len < 0) |
141 |
> |
if ((ls == NULL) | (luvs == NULL) | (len < 0)) |
142 |
|
returnErr(TM_E_ILLEGAL); |
143 |
|
/* check package registration */ |
144 |
|
if (luv32Reg < 0) { |
147 |
|
tmMkMesofact(); |
148 |
|
} |
149 |
|
/* get package data */ |
150 |
< |
if ((ld = (LUV32DATA *)tmPkgData(tmTop,luv32Reg)) == NULL) |
150 |
> |
if ((ld = (LUV32DATA *)tmPkgData(tms,luv32Reg)) == NULL) |
151 |
|
returnErr(TM_E_NOMEM); |
152 |
|
/* convert each pixel */ |
153 |
|
for (i = len; i--; ) { |
159 |
|
if (cs == TM_NOCHROM) /* no color? */ |
160 |
|
continue; |
161 |
|
/* get chrominance */ |
162 |
< |
if (tmTop->flags & TM_F_MESOPIC && ls[i] < BMESUPPER) { |
162 |
> |
if (tms->flags & TM_F_MESOPIC && ls[i] < BMESUPPER) { |
163 |
|
uvp[0] = 1./UVSCALE*((luvs[i]>>8 & 0xff) + .5); |
164 |
|
uvp[1] = 1./UVSCALE*((luvs[i] & 0xff) + .5); |
165 |
|
ls[i] = compmeshift(ls[i], uvp); |
166 |
< |
j = tmTop->flags&TM_F_BW || ls[i]<BMESLOWER |
166 |
> |
j = tms->flags&TM_F_BW || ls[i]<BMESLOWER |
167 |
|
? UVNEU |
168 |
|
: (int)(uvp[0]*UVSCALE)<<8 |
169 |
|
| (int)(uvp[1]*UVSCALE); |
170 |
|
} else { |
171 |
< |
j = tmTop->flags&TM_F_BW ? UVNEU : luvs[i]&0xffff; |
171 |
> |
j = tms->flags&TM_F_BW ? UVNEU : luvs[i]&0xffff; |
172 |
|
} |
173 |
|
if (!isuvset(ld, j)) { |
174 |
|
uvp[0] = 1./UVSCALE*((j>>8) + .5); |
175 |
|
uvp[1] = 1./UVSCALE*((j & 0xff) + .5); |
176 |
< |
uv2rgb(ld->rgbval[j], tmTop, uvp); |
176 |
> |
uv2rgb(ld->rgbval[j], tms, uvp); |
177 |
|
setuv(ld, j); |
178 |
|
} |
179 |
|
cs[3*i ] = ld->rgbval[j][RED]; |
185 |
|
|
186 |
|
|
187 |
|
int |
188 |
< |
tmCvLuv24(ls, cs, luvs, len) /* convert raw 24-bit LogLuv values */ |
189 |
< |
TMbright *ls; |
190 |
< |
BYTE *cs; |
191 |
< |
uint32 *luvs; |
192 |
< |
int len; |
188 |
> |
tmCvLuv24( /* convert raw 24-bit LogLuv values */ |
189 |
> |
TMstruct *tms, |
190 |
> |
TMbright *ls, |
191 |
> |
BYTE *cs, |
192 |
> |
uint32 *luvs, |
193 |
> |
int len |
194 |
> |
) |
195 |
|
{ |
196 |
|
char funcName[] = "tmCvLuv24"; |
197 |
|
double uvp[2]; |
198 |
|
register LUV24DATA *ld; |
199 |
|
register int i, j; |
200 |
|
/* check arguments */ |
201 |
< |
if (tmTop == NULL) |
201 |
> |
if (tms == NULL) |
202 |
|
returnErr(TM_E_TMINVAL); |
203 |
< |
if (ls == NULL | luvs == NULL | len < 0) |
203 |
> |
if ((ls == NULL) | (luvs == NULL) | (len < 0)) |
204 |
|
returnErr(TM_E_ILLEGAL); |
205 |
|
/* check package registration */ |
206 |
|
if (luv24Reg < 0) { |
209 |
|
tmMkMesofact(); |
210 |
|
} |
211 |
|
/* get package data */ |
212 |
< |
if ((ld = (LUV24DATA *)tmPkgData(tmTop,luv24Reg)) == NULL) |
212 |
> |
if ((ld = (LUV24DATA *)tmPkgData(tms,luv24Reg)) == NULL) |
213 |
|
returnErr(TM_E_NOMEM); |
214 |
|
/* convert each pixel */ |
215 |
|
for (i = len; i--; ) { |
218 |
|
if (cs == TM_NOCHROM) /* no color? */ |
219 |
|
continue; |
220 |
|
/* get chrominance */ |
221 |
< |
if (tmTop->flags & TM_F_MESOPIC && ls[i] < BMESUPPER) { |
222 |
< |
if (uv_decode(uvp, uvp+1, luvs[i]&0x3fff) < 0) { |
221 |
> |
if (tms->flags & TM_F_MESOPIC && ls[i] < BMESUPPER) { |
222 |
> |
if (uv_decode(&uvp[0], &uvp[1], luvs[i]&0x3fff) < 0) { |
223 |
|
uvp[0] = U_NEU; /* should barf? */ |
224 |
|
uvp[1] = V_NEU; |
225 |
|
} |
226 |
|
ls[i] = compmeshift(ls[i], uvp); |
227 |
< |
if (tmTop->flags&TM_F_BW || ls[i]<BMESLOWER |
227 |
> |
if (tms->flags&TM_F_BW || ls[i]<BMESLOWER |
228 |
|
|| (j = uv_encode(uvp[0], uvp[1], |
229 |
|
SGILOGENCODE_NODITHER)) < 0) |
230 |
|
j = uv14neu; |
231 |
|
} else { |
232 |
< |
j = tmTop->flags&TM_F_BW ? uv14neu : luvs[i]&0x3fff; |
232 |
> |
j = tms->flags&TM_F_BW ? uv14neu : |
233 |
> |
(int)(luvs[i]&0x3fff); |
234 |
|
} |
235 |
|
if (!isuvset(ld, j)) { |
236 |
|
if (uv_decode(&uvp[0], &uvp[1], j) < 0) { |
237 |
|
uvp[0] = U_NEU; uvp[1] = V_NEU; |
238 |
|
} |
239 |
< |
uv2rgb(ld->rgbval[j], tmTop, uvp); |
239 |
> |
uv2rgb(ld->rgbval[j], tms, uvp); |
240 |
|
setuv(ld, j); |
241 |
|
} |
242 |
|
cs[3*i ] = ld->rgbval[j][RED]; |
248 |
|
|
249 |
|
|
250 |
|
int |
251 |
< |
tmCvL16(ls, l16s, len) /* convert 16-bit LogL values */ |
252 |
< |
TMbright *ls; |
253 |
< |
uint16 *l16s; |
254 |
< |
int len; |
251 |
> |
tmCvL16( /* convert 16-bit LogL values */ |
252 |
> |
TMstruct *tms, |
253 |
> |
TMbright *ls, |
254 |
> |
uint16 *l16s, |
255 |
> |
int len |
256 |
> |
) |
257 |
|
{ |
258 |
< |
static char funcName[] = "tmCvL16"; |
258 |
> |
static const char funcName[] = "tmCvL16"; |
259 |
|
static double lastsf; |
260 |
|
static int offset; |
261 |
|
register int i; |
262 |
|
/* check arguments */ |
263 |
< |
if (tmTop == NULL) |
263 |
> |
if (tms == NULL) |
264 |
|
returnErr(TM_E_TMINVAL); |
265 |
< |
if (ls == NULL | l16s == NULL | len < 0) |
265 |
> |
if ((ls == NULL) | (l16s == NULL) | (len < 0)) |
266 |
|
returnErr(TM_E_ILLEGAL); |
267 |
|
/* check scaling offset */ |
268 |
< |
if (!FEQ(tmTop->inpsf, lastsf)) { |
268 |
> |
if (!FEQ(tms->inpsf, lastsf)) { |
269 |
|
offset = BRT2SCALE(64); |
270 |
< |
if (tmTop->inpsf > 1.0001) |
271 |
< |
offset -= (int)(TM_BRTSCALE*log(tmTop->inpsf)+.5); |
272 |
< |
else if (tmTop->inpsf < 0.9999) |
273 |
< |
offset -= (int)(TM_BRTSCALE*log(tmTop->inpsf)-.5); |
274 |
< |
lastsf = tmTop->inpsf; |
270 |
> |
if (tms->inpsf > 1.0001) |
271 |
> |
offset -= (int)(TM_BRTSCALE*log(tms->inpsf)+.5); |
272 |
> |
else if (tms->inpsf < 0.9999) |
273 |
> |
offset -= (int)(TM_BRTSCALE*log(tms->inpsf)-.5); |
274 |
> |
lastsf = tms->inpsf; |
275 |
|
} |
276 |
|
/* convert each pixel */ |
277 |
|
for (i = len; i--; ) { |
285 |
|
|
286 |
|
|
287 |
|
static void |
288 |
< |
luv32NewSpace(tm) /* initialize 32-bit LogLuv color space */ |
289 |
< |
struct tmStruct *tm; |
288 |
> |
luv32NewSpace(tms) /* initialize 32-bit LogLuv color space */ |
289 |
> |
TMstruct *tms; |
290 |
|
{ |
291 |
|
register LUV32DATA *ld; |
292 |
|
|
293 |
< |
if (tm->inppri != TM_XYZPRIM) { /* panic time! */ |
293 |
> |
if (tms->inppri != TM_XYZPRIM) { /* panic time! */ |
294 |
|
fputs("Improper input color space in luv32NewSpace!\n", stderr); |
295 |
|
exit(1); |
296 |
|
} |
297 |
< |
ld = (LUV32DATA *)tm->pd[luv32Reg]; |
297 |
> |
ld = (LUV32DATA *)tms->pd[luv32Reg]; |
298 |
|
ld->offset = BRT2SCALE(64); |
299 |
< |
if (tm->inpsf > 1.0001) |
300 |
< |
ld->offset -= (int)(TM_BRTSCALE*log(tmTop->inpsf)+.5); |
301 |
< |
else if (tm->inpsf < 0.9999) |
302 |
< |
ld->offset -= (int)(TM_BRTSCALE*log(tmTop->inpsf)-.5); |
299 |
> |
if (tms->inpsf > 1.0001) |
300 |
> |
ld->offset -= (int)(TM_BRTSCALE*log(tms->inpsf)+.5); |
301 |
> |
else if (tms->inpsf < 0.9999) |
302 |
> |
ld->offset -= (int)(TM_BRTSCALE*log(tms->inpsf)-.5); |
303 |
|
clruvall(ld); |
304 |
|
} |
305 |
|
|
306 |
|
|
307 |
|
static MEM_PTR |
308 |
< |
luv32Init(tm) /* allocate data for 32-bit LogLuv decoder */ |
309 |
< |
struct tmStruct *tm; |
308 |
> |
luv32Init(tms) /* allocate data for 32-bit LogLuv decoder */ |
309 |
> |
TMstruct *tms; |
310 |
|
{ |
311 |
|
register LUV32DATA *ld; |
312 |
|
|
313 |
|
ld = (LUV32DATA *)malloc(sizeof(LUV32DATA)); |
314 |
|
if (ld == NULL) |
315 |
|
return(NULL); |
316 |
< |
tm->pd[luv32Reg] = (MEM_PTR)ld; |
317 |
< |
luv32NewSpace(tm); |
316 |
> |
tms->pd[luv32Reg] = (MEM_PTR)ld; |
317 |
> |
luv32NewSpace(tms); |
318 |
|
return((MEM_PTR)ld); |
319 |
|
} |
320 |
|
|
321 |
|
|
322 |
|
static void |
323 |
< |
luv24NewSpace(tm) /* initialize 24-bit LogLuv color space */ |
324 |
< |
struct tmStruct *tm; |
323 |
> |
luv24NewSpace(tms) /* initialize 24-bit LogLuv color space */ |
324 |
> |
TMstruct *tms; |
325 |
|
{ |
326 |
|
register LUV24DATA *ld; |
327 |
|
|
328 |
< |
if (tm->inppri != TM_XYZPRIM) { /* panic time! */ |
328 |
> |
if (tms->inppri != TM_XYZPRIM) { /* panic time! */ |
329 |
|
fputs("Improper input color space in luv24NewSpace!\n", stderr); |
330 |
|
exit(1); |
331 |
|
} |
332 |
< |
ld = (LUV24DATA *)tm->pd[luv24Reg]; |
332 |
> |
ld = (LUV24DATA *)tms->pd[luv24Reg]; |
333 |
|
ld->offset = BRT2SCALE(12); |
334 |
< |
if (tm->inpsf > 1.0001) |
335 |
< |
ld->offset -= (int)(TM_BRTSCALE*log(tmTop->inpsf)+.5); |
336 |
< |
else if (tm->inpsf < 0.9999) |
337 |
< |
ld->offset -= (int)(TM_BRTSCALE*log(tmTop->inpsf)-.5); |
334 |
> |
if (tms->inpsf > 1.0001) |
335 |
> |
ld->offset -= (int)(TM_BRTSCALE*log(tms->inpsf)+.5); |
336 |
> |
else if (tms->inpsf < 0.9999) |
337 |
> |
ld->offset -= (int)(TM_BRTSCALE*log(tms->inpsf)-.5); |
338 |
|
clruvall(ld); |
339 |
|
} |
340 |
|
|
341 |
|
|
342 |
|
static MEM_PTR |
343 |
< |
luv24Init(tm) /* allocate data for 24-bit LogLuv decoder */ |
344 |
< |
struct tmStruct *tm; |
343 |
> |
luv24Init(tms) /* allocate data for 24-bit LogLuv decoder */ |
344 |
> |
TMstruct *tms; |
345 |
|
{ |
346 |
|
register LUV24DATA *ld; |
347 |
|
|
348 |
|
ld = (LUV24DATA *)malloc(sizeof(LUV24DATA)); |
349 |
|
if (ld == NULL) |
350 |
|
return(NULL); |
351 |
< |
tm->pd[luv24Reg] = (MEM_PTR)ld; |
351 |
> |
tms->pd[luv24Reg] = (MEM_PTR)ld; |
352 |
|
if (uv14neu < 0) /* initialize neutral color index */ |
353 |
|
uv14neu = uv_encode(U_NEU, V_NEU, SGILOGENCODE_NODITHER); |
354 |
< |
luv24NewSpace(tm); |
354 |
> |
luv24NewSpace(tms); |
355 |
|
return((MEM_PTR)ld); |
356 |
|
} |