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 |
+ |