Skip to content

Commit

Permalink
review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tore-espressif committed Oct 30, 2024
1 parent ebd2c7e commit 97e7937
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 857 deletions.
2 changes: 0 additions & 2 deletions .idf_build_apps.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
target = "all"
paths = "."
recursive = true
exclude = [
".github",
Expand Down
5 changes: 5 additions & 0 deletions esp_jpeg/.build-test-rules.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# TODO: commented out until we can select specific configuration in pytest...
# esp_jpeg/test_apps:
# disable:
# - if: (CONFIG_NAME == "rom") and (ESP_ROM_HAS_JPEG_DECODE != 1)
# reason: "Only compile test with Tjpg ROM implementation for targets that support it"
41 changes: 23 additions & 18 deletions esp_jpeg/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,33 @@

[![Component Registry](https://components.espressif.com/components/espressif/esp_jpeg/badge.svg)](https://components.espressif.com/components/espressif/esp_jpeg)

TJpgDec is a generic JPEG image decompressor that is highly optimized for small embedded systems. It works with very low memory consumption.
TJpgDec is a lightweight JPEG image decompressor optimized for embedded systems with minimal memory consumption.

Some microcontrollers have TJpg decoder in ROM, it is used, if there is. [^1] Using ROM code can be disabled in menuconfig.
On some microcontrollers, TJpgDec is available in ROM and will be used by default, though this can be disabled in menuconfig if desired[^1].

[^1]: **_NOTE:_** When the ROM decoder is used, the configuration can't be changed. The configuration is fixed.

## Features

**Compilation configuration:**
- Size of stream input buffer (default 512)
- Output pixel format (default RGB888): RGB888/RGB565
- Switches output descaling feature (default enabled)
- Use table conversion for saturation arithmetic (default enabled)
- Three optimization levels (default basic): 8/16-bit MCUs, 32-bit MCUs, Table conversion for huffman decoding
- Stream input buffer size (default: 512 bytes)
- Output pixel format (default: RGB888; options: RGB888/RGB565)
- Enable/disable output descaling (default: enabled)
- Use table-based saturation for arithmetic operations (default: enabled)
- Use default Huffman tables: Useful from decoding frames from cameras, that do not provide Huffman tables (default: disabled to save ROM)
- Three optimization levels (default: 32-bit MCUs) for different CPU types:
- 8/16-bit MCUs
- 32-bit MCUs
- Table-based Huffman decoding

**Runtime configuration:**
- Pixel Format: RGB888, RGB565
- Scaling Ratio: 1/1, 1/2, 1/4 or 1/8 Selectable on Decompression
- Allow swap the first and the last byte of the color
- Pixel format options: RGB888, RGB565
- Selectable scaling ratios: 1/1, 1/2, 1/4, or 1/8 (chosen at decompression)
- Option to swap the first and last bytes of color values

## TJpgDec in ROM

Some microcontrollers have TJpg decoder in ROM. It is used as default, but it can be disabled in menuconfig. Then there will be used code saved in this component.
On certain microcontrollers, TJpgDec is available in ROM and used by default. This can be disabled in menuconfig if you prefer to use the library code provided in this component.

### List of MCUs, which have TJpgDec in ROM
- ESP32
Expand All @@ -35,24 +39,25 @@ Some microcontrollers have TJpg decoder in ROM. It is used as default, but it ca
- ESP32-C61

### Fixed compilation configuration of the ROM code
- Stream input buffer: 512
The ROM version uses the following fixed settings:
- Stream input buffer: 512 bytes
- Output pixel format: RGB888
- Descaling feature for output: Enabled
- Table for saturation: Enabled
- Output descaling: enabled
- Saturation table: enabled
- Optimization level: Basic (JD_FASTDECODE = 0)

### Pros and cons using ROM code

**Advantages:**
- Save 5k of the flash memory (in the same configuration)
- Saves approximately 5 KB of flash memory with the same configuration

**Disadvantages:**
- Cannot be changed compilation configuration
- Some configuration can be faster in some cases
- Compilation configuration cannot be changed
- Certain configurations may provide faster performance

## Speed comparison

In this table are examples of speed decoding JPEG image with this configuration:
The table below shows example decoding times for a JPEG image using various configurations:
* Image size: 320 x 180 px
* Output format: RGB565
* CPU: ESP32-S3
Expand Down
24 changes: 12 additions & 12 deletions esp_jpeg/jpeg_default_huffman_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@
// representing the actual values associated with each Huffman code in order.

// Luminance DC Table
const unsigned char lum_dc_num_bits[16] = {0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0};
const unsigned lum_dc_codes_total = 12;
const unsigned char lum_dc_values[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
const unsigned char esp_jpeg_lum_dc_num_bits[16] = {0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0};
const unsigned esp_jpeg_lum_dc_codes_total = 12;
const unsigned char esp_jpeg_lum_dc_values[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};

// Chrominance DC Table
const unsigned char chrom_dc_num_bits[16] = {0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0};
const unsigned chrom_dc_codes_total = 12;
const unsigned char chrom_dc_values[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
const unsigned char esp_jpeg_chrom_dc_num_bits[16] = {0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0};
const unsigned esp_jpeg_chrom_dc_codes_total = 12;
const unsigned char esp_jpeg_chrom_dc_values[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};

// Luminance AC Table
const unsigned char lum_ac_num_bits[16] = {0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 125};
const unsigned lum_ac_codes_total = 162;
const unsigned char lum_ac_values[162] = {
const unsigned char esp_jpeg_lum_ac_num_bits[16] = {0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 125};
const unsigned esp_jpeg_lum_ac_codes_total = 162;
const unsigned char esp_jpeg_lum_ac_values[162] = {
0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xA1, 0x08, 0x23, 0x42, 0xB1, 0xC1, 0x15, 0x52, 0xD1, 0xF0,
0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0A, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x25, 0x26, 0x27, 0x28,
Expand All @@ -43,9 +43,9 @@ const unsigned char lum_ac_values[162] = {
};

// Chrominance AC Table
const unsigned char chrom_ac_num_bits[16] = {0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 119};
const unsigned chrom_ac_codes_total = 162;
const unsigned char chrom_ac_values[162] = {
const unsigned char esp_jpeg_chrom_ac_num_bits[16] = {0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 119};
const unsigned esp_jpeg_chrom_ac_codes_total = 162;
const unsigned char esp_jpeg_chrom_ac_values[162] = {
0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, 0xA1, 0xB1, 0xC1, 0x09, 0x23, 0x33, 0x52, 0xF0,
0x15, 0x62, 0x72, 0xD1, 0x0A, 0x16, 0x24, 0x34, 0xE1, 0x25, 0xF1, 0x17, 0x18, 0x19, 0x1A, 0x26,
Expand Down
3 changes: 2 additions & 1 deletion esp_jpeg/test_apps/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
idf_component_register(SRCS "tjpgd_test.c" "test_tjpgd_main.c"
INCLUDE_DIRS "."
PRIV_REQUIRES "unity"
WHOLE_ARCHIVE)
WHOLE_ARCHIVE
EMBED_FILES "logo.jpg" "usb_camera.jpg")
Loading

0 comments on commit 97e7937

Please sign in to comment.