Chromium Code Reviews| Index: ui/gfx/color_profile_win.cc |
| diff --git a/ui/gfx/color_profile_win.cc b/ui/gfx/color_profile_win.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..28b10f8dd775d02f214ebe8b1a0420d89f18ba3a |
| --- /dev/null |
| +++ b/ui/gfx/color_profile_win.cc |
| @@ -0,0 +1,60 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ui/gfx/color_profile.h" |
| + |
| +#include <stdio.h> |
| +#include <windows.h> |
| + |
| +#include "base/file_util.h" |
| +#include "base/sys_byteorder.h" |
| + |
| +// Max profile size is 4M. |
| +#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.
|
| + |
| +namespace { |
| + |
| +// ICC profiles store the profile length in network byte order in the first |
| +// bytes of the data. |
| +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.
|
| + uint32 length; |
| + |
| + if (data.size() < sizeof(length)) |
| + return 0; |
| + |
| + memcpy(&length, data.data(), sizeof(length)); |
| + |
| + return base::NetToHost32(length); |
| +} |
| + |
| +} // namespace |
| + |
| +namespace gfx { |
| + |
| +void ColorProfile::ReadProfile(gfx::NativeViewId parent_window, |
| + std::vector<char>* profile) { |
| + HDC screen_dc = GetDC(NULL); |
| + DWORD path_len = MAX_PATH; |
| + WCHAR path[MAX_PATH]; |
| + |
| + BOOL res = GetICMProfile(screen_dc, |
| + &path_len, |
| + reinterpret_cast<LPWSTR>(&path)); |
| + ReleaseDC(NULL, screen_dc); |
| + if (!res) |
| + return; |
| + std::string profileData; |
| + if (!file_util::ReadFileToString(FilePath(path), &profileData)) |
| + return; |
| + if (profileData.size() > MAX_PROFILE_LENGTH) |
| + 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.
|
| + size_t length = ReadLengthFromString(profileData); |
| + 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.
|
| + return; |
| + 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
|
| + profile->assign(dataBuffer, dataBuffer + length); |
| +} |
| + |
| +} // namespace gfx |
| + |