Rigs of Rods 2023.09
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
Image.h
Go to the documentation of this file.
1/*
2--------------------------------------------------------------------------------
3This source file is part of Hydrax.
4Visit ---
5
6Copyright (C) 2008 Xavier Vergu�n Gonz�lez <xavierverguin@hotmail.com>
7 <xavyiy@gmail.com>
8
9This program is free software; you can redistribute it and/or modify it under
10the terms of the GNU Lesser General Public License as published by the Free Software
11Foundation; either version 2 of the License, or (at your option) any later
12version.
13
14This program is distributed in the hope that it will be useful, but WITHOUT
15ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17
18You should have received a copy of the GNU Lesser General Public License along with
19this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21http://www.gnu.org/copyleft/lesser.txt.
22--------------------------------------------------------------------------------
23*/
24
25#ifndef _Hydrax_Image_H_
26#define _Hydrax_Image_H_
27
28#include "Prerequisites.h"
29
30#include "Help.h"
31
34
37
38namespace Hydrax
39{
42 class Image
43 {
44 public:
55
59 {
60 CHANNEL_R = 0, // Red
61 CHANNEL_G = 1, // Green
62 CHANNEL_B = 2, // Blue
63 CHANNEL_A = 3 // Alpha
64 };
65
68 struct Pixel
69 {
73 : red(0)
74 , green(0)
75 , blue(0)
76 , alpha(0)
77 {
78 }
79
83 Pixel(const float &v)
84 : red(v)
85 , green(v)
86 , blue(v)
87 , alpha(v)
88 {
89 }
90
97 Pixel(const float &r,
98 const float &g,
99 const float &b)
100 : red(r)
101 , green(g)
102 , blue(b)
103 , alpha(0)
104 {
105 }
106
113 Pixel(const float &r,
114 const float &g,
115 const float &b,
116 const float &a)
117 : red(r)
118 , green(g)
119 , blue(b)
120 , alpha(a)
121 {
122 }
123
125 float red,
129 };
130
134 Image(const Size &Size);
135
140 Image(const Size &Size, const Type &Type);
141
147 Image(const Size &Size, const Type &Type, const float &v);
148
151 ~Image();
152
159 const float& getValue(const int &x, const int &y, const int &c) const;
160
168 float getValueLI(const float &x, const float &y, const int &c) const;
169
176 inline const float& getValue(const int &x, const int &y, const Channel &c) const
177 {
178 return getValue(x, y, static_cast<int>(c));
179 }
180
188 inline float getValueLI(const float &x, const float &y, const Channel &c) const
189 {
190 return getValueLI(x, y, static_cast<int>(c));
191 }
192
198 Pixel getPixel(const int &x, const int &y) const;
199
206 Pixel getPixelLI(const float &x, const float &y) const;
207
214 void setValue(const int &x, const int &y, const int &c, const float &v);
215
222 inline void setValue(const int &x, const int &y, const Channel &c, const float &v)
223 {
224 setValue(x, y, static_cast<int>(c), v);
225 }
226
232 void setPixel(const int &x, const int &y, const Pixel &p);
233
237 inline Size getSize() const
238 {
239 return Size(mSize.Width-1,mSize.Height-1);
240 }
241
245 inline Type getType() const
246 {
247 return static_cast<Type>(mChannels);
248 }
249
253 inline const int& getNumberOfChannels() const
254 {
255 return mChannels;
256 }
257
258 private:
262 void _Initialize(const float &v);
263
268
270 float *mData;
271 };
272}
273
276
277#endif
Class for store variable channels of an image.
Definition Image.h:43
Type
Image type enum.
Definition Image.h:48
@ TYPE_ONE_CHANNEL
Definition Image.h:49
@ TYPE_RGBA
Default.
Definition Image.h:53
@ TYPE_TWO_CHANNELS
Definition Image.h:50
Pixel getPixelLI(const float &x, const float &y) const
Get a pixel with linear interpolation, like x = 4.56, y = 8.34.
Definition Image.cpp:144
~Image()
Destructor.
Definition Image.cpp:53
float getValueLI(const float &x, const float &y, const Channel &c) const
Get a pixel value with linear interpolation, like x = 4.56, y = 8.34.
Definition Image.h:188
float getValueLI(const float &x, const float &y, const int &c) const
Get a pixel value with linear interpolation, like x = 4.56, y = 8.34.
Definition Image.cpp:76
const int & getNumberOfChannels() const
Get number of channels.
Definition Image.h:253
Size getSize() const
Get image size.
Definition Image.h:237
void setValue(const int &x, const int &y, const Channel &c, const float &v)
Set a pixel value.
Definition Image.h:222
void setPixel(const int &x, const int &y, const Pixel &p)
Set a pixel.
Definition Image.cpp:192
int mChannels
Number of channels.
Definition Image.h:267
const float & getValue(const int &x, const int &y, const Channel &c) const
Get a pixel value.
Definition Image.h:176
Pixel getPixel(const int &x, const int &y) const
Get a pixel.
Definition Image.cpp:114
Channel
Channel enum.
Definition Image.h:59
const float & getValue(const int &x, const int &y, const int &c) const
Get a pixel value.
Definition Image.cpp:58
void _Initialize(const float &v)
Initialize array (Reserve dynamic memory)
Definition Image.cpp:239
Size mSize
Image size.
Definition Image.h:265
Type getType() const
Get image type.
Definition Image.h:245
void setValue(const int &x, const int &y, const int &c, const float &v)
Set a pixel value.
Definition Image.cpp:174
float * mData
Our image data.
Definition Image.h:270
Pixel structure.
Definition Image.h:69
float red
Pixel values (RGBA)
Definition Image.h:125
Pixel(const float &r, const float &g, const float &b)
Constructor.
Definition Image.h:97
Pixel(const float &r, const float &g, const float &b, const float &a)
Constructor.
Definition Image.h:113
Pixel(const float &v)
Constructor.
Definition Image.h:83
Pixel()
Default constructor.
Definition Image.h:72
Struct wich contains an especific width and height value.
Definition Help.h:41
int Height
Height value.
Definition Help.h:45
int Width
Width value.
Definition Help.h:43