From 9267930fea7df02610063608882ac7cc9925dfd4 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 19 Feb 2025 22:36:13 -0800 Subject: [PATCH] Added a fast path for converting the same format and pitch --- src/video/SDL_surface.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c index dfb2d0d077..945fda606d 100644 --- a/src/video/SDL_surface.c +++ b/src/video/SDL_surface.c @@ -2298,13 +2298,17 @@ bool SDL_ConvertPixelsAndColorspace(int width, int height, // Fast path for same format copy if (src_format == dst_format && src_colorspace == dst_colorspace) { - int i; - const int bpp = SDL_BYTESPERPIXEL(src_format); - width *= bpp; - for (i = height; i--;) { - SDL_memcpy(dst, src, width); - src = (const Uint8 *)src + src_pitch; - dst = (Uint8 *)dst + dst_pitch; + if (src_pitch == dst_pitch) { + SDL_memcpy(dst, src, height * src_pitch); + } else { + int i; + const int bpp = SDL_BYTESPERPIXEL(src_format); + width *= bpp; + for (i = height; i--;) { + SDL_memcpy(dst, src, width); + src = (const Uint8 *)src + src_pitch; + dst = (Uint8 *)dst + dst_pitch; + } } return true; }