Skip to content

Add DecodeThumbnail and DecodeThumbnailConfig#13

Open
Rosca75 wants to merge 3 commits into
gen2brain:mainfrom
Rosca75:feat/decode-thumbnail
Open

Add DecodeThumbnail and DecodeThumbnailConfig#13
Rosca75 wants to merge 3 commits into
gen2brain:mainfrom
Rosca75:feat/decode-thumbnail

Conversation

@Rosca75
Copy link
Copy Markdown

@Rosca75 Rosca75 commented Apr 18, 2026

Summary

  • Adds DecodeThumbnail(r io.Reader) (image.Image, error) and DecodeThumbnailConfig(r io.Reader) (image.Config, error) with the same WASM/dynamic dispatch pattern as
    Decode/DecodeConfig.
  • New sentinel error ErrNoThumbnail returned when the HEIF file contains no embedded thumbnail. No fallback to primary decode.
  • Multiple thumbnails: first-found is used (heif_image_handle_get_list_of_thumbnail_IDs with count=1).
  • Not registered with image.RegisterFormat — opt-in only.

Implementation

C (lib/heif.c): Added decode_thumbnail with return codes 0=failure, 1=success, 2=no thumbnail. Mirrors decode but operates on the thumbnail handle obtained via
heif_image_handle_get_thumbnail.

WASM (lib/heif.wasm.gz): Rebuilt with wasi-sdk; decode_thumbnail exported alongside decode. Built against libheif v1.18.2 / libde265 v1.0.15.

Dynamic path (decode_dynamic.go): Registers heif_image_handle_get_number_of_thumbnails, heif_image_handle_get_list_of_thumbnail_IDs, and heif_image_handle_get_thumbnail
via purego. decodeThumbnailDynamic mirrors decodeDynamic, switching to the thumbnail handle after the primary handle is obtained.

Tests

Test fixture is a real iPhone HEIC (IMG_2736.HEIC, 416×312 thumbnail) — these files require libheif ≥ 1.18 for the HDR tone-map metadata; TestDecodeThumbnailDynamic skips
automatically on older system libraries. TestDecodeThumbnailMissing verifies ErrNoThumbnail on both paths against a file with no thumbnail.

Notes

  • The WASM binary diff is larger than a minimal C change would suggest — different wasi-sdk codegen vs. the previously committed binary. wasi-sdk version: as installed at
    /opt/wasi-sdk.
  • TestDecodeThumbnailDynamic will run fully on CI once the system libheif is ≥ 1.18.

Rosca75 and others added 2 commits April 18, 2026 23:19
Both WASM and dynamic paths implemented. C wrapper decode_thumbnail
returns 0=failure, 1=success, 2=no thumbnail (ErrNoThumbnail sentinel).
WASM rebuilt with wasi-sdk; exports decode_thumbnail. Dynamic path
registers heif_image_handle_get_{number_of_thumbnails,list_of_thumbnail_IDs,thumbnail}.
Multiple thumbnails: first-found is used. No image.RegisterFormat entry.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@gen2brain
Copy link
Copy Markdown
Owner

Thanks, additions are interesting. But, now that you have something working, can you approach to discuss it? This project does not need CLAUDE.md and PLAN.md additions, it is simple enough, and for sure does not need a random binary. The current situation is not ideal. I built a binary from current sources; of course, it is not acceptable to send a binary diff.

Allows direct go get import from the fork without a replace directive.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Rosca75
Copy link
Copy Markdown
Author

Rosca75 commented Apr 19, 2026

Thanks, additions are interesting. But, now that you have something working, can you approach to discuss it? This project does not need CLAUDE.md and PLAN.md additions, it is simple enough, and for sure does not need a random binary. The current situation is not ideal. I built a binary from current sources; of course, it is not acceptable to send a binary diff.

Hello @gen2brain,
Happy to discuss it where you prefer. I am not a skilled programmer, but more a photographer who develop small local apps to speed up my personal work process.

"This project does not need CLAUDE.md and PLAN.md additions" → That is my mistake, this should have not been included as part of the PR.
"The current situation is not ideal. I built a binary from current sources; of course, it is not acceptable to send a binary diff." → I understand, the PR as such is probably not OK, but I found the project very interesting, and the method to extract the thumbnail can support interesting use cases, so I thought it could be useful to have a 1st version of it.

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