1 /*
2 * Copyright (c) 2025 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 "utils/colorspace_convertor.h"
17
18 namespace OHOS {
19 namespace Rosen {
20 namespace Drawing {
ColorSpaceConvertToDrawingColorSpace(std::shared_ptr<OHOS::ColorManager::ColorSpace> colorspace)21 std::shared_ptr<OHOS::Rosen::Drawing::ColorSpace> ColorSpaceConvertor::ColorSpaceConvertToDrawingColorSpace(
22 std::shared_ptr<OHOS::ColorManager::ColorSpace> colorspace)
23 {
24 #if defined(ROSEN_OHOS) || defined(ROSEN_ARKUI_X)
25 if (colorspace == nullptr) {
26 return nullptr;
27 }
28 OHOS::ColorManager::Matrix3x3 toXYZ = colorspace->GetRGBToXYZ();
29 OHOS::ColorManager::TransferFunc transferFunc = colorspace->GetTransferFunction();
30 OHOS::Rosen::Drawing::CMSTransferFunction drawingTransferFunc = {
31 transferFunc.g,
32 transferFunc.a,
33 transferFunc.b,
34 transferFunc.c,
35 transferFunc.d,
36 transferFunc.e,
37 transferFunc.f
38 };
39 OHOS::Rosen::Drawing::CMSMatrix3x3 drawingMatrix;
40
41 for (int i = 0; i < DIMES_3; i++) {
42 for (int j = 0; j < DIMES_3; j++) {
43 drawingMatrix.vals[i][j] = toXYZ[i][j];
44 }
45 }
46 return OHOS::Rosen::Drawing::ColorSpace::CreateCustomRGB(drawingTransferFunc, drawingMatrix);
47 #else
48 return nullptr;
49 #endif
50 }
51 } // namespace Drawing
52 } // namespace Rosen
53 } // namespace OHOS