Chromium Code Reviews| OLD | NEW |
|---|---|
| (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/sys_byteorder.h" | |
| 11 | |
| 12 // Max profile size is 4M. | |
| 13 #define MAX_PROFILE_LENGTH (4 * 1000 * 1000) | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 size_t ReadLengthFromFile(FILE *file) { | |
| 18 uint32 length; | |
| 19 | |
| 20 if (fread(&length, 1, sizeof(length), file) != sizeof(length)) | |
| 21 return 0; | |
| 22 | |
| 23 return base::NetToHost32(length); | |
| 24 } | |
| 25 | |
| 26 } // namespace | |
| 27 | |
| 28 namespace gfx { | |
| 29 | |
| 30 void ColorProfile::ReadProfile(gfx::NativeViewId parent_hwnd, | |
| 31 std::vector<char>* profile) { | |
| 32 | |
| 33 HDC screen_dc = GetDC(NULL); | |
| 34 DWORD path_len = MAX_PATH; | |
| 35 WCHAR path[MAX_PATH]; | |
| 36 | |
| 37 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.
| |
| 38 ReleaseDC(NULL, screen_dc); | |
| 39 if (!res) | |
| 40 return; | |
| 41 FILE* file = _wfopen(path, L"rb"); | |
| 42 if (!file) | |
| 43 return; | |
| 44 size_t length = ReadLengthFromFile(file); | |
| 45 if (length == 0 || length > MAX_PROFILE_LENGTH) { | |
| 46 fclose(file); | |
| 47 return; | |
| 48 } | |
| 49 char* buffer = reinterpret_cast<char*>(malloc(length)); | |
| 50 if (!buffer) { | |
| 51 fclose(file); | |
| 52 return; | |
| 53 } | |
| 54 | |
| 55 if (fread(buffer, 1, length, file) == length) { | |
| 56 profile->assign(buffer, buffer + length); | |
| 57 } | |
|
Evan Stade
2012/06/12 00:48:24
no curlies
tpayne
2012/06/19 17:51:15
Done.
| |
| 58 free(buffer); | |
| 59 fclose(file); | |
| 60 } | |
| 61 | |
| 62 } // namespace gfx | |
| 63 | |
| OLD | NEW |