Skip to content

Implement support for planar data#313

Merged
197g merged 19 commits intomainfrom
decode-planar-data
Dec 29, 2025
Merged

Implement support for planar data#313
197g merged 19 commits intomainfrom
decode-planar-data

Conversation

@197g
Copy link
Member

@197g 197g commented Nov 27, 2025

Draft because the interface is a bit odd.

  • read_image_bytes is enhanced to read additional planes if the buffer is large enough.
  • PreferredBufferLayout is augmented with fields to describe those additional requirements, with the compatibility that previous fields encode only the first plane. This should be changed in a next major version.
  • All the layout computation is moved into image.rs so we have one source of truth for the layout of sub-byte color components, planes, chunk sizes, and strides. All relevant values are computed in one function and then used.
  • expand_chunk is prepared for custom strides which it previously supported in a parameter but that would not scale to multiple planes; also support did not seem consistent? It was not exercised in the public interface and I would not have trusted that..
  • TODO: reading multiple chunks belonging to different planes of the same basic chunk. The interface is a bit odd since we may have a basic chunk index but if that is not on the first plane, should we then extract planes from that onwards (however much buffer space is available) or should plane selection be more explicit? Also thinking about subsampling here.. Maybe it should not be provided yet.

197g added 11 commits November 12, 2025 23:42
We currently have one type in decoder/image.rs and another in
decoder/mod.rs which each contributes part of the computation for laying
out the output buffer. Confusingly though they rely on shared
implementation details such as determining the number of channels that
are written and their bit depth. We should have one shared method and
resulting struct instead.
197g added 3 commits December 10, 2025 21:59
This is well-defined even if we add sub-sampling support later on. We
can adjust the layout type accordingly with factors per each plane. Note
that the layout, in theory, does not depend on the index of the unit if
we describe all planes for a multi-planar layout. The specification
requires that the subsampling factors divide the tile sizes. However we
have to handle non-planar images here and this leaves us open to other
potential parameters.
@197g 197g marked this pull request as ready for review December 28, 2025 16:22
197g added 4 commits December 28, 2025 18:48
By adding the type interpretation to `BufferLayoutPreference` (simply
computed from the same fields that are trivial to fetch in
`ReadoutLayout` with the rest) we can allocate an appropriate
`DecoderResult` without any `Decoder` instance. We still want a Limits
instance though. This lets a caller read _typed_ data from the `_bytes`
methods which perform less allocations. It also lets them read multiple
planes in a more convenient interface. See, `read_image` will keep its
planar treatment bug for a little bit so you don't accidentally break
during an upgrade.

This also implies less code is being monomorphized, just a bonus.
We previously handed it a wrapper that was supposedly type-safe but
really internally cast the buffer to bytes. That was rather pointless as
the `_bytes` method could always be used instead. We replace the
semantics by a utility which allocates an appropriate buffer with the
internal limits, wrapping the exact sequence identified previously in
the example as a pattern.
@197g
Copy link
Member Author

197g commented Dec 28, 2025

Hm, I wasn't aware we made use of read_image that much. So maybe a soft-deprecation in documentation alone is a better way for now and schedule a harder one for later.

@197g 197g merged commit 355ecc8 into main Dec 29, 2025
15 checks passed
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