fn expand_strip<'a>(
        &mut self,
        buffer: DecodingBuffer<'a>,
        offset: u32,
        length: u32,
        max_uncompressed_length: usize,
    ) -> TiffResult<usize> {
        let color_type = self.colortype()?;
        self.goto_offset(offset)?;
        let (bytes, mut reader): (usize, Box<EndianReader>) = match self.compression_method {
            CompressionMethod::None => {
                let order = self.reader.byte_order;
                (
                    usize::try_from(length)?,
                    Box::new(SmartReader::wrap(&mut self.reader, order)),
                )
            }
            CompressionMethod::LZW => {
                let (bytes, reader) = LZWReader::new(
                    &mut self.reader,
                    usize::try_from(length)?,
                    max_uncompressed_length * buffer.byte_len()
                )?;
                (bytes, Box::new(reader))
            }
            CompressionMethod::PackBits => {
                let order = self.reader.byte_order;
                let (bytes, reader) = PackBitsReader::new(
                    &mut self.reader,
                    order,
                    usize::try_from(length)?,
                )?;
                (bytes, Box::new(reader))
            }
            CompressionMethod::OldDeflate => {
                let (bytes, reader) = DeflateReader::new(&mut self.reader, max_uncompressed_length)?;
                (bytes, Box::new(reader))
            }
            method => {
                return Err(TiffError::UnsupportedError(
                    TiffUnsupportedError::UnsupportedCompressionMethod(method),
                ))
            }
        };

        if bytes / buffer.byte_len() > max_uncompressed_length {
            return Err(TiffError::FormatError(
                TiffFormatError::InconsistentSizesEncountered,
            ));
        }

        Ok(match (color_type, buffer) {
            (ColorType::RGB(8), DecodingBuffer::U8(ref mut buffer))
            | (ColorType::RGBA(8), DecodingBuffer::U8(ref mut buffer))
            | (ColorType::CMYK(8), DecodingBuffer::U8(ref mut buffer)) => {
                reader.read_exact(&mut buffer[..bytes])?;
                bytes
            }
            (ColorType::RGBA(16), DecodingBuffer::U16(ref mut buffer))
            | (ColorType::RGB(16), DecodingBuffer::U16(ref mut buffer))
            | (ColorType::CMYK(16), DecodingBuffer::U16(ref mut buffer)) => {
                reader.read_u16_into(&mut buffer[..bytes / 2])?;
                bytes / 2
            }
            (ColorType::RGBA(32), DecodingBuffer::U32(ref mut buffer))
            | (ColorType::RGB(32), DecodingBuffer::U32(ref mut buffer))
            | (ColorType::CMYK(32), DecodingBuffer::U32(ref mut buffer)) => {
                reader.read_u32_into(&mut buffer[..bytes / 4])?;
                bytes / 4
            }
            (ColorType::RGBA(64), DecodingBuffer::U64(ref mut buffer))
            | (ColorType::RGB(64), DecodingBuffer::U64(ref mut buffer))
            | (ColorType::CMYK(64), DecodingBuffer::U64(ref mut buffer)) => {
                reader.read_u64_into(&mut buffer[..bytes / 8])?;
                bytes / 8
            }
            (ColorType::Gray(64), DecodingBuffer::U64(ref mut buffer)) => {
                reader.read_u64_into(&mut buffer[..bytes / 8])?;
                if self.photometric_interpretation == PhotometricInterpretation::WhiteIsZero {
                    for datum in buffer[..bytes / 8].iter_mut() {
                        *datum = 0xffff_ffff_ffff_ffff - *datum
                    }
                }
                bytes / 8
            }
            (ColorType::Gray(32), DecodingBuffer::U32(ref mut buffer)) => {
                reader.read_u32_into(&mut buffer[..bytes / 4])?;
                if self.photometric_interpretation == PhotometricInterpretation::WhiteIsZero {
                    for datum in buffer[..bytes / 4].iter_mut() {
                        *datum = 0xffff_ffff - *datum
                    }
                }
                bytes / 4
            }
            (ColorType::Gray(16), DecodingBuffer::U16(ref mut buffer)) => {
                reader.read_u16_into(&mut buffer[..bytes / 2])?;
                if self.photometric_interpretation == PhotometricInterpretation::WhiteIsZero {
                    for datum in buffer[..bytes / 2].iter_mut() {
                        *datum = 0xffff - *datum
                    }
                }
                bytes / 2
            }
            (ColorType::Gray(n), DecodingBuffer::U8(ref mut buffer)) if n <= 8 => {
                reader.read_exact(&mut buffer[..bytes])?;
                if self.photometric_interpretation == PhotometricInterpretation::WhiteIsZero {
                    for byte in buffer[..bytes].iter_mut() {
                        *byte = 0xff - *byte
                    }
                }
                bytes
            }
            (type_, _) => {
                return Err(TiffError::UnsupportedError(
                    TiffUnsupportedError::UnsupportedColorType(type_),
                ))
            }
        })
    }
/// Decompresses the strip into the supplied buffer.
/// Returns the number of bytes read.
Decompresses the strip into the supplied buffer.
Returns the number of bytes read.
Decompresses the strip into the supplied buffer . Returns the number of bytes read .
fn expand_strip<'a>(
        &mut self,
        buffer: DecodingBuffer<'a>,
        offset: u32,
        length: u32,
        max_uncompressed_length: usize,
    ) -> TiffResult<usize> {
        let color_type = self.colortype()?;
        self.goto_offset(offset)?;
        let (bytes, mut reader): (usize, Box<EndianReader>) = match self.compression_method {
            CompressionMethod::None => {
                let order = self.reader.byte_order;
                (
                    usize::try_from(length)?,
                    Box::new(SmartReader::wrap(&mut self.reader, order)),
                )
            }
            CompressionMethod::LZW => {
                let (bytes, reader) = LZWReader::new(
                    &mut self.reader,
                    usize::try_from(length)?,
                    max_uncompressed_length * buffer.byte_len()
                )?;
                (bytes, Box::new(reader))
            }
            CompressionMethod::PackBits => {
                let order = self.reader.byte_order;
                let (bytes, reader) = PackBitsReader::new(
                    &mut self.reader,
                    order,
                    usize::try_from(length)?,
                )?;
                (bytes, Box::new(reader))
            }
            CompressionMethod::OldDeflate => {
                let (bytes, reader) = DeflateReader::new(&mut self.reader, max_uncompressed_length)?;
                (bytes, Box::new(reader))
            }
            method => {
                return Err(TiffError::UnsupportedError(
                    TiffUnsupportedError::UnsupportedCompressionMethod(method),
                ))
            }
        };
        if bytes / buffer.byte_len() > max_uncompressed_length {
            return Err(TiffError::FormatError(
                TiffFormatError::InconsistentSizesEncountered,
            ));
        }
        Ok(match (color_type, buffer) {
            (ColorType::RGB(8), DecodingBuffer::U8(ref mut buffer))
            | (ColorType::RGBA(8), DecodingBuffer::U8(ref mut buffer))
            | (ColorType::CMYK(8), DecodingBuffer::U8(ref mut buffer)) => {
                reader.read_exact(&mut buffer[..bytes])?;
                bytes
            }
            (ColorType::RGBA(16), DecodingBuffer::U16(ref mut buffer))
            | (ColorType::RGB(16), DecodingBuffer::U16(ref mut buffer))
            | (ColorType::CMYK(16), DecodingBuffer::U16(ref mut buffer)) => {
                reader.read_u16_into(&mut buffer[..bytes / 2])?;
                bytes / 2
            }
            (ColorType::RGBA(32), DecodingBuffer::U32(ref mut buffer))
            | (ColorType::RGB(32), DecodingBuffer::U32(ref mut buffer))
            | (ColorType::CMYK(32), DecodingBuffer::U32(ref mut buffer)) => {
                reader.read_u32_into(&mut buffer[..bytes / 4])?;
                bytes / 4
            }
            (ColorType::RGBA(64), DecodingBuffer::U64(ref mut buffer))
            | (ColorType::RGB(64), DecodingBuffer::U64(ref mut buffer))
            | (ColorType::CMYK(64), DecodingBuffer::U64(ref mut buffer)) => {
                reader.read_u64_into(&mut buffer[..bytes / 8])?;
                bytes / 8
            }
            (ColorType::Gray(64), DecodingBuffer::U64(ref mut buffer)) => {
                reader.read_u64_into(&mut buffer[..bytes / 8])?;
                if self.photometric_interpretation == PhotometricInterpretation::WhiteIsZero {
                    for datum in buffer[..bytes / 8].iter_mut() {
                        *datum = 0xffff_ffff_ffff_ffff - *datum
                    }
                }
                bytes / 8
            }
            (ColorType::Gray(32), DecodingBuffer::U32(ref mut buffer)) => {
                reader.read_u32_into(&mut buffer[..bytes / 4])?;
                if self.photometric_interpretation == PhotometricInterpretation::WhiteIsZero {
                    for datum in buffer[..bytes / 4].iter_mut() {
                        *datum = 0xffff_ffff - *datum
                    }
                }
                bytes / 4
            }
            (ColorType::Gray(16), DecodingBuffer::U16(ref mut buffer)) => {
                reader.read_u16_into(&mut buffer[..bytes / 2])?;
                if self.photometric_interpretation == PhotometricInterpretation::WhiteIsZero {
                    for datum in buffer[..bytes / 2].iter_mut() {
                        *datum = 0xffff - *datum
                    }
                }
                bytes / 2
            }
            (ColorType::Gray(n), DecodingBuffer::U8(ref mut buffer)) if n <= 8 => {
                reader.read_exact(&mut buffer[..bytes])?;
                if self.photometric_interpretation == PhotometricInterpretation::WhiteIsZero {
                    for byte in buffer[..bytes].iter_mut() {
                        *byte = 0xff - *byte
                    }
                }
                bytes
            }
            (type_, _) => {
                return Err(TiffError::UnsupportedError(
                    TiffUnsupportedError::UnsupportedColorType(type_),
                ))
            }
        })
    }
fn expand_strip < ' a > ( & mut self , buffer : DecodingBuffer < ' a > , offset : u32 , length : u32 , max_uncompressed_length : usize , ) -> TiffResult < usize > { let color_type = self . colortype ( ) ? ; self . goto_offset ( offset ) ? ; let ( bytes , mut reader ) : ( usize , Box < EndianReader > ) = match self . compression_method { CompressionMethod :: None => { let order = self . reader . byte_order ; ( usize :: try_from ( length ) ? , Box :: new ( SmartReader :: wrap ( & mut self . reader , order ) ) , ) } CompressionMethod :: LZW => { let ( bytes , reader ) = LZWReader :: new ( & mut self . reader , usize :: try_from ( length ) ? , max_uncompressed_length * buffer . byte_len ( ) ) ? ; ( bytes , Box :: new ( reader ) ) } CompressionMethod :: PackBits => { let order = self . reader . byte_order ; let ( bytes , reader ) = PackBitsReader :: new ( & mut self . reader , order , usize :: try_from ( length ) ? , ) ? ; ( bytes , Box :: new ( reader ) ) } CompressionMethod :: OldDeflate => { let ( bytes , reader ) = DeflateReader :: new ( & mut self . reader , max_uncompressed_length ) ? ; ( bytes , Box :: new ( reader ) ) } method => { return Err ( TiffError :: UnsupportedError ( TiffUnsupportedError :: UnsupportedCompressionMethod ( method ) , ) ) } } ; if bytes / buffer . byte_len ( ) > max_uncompressed_length { return Err ( TiffError :: FormatError ( TiffFormatError :: InconsistentSizesEncountered , ) ) ; } Ok ( match ( color_type , buffer ) { ( ColorType :: RGB ( 8 ) , DecodingBuffer :: U8 ( ref mut buffer ) ) | ( ColorType :: RGBA ( 8 ) , DecodingBuffer :: U8 ( ref mut buffer ) ) | ( ColorType :: CMYK ( 8 ) , DecodingBuffer :: U8 ( ref mut buffer ) ) => { reader . read_exact ( & mut buffer [ .. bytes ] ) ? ; bytes } ( ColorType :: RGBA ( 16 ) , DecodingBuffer :: U16 ( ref mut buffer ) ) | ( ColorType :: RGB ( 16 ) , DecodingBuffer :: U16 ( ref mut buffer ) ) | ( ColorType :: CMYK ( 16 ) , DecodingBuffer :: U16 ( ref mut buffer ) ) => { reader . read_u16_into ( & mut buffer [ .. bytes / 2 ] ) ? ; bytes / 2 } ( ColorType :: RGBA ( 32 ) , DecodingBuffer :: U32 ( ref mut buffer ) ) | ( ColorType :: RGB ( 32 ) , DecodingBuffer :: U32 ( ref mut buffer ) ) | ( ColorType :: CMYK ( 32 ) , DecodingBuffer :: U32 ( ref mut buffer ) ) => { reader . read_u32_into ( & mut buffer [ .. bytes / 4 ] ) ? ; bytes / 4 } ( ColorType :: RGBA ( 64 ) , DecodingBuffer :: U64 ( ref mut buffer ) ) | ( ColorType :: RGB ( 64 ) , DecodingBuffer :: U64 ( ref mut buffer ) ) | ( ColorType :: CMYK ( 64 ) , DecodingBuffer :: U64 ( ref mut buffer ) ) => { reader . read_u64_into ( & mut buffer [ .. bytes / 8 ] ) ? ; bytes / 8 } ( ColorType :: Gray ( 64 ) , DecodingBuffer :: U64 ( ref mut buffer ) ) => { reader . read_u64_into ( & mut buffer [ .. bytes / 8 ] ) ? ; if self . photometric_interpretation == PhotometricInterpretation :: WhiteIsZero { for datum in buffer [ .. bytes / 8 ] . iter_mut ( ) { * datum = 0xffff_ffff_ffff_ffff - * datum } } bytes / 8 } ( ColorType :: Gray ( 32 ) , DecodingBuffer :: U32 ( ref mut buffer ) ) => { reader . read_u32_into ( & mut buffer [ .. bytes / 4 ] ) ? ; if self . photometric_interpretation == PhotometricInterpretation :: WhiteIsZero { for datum in buffer [ .. bytes / 4 ] . iter_mut ( ) { * datum = 0xffff_ffff - * datum } } bytes / 4 } ( ColorType :: Gray ( 16 ) , DecodingBuffer :: U16 ( ref mut buffer ) ) => { reader . read_u16_into ( & mut buffer [ .. bytes / 2 ] ) ? ; if self . photometric_interpretation == PhotometricInterpretation :: WhiteIsZero { for datum in buffer [ .. bytes / 2 ] . iter_mut ( ) { * datum = 0xffff - * datum } } bytes / 2 } ( ColorType :: Gray ( n ) , DecodingBuffer :: U8 ( ref mut buffer ) ) if n <= 8 => { reader . read_exact ( & mut buffer [ .. bytes ] ) ? ; if self . photometric_interpretation == PhotometricInterpretation :: WhiteIsZero { for byte in buffer [ .. bytes ] . iter_mut ( ) { * byte = 0xff - * byte } } bytes } ( type_ , _ ) => { return Err ( TiffError :: UnsupportedError ( TiffUnsupportedError :: UnsupportedColorType ( type_ ) , ) ) } } ) }
Decompresses the strip into the supplied buffer.
Decompresses the strip into the supplied buffer .
&mut self
buffer
DecodingBuffer<'a>
offset
u32
length
u32
max_uncompressed_length
usize
&mut self
buffer
DecodingBuffer<'a>
offset
u32
length
u32
max_uncompressed_length
usize