mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-01 18:50:34 +03:00
refactor(jpeg): Split hal layer for jpeg
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
idf_build_get_property(target IDF_TARGET)
|
||||
if(${target} STREQUAL "linux")
|
||||
return() # This component is not supported by the POSIX/Linux simulator
|
||||
endif()
|
||||
|
||||
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/${target}/include")
|
||||
list(APPEND includes "${target}/include")
|
||||
endif()
|
||||
list(APPEND includes "include")
|
||||
|
||||
set(srcs)
|
||||
|
||||
# JPEG related source files
|
||||
if(CONFIG_SOC_JPEG_CODEC_SUPPORTED)
|
||||
list(APPEND srcs "jpeg_hal.c")
|
||||
endif()
|
||||
|
||||
idf_component_register(SRCS ${srcs}
|
||||
INCLUDE_DIRS ${includes}
|
||||
REQUIRES soc hal)
|
||||
@@ -0,0 +1,9 @@
|
||||
# `esp_hal_jpeg`
|
||||
|
||||
⚠️ This HAL component is still under heavy development at the moment, so we don't guarantee the stability and backward-compatibility among versions.
|
||||
|
||||
The `esp_hal_jpeg` component provides a **Hardware Abstraction Layer** of JPEG for all targets supported by ESP-IDF.
|
||||
|
||||
In a broad sense, the HAL layer consists of two sub-layers: HAL (upper) and Low-Level(bottom). The HAL layer defines the steps and data that is required to operate a peripheral (e.g. initialization, parameter settings). The low-level is a translation layer above the register files under the `soc` component, it only covers general conceptions to register configurations.
|
||||
|
||||
The functions in this file mainly provide hardware abstraction for IDF peripheral drivers. For advanced developers, the HAL layer functions can also be directly used to assist in implementing their own drivers. However, it needs to be mentioned again that the interfaces here do not guarantee stability.
|
||||
@@ -0,0 +1,682 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "hal/misc.h"
|
||||
#include "hal/assert.h"
|
||||
#include "soc/jpeg_struct.h"
|
||||
#include "hal/jpeg_types.h"
|
||||
#include "soc/hp_sys_clkrst_struct.h"
|
||||
#include "hal/config.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define JPEG_LL_GET_HW(num) (&JPEG)
|
||||
|
||||
typedef enum {
|
||||
JPEG_LL_DONE = (1 << 0),
|
||||
JPEG_LL_DCT_DONE = (1 << 11),
|
||||
} jpeg_ll_codec_intr_t;
|
||||
|
||||
typedef enum {
|
||||
JPEG_LL_INTR_CID_ERR = (1 << 2),
|
||||
JPEG_LL_INTR_C_DHT_DC_ID = (1 << 3),
|
||||
JPEG_LL_INTR_C_DHT_AC_ID = (1 << 4),
|
||||
JPEG_LL_INTR_C_DQT_ID = (1 << 5),
|
||||
JPEG_LL_INTR_RST_UXP_ERR = (1 << 6),
|
||||
JPEG_LL_INTR_RST_CHECK_NON_ERR = (1 << 7),
|
||||
JPEG_LL_INTR_RST_CHECK_POS_ERR = (1 << 8),
|
||||
JPEG_LL_INTR_OUT_EOF = (1 << 9),
|
||||
JPEG_LL_INTR_SCAN_CHECK_NONE = (1 << 13),
|
||||
JPEG_LL_INTR_SCAN_POS_ERR = (1 << 14),
|
||||
JPEG_LL_INTR_UXP_DET = (1 << 15),
|
||||
JPEG_LL_INTR_DE_FRAME_EOF_ERR = (1 << 18),
|
||||
JPEG_LL_INTR_DE_FRAME_EOF_LACK = (1 << 19),
|
||||
JPEG_LL_INTR_SOS_UNMATCH_ERR = (1 << 20),
|
||||
JPEG_LL_INTR_MARKER_ERR_FST = (1 << 21),
|
||||
JPEG_LL_INTR_MARKER_ERR_OTHER = (1 << 22),
|
||||
JPEG_LL_INTR_UNDETECT = (1 << 23),
|
||||
JPEG_LL_INTR_DECODE_TIMEOUT = (1 << 24),
|
||||
} jpeg_ll_decoder_intr_t;
|
||||
|
||||
#define JPEG_LL_DECODER_EVENT_INTR (JPEG_LL_INTR_CID_ERR | \
|
||||
JPEG_LL_INTR_C_DHT_DC_ID | \
|
||||
JPEG_LL_INTR_C_DHT_AC_ID | \
|
||||
JPEG_LL_INTR_C_DQT_ID | \
|
||||
JPEG_LL_INTR_RST_UXP_ERR | \
|
||||
JPEG_LL_INTR_RST_CHECK_NON_ERR | \
|
||||
JPEG_LL_INTR_RST_CHECK_POS_ERR | \
|
||||
JPEG_LL_INTR_OUT_EOF | \
|
||||
JPEG_LL_INTR_SCAN_CHECK_NONE | \
|
||||
JPEG_LL_INTR_SCAN_POS_ERR | \
|
||||
JPEG_LL_INTR_UXP_DET | \
|
||||
JPEG_LL_INTR_DE_FRAME_EOF_ERR | \
|
||||
JPEG_LL_INTR_DE_FRAME_EOF_LACK | \
|
||||
JPEG_LL_INTR_SOS_UNMATCH_ERR | \
|
||||
JPEG_LL_INTR_MARKER_ERR_FST | \
|
||||
JPEG_LL_INTR_MARKER_ERR_OTHER | \
|
||||
JPEG_LL_INTR_UNDETECT | \
|
||||
JPEG_LL_INTR_DECODE_TIMEOUT)
|
||||
|
||||
typedef enum {
|
||||
JPEG_LL_RLE_PARALLEL_ERR = (1 << 1),
|
||||
JPEG_LL_BS_LAST_BLOCK_EOF = (1 << 12),
|
||||
JPEG_LL_EN_FRAME_EOF_ERR = (1 << 16),
|
||||
JPEG_LL_EN_FRAME_EOF_LACK = (1 << 16),
|
||||
} jpeg_ll_encoder_intr_t;
|
||||
|
||||
#define JPEG_LL_ENCODER_EVENT_INTR (JPEG_LL_RLE_PARALLEL_ERR | \
|
||||
JPEG_LL_EN_FRAME_EOF_ERR)
|
||||
|
||||
/**
|
||||
* @brief Enable the hardware clock for JPEG module
|
||||
*
|
||||
* @param enable True to enable; false to disable
|
||||
*/
|
||||
static inline void jpeg_ll_enable_bus_clock(bool enable)
|
||||
{
|
||||
HP_SYS_CLKRST.soc_clk_ctrl1.reg_jpeg_sys_clk_en = enable;
|
||||
}
|
||||
|
||||
/// use a macro to wrap the function, force the caller to use it in a critical section
|
||||
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
|
||||
#define jpeg_ll_enable_bus_clock(...) do { \
|
||||
(void)__DECLARE_RCC_ATOMIC_ENV; \
|
||||
jpeg_ll_enable_bus_clock(__VA_ARGS__); \
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
* @brief Reset the JPEG module
|
||||
*/
|
||||
static inline void jpeg_ll_reset_module_register(void)
|
||||
{
|
||||
HP_SYS_CLKRST.hp_rst_en0.reg_rst_en_jpeg = 1;
|
||||
HP_SYS_CLKRST.hp_rst_en0.reg_rst_en_jpeg = 0;
|
||||
}
|
||||
|
||||
/// use a macro to wrap the function, force the caller to use it in a critical section
|
||||
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
|
||||
#define jpeg_ll_reset_module_register(...) do { \
|
||||
(void)__DECLARE_RCC_ATOMIC_ENV; \
|
||||
jpeg_ll_reset_module_register(__VA_ARGS__); \
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
* @brief Write the numbers of 1~n codewords length sum of ac0 table and write the minimum codeword of code length
|
||||
* for 1~16 of ac0 table
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware
|
||||
* @param huffman_bits_table Pointer to huffman table
|
||||
* @param minimum_code_table Pointer to minimum huffman code table
|
||||
*/
|
||||
static inline void jpeg_ll_dht_ac0_write_codeword(jpeg_dev_t *hw, uint8_t *huffman_bits_table, uint32_t *minimum_code_table)
|
||||
{
|
||||
uint32_t element_number = 0;
|
||||
for (int idx = 0; idx < JPEG_HUFFMAN_BITS_LEN_TABLE_LEN; idx++) {
|
||||
element_number += (uint32_t)huffman_bits_table[idx];
|
||||
hw->dht_totlen_ac0.dht_totlen_ac0 = element_number;
|
||||
hw->dht_codemin_ac0.dht_codemin_ac0 = minimum_code_table[idx];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Write the symbols corresponding to the decoded codeword for AC0 huffman table in FIFO mode
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware.
|
||||
* @param huffman_value_table Pointer to huffman value table.
|
||||
*/
|
||||
static inline void jpeg_ll_dht_ac0_write_value(jpeg_dev_t *hw, uint8_t *huffman_value_table)
|
||||
{
|
||||
for (int idx = 0; idx < JPEG_HUFFMAN_AC_VALUE_TABLE_LEN; idx++) {
|
||||
hw->dht_val_ac0.dht_val_ac0 = (uint32_t)huffman_value_table[idx];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Write the numbers of 1~n codewords length sum of ac1 table and write the minimum codeword of code length
|
||||
* for 1~16 of ac1 table
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware
|
||||
* @param huffman_bits_table Pointer to huffman table
|
||||
* @param minimum_code_table Pointer to minimum huffman code table
|
||||
*/
|
||||
static inline void jpeg_ll_dht_ac1_write_codeword(jpeg_dev_t *hw, uint8_t *huffman_bits_table, uint32_t *minimum_code_table)
|
||||
{
|
||||
uint32_t element_number = 0;
|
||||
for (int idx = 0; idx < JPEG_HUFFMAN_BITS_LEN_TABLE_LEN; idx++) {
|
||||
element_number += (uint32_t)huffman_bits_table[idx];
|
||||
hw->dht_totlen_ac1.dht_totlen_ac1 = element_number;
|
||||
hw->dht_codemin_ac1.dht_codemin_ac1 = minimum_code_table[idx];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Write the symbols corresponding to the decoded codeword for AC1 huffman table in FIFO mode
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware.
|
||||
* @param huffman_value_table Pointer to huffman value table.
|
||||
*/
|
||||
static inline void jpeg_ll_dht_ac1_write_value(jpeg_dev_t *hw, uint8_t *huffman_value_table)
|
||||
{
|
||||
for (int idx = 0; idx < JPEG_HUFFMAN_AC_VALUE_TABLE_LEN; idx++) {
|
||||
hw->dht_val_ac1.dht_val_ac1 = (uint32_t)huffman_value_table[idx];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Write the numbers of 1~n codewords length sum of dc0 table and write the minimum codeword of code length
|
||||
* for 1~16 of dc0 table
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware
|
||||
* @param huffman_bits_table Pointer to huffman table
|
||||
* @param minimum_code_table Pointer to minimum huffman code table
|
||||
*/
|
||||
static inline void jpeg_ll_dht_dc0_write_codeword(jpeg_dev_t *hw, uint8_t *huffman_bits_table, uint32_t *minimum_code_table)
|
||||
{
|
||||
uint32_t element_number = 0;
|
||||
for (int idx = 0; idx < JPEG_HUFFMAN_BITS_LEN_TABLE_LEN; idx++) {
|
||||
element_number += (uint32_t)huffman_bits_table[idx];
|
||||
hw->dht_totlen_dc0.dht_totlen_dc0 = element_number;
|
||||
hw->dht_codemin_dc0.dht_codemin_dc0 = minimum_code_table[idx];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Write the symbols corresponding to the decoded codeword for DC0 huffman table in FIFO mode
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware
|
||||
* @param huffman_value_table Pointer to huffman value table.
|
||||
*/
|
||||
static inline void jpeg_ll_dht_dc0_write_value(jpeg_dev_t *hw, uint8_t *huffman_value_table)
|
||||
{
|
||||
for (int idx = 0; idx < JPEG_HUFFMAN_DC_VALUE_TABLE_LEN; idx++) {
|
||||
hw->dht_val_dc0.dht_val_dc0 = (uint32_t)huffman_value_table[idx];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Write the numbers of 1~n codewords length sum of dc1 table and write the minimum codeword of code length
|
||||
* for 1~16 of dc1 table
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware
|
||||
* @param huffman_bits_table Pointer to huffman table
|
||||
* @param minimum_code_table Pointer to minimum huffman code table
|
||||
*/
|
||||
static inline void jpeg_ll_dht_dc1_write_codeword(jpeg_dev_t *hw, uint8_t *huffman_bits_table, uint32_t *minimum_code_table)
|
||||
{
|
||||
uint32_t element_number = 0;
|
||||
for (int idx = 0; idx < JPEG_HUFFMAN_BITS_LEN_TABLE_LEN; idx++) {
|
||||
element_number += (uint32_t)huffman_bits_table[idx];
|
||||
hw->dht_totlen_dc1.dht_totlen_dc1 = element_number;
|
||||
hw->dht_codemin_dc1.dht_codemin_dc1 = minimum_code_table[idx];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Write the symbols corresponding to the decoded codeword for DC1 huffman table in FIFO mode
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware
|
||||
* @param huffman_value_table Pointer to huffman value table.
|
||||
*/
|
||||
static inline void jpeg_ll_dht_dc1_write_value(jpeg_dev_t *hw, uint8_t *huffman_value_table)
|
||||
{
|
||||
for (int idx = 0; idx < JPEG_HUFFMAN_DC_VALUE_TABLE_LEN; idx++) {
|
||||
hw->dht_val_dc1.dht_val_dc1 = (uint32_t)huffman_value_table[idx];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures the quantization coefficient table precision for the encoder
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware
|
||||
* @param qnr_presition precision of quantization coefficient table
|
||||
*/
|
||||
static inline void jpeg_ll_set_qnr_presition(jpeg_dev_t *hw, uint8_t qnr_presition)
|
||||
{
|
||||
hw->config.qnr_presition = qnr_presition;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures it to write quantization coefficient for table0 in FIFO mode
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware
|
||||
* @param quantization_table Pointer to quantization table.
|
||||
*/
|
||||
static inline void jpeg_ll_write_quantization_coefficient_t0(jpeg_dev_t *hw, uint32_t *quantization_table)
|
||||
{
|
||||
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->dqt_info, t0_dqt_info, 0);
|
||||
for (int q = 0; q < JPEG_QUANTIZATION_TABLE_LEN; q++) {
|
||||
hw->t0qnr.t0_qnr_val = quantization_table[q];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures it to write quantization coefficient for table1 in FIFO mode
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware
|
||||
* @param quantization_table Pointer to quantization table.
|
||||
*/
|
||||
static inline void jpeg_ll_write_quantization_coefficient_t1(jpeg_dev_t *hw, uint32_t *quantization_table)
|
||||
{
|
||||
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->dqt_info, t1_dqt_info, 1);
|
||||
for (int q = 0; q < JPEG_QUANTIZATION_TABLE_LEN; q++) {
|
||||
hw->t1qnr.chrominance_qnr_val = quantization_table[q];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures it to write quantization coefficient for table2 in FIFO mode
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware
|
||||
* @param quantization_table Pointer to quantization table.
|
||||
*/
|
||||
static inline void jpeg_ll_write_quantization_coefficient_t2(jpeg_dev_t *hw, uint32_t *quantization_table)
|
||||
{
|
||||
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->dqt_info, t2_dqt_info, 2);
|
||||
for (int q = 0; q < JPEG_QUANTIZATION_TABLE_LEN; q++) {
|
||||
hw->t2qnr.t2_qnr_val = quantization_table[q];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures it to write quantization coefficient for table3 in FIFO mode
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware
|
||||
* @param quantization_table Pointer to quantization table.
|
||||
*/
|
||||
static inline void jpeg_ll_write_quantization_coefficient_t3(jpeg_dev_t *hw, uint32_t *quantization_table)
|
||||
{
|
||||
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->dqt_info, t3_dqt_info, 3);
|
||||
for (int q = 0; q < JPEG_QUANTIZATION_TABLE_LEN; q++) {
|
||||
hw->t3qnr.t3_qnr_val = quantization_table[q];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures image’s height
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware
|
||||
* @param height height of image.
|
||||
*/
|
||||
static inline void jpeg_ll_set_picture_height(jpeg_dev_t *hw, uint32_t height)
|
||||
{
|
||||
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->pic_size, va, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures image’s width
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware
|
||||
* @param height width of image.
|
||||
*/
|
||||
static inline void jpeg_ll_set_picture_width(jpeg_dev_t *hw, uint32_t width)
|
||||
{
|
||||
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->pic_size, ha, width);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure component0.
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware
|
||||
* @param identifier ID of component 0.
|
||||
* @param horizontal_factor Configures the horizontal sampling factor of component 0.
|
||||
* @param vertical_factor Configures the vertical sampling factor of component 0.
|
||||
* @param qun_table_id Configures the selected quantization coefficient table ID for component 0.
|
||||
*/
|
||||
static inline void jpeg_ll_set_frame_info_component0(jpeg_dev_t *hw, uint8_t identifier, uint8_t horizontal_factor, uint8_t vertical_factor, uint8_t qun_table_id)
|
||||
{
|
||||
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->c0, c0_id, identifier);
|
||||
hw->c0.c0_x_factor = horizontal_factor;
|
||||
hw->c0.c0_y_factor = vertical_factor;
|
||||
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->c0, c0_dqt_tbl_sel, qun_table_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure component1.
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware
|
||||
* @param identifier ID of component 1.
|
||||
* @param horizontal_factor Configures the horizontal sampling factor of component 1.
|
||||
* @param vertical_factor Configures the vertical sampling factor of component 1.
|
||||
* @param qun_table_id Configures the selected quantization coefficient table ID for component 1.
|
||||
*/
|
||||
static inline void jpeg_ll_set_frame_info_component1(jpeg_dev_t *hw, uint8_t identifier, uint8_t horizontal_factor, uint8_t vertical_factor, uint8_t qun_table_id)
|
||||
{
|
||||
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->c1, c1_id, identifier);
|
||||
hw->c1.c1_x_factor = horizontal_factor;
|
||||
hw->c1.c1_y_factor = vertical_factor;
|
||||
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->c1, c1_dqt_tbl_sel, qun_table_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure component2.
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware
|
||||
* @param identifier ID of component 2.
|
||||
* @param horizontal_factor Configures the horizontal sampling factor of component 2.
|
||||
* @param vertical_factor Configures the vertical sampling factor of component 2.
|
||||
* @param qun_table_id Configures the selected quantization coefficient table ID for component 2.
|
||||
*/
|
||||
static inline void jpeg_ll_set_frame_info_component2(jpeg_dev_t *hw, uint8_t identifier, uint8_t horizontal_factor, uint8_t vertical_factor, uint8_t qun_table_id)
|
||||
{
|
||||
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->c2, c2_id, identifier);
|
||||
hw->c2.c2_x_factor = horizontal_factor;
|
||||
hw->c2.c2_y_factor = vertical_factor;
|
||||
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->c2, c2_dqt_tbl_sel, qun_table_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure component3.
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware
|
||||
* @param identifier ID of component 3.
|
||||
* @param horizontal_factor Configures the horizontal sampling factor of component 3.
|
||||
* @param vertical_factor Configures the vertical sampling factor of component 3.
|
||||
* @param qun_table_id Configures the selected quantization coefficient table ID for component 3.
|
||||
*/
|
||||
static inline void jpeg_ll_set_frame_info_component3(jpeg_dev_t *hw, uint8_t identifier, uint8_t horizontal_factor, uint8_t vertical_factor, uint8_t qun_table_id)
|
||||
{
|
||||
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->c3, c3_id, identifier);
|
||||
hw->c3.c3_x_factor = horizontal_factor;
|
||||
hw->c3.c3_y_factor = vertical_factor;
|
||||
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->c3, c3_dqt_tbl_sel, qun_table_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get factor from component0
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware
|
||||
* @param component_factor Pointer to component factor
|
||||
*/
|
||||
static inline void jpeg_ll_get_component0_factor(jpeg_dev_t *hw, jpeg_component_factor_t *component_factor)
|
||||
{
|
||||
component_factor->horizontal = hw->c0.c0_x_factor;
|
||||
component_factor->vertical = hw->c0.c0_y_factor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get factor from component1
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware
|
||||
* @param component_factor Pointer to component factor
|
||||
*/
|
||||
static inline void jpeg_ll_get_component1_factor(jpeg_dev_t *hw, jpeg_component_factor_t *component_factor)
|
||||
{
|
||||
component_factor->horizontal = hw->c1.c1_x_factor;
|
||||
component_factor->vertical = hw->c1.c1_y_factor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures whether or not to start compressing a new image
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware
|
||||
*/
|
||||
static inline void jpeg_ll_process_start(jpeg_dev_t *hw)
|
||||
{
|
||||
hw->config.jpeg_start = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures whether or not pause the JPEG codec.
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware
|
||||
* @param en true: pause the jpeg codec, false: resume.
|
||||
*/
|
||||
static inline void jpeg_ll_codec_pause(jpeg_dev_t *hw, bool en)
|
||||
{
|
||||
hw->config.pause_en = en;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Apply soft reset, this will reset the hardware fsm and fifo.
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware.
|
||||
*/
|
||||
static inline void jpeg_ll_soft_rst(jpeg_dev_t *hw)
|
||||
{
|
||||
hw->config.soft_rst = 1;
|
||||
hw->config.soft_rst = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures if the JPEG codec is working as an encoder or a decoder.
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware.
|
||||
* @param mode Refer to `jpeg_codec_mode_t`
|
||||
*/
|
||||
static inline void jpeg_ll_set_codec_mode(jpeg_dev_t *hw, jpeg_codec_mode_t mode)
|
||||
{
|
||||
uint8_t mode_val = 0;
|
||||
switch (mode) {
|
||||
case JPEG_CODEC_ENCODER:
|
||||
mode_val = 0;
|
||||
break;
|
||||
case JPEG_CODEC_DECODER:
|
||||
mode_val = 1;
|
||||
break;
|
||||
default:
|
||||
HAL_ASSERT(false);
|
||||
break;
|
||||
}
|
||||
hw->config.mode = mode_val;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures whether or not to enable FIFO mode of configuring quantization coefficient tables.
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware.
|
||||
* @param mode 0: Use non-fifo mode. 1: Use fifo mode.
|
||||
*/
|
||||
static inline void jpeg_ll_set_access_qnr_ram_mode(jpeg_dev_t *hw, uint8_t mode)
|
||||
{
|
||||
hw->config.qnr_fifo_en = mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures the number of color components in image when decoding
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware.
|
||||
* @param component_num Number of color components
|
||||
*/
|
||||
static inline void jpeg_ll_set_decode_component_num(jpeg_dev_t *hw, uint8_t component_num)
|
||||
{
|
||||
// ESP32P4 only support to decode color component not larger than 4
|
||||
HAL_ASSERT(component_num <= 3);
|
||||
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->decode_conf, component_num, component_num);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures the format of the image to be compressed
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware.
|
||||
* @param mode_sel Select sample mode, refer to `jpeg_sample_mode_t`.
|
||||
*/
|
||||
static inline void jpeg_ll_sample_mode_select(jpeg_dev_t *hw, jpeg_sample_mode_t mode_sel)
|
||||
{
|
||||
uint8_t sample_sel = 0;
|
||||
switch (mode_sel) {
|
||||
case JPEG_SAMPLE_MODE_YUV444:
|
||||
sample_sel = 0;
|
||||
break;
|
||||
case JPEG_SAMPLE_MODE_YUV422:
|
||||
sample_sel = 1;
|
||||
break;
|
||||
case JPEG_SAMPLE_MODE_YUV420:
|
||||
sample_sel = 2;
|
||||
break;
|
||||
default:
|
||||
HAL_ASSERT(false);
|
||||
break;
|
||||
}
|
||||
hw->config.sample_sel = sample_sel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure whether or not to reverse the original image's pixel order.
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware.
|
||||
* @param reverse_en 0: not revert; 1: revert.
|
||||
*/
|
||||
static inline void jpeg_ll_pixel_reverse(jpeg_dev_t *hw, bool reverse_en)
|
||||
{
|
||||
hw->config.pixel_rev = reverse_en;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures whether or not to add EOI of “0xffd9” at the end of bitstream
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware.
|
||||
* @param tailer_en 1: Add `0xffd9` at the end of bitstream.
|
||||
*/
|
||||
static inline void jpeg_ll_add_tail(jpeg_dev_t *hw, bool tailer_en)
|
||||
{
|
||||
hw->config.tailer_en = tailer_en;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures whether or not to add “00” after “ff”
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware.
|
||||
* @param ff_check_en 0: not add `00` after `ff`; 1: Add.
|
||||
*/
|
||||
static inline void jpeg_ll_enable_ff_check(jpeg_dev_t *hw, bool ff_check_en)
|
||||
{
|
||||
hw->config.ff_check_en = ff_check_en;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures the luma quantization table ID for the encoder
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware.
|
||||
* @param lqnr_id ID of luma quantization table.
|
||||
*/
|
||||
static inline void jpeg_ll_luminance_qnr_table_id(jpeg_dev_t *hw, uint8_t lqnr_id)
|
||||
{
|
||||
hw->config.lqnr_tbl_sel = lqnr_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures the chroma quantization table ID for the encoder.
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware.
|
||||
* @param cqnr_id ID of chroma quantization table.
|
||||
*/
|
||||
static inline void jpeg_ll_chrominance_qnr_table_id(jpeg_dev_t *hw, uint8_t cqnr_id)
|
||||
{
|
||||
hw->config.cqnr_tbl_sel = cqnr_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures the restart interval in DRI segment when decoding
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware.
|
||||
* @param restart_interval value of restart interval.
|
||||
*/
|
||||
static inline void jpeg_ll_set_restart_interval(jpeg_dev_t *hw, uint16_t restart_interval)
|
||||
{
|
||||
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->decode_conf, restart_interval, restart_interval);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get JPEG interrupt status register address
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware.
|
||||
* @return address of interrupt status register.
|
||||
*/
|
||||
static inline volatile void *jpeg_ll_get_interrupt_status_reg(jpeg_dev_t *hw)
|
||||
{
|
||||
return &hw->int_st;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable JPEG interrupt
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware.
|
||||
*/
|
||||
static inline void jpeg_ll_enable_intr_mask(jpeg_dev_t *hw, uint32_t mask)
|
||||
{
|
||||
hw->int_ena.val |= mask;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Clear JPEG interrupt
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware.
|
||||
*/
|
||||
static inline void jpeg_ll_clear_intr_mask(jpeg_dev_t *hw, uint32_t mask)
|
||||
{
|
||||
hw->int_clr.val = mask;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable JPEG interrupt
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware.
|
||||
*/
|
||||
static inline void jpeg_ll_disable_intr_mask(jpeg_dev_t *hw, uint32_t mask)
|
||||
{
|
||||
hw->int_ena.val &= (~mask);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get JPEG interrupt status
|
||||
*
|
||||
* @param hw Pointer to JPEG hardware.
|
||||
*/
|
||||
static inline uint32_t jpeg_ll_get_intr_status(jpeg_dev_t *hw)
|
||||
{
|
||||
return hw->int_st.val;
|
||||
}
|
||||
|
||||
static inline void jpeg_ll_config_picture_pixel_format(jpeg_dev_t *hw, jpeg_enc_src_type_t pixel_format)
|
||||
{
|
||||
uint8_t cs = 0;
|
||||
#if HAL_CONFIG(CHIP_SUPPORT_MIN_REV) >= 300
|
||||
uint8_t ecs = 0;
|
||||
// Default, we disable extend color space
|
||||
hw->extd_config.extd_color_space_en = 0;
|
||||
#endif
|
||||
switch (pixel_format) {
|
||||
case JPEG_ENC_SRC_RGB888:
|
||||
cs = 0;
|
||||
break;
|
||||
case JPEG_ENC_SRC_YUV422:
|
||||
cs = 1;
|
||||
break;
|
||||
case JPEG_ENC_SRC_RGB565:
|
||||
cs = 2;
|
||||
break;
|
||||
case JPEG_ENC_SRC_GRAY:
|
||||
cs = 3;
|
||||
break;
|
||||
#if HAL_CONFIG(CHIP_SUPPORT_MIN_REV) >= 300
|
||||
case JPEG_ENC_SRC_YUV444:
|
||||
hw->extd_config.extd_color_space_en = 1;
|
||||
ecs = 0;
|
||||
break;
|
||||
case JPEG_ENC_SRC_YUV420:
|
||||
hw->extd_config.extd_color_space_en = 1;
|
||||
ecs = 1;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
hw->config.color_space = cs;
|
||||
#if HAL_CONFIG(CHIP_SUPPORT_MIN_REV) >= 300
|
||||
hw->extd_config.extd_color_space = ecs;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* NOTICE
|
||||
* The HAL is not public api, don't use in application code.
|
||||
* See readme.md in hal/include/hal/readme.md
|
||||
******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include "hal/jpeg_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct jpeg_dev_t *jpeg_soc_handle_t; // JPEG SOC layer handle
|
||||
|
||||
/**
|
||||
* Context that should be maintained by both the driver and the HAL
|
||||
*/
|
||||
typedef struct {
|
||||
jpeg_soc_handle_t dev; // JPEG SOC layer handle (i.e. register base address)
|
||||
} jpeg_hal_context_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize the JPEG codec HAL driver
|
||||
*
|
||||
* @param hal: JPEG codec HAL context
|
||||
*/
|
||||
void jpeg_hal_init(jpeg_hal_context_t *hal);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize the JPEG codec HAL driver
|
||||
*
|
||||
* @param hal: JPEG codec HAL context
|
||||
*/
|
||||
void jpeg_hal_deinit(jpeg_hal_context_t *hal);
|
||||
|
||||
/**
|
||||
* @brief Function pointer typedef for configuring DHT tables in JPEG decoding.
|
||||
*
|
||||
* This function pointer typedef represents a callback function that can be used
|
||||
* to configure the DHT (Huffman) tables in the JPEG decoding process. It takes
|
||||
* as input a JPEG HAL context, as well as pointers to arrays representing the
|
||||
* minimum codes, bit lengths, and Huffman codes for the DHT tables.
|
||||
*
|
||||
* @param hal The JPEG HAL context.
|
||||
* @param huffbits Pointer to the array of bit lengths for the DHT tables.
|
||||
* @param huffcode Pointer to the array of Huffman codes for the DHT tables.
|
||||
*/
|
||||
typedef void (*jpeg_config_dht_table_t)(jpeg_hal_context_t *hal, uint8_t *huffbits, uint8_t *huffcode, uint32_t *tmp_huff);
|
||||
|
||||
/**
|
||||
* @brief Array of function pointers for configuring DHT tables in JPEG decoding.
|
||||
*
|
||||
* This two-dimensional array represents a collection of function pointers that
|
||||
* can be used to configure the DHT (Huffman) tables in the JPEG decoding process.
|
||||
*/
|
||||
extern jpeg_config_dht_table_t dht_func[DHT_TC_NUM][DHT_TH_NUM];
|
||||
|
||||
/**
|
||||
* Typedef for a function pointer to configure frame information in JPEG.
|
||||
*
|
||||
* This function is used to configure frame information in JPEG hardware.
|
||||
*
|
||||
* @param hw The JPEG SOC handle.
|
||||
* @param identifier The identifier of the frame.
|
||||
* @param horizontal_factor The horizontal factor for chroma subsampling.
|
||||
* @param vertical_factor The vertical factor for chroma subsampling.
|
||||
* @param qun_table_id The quantization table ID.
|
||||
*/
|
||||
typedef void (*jpeg_config_frame_info_t)(jpeg_soc_handle_t hw, uint8_t identifier, uint8_t horizontal_factor, uint8_t vertical_factor, uint8_t qun_table_id);
|
||||
|
||||
/**
|
||||
* Array of function pointers to configure frame information in JPEG.
|
||||
*
|
||||
* This array holds function pointers to configure frame information in JPEG hardware.
|
||||
* Each element corresponds to a specific component number.
|
||||
*/
|
||||
extern jpeg_config_frame_info_t sof_func[JPEG_COMPONENT_NUMBER_MAX];
|
||||
|
||||
/**
|
||||
* Typedef for a function pointer to configure quantization coefficients in JPEG.
|
||||
*
|
||||
* This function is used to configure quantization coefficients in JPEG hardware.
|
||||
*
|
||||
* @param hw The JPEG SOC handle.
|
||||
* @param quantization_table Pointer to the quantization table.
|
||||
*/
|
||||
typedef void (*jpeg_config_quantization_coefficient_t)(jpeg_soc_handle_t hw, uint32_t *quantization_table);
|
||||
|
||||
/**
|
||||
* Array of function pointers to configure quantization coefficients in JPEG.
|
||||
*
|
||||
* This array holds function pointers to configure quantization coefficients in JPEG hardware.
|
||||
* Each element corresponds to a specific component number.
|
||||
*/
|
||||
extern jpeg_config_quantization_coefficient_t dqt_func[JPEG_COMPONENT_NUMBER_MAX];
|
||||
|
||||
/**
|
||||
* Set the quantization coefficients for luminance and chrominance in the JPEG hardware accelerator context.
|
||||
*
|
||||
* @param hal Pointer to the JPEG hardware accelerator context.
|
||||
* @param lqnr Pointer to an array of luminance quantization coefficients.
|
||||
* @param cqnr Pointer to an array of chrominance quantization coefficients.
|
||||
*/
|
||||
void jpeg_hal_set_quantization_coefficient(jpeg_hal_context_t *hal, uint32_t *lqnr, uint32_t *cqnr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include "soc/soc_caps.h"
|
||||
#include "hal/color_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define JPEG_HUFFMAN_BITS_LEN_TABLE_LEN (16)
|
||||
#define JPEG_HUFFMAN_AC_VALUE_TABLE_LEN (256)
|
||||
#define JPEG_HUFFMAN_DC_VALUE_TABLE_LEN (16)
|
||||
#define JPEG_QUANTIZATION_TABLE_LEN (64)
|
||||
#define JPEG_COMPONENT_NUMBER_MAX (4)
|
||||
|
||||
#define DHT_TC_NUM (2) /// Table type
|
||||
#define DHT_TH_NUM (2) /// Huffman table destination identifier
|
||||
#define JPEG_DOWN_SAMPLING_NUM (4) // The number of down sampling methods
|
||||
|
||||
/**
|
||||
* @brief Enum for JPEG codec working mode.
|
||||
*/
|
||||
typedef enum {
|
||||
JPEG_CODEC_ENCODER, ///< Encode mode
|
||||
JPEG_CODEC_DECODER, ///< Decode mode
|
||||
} jpeg_codec_mode_t;
|
||||
|
||||
/**
|
||||
* @brief Structure for recording factor of component.
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t horizontal; ///< horizontal factor
|
||||
uint32_t vertical; ///< vertical factor
|
||||
} jpeg_component_factor_t;
|
||||
|
||||
/**
|
||||
* @brief Enum for JPEG sampling mode.
|
||||
*/
|
||||
typedef enum {
|
||||
JPEG_SAMPLE_MODE_YUV444 = ESP_COLOR_FOURCC_YUV, ///< sample in YUV444
|
||||
JPEG_SAMPLE_MODE_YUV422 = ESP_COLOR_FOURCC_YVYU, ///< sample in YUV422
|
||||
JPEG_SAMPLE_MODE_YUV420 = ESP_COLOR_FOURCC_OUYY_EVYY, ///< sample in YUV420
|
||||
} jpeg_sample_mode_t;
|
||||
|
||||
/**
|
||||
* @brief Structure for huffman information
|
||||
*/
|
||||
typedef union {
|
||||
struct {
|
||||
uint8_t id : 4; ///< Huffman table id
|
||||
uint8_t type : 4; ///< Huffman table type
|
||||
};
|
||||
uint8_t info; ///< Information of huffman table
|
||||
} jpeg_huffman_table_info_t;
|
||||
|
||||
/**
|
||||
* @brief Enumeration for jpeg decoder sample methods.
|
||||
*/
|
||||
typedef enum {
|
||||
JPEG_DOWN_SAMPLING_YUV444 = ESP_COLOR_FOURCC_YUV, /*!< Sample by YUV444 */
|
||||
JPEG_DOWN_SAMPLING_YUV422 = ESP_COLOR_FOURCC_YVYU, /*!< Sample by YUV422 */
|
||||
JPEG_DOWN_SAMPLING_YUV420 = ESP_COLOR_FOURCC_OUYY_EVYY, /*!< Sample by YUV420 */
|
||||
JPEG_DOWN_SAMPLING_GRAY = ESP_COLOR_FOURCC_GREY, /*!< Sample the gray picture */
|
||||
} jpeg_down_sampling_type_t;
|
||||
|
||||
/**
|
||||
* @brief JPEG encoder source formats.
|
||||
*/
|
||||
typedef enum {
|
||||
JPEG_ENC_SRC_RGB888 = ESP_COLOR_FOURCC_BGR24, /*!< JPEG encoder source RGB888 */
|
||||
JPEG_ENC_SRC_YUV422 = ESP_COLOR_FOURCC_YVYU, /*!< JPEG encoder source YUV422 */
|
||||
JPEG_ENC_SRC_RGB565 = ESP_COLOR_FOURCC_RGB16, /*!< JPEG encoder source RGB565 */
|
||||
JPEG_ENC_SRC_YUV444 = ESP_COLOR_FOURCC_YUV, /*!< JPEG encoder source YUV444 */
|
||||
JPEG_ENC_SRC_YUV420 = ESP_COLOR_FOURCC_OUYY_EVYY, /*!< JPEG encoder source YUV420 */
|
||||
JPEG_ENC_SRC_GRAY = ESP_COLOR_FOURCC_GREY, /*!< JPEG encoder source GRAY */
|
||||
} jpeg_enc_src_type_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include "hal/jpeg_hal.h"
|
||||
#include "hal/jpeg_ll.h"
|
||||
|
||||
void jpeg_hal_init(jpeg_hal_context_t *hal)
|
||||
{
|
||||
hal->dev = JPEG_LL_GET_HW();
|
||||
}
|
||||
|
||||
void jpeg_hal_deinit(jpeg_hal_context_t *hal)
|
||||
{
|
||||
hal->dev = NULL;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Config huffman code tables with a DHT segment */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
static void jpeg_hal_create_minicode_tbl(uint8_t *huffbits, uint32_t *huffmin, uint32_t *tmp_huff)
|
||||
{
|
||||
int total_len = 0;
|
||||
/* Re-build huffman code word table */
|
||||
for (int j = 0, i = 0, hc = 0; i < JPEG_HUFFMAN_BITS_LEN_TABLE_LEN; i++, hc <<= 1) {
|
||||
int b = huffbits[i];
|
||||
// If a codeword length does not exist, the configuration value is 0xFFFF.
|
||||
if (huffbits[i] == 0) {
|
||||
huffmin[i] = 0xffff;
|
||||
continue;
|
||||
}
|
||||
total_len += huffbits[i];
|
||||
while (b--) {
|
||||
tmp_huff[j++] = hc++;
|
||||
}
|
||||
|
||||
if (huffbits[i] != 0) {
|
||||
huffmin[i] = tmp_huff[total_len - huffbits[i]];
|
||||
huffmin[i] <<= (15 - i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void jpeg_hal_config_ac0_table(jpeg_hal_context_t *hal, uint8_t *huffbits, uint8_t *huffcode, uint32_t *tmp_huff)
|
||||
{
|
||||
uint32_t huffmin[JPEG_HUFFMAN_AC_VALUE_TABLE_LEN] = {};
|
||||
jpeg_hal_create_minicode_tbl(huffbits, huffmin, tmp_huff);
|
||||
jpeg_ll_dht_ac0_write_codeword(hal->dev, huffbits, huffmin);
|
||||
jpeg_ll_dht_ac0_write_value(hal->dev, huffcode);
|
||||
}
|
||||
|
||||
void jpeg_hal_config_ac1_table(jpeg_hal_context_t *hal, uint8_t *huffbits, uint8_t *huffcode, uint32_t *tmp_huff)
|
||||
{
|
||||
uint32_t huffmin[JPEG_HUFFMAN_AC_VALUE_TABLE_LEN] = {};
|
||||
jpeg_hal_create_minicode_tbl(huffbits, huffmin, tmp_huff);
|
||||
jpeg_ll_dht_ac1_write_codeword(hal->dev, huffbits, huffmin);
|
||||
jpeg_ll_dht_ac1_write_value(hal->dev, huffcode);
|
||||
}
|
||||
|
||||
void jpeg_hal_config_dc0_table(jpeg_hal_context_t *hal, uint8_t *huffbits, uint8_t *huffcode, uint32_t *tmp_huff)
|
||||
{
|
||||
uint32_t huffmin[JPEG_HUFFMAN_AC_VALUE_TABLE_LEN] = {};
|
||||
jpeg_hal_create_minicode_tbl(huffbits, huffmin, tmp_huff);
|
||||
jpeg_ll_dht_dc0_write_codeword(hal->dev, huffbits, huffmin);
|
||||
jpeg_ll_dht_dc0_write_value(hal->dev, huffcode);
|
||||
}
|
||||
|
||||
void jpeg_hal_config_dc1_table(jpeg_hal_context_t *hal, uint8_t *huffbits, uint8_t *huffcode, uint32_t *tmp_huff)
|
||||
{
|
||||
uint32_t huffmin[JPEG_HUFFMAN_AC_VALUE_TABLE_LEN] = {};
|
||||
jpeg_hal_create_minicode_tbl(huffbits, huffmin, tmp_huff);
|
||||
jpeg_ll_dht_dc1_write_codeword(hal->dev, huffbits, huffmin);
|
||||
jpeg_ll_dht_dc1_write_value(hal->dev, huffcode);
|
||||
}
|
||||
|
||||
jpeg_config_dht_table_t dht_func[DHT_TC_NUM][DHT_TH_NUM] = {
|
||||
{jpeg_hal_config_dc0_table, jpeg_hal_config_dc1_table},
|
||||
{jpeg_hal_config_ac0_table, jpeg_hal_config_ac1_table},
|
||||
};
|
||||
|
||||
jpeg_config_frame_info_t sof_func[JPEG_COMPONENT_NUMBER_MAX] = {
|
||||
jpeg_ll_set_frame_info_component0,
|
||||
jpeg_ll_set_frame_info_component1,
|
||||
jpeg_ll_set_frame_info_component2,
|
||||
jpeg_ll_set_frame_info_component3,
|
||||
};
|
||||
|
||||
jpeg_config_quantization_coefficient_t dqt_func[JPEG_COMPONENT_NUMBER_MAX] = {
|
||||
jpeg_ll_write_quantization_coefficient_t0,
|
||||
jpeg_ll_write_quantization_coefficient_t1,
|
||||
jpeg_ll_write_quantization_coefficient_t2,
|
||||
jpeg_ll_write_quantization_coefficient_t3,
|
||||
};
|
||||
|
||||
void jpeg_hal_set_quantization_coefficient(jpeg_hal_context_t *hal, uint32_t *lqnr, uint32_t *cqnr)
|
||||
{
|
||||
jpeg_ll_set_access_qnr_ram_mode(hal->dev, 1);
|
||||
jpeg_ll_luminance_qnr_table_id(hal->dev, 0);
|
||||
jpeg_ll_chrominance_qnr_table_id(hal->dev, 1);
|
||||
jpeg_ll_write_quantization_coefficient_t0(hal->dev, lqnr);
|
||||
jpeg_ll_write_quantization_coefficient_t1(hal->dev, cqnr);
|
||||
jpeg_ll_write_quantization_coefficient_t2(hal->dev, lqnr);
|
||||
jpeg_ll_write_quantization_coefficient_t3(hal->dev, cqnr);
|
||||
}
|
||||
Reference in New Issue
Block a user