Namespace List Class Hierarchy Compound List File List Namespace Members Compound Members

# ptc::Format Class Reference

Describes a pixel format. More...

List of all members.

## Public Members

- Format ()
- Format (int bits)
- Format (int bits,int32 r,int32 g,int32 b,int32 a=0)
- Format (const Format &format)
- ~Format ()
- int32 r () const
- int32 g () const
- int32 b () const
- int32 a () const
- int bits () const
- int bytes () const
- bool direct () const
- bool indexed () const
- Format& operator= (const Format &format)
- bool operator== (const Format &format) const
- bool operator!= (const Format &format) const

## Detailed Description

Describes a pixel format.

The format class describes one of two kinds of pixel formats: indexed color and direct color.

Indexed color pixel formats describe of pixel values that index into a palette (See ptc::Palette).

Direct color pixel formats describe pixels that have red, green, blue and alpha information packed into each pixel.

Format objects are typically used when creating surface classes with Surface::Surface(), and when opening consoles with Console::open()(const char title[],const Format &format,int pages).

## Member Function Documentation

### ptc::Format::Format ()

Default constructor.

bits, r, g, b and a are all set to zero.

### ptc::Format::Format (int bits)

Creates an indexed pixel format where each pixel entry represents an index into a palette.

Currently the only indexed format supported is 8 bit indexed color, ie. 256 color.

If the bits parameter is not equal to 8 then an error exception will be thrown.

See also:
  Palette class

Parameters:
  bits - the number of bits per pixel.

Exceptions:
  Error - An Error exception is thrown on failure.

### ptc::Format::Format (int bits, int32 r, int32 g, int32 b, int32 a = 0)

Creates a direct color pixel format with the red, green, blue and alpha masks r, g, b and a.

For each of the mask values set bits (1) represent bits allocated to the color component, and clear bits (0) represent unused bits.

Here are some common direct color pixel formats:

                // 32 bit RGB888
                Format format(32,0x00FF0000,0x0000FF00,0x000000FF);

                // 24 bit RGB888
                Format format(24,0xFF0000,0x00FF00,0x0000FF);

                // 16 bit RGB565
                Format format(16,0xF800,0x07E0,0x001F);

                // 15 bit RGB555
                Format format(16,0x7C00,0x03E0,0x001F);

                // 8 bit RGB332
                Format format(8,0xE0,0x1C,0x03);

                // 32 bit ARGB8888
                Format format(32,0x00FF0000,0x0000FF00,0x000000FF,0xFF000000);

                // 16 bit ARGB1555
                Format format(16,0x7C00,0x03E0,0x001F,0x8000);

An error exception is thrown if the bits parameter is not 8, 16, 24 or 32.

Parameters:
  bits - the number of bits per pixel.
  r - the red color component.
  g - the green color component.
  b - the blue color component.
  a - the alpha color component (defaults to zero).

Exceptions:
  Error - An Error exception is thrown on failure.

### ptc::Format::Format (const Format & format)

Copy constructor.

### ptc::Format::~Format ()

Destructor.

### int32 ptc::Format::r () const

Gets the red component mask of the format object.

The red color mask is only valid if the format object is direct color.

A format object is direct color if it was created by the Format::Format()(int bits,int32 r,int32 g,int32 b,int32 a) constructor.

If the format object is not direct color then the red mask is always zero.

Returns:
  The red component mask.

### int32 ptc::Format::g () const

Gets the green component mask of the format object.

The green color mask is only valid if the format object is direct color.

A format object is direct color if it was created by the Format::Format()(int bits,int32 r,int32 g,int32 b,int32 a) constructor.

If the format object is not direct color then the green mask is always zero.

Returns:
  The green component mask.

### int32 ptc::Format::b () const

Gets the blue component mask of the format object.

The blue color mask is only valid if the format object is direct color.

A format object is direct color if it was created by the Format::Format()(int bits,int32 r,int32 g,int32 b,int32 a) constructor.

If the format object is not direct color then the blue mask is always zero.

Returns:
  The blue component mask.

### int32 ptc::Format::a () const

Gets the alpha component mask of the format object.

The alpha color mask is only valid if the format object is direct color.

A format object is direct color if it was created by the Format::Format()(int bits,int32 r,int32 g,int32 b,int32 a) constructor.

If the format object is not direct color then the alpha mask is always zero.

Returns:
  The alpha component mask.

### int ptc::Format::bits () const

Gets the bits per pixel of the format object.

Bits per pixel is either 8, 16, 24 or 32 in direct color, or 8 in indexed color.

Returns:
  The number of bits per pixel.

### int ptc::Format::bytes () const

Gets the bytes per pixel of the format object.

Bytes per pixel is either 1, 2, 3 or 4 in direct color, or 1 in indexed color.

Returns:
  The number of bytes per pixel.

### bool ptc::Format::direct () const

Checks if the format is direct color.

A format object is direct color if it was created by the Format::Format()(int bits,int32 r,int32 g,int32 b,int32 a) constructor.

Returns:
  true if the format is direct color, false otherwise.

### bool ptc::Format::indexed () const

Checks if the format is indexed color.

A format object is indexed color if it was created by the Format(int bits) constructor.

Returns:
  true if the format is indexed color, false otherwise.

### Format & ptc::Format::operator= (const Format & format)

Assignment operator.

### bool ptc::Format::operator== (const Format & format) const

Equality operator.

### bool ptc::Format::operator!= (const Format & format) const

Inequality operator.

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

- ptc.h