| OLD | NEW |
| 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 Loading... |
| 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 |
| OLD | NEW |