libg19draw Reference

libg19draw is a library that allows you to construct a virtual 4 byte per pixel bitmap. Currently a few of the features are: line draw, filling, circle drawing and filling, inserting other drawing on each other, loading 24 and 32 bit(aplha) bitmaps.

Macros:

Structures

Functions:

 

LIBG19DRAW_VERSION_MAJOR

The major version of libg19draw. (x.0.0)

LIBG19DRAW_VERSION_MINOR

The minor version of libg19draw. (0.x.0)

LIBG19DRAW_VERSION_MICRO

The micro version of libg19draw. (0.0.x)

LIBG19DRAW_VERSION

The version of libg19draw as a string.

G19_WIDTH

The width of the G19’s LCD in pixels.

G19_HEIGHT

The height of the G19’s LCD in pixels.

 

G19ColorA(r, g, b, a)

This takes four colors: red, green, blue, and alpha. It with turn them into a unsigned int color.

Parameters:

int r The amount of red. (0 – 255)
int g The amount of green. (0 – 255)
int b The amount of blue. (0 – 255)
int a The amount of alpha. (0 – 255)

Return:

An unsigned int containing the color.

 

G19Color(r, g, b)

This is the same as G19ColorA but it does not use the alpha byte.

Parameters:

int r The amount of red. (0 – 255)
int g The amount of green. (0 – 255)
int b The amount of blue. (0 – 255)

Return:

An unsigned int containing the color.

 

G19SetA(c, a)

Sets the alpha byte on a color.

Parameters:

unsigned int c An unsigned int containing the color.
int a The amount of alpha. (0 – 255)

Return:

An unsigned int containing the color.

 

G19R(c)

Gets the amount of red in a color.

Parameters:

int c An unsigned int containing the color.

Return:

The amount of red in the color. (0 – 255)

 

G19G(c)

Gets the amount of green in a color.

Parameters:

int c An unsigned int containing the color.

Return:

The amount of green in the color. (0 – 255)

 

G19B(c)

Gets the amount of blue in a color.

Parameters:

int c An unsigned int containing the color.

Return:

The amount of blue in the color. (0 – 255)

 

G19A(c)

Gets the amount of alpha in a color.

Parameters:

int c An unsigned int containing the color.

Return:

The amount of alpha in the color. (0 – 255)

 

G19Draw

The drawing structure.

Fields:

int width The width of the draw in pixels.
int height The height of the draw in pixels.
size_t size The size of the draw data. (width * height * 4)
unsigned char * data The data for the draw. A 4 byte per pixel bitmap. Note that it is just bitmap data. There is no bitmap header.

 

G19Font

The font structure.

Fields:

FT_Library lib “A handle to a FreeType library instance.” – FreeType.org
FT_Face face “A handle to a given typographic face object.” – FreeType.org
int width The width of the font character(s) in pixels.
int height The height of the font character(s) in pixels.
int space The amout of space between charaters in pixels.
unsigned int color The color to use. You can use G19Color or G19ColorA.

 

G19Draw * g19_draw_new(int width, int height)

Creates a new G19Draw to the specified width and height.

Parameters:

int width The width of the image in pixels.
int height The height of the image in pixels.

Return:

A pointer to a G19Draw.

 

G19Draw * g19_draw_bmp(char * path)

Loads a bitmap into a new G19Draw. Currently only 24 bit and 32 bit alpha bitmaps are supported.

Parameters:

char * path The path to the bitmap to load.

Return:

A pointer to a G19Draw or NULL on error.

 

void g19_draw_free(G19Draw * draw)

Frees the data inside a G19Draw and then the G19Draw.

Parameters:

G19Draw * draw A pointer to a G19Draw.

 

void g19_draw_to_bmp(G19Draw * draw)

Writes the data from a G19Draw to a 24-bit bitmap at the specified path.

Parameters:

G19Draw * draw A pointer to a G19Draw.
char * path A string containing the path.

Return:

Non-zero on error.

 

G19Draw * g19_draw_resize(G19Draw * draw, int width, int height, unsigned int color, int free_old)

Resizes a G19Draw. It creates a new drawing at the new size then copies over the old data. It will also free the old drawing if specified.

Parameters:

G19Draw * draw A pointer to a G19Draw.
int width The width of the new G19Draw.
int height The height of the new G19Draw.
unsigned int color The color to use set the background to if the old image is smaller that the new one. You can use G19Color or G19ColorA.
int free_old 0 to leave the old G19Draw or 1 to free it.

Return:

A pointer to a new G19Draw.

 

void g19_draw_insert(G19Draw * draw, G19Draw * idraw, int ix, int iy)

Inserts a G19Draw onto another G19Draw.

Parameters:

G19Draw * draw A pointer to the The G19Draw that should be inserted onto.
G19Draw * idraw A pointer to the G19Draw that should be inserted.
int ix The starting x point on draw for the upper-left corner of idraw.
int iy The starting y point on draw for the upper-left corner of idraw.

 

void g19_draw_insert_ab(G19Draw * draw, G19Draw * idraw, int ix, int iy, int opac)

This function is the same as g19_draw_insert except that it supports alpha blending.

Parameters:

G19Draw * draw A pointer to the G19Draw that should be inserted onto.
G19Draw * idraw A pointer to the G19Draw that should be inserted.
int ix The starting x point on draw for the upper-left corner of idraw.
int iy The starting y point on draw for the upper-left corner of idraw.
int opac The level of alpha to use. (0 – 255) If it is less than 0, it will uses the value stored in the alpha byte.

 

unsigned int g19_draw_get_pixel(G19Draw * draw, int x, int y)

Gets a pixel from a G19Draw.

Parameters:

G19Draw * draw A pointer to a G19Draw.
int x The x coordinate of the pixel.
int y The y coordinate of the pixel.

Return:

An unsigned int containing the pixel’s color. G19R, G19G, G19B, and G19A can be used to extract values from the color.

 

void g19_draw_set_pixel(G19Draw * draw, int x, int y, unsigned int color)

Sets a single pixel on the G19Draw.

Parameters:

G19Draw * draw A pointer to a G19Draw.
int x The x coordinate of the pixel.
int y The y coordinate of the pixel.
unsigned int color The color to use. You can use G19Color or G19ColorA.

 

void g19_draw_fill(G19Draw * draw, unsigned int color)

Fills a G19Draw with the specified color.

Parameters:

G19Draw * draw A pointer to a G19Draw.
unsigned int color The color to use. You can use G19Color or G19ColorA.

 

void g19_draw_line(G19Draw * draw, int x1, int y1, int x2, int y2, unsigned int color)

Draws a line on a G19Draw between two points.

Parameters:

G19Draw * draw A pointer to a G19Draw.
int x1 The x coordinate of the first point.
int y1 The y coordinate of the first point.
int x2 The x coordinate of the second point.
int y2 The y coordinate of the second point.
unsigned int color The color to use. You can use G19Color or G19ColorA.

 

void g19_draw_rect(G19Draw * draw, int left, int top, int right, int bottom, int fill, unsigned int color)

Draws a rectangle on G19Draw.

Parameters:

G19Draw * draw A pointer to a G19Draw.
int left The left-most point of the rectangle. (x coordinate)
int top The top-most point of the rectangle. (y coordinate)
int right The right-most point of the rectangle. (x coordinate)
int bottom The bottom-most point of the rectangle. (y coordinate)
int fill Non-zero fills the rectangle. If it is 0, a 1 pixel border will be drawn.
unsigned int color The color to use. You can use G19Color or G19ColorA.

 

void g19_draw_circle(G19Draw * draw, int cx, int cy, int cr, int fill, unsigned int color)

Draws a circle on a G19Draw.

Parameters:

G19Draw * draw A pointer to a G19Draw.
int cx The x coordinate of the circle’s center.
int cy The y coordinate of the circle’s center.
int cr The radius of the circle in pixels.
int fill Non-zero fills the circle. If it is 0, a 1 pixel border will be drawn.
unsigned int color The color to use. You can use G19Color or G19ColorA.

 

G19Font * g19_font_new(char * ttf_path, int width, int height, int space, unsigned int color)

Creates a new G19Font.

Parameters:

char * ttf_path The path of the ttf font file to use.
int width The width of the font character(s).
int height The height of the font character(s).
int space The space between characters in pixels.
unsigned int color The color to use. You can use G19Color or G19ColorA.

Return:

A pointer to a G19Font.

 

void g19_font_set_size(G19Font * font, int width, int height)

Sets the font size on a G19Font.

Parameters:

G19Font * font A pointer to a G19Font.
int width The width of the character(s) in pixels.
int height The height of the character(s) in pixels.

 

void g19_font_set_space(G19Font * font, int space)

Sets the character spacing on a G19Font.

Parameters:

G19Font * font A pointer to a G19Font.
int space The space between characters in pixels.

 

void g19_font_set_color(G19Font * font, unsigned int color)

Sets the color of the font a G19Font.

Parameters:

G19Font * font A pointer to a G19Font.
unsigned int color The color to use. You can use G19Color or G19ColorA.

 

int g19_font_draw(G19Font * font, G19Draw * draw, int x, int y, char * text)

Draws font onto a G19Draw

Parameters:

G19Font * font A pointer to a G19Font.
G19Draw * draw A pointer to a G19Draw.
int x The x coordinate on draw to start at.
int y The y coordinate on draw to start at.
char * text The text to draw.

Return:

 

void g19_font_free(G19Font * font)

Frees a G19Font.

Parameters:

G19Font * font A pointer to a G19Font.

 

Leave a comment

0 Comments.

Leave a Reply


[ Ctrl + Enter ]