### Read TIFF Directory Tags (Rust Example) Source: https://docs.rs/tiff/latest/tiff/decoder/struct.Decoder_search= Prepares to read tag values for a given TIFF directory. This Rust example demonstrates iterating through sub-IFDs and finding specific tags like 'SubfileType'. ```rust pub fn read_directory_tags<'ifd>( &'ifd mut self, ifd: &'ifd Directory, ) -> IfdDecoder<'ifd> Prepare reading values for tags of a given directory. ##### §Examples This method may be used to read the values of tags in directories that have been previously read with `Decoder::read_directory`. ``` use tiff::decoder::Decoder; use tiff::tags::Tag; let mut decoder = Decoder::new(&mut data).unwrap(); let sub_ifds = decoder.get_tag(Tag::SubIfd)?.into_ifd_vec()?; for ifd in sub_ifds { let subdir = decoder.read_directory(ifd)?; let subfile = decoder.read_directory_tags(&subdir).find_tag(Tag::SubfileType)?; // omitted: handle the subfiles, e.g. thumbnails } ``` ``` -------------------------------- ### Rust: Example of Reading Subdirectories and Tags Source: https://docs.rs/tiff/latest/src/tiff/decoder/mod.rs_search=u32+-%3E+bool This example demonstrates how to use the `Decoder` to read subdirectories and then find specific tags within those subdirectories. It involves retrieving `SubIfd` tags, iterating through them, and extracting information like `SubfileType`. This is useful for handling multi-page or multi-resolution TIFF files. Dependencies include `tiff::decoder::Decoder` and `tiff::tags::Tag`. ```rust use tiff::decoder::Decoder; use tiff::tags::Tag; # use std::io::Cursor; # let mut data = Cursor::new(vec![0]); let mut decoder = Decoder::new(&mut data).unwrap(); let sub_ifds = decoder.get_tag(Tag::SubIfd)?.into_ifd_vec()?; for ifd in sub_ifds { let subdir = decoder.read_directory(ifd)?; let subfile = decoder.read_directory_tags(&subdir).find_tag(Tag::SubfileType)?; // omitted: handle the subfiles, e.g. thumbnails } # Ok::<_, tiff::TiffError>(()) ``` -------------------------------- ### Handling File Metadata with Result.and_then Source: https://docs.rs/tiff/latest/tiff/type.TiffResult Illustrates using `and_then` to handle potential errors when retrieving file metadata. This example shows how to chain operations that might fail, such as getting metadata and then accessing its modified time, ensuring errors are propagated correctly. ```rust use std::{io::ErrorKind, path::Path}; // Note: on Windows "/" maps to "C:\" let root_modified_time = Path::new("/").metadata().and_then(|md| md.modified()); assert!(root_modified_time.is_ok()); let should_fail = Path::new("/bad/path").metadata().and_then(|md| md.modified()); assert!(should_fail.is_err()); assert_eq!(should_fail.unwrap_err().kind(), ErrorKind::NotFound); ``` -------------------------------- ### Rust: Example Usage of TiffEncoder for Image Encoding Source: https://docs.rs/tiff/latest/src/tiff/encoder/mod.rs_search=std%3A%3Avec This example demonstrates how to use `TiffEncoder` to create a new image, set tags, configure strip size, and write image data row by row. It covers initializing the encoder, creating an image with a specific color type, writing tags like 'Artist', setting 'rows_per_strip', and iterating through strips to write image data. ```rust 456# extern crate tiff; 457# fn main() { 458# let mut file = std::io::Cursor::new(Vec::new()); 459# let image_data = vec![0; 100*100*3]; 460use tiff::encoder::* 461use tiff::tags::Tag; 462 463let mut tiff = TiffEncoder::new(&mut file).unwrap(); 464let mut image = tiff.new_image::(100, 100).unwrap(); 465 466// You can encode tags here 467image.encoder().write_tag(Tag::Artist, "Image-tiff").unwrap(); 468 469// Strip size can be configured before writing data 470image.rows_per_strip(2).unwrap(); 471 472let mut idx = 0; 473while image.next_strip_sample_count() > 0 { 474 let sample_count = image.next_strip_sample_count() as usize; 475 image.write_strip(&image_data[idx..idx+sample_count]).unwrap(); 476 idx += sample_count; 477} 478image.finish().unwrap(); 479# } 480``` ``` -------------------------------- ### Directory Size and IFD Pointer Source: https://docs.rs/tiff/latest/tiff/struct.Directory_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Methods for getting the number of entries and managing the pointer to the next IFD. ```APIDOC ## Directory Size and IFD Pointer ### Methods #### `len()` - **Description**: Gets the number of entries in the directory. - **Signature**: `pub fn len(&self) -> usize` - **Returns**: The number of entries. #### `next()` - **Description**: Gets the pointer to the next IFD, if it was defined. - **Signature**: `pub fn next(&self) -> Option` - **Returns**: An `Option` containing the `IfdPointer` to the next IFD, or `None` if no next IFD is set. #### `set_next(next: Option)` - **Description**: Sets the pointer to the next IFD. - **Signature**: `pub fn set_next(&mut self, next: Option)` - **Parameters**: - **next** (Option) - The `IfdPointer` to the next IFD, or `None` to unset it. ``` -------------------------------- ### Rust: Get Metadata Modified Time with Error Handling Source: https://docs.rs/tiff/latest/tiff/type.TiffResult_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Shows how to get the modification time of a file path using `metadata().and_then(|md| md.modified())`. It includes examples for both successful retrieval and expected `NotFound` errors for invalid paths. ```rust use std::{io::ErrorKind, path::Path}; // Note: on Windows "/" maps to "C:\\" let root_modified_time = Path::new("/").metadata().and_then(|md| md.modified()); assert!(root_modified_time.is_ok()); let should_fail = Path::new("/bad/path").metadata().and_then(|md| md.modified()); assert!(should_fail.is_err()); assert_eq!(should_fail.unwrap_err().kind(), ErrorKind::NotFound); ``` -------------------------------- ### Decoder Implementations Source: https://docs.rs/tiff/latest/tiff/decoder/struct.Decoder_search= Provides methods for initializing and interacting with the TIFF decoder, such as setting limits, retrieving image properties, and reading data. ```APIDOC ## Implementations for Decoder ### `Decoder` where `R: Read + Seek` #### `fn new(r: R) -> TiffResult>` Creates a new `Decoder` instance with the provided reader. #### `fn with_limits(self, limits: Limits) -> Decoder>` Sets decoding limits for the `Decoder`. #### `fn dimensions(&mut self) -> TiffResult<(u32, u32)>` Returns the dimensions (width and height) of the current image. #### `fn colortype(&mut self) -> TiffResult` Returns the `ColorType` of the current image. #### `fn ifd_pointer(&mut self) -> Option` Returns the offset of the directory representing the current image. #### `fn seek_to_image(&mut self, ifd_index: usize) -> TiffResult<()>` Loads the IFD at the specified index in the list, if one exists. #### `fn next_image(&mut self) -> TiffResult<()>` Reads in the next image. Returns a format error if there is no further image in the TIFF file. To determine whether there are more images, call `TIFFDecoder::more_images` instead. #### `fn more_images(&self) -> bool` Returns `true` if there is at least one more image available. #### `fn byte_order(&self) -> ByteOrder` Returns the byte order of the file. #### `fn read_ifd_offset(&mut self) -> Result` Reads the offset of an IFD (Image File Directory). #### `fn inner(&mut self) -> &mut R` Returns a mutable reference to the underlying reader stream. #### `fn read_byte(&mut self) -> Result` Reads a single TIFF byte value from the stream. #### `fn read_short(&mut self) -> Result` Reads a TIFF short (16-bit unsigned integer) value from the stream. #### `fn read_sshort(&mut self) -> Result` Reads a TIFF signed short (16-bit signed integer) value from the stream. #### `fn read_long(&mut self) -> Result` Reads a TIFF long (32-bit unsigned integer) value from the stream. #### `fn read_slong(&mut self) -> Result` Reads a TIFF signed long (32-bit signed integer) value from the stream. #### `fn read_float(&mut self) -> Result` Reads a TIFF float (32-bit floating-point) value from the stream. #### `fn read_double(&mut self) -> Result` Reads a TIFF double (64-bit floating-point) value from the stream. #### `fn read_long8(&mut self) -> Result` Reads a TIFF long8 (64-bit unsigned integer) value from the stream. #### `fn read_slong8(&mut self) -> Result` Reads a TIFF signed long8 (64-bit signed integer) value from the stream. #### `fn read_string(&mut self, length: usize) -> TiffResult` Reads a string of the specified length from the stream. #### `fn read_offset(&mut self) -> TiffResult<[u8; 4]>` Reads a TIFF IFA offset/value field (4 bytes). #### `fn read_offset_u64(&mut self) -> Result<[u8; 8], Error>` Reads a TIFF IFA offset/value field (8 bytes). #### `fn goto_offset(&mut self, offset: u32) -> Result<()>` Moves the reader's cursor to the specified 32-bit offset. #### `fn goto_offset_u64(&mut self, offset: u64) -> Result<()>` Moves the reader's cursor to the specified 64-bit offset. #### `fn read_directory(&mut self, ptr: IfdPointer) -> TiffResult` Reads a tag-entry map (Directory) from a known offset. A TIFF `Directory`, also known as an Image File Directory (IFD), refers to a map from tags (identified by a `u16`) to a typed vector of elements. It is encoded as a list of ascending tag values with the offset and type of their corresponding values. The semantic interpretations of a tag and its type requirements depend on the context of the directory. The main image directories, those iterated over by the `Decoder` after construction, are represented by `Tag` and `ifd::Value`. Other forms are EXIF and GPS data as well as thumbnail Sub-IFD representations associated with each image file. This method allows the decoding of a directory from an arbitrary offset in the image file with no specific semantic interpretation. Such an offset is usually found as the value of a tag, e.g. `Tag::SubIfd`, `Tag::ExifDirectory`, `Tag::GpsDirectory` and recovered from the associated value by `ifd::Value::into_ifd_pointer`. The library will not verify whether the offset overlaps any other directory or would form a cycle with any other directory when calling this method. This will modify the position of the reader, i.e. continuing with direct reads at a later point will require going back with `Self::goto_offset`. #### `fn get_chunk_type(&self) -> ChunkType` Returns the chunk type (Strips or Tiles) of the image. #### `fn strip_count(&mut self) -> TiffResult` Returns the number of strips in the image. #### `fn tile_count(&mut self) -> TiffResult` Returns the number of tiles in the image. #### `fn read_chunk_to_buffer(&mut self, buffer: DecodingBuffer<'_>, chunk_index: u32, output_width: usize) -> TiffResult<()>` Reads a chunk (strip or tile) into the provided buffer. #### `fn image_chunk_buffer_layout(&mut self, chunk_index: u32) -> TiffResult` Returns the preferred buffer layout for reading the specified chunk. Returns the layout without being specific as to the underlying type for forward compatibility. Note that, in general, a TIFF may contain an almost arbitrary number of channels of individual _bit_ length and format each. See `Self::colortype` to describe the sample types. ``` -------------------------------- ### Initialize TiffEncoder with various configurations in Rust Source: https://docs.rs/tiff/latest/tiff/encoder/struct.TiffEncoder_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Illustrates different ways to initialize a `TiffEncoder`, including creating standard TIFF, BigTIFF, and generic TIFF/BigTIFF encoders. It also shows how to apply predictor and compression settings. These methods require a mutable writer implementing `Write + Seek`. ```rust use tiff::encoder::*; use std::io::Cursor; let mut file = Cursor::new(Vec::new()); // Creates a new encoder for standard Tiff files. let standard_encoder = TiffEncoder::new(&mut file).unwrap(); // Creates a new encoder for BigTiff files. let bigtiff_encoder = TiffEncoder::new_big(&mut file).unwrap(); // Creates a new Tiff or BigTiff encoder, inferred from the return type. let generic_encoder: TiffEncoder<_> = TiffEncoder::new_generic(&mut file).unwrap(); // Set the predictor to use for simplification before writing. let encoder_with_predictor = TiffEncoder::new(&mut file).unwrap().with_predictor(Predictor::Differ); // Set the compression method to use. let encoder_with_compression = TiffEncoder::new(&mut file).unwrap().with_compression(Compression::Lzw); ``` -------------------------------- ### Utility Functions Source: https://docs.rs/tiff/latest/tiff/decoder/struct.Decoder Utility functions to get chunk dimensions. ```APIDOC ## GET /websites/rs_tiff/chunk_dimensions ### Description Returns the default chunk size for the current image. Any given chunk in the image is at most as large as the value returned here. For the actual data size (chunk minus padding), use `chunk_data_dimensions`. ### Method GET ### Endpoint `/websites/rs_tiff/chunk_dimensions` ### Response #### Success Response (200) - **(u32, u32)** - A tuple representing the width and height of the default chunk size. #### Response Example ```json { "chunk_width": 256, "chunk_height": 256 } ``` ## GET /websites/rs_tiff/chunk_data_dimensions ### Description Returns the size of the data in the chunk with the specified index. This is the default size of the chunk, minus any padding. ### Method GET ### Endpoint `/websites/rs_tiff/chunk_data_dimensions` ### Parameters #### Path Parameters - **chunk_index** (u32) - Required - The index of the chunk to get the data dimensions for. ### Response #### Success Response (200) - **(u32, u32)** - A tuple representing the width and height of the actual data in the specified chunk. #### Response Example ```json { "chunk_data_width": 250, "chunk_data_height": 250 } ``` ``` -------------------------------- ### Get Tag as u64 Source: https://docs.rs/tiff/latest/tiff/decoder/struct.Decoder_search= Retrieves a TIFF tag and returns its value as a u64. ```APIDOC ## GET /websites/rs_tiff/tags/u64 ### Description Retrieves a specific TIFF tag and returns its value as a 64-bit unsigned integer. ### Method GET ### Endpoint `/websites/rs_tiff/tags/u64` ### Parameters #### Query Parameters - **tag** (Tag) - Required - The identifier for the TIFF tag to retrieve. ### Response #### Success Response (200) - **value** (u64) - The 64-bit unsigned integer value of the tag. #### Response Example ```json { "value": 1234567890 } ``` ``` -------------------------------- ### Directory Methods Source: https://docs.rs/tiff/latest/tiff/struct.Directory_search=u32+-%3E+bool Provides methods for creating, querying, and modifying TIFF directories. ```APIDOC ## impl Directory ### `fn empty() -> Self` Create a directory in an initial state without entries. Note that an empty directory can not be encoded in a file, it must contain at least one entry. ### `fn get(&self, tag: Tag) -> Option<&Entry>` Retrieve the value associated with a tag. ### `fn contains(&self, tag: Tag) -> bool` Check if the directory contains a specified tag. ### `fn iter(&self) -> impl Iterator + '_` Iterate over all known and unknown tags in this directory. ### `fn extend(&mut self, iter: impl IntoIterator)` Insert additional entries into the directory. Note that a directory can contain at most `u16::MAX` values. There may be one entry that does not fit into the directory. This entry is silently ignored (please check `Self::len` to detect the condition). Providing a tag multiple times or a tag that already exists within this directory overwrites the entry. ### `fn len(&self) -> usize` Get the number of entries. ### `fn is_empty(&self) -> bool` Check if there are any entries in this directory. Note that an empty directory can not be encoded in the file, it must contain at least one entry. ### `fn next(&self) -> Option` Get the pointer to the next IFD, if it was defined. ### `fn set_next(&mut self, next: Option)` Set the pointer to the next IFD. ``` -------------------------------- ### Example: Reading Sub-IFDs and Tags in TIFF Source: https://docs.rs/tiff/latest/tiff/decoder/struct.Decoder_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to use `Decoder::read_directory` and `Decoder::read_directory_tags` to iterate through sub-IFDs (sub-directories) within a TIFF file and extract specific tags like `SubfileType`. ```rust use tiff::decoder::Decoder; use tiff::tags::Tag; let mut decoder = Decoder::new(&mut data).unwrap(); let sub_ifds = decoder.get_tag(Tag::SubIfd)?.into_ifd_vec()?; for ifd in sub_ifds { let subdir = decoder.read_directory(ifd)?; let subfile = decoder.read_directory_tags(&subdir).find_tag(Tag::SubfileType)?; // omitted: handle the subfiles, e.g. thumbnails } ``` -------------------------------- ### TiffEncoder Example: Writing Images (Rust) Source: https://docs.rs/tiff/latest/src/tiff/encoder/mod.rs_search=std%3A%3Avec Demonstrates how to use the TiffEncoder to write image data to a file. It shows examples of creating both standard TIFF and BigTIFF files with RGB8 color type and specified dimensions. This requires the 'tiff' crate and standard IO operations. ```rust /// Encoder for Tiff and BigTiff files. /// /// With this type you can get a `DirectoryEncoder` or a `ImageEncoder` /// to encode Tiff/BigTiff ifd directories with images. /// /// See `DirectoryEncoder` and `ImageEncoder`. /// /// # Examples /// ``` /// # extern crate tiff; /// # fn main() { /// # let mut file = std::io::Cursor::new(Vec::new()); /// # let image_data = vec![0; 100*100*3]; /// use tiff::encoder::* ; /// /// // create a standard Tiff file /// let mut tiff = TiffEncoder::new(&mut file).unwrap(); /// tiff.write_image::(100, 100, &image_data).unwrap(); /// /// // create a BigTiff file /// let mut bigtiff = TiffEncoder::new_big(&mut file).unwrap(); /// bigtiff.write_image::(100, 100, &image_data).unwrap(); /// /// # } /// ``` ``` -------------------------------- ### Get Tag as f64 Source: https://docs.rs/tiff/latest/tiff/decoder/struct.Decoder_search= Retrieves a TIFF tag and attempts to convert its value to a 64-bit floating-point number. ```APIDOC ## GET /websites/rs_tiff/tags/f64 ### Description Retrieves a specific TIFF tag and attempts to convert its value to a 64-bit floating-point number. This may involve type coercion if the original tag type is different. ### Method GET ### Endpoint `/websites/rs_tiff/tags/f64` ### Parameters #### Query Parameters - **tag** (Tag) - Required - The identifier for the TIFF tag to retrieve. ### Response #### Success Response (200) - **value** (f64) - The 64-bit floating-point value of the tag. #### Response Example ```json { "value": 2.71828 } ``` ``` -------------------------------- ### Create and Write TIFF/BigTIFF Images with TiffEncoder Source: https://docs.rs/tiff/latest/tiff/encoder/struct.TiffEncoder Demonstrates creating standard and BigTiff files using TiffEncoder. It shows how to initialize encoders for different TIFF versions and write image data. This requires the `tiff` crate and a `Write + Seek` compatible writer. ```Rust use tiff::encoder::*; use std::fs::File; use std::io::BufWriter; // Assume image_data is defined and is a slice of bytes representing image pixels // For example: let image_data: Vec = vec![...]; // Example usage (replace with actual image data and file path) fn main() -> std::io::Result<()> { let mut file = BufWriter::new(File::create("output.tif")?); let width = 100; let height = 100; let image_data: Vec = vec![0; width * height * 3]; // Placeholder for RGB8 data // create a standard Tiff file let mut tiff = TiffEncoder::new(&mut file).unwrap(); tiff.write_image::(width, height, &image_data).unwrap(); // Reset file writer for BigTiff example let mut file_big = BufWriter::new(File::create("output_big.tif")?); // create a BigTiff file let mut bigtiff = TiffEncoder::new_big(&mut file_big).unwrap(); bigtiff.write_image::(width, height, &image_data).unwrap(); Ok(()) } ``` -------------------------------- ### Get Tag as f32 Source: https://docs.rs/tiff/latest/tiff/decoder/struct.Decoder_search= Retrieves a TIFF tag and attempts to convert its value to a 32-bit floating-point number. ```APIDOC ## GET /websites/rs_tiff/tags/f32 ### Description Retrieves a specific TIFF tag and attempts to convert its value to a 32-bit floating-point number. This may involve type coercion if the original tag type is different. ### Method GET ### Endpoint `/websites/rs_tiff/tags/f32` ### Parameters #### Query Parameters - **tag** (Tag) - Required - The identifier for the TIFF tag to retrieve. ### Response #### Success Response (200) - **value** (f32) - The 32-bit floating-point value of the tag. #### Response Example ```json { "value": 3.14 } ``` ``` -------------------------------- ### TiffEncoder Usage Example: Creating Standard and BigTIFF Files Source: https://docs.rs/tiff/latest/src/tiff/encoder/mod.rs Demonstrates how to create both standard TIFF and BigTIFF files using the TiffEncoder. It shows the instantiation of the encoder for a given writer and the subsequent writing of an image with a specific color type. ```rust use tiff::encoder::*; use tiff::colortype; // create a standard Tiff file let mut file = std::io::Cursor::new(Vec::new()); let mut tiff = TiffEncoder::new(&mut file).unwrap(); let image_data = vec![0; 100*100*3]; tiff.write_image::(100, 100, &image_data).unwrap(); // create a BigTiff file let mut bigtiff = TiffEncoder::new_big(&mut file).unwrap(); bigtiff.write_image::(100, 100, &image_data).unwrap(); ``` -------------------------------- ### Get Tag (f64) Source: https://docs.rs/tiff/latest/src/tiff/decoder/mod.rs Tries to retrieve a tag and convert it to a f64. ```APIDOC ## GET /websites/rs_tiff/get_tag_f64 ### Description Retrieves a tag from the current image directory and attempts to convert its value to a `f64`. Returns an error if the tag is not present or cannot be converted. ### Method GET ### Endpoint /websites/rs_tiff/get_tag_f64 ### Parameters #### Query Parameters - **tag** (Tag) - Required - The identifier of the tag to retrieve. ### Request Example `/websites/rs_tiff/get_tag_f64?tag=34016` ### Response #### Success Response (200) - **f64** (number) - The tag's value as a 64-bit floating-point number. #### Response Example ```json { "value": 5.6789 } ``` ``` -------------------------------- ### Rust: TIFF Encoder Initialization and Image Writing Source: https://docs.rs/tiff/latest/src/tiff/encoder/mod.rs_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to initialize a TIFF encoder for both standard and BigTIFF formats and write image data. It covers the use of `TiffEncoder` and its `write_image` method for different color types. ```rust use tiff::encoder::*; // create a standard Tiff file let mut tiff = TiffEncoder::new(&mut file).unwrap(); tiff.write_image::(100, 100, &image_data).unwrap(); // create a BigTiff file let mut bigtiff = TiffEncoder::new_big(&mut file).unwrap(); bigtiff.write_image::(100, 100, &image_data).unwrap(); ``` -------------------------------- ### Get Tag (f32) Source: https://docs.rs/tiff/latest/src/tiff/decoder/mod.rs Tries to retrieve a tag and convert it to a f32. ```APIDOC ## GET /websites/rs_tiff/get_tag_f32 ### Description Retrieves a tag from the current image directory and attempts to convert its value to a `f32`. Returns an error if the tag is not present or cannot be converted. ### Method GET ### Endpoint /websites/rs_tiff/get_tag_f32 ### Parameters #### Query Parameters - **tag** (Tag) - Required - The identifier of the tag to retrieve. ### Request Example `/websites/rs_tiff/get_tag_f32?tag=33550` ### Response #### Success Response (200) - **f32** (number) - The tag's value as a 32-bit floating-point number. #### Response Example ```json { "value": 1.234 } ``` ``` -------------------------------- ### Rust SampleFormat Trait Implementations Source: https://docs.rs/tiff/latest/tiff/tags/enum.SampleFormat Demonstrates the implementation of standard Rust traits for the `SampleFormat` enum. These include `Clone` for creating copies, `Debug` for formatted output, `PartialEq` for value comparison, `Copy` for simple bitwise copying, and `Eq` for total equality. Other traits like `Hash`, `Borrow`, `From`, `Into`, `ToOwned`, `TryFrom`, and `TryInto` are also implemented, enabling various data manipulation and interoperability features. ```rust impl Clone for SampleFormat impl Debug for SampleFormat impl Hash for SampleFormat impl PartialEq for SampleFormat impl Copy for SampleFormat impl Eq for SampleFormat ``` -------------------------------- ### Initialize and Manage TIFF Directory Entries in Rust Source: https://docs.rs/tiff/latest/src/tiff/directory.rs_search=std%3A%3Avec Provides methods for initializing and managing entries within a TIFF `Directory`. This includes creating an empty directory, retrieving entries by tag, checking for tag existence, iterating over entries, and extending the directory with new entries. It also includes methods for getting the number of entries and checking if the directory is empty. ```rust impl Directory { /// Create a directory in an initial state without entries. Note that an empty directory can /// not be encoded in a file, it must contain at least one entry. pub fn empty() -> Self { Directory { entries: BTreeMap::new(), next_ifd: None, } } /// Retrieve the value associated with a tag. pub fn get(&self, tag: Tag) -> Option<&Entry> { self.entries.get(&tag.to_u16()) } /// Check if the directory contains a specified tag. pub fn contains(&self, tag: Tag) -> bool { self.entries.contains_key(&tag.to_u16()) } /// Iterate over all known and unknown tags in this directory. pub fn iter(&self) -> impl Iterator + '_ { self.entries .iter() .map(|(k, v)| (Tag::from_u16_exhaustive(*k), v)) } /// Insert additional entries into the directory. /// /// Note that a directory can contain at most `u16::MAX` values. There may be one entry that /// does not fit into the directory. This entry is silently ignored (please check [`Self::len`] /// to detect the condition). Providing a tag multiple times or a tag that already exists /// within this directory overwrites the entry. pub fn extend(&mut self, iter: impl IntoIterator) { // Code size conscious extension, avoid monomorphic extensions with the assumption of these // not being performance sensitive in practice. (Maybe we have a polymorphic interface for // the crate usage in the future. self.extend_inner(iter.into_iter().by_ref()) } /// Get the number of entries. pub fn len(&self) -> usize { // The keys are `u16`. Since IFDs are required to have at least one entry this would have // been a trivial thing to do in the specification by storing it minus one but alas. In // BigTIFF the count is stored as 8-bit anyways. self.entries.len() } /// Check if there are any entries in this directory. Note that an empty directory can not be /// encoded in the file, it must contain at least one entry. pub fn is_empty(&self) -> bool { self.entries.is_empty() } /// Get the pointer to the next IFD, if it was defined. pub fn next(&self) -> Option { self.next_ifd.map(|n| IfdPointer(n.get())) } pub fn set_next(&mut self, next: Option) { self.next_ifd = next.and_then(|n| NonZeroU64::new(n.0)); } fn extend_inner(&mut self, iter: &mut dyn Iterator) { for (tag, entry) in iter { // If the tag is already present, it will be overwritten. let map_entry = self.entries.entry(tag.to_u16()); match map_entry { std::collections::btree_map::Entry::Vacant(vacant_entry) => { vacant_entry.insert(entry); } std::collections::btree_map::Entry::Occupied(mut occupied_entry) => { occupied_entry.insert(entry); } } } } } ``` -------------------------------- ### Get Tag (u64) Source: https://docs.rs/tiff/latest/src/tiff/decoder/mod.rs Tries to retrieve a tag and convert it to a u64. ```APIDOC ## GET /websites/rs_tiff/get_tag_u64 ### Description Retrieves a tag from the current image directory and attempts to convert its value to a `u64`. Returns an error if the tag is not present or cannot be converted. ### Method GET ### Endpoint /websites/rs_tiff/get_tag_u64 ### Parameters #### Query Parameters - **tag** (Tag) - Required - The identifier of the tag to retrieve. ### Request Example `/websites/rs_tiff/get_tag_u64?tag=33432` ### Response #### Success Response (200) - **u64** (number) - The tag's value as an unsigned 64-bit integer. #### Response Example ```json { "value": 1000000000 } ``` ``` -------------------------------- ### Get Tag (u32) Source: https://docs.rs/tiff/latest/src/tiff/decoder/mod.rs Tries to retrieve a tag and convert it to a u32. ```APIDOC ## GET /websites/rs_tiff/get_tag_u32 ### Description Retrieves a tag from the current image directory and attempts to convert its value to a `u32`. Returns an error if the tag is not present or cannot be converted. ### Method GET ### Endpoint /websites/rs_tiff/get_tag_u32 ### Parameters #### Query Parameters - **tag** (Tag) - Required - The identifier of the tag to retrieve. ### Request Example `/websites/rs_tiff/get_tag_u32?tag=256` ### Response #### Success Response (200) - **u32** (number) - The tag's value as an unsigned 32-bit integer. #### Response Example ```json { "value": 512 } ``` ``` -------------------------------- ### TIFF Encoder Example using TiffEncoder Source: https://docs.rs/tiff/latest/src/tiff/encoder/mod.rs_search=u32+-%3E+bool Demonstrates how to create and use `TiffEncoder` to write image data to both standard TIFF and BigTIFF files. It shows the basic steps of initializing an encoder and writing an image with a specified color type and dimensions. ```rust # extern crate tiff; # fn main() { # let mut file = std::io::Cursor::new(Vec::new()); # let image_data = vec![0; 100*100*3]; use tiff::encoder::* // create a standard Tiff file let mut tiff = TiffEncoder::new(&mut file).unwrap(); tiff.write_image::(100, 100, &image_data).unwrap(); // create a BigTiff file let mut bigtiff = TiffEncoder::new_big(&mut file).unwrap(); bigtiff.write_image::(100, 100, &image_data).unwrap(); # } ``` -------------------------------- ### RGB64 Blanket Implementations Source: https://docs.rs/tiff/latest/tiff/encoder/colortype/struct.RGB64_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Documentation for blanket implementations applied to RGB64, covering traits like Any, Borrow, BorrowMut, From, Into, TryFrom, and TryInto, which provide general functionalities for owned values and conversions. ```APIDOC ## Blanket Implementations ### impl Any for T #### Function type_id * **Description**: Gets the `TypeId` of `self`. * **Signature**: `fn type_id(&self) -> TypeId` ### impl Borrow for T #### Function borrow * **Description**: Immutably borrows from an owned value. * **Signature**: `fn borrow(&self) -> &T` ### impl BorrowMut for T #### Function borrow_mut * **Description**: Mutably borrows from an owned value. * **Signature**: `fn borrow_mut(&mut self) -> &mut T` ### impl From for T #### Function from * **Description**: Returns the argument unchanged. * **Signature**: `fn from(t: T) -> T` ### impl Into for T #### Function into * **Description**: Calls `U::from(self)`. * **Signature**: `fn into(self) -> U` ### impl TryFrom for T #### Associated Type Error * **Type**: `Infallible` #### Function try_from * **Description**: Performs the conversion. * **Signature**: `fn try_from(value: U) -> Result>::Error>` ### impl TryInto for T #### Associated Type Error * **Type**: `>::Error` #### Function try_into * **Description**: Performs the conversion. * **Signature**: `fn try_into(self) -> Result>::Error>` ``` -------------------------------- ### Get Tag as u8 Vector Source: https://docs.rs/tiff/latest/tiff/decoder/struct.Decoder_search= Retrieves a TIFF tag and converts its value to a vector of 8-bit unsigned integers. ```APIDOC ## GET /websites/rs_tiff/tags/u8_vec ### Description Retrieves a specific TIFF tag and converts its value to a vector of 8-bit unsigned integers. This is useful for binary data or byte arrays. ### Method GET ### Endpoint `/websites/rs_tiff/tags/u8_vec` ### Parameters #### Query Parameters - **tag** (Tag) - Required - The identifier for the TIFF tag to retrieve. ### Response #### Success Response (200) - **values** (Vec) - A vector containing the 8-bit unsigned integer values (bytes) of the tag. #### Response Example ```json { "values": [65, 66, 67] } ``` ``` -------------------------------- ### Get Tag as u64 Vector Source: https://docs.rs/tiff/latest/tiff/decoder/struct.Decoder_search= Retrieves a TIFF tag and returns its value as a vector of 64-bit unsigned integers. ```APIDOC ## GET /websites/rs_tiff/tags/u64_vec ### Description Retrieves a specific TIFF tag and returns its value as a vector of 64-bit unsigned integers. This is useful for tags that store multiple large integer values. ### Method GET ### Endpoint `/websites/rs_tiff/tags/u64_vec` ### Parameters #### Query Parameters - **tag** (Tag) - Required - The identifier for the TIFF tag to retrieve. ### Response #### Success Response (200) - **values** (Vec) - A vector containing the 64-bit unsigned integer values of the tag. #### Response Example ```json { "values": [1234567890123, 9876543210987] } ``` ``` -------------------------------- ### Prepare Reading Directory Tags Source: https://docs.rs/tiff/latest/tiff/decoder/struct.Decoder_search=std%3A%3Avec Prepares to read tag values for a given IFD (Image File Directory). This function is useful for iterating through sub-IFDs and extracting specific tag information. ```Rust pub fn read_directory_tags<'ifd>( &'ifd mut self, ifd: &'ifd Directory, ) -> IfdDecoder<'ifd> ``` -------------------------------- ### DirectoryOffset Struct Documentation Source: https://docs.rs/tiff/latest/tiff/encoder/struct.DirectoryOffset_search=u32+-%3E+bool Documentation for the `DirectoryOffset` struct, including its fields and their descriptions, as well as implemented traits. ```APIDOC ## Struct DirectoryOffset ### Description The offset of an encoded directory in the file. ### Fields - **offset** (`K::OffsetType`) - The start of the directory as a Tiff value. This field's type depends on endianness and offset size (`u32` or `u64` for BigTIFF). - **pointer** (`IfdPointer`) - The start of the directory as a pure offset. ### Trait Implementations - **Clone**: Allows creating a duplicate of `DirectoryOffset`. - **Debug**: Enables formatting `DirectoryOffset` for debugging. - **Hash**: Allows hashing `DirectoryOffset` instances. - **PartialEq**: Enables comparison of `DirectoryOffset` instances for equality. - **Copy**: Allows `DirectoryOffset` to be copied by value. - **Eq**: Indicates that equality is reflexive, symmetric, and transitive for `DirectoryOffset`. - **StructuralPartialEq**: Provides structural equality checks. ### Auto Trait Implementations - **Freeze**: Indicates that `DirectoryOffset` can be frozen (its contents cannot be mutated). - **RefUnwindSafe**: Guarantees that `DirectoryOffset` is safe to unwind across during exception handling. - **Send**: Indicates that `DirectoryOffset` can be safely transferred between threads. - **Sync**: Indicates that `DirectoryOffset` can be safely shared between threads. - **Unpin**: Indicates that `DirectoryOffset` does not move during its lifetime. - **UnwindSafe**: Guarantees that `DirectoryOffset` is safe to unwind across during exception handling (similar to `RefUnwindSafe`). ``` -------------------------------- ### Get Tag as u16 Vector Source: https://docs.rs/tiff/latest/tiff/decoder/struct.Decoder_search= Retrieves a TIFF tag and returns its value as a vector of 16-bit unsigned integers. ```APIDOC ## GET /websites/rs_tiff/tags/u16_vec ### Description Retrieves a specific TIFF tag and returns its value as a vector of 16-bit unsigned integers. This is useful for tags that store multiple short integer values. ### Method GET ### Endpoint `/websites/rs_tiff/tags/u16_vec` ### Parameters #### Query Parameters - **tag** (Tag) - Required - The identifier for the TIFF tag to retrieve. ### Response #### Success Response (200) - **values** (Vec) - A vector containing the 16-bit unsigned integer values of the tag. #### Response Example ```json { "values": [10, 20, 30] } ``` ``` -------------------------------- ### Decoder Configuration and Metadata Source: https://docs.rs/tiff/latest/tiff/decoder/struct.Decoder_search=u32+-%3E+bool Methods for configuring decoder limits and retrieving image metadata. ```APIDOC ## Decoder Configuration and Metadata ### `Decoder::with_limits(self, limits: Limits) -> Decoder` #### Description Sets decoding limits for the `Decoder`. #### Method `POST` #### Endpoint `/decoder/with_limits` #### Parameters ##### Request Body - **limits** (Limits) - Required - The decoding limits to apply. #### Response ##### Success Response (200) - **decoder** (Decoder) - The modified Decoder instance with limits. ##### Response Example ```json { "decoder": "Decoder instance with limits" } ``` ### `Decoder::dimensions(&mut self) -> TiffResult<(u32, u32)>` #### Description Returns the dimensions (width, height) of the current image. #### Method `GET` #### Endpoint `/decoder/dimensions` #### Response ##### Success Response (200) - **dimensions** (tuple[u32, u32]) - The width and height of the image. ##### Response Example ```json { "dimensions": [1920, 1080] } ``` ### `Decoder::colortype(&mut self) -> TiffResult` #### Description Returns the `ColorType` of the current image. #### Method `GET` #### Endpoint `/decoder/colortype` #### Response ##### Success Response (200) - **color_type** (ColorType) - The color type of the image. ##### Response Example ```json { "color_type": "Rgb" } ``` ### `Decoder::ifd_pointer(&mut self) -> Option` #### Description Returns the offset of the directory representing the current image. #### Method `GET` #### Endpoint `/decoder/ifd_pointer` #### Response ##### Success Response (200) - **ifd_pointer** (Option[IfdPointer]) - The offset of the IFD, or None if not available. ##### Response Example ```json { "ifd_pointer": "0x100" } ``` ### `Decoder::byte_order(&self) -> ByteOrder` #### Description Returns the byte order of the TIFF file. #### Method `GET` #### Endpoint `/decoder/byte_order` #### Response ##### Success Response (200) - **byte_order** (ByteOrder) - The byte order of the file. ##### Response Example ```json { "byte_order": "LittleEndian" } ``` ``` -------------------------------- ### Get Tag as u32 Vector Source: https://docs.rs/tiff/latest/tiff/decoder/struct.Decoder_search= Retrieves a TIFF tag and returns its value as a vector of 32-bit unsigned integers. ```APIDOC ## GET /websites/rs_tiff/tags/u32_vec ### Description Retrieves a specific TIFF tag and returns its value as a vector of 32-bit unsigned integers. This is useful for tags that store multiple integer values. ### Method GET ### Endpoint `/websites/rs_tiff/tags/u32_vec` ### Parameters #### Query Parameters - **tag** (Tag) - Required - The identifier for the TIFF tag to retrieve. ### Response #### Success Response (200) - **values** (Vec) - A vector containing the 32-bit unsigned integer values of the tag. #### Response Example ```json { "values": [1, 2, 3, 4] } ``` ``` -------------------------------- ### Get Required Tag Value Source: https://docs.rs/tiff/latest/tiff/decoder/struct.Decoder_search=std%3A%3Avec Retrieves a tag from the current image directory. Returns an error if the tag is not present. ```Rust pub fn get_tag(&mut self, tag: Tag) -> TiffResult ``` -------------------------------- ### Prepare Reading TIFF Directory Tags Source: https://docs.rs/tiff/latest/tiff/decoder/struct.Decoder_search=u32+-%3E+bool Prepares for reading tag values from a given TIFF directory (IFD). This method is useful in conjunction with `Decoder::read_directory` to extract specific metadata from sub-IFDs or the main directory. ```rust pub fn read_directory_tags<'ifd>( &'ifd mut self, ifd: &'ifd Directory, ) -> IfdDecoder<'ifd> ```