This commit is contained in:
John Cupitt 2009-03-01 21:20:27 +00:00
parent 68fe740f3c
commit ef582ca5ec
4 changed files with 0 additions and 608 deletions

View File

@ -1,207 +0,0 @@
/* RCSid $Id: color.h,v 2.29 2006/09/05 21:54:32 greg Exp $ */
/*
* color.h - header for routines using pixel color values.
*
* Must be included after X11 headers, since they declare a BYTE type.
*
* Two color representations are used, one for calculation and
* another for storage. Calculation is done with three floats
* for speed. Stored color values use 4 bytes which contain
* three single byte mantissas and a common exponent.
*/
#ifndef _RAD_COLOR_H_
#define _RAD_COLOR_H_
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
#define RED 0
#define GRN 1
#define BLU 2
#define CIEX 0 /* or, if input is XYZ... */
#define CIEY 1
#define CIEZ 2
#define EXP 3 /* exponent same for either format */
#define COLXS 128 /* excess used for exponent */
#define WHT 3 /* used for RGBPRIMS type */
#undef BYTE
#define BYTE unsigned char /* 8-bit unsigned integer */
typedef BYTE COLR[4]; /* red, green, blue (or X,Y,Z), exponent */
typedef float COLORV;
typedef COLORV COLOR[3]; /* red, green, blue (or X,Y,Z) */
typedef float RGBPRIMS[4][2]; /* (x,y) chromaticities for RGBW */
typedef float (*RGBPRIMP)[2]; /* pointer to RGBPRIMS array */
typedef float COLORMAT[3][3]; /* color coordinate conversion matrix */
#define copycolr(c1,c2) (c1[0]=c2[0],c1[1]=c2[1], \
c1[2]=c2[2],c1[3]=c2[3])
#define colval(col,pri) ((col)[pri])
#define setcolor(col,r,g,b) ((col)[RED]=(r),(col)[GRN]=(g),(col)[BLU]=(b))
#define copycolor(c1,c2) ((c1)[0]=(c2)[0],(c1)[1]=(c2)[1],(c1)[2]=(c2)[2])
#define scalecolor(col,sf) ((col)[0]*=(sf),(col)[1]*=(sf),(col)[2]*=(sf))
#define addcolor(c1,c2) ((c1)[0]+=(c2)[0],(c1)[1]+=(c2)[1],(c1)[2]+=(c2)[2])
#define multcolor(c1,c2) ((c1)[0]*=(c2)[0],(c1)[1]*=(c2)[1],(c1)[2]*=(c2)[2])
#ifdef NTSC
#define CIE_x_r 0.670 /* standard NTSC primaries */
#define CIE_y_r 0.330
#define CIE_x_g 0.210
#define CIE_y_g 0.710
#define CIE_x_b 0.140
#define CIE_y_b 0.080
#define CIE_x_w 0.3333 /* use true white */
#define CIE_y_w 0.3333
#else
#define CIE_x_r 0.640 /* nominal CRT primaries */
#define CIE_y_r 0.330
#define CIE_x_g 0.290
#define CIE_y_g 0.600
#define CIE_x_b 0.150
#define CIE_y_b 0.060
#define CIE_x_w 0.3333 /* use true white */
#define CIE_y_w 0.3333
#endif
#define STDPRIMS {{CIE_x_r,CIE_y_r},{CIE_x_g,CIE_y_g}, \
{CIE_x_b,CIE_y_b},{CIE_x_w,CIE_y_w}}
#define CIE_D ( CIE_x_r*(CIE_y_g - CIE_y_b) + \
CIE_x_g*(CIE_y_b - CIE_y_r) + \
CIE_x_b*(CIE_y_r - CIE_y_g) )
#define CIE_C_rD ( (1./CIE_y_w) * \
( CIE_x_w*(CIE_y_g - CIE_y_b) - \
CIE_y_w*(CIE_x_g - CIE_x_b) + \
CIE_x_g*CIE_y_b - CIE_x_b*CIE_y_g ) )
#define CIE_C_gD ( (1./CIE_y_w) * \
( CIE_x_w*(CIE_y_b - CIE_y_r) - \
CIE_y_w*(CIE_x_b - CIE_x_r) - \
CIE_x_r*CIE_y_b + CIE_x_b*CIE_y_r ) )
#define CIE_C_bD ( (1./CIE_y_w) * \
( CIE_x_w*(CIE_y_r - CIE_y_g) - \
CIE_y_w*(CIE_x_r - CIE_x_g) + \
CIE_x_r*CIE_y_g - CIE_x_g*CIE_y_r ) )
#define CIE_rf (CIE_y_r*CIE_C_rD/CIE_D)
#define CIE_gf (CIE_y_g*CIE_C_gD/CIE_D)
#define CIE_bf (CIE_y_b*CIE_C_bD/CIE_D)
/* As of 9-94, CIE_rf=.265074126, CIE_gf=.670114631 and CIE_bf=.064811243 */
/***** The following definitions are valid for RGB colors only... *****/
#define bright(col) (CIE_rf*(col)[RED]+CIE_gf*(col)[GRN]+CIE_bf*(col)[BLU])
#define normbright(c) ( ( (long)(CIE_rf*256.+.5)*(c)[RED] + \
(long)(CIE_gf*256.+.5)*(c)[GRN] + \
(long)(CIE_bf*256.+.5)*(c)[BLU] ) >> 8 )
/* luminous efficacies over visible spectrum */
#define MAXEFFICACY 683. /* defined maximum at 550 nm */
#define WHTEFFICACY 179. /* uniform white light */
#define D65EFFICACY 203. /* standard illuminant D65 */
#define INCEFFICACY 160. /* illuminant A (incand.) */
#define SUNEFFICACY 208. /* illuminant B (solar dir.) */
#define SKYEFFICACY D65EFFICACY /* skylight (should be 110) */
#define DAYEFFICACY D65EFFICACY /* combined sky and solar */
#define luminance(col) (WHTEFFICACY * bright(col))
/***** ...end of stuff specific to RGB colors *****/
#define intens(col) ( (col)[0] > (col)[1] \
? (col)[0] > (col)[2] ? (col)[0] : (col)[2] \
: (col)[1] > (col)[2] ? (col)[1] : (col)[2] )
#define colrval(c,p) ( (c)[EXP] ? \
ldexp((c)[p]+.5,(int)(c)[EXP]-(COLXS+8)) : \
0. )
#define WHTCOLOR {1.0,1.0,1.0}
#define BLKCOLOR {0.0,0.0,0.0}
#define WHTCOLR {128,128,128,COLXS+1}
#define BLKCOLR {0,0,0,0}
/* picture format identifier */
#define COLRFMT "32-bit_rle_rgbe"
#define CIEFMT "32-bit_rle_xyze"
#define PICFMT "32-bit_rle_???e" /* matches either */
#define LPICFMT 15 /* max format id len */
/* macros for exposures */
#define EXPOSSTR "EXPOSURE="
#define LEXPOSSTR 9
#define isexpos(hl) (!strncmp(hl,EXPOSSTR,LEXPOSSTR))
#define exposval(hl) atof((hl)+LEXPOSSTR)
#define fputexpos(ex,fp) fprintf(fp,"%s%e\n",EXPOSSTR,ex)
/* macros for pixel aspect ratios */
#define ASPECTSTR "PIXASPECT="
#define LASPECTSTR 10
#define isaspect(hl) (!strncmp(hl,ASPECTSTR,LASPECTSTR))
#define aspectval(hl) atof((hl)+LASPECTSTR)
#define fputaspect(pa,fp) fprintf(fp,"%s%f\n",ASPECTSTR,pa)
/* macros for primary specifications */
#define PRIMARYSTR "PRIMARIES="
#define LPRIMARYSTR 10
#define isprims(hl) (!strncmp(hl,PRIMARYSTR,LPRIMARYSTR))
#define primsval(p,hl) sscanf(hl+LPRIMARYSTR, \
"%f %f %f %f %f %f %f %f", \
&(p)[RED][CIEX],&(p)[RED][CIEY], \
&(p)[GRN][CIEX],&(p)[GRN][CIEY], \
&(p)[BLU][CIEX],&(p)[BLU][CIEY], \
&(p)[WHT][CIEX],&(p)[WHT][CIEY])
#define fputprims(p,fp) fprintf(fp, \
"%s %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f\n",\
PRIMARYSTR, \
(p)[RED][CIEX],(p)[RED][CIEY], \
(p)[GRN][CIEX],(p)[GRN][CIEY], \
(p)[BLU][CIEX],(p)[BLU][CIEY], \
(p)[WHT][CIEX],(p)[WHT][CIEY])
/* macros for color correction */
#define COLCORSTR "COLORCORR="
#define LCOLCORSTR 10
#define iscolcor(hl) (!strncmp(hl,COLCORSTR,LCOLCORSTR))
#define colcorval(cc,hl) sscanf(hl+LCOLCORSTR,"%f %f %f", \
&(cc)[RED],&(cc)[GRN],&(cc)[BLU])
#define fputcolcor(cc,fp) fprintf(fp,"%s %f %f %f\n",COLCORSTR, \
(cc)[RED],(cc)[GRN],(cc)[BLU])
/*
* Conversions to and from XYZ space generally don't apply WHTEFFICACY.
* If you need Y to be luminance (cd/m^2), this must be applied when
* converting from radiance (watts/sr/m^2).
*/
extern RGBPRIMS stdprims; /* standard primary chromaticities */
extern COLORMAT rgb2xyzmat; /* RGB to XYZ conversion matrix */
extern COLORMAT xyz2rgbmat; /* XYZ to RGB conversion matrix */
extern COLOR cblack, cwhite; /* black (0,0,0) and white (1,1,1) */
#define CGAMUT_LOWER 01
#define CGAMUT_UPPER 02
#define CGAMUT (CGAMUT_LOWER|CGAMUT_UPPER)
#define rgb_cie(xyz,rgb) colortrans(xyz,rgb2xyzmat,rgb)
#define cpcolormat(md,ms) memcpy((void *)md,(void *)ms,sizeof(COLORMAT))
#ifdef __cplusplus
}
#endif
#endif /* _RAD_COLOR_H_ */

View File

@ -1,231 +0,0 @@
#ifndef lint
static const char RCSid[] = "$Id: colrops.c,v 2.11 2003/07/30 10:11:06 schorsch Exp $";
#endif
/*
* Integer operations on COLR scanlines
*/
#include "copyright.h"
#include <stdio.h>
#include <math.h>
#include "rtmisc.h"
#include "color.h"
#define MAXGSHIFT 31 /* maximum shift for gamma table */
static BYTE *g_mant = NULL, *g_nexp = NULL;
static BYTE (*g_bval)[256] = NULL;
int
setcolrcor(f, a2) /* set brightness correction */
double (*f)(double,double);
double a2;
{
double mult;
register int i, j;
/* allocate tables */
if (g_bval == NULL && (g_bval =
(BYTE (*)[256])bmalloc((MAXGSHIFT+1)*256)) == NULL)
return(-1);
/* compute colr -> gamb mapping */
mult = 1.0/256.0;
for (i = 0; i <= MAXGSHIFT; i++) {
for (j = 0; j < 256; j++)
g_bval[i][j] = 256.0 * (*f)((j+.5)*mult, a2);
mult *= 0.5;
}
return(0);
}
int
setcolrinv(f, a2) /* set inverse brightness correction */
double (*f)(double,double);
double a2;
{
double mult;
register int i, j;
/* allocate tables */
if (g_mant == NULL && (g_mant = (BYTE *)bmalloc(256)) == NULL)
return(-1);
if (g_nexp == NULL && (g_nexp = (BYTE *)bmalloc(256)) == NULL)
return(-1);
/* compute gamb -> colr mapping */
i = 0;
mult = 256.0;
for (j = 256; j--; ) {
while ((g_mant[j] = mult * (*f)((j+.5)/256.0, a2)) < 128) {
i++;
mult *= 2.0;
}
g_nexp[j] = i;
}
return(0);
}
int
setcolrgam(g) /* set gamma conversion */
double g;
{
if (setcolrcor(pow, 1.0/g) < 0)
return(-1);
return(setcolrinv(pow, g));
}
int
colrs_gambs(scan, len) /* convert scanline of colrs to gamma bytes */
register COLR *scan;
int len;
{
register int i, expo;
if (g_bval == NULL)
return(-1);
while (len-- > 0) {
expo = scan[0][EXP] - COLXS;
if (expo < -MAXGSHIFT) {
if (expo < -MAXGSHIFT-8) {
scan[0][RED] =
scan[0][GRN] =
scan[0][BLU] = 0;
} else {
i = (-MAXGSHIFT-1) - expo;
scan[0][RED] =
g_bval[MAXGSHIFT][((scan[0][RED]>>i)+1)>>1];
scan[0][GRN] =
g_bval[MAXGSHIFT][((scan[0][GRN]>>i)+1)>>1];
scan[0][BLU] =
g_bval[MAXGSHIFT][((scan[0][BLU]>>i)+1)>>1];
}
} else if (expo > 0) {
if (expo > 8) {
scan[0][RED] =
scan[0][GRN] =
scan[0][BLU] = 255;
} else {
i = (scan[0][RED]<<1 | 1) << (expo-1);
scan[0][RED] = i > 255 ? 255 : g_bval[0][i];
i = (scan[0][GRN]<<1 | 1) << (expo-1);
scan[0][GRN] = i > 255 ? 255 : g_bval[0][i];
i = (scan[0][BLU]<<1 | 1) << (expo-1);
scan[0][BLU] = i > 255 ? 255 : g_bval[0][i];
}
} else {
scan[0][RED] = g_bval[-expo][scan[0][RED]];
scan[0][GRN] = g_bval[-expo][scan[0][GRN]];
scan[0][BLU] = g_bval[-expo][scan[0][BLU]];
}
scan[0][EXP] = COLXS;
scan++;
}
return(0);
}
int
gambs_colrs(scan, len) /* convert gamma bytes to colr scanline */
register COLR *scan;
int len;
{
register int nexpo;
if ((g_mant == NULL) | (g_nexp == NULL))
return(-1);
while (len-- > 0) {
nexpo = g_nexp[scan[0][RED]];
if (g_nexp[scan[0][GRN]] < nexpo)
nexpo = g_nexp[scan[0][GRN]];
if (g_nexp[scan[0][BLU]] < nexpo)
nexpo = g_nexp[scan[0][BLU]];
if (nexpo < g_nexp[scan[0][RED]])
scan[0][RED] = g_mant[scan[0][RED]]
>> (g_nexp[scan[0][RED]]-nexpo);
else
scan[0][RED] = g_mant[scan[0][RED]];
if (nexpo < g_nexp[scan[0][GRN]])
scan[0][GRN] = g_mant[scan[0][GRN]]
>> (g_nexp[scan[0][GRN]]-nexpo);
else
scan[0][GRN] = g_mant[scan[0][GRN]];
if (nexpo < g_nexp[scan[0][BLU]])
scan[0][BLU] = g_mant[scan[0][BLU]]
>> (g_nexp[scan[0][BLU]]-nexpo);
else
scan[0][BLU] = g_mant[scan[0][BLU]];
scan[0][EXP] = COLXS - nexpo;
scan++;
}
return(0);
}
void
shiftcolrs(scan, len, adjust) /* shift a scanline of colors by 2^adjust */
register COLR *scan;
register int len;
register int adjust;
{
int minexp;
if (adjust == 0)
return;
minexp = adjust < 0 ? -adjust : 0;
while (len-- > 0) {
if (scan[0][EXP] <= minexp)
scan[0][RED] = scan[0][GRN] = scan[0][BLU] =
scan[0][EXP] = 0;
else
scan[0][EXP] += adjust;
scan++;
}
}
void
normcolrs(scan, len, adjust) /* normalize a scanline of colrs */
register COLR *scan;
int len;
int adjust;
{
register int c;
register int shift;
while (len-- > 0) {
shift = scan[0][EXP] + adjust - COLXS;
if (shift > 0) {
if (shift > 8) {
scan[0][RED] =
scan[0][GRN] =
scan[0][BLU] = 255;
} else {
shift--;
c = (scan[0][RED]<<1 | 1) << shift;
scan[0][RED] = c > 255 ? 255 : c;
c = (scan[0][GRN]<<1 | 1) << shift;
scan[0][GRN] = c > 255 ? 255 : c;
c = (scan[0][BLU]<<1 | 1) << shift;
scan[0][BLU] = c > 255 ? 255 : c;
}
} else if (shift < 0) {
if (shift < -8) {
scan[0][RED] =
scan[0][GRN] =
scan[0][BLU] = 0;
} else {
shift = -1-shift;
scan[0][RED] = ((scan[0][RED]>>shift)+1)>>1;
scan[0][GRN] = ((scan[0][GRN]>>shift)+1)>>1;
scan[0][BLU] = ((scan[0][BLU]>>shift)+1)>>1;
}
}
scan[0][EXP] = COLXS - adjust;
scan++;
}
}

View File

@ -1,84 +0,0 @@
/* RCSid $Id: resolu.h,v 2.10 2005/02/01 01:28:16 greg Exp $ */
/*
* Definitions for resolution line in image file.
*
* Include after <stdio.h>
*
* True image orientation is defined by an xy coordinate system
* whose origin is at the lower left corner of the image, with
* x increasing to the right and y increasing in the upward direction.
* This true orientation is independent of how the pixels are actually
* ordered in the file, which is indicated by the resolution line.
* This line is of the form "{+-}{XY} xyres {+-}{YX} yxres\n".
* A typical line for a 1024x600 image might be "-Y 600 +X 1024\n",
* indicating that the scanlines are in English text order (PIXSTANDARD).
*/
#ifndef _RAD_RESOLU_H_
#define _RAD_RESOLU_H_
#include <time.h>
#ifdef __cplusplus
extern "C" {
#endif
/* flags for scanline ordering */
#define XDECR 1
#define YDECR 2
#define YMAJOR 4
/* standard scanline ordering */
#define PIXSTANDARD (YMAJOR|YDECR)
#define PIXSTDFMT "-Y %d +X %d\n"
/* structure for image dimensions */
typedef struct {
int rt; /* orientation (from flags above) */
int xr, yr; /* x and y resolution */
} RESOLU;
/* macros to get scanline length and number */
#define scanlen(rs) ((rs)->rt & YMAJOR ? (rs)->xr : (rs)->yr)
#define numscans(rs) ((rs)->rt & YMAJOR ? (rs)->yr : (rs)->xr)
/* resolution string buffer and its size */
#define RESOLU_BUFLEN 32
extern char resolu_buf[RESOLU_BUFLEN];
/* macros for reading/writing resolution struct */
#define fputsresolu(rs,fp) fputs(resolu2str(resolu_buf,rs),fp)
#define fgetsresolu(rs,fp) str2resolu(rs, \
fgets(resolu_buf,RESOLU_BUFLEN,fp))
/* reading/writing of standard ordering */
#define fprtresolu(sl,ns,fp) fprintf(fp,PIXSTDFMT,ns,sl)
#define fscnresolu(sl,ns,fp) (fscanf(fp,PIXSTDFMT,ns,sl)==2)
/* defined in resolu.c */
extern void fputresolu(int ord, int sl, int ns, FILE *fp);
extern int fgetresolu(int *sl, int *ns, FILE *fp);
extern char * resolu2str(char *buf, RESOLU *rp);
extern int str2resolu(RESOLU *rp, char *buf);
/* defined in header.c */
extern void newheader(char *t, FILE *fp);
extern int isheadid(char *s);
extern int headidval(char *r, char *s);
extern int dateval(time_t *t, char *s);
extern int isdate(char *s);
extern void fputdate(time_t t, FILE *fp);
extern void fputnow(FILE *fp);
extern void printargs(int ac, char **av, FILE *fp);
extern int isformat(char *s);
extern int formatval(char *r, char *s);
extern void fputformat(char *s, FILE *fp);
typedef int gethfunc(char *s, void *p); /* callback to process header lines */
extern int getheader(FILE *fp, gethfunc *f, void *p);
extern int globmatch(char *pat, char *str);
extern int checkheader(FILE *fin, char *fmt, FILE *fout);
#ifdef __cplusplus
}
#endif
#endif /* _RAD_RESOLU_H_ */

View File

@ -1,86 +0,0 @@
/* RCSid $Id: rtio.h,v 3.9 2006/12/23 17:27:45 greg Exp $ */
/*
* Radiance i/o and string routines
*/
#ifndef _RAD_RTIO_H_
#define _RAD_RTIO_H_
#include <stdio.h>
#include <sys/types.h>
#include <fcntl.h>
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
/* defined in badarg.c */
extern int badarg(int ac, char **av, char *fl);
/* defined in expandarg.c */
extern int expandarg(int *acp, char ***avp, int n);
/* defined in fdate.c */
extern time_t fdate(char *fname);
extern int setfdate(char *fname, long ftim);
/* defined in fgetline.c */
extern char *fgetline(char *s, int n, FILE *fp);
/* defined in fgetval.c */
extern int fgetval(FILE *fp, int ty, void *vp);
/* defined in fgetword.c */
extern char *fgetword(char *s, int n, FILE *fp);
/* defined in fputword.c */
extern void fputword(char *s, FILE *fp);
/* defined in fropen.c */
extern FILE *frlibopen(char *fname);
/* defined in getlibpath.c */
extern char *getrlibpath(void);
/* defined in gethomedir.c */
extern char *gethomedir(char *uname, char *path, int plen);
/* defined in getpath.c */
extern char *getpath(char *fname, char *searchpath, int mode);
/* defined in byteswap.c */
extern void swap16(char *wp, int n);
extern void swap32(char *wp, int n);
extern void swap64(char *wp, int n);
/* defined in portio.c */
extern void putstr(char *s, FILE *fp);
extern void putint(long i, int siz, FILE *fp);
extern void putflt(double f, FILE *fp);
extern char *getstr(char *s, FILE *fp);
extern long getint(int siz, FILE *fp);
extern double getflt(FILE *fp);
/* defined in rexpr.c */
extern int ecompile(char *sp, int iflg, int wflag);
extern char *expsave(void);
extern void expset(char *ep);
extern char *eindex(char *sp);
/* defined in savestr.c */
extern char *savestr(char *str);
extern void freestr(char *s);
extern int shash(char *s);
/* defined in savqstr.c */
extern char *savqstr(char *s);
extern void freeqstr(char *s);
/* defined in wordfile.c */
extern int wordfile(char **words, char *fname);
extern int wordstring(char **avl, char *str);
/* defined in words.c */
extern char *atos(char *rs, int nb, char *s);
extern char *nextword(char *cp, int nb, char *s);
extern char *sskip(char *s);
extern char *sskip2(char *s, int n);
extern char *iskip(char *s);
extern char *fskip(char *s);
extern int isint(char *s);
extern int isintd(char *s, char *ds);
extern int isflt(char *s);
extern int isfltd(char *s, char *ds);
/* defined in lamp.c */
extern float * matchlamp(char *s);
extern int loadlamps(char *file);
extern void freelamps(void);
#ifdef __cplusplus
}
#endif
#endif /* _RAD_RTIO_H_ */