On Sun, 10 Jan 2010, Vincent Trouilliez wrote: > - What's the usual/easiest file format that people use, to store > 1-bit (black and white) bitmap images/pictures ?
I just use a raw binary dump and wrote a small program to convert from
PNG (because libpng had good docs :) to it.
This image is displayed for ~2 seconds when the device (pulsed
transmitter) starts up.
I've attached the program.
If I had to generate a font table I would probably just make an image
which contained each glyph in whatever order was most convenient and
store that in flash.
Unless you're storing on some sort of "shared" medium (ie CF, SD card
etc) then I don't really see the point of an image parser, you may as
well do all the work on the PC and make the micro('s programmers) job
easier :)
--
Daniel O'Connor software and network engineer
for Genesis Software - http://www.gsoft.com.au
"The nice thing about standards is that there
are so many of them to choose from."
-- Andrew Tanenbaum
GPG Fingerprint - 5596 B766 97C0 0E94 4347 295E E593 DC20 7B3F CE8C
#include <stdio.h>
#include <stdlib.h>
#include <sys/errno.h>
#include <png.h>
int
main(int argc, char **argv) {
FILE *ifp, *ofp;
u_int8_t header[8];
png_structp png_ptr;
png_infop info_ptr;
png_infop end_info;
png_bytep *row_pointers;
png_uint_32 width, height;
int depth, channels, y;
if ((png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL)) == NULL) {
fprintf(stderr, "Unable to init PNG library\n");
exit(1);
}
if ((info_ptr = png_create_info_struct(png_ptr)) == NULL) {
fprintf(stderr, "Unable to create PNG info struct\n");
png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
exit(1);
}
if ((end_info = png_create_info_struct(png_ptr)) == NULL) {
fprintf(stderr, "Unable to create PNG end info struct\n");
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
exit(1);
}
if (argc != 3) {
fprintf(stderr, "Bad usage\n");
fprintf(stderr, "\t%s filename.png outputfile\n", argv[0]);
exit(1);
}
if (strcmp(argv[1], "-")) {
if ((ifp = fopen(argv[1], "rb")) == NULL) {
fprintf(stderr, "Unable to open '%s' - %s\n", argv[1], strerror(errno));
exit(1);
}
} else
ifp = stdin;
if (strcmp(argv[2], "-")) {
if ((ofp = fopen(argv[2], "w")) == NULL) {
fprintf(stderr, "Unable to open '%s' for writing - %s\n", argv[2], strerror(errno));
exit(1);
}
} else
ofp = stdout;
fread(header, 1, sizeof(header), ifp);
if (png_sig_cmp(header, 0, sizeof(header))) {
fprintf(stderr, "'%s' does not appear to be a PNG file\n", argv[1]);
exit(1);
}
fprintf(stderr, "Valid PNG file found\n");
png_init_io(png_ptr, ifp);
png_set_sig_bytes(png_ptr, sizeof(header));
png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_STRIP_16 | PNG_TRANSFORM_STRIP_ALPHA | PNG_TRANSFORM_PACKSWAP, NULL);
width = png_get_image_width(png_ptr, info_ptr);
height = png_get_image_height(png_ptr, info_ptr);
depth = png_get_bit_depth(png_ptr, info_ptr);
channels = png_get_channels(png_ptr, info_ptr);
fprintf(stderr, "Image is %d x %d pixels, depth %d, channels %d\n", (int)width, (int)height, depth, channels);
if (depth != 1 || channels != 1 || width != 240 || height != 64) {
fprintf(stderr, "Unvalid format, unable to continue\n"
"Must be 240x64 black and white image with no alpha\n");
exit(1);
}
if ((row_pointers = png_get_rows(png_ptr, info_ptr)) == NULL) {
fprintf(stderr, "Failed to read PNG into memory\n");
exit(1);
}
for (y = 0; y < height; y++)
fwrite(row_pointers[y], width / 8, 1, ofp);
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
fclose(ifp);
fclose(ofp);
exit(0);
}
signature.asc
Description: This is a digitally signed message part.
_______________________________________________ AVR-chat mailing list [email protected] http://lists.nongnu.org/mailman/listinfo/avr-chat
