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 21 namespace OHOS { 22 namespace Rosen { 23 namespace Drawing { 24 class ColorMatrix { 25 public: 26 enum Index { 27 SCALE_FACTOR_FOR_R = 0, 28 G_FACTOR_FOR_R = 1, 29 B_FACTOR_FOR_R = 2, 30 A_FACTOR_FOR_R = 3, 31 TRANS_FOR_R = 4, 32 33 R_FACTOR_FOR_G = 5, 34 SCALE_FACTOR_FOR_G = 6, 35 B_FACTOR_FOR_G = 7, 36 A_FACTOR_FOR_G = 8, 37 TRANS_FOR_G = 9, 38 39 R_FACTOR_FOR_B = 10, 40 G_FACTOR_FOR_B = 11, 41 SCALE_FACTOR_FOR_B = 12, 42 A_FACTOR_FOR_B = 13, 43 TRANS_FOR_B = 14, 44 45 R_FACTOR_FOR_A = 15, 46 G_FACTOR_FOR_A = 16, 47 B_FACTOR_FOR_A = 17, 48 SCALE_FACTOR_FOR_A = 18, 49 TRANS_FOR_A = 19, 50 }; 51 52 // Color matrix is a 4x5 float type matrix. 53 constexpr static int MATRIX_SIZE = 20; 54 ColorMatrix() noexcept; 55 ~ColorMatrix(); 56 57 void SetIdentity(); 58 void SetArray(const scalar src[MATRIX_SIZE]); 59 void GetArray(scalar dst[MATRIX_SIZE]) const; 60 void SetConcat(const ColorMatrix& m1, const ColorMatrix& m2); 61 void PreConcat(const ColorMatrix& m); 62 void PostConcat(const ColorMatrix& m); 63 void SetScale(scalar sr, scalar sg, scalar sb, scalar sa); 64 65 /* 66 * @brief Set the ColorMatrix to a saturation matrix. 67 * @param sat Saturation value, 0 maps to gray-scale, 1 is identity 68 */ 69 void SetSaturation(scalar sat); 70 71 private: 72 scalar array_[MATRIX_SIZE] = { 0 }; 73 }; 74 } // namespace Drawing 75 } // namespace Rosen 76 } // namespace OHOS 77 #endif 78