Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(764)

Side by Side Diff: components/wallpaper/wallpaper_color_calculator.h

Issue 2943333003: Extracting more than one wallpaper prominent color (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_WALLPAPER_WALLPAPER_COLOR_CALCULATOR_H_ 5 #ifndef COMPONENTS_WALLPAPER_WALLPAPER_COLOR_CALCULATOR_H_
6 #define COMPONENTS_WALLPAPER_WALLPAPER_COLOR_CALCULATOR_H_ 6 #define COMPONENTS_WALLPAPER_WALLPAPER_COLOR_CALCULATOR_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
11 #include "base/observer_list.h" 11 #include "base/observer_list.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "components/wallpaper/wallpaper_export.h" 13 #include "components/wallpaper/wallpaper_export.h"
14 #include "third_party/skia/include/core/SkColor.h" 14 #include "third_party/skia/include/core/SkColor.h"
15 #include "ui/gfx/color_analysis.h" 15 #include "ui/gfx/color_analysis.h"
16 #include "ui/gfx/image/image_skia.h" 16 #include "ui/gfx/image/image_skia.h"
17 17
18 namespace base { 18 namespace base {
19 class TaskRunner; 19 class TaskRunner;
20 } 20 }
21 21
22 namespace wallpaper { 22 namespace wallpaper {
23 class WallpaperColorCalculatorObserver; 23 class WallpaperColorCalculatorObserver;
24 24
25 // Calculates colors based on a wallpaper image. 25 // Calculates colors based on a wallpaper image.
26 class WALLPAPER_EXPORT WallpaperColorCalculator { 26 class WALLPAPER_EXPORT WallpaperColorCalculator {
27 public: 27 public:
28 // |image|, |luma| and |saturation| are the input parameters to the color 28 // |image|, |color_profiles| are the input parameters to the color calculation
29 // calculation that is executed on the |task_runner|. 29 // that is executed on the |task_runner|.
30 WallpaperColorCalculator(const gfx::ImageSkia& image, 30 WallpaperColorCalculator(const gfx::ImageSkia& image,
31 color_utils::LumaRange luma, 31 const color_utils::ColorProfiles& color_profiles,
32 color_utils::SaturationRange saturation,
33 scoped_refptr<base::TaskRunner> task_runner); 32 scoped_refptr<base::TaskRunner> task_runner);
34 ~WallpaperColorCalculator(); 33 ~WallpaperColorCalculator();
35 34
36 void AddObserver(WallpaperColorCalculatorObserver* observer); 35 void AddObserver(WallpaperColorCalculatorObserver* observer);
37 36
38 void RemoveObserver(WallpaperColorCalculatorObserver* observer); 37 void RemoveObserver(WallpaperColorCalculatorObserver* observer);
39 38
40 // Initiates the calculation and returns false if the calculation fails to be 39 // Initiates the calculation and returns false if the calculation fails to be
41 // initiated. Observers may be notified synchronously or asynchronously. 40 // initiated. Observers may be notified synchronously or asynchronously.
42 // Callers should be aware that this will make |image_| read-only. 41 // Callers should be aware that this will make |image_| read-only.
43 bool StartCalculation() WARN_UNUSED_RESULT; 42 bool StartCalculation() WARN_UNUSED_RESULT;
44 43
45 SkColor prominent_color() const { return prominent_color_; } 44 std::vector<SkColor> prominent_colors() const { return prominent_colors_; }
46 45
47 void set_prominent_color_for_test(SkColor prominent_color) { 46 void set_prominent_colors_for_test(
48 prominent_color_ = prominent_color; 47 const std::vector<SkColor>& prominent_colors) {
48 prominent_colors_ = prominent_colors;
49 } 49 }
50 50
51 // Explicitly sets the |task_runner_| for testing. 51 // Explicitly sets the |task_runner_| for testing.
52 void SetTaskRunnerForTest(scoped_refptr<base::TaskRunner> task_runner); 52 void SetTaskRunnerForTest(scoped_refptr<base::TaskRunner> task_runner);
53 53
54 private: 54 private:
55 // Handles asynchronous calculation results. |async_start_time| is used to 55 // Handles asynchronous calculation results. |async_start_time| is used to
56 // record duration metrics. 56 // record duration metrics.
57 void OnAsyncCalculationComplete(base::TimeTicks async_start_time, 57 void OnAsyncCalculationComplete(base::TimeTicks async_start_time,
58 SkColor prominent_color); 58 const std::vector<SkColor>& prominent_colors);
59 59
60 // Notifies observers that a color calulation has completed. Called on the 60 // Notifies observers that a color calulation has completed. Called on the
61 // same thread that constructed |this|. 61 // same thread that constructed |this|.
62 void NotifyCalculationComplete(SkColor prominent_color); 62 void NotifyCalculationComplete(const std::vector<SkColor>& prominent_colors);
63 63
64 // The result of the color calculation. 64 // The result of the color calculation.
65 SkColor prominent_color_ = SK_ColorTRANSPARENT; 65 std::vector<SkColor> prominent_colors_;
66 66
67 // The image to calculate colors from. 67 // The image to calculate colors from.
68 gfx::ImageSkia image_; 68 gfx::ImageSkia image_;
69 69
70 // Input for the color calculation. 70 // The color profiles used to calculate colors.
71 color_utils::LumaRange luma_; 71 color_utils::ColorProfiles color_profiles_;
72
73 // Input for the color calculation.
74 color_utils::SaturationRange saturation_;
75 72
76 // The task runner to run the calculation on. 73 // The task runner to run the calculation on.
77 scoped_refptr<base::TaskRunner> task_runner_; 74 scoped_refptr<base::TaskRunner> task_runner_;
78 75
79 base::ObserverList<WallpaperColorCalculatorObserver> observers_; 76 base::ObserverList<WallpaperColorCalculatorObserver> observers_;
80 77
81 base::WeakPtrFactory<WallpaperColorCalculator> weak_ptr_factory_; 78 base::WeakPtrFactory<WallpaperColorCalculator> weak_ptr_factory_;
82 79
83 DISALLOW_COPY_AND_ASSIGN(WallpaperColorCalculator); 80 DISALLOW_COPY_AND_ASSIGN(WallpaperColorCalculator);
84 }; 81 };
85 82
86 } // namespace wallpaper 83 } // namespace wallpaper
87 84
88 #endif // COMPONENTS_WALLPAPER_WALLPAPER_COLOR_CALCULATOR_H_ 85 #endif // COMPONENTS_WALLPAPER_WALLPAPER_COLOR_CALCULATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698