class::sgfx::Bitmap

class sgfx::Bitmap
  : public var::Data
  : public api::SgfxObject

This class implements a bitmap and is powered by the sgfx library.

Summary

Bitmap()

Bitmap(

const sg_bmap_header_t * hdr,
const arg::IsReadOnly is_read_only
)

Bitmap(

sg_bmap_data_t * mem,
const Area & area,
const arg::IsReadOnly is_read_only
)

Bitmap(

const Area & area,
u8 bits_per_pixel
)

Bitmap(

sg_area_t d
)

[Bitmap](#classsgfx_1_1_bitmap_1a4e424aa32b627cf41d85e1d6dbeb2d12)(  

const Bitmap & bitmap
)

[Bitmap](#classsgfx_1_1_bitmap_1aeadd208afd87e12a230f23265f42d81f)(  

Bitmap && bitmap
)

virtual ~Bitmap()

int allocate(

const Area & d
)

Area area() const

u8 bits_per_pixel() const

sg_bmap_t * bmap()

const sg_bmap_t * bmap() const

const sg_bmap_data_t * bmap_data(

const Point & p
) const

sg_bmap_data_t * bmap_data(

const Point & p
)

Region calculate_active_region() const

u32 calculate_size(

const Area & area
) const

u32 calculate_size() const

Point center() const

void clear_rectangle(

const Point & p,
const Area & d
)

sg_size_t columns() const

void downsample_bitmap(

const Bitmap & source,
const Area & factor
)

void draw_arc(

const Region & region,
s16 start,
s16 end,
s16 rotation,
sg_point_t * corners
) const

void draw_arc(

const Point & p,
const Area & d,
s16 start,
s16 end,
s16 rotation
) const

void draw_bitmap(

const Point & p_dest,
const Bitmap & src
) const

void draw_cubic_bezier(

const Point & p1,
const Point & p2,
const Point & p3,
const Point & p4,
sg_point_t * corners
) const

void draw_line(

const Point & p1,
const Point & p2
) const

void draw_pattern(

const Region & region,
sg_bmap_data_t odd_pattern,
sg_bmap_data_t even_pattern,
sg_size_t pattern_height
) const

void draw_pattern(

const Point & p,
const Area & d,
sg_bmap_data_t odd_pattern,
sg_bmap_data_t even_pattern,
sg_size_t pattern_height
) const

void draw_pixel(

const Point & p
) const

void draw_pour(

const Point & point,
const Region & bounds
) const

void draw_quadratic_bezier(

const Point & p1,
const Point & p2,
const Point & p3,
sg_point_t * corners
) const

void draw_rectangle(

const Region & region
) const

void draw_rectangle(

const Point & p,
const Area & d
) const

void draw_sub_bitmap(

const Point & p_dest,
const Bitmap & src,
const Region & region_src
) const

void draw_sub_bitmap(

const Point & p_dest,
const Bitmap & src,
const Point & p_src,
const Area & d_src
) const

int free()

sg_color_t get_pixel(

const Point & p
) const

Region get_viewable_region() const

sg_size_t height() const

void invert()

void invert_rectangle(

const Point & p,
const Area & d
)

virtual bool is_busy() const

bool is_empty(

const Region & region
) const

int load(

const arg::SourceFilePath & path
)

sg_size_t margin_bottom() const

sg_size_t margin_left() const

sg_size_t margin_right() const

sg_size_t margin_top() const

[operator const sg_bmap_t *](#classsgfx_1_1_bitmap_1a34ec11e09dffb7809768a9987b8bdcc3)() *const*

Bitmap & operator<<(

const Palette & palette
)

Bitmap & operator<<(

const Pen & pen
)

Bitmap & operator=(

const Bitmap & bitmap
)

Pen pen() const

void refer_to(

const sg_bmap_header_t * hdr,
const arg::IsReadOnly is_read_only
)

void refer_to(

sg_bmap_data_t * mem,
const Area & area,
const arg::IsReadOnly is_read_only
)

virtual void refresh() const

bool resize(

const Area & area
)

int save(

const arg::DestinationFilePath & path
) const

int set_bits_per_pixel(

u8 bits_per_pixel
)

void set_margin(

sg_size_t v
)

void set_margin_bottom(

sg_size_t v
)

void set_margin_left(

sg_size_t v
)

void set_margin_right(

sg_size_t v
)

void set_margin_top(

sg_size_t v
)

void set_pen(

const Pen & pen
)

void transform_flip_x() const

void transform_flip_xy() const

void transform_flip_y() const

void transform_shift(

sg_point_t shift,
const sg_region_t & region
) const

void transform_shift(

sg_point_t shift,
sg_point_t p,
sg_area_t d
) const

virtual void wait(

const chrono::MicroTime & resolution
) const

sg_size_t width() const

sg_int_t x_max() const

sg_int_t y_max() const

static Area load_area(

const arg::SourceFilePath & path
)

Members

Bitmap()

Constructs an empty bitmap.


Bitmap(

const sg_bmap_header_t * hdr,
const arg::IsReadOnly is_read_only
)

Constructs a bitmap using an existing sg_bmap_header_t.

Parameters

  • hdr A pointer to the existing bitmap structure

  • readonly True if the data is stored in read-only memory


Bitmap(

sg_bmap_data_t * mem,
const Area & area,
const arg::IsReadOnly is_read_only
)

Constructs a bitmap using an existing memory buffer.

Parameters

  • mem A pointer to the memory buffer

  • w The width of the bitmap that fits in the buffer

  • h The height of the bitmap buffer

  • readonly True if mem is in read-only memory


Bitmap(

const Area & area,
u8 bits_per_pixel
)

Constructs a new bitmap (dynamic memory allocation).

Parameters

  • area Dimensions of the bitmap

  • bits_per_pixel Number of bits per pixel (if not fixed by the library)


Bitmap(

sg_area_t d
)

Constructs a new bitmap (dynamic memory allocation).

Parameters

  • d Area of the bitmap

Bitmap(

const Bitmap & bitmap
)


Bitmap(

Bitmap && bitmap
)


virtual ~Bitmap()

int allocate(

const Area & d
)

Allocates memory for the bitmap data using the specified width and height. If the bitmap already has a memory associated with it, it will be freed before the new memory is assigned.


Area area() const

u8 bits_per_pixel() const

sg_bmap_t * bmap()

const sg_bmap_t * bmap() const

const sg_bmap_data_t * bmap_data(

const Point & p
) const


sg_bmap_data_t * bmap_data(

const Point & p
)


Region calculate_active_region() const

u32 calculate_size(

const Area & area
) const

Returns the number of bytes used to store a Bitmap of specified size

Parameters

  • w Width used for calculation

  • h Height used for calculation


u32 calculate_size() const

Returns the number of bytes used to store the Bitmap.


Point center() const

void clear_rectangle(

const Point & p,
const Area & d
)


sg_size_t columns() const

void downsample_bitmap(

const Bitmap & source,
const Area & factor
)

Draws the source bitmap by down sampling by factor

Parameters

  • source The bitmap to draw

  • factor number to downsample by with different values for width and height (2 means have the size of source)


void draw_arc(

const Region & region,
s16 start,
s16 end,
s16 rotation,
sg_point_t * corners
) const


void draw_arc(

const Point & p,
const Area & d,
s16 start,
s16 end,
s16 rotation
) const


void draw_bitmap(

const Point & p_dest,
const Bitmap & src
) const

This function sets the pixels in a bitmap based on the pixels of the source bitmap

Parameters

  • p_dest The point in the destination bitmap of the top left corner of bitmap

  • src The source bitmap

Returns

Zero on success


void draw_cubic_bezier(

const Point & p1,
const Point & p2,
const Point & p3,
const Point & p4,
sg_point_t * corners
) const


void draw_line(

const Point & p1,
const Point & p2
) const

Draws a line on the bitmap.

Parameters

  • p1 Starting point

  • p2 Ending point

The bitmap’s pen will determine the color, thickness, and drawing mode.


void draw_pattern(

const Region & region,
sg_bmap_data_t odd_pattern,
sg_bmap_data_t even_pattern,
sg_size_t pattern_height
) const

This function draws a pattern on the bitmap.

Parameters

  • region The region to draw the pattern in

  • odd_pattern The odd pattern as a 1bpp bitmask (e.g. 0xAA)

  • even_pattern The even pattern as a 1bpp bitmask (e.g. 0x55)

  • pattern_height The pixel height of alternating pixels


void draw_pattern(

const Point & p,
const Area & d,
sg_bmap_data_t odd_pattern,
sg_bmap_data_t even_pattern,
sg_size_t pattern_height
) const


void draw_pixel(

const Point & p
) const

Draws a pixel at the specified point.

Parameters

  • p The point where to draw the pixel

The color of the pixel is determined by the pen settings.

See also: set_pen_color()


void draw_pour(

const Point & point,
const Region & bounds
) const

Pours an area on the bitmap.

Parameters

  • point Center of the pour

  • bounds Bounds for the pour

The pour will seek boundaries going outward until it hits a non-zero color or hits the bounding box.


void draw_quadratic_bezier(

const Point & p1,
const Point & p2,
const Point & p3,
sg_point_t * corners
) const


void draw_rectangle(

const Region & region
) const

Draws a rectangle on the bitmap.

Parameters

  • region The region to draw in

The bitmap’s pen color and drawing mode will affect how the rectangle is drawn. This method affects every pixel in the rectangle not just the border.


void draw_rectangle(

const Point & p,
const Area & d
) const


void draw_sub_bitmap(

const Point & p_dest,
const Bitmap & src,
const Region & region_src
) const

This function draws a subset of the source bitmap on the destination bitmap.

Parameters

  • p_dest The point in the destination bitmap to start setting pixels

  • src The source bitmap

  • region_src The regions of the source bitmap to draw

Returns

Zero on success


void draw_sub_bitmap(

const Point & p_dest,
const Bitmap & src,
const Point & p_src,
const Area & d_src
) const


int free()

Free memory associated with bitmap (auto freed on ~Bitmap)


sg_color_t get_pixel(

const Point & p
) const

Gets the value of the pixel at the specified point.

Parameters

  • p The point to get the pixel color

Returns

The color of the pixel at p


Region get_viewable_region() const

sg_size_t height() const

void invert()

void invert_rectangle(

const Point & p,
const Area & d
)


virtual bool is_busy() const

This method is designated as an interface for classes that inherit Bitmap and use refresh() to copy the bitmap memory to a physical device. The default implementation always returns false.

The bitmap should not be modified while a refresh is in progress to prevent a frame from being partially copied.

See refresh() for an example.

Returns

True if the refresh() is still in progress, false if the bitmap can be modified again


bool is_empty(

const Region & region
) const


int load(

const arg::SourceFilePath & path
)

Loads a bitmap from a file.

Parameters

  • path The path to the bitmap file name

Returns

Zero on success


sg_size_t margin_bottom() const

sg_size_t margin_left() const

sg_size_t margin_right() const

sg_size_t margin_top() const

operator const sg_bmap_t *() const

Bitmap & operator<<(

const Palette & palette
)


Bitmap & operator<<(

const Pen & pen
)


Bitmap & operator=(

const Bitmap & bitmap
)


Pen pen() const

Returns a copy of the bitmap’s pen.


void refer_to(

const sg_bmap_header_t * hdr,
const arg::IsReadOnly is_read_only
)

Sets data pointer and size for bitmap


void refer_to(

sg_bmap_data_t * mem,
const Area & area,
const arg::IsReadOnly is_read_only
)

Sets the data pointer based on the width and height of the bitmap.

Parameters

  • mem A pointer to the memory for the bitmap

  • w The width of the bitmap in pixels

  • h The height of the bitmap in pixels

  • readonly True if mem is read-only


virtual void refresh() const

This method is designated as an interface for classes that inherit Bitmap to copy the bitmap to a physical device (such as hal::DisplayDev). The implementation in this class is simple an empty method. Here is an example:

DisplayDev display; //this class inherits bitmap and re-implments refresh()

display.clear(); //clear the bitmap in memory
display.refresh(); //copy the memory to the physical device (or notify the underlying driver that it is time to copy)

bool resize(

const Area & area
)

Changes effective size without free/allocate sequence


int save(

const arg::DestinationFilePath & path
) const

Saves a bitmap to a file.

Parameters

  • path The path for the new file

Returns

Zero on success

If the file already exists, it will be overwritten.


int set_bits_per_pixel(

u8 bits_per_pixel
)


void set_margin(

sg_size_t v
)


void set_margin_bottom(

sg_size_t v
)


void set_margin_left(

sg_size_t v
)


void set_margin_right(

sg_size_t v
)


void set_margin_top(

sg_size_t v
)


void set_pen(

const Pen & pen
)

Sets the bitmap’s pen by making a copy of the pen parameter.

The current pen can be modified using this method:

Bitmap b;
b.set_pen( b.pen().set_color(5).set_solid() );

Any methods available from sgfx::Pen can be used to update the pen.


void transform_flip_x() const

void transform_flip_xy() const

void transform_flip_y() const

void transform_shift(

sg_point_t shift,
const sg_region_t & region
) const

Performs a shift operation on an area of the bitmap.

Parameters

  • shift The amount to shift in each direction

  • region The region to shift

The shifting must respect the dimensions of the bitmap. If you want to shift the entire bitmap to the left 8 pixels, do this:

Bitmap bmap(64,64);
bmap.transform_shift(sg_point(-8,0), sg_point(8,0), sg_dim(bmap.width() - 8, bmap.height));

void transform_shift(

sg_point_t shift,
sg_point_t p,
sg_area_t d
) const


virtual void wait(

const chrono::MicroTime & resolution
) const

This method will block until the refresh operation is complete


sg_size_t width() const

sg_int_t x_max() const

Returns the maximum x value.


sg_int_t y_max() const

Returns the maximum y value.


static Area load_area(

const arg::SourceFilePath & path
)


X

Thanks for Coming!

Subscribe to news and updates