Fixed crash in Quartz gamma ramp code SDL-1.2
authorSam Lantinga <slouken@libsdl.org>
Wed, 17 Apr 2013 00:56:53 -0700
branchSDL-1.2
changeset 7069 f7fd5c3951b9
parent 6935 b6b2829cd7ef
child 7291 91ad7b43317a
Fixed crash in Quartz gamma ramp code
src/video/quartz/SDL_QuartzVideo.m
--- a/src/video/quartz/SDL_QuartzVideo.m	Wed Feb 27 15:20:31 2013 -0800
+++ b/src/video/quartz/SDL_QuartzVideo.m	Wed Apr 17 00:56:53 2013 -0700
@@ -1635,7 +1635,7 @@
 
 int QZ_SetGammaRamp (_THIS, Uint16 *ramp)
 {
-    const uint32_t tableSize = 255;
+    const uint32_t tableSize = 256;
     CGGammaValue redTable[tableSize];
     CGGammaValue greenTable[tableSize];
     CGGammaValue blueTable[tableSize];
@@ -1644,13 +1644,13 @@
 
     /* Extract gamma values into separate tables, convert to floats between 0.0 and 1.0 */
     for (i = 0; i < 256; i++)
-        redTable[i % 256] = ramp[i] / 65535.0;
+        redTable[i % tableSize] = ramp[i] / 65535.0;
 
     for (i=256; i < 512; i++)
-        greenTable[i % 256] = ramp[i] / 65535.0;
+        greenTable[i % tableSize] = ramp[i] / 65535.0;
 
     for (i=512; i < 768; i++)
-        blueTable[i % 256] = ramp[i] / 65535.0;
+        blueTable[i % tableSize] = ramp[i] / 65535.0;
 
     if ( CGDisplayNoErr == CGSetDisplayTransferByTable
          (display_id, tableSize, redTable, greenTable, blueTable) )
@@ -1661,7 +1661,7 @@
 
 int QZ_GetGammaRamp (_THIS, Uint16 *ramp)
 {
-    const uint32_t tableSize = 255;
+    const uint32_t tableSize = 256;
     CGGammaValue redTable[tableSize];
     CGGammaValue greenTable[tableSize];
     CGGammaValue blueTable[tableSize];
@@ -1676,13 +1676,13 @@
 
     /* Pack tables into one array, with values from 0 to 65535 */
     for (i = 0; i < 256; i++)
-        ramp[i] = redTable[i % 256] * 65535.0;
+        ramp[i] = redTable[i % tableSize] * 65535.0;
 
     for (i=256; i < 512; i++)
-        ramp[i] = greenTable[i % 256] * 65535.0;
+        ramp[i] = greenTable[i % tableSize] * 65535.0;
 
     for (i=512; i < 768; i++)
-        ramp[i] = blueTable[i % 256] * 65535.0;
+        ramp[i] = blueTable[i % tableSize] * 65535.0;
 
     return 0;
 }