async_tiff/geo/
affine.rs

1use crate::ImageFileDirectory;
2
3/// Affine transformation values.
4#[derive(Debug)]
5pub struct AffineTransform(f64, f64, f64, f64, f64, f64);
6
7impl AffineTransform {
8    /// Construct a new Affine Transform
9    pub fn new(a: f64, b: f64, xoff: f64, d: f64, e: f64, yoff: f64) -> Self {
10        Self(a, b, xoff, d, e, yoff)
11    }
12
13    /// a
14    pub fn a(&self) -> f64 {
15        self.0
16    }
17
18    /// b
19    pub fn b(&self) -> f64 {
20        self.1
21    }
22
23    /// c
24    pub fn c(&self) -> f64 {
25        self.2
26    }
27
28    /// d
29    pub fn d(&self) -> f64 {
30        self.3
31    }
32
33    /// e
34    pub fn e(&self) -> f64 {
35        self.4
36    }
37
38    /// f
39    pub fn f(&self) -> f64 {
40        self.5
41    }
42
43    /// Construct a new Affine Transform from the IFD
44    pub fn from_ifd(ifd: &ImageFileDirectory) -> Option<Self> {
45        if let (Some(model_pixel_scale), Some(model_tiepoint)) =
46            (&ifd.model_pixel_scale, &ifd.model_tiepoint)
47        {
48            Some(Self::new(
49                model_pixel_scale[0],
50                0.0,
51                model_tiepoint[3],
52                0.0,
53                -model_pixel_scale[1],
54                model_tiepoint[4],
55            ))
56        } else {
57            None
58        }
59    }
60}