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

Side by Side Diff: ui/gfx/color_profile_mac.mm

Issue 849523003: ui/gfx/color_profile: Add GetDisplayColorProfile for an NSWindow (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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_profile.cc ('k') | ui/gfx/color_profile_mac_unittest.mm » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "ui/gfx/color_profile.h" 5 #include "ui/gfx/color_profile.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include "base/mac/mac_util.h" 9 #include "base/mac/mac_util.h"
10 #include "base/mac/scoped_cftyperef.h" 10 #include "base/mac/scoped_cftyperef.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 if ([color_space isEqual:[NSColorSpace sRGBColorSpace]]) 47 if ([color_space isEqual:[NSColorSpace sRGBColorSpace]])
48 return true; 48 return true;
49 NSData* profile_data = [color_space ICCProfileData]; 49 NSData* profile_data = [color_space ICCProfileData];
50 const char* data = static_cast<const char*>([profile_data bytes]); 50 const char* data = static_cast<const char*>([profile_data bytes]);
51 size_t length = [profile_data length]; 51 size_t length = [profile_data length];
52 if (data && !gfx::InvalidColorProfileLength(length)) 52 if (data && !gfx::InvalidColorProfileLength(length))
53 profile->assign(data, data + length); 53 profile->assign(data, data + length);
54 return true; 54 return true;
55 } 55 }
56 56
57 GFX_EXPORT bool GetDisplayColorProfile(gfx::NativeWindow window,
58 std::vector<char>* profile) {
59 DCHECK(profile->empty());
60
61 NSColorSpace* color_space = [window colorSpace];
62 if (!color_space || NSIsEmptyRect([window frame]))
63 return false;
64
65 if ([color_space isEqual:[NSColorSpace sRGBColorSpace]])
66 return true;
67 NSData* profile_data = [color_space ICCProfileData];
68 const char* data = static_cast<const char*>([profile_data bytes]);
69 size_t length = [profile_data length];
70 if (data && !gfx::InvalidColorProfileLength(length))
71 profile->assign(data, data + length);
72 return true;
73 }
74
57 void ReadColorProfile(std::vector<char>* profile) { 75 void ReadColorProfile(std::vector<char>* profile) {
58 CGColorSpaceRef monitor_color_space(base::mac::GetSystemColorSpace()); 76 CGColorSpaceRef monitor_color_space(base::mac::GetSystemColorSpace());
59 base::ScopedCFTypeRef<CFDataRef> icc_profile( 77 base::ScopedCFTypeRef<CFDataRef> icc_profile(
60 CGColorSpaceCopyICCProfile(monitor_color_space)); 78 CGColorSpaceCopyICCProfile(monitor_color_space));
61 if (!icc_profile) 79 if (!icc_profile)
62 return; 80 return;
63 size_t length = CFDataGetLength(icc_profile); 81 size_t length = CFDataGetLength(icc_profile);
64 if (gfx::InvalidColorProfileLength(length)) 82 if (gfx::InvalidColorProfileLength(length))
65 return; 83 return;
66 const unsigned char* data = CFDataGetBytePtr(icc_profile); 84 const unsigned char* data = CFDataGetBytePtr(icc_profile);
67 profile->assign(data, data + length); 85 profile->assign(data, data + length);
68 } 86 }
69 87
70 } // namespace gfx 88 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/color_profile.cc ('k') | ui/gfx/color_profile_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698