Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
98 lines (69 sloc) 2.33 KB
/* 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);
}