diff --git a/python/python/async_tiff/_tile.pyi b/python/python/async_tiff/_tile.pyi index 884f30d..28f12bf 100644 --- a/python/python/async_tiff/_tile.pyi +++ b/python/python/async_tiff/_tile.pyi @@ -1,9 +1,18 @@ from collections.abc import Buffer +from .enums import CompressionMethod from ._decoder import DecoderRegistry from ._thread_pool import ThreadPool class Tile: + @property + def x(self) -> int: ... + @property + def y(self) -> int: ... + @property + def compressed_bytes(self) -> Buffer: ... + @property + def compression_method(self) -> CompressionMethod: ... async def decode( self, *, diff --git a/python/src/tile.rs b/python/src/tile.rs index 5b34296..96b9b3d 100644 --- a/python/src/tile.rs +++ b/python/src/tile.rs @@ -1,10 +1,12 @@ use async_tiff::Tile; +use pyo3::exceptions::PyValueError; use pyo3::prelude::*; use pyo3_async_runtimes::tokio::future_into_py; use pyo3_bytes::PyBytes; use tokio_rayon::AsyncThreadPool; use crate::decoder::get_default_decoder_registry; +use crate::enums::PyCompressionMethod; use crate::thread_pool::{get_default_pool, PyThreadPool}; use crate::PyDecoderRegistry; @@ -13,6 +15,39 @@ pub(crate) struct PyTile(Option); #[pymethods] impl PyTile { + #[getter] + fn x(&self) -> PyResult { + self.0 + .as_ref() + .ok_or(PyValueError::new_err("Tile has been consumed")) + .map(|t| t.x()) + } + + #[getter] + fn y(&self) -> PyResult { + self.0 + .as_ref() + .ok_or(PyValueError::new_err("Tile has been consumed")) + .map(|t| t.y()) + } + + #[getter] + fn compressed_bytes(&self) -> PyResult { + let tile = self + .0 + .as_ref() + .ok_or(PyValueError::new_err("Tile has been consumed"))?; + Ok(tile.compressed_bytes().clone().into()) + } + + #[getter] + fn compression_method(&self) -> PyResult { + self.0 + .as_ref() + .ok_or(PyValueError::new_err("Tile has been consumed")) + .map(|t| t.compression_method().into()) + } + #[pyo3(signature = (*, decoder_registry=None, pool=None))] fn decode_async( &mut self,