Added SDL_BLENDMODE_BLEND_PREMULTIPLIED and SDL_BLENDMODE_ADD_PREMULTIPLIED
Fixes https://github.com/libsdl-org/SDL/issues/2485
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -26,8 +26,10 @@ typedef struct SDLTest_SurfaceImage_s {
|
||||
SDL_Surface *SDLTest_ImageBlit(void);
|
||||
SDL_Surface *SDLTest_ImageBlitColor(void);
|
||||
SDL_Surface *SDLTest_ImageBlitAlpha(void);
|
||||
SDL_Surface *SDLTest_ImageBlitBlendAdd(void);
|
||||
SDL_Surface *SDLTest_ImageBlitBlend(void);
|
||||
SDL_Surface *SDLTest_ImageBlitBlendPremultiplied(void);
|
||||
SDL_Surface *SDLTest_ImageBlitBlendAdd(void);
|
||||
SDL_Surface *SDLTest_ImageBlitBlendAddPremultiplied(void);
|
||||
SDL_Surface *SDLTest_ImageBlitBlendMod(void);
|
||||
SDL_Surface *SDLTest_ImageBlitBlendNone(void);
|
||||
SDL_Surface *SDLTest_ImageBlitBlendAll(void);
|
||||
|
||||
@@ -702,6 +702,17 @@ static int render_testBlitBlend(void *arg)
|
||||
SDL_DestroySurface(referenceSurface);
|
||||
referenceSurface = NULL;
|
||||
|
||||
/* Test Blend Premultiplied. */
|
||||
testBlitBlendMode(tface, SDL_BLENDMODE_BLEND_PREMULTIPLIED);
|
||||
referenceSurface = SDLTest_ImageBlitBlendPremultiplied();
|
||||
|
||||
/* Compare, then Present */
|
||||
compare(referenceSurface, ALLOWABLE_ERROR_BLENDED);
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
SDL_DestroySurface(referenceSurface);
|
||||
referenceSurface = NULL;
|
||||
|
||||
/* Test Add. */
|
||||
testBlitBlendMode(tface, SDL_BLENDMODE_ADD);
|
||||
referenceSurface = SDLTest_ImageBlitBlendAdd();
|
||||
@@ -713,6 +724,17 @@ static int render_testBlitBlend(void *arg)
|
||||
SDL_DestroySurface(referenceSurface);
|
||||
referenceSurface = NULL;
|
||||
|
||||
/* Test Add Premultiplied. */
|
||||
testBlitBlendMode(tface, SDL_BLENDMODE_ADD_PREMULTIPLIED);
|
||||
referenceSurface = SDLTest_ImageBlitBlendAddPremultiplied();
|
||||
|
||||
/* Compare, then Present */
|
||||
compare(referenceSurface, ALLOWABLE_ERROR_BLENDED);
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
SDL_DestroySurface(referenceSurface);
|
||||
referenceSurface = NULL;
|
||||
|
||||
/* Test Mod. */
|
||||
testBlitBlendMode(tface, SDL_BLENDMODE_MOD);
|
||||
referenceSurface = SDLTest_ImageBlitBlendMod();
|
||||
@@ -1154,6 +1176,15 @@ hasBlendModes(void)
|
||||
if (!isSupported(ret)) {
|
||||
fail = 1;
|
||||
}
|
||||
ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND_PREMULTIPLIED );
|
||||
if (!isSupported(ret))
|
||||
fail = 1;
|
||||
ret = SDL_GetRenderDrawBlendMode(renderer, &mode );
|
||||
if (!isSupported(ret))
|
||||
fail = 1;
|
||||
ret = (mode != SDL_BLENDMODE_BLEND_PREMULTIPLIED);
|
||||
if (!isSupported(ret))
|
||||
fail = 1;
|
||||
ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_ADD);
|
||||
if (!isSupported(ret)) {
|
||||
fail = 1;
|
||||
@@ -1166,6 +1197,18 @@ hasBlendModes(void)
|
||||
if (!isSupported(ret)) {
|
||||
fail = 1;
|
||||
}
|
||||
ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_ADD_PREMULTIPLIED);
|
||||
if (!isSupported(ret)) {
|
||||
fail = 1;
|
||||
}
|
||||
ret = SDL_GetRenderDrawBlendMode(renderer, &mode);
|
||||
if (!isSupported(ret)) {
|
||||
fail = 1;
|
||||
}
|
||||
ret = (mode != SDL_BLENDMODE_ADD_PREMULTIPLIED);
|
||||
if (!isSupported(ret)) {
|
||||
fail = 1;
|
||||
}
|
||||
ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_MOD);
|
||||
if (!isSupported(ret)) {
|
||||
fail = 1;
|
||||
|
||||
@@ -523,6 +523,28 @@ static int surface_testBlitBlendBlend(void *arg)
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tests some more blitting routines.
|
||||
*/
|
||||
static int surface_testBlitBlendPremultiplied(void *arg)
|
||||
{
|
||||
int ret;
|
||||
SDL_Surface *compareSurface;
|
||||
|
||||
/* Blend premultiplied blitting */
|
||||
testBlitBlendMode(SDL_BLENDMODE_BLEND_PREMULTIPLIED);
|
||||
|
||||
/* Verify result by comparing surfaces */
|
||||
compareSurface = SDLTest_ImageBlitBlendPremultiplied();
|
||||
ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
|
||||
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
|
||||
|
||||
/* Clean up. */
|
||||
SDL_DestroySurface(compareSurface);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests some more blitting routines.
|
||||
*/
|
||||
@@ -545,6 +567,28 @@ static int surface_testBlitBlendAdd(void *arg)
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests some more blitting routines.
|
||||
*/
|
||||
static int surface_testBlitBlendAddPremultiplied(void *arg)
|
||||
{
|
||||
int ret;
|
||||
SDL_Surface *compareSurface;
|
||||
|
||||
/* Add blitting */
|
||||
testBlitBlendMode(SDL_BLENDMODE_ADD_PREMULTIPLIED);
|
||||
|
||||
/* Verify result by comparing surfaces */
|
||||
compareSurface = SDLTest_ImageBlitBlendAddPremultiplied();
|
||||
ret = SDLTest_CompareSurfaces(testSurface, compareSurface, 0);
|
||||
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
|
||||
|
||||
/* Clean up. */
|
||||
SDL_DestroySurface(compareSurface);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests some more blitting routines.
|
||||
*/
|
||||
@@ -958,10 +1002,20 @@ static const SDLTest_TestCaseReference surfaceTest10 = {
|
||||
|
||||
/* TODO: rewrite test case, define new test data and re-enable; current implementation fails */
|
||||
static const SDLTest_TestCaseReference surfaceTest11 = {
|
||||
(SDLTest_TestCaseFp)surface_testBlitBlendPremultiplied, "surface_testBlitBlendPremultiplied", "Tests blitting routines with premultiplied blending mode.", TEST_DISABLED
|
||||
};
|
||||
|
||||
/* TODO: rewrite test case, define new test data and re-enable; current implementation fails */
|
||||
static const SDLTest_TestCaseReference surfaceTest12 = {
|
||||
(SDLTest_TestCaseFp)surface_testBlitBlendAdd, "surface_testBlitBlendAdd", "Tests blitting routines with add blending mode.", TEST_DISABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference surfaceTest12 = {
|
||||
/* TODO: rewrite test case, define new test data and re-enable; current implementation fails */
|
||||
static const SDLTest_TestCaseReference surfaceTest13 = {
|
||||
(SDLTest_TestCaseFp)surface_testBlitBlendAddPremultiplied, "surface_testBlitBlendAddPremultiplied", "Tests blitting routines with premultiplied add blending mode.", TEST_DISABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference surfaceTest14 = {
|
||||
(SDLTest_TestCaseFp)surface_testBlitBlendMod, "surface_testBlitBlendMod", "Tests blitting routines with mod blending mode.", TEST_ENABLED
|
||||
};
|
||||
|
||||
@@ -981,8 +1035,8 @@ static const SDLTest_TestCaseReference surfaceTestPalette = {
|
||||
static const SDLTest_TestCaseReference *surfaceTests[] = {
|
||||
&surfaceTest1, &surfaceTest2, &surfaceTest3, &surfaceTest4, &surfaceTest5,
|
||||
&surfaceTest6, &surfaceTest7, &surfaceTest8, &surfaceTest9, &surfaceTest10,
|
||||
&surfaceTest11, &surfaceTest12, &surfaceTestOverflow, &surfaceTestFlip,
|
||||
&surfaceTestPalette, NULL
|
||||
&surfaceTest11, &surfaceTest12, &surfaceTest13, &surfaceTest14,
|
||||
&surfaceTestOverflow, &surfaceTestFlip, &surfaceTestPalette, NULL
|
||||
};
|
||||
|
||||
/* Surface test suite (global) */
|
||||
|
||||
@@ -243,9 +243,15 @@ int main(int argc, char *argv[])
|
||||
} else if (SDL_strcasecmp(argv[i + 1], "blend") == 0) {
|
||||
blendMode = SDL_BLENDMODE_BLEND;
|
||||
consumed = 2;
|
||||
} else if (SDL_strcasecmp(argv[i + 1], "blend_premultiplied") == 0) {
|
||||
blendMode = SDL_BLENDMODE_BLEND_PREMULTIPLIED;
|
||||
consumed = 2;
|
||||
} else if (SDL_strcasecmp(argv[i + 1], "add") == 0) {
|
||||
blendMode = SDL_BLENDMODE_ADD;
|
||||
consumed = 2;
|
||||
} else if (SDL_strcasecmp(argv[i + 1], "add_premultiplied") == 0) {
|
||||
blendMode = SDL_BLENDMODE_ADD_PREMULTIPLIED;
|
||||
consumed = 2;
|
||||
} else if (SDL_strcasecmp(argv[i + 1], "mod") == 0) {
|
||||
blendMode = SDL_BLENDMODE_MOD;
|
||||
consumed = 2;
|
||||
@@ -267,7 +273,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
if (consumed < 0) {
|
||||
static const char *options[] = {
|
||||
"[--blend none|blend|add|mod|mul]",
|
||||
"[--blend none|blend|blend_premultiplied|add|add_premultiplied|mod|mul]",
|
||||
"[--cyclecolor]",
|
||||
"[--cyclealpha]",
|
||||
"[num_objects]",
|
||||
|
||||
@@ -312,9 +312,15 @@ int main(int argc, char *argv[])
|
||||
} else if (SDL_strcasecmp(argv[i + 1], "blend") == 0) {
|
||||
blendMode = SDL_BLENDMODE_BLEND;
|
||||
consumed = 2;
|
||||
} else if (SDL_strcasecmp(argv[i + 1], "blend_premultiplied") == 0) {
|
||||
blendMode = SDL_BLENDMODE_BLEND_PREMULTIPLIED;
|
||||
consumed = 2;
|
||||
} else if (SDL_strcasecmp(argv[i + 1], "add") == 0) {
|
||||
blendMode = SDL_BLENDMODE_ADD;
|
||||
consumed = 2;
|
||||
} else if (SDL_strcasecmp(argv[i + 1], "add_premultiplied") == 0) {
|
||||
blendMode = SDL_BLENDMODE_ADD_PREMULTIPLIED;
|
||||
consumed = 2;
|
||||
} else if (SDL_strcasecmp(argv[i + 1], "mod") == 0) {
|
||||
blendMode = SDL_BLENDMODE_MOD;
|
||||
consumed = 2;
|
||||
@@ -338,7 +344,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
if (consumed < 0) {
|
||||
static const char *options[] = { "[--blend none|blend|add|mod|mul]", "[--cyclecolor]", "[--cyclealpha]", "[count]", NULL };
|
||||
static const char *options[] = { "[--blend none|blend|blend_premultiplied|add|add_premultiplied|mod|mul]", "[--cyclecolor]", "[--cyclealpha]", "[count]", NULL };
|
||||
SDLTest_CommonLogUsage(state, argv[0], options);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -451,9 +451,15 @@ int SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
} else if (SDL_strcasecmp(argv[i + 1], "blend") == 0) {
|
||||
blendMode = SDL_BLENDMODE_BLEND;
|
||||
consumed = 2;
|
||||
} else if (SDL_strcasecmp(argv[i + 1], "blend_premultiplied") == 0) {
|
||||
blendMode = SDL_BLENDMODE_BLEND_PREMULTIPLIED;
|
||||
consumed = 2;
|
||||
} else if (SDL_strcasecmp(argv[i + 1], "add") == 0) {
|
||||
blendMode = SDL_BLENDMODE_ADD;
|
||||
consumed = 2;
|
||||
} else if (SDL_strcasecmp(argv[i + 1], "add_premultiplied") == 0) {
|
||||
blendMode = SDL_BLENDMODE_ADD_PREMULTIPLIED;
|
||||
consumed = 2;
|
||||
} else if (SDL_strcasecmp(argv[i + 1], "mod") == 0) {
|
||||
blendMode = SDL_BLENDMODE_MOD;
|
||||
consumed = 2;
|
||||
@@ -506,7 +512,7 @@ int SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
}
|
||||
if (consumed < 0) {
|
||||
static const char *options[] = {
|
||||
"[--blend none|blend|add|mod|mul|sub]",
|
||||
"[--blend none|blend|blend_premultiplied|add|add_premultiplied|mod|mul|sub]",
|
||||
"[--cyclecolor]",
|
||||
"[--cyclealpha]",
|
||||
"[--suspend-when-occluded]",
|
||||
|
||||
Reference in New Issue
Block a user