2 * psychlops_io_display_Win32.cpp
3 * Psychlops Standard Library (Win32)
5 * Last Modified 2009/03/02 by Kenchi HOSOKAWA
6 * (C) 2009 Kenchi HOSOKAWA, Kazushi MARUYA, Takao SATO
12 #include "../../core/graphic/psychlops_g_canvas.h"
13 #include "psychlops_io_display_Win32.h"
19 Displays APIDisplayProperties::displays;
21 BOOL CALLBACK APIDisplayProperties::DisplayEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) {
22 APIDisplayProperties *api = new APIDisplayProperties;
23 api->monitor_ = hMonitor;
24 //api.display_ = CreateDC("DISPLAY".ptr, hMonitor, null, null);
26 displays.push_back(monitor);
31 APIDisplayProperties::APIDisplayProperties() :
33 // calibration_mode_(Color.CalibrationMode.NONE);
36 APIDisplayProperties::~APIDisplayProperties() {
37 if(display_ != 0) DeleteDC(display_);
40 Displays APIDisplayProperties::emumDisplays() {
42 EnumDisplayMonitors(NULL, NULL, &DisplayEnumProc, 0);
47 void APIDisplayProperties::getInfo(int &width, int &height, int &color_depth, double &refresh_rate, std::string& name, Rectangle& area) {
48 char info_[sizeof(MONITORINFOEXA)];
49 LPMONITORINFOEXA info = (LPMONITORINFOEXA)&info_;
50 info->cbSize = (DWORD)sizeof(MONITORINFOEXA);
51 GetMonitorInfoA(monitor_, info);
52 width = info->rcMonitor.right - info->rcMonitor.left;
53 height = info->rcMonitor.bottom - info->rcMonitor.top;
54 area.set(info->rcWork.left, info->rcWork.top, info->rcWork.right, info->rcWork.bottom);
56 primary_ = info->dwFlags;
57 name = info->szDevice;
58 display_ = CreateDC("DISPLAY", (char*)info->szDevice, (LPCTSTR)0, (const DEVMODE*)0);
59 color_depth = GetDeviceCaps(display_, BITSPIXEL);
60 refresh_rate = GetDeviceCaps(display_, VREFRESH);
63 // Hardware Gamma Settings : requires CGDirectDisplayID(target_display_)
64 void APIDisplayProperties::setGammaValue(const double gamma_r, const double gamma_g, const double gamma_b) {
67 err = CGSetDisplayTransferByFormula( did,
68 0.0, 1.0, (1.0/gamma_r),
69 0.0, 1.0, (1.0/gamma_g),
70 0.0, 1.0, (1.0/gamma_b));
71 // 0.0, 1.0, (1.0/gamma_r)*savedRedGamma_,
72 // 0.0, 1.0, (1.0/gamma_g)*savedGreenGamma_,
73 // 0.0, 1.0, (1.0/gamma_b)*savedBlueGamma_);
74 if(err!=kCGErrorSuccess) throw Exception(typeid(*this), "API ERROR", "Failed to set color calibration table for the video renderer.");
75 gamma_mode_ = Color::GAMMA_VALUE;
77 void APIDisplayProperties::setGammaTable(const std::vector<double> &table_r, const std::vector<double> &table_g, const std::vector<double> &table_b) {
79 if(table_r.size()!=256 || table_g.size()!=256 || table_b.size()!=256)
80 throw Exception(typeid(*this), "Gamma Table Error", "Table size is out of order (not 256).");
81 int num_steps = table_r.size();
83 CGGammaValue *(table[3]);
84 for(int i=0; i<3; i++) table[i] = new CGGammaValue[num_steps];
85 for(int j=0; j<num_steps; j++) {
86 table[0][j] = (CGGammaValue)table_r[j];
87 table[1][j] = (CGGammaValue)table_g[j];
88 table[2][j] = (CGGammaValue)table_b[j];
90 err = CGSetDisplayTransferByTable(did, num_steps, table[0], table[1], table[2]);
91 if(err!=kCGErrorSuccess) throw Exception(typeid(*this), "API ERROR", "Failed to set color calibration table for the video renderer.");
92 gamma_mode_ = Color::TABLE;
93 for(int i=0; i<3; i++) delete [] table[i];
95 void APIDisplayProperties::setGammaTable(const CGGammaValue * const table_r, const CGGammaValue * const table_g, const CGGammaValue * const table_b, const int num_steps) {
98 err = CGSetDisplayTransferByTable(did, num_steps, table_r, table_g, table_b);
99 gamma_mode_ = Color::TABLE;
101 void APIDisplayProperties::saveGammaValue() {
103 if(gamma_mode_==Color::NOTHING) {
104 err = CGGetDisplayTransferByFormula( did,
105 &savedRedMin_, &savedRedMax_, &savedRedGamma_,
106 &savedGreenMin_, &savedGreenMax_, &savedGreenGamma_,
107 &savedBlueMin_, &savedBlueMax_, &savedBlueGamma_);
110 void APIDisplayProperties::destroyGammaSettings() {
112 switch(gamma_mode_) {
113 case Color::GAMMA_VALUE:
116 err = CGSetDisplayTransferByFormula( did,
117 savedRedMin_, savedRedMax_, savedRedGamma_,
118 savedGreenMin_, savedGreenMax_, savedGreenGamma_,
119 savedBlueMin_, savedBlueMax_, savedBlueGamma_);
122 gamma_mode_ = Color::NOTHING;
126 const std::vector<Display> Display::list() {
127 return APIDisplayProperties::emumDisplays();
129 #ifndef MONITORINFOF_PRIMARY
130 #define MONITORINFOF_PRIMARY 1
133 const Display Display::main() {
134 int width, height, color_depth;
139 Displays d = APIDisplayProperties::emumDisplays();
141 for(i=0; i<d.size(); i++) {
142 d[i].api_->getInfo(width, height, color_depth, refresh_rate, name, area);
143 if(d[i].api_->primary_ == MONITORINFOF_PRIMARY) break;
150 Display::Display(APIDisplayProperties *apid) : api_(apid) {
151 apid->getInfo(width, height, color_depth, refresh_rate, name, area);
153 void Display::refreshInfo()
\r
155 api_->getInfo(width, height, color_depth, refresh_rate, name, area);
\r
163 } /* <- namespace Psycholops */