annotate src/video/SDL_gamma.c @ 4452:4011619aab7e

Updated Mac Xcode project for refactored rwops automated test changes.
author Eric Wing <ewing . public |-at-| gmail . com>
date Sun, 09 May 2010 07:00:28 -0700
parents f7b03b6838cb
children
rev   line source
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
3697
f7b03b6838cb Fixed bug #926
Sam Lantinga <slouken@libsdl.org>
parents: 3685
diff changeset
3 Copyright (C) 1997-2010 Sam Lantinga
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
4
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
6 modify it under the terms of the GNU Lesser General Public
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
9
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
13 Lesser General Public License for more details.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
14
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
15 You should have received a copy of the GNU Lesser General Public
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
16 License along with this library; if not, write to the Free Software
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
18
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
19 Sam Lantinga
252
e8157fcb3114 Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents: 152
diff changeset
20 slouken@libsdl.org
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
21 */
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
22 #include "SDL_config.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
23
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
24 /* Gamma correction support */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
25
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
26 #include "SDL_sysvideo.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
27
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
28
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
29 static void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
30 CalculateGammaRamp(float gamma, Uint16 * ramp)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
31 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
32 int i;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
33
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
34 /* 0.0 gamma is all black */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
35 if (gamma <= 0.0f) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
36 for (i = 0; i < 256; ++i) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
37 ramp[i] = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
38 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
39 return;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
40 } else
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
41 /* 1.0 gamma is identity */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
42 if (gamma == 1.0f) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
43 for (i = 0; i < 256; ++i) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
44 ramp[i] = (i << 8) | i;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
45 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
46 return;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
47 } else
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
48 /* Calculate a real gamma ramp */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
49 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
50 int value;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
51 gamma = 1.0f / gamma;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
52 for (i = 0; i < 256; ++i) {
3040
Sam Lantinga <slouken@libsdl.org>
parents: 3012
diff changeset
53 value =
Sam Lantinga <slouken@libsdl.org>
parents: 3012
diff changeset
54 (int) (SDL_pow((double) i / 256.0, gamma) * 65535.0 + 0.5);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
55 if (value > 65535) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
56 value = 65535;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
57 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
58 ramp[i] = (Uint16) value;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
59 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
60 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
61 }
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
62
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
63 static void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
64 CalculateGammaFromRamp(float *gamma, Uint16 * ramp)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
65 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
66 /* The following is adapted from a post by Garrett Bass on OpenGL
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
67 Gamedev list, March 4, 2000.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
68 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
69 float sum = 0.0f;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
70 int i, count = 0;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
71
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
72 *gamma = 1.0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
73 for (i = 1; i < 256; ++i) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
74 if ((ramp[i] != 0) && (ramp[i] != 65535)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
75 double B = (double) i / 256.0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
76 double A = ramp[i] / 65535.0;
3040
Sam Lantinga <slouken@libsdl.org>
parents: 3012
diff changeset
77 sum += (float) (SDL_log(A) / SDL_log(B));
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
78 count++;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
79 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
80 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
81 if (count && sum > 0.0f) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
82 *gamma = 1.0f / (sum / count);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
83 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
84 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
85
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
86 int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
87 SDL_SetGamma(float red, float green, float blue)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
88 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
89 Uint16 ramp[3][256];
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
90
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
91 CalculateGammaRamp(red, ramp[0]);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
92 CalculateGammaRamp(green, ramp[1]);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
93 CalculateGammaRamp(blue, ramp[2]);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
94
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
95 return SDL_SetGammaRamp(ramp[0], ramp[1], ramp[2]);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
96 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
97
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
98 /* Calculating the gamma by integrating the gamma ramps isn't exact,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
99 so this function isn't officially supported.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
100 */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
101 int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
102 SDL_GetGamma(float *red, float *green, float *blue)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
103 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
104 int succeeded;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
105 Uint16 ramp[3][256];
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
106
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
107 succeeded = SDL_GetGammaRamp(ramp[0], ramp[1], ramp[2]);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
108 if (succeeded >= 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
109 CalculateGammaFromRamp(red, ramp[0]);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
110 CalculateGammaFromRamp(green, ramp[1]);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
111 CalculateGammaFromRamp(blue, ramp[2]);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
112 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
113 return succeeded;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
114 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
115
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
116 static void
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
117 SDL_UninitializedVideo()
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
118 {
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
119 SDL_SetError("Video subsystem has not been initialized");
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
120 }
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
121
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
122 int
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
123 SDL_SetGammaRampForDisplay(SDL_VideoDisplay * display, const Uint16 * red, const Uint16 * green, const Uint16 * blue)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
124 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
125 SDL_VideoDevice *_this = SDL_GetVideoDevice();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
126 int succeeded;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
127
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
128 if (!_this) {
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
129 SDL_UninitializedVideo();
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
130 return -1;
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
131 }
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
132
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
133 /* Lazily allocate the gamma tables */
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
134 if (!display->gamma) {
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
135 if (SDL_GetGammaRampForDisplay(display, NULL, NULL, NULL) < 0) {
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
136 return -1;
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
137 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
138 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
139
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
140 /* Fill the gamma table with the new values */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
141 if (red) {
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
142 SDL_memcpy(&display->gamma[0 * 256], red, 256 * sizeof(*display->gamma));
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
143 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
144 if (green) {
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
145 SDL_memcpy(&display->gamma[1 * 256], green, 256 * sizeof(*display->gamma));
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
146 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
147 if (blue) {
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
148 SDL_memcpy(&display->gamma[2 * 256], blue, 256 * sizeof(*display->gamma));
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
149 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
150
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
151 /* Try to set the gamma ramp in the driver */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
152 succeeded = -1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
153 if (_this && _this->SetDisplayGammaRamp) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
154 if (SDL_GetFocusWindow()) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
155 succeeded =
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
156 _this->SetDisplayGammaRamp(_this, display, display->gamma);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
157 } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
158 succeeded = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
159 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
160 } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
161 SDL_SetError("Gamma ramp manipulation not supported");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
162 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
163 return succeeded;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
164 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
165
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
166 int
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
167 SDL_SetGammaRamp(const Uint16 * red, const Uint16 * green, const Uint16 * blue)
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
168 {
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
169 SDL_VideoDevice *_this = SDL_GetVideoDevice();
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
170 if (!_this) {
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
171 SDL_UninitializedVideo();
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
172 return -1;
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
173 }
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3500
diff changeset
174 return SDL_SetGammaRampForDisplay(SDL_CurrentDisplay, red, green, blue);
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
175 }
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
176
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
177 int
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
178 SDL_GetGammaRampForDisplay(SDL_VideoDisplay * display, Uint16 * red, Uint16 * green, Uint16 * blue)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
179 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
180 SDL_VideoDevice *_this = SDL_GetVideoDevice();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
181
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
182 if (!_this) {
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
183 SDL_UninitializedVideo();
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
184 return -1;
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
185 }
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
186
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
187 /* Lazily allocate the gamma table */
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
188 if (!display->gamma) {
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
189 size_t rampsize = (3 * 256 * sizeof(*display->gamma));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
190
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
191 display->gamma = SDL_malloc(rampsize * 2);
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
192 if (!display->gamma) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
193 SDL_OutOfMemory();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
194 return -1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
195 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
196 if (_this && _this->GetDisplayGammaRamp) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
197 /* Get the real hardware gamma */
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
198 _this->GetDisplayGammaRamp(_this, display, display->gamma);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
199 } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
200 /* Assume an identity gamma */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
201 int i;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
202 for (i = 0; i < 256; ++i) {
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
203 display->gamma[0 * 256 + i] = (i << 8) | i;
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
204 display->gamma[1 * 256 + i] = (i << 8) | i;
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
205 display->gamma[2 * 256 + i] = (i << 8) | i;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
206 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
207 }
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
208 display->saved_gamma = display->gamma + (3 * 256);
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
209 SDL_memcpy(display->saved_gamma, display->gamma, rampsize);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
210 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
211
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
212 /* Just copy from our internal table */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
213 if (red) {
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
214 SDL_memcpy(red, &display->gamma[0 * 256], 256 * sizeof(*red));
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
215 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
216 if (green) {
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
217 SDL_memcpy(green, &display->gamma[1 * 256], 256 * sizeof(*green));
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
218 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
219 if (blue) {
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
220 SDL_memcpy(blue, &display->gamma[2 * 256], 256 * sizeof(*blue));
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
221 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
222 return 0;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
223 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
224
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
225 int
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
226 SDL_GetGammaRamp(Uint16 * red, Uint16 * green, Uint16 * blue)
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
227 {
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
228 SDL_VideoDevice *_this = SDL_GetVideoDevice();
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
229 if (!_this) {
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
230 SDL_UninitializedVideo();
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
231 return -1;
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
232 }
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3500
diff changeset
233 return SDL_GetGammaRampForDisplay(SDL_CurrentDisplay, red, green, blue);
3500
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
234 }
4b594623401b Work in progress on multi-display support:
Sam Lantinga <slouken@libsdl.org>
parents: 3040
diff changeset
235
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1869
diff changeset
236 /* vi: set ts=4 sw=4 expandtab: */