Optimized SDL_DuplicatePixels()

This commit is contained in:
Sam Lantinga
2024-02-03 10:32:55 -08:00
parent 89b9d6cbdc
commit c3e821fa80

View File

@@ -1554,17 +1554,23 @@ static void SDL_DestroySurfaceOnStack(SDL_Surface *surface)
SDL_Surface *SDL_DuplicatePixels(int width, int height, Uint32 format, SDL_Colorspace colorspace, void *pixels, int pitch)
{
SDL_Surface surface;
SDL_PixelFormat fmt;
SDL_BlitMap blitmap;
SDL_Surface *result = NULL;
if (SDL_CreateSurfaceOnStack(width, height, format, colorspace, pixels, pitch, &surface, &fmt, &blitmap)) {
result = SDL_DuplicateSurface(&surface);
SDL_DestroySurfaceOnStack(&surface);
SDL_Surface *surface = SDL_CreateSurface(width, height, format);
if (surface) {
int length = width * SDL_BYTESPERPIXEL(format);
Uint8 *src = (Uint8 *)pixels;
Uint8 *dst = (Uint8 *)surface->pixels;
int rows = height;
while (rows--) {
SDL_memcpy(dst, src, length);
dst += surface->pitch;
src += pitch;
}
return result;
if (colorspace != SDL_GetDefaultColorspaceForFormat(format)) {
SDL_SetNumberProperty(SDL_GetSurfaceProperties(surface), SDL_PROP_SURFACE_COLORSPACE_NUMBER, colorspace);
}
}
return surface;
}
int SDL_ConvertPixelsAndColorspace(int width, int height,