1 /* 2 * Copyright (c) 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 RS_COLOR_PICKER_H 17 #define RS_COLOR_PICKER_H 18 19 #include <iostream> 20 #include "image/pixmap.h" 21 #include "draw/color.h" 22 #include "rs_color_extract.h" 23 24 namespace OHOS { 25 namespace Rosen { 26 27 struct HSV { 28 int h; // 色度取值(0-360) 29 double s; // 饱和度取值 (0-100) 30 double v; // 亮度取值 (0-100) 31 }; 32 33 class RSColorPicker : public RSColorExtract { 34 public: ~RSColorPicker()35 ~RSColorPicker() {} 36 NATIVEEXPORT static std::shared_ptr<RSColorPicker> CreateColorPicker( 37 const std::shared_ptr<Drawing::Pixmap>& pixmap, uint32_t &errorCode); 38 NATIVEEXPORT static std::shared_ptr<RSColorPicker> CreateColorPicker( 39 const std::shared_ptr<Drawing::Pixmap>& pixmap, double* coordinates, uint32_t &errorCode); 40 41 NATIVEEXPORT uint32_t GetLargestProportionColor(Drawing::ColorQuad &color) const; 42 NATIVEEXPORT uint32_t GetHighestSaturationColor(Drawing::ColorQuad &color) const; 43 NATIVEEXPORT uint32_t GetAverageColor(Drawing::ColorQuad &color) const; 44 NATIVEEXPORT bool IsBlackOrWhiteOrGrayColor(uint32_t color) const; 45 46 private: 47 RSColorPicker(std::shared_ptr<Drawing::Pixmap> pixmap); 48 RSColorPicker(std::shared_ptr<Drawing::Pixmap> pixmap, double* coordinates); 49 bool IsEquals(double val1, double val2) const; 50 HSV RGB2HSV(uint32_t rgb) const; 51 void AdjustHSVToDefinedIterval(HSV& hsv) const; 52 uint32_t HSVtoRGB(HSV hsv) const; 53 }; 54 } // namespace Rosen 55 } // namespace OHOS 56 57 #endif // RS_COLOR_PICKER_H 58