Back to index

radiance  4R0+20100331
Functions
tmaptiff.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int tmCvL16 (TMstruct *tms, TMbright *ls, uint16 *luvs, int len)
int tmCvLuv24 (TMstruct *tms, TMbright *ls, BYTE *cs, uint32 *luvs, int len)
int tmCvLuv32 (TMstruct *tms, TMbright *ls, BYTE *cs, uint32 *luvs, int len)
int tmLoadTIFF (TMstruct *tms, TMbright **lpp, BYTE **cpp, int *xp, int *yp, char *fname, TIFF *tp)
int tmMapTIFF (BYTE **psp, int *xp, int *yp, int flags, RGBPRIMP monpri, double gamval, double Lddyn, double Ldmax, char *fname, TIFF *tp)

Function Documentation

int tmCvL16 ( TMstruct tms,
TMbright ls,
uint16 *  luvs,
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:

int tmLoadTIFF ( TMstruct tms,
TMbright **  lpp,
BYTE **  cpp,
int *  xp,
int *  yp,
char *  fname,
TIFF *  tp 
)

Definition at line 82 of file tmaptiff.c.

{
       char   *funcName = fname==NULL ? "tmLoadTIFF" : fname;
       RGBPRIMP      inppri = tms->monpri;
       RGBPRIMS      myprims;
       float  *fa;
       TIFF   *tif;
       int    err;
       union {uint16 *w; uint32 *l; float *f; MEM_PTR p;} sl;
       uint32 width, height;
       int    tcase;
       double stonits;
       int    y;
                                   /* check arguments */
       if (tms == NULL)
              returnErr(TM_E_TMINVAL);
       if ((lpp == NULL) | (xp == NULL) | (yp == NULL) |
                     ((fname == NULL) & (tp == NULL)))
              returnErr(TM_E_ILLEGAL);
                                   /* check/get TIFF tags */
       sl.p = NULL; *lpp = NULL;
       if (cpp != TM_NOCHROMP) *cpp = TM_NOCHROM;
       err = TM_E_BADFILE;
       if ((tif = tp) == NULL && (tif = TIFFOpen(fname, "r")) == NULL)
              returnErr(TM_E_BADFILE);
       tcase = getTIFFtype(tif);
       if (!tcase)
              goto done;
       if (!TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width) ||
                     !TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height))
              goto done;
       *xp = width; *yp = height;
       if (TIFFGetField(tif, TIFFTAG_PRIMARYCHROMATICITIES, &fa)) {
              myprims[RED][CIEX] = fa[0];
              myprims[RED][CIEY] = fa[1];
              myprims[GRN][CIEX] = fa[2];
              myprims[GRN][CIEY] = fa[3];
              myprims[BLU][CIEX] = fa[4];
              myprims[BLU][CIEY] = fa[5];
              myprims[WHT][CIEX] = 1./3.;
              myprims[WHT][CIEY] = 1./3.;
              if (TIFFGetField(tif, TIFFTAG_WHITEPOINT, &fa)) {
                     myprims[WHT][CIEX] = fa[0];
                     myprims[WHT][CIEY] = fa[1];
              }
              inppri = myprims;
       }
       if (!TIFFGetField(tif, TIFFTAG_STONITS, &stonits))
              stonits = 1.;
       switch (tcase) {            /* set up conversion */
       case TC_LOGLUV32:
       case TC_LOGLUV24:
              TIFFSetField(tif, TIFFTAG_SGILOGDATAFMT, SGILOGDATAFMT_RAW);
              sl.l = (uint32 *)malloc(width*sizeof(uint32));
              tmSetSpace(tms, TM_XYZPRIM, stonits, NULL);
              break;
       case TC_LOGL16:
              TIFFSetField(tif, TIFFTAG_SGILOGDATAFMT, SGILOGDATAFMT_16BIT);
              sl.w = (uint16 *)malloc(width*sizeof(uint16));
              tmSetSpace(tms, tms->monpri, stonits, NULL);
              break;
       case TC_RGBFLOAT:
              sl.f = (float *)malloc(width*3*sizeof(float));
              tmSetSpace(tms, inppri, stonits, NULL);
              break;
       case TC_GRYFLOAT:
              sl.f = (float *)malloc(width*sizeof(float));
              tmSetSpace(tms, tms->monpri, stonits, NULL);
              break;
       case TC_RGBSHORT:
              sl.w = (uint16 *)malloc(width*3*sizeof(uint16));
              tmSetSpace(tms, inppri, stonits, NULL);
              break;
       case TC_GRYSHORT:
              sl.w = (uint16 *)malloc(width*sizeof(uint16));
              tmSetSpace(tms, tms->monpri, stonits, NULL);
              break;
       default:
              err = TM_E_CODERR1;
              goto done;
       }
       *lpp = (TMbright *)malloc(width*height*sizeof(TMbright));
       if ((sl.p == NULL) | (*lpp == NULL)) {
              err = TM_E_NOMEM;
              goto done;
       }
       switch (tcase) {            /* allocate color if needed */
       case TC_LOGLUV32:
       case TC_LOGLUV24:
       case TC_RGBFLOAT:
       case TC_RGBSHORT:
              if (cpp == TM_NOCHROMP)
                     break;
              *cpp = (BYTE *)malloc(width*height*3*sizeof(BYTE));
              if (*cpp == NULL) {
                     err = TM_E_NOMEM;
                     goto done;
              }
              break;
       }
                                   /* read and convert each scanline */
       for (y = 0; y < height; y++) {
              if (TIFFReadScanline(tif, sl.p, y, 0) < 0) {
                     err = TM_E_BADFILE;
                     break;
              }
              switch (tcase) {
              case TC_LOGLUV32:
                     err = tmCvLuv32(tms, *lpp + y*width,
                            cpp==TM_NOCHROMP ? TM_NOCHROM : *cpp+y*3*width,
                                   sl.l, width);
                     break;
              case TC_LOGLUV24:
                     err = tmCvLuv24(tms, *lpp + y*width,
                            cpp==TM_NOCHROMP ? TM_NOCHROM : *cpp+y*3*width,
                                   sl.l, width);
                     break;
              case TC_LOGL16:
                     err = tmCvL16(tms, *lpp + y*width, sl.w, width);
                     break;
              case TC_RGBFLOAT:
                     err = tmCvColors(tms, *lpp + y*width,
                            cpp==TM_NOCHROMP ? TM_NOCHROM : *cpp+y*3*width,
                                   (COLOR *)sl.f, width);
                     break;
              case TC_GRYFLOAT:
                     err = tmCvGrays(tms, *lpp + y*width, sl.f, width);
                     break;
              case TC_RGBSHORT:
                     err = tmCvRGB48(tms, *lpp + y*width,
                            cpp==TM_NOCHROMP ? TM_NOCHROM : *cpp+y*3*width,
                                   (uint16 (*)[3])sl.w, width, DEFGAM);
                     break;
              case TC_GRYSHORT:
                     err = tmCvGray16(tms, *lpp + y*width,
                                   sl.w, width, DEFGAM);
                     break;
              default:
                     err = TM_E_CODERR1;
                     break;
              }
              if (err != TM_E_OK)
                     break;
       }
done:                              /* clean up */
       if (tp == NULL)
              TIFFClose(tif);
       if (sl.p != NULL)
              free(sl.p);
       if (err != TM_E_OK) {              /* free buffers on error */
              if (*lpp != NULL)
                     free((MEM_PTR)*lpp);
              *lpp = NULL;
              if (cpp != TM_NOCHROMP) {
                     if (*cpp != TM_NOCHROM)
                            free((MEM_PTR)*cpp);
                     *cpp = NULL;
              }
              *xp = *yp = 0;
              returnErr(err);
       }
       returnOK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int tmMapTIFF ( BYTE **  psp,
int *  xp,
int *  yp,
int  flags,
RGBPRIMP  monpri,
double  gamval,
double  Lddyn,
double  Ldmax,
char *  fname,
TIFF *  tp 
)

Definition at line 255 of file tmaptiff.c.

{
       char   *funcName = fname==NULL ? "tmMapTIFF" : fname;
       TMstruct      *tms;
       TMbright      *lp;
       BYTE   *cp;
       int    err;
                                   /* check arguments */
       if ((psp == NULL) | (xp == NULL) | (yp == NULL) | (monpri == NULL) |
                     ((fname == NULL) & (tp == NULL)))
              returnErr(TM_E_ILLEGAL);
       if (gamval < MINGAM) gamval = DEFGAM;
       if (Lddyn < MINLDDYN) Lddyn = DEFLDDYN;
       if (Ldmax < MINLDMAX) Ldmax = DEFLDMAX;
       if (flags & TM_F_BW) monpri = stdprims;
                                   /* initialize tone mapping */
       if ((tms = tmInit(flags, monpri, gamval)) == NULL)
              returnErr(TM_E_NOMEM);
                                   /* load and convert TIFF */
       cp = TM_NOCHROM;
       err = tmLoadTIFF(tms, &lp, flags&TM_F_BW ? TM_NOCHROMP : &cp,
                     xp, yp, fname, tp);
       if (err != TM_E_OK) {
              tmDone(tms);
              return(err);
       }
       if (cp == TM_NOCHROM) {
              *psp = (BYTE *)malloc(*xp * *yp * sizeof(BYTE));
              if (*psp == NULL) {
                     free((MEM_PTR)lp);
                     tmDone(tms);
                     returnErr(TM_E_NOMEM);
              }
       } else
              *psp = cp;
                                   /* compute color mapping */
       err = tmAddHisto(tms, lp, *xp * *yp, 1);
       if (err != TM_E_OK)
              goto done;
       err = tmComputeMapping(tms, gamval, Lddyn, Ldmax);
       if (err != TM_E_OK)
              goto done;
                                   /* map pixels */
       err = tmMapPixels(tms, *psp, lp, cp, *xp * *yp);

done:                              /* clean up */
       free((MEM_PTR)lp);
       tmDone(tms);
       if (err != TM_E_OK) {              /* free memory on error */
              free((MEM_PTR)*psp);
              *psp = NULL;
              *xp = *yp = 0;
              returnErr(err);
       }
       returnOK;
}

Here is the call graph for this function:

Here is the caller graph for this function: