Img

The image widget is the basic widget used to display images. Image widgets support moving, zooming, rotating, etc.

Usage

Create Widget

It is possible to use gui_img_create_from_mem() to create an image widget from memory, or use gui_img_create_from_fs() to create an image widget from a file. Alternatively, gui_img_create_from_ftl() can be used to create an image widget from ftl. If the width or height of the image widget is set to 0, the widget’s size will be set according to the size of the image source automatically.

Set Fouce

The default focus position of the image widget is at the top-left corner of the image (0,0). Developers can use gui_img_set_focus() to set a new focus point for the image widget. After setting a new focus, all transformations, rotations, and translations of the image widget will be performed based on the new focus point.

Set Attribute

It is possible to use gui_img_set_attribute() to set the attribute of an image widget, replace it with a new image, and set a new coordinate.

Get Height/Width

If you want to get the height/width of image widget, do so with gui_img_get_height() or gui_img_get_width().

Refresh

Refresh the image size using gui_img_refresh_size().

Blend Mode

Set the image’s blend mode using gui_img_set_mode().

Translation

Use gui_img_translate() to move the image widget. It can move an image widget to a new coordinate without changing the original coordinate in the widget’s attribute.

Rotation

Rotate the image widget around the center of the circle with this API gui_img_rotation().

Zoom

You can adjust the size of the image widget to fit your requirements by this API gui_img_scale().

Opacity

The opacity value of the image is adjustable, and it can be set using gui_img_set_opacity().

Quality

The image’s quality can be set using gui_img_set_quality().

Screenshot

The gui_img_tree_convert_to_img() can be used to save a fullscreen screenshot. The saved image will be in RGB format.

Example

void test_event_cb(void *obj, gui_event_t e, void *param)
{
    GUI_UNUSED(e);
    GUI_UNUSED(param);
    gui_obj_t *this = (gui_obj_t *)obj;
    gui_log("Event test obj name = %s, e = 0x%x !\n", this->name, e);
}

void test_timer_cb(void *param)
{
    GUI_UNUSED(param);
    gui_log("timer cb test!\n");
}

#include "gifdec.h"
static int app_init(void)
{

    void *addr = (void *)_actiger_blue_compressed;
    // void *addr = (void *)_acgreen;
    // void *addr = (void *)_acgif_demo;

    gui_img_t *img = gui_img_create_from_mem(gui_obj_get_root(),  "img_1_test", addr, 0, 0, 0, 0);

    gui_img_set_focus(img, 50, 50);

    gui_img_rotation(img, 45.0f);

    gui_img_translate(img, 50, 50);

    // gui_obj_add_event_cb(img, (gui_event_cb_t)test_event_cb, GUI_EVENT_TOUCH_CLICKED, NULL);


    // gui_obj_create_timer(&(img->base), 1000, true, test_timer_cb);
    // gui_obj_start_timer(&(img->base));

    return 0;
}

GUI_INIT_APP_EXPORT(app_init);


API

Functions

uint16_t gui_img_get_width(gui_img_t *_this)

Load the image to read its width.

Parameters:

this – The image widget pointer.

Returns:

uint16_t Image’s width.

uint16_t gui_img_get_height(gui_img_t *_this)

Load the image to read its height.

Parameters:

this – The image widget pointer.

Returns:

uint16_t Image’s height.

void gui_img_refresh_size(gui_img_t *_this)

Refresh the image size from source.

Parameters:

this – The image widget pointer.

void gui_img_refresh_draw_data(gui_img_t *_this)
void gui_img_set_mode(gui_img_t *_this, BLEND_MODE_TYPE mode)

Set the image’s blend mode.

Parameters:
  • this – The image widget pointer.

  • mode – The enumeration value of the mode (BLEND_MODE_TYPE).

void gui_img_set_attribute(gui_img_t *_this, const char *name, void *addr, int16_t x, int16_t y)

Set image attributes (name, path, position).

Parameters:
  • this – Image widget pointer.

  • name – Widget name.

  • addr – Image address/path.

  • x – X-axis coordinate.

  • y – Y-axis coordinate.

void gui_img_rotation(gui_img_t *_this, float degrees)

Rotate the image around its center.

Parameters:
  • this – The image widget pointer.

  • degrees – Clockwise rotation absolute angle.

void gui_img_scale(gui_img_t *_this, float scale_x, float scale_y)

Scale the image, taking (0,0) as the zoom center.

Parameters:
  • this – The image widget pointer.

  • scale_x – Scale factor in X direction.

  • scale_y – Scale factor in Y direction.

void gui_img_translate(gui_img_t *_this, float t_x, float t_y)

Translate (move) the image.

Parameters:
  • this – The image widget pointer.

  • t_x – New X-axis coordinate.

  • t_y – New Y-axis coordinate.

void gui_img_skew_x(gui_img_t *_this, float degrees)

Skew the image on X-axis.

Parameters:
  • this – The image widget pointer.

  • degrees – Skew angle.

void gui_img_skew_y(gui_img_t *_this, float degrees)

Skew the image on Y-axis.

Parameters:
  • this – The image widget pointer.

  • degrees – Skew angle.

void gui_img_set_opacity(gui_img_t *_this, unsigned char opacity_value)

Set the opacity of the image.

Parameters:
  • this – The image widget pointer.

  • opacity_value – Opacity value (0-255, default 255).

void gui_img_set_focus(gui_img_t *_this, float c_x, float c_y)

Set the focus point for image transformations.

Parameters:
  • this – The image widget pointer.

  • c_x – Center X coordinate.

  • c_y – Center Y coordinate.

gui_img_t *gui_img_create_from_mem(void *parent, const char *name, void *addr, int16_t x, int16_t y, int16_t w, int16_t h)

Create an image widget from memory address.

Note

Create an image widget and set attribute.

Parameters:
  • parent – The father widget it nested in.

  • name – Widget name.

  • addr – The bin file address.

  • x – The X-axis coordinate of the widget.

  • y – The Y-axis coordinate of the widget.

  • w – The width of the widget.

  • h – The height of the widget.

Returns:

The widget object pointer.

gui_img_t *gui_img_create_from_ftl(void *parent, const char *name, void *ftl, int16_t x, int16_t y, int16_t w, int16_t h)

Create an image widget from memory address.

Note

Create an image widget and set attribute.

Parameters:
  • parent – The father widget it nested in.

  • name – Widget name.

  • ftl – Not xip address, use ftl address.

  • x – The X-axis coordinate of the widget.

  • y – The Y-axis coordinate of the widget.

  • w – The width of the widget.

  • h – The height of the widget.

Returns:

Return the widget object pointer.

gui_img_t *gui_img_create_from_fs(void *parent, const char *name, void *file, int16_t x, int16_t y, int16_t w, int16_t h)

Create an image widget from filesystem.

Parameters:
  • parent – The father widget it nested in.

  • name – Image widget name.

  • file – Image file path.

  • x – The X-axis coordinate of the widget.

  • y – The Y-axis coordinate of the widget.

  • w – The width of the widget.

  • h – The height of the widget.

Returns:

gui_img_t*.

void gui_img_set_quality(gui_img_t *_this, bool high_quality)

Set the image’s quality.

Parameters:
  • this – The image widget pointer.

  • high_quality – True for high quality rendering, false otherwise.

void gui_img_tree_convert_to_img(gui_obj_t *obj, gui_matrix_t *matrix, uint8_t *shot_buf)

Convert a tree to an image data.

Parameters:
  • obj – Tree root.

  • matrix – Null if no need to transform.

  • shot_buf – Buffer for the screenshot.

float gui_img_get_scale_x(gui_img_t *_this)

Get the scale factor in X direction.

Parameters:

this – The image widget pointer.

Returns:

Scale factor in X direction.

float gui_img_get_scale_y(gui_img_t *_this)

Get the scale factor in Y direction.

Parameters:

this – The image widget pointer.

Returns:

Scale factor in Y direction.

float gui_img_get_degrees(gui_img_t *_this)

Get the rotation angle in degrees.

Parameters:

this – The image widget pointer.

Returns:

Rotation angle in degrees.

float gui_img_get_c_x(gui_img_t *_this)

Get the center X coordinate for transformations.

Parameters:

this – The image widget pointer.

Returns:

Center X coordinate.

float gui_img_get_c_y(gui_img_t *_this)

Get the center Y coordinate for transformations.

Parameters:

this – The image widget pointer.

Returns:

Center Y coordinate.

float gui_img_get_t_x(gui_img_t *_this)

Get the translation in X direction.

Parameters:

this – The image widget pointer.

Returns:

Translation in X direction.

float gui_img_get_t_y(gui_img_t *_this)

Get the translation in Y direction.

Parameters:

this – The image widget pointer.

Returns:

Translation in Y direction.

void gui_img_set_image_data(gui_img_t *_this, const uint8_t *image_data_pointer)

Sets the image data for a specified image widget.

This function assigns the given image data to the specified image widget. The image data might correspond to various formats, and the format should be compatible with the handling of gui_img_t.

Parameters:
  • widget – The pointer to the image widget (gui_img_t) for which the image data is to be set.

  • image_data_pointer – The pointer to the image data to be set to the widget. The data should persist as long as the widget needs it or until it is explicitly updated.

const uint8_t *gui_img_get_image_data(gui_img_t *_this)

Gets the image data from a specified image widget.

This function returns the current image data that is set in the specified image widget.

Parameters:

widget – The pointer to the image widget (gui_img_t) from which the image data should be retrieved.

Returns:

A pointer to the image data currently set in the widget. If no image data is set, the result may be NULL.

struct gui_img_t

Image widget structure.

Public Members

gui_obj_t base
draw_img_t *draw_img
float degrees
float scale_x
float scale_y
float f_x
float f_y
float t_x
float t_y
void *data
void *filename
void *ftl
union gui_img_t
gd_GIF *gif
uint32_t opacity_value
uint32_t blend_mode
uint32_t storage_type
uint32_t high_quality
uint32_t need_clip
uint32_t gif_flag
uint8_t checksum
uint8_t animate_array_length