Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * Contributors: Amorilia (amorilia@users.sourceforge.net) 00019 * 00020 * ***** END GPL LICENSE BLOCK ***** 00021 */ 00022 00028 /* 00029 * This file is based on a similar file from the NVIDIA texture tools 00030 * (http://nvidia-texture-tools.googlecode.com/) 00031 * 00032 * Original license from NVIDIA follows. 00033 */ 00034 00035 // This code is in the public domain -- castanyo@yahoo.es 00036 00037 #include <Color.h> 00038 #include <Image.h> 00039 00040 #include <stdio.h> // printf 00041 00042 Image::Image() : m_width(0), m_height(0), m_format(Format_RGB), m_data(NULL) 00043 { 00044 } 00045 00046 Image::~Image() 00047 { 00048 free(); 00049 } 00050 00051 void Image::allocate(uint w, uint h) 00052 { 00053 free(); 00054 m_width = w; 00055 m_height = h; 00056 m_data = new Color32[w * h]; 00057 } 00058 00059 void Image::free() 00060 { 00061 if (m_data) delete [] m_data; 00062 m_data = NULL; 00063 } 00064 00065 00066 uint Image::width() const 00067 { 00068 return m_width; 00069 } 00070 00071 uint Image::height() const 00072 { 00073 return m_height; 00074 } 00075 00076 const Color32 * Image::scanline(uint h) const 00077 { 00078 if (h >= m_height) { 00079 printf("DDS: scanline beyond dimensions of image"); 00080 return m_data; 00081 } 00082 return m_data + h * m_width; 00083 } 00084 00085 Color32 * Image::scanline(uint h) 00086 { 00087 if (h >= m_height) { 00088 printf("DDS: scanline beyond dimensions of image"); 00089 return m_data; 00090 } 00091 return m_data + h * m_width; 00092 } 00093 00094 const Color32 * Image::pixels() const 00095 { 00096 return m_data; 00097 } 00098 00099 Color32 * Image::pixels() 00100 { 00101 return m_data; 00102 } 00103 00104 const Color32 & Image::pixel(uint idx) const 00105 { 00106 if (idx >= m_width * m_height) { 00107 printf("DDS: pixel beyond dimensions of image"); 00108 return m_data[0]; 00109 } 00110 return m_data[idx]; 00111 } 00112 00113 Color32 & Image::pixel(uint idx) 00114 { 00115 if (idx >= m_width * m_height) { 00116 printf("DDS: pixel beyond dimensions of image"); 00117 return m_data[0]; 00118 } 00119 return m_data[idx]; 00120 } 00121 00122 00123 Image::Format Image::format() const 00124 { 00125 return m_format; 00126 } 00127 00128 void Image::setFormat(Image::Format f) 00129 { 00130 m_format = f; 00131 } 00132 00133