1 /*
2 * Copyright (c) 2024 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 "cj_color_picker.h"
17
18 #include "color_picker.h"
19 #include "effect_errors.h"
20 #include "effect_utils.h"
21 namespace OHOS {
22 namespace CJEffectKit {
23 using namespace OHOS::ColorManager;
24 using namespace OHOS::Media;
25 using namespace OHOS::Rosen;
26
27 const int64_t EFFECTKIT_ERROR = -1;
28
CJColorPicker()29 CJColorPicker::CJColorPicker() {}
30
CreateColorPicker(Media::PixelMapImpl * source,uint32_t & code)31 int64_t CJColorPicker::CreateColorPicker(Media::PixelMapImpl* source, uint32_t& code)
32 {
33 std::shared_ptr<Media::PixelMap> pixmap = source->GetRealPixelMap();
34 ColorPickerCommon::CreateColorPicker(pixmap, code);
35 auto native = FFIData::Create<CJColorPicker>();
36 if (!native) {
37 return EFFECTKIT_ERROR;
38 }
39 return native->GetID();
40 }
41
CreateColorPicker(Media::PixelMapImpl * source,std::vector<double> region,uint32_t & code)42 int64_t CJColorPicker::CreateColorPicker(Media::PixelMapImpl* source, std::vector<double> region, uint32_t& code)
43 {
44 std::shared_ptr<Media::PixelMap> pixmap = source->GetRealPixelMap();
45 ColorPickerCommon::CreateColorPicker(pixmap, region, code);
46 auto native = FFIData::Create<CJColorPicker>();
47 if (!native) {
48 return EFFECTKIT_ERROR;
49 }
50 return native->GetID();
51 }
52
GetMainColor(Color & color)53 uint32_t CJColorPicker::GetMainColor(Color& color)
54 {
55 return ColorPickerCommon::GetMainColor(color);
56 }
57
GetLargestProportionColor(Color & color)58 uint32_t CJColorPicker::GetLargestProportionColor(Color& color)
59 {
60 return ColorPickerCommon::GetLargestProportionColor(color);
61 }
62
GetHighestSaturationColor(Color & color)63 uint32_t CJColorPicker::GetHighestSaturationColor(Color& color)
64 {
65 return ColorPickerCommon::GetHighestSaturationColor(color);
66 }
67
GetAverageColor(Color & color)68 uint32_t CJColorPicker::GetAverageColor(Color& color)
69 {
70 return ColorPickerCommon::GetAverageColor(color);
71 }
72
IsBlackOrWhiteOrGrayColor(uint32_t color,uint32_t & code)73 bool CJColorPicker::IsBlackOrWhiteOrGrayColor(uint32_t color, uint32_t& code)
74 {
75 return ColorPickerCommon::IsBlackOrWhiteOrGrayColor(color, code);
76 }
77
GetTopProportionColors(double colorCount,uint32_t & code)78 std::vector<ColorManager::Color> CJColorPicker::GetTopProportionColors(double colorCount, uint32_t& code)
79 {
80 return ColorPickerCommon::GetTopProportionColors(colorCount, code);
81 }
82
83 } // namespace CJEffectKit
84 } // namespace OHOS