blip  0.1
Pixmap Class Reference

A buffer for two-dimensional pixel data, stored in inverted row order (bottom row first, top row last) as expected by OpenGL. More...

#include <Pixmap.hpp>

Public Types

enum  Format { Format_RGBA_32, Format_Alpha_8 }
 

Public Member Functions

 Pixmap (Format format, uint_t width, uint_t height, uint_t alignment=DEFAULT_ALIGNMENT)
 Construct a new pixmap with the specified pixel format, size, and alignment. More...
 
 ~Pixmap () throw ()
 Destructor. More...
 
uint_t getWidth () const throw ()
 Get the width of the Pixmap, in pixels. More...
 
uint_t getHeight () const throw ()
 Get the height of the Pixmap, in pixels. More...
 
Size getSize () const throw ()
 Get the size of the pixmap. More...
 
void setImageSize (const Size &imageSize) throw ()
 Set the size of the image that is currently being stored in the Pixmap. More...
 
const SizegetImageSize () const throw ()
 Get the size of the image that is currently being stored in the Pixmap. More...
 
int getImageWidth () const throw ()
 Get the width of the image that is currently being stored in the Pixmap, in pixels. More...
 
int getImageHeight () const throw ()
 Get the height of the image that is currently being stored in the Pixmap, in pixels. More...
 
uint_t getRowStride () const throw ()
 Get the row stride for the Pixmap, i.e., the number of bytes occupied by one row of pixel data, including any padding bytes as dictated by the alignment. More...
 
Format getFormat () const throw ()
 Get the image format. More...
 
const byte_t * getData () const throw ()
 Get a pointer to the beginning (the bottom-left corner) of the pixel data. More...
 
byte_t * getData () throw ()
 Get a pointer to the beginning (the bottom-left corner) of the pixel data. More...
 
const size_t getDataLength () const throw ()
 Get the length of the pixel data, in bytes. More...
 
uint_t getAlignment () const throw ()
 Get the storage alignment. More...
 
void clear () throw ()
 Clear the Pixmap. More...
 
bool isNull () const throw ()
 Test if the Pixmap is null, that is, a Pixmap with 0x0 size. More...
 

Static Public Attributes

static const uint_t DEFAULT_ALIGNMENT = sizeof(void*)
 The default alignment for pixel data for the host platform. More...
 

Detailed Description

A buffer for two-dimensional pixel data, stored in inverted row order (bottom row first, top row last) as expected by OpenGL.

The format of the pixel data may be either 32-bit RGBA (corresponding to GL_RGBA) or 8-bit alpha channel (corresponding to GL_ALPHA).

A Pixmap cannot be resized once it has been created; however, the Pixmap may be used to store images that are smaller than itself. The image size is the size of the image currently stored in the pixmap. Unless otherwise specified via a call to setImageSize(), this will be equal to the Pixmap's size.

When passing the Pixmap's data to an OpenGL routine such as glTexImage2D(), care must be taken to first set the pixel storage modes to match the characteristics of the pixmap, and to pass the width and height of the image within the pixmap (rather than the width and height of the pixmap itself, which may be larger than the image data it contains) to the function that receives the pixel data, e.g.:

GLint oldAlignment;
glGetIntegerv(GL_UNPACK_ALIGNMENT, &oldAlignment);
glPixelStorei(GL_UNPACK_ALIGNMENT, pixmap->getAlignment());
glPixelStorei(GL_UNPACK_ROW_LENGTH, pixmap->getWidth());
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pixmap->getImageWidth(),
             pixmap->getImageHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE,
             pixmap->getData());
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
glPixelStorei(GL_UNPACK_ALIGNMENT, oldAlignment);

OpenGL ES does not support GL_UNPACK_ROW_LENGTH. An alternative approach is:

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pixmap->getImageWidth(),
             pixmap->getImageHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE,
             NULL);
const byte_t* row = pixmap->getData();
int h = pixmap->getImageHeight();
for(int y = 0; y < h; ++y)
{
  glTexSubImage2D(GL_TEXTURE_2D, 0, 0, y, pixmap->getImageWidth(), 1,
                  GL_RGBA, GL_UNSIGNED_BYTE, row);
  row += pixmap->getRowStride();
}
Author
Mark Lindner

Member Enumeration Documentation

◆ Format

enum Format
Enumerator
Format_RGBA_32 
Format_Alpha_8 

Constructor & Destructor Documentation

◆ Pixmap()

Pixmap ( Format  format,
uint_t  width,
uint_t  height,
uint_t  alignment = DEFAULT_ALIGNMENT 
)

Construct a new pixmap with the specified pixel format, size, and alignment.

Parameters
formatThe image format.
widthThe width of the Pixmap, in pixels.
heightThe width of the Pixmap, in pixels.
alignmentThe alignment; each row of pixel data will have a length that is an even multiple of the alignment. Allowed values are 1, 2, 4, and 8. If an invalid value is specified, DEFAULT_ALIGNMENT is used instead.

◆ ~Pixmap()

~Pixmap ( )
throw (
)

Destructor.

Member Function Documentation

◆ clear()

void clear ( )
throw (
)

Clear the Pixmap.

Zeroes the pixmap data.

◆ getAlignment()

uint_t getAlignment ( ) const
throw (
)
inline

Get the storage alignment.

◆ getData() [1/2]

const byte_t* getData ( ) const
throw (
)
inline

Get a pointer to the beginning (the bottom-left corner) of the pixel data.

◆ getData() [2/2]

byte_t* getData ( )
throw (
)
inline

Get a pointer to the beginning (the bottom-left corner) of the pixel data.

◆ getDataLength()

const size_t getDataLength ( ) const
throw (
)
inline

Get the length of the pixel data, in bytes.

◆ getFormat()

Format getFormat ( ) const
throw (
)
inline

Get the image format.

◆ getHeight()

uint_t getHeight ( ) const
throw (
)
inline

Get the height of the Pixmap, in pixels.

◆ getImageHeight()

int getImageHeight ( ) const
throw (
)
inline

Get the height of the image that is currently being stored in the Pixmap, in pixels.

◆ getImageSize()

const Size& getImageSize ( ) const
throw (
)
inline

Get the size of the image that is currently being stored in the Pixmap.

If an image size has not been explicitly set with setImageSize(), this will be equal to the Pixmap's size.

◆ getImageWidth()

int getImageWidth ( ) const
throw (
)
inline

Get the width of the image that is currently being stored in the Pixmap, in pixels.

◆ getRowStride()

uint_t getRowStride ( ) const
throw (
)
inline

Get the row stride for the Pixmap, i.e., the number of bytes occupied by one row of pixel data, including any padding bytes as dictated by the alignment.

◆ getSize()

Size getSize ( ) const
throw (
)
inline

Get the size of the pixmap.

◆ getWidth()

uint_t getWidth ( ) const
throw (
)
inline

Get the width of the Pixmap, in pixels.

◆ isNull()

bool isNull ( ) const
throw (
)

Test if the Pixmap is null, that is, a Pixmap with 0x0 size.

◆ setImageSize()

void setImageSize ( const Size imageSize)
throw (
)

Set the size of the image that is currently being stored in the Pixmap.

Parameters
imageSizeThe image size. If either dimension of this size is greater than the corresponding dimension of the Pixmap, the value is ignored, and the image size will remain unchanged.

Member Data Documentation

◆ DEFAULT_ALIGNMENT

const uint_t DEFAULT_ALIGNMENT = sizeof(void*)
static

The default alignment for pixel data for the host platform.


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