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()55 ColorSpace::ColorSpace() noexcept
56 : type_(ColorSpace::ColorSpaceType::NO_TYPE), impl_(ImplFactory::CreateColorSpaceImpl())
57 {}
58
GetType() const59 ColorSpace::ColorSpaceType ColorSpace::GetType() const
60 {
61 return type_;
62 }
63
CreateFromImpl(std::shared_ptr<ColorSpaceImpl> impl)64 std::shared_ptr<ColorSpace> ColorSpace::CreateFromImpl(std::shared_ptr<ColorSpaceImpl> impl)
65 {
66 return std::make_shared<ColorSpace>(impl);
67 }
68
CreateSRGB()69 std::shared_ptr<ColorSpace> ColorSpace::CreateSRGB()
70 {
71 return std::make_shared<ColorSpace>(ColorSpace::ColorSpaceType::SRGB);
72 }
73
CreateSRGBLinear()74 std::shared_ptr<ColorSpace> ColorSpace::CreateSRGBLinear()
75 {
76 return std::make_shared<ColorSpace>(ColorSpace::ColorSpaceType::SRGB_LINEAR);
77 }
78
CreateRefImage(const Image & image)79 std::shared_ptr<ColorSpace> ColorSpace::CreateRefImage(const Image& image)
80 {
81 return std::make_shared<ColorSpace>(ColorSpace::ColorSpaceType::REF_IMAGE, image);
82 }
83
CreateRGB(const CMSTransferFuncType & func,const CMSMatrixType & matrix)84 std::shared_ptr<ColorSpace> ColorSpace::CreateRGB(const CMSTransferFuncType& func, const CMSMatrixType& matrix)
85 {
86 return std::make_shared<ColorSpace>(ColorSpace::ColorSpaceType::RGB, func, matrix);
87 }
88
GetSkColorSpace() const89 sk_sp<SkColorSpace> ColorSpace::GetSkColorSpace() const
90 {
91 return impl_->GetSkColorSpace();
92 }
93
Serialize() const94 std::shared_ptr<Data> ColorSpace::Serialize() const
95 {
96 return impl_->Serialize();
97 }
98
Deserialize(std::shared_ptr<Data> data)99 bool ColorSpace::Deserialize(std::shared_ptr<Data> data)
100 {
101 return impl_->Deserialize(data);
102 }
103
104 } // namespace Drawing
105 } // namespace Rosen
106 } // namespace OHOS