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..4e32183f12abdd43bd324274f002dc177849824a |
| --- /dev/null |
| +++ b/ui/gfx/color_profile_win.cc |
| @@ -0,0 +1,64 @@ |
| +// 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/sys_byteorder.h" |
| + |
| +// Max profile size is 4M. |
| +#define MAX_PROFILE_LENGTH (4 * 1000 * 1000) |
| + |
| +namespace { |
| + |
| +size_t ReadLengthFromFile(FILE *file) { |
| + uint32 length; |
| + |
| + if (fread(&length, 1, sizeof(length), file) != sizeof(length)) |
| + return 0; |
| + |
| + return base::NetToHost32(length); |
| +} |
| + |
| +} // namespace |
| + |
| +namespace gfx { |
| + |
| +void ColorProfile::ReadProfile(gfx::NativeViewId parent_window, |
| + std::vector<char>* profile) { |
|
abarth-chromium
2012/06/19 20:36:50
Should we ASSERT that we're on the FILE thread her
Evan Stade
2012/06/19 21:08:56
yea, I think it happens automatically with browser
Evan Stade
2012/06/19 21:32:38
nix this comment ^
use file_util::ReadFileToStrin
tpayne
2012/06/19 21:44:52
Done.
tpayne
2012/06/20 01:36:09
file_util::ReadFileAsString already does this.
tpayne
2012/06/20 01:36:09
Actually done this time.
|
| + |
| + 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; |
| + FILE* file = _wfopen(path, L"rb"); |
| + if (!file) |
| + return; |
| + size_t length = ReadLengthFromFile(file); |
| + if (length == 0 || length > MAX_PROFILE_LENGTH) { |
| + fclose(file); |
| + return; |
| + } |
| + char* buffer = reinterpret_cast<char*>(malloc(length)); |
| + if (!buffer) { |
| + fclose(file); |
| + return; |
| + } |
| + |
| + if (fread(buffer, 1, length, file) == length) |
| + profile->assign(buffer, buffer + length); |
| + free(buffer); |
| + fclose(file); |
| +} |
| + |
| +} // namespace gfx |
| + |