Skip to content

Commit 5487c3a

Browse files
committed
added Endianness access from IFD to python
1 parent 6fe3da9 commit 5487c3a

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed

python/src/enums.rs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,40 @@
1-
use async_tiff::tiff::tags::{
2-
CompressionMethod, PhotometricInterpretation, PlanarConfiguration, Predictor, ResolutionUnit,
3-
SampleFormat,
1+
use async_tiff::{
2+
reader::Endianness,
3+
tiff::tags::{
4+
CompressionMethod, PhotometricInterpretation, PlanarConfiguration, Predictor,
5+
ResolutionUnit, SampleFormat,
6+
},
47
};
58
use pyo3::prelude::*;
69
use pyo3::types::{PyString, PyTuple};
710
use pyo3::{intern, IntoPyObjectExt};
811

12+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
13+
#[pyclass(eq, eq_int, name = "Endianness")]
14+
#[repr(u16)]
15+
pub(crate) enum PyEndianness {
16+
LittleEndian = 0x4949, // b"II"
17+
BigEndian = 0x4D4D, // b"MM"
18+
}
19+
20+
impl From<Endianness> for PyEndianness {
21+
fn from(value: Endianness) -> Self {
22+
match value {
23+
Endianness::LittleEndian => Self::LittleEndian,
24+
Endianness::BigEndian => Self::BigEndian,
25+
}
26+
}
27+
}
28+
29+
impl From<PyEndianness> for Endianness {
30+
fn from(value: PyEndianness) -> Self {
31+
match value {
32+
PyEndianness::LittleEndian => Self::LittleEndian,
33+
PyEndianness::BigEndian => Self::BigEndian,
34+
}
35+
}
36+
}
37+
938
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1039
pub(crate) struct PyCompressionMethod(CompressionMethod);
1140

python/src/ifd.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use async_tiff::ImageFileDirectory;
44
use pyo3::prelude::*;
55

66
use crate::enums::{
7-
PyCompressionMethod, PyPhotometricInterpretation, PyPlanarConfiguration, PyPredictor,
8-
PyResolutionUnit, PySampleFormat,
7+
PyCompressionMethod, PyEndianness, PyPhotometricInterpretation, PyPlanarConfiguration,
8+
PyPredictor, PyResolutionUnit, PySampleFormat,
99
};
1010
use crate::geo::PyGeoKeyDirectory;
1111
use crate::value::PyValue;
@@ -15,6 +15,11 @@ pub(crate) struct PyImageFileDirectory(ImageFileDirectory);
1515

1616
#[pymethods]
1717
impl PyImageFileDirectory {
18+
#[getter]
19+
pub fn endianness(&self) -> PyEndianness {
20+
self.0.endianness().into()
21+
}
22+
1823
#[getter]
1924
pub fn new_subfile_type(&self) -> Option<u32> {
2025
self.0.new_subfile_type()

src/ifd.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,12 @@ impl ImageFileDirectory {
402402
})
403403
}
404404

405+
406+
/// The Endianness of the file
407+
pub fn endianness(&self) -> Endianness {
408+
self.endianness
409+
}
410+
405411
/// A general indication of the kind of data contained in this subfile.
406412
/// <https://web.archive.org/web/20240329145250/https://www.awaresystems.be/imaging/tiff/tifftags/newsubfiletype.html>
407413
pub fn new_subfile_type(&self) -> Option<u32> {

0 commit comments

Comments
 (0)