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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/color_profile_mac.cc ('k') | ui/ui.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..5b985e738d0f1ae38e86f36e469d29167eca3bf9
--- /dev/null
+++ b/ui/gfx/color_profile_win.cc
@@ -0,0 +1,57 @@
+// 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)
+
+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) {
+ uint32 length;
+
+ 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.
+
+ 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;
+ size_t length = ReadLengthFromString(profileData);
+ if (length == 0 || length + sizeof(uint32) > profileData.size())
+ return;
+ const char* dataBuffer = profileData.data() + sizeof(uint32);
+ profile->assign(dataBuffer, dataBuffer + length);
+}
+
+} // namespace gfx
+
« 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