ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/tmapluv.c
(Generate patch)

Comparing ray/src/common/tmapluv.c (file contents):
Revision 3.6 by schorsch, Mon Jun 30 14:59:11 2003 UTC vs.
Revision 3.16 by greg, Fri May 20 02:06:38 2011 UTC

# Line 12 | Line 12 | static const char      RCSid[] = "$Id$";
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"
# Line 30 | Line 31 | static void    luv32NewSpace();
31   static MEM_PTR  luv24Init();
32   static void     luv24NewSpace();
33   #else
34 < static MEM_PTR  luv32Init(struct tmStruct *);
35 < static void     luv32NewSpace(struct tmStruct *);
36 < static MEM_PTR  luv24Init(struct tmStruct *);
37 < static void     luv24NewSpace(struct tmStruct *);
34 > static MEM_PTR  luv32Init(TMstruct *);
35 > static void     luv32NewSpace(TMstruct *);
36 > static MEM_PTR  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  
# Line 52 | Line 53 | static int     luv32Reg = -1;          /* 32-bit package reg. numb
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  
# Line 65 | Line 66 | static int     uv14neu = -1;           /* neutral index for 14-bit
66  
67  
68   static void
69 < uv2rgb(rgb, tm, uvp)                    /* compute RGB from uv coordinate */
70 < BYTE    rgb[3];
71 < register struct tmStruct        *tm;
69 > uv2rgb(rgb, tms, uvp)                   /* compute RGB from uv coordinate */
70 > uby8    rgb[3];
71 > register 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);
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  
# Line 123 | Line 124 | double uvp[2];                 /* world (u',v') -> returned desatura
124  
125  
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;
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) {
# Line 145 | Line 148 | int    len;
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--; ) {
# Line 157 | Line 160 | int    len;
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*((j>>8) + .5);
176                          uvp[1] = 1./UVSCALE*((j & 0xff) + .5);
177 <                        uv2rgb(ld->rgbval[j], tmTop, uvp);
177 >                        uv2rgb(ld->rgbval[j], tms, uvp);
178                          setuv(ld, j);
179                  }
180                  cs[3*i  ] = ld->rgbval[j][RED];
# Line 183 | Line 186 | int    len;
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;
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) {
# Line 205 | Line 210 | int    len;
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--; ) {
# Line 214 | Line 219 | int    len;
219                  if (cs == TM_NOCHROM)           /* no color? */
220                          continue;
221                                                  /* get chrominance */
222 <                if (tmTop->flags & TM_F_MESOPIC && ls[i] < BMESUPPER) {
223 <                        if (uv_decode(uvp, uvp+1, 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
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 (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];
# Line 243 | Line 249 | int    len;
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;
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)
264 <                        offset -= (int)(TM_BRTSCALE*log(tmTop->inpsf)+.5);
265 <                else if (tmTop->inpsf < 0.9999)
266 <                        offset -= (int)(TM_BRTSCALE*log(tmTop->inpsf)-.5);
267 <                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--; ) {
# Line 278 | Line 282 | int    len;
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;
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);
292 <        if (tm->inpsf > 1.0001)
293 <                ld->offset -= (int)(TM_BRTSCALE*log(tmTop->inpsf)+.5);
294 <        else if (tm->inpsf < 0.9999)
295 <                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;
301 > luv32Init(tms)                  /* allocate data for 32-bit LogLuv decoder */
302 > TMstruct        *tms;
303   {
304          register 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);
309 >        tms->pd[luv32Reg] = (MEM_PTR)ld;
310 >        luv32NewSpace(tms);
311          return((MEM_PTR)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;
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);
327 <        if (tm->inpsf > 1.0001)
328 <                ld->offset -= (int)(TM_BRTSCALE*log(tmTop->inpsf)+.5);
329 <        else if (tm->inpsf < 0.9999)
330 <                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;
332 > luv24Init(tms)                  /* allocate data for 24-bit LogLuv decoder */
333 > TMstruct        *tms;
334   {
335          register LUV24DATA      *ld;
336  
337          ld = (LUV24DATA *)malloc(sizeof(LUV24DATA));
338          if (ld == NULL)
339                  return(NULL);
340 <        tm->pd[luv24Reg] = (MEM_PTR)ld;
340 >        tms->pd[luv24Reg] = (MEM_PTR)ld;
341          if (uv14neu < 0)                /* initialize neutral color index */
342                  uv14neu = uv_encode(U_NEU, V_NEU, SGILOGENCODE_NODITHER);
343 <        luv24NewSpace(tm);
343 >        luv24NewSpace(tms);
344          return((MEM_PTR)ld);
345   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines