exr: Support reading and writing Luma<f32> images - #3066
Conversation
|
Given that you made 9 PRs to 8 repos in the last hour, I'll assume that all of this is AI-generated, correct? If so, then I'm not sure whether we should accept this. "Good first issue" issues aren't supposed to be fodder for AI agents but starting points for humans. @197g What's your take on this? |
|
Sure, I'd prefer them to be non-AI but it's not dogmatic either in that I suppose some newer programmers just do that nowadays so that is the shape of their first contribution. I'd say the problem here is the LLM'ism of the code itself. The code needs a bit of structural thought but instead gets pure repetition. Firstly, LumaA is maybe out-of-scope but that's different from more or less ignoring its existence. That is, if it's not supported to decode that plane and tack it on then there should be an error to avoid behavior change in the future when it gets added. (Note the exclusion is partly an artifact of missing Secondly, I have a parse-don't-validate concern. While parsing the header there's a boolean flag that decides Rgba vs. Luma decoding based on available channels that was tacked on to the existing |
|
Fair question, and yes I used AI assistance on these. I do review, test, and stand behind what I send, but I hear the concern, especially on good-first-issues. If AI-assisted PRs aren't welcome here, I completely understand - say the word and I'll close it. On the substance, @197g:
Update incoming - happy to iterate. |
Replace the loose `is_luma`/`alpha_present_in_file` booleans with a private `ExrColorLayout` enum (Rgb/Rgba/Luma) that captures the color decision made while parsing the selected header exactly once. The enum retains the parsed channel indices; `prepare_image` and `read_image` consume this decision instead of re-inspecting channels, and decoding resolves those indices to the channel names it reads so the header is never re-interpreted in a different way. Detect luma-plus-alpha (`Y` + `A`) images during parsing and return an unsupported-color error (`La32F`) instead of silently dropping the alpha plane, so that adding `LumaA<f32>` decoding later is an additive change rather than a behavior change.
|
@197g Sorry for the long silence - I pushed these changes in e93a978 the same day and then never actually said so here. Both of your points are addressed: LumaA is no longer silently dropped. A header carrying Parse, don't validate. Happy to rework it if the shape isn't what you had in mind. |
Closes #3016.
The OpenEXR codec previously only handled RGB/RGBA float images, so saving a
Luma<f32>image (e.g.ImageBuffer::from_fn(w, h, |x, y| Luma([...]))) failed with an unsupported-color error.This adds read and write support for single-channel luma. The encoder writes a single
Ychannel, as recommended by the OpenEXR specification. The decoder looks for aYchannel and decodes it asLuma<f32>; when a file contains both RGB andYchannels it still prefers RGB/RGBA, so existing behavior is unchanged.Luma + alpha is intentionally out of scope, as noted in the issue.
Tested with a roundtrip (
roundtrip_luma): generate aLuma<f32>image, encode it to an in-memory EXR, decode it back, and compare — mirroring the existingroundtrip_rgb/roundtrip_rgbatests.