Added a fast path for converting the same format and pitch

This commit is contained in:
Sam Lantinga
2025-02-19 22:36:13 -08:00
parent f24f9d3bed
commit 9267930fea

View File

@@ -2298,6 +2298,9 @@ bool SDL_ConvertPixelsAndColorspace(int width, int height,
// Fast path for same format copy // Fast path for same format copy
if (src_format == dst_format && src_colorspace == dst_colorspace) { if (src_format == dst_format && src_colorspace == dst_colorspace) {
if (src_pitch == dst_pitch) {
SDL_memcpy(dst, src, height * src_pitch);
} else {
int i; int i;
const int bpp = SDL_BYTESPERPIXEL(src_format); const int bpp = SDL_BYTESPERPIXEL(src_format);
width *= bpp; width *= bpp;
@@ -2306,6 +2309,7 @@ bool SDL_ConvertPixelsAndColorspace(int width, int height,
src = (const Uint8 *)src + src_pitch; src = (const Uint8 *)src + src_pitch;
dst = (Uint8 *)dst + dst_pitch; dst = (Uint8 *)dst + dst_pitch;
} }
}
return true; return true;
} }