59 |
|
|
60 |
|
/* Fill our monitor gamma table */ |
61 |
|
static void |
62 |
< |
mkMonGamTable() |
62 |
> |
mkMonGamTable(TMstruct *tms) |
63 |
|
{ |
64 |
|
int i; |
65 |
|
|
66 |
< |
if (tmTop->mongam == cur_mongam) |
66 |
> |
if (tms->mongam == cur_mongam) |
67 |
|
return; |
68 |
|
for (i = MONGAMTSZ; i--; ) |
69 |
< |
mongamtab[i] = 256.*pow((i+.5)*(1./MONGAMTSZ), 1./tmTop->mongam); |
70 |
< |
cur_mongam = tmTop->mongam; |
69 |
> |
mongamtab[i] = 256.*pow((i+.5)*(1./MONGAMTSZ), 1./tms->mongam); |
70 |
> |
cur_mongam = tms->mongam; |
71 |
|
} |
72 |
|
|
73 |
|
|
131 |
|
|
132 |
|
/* Convert 16-bit gray scanline to encoded luminance */ |
133 |
|
int |
134 |
< |
tmCvGray16(TMbright *ls, uint16 *scan, int len, double gv) |
134 |
> |
tmCvGray16(TMstruct *tms, TMbright *ls, uint16 *scan, int len, double gv) |
135 |
|
{ |
136 |
< |
static char funcName[] = "tmCvGray16"; |
136 |
> |
static const char funcName[] = "tmCvGray16"; |
137 |
|
static double cur_inpsf = 1.; |
138 |
|
static double log_inpsf = 0.; |
139 |
|
int nshft; |
140 |
|
double d; |
141 |
|
|
142 |
< |
if (tmTop == NULL) |
142 |
> |
if (tms == NULL) |
143 |
|
returnErr(TM_E_TMINVAL); |
144 |
< |
if (ls == NULL | scan == NULL | len < 0) |
144 |
> |
if ((ls == NULL) | (scan == NULL) | (len < 0)) |
145 |
|
returnErr(TM_E_ILLEGAL); |
146 |
|
if (gv <= 0.) |
147 |
|
gv = DEFGAM; |
148 |
|
/* initialize log table */ |
149 |
|
if (logtab[0] == 0.f) |
150 |
|
mkLogTable(); |
151 |
< |
if (cur_inpsf != tmTop->inpsf) |
152 |
< |
log_inpsf = log(cur_inpsf = tmTop->inpsf); |
151 |
> |
if (cur_inpsf != tms->inpsf) |
152 |
> |
log_inpsf = log(cur_inpsf = tms->inpsf); |
153 |
|
/* convert 16-bit grays */ |
154 |
|
while (len--) { |
155 |
|
nshft = normShift16(*scan); |
170 |
|
|
171 |
|
/* Convert a 48-bit RGB scanline to encoded luminance/chrominance */ |
172 |
|
int |
173 |
< |
tmCvRGB48(TMbright *ls, BYTE *cs, uint16 (*scan)[3], int len, double gv) |
173 |
> |
tmCvRGB48(TMstruct *tms, TMbright *ls, BYTE *cs, |
174 |
> |
uint16 (*scan)[3], int len, double gv) |
175 |
|
{ |
176 |
< |
static char funcName[] = "tmCvRGB48"; |
176 |
> |
static const char funcName[] = "tmCvRGB48"; |
177 |
|
static double cur_inpsf = 1.; |
178 |
|
static double log_inpsf = 0.; |
179 |
|
int i; |
180 |
|
|
181 |
< |
if (tmTop == NULL) |
181 |
> |
if (tms == NULL) |
182 |
|
returnErr(TM_E_TMINVAL); |
183 |
< |
if (ls == NULL | scan == NULL | len < 0) |
183 |
> |
if ((ls == NULL) | (scan == NULL) | (len < 0)) |
184 |
|
returnErr(TM_E_ILLEGAL); |
185 |
|
if (gv <= 0.) |
186 |
|
gv = DEFGAM; |
187 |
|
/* sync input gamma table */ |
188 |
< |
if (gv != 1. & gv != cur_gam) |
188 |
> |
if ((gv != 1.) & (gv != cur_gam)) |
189 |
|
mkGamTable(gv); |
190 |
< |
if (tmNeedMatrix(tmTop)) { /* need floating point */ |
190 |
> |
if (tmNeedMatrix(tms)) { /* need floating point */ |
191 |
|
COLOR *newscan; |
192 |
|
newscan = (COLOR *)tempbuffer(len*sizeof(COLOR)); |
193 |
|
if (newscan == NULL) |
194 |
|
returnErr(TM_E_NOMEM); |
195 |
|
for (i = len; i--; ) |
196 |
|
rgb48_color(newscan[i], scan[i], gv); |
197 |
< |
return(tmCvColors(ls, cs, newscan, len)); |
197 |
> |
return(tmCvColors(tms, ls, cs, newscan, len)); |
198 |
|
} |
199 |
|
/* sync monitor gamma table */ |
200 |
< |
if (cs != TM_NOCHROM && tmTop->mongam != cur_mongam) |
201 |
< |
mkMonGamTable(); |
200 |
> |
if (cs != TM_NOCHROM && tms->mongam != cur_mongam) |
201 |
> |
mkMonGamTable(tms); |
202 |
|
/* initialize log table */ |
203 |
|
if (logtab[0] == 0.f) |
204 |
|
mkLogTable(); |
205 |
< |
if (cur_inpsf != tmTop->inpsf) |
206 |
< |
log_inpsf = log(cur_inpsf = tmTop->inpsf); |
207 |
< |
if (tmTop->flags & TM_F_MESOPIC) |
205 |
> |
if (cur_inpsf != tms->inpsf) |
206 |
> |
log_inpsf = log(cur_inpsf = tms->inpsf); |
207 |
> |
if (tms->flags & TM_F_MESOPIC) |
208 |
|
tmMkMesofact(); |
209 |
|
/* convert scanline */ |
210 |
|
for (i = len; i--; ) { |
224 |
|
setcolor(cmon, gamtab[imultpow2(scan[i][0],j)], |
225 |
|
gamtab[imultpow2(scan[i][1],j)], |
226 |
|
gamtab[imultpow2(scan[i][2],j)] ); |
227 |
< |
lum = tmTop->clf[RED]*cmon[RED]; |
228 |
< |
lum += tmTop->clf[GRN]*cmon[GRN]; |
229 |
< |
lum += tmTop->clf[BLU]*cmon[BLU]; |
227 |
> |
lum = tms->clf[RED]*cmon[RED]; |
228 |
> |
lum += tms->clf[GRN]*cmon[GRN]; |
229 |
> |
lum += tms->clf[BLU]*cmon[BLU]; |
230 |
|
/* convert to log Y */ |
231 |
|
j = lum * (double)(1L<<16); |
232 |
|
nshft2 = normShift16(j); |
241 |
|
if (cs == TM_NOCHROM) /* no color? */ |
242 |
|
continue; |
243 |
|
/* mesopic adj. */ |
244 |
< |
if (tmTop->flags & TM_F_MESOPIC && bi < BMESUPPER) { |
244 |
> |
if (tms->flags & TM_F_MESOPIC && bi < BMESUPPER) { |
245 |
|
double slum = scotlum(cmon); |
246 |
|
if (bi < BMESLOWER) |
247 |
|
setcolor(cmon, slum, slum, slum); |
248 |
|
else { |
249 |
|
double pf; |
250 |
|
pf = (1./256.)*tmMesofact[bi-BMESLOWER]; |
251 |
< |
if (tmTop->flags & TM_F_BW) |
251 |
> |
if (tms->flags & TM_F_BW) |
252 |
|
cmon[RED] = cmon[GRN] = cmon[BLU] = lum; |
253 |
|
slum *= 1. - pf; |
254 |
|
cmon[RED] = slum + pf*cmon[RED]; |
255 |
|
cmon[GRN] = slum + pf*cmon[GRN]; |
256 |
|
cmon[BLU] = slum + pf*cmon[BLU]; |
257 |
|
} |
258 |
< |
} else if (tmTop->flags & TM_F_BW) { |
258 |
> |
} else if (tms->flags & TM_F_BW) { |
259 |
|
cmon[RED] = cmon[GRN] = cmon[BLU] = lum; |
260 |
|
} |
261 |
< |
bi = (double)MONGAMTSZ*tmTop->clf[RED]*cmon[RED]/lum; |
261 |
> |
bi = (double)MONGAMTSZ*tms->clf[RED]*cmon[RED]/lum; |
262 |
|
cs[3*i ] = bi>=MONGAMTSZ ? 255 : mongamtab[bi]; |
263 |
< |
bi = (double)MONGAMTSZ*tmTop->clf[GRN]*cmon[GRN]/lum; |
263 |
> |
bi = (double)MONGAMTSZ*tms->clf[GRN]*cmon[GRN]/lum; |
264 |
|
cs[3*i+1] = bi>=MONGAMTSZ ? 255 : mongamtab[bi]; |
265 |
< |
bi = (double)MONGAMTSZ*tmTop->clf[BLU]*cmon[BLU]/lum; |
265 |
> |
bi = (double)MONGAMTSZ*tms->clf[BLU]*cmon[BLU]/lum; |
266 |
|
cs[3*i+2] = bi>=MONGAMTSZ ? 255 : mongamtab[bi]; |
267 |
|
} |
268 |
|
returnOK; |