#include "Helpers.h" #include static void PrintRLEStructDefinition(RLEBitmap *rle); static void PrintRLEBitmapInitializer(RLEBitmap *rle,const char *indent); int main(int argc,const char **argv) { if(argc!=2 && argc!=4) { fprintf(stderr,"Usage: %s name [framewidth frameheight]output.c\n",argv[0]); exit(1); } const char *name=argv[1]; Bitmap *bitmap=AllocateBitmapWithContentsOfPNGFileOrDie("-"); if(argc==2) { RLEBitmap *rle=AllocateRLEBitmapWithBitmapOrDie(bitmap); PrintRLEStructDefinition(rle); printf(" %s=\n",name); PrintRLEBitmapInitializer(rle,""); printf(";\n"); free(rle); } else { int fw=atoi(argv[2]); int fh=atoi(argv[3]); if(fw<=0) { fprintf(stderr,"Invalid frame width.\n"); exit(1); } if(fh<=0) { fprintf(stderr,"Invalid frame height.\n"); exit(1); } int w=bitmap->width; int h=bitmap->height; int numcols=w/fw; int numrows=h/fh; printf("const RLEBitmap * const %s[%d]=\n",name,numcols*numrows); printf("{\n"); for(int row=0;rowcodes; while(yheight) { Pixel spans=*ptr++; int empty=spans>>8; int filled=spans&0xff; x+=empty+filled; bool isend=false; if(x==rle->width) { x=0; y++; if(!filled) isend=true; } if(isend) numends++; else numlengths++; numpixels+=filled; ptr+=filled; } printf("const struct { RLEBitmap rle; Pixel codes[RLECodeCount(%d,%d,%d)]; }",numpixels,numlengths,numends); } static void PrintRLEBitmapInitializer(RLEBitmap *rle,const char *indent) { printf("{\n"); printf("%s\t{ %d,%d },\n",indent,rle->width,rle->height); printf("%s\t{",indent); int n=0; int x=0,y=0; Pixel *ptr=rle->codes; while(yheight) { Pixel spans=*ptr++; int empty=spans>>8; int filled=spans&0xff; x+=empty+filled; bool isend=false; if(x==rle->width) { x=0; y++; if(!filled) isend=true; } if(n++%4==0) printf("\n%s\t\t",indent); if(isend) printf("RLEEndCode(0x%02x), ",empty); else printf("RLECode(0x%02x,0x%02x), ",empty,filled); for(int i=0;i