--- ray/src/common/tmapluv.c 2003/02/22 02:07:22 3.4
+++ ray/src/common/tmapluv.c 2022/01/15 16:57:46 3.17
@@ -1,5 +1,5 @@
#ifndef lint
-static const char RCSid[] = "$Id: tmapluv.c,v 3.4 2003/02/22 02:07:22 greg Exp $";
+static const char RCSid[] = "$Id: tmapluv.c,v 3.17 2022/01/15 16:57:46 greg Exp $";
#endif
/*
* Routines for tone-mapping LogLuv encoded pixels.
@@ -7,96 +7,39 @@ static const char RCSid[] = "$Id: tmapluv.c,v 3.4 2003
* Externals declared in tmaptiff.h
*/
-/* ====================================================================
- * The Radiance Software License, Version 1.0
- *
- * Copyright (c) 1990 - 2002 The Regents of the University of California,
- * through Lawrence Berkeley National Laboratory. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes Radiance software
- * (http://radsite.lbl.gov/)
- * developed by the Lawrence Berkeley National Laboratory
- * (http://www.lbl.gov/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
- * and "The Regents of the University of California" must
- * not be used to endorse or promote products derived from this
- * software without prior written permission. For written
- * permission, please contact radiance@radsite.lbl.gov.
- *
- * 5. Products derived from this software may not be called "Radiance",
- * nor may "Radiance" appear in their name, without prior written
- * permission of Lawrence Berkeley National Laboratory.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of Lawrence Berkeley National Laboratory. For more
- * information on Lawrence Berkeley National Laboratory, please see
- * .
- */
+#include "copyright.h"
#define LOGLUV_PUBLIC 1
#include
+#include
#include
#include
#include "tiffio.h"
#include "tmprivat.h"
#include "tmaptiff.h"
-#ifndef BSD
-#define bzero(d,n) (void)memset(d,0,n)
-#endif
#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) bzero((MEM_PTR)(p)->rgbflg,sizeof((p)->rgbflg))
+#define clruvall(p) memset((p)->rgbflg,'\0',sizeof((p)->rgbflg))
#ifdef NOPROTO
-static MEM_PTR luv32Init();
+static void * luv32Init();
static void luv32NewSpace();
-static MEM_PTR luv24Init();
+static void * luv24Init();
static void luv24NewSpace();
#else
-static MEM_PTR luv32Init(struct tmStruct *);
-static void luv32NewSpace(struct tmStruct *);
-static MEM_PTR luv24Init(struct tmStruct *);
-static void luv24NewSpace(struct tmStruct *);
+static void * luv32Init(TMstruct *);
+static void luv32NewSpace(TMstruct *);
+static void * luv24Init(TMstruct *);
+static void luv24NewSpace(TMstruct *);
#endif
typedef struct {
int offset; /* computed luminance offset */
- BYTE rgbval[1<<16][3]; /* computed RGB value for given uv */
+ uby8 rgbval[1<<16][3]; /* computed RGB value for given uv */
uint32 rgbflg[1<<(16-5)]; /* flags for computed values */
} LUV32DATA; /* LogLuv 32-bit conversion data */
@@ -110,7 +53,7 @@ static int luv32Reg = -1; /* 32-bit package reg. numb
typedef struct {
int offset; /* computed luminance offset */
- BYTE rgbval[1<<14][3]; /* computed rgb value for uv index */
+ uby8 rgbval[1<<14][3]; /* computed rgb value for uv index */
uint32 rgbflg[1<<(14-5)]; /* flags for computed values */
} LUV24DATA; /* LogLuv 24-bit conversion data */
@@ -123,30 +66,30 @@ static int uv14neu = -1; /* neutral index for 14-bit
static void
-uv2rgb(rgb, tm, uvp) /* compute RGB from uv coordinate */
-BYTE rgb[3];
-register struct tmStruct *tm;
+uv2rgb(rgb, tms, uvp) /* compute RGB from uv coordinate */
+uby8 rgb[3];
+TMstruct *tms;
double uvp[2];
-{ /* Should check that tm->inppri==TM_XYZPRIM beforehand... */
+{ /* 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./tm->inpsf;
+ 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, tm->cmat, XYZ);
+ colortrans(RGB, tms->cmat, XYZ);
clipgamut(RGB, 1., CGAMUT_LOWER, cblack, cwhite);
/* perform final scaling & gamma */
- d = tm->clf[RED] * RGB[RED];
- rgb[RED] = d>=.999 ? 255 : (int)(256.*pow(d, 1./tm->mongam));
- d = tm->clf[GRN] * RGB[GRN];
- rgb[GRN] = d>=.999 ? 255 : (int)(256.*pow(d, 1./tm->mongam));
- d = tm->clf[BLU] * RGB[BLU];
- rgb[BLU] = d>=.999 ? 255 : (int)(256.*pow(d, 1./tm->mongam));
+ 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));
}
@@ -156,7 +99,7 @@ TMbright li; /* encoded world luminance */
double uvp[2]; /* world (u',v') -> returned desaturated */
{
double scotrat;
- register double d;
+ double d;
if (li >= BMESUPPER)
return(li);
@@ -181,20 +124,22 @@ double uvp[2]; /* world (u',v') -> returned desatura
int
-tmCvLuv32(ls, cs, luvs, len) /* convert raw 32-bit LogLuv values */
-TMbright *ls;
-BYTE *cs;
-uint32 *luvs;
-int len;
+tmCvLuv32( /* convert raw 32-bit LogLuv values */
+TMstruct *tms,
+TMbright *ls,
+uby8 *cs,
+uint32 *luvs,
+int len
+)
{
- static char funcName[] = "tmCvLuv32";
+ static const char funcName[] = "tmCvLuv32";
double uvp[2];
- register LUV32DATA *ld;
- register int i, j;
+ LUV32DATA *ld;
+ int i, j;
/* check arguments */
- if (tmTop == NULL)
+ if (tms == NULL)
returnErr(TM_E_TMINVAL);
- if (ls == NULL | luvs == NULL | len < 0)
+ if ((ls == NULL) | (luvs == NULL) | (len < 0))
returnErr(TM_E_ILLEGAL);
/* check package registration */
if (luv32Reg < 0) {
@@ -203,7 +148,7 @@ int len;
tmMkMesofact();
}
/* get package data */
- if ((ld = (LUV32DATA *)tmPkgData(tmTop,luv32Reg)) == NULL)
+ if ((ld = (LUV32DATA *)tmPkgData(tms,luv32Reg)) == NULL)
returnErr(TM_E_NOMEM);
/* convert each pixel */
for (i = len; i--; ) {
@@ -215,21 +160,21 @@ int len;
if (cs == TM_NOCHROM) /* no color? */
continue;
/* get chrominance */
- if (tmTop->flags & TM_F_MESOPIC && ls[i] < BMESUPPER) {
+ 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 = tmTop->flags&TM_F_BW || ls[i]flags&TM_F_BW || ls[i]flags&TM_F_BW ? UVNEU : luvs[i]&0xffff;
+ 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], tmTop, uvp);
+ uv2rgb(ld->rgbval[j], tms, uvp);
setuv(ld, j);
}
cs[3*i ] = ld->rgbval[j][RED];
@@ -241,20 +186,22 @@ int len;
int
-tmCvLuv24(ls, cs, luvs, len) /* convert raw 24-bit LogLuv values */
-TMbright *ls;
-BYTE *cs;
-uint32 *luvs;
-int len;
+tmCvLuv24( /* convert raw 24-bit LogLuv values */
+TMstruct *tms,
+TMbright *ls,
+uby8 *cs,
+uint32 *luvs,
+int len
+)
{
char funcName[] = "tmCvLuv24";
double uvp[2];
- register LUV24DATA *ld;
- register int i, j;
+ LUV24DATA *ld;
+ int i, j;
/* check arguments */
- if (tmTop == NULL)
+ if (tms == NULL)
returnErr(TM_E_TMINVAL);
- if (ls == NULL | luvs == NULL | len < 0)
+ if ((ls == NULL) | (luvs == NULL) | (len < 0))
returnErr(TM_E_ILLEGAL);
/* check package registration */
if (luv24Reg < 0) {
@@ -263,7 +210,7 @@ int len;
tmMkMesofact();
}
/* get package data */
- if ((ld = (LUV24DATA *)tmPkgData(tmTop,luv24Reg)) == NULL)
+ if ((ld = (LUV24DATA *)tmPkgData(tms,luv24Reg)) == NULL)
returnErr(TM_E_NOMEM);
/* convert each pixel */
for (i = len; i--; ) {
@@ -272,24 +219,25 @@ int len;
if (cs == TM_NOCHROM) /* no color? */
continue;
/* get chrominance */
- if (tmTop->flags & TM_F_MESOPIC && ls[i] < BMESUPPER) {
- if (uv_decode(uvp, uvp+1, luvs[i]&0x3fff) < 0) {
+ 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 (tmTop->flags&TM_F_BW || ls[i]flags&TM_F_BW || ls[i]flags&TM_F_BW ? uv14neu : luvs[i]&0x3fff;
+ 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], tmTop, uvp);
+ uv2rgb(ld->rgbval[j], tms, uvp);
setuv(ld, j);
}
cs[3*i ] = ld->rgbval[j][RED];
@@ -301,28 +249,26 @@ int len;
int
-tmCvL16(ls, l16s, len) /* convert 16-bit LogL values */
-TMbright *ls;
-uint16 *l16s;
-int len;
+tmCvL16( /* convert 16-bit LogL values */
+TMstruct *tms,
+TMbright *ls,
+uint16 *l16s,
+int len
+)
{
- static char funcName[] = "tmCvL16";
+ static const char funcName[] = "tmCvL16";
static double lastsf;
static int offset;
- register int i;
+ int i;
/* check arguments */
- if (tmTop == NULL)
+ if (tms == NULL)
returnErr(TM_E_TMINVAL);
- if (ls == NULL | l16s == NULL | len < 0)
+ if ((ls == NULL) | (l16s == NULL) | (len < 0))
returnErr(TM_E_ILLEGAL);
/* check scaling offset */
- if (!FEQ(tmTop->inpsf, lastsf)) {
- offset = BRT2SCALE(64);
- if (tmTop->inpsf > 1.0001)
- offset -= (int)(TM_BRTSCALE*log(tmTop->inpsf)+.5);
- else if (tmTop->inpsf < 0.9999)
- offset -= (int)(TM_BRTSCALE*log(tmTop->inpsf)-.5);
- lastsf = tmTop->inpsf;
+ if (!FEQ(tms->inpsf, lastsf)) {
+ offset = BRT2SCALE(64) - tmCvLuminance(tms->inpsf);
+ lastsf = tms->inpsf;
}
/* convert each pixel */
for (i = len; i--; ) {
@@ -336,72 +282,64 @@ int len;
static void
-luv32NewSpace(tm) /* initialize 32-bit LogLuv color space */
-struct tmStruct *tm;
+luv32NewSpace(tms) /* initialize 32-bit LogLuv color space */
+TMstruct *tms;
{
- register LUV32DATA *ld;
+ LUV32DATA *ld;
- if (tm->inppri != TM_XYZPRIM) { /* panic time! */
+ if (tms->inppri != TM_XYZPRIM) { /* panic time! */
fputs("Improper input color space in luv32NewSpace!\n", stderr);
exit(1);
}
- ld = (LUV32DATA *)tm->pd[luv32Reg];
- ld->offset = BRT2SCALE(64);
- if (tm->inpsf > 1.0001)
- ld->offset -= (int)(TM_BRTSCALE*log(tmTop->inpsf)+.5);
- else if (tm->inpsf < 0.9999)
- ld->offset -= (int)(TM_BRTSCALE*log(tmTop->inpsf)-.5);
+ ld = (LUV32DATA *)tms->pd[luv32Reg];
+ ld->offset = BRT2SCALE(64) - tmCvLuminance(tms->inpsf);
clruvall(ld);
}
-static MEM_PTR
-luv32Init(tm) /* allocate data for 32-bit LogLuv decoder */
-struct tmStruct *tm;
+static void *
+luv32Init(tms) /* allocate data for 32-bit LogLuv decoder */
+TMstruct *tms;
{
- register LUV32DATA *ld;
+ LUV32DATA *ld;
ld = (LUV32DATA *)malloc(sizeof(LUV32DATA));
if (ld == NULL)
return(NULL);
- tm->pd[luv32Reg] = (MEM_PTR)ld;
- luv32NewSpace(tm);
- return((MEM_PTR)ld);
+ tms->pd[luv32Reg] = (void *)ld;
+ luv32NewSpace(tms);
+ return((void *)ld);
}
static void
-luv24NewSpace(tm) /* initialize 24-bit LogLuv color space */
-struct tmStruct *tm;
+luv24NewSpace(tms) /* initialize 24-bit LogLuv color space */
+TMstruct *tms;
{
- register LUV24DATA *ld;
+ LUV24DATA *ld;
- if (tm->inppri != TM_XYZPRIM) { /* panic time! */
+ if (tms->inppri != TM_XYZPRIM) { /* panic time! */
fputs("Improper input color space in luv24NewSpace!\n", stderr);
exit(1);
}
- ld = (LUV24DATA *)tm->pd[luv24Reg];
- ld->offset = BRT2SCALE(12);
- if (tm->inpsf > 1.0001)
- ld->offset -= (int)(TM_BRTSCALE*log(tmTop->inpsf)+.5);
- else if (tm->inpsf < 0.9999)
- ld->offset -= (int)(TM_BRTSCALE*log(tmTop->inpsf)-.5);
+ ld = (LUV24DATA *)tms->pd[luv24Reg];
+ ld->offset = BRT2SCALE(12) - tmCvLuminance(tms->inpsf);
clruvall(ld);
}
-static MEM_PTR
-luv24Init(tm) /* allocate data for 24-bit LogLuv decoder */
-struct tmStruct *tm;
+static void *
+luv24Init(tms) /* allocate data for 24-bit LogLuv decoder */
+TMstruct *tms;
{
- register LUV24DATA *ld;
+ LUV24DATA *ld;
ld = (LUV24DATA *)malloc(sizeof(LUV24DATA));
if (ld == NULL)
return(NULL);
- tm->pd[luv24Reg] = (MEM_PTR)ld;
+ tms->pd[luv24Reg] = (void *)ld;
if (uv14neu < 0) /* initialize neutral color index */
uv14neu = uv_encode(U_NEU, V_NEU, SGILOGENCODE_NODITHER);
- luv24NewSpace(tm);
- return((MEM_PTR)ld);
+ luv24NewSpace(tms);
+ return((void *)ld);
}