summaryrefslogtreecommitdiff
path: root/chromium/ui/gfx/color_profile_win.cc
blob: 2e08a36d4b65a06a079fcf73ebcc335ab2c70c91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// 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 <windows.h>

#include "base/file_util.h"

namespace gfx {

void ReadColorProfile(std::vector<char>* profile) {
  // TODO: support multiple monitors.
  HDC screen_dc = GetDC(NULL);
  DWORD path_len = MAX_PATH;
  WCHAR path[MAX_PATH + 1];

  BOOL res = GetICMProfile(screen_dc, &path_len, path);
  ReleaseDC(NULL, screen_dc);
  if (!res)
    return;
  std::string profileData;
  if (!base::ReadFileToString(base::FilePath(path), &profileData))
    return;
  size_t length = profileData.size();
  if (length > gfx::kMaxProfileLength)
    return;
  if (length < gfx::kMinProfileLength)
    return;
  profile->assign(profileData.data(), profileData.data() + length);
}

}  // namespace gfx