#include #include #include #include namespace hgl { namespace graph { bool Texture2DLoader::Load(io::InputStream *is) { if(!is)return(false); if(is->Read(&file_header,sizeof(Tex2DFileHeader))!=sizeof(Tex2DFileHeader)) return(false); if(file_header.version!=2) return(false); if(file_header.total_bytes()==0) return(false); const uint total_bytes=file_header.total_bytes(); if(is->Available()Read(ptr,total_bytes)!=total_bytes) OnError(); OnEnd(); return(true); } bool Texture2DLoader::Load(const OSString &filename) { io::OpenFileInputStream fis(filename); if(!fis) { LOG_ERROR(OS_TEXT("[ERROR] open texture file<")+filename+OS_TEXT("> failed.")); return(false); } return this->Load(&fis); } }//namespace graph namespace graph { Bitmap2DLoader::~Bitmap2DLoader() { SAFE_CLEAR(bmp); } void *Bitmap2DLoader::OnBegin(uint32 total_bytes) { SAFE_CLEAR(bmp); bmp=new BitmapData; bmp->width =file_header.width; bmp->height =file_header.height; bmp->total_bytes=total_bytes; bmp->data=new char[total_bytes]; return bmp->data; } BitmapData *Bitmap2DLoader::GetBitmap() { BitmapData *result=bmp; bmp=nullptr; return result; } BitmapData *LoadBitmapFromFile(const OSString &filename) { Bitmap2DLoader loader; if(!loader.Load(filename)) return(false); return loader.GetBitmap(); } }//namespace graph }//namespace hgl