Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Surface.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2010, The Cinder Project, All rights reserved.
3  Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
4 
5  This code is intended for use with the Cinder C++ library: http://libcinder.org
6 
7  Portions Copyright (c) 2010, The Barbarian Group
8  All rights reserved.
9 
10  Redistribution and use in source and binary forms, with or without modification, are permitted provided that
11  the following conditions are met:
12 
13  * Redistributions of source code must retain the above copyright notice, this list of conditions and
14  the following disclaimer.
15  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
16  the following disclaimer in the documentation and/or other materials provided with the distribution.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
19  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
21  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
22  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  POSSIBILITY OF SUCH DAMAGE.
26 */
27 
28 #pragma once
29 
30 #include "cinder/Cinder.h"
31 #include "cinder/Area.h"
32 #include "cinder/Channel.h"
33 #include "cinder/ChanTraits.h"
34 #include "cinder/Color.h"
35 #include "cinder/Filesystem.h"
36 
37 #include <boost/logic/tribool.hpp>
38 
39 namespace cinder {
40 
43  public:
44  SurfaceChannelOrder() : mCode( UNSPECIFIED ), mRed( INVALID ), mGreen( INVALID ), mBlue( INVALID ), mAlpha( INVALID ), mPixelInc( INVALID ) {}
45  SurfaceChannelOrder( int aCode );
47 
48 // static ChannelOrder GetPlatformNativeChannelOrder( bool includeAlpha );
49 
50  uint8_t getRedOffset() const { return mRed; }
51  uint8_t getGreenOffset() const { return mGreen; }
52  uint8_t getBlueOffset() const { return mBlue; }
53  uint8_t getAlphaOffset() const { return mAlpha; }
54  bool hasAlpha() const { return ( mAlpha != INVALID ) ? true : false; }
55  uint8_t getPixelInc() const { return mPixelInc; }
56  int getCode() const { return mCode; }
57 
58  bool operator==( const SurfaceChannelOrder& sco ) const
59  {
60  return mCode == sco.mCode;
61  }
62 
64  enum { RGBA, BGRA, ARGB, ABGR, RGBX, BGRX, XRGB, XBGR, RGB, BGR, UNSPECIFIED }; // Codes
65 
66  int getImageIoChannelOrder() const;
67 
68  private:
69  void set( uint8_t aRed, uint8_t aGreen, uint8_t aBlue, uint8_t aAlpha, uint8_t aPixelInc );
70  int mCode; // the enum
71  uint8_t mRed, mGreen, mBlue, mAlpha, mPixelInc;
72 
73 };
74 
77  public:
78  virtual ~SurfaceConstraints() {}
79 
81  virtual int32_t getRowBytes( int requestedWidth, const SurfaceChannelOrder &sco, int elementSize ) const { return requestedWidth * elementSize * sco.getPixelInc(); }
82 };
83 
85 };
86 
87 typedef std::shared_ptr<class ImageSource> ImageSourceRef;
88 typedef std::shared_ptr<class ImageTarget> ImageTargetRef;
89 
90 template<typename T>
92 class SurfaceT {
93  private:
95  struct Obj {
96  Obj( int32_t aWidth, int32_t aHeight, SurfaceChannelOrder aChannelOrder, T *aData, bool aOwnsData, int32_t aRowBytes );
97  ~Obj();
98 
99  void initChannels();
100  void setChannelOrder( const SurfaceChannelOrder &aChannelOrder );
101  void setDeallocator( void(*aDeallocatorFunc)( void * ), void *aDeallocatorRefcon );
102 
103  int32_t mWidth, mHeight, mRowBytes;
104  bool mIsPremultiplied;
105  T *mData;
106  bool mOwnsData;
107  SurfaceChannelOrder mChannelOrder;
108  ChannelT<T> mChannels[4];
109 
110  void (*mDeallocatorFunc)(void *refcon);
111  void *mDeallocatorRefcon;
112  };
114 
115  public:
117  SurfaceT() {}
123  SurfaceT( int32_t width, int32_t height, bool alpha, SurfaceChannelOrder channelOrder = SurfaceChannelOrder::UNSPECIFIED );
124  SurfaceT( int32_t width, int32_t height, bool alpha, const SurfaceConstraints &constraints );
126  SurfaceT( T *data, int32_t width, int32_t height, int32_t rowBytes, SurfaceChannelOrder channelOrder );
132  SurfaceT( ImageSourceRef imageSource, const SurfaceConstraints &constraints = SurfaceConstraintsDefault(), boost::tribool alpha = boost::logic::indeterminate );
133 
134 #if defined( CINDER_WINRT )
135 
138  static void loadImageAsync(const fs::path path, SurfaceT &surface, const SurfaceConstraints &constraints = SurfaceConstraintsDefault(), boost::tribool alpha = boost::logic::indeterminate );
139 #endif
140 
141  operator ImageSourceRef() const;
142  operator ImageTargetRef();
143 
145  int32_t getWidth() const { return mObj->mWidth; }
147  int32_t getHeight() const { return mObj->mHeight; }
149  Vec2i getSize() const { return Vec2i( mObj->mWidth, mObj->mHeight ); }
151  float getAspectRatio() const { return mObj->mWidth / (float)mObj->mHeight; }
153  Area getBounds() const { return Area( 0, 0, mObj->mWidth, mObj->mHeight ); }
155  bool hasAlpha() const { return mObj->mChannelOrder.hasAlpha(); }
157  bool isPremultiplied() const { return mObj->mIsPremultiplied; }
159  bool setPremultiplied( bool premult = true ) const { return mObj->mIsPremultiplied = premult; }
161  int32_t getRowBytes() const { return mObj->mRowBytes; }
163  uint8_t getPixelInc() const { return mObj->mChannelOrder.getPixelInc(); }
164 
166  SurfaceT clone( bool copyPixels = true ) const;
168  SurfaceT clone( const Area &area, bool copyPixels = true ) const;
169 
171  T* getData() { return mObj->mData; }
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 ); }
176  T* getDataRed( const Vec2i &offset ) { return getData( offset ) + getRedOffset(); }
177  const T* getDataRed( const Vec2i &offset ) const { return getData( offset ) + getRedOffset(); }
179  T* getDataGreen( const Vec2i &offset ) { return getData( offset ) + getGreenOffset(); }
180  const T* getDataGreen( const Vec2i &offset ) const { return getData( offset ) + getGreenOffset(); }
182  T* getDataBlue( const Vec2i &offset ) { return getData( offset ) + getBlueOffset(); }
183  const T* getDataBlue( const Vec2i &offset ) const { return getData( offset ) + getBlueOffset(); }
185  T* getDataAlpha( const Vec2i &offset ) { return getData( offset ) + getAlphaOffset(); }
186  const T* getDataAlpha( const Vec2i &offset ) const { return getData( offset ) + getAlphaOffset(); }
187 
189  void setDeallocator( void(*aDeallocatorFunc)( void * ), void *aDeallocatorRefcon );
190 
192  const SurfaceChannelOrder& getChannelOrder() const { return mObj->mChannelOrder; }
194  uint8_t getRedOffset() const { return mObj->mChannelOrder.getRedOffset(); }
196  uint8_t getGreenOffset() const { return mObj->mChannelOrder.getGreenOffset(); }
198  uint8_t getBlueOffset() const { return mObj->mChannelOrder.getBlueOffset(); }
200  uint8_t getAlphaOffset() const { return mObj->mChannelOrder.getAlphaOffset(); }
202  void setChannelOrder( const SurfaceChannelOrder &aChannelOrder );
203 
205  ChannelT<T>& getChannel( uint8_t channelIndex ) { return mObj->mChannels[channelIndex]; }
207  const ChannelT<T>& getChannel( uint8_t channelIndex ) const { return mObj->mChannels[channelIndex]; }
208 
217 
219  const ChannelT<T>& getChannelRed() const { return mObj->mChannels[SurfaceChannelOrder::CHAN_RED]; }
221  const ChannelT<T>& getChannelGreen() const { return mObj->mChannels[SurfaceChannelOrder::CHAN_GREEN]; }
223  const ChannelT<T>& getChannelBlue() const { return mObj->mChannels[SurfaceChannelOrder::CHAN_BLUE]; }
225  const ChannelT<T>& getChannelAlpha() const { return mObj->mChannels[SurfaceChannelOrder::CHAN_ALPHA]; }
226 
228  ColorAT<T> getPixel( Vec2i pos ) const { pos.x = constrain<int32_t>( pos.x, 0, mObj->mWidth - 1); pos.y = constrain<int32_t>( pos.y, 0, mObj->mHeight - 1 ); const T *p = getData( pos ); return ColorAT<T>( p[getRedOffset()], p[getGreenOffset()], p[getBlueOffset()], ( hasAlpha() ) ? p[getAlphaOffset()] : CHANTRAIT<T>::max() ); }
230  void setPixel( Vec2i pos, const ColorT<T> &c ) { pos.x = constrain<int32_t>( pos.x, 0, mObj->mWidth - 1); pos.y = constrain<int32_t>( pos.y, 0, mObj->mHeight - 1 ); T *p = getData( pos ); p[getRedOffset()] = c.r; p[getGreenOffset()] = c.g; p[getBlueOffset()] = c.b; }
232  void setPixel( Vec2i pos, const ColorAT<T> &c ) { pos.x = constrain<int32_t>( pos.x, 0, mObj->mWidth - 1); pos.y = constrain<int32_t>( pos.y, 0, mObj->mHeight - 1 ); T *p = getData( pos ); p[getRedOffset()] = c.r; p[getGreenOffset()] = c.g; p[getBlueOffset()] = c.b; if( hasAlpha() ) p[getAlphaOffset()] = c.a; }
233 
235  void copyFrom( const SurfaceT<T> &srcSurface, const Area &srcArea, const Vec2i &relativeOffset = Vec2i::zero() );
236 
238  ColorT<T> areaAverage( const Area &area ) const;
239 
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(); }
245 
246  private:
247  std::shared_ptr<Obj> mObj;
248 
249  void init( ImageSourceRef imageSource, const SurfaceConstraints &constraints = SurfaceConstraintsDefault(), boost::tribool alpha = boost::logic::indeterminate );
250 
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 );
255 
256  public:
257 
259  class Iter {
260  public:
261  Iter( SurfaceT<T> &SurfaceT, const Area &area )
262  : mRedOff( SurfaceT.getRedOffset() ), mGreenOff( SurfaceT.getGreenOffset() ),
263  mBlueOff( SurfaceT.getBlueOffset() ), mAlphaOff( SurfaceT.getAlphaOffset() ),
264  mInc( SurfaceT.getPixelInc() ), mRowInc( SurfaceT.getRowBytes() )
265  {
266  Area clippedArea( area.getClipBy( SurfaceT.getBounds() ) );
267  mWidth = clippedArea.getWidth();
268  mHeight = clippedArea.getHeight();
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();
275  // in order to be at the right place after an initial call to line(), we need to back up one line
276  mY = clippedArea.getY1() - 1;
277  mLinePtr -= mRowInc;
278  }
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]; }
287 
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]; }
296 
298  T& rClamped( int32_t xOff, int32_t yOff ) const
299  { xOff = std::min(std::max(mX + xOff, mStartX),mEndX - 1) - mX; yOff = std::min(std::max( mY + yOff, mStartY ), mEndY - 1) - mY;
300  return *(T*)((uint8_t*)( mPtr + mRedOff + xOff * mInc ) + yOff * mRowInc); }
302  T& gClamped( int32_t xOff, int32_t yOff ) const
303  { xOff = std::min(std::max(mX + xOff, mStartX),mEndX - 1) - mX; yOff = std::min(std::max( mY + yOff, mStartY ), mEndY - 1) - mY;
304  return *(T*)((uint8_t*)( mPtr + mGreenOff + xOff * mInc ) + yOff * mRowInc); }
306  T& bClamped( int32_t xOff, int32_t yOff ) const
307  { xOff = std::min(std::max(mX + xOff, mStartX),mEndX - 1) - mX; yOff = std::min(std::max( mY + yOff, mStartY ), mEndY - 1) - mY;
308  return *(T*)((uint8_t*)( mPtr + mBlueOff + xOff * mInc ) + yOff * mRowInc); }
310  T& aClamped( int32_t xOff, int32_t yOff ) const
311  { xOff = std::min(std::max(mX + xOff, mStartX),mEndX - 1) - mX; yOff = std::min(std::max( mY + yOff, mStartY ), mEndY - 1) - mY;
312  return *(T*)((uint8_t*)( mPtr + mAlphaOff + xOff * mInc ) + yOff * mRowInc); }
313 
315  const int32_t x() const { return mX; }
317  const int32_t y() const { return mY; }
319  Vec2i getPos() const { return Vec2i( mX, mY ); }
320 
322  bool pixel() {
323  ++mX;
324  mPtr += mInc;
325  return mX < mEndX;
326  }
327 
329  bool line() {
330  ++mY;
331  mLinePtr += mRowInc;
332  mPtr = reinterpret_cast<T*>( mLinePtr );
333  // in order to be at the right place after an initial call to pixel(), we need to back up one pixel
334  mPtr -= mInc;
335  mX = mStartX - 1;
336  return mY < mEndY;
337  }
338 
340  int32_t getWidth() const { return mWidth; }
342  int32_t getHeight() const { return mHeight; }
343 
345  uint8_t mRedOff, mGreenOff, mBlueOff, mAlphaOff, mInc;
346  uint8_t *mLinePtr;
347  T *mPtr;
348  int32_t mRowInc, mWidth, mHeight;
349  int32_t mX, mY, mStartX, mStartY, mEndX, mEndY;
351  };
352 
354  class ConstIter {
355  public:
356  ConstIter( const Iter &iter ) {
357  mRedOff = iter.mRedOff;
358  mGreenOff = iter.mGreenOff;
359  mBlueOff = iter.mBlueOff;
360  mAlphaOff = iter.mAlphaOff;
361  mInc = iter.mInc;
362  mRowInc = iter.mRowInc;
363  mWidth = iter.mWidth;
364  mHeight = iter.mHeight;
365  mLinePtr = iter.mLinePtr;
366  mPtr = iter.mPtr;
367  mStartX = iter.mStartX;
368  mX = iter.mX;
369  mStartY = iter.mStartY;
370  mY = iter.mY;
371  mEndX = iter.mEndX;
372  mEndY = iter.mEndY;
373  }
374 
375  ConstIter( const SurfaceT<T> &SurfaceT, const Area &area )
376  : mRedOff( SurfaceT.getRedOffset() ), mGreenOff( SurfaceT.getGreenOffset() ),
377  mBlueOff( SurfaceT.getBlueOffset() ), mAlphaOff( SurfaceT.getAlphaOffset() ),
378  mInc( SurfaceT.getPixelInc() ), mRowInc( SurfaceT.getRowBytes() )
379  {
380  Area clippedArea( area.getClipBy( SurfaceT.getBounds() ) );
381  mWidth = clippedArea.getWidth();
382  mHeight = clippedArea.getHeight();
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();
389  // in order to be at the right place after an initial call to line(), we need to back up one line
390  mY = clippedArea.getY1() - 1;
391  mLinePtr -= mRowInc;
392  }
393 
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]; }
402 
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]; }
411 
413  const T& rClamped( int32_t xOff, int32_t yOff ) const
414  { xOff = std::min(std::max(mX + xOff, mStartX),mEndX - 1) - mX; yOff = std::min(std::max( mY + yOff, mStartY ), mEndY - 1) - mY;
415  return *(T*)((uint8_t*)( mPtr + mRedOff + xOff * mInc ) + yOff * mRowInc); }
417  const T& gClamped( int32_t xOff, int32_t yOff ) const
418  { xOff = std::min(std::max(mX + xOff, mStartX),mEndX - 1) - mX; yOff = std::min(std::max( mY + yOff, mStartY ), mEndY - 1) - mY;
419  return *(T*)((uint8_t*)( mPtr + mGreenOff + xOff * mInc ) + yOff * mRowInc); }
421  const T& bClamped( int32_t xOff, int32_t yOff ) const
422  { xOff = std::min(std::max(mX + xOff, mStartX),mEndX - 1) - mX; yOff = std::min(std::max( mY + yOff, mStartY ), mEndY - 1) - mY;
423  return *(T*)((uint8_t*)( mPtr + mBlueOff + xOff * mInc ) + yOff * mRowInc); }
425  const T& aClamped( int32_t xOff, int32_t yOff ) const
426  { xOff = std::min(std::max(mX + xOff, mStartX),mEndX - 1) - mX; yOff = std::min(std::max( mY + yOff, mStartY ), mEndY - 1) - mY;
427  return *(T*)((uint8_t*)( mPtr + mAlphaOff + xOff * mInc ) + yOff * mRowInc); }
428 
430  const int32_t x() const { return mX; }
432  const int32_t y() const { return mY; }
434  Vec2i getPos() const { return Vec2i( mX, mY ); }
435 
437  bool pixel() {
438  ++mX;
439  mPtr += mInc;
440  return mX < mEndX;
441  }
442 
444  bool line() {
445  ++mY;
446  mLinePtr += mRowInc;
447  mPtr = reinterpret_cast<const T*>( mLinePtr );
448  // in order to be at the right place after an initial call to pixel(), we need to back up one pixel
449  mPtr -= mInc;
450  mX = mStartX - 1;
451  return mY < mEndY;
452  }
453 
455  int32_t getWidth() const { return mWidth; }
457  int32_t getHeight() const { return mHeight; }
458 
460  uint8_t mRedOff, mGreenOff, mBlueOff, mAlphaOff, mInc;
461  const uint8_t *mLinePtr;
462  const T *mPtr;
463  int32_t mRowInc, mWidth, mHeight;
464  int32_t mX, mY, mStartX, mStartY, mEndX, mEndY;
466  };
467 
469  Iter getIter() { return Iter( *this, this->getBounds() ); }
471  Iter getIter( const Area &area ) { return Iter( *this, area ); }
473  ConstIter getIter() const { return ConstIter( *this, this->getBounds() ); }
475  ConstIter getIter( const Area &area ) const { return ConstIter( *this, area ); }
476 };
477 
478 class SurfaceExc : public std::exception {
479  virtual const char* what() const throw() {
480  return "Surface exception";
481  }
482 };
483 
485  virtual const char* what() const throw() {
486  return "Surface exception: does not conform to expected SurfaceConstraints";
487  }
488 };
489 
498 
499 } // namespace cinder
ConstIter getIter() const
Returns a ConstIter which iterates the entire Surface.
Definition: Surface.h:473
Definition: Surface.h:64
Definition: Surface.h:64
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
Definition: Surface.h:64
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
Definition: Surface.h:64
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
Definition: Area.h:37
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
Definition: Surface.h:63
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
Definition: Color.h:214
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
Definition: Surface.h:64
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
Definition: Surface.h:64
Definition: Surface.h:64
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
Definition: Surface.h:84
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
Definition: Surface.h:64
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
Definition: Surface.h:64
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
Definition: Surface.h:64
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
Definition: Color.h:41
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