#include "Helpers.h" #include static void PrintPartialBitmapInitializer(Bitmap *bitmap,int x,int y,int w,int h,const char *name,int n,const char *indent); static void PrintPartialBitmapPixelArray(Bitmap *bitmap,int x,int y,int w,int h,const char *name,int n); static void PrintRLEStructDefinition(RLEBitmap *rle); static void PrintRLEBitmapInitializer(RLEBitmap *rle,const char *indent); static void PrintAdaptiveBitmapPointerFromPartialBitmap(Bitmap *bitmap,int x,int y,int w,int h,const char *name,int n,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) { if(!IsBitmapTransparent(bitmap)) PrintPartialBitmapPixelArray(bitmap,0,0,bitmap->width,bitmap->height,name,0); printf("const AdaptiveBitmap * const %s=",name); PrintAdaptiveBitmapPointerFromPartialBitmap(bitmap,0,0,bitmap->width,bitmap->height,name,0,""); printf(";\n"); } 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; 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