Blender  V3.3
Image.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 /*
8  * This file is based on a similar file from the NVIDIA texture tools
9  * (http://nvidia-texture-tools.googlecode.com/)
10  *
11  * Original license from NVIDIA follows.
12  */
13 
14 /* This code is in the public domain -- <castanyo@yahoo.es>. */
15 
16 #include <Color.h>
17 #include <Image.h>
18 
19 #include <cstdio> /* printf */
20 
21 Image::Image() : m_width(0), m_height(0), m_format(Format_RGB), m_data(nullptr)
22 {
23 }
24 
26 {
27  free();
28 }
29 
31 {
32  free();
33  m_width = w;
34  m_height = h;
35  m_data = new Color32[w * h];
36 }
37 
38 void Image::free()
39 {
40  delete[] m_data;
41  m_data = nullptr;
42 }
43 
45 {
46  return m_width;
47 }
48 
50 {
51  return m_height;
52 }
53 
54 const Color32 *Image::scanline(uint h) const
55 {
56  if (h >= m_height) {
57  printf("DDS: scanline beyond dimensions of image\n");
58  return m_data;
59  }
60  return m_data + h * m_width;
61 }
62 
64 {
65  if (h >= m_height) {
66  printf("DDS: scanline beyond dimensions of image\n");
67  return m_data;
68  }
69  return m_data + h * m_width;
70 }
71 
72 const Color32 *Image::pixels() const
73 {
74  return m_data;
75 }
76 
78 {
79  return m_data;
80 }
81 
82 const Color32 &Image::pixel(uint idx) const
83 {
84  if (idx >= m_width * m_height) {
85  printf("DDS: pixel beyond dimensions of image\n");
86  return m_data[0];
87  }
88  return m_data[idx];
89 }
90 
92 {
93  if (idx >= m_width * m_height) {
94  printf("DDS: pixel beyond dimensions of image\n");
95  return m_data[0];
96  }
97  return m_data[idx];
98 }
99 
101 {
102  return m_format;
103 }
104 
106 {
107  m_format = f;
108 }
unsigned int uint
Definition: BLI_sys_types.h:67
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:19
~Image()
Definition: Image.cpp:25
Format format() const
Definition: Image.cpp:100
void allocate(uint w, uint h)
Definition: Image.cpp:30
const Color32 * pixels() const
Definition: Image.cpp:72
const Color32 & pixel(uint idx) const
Definition: Image.cpp:82
Image()
Definition: Image.cpp:21
uint height() const
Definition: Image.cpp:49
const Color32 * scanline(uint h) const
Definition: Image.cpp:54
void setFormat(Format f)
Definition: Image.cpp:105
uint width() const
Definition: Image.cpp:44