mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-05-20 11:48:29 +00:00
Remove SDL_CalculateGammaRamp.
This commit is contained in:
parent
52f4cc843d
commit
ac8fbb7040
6 changed files with 5 additions and 160 deletions
|
@ -4,6 +4,10 @@ This guide provides useful information for migrating applications from SDL 2.0 t
|
||||||
|
|
||||||
We have provided a handy Python script to automate some of this work for you [link to script], and details on the changes are organized by SDL 2.0 header below.
|
We have provided a handy Python script to automate some of this work for you [link to script], and details on the changes are organized by SDL 2.0 header below.
|
||||||
|
|
||||||
|
## SDL_pixels.h
|
||||||
|
|
||||||
|
SDL_CalculateGammaRamp has been removed, because SDL_SetWindowGammaRamp has been removed as well due to poor support in modern operating systems (see [SDL_video.h](#sdl_videoh)).
|
||||||
|
|
||||||
## SDL_rwops.h
|
## SDL_rwops.h
|
||||||
|
|
||||||
SDL_RWFromFP has been removed from the API, due to issues when the SDL library uses a different C runtime from the application.
|
SDL_RWFromFP has been removed from the API, due to issues when the SDL library uses a different C runtime from the application.
|
||||||
|
|
|
@ -620,16 +620,6 @@ extern DECLSPEC void SDLCALL SDL_GetRGBA(Uint32 pixel,
|
||||||
Uint8 * r, Uint8 * g, Uint8 * b,
|
Uint8 * r, Uint8 * g, Uint8 * b,
|
||||||
Uint8 * a);
|
Uint8 * a);
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculate a 256 entry gamma ramp for a gamma value.
|
|
||||||
*
|
|
||||||
* \param gamma a gamma value where 0.0 is black and 1.0 is identity
|
|
||||||
* \param ramp an array of 256 values filled in with the gamma ramp
|
|
||||||
*
|
|
||||||
* \since This function is available since SDL 3.0.0.
|
|
||||||
*/
|
|
||||||
extern DECLSPEC void SDLCALL SDL_CalculateGammaRamp(float gamma, Uint16 * ramp);
|
|
||||||
|
|
||||||
|
|
||||||
/* Ends C function definitions when using C++ */
|
/* Ends C function definitions when using C++ */
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -286,7 +286,6 @@
|
||||||
#define SDL_MapRGBA SDL_MapRGBA_REAL
|
#define SDL_MapRGBA SDL_MapRGBA_REAL
|
||||||
#define SDL_GetRGB SDL_GetRGB_REAL
|
#define SDL_GetRGB SDL_GetRGB_REAL
|
||||||
#define SDL_GetRGBA SDL_GetRGBA_REAL
|
#define SDL_GetRGBA SDL_GetRGBA_REAL
|
||||||
#define SDL_CalculateGammaRamp SDL_CalculateGammaRamp_REAL
|
|
||||||
#define SDL_GetPlatform SDL_GetPlatform_REAL
|
#define SDL_GetPlatform SDL_GetPlatform_REAL
|
||||||
#define SDL_GetPowerInfo SDL_GetPowerInfo_REAL
|
#define SDL_GetPowerInfo SDL_GetPowerInfo_REAL
|
||||||
#define SDL_HasIntersection SDL_HasIntersection_REAL
|
#define SDL_HasIntersection SDL_HasIntersection_REAL
|
||||||
|
|
|
@ -313,7 +313,6 @@ SDL_DYNAPI_PROC(Uint32,SDL_MapRGB,(const SDL_PixelFormat *a, Uint8 b, Uint8 c, U
|
||||||
SDL_DYNAPI_PROC(Uint32,SDL_MapRGBA,(const SDL_PixelFormat *a, Uint8 b, Uint8 c, Uint8 d, Uint8 e),(a,b,c,d,e),return)
|
SDL_DYNAPI_PROC(Uint32,SDL_MapRGBA,(const SDL_PixelFormat *a, Uint8 b, Uint8 c, Uint8 d, Uint8 e),(a,b,c,d,e),return)
|
||||||
SDL_DYNAPI_PROC(void,SDL_GetRGB,(Uint32 a, const SDL_PixelFormat *b, Uint8 *c, Uint8 *d, Uint8 *e),(a,b,c,d,e),)
|
SDL_DYNAPI_PROC(void,SDL_GetRGB,(Uint32 a, const SDL_PixelFormat *b, Uint8 *c, Uint8 *d, Uint8 *e),(a,b,c,d,e),)
|
||||||
SDL_DYNAPI_PROC(void,SDL_GetRGBA,(Uint32 a, const SDL_PixelFormat *b, Uint8 *c, Uint8 *d, Uint8 *e, Uint8 *f),(a,b,c,d,e,f),)
|
SDL_DYNAPI_PROC(void,SDL_GetRGBA,(Uint32 a, const SDL_PixelFormat *b, Uint8 *c, Uint8 *d, Uint8 *e, Uint8 *f),(a,b,c,d,e,f),)
|
||||||
SDL_DYNAPI_PROC(void,SDL_CalculateGammaRamp,(float a, Uint16 *b),(a,b),)
|
|
||||||
SDL_DYNAPI_PROC(const char*,SDL_GetPlatform,(void),(),return)
|
SDL_DYNAPI_PROC(const char*,SDL_GetPlatform,(void),(),return)
|
||||||
SDL_DYNAPI_PROC(SDL_PowerState,SDL_GetPowerInfo,(int *a, int *b),(a,b),return)
|
SDL_DYNAPI_PROC(SDL_PowerState,SDL_GetPowerInfo,(int *a, int *b),(a,b),return)
|
||||||
SDL_DYNAPI_PROC(SDL_bool,SDL_HasIntersection,(const SDL_Rect *a, const SDL_Rect *b),(a,b),return)
|
SDL_DYNAPI_PROC(SDL_bool,SDL_HasIntersection,(const SDL_Rect *a, const SDL_Rect *b),(a,b),return)
|
||||||
|
|
|
@ -1150,44 +1150,4 @@ SDL_FreeBlitMap(SDL_BlitMap * map)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
SDL_CalculateGammaRamp(float gamma, Uint16 * ramp)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
/* Input validation */
|
|
||||||
if (gamma < 0.0f ) {
|
|
||||||
SDL_InvalidParamError("gamma");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (ramp == NULL) {
|
|
||||||
SDL_InvalidParamError("ramp");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 0.0 gamma is all black */
|
|
||||||
if (gamma == 0.0f) {
|
|
||||||
SDL_memset(ramp, 0, 256 * sizeof(Uint16));
|
|
||||||
return;
|
|
||||||
} else if (gamma == 1.0f) {
|
|
||||||
/* 1.0 gamma is identity */
|
|
||||||
for (i = 0; i < 256; ++i) {
|
|
||||||
ramp[i] = (i << 8) | i;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
/* Calculate a real gamma ramp */
|
|
||||||
int value;
|
|
||||||
gamma = 1.0f / gamma;
|
|
||||||
for (i = 0; i < 256; ++i) {
|
|
||||||
value =
|
|
||||||
(int) (SDL_pow((double) i / 256.0, gamma) * 65535.0 + 0.5);
|
|
||||||
if (value > 65535) {
|
|
||||||
value = 65535;
|
|
||||||
}
|
|
||||||
ramp[i] = (Uint16) value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* vi: set ts=4 sw=4 expandtab: */
|
/* vi: set ts=4 sw=4 expandtab: */
|
||||||
|
|
|
@ -400,110 +400,6 @@ pixels_allocFreePalette(void *arg)
|
||||||
return TEST_COMPLETED;
|
return TEST_COMPLETED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Call to SDL_CalculateGammaRamp
|
|
||||||
*
|
|
||||||
* @sa http://wiki.libsdl.org/SDL_CalculateGammaRamp
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
pixels_calcGammaRamp(void *arg)
|
|
||||||
{
|
|
||||||
const char *expectedError1 = "Parameter 'gamma' is invalid";
|
|
||||||
const char *expectedError2 = "Parameter 'ramp' is invalid";
|
|
||||||
const char *error;
|
|
||||||
float gamma;
|
|
||||||
Uint16 *ramp;
|
|
||||||
int variation;
|
|
||||||
int i;
|
|
||||||
int changed;
|
|
||||||
Uint16 magic = 0xbeef;
|
|
||||||
|
|
||||||
/* Allocate temp ramp array and fill with some value */
|
|
||||||
ramp = (Uint16 *)SDL_malloc(256 * sizeof(Uint16));
|
|
||||||
SDLTest_AssertCheck(ramp != NULL, "Validate temp ramp array could be allocated");
|
|
||||||
if (ramp == NULL) return TEST_ABORTED;
|
|
||||||
|
|
||||||
/* Make call with different gamma values */
|
|
||||||
for (variation = 0; variation < 4; variation++) {
|
|
||||||
switch (variation) {
|
|
||||||
/* gamma = 0 all black */
|
|
||||||
default:
|
|
||||||
case 0:
|
|
||||||
gamma = 0.0f;
|
|
||||||
break;
|
|
||||||
/* gamma = 1 identity */
|
|
||||||
case 1:
|
|
||||||
gamma = 1.0f;
|
|
||||||
break;
|
|
||||||
/* gamma = [0.2,0.8] normal range */
|
|
||||||
case 2:
|
|
||||||
gamma = 0.2f + 0.8f * SDLTest_RandomUnitFloat();
|
|
||||||
break;
|
|
||||||
/* gamma = >1.1 non-standard range */
|
|
||||||
case 3:
|
|
||||||
gamma = 1.1f + SDLTest_RandomUnitFloat();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Make call and check that values were updated */
|
|
||||||
for (i = 0; i < 256; i++) ramp[i] = magic;
|
|
||||||
SDL_CalculateGammaRamp(gamma, ramp);
|
|
||||||
SDLTest_AssertPass("Call to SDL_CalculateGammaRamp(%f)", gamma);
|
|
||||||
changed = 0;
|
|
||||||
for (i = 0; i < 256; i++) if (ramp[i] != magic) changed++;
|
|
||||||
SDLTest_AssertCheck(changed > 250, "Validate that ramp was calculated; expected: >250 values changed, got: %d values changed", changed);
|
|
||||||
|
|
||||||
/* Additional value checks for some cases */
|
|
||||||
i = SDLTest_RandomIntegerInRange(64,192);
|
|
||||||
switch (variation) {
|
|
||||||
case 0:
|
|
||||||
SDLTest_AssertCheck(ramp[i] == 0, "Validate value at position %d; expected: 0, got: %d", i, ramp[i]);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
SDLTest_AssertCheck(ramp[i] == ((i << 8) | i), "Validate value at position %d; expected: %d, got: %d", i, (i << 8) | i, ramp[i]);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
case 3:
|
|
||||||
SDLTest_AssertCheck(ramp[i] > 0, "Validate value at position %d; expected: >0, got: %d", i, ramp[i]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Negative cases */
|
|
||||||
SDL_ClearError();
|
|
||||||
SDLTest_AssertPass("Call to SDL_ClearError()");
|
|
||||||
gamma = -1;
|
|
||||||
for (i=0; i<256; i++) ramp[i] = magic;
|
|
||||||
SDL_CalculateGammaRamp(gamma, ramp);
|
|
||||||
SDLTest_AssertPass("Call to SDL_CalculateGammaRamp(%f)", gamma);
|
|
||||||
error = SDL_GetError();
|
|
||||||
SDLTest_AssertPass("Call to SDL_GetError()");
|
|
||||||
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
|
|
||||||
if (error != NULL) {
|
|
||||||
SDLTest_AssertCheck(SDL_strcmp(error, expectedError1) == 0,
|
|
||||||
"Validate error message, expected: '%s', got: '%s'", expectedError1, error);
|
|
||||||
}
|
|
||||||
changed = 0;
|
|
||||||
for (i = 0; i < 256; i++) if (ramp[i] != magic) changed++;
|
|
||||||
SDLTest_AssertCheck(changed ==0, "Validate that ramp unchanged; expected: 0 values changed got: %d values changed", changed);
|
|
||||||
|
|
||||||
SDL_CalculateGammaRamp(0.5f, NULL);
|
|
||||||
SDLTest_AssertPass("Call to SDL_CalculateGammaRamp(0.5,NULL)");
|
|
||||||
error = SDL_GetError();
|
|
||||||
SDLTest_AssertPass("Call to SDL_GetError()");
|
|
||||||
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
|
|
||||||
if (error != NULL) {
|
|
||||||
SDLTest_AssertCheck(SDL_strcmp(error, expectedError2) == 0,
|
|
||||||
"Validate error message, expected: '%s', got: '%s'", expectedError2, error);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Cleanup */
|
|
||||||
SDL_free(ramp);
|
|
||||||
|
|
||||||
|
|
||||||
return TEST_COMPLETED;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ================= Test References ================== */
|
/* ================= Test References ================== */
|
||||||
|
|
||||||
/* Pixels test cases */
|
/* Pixels test cases */
|
||||||
|
@ -514,14 +410,11 @@ static const SDLTest_TestCaseReference pixelsTest2 =
|
||||||
{ (SDLTest_TestCaseFp)pixels_allocFreePalette, "pixels_allocFreePalette", "Call to SDL_AllocPalette and SDL_FreePalette", TEST_ENABLED };
|
{ (SDLTest_TestCaseFp)pixels_allocFreePalette, "pixels_allocFreePalette", "Call to SDL_AllocPalette and SDL_FreePalette", TEST_ENABLED };
|
||||||
|
|
||||||
static const SDLTest_TestCaseReference pixelsTest3 =
|
static const SDLTest_TestCaseReference pixelsTest3 =
|
||||||
{ (SDLTest_TestCaseFp)pixels_calcGammaRamp, "pixels_calcGammaRamp", "Call to SDL_CalculateGammaRamp", TEST_ENABLED };
|
|
||||||
|
|
||||||
static const SDLTest_TestCaseReference pixelsTest4 =
|
|
||||||
{ (SDLTest_TestCaseFp)pixels_getPixelFormatName, "pixels_getPixelFormatName", "Call to SDL_GetPixelFormatName", TEST_ENABLED };
|
{ (SDLTest_TestCaseFp)pixels_getPixelFormatName, "pixels_getPixelFormatName", "Call to SDL_GetPixelFormatName", TEST_ENABLED };
|
||||||
|
|
||||||
/* Sequence of Pixels test cases */
|
/* Sequence of Pixels test cases */
|
||||||
static const SDLTest_TestCaseReference *pixelsTests[] = {
|
static const SDLTest_TestCaseReference *pixelsTests[] = {
|
||||||
&pixelsTest1, &pixelsTest2, &pixelsTest3, &pixelsTest4, NULL
|
&pixelsTest1, &pixelsTest2, &pixelsTest3, NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Pixels test suite (global) */
|
/* Pixels test suite (global) */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue