#include "RLELoader.h" #include "BitmapLoader.h" #include static size_t SizeOfRLEBitmapFromPartialBitmap(const UnpackedBitmap *bitmap,int x0,int y0,int width,int height); static void InitializeRLEBitmapFromPartialBitmap(UnpackedRLEBitmap *self,const UnpackedBitmap *bitmap,int x0,int y0,int width,int height); UnpackedRLEBitmap *AllocRLEBitmapFromBitmap(const UnpackedBitmap *bitmap) { return AllocRLEBitmapFromPartialBitmap(bitmap,0,0,bitmap->width,bitmap->height); } UnpackedRLEBitmap *AllocRLEBitmapFromPartialBitmap(const UnpackedBitmap *bitmap,int x0,int y0,int width,int height) { size_t size=SizeOfRLEBitmapFromPartialBitmap(bitmap,0,0,bitmap->width,bitmap->height); UnpackedRLEBitmap *self=malloc(size); if(!self) { fprintf(stderr,"Out of memory.\n"); exit(1); } InitializeRLEBitmapFromPartialBitmap(self,bitmap,x0,y0,width,height); return self; } static size_t SizeOfRLEBitmapFromPartialBitmap(const UnpackedBitmap *bitmap,int x0,int y0,int width,int height) { int numcodes=0; for(int y=0;ywidth=width; self->height=height; self->numcodes=0; UnpackedRLECode *ptr=self->codes; for(int y=0;yislength=true; ptr->isend=x>=width && filled==0; ptr->value.lengths.empty=empty; ptr->value.lengths.filled=filled; ptr++; for(int i=0;iislength=false; ptr->value.pixel=p; ptr++; } self->numcodes+=1+filled; } } }