Foenix A2650 OS/f Library
 
Loading...
Searching...
No Matches
bitmap.h File Reference
#include "general.h"
#include "text.h"
#include <stdbool.h>
#include <mcp/syscalls.h>
#include "a2560k.h"

Go to the source code of this file.

Data Structures

struct  Bitmap
 

Macros

#define PARAM_DRAW_NE   true
 for Bitmap_DrawCircleQuadrants, do draw NE quadrant
 
#define PARAM_DRAW_SE   true
 for Bitmap_DrawCircleQuadrants, do draw SE quadrant
 
#define PARAM_DRAW_SW   true
 for Bitmap_DrawCircleQuadrants, do draw SW quadrant
 
#define PARAM_DRAW_NW   true
 for Bitmap_DrawCircleQuadrants, do draw NW quadrant
 
#define PARAM_SKIP_NE   false
 for Bitmap_DrawCircleQuadrants, do NOT draw NE quadrant
 
#define PARAM_SKIP_SE   false
 for Bitmap_DrawCircleQuadrants, do NOT draw SE quadrant
 
#define PARAM_SKIP_SW   false
 for Bitmap_DrawCircleQuadrants, do NOT draw SW quadrant
 
#define PARAM_SKIP_NW   false
 for Bitmap_DrawCircleQuadrants, do NOT draw NW quadrant
 
#define PARAM_DO_FILL   true
 for various graphic routines
 
#define PARAM_DO_NOT_FILL   false
 for various graphic routines
 
#define PARAM_IN_VRAM   true
 for Bitmap_New
 
#define PARAM_NOT_IN_VRAM   false
 for Bitmap_New
 

Functions

BitmapBitmap_New (int16_t width, int16_t height, Font *the_font, bool in_vram)
 Create a new bitmap object by allocating space for the bitmap struct in regular memory, and for the graphics, in VRAM NOTE: when creating a bitmap to represent something actually in VRAM, pass true to in_vram, and manually assign a known VRAM location afterwards. More...
 
bool Bitmap_Resize (Bitmap *the_bitmap, int16_t width, int16_t height)
 Resize and existing bitmap by setting new width/height and allocating bigger storage if necessary NOTE: if the bitmap is held in VRAM, storage will not be reallocated NOTE: if the new size for the bitmap is smaller than the previous size, storage will not be reallocated - extra bytes will simply not be used. More...
 
bool Bitmap_BlitRect (Bitmap *src_bm, Rectangle *src_rect, Bitmap *dst_bm, int16_t dst_x, int16_t dst_y)
 Blit a rect from source bitmap to distination bitmap This is a wrapper around Bitmap_Blit() The source and destination bitmaps can be the same: you can use this to copy a chunk of pixels from one part of a screen to another. More...
 
bool Bitmap_Blit (Bitmap *src_bm, int16_t src_x, int16_t src_y, Bitmap *dst_bm, int16_t dst_x, int16_t dst_y, int16_t width, int16_t height)
 Blit from source bitmap to distination bitmap. More...
 
bool Bitmap_Tile (Bitmap *src_bm, int16_t src_x, int16_t src_y, Bitmap *dst_bm, int16_t width, int16_t height)
 Tile the source bitmap into the destination bitmap, filling it The source and destination bitmaps can be the same: you can use this to copy a chunk of pixels from one part of a screen to another. More...
 
bool Bitmap_TileV1 (Bitmap *src_bm, int16_t src_x, int16_t src_y, Bitmap *dst_bm, int16_t width, int16_t height)
 Tile the source bitmap into the destination bitmap, filling it The source and destination bitmaps can be the same: you can use this to copy a chunk of pixels from one part of a screen to another. More...
 
bool Bitmap_TileV2 (Bitmap *src_bm, int16_t src_x, int16_t src_y, Bitmap *dst_bm, int16_t width, int16_t height)
 Tile the source bitmap into the destination bitmap, filling it The source and destination bitmaps can be the same: you can use this to copy a chunk of pixels from one part of a screen to another. More...
 
bool Bitmap_TileV3 (Bitmap *src_bm, int16_t src_x, int16_t src_y, Bitmap *dst_bm, int16_t width, int16_t height)
 Tile the source bitmap into the destination bitmap, filling it The source and destination bitmaps can be the same: you can use this to copy a chunk of pixels from one part of a screen to another. More...
 
bool Bitmap_FillMemory (Bitmap *the_bitmap, uint8_t the_color)
 
bool Bitmap_FillBoxRect (Bitmap *the_bitmap, Rectangle *the_coords, uint8_t the_color)
 Fill pixel values for the passed Rectangle object, using the specified LUT value. More...
 
bool Bitmap_FillBox (Bitmap *the_bitmap, int16_t x, int16_t y, int16_t width, int16_t height, uint8_t the_color)
 Fill pixel values for a specific box area calling function must validate screen id, coords! More...
 
bool Bitmap_SetFont (Bitmap *the_bitmap, Font *the_font)
 Set the font This is the font that will be used for all font drawing in this bitmap. More...
 
bool Bitmap_SetColor (Bitmap *the_bitmap, uint8_t the_color)
 Set the "pen" color This is the color that the next pen-based graphics function will use This only affects functions that use the pen: any graphics function that specifies a color will use that instead. More...
 
bool Bitmap_SetXY (Bitmap *the_bitmap, int16_t x, int16_t y)
 Set the "pen" position This is the location that the next pen-based graphics function will use for a starting location NOTE: you are allowed to set negative values, but not values greater than the height/width of the screen. More...
 
uint8_t Bitmap_GetColor (Bitmap *the_bitmap)
 Get the current color of the pen. More...
 
int16_t Bitmap_GetX (Bitmap *the_bitmap)
 Get the current X position of the pen. More...
 
int16_t Bitmap_GetY (Bitmap *the_bitmap)
 Get the current Y position of the pen. More...
 
unsigned char * Bitmap_GetMemLoc (Bitmap *the_bitmap)
 Calculate the VRAM location of the current coordinate within the bitmap. More...
 
uint32_t Bitmap_GetMemLocInt (Bitmap *the_bitmap)
 Calculate the VRAM location of the current coordinate within the bitmap. More...
 
FontBitmap_GetFont (Bitmap *the_bitmap)
 Get the current font of the pen. More...
 
bool Bitmap_SetPixelAtXY (Bitmap *the_bitmap, int16_t x, int16_t y, uint8_t the_color)
 Set a char at a specified x, y coord. More...
 
uint8_t Bitmap_GetPixelAtXY (Bitmap *the_bitmap, int16_t x, int16_t y)
 Get the pixel CLUT index at a specified x, y coord. More...
 
bool Bitmap_DrawLine (Bitmap *the_bitmap, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t the_color)
 Draws a line between 2 passed coordinates. More...
 
bool Bitmap_DrawHLine (Bitmap *the_bitmap, int16_t x, int16_t y, int16_t the_line_len, uint8_t the_color)
 Draws a horizontal line from specified coords, for n pixels, using the specified pixel value. More...
 
bool Bitmap_DrawVLine (Bitmap *the_bitmap, int16_t x, int16_t y, int16_t the_line_len, uint8_t the_color)
 Draws a vertical line from specified coords, for n pixels. More...
 
bool Bitmap_DrawBoxRect (Bitmap *the_bitmap, Rectangle *the_coords, uint8_t the_color)
 Draws a rectangle based on the passed Rectangle object, using the specified LUT value. More...
 
bool Bitmap_DrawBoxCoords (Bitmap *the_bitmap, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t the_color)
 Draws a rectangle based on 2 sets of coords, using the specified LUT value. More...
 
bool Bitmap_DrawBox (Bitmap *the_bitmap, int16_t x, int16_t y, int16_t width, int16_t height, uint8_t the_color, bool do_fill)
 Draws a rectangle based on start coords and width/height, and optionally fills the rectangle. More...
 
bool Bitmap_DrawRoundBox (Bitmap *the_bitmap, int16_t x, int16_t y, int16_t width, int16_t height, int16_t radius, uint8_t the_color, bool do_fill)
 Draws a rounded rectangle with the specified size and radius, and optionally fills the rectangle. More...
 
bool Bitmap_DrawCircle (Bitmap *the_bitmap, int16_t x1, int16_t y1, int16_t radius, uint8_t the_color)
 Draw a circle Based on http://rosettacode.org/wiki/Bitmap/Midpoint_circle_algorithm#C.
 

Function Documentation

◆ Bitmap_Blit()

bool Bitmap_Blit ( Bitmap src_bm,
int16_t  src_x,
int16_t  src_y,
Bitmap dst_bm,
int16_t  dst_x,
int16_t  dst_y,
int16_t  width,
int16_t  height 
)

Blit from source bitmap to distination bitmap.

The source and destination bitmaps can be the same: you can use this to copy a chunk of pixels from one part of a screen to another. If the destination location cannot fit the entirety of the copied rectangle, the copy will be truncated, but will not return an error.

Parameters
src_bm– the source bitmap. It must have a valid address within the VRAM memory space.
dst_bm– the destination bitmap. It must have a valid address within the VRAM memory space. It can be the same bitmap as the source.
src_x– the upper left coordinate within the source bitmap, for the rectangle you want to copy. May be negative.
src_y– the upper left coordinate within the source bitmap, for the rectangle you want to copy. May be negative.
dst_x– the location within the destination bitmap to copy pixels to. May be negative.
dst_y– the location within the destination bitmap to copy pixels to. May be negative.
width– the scope of the copy, in pixels.
height– the scope of the copy, in pixels.

◆ Bitmap_BlitRect()

bool Bitmap_BlitRect ( Bitmap src_bm,
Rectangle src_rect,
Bitmap dst_bm,
int16_t  dst_x,
int16_t  dst_y 
)

Blit a rect from source bitmap to distination bitmap This is a wrapper around Bitmap_Blit() The source and destination bitmaps can be the same: you can use this to copy a chunk of pixels from one part of a screen to another.

If the destination location cannot fit the entirety of the copied rectangle, the copy will be truncated, but will not return an error.

Parameters
src_bm– the source bitmap. It must have a valid address within the VRAM memory space.
dst_bm– the destination bitmap. It must have a valid address within the VRAM memory space. It can be the same bitmap as the source.
src_rect– the rectangle from the source bitmap to be blitted to the target bitmap
dst_x– the location within the destination bitmap to copy pixels to. May be negative.
dst_y– the location within the destination bitmap to copy pixels to. May be negative.

◆ Bitmap_DrawBox()

bool Bitmap_DrawBox ( Bitmap the_bitmap,
int16_t  x,
int16_t  y,
int16_t  width,
int16_t  height,
uint8_t  the_color,
bool  do_fill 
)

Draws a rectangle based on start coords and width/height, and optionally fills the rectangle.

Parameters
width– width, in pixels, of the rectangle to be drawn
height– height, in pixels, of the rectangle to be drawn
the_color– a 1-byte index to the current LUT
do_fill– If true, the box will be filled with the provided color. If false, the box will only draw the outline.
Returns
returns false on any error/invalid input.

◆ Bitmap_DrawBoxCoords()

bool Bitmap_DrawBoxCoords ( Bitmap the_bitmap,
int16_t  x1,
int16_t  y1,
int16_t  x2,
int16_t  y2,
uint8_t  the_color 
)

Draws a rectangle based on 2 sets of coords, using the specified LUT value.

Parameters
the_color– a 1-byte index to the current LUT
Returns
returns false on any error/invalid input.

◆ Bitmap_DrawBoxRect()

bool Bitmap_DrawBoxRect ( Bitmap the_bitmap,
Rectangle the_coords,
uint8_t  the_color 
)

Draws a rectangle based on the passed Rectangle object, using the specified LUT value.

Parameters
the_color– a 1-byte index to the current LUT
Returns
returns false on any error/invalid input.

◆ Bitmap_DrawHLine()

bool Bitmap_DrawHLine ( Bitmap the_bitmap,
int16_t  x,
int16_t  y,
int16_t  the_line_len,
uint8_t  the_color 
)

Draws a horizontal line from specified coords, for n pixels, using the specified pixel value.

Parameters
the_color– a 1-byte index to the current LUT
Returns
returns false on any error/invalid input.

◆ Bitmap_DrawLine()

bool Bitmap_DrawLine ( Bitmap the_bitmap,
int16_t  x1,
int16_t  y1,
int16_t  x2,
int16_t  y2,
uint8_t  the_color 
)

Draws a line between 2 passed coordinates.

Use for any line that is not perfectly vertical or perfectly horizontal Based on http://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#C. Used in C128 Lich King.

◆ Bitmap_DrawRoundBox()

bool Bitmap_DrawRoundBox ( Bitmap the_bitmap,
int16_t  x,
int16_t  y,
int16_t  width,
int16_t  height,
int16_t  radius,
uint8_t  the_color,
bool  do_fill 
)

Draws a rounded rectangle with the specified size and radius, and optionally fills the rectangle.

Parameters
width– width, in pixels, of the rectangle to be drawn
height– height, in pixels, of the rectangle to be drawn
radius– radius, in pixels, of the arc to be applied to the rectangle's corners. Enforces a minimum of 3, maximum of 20.
the_color– a 1-byte index to the current color LUT
do_fill– If true, the box will be filled with the provided color. If false, the box will only draw the outline.
Returns
returns false on any error/invalid input.

◆ Bitmap_DrawVLine()

bool Bitmap_DrawVLine ( Bitmap the_bitmap,
int16_t  x,
int16_t  y,
int16_t  the_line_len,
uint8_t  the_color 
)

Draws a vertical line from specified coords, for n pixels.

Parameters
the_color– a 1-byte index to the current LUT
Returns
returns false on any error/invalid input.

◆ Bitmap_FillBox()

bool Bitmap_FillBox ( Bitmap the_bitmap,
int16_t  x,
int16_t  y,
int16_t  width,
int16_t  height,
uint8_t  the_color 
)

Fill pixel values for a specific box area calling function must validate screen id, coords!

Parameters
the_color– a 1-byte index to the current LUT
Returns
returns false on any error/invalid input.
Parameters
width– width, in pixels, of the rectangle to be filled
height– height, in pixels, of the rectangle to be filled
the_color– a 1-byte index to the current LUT
Returns
returns false on any error/invalid input.

◆ Bitmap_FillBoxRect()

bool Bitmap_FillBoxRect ( Bitmap the_bitmap,
Rectangle the_coords,
uint8_t  the_color 
)

Fill pixel values for the passed Rectangle object, using the specified LUT value.

Parameters
the_color– a 1-byte index to the current LUT
Returns
returns false on any error/invalid input.

◆ Bitmap_FillMemory()

bool Bitmap_FillMemory ( Bitmap the_bitmap,
uint8_t  the_color 
)
Parameters
the_color– a 1-byte index to the current LUT
Returns
returns false on any error/invalid input.

◆ Bitmap_GetColor()

uint8_t Bitmap_GetColor ( Bitmap the_bitmap)

Get the current color of the pen.

Parameters
the_bitmap– reference to a valid Bitmap object.
Returns
Returns a 1-byte index to the current LUT, or 0 on any error

◆ Bitmap_GetFont()

Font * Bitmap_GetFont ( Bitmap the_bitmap)

Get the current font of the pen.

Parameters
the_bitmap– reference to a valid Bitmap object.
Returns
Returns NULL on any error

◆ Bitmap_GetMemLoc()

unsigned char * Bitmap_GetMemLoc ( Bitmap the_bitmap)

Calculate the VRAM location of the current coordinate within the bitmap.

Parameters
the_bitmap– reference to a valid Bitmap object.
Returns
Returns a pointer to the VRAM location that corresponds to the current "pen" X, Y, or NULL on any error condition

◆ Bitmap_GetMemLocInt()

uint32_t Bitmap_GetMemLocInt ( Bitmap the_bitmap)

Calculate the VRAM location of the current coordinate within the bitmap.

Parameters
the_bitmap– reference to a valid Bitmap object.
Returns
Returns an unsigned long that can be converted to the VRAM location that corresponds to the current "pen" X, Y, or NULL on any error condition

◆ Bitmap_GetPixelAtXY()

uint8_t Bitmap_GetPixelAtXY ( Bitmap the_bitmap,
int16_t  x,
int16_t  y 
)

Get the pixel CLUT index at a specified x, y coord.

Returns
returns an 8-bit CLUT index

◆ Bitmap_GetX()

int16_t Bitmap_GetX ( Bitmap the_bitmap)

Get the current X position of the pen.

Parameters
the_bitmap– reference to a valid Bitmap object.
Returns
Returns -1 on any error

◆ Bitmap_GetY()

int16_t Bitmap_GetY ( Bitmap the_bitmap)

Get the current Y position of the pen.

Parameters
the_bitmap– reference to a valid Bitmap object.
Returns
Returns -1 on any error

◆ Bitmap_New()

Bitmap * Bitmap_New ( int16_t  width,
int16_t  height,
Font the_font,
bool  in_vram 
)

Create a new bitmap object by allocating space for the bitmap struct in regular memory, and for the graphics, in VRAM NOTE: when creating a bitmap to represent something actually in VRAM, pass true to in_vram, and manually assign a known VRAM location afterwards.

Parameters
width– width, in pixels, of the bitmap to be created
height– height, in pixels, of the bitmap to be created
the_font– optional font object to associate with the Bitmap.
in_vram– if true, no space will be allocated for the bitmap graphics. If false, width * height area of memory will be allocated in standard memory.

◆ Bitmap_Resize()

bool Bitmap_Resize ( Bitmap the_bitmap,
int16_t  width,
int16_t  height 
)

Resize and existing bitmap by setting new width/height and allocating bigger storage if necessary NOTE: if the bitmap is held in VRAM, storage will not be reallocated NOTE: if the new size for the bitmap is smaller than the previous size, storage will not be reallocated - extra bytes will simply not be used.

Parameters
width– the new width, in pixels, to resize the bitmap to
height– the new height, in pixels, to resize the bitmap to
Returns
Returns false in any error condition

◆ Bitmap_SetColor()

bool Bitmap_SetColor ( Bitmap the_bitmap,
uint8_t  the_color 
)

Set the "pen" color This is the color that the next pen-based graphics function will use This only affects functions that use the pen: any graphics function that specifies a color will use that instead.

Parameters
the_bitmap– reference to a valid Bitmap object.
the_color– a 1-byte index to the current LUT
Returns
Returns false on any error condition

◆ Bitmap_SetFont()

bool Bitmap_SetFont ( Bitmap the_bitmap,
Font the_font 
)

Set the font This is the font that will be used for all font drawing in this bitmap.

Parameters
the_bitmap– reference to a valid Bitmap object.
the_font– reference to a complete, loaded Font object.
Returns
Returns false on any error condition

◆ Bitmap_SetPixelAtXY()

bool Bitmap_SetPixelAtXY ( Bitmap the_bitmap,
int16_t  x,
int16_t  y,
uint8_t  the_color 
)

Set a char at a specified x, y coord.

Parameters
the_color– a 1-byte index to the current LUT
Returns
returns false on any error/invalid input.

◆ Bitmap_SetXY()

bool Bitmap_SetXY ( Bitmap the_bitmap,
int16_t  x,
int16_t  y 
)

Set the "pen" position This is the location that the next pen-based graphics function will use for a starting location NOTE: you are allowed to set negative values, but not values greater than the height/width of the screen.

This is to allow for functions that may have portions visible on the screen, such as a row of text that starts 2 pixels to the left of the bitmap's left edge. This only affects functions that use the pen: any graphics function that specifies an X, Y coordinate will use that instead

Parameters
the_bitmap– reference to a valid Bitmap object.
x– the horizontal position, between 0 and bitmap width - 1
y– the vertical position, between 0 and bitmap height - 1
Returns
Returns false on any error condition

◆ Bitmap_Tile()

bool Bitmap_Tile ( Bitmap src_bm,
int16_t  src_x,
int16_t  src_y,
Bitmap dst_bm,
int16_t  width,
int16_t  height 
)

Tile the source bitmap into the destination bitmap, filling it The source and destination bitmaps can be the same: you can use this to copy a chunk of pixels from one part of a screen to another.

If the destination location cannot fit the entirety of the copied rectangle, the copy will be truncated, but will not return an error.

Parameters
src_bm– the source bitmap. It must have a valid address within the VRAM memory space.
dst_bm– the destination bitmap. It must have a valid address within the VRAM memory space. It can be the same bitmap as the source.
src_x– the upper left coordinate within the source bitmap, for the tile you want to copy. Must be non-negative.
src_y– the upper left coordinate within the source bitmap, for the tile you want to copy. Must be non-negative.
width– the size of the tile to be derived from the source bitmap, in pixels.
height– the size of the tile to be derived from the source bitmap, in pixels.

◆ Bitmap_TileV1()

bool Bitmap_TileV1 ( Bitmap src_bm,
int16_t  src_x,
int16_t  src_y,
Bitmap dst_bm,
int16_t  width,
int16_t  height 
)

Tile the source bitmap into the destination bitmap, filling it The source and destination bitmaps can be the same: you can use this to copy a chunk of pixels from one part of a screen to another.

If the destination location cannot fit the entirety of the copied rectangle, the copy will be truncated, but will not return an error.

Parameters
src_bm– the source bitmap. It must have a valid address within the VRAM memory space.
dst_bm– the destination bitmap. It must have a valid address within the VRAM memory space. It can be the same bitmap as the source.
src_x– the upper left coordinate within the source bitmap, for the tile you want to copy. Must be non-negative.
src_y– the upper left coordinate within the source bitmap, for the tile you want to copy. Must be non-negative.
width– the size of the tile to be derived from the source bitmap, in pixels.
height– the size of the tile to be derived from the source bitmap, in pixels.

◆ Bitmap_TileV2()

bool Bitmap_TileV2 ( Bitmap src_bm,
int16_t  src_x,
int16_t  src_y,
Bitmap dst_bm,
int16_t  width,
int16_t  height 
)

Tile the source bitmap into the destination bitmap, filling it The source and destination bitmaps can be the same: you can use this to copy a chunk of pixels from one part of a screen to another.

If the destination location cannot fit the entirety of the copied rectangle, the copy will be truncated, but will not return an error.

Parameters
src_bm– the source bitmap. It must have a valid address within the VRAM memory space.
dst_bm– the destination bitmap. It must have a valid address within the VRAM memory space. It can be the same bitmap as the source.
src_x– the upper left coordinate within the source bitmap, for the tile you want to copy. Must be non-negative.
src_y– the upper left coordinate within the source bitmap, for the tile you want to copy. Must be non-negative.
width– the size of the tile to be derived from the source bitmap, in pixels.
height– the size of the tile to be derived from the source bitmap, in pixels.

◆ Bitmap_TileV3()

bool Bitmap_TileV3 ( Bitmap src_bm,
int16_t  src_x,
int16_t  src_y,
Bitmap dst_bm,
int16_t  width,
int16_t  height 
)

Tile the source bitmap into the destination bitmap, filling it The source and destination bitmaps can be the same: you can use this to copy a chunk of pixels from one part of a screen to another.

If the destination location cannot fit the entirety of the copied rectangle, the copy will be truncated, but will not return an error.

Parameters
src_bm– the source bitmap. It must have a valid address within the VRAM memory space.
dst_bm– the destination bitmap. It must have a valid address within the VRAM memory space. It can be the same bitmap as the source.
src_x– the upper left coordinate within the source bitmap, for the tile you want to copy. Must be non-negative.
src_y– the upper left coordinate within the source bitmap, for the tile you want to copy. Must be non-negative.
width– the size of the tile to be derived from the source bitmap, in pixels.
height– the size of the tile to be derived from the source bitmap, in pixels.