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_SPACE_H 17 #define COLOR_SPACE_H 18 19 #include <string> 20 21 #include "include/core/SkColorSpace.h" 22 23 #include "drawing/engine_adapter/impl_interface/color_space_impl.h" 24 #include "utils/drawing_macros.h" 25 26 namespace OHOS { 27 namespace Rosen { 28 namespace Drawing { 29 enum class CMSTransferFuncType { 30 SRGB, 31 DOT2, 32 LINEAR, 33 REC2020, 34 }; 35 36 enum class CMSMatrixType { 37 SRGB, 38 ADOBE_RGB, 39 DCIP3, 40 REC2020, 41 XYZ, 42 }; 43 44 class DRAWING_API ColorSpace { 45 public: 46 enum class ColorSpaceType { 47 NO_TYPE, 48 SRGB, 49 SRGB_LINEAR, 50 REF_IMAGE, 51 RGB, 52 }; 53 54 static std::shared_ptr<ColorSpace> CreateSRGB(); 55 static std::shared_ptr<ColorSpace> CreateSRGBLinear(); 56 static std::shared_ptr<ColorSpace> CreateRefImage(const Image& image); 57 /* 58 * @brief Create a ColorSpace form a transfer function and a row-major 3x3 transformation to XYZ. 59 * @param func A transfer function type 60 * @param matrix A row-major 3x3 transformation type to XYZ 61 * @return A shared pointer to ColorSpace that its type is RGB. 62 */ 63 static std::shared_ptr<ColorSpace> CreateRGB(const CMSTransferFuncType& func, const CMSMatrixType& matrix); 64 /* 65 * @brief Create a ColorSpace form a adaptro impl, only used by ImageInfo to ccreate from adaptor image info 66 * @param impl A adaptor impl of color space 67 * @return A shared pointer to ColorSpace that its type is RGB. 68 */ 69 static std::shared_ptr<ColorSpace> CreateFromImpl(std::shared_ptr<ColorSpaceImpl> impl); 70 71 ColorSpace() noexcept; 72 virtual ~ColorSpace() = default; 73 ColorSpaceType GetType() const; GetDrawingType()74 virtual DrawingType GetDrawingType() const 75 { 76 return DrawingType::COMMON; 77 } 78 79 template<typename T> GetImpl()80 T* GetImpl() const 81 { 82 return impl_->DowncastingTo<T>(); 83 } 84 85 ColorSpace(std::shared_ptr<ColorSpaceImpl> impl) noexcept; 86 ColorSpace(ColorSpaceType t) noexcept; 87 ColorSpace(ColorSpaceType t, const Image& image) noexcept; 88 ColorSpace(ColorSpaceType t, const CMSTransferFuncType& func, const CMSMatrixType& matrix) noexcept; 89 90 /* 91 * @brief Caller use method toProfile of SkColorSpace, the parameter is type skcms_ICCProfile. 92 * @ In order not to encapsulate this method. Drawing ColorSpace needs to be converted to SkColorSpace. 93 * @return A shared pointer to SkColorSpace. 94 */ 95 sk_sp<SkColorSpace> GetSkColorSpace() const; 96 std::shared_ptr<Data> Serialize() const; 97 bool Deserialize(std::shared_ptr<Data> data); 98 99 private: 100 ColorSpaceType type_; 101 std::shared_ptr<ColorSpaceImpl> impl_; 102 }; 103 } // namespace Drawing 104 } // namespace Rosen 105 } // namespace OHOS 106 #endif 107