Blender V2.27

Image.cpp

00001 
00025 /*
00026  * This file is based on a similar file from the NVIDIA texture tools
00027  * (http://nvidia-texture-tools.googlecode.com/)
00028  *
00029  * Original license from NVIDIA follows.
00030  */
00031 
00032 // This code is in the public domain -- castanyo@yahoo.es
00033 
00034 #include <Color.h>
00035 #include <Image.h>
00036 
00037 #include <stdio.h> // printf
00038 
00039 Image::Image() : m_width(0), m_height(0), m_format(Format_RGB), m_data(0)
00040 {
00041 }
00042 
00043 Image::~Image()
00044 {
00045         free();
00046 }
00047 
00048 void Image::allocate(uint w, uint h)
00049 {
00050         free();
00051         m_width = w;
00052         m_height = h;
00053         m_data = new Color32[w * h];
00054 }
00055 
00056 void Image::free()
00057 {
00058         if (m_data) delete [] m_data;
00059         m_data = 0;
00060 }
00061 
00062 
00063 uint Image::width() const
00064 {
00065         return m_width;
00066 }
00067 
00068 uint Image::height() const
00069 {
00070         return m_height;
00071 }
00072 
00073 const Color32 * Image::scanline(uint h) const
00074 {
00075         if (h >= m_height) {
00076                 printf("DDS: scanline beyond dimensions of image");
00077                 return m_data;
00078         }
00079         return m_data + h * m_width;
00080 }
00081 
00082 Color32 * Image::scanline(uint h)
00083 {
00084         if (h >= m_height) {
00085                 printf("DDS: scanline beyond dimensions of image");
00086                 return m_data;
00087         }
00088         return m_data + h * m_width;
00089 }
00090 
00091 const Color32 * Image::pixels() const
00092 {
00093         return m_data;
00094 }
00095 
00096 Color32 * Image::pixels()
00097 {
00098         return m_data;
00099 }
00100 
00101 const Color32 & Image::pixel(uint idx) const
00102 {
00103         if (idx >= m_width * m_height) {
00104                 printf("DDS: pixel beyond dimensions of image");
00105                 return m_data[0];
00106         }
00107         return m_data[idx];
00108 }
00109 
00110 Color32 & Image::pixel(uint idx)
00111 {
00112         if (idx >= m_width * m_height) {
00113                 printf("DDS: pixel beyond dimensions of image");
00114                 return m_data[0];
00115         }
00116         return m_data[idx];
00117 }
00118 
00119 
00120 Image::Format Image::format() const
00121 {
00122         return m_format;
00123 }
00124 
00125 void Image::setFormat(Image::Format f)
00126 {
00127         m_format = f;
00128 }
00129