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/sys_byteorder.h" | |
11 | |
12 // Max profile size is 4M. | |
13 #define MAX_PROFILE_LENGTH (4 * 1000 * 1000) | |
14 | |
15 namespace { | |
16 | |
17 size_t ReadLengthFromFile(FILE *file) { | |
18 uint32 length; | |
19 | |
20 if (fread(&length, 1, sizeof(length), file) != sizeof(length)) | |
21 return 0; | |
22 | |
23 return base::NetToHost32(length); | |
24 } | |
25 | |
26 } // namespace | |
27 | |
28 namespace gfx { | |
29 | |
30 void ColorProfile::ReadProfile(gfx::NativeViewId parent_window, | |
31 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.
| |
32 | |
33 HDC screen_dc = GetDC(NULL); | |
34 DWORD path_len = MAX_PATH; | |
35 WCHAR path[MAX_PATH]; | |
36 | |
37 BOOL res = GetICMProfile(screen_dc, | |
38 &path_len, | |
39 reinterpret_cast<LPWSTR>(&path)); | |
40 ReleaseDC(NULL, screen_dc); | |
41 if (!res) | |
42 return; | |
43 FILE* file = _wfopen(path, L"rb"); | |
44 if (!file) | |
45 return; | |
46 size_t length = ReadLengthFromFile(file); | |
47 if (length == 0 || length > MAX_PROFILE_LENGTH) { | |
48 fclose(file); | |
49 return; | |
50 } | |
51 char* buffer = reinterpret_cast<char*>(malloc(length)); | |
52 if (!buffer) { | |
53 fclose(file); | |
54 return; | |
55 } | |
56 | |
57 if (fread(buffer, 1, length, file) == length) | |
58 profile->assign(buffer, buffer + length); | |
59 free(buffer); | |
60 fclose(file); | |
61 } | |
62 | |
63 } // namespace gfx | |
64 | |
OLD | NEW |