1use bytes::Bytes;
2
3use crate::decoder::DecoderRegistry;
4use crate::error::AsyncTiffResult;
5use crate::tiff::tags::{CompressionMethod, PhotometricInterpretation};
6use crate::tiff::{TiffError, TiffUnsupportedError};
7
8#[derive(Debug)]
15pub struct Tile {
16 pub(crate) x: usize,
17 pub(crate) y: usize,
18 pub(crate) compressed_bytes: Bytes,
19 pub(crate) compression_method: CompressionMethod,
20 pub(crate) photometric_interpretation: PhotometricInterpretation,
21 pub(crate) jpeg_tables: Option<Bytes>,
22}
23
24impl Tile {
25 pub fn x(&self) -> usize {
27 self.x
28 }
29
30 pub fn y(&self) -> usize {
32 self.y
33 }
34
35 pub fn compressed_bytes(&self) -> &Bytes {
39 &self.compressed_bytes
40 }
41
42 pub fn compression_method(&self) -> CompressionMethod {
44 self.compression_method
45 }
46
47 pub fn photometric_interpretation(&self) -> PhotometricInterpretation {
49 self.photometric_interpretation
50 }
51
52 pub fn jpeg_tables(&self) -> Option<&Bytes> {
56 self.jpeg_tables.as_ref()
57 }
58
59 pub fn decode(self, decoder_registry: &DecoderRegistry) -> AsyncTiffResult<Bytes> {
64 let decoder = decoder_registry
65 .as_ref()
66 .get(&self.compression_method)
67 .ok_or(TiffError::UnsupportedError(
68 TiffUnsupportedError::UnsupportedCompressionMethod(self.compression_method),
69 ))?;
70
71 decoder.decode_tile(
72 self.compressed_bytes.clone(),
73 self.photometric_interpretation,
74 self.jpeg_tables.as_deref(),
75 )
76 }
77}