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

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: Trying again... 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 size_t ReadLengthFromString(const std::string& data) {
Evan Stade 2012/06/20 02:41:47 comment this function
tpayne 2012/06/20 02:46:54 Done.
19 uint32 length;
20
21 memcpy(&length, data.data(), sizeof(length));
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) {
32 HDC screen_dc = GetDC(NULL);
33 DWORD path_len = MAX_PATH;
34 WCHAR path[MAX_PATH];
35
36 BOOL res = GetICMProfile(screen_dc,
37 &path_len,
38 reinterpret_cast<LPWSTR>(&path));
39 ReleaseDC(NULL, screen_dc);
40 if (!res)
41 return;
42 std::string profileData;
43 if (!file_util::ReadFileToString(FilePath(path), &profileData))
44 return;
45 if (profileData.size() > MAX_PROFILE_LENGTH)
Evan Stade 2012/06/20 02:41:47 put this check with the rest of the length checks
tpayne 2012/06/20 02:46:54 I'd prefer to bail out as soon as possible. No nee
Evan Stade 2012/06/20 02:56:58 there's a slight difference: you're effectively ma
46 return;
47 size_t length = ReadLengthFromString(profileData);
48 if (length == 0 || length + sizeof(uint32) > profileData.size())
49 return;
50 const char* dataBuffer = profileData.data() + sizeof(uint32);
51 profile->assign(dataBuffer, dataBuffer + length);
52 }
53
54 } // namespace gfx
55
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