Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

esp_jpeg: Add support for default Huffman tables #439

Merged
merged 3 commits into from
Oct 31, 2024

Conversation

tore-espressif
Copy link
Collaborator

@tore-espressif tore-espressif commented Oct 26, 2024

Summary:
This PR introduces an enhancement to the JPEG decoder in the ESP-IDF library to enable decoding of JPEG images that do not include Huffman tables. Specifically, this update enables decoding of non-standard JPEG frames, such as those produced by certain USB cameras (e.g., Logitech C270), which omit Huffman tables to save space and instead rely on predefined quantization and color subsampling settings. This PR adds robustness to the JPEG decoder by expanding support for such non-standard formats.
Key Changes

  • JPEG Decoder Update:
    Modified the JPEG decoder to support images without Huffman tables, allowing the library to apply default Huffman tables when none are found in the input data.
    This change is essential for handling image data from specific USB cameras that omit Huffman tables.

  • Double Block Size Support (16x8):
    Added handling for double-block size in images (16x8 pixels), a structure unique to frames from certain USB cameras, which diverge from the more common 8x8 block size.
    Improved parsing logic to ensure accurate decompression for such formats while maintaining compatibility with standard JPEG images.

  • Test Case Addition:
    Created a new test case for JPEG decompression without Huffman tables to validate decoding accuracy and RGB888 output correctness.
    The test compares decompressed image data to reference RGB888 arrays, allowing a color tolerance of ±16 for minor discrepancies, as certain decoding processes (e.g., Windows-based decoders) might use slight variations in default tables.
    The test validates the decompressed image dimensions and color data to ensure it falls within acceptable margins of error.

Testing and Validation

  • New Test Coverage: The newly added test case simulates the decoding of a JPEG file without Huffman tables and checks output against expected RGB888 data, allowing for a minor margin of color error.
  • Backward Compatibility: No impact on decoding standard JPEG images, as the decoder falls back on default tables only when Huffman tables are absent in the input.

Motivation and Context

Some USB cameras, such as the Logitech C270, output JPEG frames without Huffman tables, which standard JPEG decoders often cannot process. By introducing support for these cases, this PR enables ESP-IDF to handle a broader range of JPEG image formats, improving its utility in applications that interface with USB cameras or other devices producing such non-standard JPEG frames.

@tore-espressif
Copy link
Collaborator Author

@suda-morris @igrr PTAL or please help me find someone for review, thank you

FYI @espzav

Copy link

github-actions bot commented Oct 26, 2024

Test Results

15 files  15 suites   1m 19s ⏱️
 2 tests  2 ✅ 0 💤 0 ❌
10 runs  10 ✅ 0 💤 0 ❌

Results for commit e793c31.

♻️ This comment has been updated with latest results.

Copy link
Member

@igrr igrr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM, left a few minor comments.

esp_jpeg/jpeg_default_huffman_table.c Outdated Show resolved Hide resolved
esp_jpeg/test_apps/main/test_usb_camera_jpg.h Outdated Show resolved Hide resolved
esp_jpeg/test_apps/sdkconfig.defaults Outdated Show resolved Hide resolved
esp_jpeg/Kconfig Show resolved Hide resolved
@tore-espressif
Copy link
Collaborator Author

Thank you for the review @igrr ! I implemented your comments and also tested on esp-idf examples that use esp_jpeg

@tore-espressif
Copy link
Collaborator Author

Thank you for the review @igrr ! I implemented your comments and also tested on esp-idf examples that use esp_jpeg

@igrr Also tested with USB camera. Please let me know if you want to have a second look or I can merge, thanks!

Some JPEG images, typically frames from cameras, do not contain Huffman tables.
This commit adds an option to use default Huffman tables defined in JPEG specification.
@tore-espressif tore-espressif merged commit 4d380e0 into master Oct 31, 2024
49 checks passed
@tore-espressif tore-espressif deleted the feature/esp_jpeg_default_huffman branch October 31, 2024 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants