1 //========================================================================
2 // GLFW 3.0 Win32 - www.glfw.org
3 //------------------------------------------------------------------------
4 // Copyright (c) 2010 Camilla Berglund <elmindreda@elmindreda.org>
5 //
6 // This software is provided 'as-is', without any express or implied
7 // warranty. In no event will the authors be held liable for any damages
8 // arising from the use of this software.
9 //
10 // Permission is granted to anyone to use this software for any purpose,
11 // including commercial applications, and to alter it and redistribute it
12 // freely, subject to the following restrictions:
13 //
14 // 1. The origin of this software must not be misrepresented; you must not
15 // claim that you wrote the original software. If you use this software
16 // in a product, an acknowledgment in the product documentation would
17 // be appreciated but is not required.
18 //
19 // 2. Altered source versions must be plainly marked as such, and must not
20 // be misrepresented as being the original software.
21 //
22 // 3. This notice may not be removed or altered from any source
23 // distribution.
24 //
25 //========================================================================
26
27 #include "internal.h"
28
29 #include <limits.h>
30
31
32 //////////////////////////////////////////////////////////////////////////
33 ////// GLFW platform API //////
34 //////////////////////////////////////////////////////////////////////////
35
_glfwPlatformGetGammaRamp(_GLFWmonitor * monitor,GLFWgammaramp * ramp)36 void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp)
37 {
38 HDC dc;
39 WORD values[768];
40 DISPLAY_DEVICE display;
41
42 ZeroMemory(&display, sizeof(DISPLAY_DEVICE));
43 display.cb = sizeof(DISPLAY_DEVICE);
44 EnumDisplayDevices(monitor->win32.name, 0, &display, 0);
45
46 dc = CreateDC(L"DISPLAY", display.DeviceString, NULL, NULL);
47 GetDeviceGammaRamp(dc, values);
48 DeleteDC(dc);
49
50 _glfwAllocGammaArrays(ramp, 256);
51
52 memcpy(ramp->red, values + 0, 256 * sizeof(unsigned short));
53 memcpy(ramp->green, values + 256, 256 * sizeof(unsigned short));
54 memcpy(ramp->blue, values + 512, 256 * sizeof(unsigned short));
55 }
56
_glfwPlatformSetGammaRamp(_GLFWmonitor * monitor,const GLFWgammaramp * ramp)57 void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp)
58 {
59 HDC dc;
60 WORD values[768];
61 DISPLAY_DEVICE display;
62
63 if (ramp->size != 256)
64 {
65 _glfwInputError(GLFW_PLATFORM_ERROR,
66 "Win32: Gamma ramp size must be 256");
67 return;
68 }
69
70 memcpy(values + 0, ramp->red, 256 * sizeof(unsigned short));
71 memcpy(values + 256, ramp->green, 256 * sizeof(unsigned short));
72 memcpy(values + 512, ramp->blue, 256 * sizeof(unsigned short));
73
74 ZeroMemory(&display, sizeof(DISPLAY_DEVICE));
75 display.cb = sizeof(DISPLAY_DEVICE);
76 EnumDisplayDevices(monitor->win32.name, 0, &display, 0);
77
78 dc = CreateDC(L"DISPLAY", display.DeviceString, NULL, NULL);
79 SetDeviceGammaRamp(dc, values);
80 DeleteDC(dc);
81 }
82
83