-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
97 lines (69 loc) · 2.33 KB
/
main.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
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
/* Convert 1-bit GIMP .h file to GLCD-compatible bitmap .h-file.
In essence it does the same as Michael Margolis's glcdBitmap sketch,
however this program is written from scratch without looking at his code.
Author: Kristian Gunstone
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
// GIMP 1-bit header file. header_data_cmap will be ignored.
#include "SOURCE.h"
int main(int argc, const char *argv[]) {
assert(argc == 2);
const char *file_out = argv[1];
FILE *fp;
fp = fopen(file_out, "wb");
if(fp == NULL) {
perror("fopen");
return(EXIT_FAILURE);
}
if((float) width / 8 != abs(width / 8))
printf("%d is not padded!\n", width);
if((float) height / 8 != abs(height / 8))
printf("%d is not padded!\n", height);
printf("%dx%d\n", width, height);
fprintf(fp,
"// This file is autogenerated.\n"
"#include <inttypes.h>\n"
"#include <avr/pgmspace.h>\n\n"
"static uint8_t bitmap[] PROGMEM = {\n"
"\t%3d, // Width\n"
"\t%3d, // height\n\n"
"\t// Bit packed image data (%d bytes)\n",
width, height, width * height / 8);
size_t offset = 0;
int x, y, page;
// Page is the vertical bank
for(page = 0; page < (height / 8); page ++) {
fprintf(fp, "\n\t// Page %02d\n\t", page);
// horizontal traversion in st
for(x = 0; x < width; x++) {
uint8_t byte = 0;
// Packing (vertical pixels)
for(y = 0; y < 8; y++) {
long bit = x + (((page * 8) + y) * width);
byte ^= header_data[bit] << y;
}
fprintf(fp, "0x%02x,", byte);
if(x % 8 == 7)
fprintf(fp, "\n\t");
offset++;
}
}
printf("%d bytes, %d pages.\n", (int) offset, page);
fprintf(fp, "\n};\n");
fclose(fp);
return(EXIT_SUCCESS);
}