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

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: Fix Windows lak 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
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..e243f0877b36a4cfea4b41b552e5d023ac213c9a
--- /dev/null
+++ b/ui/gfx/color_profile_win.cc
@@ -0,0 +1,63 @@
+// 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_hwnd,
+ 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));
Evan Stade 2012/06/12 00:48:24 80
tpayne 2012/06/19 17:51:15 Done.
+ 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);
+ }
Evan Stade 2012/06/12 00:48:24 no curlies
tpayne 2012/06/19 17:51:15 Done.
+ free(buffer);
+ fclose(file);
+}
+
+} // namespace gfx
+
« ui/gfx/color_profile.cc ('K') | « 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