cinder::SurfaceT< T >::ConstIter Class Reference

Convenience class for iterating the pixels of a Surface. The iteration is const, performing read-only operations on the Surface. More...

#include <Surface.h>

List of all members.

Public Member Functions

 ConstIter (const Iter &iter)
 ConstIter (const SurfaceT< T > &SurfaceT, const Area &area)
const T & r () const
 Returns a reference to the red value of the pixel that the Iter currently points to.
const T & g () const
 Returns a reference to the green value of the pixel that the Iter currently points to.
const T & b () const
 Returns a reference to the blue value of the pixel that the Iter currently points to.
const T & a () const
 Returns a reference to the alpha value of the pixel that the Iter currently points to. Undefined in the absence of an alpha channel.
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.
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, offset by (xOff, yOff) pixels.
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, offset by (xOff, yOff) pixels.
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, offset by (xOff, yOff) pixels.
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.
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, yOff) pixels. Clamps offset to the bounds of the Iter.
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.
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, yOff) pixels. Clamps offset to the bounds of the Iter. Undefined in the absence of an alpha channel.
const int32_t x () const
 Returns the x coordinate of the pixel the Iter currently points to.
const int32_t y () const
 Returns the t coordinate of the pixel the Iter currently points to.
Vec2i getPos () const
 Returns the coordinate of the pixel the Iter currently points to.
bool pixel ()
 Increments which pixel of the current row the Iter points to, and returns false when no pixels remain in the current row.
bool line ()
 Increments which row the Iter points to, and returns false when no rows remain in the Surface.
int32_t getWidth () const
 Returns the width of the Area the Iter iterates.
int32_t getHeight () const
 Returns the height of the Area the Iter iterates.

Detailed Description

template<typename T>
class cinder::SurfaceT< T >::ConstIter

Convenience class for iterating the pixels of a Surface. The iteration is const, performing read-only operations on the Surface.

The ConstIter class can be used to walk the pixels of a Surface using a nested for-loop, where the outer loop calls line(), and the inner calls pixel().
The code below finds the maximum red value in the Area area of surface:

Surface::ConstIter iter = surface.getIter( area );
uint8_t maxRed = 0;
while( iter.line() ) {
    while( iter.pixel() ) {
        if( iter.r() > maxRed )
            maxRed = iter.r();
    }
}

In addition to r(), g(), b() and a(), the Iter provides accessors which accept an offset in x & y relative to the current location:

inputIter.r(1, 1); // will return the red value of the pixel to the lower right of the current pixel
inputIter.b(0, -1); // will return the blue value of the pixel directly above the current pixel

A final family accessors, rClamped(), gClamped(), bClamped() and aClamped() also accept an x & y relative offset, but will not sample outside of the bounds of the iterator.

inputIter.rClamped(-2,0); // when called on the left edge of a row,
                          //this will simply return the left-most pixel's red value
See also:
cinder::SurfaceT::Iter
Images in Cinder

Constructor & Destructor Documentation

template<typename T>
cinder::SurfaceT< T >::ConstIter::ConstIter ( const Iter iter  ) 
template<typename T>
cinder::SurfaceT< T >::ConstIter::ConstIter ( const SurfaceT< T > &  SurfaceT,
const Area area 
)

Member Function Documentation

template<typename T>
const T& cinder::SurfaceT< T >::ConstIter::r (  )  const

Returns a reference to the red value of the pixel that the Iter currently points to.

template<typename T>
const T& cinder::SurfaceT< T >::ConstIter::g (  )  const

Returns a reference to the green value of the pixel that the Iter currently points to.

template<typename T>
const T& cinder::SurfaceT< T >::ConstIter::b (  )  const

Returns a reference to the blue value of the pixel that the Iter currently points to.

template<typename T>
const T& cinder::SurfaceT< T >::ConstIter::a (  )  const

Returns a reference to the alpha value of the pixel that the Iter currently points to. Undefined in the absence of an alpha channel.

template<typename T>
const T& cinder::SurfaceT< T >::ConstIter::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.

template<typename T>
const T& cinder::SurfaceT< T >::ConstIter::g ( int32_t  xOff,
int32_t  yOff 
) const

Returns a reference to the green value of the pixel that the Iter currently points to, offset by (xOff, yOff) pixels.

template<typename T>
const T& cinder::SurfaceT< T >::ConstIter::b ( int32_t  xOff,
int32_t  yOff 
) const

Returns a reference to the blue value of the pixel that the Iter currently points to, offset by (xOff, yOff) pixels.

template<typename T>
const T& cinder::SurfaceT< T >::ConstIter::a ( int32_t  xOff,
int32_t  yOff 
) const

Returns a reference to the alpha value of the pixel that the Iter currently points to, offset by (xOff, yOff) pixels.

template<typename T>
const T& cinder::SurfaceT< T >::ConstIter::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.

template<typename T>
const T& cinder::SurfaceT< T >::ConstIter::gClamped ( int32_t  xOff,
int32_t  yOff 
) const

Returns the green value of the pixel that the Iter currently points to, offset by (xOff, yOff) pixels. Clamps offset to the bounds of the Iter.

template<typename T>
const T& cinder::SurfaceT< T >::ConstIter::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.

template<typename T>
const T& cinder::SurfaceT< T >::ConstIter::aClamped ( int32_t  xOff,
int32_t  yOff 
) const

Returns the alpha value of the pixel that the Iter currently points to, offset by (xOff, yOff) pixels. Clamps offset to the bounds of the Iter. Undefined in the absence of an alpha channel.

template<typename T>
const int32_t cinder::SurfaceT< T >::ConstIter::x (  )  const

Returns the x coordinate of the pixel the Iter currently points to.

template<typename T>
const int32_t cinder::SurfaceT< T >::ConstIter::y (  )  const

Returns the t coordinate of the pixel the Iter currently points to.

template<typename T>
Vec2i cinder::SurfaceT< T >::ConstIter::getPos (  )  const

Returns the coordinate of the pixel the Iter currently points to.

template<typename T>
bool cinder::SurfaceT< T >::ConstIter::pixel (  ) 

Increments which pixel of the current row the Iter points to, and returns false when no pixels remain in the current row.

template<typename T>
bool cinder::SurfaceT< T >::ConstIter::line (  ) 

Increments which row the Iter points to, and returns false when no rows remain in the Surface.

template<typename T>
int32_t cinder::SurfaceT< T >::ConstIter::getWidth (  )  const

Returns the width of the Area the Iter iterates.

template<typename T>
int32_t cinder::SurfaceT< T >::ConstIter::getHeight (  )  const

Returns the height of the Area the Iter iterates.


The documentation for this class was generated from the following file: