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 "drawing/engine_adapter/impl_interface/color_space_impl.h" 22 23 namespace OHOS { 24 namespace Rosen { 25 namespace Drawing { 26 enum class CMSTransferFuncType { 27 SRGB, 28 DOT2, 29 LINEAR, 30 REC2020, 31 }; 32 33 enum class CMSMatrixType { 34 SRGB, 35 ADOBE_RGB, 36 DCIP3, 37 REC2020, 38 XYZ, 39 }; 40 41 class ColorSpace { 42 public: 43 enum class ColorSpaceType { 44 NO_TYPE, 45 SRGB, 46 SRGB_LINEAR, 47 REF_IMAGE, 48 RGB, 49 }; 50 51 static std::shared_ptr<ColorSpace> CreateSRGB(); 52 static std::shared_ptr<ColorSpace> CreateSRGBLinear(); 53 static std::shared_ptr<ColorSpace> CreateRefImage(const Image& image); 54 /* 55 * @brief Create a ColorSpace form a transfer function and a row-major 3x3 transformation to XYZ. 56 * @param func A transfer function type 57 * @param matrix A row-major 3x3 transformation type to XYZ 58 * @return A shared pointer to ColorSpace that its type is RGB. 59 */ 60 static std::shared_ptr<ColorSpace> CreateRGB(const CMSTransferFuncType& func, const CMSMatrixType& matrix); 61 62 virtual ~ColorSpace() = default; 63 ColorSpaceType GetType() const; GetDrawingType()64 virtual DrawingType GetDrawingType() const 65 { 66 return DrawingType::COMMON; 67 } 68 69 template<typename T> GetImpl()70 const std::shared_ptr<T> GetImpl() const 71 { 72 return impl_->DowncastingTo<T>(); 73 } 74 75 ColorSpace(ColorSpaceType t) noexcept; 76 ColorSpace(ColorSpaceType t, const Image& image) noexcept; 77 ColorSpace(ColorSpaceType t, const CMSTransferFuncType& func, const CMSMatrixType& matrix) noexcept; 78 79 protected: 80 ColorSpace() noexcept; 81 82 private: 83 ColorSpaceType type_; 84 std::shared_ptr<ColorSpaceImpl> impl_; 85 }; 86 } // namespace Drawing 87 } // namespace Rosen 88 } // namespace OHOS 89 #endif 90