FreeCalypso > hg > freecalypso-tools
comparison miscutil/fc-rgbconv.c @ 0:e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 11 Jun 2016 00:13:35 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e7502631a0f9 |
---|---|
1 /* | |
2 * This utility is an aid for phone UI development. The color LCDs in the | |
3 * phones targeted by FreeCalypso implement 16-bit color in RGB 5:6:5 format, | |
4 * but these 16-bit color words are not particularly intuitive in raw hex form. | |
5 * In contrast, a 24-bit RGB 8:8:8 color given in RRGGBB hex form is quite | |
6 * intuitive, at least to those who understand RGB. | |
7 * | |
8 * This utility performs the conversion. It takes a single command line | |
9 * argument that must be either 4 or 6 hex digits. If the argument is 4 hex | |
10 * digits, it is interpreted as RGB 5:6:5 and converted into RGB 8:8:8. | |
11 * If the argument is 6 hex digits, it is interpreted as RGB 8:8:8 and | |
12 * converted into RGB 5:6:5. The output of the conversion is emitted on | |
13 * stdout as 4 or 6 hex digits. | |
14 */ | |
15 | |
16 #include <stdio.h> | |
17 #include <stdlib.h> | |
18 #include <ctype.h> | |
19 #include <string.h> | |
20 | |
21 is_arg_all_hex(str) | |
22 char *str; | |
23 { | |
24 char *cp; | |
25 int c; | |
26 | |
27 for (cp = str; c = *cp++; ) | |
28 if (!isxdigit(c)) | |
29 return(0); | |
30 return(1); | |
31 } | |
32 | |
33 convert_565_to_888(in) | |
34 unsigned in; | |
35 { | |
36 unsigned r, g, b; | |
37 | |
38 r = in >> 11; | |
39 g = (in >> 5) & 0x3F; | |
40 b = in & 0x1F; | |
41 printf("%02X%02X%02X\n", r << 3, g << 2, b << 3); | |
42 } | |
43 | |
44 convert_888_to_565(in) | |
45 unsigned in; | |
46 { | |
47 unsigned r, g, b; | |
48 | |
49 r = (in >> 16) >> 3; | |
50 g = ((in >> 8) & 0xFF) >> 2; | |
51 b = (in & 0xFF) >> 3; | |
52 printf("%04X\n", (r << 11) | (g << 5) | b); | |
53 } | |
54 | |
55 main(argc, argv) | |
56 char **argv; | |
57 { | |
58 unsigned in; | |
59 | |
60 if (argc != 2) { | |
61 usage: fprintf(stderr, | |
62 "please specify one 4-digit or 6-digit hex RGB value\n"); | |
63 exit(1); | |
64 } | |
65 if (!is_arg_all_hex(argv[1])) | |
66 goto usage; | |
67 in = strtoul(argv[1], 0, 16); | |
68 switch (strlen(argv[1])) { | |
69 case 4: | |
70 convert_565_to_888(in); | |
71 exit(0); | |
72 case 6: | |
73 convert_888_to_565(in); | |
74 exit(0); | |
75 } | |
76 goto usage; | |
77 } |