10 |
|
#include "copyright.h" |
11 |
|
|
12 |
|
#include <stdio.h> |
13 |
+ |
#include <stdlib.h> |
14 |
|
#include <string.h> |
15 |
|
#include <math.h> |
16 |
|
#include <time.h> |
17 |
|
|
18 |
+ |
#ifdef PCOND |
19 |
+ |
#include "rtprocess.h" |
20 |
+ |
#endif |
21 |
|
#include "tmprivat.h" |
22 |
|
#include "resolu.h" |
19 |
– |
#include "rtprocess.h" |
23 |
|
|
21 |
– |
#ifndef TM_PIC_CTRANS |
22 |
– |
#define TM_PIC_CTRANS 1 /* transform colors? (expensive) */ |
23 |
– |
#endif |
24 |
– |
|
24 |
|
#define GAMTSZ 1024 |
25 |
|
|
26 |
|
typedef struct { |
27 |
|
BYTE gamb[GAMTSZ]; /* gamma lookup table */ |
28 |
< |
COLR clfb; /* encoded tm->clf */ |
28 |
> |
int clfb[3]; /* encoded tm->clf */ |
29 |
> |
int32 cmatb[3][3]; /* encoded color transform */ |
30 |
|
TMbright inpsfb; /* encoded tm->inpsf */ |
31 |
|
} COLRDATA; |
32 |
|
|
53 |
|
) |
54 |
|
{ |
55 |
|
static const char funcName[] = "tmCvColrs"; |
56 |
< |
COLR cmon; |
56 |
> |
int cmon[4]; |
57 |
|
register COLRDATA *cd; |
58 |
< |
register int i, bi, li; |
58 |
> |
register int i, j, li, bi; |
59 |
> |
int32 vl; |
60 |
|
|
61 |
|
if (tms == NULL) |
62 |
|
returnErr(TM_E_TMINVAL); |
63 |
|
if ((ls == NULL) | (scan == NULL) | (len < 0)) |
64 |
|
returnErr(TM_E_ILLEGAL); |
64 |
– |
#if TM_PIC_CTRANS |
65 |
– |
if (tmNeedMatrix(tms)) { /* need floating point */ |
66 |
– |
#else |
67 |
– |
if (tms->inppri == TM_XYZPRIM) { /* no way around this */ |
68 |
– |
#endif |
69 |
– |
register COLOR *newscan; |
70 |
– |
newscan = (COLOR *)tempbuffer(len*sizeof(COLOR)); |
71 |
– |
if (newscan == NULL) |
72 |
– |
returnErr(TM_E_NOMEM); |
73 |
– |
for (i = len; i--; ) |
74 |
– |
colr_color(newscan[i], scan[i]); |
75 |
– |
return(tmCvColors(tms, ls, cs, newscan, len)); |
76 |
– |
} |
65 |
|
if (colrReg < 0) { /* build tables if necessary */ |
66 |
|
colrReg = tmRegPkg(&colrPkg); |
67 |
|
if (colrReg < 0) |
75 |
|
if ((cd = (COLRDATA *)tmPkgData(tms,colrReg)) == NULL) |
76 |
|
returnErr(TM_E_NOMEM); |
77 |
|
for (i = len; i--; ) { |
78 |
< |
copycolr(cmon, scan[i]); |
78 |
> |
if (tmNeedMatrix(tms)) { /* apply color xform */ |
79 |
> |
for (j = 3; j--; ) { |
80 |
> |
vl = cd->cmatb[j][RED]*(int32)scan[i][RED] + |
81 |
> |
cd->cmatb[j][GRN]*(int32)scan[i][GRN] + |
82 |
> |
cd->cmatb[j][BLU]*(int32)scan[i][BLU] ; |
83 |
> |
if (vl < 0) cmon[j] = vl/0x10000; |
84 |
> |
else cmon[j] = vl>>16; |
85 |
> |
} |
86 |
> |
cmon[EXP] = scan[i][EXP]; |
87 |
> |
} else |
88 |
> |
copycolr(cmon, scan[i]); |
89 |
|
/* world luminance */ |
90 |
< |
li = ( cd->clfb[RED]*cmon[RED] + |
90 |
> |
li = cd->clfb[RED]*cmon[RED] + |
91 |
|
cd->clfb[GRN]*cmon[GRN] + |
92 |
< |
cd->clfb[BLU]*cmon[BLU] ) >> 8; |
93 |
< |
bi = BRT2SCALE(cmon[EXP]-COLXS) + |
94 |
< |
logi[li] + cd->inpsfb; |
95 |
< |
if (li <= 0) { |
96 |
< |
bi = TM_NOBRT; /* bogus value */ |
97 |
< |
li = 1; /* avoid li==0 */ |
92 |
> |
cd->clfb[BLU]*cmon[BLU] ; |
93 |
> |
if (li >= 0xfff00) li = 255; |
94 |
> |
else li >>= 12; |
95 |
> |
bi = BRT2SCALE(cmon[EXP]-COLXS) + cd->inpsfb; |
96 |
> |
if (li > 0) |
97 |
> |
bi += logi[li]; |
98 |
> |
else { |
99 |
> |
bi += logi[0]; |
100 |
> |
li = 1; /* avoid /0 */ |
101 |
|
} |
102 |
|
ls[i] = bi; |
103 |
|
if (cs == TM_NOCHROM) /* no color? */ |
104 |
|
continue; |
105 |
|
/* mesopic adj. */ |
106 |
|
if (tms->flags & TM_F_MESOPIC && bi < BMESUPPER) { |
107 |
< |
register int pf, sli = normscot(cmon); |
108 |
< |
if (bi < BMESLOWER) |
107 |
> |
int pf, sli = normscot(cmon); |
108 |
> |
if (bi < BMESLOWER) { |
109 |
|
cmon[RED] = cmon[GRN] = cmon[BLU] = sli; |
110 |
< |
else { |
110 |
> |
} else { |
111 |
|
if (tms->flags & TM_F_BW) |
112 |
|
cmon[RED] = cmon[GRN] = cmon[BLU] = li; |
113 |
|
pf = tmMesofact[bi-BMESLOWER]; |
114 |
|
sli *= 256 - pf; |
115 |
< |
cmon[RED] = ( sli + pf*cmon[RED] ) >> 8; |
116 |
< |
cmon[GRN] = ( sli + pf*cmon[GRN] ) >> 8; |
117 |
< |
cmon[BLU] = ( sli + pf*cmon[BLU] ) >> 8; |
115 |
> |
for (j = 3; j--; ) { |
116 |
> |
cmon[j] = sli + pf*cmon[j]; |
117 |
> |
if (cmon[j] <= 0) cmon[j] = 0; |
118 |
> |
else cmon[j] >>= 8; |
119 |
> |
} |
120 |
|
} |
121 |
|
} else if (tms->flags & TM_F_BW) { |
122 |
|
cmon[RED] = cmon[GRN] = cmon[BLU] = li; |
123 |
+ |
} else { |
124 |
+ |
for (j = 3; j--; ) |
125 |
+ |
if (cmon[j] < 0) cmon[j] = 0; |
126 |
|
} |
127 |
< |
bi = ( (int32)GAMTSZ*cd->clfb[RED]*cmon[RED]/li ) >> 8; |
127 |
> |
bi = ( (int32)GAMTSZ*cd->clfb[RED]*cmon[RED]/li ) >> 12; |
128 |
|
cs[3*i ] = bi>=GAMTSZ ? 255 : cd->gamb[bi]; |
129 |
< |
bi = ( (int32)GAMTSZ*cd->clfb[GRN]*cmon[GRN]/li ) >> 8; |
129 |
> |
bi = ( (int32)GAMTSZ*cd->clfb[GRN]*cmon[GRN]/li ) >> 12; |
130 |
|
cs[3*i+1] = bi>=GAMTSZ ? 255 : cd->gamb[bi]; |
131 |
< |
bi = ( (int32)GAMTSZ*cd->clfb[BLU]*cmon[BLU]/li ) >> 8; |
131 |
> |
bi = ( (int32)GAMTSZ*cd->clfb[BLU]*cmon[BLU]/li ) >> 12; |
132 |
|
cs[3*i+2] = bi>=GAMTSZ ? 255 : cd->gamb[bi]; |
133 |
|
} |
134 |
|
returnOK; |
203 |
|
((fname == NULL) & (fp == TM_GETFILE))) |
204 |
|
returnErr(TM_E_ILLEGAL); |
205 |
|
*xp = *yp = 0; /* error precaution */ |
206 |
< |
if ((inpf = fp) == TM_GETFILE && (inpf = fopen(fname, "r")) == NULL) |
206 |
> |
if ((inpf = fp) == TM_GETFILE && (inpf = fopen(fname, "rb")) == NULL) |
207 |
|
returnErr(TM_E_BADFILE); |
208 |
|
*lpp = NULL; |
209 |
|
if (cpp != TM_NOCHROMP) *cpp = NULL; |
220 |
|
else if (info.format == FMTCIE) |
221 |
|
info.primp = TM_XYZPRIM; |
222 |
|
/* prepare library */ |
223 |
< |
if ((err = tmSetSpace(tms, info.primp, 1./info.expos)) != TM_E_OK) |
223 |
> |
if ((err = tmSetSpace(tms, info.primp, 1./info.expos, NULL)) != TM_E_OK) |
224 |
|
goto done; |
225 |
|
err = TM_E_NOMEM; /* allocate arrays */ |
226 |
|
*lpp = (TMbright *)malloc(sizeof(TMbright) * *xp * *yp); |
428 |
|
{ |
429 |
|
register COLRDATA *cd; |
430 |
|
double d; |
431 |
+ |
int i, j; |
432 |
|
|
433 |
|
cd = (COLRDATA *)tms->pd[colrReg]; |
434 |
< |
cd->clfb[RED] = 256.*tms->clf[RED] + .5; |
435 |
< |
cd->clfb[GRN] = 256.*tms->clf[GRN] + .5; |
436 |
< |
cd->clfb[BLU] = 256.*tms->clf[BLU] + .5; |
437 |
< |
cd->clfb[EXP] = COLXS; |
438 |
< |
d = TM_BRTSCALE*log(tms->inpsf); |
439 |
< |
cd->inpsfb = d<0. ? d-.5 : d+.5; |
434 |
> |
for (i = 3; i--; ) |
435 |
> |
cd->clfb[i] = 0x1000*tms->clf[i] + .5; |
436 |
> |
cd->inpsfb = tmCvLuminance(tms->inpsf); |
437 |
> |
for (i = 3; i--; ) |
438 |
> |
for (j = 3; j--; ) { |
439 |
> |
d = tms->cmat[i][j] / tms->inpsf; |
440 |
> |
cd->cmatb[i][j] = 0x10000*d + (d<0. ? -.5 : .5); |
441 |
> |
} |
442 |
|
} |
443 |
|
|
444 |
|
|