mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-13 13:25:59 +00:00
Optimized SDL_DuplicatePixels()
This commit is contained in:
@@ -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,
|
||||
|
Reference in New Issue
Block a user