Image.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "Image.h"
00013 #include <OpenCAL/ImageLoader.h>
00014 using namespace OpenCAL::Utils;
00015
00016 using namespace std;
00017
00018
00019
00020
00021
00022
00023 Image::Image(unsigned int width, unsigned int height, unsigned int depth)
00024 : m_width(width), m_height(height), m_depth(depth)
00025 {
00026 m_data = new unsigned char[width * height * depth];
00027 }
00028
00029 Image::Image(const string &filename)
00030 : m_width(0), m_height(0), m_depth(0), m_data(0)
00031 {
00032 ImageLoader::loadImage(this, filename);
00033 }
00034
00035 Image::~Image()
00036 {
00037 if(m_data)
00038 delete[] m_data;
00039 }
00040
00041
00042
00043
00044
00045
00046 void Image::resize(unsigned int width, unsigned int height, unsigned int depth)
00047 {
00048 if(m_data)
00049 delete[] m_data;
00050
00051 m_width = width;
00052 m_height = height;
00053 m_depth = depth;
00054
00055 m_data = new unsigned char[width * height * depth];
00056 }
00057
00058 void Image::clear()
00059 {
00060 memcpy(m_data, 0, m_width * m_height * m_depth * sizeof(unsigned char));
00061 }
00062
00063
00064 #ifdef BLABLABLA
00065 void Image::load(const string &filename, bool clamp)
00066 {
00067 m_textureID = 0;
00068
00069
00070 if(stricmp(strrchr(filename.c_str(), '.'), ".tga") == 0)
00071 {
00072 CTga * Tga;
00073 Tga = new CTga();
00074 if(Tga->ReadFile(filename.c_str()) == 0)
00075 {
00076 Tga->Release();
00077 return;
00078 }
00079
00080 if(Tga->Bpp() != 32)
00081 {
00082 Tga->Release();
00083 return;
00084 }
00085
00086
00087 m_width = Tga->GetSizeX();
00088 m_height = Tga->GetSizeY();
00089 m_depth = Tga->Bpp() / 8;
00090
00091 char* texData = new char[m_width * m_height * m_depth];
00092
00093 for(int y = 0; y < (int) m_height; ++y)
00094 {
00095 memcpy(&texData[y * m_width * m_depth],
00096 &((char*) Tga->GetPointer()) [(m_height - y - 1) * m_width * m_depth], m_width * m_depth);
00097 }
00098
00099
00100 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
00101
00102 glGenImages(1, &m_textureID);
00103
00104 glBindImage(GL_TEXTURE_2D, m_textureID);
00105 if(clamp)
00106 {
00107 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
00108 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
00109
00110 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
00111 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
00112
00113 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_width, m_height, 0, GL_RGBA , GL_UNSIGNED_BYTE, texData);
00114 }
00115 else
00116 {
00117
00118
00119
00120
00121
00122
00123
00124
00125 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
00126 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
00127 gluBuild2DMipmaps(GL_TEXTURE_2D, 4, m_width, m_height, GL_RGBA, GL_UNSIGNED_BYTE, texData);
00128 }
00129
00130 Tga->Release();
00131
00132 delete[] texData;
00133 }
00134 }
00135 #endif // BLABLABLA
Generated on Sun Aug 15 19:19:22 2004 for OpenCAL: Open Computer Animation Library by
1.3.8