-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbin.c
58 lines (49 loc) · 1.32 KB
/
bin.c
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
#include <stdio.h>
#include <stdint.h>
extern unsigned char cry[];
static unsigned int
do_cry(unsigned char red, unsigned char green, unsigned char blue)
{
unsigned int intensity;
unsigned int color_offset; /* offset for cry lookup table */
unsigned int result;
unsigned int rcomp,gcomp,bcomp;
intensity = red; /* start with red */
if(green > intensity)
intensity = green;
if(blue > intensity)
intensity = blue; /* get highest RGB value */
if(intensity != 0)
{
rcomp = (unsigned int)red * 255 / intensity;
gcomp = (unsigned int)green * 255 / intensity;
bcomp = (unsigned int)blue * 255 / intensity;
}
else
rcomp = gcomp = bcomp = 0; /* R, G, B, were all 0 (black) */
color_offset = (rcomp & 0xF8) << 7;
color_offset |= (gcomp & 0xF8) << 2;
color_offset |= (bcomp & 0xF8) >> 3; /* now we have offset for cry table */
result = ((color_offset = cry[color_offset]) << 8) | intensity;
return result;
}
int
main()
{
uint32_t i;
unsigned char red, green, blue;
unsigned int output;
FILE *f;
printf("Create a CRY binary file (cry.bin).\n");
f = fopen("cry.bin", "wb");
for (i = 0; i < 2*32768; i++) {
red = ((i>>11) & 0x1f) << 3;
blue = ((i>>6) & 0x1f) << 3;
green = (i & 0x3f) << 2;
output = do_cry(red, green, blue);
fputc((output >> 8), f);
fputc((output & 0xff), f);
}
fclose(f);
return 0;
}