Add DecodeThumbnail and DecodeThumbnailConfig#13
Conversation
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>
|
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>
Hello @gen2brain, "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. |
Summary
DecodeThumbnail(r io.Reader) (image.Image, error)andDecodeThumbnailConfig(r io.Reader) (image.Config, error)with the same WASM/dynamic dispatch pattern asDecode/DecodeConfig.ErrNoThumbnailreturned when the HEIF file contains no embedded thumbnail. No fallback to primary decode.heif_image_handle_get_list_of_thumbnail_IDswithcount=1).image.RegisterFormat— opt-in only.Implementation
C (
lib/heif.c): Addeddecode_thumbnailwith return codes0=failure,1=success,2=no thumbnail. Mirrorsdecodebut operates on the thumbnail handle obtained viaheif_image_handle_get_thumbnail.WASM (
lib/heif.wasm.gz): Rebuilt with wasi-sdk;decode_thumbnailexported alongsidedecode. Built against libheif v1.18.2 / libde265 v1.0.15.Dynamic path (
decode_dynamic.go): Registersheif_image_handle_get_number_of_thumbnails,heif_image_handle_get_list_of_thumbnail_IDs, andheif_image_handle_get_thumbnailvia purego.
decodeThumbnailDynamicmirrorsdecodeDynamic, 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;TestDecodeThumbnailDynamicskipsautomatically on older system libraries.
TestDecodeThumbnailMissingverifiesErrNoThumbnailon both paths against a file with no thumbnail.Notes
/opt/wasi-sdk.TestDecodeThumbnailDynamicwill run fully on CI once the system libheif is ≥ 1.18.