OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/gfx/color_profile.h" |
| 6 |
| 7 #include <stdio.h> |
| 8 #include <windows.h> |
| 9 |
| 10 #include "base/file_util.h" |
| 11 #include "base/sys_byteorder.h" |
| 12 |
| 13 // Max profile size is 4M. |
| 14 #define MAX_PROFILE_LENGTH (4 * 1000 * 1000) |
| 15 |
| 16 namespace { |
| 17 |
| 18 // ICC profiles store the profile length in network byte order in the first |
| 19 // bytes of the data. |
| 20 size_t ReadLengthFromString(const std::string& data) { |
| 21 uint32 length; |
| 22 |
| 23 memcpy(&length, data.data(), sizeof(length)); |
| 24 |
| 25 return base::NetToHost32(length); |
| 26 } |
| 27 |
| 28 } // namespace |
| 29 |
| 30 namespace gfx { |
| 31 |
| 32 void ColorProfile::ReadProfile(gfx::NativeViewId parent_window, |
| 33 std::vector<char>* profile) { |
| 34 HDC screen_dc = GetDC(NULL); |
| 35 DWORD path_len = MAX_PATH; |
| 36 WCHAR path[MAX_PATH]; |
| 37 |
| 38 BOOL res = GetICMProfile(screen_dc, |
| 39 &path_len, |
| 40 reinterpret_cast<LPWSTR>(&path)); |
| 41 ReleaseDC(NULL, screen_dc); |
| 42 if (!res) |
| 43 return; |
| 44 std::string profileData; |
| 45 if (!file_util::ReadFileToString(FilePath(path), &profileData)) |
| 46 return; |
| 47 if (profileData.size() > MAX_PROFILE_LENGTH) |
| 48 return; |
| 49 size_t length = ReadLengthFromString(profileData); |
| 50 if (length == 0 || length + sizeof(uint32) > profileData.size()) |
| 51 return; |
| 52 const char* dataBuffer = profileData.data() + sizeof(uint32); |
| 53 profile->assign(dataBuffer, dataBuffer + length); |
| 54 } |
| 55 |
| 56 } // namespace gfx |
| 57 |
OLD | NEW |