Chromium Code Reviews| 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) | |
|
Noel Gordon
2012/06/21 16:58:33
I don't see how this #define is particular to win3
tpayne
2012/07/02 19:22:32
Done.
| |
| 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) { | |
|
Noel Gordon
2012/06/21 16:58:33
Nice comment, but this function has really confuse
tpayne
2012/07/02 19:22:32
Done.
| |
| 21 uint32 length; | |
| 22 | |
| 23 if (data.size() < sizeof(length)) | |
| 24 return 0; | |
| 25 | |
| 26 memcpy(&length, data.data(), sizeof(length)); | |
| 27 | |
| 28 return base::NetToHost32(length); | |
| 29 } | |
| 30 | |
| 31 } // namespace | |
| 32 | |
| 33 namespace gfx { | |
| 34 | |
| 35 void ColorProfile::ReadProfile(gfx::NativeViewId parent_window, | |
| 36 std::vector<char>* profile) { | |
| 37 HDC screen_dc = GetDC(NULL); | |
| 38 DWORD path_len = MAX_PATH; | |
| 39 WCHAR path[MAX_PATH]; | |
| 40 | |
| 41 BOOL res = GetICMProfile(screen_dc, | |
| 42 &path_len, | |
| 43 reinterpret_cast<LPWSTR>(&path)); | |
| 44 ReleaseDC(NULL, screen_dc); | |
| 45 if (!res) | |
| 46 return; | |
| 47 std::string profileData; | |
| 48 if (!file_util::ReadFileToString(FilePath(path), &profileData)) | |
| 49 return; | |
| 50 if (profileData.size() > MAX_PROFILE_LENGTH) | |
| 51 return; | |
|
Noel Gordon
2012/06/21 16:58:33
I'd add an additional clause here:
if (profileDat
tpayne
2012/07/02 19:22:32
Done.
| |
| 52 size_t length = ReadLengthFromString(profileData); | |
| 53 if (length == 0 || length + sizeof(uint32) > profileData.size()) | |
|
Noel Gordon
2012/06/21 16:58:33
So maybe length + sizeof(uint32) could be less tha
tpayne
2012/07/02 19:22:32
Done.
| |
| 54 return; | |
| 55 const char* dataBuffer = profileData.data() + sizeof(uint32); | |
|
Noel Gordon
2012/06/21 16:58:33
... as your comment @ line 18 said, the length is
tpayne
2012/07/02 19:22:32
I haven't figured out a reliable way of testing, m
| |
| 56 profile->assign(dataBuffer, dataBuffer + length); | |
| 57 } | |
| 58 | |
| 59 } // namespace gfx | |
| 60 | |
| OLD | NEW |