#ifndef __TOOLS_HELPERS_H__ #define __TOOLS_HELPERS_H__ #include "../Helpers/BitmapAllocator.h" #include "../Helpers/BitmapLoader.h" #include "../Helpers/BitmapSaver.h" #include "../Helpers/RLEBitmapAllocator.h" #include "../Helpers/RLEBitmapLoader.h" #include #include static void Die(const char *reason) { fprintf(stderr,"Fatal error: %s\n",reason); exit(1); } static inline Bitmap *AllocateBitmapOrDie(int width,int height) { Bitmap *bitmap=AllocateBitmap(width,height); if(!bitmap) { char buf[128]; sprintf(buf,"Failed to allocate bitmap of size %dx%d.",width,height); Die(buf); } return bitmap; } static Bitmap *AllocateSubBitmapAsReferenceOrDie(Bitmap *bitmap,int x,int y,int width,int height) { Bitmap *subbitmap=AllocateSubBitmapAsReference(bitmap,x,y,width,height); if(!subbitmap) { Die("Failed to allocate reference subbitmap."); } return subbitmap; } static Bitmap *AllocateSubBitmapAsCopyOrDie(const Bitmap *bitmap,int x,int y,int width,int height) { Bitmap *subbitmap=AllocateSubBitmapAsCopy(bitmap,x,y,width,height); if(!subbitmap) { char buf[128]; sprintf(buf,"Failed to allocate bitmap of size %dx%d.",width,height); Die(buf); } return subbitmap; } static RLEBitmap *AllocateRLEBitmapWithBitmapOrDie(const Bitmap *bitmap) { RLEBitmap *rle=AllocateRLEBitmapWithBitmap(bitmap); if(!rle) { char buf[128]; sprintf(buf,"Failed to allocate RLE bitmap of size %dx%d.",bitmap->width,bitmap->height); Die(buf); } return rle; } static RLEBitmap *AllocateRLEBitmapWithPartialBitmapOrDie(const Bitmap *bitmap,int x,int y,int width,int height) { RLEBitmap *rle=AllocateRLEBitmapWithPartialBitmap(bitmap,x,y,width,height); if(!rle) { char buf[128]; sprintf(buf,"Failed to allocate RLE bitmap of size %dx%d.",width,height); Die(buf); } return rle; } static Bitmap *AllocateBitmapWithContentsOfPNGFileOrDie(const char *filename) { Bitmap *bitmap=AllocateBitmapWithContentsOfPNGFile(filename); if(!bitmap) { char buf[4096]; sprintf(buf,"Failed to load \"%s\" as a PNG file.",filename); Die(buf); } return bitmap; } static void SaveBitmapToPNGFileOrDie(const Bitmap *bitmap,const char *filename) { if(!SaveBitmapToPNGFile(bitmap,filename)) { char buf[4096]; sprintf(buf,"Failed to save bitmap to file \"%s\".",filename); Die(buf); } } static inline bool IsPixelBlended(Pixel p) { return ExtractAlpha(p)<255; } static inline bool IsPixelBlendedAt(const Bitmap *bitmap,int x,int y) { return IsPixelBlended(ReadPixel(bitmap,x,y)); } static bool IsPartialBitmapBlended(const Bitmap *bitmap,int x,int y,int w,int h) { for(int dy=0;dywidth,bitmap->height); } static inline bool IsPixelTransparentAt(const Bitmap *bitmap,int x,int y) { return IsPixelTransparent(ReadPixel(bitmap,x,y)); } static bool IsPartialBitmapTransparent(const Bitmap *bitmap,int x,int y,int w,int h) { for(int dy=0;dywidth,bitmap->height); } static inline bool IsBitmapInvisible(const Bitmap *bitmap) { return IsPartialBitmapInvisible(bitmap,0,0,bitmap->width,bitmap->height); } #endif