Skip to content

feat: add etc1 codec#6

Open
guilhhotina wants to merge 3 commits into
develop-02Xfrom
guily/etc1-codec
Open

feat: add etc1 codec#6
guilhhotina wants to merge 3 commits into
develop-02Xfrom
guily/etc1-codec

Conversation

@guilhhotina

@guilhhotina guilhhotina commented Jun 11, 2026

Copy link
Copy Markdown

summary

adds cpu-side etc1 encode/decode support and initial gpu texture container support.

this covers issue #2 and the first-pass scope of issue #5 for single-image/mip0 payloads.

changes

  • adds Format::ETC1 with Encode<ETC1>() and Decode<ETC1>()
    • input encode format: RGBA8888
    • output decode format: RGBA8888
    • pads non-4x4 images by replicating edge pixels
    • uses wolfpld/etcpak 2.1 via FetchContent_Populate
    • applies -msse4.1 only to etcpak sources when supported on x86
  • adds Format::RGB565 with encode/decode helpers
  • adds gpu container encode/decode for single-image/mip0 textures:
    • KTX: RGBA8888, RGB565, ETC1
    • PVR: RGBA8888, RGB565, ETC1
    • KTX2: RGBA8888, RGB565, ETC1
    • DDS: RGBA8888, RGB565
  • keeps DDS from accepting ETC1, since etc1 is not a standard dds payload format

validation

  • cmake -B build -DHAIO_TESTS=ON
  • cmake --build build -j$(nproc)
  • ctest --test-dir build -R '^(test_image_etc1_roundtrip|test_gpu_formats_roundtrip)$' --output-on-failure
  • manual e2e:
    • ./build/test_image_convert_png_to_ppm assets/logo8x8.png build/logo8x8_direct.ppm
    • ./build/test_image_convert_png_to_etc1_ppm assets/logo8x8.png build/logo8x8_etc1.ppm
  • temporary sanitizer stress:
    • etc1 roundtrip: 16384 cases
    • gpu container roundtrip: 11264 cases

etc1 roundtrip result:

gradient psnr: 33.7243 db

sample files were also recognized by file as dds, pvr, ktx, and ktx2.

notes

ctest without filters still fails for the two conversion binaries because they require input/output argv, but cmake registers them without arguments. the actual unit tests pass through ctest, and the conversion binaries pass when run manually with inputs.

etcpak emits one vendor warning in ProcessRGB.cpp; no haio warning was introduced.

Use wolfpld/etcpak 2.1 as the CPU ETC1 encoder because it provides maintained SIMD paths for x86 and NEON-friendly builds under BSD-3.

Keep KTX/Basis container work out of this change; KTX is better suited for the GPU container issue and its ETC1 path goes through ETC1S transcode instead of a direct ETC1 encoder.

@RodrigoDornelles RodrigoDornelles left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@guilhhotina essa implementação ta muito boa, só falta dar uma organizada nos arquivos.

Comment thread library/codecs/etc1.cpp Outdated
Comment thread library/codecs/gpu_containers.cpp Outdated
Comment thread library/codecs/gpu_containers.cpp Outdated
Comment thread library/codecs/gpu_containers.cpp Outdated
Comment thread library/codecs/rgb565.cpp Outdated
Comment thread library/codecs/rgb565.cpp Outdated
Comment thread library/codecs/rgb565.cpp Outdated
Comment thread tests/test_image_etc1_roundtrip.cpp Outdated
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