Sample types in layouts, resize DecoderResult

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.
This commit is contained in:
A. Molzer committed 2025-12-28 21:06:59 +01:00
1 parent af8a8d660f
commit 6d56d014a1
3 files changed
+163 -73

No files matched your search

+6 -1
View File
@@ -10,12 +10,17 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let io = std::io::BufReader::new(file);
let mut reader = Decoder::new(io)?;
let mut data = DecodingResult::I8(vec![]);
let limits = tiff::decoder::Limits::unlimited();
for i in 0u32.. {
let layout = reader.image_buffer_layout()?;
let colortype = reader.colortype()?;
let dimensions = reader.dimensions()?;
let mut data = reader.read_image()?;
data.resize_to(&layout, &limits)?;
reader.read_image_bytes(data.as_buffer(0).as_bytes_mut())?;
debug_planes(i, &mut data, &layout, &colortype, dimensions);
if !reader.more_images() {