1 |
/* Copyright (c) 1986 Regents of the University of California */ |
2 |
|
3 |
/* SCCSid "$SunId$ LBL" */ |
4 |
|
5 |
/* |
6 |
* color.h - header for routines using pixel color values. |
7 |
* |
8 |
* 12/31/85 |
9 |
* |
10 |
* Two color representations are used, one for calculation and |
11 |
* another for storage. Calculation is done with three floats |
12 |
* for speed. Stored color values use 4 bytes which contain |
13 |
* three single byte mantissas and a common exponent. |
14 |
*/ |
15 |
|
16 |
#define RED 0 |
17 |
#define GRN 1 |
18 |
#define BLU 2 |
19 |
#define EXP 3 |
20 |
#define COLXS 128 /* excess used for exponent */ |
21 |
|
22 |
typedef unsigned char BYTE; /* 8-bit unsigned integer */ |
23 |
|
24 |
typedef BYTE COLR[4]; /* red, green, blue, exponent */ |
25 |
|
26 |
#define copycolr(c1,c2) (c1[0]=c2[0],c1[1]=c2[1], \ |
27 |
c1[2]=c2[2],c1[3]=c2[3]) |
28 |
|
29 |
typedef float COLOR[3]; /* red, green, blue */ |
30 |
|
31 |
#define colval(col,pri) ((col)[pri]) |
32 |
|
33 |
#define setcolor(col,r,g,b) ((col)[RED]=(r),(col)[GRN]=(g),(col)[BLU]=(b)) |
34 |
|
35 |
#define copycolor(c1,c2) ((c1)[0]=(c2)[0],(c1)[1]=(c2)[1],(c1)[2]=(c2)[2]) |
36 |
|
37 |
#define scalecolor(col,sf) ((col)[0]*=(sf),(col)[1]*=(sf),(col)[2]*=(sf)) |
38 |
|
39 |
#define addcolor(c1,c2) ((c1)[0]+=(c2)[0],(c1)[1]+=(c2)[1],(c1)[2]+=(c2)[2]) |
40 |
|
41 |
#define multcolor(c1,c2) ((c1)[0]*=(c2)[0],(c1)[1]*=(c2)[1],(c1)[2]*=(c2)[2]) |
42 |
|
43 |
#ifdef NTSC |
44 |
#define bright(col) (.295*(col)[RED]+.636*(col)[GRN]+.070*(col)[BLU]) |
45 |
#define normbright(c) (int)((74L*(c)[RED]+164L*(c)[GRN]+18L*(c)[BLU])/256) |
46 |
#else |
47 |
#define bright(col) (.263*(col)[RED]+.655*(col)[GRN]+.082*(col)[BLU]) |
48 |
#define normbright(c) (int)((67L*(c)[RED]+168L*(c)[GRN]+21L*(c)[BLU])/256) |
49 |
#endif |
50 |
|
51 |
#define intens(col) ( (col)[0] > (col)[1] \ |
52 |
? (col)[0] > (col)[2] ? (col)[0] : (col)[2] \ |
53 |
: (col)[1] > (col)[2] ? (col)[1] : (col)[2] ) |
54 |
|
55 |
#define colrval(c,p) ( (c)[EXP] ? \ |
56 |
ldexp((c)[p]+.5,(int)(c)[EXP]-(COLXS+8)) : \ |
57 |
0. ) |
58 |
|
59 |
#define WHTCOLOR {1.0,1.0,1.0} |
60 |
#define BLKCOLOR {0.0,0.0,0.0} |
61 |
#define WHTCOLR {128,128,128,COLXS+1} |
62 |
#define BLKCOLR {0,0,0,0} |
63 |
|
64 |
/* definitions for resolution header */ |
65 |
#define XDECR 1 |
66 |
#define YDECR 2 |
67 |
#define YMAJOR 4 |
68 |
|
69 |
/* macros for exposures */ |
70 |
#define EXPOSSTR "EXPOSURE=" |
71 |
#define EXPOSSTRL 9 |
72 |
#define isexpos(hl) (!strncmp(hl,EXPOSSTR,EXPOSSTRL)) |
73 |
#define exposval(hl) atof((hl)+EXPOSSTRL) |
74 |
#define fputexpos(ex,fp) fprintf(fp,"%s%e\n",EXPOSSTR,ex) |
75 |
|
76 |
/* macros for pixel aspect ratios */ |
77 |
#define ASPECTSTR "PIXASPECT=" |
78 |
#define ASPECTSTRL 10 |
79 |
#define isaspect(hl) (!strncmp(hl,ASPECTSTR,ASPECTSTRL)) |
80 |
#define aspectval(hl) atof((hl)+ASPECTSTRL) |
81 |
#define fputaspect(pa,fp) fprintf(fp,"%s%f\n",ASPECTSTR,pa) |
82 |
|
83 |
extern double ldexp(), atof(); |