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

Side by Side Diff: ui/gfx/icc_profile.h

Issue 2652503002: Use SkICC in gfx::ICCProfile and gfx::ColorSpace (Closed)
Patch Set: Rebase Created 3 years, 10 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
« no previous file with comments | « ui/gfx/color_transform_unittest.cc ('k') | ui/gfx/icc_profile.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 UI_GFX_ICC_PROFILE_H_ 5 #ifndef UI_GFX_ICC_PROFILE_H_
6 #define UI_GFX_ICC_PROFILE_H_ 6 #define UI_GFX_ICC_PROFILE_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/gtest_prod_util.h" 11 #include "base/gtest_prod_util.h"
12 #include "ui/gfx/color_space.h" 12 #include "ui/gfx/color_space.h"
13 13
14 #if defined(OS_MACOSX) 14 #if defined(OS_MACOSX)
15 #include <CoreGraphics/CGColorSpace.h> 15 #include <CoreGraphics/CGColorSpace.h>
16 #endif 16 #endif
17 17
18 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size); 18 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size);
19 19
20 namespace mojo { 20 namespace mojo {
21 template <typename, typename> struct StructTraits; 21 template <typename, typename> struct StructTraits;
22 } 22 }
23 23
24 namespace gfx { 24 namespace gfx {
25 25
26 namespace mojom {
27 class ICCProfileDataView;
28 }
29
30 // Used to represent a full ICC profile, usually retrieved from a monitor. It 26 // Used to represent a full ICC profile, usually retrieved from a monitor. It
31 // can be lossily compressed into a ColorSpace object. This structure should 27 // can be lossily compressed into a ColorSpace object. This structure should
32 // only be sent from higher-privilege processes to lower-privilege processes, 28 // only be sent from higher-privilege processes to lower-privilege processes,
33 // as parsing this structure is not secure. 29 // as parsing this structure is not secure.
34 class GFX_EXPORT ICCProfile { 30 class GFX_EXPORT ICCProfile {
35 public: 31 public:
36 ICCProfile(); 32 ICCProfile();
37 ICCProfile(ICCProfile&& other); 33 ICCProfile(ICCProfile&& other);
38 ICCProfile(const ICCProfile& other); 34 ICCProfile(const ICCProfile& other);
39 ICCProfile& operator=(ICCProfile&& other); 35 ICCProfile& operator=(ICCProfile&& other);
40 ICCProfile& operator=(const ICCProfile& other); 36 ICCProfile& operator=(const ICCProfile& other);
41 ~ICCProfile(); 37 ~ICCProfile();
42 bool operator==(const ICCProfile& other) const; 38 bool operator==(const ICCProfile& other) const;
43 bool operator!=(const ICCProfile& other) const; 39 bool operator!=(const ICCProfile& other) const;
44 40
45 // Returns the color profile of the monitor that can best represent color. 41 // Returns the color profile of the monitor that can best represent color.
46 // This profile should be used for creating content that does not know on 42 // This profile should be used for creating content that does not know on
47 // which monitor it will be displayed. 43 // which monitor it will be displayed.
48 static ICCProfile FromBestMonitor(); 44 static ICCProfile FromBestMonitor();
49 #if defined(OS_MACOSX) 45 #if defined(OS_MACOSX)
50 static ICCProfile FromCGColorSpace(CGColorSpaceRef cg_color_space); 46 static ICCProfile FromCGColorSpace(CGColorSpaceRef cg_color_space);
51 #endif 47 #endif
52 48
53 // This will recover a ICCProfile from a compact ColorSpace representation. 49 // This will recover a ICCProfile from a compact ColorSpace representation.
54 // Internally, this will make an effort to create an identical ICCProfile 50 // Internally, this will make an effort to create an identical ICCProfile
55 // to the one that created |color_space|, but this is not guaranteed. 51 // to the one that created |color_space|, but this is not guaranteed.
56 static ICCProfile FromColorSpace(const gfx::ColorSpace& color_space); 52 static ICCProfile FromColorSpace(const gfx::ColorSpace& color_space);
57 static ICCProfile FromSkColorSpace(sk_sp<SkColorSpace> color_space);
58 53
59 // Create directly from profile data. 54 // Create directly from profile data.
60 static ICCProfile FromData(const char* icc_profile, size_t size); 55 static ICCProfile FromData(const void* icc_profile, size_t size);
61 56
62 // This will perform a potentially-lossy conversion to a more compact color 57 // This will perform a potentially-lossy conversion to a more compact color
63 // space representation. 58 // space representation.
64 ColorSpace GetColorSpace() const; 59 const ColorSpace& GetColorSpace() const;
65 60
66 const std::vector<char>& GetData() const; 61 const std::vector<char>& GetData() const;
67 62
68 #if defined(OS_WIN) 63 #if defined(OS_WIN)
69 // This will read monitor ICC profiles from disk and cache the results for the 64 // This will read monitor ICC profiles from disk and cache the results for the
70 // other functions to read. This should not be called on the UI or IO thread. 65 // other functions to read. This should not be called on the UI or IO thread.
71 static void UpdateCachedProfilesOnBackgroundThread(); 66 static void UpdateCachedProfilesOnBackgroundThread();
72 static bool CachedProfilesNeedUpdate(); 67 static bool CachedProfilesNeedUpdate();
73 #endif 68 #endif
74 69
75 enum class Type { 70 private:
76 // This is not a valid profile. 71 // TODO(ccameron): Remove this function once its callerrs are gone.
77 INVALID, 72 static ICCProfile FromSkColorSpace(sk_sp<SkColorSpace> color_space);
78 // This is from a gfx::ColorSpace. This ensures that GetColorSpace returns 73 static bool IsValidProfileLength(size_t length);
79 // the exact same object as was used to create this. 74 void ComputeColorSpaceAndCache();
80 FROM_COLOR_SPACE,
81 // This was created from ICC profile data.
82 FROM_DATA,
83 LAST = FROM_DATA
84 };
85 75
86 private: 76 // This globally identifies this ICC profile. It is used to look up this ICC
87 static bool IsValidProfileLength(size_t length); 77 // profile from a ColorSpace object created from it. The object is invalid if
88 78 // |id_| is zero.
89 Type type_ = Type::INVALID; 79 uint64_t id_ = 0;
90 gfx::ColorSpace color_space_;
91 std::vector<char> data_; 80 std::vector<char> data_;
92 81
93 // This globally identifies this ICC profile. It is used to look up this ICC 82 gfx::ColorSpace color_space_;
94 // profile from a ColorSpace object created from it.
95 uint64_t id_ = 0;
96 83
97 FRIEND_TEST_ALL_PREFIXES(SimpleColorSpace, BT709toSRGBICC); 84 FRIEND_TEST_ALL_PREFIXES(SimpleColorSpace, BT709toSRGBICC);
98 FRIEND_TEST_ALL_PREFIXES(SimpleColorSpace, GetColorSpace); 85 FRIEND_TEST_ALL_PREFIXES(SimpleColorSpace, GetColorSpace);
99 friend int ::LLVMFuzzerTestOneInput(const uint8_t*, size_t); 86 friend int ::LLVMFuzzerTestOneInput(const uint8_t*, size_t);
100 friend class ColorSpace; 87 friend class ColorSpace;
101 friend struct IPC::ParamTraits<gfx::ICCProfile>; 88 friend struct IPC::ParamTraits<gfx::ICCProfile>;
102 friend struct IPC::ParamTraits<gfx::ICCProfile::Type>;
103 friend struct mojo::StructTraits<gfx::mojom::ICCProfileDataView,
104 gfx::ICCProfile>;
105 }; 89 };
106 90
107 } // namespace gfx 91 } // namespace gfx
108 92
109 #endif // UI_GFX_ICC_PROFILE_H_ 93 #endif // UI_GFX_ICC_PROFILE_H_
OLDNEW
« no previous file with comments | « ui/gfx/color_transform_unittest.cc ('k') | ui/gfx/icc_profile.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698