mirror of
https://github.com/espressif/esp-idf.git
synced 2026-08-18 06:35:35 +03:00
feat(jpeg_encoder): Add the basic support for jpeg encoder
This commit is contained in:
@@ -126,7 +126,7 @@ esp_err_t jpeg_del_decoder_engine(jpeg_decoder_handle_t decoder_engine);
|
||||
* @param[out] allocated_size Actual allocated buffer size.
|
||||
* @return Pointer to the allocated memory space, or NULL if allocation fails.
|
||||
*/
|
||||
void *jpeg_alloc_decoder_mem(size_t size, jpeg_decode_memory_alloc_cfg_t *mem_cfg, size_t *allocated_size);
|
||||
void *jpeg_alloc_decoder_mem(size_t size, const jpeg_decode_memory_alloc_cfg_t *mem_cfg, size_t *allocated_size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
103
components/esp_driver_jpeg/include/driver/jpeg_encode.h
Normal file
103
components/esp_driver_jpeg/include/driver/jpeg_encode.h
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include "esp_err.h"
|
||||
#include "jpeg_types.h"
|
||||
#include "hal/jpeg_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief JPEG encoder configure structure
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t height; /*!< Number of pixels in the horizontal direction */
|
||||
uint32_t width; /*!< Number of pixels in the vertical direction */
|
||||
jpeg_enc_input_format_t src_type; /*!< Source type of raw image to be encoded, see `jpeg_enc_src_type_t` */
|
||||
jpeg_down_sampling_type_t sub_sample; /*!< JPEG subsampling method */
|
||||
uint32_t image_quality; /*!< JPEG compressing quality, value from 1-100 */
|
||||
} jpeg_encode_cfg_t;
|
||||
|
||||
/**
|
||||
* @brief Configuration parameters for the JPEG encode engine.
|
||||
*/
|
||||
typedef struct {
|
||||
int intr_priority; /*!< JPEG interrupt priority, if set to 0, driver will select the default priority (1,2,3). */
|
||||
int timeout_ms; /*!< JPEG timeout threshold for handling a picture, should larger than valid decode time in ms. For example, for 30fps decode, this value must larger than 34. -1 means wait forever */
|
||||
} jpeg_encode_engine_cfg_t;
|
||||
|
||||
/**
|
||||
* @brief JPEG encoder memory allocation config
|
||||
*/
|
||||
typedef struct {
|
||||
jpeg_enc_buffer_alloc_direction_t buffer_direction; /*!< Buffer direction for jpeg decoder memory allocation */
|
||||
} jpeg_encode_memory_alloc_cfg_t;
|
||||
|
||||
/**
|
||||
* @brief Allocate JPEG encoder
|
||||
*
|
||||
* @param[in] enc_eng_cfg config for jpeg encoder
|
||||
* @param[out] ret_encoder handle for jpeg encoder
|
||||
* @return
|
||||
* - ESP_OK: JPEG encoder initialized successfully.
|
||||
* - ESP_ERR_INVALID_ARG: JPEG encoder initialization failed because of invalid argument.
|
||||
* - ESP_ERR_NO_MEM: Create JPEG encoder failed because of out of memory.
|
||||
*/
|
||||
esp_err_t jpeg_new_encoder_engine(const jpeg_encode_engine_cfg_t *enc_eng_cfg, jpeg_encoder_handle_t *ret_encoder);
|
||||
|
||||
/**
|
||||
* @brief Process encoding of JPEG data using the specified encoder engine.
|
||||
*
|
||||
* This function processes the encoding of JPEG data using the provided encoder engine
|
||||
* and configuration. It takes an input buffer containing the raw image data, performs
|
||||
* encoding based on the configuration settings, and outputs the compressed bitstream.
|
||||
*
|
||||
* @param[in] encoder_engine Handle to the JPEG encoder engine to be used for encoding.
|
||||
* @param[in] encode_cfg Pointer to the configuration structure for the JPEG encoding process.
|
||||
* @param[in] encode_inbuf Pointer to the input buffer containing the raw image data.
|
||||
* @param[in] inbuf_size Size of the input buffer in bytes.
|
||||
* @param[in] encode_outbuf Pointer to the output buffer where the compressed bitstream will be stored.
|
||||
* @param[in] outbuf_size The size of output buffer.
|
||||
* @param[out] out_size Pointer to a variable where the size of the output bitstream will be stored.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: JPEG encoder process successfully.
|
||||
* - ESP_ERR_INVALID_ARG: JPEG encoder process failed because of invalid argument.
|
||||
* - ESP_ERR_TIMEOUT: JPEG encoder process timeout.
|
||||
*/
|
||||
esp_err_t jpeg_encoder_process(jpeg_encoder_handle_t encoder_engine, const jpeg_encode_cfg_t *encode_cfg, const uint8_t *encode_inbuf, uint32_t inbuf_size, uint8_t *encode_outbuf, uint32_t outbuf_size, uint32_t *out_size);
|
||||
|
||||
/**
|
||||
* @brief Release resources used by a JPEG encoder instance.
|
||||
*
|
||||
* This function releases the resources used by the specified JPEG encoder instance. The encoder instance is
|
||||
* specified by the `encoder_engine` parameter.
|
||||
*
|
||||
* @param[in] encoder_engine Handle of the JPEG encoder instance to release resources for.
|
||||
* @return
|
||||
* - ESP_OK: Delete JPEG encoder successfully.
|
||||
* - ESP_ERR_INVALID_ARG: Delete JPEG encoder failed because of invalid argument.
|
||||
*/
|
||||
esp_err_t jpeg_del_encoder_engine(jpeg_encoder_handle_t encoder_engine);
|
||||
|
||||
/**
|
||||
* @brief A helper function to allocate memory space for JPEG encoder.
|
||||
*
|
||||
* @param[in] size The size of memory to allocate.
|
||||
* @param[in] mem_cfg Memory configuration for memory allocation
|
||||
* @param[out] allocated_size Actual allocated buffer size.
|
||||
* @return Pointer to the allocated memory space, or NULL if allocation fails.
|
||||
*/
|
||||
void *jpeg_alloc_encoder_mem(size_t size, const jpeg_encode_memory_alloc_cfg_t *mem_cfg, size_t *allocated_size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -46,11 +46,38 @@ typedef enum {
|
||||
JPEG_DEC_ALLOC_OUTPUT_BUFFER = 1, /*!< Alloc the picture output buffer, (decompressed format in decoder) */
|
||||
} jpeg_dec_buffer_alloc_direction_t;
|
||||
|
||||
/**
|
||||
* @brief Enumeration for jpeg input format.
|
||||
*/
|
||||
typedef enum {
|
||||
JPEG_ENCODE_IN_FORMAT_RGB888 = COLOR_TYPE_ID(COLOR_SPACE_RGB, COLOR_PIXEL_RGB888), /*!< input RGB888 format */
|
||||
JPEG_ENCODE_IN_FORMAT_RGB565 = COLOR_TYPE_ID(COLOR_SPACE_RGB, COLOR_PIXEL_RGB565), /*!< input RGB565 format */
|
||||
JPEG_ENCODE_IN_FORMAT_GRAY = COLOR_TYPE_ID(COLOR_SPACE_GRAY, COLOR_PIXEL_GRAY8), /*!< input GRAY format */
|
||||
} jpeg_enc_input_format_t;
|
||||
|
||||
/**
|
||||
* @brief Enumeration for jpeg encoder alloc buffer direction.
|
||||
*/
|
||||
typedef enum {
|
||||
JPEG_ENC_ALLOC_INPUT_BUFFER = 0, /*!< Alloc the picture input buffer, (decompressed format in encoder) */
|
||||
JPEG_ENC_ALLOC_OUTPUT_BUFFER = 1, /*!< Alloc the picture output buffer, (compressed format in encoder) */
|
||||
} jpeg_enc_buffer_alloc_direction_t;
|
||||
|
||||
/**
|
||||
* @brief Type of jpeg decoder handle
|
||||
*/
|
||||
typedef struct jpeg_decoder_t *jpeg_decoder_handle_t;
|
||||
|
||||
/**
|
||||
* @brief Type of jpeg codec handle
|
||||
*/
|
||||
typedef struct jpeg_codec_t *jpeg_codec_handle_t;
|
||||
|
||||
/**
|
||||
* @brief Type of jpeg encoder handle
|
||||
*/
|
||||
typedef struct jpeg_encoder_t *jpeg_encoder_handle_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user