| 1 | pub use tiff_valuerust-analyzer cargo tiff 0.11.3 encoder/tiff_value/::*; |
| 2 | |
| 3 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{ |
| 4 | cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/, |
| 5 | iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::{selfrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/, Seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#, Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#}, |
| 6 | markerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/::PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#, |
| 7 | memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/, |
| 8 | numrust-analyzer cargo std https://github.com/rust-lang/rust/library/std num/::{NonZeroU64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU64#, TryFromIntErrorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/error/TryFromIntError#}, |
| 9 | }; |
| 10 | |
| 11 | use craterust-analyzer cargo tiff 0.11.3 crate/::{ |
| 12 | decoderrust-analyzer cargo tiff 0.11.3 decoder/::ifdrust-analyzer cargo tiff 0.11.3 decoder/ifd/::Entryrust-analyzer cargo tiff 0.11.3 decoder/ifd/Entry#, |
| 13 | errorrust-analyzer cargo tiff 0.11.3 error/::{TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#, UsageErrorrust-analyzer cargo tiff 0.11.3 error/UsageError#}, |
| 14 | tagsrust-analyzer cargo tiff 0.11.3 tags/::{ |
| 15 | ByteOrderrust-analyzer cargo tiff 0.11.3 tags/ByteOrder#, CompressionMethodrust-analyzer cargo tiff 0.11.3 tags/CompressionMethod#, ExtraSamplesrust-analyzer cargo tiff 0.11.3 tags/ExtraSamples#, IfdPointerrust-analyzer cargo tiff 0.11.3 tags/IfdPointer#, PhotometricInterpretationrust-analyzer cargo tiff 0.11.3 tags/PhotometricInterpretation#, |
| 16 | ResolutionUnitrust-analyzer cargo tiff 0.11.3 tags/ResolutionUnit#, SampleFormatrust-analyzer cargo tiff 0.11.3 tags/SampleFormat#, Tagrust-analyzer cargo tiff 0.11.3 tags/Tag#, Typerust-analyzer cargo tiff 0.11.3 tags/Type#, ValueBufferrust-analyzer cargo tiff 0.11.3 tags/ValueBuffer#, |
| 17 | }, |
| 18 | Directoryrust-analyzer cargo tiff 0.11.3 directory/Directory#, TiffErrorrust-analyzer cargo tiff 0.11.3 error/TiffError#, TiffFormatErrorrust-analyzer cargo tiff 0.11.3 error/TiffFormatError#, |
| 19 | }; |
| 20 | |
| 21 | pub mod colortyperust-analyzer cargo tiff 0.11.3 encoder/colortype/; |
| 22 | pub mod compressionrust-analyzer cargo tiff 0.11.3 encoder/compression/; |
| 23 | mod tiff_valuerust-analyzer cargo tiff 0.11.3 encoder/tiff_value/; |
| 24 | mod writerrust-analyzer cargo tiff 0.11.3 encoder/writer/; |
| 25 | |
| 26 | use selfrust-analyzer cargo tiff 0.11.3 encoder/::colortyperust-analyzer cargo tiff 0.11.3 encoder/colortype/::*; |
| 27 | use selfrust-analyzer cargo tiff 0.11.3 encoder/::compressionrust-analyzer cargo tiff 0.11.3 encoder/compression/::Compressionrust-analyzer cargo tiff 0.11.3 encoder/compression/Compression# as Comprust-analyzer cargo tiff 0.11.3 encoder/compression/Compression#; |
| 28 | use selfrust-analyzer cargo tiff 0.11.3 encoder/::compressionrust-analyzer cargo tiff 0.11.3 encoder/compression/::*; |
| 29 | use selfrust-analyzer cargo tiff 0.11.3 encoder/::writerrust-analyzer cargo tiff 0.11.3 encoder/writer/::*; |
| 30 | |
| 31 | /// Type of prediction to prepare the image with. |
| 32 | /// |
| 33 | /// Image data can be very unpredictable, and thus very hard to compress. Predictors are simple |
| 34 | /// passes ran over the image data to prepare it for compression. This is mostly used for LZW |
| 35 | /// compression, where using [Predictor::Horizontal] we see a 35% improvement in compression |
| 36 | /// ratio over the unpredicted compression ! |
| 37 | /// |
| 38 | /// [Predictor::FloatingPoint] is currently not supported. |
| 39 | pub type Predictorrust-analyzer cargo tiff 0.11.3 encoder/Predictor# = craterust-analyzer cargo tiff 0.11.3 crate/::tagsrust-analyzer cargo tiff 0.11.3 tags/::Predictorrust-analyzer cargo tiff 0.11.3 tags/Predictor#; |
| 40 | #[cfg(feature = "deflate")] |
| 41 | pub type DeflateLevelrust-analyzer cargo tiff 0.11.3 encoder/DeflateLevel# = compressionrust-analyzer cargo tiff 0.11.3 encoder/compression/::DeflateLevelrust-analyzer cargo tiff 0.11.3 encoder/compression/deflate/DeflateLevel#; |
| 42 | |
| 43 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)] |
| 44 | pub enum Compressionrust-analyzer cargo tiff 0.11.3 encoder/Compression# { |
| 45 | #[defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/default:] |
| 46 | Uncompressedrust-analyzer cargo tiff 0.11.3 encoder/Compression#Uncompressed#, |
| 47 | #[cfg(feature = "lzw")] |
| 48 | Lzwrust-analyzer cargo tiff 0.11.3 encoder/Compression#Lzw#, |
| 49 | #[cfg(feature = "deflate")] |
| 50 | Deflaterust-analyzer cargo tiff 0.11.3 encoder/Compression#Deflate#(DeflateLevelrust-analyzer cargo tiff 0.11.3 encoder/DeflateLevel#), |
| 51 | Packbitsrust-analyzer cargo tiff 0.11.3 encoder/Compression#Packbits#, |
| 52 | } |
| 53 | |
| 54 | impl Compressionrust-analyzer cargo tiff 0.11.3 encoder/Compression# { |
| 55 | fn tagrust-analyzer cargo tiff 0.11.3 encoder/impl#[Compression]tag().(&self) -> CompressionMethodrust-analyzer cargo tiff 0.11.3 tags/CompressionMethod# { |
| 56 | match self { |
| 57 | Compressionrust-analyzer cargo tiff 0.11.3 encoder/Compression#::Uncompressedrust-analyzer cargo tiff 0.11.3 encoder/Compression#Uncompressed# => CompressionMethodrust-analyzer cargo tiff 0.11.3 tags/CompressionMethod#::Nonerust-analyzer cargo tiff 0.11.3 tags/CompressionMethod#None#, |
| 58 | #[cfg(feature = "lzw")] |
| 59 | Compressionrust-analyzer cargo tiff 0.11.3 encoder/Compression#::Lzwrust-analyzer cargo tiff 0.11.3 encoder/Compression#Lzw# => CompressionMethodrust-analyzer cargo tiff 0.11.3 tags/CompressionMethod#::LZWrust-analyzer cargo tiff 0.11.3 tags/CompressionMethod#LZW#, |
| 60 | #[cfg(feature = "deflate")] |
| 61 | Compressionrust-analyzer cargo tiff 0.11.3 encoder/Compression#::Deflaterust-analyzer cargo tiff 0.11.3 encoder/Compression#Deflate#(_) => CompressionMethodrust-analyzer cargo tiff 0.11.3 tags/CompressionMethod#::Deflaterust-analyzer cargo tiff 0.11.3 tags/CompressionMethod#Deflate#, |
| 62 | Compressionrust-analyzer cargo tiff 0.11.3 encoder/Compression#::Packbitsrust-analyzer cargo tiff 0.11.3 encoder/Compression#Packbits# => CompressionMethodrust-analyzer cargo tiff 0.11.3 tags/CompressionMethod#::PackBitsrust-analyzer cargo tiff 0.11.3 tags/CompressionMethod#PackBits#, |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | fn get_algorithmrust-analyzer cargo tiff 0.11.3 encoder/impl#[Compression]get_algorithm().(&self) -> Compressorrust-analyzer cargo tiff 0.11.3 encoder/compression/Compressor# { |
| 67 | match self { |
| 68 | Compressionrust-analyzer cargo tiff 0.11.3 encoder/Compression#::Uncompressedrust-analyzer cargo tiff 0.11.3 encoder/Compression#Uncompressed# => compressionrust-analyzer cargo tiff 0.11.3 encoder/compression/::Uncompressedrust-analyzer cargo tiff 0.11.3 encoder/compression/uncompressed/Uncompressed# {}.get_algorithmrust-analyzer cargo tiff 0.11.3 encoder/compression/uncompressed/impl#[Uncompressed][Compression]get_algorithm().(), |
| 69 | #[cfg(feature = "lzw")] |
| 70 | Compressionrust-analyzer cargo tiff 0.11.3 encoder/Compression#::Lzwrust-analyzer cargo tiff 0.11.3 encoder/Compression#Lzw# => compressionrust-analyzer cargo tiff 0.11.3 encoder/compression/::Lzwrust-analyzer cargo tiff 0.11.3 encoder/compression/lzw/Lzw# {}.get_algorithmrust-analyzer cargo tiff 0.11.3 encoder/compression/lzw/impl#[Lzw][Compression]get_algorithm().(), |
| 71 | #[cfg(feature = "deflate")] |
| 72 | Compressionrust-analyzer cargo tiff 0.11.3 encoder/Compression#::Deflaterust-analyzer cargo tiff 0.11.3 encoder/Compression#Deflate#(level) => compressionrust-analyzer cargo tiff 0.11.3 encoder/compression/::Deflaterust-analyzer cargo tiff 0.11.3 encoder/compression/deflate/Deflate#::with_levelrust-analyzer cargo tiff 0.11.3 encoder/compression/deflate/impl#[Deflate]with_level().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().level).get_algorithmrust-analyzer cargo tiff 0.11.3 encoder/compression/deflate/impl#[Deflate][Compression]get_algorithm().(), |
| 73 | Compressionrust-analyzer cargo tiff 0.11.3 encoder/Compression#::Packbitsrust-analyzer cargo tiff 0.11.3 encoder/Compression#Packbits# => compressionrust-analyzer cargo tiff 0.11.3 encoder/compression/::Packbitsrust-analyzer cargo tiff 0.11.3 encoder/compression/packbits/Packbits# {}.get_algorithmrust-analyzer cargo tiff 0.11.3 encoder/compression/packbits/impl#[Packbits][Compression]get_algorithm().(), |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | /// Encoder for Tiff and BigTiff files. |
| 79 | /// |
| 80 | /// With this type you can get a [`DirectoryEncoder`] or a [`ImageEncoder`] |
| 81 | /// to encode Tiff/BigTiff ifd directories with images. |
| 82 | /// |
| 83 | /// See [`DirectoryEncoder`] and [`ImageEncoder`]. |
| 84 | /// |
| 85 | /// # Examples |
| 86 | /// ``` |
| 87 | /// # extern crate tiff; |
| 88 | /// # fn main() { |
| 89 | /// # let mut file = std::io::Cursor::new(Vec::new()); |
| 90 | /// # let image_data = vec![0; 100*100*3]; |
| 91 | /// use tiff::encoder::*; |
| 92 | /// |
| 93 | /// // create a standard Tiff file |
| 94 | /// let mut tiff = TiffEncoder::new(&mut file).unwrap(); |
| 95 | /// tiff.write_image::<colortype::RGB8>(100, 100, &image_data).unwrap(); |
| 96 | /// |
| 97 | /// // create a BigTiff file |
| 98 | /// let mut bigtiff = TiffEncoder::new_big(&mut file).unwrap(); |
| 99 | /// bigtiff.write_image::<colortype::RGB8>(100, 100, &image_data).unwrap(); |
| 100 | /// |
| 101 | /// # } |
| 102 | /// ``` |
| 103 | pub struct TiffEncoderrust-analyzer cargo tiff 0.11.3 encoder/TiffEncoder#<W, K: TiffKindrust-analyzer cargo tiff 0.11.3 encoder/TiffKind# = TiffKindStandardrust-analyzer cargo tiff 0.11.3 encoder/TiffKindStandard#> { |
| 104 | writerrust-analyzer cargo tiff 0.11.3 encoder/TiffEncoder#writer.: TiffWriterrust-analyzer cargo tiff 0.11.3 encoder/writer/TiffWriter#<W>, |
| 105 | kindrust-analyzer cargo tiff 0.11.3 encoder/TiffEncoder#kind.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#<K>, |
| 106 | predictorrust-analyzer cargo tiff 0.11.3 encoder/TiffEncoder#predictor.: Predictorrust-analyzer cargo tiff 0.11.3 encoder/Predictor#, |
| 107 | compressionrust-analyzer cargo tiff 0.11.3 encoder/TiffEncoder#compression.: Compressionrust-analyzer cargo tiff 0.11.3 encoder/Compression#, |
| 108 | /// The offset of the last main image directory's `next` field. |
| 109 | last_ifd_chainrust-analyzer cargo tiff 0.11.3 encoder/TiffEncoder#last_ifd_chain.: NonZeroU64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU64#, |
| 110 | } |
| 111 | |
| 112 | /// Constructor functions to create standard Tiff files. |
| 113 | impl<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write# + Seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#> TiffEncoderrust-analyzer cargo tiff 0.11.3 encoder/TiffEncoder#<W> { |
| 114 | /// Creates a new encoder for standard Tiff files. |
| 115 | /// |
| 116 | /// To create BigTiff files, use [`new_big`][TiffEncoder::new_big] or |
| 117 | /// [`new_generic`][TiffEncoder::new_generic]. |
| 118 | pub fn newrust-analyzer cargo tiff 0.11.3 encoder/impl#[`TiffEncoder<W>`]new().(writer: W) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<TiffEncoderrust-analyzer cargo tiff 0.11.3 encoder/TiffEncoder#<W, TiffKindStandardrust-analyzer cargo tiff 0.11.3 encoder/TiffKindStandard#>> { |
| 119 | TiffEncoderrust-analyzer cargo tiff 0.11.3 encoder/TiffEncoder#::new_genericrust-analyzer cargo tiff 0.11.3 encoder/impl#[`TiffEncoder<W, K>`]new_generic().(writer) |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | /// Constructor functions to create BigTiff files. |
| 124 | impl<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write# + Seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#> TiffEncoderrust-analyzer cargo tiff 0.11.3 encoder/TiffEncoder#<W, TiffKindBigrust-analyzer cargo tiff 0.11.3 encoder/TiffKindBig#> { |
| 125 | /// Creates a new encoder for BigTiff files. |
| 126 | /// |
| 127 | /// To create standard Tiff files, use [`new`][TiffEncoder::new] or |
| 128 | /// [`new_generic`][TiffEncoder::new_generic]. |
| 129 | pub fn new_bigrust-analyzer cargo tiff 0.11.3 encoder/impl#[`TiffEncoder<W, TiffKindBig>`]new_big().(writer: W) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<Selfrust-analyzer cargo tiff 0.11.3 encoder/impl#[`TiffEncoder<W, TiffKindBig>`]> { |
| 130 | TiffEncoderrust-analyzer cargo tiff 0.11.3 encoder/TiffEncoder#::new_genericrust-analyzer cargo tiff 0.11.3 encoder/impl#[`TiffEncoder<W, K>`]new_generic().(writer) |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | /// Generic functions that are available for both Tiff and BigTiff encoders. |
| 135 | impl<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write# + Seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#, K: TiffKindrust-analyzer cargo tiff 0.11.3 encoder/TiffKind#> TiffEncoderrust-analyzer cargo tiff 0.11.3 encoder/TiffEncoder#<W, K> { |
| 136 | /// Creates a new Tiff or BigTiff encoder, inferred from the return type. |
| 137 | pub fn new_genericrust-analyzer cargo tiff 0.11.3 encoder/impl#[`TiffEncoder<W, K>`]new_generic().(writer: W) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<Selfrust-analyzer cargo tiff 0.11.3 encoder/impl#[`TiffEncoder<W, K>`]> { |
| 138 | let mut writer = TiffWriterrust-analyzer cargo tiff 0.11.3 encoder/writer/TiffWriter#::newrust-analyzer cargo tiff 0.11.3 encoder/writer/impl#[`TiffWriter<W>`]new().(writer); |
| 139 | K::write_headerrust-analyzer cargo tiff 0.11.3 encoder/TiffKind#write_header().(&mut writer)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 140 | |
| 141 | let last_ifd_chain = NonZeroU64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU64#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/impl#[`NonZero<T>`]new().(writer.previous_ifd_pointerrust-analyzer cargo tiff 0.11.3 encoder/writer/impl#[`TiffWriter<W>`]previous_ifd_pointer().::<K>()) |
| 142 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Header is at a non-zero offset"); |
| 143 | |
| 144 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(TiffEncoderrust-analyzer cargo tiff 0.11.3 encoder/TiffEncoder# { |
| 145 | writerrust-analyzer cargo tiff 0.11.3 encoder/TiffEncoder#writer., |
| 146 | kindrust-analyzer cargo tiff 0.11.3 encoder/TiffEncoder#kind.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#, |
| 147 | predictorrust-analyzer cargo tiff 0.11.3 encoder/TiffEncoder#predictor.: Predictorrust-analyzer cargo tiff 0.11.3 encoder/Predictor#::Nonerust-analyzer cargo tiff 0.11.3 tags/Predictor#None#, |
| 148 | compressionrust-analyzer cargo tiff 0.11.3 encoder/TiffEncoder#compression.: Compressionrust-analyzer cargo tiff 0.11.3 encoder/Compression#::Uncompressedrust-analyzer cargo tiff 0.11.3 encoder/Compression#Uncompressed#, |
| 149 | last_ifd_chainrust-analyzer cargo tiff 0.11.3 encoder/TiffEncoder#last_ifd_chain., |
| 150 | }) |
| 151 | } |
| 152 | |
| 153 | /// Set the predictor to use |
| 154 | /// |
| 155 | /// A predictor is used to simplify the file before writing it. This is very |
| 156 | /// useful when writing a file compressed using LZW as it can improve efficiency |
| 157 | pub fn with_predictorrust-analyzer cargo tiff 0.11.3 encoder/impl#[`TiffEncoder<W, K>`]with_predictor().(mut self, predictor: Predictorrust-analyzer cargo tiff 0.11.3 encoder/Predictor#) -> Selfrust-analyzer cargo tiff 0.11.3 encoder/impl#[`TiffEncoder<W, K>`] { |
| 158 | self.predictorrust-analyzer cargo tiff 0.11.3 encoder/TiffEncoder#predictor. = predictor; |
| 159 | |
| 160 | self |
| 161 | } |
| 162 | |
| 163 | /// Set the compression method to use |
| 164 | pub fn with_compressionrust-analyzer cargo tiff 0.11.3 encoder/impl#[`TiffEncoder<W, K>`]with_compression().(mut self, compression: Compressionrust-analyzer cargo tiff 0.11.3 encoder/Compression#) -> Selfrust-analyzer cargo tiff 0.11.3 encoder/impl#[`TiffEncoder<W, K>`] { |
| 165 | self.compressionrust-analyzer cargo tiff 0.11.3 encoder/TiffEncoder#compression. = compression; |
| 166 | |
| 167 | self |
| 168 | } |
| 169 | |
| 170 | /// Create a [`DirectoryEncoder`] to encode an ifd directory. |
| 171 | #[deprecated = "`image_directory` replaced the old behavior and clarifies the intent"] |
| 172 | #[doc(hidden)] |
| 173 | pub fn new_directoryrust-analyzer cargo tiff 0.11.3 encoder/impl#[`TiffEncoder<W, K>`]new_directory().(&mut self) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<DirectoryEncoderrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#<'_, W, K>> { |
| 174 | Selfrust-analyzer cargo tiff 0.11.3 encoder/impl#[`TiffEncoder<W, K>`]::chain_directoryrust-analyzer cargo tiff 0.11.3 encoder/impl#[`TiffEncoder<W, K>`]chain_directory().(&mut self.writerrust-analyzer cargo tiff 0.11.3 encoder/TiffEncoder#writer., &mut self.last_ifd_chainrust-analyzer cargo tiff 0.11.3 encoder/TiffEncoder#last_ifd_chain.) |
| 175 | } |
| 176 | |
| 177 | /// Create a [`DirectoryEncoder`] to encode an ifd (directory). |
| 178 | /// |
| 179 | /// The caller is responsible for ensuring that the directory is a valid image in the main TIFF |
| 180 | /// IFD sequence. To encode additional directories that are not linked into the sequence, use |
| 181 | /// [`Self::extra_directory`][TiffEncoder::extra_directory]. |
| 182 | pub fn image_directoryrust-analyzer cargo tiff 0.11.3 encoder/impl#[`TiffEncoder<W, K>`]image_directory().(&mut self) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<DirectoryEncoderrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#<'_, W, K>> { |
| 183 | Selfrust-analyzer cargo tiff 0.11.3 encoder/impl#[`TiffEncoder<W, K>`]::chain_directoryrust-analyzer cargo tiff 0.11.3 encoder/impl#[`TiffEncoder<W, K>`]chain_directory().(&mut self.writerrust-analyzer cargo tiff 0.11.3 encoder/TiffEncoder#writer., &mut self.last_ifd_chainrust-analyzer cargo tiff 0.11.3 encoder/TiffEncoder#last_ifd_chain.) |
| 184 | } |
| 185 | |
| 186 | /// Create a [`DirectoryEncoder`] to encode a non-image directory. |
| 187 | /// |
| 188 | /// The directory is not linked into the sequence of directories. For instance, encode Exif |
| 189 | /// directories or SubIfd directories with this method. |
| 190 | pub fn extra_directoryrust-analyzer cargo tiff 0.11.3 encoder/impl#[`TiffEncoder<W, K>`]extra_directory().(&mut self) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<DirectoryEncoderrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#<'_, W, K>> { |
| 191 | Selfrust-analyzer cargo tiff 0.11.3 encoder/impl#[`TiffEncoder<W, K>`]::unchained_directoryrust-analyzer cargo tiff 0.11.3 encoder/impl#[`TiffEncoder<W, K>`]unchained_directory().(&mut self.writerrust-analyzer cargo tiff 0.11.3 encoder/TiffEncoder#writer.) |
| 192 | } |
| 193 | |
| 194 | /// Create an [`ImageEncoder`] to encode an image one slice at a time. |
| 195 | pub fn new_imagerust-analyzer cargo tiff 0.11.3 encoder/impl#[`TiffEncoder<W, K>`]new_image().<C: ColorTyperust-analyzer cargo tiff 0.11.3 encoder/colortype/ColorType#>( |
| 196 | &mut self, |
| 197 | width: u32, |
| 198 | height: u32, |
| 199 | ) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<ImageEncoderrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#<'_, W, C, K>> { |
| 200 | let encoder = Selfrust-analyzer cargo tiff 0.11.3 encoder/impl#[`TiffEncoder<W, K>`]::chain_directoryrust-analyzer cargo tiff 0.11.3 encoder/impl#[`TiffEncoder<W, K>`]chain_directory().(&mut self.writerrust-analyzer cargo tiff 0.11.3 encoder/TiffEncoder#writer., &mut self.last_ifd_chainrust-analyzer cargo tiff 0.11.3 encoder/TiffEncoder#last_ifd_chain.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 201 | ImageEncoderrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#::newrust-analyzer cargo tiff 0.11.3 encoder/impl#[`ImageEncoder<'a, W, T, K>`]new().(encoder, width, height, self.compressionrust-analyzer cargo tiff 0.11.3 encoder/TiffEncoder#compression., self.predictorrust-analyzer cargo tiff 0.11.3 encoder/TiffEncoder#predictor.) |
| 202 | } |
| 203 | |
| 204 | /// Convenience function to write an entire image from memory. |
| 205 | pub fn write_imagerust-analyzer cargo tiff 0.11.3 encoder/impl#[`TiffEncoder<W, K>`]write_image().<C: ColorTyperust-analyzer cargo tiff 0.11.3 encoder/colortype/ColorType#>( |
| 206 | &mut self, |
| 207 | width: u32, |
| 208 | height: u32, |
| 209 | data: &[C::Innerrust-analyzer cargo tiff 0.11.3 encoder/colortype/ColorType#Inner#], |
| 210 | ) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<()> |
| 211 | where |
| 212 | [C::Innerrust-analyzer cargo tiff 0.11.3 encoder/colortype/ColorType#Inner#]: TiffValuerust-analyzer cargo tiff 0.11.3 encoder/tiff_value/TiffValue#, |
| 213 | { |
| 214 | let encoder = Selfrust-analyzer cargo tiff 0.11.3 encoder/impl#[`TiffEncoder<W, K>`]::chain_directoryrust-analyzer cargo tiff 0.11.3 encoder/impl#[`TiffEncoder<W, K>`]chain_directory().(&mut self.writerrust-analyzer cargo tiff 0.11.3 encoder/TiffEncoder#writer., &mut self.last_ifd_chainrust-analyzer cargo tiff 0.11.3 encoder/TiffEncoder#last_ifd_chain.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 215 | let image: ImageEncoderrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#<W, C, K> = |
| 216 | ImageEncoderrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#::newrust-analyzer cargo tiff 0.11.3 encoder/impl#[`ImageEncoder<'a, W, T, K>`]new().(encoder, width, height, self.compressionrust-analyzer cargo tiff 0.11.3 encoder/TiffEncoder#compression., self.predictorrust-analyzer cargo tiff 0.11.3 encoder/TiffEncoder#predictor.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 217 | image.write_datarust-analyzer cargo tiff 0.11.3 encoder/impl#[`ImageEncoder<'a, W, T, K>`]write_data().(data) |
| 218 | } |
| 219 | |
| 220 | fn chain_directoryrust-analyzer cargo tiff 0.11.3 encoder/impl#[`TiffEncoder<W, K>`]chain_directory().<'lt>( |
| 221 | writer: &'lt mut TiffWriterrust-analyzer cargo tiff 0.11.3 encoder/writer/TiffWriter#<W>, |
| 222 | last_ifd_chain: &'lt mut NonZeroU64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU64#, |
| 223 | ) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<DirectoryEncoderrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#<'lt, W, K>> { |
| 224 | let last_ifd = *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().last_ifd_chain; |
| 225 | DirectoryEncoderrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#::newrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]new().(writer, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(last_ifd), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(last_ifd_chain)) |
| 226 | } |
| 227 | |
| 228 | fn unchained_directoryrust-analyzer cargo tiff 0.11.3 encoder/impl#[`TiffEncoder<W, K>`]unchained_directory().(writer: &mut TiffWriterrust-analyzer cargo tiff 0.11.3 encoder/writer/TiffWriter#<W>) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<DirectoryEncoderrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#<'_, W, K>> { |
| 229 | DirectoryEncoderrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#::newrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]new().(writer, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | /// Low level interface to encode ifd directories. |
| 234 | /// |
| 235 | /// You should call `finish` on this when you are finished with it. |
| 236 | /// Encoding can silently fail while this is dropping. |
| 237 | pub struct DirectoryEncoderrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#<'a, W: 'a + Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write# + Seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#, K: TiffKindrust-analyzer cargo tiff 0.11.3 encoder/TiffKind#> { |
| 238 | writerrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#writer.: &'a mut TiffWriterrust-analyzer cargo tiff 0.11.3 encoder/writer/TiffWriter#<W>, |
| 239 | /// The position of the previous directory's `next` field, if any. |
| 240 | chained_ifd_posrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#chained_ifd_pos.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<NonZeroU64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU64#>, |
| 241 | /// An output to write the `next` field offset on completion. |
| 242 | write_chainrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#write_chain.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a mut NonZeroU64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU64#>, |
| 243 | kindrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#kind.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#<K>, |
| 244 | // We use BTreeMap to make sure tags are written in correct order |
| 245 | directoryrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#directory.: Directoryrust-analyzer cargo tiff 0.11.3 directory/Directory#, |
| 246 | droppedrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#dropped.: bool, |
| 247 | } |
| 248 | |
| 249 | /// The offset of an encoded directory in the file. |
| 250 | /// |
| 251 | /// Both the `offset` and `pointer` field are a complete description of the start offset of the |
| 252 | /// dictionary which is used to point to it. The struct also describes the extent covered by the |
| 253 | /// encoding of the directory. The constructors [`new`][DirectoryOffset::new] allow the checked |
| 254 | /// conversion. Note that even though the offsets are public do not expect their information to |
| 255 | /// propagate when modified. |
| 256 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:)] |
| 257 | pub struct DirectoryOffsetrust-analyzer cargo tiff 0.11.3 encoder/DirectoryOffset#<K: TiffKindrust-analyzer cargo tiff 0.11.3 encoder/TiffKind#> { |
| 258 | /// The start of the directory as a Tiff value. |
| 259 | /// |
| 260 | /// This is a bit of a wart in the strongly typed design of the encoder. The value _type_ must |
| 261 | /// itself know how to be represented in the Tiff file but that may differ based on endianess |
| 262 | /// as well as the offset size (`u32` or BigTIFF's `u64`). Thankfully we're allowed to |
| 263 | /// represent offsets with `LONG` or `IFD` in the usual case. |
| 264 | pub offsetrust-analyzer cargo tiff 0.11.3 encoder/DirectoryOffset#offset.: K::OffsetTyperust-analyzer cargo tiff 0.11.3 encoder/TiffKind#OffsetType#, |
| 265 | /// The start of the directory as a pure offset. |
| 266 | pub pointerrust-analyzer cargo tiff 0.11.3 encoder/DirectoryOffset#pointer.: IfdPointerrust-analyzer cargo tiff 0.11.3 tags/IfdPointer#, |
| 267 | /// The offset of its sequence link field, in our private representation. Before exposing this |
| 268 | /// make sure that we don't want any invariants (e.g. pointer being smaller than this). The |
| 269 | /// type should be fine. |
| 270 | ifd_chainrust-analyzer cargo tiff 0.11.3 encoder/DirectoryOffset#ifd_chain.: NonZeroU64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU64#, |
| 271 | /// The kind of Tiff file the offset is for. |
| 272 | kindrust-analyzer cargo tiff 0.11.3 encoder/DirectoryOffset#kind.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#<K>, |
| 273 | } |
| 274 | |
| 275 | impl<'a, W: 'a + Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write# + Seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#, K: TiffKindrust-analyzer cargo tiff 0.11.3 encoder/TiffKind#> DirectoryEncoderrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#<'a, W, K> { |
| 276 | /// Construct a directory writer appending to data, assuming the writer is currently positioned |
| 277 | /// immediately after a previously written IFD to which to append. |
| 278 | fn newrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]new().( |
| 279 | writer: &'a mut TiffWriterrust-analyzer cargo tiff 0.11.3 encoder/writer/TiffWriter#<W>, |
| 280 | chained_ifd_pos: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<NonZeroU64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU64#>, |
| 281 | chain_into: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a mut NonZeroU64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU64#>, |
| 282 | ) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<Selfrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]> { |
| 283 | writer.pad_word_boundaryrust-analyzer cargo tiff 0.11.3 encoder/writer/impl#[`TiffWriter<W>`]pad_word_boundary().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; // TODO: Do we need to adjust this for BigTiff? |
| 284 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`] { |
| 285 | writerrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#writer., |
| 286 | chained_ifd_posrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#chained_ifd_pos., |
| 287 | write_chainrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#write_chain.: chain_into, |
| 288 | kindrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#kind.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#, |
| 289 | directoryrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#directory.: Directoryrust-analyzer cargo tiff 0.11.3 directory/Directory#::emptyrust-analyzer cargo tiff 0.11.3 directory/impl#[Directory]empty().(), |
| 290 | droppedrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#dropped.: false, |
| 291 | }) |
| 292 | } |
| 293 | |
| 294 | /// Write a single ifd tag. |
| 295 | pub fn write_tagrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_tag().<T: TiffValuerust-analyzer cargo tiff 0.11.3 encoder/tiff_value/TiffValue#>(&mut self, tag: Tagrust-analyzer cargo tiff 0.11.3 tags/Tag#, value: T) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<()> { |
| 296 | // Encodes the value if necessary. In the current bytes all integers are taken as native |
| 297 | // endian and thus transparent but this keeps the interface generic. |
| 298 | let mut bytes = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(value.bytesrust-analyzer cargo tiff 0.11.3 encoder/tiff_value/TiffValue#bytes().()); |
| 299 | { |
| 300 | let mut writer = TiffWriterrust-analyzer cargo tiff 0.11.3 encoder/writer/TiffWriter#::newrust-analyzer cargo tiff 0.11.3 encoder/writer/impl#[`TiffWriter<W>`]new().(&mut bytes); |
| 301 | value.writerust-analyzer cargo tiff 0.11.3 encoder/tiff_value/TiffValue#write().(&mut writer)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 302 | } |
| 303 | |
| 304 | let entry = Selfrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]::write_entry_innerrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_entry_inner().( |
| 305 | self.writerrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#writer., |
| 306 | DirectoryEntryrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEntry# { |
| 307 | data_typerust-analyzer cargo tiff 0.11.3 encoder/DirectoryEntry#data_type.: <T>::FIELD_TYPErust-analyzer cargo tiff 0.11.3 encoder/tiff_value/TiffValue#FIELD_TYPE., |
| 308 | countrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEntry#count.: value.countrust-analyzer cargo tiff 0.11.3 encoder/tiff_value/TiffValue#count().().try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 309 | datarust-analyzer cargo tiff 0.11.3 encoder/DirectoryEntry#data.: bytes.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 310 | }, |
| 311 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 312 | |
| 313 | self.directoryrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#directory..extendrust-analyzer cargo tiff 0.11.3 directory/impl#[Directory]extend().([(tag, entry)]); |
| 314 | |
| 315 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 316 | } |
| 317 | |
| 318 | /// Write a tag-value pair with prepared byte data. |
| 319 | /// |
| 320 | /// Note that the library will _not_ attempt to verify that the data type or the count of the |
| 321 | /// buffered value is permissible for the given tag. The data will be associated with the tag |
| 322 | /// exactly as-is. |
| 323 | /// |
| 324 | /// An error is returned if the byte order of the presented value does not match the byte order |
| 325 | /// of the underlying file (i.e. the [native byte order](`crate::tags::ByteOrder::native`)). |
| 326 | pub fn write_tag_bufrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_tag_buf().(&mut self, tag: Tagrust-analyzer cargo tiff 0.11.3 tags/Tag#, value: &ValueBufferrust-analyzer cargo tiff 0.11.3 tags/ValueBuffer#) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<()> { |
| 327 | let entry = self.write_entry_bufrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_entry_buf().(value)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 328 | self.directoryrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#directory..extendrust-analyzer cargo tiff 0.11.3 directory/impl#[Directory]extend().([(tag, entry)]); |
| 329 | |
| 330 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 331 | } |
| 332 | |
| 333 | /// Write some data to the tiff file, the offset of the data is returned. |
| 334 | /// |
| 335 | /// This could be used to write tiff strips. All of the data will be written into the file as a |
| 336 | /// slice of bytes. It can not be used as an entry in a directory directly, where very short |
| 337 | /// values are instead represented in the offset field directly. Use [`Self::write_entry`] |
| 338 | /// instead. |
| 339 | pub fn write_datarust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_data().<T: TiffValuerust-analyzer cargo tiff 0.11.3 encoder/tiff_value/TiffValue#>(&mut self, value: T) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<u64> { |
| 340 | let offset = self.writerrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#writer..offsetrust-analyzer cargo tiff 0.11.3 encoder/writer/impl#[`TiffWriter<W>`]offset().(); |
| 341 | value.writerust-analyzer cargo tiff 0.11.3 encoder/tiff_value/TiffValue#write().(self.writerrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#writer.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 342 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(offset) |
| 343 | } |
| 344 | |
| 345 | /// Write some data directly to the tiff file, the offset of the data is returned. |
| 346 | /// |
| 347 | /// All of the data will be written into the file as a slice of bytes. It can not be used as an |
| 348 | /// entry in a directory directly, where very short values are instead represented in the |
| 349 | /// offset field directly. Use [`Self::write_entry_buf`] instead. |
| 350 | /// |
| 351 | /// An error is returned if the byte order of the presented value does not match the byte order |
| 352 | /// of the underlying file (i.e. the [native byte order](`crate::tags::ByteOrder::native`)). |
| 353 | pub fn write_data_bufrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_data_buf().(&mut self, value: &ValueBufferrust-analyzer cargo tiff 0.11.3 tags/ValueBuffer#) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<u64> { |
| 354 | self.check_value_byteorderrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]check_value_byteorder().(value)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 355 | let offset = self.writerrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#writer..offsetrust-analyzer cargo tiff 0.11.3 encoder/writer/impl#[`TiffWriter<W>`]offset().(); |
| 356 | self.writerrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#writer..write_bytesrust-analyzer cargo tiff 0.11.3 encoder/writer/impl#[`TiffWriter<W>`]write_bytes().(value.as_bytesrust-analyzer cargo tiff 0.11.3 tags/impl#[ValueBuffer]as_bytes().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 357 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(offset) |
| 358 | } |
| 359 | |
| 360 | /// Write a directory value into the file. |
| 361 | /// |
| 362 | /// Returns an [`Entry`]. If the value is short enough it will *not* be written in the file but |
| 363 | /// stored in the entry's offset field. |
| 364 | pub fn write_entryrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_entry().<T: TiffValuerust-analyzer cargo tiff 0.11.3 encoder/tiff_value/TiffValue#>(&mut self, value: T) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<Entryrust-analyzer cargo tiff 0.11.3 decoder/ifd/Entry#> { |
| 365 | Selfrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]::write_entry_innerrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_entry_inner().( |
| 366 | self.writerrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#writer., |
| 367 | DirectoryEntryrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEntry# { |
| 368 | data_typerust-analyzer cargo tiff 0.11.3 encoder/DirectoryEntry#data_type.: T::FIELD_TYPErust-analyzer cargo tiff 0.11.3 encoder/tiff_value/TiffValue#FIELD_TYPE., |
| 369 | countrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEntry#count.: K::convert_offsetrust-analyzer cargo tiff 0.11.3 encoder/TiffKind#convert_offset().(value.countrust-analyzer cargo tiff 0.11.3 encoder/tiff_value/TiffValue#count().() as u64)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 370 | // FIXME: not optimal we always allocate here. But the only other method we have |
| 371 | // available is `T::write(&mut TiffWriter<W>)` and we must pass that into |
| 372 | // `write_entry_inner` but then have a combinatorial explosion of instantiations |
| 373 | // which is absurd. |
| 374 | datarust-analyzer cargo tiff 0.11.3 encoder/DirectoryEntry#data.: value.datarust-analyzer cargo tiff 0.11.3 encoder/tiff_value/TiffValue#data().(), |
| 375 | }, |
| 376 | ) |
| 377 | } |
| 378 | |
| 379 | /// Write a directory value into the file. |
| 380 | /// |
| 381 | /// An error is returned if the byte order of the presented value does not match the byte order |
| 382 | /// of the underlying file (i.e. the [native byte order](`crate::tags::ByteOrder::native`)). |
| 383 | /// |
| 384 | /// Returns an [`Entry`]. If the value is short enough it will *not* be written in the file but |
| 385 | /// stored in the entry's offset field. |
| 386 | pub fn write_entry_bufrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_entry_buf().(&mut self, value: &ValueBufferrust-analyzer cargo tiff 0.11.3 tags/ValueBuffer#) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<Entryrust-analyzer cargo tiff 0.11.3 decoder/ifd/Entry#> { |
| 387 | self.check_value_byteorderrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]check_value_byteorder().(value)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 388 | |
| 389 | Selfrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]::write_entry_innerrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_entry_inner().( |
| 390 | self.writerrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#writer., |
| 391 | DirectoryEntryrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEntry# { |
| 392 | data_typerust-analyzer cargo tiff 0.11.3 encoder/DirectoryEntry#data_type.: value.data_typerust-analyzer cargo tiff 0.11.3 tags/impl#[ValueBuffer]data_type().(), |
| 393 | countrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEntry#count.: K::convert_offsetrust-analyzer cargo tiff 0.11.3 encoder/TiffKind#convert_offset().(value.countrust-analyzer cargo tiff 0.11.3 tags/impl#[ValueBuffer]count().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 394 | datarust-analyzer cargo tiff 0.11.3 encoder/DirectoryEntry#data.: value.as_bytesrust-analyzer cargo tiff 0.11.3 tags/impl#[ValueBuffer]as_bytes().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 395 | }, |
| 396 | ) |
| 397 | } |
| 398 | |
| 399 | /// Write a directory entry by its byte data. |
| 400 | /// |
| 401 | /// The data must be pre-formatted to the byte order expected by the file. |
| 402 | /// |
| 403 | /// Returns an [`Entry`]. If the value is short enough it will *not* be written in the file but |
| 404 | /// stored in the entry's offset field. |
| 405 | pub fn write_entry_bytesrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_entry_bytes().(&mut self, ty: Typerust-analyzer cargo tiff 0.11.3 tags/Type#, data: &[u8]) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<Entryrust-analyzer cargo tiff 0.11.3 decoder/ifd/Entry#> { |
| 406 | if data.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().usize::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`From<u8>`]from().(ty.byte_lenrust-analyzer cargo tiff 0.11.3 tags/impl#[Type]byte_len().()) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().0 { |
| 407 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(TiffErrorrust-analyzer cargo tiff 0.11.3 error/TiffError#::UsageErrorrust-analyzer cargo tiff 0.11.3 error/TiffError#UsageError#(UsageErrorrust-analyzer cargo tiff 0.11.3 error/UsageError#::MismatchedEntryLengthrust-analyzer cargo tiff 0.11.3 error/UsageError#MismatchedEntryLength# { |
| 408 | tyrust-analyzer cargo tiff 0.11.3 error/UsageError#MismatchedEntryLength#ty., |
| 409 | foundrust-analyzer cargo tiff 0.11.3 error/UsageError#MismatchedEntryLength#found.: data.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(), |
| 410 | })); |
| 411 | } |
| 412 | |
| 413 | let count = data.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().usize::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`From<u8>`]from().(ty.byte_lenrust-analyzer cargo tiff 0.11.3 tags/impl#[Type]byte_len().()); |
| 414 | let count = u64::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/ptr_try_from_impls/impl#[u64][`TryFrom<usize>`]try_from().(count)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 415 | |
| 416 | Selfrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]::write_entry_innerrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_entry_inner().( |
| 417 | self.writerrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#writer., |
| 418 | DirectoryEntryrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEntry# { |
| 419 | data_typerust-analyzer cargo tiff 0.11.3 encoder/DirectoryEntry#data_type.: ty, |
| 420 | countrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEntry#count.: K::convert_offsetrust-analyzer cargo tiff 0.11.3 encoder/TiffKind#convert_offset().(count)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 421 | datarust-analyzer cargo tiff 0.11.3 encoder/DirectoryEntry#data.: data.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 422 | }, |
| 423 | ) |
| 424 | } |
| 425 | |
| 426 | /// Insert previously written key-value entries. |
| 427 | /// |
| 428 | /// It is the caller's responsibility to ensure that the data referred to by the entries is |
| 429 | /// actually (or will be) written to the file. Note that small values are necessarily inline in |
| 430 | /// the entry, the size limit depends on the Tiff kind. So do not confuse a directory from a |
| 431 | /// BigTiff in a standard tiff or the other way around. |
| 432 | pub fn extend_fromrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]extend_from().(&mut self, dir: &Directoryrust-analyzer cargo tiff 0.11.3 directory/Directory#) { |
| 433 | let entries = dir.iterrust-analyzer cargo tiff 0.11.3 directory/impl#[Directory]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(tag, val)| (tag, val.clonerust-analyzer cargo tiff 0.11.3 decoder/ifd/impl#[Entry][Clone]clone().())); |
| 434 | self.directoryrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#directory..extendrust-analyzer cargo tiff 0.11.3 directory/impl#[Directory]extend().(entries); |
| 435 | } |
| 436 | |
| 437 | /// Define the parent directory. |
| 438 | /// |
| 439 | /// Each directory has an offset based link to its successor, forming a linked list in the |
| 440 | /// file. The encoder writes its own offset into the parent's field when [`Self::finish`] is |
| 441 | /// called or it is dropped. This redefines the parent. An offset representation of the parent |
| 442 | /// must be acquired by finishing it with [`Self::finish_with_offsets`]. |
| 443 | pub fn set_parentrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]set_parent().(&mut self, offset: &DirectoryOffsetrust-analyzer cargo tiff 0.11.3 encoder/DirectoryOffset#<K>) { |
| 444 | self.chained_ifd_posrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#chained_ifd_pos. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(offset.ifd_chainrust-analyzer cargo tiff 0.11.3 encoder/DirectoryOffset#ifd_chain.); |
| 445 | } |
| 446 | |
| 447 | /// Write out the ifd directory itself. |
| 448 | pub fn finishrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]finish().(mut self) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<()> { |
| 449 | self.finish_internalrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]finish_internal().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 450 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 451 | } |
| 452 | |
| 453 | /// Write the IFD to the file and return the offset it is written to. |
| 454 | /// |
| 455 | /// The offset can be used as the value, or as part of a list of values, in the entry of |
| 456 | /// another directory. If you're constructing the entry directly you'll want to use an |
| 457 | /// appropriate type variant for this such as [`Type::IFD`]. |
| 458 | pub fn finish_with_offsetsrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]finish_with_offsets().(mut self) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<DirectoryOffsetrust-analyzer cargo tiff 0.11.3 encoder/DirectoryOffset#<K>> { |
| 459 | self.finish_internalrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]finish_internal().() |
| 460 | } |
| 461 | |
| 462 | fn write_directoryrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_directory().(&mut self) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<u64> { |
| 463 | // Start by turning all buffered unwritten values into entries. |
| 464 | let offset = self.writerrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#writer..offsetrust-analyzer cargo tiff 0.11.3 encoder/writer/impl#[`TiffWriter<W>`]offset().(); |
| 465 | K::write_entry_countrust-analyzer cargo tiff 0.11.3 encoder/TiffKind#write_entry_count().(self.writerrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#writer., self.directoryrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#directory..lenrust-analyzer cargo tiff 0.11.3 directory/impl#[Directory]len().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 466 | |
| 467 | let offset_bytes = memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<K::OffsetTyperust-analyzer cargo tiff 0.11.3 encoder/TiffKind#OffsetType#>(); |
| 468 | for (tag, entry) in self.directoryrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#directory..iterrust-analyzer cargo tiff 0.11.3 directory/impl#[Directory]iter().() { |
| 469 | self.writerrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#writer..write_u16rust-analyzer cargo tiff 0.11.3 encoder/writer/impl#[`TiffWriter<W>`]write_u16().(tag.to_u16rust-analyzer cargo tiff 0.11.3 tags/impl#[Tag]to_u16().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 470 | self.writerrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#writer..write_u16rust-analyzer cargo tiff 0.11.3 encoder/writer/impl#[`TiffWriter<W>`]write_u16().(entry.field_typerust-analyzer cargo tiff 0.11.3 decoder/ifd/impl#[Entry]field_type().().to_u16rust-analyzer cargo tiff 0.11.3 tags/impl#[Type]to_u16().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 471 | let count = K::convert_offsetrust-analyzer cargo tiff 0.11.3 encoder/TiffKind#convert_offset().(entry.countrust-analyzer cargo tiff 0.11.3 decoder/ifd/impl#[Entry]count().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 472 | count.writerust-analyzer cargo tiff 0.11.3 encoder/tiff_value/TiffValue#write().(self.writerrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#writer.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 473 | self.writerrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#writer..write_bytesrust-analyzer cargo tiff 0.11.3 encoder/writer/impl#[`TiffWriter<W>`]write_bytes().(&entry.offsetrust-analyzer cargo tiff 0.11.3 decoder/ifd/impl#[Entry]offset().()[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#offset_bytes]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 474 | } |
| 475 | |
| 476 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(offset) |
| 477 | } |
| 478 | |
| 479 | // Does it really make sense that this would be a (potentially) compressible write? For actual |
| 480 | // directory values their size must match the data written so there's going to be a silent |
| 481 | // problem if that actually occurs. |
| 482 | fn write_entry_innerrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_entry_inner().( |
| 483 | writer: &mut TiffWriterrust-analyzer cargo tiff 0.11.3 encoder/writer/TiffWriter#<W>, |
| 484 | value: DirectoryEntryrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEntry#<K::OffsetTyperust-analyzer cargo tiff 0.11.3 encoder/TiffKind#OffsetType#>, |
| 485 | ) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<Entryrust-analyzer cargo tiff 0.11.3 decoder/ifd/Entry#> { |
| 486 | let DirectoryEntryrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEntry# { |
| 487 | datarust-analyzer cargo tiff 0.11.3 encoder/DirectoryEntry#data.: ref bytes, |
| 488 | ref countrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEntry#count., |
| 489 | data_typerust-analyzer cargo tiff 0.11.3 encoder/DirectoryEntry#data_type., |
| 490 | } = value; |
| 491 | |
| 492 | let in_entry_bytes = memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<K::OffsetTyperust-analyzer cargo tiff 0.11.3 encoder/TiffKind#OffsetType#>(); |
| 493 | |
| 494 | let mut offset_bytes = [0; 8]; |
| 495 | |
| 496 | if bytes.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().in_entry_bytes { |
| 497 | let offset = writer.offsetrust-analyzer cargo tiff 0.11.3 encoder/writer/impl#[`TiffWriter<W>`]offset().(); |
| 498 | writer.write_bytesrust-analyzer cargo tiff 0.11.3 encoder/writer/impl#[`TiffWriter<W>`]write_bytes().(bytes)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 499 | |
| 500 | let offset = K::convert_offsetrust-analyzer cargo tiff 0.11.3 encoder/TiffKind#convert_offset().(offset)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 501 | offset_bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#offset.bytesrust-analyzer cargo tiff 0.11.3 encoder/tiff_value/TiffValue#bytes().()]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut()..copy_from_slicerust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]copy_from_slice().(&offset.datarust-analyzer cargo tiff 0.11.3 encoder/tiff_value/TiffValue#data().()); |
| 502 | } else { |
| 503 | // Note: we have indicated our native byte order in the header, hence this |
| 504 | // corresponds to our byte order no matter the value type. |
| 505 | offset_bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#bytes.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut()..copy_from_slicerust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]copy_from_slice().(bytes); |
| 506 | } |
| 507 | |
| 508 | // Undoing some hidden type. Offset is either u32 or u64. Due to the trait API being public |
| 509 | // and some oversight, we can not clone the `count: K::OffsetType` and thus not convert it. |
| 510 | // Instead, write it to a buffer... |
| 511 | let mut count_bytes = [0; 8]; |
| 512 | debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!(in_entry_bytes == 4 || in_entry_bytes == 8); |
| 513 | // Nominally Cow but we only expect `Cow::Borrowed`. |
| 514 | count_bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#count.bytesrust-analyzer cargo tiff 0.11.3 encoder/tiff_value/TiffValue#bytes().()]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut()..copy_from_slicerust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]copy_from_slice().(&count.datarust-analyzer cargo tiff 0.11.3 encoder/tiff_value/TiffValue#data().()); |
| 515 | |
| 516 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(if in_entry_bytes rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().4 { |
| 517 | let count = u32::from_ne_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]from_ne_bytes().(count_bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#4]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()..try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryInto#try_into().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()); |
| 518 | Entryrust-analyzer cargo tiff 0.11.3 decoder/ifd/Entry#::newrust-analyzer cargo tiff 0.11.3 decoder/ifd/impl#[Entry]new().(data_type, count, offset_bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#4]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()..try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()) |
| 519 | } else { |
| 520 | debug_assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert_eq!!(in_entry_bytes, 8); |
| 521 | let count = u64::from_ne_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]from_ne_bytes().(count_bytes); |
| 522 | Entryrust-analyzer cargo tiff 0.11.3 decoder/ifd/Entry#::new_u64rust-analyzer cargo tiff 0.11.3 decoder/ifd/impl#[Entry]new_u64().(data_type, count, offset_bytes) |
| 523 | }) |
| 524 | } |
| 525 | |
| 526 | fn check_value_byteorderrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]check_value_byteorder().(&self, value: &ValueBufferrust-analyzer cargo tiff 0.11.3 tags/ValueBuffer#) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<()> { |
| 527 | // FIXME: we should enable writing files with any chosen byte order. |
| 528 | if value.byte_orderrust-analyzer cargo tiff 0.11.3 tags/impl#[ValueBuffer]byte_order().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().ByteOrderrust-analyzer cargo tiff 0.11.3 tags/ByteOrder#::nativerust-analyzer cargo tiff 0.11.3 tags/impl#[ByteOrder]native().() { |
| 529 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(TiffErrorrust-analyzer cargo tiff 0.11.3 error/TiffError#::UsageErrorrust-analyzer cargo tiff 0.11.3 error/TiffError#UsageError#(UsageErrorrust-analyzer cargo tiff 0.11.3 error/UsageError#::ByteOrderMismatchrust-analyzer cargo tiff 0.11.3 error/UsageError#ByteOrderMismatch#)) |
| 530 | } else { |
| 531 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | /// Provides the number of bytes written by the underlying TiffWriter during the last call. |
| 536 | fn last_writtenrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]last_written().(&self) -> u64 { |
| 537 | self.writerrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#writer..last_writtenrust-analyzer cargo tiff 0.11.3 encoder/writer/impl#[`TiffWriter<W>`]last_written().() |
| 538 | } |
| 539 | |
| 540 | fn finish_internalrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]finish_internal().(&mut self) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<DirectoryOffsetrust-analyzer cargo tiff 0.11.3 encoder/DirectoryOffset#<K>> { |
| 541 | let ifd_pointer = self.write_directoryrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_directory().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 542 | let offset = K::convert_offsetrust-analyzer cargo tiff 0.11.3 encoder/TiffKind#convert_offset().(ifd_pointer)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 543 | |
| 544 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(prior) = self.chained_ifd_posrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#chained_ifd_pos. { |
| 545 | let curr_pos = self.writerrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#writer..offsetrust-analyzer cargo tiff 0.11.3 encoder/writer/impl#[`TiffWriter<W>`]offset().(); |
| 546 | |
| 547 | self.writerrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#writer..goto_offsetrust-analyzer cargo tiff 0.11.3 encoder/writer/impl#[`TiffWriter<W>`]goto_offset().(prior.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/impl#[`NonZero<T>`]get().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 548 | // Note how we are not writing the `offset` type itself here as doing so would need to |
| 549 | // go through the `TiffValue` trait—the type is not constrained by much. But for the |
| 550 | // trait we need a `TiffWriter` which comes with a bunch of additional state such as |
| 551 | // compressor etc. that we have no need for. |
| 552 | K::write_offsetrust-analyzer cargo tiff 0.11.3 encoder/TiffKind#write_offset().(self.writerrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#writer., ifd_pointer)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 553 | |
| 554 | self.writerrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#writer..goto_offsetrust-analyzer cargo tiff 0.11.3 encoder/writer/impl#[`TiffWriter<W>`]goto_offset().(curr_pos)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 555 | } |
| 556 | |
| 557 | K::write_offsetrust-analyzer cargo tiff 0.11.3 encoder/TiffKind#write_offset().(self.writerrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#writer., 0)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 558 | |
| 559 | let ifd_chain = NonZeroU64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU64#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/impl#[`NonZero<T>`]new().(self.writerrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#writer..previous_ifd_pointerrust-analyzer cargo tiff 0.11.3 encoder/writer/impl#[`TiffWriter<W>`]previous_ifd_pointer().::<K>()) |
| 560 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("IFD chain field is at a non-zero offset"); |
| 561 | |
| 562 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(prior) = self.write_chainrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#write_chain..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().() { |
| 563 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().prior = ifd_chain; |
| 564 | } |
| 565 | |
| 566 | self.droppedrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#dropped. = true; |
| 567 | |
| 568 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(DirectoryOffsetrust-analyzer cargo tiff 0.11.3 encoder/DirectoryOffset# { |
| 569 | pointerrust-analyzer cargo tiff 0.11.3 encoder/DirectoryOffset#pointer.: IfdPointerrust-analyzer cargo tiff 0.11.3 tags/IfdPointer#(ifd_pointer), |
| 570 | offsetrust-analyzer cargo tiff 0.11.3 encoder/DirectoryOffset#offset., |
| 571 | ifd_chainrust-analyzer cargo tiff 0.11.3 encoder/DirectoryOffset#ifd_chain., |
| 572 | kindrust-analyzer cargo tiff 0.11.3 encoder/DirectoryOffset#kind.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#, |
| 573 | }) |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | impl<'a, W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write# + Seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#, K: TiffKindrust-analyzer cargo tiff 0.11.3 encoder/TiffKind#> Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for DirectoryEncoderrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#<'a, W, K> { |
| 578 | fn droprust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`][Drop]drop().(&mut self) { |
| 579 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.droppedrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#dropped. { |
| 580 | let _ = self.finish_internalrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]finish_internal().(); |
| 581 | } |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | /// Type to encode images strip by strip. |
| 586 | /// |
| 587 | /// You should call `finish` on this when you are finished with it. |
| 588 | /// Encoding can silently fail while this is dropping. |
| 589 | /// |
| 590 | /// # Examples |
| 591 | /// ``` |
| 592 | /// # extern crate tiff; |
| 593 | /// # fn main() { |
| 594 | /// # let mut file = std::io::Cursor::new(Vec::new()); |
| 595 | /// # let image_data = vec![0; 100*100*3]; |
| 596 | /// use tiff::encoder::*; |
| 597 | /// use tiff::tags::Tag; |
| 598 | /// |
| 599 | /// let mut tiff = TiffEncoder::new(&mut file).unwrap(); |
| 600 | /// let mut image = tiff.new_image::<colortype::RGB8>(100, 100).unwrap(); |
| 601 | /// |
| 602 | /// // You can encode tags here |
| 603 | /// image.encoder().write_tag(Tag::Artist, "Image-tiff").unwrap(); |
| 604 | /// |
| 605 | /// // Strip size can be configured before writing data |
| 606 | /// image.rows_per_strip(2).unwrap(); |
| 607 | /// |
| 608 | /// let mut idx = 0; |
| 609 | /// while image.next_strip_sample_count() > 0 { |
| 610 | /// let sample_count = image.next_strip_sample_count() as usize; |
| 611 | /// image.write_strip(&image_data[idx..idx+sample_count]).unwrap(); |
| 612 | /// idx += sample_count; |
| 613 | /// } |
| 614 | /// image.finish().unwrap(); |
| 615 | /// # } |
| 616 | /// ``` |
| 617 | /// You can also call write_data function wich will encode by strip and finish |
| 618 | pub struct ImageEncoderrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#<'a, W: 'a + Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write# + Seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#, C: ColorTyperust-analyzer cargo tiff 0.11.3 encoder/colortype/ColorType#, K: TiffKindrust-analyzer cargo tiff 0.11.3 encoder/TiffKind#> { |
| 619 | encoderrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#encoder.: DirectoryEncoderrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#<'a, W, K>, |
| 620 | strip_idxrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#strip_idx.: u64, |
| 621 | strip_countrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#strip_count.: u64, |
| 622 | row_samplesrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#row_samples.: u64, |
| 623 | widthrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#width.: u32, |
| 624 | heightrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#height.: u32, |
| 625 | extra_samplesrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#extra_samples.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u16>, |
| 626 | rows_per_striprust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#rows_per_strip.: u64, |
| 627 | strip_offsetsrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#strip_offsets.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<K::OffsetTyperust-analyzer cargo tiff 0.11.3 encoder/TiffKind#OffsetType#>, |
| 628 | strip_byte_countrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#strip_byte_count.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<K::OffsetTyperust-analyzer cargo tiff 0.11.3 encoder/TiffKind#OffsetType#>, |
| 629 | droppedrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#dropped.: bool, |
| 630 | compressionrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#compression.: Compressionrust-analyzer cargo tiff 0.11.3 encoder/Compression#, |
| 631 | predictorrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#predictor.: Predictorrust-analyzer cargo tiff 0.11.3 encoder/Predictor#, |
| 632 | _phantomrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#_phantom.: ::stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::markerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/::PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#<C>, |
| 633 | } |
| 634 | |
| 635 | impl<'a, W: 'a + Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write# + Seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#, T: ColorTyperust-analyzer cargo tiff 0.11.3 encoder/colortype/ColorType#, K: TiffKindrust-analyzer cargo tiff 0.11.3 encoder/TiffKind#> ImageEncoderrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#<'a, W, T, K> { |
| 636 | fn sanity_checkrust-analyzer cargo tiff 0.11.3 encoder/impl#[`ImageEncoder<'a, W, T, K>`]sanity_check().(compression: Compressionrust-analyzer cargo tiff 0.11.3 encoder/Compression#, predictor: Predictorrust-analyzer cargo tiff 0.11.3 encoder/Predictor#) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<()> { |
| 637 | match (predictor, compression, T::SAMPLE_FORMATrust-analyzer cargo tiff 0.11.3 encoder/colortype/ColorType#SAMPLE_FORMAT.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().) { |
| 638 | (Predictorrust-analyzer cargo tiff 0.11.3 encoder/Predictor#::Horizontalrust-analyzer cargo tiff 0.11.3 tags/Predictor#Horizontal#, _, SampleFormatrust-analyzer cargo tiff 0.11.3 tags/SampleFormat#::IEEEFPrust-analyzer cargo tiff 0.11.3 tags/SampleFormat#IEEEFP# | SampleFormatrust-analyzer cargo tiff 0.11.3 tags/SampleFormat#::Voidrust-analyzer cargo tiff 0.11.3 tags/SampleFormat#Void#) => { |
| 639 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(TiffErrorrust-analyzer cargo tiff 0.11.3 error/TiffError#::UsageErrorrust-analyzer cargo tiff 0.11.3 error/TiffError#UsageError#(UsageErrorrust-analyzer cargo tiff 0.11.3 error/UsageError#::PredictorIncompatiblerust-analyzer cargo tiff 0.11.3 error/UsageError#PredictorIncompatible#)) |
| 640 | } |
| 641 | (Predictorrust-analyzer cargo tiff 0.11.3 encoder/Predictor#::FloatingPointrust-analyzer cargo tiff 0.11.3 tags/Predictor#FloatingPoint#, _, _) => { |
| 642 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(TiffErrorrust-analyzer cargo tiff 0.11.3 error/TiffError#::UsageErrorrust-analyzer cargo tiff 0.11.3 error/TiffError#UsageError#(UsageErrorrust-analyzer cargo tiff 0.11.3 error/UsageError#::PredictorUnavailablerust-analyzer cargo tiff 0.11.3 error/UsageError#PredictorUnavailable#)) |
| 643 | } |
| 644 | _ => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()), |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | fn newrust-analyzer cargo tiff 0.11.3 encoder/impl#[`ImageEncoder<'a, W, T, K>`]new().( |
| 649 | mut encoder: DirectoryEncoderrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#<'a, W, K>, |
| 650 | width: u32, |
| 651 | height: u32, |
| 652 | compression: Compressionrust-analyzer cargo tiff 0.11.3 encoder/Compression#, |
| 653 | predictor: Predictorrust-analyzer cargo tiff 0.11.3 encoder/Predictor#, |
| 654 | ) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<Selfrust-analyzer cargo tiff 0.11.3 encoder/impl#[`ImageEncoder<'a, W, T, K>`]> { |
| 655 | if width rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().0 || height rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().0 { |
| 656 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(TiffErrorrust-analyzer cargo tiff 0.11.3 error/TiffError#::FormatErrorrust-analyzer cargo tiff 0.11.3 error/TiffError#FormatError#(TiffFormatErrorrust-analyzer cargo tiff 0.11.3 error/TiffFormatError#::InvalidDimensionsrust-analyzer cargo tiff 0.11.3 error/TiffFormatError#InvalidDimensions#( |
| 657 | width, height, |
| 658 | ))); |
| 659 | } |
| 660 | |
| 661 | Selfrust-analyzer cargo tiff 0.11.3 encoder/impl#[`ImageEncoder<'a, W, T, K>`]::sanity_checkrust-analyzer cargo tiff 0.11.3 encoder/impl#[`ImageEncoder<'a, W, T, K>`]sanity_check().(compression, predictor)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 662 | |
| 663 | let row_samples = u64::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u64][`From<u32>`]from().(width) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().u64::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/ptr_try_from_impls/impl#[u64][`TryFrom<usize>`]try_from().(<T>::BITS_PER_SAMPLErust-analyzer cargo tiff 0.11.3 encoder/colortype/ColorType#BITS_PER_SAMPLE..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 664 | let row_bytes = row_samples rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().u64::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u64][`From<u8>`]from().(<T::Innerrust-analyzer cargo tiff 0.11.3 encoder/colortype/ColorType#Inner#>::BYTE_LENrust-analyzer cargo tiff 0.11.3 encoder/tiff_value/TiffValue#BYTE_LEN.); |
| 665 | |
| 666 | // Limit the strip size to prevent potential memory and security issues. |
| 667 | // Also keep the multiple strip handling 'oiled' |
| 668 | let rows_per_strip = { |
| 669 | match compression.tagrust-analyzer cargo tiff 0.11.3 encoder/impl#[Compression]tag().() { |
| 670 | CompressionMethodrust-analyzer cargo tiff 0.11.3 tags/CompressionMethod#::PackBitsrust-analyzer cargo tiff 0.11.3 tags/CompressionMethod#PackBits# => 1, // Each row must be packed separately. Do not compress across row boundaries |
| 671 | _ => 1_000_000_u64.div_ceilrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]div_ceil().(row_bytes), |
| 672 | } |
| 673 | }; |
| 674 | |
| 675 | let strip_count = u64::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u64][`From<u32>`]from().(height).div_ceilrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]div_ceil().(rows_per_strip); |
| 676 | |
| 677 | encoder.write_tagrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_tag().(Tagrust-analyzer cargo tiff 0.11.3 tags/Tag#::ImageWidthrust-analyzer cargo tiff 0.11.3 tags/Tag#ImageWidth#, width)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 678 | encoder.write_tagrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_tag().(Tagrust-analyzer cargo tiff 0.11.3 tags/Tag#::ImageLengthrust-analyzer cargo tiff 0.11.3 tags/Tag#ImageLength#, height)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 679 | encoder.write_tagrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_tag().(Tagrust-analyzer cargo tiff 0.11.3 tags/Tag#::Compressionrust-analyzer cargo tiff 0.11.3 tags/Tag#Compression#, compression.tagrust-analyzer cargo tiff 0.11.3 encoder/impl#[Compression]tag().().to_u16rust-analyzer cargo tiff 0.11.3 tags/impl#[CompressionMethod]to_u16().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 680 | encoder.write_tagrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_tag().(Tagrust-analyzer cargo tiff 0.11.3 tags/Tag#::Predictorrust-analyzer cargo tiff 0.11.3 tags/Tag#Predictor#, predictor.to_u16rust-analyzer cargo tiff 0.11.3 tags/impl#[Predictor]to_u16().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 681 | |
| 682 | encoder.write_tagrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_tag().(Tagrust-analyzer cargo tiff 0.11.3 tags/Tag#::PhotometricInterpretationrust-analyzer cargo tiff 0.11.3 tags/Tag#PhotometricInterpretation#, <T>::TIFF_VALUErust-analyzer cargo tiff 0.11.3 encoder/colortype/ColorType#TIFF_VALUE..to_u16rust-analyzer cargo tiff 0.11.3 tags/impl#[PhotometricInterpretation]to_u16().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 683 | |
| 684 | if matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(<T>::TIFF_VALUErust-analyzer cargo tiff 0.11.3 encoder/colortype/ColorType#TIFF_VALUE., PhotometricInterpretationrust-analyzer cargo tiff 0.11.3 tags/PhotometricInterpretation#::YCbCrrust-analyzer cargo tiff 0.11.3 tags/PhotometricInterpretation#YCbCr#) { |
| 685 | // The default for this tag is 2,2 for subsampling but we do not support such a |
| 686 | // transformation. Instead all samples must be provided. |
| 687 | encoder.write_tagrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_tag().(Tagrust-analyzer cargo tiff 0.11.3 tags/Tag#::ChromaSubsamplingrust-analyzer cargo tiff 0.11.3 tags/Tag#ChromaSubsampling#, &[1u16, 1u16][rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 688 | } |
| 689 | |
| 690 | encoder.write_tagrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_tag().(Tagrust-analyzer cargo tiff 0.11.3 tags/Tag#::RowsPerStriprust-analyzer cargo tiff 0.11.3 tags/Tag#RowsPerStrip#, u32::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u32][`TryFrom<u64>`]try_from().(rows_per_strip)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 691 | |
| 692 | encoder.write_tagrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_tag().( |
| 693 | Tagrust-analyzer cargo tiff 0.11.3 tags/Tag#::SamplesPerPixelrust-analyzer cargo tiff 0.11.3 tags/Tag#SamplesPerPixel#, |
| 694 | u16::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/ptr_try_from_impls/impl#[u16][`TryFrom<usize>`]try_from().(<T>::BITS_PER_SAMPLErust-analyzer cargo tiff 0.11.3 encoder/colortype/ColorType#BITS_PER_SAMPLE..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 695 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 696 | encoder.write_tagrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_tag().(Tagrust-analyzer cargo tiff 0.11.3 tags/Tag#::XResolutionrust-analyzer cargo tiff 0.11.3 tags/Tag#XResolution#, Rationalrust-analyzer cargo tiff 0.11.3 encoder/tiff_value/Rational# { nrust-analyzer cargo tiff 0.11.3 encoder/tiff_value/Rational#n.: 1, drust-analyzer cargo tiff 0.11.3 encoder/tiff_value/Rational#d.: 1 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 697 | encoder.write_tagrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_tag().(Tagrust-analyzer cargo tiff 0.11.3 tags/Tag#::YResolutionrust-analyzer cargo tiff 0.11.3 tags/Tag#YResolution#, Rationalrust-analyzer cargo tiff 0.11.3 encoder/tiff_value/Rational# { nrust-analyzer cargo tiff 0.11.3 encoder/tiff_value/Rational#n.: 1, drust-analyzer cargo tiff 0.11.3 encoder/tiff_value/Rational#d.: 1 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 698 | encoder.write_tagrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_tag().(Tagrust-analyzer cargo tiff 0.11.3 tags/Tag#::ResolutionUnitrust-analyzer cargo tiff 0.11.3 tags/Tag#ResolutionUnit#, ResolutionUnitrust-analyzer cargo tiff 0.11.3 tags/ResolutionUnit#::Nonerust-analyzer cargo tiff 0.11.3 tags/ResolutionUnit#None#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 699 | |
| 700 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ImageEncoderrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder# { |
| 701 | encoderrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#encoder., |
| 702 | strip_countrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#strip_count., |
| 703 | strip_idxrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#strip_idx.: 0, |
| 704 | row_samplesrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#row_samples., |
| 705 | rows_per_striprust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#rows_per_strip., |
| 706 | extra_samplesrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#extra_samples.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![], |
| 707 | widthrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#width., |
| 708 | heightrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#height., |
| 709 | strip_offsetsrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#strip_offsets.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(), |
| 710 | strip_byte_countrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#strip_byte_count.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(), |
| 711 | droppedrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#dropped.: false, |
| 712 | compressionrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#compression., |
| 713 | predictorrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#predictor., |
| 714 | _phantomrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#_phantom.: ::stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::markerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/::PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#, |
| 715 | }) |
| 716 | } |
| 717 | |
| 718 | pub fn extra_samplesrust-analyzer cargo tiff 0.11.3 encoder/impl#[`ImageEncoder<'a, W, T, K>`]extra_samples().(&mut self, extra: &[ExtraSamplesrust-analyzer cargo tiff 0.11.3 tags/ExtraSamples#]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), TiffErrorrust-analyzer cargo tiff 0.11.3 error/TiffError#> { |
| 719 | if self.strip_idxrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#strip_idx. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne().0 { |
| 720 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(TiffErrorrust-analyzer cargo tiff 0.11.3 error/TiffError#::UsageErrorrust-analyzer cargo tiff 0.11.3 error/TiffError#UsageError#( |
| 721 | UsageErrorrust-analyzer cargo tiff 0.11.3 error/UsageError#::ReconfiguredAfterImageWriterust-analyzer cargo tiff 0.11.3 error/UsageError#ReconfiguredAfterImageWrite#, |
| 722 | )); |
| 723 | } |
| 724 | |
| 725 | let samples = self.extra_samplesrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#extra_samples..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().extra.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().<T>::BITS_PER_SAMPLErust-analyzer cargo tiff 0.11.3 encoder/colortype/ColorType#BITS_PER_SAMPLE..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(); |
| 726 | let row_samples = u64::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u64][`From<u32>`]from().(self.widthrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#width.) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().u64::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/ptr_try_from_impls/impl#[u64][`TryFrom<usize>`]try_from().(samples)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 727 | |
| 728 | self.extra_samplesrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#extra_samples. |
| 729 | .extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(extra.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(ExtraSamplesrust-analyzer cargo tiff 0.11.3 tags/ExtraSamples#::to_u16rust-analyzer cargo tiff 0.11.3 tags/impl#[ExtraSamples]to_u16().)); |
| 730 | |
| 731 | self.encoderrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#encoder. |
| 732 | .write_tagrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_tag().(Tagrust-analyzer cargo tiff 0.11.3 tags/Tag#::ExtraSamplesrust-analyzer cargo tiff 0.11.3 tags/Tag#ExtraSamples#, &self.extra_samplesrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#extra_samples.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 733 | |
| 734 | self.row_samplesrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#row_samples. = row_samples; |
| 735 | |
| 736 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 737 | } |
| 738 | |
| 739 | /// Number of samples the next strip should have. |
| 740 | pub fn next_strip_sample_countrust-analyzer cargo tiff 0.11.3 encoder/impl#[`ImageEncoder<'a, W, T, K>`]next_strip_sample_count().(&self) -> u64 { |
| 741 | if self.strip_idxrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#strip_idx. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]ge().self.strip_countrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#strip_count. { |
| 742 | return 0; |
| 743 | } |
| 744 | |
| 745 | let raw_start_row = self.strip_idxrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#strip_idx. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().self.rows_per_striprust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#rows_per_strip.; |
| 746 | let start_row = cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().(u64::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u64][`From<u32>`]from().(self.heightrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#height.), raw_start_row); |
| 747 | let end_row = cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().(u64::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u64][`From<u32>`]from().(self.heightrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#height.), raw_start_row rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add().self.rows_per_striprust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#rows_per_strip.); |
| 748 | |
| 749 | (end_row rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub().start_row) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().self.row_samplesrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#row_samples. |
| 750 | } |
| 751 | |
| 752 | /// Write a single strip. |
| 753 | pub fn write_striprust-analyzer cargo tiff 0.11.3 encoder/impl#[`ImageEncoder<'a, W, T, K>`]write_strip().(&mut self, value: &[T::Innerrust-analyzer cargo tiff 0.11.3 encoder/colortype/ColorType#Inner#]) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<()> |
| 754 | where |
| 755 | [T::Innerrust-analyzer cargo tiff 0.11.3 encoder/colortype/ColorType#Inner#]: TiffValuerust-analyzer cargo tiff 0.11.3 encoder/tiff_value/TiffValue#, |
| 756 | { |
| 757 | let samples = self.next_strip_sample_countrust-analyzer cargo tiff 0.11.3 encoder/impl#[`ImageEncoder<'a, W, T, K>`]next_strip_sample_count().(); |
| 758 | if u64::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/ptr_try_from_impls/impl#[u64][`TryFrom<usize>`]try_from().(value.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne().samples { |
| 759 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().( |
| 760 | iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::InvalidDatarust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#InvalidData#, |
| 761 | "Slice is wrong size for strip", |
| 762 | ) |
| 763 | .intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 764 | } |
| 765 | |
| 766 | // Write the (possible compressed) data to the encoder. |
| 767 | let offset = match self.predictorrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#predictor. { |
| 768 | Predictorrust-analyzer cargo tiff 0.11.3 encoder/Predictor#::Nonerust-analyzer cargo tiff 0.11.3 tags/Predictor#None# => self.encoderrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#encoder..write_datarust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_data().(value)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 769 | Predictorrust-analyzer cargo tiff 0.11.3 encoder/Predictor#::Horizontalrust-analyzer cargo tiff 0.11.3 tags/Predictor#Horizontal# => { |
| 770 | let mut row_result = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(value.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()); |
| 771 | for row in value.chunks_exactrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]chunks_exact().(self.row_samplesrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#row_samples. as usize) { |
| 772 | T::horizontal_predictrust-analyzer cargo tiff 0.11.3 encoder/colortype/ColorType#horizontal_predict().(row, &mut row_result); |
| 773 | } |
| 774 | self.encoderrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#encoder..write_datarust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_data().(row_result.as_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_slice().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). |
| 775 | } |
| 776 | _ => unimplementedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unimplemented!!(), |
| 777 | }; |
| 778 | |
| 779 | let byte_count = self.encoderrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#encoder..last_writtenrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]last_written().() as usize; |
| 780 | |
| 781 | self.strip_offsetsrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#strip_offsets..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(K::convert_offsetrust-analyzer cargo tiff 0.11.3 encoder/TiffKind#convert_offset().(offset)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().); |
| 782 | self.strip_byte_countrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#strip_byte_count..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(byte_count.try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().); |
| 783 | |
| 784 | self.strip_idxrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#strip_idx. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`AddAssign<Self>`]add_assign().1; |
| 785 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 786 | } |
| 787 | |
| 788 | /// Write strips from data |
| 789 | pub fn write_datarust-analyzer cargo tiff 0.11.3 encoder/impl#[`ImageEncoder<'a, W, T, K>`]write_data().(mut self, data: &[T::Innerrust-analyzer cargo tiff 0.11.3 encoder/colortype/ColorType#Inner#]) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<()> |
| 790 | where |
| 791 | [T::Innerrust-analyzer cargo tiff 0.11.3 encoder/colortype/ColorType#Inner#]: TiffValuerust-analyzer cargo tiff 0.11.3 encoder/tiff_value/TiffValue#, |
| 792 | { |
| 793 | let num_pix = usize::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/ptr_try_from_impls/impl#[usize][`TryFrom<u32>`]try_from().(self.widthrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#width.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). |
| 794 | .checked_mulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_mul().(usize::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/ptr_try_from_impls/impl#[usize][`TryFrom<u32>`]try_from().(self.heightrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#height.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().) |
| 795 | .ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| { |
| 796 | iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().( |
| 797 | iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::InvalidInputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#InvalidInput#, |
| 798 | "Image width * height exceeds usize", |
| 799 | ) |
| 800 | })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 801 | if data.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().num_pix { |
| 802 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().( |
| 803 | iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::InvalidDatarust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#InvalidData#, |
| 804 | "Input data slice is undersized for provided dimensions", |
| 805 | ) |
| 806 | .intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 807 | } |
| 808 | |
| 809 | self.encoderrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#encoder. |
| 810 | .writerrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#writer. |
| 811 | .set_compressionrust-analyzer cargo tiff 0.11.3 encoder/writer/impl#[`TiffWriter<W>`]set_compression().(self.compressionrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#compression..get_algorithmrust-analyzer cargo tiff 0.11.3 encoder/impl#[Compression]get_algorithm().()); |
| 812 | |
| 813 | let mut idx = 0; |
| 814 | while self.next_strip_sample_countrust-analyzer cargo tiff 0.11.3 encoder/impl#[`ImageEncoder<'a, W, T, K>`]next_strip_sample_count().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().0 { |
| 815 | let sample_count = usize::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/ptr_try_from_impls/impl#[usize][`TryFrom<u64>`]try_from().(self.next_strip_sample_countrust-analyzer cargo tiff 0.11.3 encoder/impl#[`ImageEncoder<'a, W, T, K>`]next_strip_sample_count().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 816 | self.write_striprust-analyzer cargo tiff 0.11.3 encoder/impl#[`ImageEncoder<'a, W, T, K>`]write_strip().(&data[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().idx..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().sample_count]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 817 | idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().sample_count; |
| 818 | } |
| 819 | |
| 820 | self.encoderrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#encoder..writerrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#writer..reset_compressionrust-analyzer cargo tiff 0.11.3 encoder/writer/impl#[`TiffWriter<W>`]reset_compression().(); |
| 821 | self.finishrust-analyzer cargo tiff 0.11.3 encoder/impl#[`ImageEncoder<'a, W, T, K>`]finish().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 822 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 823 | } |
| 824 | |
| 825 | /// Set image resolution |
| 826 | pub fn resolutionrust-analyzer cargo tiff 0.11.3 encoder/impl#[`ImageEncoder<'a, W, T, K>`]resolution().(&mut self, unit: ResolutionUnitrust-analyzer cargo tiff 0.11.3 tags/ResolutionUnit#, value: Rationalrust-analyzer cargo tiff 0.11.3 encoder/tiff_value/Rational#) { |
| 827 | self.encoderrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#encoder. |
| 828 | .write_tagrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_tag().(Tagrust-analyzer cargo tiff 0.11.3 tags/Tag#::ResolutionUnitrust-analyzer cargo tiff 0.11.3 tags/Tag#ResolutionUnit#, unit.to_u16rust-analyzer cargo tiff 0.11.3 tags/impl#[ResolutionUnit]to_u16().()) |
| 829 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 830 | self.encoderrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#encoder. |
| 831 | .write_tagrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_tag().(Tagrust-analyzer cargo tiff 0.11.3 tags/Tag#::XResolutionrust-analyzer cargo tiff 0.11.3 tags/Tag#XResolution#, value.clonerust-analyzer cargo tiff 0.11.3 encoder/tiff_value/impl#[Rational][Clone]clone().()) |
| 832 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 833 | self.encoderrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#encoder..write_tagrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_tag().(Tagrust-analyzer cargo tiff 0.11.3 tags/Tag#::YResolutionrust-analyzer cargo tiff 0.11.3 tags/Tag#YResolution#, value).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 834 | } |
| 835 | |
| 836 | /// Set image resolution unit |
| 837 | pub fn resolution_unitrust-analyzer cargo tiff 0.11.3 encoder/impl#[`ImageEncoder<'a, W, T, K>`]resolution_unit().(&mut self, unit: ResolutionUnitrust-analyzer cargo tiff 0.11.3 tags/ResolutionUnit#) { |
| 838 | self.encoderrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#encoder. |
| 839 | .write_tagrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_tag().(Tagrust-analyzer cargo tiff 0.11.3 tags/Tag#::ResolutionUnitrust-analyzer cargo tiff 0.11.3 tags/Tag#ResolutionUnit#, unit.to_u16rust-analyzer cargo tiff 0.11.3 tags/impl#[ResolutionUnit]to_u16().()) |
| 840 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 841 | } |
| 842 | |
| 843 | /// Set image x-resolution |
| 844 | pub fn x_resolutionrust-analyzer cargo tiff 0.11.3 encoder/impl#[`ImageEncoder<'a, W, T, K>`]x_resolution().(&mut self, value: Rationalrust-analyzer cargo tiff 0.11.3 encoder/tiff_value/Rational#) { |
| 845 | self.encoderrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#encoder..write_tagrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_tag().(Tagrust-analyzer cargo tiff 0.11.3 tags/Tag#::XResolutionrust-analyzer cargo tiff 0.11.3 tags/Tag#XResolution#, value).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 846 | } |
| 847 | |
| 848 | /// Set image y-resolution |
| 849 | pub fn y_resolutionrust-analyzer cargo tiff 0.11.3 encoder/impl#[`ImageEncoder<'a, W, T, K>`]y_resolution().(&mut self, value: Rationalrust-analyzer cargo tiff 0.11.3 encoder/tiff_value/Rational#) { |
| 850 | self.encoderrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#encoder..write_tagrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_tag().(Tagrust-analyzer cargo tiff 0.11.3 tags/Tag#::YResolutionrust-analyzer cargo tiff 0.11.3 tags/Tag#YResolution#, value).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 851 | } |
| 852 | |
| 853 | /// Set image number of lines per strip |
| 854 | /// |
| 855 | /// This function needs to be called before any calls to `write_data` or |
| 856 | /// `write_strip` and will return an error otherwise. |
| 857 | pub fn rows_per_striprust-analyzer cargo tiff 0.11.3 encoder/impl#[`ImageEncoder<'a, W, T, K>`]rows_per_strip().(&mut self, value: u32) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<()> { |
| 858 | if self.strip_idxrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#strip_idx. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne().0 { |
| 859 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().( |
| 860 | iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::InvalidInputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#InvalidInput#, |
| 861 | "Cannot change strip size after data was written", |
| 862 | ) |
| 863 | .intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 864 | } |
| 865 | // Write tag as 32 bits |
| 866 | self.encoderrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#encoder..write_tagrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_tag().(Tagrust-analyzer cargo tiff 0.11.3 tags/Tag#::RowsPerStriprust-analyzer cargo tiff 0.11.3 tags/Tag#RowsPerStrip#, value)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 867 | |
| 868 | let value: u64 = value as u64; |
| 869 | self.strip_countrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#strip_count. = (self.heightrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#height. as u64).div_ceilrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]div_ceil().(value); |
| 870 | self.rows_per_striprust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#rows_per_strip. = value; |
| 871 | |
| 872 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 873 | } |
| 874 | |
| 875 | fn finish_internalrust-analyzer cargo tiff 0.11.3 encoder/impl#[`ImageEncoder<'a, W, T, K>`]finish_internal().(&mut self) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<DirectoryOffsetrust-analyzer cargo tiff 0.11.3 encoder/DirectoryOffset#<K>> { |
| 876 | if self.extra_samplesrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#extra_samples..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 877 | self.encoderrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#encoder. |
| 878 | .write_tagrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_tag().(Tagrust-analyzer cargo tiff 0.11.3 tags/Tag#::BitsPerSamplerust-analyzer cargo tiff 0.11.3 tags/Tag#BitsPerSample#, <T>::BITS_PER_SAMPLErust-analyzer cargo tiff 0.11.3 encoder/colortype/ColorType#BITS_PER_SAMPLE.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 879 | } else { |
| 880 | let mut sample_format: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = <T>::BITS_PER_SAMPLErust-analyzer cargo tiff 0.11.3 encoder/colortype/ColorType#BITS_PER_SAMPLE..to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().(); |
| 881 | let replicated = |
| 882 | corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::repeat_nrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/repeat_n/repeat_n().(<T>::BITS_PER_SAMPLErust-analyzer cargo tiff 0.11.3 encoder/colortype/ColorType#BITS_PER_SAMPLE.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., self.extra_samplesrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#extra_samples..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()); |
| 883 | sample_format.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(replicated); |
| 884 | |
| 885 | self.encoderrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#encoder. |
| 886 | .write_tagrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_tag().(Tagrust-analyzer cargo tiff 0.11.3 tags/Tag#::BitsPerSamplerust-analyzer cargo tiff 0.11.3 tags/Tag#BitsPerSample#, &sample_format[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 887 | |
| 888 | self.encoderrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#encoder..write_tagrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_tag().( |
| 889 | Tagrust-analyzer cargo tiff 0.11.3 tags/Tag#::SamplesPerPixelrust-analyzer cargo tiff 0.11.3 tags/Tag#SamplesPerPixel#, |
| 890 | u16::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/ptr_try_from_impls/impl#[u16][`TryFrom<usize>`]try_from().(<T>::BITS_PER_SAMPLErust-analyzer cargo tiff 0.11.3 encoder/colortype/ColorType#BITS_PER_SAMPLE..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().self.extra_samplesrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#extra_samples..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 891 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 892 | } |
| 893 | |
| 894 | let mut sample_format: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = <T>::SAMPLE_FORMATrust-analyzer cargo tiff 0.11.3 encoder/colortype/ColorType#SAMPLE_FORMAT..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|s| s.to_u16rust-analyzer cargo tiff 0.11.3 tags/impl#[SampleFormat]to_u16().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 895 | let extra_format = sample_format |
| 896 | .firstrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]first().() |
| 897 | .copiedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<&T>`]copied().() |
| 898 | // Frankly should not occur, we have no sample format without at least one entry. We |
| 899 | // would need an interface upgrade to handle this however. Either decide to support |
| 900 | // heterogeneous sample formats or a way to provide fallback that is used for purely |
| 901 | // extra samples and not provided via a slice used for samples themselves. |
| 902 | .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(SampleFormatrust-analyzer cargo tiff 0.11.3 tags/SampleFormat#::Voidrust-analyzer cargo tiff 0.11.3 tags/SampleFormat#Void#.to_u16rust-analyzer cargo tiff 0.11.3 tags/impl#[SampleFormat]to_u16().()); |
| 903 | |
| 904 | sample_format.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::repeat_nrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/repeat_n/repeat_n().(extra_format, self.extra_samplesrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#extra_samples..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().())); |
| 905 | |
| 906 | self.encoderrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#encoder. |
| 907 | .write_tagrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_tag().(Tagrust-analyzer cargo tiff 0.11.3 tags/Tag#::SampleFormatrust-analyzer cargo tiff 0.11.3 tags/Tag#SampleFormat#, &sample_format[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 908 | |
| 909 | self.encoderrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#encoder. |
| 910 | .write_tagrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_tag().(Tagrust-analyzer cargo tiff 0.11.3 tags/Tag#::StripOffsetsrust-analyzer cargo tiff 0.11.3 tags/Tag#StripOffsets#, K::convert_slicerust-analyzer cargo tiff 0.11.3 encoder/TiffKind#convert_slice().(&self.strip_offsetsrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#strip_offsets.))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 911 | self.encoderrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#encoder..write_tagrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]write_tag().( |
| 912 | Tagrust-analyzer cargo tiff 0.11.3 tags/Tag#::StripByteCountsrust-analyzer cargo tiff 0.11.3 tags/Tag#StripByteCounts#, |
| 913 | K::convert_slicerust-analyzer cargo tiff 0.11.3 encoder/TiffKind#convert_slice().(&self.strip_byte_countrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#strip_byte_count.), |
| 914 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 915 | self.droppedrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#dropped. = true; |
| 916 | |
| 917 | self.encoderrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#encoder..finish_internalrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]finish_internal().() |
| 918 | } |
| 919 | |
| 920 | /// Get a reference of the underlying `DirectoryEncoder` |
| 921 | pub fn encoderrust-analyzer cargo tiff 0.11.3 encoder/impl#[`ImageEncoder<'a, W, T, K>`]encoder().(&mut self) -> &mut DirectoryEncoderrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEncoder#<'a, W, K> { |
| 922 | &mut self.encoderrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#encoder. |
| 923 | } |
| 924 | |
| 925 | /// Write out image and ifd directory. |
| 926 | pub fn finishrust-analyzer cargo tiff 0.11.3 encoder/impl#[`ImageEncoder<'a, W, T, K>`]finish().(mut self) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<()> { |
| 927 | self.finish_internalrust-analyzer cargo tiff 0.11.3 encoder/impl#[`ImageEncoder<'a, W, T, K>`]finish_internal().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 928 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 929 | } |
| 930 | } |
| 931 | |
| 932 | impl<'a, W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write# + Seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#, C: ColorTyperust-analyzer cargo tiff 0.11.3 encoder/colortype/ColorType#, K: TiffKindrust-analyzer cargo tiff 0.11.3 encoder/TiffKind#> Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for ImageEncoderrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#<'a, W, C, K> { |
| 933 | fn droprust-analyzer cargo tiff 0.11.3 encoder/impl#[`ImageEncoder<'a, W, C, K>`][Drop]drop().(&mut self) { |
| 934 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.droppedrust-analyzer cargo tiff 0.11.3 encoder/ImageEncoder#dropped. { |
| 935 | let _ = self.finish_internalrust-analyzer cargo tiff 0.11.3 encoder/impl#[`ImageEncoder<'a, W, T, K>`]finish_internal().(); |
| 936 | } |
| 937 | } |
| 938 | } |
| 939 | |
| 940 | struct DirectoryEntryrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEntry#<'data, S> { |
| 941 | data_typerust-analyzer cargo tiff 0.11.3 encoder/DirectoryEntry#data_type.: Typerust-analyzer cargo tiff 0.11.3 tags/Type#, |
| 942 | countrust-analyzer cargo tiff 0.11.3 encoder/DirectoryEntry#count.: S, |
| 943 | datarust-analyzer cargo tiff 0.11.3 encoder/DirectoryEntry#data.: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'data, [u8]>, |
| 944 | } |
| 945 | |
| 946 | /// Trait to abstract over Tiff/BigTiff differences. |
| 947 | /// |
| 948 | /// Implemented for [`TiffKindStandard`] and [`TiffKindBig`]. |
| 949 | pub trait TiffKindrust-analyzer cargo tiff 0.11.3 encoder/TiffKind# { |
| 950 | /// The type of offset fields, `u32` for normal Tiff, `u64` for BigTiff. |
| 951 | type OffsetTyperust-analyzer cargo tiff 0.11.3 encoder/TiffKind#OffsetType#: TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#<usize, Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#Error# = TryFromIntErrorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/error/TryFromIntError#> + Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<u64> + TiffValuerust-analyzer cargo tiff 0.11.3 encoder/tiff_value/TiffValue#; |
| 952 | |
| 953 | /// Needed for the `convert_slice` method. |
| 954 | type OffsetArrayTyperust-analyzer cargo tiff 0.11.3 encoder/TiffKind#OffsetArrayType#: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# + TiffValuerust-analyzer cargo tiff 0.11.3 encoder/tiff_value/TiffValue#; |
| 955 | |
| 956 | /// Write the (Big)Tiff header. |
| 957 | fn write_headerrust-analyzer cargo tiff 0.11.3 encoder/TiffKind#write_header().<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#>(writer: &mut TiffWriterrust-analyzer cargo tiff 0.11.3 encoder/writer/TiffWriter#<W>) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<()>; |
| 958 | |
| 959 | /// Convert a file offset to `Self::OffsetType`. |
| 960 | /// |
| 961 | /// This returns an error for normal Tiff if the offset is larger than `u32::MAX`. |
| 962 | fn convert_offsetrust-analyzer cargo tiff 0.11.3 encoder/TiffKind#convert_offset().(offset: u64) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<Self::OffsetTyperust-analyzer cargo tiff 0.11.3 encoder/TiffKind#OffsetType#>; |
| 963 | |
| 964 | /// Write an offset value to the given writer. |
| 965 | /// |
| 966 | /// Like `convert_offset`, this errors if `offset > u32::MAX` for normal Tiff. |
| 967 | fn write_offsetrust-analyzer cargo tiff 0.11.3 encoder/TiffKind#write_offset().<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#>(writer: &mut TiffWriterrust-analyzer cargo tiff 0.11.3 encoder/writer/TiffWriter#<W>, offset: u64) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<()>; |
| 968 | |
| 969 | /// Write the IFD entry count field with the given `count` value. |
| 970 | /// |
| 971 | /// The entry count field is an `u16` for normal Tiff and `u64` for BigTiff. Errors |
| 972 | /// if the given `usize` is larger than the representable values. |
| 973 | fn write_entry_countrust-analyzer cargo tiff 0.11.3 encoder/TiffKind#write_entry_count().<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#>(writer: &mut TiffWriterrust-analyzer cargo tiff 0.11.3 encoder/writer/TiffWriter#<W>, count: usize) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<()>; |
| 974 | |
| 975 | /// Internal helper method for satisfying Rust's type checker. |
| 976 | /// |
| 977 | /// The `TiffValue` trait is implemented for both primitive values (e.g. `u8`, `u32`) and |
| 978 | /// slices of primitive values (e.g. `[u8]`, `[u32]`). However, this is not represented in |
| 979 | /// the type system, so there is no guarantee that that for all `T: TiffValue` there is also |
| 980 | /// an implementation of `TiffValue` for `[T]`. This method works around that problem by |
| 981 | /// providing a conversion from `[T]` to some value that implements `TiffValue`, thereby |
| 982 | /// making all slices of `OffsetType` usable with `write_tag` and similar methods. |
| 983 | /// |
| 984 | /// Implementations of this trait should always set `OffsetArrayType` to `[OffsetType]`. |
| 985 | fn convert_slicerust-analyzer cargo tiff 0.11.3 encoder/TiffKind#convert_slice().(slice: &[Self::OffsetTyperust-analyzer cargo tiff 0.11.3 encoder/TiffKind#OffsetType#]) -> &Self::OffsetArrayTyperust-analyzer cargo tiff 0.11.3 encoder/TiffKind#OffsetArrayType#; |
| 986 | } |
| 987 | |
| 988 | impl<K: TiffKindrust-analyzer cargo tiff 0.11.3 encoder/TiffKind#> DirectoryOffsetrust-analyzer cargo tiff 0.11.3 encoder/DirectoryOffset#<K> { |
| 989 | /// Construct the directory pointer information from its raw offset. |
| 990 | /// |
| 991 | /// Fails in these cases: |
| 992 | /// |
| 993 | /// - if start offset is too large to be represented with the chosen TIFF format, i.e. a value |
| 994 | /// larger than [`u32::MAX`] with a standard tiff which is only valid in a BigTiff. This |
| 995 | /// returns [`TiffError::IntSizeError`]. |
| 996 | /// - the extent of the directory would overflow the file length. This returns a |
| 997 | /// [`TiffError::UsageError`]. |
| 998 | /// |
| 999 | /// The library does *not* validate the contents or offset in any way, it just performs the |
| 1000 | /// necessary math assuming the data is an accurate representation of existing content. |
| 1001 | /// |
| 1002 | /// # Examples |
| 1003 | /// |
| 1004 | /// If you have any custom way of writing a directory to a file that can not go through the |
| 1005 | /// usual [`TiffEncoder::extra_directory`] then you can reconstruct the offset information as |
| 1006 | /// long as you provide all the necessary data to the library. You can then use it as a parent |
| 1007 | /// directory, i.e. have the library overwrite its `next` field. |
| 1008 | /// |
| 1009 | /// ``` |
| 1010 | /// use tiff::{ |
| 1011 | /// encoder::{TiffEncoder, DirectoryOffset}, |
| 1012 | /// Directory, |
| 1013 | /// tags::IfdPointer, |
| 1014 | /// }; |
| 1015 | /// |
| 1016 | /// # let mut file = std::io::Cursor::new(Vec::new()); |
| 1017 | /// let mut tiff = TiffEncoder::new(&mut file)?; |
| 1018 | /// |
| 1019 | /// // … some custom data writes, assume we know where a directory was written |
| 1020 | /// # fn reconstruction_of_your_directory() -> Directory { Directory::from_iter([]) } |
| 1021 | /// let known_offset = IfdPointer(1024); |
| 1022 | /// let known_contents: Directory = reconstruction_of_your_directory(); |
| 1023 | /// |
| 1024 | /// let reconstructed = DirectoryOffset::new(known_offset, &known_contents)?; |
| 1025 | /// |
| 1026 | /// // Now we can use it as if the directory was written by the `TiffEncoder` itself. |
| 1027 | /// let mut chain = tiff.extra_directory()?; |
| 1028 | /// chain.set_parent(&reconstructed); |
| 1029 | /// chain.finish_with_offsets()?; |
| 1030 | /// |
| 1031 | /// # Ok::<_, tiff::TiffError>(()) |
| 1032 | /// ``` |
| 1033 | pub fn newrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryOffset<K>`]new().(pointer: IfdPointerrust-analyzer cargo tiff 0.11.3 tags/IfdPointer#, dir: &Directoryrust-analyzer cargo tiff 0.11.3 directory/Directory#) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<Selfrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryOffset<K>`]> { |
| 1034 | let offset = K::convert_offsetrust-analyzer cargo tiff 0.11.3 encoder/TiffKind#convert_offset().(pointer.0rust-analyzer cargo tiff 0.11.3 tags/IfdPointer#0.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 1035 | let encoded = dir.encoded_lenrust-analyzer cargo tiff 0.11.3 directory/impl#[Directory]encoded_len().::<K>(); |
| 1036 | let offset_field_offset = encoded rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub().memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_of_valrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of_val().(&offset) as u64; |
| 1037 | |
| 1038 | let ifd_chain = pointer |
| 1039 | .0rust-analyzer cargo tiff 0.11.3 tags/IfdPointer#0. |
| 1040 | .checked_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]checked_add().(offset_field_offset) |
| 1041 | .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(NonZeroU64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU64#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/impl#[`NonZero<T>`]new().) |
| 1042 | .ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(TiffErrorrust-analyzer cargo tiff 0.11.3 error/TiffError#::UsageErrorrust-analyzer cargo tiff 0.11.3 error/TiffError#UsageError#(UsageErrorrust-analyzer cargo tiff 0.11.3 error/UsageError#::ZeroIfdPointerrust-analyzer cargo tiff 0.11.3 error/UsageError#ZeroIfdPointer#))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 1043 | |
| 1044 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(DirectoryOffsetrust-analyzer cargo tiff 0.11.3 encoder/DirectoryOffset# { |
| 1045 | pointerrust-analyzer cargo tiff 0.11.3 encoder/DirectoryOffset#pointer., |
| 1046 | offsetrust-analyzer cargo tiff 0.11.3 encoder/DirectoryOffset#offset., |
| 1047 | ifd_chainrust-analyzer cargo tiff 0.11.3 encoder/DirectoryOffset#ifd_chain., |
| 1048 | kindrust-analyzer cargo tiff 0.11.3 encoder/DirectoryOffset#kind.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#, |
| 1049 | }) |
| 1050 | } |
| 1051 | } |
| 1052 | |
| 1053 | /// Create a standard Tiff file. |
| 1054 | pub struct TiffKindStandardrust-analyzer cargo tiff 0.11.3 encoder/TiffKindStandard#; |
| 1055 | |
| 1056 | impl TiffKindrust-analyzer cargo tiff 0.11.3 encoder/TiffKind# for TiffKindStandardrust-analyzer cargo tiff 0.11.3 encoder/TiffKindStandard# { |
| 1057 | type OffsetTyperust-analyzer cargo tiff 0.11.3 encoder/impl#[TiffKindStandard][TiffKind]OffsetType# = u32; |
| 1058 | type OffsetArrayTyperust-analyzer cargo tiff 0.11.3 encoder/impl#[TiffKindStandard][TiffKind]OffsetArrayType# = [u32]; |
| 1059 | |
| 1060 | fn write_headerrust-analyzer cargo tiff 0.11.3 encoder/impl#[TiffKindStandard][TiffKind]write_header().<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#>(writer: &mut TiffWriterrust-analyzer cargo tiff 0.11.3 encoder/writer/TiffWriter#<W>) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<()> { |
| 1061 | write_tiff_headerrust-analyzer cargo tiff 0.11.3 encoder/writer/write_tiff_header().(writer)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 1062 | // blank the IFD offset location |
| 1063 | writer.write_u32rust-analyzer cargo tiff 0.11.3 encoder/writer/impl#[`TiffWriter<W>`]write_u32().(0)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 1064 | |
| 1065 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 1066 | } |
| 1067 | |
| 1068 | fn convert_offsetrust-analyzer cargo tiff 0.11.3 encoder/impl#[TiffKindStandard][TiffKind]convert_offset().(offset: u64) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<Selfrust-analyzer cargo tiff 0.11.3 encoder/impl#[TiffKindStandard][TiffKind]::OffsetTyperust-analyzer cargo tiff 0.11.3 encoder/TiffKind#OffsetType#> { |
| 1069 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo tiff 0.11.3 encoder/impl#[TiffKindStandard][TiffKind]::OffsetTyperust-analyzer cargo tiff 0.11.3 encoder/TiffKind#OffsetType#::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u32][`TryFrom<u64>`]try_from().(offset)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().) |
| 1070 | } |
| 1071 | |
| 1072 | fn write_offsetrust-analyzer cargo tiff 0.11.3 encoder/impl#[TiffKindStandard][TiffKind]write_offset().<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#>(writer: &mut TiffWriterrust-analyzer cargo tiff 0.11.3 encoder/writer/TiffWriter#<W>, offset: u64) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<()> { |
| 1073 | writer.write_u32rust-analyzer cargo tiff 0.11.3 encoder/writer/impl#[`TiffWriter<W>`]write_u32().(u32::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u32][`TryFrom<u64>`]try_from().(offset)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 1074 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 1075 | } |
| 1076 | |
| 1077 | fn write_entry_countrust-analyzer cargo tiff 0.11.3 encoder/impl#[TiffKindStandard][TiffKind]write_entry_count().<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#>(writer: &mut TiffWriterrust-analyzer cargo tiff 0.11.3 encoder/writer/TiffWriter#<W>, count: usize) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<()> { |
| 1078 | writer.write_u16rust-analyzer cargo tiff 0.11.3 encoder/writer/impl#[`TiffWriter<W>`]write_u16().(u16::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/ptr_try_from_impls/impl#[u16][`TryFrom<usize>`]try_from().(count)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 1079 | |
| 1080 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 1081 | } |
| 1082 | |
| 1083 | fn convert_slicerust-analyzer cargo tiff 0.11.3 encoder/impl#[TiffKindStandard][TiffKind]convert_slice().(slice: &[Selfrust-analyzer cargo tiff 0.11.3 encoder/impl#[TiffKindStandard][TiffKind]::OffsetTyperust-analyzer cargo tiff 0.11.3 encoder/TiffKind#OffsetType#]) -> &Selfrust-analyzer cargo tiff 0.11.3 encoder/impl#[TiffKindStandard][TiffKind]::OffsetArrayTyperust-analyzer cargo tiff 0.11.3 encoder/TiffKind#OffsetArrayType# { |
| 1084 | slice |
| 1085 | } |
| 1086 | } |
| 1087 | |
| 1088 | /// Create a BigTiff file. |
| 1089 | pub struct TiffKindBigrust-analyzer cargo tiff 0.11.3 encoder/TiffKindBig#; |
| 1090 | |
| 1091 | impl TiffKindrust-analyzer cargo tiff 0.11.3 encoder/TiffKind# for TiffKindBigrust-analyzer cargo tiff 0.11.3 encoder/TiffKindBig# { |
| 1092 | type OffsetTyperust-analyzer cargo tiff 0.11.3 encoder/impl#[TiffKindBig][TiffKind]OffsetType# = u64; |
| 1093 | type OffsetArrayTyperust-analyzer cargo tiff 0.11.3 encoder/impl#[TiffKindBig][TiffKind]OffsetArrayType# = [u64]; |
| 1094 | |
| 1095 | fn write_headerrust-analyzer cargo tiff 0.11.3 encoder/impl#[TiffKindBig][TiffKind]write_header().<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#>(writer: &mut TiffWriterrust-analyzer cargo tiff 0.11.3 encoder/writer/TiffWriter#<W>) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<()> { |
| 1096 | write_bigtiff_headerrust-analyzer cargo tiff 0.11.3 encoder/writer/write_bigtiff_header().(writer)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 1097 | // blank the IFD offset location |
| 1098 | writer.write_u64rust-analyzer cargo tiff 0.11.3 encoder/writer/impl#[`TiffWriter<W>`]write_u64().(0)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 1099 | |
| 1100 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 1101 | } |
| 1102 | |
| 1103 | fn convert_offsetrust-analyzer cargo tiff 0.11.3 encoder/impl#[TiffKindBig][TiffKind]convert_offset().(offset: u64) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<Selfrust-analyzer cargo tiff 0.11.3 encoder/impl#[TiffKindBig][TiffKind]::OffsetTyperust-analyzer cargo tiff 0.11.3 encoder/TiffKind#OffsetType#> { |
| 1104 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(offset) |
| 1105 | } |
| 1106 | |
| 1107 | fn write_offsetrust-analyzer cargo tiff 0.11.3 encoder/impl#[TiffKindBig][TiffKind]write_offset().<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#>(writer: &mut TiffWriterrust-analyzer cargo tiff 0.11.3 encoder/writer/TiffWriter#<W>, offset: u64) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<()> { |
| 1108 | writer.write_u64rust-analyzer cargo tiff 0.11.3 encoder/writer/impl#[`TiffWriter<W>`]write_u64().(offset)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 1109 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 1110 | } |
| 1111 | |
| 1112 | fn write_entry_countrust-analyzer cargo tiff 0.11.3 encoder/impl#[TiffKindBig][TiffKind]write_entry_count().<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#>(writer: &mut TiffWriterrust-analyzer cargo tiff 0.11.3 encoder/writer/TiffWriter#<W>, count: usize) -> TiffResultrust-analyzer cargo tiff 0.11.3 error/TiffResult#<()> { |
| 1113 | writer.write_u64rust-analyzer cargo tiff 0.11.3 encoder/writer/impl#[`TiffWriter<W>`]write_u64().(u64::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/ptr_try_from_impls/impl#[u64][`TryFrom<usize>`]try_from().(count)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 1114 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 1115 | } |
| 1116 | |
| 1117 | fn convert_slicerust-analyzer cargo tiff 0.11.3 encoder/impl#[TiffKindBig][TiffKind]convert_slice().(slice: &[Selfrust-analyzer cargo tiff 0.11.3 encoder/impl#[TiffKindBig][TiffKind]::OffsetTyperust-analyzer cargo tiff 0.11.3 encoder/TiffKind#OffsetType#]) -> &Selfrust-analyzer cargo tiff 0.11.3 encoder/impl#[TiffKindBig][TiffKind]::OffsetArrayTyperust-analyzer cargo tiff 0.11.3 encoder/TiffKind#OffsetArrayType# { |
| 1118 | slice |
| 1119 | } |
| 1120 | } |
| 1121 | |
| 1122 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1123 | fn directory_offset_new_equivalent_to_writingrust-analyzer cargo tiff 0.11.3 encoder/directory_offset_new_equivalent_to_writing().() { |
| 1124 | type Krust-analyzer cargo tiff 0.11.3 encoder/K# = TiffKindStandardrust-analyzer cargo tiff 0.11.3 encoder/TiffKindStandard#; |
| 1125 | |
| 1126 | let dir = Directoryrust-analyzer cargo tiff 0.11.3 directory/Directory#::from_iterrust-analyzer cargo tiff 0.11.3 directory/impl#[Directory][`FromIterator<(Tag, Entry)>`]from_iter().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 1127 | ( |
| 1128 | Tagrust-analyzer cargo tiff 0.11.3 tags/Tag#::ImageWidthrust-analyzer cargo tiff 0.11.3 tags/Tag#ImageWidth#, |
| 1129 | Entryrust-analyzer cargo tiff 0.11.3 decoder/ifd/Entry#::newrust-analyzer cargo tiff 0.11.3 decoder/ifd/impl#[Entry]new().(Typerust-analyzer cargo tiff 0.11.3 tags/Type#::LONGrust-analyzer cargo tiff 0.11.3 tags/Type#LONG#, 1, 100u32.to_ne_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]to_ne_bytes().()), |
| 1130 | ), |
| 1131 | ( |
| 1132 | Tagrust-analyzer cargo tiff 0.11.3 tags/Tag#::ImageLengthrust-analyzer cargo tiff 0.11.3 tags/Tag#ImageLength#, |
| 1133 | Entryrust-analyzer cargo tiff 0.11.3 decoder/ifd/Entry#::newrust-analyzer cargo tiff 0.11.3 decoder/ifd/impl#[Entry]new().(Typerust-analyzer cargo tiff 0.11.3 tags/Type#::LONGrust-analyzer cargo tiff 0.11.3 tags/Type#LONG#, 1, 200u32.to_ne_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]to_ne_bytes().()), |
| 1134 | ), |
| 1135 | ]); |
| 1136 | |
| 1137 | let data = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Cursorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/Cursor#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`]new().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]); |
| 1138 | let mut file = TiffEncoderrust-analyzer cargo tiff 0.11.3 encoder/TiffEncoder#::newrust-analyzer cargo tiff 0.11.3 encoder/impl#[`TiffEncoder<W>`]new().(data).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1139 | |
| 1140 | let mut as_dir_encoder = file.extra_directoryrust-analyzer cargo tiff 0.11.3 encoder/impl#[`TiffEncoder<W, K>`]extra_directory().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1141 | as_dir_encoder.extend_fromrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]extend_from().(&dir); |
| 1142 | let dir_extent = as_dir_encoder.finish_with_offsetsrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryEncoder<'a, W, K>`]finish_with_offsets().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1143 | |
| 1144 | // Check we can recreate the extent had we written ourselves. |
| 1145 | let synth = DirectoryOffsetrust-analyzer cargo tiff 0.11.3 encoder/DirectoryOffset#::<Krust-analyzer cargo tiff 0.11.3 encoder/K#>::newrust-analyzer cargo tiff 0.11.3 encoder/impl#[`DirectoryOffset<K>`]new().(dir_extent.pointerrust-analyzer cargo tiff 0.11.3 encoder/DirectoryOffset#pointer., &dir).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1146 | |
| 1147 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(synth.pointerrust-analyzer cargo tiff 0.11.3 encoder/DirectoryOffset#pointer., dir_extent.pointerrust-analyzer cargo tiff 0.11.3 encoder/DirectoryOffset#pointer.); |
| 1148 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(synth.offsetrust-analyzer cargo tiff 0.11.3 encoder/DirectoryOffset#offset., dir_extent.offsetrust-analyzer cargo tiff 0.11.3 encoder/DirectoryOffset#offset.); |
| 1149 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(synth.ifd_chainrust-analyzer cargo tiff 0.11.3 encoder/DirectoryOffset#ifd_chain., dir_extent.ifd_chainrust-analyzer cargo tiff 0.11.3 encoder/DirectoryOffset#ifd_chain.); |
| 1150 | } |