jiao/effects/
color_matrix.rs

1// Copyright (c) 2023 Xu Shaohua <shaohua@biofan.org>. All rights reserved.
2// Use of this source is governed by Lesser General Public License that can be found
3// in the LICENSE file.
4
5use crate::core::image_info::YuvColorSpace;
6
7#[derive(Debug, Clone, PartialEq)]
8pub struct ColorMatrix {
9    mat: [f32; 20],
10}
11
12impl Default for ColorMatrix {
13    fn default() -> Self {
14        Self::new()
15    }
16}
17
18impl ColorMatrix {
19    #[must_use]
20    #[rustfmt::skip]
21    pub const fn new() -> Self {
22        Self {
23            mat: [
24                1., 0., 0., 0., 0.,
25                0., 1., 0., 0., 0.,
26                0., 0., 1., 0., 0.,
27                0., 0., 0., 1., 0.,
28            ]
29        }
30    }
31
32    #[must_use]
33    #[rustfmt::skip]
34    #[allow(clippy::too_many_arguments)]
35    pub const fn from(
36        m00: f32, m01: f32, m02: f32, m03: f32, m04: f32,
37        m10: f32, m11: f32, m12: f32, m13: f32, m14: f32,
38        m20: f32, m21: f32, m22: f32, m23: f32, m24: f32,
39        m30: f32, m31: f32, m32: f32, m33: f32, m34: f32) -> Self {
40        Self {
41            mat: [
42                m00, m01, m02, m03, m04,
43                m10, m11, m12, m13, m14,
44                m20, m21, m22, m23, m24,
45                m30, m31, m32, m33, m34,
46            ],
47        }
48    }
49
50    #[must_use]
51    pub fn rgb_to_yuv(_color_space: YuvColorSpace) -> Self {
52        unimplemented!()
53    }
54
55    #[must_use]
56    pub fn yuv_to_rgb(_color_space: YuvColorSpace) -> Self {
57        unimplemented!()
58    }
59
60    #[rustfmt::skip]
61    pub fn set_identity(&mut self) {
62        self.mat = [
63            1., 0., 0., 0., 0.,
64            0., 1., 0., 0., 0.,
65            0., 0., 1., 0., 0.,
66            0., 0., 0., 1., 0.,
67        ];
68    }
69
70    pub fn set_scale(&mut self, red_scale: f32, green_scale: f32, blue_scale: f32) {
71        self.set_scale_with_alpha(red_scale, green_scale, blue_scale, 1.0);
72    }
73
74    pub fn set_scale_with_alpha(
75        &mut self,
76        _red_scale: f32,
77        _green_scale: f32,
78        _blue_scale: f32,
79        _alpha_scale: f32,
80    ) {
81        unimplemented!();
82    }
83
84    pub fn post_translate(&mut self, _dr: f32, _dg: f32, _db: f32, _da: f32) {
85        unimplemented!();
86    }
87
88    pub fn set_concat(&mut self, _mat_a: &Self, _mat_b: &Self) {
89        unimplemented!();
90    }
91
92    pub fn pre_concat(&mut self, _mat: &Self) {
93        unimplemented!();
94        //this->setConcat(*this, mat)
95    }
96
97    pub fn post_concat(&mut self, _mat: &Self) {
98        unimplemented!()
99        //this->setConcat(mat, *this);
100    }
101
102    pub fn set_saturation(&mut self, _sat: f32) {
103        unimplemented!()
104    }
105
106    pub fn set_row_major(&mut self, src: &[f32; 20]) {
107        self.mat = *src;
108    }
109
110    #[must_use]
111    pub const fn get_row_major(&self) -> &[f32; 20] {
112        &self.mat
113    }
114}