Blender  V2.93
Image.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 /*
22  * This file is based on a similar file from the NVIDIA texture tools
23  * (http://nvidia-texture-tools.googlecode.com/)
24  *
25  * Original license from NVIDIA follows.
26  */
27 
28 /* This code is in the public domain -- <castanyo@yahoo.es>. */
29 
30 #include <Color.h>
31 #include <Image.h>
32 
33 #include <cstdio> /* printf */
34 
35 Image::Image() : m_width(0), m_height(0), m_format(Format_RGB), m_data(nullptr)
36 {
37 }
38 
40 {
41  free();
42 }
43 
45 {
46  free();
47  m_width = w;
48  m_height = h;
49  m_data = new Color32[w * h];
50 }
51 
52 void Image::free()
53 {
54  delete[] m_data;
55  m_data = nullptr;
56 }
57 
59 {
60  return m_width;
61 }
62 
64 {
65  return m_height;
66 }
67 
68 const Color32 *Image::scanline(uint h) const
69 {
70  if (h >= m_height) {
71  printf("DDS: scanline beyond dimensions of image\n");
72  return m_data;
73  }
74  return m_data + h * m_width;
75 }
76 
78 {
79  if (h >= m_height) {
80  printf("DDS: scanline beyond dimensions of image\n");
81  return m_data;
82  }
83  return m_data + h * m_width;
84 }
85 
86 const Color32 *Image::pixels() const
87 {
88  return m_data;
89 }
90 
92 {
93  return m_data;
94 }
95 
96 const Color32 &Image::pixel(uint idx) const
97 {
98  if (idx >= m_width * m_height) {
99  printf("DDS: pixel beyond dimensions of image\n");
100  return m_data[0];
101  }
102  return m_data[idx];
103 }
104 
106 {
107  if (idx >= m_width * m_height) {
108  printf("DDS: pixel beyond dimensions of image\n");
109  return m_data[0];
110  }
111  return m_data[idx];
112 }
113 
115 {
116  return m_format;
117 }
118 
120 {
121  m_format = f;
122 }
unsigned int uint
Definition: BLI_sys_types.h:83
btScalar m_height
Definition: btConeShape.h:29
btScalar m_width
btAlignedObjectArray< btScalar > m_data
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition: btQuadWord.h:119
Definition: Color.h:33
~Image()
Definition: Image.cpp:39
Format format() const
Definition: Image.cpp:114
void allocate(uint w, uint h)
Definition: Image.cpp:44
const Color32 * pixels() const
Definition: Image.cpp:86
const Color32 & pixel(uint idx) const
Definition: Image.cpp:96
Image()
Definition: Image.cpp:35
uint height() const
Definition: Image.cpp:63
const Color32 * scanline(uint h) const
Definition: Image.cpp:68
void setFormat(Format f)
Definition: Image.cpp:119
uint width() const
Definition: Image.cpp:58