RigsofRods
Soft-body Physics Simulation
Image.h
Go to the documentation of this file.
1 /*
2 --------------------------------------------------------------------------------
3 This source file is part of Hydrax.
4 Visit ---
5 
6 Copyright (C) 2008 Xavier Verguín González <xavierverguin@hotmail.com>
7  <xavyiy@gmail.com>
8 
9 This program is free software; you can redistribute it and/or modify it under
10 the terms of the GNU Lesser General Public License as published by the Free Software
11 Foundation; either version 2 of the License, or (at your option) any later
12 version.
13 
14 This program is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17 
18 You should have received a copy of the GNU Lesser General Public License along with
19 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21 http://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 
38 namespace Hydrax
39 {
42  class Image
43  {
44  public:
47  enum Type
48  {
51  TYPE_RGB = 3,
54  };
55 
58  enum Channel
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
Hydrax::Image::getValue
const float & getValue(const int &x, const int &y, const Channel &c) const
Get a pixel value.
Definition: Image.h:176
Hydrax::Image::Image
Image(const Size &Size)
Constructor.
Definition: Image.cpp:29
y
float y
Definition: (ValueTypes) quaternion.h:6
Hydrax::Image::getPixelLI
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
Hydrax::Image::mChannels
int mChannels
Number of channels.
Definition: Image.h:267
Hydrax::Image::Pixel::Pixel
Pixel(const float &r, const float &g, const float &b, const float &a)
Constructor.
Definition: Image.h:113
Hydrax
Definition: CfgFileManager.cpp:28
Hydrax::Image::TYPE_RGBA
@ TYPE_RGBA
Default.
Definition: Image.h:53
Hydrax::Image::Pixel::Pixel
Pixel()
Default constructor.
Definition: Image.h:72
Hydrax::Size
Struct wich contains an especific width and height value.
Definition: Help.h:40
Hydrax::Image::TYPE_TWO_CHANNELS
@ TYPE_TWO_CHANNELS
Definition: Image.h:50
Hydrax::Image::mSize
Size mSize
Image size.
Definition: Image.h:265
Hydrax::Image::~Image
~Image()
Destructor.
Definition: Image.cpp:53
Hydrax::Image::setValue
void setValue(const int &x, const int &y, const Channel &c, const float &v)
Set a pixel value.
Definition: Image.h:222
Hydrax::Image::_Initialize
void _Initialize(const float &v)
Initialize array (Reserve dynamic memory)
Definition: Image.cpp:239
Hydrax::Image::CHANNEL_B
@ CHANNEL_B
Definition: Image.h:62
Hydrax::Image::Pixel::alpha
float alpha
Definition: Image.h:128
Hydrax::Image::getValueLI
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
Hydrax::Image::Type
Type
Image type enum.
Definition: Image.h:47
Hydrax::Image::CHANNEL_A
@ CHANNEL_A
Definition: Image.h:63
Help.h
Hydrax::Image::getValue
const float & getValue(const int &x, const int &y, const int &c) const
Get a pixel value.
Definition: Image.cpp:58
Hydrax::Image::mData
float * mData
Our image data.
Definition: Image.h:270
Hydrax::Image::Pixel::Pixel
Pixel(const float &v)
Constructor.
Definition: Image.h:83
Hydrax::Image::getValueLI
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
Hydrax::Image::Pixel::blue
float blue
Definition: Image.h:127
Hydrax::Image::getType
Type getType() const
Get image type.
Definition: Image.h:245
Hydrax::Image::Pixel
Pixel structure.
Definition: Image.h:68
Hydrax::Image::CHANNEL_R
@ CHANNEL_R
Definition: Image.h:60
Hydrax::Image::setPixel
void setPixel(const int &x, const int &y, const Pixel &p)
Set a pixel.
Definition: Image.cpp:192
Hydrax::Image::Channel
Channel
Channel enum.
Definition: Image.h:58
Hydrax::Image::TYPE_ONE_CHANNEL
@ TYPE_ONE_CHANNEL
Definition: Image.h:49
Hydrax::Image::getPixel
Pixel getPixel(const int &x, const int &y) const
Get a pixel.
Definition: Image.cpp:114
Hydrax::Image::Pixel::Pixel
Pixel(const float &r, const float &g, const float &b)
Constructor.
Definition: Image.h:97
Hydrax::Image::setValue
void setValue(const int &x, const int &y, const int &c, const float &v)
Set a pixel value.
Definition: Image.cpp:174
Hydrax::Image::getNumberOfChannels
const int & getNumberOfChannels() const
Get number of channels.
Definition: Image.h:253
Prerequisites.h
Hydrax::Image
Class for store variable channels of an image.
Definition: Image.h:42
Hydrax::Size::Width
int Width
Width value.
Definition: Help.h:43
Hydrax::Image::TYPE_RGB
@ TYPE_RGB
Definition: Image.h:51
Hydrax::Image::Pixel::red
float red
Pixel values (RGBA)
Definition: Image.h:125
Hydrax::Image::getSize
Size getSize() const
Get image size.
Definition: Image.h:237
Hydrax::Size::Height
int Height
Height value.
Definition: Help.h:45
Hydrax::Image::CHANNEL_G
@ CHANNEL_G
Definition: Image.h:61
Hydrax::Image::Pixel::green
float green
Definition: Image.h:126
x
float x
Definition: (ValueTypes) quaternion.h:5