Remove depth field from SDL_CreateRGBSurfaceWithFormat and SDL_Create… (#6685)

* Remove depth field from SDL_CreateRGBSurfaceWithFormat and SDL_CreateRGBSurfaceWithFormatFrom
* Removed unused 'flags' parameter from SDL_CreateRGBSurface and SDL_CreateRGBSurfaceWithFormat
* Removed unused 'flags' parameter from SDL_ConvertSurface and SDL_ConvertSurfaceFormat
This commit is contained in:
Sylvain Becker
2022-11-29 18:40:09 +01:00
committed by GitHub
parent 6873082c34
commit fc4fc5295f
30 changed files with 95 additions and 109 deletions

View File

@@ -55,7 +55,7 @@ _surfaceSetUp(void *arg)
#endif
referenceSurface = SDLTest_ImageBlit(); /* For size info */
testSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, referenceSurface->w, referenceSurface->h, 32, rmask, gmask, bmask, amask);
testSurface = SDL_CreateRGBSurface(referenceSurface->w, referenceSurface->h, 32, rmask, gmask, bmask, amask);
SDLTest_AssertCheck(testSurface != NULL, "Check that testSurface is not NULL");
if (testSurface != NULL) {
/* Disable blend mode for target surface */
@@ -299,7 +299,7 @@ surface_testSurfaceConversion(void *arg)
}
/* Convert to 32 bit to compare. */
rface = SDL_ConvertSurface( face, testSurface->format, 0 );
rface = SDL_ConvertSurface( face, testSurface->format);
SDLTest_AssertPass("Call to SDL_ConvertSurface()");
SDLTest_AssertCheck(rface != NULL, "Verify result from SDL_ConvertSurface is not NULL");
@@ -374,19 +374,19 @@ surface_testCompleteSurfaceConversion(void *arg)
for ( j = 0; j < SDL_arraysize(pixel_formats); ++j ) {
fmt1 = SDL_AllocFormat(pixel_formats[i]);
SDL_assert(fmt1 != NULL);
cvt1 = SDL_ConvertSurface(face, fmt1, 0);
cvt1 = SDL_ConvertSurface(face, fmt1);
SDL_assert(cvt1 != NULL);
fmt2 = SDL_AllocFormat(pixel_formats[j]);
SDL_assert(fmt1 != NULL);
cvt2 = SDL_ConvertSurface(cvt1, fmt2, 0);
cvt2 = SDL_ConvertSurface(cvt1, fmt2);
SDL_assert(cvt2 != NULL);
if ( fmt1->BytesPerPixel == face->format->BytesPerPixel &&
fmt2->BytesPerPixel == face->format->BytesPerPixel &&
(fmt1->Amask != 0) == (face->format->Amask != 0) &&
(fmt2->Amask != 0) == (face->format->Amask != 0) ) {
final = SDL_ConvertSurface( cvt2, face->format, 0 );
final = SDL_ConvertSurface( cvt2, face->format);
SDL_assert(final != NULL);
/* Compare surface. */
@@ -617,11 +617,11 @@ surface_testOverflow(void *arg)
SDL_memset(buf, '\0', sizeof(buf));
expectedError = "Parameter 'width' is invalid";
surface = SDL_CreateRGBSurfaceWithFormat(0, -3, 100, 8, SDL_PIXELFORMAT_INDEX8);
surface = SDL_CreateRGBSurfaceWithFormat(-3, 100, SDL_PIXELFORMAT_INDEX8);
SDLTest_AssertCheck(surface == NULL, "Should detect negative width");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, -1, 1, 8, 4, SDL_PIXELFORMAT_INDEX8);
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, -1, 1, 4, SDL_PIXELFORMAT_INDEX8);
SDLTest_AssertCheck(surface == NULL, "Should detect negative width");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
@@ -631,11 +631,11 @@ surface_testOverflow(void *arg)
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
expectedError = "Parameter 'height' is invalid";
surface = SDL_CreateRGBSurfaceWithFormat(0, 100, -3, 8, SDL_PIXELFORMAT_INDEX8);
surface = SDL_CreateRGBSurfaceWithFormat(100, -3, SDL_PIXELFORMAT_INDEX8);
SDLTest_AssertCheck(surface == NULL, "Should detect negative height");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 1, -1, 8, 4, SDL_PIXELFORMAT_INDEX8);
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 1, -1, 4, SDL_PIXELFORMAT_INDEX8);
SDLTest_AssertCheck(surface == NULL, "Should detect negative height");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
@@ -645,7 +645,7 @@ surface_testOverflow(void *arg)
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
expectedError = "Parameter 'pitch' is invalid";
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 4, 1, 8, -1, SDL_PIXELFORMAT_INDEX8);
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 4, 1, -1, SDL_PIXELFORMAT_INDEX8);
SDLTest_AssertCheck(surface == NULL, "Should detect negative pitch");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
@@ -657,7 +657,7 @@ surface_testOverflow(void *arg)
/* Less than 1 byte per pixel: the pitch can legitimately be less than
* the width, but it must be enough to hold the appropriate number of
* bits per pixel. SDL_PIXELFORMAT_INDEX4* needs 1 byte per 2 pixels. */
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 6, 1, 4, 3, SDL_PIXELFORMAT_INDEX4LSB);
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 6, 1, 3, SDL_PIXELFORMAT_INDEX4LSB);
SDLTest_AssertCheck(surface != NULL, "6px * 4 bits per px fits in 3 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_FreeSurface(surface);
@@ -666,7 +666,7 @@ surface_testOverflow(void *arg)
surface != NULL ? "(success)" : SDL_GetError());
SDL_FreeSurface(surface);
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 7, 1, 4, 3, SDL_PIXELFORMAT_INDEX4LSB);
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 7, 1, 3, SDL_PIXELFORMAT_INDEX4LSB);
SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
@@ -675,7 +675,7 @@ surface_testOverflow(void *arg)
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 7, 1, 4, 4, SDL_PIXELFORMAT_INDEX4LSB);
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 7, 1, 4, SDL_PIXELFORMAT_INDEX4LSB);
SDLTest_AssertCheck(surface != NULL, "7px * 4 bits per px fits in 4 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_FreeSurface(surface);
@@ -685,7 +685,7 @@ surface_testOverflow(void *arg)
SDL_FreeSurface(surface);
/* SDL_PIXELFORMAT_INDEX1* needs 1 byte per 8 pixels. */
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 16, 1, 1, 2, SDL_PIXELFORMAT_INDEX1LSB);
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 16, 1, 2, SDL_PIXELFORMAT_INDEX1LSB);
SDLTest_AssertCheck(surface != NULL, "16px * 1 bit per px fits in 2 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_FreeSurface(surface);
@@ -694,7 +694,7 @@ surface_testOverflow(void *arg)
surface != NULL ? "(success)" : SDL_GetError());
SDL_FreeSurface(surface);
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 17, 1, 1, 2, SDL_PIXELFORMAT_INDEX1LSB);
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 17, 1, 2, SDL_PIXELFORMAT_INDEX1LSB);
SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
@@ -703,7 +703,7 @@ surface_testOverflow(void *arg)
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 17, 1, 1, 3, SDL_PIXELFORMAT_INDEX1LSB);
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 17, 1, 3, SDL_PIXELFORMAT_INDEX1LSB);
SDLTest_AssertCheck(surface != NULL, "17px * 1 bit per px fits in 3 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_FreeSurface(surface);
@@ -713,7 +713,7 @@ surface_testOverflow(void *arg)
SDL_FreeSurface(surface);
/* SDL_PIXELFORMAT_INDEX8 and SDL_PIXELFORMAT_RGB332 require 1 byte per pixel. */
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 5, 1, 8, 5, SDL_PIXELFORMAT_RGB332);
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 5, 1, 5, SDL_PIXELFORMAT_RGB332);
SDLTest_AssertCheck(surface != NULL, "5px * 8 bits per px fits in 5 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_FreeSurface(surface);
@@ -722,7 +722,7 @@ surface_testOverflow(void *arg)
surface != NULL ? "(success)" : SDL_GetError());
SDL_FreeSurface(surface);
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 6, 1, 8, 5, SDL_PIXELFORMAT_RGB332);
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 6, 1, 5, SDL_PIXELFORMAT_RGB332);
SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
@@ -734,7 +734,7 @@ surface_testOverflow(void *arg)
/* Everything else requires more than 1 byte per pixel, and rounds up
* each pixel to an integer number of bytes (e.g. RGB555 is really
* XRGB1555, with 1 bit per pixel wasted). */
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 3, 1, 15, 6, SDL_PIXELFORMAT_RGB555);
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 3, 1, 6, SDL_PIXELFORMAT_RGB555);
SDLTest_AssertCheck(surface != NULL, "3px * 15 (really 16) bits per px fits in 6 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_FreeSurface(surface);
@@ -743,7 +743,7 @@ surface_testOverflow(void *arg)
surface != NULL ? "(success)" : SDL_GetError());
SDL_FreeSurface(surface);
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 4, 1, 15, 6, SDL_PIXELFORMAT_RGB555);
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 4, 1, 6, SDL_PIXELFORMAT_RGB555);
SDLTest_AssertCheck(surface == NULL, "4px * 15 (really 16) bits per px doesn't fit in 6 bytes");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
@@ -754,19 +754,19 @@ surface_testOverflow(void *arg)
if (sizeof (size_t) == 4 && sizeof (int) >= 4) {
expectedError = "Out of memory";
surface = SDL_CreateRGBSurfaceWithFormat(0, SDL_MAX_SINT32, 1, 8, SDL_PIXELFORMAT_INDEX8);
surface = SDL_CreateRGBSurfaceWithFormat(SDL_MAX_SINT32, 1, SDL_PIXELFORMAT_INDEX8);
SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width + alignment");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
surface = SDL_CreateRGBSurfaceWithFormat(0, SDL_MAX_SINT32 / 2, 1, 32, SDL_PIXELFORMAT_ARGB8888);
surface = SDL_CreateRGBSurfaceWithFormat(SDL_MAX_SINT32 / 2, 1, SDL_PIXELFORMAT_ARGB8888);
SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width * bytes per pixel");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
surface = SDL_CreateRGBSurfaceWithFormat(0, (1 << 29) - 1, (1 << 29) - 1, 8, SDL_PIXELFORMAT_INDEX8);
surface = SDL_CreateRGBSurfaceWithFormat((1 << 29) - 1, (1 << 29) - 1, SDL_PIXELFORMAT_INDEX8);
SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width * height");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
surface = SDL_CreateRGBSurfaceWithFormat(0, (1 << 15) + 1, (1 << 15) + 1, 32, SDL_PIXELFORMAT_ARGB8888);
surface = SDL_CreateRGBSurfaceWithFormat((1 << 15) + 1, (1 << 15) + 1, SDL_PIXELFORMAT_ARGB8888);
SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width * height * bytes per pixel");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());

View File

@@ -612,7 +612,7 @@ main(int argc, char *argv[])
TTF_CloseFont(font);
TTF_Quit();
#endif
g_surf_sdf = SDL_ConvertSurfaceFormat(tmp, SDL_PIXELFORMAT_ABGR8888, 0);
g_surf_sdf = SDL_ConvertSurfaceFormat(tmp, SDL_PIXELFORMAT_ABGR8888);
SDL_SetSurfaceBlendMode(g_surf_sdf, SDL_BLENDMODE_BLEND);
}

View File

@@ -61,7 +61,7 @@ save_surface_to_bmp()
pixel_format = SDL_GetWindowPixelFormat(window);
SDL_PixelFormatEnumToMasks(pixel_format, &bbp, &r_mask, &g_mask, &b_mask, &a_mask);
surface = SDL_CreateRGBSurface(0, width, height, bbp, r_mask, g_mask, b_mask, a_mask);
surface = SDL_CreateRGBSurface(width, height, bbp, r_mask, g_mask, b_mask, a_mask);
SDL_RenderReadPixels(renderer, NULL, pixel_format, (void*)surface->pixels, surface->pitch);
SDL_snprintf(file, sizeof(file), "SDL_window%" SDL_PRIs32 "-%8.8d.bmp",

View File

@@ -324,7 +324,7 @@ SDL_GL_LoadTexture(SDL_Surface * surface, GLfloat * texcoord)
texcoord[2] = (GLfloat) surface->w / w; /* Max X */
texcoord[3] = (GLfloat) surface->h / h; /* Max Y */
image = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32,
image = SDL_CreateRGBSurface(w, h, 32,
#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
0x000000FF,
0x0000FF00, 0x00FF0000, 0xFF000000

View File

@@ -27,7 +27,7 @@ static SDL_bool is_packed_yuv_format(Uint32 format)
/* Create a surface with a good pattern for verifying YUV conversion */
static SDL_Surface *generate_test_pattern(int pattern_size)
{
SDL_Surface *pattern = SDL_CreateRGBSurfaceWithFormat(0, pattern_size, pattern_size, 0, SDL_PIXELFORMAT_RGB24);
SDL_Surface *pattern = SDL_CreateRGBSurfaceWithFormat(pattern_size, pattern_size, SDL_PIXELFORMAT_RGB24);
if (pattern) {
int i, x, y;
@@ -325,7 +325,7 @@ main(int argc, char **argv)
} else {
filename = "testyuv.bmp";
}
original = SDL_ConvertSurfaceFormat(SDL_LoadBMP(filename), SDL_PIXELFORMAT_RGB24, 0);
original = SDL_ConvertSurfaceFormat(SDL_LoadBMP(filename), SDL_PIXELFORMAT_RGB24);
if (original == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", filename, SDL_GetError());
return 3;
@@ -337,7 +337,7 @@ main(int argc, char **argv)
0, 100);
pitch = CalculateYUVPitch(yuv_format, original->w);
converted = SDL_CreateRGBSurfaceWithFormat(0, original->w, original->h, 0, rgb_format);
converted = SDL_CreateRGBSurfaceWithFormat(original->w, original->h, rgb_format);
if (converted == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create converted surface: %s\n", SDL_GetError());
return 3;