mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-06 11:28:15 +00:00
Added unaligned version of SDL_ConvertPixels_SwapNV_std()
Fixes https://github.com/libsdl-org/SDL/issues/12546
This commit is contained in:
@@ -1628,18 +1628,18 @@ static bool SDL_ConvertPixels_SwapNV_std(int width, int height, const void *src,
|
|||||||
const int UVwidth = (width + 1) / 2;
|
const int UVwidth = (width + 1) / 2;
|
||||||
const int UVheight = (height + 1) / 2;
|
const int UVheight = (height + 1) / 2;
|
||||||
const int srcUVPitch = ((src_pitch + 1) / 2) * 2;
|
const int srcUVPitch = ((src_pitch + 1) / 2) * 2;
|
||||||
const int srcUVPitchLeft = (srcUVPitch - UVwidth * 2) / sizeof(Uint16);
|
|
||||||
const int dstUVPitch = ((dst_pitch + 1) / 2) * 2;
|
const int dstUVPitch = ((dst_pitch + 1) / 2) * 2;
|
||||||
const int dstUVPitchLeft = (dstUVPitch - UVwidth * 2) / sizeof(Uint16);
|
|
||||||
const Uint16 *srcUV;
|
|
||||||
Uint16 *dstUV;
|
|
||||||
|
|
||||||
// Skip the Y plane
|
// Skip the Y plane
|
||||||
src = (const Uint8 *)src + height * src_pitch;
|
src = (const Uint8 *)src + height * src_pitch;
|
||||||
dst = (Uint8 *)dst + height * dst_pitch;
|
dst = (Uint8 *)dst + height * dst_pitch;
|
||||||
|
|
||||||
srcUV = (const Uint16 *)src;
|
bool aligned = (((uintptr_t)src | (uintptr_t)dst) & 1) == 0;
|
||||||
dstUV = (Uint16 *)dst;
|
if (aligned) {
|
||||||
|
const int srcUVPitchLeft = (srcUVPitch - UVwidth * 2) / sizeof(Uint16);
|
||||||
|
const int dstUVPitchLeft = (dstUVPitch - UVwidth * 2) / sizeof(Uint16);
|
||||||
|
const Uint16 *srcUV = (const Uint16 *)src;
|
||||||
|
Uint16 *dstUV = (Uint16 *)dst;
|
||||||
y = UVheight;
|
y = UVheight;
|
||||||
while (y--) {
|
while (y--) {
|
||||||
x = UVwidth;
|
x = UVwidth;
|
||||||
@@ -1649,6 +1649,24 @@ static bool SDL_ConvertPixels_SwapNV_std(int width, int height, const void *src,
|
|||||||
srcUV += srcUVPitchLeft;
|
srcUV += srcUVPitchLeft;
|
||||||
dstUV += dstUVPitchLeft;
|
dstUV += dstUVPitchLeft;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
const int srcUVPitchLeft = (srcUVPitch - UVwidth * 2);
|
||||||
|
const int dstUVPitchLeft = (dstUVPitch - UVwidth * 2);
|
||||||
|
const Uint8 *srcUV = (const Uint8 *)src;
|
||||||
|
Uint8 *dstUV = (Uint8 *)dst;
|
||||||
|
y = UVheight;
|
||||||
|
while (y--) {
|
||||||
|
x = UVwidth;
|
||||||
|
while (x--) {
|
||||||
|
Uint8 u = *srcUV++;
|
||||||
|
Uint8 v = *srcUV++;
|
||||||
|
*dstUV++ = v;
|
||||||
|
*dstUV++ = u;
|
||||||
|
}
|
||||||
|
srcUV += srcUVPitchLeft;
|
||||||
|
dstUV += dstUVPitchLeft;
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user