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