Back to index

radiance  4R0+20100331
Classes | Defines | Functions | Variables
tmapluv.c File Reference
#include "copyright.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "tmprivat.h"
#include "tiffio.h"
#include "tmaptiff.h"

Go to the source code of this file.

Classes

struct  LUV32DATA
struct  LUV24DATA

Defines

#define LOGLUV_PUBLIC   1
#define uvflgop(p, uv, op)   ((p)->rgbflg[(uv)>>5] op (1L<<((uv)&0x1f)))
#define isuvset(p, uv)   uvflgop(p,uv,&)
#define setuv(p, uv)   uvflgop(p,uv,|=)
#define clruv(p, uv)   uvflgop(p,uv,&=~)
#define clruvall(p)   memset((MEM_PTR)(p)->rgbflg,'\0',sizeof((p)->rgbflg))
#define UVNEU

Functions

static MEM_PTR luv32Init (TMstruct *)
static void luv32NewSpace (TMstruct *)
static MEM_PTR luv24Init (TMstruct *)
static void luv24NewSpace (TMstruct *)
static void uv2rgb (rgb, TMstruct *tms, uvp)
static TMbright compmeshift (TMbright li, uvp)
int tmCvLuv32 (TMstruct *tms, TMbright *ls, BYTE *cs, uint32 *luvs, int len)
int tmCvLuv24 (TMstruct *tms, TMbright *ls, BYTE *cs, uint32 *luvs, int len)
int tmCvL16 (TMstruct *tms, TMbright *ls, uint16 *l16s, int len)

Variables

static const char RCSid [] = "$Id: tmapluv.c,v 3.14 2009/02/09 20:48:08 greg Exp $"
static struct tmPackage
static int luv32Reg = -1
static int luv24Reg = -1
static int uv14neu = -1

Class Documentation

struct LUV32DATA

Definition at line 40 of file tmapluv.c.

Class Members
int offset
uint32 rgbflg
BYTE rgbval
struct LUV24DATA

Definition at line 54 of file tmapluv.c.

Class Members
int offset
uint32 rgbflg
BYTE rgbval

Define Documentation

#define clruv (   p,
  uv 
)    uvflgop(p,uv,&=~)

Definition at line 25 of file tmapluv.c.

#define clruvall (   p)    memset((MEM_PTR)(p)->rgbflg,'\0',sizeof((p)->rgbflg))

Definition at line 26 of file tmapluv.c.

#define isuvset (   p,
  uv 
)    uvflgop(p,uv,&)

Definition at line 23 of file tmapluv.c.

#define LOGLUV_PUBLIC   1

Definition at line 12 of file tmapluv.c.

#define setuv (   p,
  uv 
)    uvflgop(p,uv,|=)

Definition at line 24 of file tmapluv.c.

#define uvflgop (   p,
  uv,
  op 
)    ((p)->rgbflg[(uv)>>5] op (1L<<((uv)&0x1f)))

Definition at line 22 of file tmapluv.c.

#define UVNEU
Value:
((int)(UVSCALE*U_NEU)<<8 \
                                   | (int)(UVSCALE*V_NEU))

Definition at line 46 of file tmapluv.c.


Function Documentation

static TMbright compmeshift ( TMbright  li,
uvp   
) [static]

Definition at line 97 of file tmapluv.c.

{
       double scotrat;
       register double      d;

       if (li >= BMESUPPER)
              return(li);
       scotrat = (.767676768 - 1.02356902*uvp[1])/uvp[0] - .343434343;
       if (li <= BMESLOWER) {
              d = 0.;
              uvp[0] = U_NEU; uvp[1] = V_NEU;
       } else {
              d = (tmMesofact[li-BMESLOWER] + .5) * (1./256.);
              uvp[0] = d*uvp[0] + (1.-d)*U_NEU;
              uvp[1] = d*uvp[1] + (1.-d)*V_NEU;
       }
       /*
       d = li + (double)TM_BRTSCALE*log(d + (1.-d)*scotrat);
       */
       d = d + (1.-d)*scotrat;
       d -= 1.;                    /* Taylor expansion of log(x) about 1 */
       d = d*(1. + d*(-.5 + d*(1./3. + d*-.125)));
       d = li + (double)TM_BRTSCALE*d;
       return((TMbright)(d>0. ? d+.5 : d-.5));
}

Here is the caller graph for this function:

static MEM_PTR luv24Init ( TMstruct tms) [static]

Definition at line 332 of file tmapluv.c.

{
       register LUV24DATA   *ld;

       ld = (LUV24DATA *)malloc(sizeof(LUV24DATA));
       if (ld == NULL)
              return(NULL);
       tms->pd[luv24Reg] = (MEM_PTR)ld;
       if (uv14neu < 0)            /* initialize neutral color index */
              uv14neu = uv_encode(U_NEU, V_NEU, SGILOGENCODE_NODITHER);
       luv24NewSpace(tms);
       return((MEM_PTR)ld);
}

Here is the call graph for this function:

static void luv24NewSpace ( TMstruct tms) [static]

Definition at line 316 of file tmapluv.c.

{
       register LUV24DATA   *ld;

       if (tms->inppri != TM_XYZPRIM) {          /* panic time! */
              fputs("Improper input color space in luv24NewSpace!\n", stderr);
              exit(1);
       }
       ld = (LUV24DATA *)tms->pd[luv24Reg];
       ld->offset = BRT2SCALE(12) - tmCvLuminance(tms->inpsf);
       clruvall(ld);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static MEM_PTR luv32Init ( TMstruct tms) [static]

Definition at line 301 of file tmapluv.c.

{
       register LUV32DATA   *ld;

       ld = (LUV32DATA *)malloc(sizeof(LUV32DATA));
       if (ld == NULL)
              return(NULL);
       tms->pd[luv32Reg] = (MEM_PTR)ld;
       luv32NewSpace(tms);
       return((MEM_PTR)ld);
}

Here is the call graph for this function:

static void luv32NewSpace ( TMstruct tms) [static]

Definition at line 285 of file tmapluv.c.

{
       register LUV32DATA   *ld;

       if (tms->inppri != TM_XYZPRIM) {          /* panic time! */
              fputs("Improper input color space in luv32NewSpace!\n", stderr);
              exit(1);
       }
       ld = (LUV32DATA *)tms->pd[luv32Reg];
       ld->offset = BRT2SCALE(64) - tmCvLuminance(tms->inpsf);
       clruvall(ld);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int tmCvL16 ( TMstruct tms,
TMbright ls,
uint16 *  l16s,
int  len 
)

Definition at line 252 of file tmapluv.c.

{
       static const char    funcName[] = "tmCvL16";
       static double lastsf;
       static int    offset;
       register int  i;
                                   /* check arguments */
       if (tms == NULL)
              returnErr(TM_E_TMINVAL);
       if ((ls == NULL) | (l16s == NULL) | (len < 0))
              returnErr(TM_E_ILLEGAL);
                                   /* check scaling offset */
       if (!FEQ(tms->inpsf, lastsf)) {
              offset = BRT2SCALE(64) - tmCvLuminance(tms->inpsf);
              lastsf = tms->inpsf;
       }
                                   /* convert each pixel */
       for (i = len; i--; ) {
              if (l16s[i] & 0x8000)              /* negative luminance */
                     ls[i] = TM_NOBRT;    /* assign bogus value */
              else                        /* else convert to lnL */
                     ls[i] = (BRT2SCALE(l16s[i]) >> 8) - offset;
       }
       returnOK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int tmCvLuv24 ( TMstruct tms,
TMbright ls,
BYTE cs,
uint32 *  luvs,
int  len 
)

Definition at line 189 of file tmapluv.c.

{
       char   funcName[] = "tmCvLuv24";
       double uvp[2];
       register LUV24DATA   *ld;
       register int  i, j;
                                   /* check arguments */
       if (tms == NULL)
              returnErr(TM_E_TMINVAL);
       if ((ls == NULL) | (luvs == NULL) | (len < 0))
              returnErr(TM_E_ILLEGAL);
                                   /* check package registration */
       if (luv24Reg < 0) {
              if ((luv24Reg = tmRegPkg(&luv24Pkg)) < 0)
                     returnErr(TM_E_CODERR1);
              tmMkMesofact();
       }
                                   /* get package data */
       if ((ld = (LUV24DATA *)tmPkgData(tms,luv24Reg)) == NULL)
              returnErr(TM_E_NOMEM);
                                   /* convert each pixel */
       for (i = len; i--; ) {
              j = luvs[i] >> 14;          /* get luminance */
              ls[i] = (BRT2SCALE(j) >> 6) - ld->offset;
              if (cs == TM_NOCHROM)              /* no color? */
                     continue;
                                          /* get chrominance */
              if (tms->flags & TM_F_MESOPIC && ls[i] < BMESUPPER) {
                     if (uv_decode(&uvp[0], &uvp[1], luvs[i]&0x3fff) < 0) {
                            uvp[0] = U_NEU;             /* should barf? */
                            uvp[1] = V_NEU;
                     }
                     ls[i] = compmeshift(ls[i], uvp);
                     if (tms->flags&TM_F_BW || ls[i]<BMESLOWER
                                   || (j = uv_encode(uvp[0], uvp[1],
                                          SGILOGENCODE_NODITHER)) < 0)
                            j = uv14neu;
              } else {
                     j = tms->flags&TM_F_BW ? uv14neu :
                                   (int)(luvs[i]&0x3fff);
              }
              if (!isuvset(ld, j)) {
                     if (uv_decode(&uvp[0], &uvp[1], j) < 0) {
                            uvp[0] = U_NEU; uvp[1] = V_NEU;
                     }
                     uv2rgb(ld->rgbval[j], tms, uvp);
                     setuv(ld, j);
              }
              cs[3*i  ] = ld->rgbval[j][RED];
              cs[3*i+1] = ld->rgbval[j][GRN];
              cs[3*i+2] = ld->rgbval[j][BLU];
       }
       returnOK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int tmCvLuv32 ( TMstruct tms,
TMbright ls,
BYTE cs,
uint32 *  luvs,
int  len 
)

Definition at line 127 of file tmapluv.c.

{
       static const char    funcName[] = "tmCvLuv32";
       double uvp[2];
       register LUV32DATA   *ld;
       register int  i, j;
                                   /* check arguments */
       if (tms == NULL)
              returnErr(TM_E_TMINVAL);
       if ((ls == NULL) | (luvs == NULL) | (len < 0))
              returnErr(TM_E_ILLEGAL);
                                   /* check package registration */
       if (luv32Reg < 0) {
              if ((luv32Reg = tmRegPkg(&luv32Pkg)) < 0)
                     returnErr(TM_E_CODERR1);
              tmMkMesofact();
       }
                                   /* get package data */
       if ((ld = (LUV32DATA *)tmPkgData(tms,luv32Reg)) == NULL)
              returnErr(TM_E_NOMEM);
                                   /* convert each pixel */
       for (i = len; i--; ) {
              j = luvs[i] >> 16;          /* get luminance */
              if (j & 0x8000)                    /* negative luminance */
                     ls[i] = TM_NOBRT;    /* assign bogus value */
              else                        /* else convert to lnL */
                     ls[i] = (BRT2SCALE(j) >> 8) - ld->offset;
              if (cs == TM_NOCHROM)              /* no color? */
                     continue;
                                          /* get chrominance */
              if (tms->flags & TM_F_MESOPIC && ls[i] < BMESUPPER) {
                     uvp[0] = 1./UVSCALE*((luvs[i]>>8 & 0xff) + .5);
                     uvp[1] = 1./UVSCALE*((luvs[i] & 0xff) + .5);
                     ls[i] = compmeshift(ls[i], uvp);
                     j = tms->flags&TM_F_BW || ls[i]<BMESLOWER
                                   ? UVNEU
                                   : (int)(uvp[0]*UVSCALE)<<8
                                          | (int)(uvp[1]*UVSCALE);
              } else {
                     j = tms->flags&TM_F_BW ? UVNEU : luvs[i]&0xffff;
              }
              if (!isuvset(ld, j)) {
                     uvp[0] = 1./UVSCALE*((j>>8) + .5);
                     uvp[1] = 1./UVSCALE*((j & 0xff) + .5);
                     uv2rgb(ld->rgbval[j], tms, uvp);
                     setuv(ld, j);
              }
              cs[3*i  ] = ld->rgbval[j][RED];
              cs[3*i+1] = ld->rgbval[j][GRN];
              cs[3*i+2] = ld->rgbval[j][BLU];
       }
       returnOK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void uv2rgb ( rgb  ,
TMstruct tms,
uvp   
) [static]

Definition at line 69 of file tmapluv.c.

{      /* Should check that tms->inppri==TM_XYZPRIM beforehand... */
       double d, x, y;
       COLOR  XYZ, RGB;
                                   /* convert to XYZ */
       d = 1./(6.*uvp[0] - 16.*uvp[1] + 12.);
       x = 9.*uvp[0] * d;
       y = 4.*uvp[1] * d;
       XYZ[CIEY] = 1./tms->inpsf;
       XYZ[CIEX] = x/y * XYZ[CIEY];
       XYZ[CIEZ] = (1.-x-y)/y * XYZ[CIEY];
                                   /* convert to RGB and clip */
       colortrans(RGB, tms->cmat, XYZ);
       clipgamut(RGB, 1., CGAMUT_LOWER, cblack, cwhite);
                                   /* perform final scaling & gamma */
       d = tms->clf[RED] * RGB[RED];
       rgb[RED] = d>=.999 ? 255 : (int)(256.*pow(d, 1./tms->mongam));
       d = tms->clf[GRN] * RGB[GRN];
       rgb[GRN] = d>=.999 ? 255 : (int)(256.*pow(d, 1./tms->mongam));
       d = tms->clf[BLU] * RGB[BLU];
       rgb[BLU] = d>=.999 ? 255 : (int)(256.*pow(d, 1./tms->mongam));
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

int luv24Reg = -1 [static]

Definition at line 63 of file tmapluv.c.

int luv32Reg = -1 [static]

Definition at line 52 of file tmapluv.c.

const char RCSid[] = "$Id: tmapluv.c,v 3.14 2009/02/09 20:48:08 greg Exp $" [static]

Definition at line 2 of file tmapluv.c.

static struct tmPackage [static]
Initial value:

Definition at line 49 of file tmapluv.c.

int uv14neu = -1 [static]

Definition at line 65 of file tmapluv.c.