pattern_generator.c
4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#include <stdio.h>
#include <stdlib.h>
#ifdef __linux__
#include <getopt.h>
#endif
#define DEFAULT_WIDTH 640
#define DEFAULT_HEIGHT 480
#define DEFAULT_FORMAT 0
#define NUM_COLORBARS 8
#define BLACK_16_75 0x0000
#define BLUE_16_75 0x0038
#define GREEN_16_75 0x0700
#define RED_16_75 0xe000
#define CYAN_16_75 (BLUE_16_75 | GREEN_16_75)
#define MAGENTA_16_75 (BLUE_16_75 | RED_16_75)
#define YELLOW_16_75 (GREEN_16_75 | RED_16_75)
#define WHITE_16_75 (BLUE_16_75 | GREEN_16_75 | RED_16_75)
#define BLACK_16_100 0x0000
#define BLUE_16_100 0x003e
#define GREEN_16_100 0x07c0
#define RED_16_100 0xf800
#define CYAN_16_100 (BLUE_16_100 | GREEN_16_100)
#define MAGENTA_16_100 (BLUE_16_100 | RED_16_100)
#define YELLOW_16_100 (GREEN_16_100 | RED_16_100)
#define WHITE_16_100 (BLUE_16_100 | GREEN_16_100 | RED_16_100)
#define BLACK_32_75 0x00000000
#define BLUE_32_75 0x0000c000
#define GREEN_32_75 0x00c00000
#define RED_32_75 0xc0000000
#define CYAN_32_75 (BLUE_32_75 | GREEN_32_75)
#define MAGENTA_32_75 (BLUE_32_75 | RED_32_75)
#define YELLOW_32_75 (GREEN_32_75 | RED_32_75)
#define WHITE_32_75 (BLUE_32_75 | GREEN_32_75 | RED_32_75)
#define BLACK_32_100 0x00000000
#define BLUE_32_100 0x0000ff00
#define GREEN_32_100 0x00ff0000
#define RED_32_100 0xff000000
#define CYAN_32_100 (BLUE_32_100 | GREEN_32_100)
#define MAGENTA_32_100 (BLUE_32_100 | RED_32_100)
#define YELLOW_32_100 (GREEN_32_100 | RED_32_100)
#define WHITE_32_100 (BLUE_32_100 | GREEN_32_100 | RED_32_100)
const int Colorbar_Pattern_16_75[NUM_COLORBARS] = {
WHITE_16_75,
YELLOW_16_75,
CYAN_16_75,
GREEN_16_75,
MAGENTA_16_75,
RED_16_75,
BLUE_16_75,
BLACK_16_75,
};
const int Colorbar_Pattern_16_100[NUM_COLORBARS] = {
WHITE_16_100,
YELLOW_16_100,
CYAN_16_100,
GREEN_16_100,
MAGENTA_16_100,
RED_16_100,
BLUE_16_100,
BLACK_16_100,
};
const int Colorbar_Pattern_32_75[NUM_COLORBARS] = {
WHITE_32_75,
YELLOW_32_75,
CYAN_32_75,
GREEN_32_75,
MAGENTA_32_75,
RED_32_75,
BLUE_32_75,
BLACK_32_75,
};
const int Colorbar_Pattern_32_100[NUM_COLORBARS] = {
WHITE_32_100,
YELLOW_32_100,
CYAN_32_100,
GREEN_32_100,
MAGENTA_32_100,
RED_32_100,
BLUE_32_100,
BLACK_32_100,
};
void
main (int argc, char **argv) {
FILE *file_p;
int c;
int scanline;
int colorbar_width;
int colorbar_saturation = 100;
const int *colorbar_pattern = Colorbar_Pattern_16_100;
int frame_width = DEFAULT_WIDTH;
int frame_height = DEFAULT_HEIGHT;
int frame_depth = 16;
file_p = stdout;
while ((c = getopt(argc, argv, "w:h:s:d:o:")) != EOF) {
switch (c) {
case 'w':
frame_width = atoi(optarg);
break;
case 'h':
frame_height = atoi(optarg);
break;
case 's':
colorbar_saturation = atoi(optarg);
break;
case 'd':
frame_depth = atoi(optarg);
break;
case 'o':
if ((file_p = fopen(optarg, "w")) == NULL) {
perror(argv[0]);
exit(1);
}
break;
default:
fprintf(stderr, "usage: %s -w width -h height -s saturation -d depth -o file\n",
argv[0]);
exit(1);
}
}
if (colorbar_saturation == 75)
if (frame_depth == 16)
colorbar_pattern = Colorbar_Pattern_16_75;
else if (frame_depth == 32)
colorbar_pattern = Colorbar_Pattern_32_75;
else {
fprintf(stderr, "%s: depth must be either 16 or 32", argv[0]);
exit(1);
}
else if (colorbar_saturation == 100)
if (frame_depth == 16)
colorbar_pattern = Colorbar_Pattern_16_100;
else if (frame_depth == 32)
colorbar_pattern = Colorbar_Pattern_32_100;
else {
fprintf(stderr, "%s: depth must be either 16 or 32", argv[0]);
exit(1);
}
else {
fprintf(stderr, "%s: saturation must be either 75 or 100", argv[0]);
exit(1);
}
fprintf(file_p, "# width %d\n", frame_width);
fprintf(file_p, "# height %d\n", frame_height);
fprintf(file_p, "# depth %d\n", frame_depth);
colorbar_width = frame_width / NUM_COLORBARS;
for (scanline = 0; scanline < frame_height; scanline++) {
int colorbar;
int i;
int unused_width = frame_width % NUM_COLORBARS;
fprintf(file_p, "# scanline %d\n", scanline);
for (colorbar = 0; colorbar < NUM_COLORBARS; colorbar++) {
for (i = 0; i < colorbar_width; i++) {
fprintf(file_p, "%x\n", colorbar_pattern[colorbar]);
}
if (unused_width) {
fprintf(file_p, "%x\n", colorbar_pattern[colorbar]);
unused_width--;
}
}
}
exit(0);
}