Skip to content

Fix routing, orientation, and video correctness issues from project review - #30

Merged
ghosthack merged 7 commits into
mainfrom
fix/review-findings
Nov 14, 2026
Merged

ghosthack merged 7 commits into
mainfrom
fix/review-findings

Conversation

@ghosthack

@ghosthack ghosthack commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Summary

Fixes from a full project review. Each commit is one fix with its own regression tests.

  • Routing: the routing SPIs kept the canDecodeInput decision in a thread-local and handed it to the next createReaderInstance. A caller that probed one input and then requested a reader by format name got the backend chosen for the earlier input. Readers are now always deferred and route from the input passed to setInput.
  • EXIF orientation: libvips and ImageMagick returned the stored orientation while Apple and WIC return the displayed one, so installing a portable backend un-rotated phone photos. libvips also rotated reduced decodes but not full ones. Both backends now rotate every decode path and report oriented sizes.
  • Video: AVFoundation reported the stored size for rotated video but returned the displayed frame (32x16 vs 16x32 on the new fixture). FFmpeg ignored the display matrix and returned the keyframe before the requested time. Both backends now report and return the displayed frame, FFmpeg decodes forward to the requested time, and AVFoundation calls drain an autorelease pool.
  • Detection and limits: TIFF-based RAW is recognised from the first IFD rather than by searching for "DNG", "Nikon", or "SONY". A codec brand wins over a generic mif1 major brand. Video detection shares the still-image brand list, so Canon CR3 and JPEG XL are not offered to video backends. imageio.native.maxPixels is read in one place.
  • Backend discovery: backends check the operating system before touching native bindings; ROUTING.md is removed (the README carries the contract).

Behaviour and API changes

  • ImageIO.getImageReaders(input) now returns RoutingImageReader rather than the backend's reader class. RoutingImageReader.backendId() reports the owner; listeners and abort() are forwarded. Each read probes the input twice.
  • NEF and ARW are labelled as such only when the first IFD is a preview of sub-IFD data; other TIFF-based RAW is labelled tiff and still decoded by any backend whose probe accepts it.
  • No public API is removed. The branch contains a removal commit followed by its revert; squash-merge, or drop both, to keep them out of history.
  • New: NativeLimits, FormatDetector.isStillImageBrand, fixtures test-video-rotated.mp4 and test-video-long-gop.mp4 with generator scripts.

Testing

  • macOS arm64, JDK 26: ./mvnw clean install — 270 tests, 0 failures, 32 skipped (Windows-only). example-consumer — 17 tests pass.
  • Not run locally: the Windows modules. WicImageReaderTest was updated for the new reader type without being run; CI needs to confirm it.
  • The AVFoundation track-transform read was exercised on arm64 only.

Follow-up outside this repo

panama-media 0.1.4: AVFoundation.getVideoInfo ignores the track's preferred transform, and getVideoInfo / extractFrame do not hold an autorelease pool. Both are worked around here.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VwoQ7k4zMHqQ43juZ2juRw

ghosthack and others added 7 commits November 13, 2026 18:47
Service discovery instantiates every installed backend on every platform.
Check the operating system before touching a platform's native bindings,
and register the Apple video backend through a lightweight wrapper that
only loads the AVFoundation bridge on macOS.

Run the example consumer as a named module, and drop ROUTING.md now that
the README carries the routing contract.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VwoQ7k4zMHqQ43juZ2juRw
The routing SPIs kept the decision made in canDecodeInput in a
thread-local and handed it to the next createReaderInstance call. A
caller that probed one input and then asked for a reader by format name
received the backend chosen for the earlier input.

Always return a deferred reader that selects its owner from the input
passed to setInput. RoutingImageReader now reports the owning backend
and forwards listeners and abort to the backend reader. The video
reader re-routes on each input unless it was bound to a backend.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VwoQ7k4zMHqQ43juZ2juRw
Apple and WIC return display-oriented images, but libvips and
ImageMagick returned the stored orientation. Because portable backends
win intersections by default, installing either one un-rotated phone
photos. libvips also disagreed with itself: reduced decodes go through
vips_thumbnail, which rotates, while full decodes did not.

Rotate full, cropped, and reduced decodes in both backends and report
display-oriented dimensions from the size queries. libvips reopens an
image with random access when it needs a transform, since rotation
cannot be streamed. The per-call downcall handle for the sequential
loader is now created once.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VwoQ7k4zMHqQ43juZ2juRw
AVFoundation applies the track's preferred transform when it extracts a
frame, but the reported size was the stored one, so a portrait video
reported 32x16 and returned a 16x32 frame. FFmpeg ignored the display
matrix altogether and returned the frame sideways, and a seek returned
the keyframe before the requested time rather than the frame at it.

Report the displayed size on both backends, rotate FFmpeg frames by the
display matrix, and decode forward from the keyframe to the requested
time. Drain an autorelease pool around the AVFoundation calls so
long-lived Java threads do not accumulate assets and generators.

Add rotated and long-GOP fixtures with their generator scripts.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VwoQ7k4zMHqQ43juZ2juRw
TIFF-based RAW formats were recognised by searching the first 4 KB for
"DNG", "Nikon", or "SONY", case-insensitively. A plain TIFF exported
from a camera JPEG, or one whose text happened to contain those
letters, was classified as RAW and bypassed any routing preference for
TIFF. Read the first IFD instead: DNG by its version tag, NEF and ARW
only when the make matches and the first IFD is a preview of sub-IFD
data.

Let a codec brand win over the generic HEIF brands so an AVIF or HEIC
file with a mif1 major brand keeps its codec's format, and share one
still-image brand list with video detection so Canon CR3 and JPEG XL
are no longer offered to video backends. Audio-only MP4 is skipped.

Read imageio.native.maxPixels in one place. libvips previously
hard-coded the limit, and the video reader kept its own copy of the
intermediate-size limit.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VwoQ7k4zMHqQ43juZ2juRw
Drop FormatDetector.matchesFtyp and matchesWebP, which nothing has
called since routing moved to the single format detector; the
javaNative flag on FormatRegistry.Format, which no code reads; and the
deprecated, unregistered PathAware stream aliases in video-common,
superseded by the ones in common.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VwoQ7k4zMHqQ43juZ2juRw
Bring back FormatDetector.matchesFtyp and matchesWebP, the javaNative
component of FormatRegistry.Format, and the deprecated PathAware stream
aliases in video-common. They stay part of the public API.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VwoQ7k4zMHqQ43juZ2juRw
@ghosthack
ghosthack merged commit af9262a into main Nov 14, 2026
3 checks passed
@ghosthack
ghosthack deleted the fix/review-findings branch November 14, 2026 05:02
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.

1 participant