2
--------------------------------------------------------------------------------
3
This source file is part of Hydrax.
6
Copyright (C) 2008 Xavier Verguļæ½n Gonzļæ½lez <xavierverguin@hotmail.com>
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
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.
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
--------------------------------------------------------------------------------
29
Image::Image(const Size &Size)
30
: mSize(Hydrax::Size(Size.Width+1,Size.Height+1))
31
, mChannels(static_cast<int>(TYPE_RGBA))
37
Image::Image(const Size &Size, const Type &Type)
38
: mSize(Hydrax::Size(Size.Width+1,Size.Height+1))
39
, mChannels(static_cast<int>(Type))
45
Image::Image(const Size &Size, const Type &Type, const float &v)
46
: mSize(Hydrax::Size(Size.Width+1,Size.Height+1))
47
, mChannels(static_cast<int>(Type))
58
const float& Image::getValue(const int &x, const int &y, const int &c) const
60
#if HYDRAX_IMAGE_CHECK_PIXELS == 1
61
if (c < 0 || c > mChannels ||
62
x < 0 || x > mSize.Width ||
63
y < 0 || y > mSize.Height)
65
HydraxLOG("Error in Image::getValue, x = " + Ogre::StringConverter::toString(x)
66
+ " y = " + Ogre::StringConverter::toString(y)
67
+ " Channel = " + Ogre::StringConverter::toString(c));
73
return mData[(y*mSize.Width+x)*mChannels+c];
76
float Image::getValueLI(const float &x, const float &y, const int &c) const
78
#if HYDRAX_IMAGE_CHECK_PIXELS == 1
79
if (c < 0 || c > mChannels ||
80
x < 0 || x > mSize.Width ||
81
y < 0 || y > mSize.Height)
83
HydraxLOG("Error in Image::getValue, x = " + Ogre::StringConverter::toString(x)
84
+ " y = " + Ogre::StringConverter::toString(y)
85
+ " Channel = " + Ogre::StringConverter::toString(c));
91
int xINT = static_cast<int>(x),
92
yINT = static_cast<int>(y);
103
float A = mData[(yINT*mSize.Width+xINT)*mChannels+c],
104
B = mData[(yINT*mSize.Width+xINT+1)*mChannels+c],
105
C = mData[((yINT+1)*mSize.Width+xINT)*mChannels+c],
106
D = mData[((yINT+1)*mSize.Width+xINT+1)*mChannels+c];
108
return A*_xDIFF*_yDIFF +
114
Image::Pixel Image::getPixel(const int &x, const int &y) const
116
#if HYDRAX_IMAGE_CHECK_PIXELS == 1
117
if (x < 0 || x > mSize.Width ||
118
y < 0 || y > mSize.Height)
120
HydraxLOG("Error in Image::getPixel, x = " + Ogre::StringConverter::toString(x)
121
+ " y = " + Ogre::StringConverter::toString(y));
129
for(int k = 0; k < 4; k++)
133
v[k] = getValue(x, y, k);
141
return Pixel(v[0], v[1], v[2], v[3]);
144
Image::Pixel Image::getPixelLI(const float &x, const float &y) const
146
#if HYDRAX_IMAGE_CHECK_PIXELS == 1
147
if (x < 0 || x > mSize.Width ||
148
y < 0 || y > mSize.Height)
150
HydraxLOG("Error in Image::getPixel, x = " + Ogre::StringConverter::toString(x)
151
+ " y = " + Ogre::StringConverter::toString(y));
159
for(int k = 0; k < 4; k++)
163
v[k] = getValueLI(x, y, k);
171
return Pixel(v[0], v[1], v[2], v[3]);
174
void Image::setValue(const int &x, const int &y, const int &c, const float &v)
176
#if HYDRAX_IMAGE_CHECK_PIXELS == 1
177
if (c < 0 || c > mChannels ||
178
x < 0 || x > mSize.Width ||
179
y < 0 || y > mSize.Height)
181
HydraxLOG("Error in Image::setValue, x = " + Ogre::StringConverter::toString(x)
182
+ " y = " + Ogre::StringConverter::toString(y)
183
+ " Channel = " + Ogre::StringConverter::toString(c));
189
mData[(y*mSize.Width+x)*mChannels+c] = v;
192
void Image::setPixel(const int &x, const int &y, const Pixel &p)
194
#if HYDRAX_IMAGE_CHECK_PIXELS == 1
195
if (x < 0 || x > mSize.Width ||
196
y < 0 || y > mSize.Height)
198
HydraxLOG("Error in Image::setPixel, x = " + Ogre::StringConverter::toString(x)
199
+ " y = " + Ogre::StringConverter::toString(y));
209
setValue(x, y, 0, p.red);
215
setValue(x, y, 0, p.red);
216
setValue(x, y, 1, p.green);
222
setValue(x, y, 0, p.red);
223
setValue(x, y, 1, p.green);
224
setValue(x, y, 2, p.blue);
230
setValue(x, y, 0, p.red);
231
setValue(x, y, 1, p.green);
232
setValue(x, y, 2, p.blue);
233
setValue(x, y, 3, p.alpha);
239
void Image::_Initialize(const float &v)
241
mData = new float[(mSize.Width) *
247
for (x = 0; x < mSize.Width; x++)
249
for (y = 0; y < mSize.Height; y++)
251
for(c = 0; c < mChannels; c++)
253
mData[(y*mSize.Width+x)*mChannels+c] = v;