# HG changeset patch # User John Tsiombikas # Date 1508954724 -10800 # Node ID 6320a20f17c5855f3488fc46bcf7c12d86377b21 # Parent a4788c95991855fe759e02ae07a063d4d913107a file formats in comments diff -r a4788c959918 -r 6320a20f17c5 tools/convhammer/main.c --- a/tools/convhammer/main.c Wed Oct 25 19:34:53 2017 +0300 +++ b/tools/convhammer/main.c Wed Oct 25 21:05:24 2017 +0300 @@ -1,10 +1,99 @@ #include #include +#include +#include #include "image.h" +/* hammer dump format (input) + * byte order: little endian + * + * 4 bytes: palette changes per scanline (cps) + * 256 * cps * 2 bytes: [ idx | r | g | b ] + * 320 * 256 bytes: linear HAM pixels + */ + +/* interleaved ham format (output) + * byte order: big endian + * + * 4 bytes: magic: "HAAM" + * 2 bytes: width + * 2 bytes: height + * 1 byte: number of bitplanes + * 1 byte: padding + * 2 bytes: number of palette change descriptors (nchg) + * 16 * 2 bytes: initial palette [ x | r | g | b ] + * nchg * 4 bytes: [ scanline ] [ idx | r | g | b ] + * width * height / 8 * bitplanes bytes: pixels interleaved scanlines + * [ row0 bpl0 ] ... [ row0 bplN ] [ row1 bpl0 ] ... [ row1 bplN ] ... + */ + struct ham_image *load_hammer(const char *fname); int save_ham(struct ham_image *img, const char *fname); +void free_image(struct ham_image *img); int main(int argc, char **argv) { + int i; + struct ham_image *img; + char *name, *dot; + + for(i=1; iwidth); + fwrite(fp, 2, 1, &val); + val = htons(img->height); + fwrite(fp, 2, 1, &val); + /* TODO: continue */ +} + +void free_image(struct ham_image *img) +{ + if(img) { + free(img->pixels); + while(img->chglist) { + void *tmp = img->chglist; + img->chglist = img->chglist->next; + free(tmp); + } + free(img); + } +}