mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-01 18:50:34 +03:00
fix(jpeg): JPEG can encode and decode in encryption situation
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "mbedtls/base64.h"
|
||||
#include "esp_check.h"
|
||||
#include "driver/jpeg_encode.h"
|
||||
@@ -44,6 +45,7 @@ void app_main(void)
|
||||
const size_t embedded_size = esp720p_rgb_end - esp720p_rgb_start;
|
||||
uint32_t jpeg_size = 0;
|
||||
jpeg_encoder_handle_t jpeg_handle = NULL;
|
||||
uint8_t *rgb_buf = NULL;
|
||||
|
||||
printf("Loading embedded BGR24 image from flash...\n");
|
||||
printf("Embedded raw image size: %zu bytes\n", embedded_size);
|
||||
@@ -60,6 +62,18 @@ void app_main(void)
|
||||
.height = EXAMPLE_HEIGHT,
|
||||
};
|
||||
|
||||
const uint8_t *rgb_src = esp720p_rgb_start;
|
||||
#if CONFIG_SECURE_FLASH_ENC_ENABLED
|
||||
size_t input_buffer_size = 0;
|
||||
jpeg_encode_memory_alloc_cfg_t rx_mem_cfg = {
|
||||
.buffer_direction = JPEG_ENC_ALLOC_INPUT_BUFFER,
|
||||
};
|
||||
rgb_buf = (uint8_t *)jpeg_alloc_encoder_mem(EXAMPLE_RGB_FRAME_SIZE, &rx_mem_cfg, &input_buffer_size);
|
||||
assert(rgb_buf != NULL);
|
||||
memcpy(rgb_buf, esp720p_rgb_start, EXAMPLE_RGB_FRAME_SIZE);
|
||||
rgb_src = rgb_buf;
|
||||
#endif
|
||||
|
||||
size_t result_buffer_size = 0;
|
||||
/* The output JPEG is compressed, so the example does not need to reserve
|
||||
* a full raw-frame worth of space for the bitstream. This 10:1 estimate
|
||||
@@ -78,9 +92,8 @@ void app_main(void)
|
||||
};
|
||||
ESP_ERROR_CHECK(jpeg_new_encoder_engine(&encode_eng_cfg, &jpeg_handle));
|
||||
|
||||
printf("JPEG encoder will read the embedded raw buffer directly from flash.\n");
|
||||
printf("Encoding BGR24(raw) -> JPEG...\n");
|
||||
ESP_ERROR_CHECK(jpeg_encoder_process(jpeg_handle, &enc_config, esp720p_rgb_start, EXAMPLE_RGB_FRAME_SIZE,
|
||||
ESP_ERROR_CHECK(jpeg_encoder_process(jpeg_handle, &enc_config, rgb_src, EXAMPLE_RGB_FRAME_SIZE,
|
||||
jpeg_buf, result_buffer_size, &jpeg_size));
|
||||
printf("Encoded JPEG size: %" PRIu32 " bytes\n", jpeg_size);
|
||||
|
||||
@@ -103,4 +116,5 @@ void app_main(void)
|
||||
ESP_ERROR_CHECK(jpeg_del_encoder_engine(jpeg_handle));
|
||||
free(encoded);
|
||||
free(jpeg_buf);
|
||||
free(rgb_buf);
|
||||
}
|
||||
|
||||
@@ -101,12 +101,9 @@ def assert_jpeg_matches_golden(result_bytes: bytes, golden_path: Path) -> None:
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.generic
|
||||
@idf_parametrize('target', soc_filtered_targets('SOC_JPEG_ENCODE_SUPPORTED == 1'), indirect=['target'])
|
||||
def test_jpeg_encode_example(dut: Dut) -> None:
|
||||
def run_jpeg_encode_example(dut: Dut) -> None:
|
||||
dut.expect_exact('Loading embedded BGR24 image from flash...')
|
||||
dut.expect(r'Embedded raw image size: \d+ bytes')
|
||||
dut.expect_exact('JPEG encoder will read the embedded raw buffer directly from flash.')
|
||||
dut.expect_exact('Encoding BGR24(raw) -> JPEG...')
|
||||
dut.expect(r'Encoded JPEG size: \d+ bytes')
|
||||
|
||||
@@ -123,3 +120,26 @@ def test_jpeg_encode_example(dut: Dut) -> None:
|
||||
assert_jpeg_matches_golden(jpeg_bytes, GOLDEN_IMAGE_PATH)
|
||||
|
||||
dut.expect_exact('JPEG encode demo done.')
|
||||
|
||||
|
||||
@pytest.mark.generic
|
||||
@idf_parametrize('target', soc_filtered_targets('SOC_JPEG_ENCODE_SUPPORTED == 1'), indirect=['target'])
|
||||
def test_jpeg_encode_example(dut: Dut) -> None:
|
||||
run_jpeg_encode_example(dut)
|
||||
|
||||
|
||||
@pytest.mark.flash_encryption
|
||||
@pytest.mark.parametrize(
|
||||
'config',
|
||||
[
|
||||
'flash_enc',
|
||||
],
|
||||
indirect=True,
|
||||
)
|
||||
@idf_parametrize(
|
||||
'target',
|
||||
soc_filtered_targets('SOC_JPEG_ENCODE_SUPPORTED == 1 and SOC_FLASH_ENC_SUPPORTED == 1'),
|
||||
indirect=['target'],
|
||||
)
|
||||
def test_jpeg_encode_example_with_flash_encryption(dut: Dut) -> None:
|
||||
run_jpeg_encode_example(dut)
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
# Default CI build, inherits sdkconfig.defaults
|
||||
@@ -0,0 +1,7 @@
|
||||
CONFIG_PARTITION_TABLE_OFFSET=0x9000
|
||||
CONFIG_SECURE_FLASH_ENC_ENABLED=y
|
||||
CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT=y
|
||||
CONFIG_SECURE_FLASH_UART_BOOTLOADER_ALLOW_ENC=y
|
||||
CONFIG_SECURE_FLASH_REQUIRE_ALREADY_ENABLED=y
|
||||
CONFIG_SPIRAM_ENC_EXEMPT=y
|
||||
CONFIG_SPIRAM_ENC_EXEMPT_SIZE=4096
|
||||
Reference in New Issue
Block a user