Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

Image.cpp

Go to the documentation of this file.
00001 
00007 #include "Image.h"
00008 
00009 /********************************************************************
00010  * Constructor
00011  */
00012 Image::Image() {
00013         data = NULL;
00014         clear();
00015 }
00016 
00017 /********************************************************************
00018  * Destructor
00019  */
00020 Image::~Image() {
00021         clear();
00022 }
00023 
00024 /********************************************************************
00025  * Clear
00026  */
00027 void Image::clear() {
00028         if (data != NULL) delete data;
00029         data = NULL;
00030         width = height = 0;
00031         format = 0;
00032 }
00033 
00034 /********************************************************************
00035  * Load image
00036  */
00037 bool Image::loadImage(const char *filename) {
00038         char *extension = strrchr(filename, '.');
00039 
00040         if (extension == NULL)
00041                 return false;
00042 
00043         clear();
00044 
00045         if (stricmp(extension, ".bmp") == 0)
00046                 return loadBMP(filename);
00047 
00048         LOG_ERROR(("Unable to load image << %s >>", filename));
00049         return false;
00050 }
00051 
00052 /********************************************************************
00053  * Load BMP
00054  */
00055 bool Image::loadBMP(const char *filename) {
00056         FILE *file = NULL;
00057         if (!filename)
00058                 return NULL;
00059 
00060         file = fopen(filename, "r");
00061         if (!file) {
00062                 LOG_ERROR(("Unable to load image << %s >>", filename));
00063                 return false;
00064         }
00065 
00066         fclose(file);
00067         AUX_RGBImageRec *TextureImage[1];
00068         TextureImage[0] = auxDIBImageLoad(filename);
00069 
00070         width = TextureImage[0]->sizeX;
00071         height = TextureImage[0]->sizeY;
00072         data = TextureImage[0]->data;
00073         format = GL_RGB;
00074 
00075         LOG_SUCCESS(("Image << %s >> loaded", filename));
00076         return true;
00077 }
00078 
00079 /********************************************************************
00080  * Get height
00081  */
00082 int Image::getHeight() const {
00083         return (height == 0) ? 1 : height;
00084 }
00085 
00086 /********************************************************************
00087  * Get width
00088  */
00089 int Image::getWidth() const {
00090         return (width == 0) ? 1 : width;
00091 }
00092 
00093 /********************************************************************
00094  * Get format
00095  */
00096 int Image::getFormat() const {
00097         return format;
00098 }
00099 
00100 /********************************************************************
00101  * Get data
00102  */
00103 unsigned char *Image::getData() const {
00104         return data;
00105 }
00106 
00107 
00108 bool Image::toNormalMap(const bool useRGBA, const bool keepHeight) {
00109         return true;
00110 }
00111 
00112 
00113 bool Image::toGrayScale(const bool isRGBA, const bool reallocate) {
00114         return true;
00115 }
00116 
00117 bool Image::alphaFade() {
00118         return true;
00119 }

Generated on Sun Jun 5 15:47:04 2005 for Defacto by  doxygen 1.4.3