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 LogLuv encoded pixels. |
6 |
+ |
* |
7 |
+ |
* Externals declared in tmaptiff.h |
8 |
|
*/ |
9 |
|
|
10 |
+ |
#include "copyright.h" |
11 |
+ |
|
12 |
+ |
#define LOGLUV_PUBLIC 1 |
13 |
+ |
|
14 |
|
#include <stdio.h> |
15 |
+ |
#include <stdlib.h> |
16 |
+ |
#include <string.h> |
17 |
|
#include <math.h> |
18 |
|
#include "tiffio.h" |
19 |
|
#include "tmprivat.h" |
20 |
< |
#include "uvcode.h" |
20 |
> |
#include "tmaptiff.h" |
21 |
|
|
17 |
– |
#ifndef BSD |
18 |
– |
#define bzero(d,n) (void)memset(d,0,n) |
19 |
– |
#endif |
22 |
|
#define uvflgop(p,uv,op) ((p)->rgbflg[(uv)>>5] op (1L<<((uv)&0x1f))) |
23 |
|
#define isuvset(p,uv) uvflgop(p,uv,&) |
24 |
|
#define setuv(p,uv) uvflgop(p,uv,|=) |
25 |
|
#define clruv(p,uv) uvflgop(p,uv,&=~) |
26 |
< |
#define clruvall(p) bzero((MEM_PTR)(p)->rgbflg,sizeof((p)->rgbflg)) |
26 |
> |
#define clruvall(p) memset((p)->rgbflg,'\0',sizeof((p)->rgbflg)) |
27 |
|
|
28 |
< |
#define U_NEU 0.210526316 |
29 |
< |
#define V_NEU 0.473684211 |
28 |
< |
|
29 |
< |
static MEM_PTR luv32Init(); |
28 |
> |
#ifdef NOPROTO |
29 |
> |
static void * luv32Init(); |
30 |
|
static void luv32NewSpace(); |
31 |
< |
static MEM_PTR luv24Init(); |
31 |
> |
static void * luv24Init(); |
32 |
|
static void luv24NewSpace(); |
33 |
< |
extern void free(); |
33 |
> |
#else |
34 |
> |
static void * luv32Init(TMstruct *); |
35 |
> |
static void luv32NewSpace(TMstruct *); |
36 |
> |
static void * luv24Init(TMstruct *); |
37 |
> |
static void luv24NewSpace(TMstruct *); |
38 |
> |
#endif |
39 |
|
|
40 |
|
typedef struct { |
41 |
|
int offset; /* computed luminance offset */ |
42 |
< |
BYTE rgbval[1<<16][3]; /* computed RGB value for given uv */ |
42 |
> |
uby8 rgbval[1<<16][3]; /* computed RGB value for given uv */ |
43 |
|
uint32 rgbflg[1<<(16-5)]; /* flags for computed values */ |
44 |
|
} LUV32DATA; /* LogLuv 32-bit conversion data */ |
45 |
|
|
41 |
– |
#define UVSCALE 410. |
46 |
|
#define UVNEU ((int)(UVSCALE*U_NEU)<<8 \ |
47 |
|
| (int)(UVSCALE*V_NEU)) |
48 |
|
|
53 |
|
|
54 |
|
typedef struct { |
55 |
|
int offset; /* computed luminance offset */ |
56 |
< |
BYTE rgbval[1<<14][3]; /* computed rgb value for uv index */ |
56 |
> |
uby8 rgbval[1<<14][3]; /* computed rgb value for uv index */ |
57 |
|
uint32 rgbflg[1<<(14-5)]; /* flags for computed values */ |
58 |
|
} LUV24DATA; /* LogLuv 24-bit conversion data */ |
59 |
|
|
65 |
|
static int uv14neu = -1; /* neutral index for 14-bit (u',v') */ |
66 |
|
|
67 |
|
|
68 |
< |
static |
69 |
< |
uv2rgb(rgb, tm, uvp) /* compute RGB from uv coordinate */ |
70 |
< |
BYTE rgb[3]; |
71 |
< |
register struct tmStruct *tm; |
68 |
> |
static void |
69 |
> |
uv2rgb(rgb, tms, uvp) /* compute RGB from uv coordinate */ |
70 |
> |
uby8 rgb[3]; |
71 |
> |
TMstruct *tms; |
72 |
|
double uvp[2]; |
73 |
< |
{ /* Should check that tm->inppri==TM_XYZPRIM beforehand... */ |
73 |
> |
{ /* Should check that tms->inppri==TM_XYZPRIM beforehand... */ |
74 |
|
double d, x, y; |
75 |
|
COLOR XYZ, RGB; |
76 |
|
/* convert to XYZ */ |
77 |
|
d = 1./(6.*uvp[0] - 16.*uvp[1] + 12.); |
78 |
|
x = 9.*uvp[0] * d; |
79 |
|
y = 4.*uvp[1] * d; |
80 |
< |
XYZ[CIEY] = 1./tm->inpsf; |
80 |
> |
XYZ[CIEY] = 1./tms->inpsf; |
81 |
|
XYZ[CIEX] = x/y * XYZ[CIEY]; |
82 |
|
XYZ[CIEZ] = (1.-x-y)/y * XYZ[CIEY]; |
83 |
|
/* convert to RGB and clip */ |
84 |
< |
colortrans(RGB, tm->cmat, XYZ); |
85 |
< |
clipgamut(RGB, XYZ[CIEY], CGAMUT_LOWER, cblack, cwhite); |
84 |
> |
colortrans(RGB, tms->cmat, XYZ); |
85 |
> |
clipgamut(RGB, 1., CGAMUT_LOWER, cblack, cwhite); |
86 |
|
/* perform final scaling & gamma */ |
87 |
< |
d = tm->clf[RED] * RGB[RED]; |
88 |
< |
rgb[RED] = d>=.999 ? 255 : (int)(256.*pow(d, 1./tm->mongam)); |
89 |
< |
d = tm->clf[GRN] * RGB[GRN]; |
90 |
< |
rgb[GRN] = d>=.999 ? 255 : (int)(256.*pow(d, 1./tm->mongam)); |
91 |
< |
d = tm->clf[BLU] * RGB[BLU]; |
92 |
< |
rgb[BLU] = d>=.999 ? 255 : (int)(256.*pow(d, 1./tm->mongam)); |
87 |
> |
d = tms->clf[RED] * RGB[RED]; |
88 |
> |
rgb[RED] = d>=.999 ? 255 : (int)(256.*pow(d, 1./tms->mongam)); |
89 |
> |
d = tms->clf[GRN] * RGB[GRN]; |
90 |
> |
rgb[GRN] = d>=.999 ? 255 : (int)(256.*pow(d, 1./tms->mongam)); |
91 |
> |
d = tms->clf[BLU] * RGB[BLU]; |
92 |
> |
rgb[BLU] = d>=.999 ? 255 : (int)(256.*pow(d, 1./tms->mongam)); |
93 |
|
} |
94 |
|
|
95 |
|
|
98 |
|
TMbright li; /* encoded world luminance */ |
99 |
|
double uvp[2]; /* world (u',v') -> returned desaturated */ |
100 |
|
{ |
101 |
< |
double scotrat, d; |
101 |
> |
double scotrat; |
102 |
> |
double d; |
103 |
|
|
104 |
|
if (li >= BMESUPPER) |
105 |
|
return(li); |
106 |
< |
scotrat = 1.33/9.*(6.*uvp[0]-16.*uvp[1]+12.)/uvp[0] - 1.68; |
106 |
> |
scotrat = (.767676768 - 1.02356902*uvp[1])/uvp[0] - .343434343; |
107 |
|
if (li <= BMESLOWER) { |
108 |
|
d = 0.; |
109 |
|
uvp[0] = U_NEU; uvp[1] = V_NEU; |
110 |
|
} else { |
111 |
< |
d = (tmLuminance(li) - LMESLOWER)/(LMESUPPER - LMESLOWER); |
111 |
> |
d = (tmMesofact[li-BMESLOWER] + .5) * (1./256.); |
112 |
|
uvp[0] = d*uvp[0] + (1.-d)*U_NEU; |
113 |
|
uvp[1] = d*uvp[1] + (1.-d)*V_NEU; |
114 |
|
} |
115 |
< |
d = li + (double)TM_BRTSCALE*log(d + (1.-d)*scotrat/2.26); |
116 |
< |
return((TMbright)(d+.5)); |
115 |
> |
/* |
116 |
> |
d = li + (double)TM_BRTSCALE*log(d + (1.-d)*scotrat); |
117 |
> |
*/ |
118 |
> |
d = d + (1.-d)*scotrat; |
119 |
> |
d -= 1.; /* Taylor expansion of log(x) about 1 */ |
120 |
> |
d = d*(1. + d*(-.5 + d*(1./3. + d*-.125))); |
121 |
> |
d = li + (double)TM_BRTSCALE*d; |
122 |
> |
return((TMbright)(d>0. ? d+.5 : d-.5)); |
123 |
|
} |
124 |
|
|
125 |
|
|
115 |
– |
static int |
116 |
– |
uvpencode(uvp) /* encode (u',v') coordinates */ |
117 |
– |
double uvp[2]; |
118 |
– |
{ |
119 |
– |
register int vi, ui; |
120 |
– |
|
121 |
– |
if (uvp[1] < UV_VSTART) |
122 |
– |
return(-1); |
123 |
– |
vi = (uvp[1] - UV_VSTART)*(1./UV_SQSIZ); |
124 |
– |
if (vi >= UV_NVS) |
125 |
– |
return(-1); |
126 |
– |
if (uvp[0] < uv_row[vi].ustart) |
127 |
– |
return(-1); |
128 |
– |
ui = (uvp[0] - uv_row[vi].ustart)*(1./UV_SQSIZ); |
129 |
– |
if (ui >= uv_row[vi].nus) |
130 |
– |
return(-1); |
131 |
– |
return(uv_row[vi].ncum + ui); |
132 |
– |
} |
133 |
– |
|
134 |
– |
|
135 |
– |
static int |
136 |
– |
uvpdecode(uvp, c) /* decode (u',v') index */ |
137 |
– |
double uvp[2]; |
138 |
– |
int c; |
139 |
– |
{ |
140 |
– |
int upper, lower; |
141 |
– |
register int ui, vi; |
142 |
– |
|
143 |
– |
if (c < 0 || c >= UV_NDIVS) |
144 |
– |
return(-1); |
145 |
– |
lower = 0; /* binary search */ |
146 |
– |
upper = UV_NVS; |
147 |
– |
do { |
148 |
– |
vi = (lower + upper) >> 1; |
149 |
– |
ui = c - uv_row[vi].ncum; |
150 |
– |
if (ui > 0) |
151 |
– |
lower = vi; |
152 |
– |
else if (ui < 0) |
153 |
– |
upper = vi; |
154 |
– |
else |
155 |
– |
break; |
156 |
– |
} while (upper - lower > 1); |
157 |
– |
vi = lower; |
158 |
– |
ui = c - uv_row[vi].ncum; |
159 |
– |
uvp[0] = uv_row[vi].ustart + (ui+.5)*UV_SQSIZ; |
160 |
– |
uvp[1] = UV_VSTART + (vi+.5)*UV_SQSIZ; |
161 |
– |
return(0); |
162 |
– |
} |
163 |
– |
|
164 |
– |
|
126 |
|
int |
127 |
< |
tmCvLuv32(ls, cs, luvs, len) /* convert raw 32-bit LogLuv values */ |
128 |
< |
TMbright *ls; |
129 |
< |
BYTE *cs; |
130 |
< |
uint32 *luvs; |
131 |
< |
int len; |
127 |
> |
tmCvLuv32( /* convert raw 32-bit LogLuv values */ |
128 |
> |
TMstruct *tms, |
129 |
> |
TMbright *ls, |
130 |
> |
uby8 *cs, |
131 |
> |
uint32 *luvs, |
132 |
> |
int len |
133 |
> |
) |
134 |
|
{ |
135 |
< |
static char funcName[] = "tmCvLuv32"; |
135 |
> |
static const char funcName[] = "tmCvLuv32"; |
136 |
|
double uvp[2]; |
137 |
< |
register LUV32DATA *ld; |
138 |
< |
register int i, j; |
137 |
> |
LUV32DATA *ld; |
138 |
> |
int i, j; |
139 |
|
/* check arguments */ |
140 |
< |
if (tmTop == NULL) |
140 |
> |
if (tms == NULL) |
141 |
|
returnErr(TM_E_TMINVAL); |
142 |
< |
if (ls == NULL | luvs == NULL | len < 0) |
142 |
> |
if ((ls == NULL) | (luvs == NULL) | (len < 0)) |
143 |
|
returnErr(TM_E_ILLEGAL); |
144 |
|
/* check package registration */ |
145 |
< |
if (luv32Reg < 0 && (luv32Reg = tmRegPkg(&luv32Pkg)) < 0) |
146 |
< |
returnErr(TM_E_CODERR1); |
145 |
> |
if (luv32Reg < 0) { |
146 |
> |
if ((luv32Reg = tmRegPkg(&luv32Pkg)) < 0) |
147 |
> |
returnErr(TM_E_CODERR1); |
148 |
> |
tmMkMesofact(); |
149 |
> |
} |
150 |
|
/* get package data */ |
151 |
< |
if ((ld = (LUV32DATA *)tmPkgData(tmTop,luv32Reg)) == NULL) |
151 |
> |
if ((ld = (LUV32DATA *)tmPkgData(tms,luv32Reg)) == NULL) |
152 |
|
returnErr(TM_E_NOMEM); |
153 |
|
/* convert each pixel */ |
154 |
|
for (i = len; i--; ) { |
155 |
|
j = luvs[i] >> 16; /* get luminance */ |
156 |
|
if (j & 0x8000) /* negative luminance */ |
157 |
< |
ls[i] = MINBRT-1; /* assign bogus value */ |
157 |
> |
ls[i] = TM_NOBRT; /* assign bogus value */ |
158 |
|
else /* else convert to lnL */ |
159 |
< |
ls[i] = (BRT2SCALE*j >> 8) - ld->offset; |
159 |
> |
ls[i] = (BRT2SCALE(j) >> 8) - ld->offset; |
160 |
|
if (cs == TM_NOCHROM) /* no color? */ |
161 |
|
continue; |
162 |
|
/* get chrominance */ |
163 |
< |
if (tmTop->flags & TM_F_MESOPIC && ls[i] < BMESUPPER) { |
163 |
> |
if (tms->flags & TM_F_MESOPIC && ls[i] < BMESUPPER) { |
164 |
|
uvp[0] = 1./UVSCALE*((luvs[i]>>8 & 0xff) + .5); |
165 |
|
uvp[1] = 1./UVSCALE*((luvs[i] & 0xff) + .5); |
166 |
|
ls[i] = compmeshift(ls[i], uvp); |
167 |
< |
j = tmTop->flags&TM_F_BW || ls[i]<BMESLOWER |
167 |
> |
j = tms->flags&TM_F_BW || ls[i]<BMESLOWER |
168 |
|
? UVNEU |
169 |
|
: (int)(uvp[0]*UVSCALE)<<8 |
170 |
|
| (int)(uvp[1]*UVSCALE); |
171 |
|
} else { |
172 |
< |
j = tmTop->flags&TM_F_BW ? UVNEU : luvs[i]&0xffff; |
172 |
> |
j = tms->flags&TM_F_BW ? UVNEU : luvs[i]&0xffff; |
173 |
|
} |
174 |
|
if (!isuvset(ld, j)) { |
175 |
< |
uvp[0] = 1./UVSCALE*((luvs[i]>>8 & 0xff) + .5); |
176 |
< |
uvp[1] = 1./UVSCALE*((luvs[i] & 0xff) + .5); |
177 |
< |
uv2rgb(ld->rgbval[j], tmTop, uvp); |
175 |
> |
uvp[0] = 1./UVSCALE*((j>>8) + .5); |
176 |
> |
uvp[1] = 1./UVSCALE*((j & 0xff) + .5); |
177 |
> |
uv2rgb(ld->rgbval[j], tms, uvp); |
178 |
|
setuv(ld, j); |
179 |
|
} |
180 |
|
cs[3*i ] = ld->rgbval[j][RED]; |
186 |
|
|
187 |
|
|
188 |
|
int |
189 |
< |
tmCvLuv24(ls, cs, luvs, len) /* convert raw 24-bit LogLuv values */ |
190 |
< |
TMbright *ls; |
191 |
< |
BYTE *cs; |
192 |
< |
uint32 *luvs; |
193 |
< |
int len; |
189 |
> |
tmCvLuv24( /* convert raw 24-bit LogLuv values */ |
190 |
> |
TMstruct *tms, |
191 |
> |
TMbright *ls, |
192 |
> |
uby8 *cs, |
193 |
> |
uint32 *luvs, |
194 |
> |
int len |
195 |
> |
) |
196 |
|
{ |
197 |
|
char funcName[] = "tmCvLuv24"; |
198 |
|
double uvp[2]; |
199 |
< |
register LUV24DATA *ld; |
200 |
< |
register int i, j; |
199 |
> |
LUV24DATA *ld; |
200 |
> |
int i, j; |
201 |
|
/* check arguments */ |
202 |
< |
if (tmTop == NULL) |
202 |
> |
if (tms == NULL) |
203 |
|
returnErr(TM_E_TMINVAL); |
204 |
< |
if (ls == NULL | luvs == NULL | len < 0) |
204 |
> |
if ((ls == NULL) | (luvs == NULL) | (len < 0)) |
205 |
|
returnErr(TM_E_ILLEGAL); |
206 |
|
/* check package registration */ |
207 |
< |
if (luv24Reg < 0 && (luv24Reg = tmRegPkg(&luv24Pkg)) < 0) |
208 |
< |
returnErr(TM_E_CODERR1); |
207 |
> |
if (luv24Reg < 0) { |
208 |
> |
if ((luv24Reg = tmRegPkg(&luv24Pkg)) < 0) |
209 |
> |
returnErr(TM_E_CODERR1); |
210 |
> |
tmMkMesofact(); |
211 |
> |
} |
212 |
|
/* get package data */ |
213 |
< |
if ((ld = (LUV24DATA *)tmPkgData(tmTop,luv24Reg)) == NULL) |
213 |
> |
if ((ld = (LUV24DATA *)tmPkgData(tms,luv24Reg)) == NULL) |
214 |
|
returnErr(TM_E_NOMEM); |
215 |
|
/* convert each pixel */ |
216 |
|
for (i = len; i--; ) { |
217 |
|
j = luvs[i] >> 14; /* get luminance */ |
218 |
< |
ls[i] = (BRT2SCALE*j >> 6) - ld->offset; |
218 |
> |
ls[i] = (BRT2SCALE(j) >> 6) - ld->offset; |
219 |
|
if (cs == TM_NOCHROM) /* no color? */ |
220 |
|
continue; |
221 |
|
/* get chrominance */ |
222 |
< |
if (tmTop->flags & TM_F_MESOPIC && ls[i] < BMESUPPER) { |
223 |
< |
if (uvpdecode(uvp, luvs[i]&0x3fff) < 0) { |
222 |
> |
if (tms->flags & TM_F_MESOPIC && ls[i] < BMESUPPER) { |
223 |
> |
if (uv_decode(&uvp[0], &uvp[1], luvs[i]&0x3fff) < 0) { |
224 |
|
uvp[0] = U_NEU; /* should barf? */ |
225 |
|
uvp[1] = V_NEU; |
226 |
|
} |
227 |
|
ls[i] = compmeshift(ls[i], uvp); |
228 |
< |
if (tmTop->flags&TM_F_BW || ls[i]<BMESLOWER |
229 |
< |
|| (j = uvpencode(uvp)) < 0) |
228 |
> |
if (tms->flags&TM_F_BW || ls[i]<BMESLOWER |
229 |
> |
|| (j = uv_encode(uvp[0], uvp[1], |
230 |
> |
SGILOGENCODE_NODITHER)) < 0) |
231 |
|
j = uv14neu; |
232 |
|
} else { |
233 |
< |
j = tmTop->flags&TM_F_BW ? uv14neu : luvs[i]&0x3fff; |
233 |
> |
j = tms->flags&TM_F_BW ? uv14neu : |
234 |
> |
(int)(luvs[i]&0x3fff); |
235 |
|
} |
236 |
|
if (!isuvset(ld, j)) { |
237 |
< |
if (uvpdecode(uvp, j) < 0) { |
237 |
> |
if (uv_decode(&uvp[0], &uvp[1], j) < 0) { |
238 |
|
uvp[0] = U_NEU; uvp[1] = V_NEU; |
239 |
|
} |
240 |
< |
uv2rgb(ld->rgbval[j], tmTop, uvp); |
240 |
> |
uv2rgb(ld->rgbval[j], tms, uvp); |
241 |
|
setuv(ld, j); |
242 |
|
} |
243 |
|
cs[3*i ] = ld->rgbval[j][RED]; |
249 |
|
|
250 |
|
|
251 |
|
int |
252 |
< |
tmCvL16(ls, l16s, len) /* convert 16-bit LogL values */ |
253 |
< |
TMbright *ls; |
254 |
< |
uint16 *l16s; |
255 |
< |
int len; |
252 |
> |
tmCvL16( /* convert 16-bit LogL values */ |
253 |
> |
TMstruct *tms, |
254 |
> |
TMbright *ls, |
255 |
> |
uint16 *l16s, |
256 |
> |
int len |
257 |
> |
) |
258 |
|
{ |
259 |
< |
static char funcName[] = "tmCvL16"; |
259 |
> |
static const char funcName[] = "tmCvL16"; |
260 |
|
static double lastsf; |
261 |
|
static int offset; |
262 |
< |
register int i; |
262 |
> |
int i; |
263 |
|
/* check arguments */ |
264 |
< |
if (tmTop == NULL) |
264 |
> |
if (tms == NULL) |
265 |
|
returnErr(TM_E_TMINVAL); |
266 |
< |
if (ls == NULL | l16s == NULL | len < 0) |
266 |
> |
if ((ls == NULL) | (l16s == NULL) | (len < 0)) |
267 |
|
returnErr(TM_E_ILLEGAL); |
268 |
|
/* check scaling offset */ |
269 |
< |
if (!FEQ(tmTop->inpsf, lastsf)) { |
270 |
< |
offset = BRT2SCALE*64; |
271 |
< |
if (tmTop->inpsf > 1.0001) |
297 |
< |
offset -= (int)(TM_BRTSCALE*log(tmTop->inpsf)+.5); |
298 |
< |
else if (tmTop->inpsf < 0.9999) |
299 |
< |
offset -= (int)(TM_BRTSCALE*log(tmTop->inpsf)-.5); |
300 |
< |
lastsf = tmTop->inpsf; |
269 |
> |
if (!FEQ(tms->inpsf, lastsf)) { |
270 |
> |
offset = BRT2SCALE(64) - tmCvLuminance(tms->inpsf); |
271 |
> |
lastsf = tms->inpsf; |
272 |
|
} |
273 |
|
/* convert each pixel */ |
274 |
|
for (i = len; i--; ) { |
275 |
|
if (l16s[i] & 0x8000) /* negative luminance */ |
276 |
< |
ls[i] = MINBRT-1; /* assign bogus value */ |
276 |
> |
ls[i] = TM_NOBRT; /* assign bogus value */ |
277 |
|
else /* else convert to lnL */ |
278 |
< |
ls[i] = (BRT2SCALE*l16s[i] >> 8) - offset; |
278 |
> |
ls[i] = (BRT2SCALE(l16s[i]) >> 8) - offset; |
279 |
|
} |
280 |
|
returnOK; |
281 |
|
} |
282 |
|
|
283 |
|
|
284 |
|
static void |
285 |
< |
luv32NewSpace(tm) /* initialize 32-bit LogLuv color space */ |
286 |
< |
struct tmStruct *tm; |
285 |
> |
luv32NewSpace(tms) /* initialize 32-bit LogLuv color space */ |
286 |
> |
TMstruct *tms; |
287 |
|
{ |
288 |
< |
register LUV32DATA *ld; |
288 |
> |
LUV32DATA *ld; |
289 |
|
|
290 |
< |
if (tm->inppri != TM_XYZPRIM) { /* panic time! */ |
290 |
> |
if (tms->inppri != TM_XYZPRIM) { /* panic time! */ |
291 |
|
fputs("Improper input color space in luv32NewSpace!\n", stderr); |
292 |
|
exit(1); |
293 |
|
} |
294 |
< |
ld = (LUV32DATA *)tm->pd[luv32Reg]; |
295 |
< |
ld->offset = BRT2SCALE*64; |
325 |
< |
if (tm->inpsf > 1.0001) |
326 |
< |
ld->offset -= (int)(TM_BRTSCALE*log(tmTop->inpsf)+.5); |
327 |
< |
else if (tm->inpsf < 0.9999) |
328 |
< |
ld->offset -= (int)(TM_BRTSCALE*log(tmTop->inpsf)-.5); |
294 |
> |
ld = (LUV32DATA *)tms->pd[luv32Reg]; |
295 |
> |
ld->offset = BRT2SCALE(64) - tmCvLuminance(tms->inpsf); |
296 |
|
clruvall(ld); |
297 |
|
} |
298 |
|
|
299 |
|
|
300 |
< |
static MEM_PTR |
301 |
< |
luv32Init(tm) /* allocate data for 32-bit LogLuv decoder */ |
302 |
< |
struct tmStruct *tm; |
300 |
> |
static void * |
301 |
> |
luv32Init(tms) /* allocate data for 32-bit LogLuv decoder */ |
302 |
> |
TMstruct *tms; |
303 |
|
{ |
304 |
< |
register LUV32DATA *ld; |
304 |
> |
LUV32DATA *ld; |
305 |
|
|
306 |
|
ld = (LUV32DATA *)malloc(sizeof(LUV32DATA)); |
307 |
|
if (ld == NULL) |
308 |
|
return(NULL); |
309 |
< |
tm->pd[luv32Reg] = (MEM_PTR)ld; |
310 |
< |
luv32NewSpace(tm); |
311 |
< |
return((MEM_PTR)ld); |
309 |
> |
tms->pd[luv32Reg] = (void *)ld; |
310 |
> |
luv32NewSpace(tms); |
311 |
> |
return((void *)ld); |
312 |
|
} |
313 |
|
|
314 |
|
|
315 |
|
static void |
316 |
< |
luv24NewSpace(tm) /* initialize 24-bit LogLuv color space */ |
317 |
< |
struct tmStruct *tm; |
316 |
> |
luv24NewSpace(tms) /* initialize 24-bit LogLuv color space */ |
317 |
> |
TMstruct *tms; |
318 |
|
{ |
319 |
< |
register LUV24DATA *ld; |
353 |
< |
double uvp[2]; |
319 |
> |
LUV24DATA *ld; |
320 |
|
|
321 |
< |
if (tm->inppri != TM_XYZPRIM) { /* panic time! */ |
321 |
> |
if (tms->inppri != TM_XYZPRIM) { /* panic time! */ |
322 |
|
fputs("Improper input color space in luv24NewSpace!\n", stderr); |
323 |
|
exit(1); |
324 |
|
} |
325 |
< |
ld = (LUV24DATA *)tm->pd[luv24Reg]; |
326 |
< |
ld->offset = BRT2SCALE*12; |
361 |
< |
if (tm->inpsf > 1.0001) |
362 |
< |
ld->offset -= (int)(TM_BRTSCALE*log(tmTop->inpsf)+.5); |
363 |
< |
else if (tm->inpsf < 0.9999) |
364 |
< |
ld->offset -= (int)(TM_BRTSCALE*log(tmTop->inpsf)-.5); |
325 |
> |
ld = (LUV24DATA *)tms->pd[luv24Reg]; |
326 |
> |
ld->offset = BRT2SCALE(12) - tmCvLuminance(tms->inpsf); |
327 |
|
clruvall(ld); |
328 |
|
} |
329 |
|
|
330 |
|
|
331 |
< |
static MEM_PTR |
332 |
< |
luv24Init(tm) /* allocate data for 24-bit LogLuv decoder */ |
333 |
< |
struct tmStruct *tm; |
331 |
> |
static void * |
332 |
> |
luv24Init(tms) /* allocate data for 24-bit LogLuv decoder */ |
333 |
> |
TMstruct *tms; |
334 |
|
{ |
335 |
< |
register LUV24DATA *ld; |
335 |
> |
LUV24DATA *ld; |
336 |
|
|
337 |
|
ld = (LUV24DATA *)malloc(sizeof(LUV24DATA)); |
338 |
|
if (ld == NULL) |
339 |
|
return(NULL); |
340 |
< |
tm->pd[luv24Reg] = (MEM_PTR)ld; |
341 |
< |
if (uv14neu < 0) { /* initialize neutral color index */ |
342 |
< |
double uvp[2]; |
343 |
< |
uvp[0] = U_NEU; uvp[1] = V_NEU; |
344 |
< |
uv14neu = uvpencode(uvp); |
383 |
< |
} |
384 |
< |
luv24NewSpace(tm); |
385 |
< |
return((MEM_PTR)ld); |
340 |
> |
tms->pd[luv24Reg] = (void *)ld; |
341 |
> |
if (uv14neu < 0) /* initialize neutral color index */ |
342 |
> |
uv14neu = uv_encode(U_NEU, V_NEU, SGILOGENCODE_NODITHER); |
343 |
> |
luv24NewSpace(tms); |
344 |
> |
return((void *)ld); |
345 |
|
} |