37 #include <boost/logic/tribool.hpp>
60 return mCode == sco.mCode;
64 enum {
RGBA,
BGRA,
ARGB,
ABGR,
RGBX,
BGRX,
XRGB,
XBGR,
RGB,
BGR,
UNSPECIFIED };
69 void set( uint8_t aRed, uint8_t aGreen, uint8_t aBlue, uint8_t aAlpha, uint8_t aPixelInc );
71 uint8_t mRed, mGreen, mBlue, mAlpha, mPixelInc;
96 Obj( int32_t aWidth, int32_t aHeight,
SurfaceChannelOrder aChannelOrder, T *aData,
bool aOwnsData, int32_t aRowBytes );
101 void setDeallocator(
void(*aDeallocatorFunc)(
void * ),
void *aDeallocatorRefcon );
103 int32_t mWidth, mHeight, mRowBytes;
104 bool mIsPremultiplied;
110 void (*mDeallocatorFunc)(
void *refcon);
111 void *mDeallocatorRefcon;
134 #if defined( CINDER_WINRT )
155 bool hasAlpha()
const {
return mObj->mChannelOrder.hasAlpha(); }
159 bool setPremultiplied(
bool premult =
true )
const {
return mObj->mIsPremultiplied = premult; }
163 uint8_t
getPixelInc()
const {
return mObj->mChannelOrder.getPixelInc(); }
172 const T*
getData()
const {
return mObj->mData; }
173 T*
getData(
const Vec2i &
offset ) {
return reinterpret_cast<T*
>(
reinterpret_cast<unsigned char*
>( mObj->mData + offset.
x *
getPixelInc() ) + offset.
y * mObj->mRowBytes ); }
174 const T*
getData(
const Vec2i &
offset )
const {
return reinterpret_cast<T*
>(
reinterpret_cast<unsigned char*
>( mObj->mData + offset.
x *
getPixelInc() ) + offset.
y * mObj->mRowBytes ); }
189 void setDeallocator(
void(*aDeallocatorFunc)(
void * ),
void *aDeallocatorRefcon );
194 uint8_t
getRedOffset()
const {
return mObj->mChannelOrder.getRedOffset(); }
198 uint8_t
getBlueOffset()
const {
return mObj->mChannelOrder.getBlueOffset(); }
241 typedef std::shared_ptr<Obj>
SurfaceT::*unspecified_bool_type;
242 operator unspecified_bool_type()
const {
return ( mObj.get() == 0 ) ? 0 : &SurfaceT::mObj; }
243 void reset() { mObj.reset(); }
247 std::shared_ptr<Obj> mObj;
249 void init(
ImageSourceRef imageSource,
const SurfaceConstraints &constraints = SurfaceConstraintsDefault(), boost::tribool
alpha = boost::logic::indeterminate );
251 void copyRawSameChannelOrder(
const SurfaceT<T> &srcSurface,
const Area &srcArea,
const Vec2i &absoluteOffset );
252 void copyRawRgba(
const SurfaceT<T> &srcSurface,
const Area &srcArea,
const Vec2i &absoluteOffset );
253 void copyRawRgbFullAlpha(
const SurfaceT<T> &srcSurface,
const Area &srcArea,
const Vec2i &absoluteOffset );
254 void copyRawRgb(
const SurfaceT<T> &srcSurface,
const Area &srcArea,
const Vec2i &absoluteOffset );
269 mLinePtr =
reinterpret_cast<uint8_t*
>( SurfaceT.
getData( clippedArea.
getUL() ) );
270 mPtr =
reinterpret_cast<T*
>( mLinePtr );
271 mStartX = mX = clippedArea.
getX1();
272 mStartY = mY = clippedArea.
getY1();
273 mEndX = clippedArea.
getX2();
274 mEndY = clippedArea.
getY2();
276 mY = clippedArea.
getY1() - 1;
280 T&
r()
const {
return mPtr[mRedOff]; }
282 T&
g()
const {
return mPtr[mGreenOff]; }
284 T&
b()
const {
return mPtr[mBlueOff]; }
286 T&
a()
const {
return mPtr[mAlphaOff]; }
289 T&
r( int32_t xOff, int32_t yOff )
const {
return mPtr[mRedOff + xOff * mInc + yOff * mRowInc]; }
291 T&
g( int32_t xOff, int32_t yOff )
const {
return mPtr[mGreenOff + xOff * mInc + yOff * mRowInc]; }
293 T&
b( int32_t xOff, int32_t yOff )
const {
return mPtr[mBlueOff + xOff * mInc + yOff * mRowInc]; }
295 T&
a( int32_t xOff, int32_t yOff )
const {
return mPtr[mAlphaOff + xOff * mInc + yOff * mRowInc]; }
300 return *(T*)((uint8_t*)( mPtr + mRedOff + xOff * mInc ) + yOff * mRowInc); }
304 return *(T*)((uint8_t*)( mPtr + mGreenOff + xOff * mInc ) + yOff * mRowInc); }
308 return *(T*)((uint8_t*)( mPtr + mBlueOff + xOff * mInc ) + yOff * mRowInc); }
312 return *(T*)((uint8_t*)( mPtr + mAlphaOff + xOff * mInc ) + yOff * mRowInc); }
315 const int32_t
x()
const {
return mX; }
317 const int32_t
y()
const {
return mY; }
332 mPtr =
reinterpret_cast<T*
>( mLinePtr );
345 uint8_t mRedOff, mGreenOff, mBlueOff, mAlphaOff, mInc;
348 int32_t mRowInc, mWidth, mHeight;
349 int32_t mX, mY, mStartX, mStartY, mEndX, mEndY;
357 mRedOff = iter.mRedOff;
358 mGreenOff = iter.mGreenOff;
359 mBlueOff = iter.mBlueOff;
360 mAlphaOff = iter.mAlphaOff;
362 mRowInc = iter.mRowInc;
363 mWidth = iter.mWidth;
364 mHeight = iter.mHeight;
365 mLinePtr = iter.mLinePtr;
367 mStartX = iter.mStartX;
369 mStartY = iter.mStartY;
383 mLinePtr =
reinterpret_cast<const uint8_t*
>( SurfaceT.
getData( clippedArea.
getUL() ) );
384 mPtr =
reinterpret_cast<const T*
>( mLinePtr );
385 mStartX = mX = clippedArea.
getX1();
386 mStartY = mY = clippedArea.
getY1();
387 mEndX = clippedArea.
getX2();
388 mEndY = clippedArea.
getY2();
390 mY = clippedArea.
getY1() - 1;
395 const T&
r()
const {
return mPtr[mRedOff]; }
397 const T&
g()
const {
return mPtr[mGreenOff]; }
399 const T&
b()
const {
return mPtr[mBlueOff]; }
401 const T&
a()
const {
return mPtr[mAlphaOff]; }
404 const T&
r( int32_t xOff, int32_t yOff )
const {
return mPtr[mRedOff + xOff * mInc + yOff * mRowInc]; }
406 const T&
g( int32_t xOff, int32_t yOff )
const {
return mPtr[mGreenOff + xOff * mInc + yOff * mRowInc]; }
408 const T&
b( int32_t xOff, int32_t yOff )
const {
return mPtr[mBlueOff + xOff * mInc + yOff * mRowInc]; }
410 const T&
a( int32_t xOff, int32_t yOff )
const {
return mPtr[mAlphaOff + xOff * mInc + yOff * mRowInc]; }
413 const T&
rClamped( int32_t xOff, int32_t yOff )
const
415 return *(T*)((uint8_t*)( mPtr + mRedOff + xOff * mInc ) + yOff * mRowInc); }
417 const T&
gClamped( int32_t xOff, int32_t yOff )
const
419 return *(T*)((uint8_t*)( mPtr + mGreenOff + xOff * mInc ) + yOff * mRowInc); }
421 const T&
bClamped( int32_t xOff, int32_t yOff )
const
423 return *(T*)((uint8_t*)( mPtr + mBlueOff + xOff * mInc ) + yOff * mRowInc); }
425 const T&
aClamped( int32_t xOff, int32_t yOff )
const
427 return *(T*)((uint8_t*)( mPtr + mAlphaOff + xOff * mInc ) + yOff * mRowInc); }
430 const int32_t
x()
const {
return mX; }
432 const int32_t
y()
const {
return mY; }
447 mPtr =
reinterpret_cast<const T*
>( mLinePtr );
460 uint8_t mRedOff, mGreenOff, mBlueOff, mAlphaOff, mInc;
461 const uint8_t *mLinePtr;
463 int32_t mRowInc, mWidth, mHeight;
464 int32_t mX, mY, mStartX, mStartY, mEndX, mEndY;
475 ConstIter
getIter(
const Area &area )
const {
return ConstIter( *
this, area ); }
479 virtual const char* what()
const throw() {
480 return "Surface exception";
485 virtual const char* what()
const throw() {
486 return "Surface exception: does not conform to expected SurfaceConstraints";
ConstIter getIter() const
Returns a ConstIter which iterates the entire Surface.
Definition: Surface.h:473
Base class for defining the properties of a Surface necessary to be interoperable with different APIs...
Definition: Surface.h:76
int32_t getY1() const
Definition: Area.h:69
ColorT< T > areaAverage(const Area &area) const
Returns an averaged color for the Area defined by area.
Definition: Surface.cpp:500
T b
Definition: Color.h:216
const T * getData(const Vec2i &offset) const
Definition: Surface.h:174
Area getBounds() const
Returns the bounding Area of the Surface in pixels: [0,0]-(width,height)
Definition: Surface.h:153
void copyFrom(const SurfaceT< T > &srcSurface, const Area &srcArea, const Vec2i &relativeOffset=Vec2i::zero())
Copies the Area srcArea of the Surface srcSurface to this Surface. The destination Area is srcArea of...
Definition: Surface.cpp:381
T & a(int32_t xOff, int32_t yOff) const
Returns a reference to the alpha value of the pixel that the Iter currently points to...
Definition: Surface.h:295
bool operator==(const SurfaceChannelOrder &sco) const
Definition: Surface.h:58
uint8_t getPixelInc() const
Returns the amount to increment a T* to increment by a pixel. Analogous to the number of channels...
Definition: Surface.h:163
ChannelT< T > & getChannelRed()
Returns a reference to the red Channel of the Surface.
Definition: Surface.h:210
int32_t getHeight() const
Returns the height of the Area the Iter iterates.
Definition: Surface.h:342
void setPixel(Vec2i pos, const ColorT< T > &c)
Convenience method for setting a single pixel. For performance-sensitive code consider Surface::Iter ...
Definition: Surface.h:230
int int * max
Definition: GLee.h:17208
An in-memory representation of an image. Implicitly shared object.
Definition: Surface.h:92
int32_t getY2() const
Definition: Area.h:73
int32_t getX2() const
Definition: Area.h:71
const T & g() const
Returns a reference to the green value of the pixel that the Iter currently points to...
Definition: Surface.h:397
const ChannelT< T > & getChannel(uint8_t channelIndex) const
Returns a const reference to a Channel channelIndex indexed according to how the channels are arrange...
Definition: Surface.h:207
const T * getDataAlpha(const Vec2i &offset) const
Definition: Surface.h:186
int32_t getWidth() const
Returns the width of the Area the Iter iterates.
Definition: Surface.h:340
GLenum GLsizei width
Definition: GLee.h:969
const int32_t x() const
Returns the x coordinate of the pixel the Iter currently points to.
Definition: Surface.h:315
ChannelT< T > & getChannel(uint8_t channelIndex)
Returns a reference to a Channel channelIndex indexed according to how the channels are arranged per ...
Definition: Surface.h:205
static Vec2< int > zero()
Definition: Vector.h:295
T b
Definition: Color.h:44
virtual ~SurfaceConstraints()
Definition: Surface.h:78
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: GLee.h:1011
T x
Definition: Vector.h:71
Iter(SurfaceT< T > &SurfaceT, const Area &area)
Definition: Surface.h:261
ChannelT< T > & getChannelAlpha()
Returns a reference to the alpha Channel of the Surface.
Definition: Surface.h:216
Vec2i getUL() const
Definition: Area.h:75
typedef void(APIENTRYP GLEEPFNGLBLENDCOLORPROC)(GLclampf red
T * getData()
Retuns the raw data of an image as a pointer to either uin8t_t values in the case of a Surface8u or f...
Definition: Surface.h:171
const int32_t x() const
Returns the x coordinate of the pixel the Iter currently points to.
Definition: Surface.h:430
const ChannelT< T > & getChannelGreen() const
Returns a const reference to the green Channel of the Surface.
Definition: Surface.h:221
uint8_t getBlueOffset() const
Returns the in-memory offset relative to a pixel for the red data. For example, for RGBA...
Definition: Surface.h:198
int getCode() const
Definition: Surface.h:56
std::shared_ptr< class ImageTarget > ImageTargetRef
Definition: ImageIo.h:42
uint8_t getGreenOffset() const
Definition: Surface.h:51
bool pixel()
Increments which pixel of the current row the Iter points to, and returns false when no pixels remain...
Definition: Surface.h:322
Specifies the in-memory ordering of the channels of a Surface.
Definition: Surface.h:42
int32_t getX1() const
Definition: Area.h:67
Vec2i getPos() const
Returns the coordinate of the pixel the Iter currently points to.
Definition: Surface.h:319
SurfaceT< uint8_t > Surface
8-bit image. Synonym for Surface8u.
Definition: Surface.h:491
int32_t getWidth() const
Returns the width of the Area the Iter iterates.
Definition: Surface.h:455
const int32_t y() const
Returns the y coordinate of the pixel the Iter currently points to.
Definition: Surface.h:317
const T & r() const
Returns a reference to the red value of the pixel that the Iter currently points to.
Definition: Surface.h:395
const T * getDataGreen(const Vec2i &offset) const
Definition: Surface.h:180
#define min(a, b)
Definition: AppImplMsw.cpp:36
T g
Definition: Color.h:44
SurfaceT()
Constructs an empty Surface, which is the equivalent of NULL and should not be used directly...
Definition: Surface.h:117
uint8_t getGreenOffset() const
Returns the in-memory offset relative to a pixel for the red data. For example, for RGBA...
Definition: Surface.h:196
bool hasAlpha() const
Definition: Surface.h:54
void setPixel(Vec2i pos, const ColorAT< T > &c)
Convenience method for setting a single pixel. For performance-sensitive code consider Surface::Iter ...
Definition: Surface.h:232
virtual SurfaceChannelOrder getChannelOrder(bool alpha) const
Definition: Surface.h:80
const ChannelT< T > & getChannelRed() const
Returns a const reference to the red Channel of the Surface.
Definition: Surface.h:219
const T * getData() const
Definition: Surface.h:172
void setDeallocator(void(*aDeallocatorFunc)(void *), void *aDeallocatorRefcon)
Definition: Surface.cpp:339
bool line()
Increments which row the Iter points to, and returns false when no rows remain in the Surface...
Definition: Surface.h:329
const T & aClamped(int32_t xOff, int32_t yOff) const
Returns the alpha value of the pixel that the Iter currently points to, offset by (xOff...
Definition: Surface.h:425
virtual int32_t getRowBytes(int requestedWidth, const SurfaceChannelOrder &sco, int elementSize) const
Definition: Surface.h:81
const T & a(int32_t xOff, int32_t yOff) const
Returns a reference to the alpha value of the pixel that the Iter currently points to...
Definition: Surface.h:410
ConstIter(const Iter &iter)
Definition: Surface.h:356
ConstIter getIter(const Area &area) const
Returns a ConstIter which iterates the Area area.
Definition: Surface.h:475
const ChannelT< T > & getChannelBlue() const
Returns a const reference to the blue Channel of the Surface.
Definition: Surface.h:223
int32_t getWidth() const
Definition: Area.h:47
GLenum GLsizei GLsizei height
Definition: GLee.h:1029
T & bClamped(int32_t xOff, int32_t yOff) const
Returns a reference to the blue value of the pixel that the Iter currently points to...
Definition: Surface.h:306
GLclampf GLclampf GLclampf alpha
Definition: GLee.h:951
bool isPremultiplied() const
Returns whether the Surface color data is premultiplied by its alpha channel or not.
Definition: Surface.h:157
T & a() const
Returns a reference to the alpha value of the pixel that the Iter currently points to...
Definition: Surface.h:286
const T & b() const
Returns a reference to the blue value of the pixel that the Iter currently points to...
Definition: Surface.h:399
T & b(int32_t xOff, int32_t yOff) const
Returns a reference to the blue value of the pixel that the Iter currently points to...
Definition: Surface.h:293
const SurfaceChannelOrder & getChannelOrder() const
Returns the channel order of the Surface, the in-memory ordering of the channels of each pixel...
Definition: Surface.h:192
uint8_t getAlphaOffset() const
Returns the in-memory offset relative to a pixel for the red data. For example, for RGBA...
Definition: Surface.h:200
Definition: Surface.h:484
Iter getIter()
Returns an Iter which iterates the entire Surface.
Definition: Surface.h:469
Area getClipBy(const Area &clip) const
Definition: Area.cpp:82
bool pixel()
Increments which pixel of the current row the Iter points to, and returns false when no pixels remain...
Definition: Surface.h:437
GLintptr offset
Definition: GLee.h:2095
uint8_t getAlphaOffset() const
Definition: Surface.h:53
uint8_t getBlueOffset() const
Definition: Surface.h:52
A single channel of image data, either a color channel of a Surface or a grayscale image...
Definition: Channel.h:37
ChannelT< T > & getChannelBlue()
Returns a reference to the blue Channel of the Surface.
Definition: Surface.h:214
ColorAT< T > getPixel(Vec2i pos) const
Convenience method for getting a single pixel. For performance-sensitive code consider Surface::Iter ...
Definition: Surface.h:228
uint8_t getRedOffset() const
Definition: Surface.h:50
T & r(int32_t xOff, int32_t yOff) const
Returns a reference to the red value of the pixel that the Iter currently points to, offset by (xOff, yOff) pixels.
Definition: Surface.h:289
T * getDataBlue(const Vec2i &offset)
Returns a pointer to the blue channel data of the pixel located at offset. Result is a uint8_t* for S...
Definition: Surface.h:182
T * getData(const Vec2i &offset)
Definition: Surface.h:173
int32_t getRowBytes() const
Returns the width of a row of the Surface measured in bytes, which is not necessarily getWidth() * ge...
Definition: Surface.h:161
Iter getIter(const Area &area)
Returns an Iter which iterates the Area area.
Definition: Surface.h:471
const T & b(int32_t xOff, int32_t yOff) const
Returns a reference to the blue value of the pixel that the Iter currently points to...
Definition: Surface.h:408
bool hasAlpha() const
Returns whether the Surface contains an alpha channel.
Definition: Surface.h:155
const T & bClamped(int32_t xOff, int32_t yOff) const
Returns the blue value of the pixel that the Iter currently points to, offset by (xOff, yOff) pixels. Clamps offset to the bounds of the Iter.
Definition: Surface.h:421
uint8_t getPixelInc() const
Definition: Surface.h:55
T & g() const
Returns a reference to the green value of the pixel that the Iter currently points to...
Definition: Surface.h:282
const T & gClamped(int32_t xOff, int32_t yOff) const
Returns the green value of the pixel that the Iter currently points to, offset by (xOff...
Definition: Surface.h:417
T & g(int32_t xOff, int32_t yOff) const
Returns a reference to the green value of the pixel that the Iter currently points to...
Definition: Surface.h:291
T y
Definition: Vector.h:71
Vec2i getPos() const
Returns the coordinate of the pixel the Iter currently points to.
Definition: Surface.h:434
Convenience class for iterating the pixels of a Surface. The iteration is const, performing read-only...
Definition: Surface.h:354
GLfloat GLfloat p
Definition: GLee.h:8473
Definition: Surface.h:478
int32_t getHeight() const
Returns the height of the Area the Iter iterates.
Definition: Surface.h:457
const ChannelT< T > & getChannelAlpha() const
Returns a const reference to the alpha Channel of the Surface.
Definition: Surface.h:225
const GLubyte * c
Definition: GLee.h:8491
SurfaceT< uint8_t > Surface8u
8-bit image
Definition: Surface.h:493
int32_t getWidth() const
Returns the width of the Surface in pixels.
Definition: Surface.h:145
SurfaceChannelOrder()
Definition: Surface.h:44
T & aClamped(int32_t xOff, int32_t yOff) const
Returns a reference to the alpha value of the pixel that the Iter currently points to...
Definition: Surface.h:310
ChannelT< T > & getChannelGreen()
Returns a reference to the green Channel of the Surface.
Definition: Surface.h:212
const T & r(int32_t xOff, int32_t yOff) const
Returns a reference to the red value of the pixel that the Iter currently points to, offset by (xOff, yOff) pixels.
Definition: Surface.h:404
bool line()
Increments which row the Iter points to, and returns false when no rows remain in the Surface...
Definition: Surface.h:444
T a
Definition: Color.h:216
T * getDataGreen(const Vec2i &offset)
Returns a pointer to the green channel data of the pixel located at offset. Result is a uint8_t* for ...
Definition: Surface.h:179
T r
Definition: Color.h:216
GLboolean reset
Definition: GLee.h:1101
void setChannelOrder(const SurfaceChannelOrder &aChannelOrder)
Sets the channel order of the Surface, the in-memory ordering of the channels of each pixel...
Definition: Surface.cpp:375
SurfaceT clone(bool copyPixels=true) const
Returns a new Surface which is a duplicate. If copyPixels the pixel values are copied, otherwise the clone's pixels remain uninitialized.
Definition: Surface.cpp:319
const T & a() const
Returns a reference to the alpha value of the pixel that the Iter currently points to...
Definition: Surface.h:401
Convenience class for iterating the pixels of a Surface.
Definition: Surface.h:259
bool setPremultiplied(bool premult=true) const
Sets whether the Surface color data should be interpreted as being premultiplied by its alpha channel...
Definition: Surface.h:159
const T * getDataBlue(const Vec2i &offset) const
Definition: Surface.h:183
int getImageIoChannelOrder() const
Translates a SurfaceChannelOrder into an ImageIo::ChannelOrder.
Definition: Surface.cpp:171
int32_t getHeight() const
Returns the height of the Surface in pixels.
Definition: Surface.h:147
float getAspectRatio() const
Returns the Surface aspect ratio, which is its width / height.
Definition: Surface.h:151
Vec2i getSize() const
Returns the size of the Surface in pixels.
Definition: Surface.h:149
T & rClamped(int32_t xOff, int32_t yOff) const
Returns a reference to the red value of the pixel that the Iter currently points to, offset by (xOff, yOff) pixels. Clamps offset to the bounds of the Iter.
Definition: Surface.h:298
std::shared_ptr< class ImageSource > ImageSourceRef
Definition: Channel.h:33
SurfaceT< uint16_t > Surface16u
16-bit image. Suitable as an intermediate representation and ImageIo but not a first-class citizen...
Definition: Surface.h:495
const int32_t y() const
Returns the t coordinate of the pixel the Iter currently points to.
Definition: Surface.h:432
T & gClamped(int32_t xOff, int32_t yOff) const
Returns a reference to the green value of the pixel that the Iter currently points to...
Definition: Surface.h:302
ConstIter(const SurfaceT< T > &SurfaceT, const Area &area)
Definition: Surface.h:375
T & b() const
Returns a reference to the blue value of the pixel that the Iter currently points to...
Definition: Surface.h:284
const T & rClamped(int32_t xOff, int32_t yOff) const
Returns the red value of the pixel that the Iter currently points to, offset by (xOff, yOff) pixels. Clamps offset to the bounds of the Iter.
Definition: Surface.h:413
const T & g(int32_t xOff, int32_t yOff) const
Returns a reference to the green value of the pixel that the Iter currently points to...
Definition: Surface.h:406
const T * getDataRed(const Vec2i &offset) const
Definition: Surface.h:177
T * getDataAlpha(const Vec2i &offset)
Returns a pointer to the alpha channel data of the pixel located at offset. Result is a uint8_t* for ...
Definition: Surface.h:185
T r
Definition: Color.h:44
T g
Definition: Color.h:216
SurfaceT< float > Surface32f
32-bit floating point image
Definition: Surface.h:497
T & r() const
Returns a reference to the red value of the pixel that the Iter currently points to.
Definition: Surface.h:280
int32_t getHeight() const
Definition: Area.h:48
uint8_t getRedOffset() const
Returns the in-memory offset relative to a pixel for the red data. For example, for RGBA...
Definition: Surface.h:194
T * getDataRed(const Vec2i &offset)
Returns a pointer to the red channel data of the pixel located at offset. Result is a uint8_t* for Su...
Definition: Surface.h:176
Vec2< int > Vec2i
Definition: Vector.h:1313