Pebble Foundation Classes  0.2.0
C++ for Pebble
Pebble::GOwnedBitmap Class Reference

A bitmap that destroys the underlying reference when destructed. More...

#include <pebble_graphics_types.hpp>

Inheritance diagram for Pebble::GOwnedBitmap:
Collaboration diagram for Pebble::GOwnedBitmap:

Public Member Functions

 GOwnedBitmap (const GBitmap &)=delete
 No copy constructor.
 
 GOwnedBitmap (GOwnedBitmap &&that)
 Move constructor.
 
GOwnedBitmapoperator= (GOwnedBitmap that)
 Swap assignment operator.
 
GOwnedBitmapoperator= (GOwnedBitmap &that)
 Swap assignment operator.
 
virtual ~GOwnedBitmap ()
 Destroy the bitmap if pointer provided.
 
void SetData (uint8_t *data, GBitmapFormat format, uint16_t row_size_bytes, bool free_on_destroy)
 
void SetBounds (const GRect &bounds)
 
void SetPalette (GColor *palette, bool free_on_destroy)
 
- Public Member Functions inherited from Pebble::GBitmapBase
 operator::GBitmap * () const
 Instances of this class can be automatically converted to Pebble gbitmap pointer.
 
virtual ~GBitmapBase ()
 Destructor.
 
uint16_t GetBytesPerRow () const
 
GBitmapFormat GetFormat () const
 
uint8_t * GetData () const
 
GRect GetBounds () const
 
GColorGetPalette () const
 

Static Public Member Functions

static GOwnedBitmap CreateFromPngData (const uint8_t *png_data, size_t png_data_size)
 
static GOwnedBitmap CreateSubBitmap (const ::GBitmap *base_bitmap, ::GRect sub_rect)
 
static GOwnedBitmap CreateWithData (const uint8_t *data)
 
static GOwnedBitmap CreateWithResource (uint32_t resource_id)
 
static GOwnedBitmap CreateBlank (GSize size, GBitmapFormat format)
 
static GOwnedBitmap CreateBlank (GSize size, GBitmapFormat format, GColor *palette, bool free_on_destroy)
 
static GOwnedBitmap CreatePalettizedFrom1bit (const ::GBitmap *src_bitmap)
 

Protected Member Functions

 GOwnedBitmap (::GBitmap *bitmap)
 Create bitmap as sub bitmap.
 
- Protected Member Functions inherited from Pebble::GBitmapBase
 GBitmapBase ()
 Cannot construct.
 
 GBitmapBase (::GBitmap *gbitmap)
 Wrap a Pebble bitmap.
 

Additional Inherited Members

- Protected Attributes inherited from Pebble::GBitmapBase
::GBitmapgbitmap_
 

Detailed Description

A bitmap that destroys the underlying reference when destructed.

Member Function Documentation

◆ CreateBlank() [1/2]

static GOwnedBitmap Pebble::GOwnedBitmap::CreateBlank ( GSize  size,
GBitmapFormat  format 
)
inlinestatic

Creates a new blank GBitmap on the heap initialized to zeroes. In the case that the format indicates a palettized bitmap, a palette of appropriate size will also be allocated on the heap.

Parameters
sizeThe Pebble image dimensions as a GSize.
formatThe GBitmapFormat the created image should be in.
Returns
The GBitmap.

◆ CreateBlank() [2/2]

static GOwnedBitmap Pebble::GOwnedBitmap::CreateBlank ( GSize  size,
GBitmapFormat  format,
GColor palette,
bool  free_on_destroy 
)
inlinestatic

Creates a new blank GBitmap on the heap, initialized to zeroes, and assigns it the given palette. No deep-copying of the palette occurs, so the caller is responsible for making sure the palette remains available when using the resulting bitmap. Management of that memory can be handed off to the system with the free_on_destroy argument.

Parameters
sizeThe Pebble image dimensions as a GSize.
formatthe GBitmapFormat the created image and palette should be in.
palettea pointer to a palette that is to be used for this GBitmap. The palette should be large enough to hold enough colors for the specified format. For example, GBitmapFormat2BitPalette should have 4 colors, since 2^2 = 4.
free_on_destroySet whether the palette data should be freed along with the bitmap data when the GBitmap is destroyed.
Returns
The GBitmap.

◆ CreateFromPngData()

static GOwnedBitmap Pebble::GOwnedBitmap::CreateFromPngData ( const uint8_t *  png_data,
size_t  png_data_size 
)
inlinestatic

Create a GBitmap based on raw PNG data. The resulting GBitmap must be destroyed using gbitmap_destroy(). The developer is responsible for freeing png_data following this call.

Note
PNG decoding currently supports 1,2,4 and 8 bit palettized and grayscale images.
Parameters
png_dataPNG image data.
png_data_sizePNG image size in bytes.
Returns
Bitmap

◆ CreatePalettizedFrom1bit()

static GOwnedBitmap Pebble::GOwnedBitmap::CreatePalettizedFrom1bit ( const ::GBitmap src_bitmap)
inlinestatic

Given a 1-bit GBitmap, create a new bitmap of format GBitmapFormat1BitPalette. The new data buffer is allocated on the heap, and a 2-color palette is allocated as well.

Parameters
src_bitmapA GBitmap of format GBitmapFormat1Bit which is to be copied into a newly created GBitmap of format GBitmapFormat1BitPalettized.
Returns
The newly created 1-bit palettized GBitmap.
Note
The new bitmap does not depend on any data from src_bitmap, so src_bitmap can be freed without worry.

◆ CreateSubBitmap()

static GOwnedBitmap Pebble::GOwnedBitmap::CreateSubBitmap ( const ::GBitmap base_bitmap,
::GRect  sub_rect 
)
inlinestatic

Create a new GBitmap on the heap as a sub-bitmap of a 'base' GBitmap, using a GRect to indicate what portion of the base to use. The sub-bitmap will just reference the image data and palette of the base bitmap. No deep-copying occurs as a result of calling this function, thus the caller is responsible for making sure the base bitmap and palette will remain available when using the sub-bitmap. Note that you should not destroy the parent bitmap until the sub_bitmap has been destroyed.

Parameters
[in]base_bitmapThe bitmap that the sub-bitmap of which the image data will be used by the sub-bitmap
sub_rectThe rectangle within the image data of the base bitmap. The bounds of the base bitmap will be used to clip sub_rect.
Returns
A GBitmap.

◆ CreateWithData()

static GOwnedBitmap Pebble::GOwnedBitmap::CreateWithData ( const uint8_t *  data)
inlinestatic

Creates a new GBitmap on the heap initialized with the provided Pebble image data.

When the GBitmap is destroyed but the image data will not be freed automatically. The developer is responsible for keeping the image data in memory as long as the bitmap is used and releasing it after the bitmap is destroyed.

Note
One way to generate Pebble image data is to use bitmapgen.py in the Pebble SDK to generate a .pbi file.
Parameters
dataThe Pebble image data. Must not be NULL. The function assumes the data to be correct; there are no sanity checks performed on the data. The data will not be copied and the pointer must remain valid for the lifetime of this GBitmap.
Returns
The GBitmap.

◆ CreateWithResource()

static GOwnedBitmap Pebble::GOwnedBitmap::CreateWithResource ( uint32_t  resource_id)
inlinestatic

Creates a new GBitmap on the heap using a Pebble image file stored as a resource.

Parameters
resource_idThe ID of the bitmap resource to load
Returns
The GBitmap.

◆ SetBounds()

void Pebble::GOwnedBitmap::SetBounds ( const GRect bounds)
inline

Set the bounds of the given GBitmap.

Parameters
boundsThe bounding box to set.
See also
GetBounds

◆ SetData()

void Pebble::GOwnedBitmap::SetData ( uint8_t *  data,
GBitmapFormat  format,
uint16_t  row_size_bytes,
bool  free_on_destroy 
)
inline

Set the bitmap data for the given GBitmap.

Parameters
dataA pointer to the bitmap data
formatthe format of the bitmap data. If this is a palettized format, make sure that there is an accompanying call to gbitmap_set_palette.
row_size_bytesHow many bytes a single row takes. For example, bitmap data of format GBitmapFormat1Bit must have a row size as a multiple of 4 bytes.
free_on_destroySet whether the data should be freed when the GBitmap is destroyed.

◆ SetPalette()

void Pebble::GOwnedBitmap::SetPalette ( GColor palette,
bool  free_on_destroy 
)
inline

Set the palette for the given GBitmap.

Parameters
paletteThe palette to be used. Make sure that the palette is large enough for the bitmap's format.
free_on_destroySet whether the palette data should be freed when the GBitmap is destroyed or when another palette is set.
See also
GetFormat

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