00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 #ifndef __EXCIMAGELOADER__
00056 #define __EXCIMAGELOADER__
00057
00058
00059
00060 #include "ExDefine.h"
00061 #include "Math/ExMath.h"
00062 #include "ExNihiloExecption.h"
00063 #include "ExNihiloNameSpace.h"
00064
00065 #include <ddraw.h>
00066
00067
00068
00069 #define TGA_RGB 2 // Normal RGB file
00070 #define TGA_A 3 // ALPHA file
00071 #define TGA_RLE 10 // Run-Length Encoded (RLE) file
00072
00073 enum TextureType
00074 {
00075 BMP,TGA,PCX,JPG,RGB,RAW,PPM,DDS,UNKNOWN
00076 };
00077
00078
00079 class ExCImageLoader
00080 {
00081 private:
00082
00083
00084
00085 typedef struct
00086 {
00087 unsigned char manufacturer;
00088 unsigned char version;
00089 unsigned char encoding;
00090 unsigned char bits;
00091 unsigned char xMin;
00092 unsigned char yMin;
00093 unsigned char xMax;
00094 unsigned char yMax;
00095 unsigned char *palette;
00096 } PCXHEADER;
00097
00098 typedef struct tagBITMAPINFOHEADER{
00099 DWORD biSize;
00100 LONG biWidth;
00101 LONG biHeight;
00102 WORD biPlanes;
00103 WORD biBitCount;
00104 DWORD biCompression;
00105 DWORD biSizeImage;
00106 LONG biXPelsPerMeter;
00107 LONG biYPelsPerMeter;
00108 DWORD biClrUsed;
00109 DWORD biClrImportant;
00110 } BITMAPINFOHEADER;
00111
00112
00113
00114
00115
00116 unsigned char *LoadPCXFile(std::string filename, PCXHEADER *pcxHeader);
00117
00118 TextureType FindTextureType(std::string FileName);
00119 public:
00120
00121
00122
00123 TextureType m_TextureType;
00124 int m_channels;
00125 int m_sizeX;
00126 int m_sizeY;
00127 long int m_scaledWidth;
00128 long int m_scaledHeight;
00129 unsigned int m_type;
00130 unsigned char *m_data;
00131 unsigned char *m_palette;
00132
00133
00134 int m_ddsBufsize;
00135 int m_ddsNumMipmaps;
00136 int m_ddsFormat;
00137 int m_ddsComponent;
00138
00139
00140
00141 ExCImageLoader(void);
00142 ExCImageLoader(std::string FileName);
00143 ~ExCImageLoader(void);
00144
00145
00146
00147 bool LoadImage(std::string FileName);
00148
00149 bool LoadBMP(const char *strFileName);
00150
00151 bool LoadBMP(std::string strFileName);
00152 bool LoadTGA(std::string strFileName);
00153 bool LoadJPG(std::string strFileName);
00154 bool LoadPCX(std::string strFileName);
00155 bool LoadRAW(std::string strFileName);
00156 bool LoadRGB(std::string strFileName);
00157 bool LoadPPM(std::string strFileName);
00158 bool LoadDDS(std::string strFileName);
00159
00160 bool SaveImage(std::string FileName,int width,int height);
00161
00162 bool SaveBMP(std::string strFileName,int width,int height,unsigned char * ImageData);
00163 bool SaveTGA(std::string strFileName,int width,int height,unsigned char * ImageData);
00164 bool SaveJPG(std::string strFileName,int width,int height,unsigned char * ImageData);
00165 bool SavePCX(std::string strFileName,int width,int height,unsigned char * ImageData);
00166 bool SaveRAW(std::string strFileName,int width,int height,unsigned char * ImageData);
00167 bool SaveRGB(std::string strFileName,int width,int height,unsigned char * ImageData);
00168 bool SavePPM(std::string strFileName,int width,int height,unsigned char * ImageData);
00169 };
00170
00171 #endif //__EXCIMAGELOADER__
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182