ImageFormat.cpp
Go to the documentation of this file.00001 //*** ImageFormat.cpp *** 00002 00003 #include "ImageFormat.h" 00004 #include "Debug.h" 00005 #include "Asset.h" 00006 #include "StandardLibrary.h" 00007 00008 Array<ImageFormat::ImageFormatEntry> ImageFormat::imageFormats_; 00009 00010 //*** RegisterImageFormat *** 00011 00012 void ImageFormat::RegisterImageFormat(bool (*TestFunction)(const Asset&),ImageFormat* (*CreateFunction)(const Asset&)) 00013 { 00014 ImageFormatEntry entry; 00015 entry.TestFunction=TestFunction; 00016 entry.CreateFunction=CreateFunction; 00017 imageFormats_.Add(entry); 00018 } 00019 00020 00021 //*** CreateImageFormat *** 00022 00023 ImageFormat* ImageFormat::CreateImageFormat(const Asset& asset) 00024 { 00025 // Make sure asset exists 00026 #ifdef _DEBUG 00027 if (!asset.Open()) 00028 { 00029 const char* filename=asset.GetFilename().GetString(); 00030 if (filename) 00031 { 00032 char errorMessage[1024]; 00033 SNPrintF(errorMessage,1024,"File not found: %s",filename); 00034 Assert(false,errorMessage); 00035 } 00036 else 00037 { 00038 Assert(false,"An asset could not be accessed."); 00039 } 00040 00041 return 0; 00042 } 00043 asset.Close(); 00044 #endif 00045 00046 for (int i=0; i<imageFormats_.GetItemCount(); i++) 00047 { 00048 ImageFormatEntry entry=imageFormats_.Get(i); 00049 if (entry.TestFunction(asset)) 00050 { 00051 return entry.CreateFunction(asset); 00052 } 00053 } 00054 00055 // Report unknown image format 00056 #ifdef _DEBUG 00057 const char* filename=asset.GetFilename().GetString(); 00058 if (filename) 00059 { 00060 char errorMessage[1024]; 00061 SNPrintF(errorMessage,1024,"Unknown image format: %s",filename); 00062 Assert(false,errorMessage); 00063 } 00064 else 00065 { 00066 Assert(false,"Unknown image format."); 00067 } 00068 #endif 00069 00070 return 0; 00071 }
Reproduction/republishing of any material on this site without permission is strictly prohibited.
