Commit a859bfec4823af8b7b558a76470c443972f31ccb
1 parent
b91288ec
Finaly working properly
Showing
1 changed file
with
79 additions
and
0 deletions
Show diff stats
@@ -11,6 +11,8 @@ int main(int argc, char *argv[]) | @@ -11,6 +11,8 @@ int main(int argc, char *argv[]) | ||
11 | 11 | ||
12 | FILE* src = NULL; | 12 | FILE* src = NULL; |
13 | FILE* dst = NULL; | 13 | FILE* dst = NULL; |
14 | + unsigned char buffer[5]; | ||
15 | + int initOffsetBMP; | ||
14 | 16 | ||
15 | src = fopen(argv[1], "r"); | 17 | src = fopen(argv[1], "r"); |
16 | dst = fopen(argv[2], "w"); | 18 | dst = fopen(argv[2], "w"); |
@@ -27,5 +29,82 @@ int main(int argc, char *argv[]) | @@ -27,5 +29,82 @@ int main(int argc, char *argv[]) | ||
27 | return 3; | 29 | return 3; |
28 | } | 30 | } |
29 | 31 | ||
32 | + printf("Reading BMP\n"); | ||
33 | + | ||
34 | + fseek(src, 0x0A, SEEK_SET); | ||
35 | + buffer[0] = getc(src); | ||
36 | + buffer[1] = getc(src); | ||
37 | + buffer[2] = getc(src); | ||
38 | + buffer[3] = getc(src); | ||
39 | + printf("Pixel array offset %02x %02x %02x %02x\n", buffer[3], buffer[2], buffer[1], buffer[0]); | ||
40 | + initOffsetBMP = buffer[0] + (buffer[1] >> 8) + (buffer[2] >> 16) + (buffer[3] >> 24); | ||
41 | + | ||
42 | + fseek(src, 0x12, SEEK_SET); | ||
43 | + buffer[0] = getc(src); | ||
44 | + buffer[1] = getc(src); | ||
45 | + buffer[2] = getc(src); | ||
46 | + buffer[3] = getc(src); | ||
47 | + printf("Width %02x %02x %02x %02x\n", buffer[3], buffer[2], buffer[1], buffer[0]); | ||
48 | + | ||
49 | + //fseek(src, 0x12, SEEK_SET); | ||
50 | + buffer[0] = getc(src); | ||
51 | + buffer[1] = getc(src); | ||
52 | + buffer[2] = getc(src); | ||
53 | + buffer[3] = getc(src); | ||
54 | + printf("Height %02x %02x %02x %02x\n", buffer[3], buffer[2], buffer[1], buffer[0]); | ||
55 | + | ||
56 | + fseek(src, 0x1C, SEEK_SET); | ||
57 | + buffer[0] = getc(src); | ||
58 | + buffer[1] = getc(src); | ||
59 | + printf("Bits Per Pixel %02x %02x\n", buffer[0], buffer[1]); | ||
60 | + | ||
61 | + if(buffer[1] != 0 || buffer[0] != 0x18) | ||
62 | + { | ||
63 | + printf("Could not read BMP\n"); | ||
64 | + return 1; | ||
65 | + } | ||
66 | + | ||
67 | + fseek(src, initOffsetBMP, SEEK_SET); | ||
68 | + | ||
69 | + printf("Now reading BMP pixels and printing them to the RBG565 file\n"); | ||
70 | + while(1) | ||
71 | + { | ||
72 | + buffer[0] = getc(src); | ||
73 | + buffer[1] = getc(src); | ||
74 | + buffer[2] = getc(src); | ||
75 | + if(feof(src)) | ||
76 | + break; | ||
77 | + printf("Pixel BMP 24 bits R %02X G %02X B %02X ", buffer[2], buffer[1], buffer[0]); | ||
78 | + buffer[2] = buffer[2] >> 3; //R | ||
79 | + buffer[1] = buffer[1] >> 2; //G | ||
80 | + buffer[0] = buffer[0] >> 3; //B | ||
81 | + printf("-> RGB 565 R %02X G %02X B %02X ", buffer[2], buffer[1], buffer[0]); | ||
82 | + buffer[3] = ((buffer[0] & 0x1F) << 3) + ((buffer[1] & 0x38) >> 3); | ||
83 | + buffer[4] = ((buffer[1] & 0x07) << 5) + (buffer[2] & 0x1F); | ||
84 | + printf("-> RGB 565 M %02X%02X\n", buffer[3], buffer[4]); | ||
85 | + fprintf(dst, "%c%c", buffer[4], buffer[3]); | ||
86 | + } | ||
87 | + | ||
88 | + printf("Done !\n"); | ||
89 | + | ||
90 | + fclose(src); | ||
91 | + fclose(dst); | ||
92 | + | ||
30 | return 0; | 93 | return 0; |
31 | } | 94 | } |
95 | + | ||
96 | + | ||
97 | + | ||
98 | + | ||
99 | + | ||
100 | + | ||
101 | + | ||
102 | + | ||
103 | + | ||
104 | + | ||
105 | + | ||
106 | + | ||
107 | + | ||
108 | + | ||
109 | + | ||
110 | + |