1 /*
2  * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef COLOR_MATRIX_H
17 #define COLOR_MATRIX_H
18 
19 #include "utils/scalar.h"
20 #include "utils/drawing_macros.h"
21 
22 namespace OHOS {
23 namespace Rosen {
24 namespace Drawing {
25 class DRAWING_API ColorMatrix {
26 public:
27     enum Index {
28         SCALE_FACTOR_FOR_R = 0,
29         G_FACTOR_FOR_R = 1,
30         B_FACTOR_FOR_R = 2,
31         A_FACTOR_FOR_R = 3,
32         TRANS_FOR_R = 4,
33 
34         R_FACTOR_FOR_G = 5,
35         SCALE_FACTOR_FOR_G = 6,
36         B_FACTOR_FOR_G = 7,
37         A_FACTOR_FOR_G = 8,
38         TRANS_FOR_G = 9,
39 
40         R_FACTOR_FOR_B = 10,
41         G_FACTOR_FOR_B = 11,
42         SCALE_FACTOR_FOR_B = 12,
43         A_FACTOR_FOR_B = 13,
44         TRANS_FOR_B = 14,
45 
46         R_FACTOR_FOR_A = 15,
47         G_FACTOR_FOR_A = 16,
48         B_FACTOR_FOR_A = 17,
49         SCALE_FACTOR_FOR_A = 18,
50         TRANS_FOR_A = 19,
51     };
52 
53     // Color matrix is a 4x5 float type matrix.
54     constexpr static int MATRIX_SIZE = 20;
55     ColorMatrix() noexcept;
56     ~ColorMatrix();
57 
58     void SetIdentity();
59     void SetArray(const scalar src[MATRIX_SIZE]);
60     void GetArray(scalar (&dst)[MATRIX_SIZE]) const;
61     void SetConcat(const ColorMatrix& m1, const ColorMatrix& m2);
62     void PreConcat(const ColorMatrix& m);
63     void PostConcat(const ColorMatrix& m);
64     void SetScale(scalar sr, scalar sg, scalar sb, scalar sa);
65 
66     /*
67      * @brief      Set the ColorMatrix to a saturation matrix.
68      * @param sat  Saturation value, 0 maps to gray-scale, 1 is identity
69      */
70     void SetSaturation(scalar sat);
71 
72 private:
73     scalar array_[MATRIX_SIZE] = { 0 };
74 };
75 } // namespace Drawing
76 } // namespace Rosen
77 } // namespace OHOS
78 #endif
79