fixed 8bit writes to vmem, unaligned data buffers, and started on
[gba_blender] / tools / pngdump / main.c
index a2b37fd..908818d 100644 (file)
@@ -84,7 +84,17 @@ int main(int argc, char **argv)
 
        switch(mode) {
        case 0:
-               fwrite(img.pixels, 1, img.scansz * img.height, out);
+               if(img.bpp > 8 || img.cmap_ncolors == 0 || img.cmap_ncolors > 16) {
+                       fwrite(img.pixels, 1, img.scansz * img.height, out);
+               } else {
+                       /* pack into nibbles */
+                       unsigned char *ptr = img.pixels;
+                       for(i=0; i<img.width * img.height / 2; i++) {
+                               unsigned char pair = (ptr[0] << 4) | ptr[1];
+                               fputc(pair, out);
+                               ptr += 2;
+                       }
+               }
                break;
 
        case 1: