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,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