Repository navigation
Add probe mode to efficiently detect UltraHDR images - #6
Conversation
Implements a new probe() function that efficiently validates if an image is UltraHDR by checking for required components (primary image, gain map, metadata) without full decoding. Returns structured results useful for batch processing and filtering. Features: - Never throws - always returns an UltraHdrProbeResult - Checks JPEG magic bytes first for early return on non-JPEGs - Provides detailed flags: isValid, hasPrimaryImage, hasGainMap, hasMetadata - Extracts dimensions, HDR capacity, and metadata version when available - Reuses existing parsing infrastructure (no image decompression) Files changed: - wasm/src/types.rs: Add UltraHdrProbeResult struct - wasm/src/ultrahdr/decoder.rs: Add probe() function + tests - wasm/src/ultrahdr/mod.rs: Export probe - wasm/src/lib.rs: Add WASM binding probeUltraHdr - js/src/types.ts: Add TypeScript interface - js/src/index.ts: Add async wrapper and exports - js/__tests__/probe.test.ts: Add 11 test cases Closes #5 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
📝 WalkthroughWalkthroughAdds a probe mode that inspects image buffers for UltraHDR components without full decoding, exposing a new JS API Changes
Sequence DiagramsequenceDiagram
participant Client
participant JS_API as JS API
participant WASM as WASM Module
participant Decoder as Decoder
Client->>JS_API: probeUltraHdr(buffer: ArrayBuffer)
JS_API->>WASM: call probeUltraHdr(buffer: Uint8Array)
WASM->>Decoder: probe(data: &[u8])
Decoder->>Decoder: quick JPEG validation & parse segments
Decoder->>Decoder: extract primary image dimensions
Decoder->>Decoder: detect XMP metadata
Decoder->>Decoder: probe for gain map (MPF or second JPEG)
Decoder-->>WASM: UltraHdrProbeResult
WASM-->>JS_API: UltraHdrProbeResult
JS_API-->>Client: resolve Promise<UltraHdrProbeResult>
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Fix all issues with AI agents
In `@js/__tests__/probe.test.ts`:
- Around line 1-145: Prettier formatting errors in the test file are causing CI
failures; run Prettier on this file (or the whole repo) to apply the project's
formatting rules and commit the changes. Specifically, format
js/__tests__/probe.test.ts (which contains tests referencing probeUltraHdr,
base64ToArrayBuffer, REGULAR_JPEG_BASE64, PNG_HEADER_BASE64) using your
project's Prettier config (e.g., npx prettier --write js/__tests__/probe.test.ts
or yarn prettier --write) and push the formatted file so the CI Prettier check
passes.
In `@wasm/src/ultrahdr/decoder.rs`:
- Around line 465-481: Replace the tautological Clippy-triggering assertion in
test_probe_never_panics: instead of asserting "result.width == 0 || result.width
> 0", assert that probe returned the expected zero width for these non-JPEG
inputs (e.g., assert_eq!(result.width, 0) or assert!(result.width == 0)); locate
this in the test function test_probe_never_panics and use the probe return value
(result.width) to make a meaningful check (you can also assert result.height ==
0 if appropriate).
- Around line 73-88: In probe_for_gain_map, the u32->usize casts for offset and
size can overflow on wasm32 and cause a slice panic; update the MPF branch
(where mpf_segment is handled and parse_mpf_for_gainmap returns (offset, size))
to perform checked arithmetic: convert to usize only after using checked_add (or
checked_add on usize) to ensure offset.checked_add(size) succeeds, and if it
returns None skip the MPF branch instead of slicing; ensure the subsequent
JpegParser::parse/gm dimensions logic only runs when the checked bounds test
passes.
- Run Prettier on probe.test.ts to fix formatting - Fix tautological assertion in decoder.rs test (Clippy) - Add checked arithmetic for potential overflow on wasm32 (Clippy) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@wasm/src/ultrahdr/decoder.rs`:
- Around line 25-37: The code sets result.has_primary_image before confirming
the JPEG structure, so if JpegParser::parse(data) fails you incorrectly report a
primary image; move the assignment of result.has_primary_image = true to after
the successful match arm of JpegParser::parse (i.e., only set it once you have
Ok(p)), leaving the initial magic-byte check as an early non-primary exit and
ensuring the Err(_) branch returns without mutating has_primary_image.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Summary
probeUltraHdr()function that efficiently validates if an image is UltraHDR by checking for required components (primary image, gain map, metadata) without full decodingUltraHdrProbeResultwith detailed information useful for batch processing and filteringFeatures
The probe result includes:
isValid- Whether image has all required UltraHDR componentshasPrimaryImage- Whether a valid JPEG was foundhasGainMap- Whether a gain map image was foundhasMetadata- Whether XMP gain map metadata was foundwidth,height- Primary image dimensions (0 if not found)gainMapWidth,gainMapHeight- Gain map dimensions (0 if not found)hdrCapacity- HDR capacity in stops (0 if not found)metadataVersion- Metadata version string (empty if not found)Example Usage
Test plan
Closes #5
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Tests
✏️ Tip: You can customize this high-level summary in your review settings.