ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/colorscale.c
Revision: 2.5
Committed: Sun Mar 28 20:33:13 2004 UTC (20 years ago) by schorsch
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R6P1, rad3R6
Changes since 2.4: +17 -9 lines
Log Message:
Continued ANSIfication, and other fixes and clarifications.

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: colorscale.c,v 2.4 2003/02/22 02:07:27 greg Exp $";
3 #endif
4 /*
5 * colorscale.c - program to produce color pallets
6 *
7 * 9/9/87
8 */
9
10 #include <stdio.h>
11
12 #include <math.h>
13
14 #include "color.h"
15
16 int primary = -1;
17 double prival = 0.0;
18
19 static void colorscale(void);
20 static void printargs(int ac, char **av, FILE *fp);
21
22
23 int
24 main(
25 int argc,
26 char *argv[]
27 )
28 {
29 int i;
30
31 for (i = 1; i < argc && argv[i][0] == '-'; i++)
32 switch (argv[i][1]) {
33 case 'r':
34 primary = RED;
35 prival = atof(argv[++i]);
36 break;
37 case 'g':
38 primary = GRN;
39 prival = atof(argv[++i]);
40 break;
41 case 'b':
42 primary = BLU;
43 prival = atof(argv[++i]);
44 break;
45 default:
46 goto userr;
47 }
48 if (primary < 0 || i < argc)
49 goto userr;
50 printargs(argc, argv, stdout);
51 printf("\n");
52 printf("-Y 256 +X 256\n");
53 colorscale();
54 exit(0);
55 userr:
56 fprintf(stderr, "Usage: %s -r|-g|-b value\n", argv[0]);
57 exit(1);
58 }
59
60
61 static void
62 colorscale(void) /* output our color scale */
63 {
64 COLOR scanline[256];
65 int j;
66 register int i;
67
68 for (j = 256-1; j >= 0; j--) {
69 for (i = 0; i < 256; i++)
70 switch (primary) {
71 case RED:
72 setcolor(scanline[i],prival,i/256.0,j/256.0);
73 break;
74 case GRN:
75 setcolor(scanline[i],i/256.0,prival,j/256.0);
76 break;
77 case BLU:
78 setcolor(scanline[i],i/256.0,j/256.0,prival);
79 break;
80 }
81 if (fwritescan(scanline, 256, stdout) < 0)
82 goto writerr;
83 }
84 return;
85 writerr:
86 fprintf(stderr, "write error in colorscale\n");
87 exit(1);
88 }
89
90
91 static void
92 printargs( /* print arguments to a file */
93 int ac,
94 char **av,
95 FILE *fp
96 )
97 {
98 while (ac-- > 0) {
99 fputs(*av++, fp);
100 putc(' ', fp);
101 }
102 putc('\n', fp);
103 }