ImageFormat_GIF.cpp
Go to the documentation of this file.00001 //*** ImageFormat_GIF.cpp *** 00002 00003 #include "ImageFormat_GIF.h" 00004 #include "Debug.h" 00005 #include "Asset.h" 00006 #include "StandardLibrary.h" 00007 #include "ColorHelper.h" 00008 #include "gif/gif.h" 00009 00010 00011 00012 //*** Register *** 00013 00014 void ImageFormat_GIF::Register() 00015 { 00016 ImageFormat::RegisterImageFormat(TestAsset,Create); 00017 } 00018 00019 00020 //*** Create *** 00021 00022 ImageFormat* ImageFormat_GIF::Create(const Asset& asset) 00023 { 00024 return new ImageFormat_GIF(asset); 00025 } 00026 00027 00028 //*** TestAsset *** 00029 00030 bool ImageFormat_GIF::TestAsset(const Asset& asset) 00031 { 00032 if (asset.Open()) 00033 { 00034 char buffer[3]; 00035 asset.Read(buffer,3); 00036 asset.Close(); 00037 if (StrNCmp(buffer,"GIF",3)==0) 00038 { 00039 return true; 00040 } 00041 } 00042 00043 return false; 00044 } 00045 00046 00047 //*** Constructor *** 00048 00049 ImageFormat_GIF::ImageFormat_GIF(const Asset& asset): 00050 image_(0) 00051 { 00052 GifLoader* image=new GifLoader(); 00053 image_=image; 00054 bool result=image->Load(asset); 00055 Assert(result,"Failed to load gif image"); 00056 if (!result) 00057 { 00058 delete image_; 00059 image_=0; 00060 } 00061 } 00062 00063 00064 //*** Destructor *** 00065 00066 ImageFormat_GIF::~ImageFormat_GIF() 00067 { 00068 if (image_) 00069 { 00070 delete image_; 00071 } 00072 } 00073 00074 00075 //*** GetWidth *** 00076 00077 int ImageFormat_GIF::GetWidth() 00078 { 00079 if (!image_) 00080 { 00081 return 0; 00082 } 00083 return image_->width_; 00084 } 00085 00086 00087 //*** GetHeight *** 00088 00089 int ImageFormat_GIF::GetHeight() 00090 { 00091 if (!image_) 00092 { 00093 return 0; 00094 } 00095 return image_->height_; 00096 } 00097 00098 00099 //*** GetCelCount *** 00100 00101 int ImageFormat_GIF::GetCelCount() 00102 { 00103 if (!image_) 00104 { 00105 return 0; 00106 } 00107 00108 return image_->cels_.GetItemCount(); 00109 } 00110 00111 00112 //*** GetCelDelay *** 00113 00114 float ImageFormat_GIF::GetCelDelay(int celIndex) 00115 { 00116 if (!image_) 00117 { 00118 return 0; 00119 } 00120 GifLoader::Cel* cel=image_->cels_.Get(celIndex); 00121 return cel->delay/100.0f; 00122 } 00123 00124 00125 //*** CopyPixels *** 00126 00127 void ImageFormat_GIF::CopyPixels(unsigned int* destination) 00128 { 00129 if (!image_) 00130 { 00131 return; 00132 } 00133 00134 MemSet(destination,0,GetWidth()*GetHeight()*GetCelCount()*sizeof(unsigned int)); 00135 for (int i=0; i<GetCelCount(); i++) 00136 { 00137 GifLoader::Cel* cel=image_->cels_.Get(i); 00138 for (int y=0; y<cel->height; y++) 00139 { 00140 for (int x=0; x<cel->width; x++) 00141 { 00142 unsigned char p=cel->pixels[x+y*cel->width]; 00143 if (cel->transparency!=p) 00144 { 00145 unsigned int c=cel->palette[p]; 00146 unsigned char r=(unsigned char)((c&0x00ff0000)>>16); 00147 unsigned char g=(unsigned char)((c&0x0000ff00)>>8); 00148 unsigned char b=(unsigned char)((c&0x000000ff)); 00149 destination[GetWidth()*GetHeight()*i+(x+cel->x)+(y+cel->y)*GetWidth()]=RGB32(r,g,b); 00150 } 00151 } 00152 } 00153 } 00154 00155 } 00156 00157 00158 //*** Save *** 00159 00160 void ImageFormat_GIF::Save(const Filename& filename, int width, int height, void* data) 00161 { 00162 00163 }
Reproduction/republishing of any material on this site without permission is strictly prohibited.
