Return buffer layout as a struct
Prepares extensibility for the eventual case of supporting multi-planar image layouts that are to be written into a multi-planar buffer as indicated by the caller in some way (possibly not via read_*_bytes but a method taking a wrapper around the output buffer instead). Through the struct we can later add an indicator that can be used by the caller to decide between methods of fetching the pixel data as appropriate.
This commit is contained in:
1 parent
c370ac4b92
commit
48d52bed9b
3 files changed
+73
-18
No files matched your search
@@ -10,6 +10,7 @@ use crate::{
|
||||
ColorType, Directory, TiffError, TiffFormatError, TiffResult, TiffUnsupportedError, UsageError,
|
||||
};
|
||||
use std::io::{self, Cursor, Read, Seek};
|
||||
use std::num::NonZeroUsize;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -363,6 +364,22 @@ impl Image {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn minimum_row_stride(&self, dims: (u32, u32)) -> Option<NonZeroUsize> {
|
||||
let (width, height) = dims;
|
||||
|
||||
let row_stride = u64::from(width)
|
||||
.saturating_mul(self.samples_per_pixel() as u64)
|
||||
.saturating_mul(self.bits_per_sample as u64)
|
||||
.div_ceil(8);
|
||||
|
||||
// Note: row stride should be smaller than the len if we have an actual buffer. If there
|
||||
// are no pixels in the buffer (height _or_ width is 0) then the stride is not well defined
|
||||
// and we return `None`.
|
||||
(height > 0)
|
||||
.then_some(row_stride as usize)
|
||||
.and_then(NonZeroUsize::new)
|
||||
}
|
||||
|
||||
fn create_reader<'r, R: 'r + Read>(
|
||||
reader: R,
|
||||
compression_method: CompressionMethod,
|
||||
|
||||
Reference in new issue
Block a user