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(std::shared_ptr<ColorSpaceImpl> impl)38 ColorSpace::ColorSpace(std::shared_ptr<ColorSpaceImpl> impl) noexcept
39 : type_(ColorSpace::ColorSpaceType::NO_TYPE), impl_(impl)
40 {}
41
ColorSpace(ColorSpaceType t,const Image & image)42 ColorSpace::ColorSpace(ColorSpaceType t, const Image& image) noexcept : ColorSpace()
43 {
44 type_ = t;
45 impl_->InitWithImage(image);
46 }
47
ColorSpace(ColorSpaceType t,const CMSTransferFuncType & func,const CMSMatrixType & matrix)48 ColorSpace::ColorSpace(ColorSpaceType t,
49 const CMSTransferFuncType& func, const CMSMatrixType& matrix) noexcept : ColorSpace()
50 {
51 type_ = t;
52 impl_->InitWithRGB(func, matrix);
53 }
54
ColorSpace(ColorSpaceType t,const CMSTransferFunction & func,const CMSMatrix3x3 & matrix)55 ColorSpace::ColorSpace(ColorSpaceType t,
56 const CMSTransferFunction& func, const CMSMatrix3x3& matrix) noexcept : ColorSpace()
57 {
58 type_ = t;
59 impl_->InitWithCustomRGB(func, matrix);
60 }
61
ColorSpace()62 ColorSpace::ColorSpace() noexcept
63 : type_(ColorSpace::ColorSpaceType::NO_TYPE), impl_(ImplFactory::CreateColorSpaceImpl())
64 {}
65
GetType() const66 ColorSpace::ColorSpaceType ColorSpace::GetType() const
67 {
68 return type_;
69 }
70
CreateFromImpl(std::shared_ptr<ColorSpaceImpl> impl)71 std::shared_ptr<ColorSpace> ColorSpace::CreateFromImpl(std::shared_ptr<ColorSpaceImpl> impl)
72 {
73 return std::make_shared<ColorSpace>(impl);
74 }
75
CreateSRGB()76 std::shared_ptr<ColorSpace> ColorSpace::CreateSRGB()
77 {
78 return std::make_shared<ColorSpace>(ColorSpace::ColorSpaceType::SRGB);
79 }
80
CreateSRGBLinear()81 std::shared_ptr<ColorSpace> ColorSpace::CreateSRGBLinear()
82 {
83 return std::make_shared<ColorSpace>(ColorSpace::ColorSpaceType::SRGB_LINEAR);
84 }
85
CreateRefImage(const Image & image)86 std::shared_ptr<ColorSpace> ColorSpace::CreateRefImage(const Image& image)
87 {
88 return std::make_shared<ColorSpace>(ColorSpace::ColorSpaceType::REF_IMAGE, image);
89 }
90
CreateRGB(const CMSTransferFuncType & func,const CMSMatrixType & matrix)91 std::shared_ptr<ColorSpace> ColorSpace::CreateRGB(const CMSTransferFuncType& func, const CMSMatrixType& matrix)
92 {
93 return std::make_shared<ColorSpace>(ColorSpace::ColorSpaceType::RGB, func, matrix);
94 }
95
CreateCustomRGB(const CMSTransferFunction & func,const CMSMatrix3x3 & matrix)96 std::shared_ptr<ColorSpace> ColorSpace::CreateCustomRGB(const CMSTransferFunction& func, const CMSMatrix3x3& matrix)
97 {
98 return std::make_shared<ColorSpace>(ColorSpace::ColorSpaceType::RGB, func, matrix);
99 }
100
GetSkColorSpace() const101 sk_sp<SkColorSpace> ColorSpace::GetSkColorSpace() const
102 {
103 return impl_->GetSkColorSpace();
104 }
105
Serialize() const106 std::shared_ptr<Data> ColorSpace::Serialize() const
107 {
108 return impl_->Serialize();
109 }
110
Deserialize(std::shared_ptr<Data> data)111 bool ColorSpace::Deserialize(std::shared_ptr<Data> data)
112 {
113 return impl_->Deserialize(data);
114 }
115
IsSRGB() const116 bool ColorSpace::IsSRGB() const
117 {
118 return impl_->IsSRGB();
119 }
120
Equals(const std::shared_ptr<ColorSpace> & colorSpace) const121 bool ColorSpace::Equals(const std::shared_ptr<ColorSpace>& colorSpace) const
122 {
123 return impl_->Equals(colorSpace);
124 }
125
126 } // namespace Drawing
127 } // namespace Rosen
128 } // namespace OHOS