Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: ui/gfx/color_profile_win.cc

Issue 10448110: Adds monitor ICC profile support for win and mac (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Renamed reply_msg to rofile Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gfx/color_profile_mac.cc ('k') | ui/ui.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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));
Evan Stade 2012/06/20 21:10:51 this will be an error if data.empty()
Evan Stade 2012/06/20 21:11:30 or if size < sizeof(uint32)
tpayne 2012/06/20 21:45:26 Good catch. Done.
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
OLDNEW
« no previous file with comments | « ui/gfx/color_profile_mac.cc ('k') | ui/ui.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698