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

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: Missed one hwnd reference 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..4e32183f12abdd43bd324274f002dc177849824a
--- /dev/null
+++ b/ui/gfx/color_profile_win.cc
@@ -0,0 +1,64 @@
+// 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_window,
+ 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.
+
+ 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;
+ 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);
+ 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