add some code

This commit is contained in:
2025-09-05 13:25:11 +08:00
parent 9ff0a99e7a
commit 3cf1229a85
8911 changed files with 2535396 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "core/gfx_types.h"
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* DEFINES
*********************/
gfx_color_t gfx_blend_color_mix(gfx_color_t c1, gfx_color_t c2, uint8_t mix);
/**********************
* GLOBAL PROTOTYPES
**********************/
/*=====================
* Software blending functions
*====================*/
/**
* @brief Draw a blended color onto a destination buffer
* @param dest_buf Pointer to the destination buffer where the color will be drawn
* @param dest_stride Stride (width) of the destination buffer
* @param color The color to draw in gfx_color_t type
* @param opa The opacity of the color to draw (0-255)
* @param mask Pointer to the mask buffer, if any
* @param clip_area Pointer to the clipping area, which limits the area to draw
* @param mask_stride Stride (width) of the mask buffer
*/
void gfx_sw_blend_draw(gfx_color_t *dest_buf, gfx_coord_t dest_stride, gfx_color_t color, gfx_opa_t opa,
const gfx_opa_t *mask, gfx_area_t *clip_area, gfx_coord_t mask_stride, bool swap);
/**
* @brief Draw a blended image onto a destination buffer
* @param dest_buf Pointer to the destination buffer where the image will be drawn
* @param dest_stride Stride (width) of the destination buffer
* @param src_buf Pointer to the source image buffer
* @param src_stride Stride (width) of the source image buffer
* @param mask Pointer to the mask buffer, if any
* @param mask_stride Stride (width) of the mask buffer
* @param clip_area Pointer to the clipping area, which limits the area to draw
* @param opa The opacity of the image to draw (0-255)
* @param swap Whether to swap the color format
*/
void gfx_sw_blend_img_draw(gfx_color_t *dest_buf, gfx_coord_t dest_stride,
const gfx_color_t *src_buf, gfx_coord_t src_stride,
const gfx_opa_t *mask, gfx_coord_t mask_stride,
gfx_area_t *clip_area, gfx_opa_t opa, bool swap);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,131 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "freertos/event_groups.h"
#include "core/gfx_types.h"
#include "core/gfx_core.h"
#include "core/gfx_timer_internal.h"
#include "core/gfx_obj_internal.h"
#include "widget/gfx_font_internal.h"
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* DEFINES
*********************/
/* Event bits for synchronization */
#define NEED_DELETE BIT0
#define DELETE_DONE BIT1
#define WAIT_FLUSH_DONE BIT2
/* Animation timer constants */
#define ANIM_NO_TIMER_READY 0xFFFFFFFF
/**********************
* TYPEDEFS
**********************/
/* Core context structure */
typedef struct {
/* Display configuration */
struct {
uint32_t h_res; /**< Horizontal resolution */
uint32_t v_res; /**< Vertical resolution */
uint32_t fb_v_res; /**< Frame buffer vertical resolution */
struct {
unsigned char swap:1; /**< Color swap flag */
} flags; /**< Display flags */
} display; /**< Display configuration */
/* Callback functions */
struct {
gfx_player_flush_cb_t flush_cb; /**< Flush callback function */
gfx_player_update_cb_t update_cb; /**< Update callback function */
void *user_data; /**< User data pointer */
} callbacks; /**< Callback functions */
/* Timer management */
struct {
gfx_timer_manager_t timer_mgr; /**< Timer manager */
} timer; /**< Timer management */
/* Graphics rendering */
struct {
gfx_ft_lib_handle_t font_lib; /**< Font library handle */
gfx_core_child_t *child_list; /**< Child object list */
uint16_t *buf1; /**< Frame buffer 1 */
uint16_t *buf2; /**< Frame buffer 2 */
uint16_t *buf_act; /**< Active frame buffer */
size_t buf_pixels; /**< Buffer size in pixels */
gfx_color_t bg_color; /**< Default background color */
bool ext_bufs; /**< Whether using external buffers */
bool flushing_last; /**< Whether flushing the last block */
bool swap_act_buf; /**< Whether swap the active buffer */
} disp;
/* Synchronization primitives */
struct {
SemaphoreHandle_t lock_mutex; /**< Render mutex for thread safety */
EventGroupHandle_t event_group; /**< Event group for synchronization */
} sync; /**< Synchronization primitives */
} gfx_core_context_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/*=====================
* Internal core functions
*====================*/
/**
* @brief Add a child element to the graphics context
*
* @param handle Graphics handle
* @param type Type of the child element
* @param src Source data pointer
* @return esp_err_t ESP_OK on success, otherwise an error code
*/
esp_err_t gfx_emote_add_chlid(gfx_handle_t handle, int type, void *src);
/**
* @brief Remove a child element from the graphics context
*
* @param handle Graphics handle
* @param src Source data pointer to remove
* @return esp_err_t ESP_OK on success, otherwise an error code
*/
esp_err_t gfx_emote_remove_child(gfx_handle_t handle, void *src);
/**
* @brief Blend child objects to destination buffer
* @param ctx Graphics context
* @param x1 Left coordinate
* @param y1 Top coordinate
* @param x2 Right coordinate
* @param y2 Bottom coordinate
* @param dest_buf Destination buffer
*/
void gfx_draw_child(gfx_core_context_t *ctx, int x1, int y1, int x2, int y2, const void *dest_buf);
/**
* @brief Get the font library handle from graphics context
* @param handle Graphics handle
* @return gfx_ft_lib_handle_t Font library handle, NULL on error
*/
gfx_ft_lib_handle_t gfx_get_font_lib(gfx_handle_t handle);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,56 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdint.h>
#include "core/gfx_types.h"
#include "core/gfx_core.h"
#include "core/gfx_obj.h"
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* DEFINES
*********************/
// Default screen dimensions for alignment calculation
#define DEFAULT_SCREEN_WIDTH 320
#define DEFAULT_SCREEN_HEIGHT 240
/**********************
* TYPEDEFS
**********************/
typedef struct gfx_core_child_t {
int type;
void *src;
struct gfx_core_child_t *next; // Pointer to next child in the list
} gfx_core_child_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/*=====================
* Internal alignment functions
*====================*/
/**
* @brief Calculate aligned position for an object (internal use)
* @param obj Pointer to the object
* @param parent_width Parent container width in pixels
* @param parent_height Parent container height in pixels
* @param x Pointer to store calculated X coordinate
* @param y Pointer to store calculated Y coordinate
*/
void gfx_obj_calculate_aligned_position(gfx_obj_t *obj, uint32_t parent_width, uint32_t parent_height, gfx_coord_t *x, gfx_coord_t *y);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,87 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "core/gfx_types.h"
#include "core/gfx_timer.h"
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/* Timer handle type for external use */
typedef void* gfx_timer_handle_t;
/* Timer structure (internal use) */
typedef struct gfx_timer_s {
uint32_t period;
uint32_t last_run;
gfx_timer_cb_t timer_cb;
void *user_data;
int32_t repeat_count;
bool paused;
struct gfx_timer_s *next;
} gfx_timer_t;
/* Timer manager structure (internal use) */
typedef struct {
gfx_timer_t *timer_list;
uint32_t time_until_next;
uint32_t last_tick;
uint32_t fps; ///< Target FPS for timer scheduling
uint32_t actual_fps; ///< Actual measured FPS
/* FPS statistics */
uint32_t fps_last_report_tick; ///< Last time FPS was reported
uint32_t fps_report_interval_ms; ///< FPS report interval in milliseconds (default 500 ms)
} gfx_timer_manager_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/*=====================
* Internal timer functions
*====================*/
/**
* @brief Execute a timer
* @param timer Timer to execute
* @return true if timer was executed, false otherwise
*/
bool gfx_timer_exec(gfx_timer_t *timer);
/**
* @brief Handle timer manager operations
* @param timer_mgr Timer manager
* @return Time until next timer execution
*/
uint32_t gfx_timer_handler(gfx_timer_manager_t *timer_mgr);
/**
* @brief Initialize timer manager
* @param timer_mgr Timer manager to initialize
* @param fps Target FPS for timer scheduling
*/
void gfx_timer_manager_init(gfx_timer_manager_t *timer_mgr, uint32_t fps);
/**
* @brief Deinitialize timer manager
* @param timer_mgr Timer manager to deinitialize
*/
void gfx_timer_manager_deinit(gfx_timer_manager_t *timer_mgr);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,75 @@
/*
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdint.h>
#include "esp_err.h"
#include "core/gfx_types.h"
#include "decoder/gfx_aaf_format.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
GFX_AAF_FORMAT_SBMP = 0, // Split BMP format
GFX_AAF_FORMAT_REDIRECT = 1, // Redirect format
GFX_AAF_FORMAT_INVALID = 2
} gfx_aaf_format_t;
typedef enum {
GFX_AAF_ENCODING_RLE = 0,
GFX_AAF_ENCODING_HUFFMAN = 1,
GFX_AAF_ENCODING_JPEG = 2,
GFX_AAF_ENCODING_HUFFMAN_DIRECT = 3
} gfx_aaf_encoding_t;
// Image header structure
typedef struct {
char format[3]; // Format identifier (e.g., "_S")
char version[6]; // Version string
uint8_t bit_depth; // Bit depth (4 or 8)
uint16_t width; // Image width
uint16_t height; // Image height
uint16_t blocks; // Number of blocks
uint16_t block_height; // Height of each block
uint32_t *block_len; // Data length of each block (changed from uint16_t to uint32_t)
uint16_t data_offset; // Offset to data segment
uint8_t *palette; // Color palette (dynamically allocated)
int num_colors; // Number of colors in palette
} gfx_aaf_header_t;
// Huffman tree node structure
typedef struct Node {
uint8_t is_leaf;
uint8_t value;
struct Node* left;
struct Node* right;
} Node;
/**
* @brief Parse the header of an image file
* @param data Pointer to the image data
* @param data_len Length of the image data
* @param header Pointer to store the parsed header information
* @return Image format type (SBMP, REDIRECT, or INVALID)
*/
gfx_aaf_format_t gfx_aaf_parse_header(const uint8_t *data, size_t data_len, gfx_aaf_header_t *header);
gfx_color_t gfx_aaf_parse_palette(const gfx_aaf_header_t *header, uint8_t index, bool swap);
void gfx_aaf_calculate_offsets(const gfx_aaf_header_t *header, uint32_t *offsets);
void gfx_aaf_free_header(gfx_aaf_header_t *header);
esp_err_t gfx_aaf_huffman_decode(const uint8_t* buffer, size_t buflen, uint8_t* output, size_t* output_len);
esp_err_t gfx_aaf_rle_decode(const uint8_t *input, size_t input_len, uint8_t *output, size_t output_len);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,30 @@
/*
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdint.h>
#include "esp_err.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct gfx_aaf_format_ctx_t *gfx_aaf_format_handle_t;
esp_err_t gfx_aaf_format_init(const uint8_t *data, size_t data_len, gfx_aaf_format_handle_t *ret_parser);
esp_err_t gfx_aaf_format_deinit(gfx_aaf_format_handle_t handle);
int gfx_aaf_format_get_total_frames(gfx_aaf_format_handle_t handle);
int gfx_aaf_format_get_frame_size(gfx_aaf_format_handle_t handle, int index);
const uint8_t *gfx_aaf_format_get_frame_data(gfx_aaf_format_handle_t handle, int index);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,132 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdint.h>
#include "esp_err.h"
#include "widget/gfx_img.h"
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* DEFINES
*********************/
/**
* @brief Image format types
*/
typedef enum {
GFX_IMAGE_FORMAT_UNKNOWN = 0, /**< Unknown format */
GFX_IMAGE_FORMAT_C_ARRAY = 1, /**< C array format */
GFX_IMAGE_FORMAT_AAF = 3, /**< AAF animation format */
} gfx_image_format_t;
/* Image decoder descriptor - for internal use */
typedef struct {
const void * src; /**< Image source: file name or variable */
gfx_image_header_t header; /**< Image header information */
const uint8_t * data; /**< Decoded image data */
uint32_t data_size; /**< Size of decoded data */
void * user_data; /**< User data for decoder */
} gfx_image_decoder_dsc_t;
/* Forward declaration for image decoder structure */
typedef struct gfx_image_decoder_t gfx_image_decoder_t;
/* Image decoder structure - for internal use */
struct gfx_image_decoder_t {
const char * name; /**< Decoder name */
/**
* Get image information from source
* @param decoder pointer to the decoder
* @param dsc pointer to decoder descriptor
* @param header store the info here
* @return ESP_OK: no error; ESP_ERR_INVALID: can't get the info
*/
esp_err_t (*info_cb)(gfx_image_decoder_t * decoder, gfx_image_decoder_dsc_t * dsc, gfx_image_header_t * header);
/**
* Open and decode image
* @param decoder pointer to the decoder
* @param dsc pointer to decoder descriptor
* @return ESP_OK: no error; ESP_ERR_INVALID: can't open the image
*/
esp_err_t (*open_cb)(gfx_image_decoder_t * decoder, gfx_image_decoder_dsc_t * dsc);
/**
* Close image and free resources
* @param decoder pointer to the decoder
* @param dsc pointer to decoder descriptor
*/
void (*close_cb)(gfx_image_decoder_t * decoder, gfx_image_decoder_dsc_t * dsc);
};
/**********************
* GLOBAL PROTOTYPES
**********************/
/*=====================
* Image format detection (internal)
*====================*/
/**
* @brief Detect image format from source data (internal)
* @param src Source data pointer
* @return Format type: GFX_IMAGE_FORMAT_UNKNOWN, GFX_IMAGE_FORMAT_C_ARRAY, or GFX_IMAGE_FORMAT_AAF
*/
gfx_image_format_t gfx_image_detect_format(const void *src);
/*=====================
* Image decoder functions (internal)
*====================*/
/**
* @brief Register an image decoder (internal)
* @param decoder Pointer to decoder structure
* @return ESP_OK on success, otherwise error code
*/
esp_err_t gfx_image_decoder_register(gfx_image_decoder_t *decoder);
/**
* @brief Get image information using registered decoders (internal)
* @param dsc Decoder descriptor
* @param header Output header structure
* @return ESP_OK on success, otherwise error code
*/
esp_err_t gfx_image_decoder_info(gfx_image_decoder_dsc_t *dsc, gfx_image_header_t *header);
/**
* @brief Open and decode image using registered decoders (internal)
* @param dsc Decoder descriptor
* @return ESP_OK on success, otherwise error code
*/
esp_err_t gfx_image_decoder_open(gfx_image_decoder_dsc_t *dsc);
/**
* @brief Close image decoder and free resources (internal)
* @param dsc Decoder descriptor
*/
void gfx_image_decoder_close(gfx_image_decoder_dsc_t *dsc);
/**
* @brief Initialize image decoder system (internal)
* @return ESP_OK on success, otherwise error code
*/
esp_err_t gfx_image_decoder_init(void);
/**
* @brief Deinitialize image decoder system (internal)
* @return ESP_OK on success, otherwise error code
*/
esp_err_t gfx_image_decoder_deinit(void);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,31 @@
/*
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "esp_err.h"
#include "esp_jpeg_dec.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Decode JPEG data to specified output buffer
* @param in Input JPEG data
* @param insize Input data length
* @param out Output buffer pointer
* @param out_size Output buffer size
* @param w Output image width
* @param h Output image height
* @param swap Whether to swap byte order (true: RGB565LE, false: RGB565BE)
* @return ESP_OK on success, ESP_FAIL on failure
*/
esp_err_t gfx_jpeg_decode(const uint8_t *in, uint32_t insize, uint8_t *out, size_t out_size, uint32_t *w, uint32_t *h, bool swap);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,99 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "core/gfx_types.h"
#include "core/gfx_obj.h"
#include "core/gfx_timer.h"
#include "widget/gfx_anim.h"
#include "decoder/gfx_aaf_dec.h"
#include "decoder/gfx_aaf_format.h"
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/* Frame processing information structure */
typedef struct {
/*!< Pre-parsed header information to avoid repeated parsing */
gfx_aaf_header_t header; /*!< Pre-parsed header for current frame */
/*!< Pre-fetched frame data to avoid repeated fetching */
const void *frame_data; /*!< Pre-fetched frame data for current frame */
size_t frame_size; /*!< Size of pre-fetched frame data */
/*!< Pre-allocated parsing resources to avoid repeated allocation */
uint32_t *block_offsets; /*!< Pre-allocated block offsets array */
uint8_t *pixel_buffer; /*!< Pre-allocated pixel decode buffer */
uint32_t *color_palette; /*!< Pre-allocated color palette cache */
/*!< Decoding state tracking */
int last_block; /*!< Last decoded block index to avoid repeated decoding */
} gfx_anim_frame_info_t;
typedef struct {
uint32_t start_frame; /*!< Start frame index */
uint32_t end_frame; /*!< End frame index */
uint32_t current_frame; /*!< Current frame index */
uint32_t fps; /*!< Frames per second */
bool is_playing; /*!< Whether animation is currently playing */
bool repeat; /*!< Whether animation should repeat */
gfx_timer_handle_t timer; /*!< Timer handle for frame updates */
/*!< Frame processing information */
gfx_aaf_format_handle_t file_desc; /*!< Animation file descriptor */
gfx_anim_frame_info_t frame; /*!< Frame processing info */
/*!< Widget-specific display properties */
bool mirror_enabled; /*!< Whether mirror display is enabled */
int16_t mirror_offset; /*!< Mirror buffer offset for positioning */
} gfx_anim_property_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/*=====================
* Internal drawing functions
*====================*/
/**
* @brief Free frame processing information and allocated resources
* @param frame Frame processing information structure
*/
void gfx_anim_free_frame_info(gfx_anim_frame_info_t *frame);
/**
* @brief Preprocess animation frame data and allocate parsing resources
* @param anim Animation property structure
* @return true if preprocessing was successful, false otherwise
*/
bool gfx_anim_preprocess_frame(gfx_anim_property_t *anim);
/**
* @brief Draw an animation object
* @param obj Animation object
* @param x1 Left coordinate
* @param y1 Top coordinate
* @param x2 Right coordinate
* @param y2 Bottom coordinate
* @param dest_buf Destination buffer
* @param swap_color Whether to swap color format
*/
void gfx_draw_animation(gfx_obj_t *obj, int x1, int y1, int x2, int y2, const void *dest_buf, bool swap_color);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,24 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
// Common macro definitions for renderer modules
#ifndef MAX
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#endif
#ifndef MIN
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#endif
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,71 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "esp_err.h"
#include "core/gfx_types.h"
#include "core/gfx_core.h"
#include "core/gfx_obj.h"
#include "widget/gfx_label.h"
#include "ft2build.h"
#include FT_FREETYPE_H
#ifdef __cplusplus
extern "C" {
#endif
// Forward declarations
typedef void *gfx_ft_handle_t;
typedef void *gfx_ft_lib_handle_t;
typedef struct face_entry {
void *face;
const void *mem;
struct face_entry *next;
} gfx_ft_face_entry_t;
typedef struct {
gfx_ft_face_entry_t *ft_face_head;
void *ft_library;
} gfx_ft_lib_t;
/* Default font configuration */
typedef struct {
const char *name; /*!< Font name */
const void *mem; /*!< Font data pointer */
size_t mem_size; /*!< Font data size */
uint16_t default_size; /*!< Default font size */
gfx_color_t bg_color; /*!< Default font color */
gfx_opa_t default_opa; /*!< Default opacity */
} gfx_default_font_cfg_t;
// Internal function declarations
esp_err_t gfx_ft_lib_create(gfx_ft_lib_handle_t *ret_lib);
esp_err_t gfx_ft_lib_cleanup(gfx_ft_lib_handle_t lib_handle);
esp_err_t gfx_get_glphy_dsc(gfx_obj_t * obj);
/**
* @brief Get default font handle (internal use)
* @param handle Animation player handle
* @param ret_font Pointer to store the default font handle
* @return ESP_OK on success, error code otherwise
*/
esp_err_t gfx_get_default_font(gfx_handle_t handle, gfx_font_t *ret_font);
/**
* @brief Get default font configuration (internal use)
* @param font Pointer to store default font handle
* @param size Pointer to store default font size
* @param color Pointer to store default font color
* @param opa Pointer to store default font opacity
*/
void gfx_get_default_font_config(gfx_font_t *font, uint16_t *size, gfx_color_t *color, gfx_opa_t *opa);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,155 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include "esp_err.h"
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* DEFINES
*********************/
#define GFX_FONT_SUBPX_NONE 0
/**********************
* TYPEDEFS
**********************/
/**
* Font type enumeration
*/
typedef enum {
GFX_FONT_TYPE_FREETYPE, /**< FreeType font (TTF/OTF) */
GFX_FONT_TYPE_LVGL_C, /**< LVGL C format font */
} gfx_font_type_t;
/**
* LVGL character mapping types (from LVGL)
*/
typedef enum {
GFX_FONT_FMT_TXT_CMAP_FORMAT0_TINY,
GFX_FONT_FMT_TXT_CMAP_FORMAT0_FULL,
GFX_FONT_FMT_TXT_CMAP_SPARSE_TINY,
GFX_FONT_FMT_TXT_CMAP_SPARSE_FULL,
} gfx_font_fmt_txt_cmap_type_t;
/**
* LVGL glyph description structure (mirrors lv_font_fmt_txt_glyph_dsc_t)
*/
typedef struct {
uint32_t bitmap_index; /**< Start index in the bitmap array */
uint32_t adv_w; /**< Advance width */
uint16_t box_w; /**< Width of the glyph's bounding box */
uint16_t box_h; /**< Height of the glyph's bounding box */
int16_t ofs_x; /**< X offset of the bounding box */
int16_t ofs_y; /**< Y offset of the bounding box */
} gfx_font_glyph_dsc_t;
/**
* LVGL character mapping structure (mirrors lv_font_fmt_txt_cmap_t)
*/
typedef struct {
uint32_t range_start; /**< First character code in this range */
uint32_t range_length; /**< Number of characters in this range */
uint32_t glyph_id_start; /**< First glyph ID for this range */
const uint32_t *unicode_list; /**< List of unicode values (if sparse) */
const void *glyph_id_ofs_list; /**< List of glyph ID offsets (if sparse) */
uint32_t list_length; /**< Length of unicode_list and glyph_id_ofs_list */
gfx_font_fmt_txt_cmap_type_t type; /**< Type of this character map */
} gfx_font_cmap_t;
/**
* LVGL font descriptor structure (mirrors lv_font_fmt_txt_dsc_t)
*/
typedef struct {
const uint8_t *glyph_bitmap; /**< Bitmap data of all glyphs */
const gfx_font_glyph_dsc_t *glyph_dsc; /**< Array of glyph descriptions */
const gfx_font_cmap_t *cmaps; /**< Array of character maps */
const void *kern_dsc; /**< Kerning data (not used yet) */
uint16_t kern_scale; /**< Kerning scaling */
uint16_t cmap_num; /**< Number of character maps */
uint16_t bpp; /**< Bits per pixel */
uint16_t kern_classes; /**< Number of kerning classes */
uint16_t bitmap_format; /**< Bitmap format */
} gfx_font_fmt_txt_dsc_t;
/**
* LVGL font structure (mirrors lv_font_t)
*/
typedef struct {
const void *get_glyph_dsc; /**< Function pointer to get glyph's data */
const void *get_glyph_bitmap; /**< Function pointer to get glyph's bitmap */
uint16_t line_height; /**< The maximum line height required by the font */
uint16_t base_line; /**< Baseline measured from the bottom of the line */
uint8_t subpx; /**< Subpixel configuration */
int8_t underline_position; /**< Underline position */
uint8_t underline_thickness; /**< Underline thickness */
const gfx_font_fmt_txt_dsc_t *dsc; /**< The custom font data */
bool static_bitmap; /**< Static bitmap flag */
const void *fallback; /**< Fallback font */
const void *user_data; /**< User data */
} gfx_lvgl_font_t;
/**
* Unified font handle structure
*/
typedef struct {
gfx_font_type_t type; /**< Font type */
union {
void *freetype_face; /**< FreeType face handle */
const gfx_lvgl_font_t *lvgl_font; /**< LVGL font structure */
} font;
const char *name; /**< Font name */
} gfx_font_handle_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* @brief Parse LVGL C format font data
* @param font_data Pointer to the font structure (e.g., &font_16)
* @param font_name Name for the font
* @param ret_handle Pointer to store the created font handle
* @return ESP_OK on success, error code otherwise
*/
esp_err_t gfx_parse_lvgl_font(const gfx_lvgl_font_t *font_data, const char *font_name, gfx_font_handle_t **ret_handle);
/**
* @brief Get glyph information from LVGL font
* @param font LVGL font structure
* @param unicode Unicode character
* @param glyph_dsc Output glyph descriptor
* @return true if glyph found, false otherwise
*/
bool gfx_lvgl_font_get_glyph_dsc(const gfx_lvgl_font_t *font, uint32_t unicode, gfx_font_glyph_dsc_t *glyph_dsc);
/**
* @brief Get glyph bitmap from LVGL font
* @param font LVGL font structure
* @param glyph_dsc Glyph descriptor
* @return Pointer to glyph bitmap data
*/
const uint8_t *gfx_lvgl_font_get_glyph_bitmap(const gfx_lvgl_font_t *font, const gfx_font_glyph_dsc_t *glyph_dsc);
/**
* @brief Convert external LVGL font (like your font_16) to internal format
* @param external_font Pointer to external font structure
* @param font_name Name for the font
* @param ret_handle Pointer to store the created font handle
* @return ESP_OK on success, error code otherwise
*/
esp_err_t gfx_convert_external_lvgl_font(const void *external_font, const char *font_name, gfx_font_handle_t **ret_handle);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,40 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "core/gfx_types.h"
#include "core/gfx_obj.h"
#include "widget/gfx_img.h"
#include "decoder/gfx_img_decoder.h"
#ifdef __cplusplus
extern "C" {
#endif
/**********************
* GLOBAL PROTOTYPES
**********************/
/*=====================
* Internal drawing functions
*====================*/
/**
* @brief Draw an image object (internal)
* @param obj Image object
* @param x1 Left coordinate
* @param y1 Top coordinate
* @param x2 Right coordinate
* @param y2 Bottom coordinate
* @param dest_buf Destination buffer
* @param swap Whether to swap byte order
*/
void gfx_draw_img(gfx_obj_t *obj, int x1, int y1, int x2, int y2, const void *dest_buf, bool swap);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,94 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "core/gfx_types.h"
#include "core/gfx_obj.h"
#include "core/gfx_timer.h"
#include "widget/gfx_label.h"
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/* Label property structure */
typedef struct {
void *face; /**< Font face handle */
char *text; /**< Text string */
uint8_t font_size; /**< Font size */
gfx_color_t color; /**< Text color */
gfx_opa_t opa; /**< Text opacity */
gfx_color_t bg_color; /**< Background color */
bool bg_enable; /**< Enable background */
bool bg_dirty; /**< Background needs redraw (but not text reparse) */
gfx_opa_t *mask; /**< Text mask buffer */
gfx_text_align_t text_align; /**< Text alignment */
gfx_label_long_mode_t long_mode; /**< Long text handling mode */
uint16_t line_spacing; /**< Spacing between lines in pixels */
/* Cached line data for scroll optimization */
char **cached_lines; /**< Cached parsed lines */
int cached_line_count; /**< Number of cached lines */
int *cached_line_widths; /**< Cached width of each line for alignment */
/* Horizontal scroll properties (only used when long_mode is SCROLL) */
int32_t scroll_offset; /**< Current horizontal scroll offset */
uint32_t scroll_speed_ms; /**< Scrolling speed in milliseconds per pixel */
bool scroll_loop; /**< Enable continuous looping */
bool scroll_active; /**< Is scrolling currently active */
bool scroll_dirty; /**< Scroll position changed (needs redraw but not reparse) */
void *scroll_timer; /**< Timer handle for scrolling animation */
int32_t text_width; /**< Actual text width for scroll calculation */
} gfx_label_property_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/*=====================
* Internal drawing functions
*====================*/
/**
* @brief Draw a label object
* @param obj Label object
* @param x1 Left coordinate
* @param y1 Top coordinate
* @param x2 Right coordinate
* @param y2 Bottom coordinate
* @param dest_buf Destination buffer
* @param swap Whether to swap the color format
*/
esp_err_t gfx_draw_label(gfx_obj_t *obj, int x1, int y1, int x2, int y2, const void *dest_buf, bool swap);
/**
* @brief Get glyph descriptor for label rendering
* @param obj Label object
* @return ESP_OK on success, error code otherwise
*/
esp_err_t gfx_get_glphy_dsc(gfx_obj_t * obj);
/**
* @brief Get default font configuration
* @param font Font handle pointer
* @param size Font size pointer
* @param color Font color pointer
* @param opa Font opacity pointer
*/
void gfx_get_default_font_config(gfx_font_t *font, uint16_t *size, gfx_color_t *color, gfx_opa_t *opa);
#ifdef __cplusplus
}
#endif