@@ -18,25 +18,45 @@ use crate::tiff::{TiffError, TiffUnsupportedError};
1818///
1919#[ derive( Debug , Clone , Copy ) ]
2020pub struct PredictorInfo < ' a > {
21+ /// endianness
2122 pub endianness : Endianness ,
23+ /// width of the image in pixels
2224 pub image_width : u32 ,
25+ /// height of the image in pixels
2326 pub image_height : u32 ,
27+ /// chunk width in pixels
28+ ///
29+ /// If this is a stripped tiff, `chunk_width=image_width`
2430 pub chunk_width : u32 ,
31+ /// chunk height in pixels
2532 pub chunk_height : u32 ,
33+ /// bits per sample, as an array
34+ ///
35+ /// Can also be a single value, in which case it applies to all samples
2636 pub bits_per_sample : & ' a [ u16 ] , // maybe say that we only support a single bits_per_sample?
37+ /// number of samples per pixel
2738 pub samples_per_pixel : u16 ,
39+ /// sample format for each sample
40+ ///
41+ /// There is no decoding implementation in this crate (or libtiff) for mixed sample formats
2842 pub sample_format : & ' a [ SampleFormat ] , // and a single sample_format?
43+ /// planar configuration
44+ ///
45+ /// determines the bits per pixel
2946 pub planar_configuration : PlanarConfiguration ,
3047}
3148
3249impl PredictorInfo < ' _ > {
33- /// chunk height in pixels, taking padding into account
50+ /// chunk width in pixels, taking padding into account
3451 ///
3552 /// strips are considered image-width chunks
3653 ///
3754 /// # Example
3855 ///
3956 /// ```rust
57+ /// # use async_tiff::tiff::tags::{SampleFormat, PlanarConfiguration};
58+ /// # use async_tiff::reader::Endianness;
59+ /// # use async_tiff::PredictorInfo;
4060 /// let info = PredictorInfo {
4161 /// # endianness: Endianness::LittleEndian,
4262 /// image_width: 15,
@@ -47,10 +67,10 @@ impl PredictorInfo<'_> {
4767 /// # samples_per_pixel: 1,
4868 /// # sample_format: &[SampleFormat::IEEEFP],
4969 /// # planar_configuration: PlanarConfiguration::Chunky,
50- /// }
70+ /// };
5171 ///
52- /// assert_eq!(info.chunk_width_pixels(1).unwrap(), (7))
53- /// info.chunk_width_pixels(2).unwrap_err()
72+ /// assert_eq!(info.chunk_width_pixels(1).unwrap(), (7));
73+ /// info.chunk_width_pixels(2).unwrap_err();
5474 /// ```
5575 pub fn chunk_width_pixels ( & self , x : u32 ) -> AsyncTiffResult < u32 > {
5676 if x >= self . chunks_across ( ) {
@@ -66,6 +86,31 @@ impl PredictorInfo<'_> {
6686 }
6787 }
6888
89+ /// chunk height in pixels, taking padding into account
90+ ///
91+ /// strips are considered image-width chunks
92+ ///
93+ /// # Example
94+ ///
95+ /// ```rust
96+ /// # use async_tiff::tiff::tags::{SampleFormat, PlanarConfiguration};
97+ /// # use async_tiff::reader::Endianness;
98+ /// # use async_tiff::PredictorInfo;
99+ /// let info = PredictorInfo {
100+ /// # endianness: Endianness::LittleEndian,
101+ /// image_width: 15,
102+ /// image_height: 15,
103+ /// chunk_width: 8,
104+ /// chunk_height: 8,
105+ /// # bits_per_sample: &[32],
106+ /// # samples_per_pixel: 1,
107+ /// # sample_format: &[SampleFormat::IEEEFP],
108+ /// # planar_configuration: PlanarConfiguration::Chunky,
109+ /// };
110+ ///
111+ /// assert_eq!(info.chunk_height_pixels(1).unwrap(), (7));
112+ /// info.chunk_height_pixels(2).unwrap_err();
113+ /// ```
69114 pub fn chunk_height_pixels ( & self , y : u32 ) -> AsyncTiffResult < u32 > {
70115 if y >= self . chunks_down ( ) {
71116 Err ( crate :: error:: AsyncTiffError :: TileIndexError (
@@ -91,19 +136,27 @@ impl PredictorInfo<'_> {
91136 /// it to be a single value that applies to all samples.
92137 ///
93138 /// Libtiff and image-tiff do not support mixed bits per sample, but we give the possibility
139+ /// unless you also have PlanarConfiguration::Planar, at which point the first is taken
94140 pub fn bits_per_pixel ( & self ) -> usize {
95- if self . bits_per_sample . len ( ) == 1 {
96- self . samples_per_pixel as usize * self . bits_per_sample [ 0 ] as usize
97- } else {
98- assert_eq ! ( self . samples_per_pixel as usize , self . bits_per_sample. len( ) ) ;
99- self . bits_per_sample . iter ( ) . map ( |v| * v as usize ) . product ( )
141+ match self . planar_configuration {
142+ PlanarConfiguration :: Chunky => {
143+ if self . bits_per_sample . len ( ) == 1 {
144+ self . samples_per_pixel as usize * self . bits_per_sample [ 0 ] as usize
145+ } else {
146+ assert_eq ! ( self . samples_per_pixel as usize , self . bits_per_sample. len( ) ) ;
147+ self . bits_per_sample . iter ( ) . map ( |v| * v as usize ) . product ( )
148+ }
149+ }
150+ PlanarConfiguration :: Planar => self . bits_per_sample [ 0 ] as usize ,
100151 }
101152 }
102153
154+ /// The number of chunks in the horizontal (x) direction
103155 pub fn chunks_across ( & self ) -> u32 {
104156 self . image_width . div_ceil ( self . chunk_width )
105157 }
106158
159+ /// The number of chunks in the vertical (y) direction
107160 pub fn chunks_down ( & self ) -> u32 {
108161 self . image_height . div_ceil ( self . chunk_height )
109162 }
0 commit comments