An in-memory representation of an image. Implicitly shared object.

A Surface always contains red, green and blue data, along with an optional alpha channel.

Surfaces come in two primary configurations, the traditional 8-bits per channel represented by Surface8u, and a float per channel, suitable for high dynamic range images, represented by Surface32f. Surface is a short-hand synonym for Surface8u.

Surfaces are a CPU-based image representation, and must be converted appropriately to be drawn using the GPU. For example,to be used with OpenGL, the gl::Texture is a natural choice, and it can be constructed directly from a Surface.

To manipulate individual pixels of a Surface, the Surface::Iter class can be used.

To allocate a Surface that is 640x480 and has an alpha channel, use:

Surface mySurface( 640, 480, true );

A Surface can be created from an image file using the result of loadImage():

Surface bitmap( loadImage( "image.jpg" ) );

The pixels of each row of a Surface are stored in contiguous memory, and the start of each row is offset from the previous by the stride (measured in bytes) returned by getRowBytes(). Pixels can be ordered in memory in a number of configurations, specified using the SurfaceChannelOrder class.


Public Member Functions

  • SurfaceT< T > &
    operator= (const SurfaceT< T > &rhs)
  • SurfaceT< T > &
    operator= (SurfaceT< T > &&rhs)
  • operator ImageSourceRef () const
  • operator ImageTargetRef ()
  • const T *
    getData () const
  • T *
    getData (const ivec2 &offset)
  • const T *
    getData (const ivec2 &offset) const
  • const T *
    getDataRed (const ivec2 &offset) const
  • const T *
    getDataGreen (const ivec2 &offset) const
  • const T *
    getDataBlue (const ivec2 &offset) const
  • const T *
    getDataAlpha (const ivec2 &offset) const

Static Public Member Functions