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 7069f7fd5c3951b9
parent 6935 b6b2829cd7ef
child 7291 91ad7b43317a
Fixed crash in Quartz gamma ramp code
src/video/quartz/SDL_QuartzVideo.m
     1.1 --- a/src/video/quartz/SDL_QuartzVideo.m	Wed Feb 27 15:20:31 2013 -0800
     1.2 +++ b/src/video/quartz/SDL_QuartzVideo.m	Wed Apr 17 00:56:53 2013 -0700
     1.3 @@ -1635,7 +1635,7 @@
     1.4  
     1.5  int QZ_SetGammaRamp (_THIS, Uint16 *ramp)
     1.6  {
     1.7 -    const uint32_t tableSize = 255;
     1.8 +    const uint32_t tableSize = 256;
     1.9      CGGammaValue redTable[tableSize];
    1.10      CGGammaValue greenTable[tableSize];
    1.11      CGGammaValue blueTable[tableSize];
    1.12 @@ -1644,13 +1644,13 @@
    1.13  
    1.14      /* Extract gamma values into separate tables, convert to floats between 0.0 and 1.0 */
    1.15      for (i = 0; i < 256; i++)
    1.16 -        redTable[i % 256] = ramp[i] / 65535.0;
    1.17 +        redTable[i % tableSize] = ramp[i] / 65535.0;
    1.18  
    1.19      for (i=256; i < 512; i++)
    1.20 -        greenTable[i % 256] = ramp[i] / 65535.0;
    1.21 +        greenTable[i % tableSize] = ramp[i] / 65535.0;
    1.22  
    1.23      for (i=512; i < 768; i++)
    1.24 -        blueTable[i % 256] = ramp[i] / 65535.0;
    1.25 +        blueTable[i % tableSize] = ramp[i] / 65535.0;
    1.26  
    1.27      if ( CGDisplayNoErr == CGSetDisplayTransferByTable
    1.28           (display_id, tableSize, redTable, greenTable, blueTable) )
    1.29 @@ -1661,7 +1661,7 @@
    1.30  
    1.31  int QZ_GetGammaRamp (_THIS, Uint16 *ramp)
    1.32  {
    1.33 -    const uint32_t tableSize = 255;
    1.34 +    const uint32_t tableSize = 256;
    1.35      CGGammaValue redTable[tableSize];
    1.36      CGGammaValue greenTable[tableSize];
    1.37      CGGammaValue blueTable[tableSize];
    1.38 @@ -1676,13 +1676,13 @@
    1.39  
    1.40      /* Pack tables into one array, with values from 0 to 65535 */
    1.41      for (i = 0; i < 256; i++)
    1.42 -        ramp[i] = redTable[i % 256] * 65535.0;
    1.43 +        ramp[i] = redTable[i % tableSize] * 65535.0;
    1.44  
    1.45      for (i=256; i < 512; i++)
    1.46 -        ramp[i] = greenTable[i % 256] * 65535.0;
    1.47 +        ramp[i] = greenTable[i % tableSize] * 65535.0;
    1.48  
    1.49      for (i=512; i < 768; i++)
    1.50 -        ramp[i] = blueTable[i % 256] * 65535.0;
    1.51 +        ramp[i] = blueTable[i % tableSize] * 65535.0;
    1.52  
    1.53      return 0;
    1.54  }