mikroSDK Reference Manual
Drawing Images

Image Drawing API. More...

Functions list

int gl_draw_image (gl_rectangle_t *dest, gl_rectangle_t *src, const uint8_t *__generic image)
 Draw image on display. More...
 
uint16_t gl_image_width (const uint8_t *__generic image)
 Calculate width of the image. More...
 
uint16_t gl_image_height (const uint8_t *__generic image)
 Calculate height of the image. More...
 
gl_image_format_t gl_image_format (const uint8_t *__generic image)
 Return format of the image. More...
 

Detailed Description

This API is used for drawing and managing images on the display.

Function Documentation

◆ gl_draw_image()

int gl_draw_image ( gl_rectangle_t dest,
gl_rectangle_t src,
const uint8_t *__generic  image 
)

This function draws an image on display. It is specialized for drawing support image formats, but may redefined by user. For that option please have a look at the Image Graphics Format Handlers.

Parameters
[in]destFrame in which the image will be drawn. See gl_rectangle_t structure definition for detailed explanation.
[in]srcPart of the original image which will be drawn into dest frame. See gl_rectangle_t structure definition for detailed explanation.
[in]imagePointer to an image.
Returns
Returns zero if the image is successfully drawn, otherwise returns non-zero value.
Precondition
Before using this function a driver must be set using the gl_set_driver function.
Note
Image must be generated by NECTO Studio's resource generator.
See also
gl_draw_jpeg_image, gl_draw_bitmap_16bpp, gl_draw_bitmap_8bpp, gl_draw_bitmap_4bpp, gl_draw_bitmap_1bpp

Example

#include "gl.h"
#include "board.h"
#include "tft8.h"
#include "resource.h"
static gl_driver_t driver;
static tft8_cfg_t tft_cfg;
void main()
{
gl_rectangle_t dest = { {0,0}, 0, 0 };
gl_rectangle_t src = { {0,0}, 100, 100 };
// initialize driver
TFT8_MAP_PINOUTS_16BIT(tft_cfg);
tft_cfg.board = &TFT_BOARD_7_CAPACITIVE;
tft8_init(&tft_cfg, &driver);
// prepare display for drawing
gl_set_driver(&driver); // set initialized driver
gl_clear(GL_CHARLESTON_GREEN); // clear display
// display image true to its size
// setting 0 for a source rectangle will use whole image without cropping
dest.top_left.x = 10;
dest.top_left.y = 70;
dest.width = gl_image_width(mikroejpg);
dest.height = gl_image_height(mikroejpg);
gl_draw_image(&dest, 0, mikroejpg);
// depending on the destination rectangle actual image can be stretched to fit rectangle dimensions
// larger destination
dest.top_left.x = 276;
dest.width = gl_image_width(mikroebmp16) + 50;
dest.height = gl_image_height(mikroebmp16) + 10;
gl_draw_image(&dest, 0, mikroebmp16);
// smaller destination
dest.top_left.x = 600;
dest.width = gl_image_width(mikroebmp8) / 2;
dest.height = gl_image_height(mikroebmp8) / 2;
gl_draw_image(&dest, 0, mikroebmp8);
// and setting the soruce rectangle will crop the image
// function will fit stretch source rect over crop rect area
src.top_left.x = 10;
src.top_left.y = 10;
src.width = 40;
src.height = 50;
dest.top_left.x = 10;
dest.top_left.y = 290;
dest.width = gl_image_width(mikroebmp4);
dest.height = gl_image_height(mikroebmp4);
gl_draw_image(&dest, &src, mikroebmp4);
// no destination giver results in an error
if (gl_draw_image(&dest, 0, NULL) != 0)
{
gl_draw_circle(400, 340, 30);
}
// no destination giver results in an error
if (gl_draw_image(NULL, 0, mikroebmp1) != 0)
{
gl_draw_circle(640, 340, 30);
}
}

◆ gl_image_width()

uint16_t gl_image_width ( const uint8_t *__generic  image)

This function returns the width of the image.

Parameters
[in]imagePointer to an image.
Returns
If the image is not null returns width of the image, otherwise returns zero.
Note
Image must be generated by NECTO Studio's resource generator.

Example

#include "gl.h"
#include "board.h"
#include "tft8.h"
#include "resource.h"
#include "conversions.h"
static gl_driver_t driver;
static tft8_cfg_t tft_cfg;
const code char* images[] = {
mikroejpg,
mikroebmp1,
mikroebmp4,
mikroebmp8,
mikroebmp16
};
void print_num(gl_uint_t num, gl_coord_t x, gl_coord_t y){
char str_buff[10];
uint16_to_str(num, str_buff);
gl_draw_text(str_buff, x, y);
}
void main()
{
// initialize driver
TFT8_MAP_PINOUTS_16BIT(tft_cfg);
tft_cfg.board = &TFT_BOARD_7_CAPACITIVE;
tft8_init(&tft_cfg, &driver);
// prepare display for drawing
gl_set_driver(&driver); // set initialized driver
gl_set_font(test_font); // set font
gl_clear(GL_CHARLESTON_GREEN); // clear display
gl_rectangle_t dest = { {5,5}, 100, 100 };
for (int i = 0; i < 5 ; i++)
{
dest.width = gl_image_width(images[i]);
dest.height = gl_image_height(images[i]);
gl_draw_image(&dest, 0, images[i]);
print_num(dest.width, dest.width , dest.top_left.y);
dest.top_left.y += dest.height + 10;
}
}

◆ gl_image_height()

uint16_t gl_image_height ( const uint8_t *__generic  image)

This function returns the height of the image.

Parameters
[in]imagePointer to an image.
Returns
If the image is not null returns height of the image, otherwise returns zero.
Note
Image must be generated by NECTO Studio's resource generator.

Example

#include "gl.h"
#include "board.h"
#include "tft8.h"
#include "resource.h"
#include "conversions.h"
static gl_driver_t driver;
static tft8_cfg_t tft_cfg;
const code char* images[] = {
mikroejpg,
mikroebmp1,
mikroebmp4,
mikroebmp8,
mikroebmp16
};
void print_num(gl_uint_t num, gl_coord_t x, gl_coord_t y){
char str_buff[10];
uint16_to_str(num, str_buff);
gl_draw_text(str_buff, x, y);
}
void main()
{
// initialize driver
TFT8_MAP_PINOUTS_16BIT(tft_cfg);
tft_cfg.board = &TFT_BOARD_7_CAPACITIVE;
tft8_init(&tft_cfg, &driver);
// prepare display for drawing
gl_set_driver(&driver); // set initialized driver
gl_set_font(test_font); // set font
gl_clear(GL_CHARLESTON_GREEN); // clear display
gl_rectangle_t dest = { {5,5}, 100, 100 };
for (int i = 0; i < 5 ; i++)
{
dest.width = gl_image_width(images[i]);
dest.height = gl_image_height(images[i]);
gl_draw_image(&dest, 0, images[i]);
print_num(dest.height, dest.width , dest.top_left.y);
dest.top_left.y += dest.height + 10;
}
}

◆ gl_image_format()

gl_image_format_t gl_image_format ( const uint8_t *__generic  image)

This function returns the format of the image.

Parameters
[in]imagePointer to an image.
Returns
If the image is not null returns format of image, otherwise returns zero. See gl_image_format_t structure definition for detailed explanation.
Note
Image must be generated by NECTO Studio's resource generator.

Example

#include "gl.h"
#include "board.h"
#include "tft8.h"
static gl_driver_t driver;
static tft8_cfg_t tft_cfg;
extern const code char mikroejpg[2701];
extern const code char mikroebmp1[2662];
extern const code char mikroebmp4[10493];
extern const code char mikroebmp8[21428];
extern const code char mikroebmp16[41826];
void main()
{
// initialize driver
TFT8_MAP_PINOUTS_16BIT(tft_cfg);
tft_cfg.board = &TFT_BOARD_7_CAPACITIVE;
tft8_init(&tft_cfg, &driver);
// prepare display for drawing
gl_set_driver(&driver); // set initialized driver
gl_clear(GL_CHARLESTON_GREEN); // clear display
gl_set_pen_width(0); // turn off pen
// we expect every circle to be green as confirmation that image format is correctly guessed
// JPEG
else
gl_draw_circle(20, 20, 10);
// 1 bit BMP
else
gl_draw_circle(40, 20, 10);
// 4 bit BMP
else
gl_draw_circle(60, 20, 10);
// 8 bit BMP
else
gl_draw_circle(80, 20, 10);
// 16 bit BMP
else
gl_draw_circle(100, 20, 10);
}
gl_rectangle_t::width
uint16_t width
Definition: gl_types.h:131
GL_IMAGE_FORMAT_BITMAP_4BPP
Definition: gl_types.h:74
uint16_to_str
void uint16_to_str(uint16_t input, char *output)
Converts uint16_t to string.
gl_set_font
void gl_set_font(const uint8_t *font)
Initialize the active font.
gl_driver_t
The context structure for storing driver configuration.
Definition: gl_types.h:145
gl_set_brush_color
void gl_set_brush_color(gl_color_t color)
Sets active brush color.
GL_IMAGE_FORMAT_BITMAP_16BPP
Definition: gl_types.h:76
GL_GREEN
Definition: gl_colors.h:147
GL_RED
Definition: gl_colors.h:212
gl_rectangle_t::top_left
gl_point_t top_left
Definition: gl_types.h:130
gl_image_width
uint16_t gl_image_width(const uint8_t *__generic image)
Calculate width of the image.
GL_CHARLESTON_GREEN
Definition: gl_colors.h:246
gl_draw_text
void gl_draw_text(const char *__generic text, gl_coord_t x, gl_coord_t y)
Write a text on display.
gl_set_pen_width
void gl_set_pen_width(uint16_t width)
Sets the active pen width.
gl_rectangle_t::height
uint16_t height
Definition: gl_types.h:132
gl_set_driver
void gl_set_driver(gl_driver_t *driver)
Sets the driver to the active state and enables drawing on whole display.
conversions.h
Conversion function prototypes.
gl_rectangle_t
The context structure for storing rectangle by its top left point and width and height (in pixels).
Definition: gl_types.h:128
GL_IMAGE_FORMAT_BITMAP_1BPP
Definition: gl_types.h:73
gl_image_height
uint16_t gl_image_height(const uint8_t *__generic image)
Calculate height of the image.
gl_draw_image
int gl_draw_image(gl_rectangle_t *dest, gl_rectangle_t *src, const uint8_t *__generic image)
Draw image on display.
GL_IMAGE_FORMAT_BITMAP_8BPP
Definition: gl_types.h:75
gl_coord_t
int16_t gl_coord_t
Definition: gl_types.h:102
gl_clear
void gl_clear(gl_color_t color)
Paint whole display.
GL_IMAGE_FORMAT_JPEG
Definition: gl_types.h:77
gl_image_format
gl_image_format_t gl_image_format(const uint8_t *__generic image)
Return format of the image.
gl_point_t::y
gl_int_t y
Definition: gl_types.h:111
gl_uint_t
uint16_t gl_uint_t
Definition: gl_types.h:91
gl_point_t::x
gl_int_t x
Definition: gl_types.h:110
gl.h
Graphics Library.
gl_draw_circle
void gl_draw_circle(gl_coord_t x0, gl_coord_t y0, gl_uint_t radius)
Draw a circle on display.