clan::PixelBuffer Class Reference - ClanLib SDK
Description: clan::PixelBuffer Class Reference

Public Member Functions | Static Public Member Functions | Friends | List of all members
clan::PixelBuffer Class Reference
clanDisplay Display

Pixel data container. More...

`#include <pixel_buffer.h>`

Inheritance diagram for clan::PixelBuffer:

## Public Member Functions
| PixelBuffer ()
| Constructs a null instance.
| PixelBuffer (const std::string &filename, const FileSystem &file_system, bool srgb=false)
| Constructs a PixelBuffer.
| PixelBuffer (const std::string &fullname, bool srgb=false)
| Constructs a PixelBuffer.
| PixelBuffer (int width, int height, TextureFormat texture_format, const void *data=nullptr, bool only_reference_data=false)
| Constructs a PixelBuffer.
| PixelBuffer (IODevice &file, const std::string &image_type, bool srgb=false)
| Constructs a PixelBuffer.
| PixelBuffer (PixelBufferProvider *provider)
| Constructs a PixelBuffer.
virtual | ~PixelBuffer ()
PixelBuffer | copy () const
| Create a copy of the pixelbuffer that doesn't share data with the original pixel buffer.
PixelBuffer | copy (const Rect &rect) const
| Create a copy of the pixelbuffer that doesn't share data with the original pixel buffer.
void | flip_vertical ()
| Flip the entire image vertically (turn it upside down)
unsigned int | get_bytes_per_block () const
| Returns the number of bytes per compression block.
unsigned int | get_bytes_per_pixel () const
| Returns the number of bytes per pixel.
void * | get_data ()
| Returns a pointer to the beginning of the pixel buffer.
template<typename Type >
Type * | get_data ()
const void * | get_data () const
template<typename Type >
const Type * | get_data () const
unsigned int | get_data_size () const
| Returns the size in bytes of the image data.
unsigned short * | get_data_uint16 ()
| Returns a pointer to the beginning of the pixel buffer as 16 bit data.
const unsigned short * | get_data_uint16 () const
unsigned int * | get_data_uint32 ()
| Returns a pointer to the beginning of the pixel buffer as 32 bit data.
const unsigned int * | get_data_uint32 () const
unsigned char * | get_data_uint8 ()
| Returns a pointer to the beginning of the pixel buffer as 8 bit data.
const unsigned char * | get_data_uint8 () const
float | get_dip_height () const
| Returns the device independent height of this texture.
Sizef | get_dip_size () const
| Returns the device independent size of this texture.
float | get_dip_width () const
| Returns the device independent width of this texture.
TextureFormat | get_format () const
| Returns the pixel format.
int | get_height () const
| Retrieves the actual height of the buffer.
void * | get_line (int line)
| Returns a pointer to the beginning of a specific line.
const void * | get_line (int line) const
unsigned short * | get_line_uint16 (int line)
| Returns a pointer to the beginning of a specific line as 16 bit data.
const unsigned short * | get_line_uint16 (int line) const
unsigned int * | get_line_uint32 (int line)
| Returns a pointer to the beginning of a specific line as 32 bit data.
const unsigned int * | get_line_uint32 (int line) const
unsigned char * | get_line_uint8 (int line)
| Returns a pointer to the beginning of a specific line as 8 bit data.
const unsigned char * | get_line_uint8 (int line) const
int | get_pitch () const
| Returns the pitch (in bytes per scanline).
Colorf | get_pixel (int x, int y)
| Return color of pixel at the specified coordinates.
float | get_pixel_ratio () const
PixelBufferProvider * | get_provider () const
| Get Provider.
Size | get_size () const
| Retrieves the actual size of the buffer.
int | get_width () const
| Retrieves the actual width of the buffer.
bool | has_transparency () const
| Returns true if format has an alpha channel.
bool | is_compressed () const
| Returns true if compressed.
bool | is_gpu () const
| Returns true if this pixel buffer is a GPU based one.
bool | is_null () const
| Returns true if this object is invalid.
void | lock (GraphicContext &gc, BufferAccess access)
| Maps buffer into system memory.
| operator bool () const
void | premultiply_alpha ()
| Multiply the RGB components by the Alpha component.
void | premultiply_gamma (float gamma)
| Multiply the RGB components by gamma value.
void | set_image (const PixelBuffer &source)
| Copy source pixel buffer into this buffer, doing a format conversion if needed.
void | set_image (const PixelBuffer &source, PixelConverter &converter)
| Copy source pixel buffer into this buffer, doing a format conversion if needed.
void | set_pixel_ratio (float ratio)
| Sets the display pixel ratio for this texture.
void | set_subimage (const PixelBuffer &source, const Point &dest_pos, const Rect &src_rect)
| Copy source pixel buffer into this buffer, doing a format conversion if needed.
void | set_subimage (const PixelBuffer &source, const Point &dest_pos, const Rect &src_rect, PixelConverter &converter)
| Copy source pixel buffer into this buffer, doing a format conversion if needed.
void | throw_if_null () const
| Throw an exception if this object is invalid.
PixelBuffer | to_cpu (GraphicContext &gc)
| Downloads the pixel buffer to CPU memory.
PixelBuffer | to_format (TextureFormat texture_format) const
| Converts current buffer to a new pixel format and returns the result.
PixelBuffer | to_format (TextureFormat texture_format, PixelConverter &converter) const
| Converts current buffer to a new pixel format and returns the result.
PixelBuffer | to_gpu (GraphicContext &gc)
| Uploads the pixel buffer to GPU memory.
void | unlock ()
| Unmaps element buffer.
void | upload_data (GraphicContext &gc, const Rect &dest_rect, const void *data)
| Uploads data to buffer.

## Static Public Member Functions
static unsigned int | get_bytes_per_block (TextureFormat texture_format)
| Returns the number of bytes per compression block.
static unsigned int | get_bytes_per_pixel (TextureFormat texture_format)
| Returns the number of bytes per pixel.
static unsigned int | get_data_size (const Size &size, TextureFormat texture_format)
| Returns the size in bytes of the image data.
static bool | is_compressed (TextureFormat texture_format)
| Returns true if compressed.

## Friends
class | PixelBuffer_Impl

## Detailed Description

Pixel data container.

## Constructor & Destructor Documentation

## ◆ PixelBuffer() [1/6]

clan::PixelBuffer::PixelBuffer | ( |  | ) |

Constructs a null instance.

## ◆ PixelBuffer() [2/6]

clan::PixelBuffer::PixelBuffer | ( | int | width,
|  | int | height,
|  | TextureFormat | texture_format,
|  | const void * | data = nullptr,
|  | bool | only_reference_data = false )

Constructs a PixelBuffer.

Parameters

  width | = value
  height | = value
  sized_format | = Pixel Format
  data | = The data (0 = Allocate automatically to a boundary of 16 bytes)
  only_reference_data | : true = Reference the data. false = Copy the data

## ◆ PixelBuffer() [3/6]

clan::PixelBuffer::PixelBuffer | ( | const std::string & | fullname,
|  | bool | srgb = false )

Constructs a PixelBuffer.

Parameters

  fullname | = String Ref

## ◆ PixelBuffer() [4/6]

clan::PixelBuffer::PixelBuffer | ( | const std::string & | filename,
|  | const FileSystem & | file_system,
|  | bool | srgb = false )

Constructs a PixelBuffer.

Parameters

  filename | = String Ref
  dir | = Virtual Directory

## ◆ PixelBuffer() [5/6]

clan::PixelBuffer::PixelBuffer | ( | IODevice & | file,
|  | const std::string & | image_type,
|  | bool | srgb = false )

Constructs a PixelBuffer.

Parameters

  file | = IODevice
  image_type | = String

## ◆ PixelBuffer() [6/6]

clan::PixelBuffer::PixelBuffer | ( | PixelBufferProvider * | provider | ) |

Constructs a PixelBuffer.

Parameters

  provider | = Font Provider

## ◆ ~PixelBuffer()

virtual clan::PixelBuffer::~PixelBuffer | ( |  | ) |
| virtual

## Member Function Documentation

## ◆ copy() [1/2]

PixelBuffer clan::PixelBuffer::copy | ( |  | ) | const

Create a copy of the pixelbuffer that doesn't share data with the original pixel buffer.

## ◆ copy() [2/2]

PixelBuffer clan::PixelBuffer::copy | ( | const Rect & | rect | ) | const

Create a copy of the pixelbuffer that doesn't share data with the original pixel buffer.

## ◆ flip_vertical()

void clan::PixelBuffer::flip_vertical | ( |  | ) |

Flip the entire image vertically (turn it upside down)

## ◆ get_bytes_per_block() [1/2]

unsigned int clan::PixelBuffer::get_bytes_per_block | ( |  | ) | const

Returns the number of bytes per compression block.

Returns
  Bytes per block. Exception thrown if not available (hint, use is_compressed() )

## ◆ get_bytes_per_block() [2/2]

static unsigned int clan::PixelBuffer::get_bytes_per_block | ( | TextureFormat | texture_format | ) |
| static

Returns the number of bytes per compression block.

Returns
  Bytes per block. Exception thrown if not available (hint, use is_compressed() )

## ◆ get_bytes_per_pixel() [1/2]

unsigned int clan::PixelBuffer::get_bytes_per_pixel | ( |  | ) | const

Returns the number of bytes per pixel.

Returns
  Bytes per pixel. Exception thrown if not available (hint, use is_compressed() )

## ◆ get_bytes_per_pixel() [2/2]

static unsigned int clan::PixelBuffer::get_bytes_per_pixel | ( | TextureFormat | texture_format | ) |
| static

Returns the number of bytes per pixel.

Returns
  Bytes per pixel. Exception thrown if not available (hint, use is_compressed() )

## ◆ get_data() [1/4]

void * clan::PixelBuffer::get_data | ( |  | ) |

Returns a pointer to the beginning of the pixel buffer.

Referenced by get_data_uint16(), get_data_uint16(), get_data_uint32(), get_data_uint32(), get_data_uint8(), get_data_uint8(), clan::PixelBufferLock< Type >::lock(), and clan::PixelBufferLock< Type >::lock().

## ◆ get_data() [2/4]

template<typename Type >

Type * clan::PixelBuffer::get_data | ( |  | ) |
| inline

References get_data().

Referenced by get_data().

## ◆ get_data() [3/4]

const void * clan::PixelBuffer::get_data | ( |  | ) | const

## ◆ get_data() [4/4]

template<typename Type >

const Type * clan::PixelBuffer::get_data | ( |  | ) | const
| inline

References get_data().

Referenced by get_data().

## ◆ get_data_size() [1/2]

unsigned int clan::PixelBuffer::get_data_size | ( |  | ) | const

Returns the size in bytes of the image data.

Returns
  The data size

## ◆ get_data_size() [2/2]

static unsigned int clan::PixelBuffer::get_data_size | ( | const Size & | size,
|  | TextureFormat | texture_format )
| static

Returns the size in bytes of the image data.

Returns
  The data size

## ◆ get_data_uint16() [1/2]

unsigned short * clan::PixelBuffer::get_data_uint16 | ( |  | ) |
| inline

Returns a pointer to the beginning of the pixel buffer as 16 bit data.

References get_data().

## ◆ get_data_uint16() [2/2]

const unsigned short * clan::PixelBuffer::get_data_uint16 | ( |  | ) | const
| inline

References get_data().

## ◆ get_data_uint32() [1/2]

unsigned int * clan::PixelBuffer::get_data_uint32 | ( |  | ) |
| inline

Returns a pointer to the beginning of the pixel buffer as 32 bit data.

References get_data().

## ◆ get_data_uint32() [2/2]

const unsigned int * clan::PixelBuffer::get_data_uint32 | ( |  | ) | const
| inline

References get_data().

## ◆ get_data_uint8() [1/2]

unsigned char * clan::PixelBuffer::get_data_uint8 | ( |  | ) |
| inline

Returns a pointer to the beginning of the pixel buffer as 8 bit data.

References get_data().

Referenced by get_line(), and get_line().

## ◆ get_data_uint8() [2/2]

const unsigned char * clan::PixelBuffer::get_data_uint8 | ( |  | ) | const
| inline

References get_data().

## ◆ get_dip_height()

float clan::PixelBuffer::get_dip_height | ( |  | ) | const
| inline

Returns the device independent height of this texture.

References get_height(), and get_pixel_ratio().

Referenced by get_dip_size().

## ◆ get_dip_size()

Sizef clan::PixelBuffer::get_dip_size | ( |  | ) | const
| inline

Returns the device independent size of this texture.

References get_dip_height(), and get_dip_width().

## ◆ get_dip_width()

float clan::PixelBuffer::get_dip_width | ( |  | ) | const
| inline

Returns the device independent width of this texture.

References get_pixel_ratio(), and get_width().

Referenced by get_dip_size().

## ◆ get_format()

TextureFormat clan::PixelBuffer::get_format | ( |  | ) | const

Returns the pixel format.

## ◆ get_height()

int clan::PixelBuffer::get_height | ( |  | ) | const

Retrieves the actual height of the buffer.

Referenced by clan::PixelBufferLock< Type >::PixelBufferLock(), clan::PixelBufferLock< Type >::PixelBufferLock(), get_dip_height(), and get_size().

## ◆ get_line() [1/2]

void * clan::PixelBuffer::get_line | ( | int | line | ) |
| inline

Returns a pointer to the beginning of a specific line.

References clan::d, get_data_uint8(), get_pitch(), and clan::line.

Referenced by get_line_uint16(), get_line_uint16(), get_line_uint32(), get_line_uint32(), get_line_uint8(), and get_line_uint8().

## ◆ get_line() [2/2]

const void * clan::PixelBuffer::get_line | ( | int | line | ) | const
| inline

References clan::d, get_data_uint8(), get_pitch(), and clan::line.

## ◆ get_line_uint16() [1/2]

unsigned short * clan::PixelBuffer::get_line_uint16 | ( | int | line | ) |
| inline

Returns a pointer to the beginning of a specific line as 16 bit data.

References get_line(), and clan::line.

## ◆ get_line_uint16() [2/2]

const unsigned short * clan::PixelBuffer::get_line_uint16 | ( | int | line | ) | const
| inline

References get_line(), and clan::line.

## ◆ get_line_uint32() [1/2]

unsigned int * clan::PixelBuffer::get_line_uint32 | ( | int | line | ) |
| inline

Returns a pointer to the beginning of a specific line as 32 bit data.

References get_line(), and clan::line.

## ◆ get_line_uint32() [2/2]

const unsigned int * clan::PixelBuffer::get_line_uint32 | ( | int | line | ) | const
| inline

References get_line(), and clan::line.

## ◆ get_line_uint8() [1/2]

unsigned char * clan::PixelBuffer::get_line_uint8 | ( | int | line | ) |
| inline

Returns a pointer to the beginning of a specific line as 8 bit data.

References get_line(), and clan::line.

## ◆ get_line_uint8() [2/2]

const unsigned char * clan::PixelBuffer::get_line_uint8 | ( | int | line | ) | const
| inline

References get_line(), and clan::line.

## ◆ get_pitch()

int clan::PixelBuffer::get_pitch | ( |  | ) | const

Returns the pitch (in bytes per scanline).

Referenced by get_line(), get_line(), clan::PixelBufferLock< Type >::lock(), and clan::PixelBufferLock< Type >::lock().

## ◆ get_pixel()

Colorf clan::PixelBuffer::get_pixel | ( | int | x,
|  | int | y )

Return color of pixel at the specified coordinates.

## ◆ get_pixel_ratio()

float clan::PixelBuffer::get_pixel_ratio | ( |  | ) | const

Retrieves the pixel ratio of this texture.

Returns
  The display pixel ratio set for this texture. A zero value implies that no pixel ratio has been set

Referenced by get_dip_height(), and get_dip_width().

## ◆ get_provider()

PixelBufferProvider * clan::PixelBuffer::get_provider | ( |  | ) | const

Get Provider.

Returns
  provider

## ◆ get_size()

Size clan::PixelBuffer::get_size | ( |  | ) | const
| inline

Retrieves the actual size of the buffer.

References get_height(), and get_width().

## ◆ get_width()

int clan::PixelBuffer::get_width | ( |  | ) | const

Retrieves the actual width of the buffer.

Referenced by clan::PixelBufferLock< Type >::PixelBufferLock(), clan::PixelBufferLock< Type >::PixelBufferLock(), get_dip_width(), and get_size().

## ◆ has_transparency()

bool clan::PixelBuffer::has_transparency | ( |  | ) | const

Returns true if format has an alpha channel.

## ◆ is_compressed() [1/2]

bool clan::PixelBuffer::is_compressed | ( |  | ) | const

Returns true if compressed.

## ◆ is_compressed() [2/2]

static bool clan::PixelBuffer::is_compressed | ( | TextureFormat | texture_format | ) |
| static

Returns true if compressed.

## ◆ is_gpu()

bool clan::PixelBuffer::is_gpu | ( |  | ) | const

Returns true if this pixel buffer is a GPU based one.

Referenced by clan::PixelBufferLock< Type >::lock().

## ◆ is_null()

bool clan::PixelBuffer::is_null | ( |  | ) | const
| inline

Returns true if this object is invalid.

Referenced by clan::PixelBufferLock< Type >::~PixelBufferLock(), clan::PixelBufferLock< Type >::lock(), clan::PixelBufferLock< Type >::lock(), and clan::PixelBufferLock< Type >::unlock().

## ◆ lock()

void clan::PixelBuffer::lock | ( | GraphicContext & | gc,
|  | BufferAccess | access )

Maps buffer into system memory.

Referenced by clan::PixelBufferLock< Type >::lock().

## ◆ operator bool()

clan::PixelBuffer::operator bool | ( |  | ) | const
| inlineexplicit

## ◆ premultiply_alpha()

void clan::PixelBuffer::premultiply_alpha | ( |  | ) |

Multiply the RGB components by the Alpha component.

This is useful with certain blending functions

## ◆ premultiply_gamma()

void clan::PixelBuffer::premultiply_gamma | ( | float | gamma | ) |

Multiply the RGB components by gamma value.

Calling this function with 2.2 gamma converts a sRGB image into linear space. To convert from linear to sRGB use 1.0/2.2

## ◆ set_image() [1/2]

void clan::PixelBuffer::set_image | ( | const PixelBuffer & | source | ) |

Copy source pixel buffer into this buffer, doing a format conversion if needed.

Parameters

  source | Source pixel buffer.

## ◆ set_image() [2/2]

void clan::PixelBuffer::set_image | ( | const PixelBuffer & | source,
|  | PixelConverter & | converter )

Copy source pixel buffer into this buffer, doing a format conversion if needed.

Parameters

  source | Source pixel buffer.

## ◆ set_pixel_ratio()

void clan::PixelBuffer::set_pixel_ratio | ( | float | ratio | ) |

Sets the display pixel ratio for this texture.

## ◆ set_subimage() [1/2]

void clan::PixelBuffer::set_subimage | ( | const PixelBuffer & | source,
|  | const Point & | dest_pos,
|  | const Rect & | src_rect )

Copy source pixel buffer into this buffer, doing a format conversion if needed.

Parameters

  source | Source pixel buffer.
  dest_rect | Destination position for copy.
  src_rect | Source rectangle for copy.

## ◆ set_subimage() [2/2]

void clan::PixelBuffer::set_subimage | ( | const PixelBuffer & | source,
|  | const Point & | dest_pos,
|  | const Rect & | src_rect,
|  | PixelConverter & | converter )

Copy source pixel buffer into this buffer, doing a format conversion if needed.

Parameters

  source | Source pixel buffer.
  dest_rect | Destination position for copy.
  src_rect | Source rectangle for copy.

## ◆ throw_if_null()

void clan::PixelBuffer::throw_if_null | ( |  | ) | const

Throw an exception if this object is invalid.

## ◆ to_cpu()

PixelBuffer clan::PixelBuffer::to_cpu | ( | GraphicContext & | gc | ) |

Downloads the pixel buffer to CPU memory.

If the pixel buffer is already in CPU memory the function returns the current pixel buffer.

## ◆ to_format() [1/2]

PixelBuffer clan::PixelBuffer::to_format | ( | TextureFormat | texture_format | ) | const

Converts current buffer to a new pixel format and returns the result.

## ◆ to_format() [2/2]

PixelBuffer clan::PixelBuffer::to_format | ( | TextureFormat | texture_format,
|  | PixelConverter & | converter ) const

Converts current buffer to a new pixel format and returns the result.

## ◆ to_gpu()

PixelBuffer clan::PixelBuffer::to_gpu | ( | GraphicContext & | gc | ) |

Uploads the pixel buffer to GPU memory.

If the pixel buffer is already in GPU memory the function returns the current pixel buffer.

## ◆ unlock()

void clan::PixelBuffer::unlock | ( |  | ) |

Unmaps element buffer.

Referenced by clan::PixelBufferLock< Type >::~PixelBufferLock(), and clan::PixelBufferLock< Type >::unlock().

## ◆ upload_data()

void clan::PixelBuffer::upload_data | ( | GraphicContext & | gc,
|  | const Rect & | dest_rect,
|  | const void * | data )

Uploads data to buffer.

## Friends And Related Symbol Documentation

## ◆ PixelBuffer_Impl

friend class PixelBuffer_Impl
| friend

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

- pixel_buffer.h