• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "effect/color_space.h"
17 
18 #include "impl_factory.h"
19 
20 namespace OHOS {
21 namespace Rosen {
22 namespace Drawing {
ColorSpace(ColorSpaceType t)23 ColorSpace::ColorSpace(ColorSpaceType t) noexcept : ColorSpace()
24 {
25     type_ = t;
26     switch (type_) {
27         case ColorSpace::ColorSpaceType::SRGB:
28             impl_->InitWithSRGB();
29             break;
30         case ColorSpace::ColorSpaceType::SRGB_LINEAR:
31             impl_->InitWithSRGBLinear();
32             break;
33         default:
34             break;
35     }
36 }
37 
ColorSpace(ColorSpaceType t,const Image & image)38 ColorSpace::ColorSpace(ColorSpaceType t, const Image& image) noexcept : ColorSpace()
39 {
40     type_ = t;
41     impl_->InitWithImage(image);
42 }
43 
ColorSpace(ColorSpaceType t,const CMSTransferFuncType & func,const CMSMatrixType & matrix)44 ColorSpace::ColorSpace(ColorSpaceType t,
45                        const CMSTransferFuncType& func, const CMSMatrixType& matrix) noexcept : ColorSpace()
46 {
47     type_ = t;
48     impl_->InitWithRGB(func, matrix);
49 }
50 
ColorSpace(ColorSpaceType t,const CMSTransferFunction & func,const CMSMatrix3x3 & matrix)51 ColorSpace::ColorSpace(ColorSpaceType t,
52                        const CMSTransferFunction& func, const CMSMatrix3x3& matrix) noexcept : ColorSpace()
53 {
54     type_ = t;
55     impl_->InitWithCustomRGB(func, matrix);
56 }
57 
ColorSpace()58 ColorSpace::ColorSpace() noexcept
59     : type_(ColorSpace::ColorSpaceType::NO_TYPE), impl_(ImplFactory::CreateColorSpaceImpl())
60 {}
61 
GetType() const62 ColorSpace::ColorSpaceType ColorSpace::GetType() const
63 {
64     return type_;
65 }
66 
CreateSRGB()67 std::shared_ptr<ColorSpace> ColorSpace::CreateSRGB()
68 {
69     return std::make_shared<ColorSpace>(ColorSpace::ColorSpaceType::SRGB);
70 }
71 
CreateSRGBLinear()72 std::shared_ptr<ColorSpace> ColorSpace::CreateSRGBLinear()
73 {
74     return std::make_shared<ColorSpace>(ColorSpace::ColorSpaceType::SRGB_LINEAR);
75 }
76 
CreateRefImage(const Image & image)77 std::shared_ptr<ColorSpace> ColorSpace::CreateRefImage(const Image& image)
78 {
79     return std::make_shared<ColorSpace>(ColorSpace::ColorSpaceType::REF_IMAGE, image);
80 }
81 
CreateRGB(const CMSTransferFuncType & func,const CMSMatrixType & matrix)82 std::shared_ptr<ColorSpace> ColorSpace::CreateRGB(const CMSTransferFuncType& func, const CMSMatrixType& matrix)
83 {
84     return std::make_shared<ColorSpace>(ColorSpace::ColorSpaceType::RGB, func, matrix);
85 }
86 
CreateCustomRGB(const CMSTransferFunction & func,const CMSMatrix3x3 & matrix)87 std::shared_ptr<ColorSpace> ColorSpace::CreateCustomRGB(const CMSTransferFunction& func, const CMSMatrix3x3& matrix)
88 {
89     return std::make_shared<ColorSpace>(ColorSpace::ColorSpaceType::RGB, func, matrix);
90 }
91 
GetSkColorSpace() const92 sk_sp<SkColorSpace> ColorSpace::GetSkColorSpace() const
93 {
94     return impl_->GetSkColorSpace();
95 }
96 
Serialize() const97 std::shared_ptr<Data> ColorSpace::Serialize() const
98 {
99     return impl_->Serialize();
100 }
101 
Deserialize(std::shared_ptr<Data> data)102 bool ColorSpace::Deserialize(std::shared_ptr<Data> data)
103 {
104     return impl_->Deserialize(data);
105 }
106 
IsSRGB() const107 bool ColorSpace::IsSRGB() const
108 {
109     return impl_->IsSRGB();
110 }
111 
Equals(const std::shared_ptr<ColorSpace> & colorSpace) const112 bool ColorSpace::Equals(const std::shared_ptr<ColorSpace>& colorSpace) const
113 {
114     return impl_->Equals(colorSpace);
115 }
116 
ToXYZD50(bool & hasToXYZD50)117 CMSMatrix3x3 ColorSpace::ToXYZD50(bool& hasToXYZD50)
118 {
119     return impl_->ToXYZD50(hasToXYZD50);
120 }
121 } // namespace Drawing
122 } // namespace Rosen
123 } // namespace OHOS