Blender V2.61 - r43446

Image.h

Go to the documentation of this file.
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 #ifndef _DDS_IMAGE_H
00038 #define _DDS_IMAGE_H
00039 
00040 #include <Common.h>
00041 #include <Color.h>
00042 
00044 class Image
00045 {
00046 public:
00047     
00048     enum Format 
00049     {
00050         Format_RGB,
00051         Format_ARGB,
00052     };
00053     
00054     Image();
00055     ~Image();
00056     
00057     void allocate(uint w, uint h);
00058     /*
00059     bool load(const char * name);
00060     
00061     void wrap(void * data, uint w, uint h);
00062     void unwrap();
00063     */
00064     
00065     uint width() const;
00066     uint height() const;
00067     
00068     const Color32 * scanline(uint h) const;
00069     Color32 * scanline(uint h);
00070     
00071     const Color32 * pixels() const;
00072     Color32 * pixels();
00073     
00074     const Color32 & pixel(uint idx) const;
00075     Color32 & pixel(uint idx);
00076     
00077     const Color32 & pixel(uint x, uint y) const;
00078     Color32 & pixel(uint x, uint y);
00079     
00080     Format format() const;
00081     void setFormat(Format f);
00082     
00083 private:
00084     void free();
00085     
00086 private:
00087     uint m_width;
00088     uint m_height;
00089     Format m_format;
00090     Color32 * m_data;
00091 };
00092 
00093 
00094 inline const Color32 & Image::pixel(uint x, uint y) const
00095 {
00096     return pixel(y * width() + x);
00097 }
00098 
00099 inline Color32 & Image::pixel(uint x, uint y)
00100 {
00101     return pixel(y * width() + x);
00102 }
00103 
00104 #endif // _DDS_IMAGE_H