Fixed warning C4127 (conditional expression is constant) in Visual Studio

This commit is contained in:
Sam Lantinga
2025-11-17 16:06:58 -08:00
parent b144c79da2
commit 4931c675ab
5 changed files with 144 additions and 157 deletions

View File

@@ -1093,7 +1093,6 @@ static void ChooseBestCameraSpec(SDL_Camera *device, const SDL_CameraSpec *spec,
// that. // that.
SDL_zerop(closest); SDL_zerop(closest);
SDL_assert(((Uint32) SDL_PIXELFORMAT_UNKNOWN) == 0); // since we SDL_zerop'd to this value.
if (device->num_specs == 0) { // device listed no specs! You get whatever you want! if (device->num_specs == 0) { // device listed no specs! You get whatever you want!
if (spec) { if (spec) {

View File

@@ -2621,8 +2621,8 @@ static void HandleFullControllerState(SDL_Joystick *joystick, SDL_DriverSwitch_C
if (ctx->m_bReportSensors) { if (ctx->m_bReportSensors) {
// Need to copy the imuState to an aligned variable // Need to copy the imuState to an aligned variable
SwitchControllerIMUState_t imuState[3]; SwitchControllerIMUState_t imuState[3];
SDL_assert(sizeof(imuState) == sizeof(packet->imuState)); SDL_COMPILE_TIME_ASSERT(imuState_size, sizeof(imuState) == sizeof(packet->imuState));
SDL_memcpy(imuState, packet->imuState, sizeof(imuState)); SDL_memcpy(imuState, packet->imuState, sizeof(packet->imuState));
bool bHasSensorData = (imuState[0].sAccelZ != 0 || bool bHasSensorData = (imuState[0].sAccelZ != 0 ||
imuState[0].sAccelY != 0 || imuState[0].sAccelY != 0 ||

View File

@@ -170,6 +170,17 @@
/* /*
* The general slow catch-all function, for remaining depths and formats * The general slow catch-all function, for remaining depths and formats
*/ */
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
#define SET_RGB24(dst, d) \
dst[0] = (Uint8)(d >> 16); \
dst[1] = (Uint8)(d >> 8); \
dst[2] = (Uint8)(d);
#else
#define SET_RGB24(dst, d) \
dst[0] = (Uint8)(d); \
dst[1] = (Uint8)(d >> 8); \
dst[2] = (Uint8)(d >> 16);
#endif
#define ALPHA_BLIT_ANY(to, from, length, bpp, alpha) \ #define ALPHA_BLIT_ANY(to, from, length, bpp, alpha) \
do { \ do { \
int i; \ int i; \
@@ -184,13 +195,8 @@
d = *(Uint16 *)dst; \ d = *(Uint16 *)dst; \
break; \ break; \
case 3: \ case 3: \
if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { \ s = GET_RGB24(src); \
s = (src[0] << 16) | (src[1] << 8) | src[2]; \ d = GET_RGB24(dst); \
d = (dst[0] << 16) | (dst[1] << 8) | dst[2]; \
} else { \
s = (src[2] << 16) | (src[1] << 8) | src[0]; \
d = (dst[2] << 16) | (dst[1] << 8) | dst[0]; \
} \
break; \ break; \
case 4: \ case 4: \
s = *(Uint32 *)src; \ s = *(Uint32 *)src; \
@@ -208,15 +214,7 @@
*(Uint16 *)dst = (Uint16)d; \ *(Uint16 *)dst = (Uint16)d; \
break; \ break; \
case 3: \ case 3: \
if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { \ SET_RGB24(dst, d); \
dst[0] = (Uint8)(d >> 16); \
dst[1] = (Uint8)(d >> 8); \
dst[2] = (Uint8)(d); \
} else { \
dst[0] = (Uint8)d; \
dst[1] = (Uint8)(d >> 8); \
dst[2] = (Uint8)(d >> 16); \
} \
break; \ break; \
case 4: \ case 4: \
*(Uint32 *)dst = d; \ *(Uint32 *)dst = d; \
@@ -649,7 +647,8 @@ static void RLEAlphaClipBlit(int w, Uint8 *srcbuf, SDL_Surface *surf_dst,
return; \ return; \
} while (ofs < w); \ } while (ofs < w); \
/* skip padding if necessary */ \ /* skip padding if necessary */ \
if (sizeof(Ptype) == 2) \ const size_t psize = sizeof(Ptype); \
if (psize == 2) \
srcbuf += (uintptr_t)srcbuf & 2; \ srcbuf += (uintptr_t)srcbuf & 2; \
/* blit translucent pixels on the same line */ \ /* blit translucent pixels on the same line */ \
ofs = 0; \ ofs = 0; \
@@ -806,7 +805,8 @@ static bool SDLCALL SDL_RLEAlphaBlit(SDL_Surface *surf_src, const SDL_Rect *srcr
goto done; \ goto done; \
} while (ofs < w); \ } while (ofs < w); \
/* skip padding if necessary */ \ /* skip padding if necessary */ \
if (sizeof(Ptype) == 2) \ const size_t psize = sizeof(Ptype); \
if (psize == 2) \
srcbuf += (uintptr_t)srcbuf & 2; \ srcbuf += (uintptr_t)srcbuf & 2; \
/* blit translucent pixels on the same line */ \ /* blit translucent pixels on the same line */ \
ofs = 0; \ ofs = 0; \

View File

@@ -150,6 +150,11 @@ extern SDL_BlitFunc SDL_CalculateBlitA(SDL_Surface *surface);
g = ((Pixel & 0xFF00) >> 8); \ g = ((Pixel & 0xFF00) >> 8); \
b = (Pixel & 0xFF); \ b = (Pixel & 0xFF); \
} }
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
#define GET_RGB24(B) (B[2] << 16) | (B[1] << 8) | B[0]
#else
#define GET_RGB24(B) (B[0] << 16) | (B[1] << 8) | B[2]
#endif
#define RETRIEVE_RGB_PIXEL(buf, bpp, Pixel) \ #define RETRIEVE_RGB_PIXEL(buf, bpp, Pixel) \
do { \ do { \
switch (bpp) { \ switch (bpp) { \
@@ -164,11 +169,7 @@ extern SDL_BlitFunc SDL_CalculateBlitA(SDL_Surface *surface);
case 3: \ case 3: \
{ \ { \
Uint8 *B = (Uint8 *)(buf); \ Uint8 *B = (Uint8 *)(buf); \
if (SDL_BYTEORDER == SDL_LIL_ENDIAN) { \ Pixel = GET_RGB24(B); \
Pixel = B[0] + (B[1] << 8) + (B[2] << 16); \
} else { \
Pixel = (B[0] << 16) + (B[1] << 8) + B[2]; \
} \
} break; \ } break; \
\ \
case 4: \ case 4: \
@@ -181,6 +182,11 @@ extern SDL_BlitFunc SDL_CalculateBlitA(SDL_Surface *surface);
} \ } \
} while (0) } while (0)
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
#define GET_RGB24_COMPONENT(buf, fmt, shift) *((buf) + fmt->shift / 8)
#else
#define GET_RGB24_COMPONENT(buf, fmt, shift) *((buf) + 2 - fmt->shift / 8)
#endif
#define DISEMBLE_RGB(buf, bpp, fmt, Pixel, r, g, b) \ #define DISEMBLE_RGB(buf, bpp, fmt, Pixel, r, g, b) \
do { \ do { \
switch (bpp) { \ switch (bpp) { \
@@ -197,15 +203,9 @@ extern SDL_BlitFunc SDL_CalculateBlitA(SDL_Surface *surface);
case 3: \ case 3: \
{ \ { \
Pixel = 0; \ Pixel = 0; \
if (SDL_BYTEORDER == SDL_LIL_ENDIAN) { \ r = GET_RGB24_COMPONENT(buf, fmt, Rshift); \
r = *((buf) + fmt->Rshift / 8); \ g = GET_RGB24_COMPONENT(buf, fmt, Gshift); \
g = *((buf) + fmt->Gshift / 8); \ b = GET_RGB24_COMPONENT(buf, fmt, Bshift); \
b = *((buf) + fmt->Bshift / 8); \
} else { \
r = *((buf) + 2 - fmt->Rshift / 8); \
g = *((buf) + 2 - fmt->Gshift / 8); \
b = *((buf) + 2 - fmt->Bshift / 8); \
} \
} break; \ } break; \
\ \
case 4: \ case 4: \
@@ -320,15 +320,9 @@ extern SDL_BlitFunc SDL_CalculateBlitA(SDL_Surface *surface);
\ \
case 3: \ case 3: \
{ \ { \
if (SDL_BYTEORDER == SDL_LIL_ENDIAN) { \ GET_RGB24_COMPONENT(buf, fmt, Rshift) = r; \
*((buf) + fmt->Rshift / 8) = r; \ GET_RGB24_COMPONENT(buf, fmt, Gshift) = g; \
*((buf) + fmt->Gshift / 8) = g; \ GET_RGB24_COMPONENT(buf, fmt, Bshift) = b; \
*((buf) + fmt->Bshift / 8) = b; \
} else { \
*((buf) + 2 - fmt->Rshift / 8) = r; \
*((buf) + 2 - fmt->Gshift / 8) = g; \
*((buf) + 2 - fmt->Bshift / 8) = b; \
} \
} break; \ } break; \
\ \
case 4: \ case 4: \
@@ -428,15 +422,9 @@ extern SDL_BlitFunc SDL_CalculateBlitA(SDL_Surface *surface);
case 3: \ case 3: \
{ \ { \
Pixel = 0; \ Pixel = 0; \
if (SDL_BYTEORDER == SDL_LIL_ENDIAN) { \ r = GET_RGB24_COMPONENT(buf, fmt, Rshift); \
r = *((buf) + fmt->Rshift / 8); \ g = GET_RGB24_COMPONENT(buf, fmt, Gshift); \
g = *((buf) + fmt->Gshift / 8); \ b = GET_RGB24_COMPONENT(buf, fmt, Bshift); \
b = *((buf) + fmt->Bshift / 8); \
} else { \
r = *((buf) + 2 - fmt->Rshift / 8); \
g = *((buf) + 2 - fmt->Gshift / 8); \
b = *((buf) + 2 - fmt->Bshift / 8); \
} \
a = 0xFF; \ a = 0xFF; \
} break; \ } break; \
\ \
@@ -482,15 +470,9 @@ extern SDL_BlitFunc SDL_CalculateBlitA(SDL_Surface *surface);
\ \
case 3: \ case 3: \
{ \ { \
if (SDL_BYTEORDER == SDL_LIL_ENDIAN) { \ GET_RGB24_COMPONENT(buf, fmt, Rshift) = r; \
*((buf) + fmt->Rshift / 8) = r; \ GET_RGB24_COMPONENT(buf, fmt, Gshift) = g; \
*((buf) + fmt->Gshift / 8) = g; \ GET_RGB24_COMPONENT(buf, fmt, Bshift) = b; \
*((buf) + fmt->Bshift / 8) = b; \
} else { \
*((buf) + 2 - fmt->Rshift / 8) = r; \
*((buf) + 2 - fmt->Gshift / 8) = g; \
*((buf) + 2 - fmt->Bshift / 8) = b; \
} \
} break; \ } break; \
\ \
case 4: \ case 4: \

View File

@@ -180,7 +180,8 @@ void STD_FUNCTION_NAME(
} }
/* Catch the last pixel, if needed */ /* Catch the last pixel, if needed */
if (uv_x_sample_interval == 2 && x == (width-1)) #if uv_x_sample_interval == 2
if (x == (width-1))
{ {
// Compute U and V contributions, common to the four pixels // Compute U and V contributions, common to the four pixels
@@ -201,10 +202,12 @@ void STD_FUNCTION_NAME(
PACK_PIXEL(rgb_ptr2); PACK_PIXEL(rgb_ptr2);
#endif #endif
} }
#endif
} }
/* Catch the last line, if needed */ /* Catch the last line, if needed */
if (uv_y_sample_interval == 2 && y == (height-1)) #if uv_y_sample_interval == 2
if (y == (height-1))
{ {
const YUV_TYPE *y_ptr1=Y+y*Y_stride, const YUV_TYPE *y_ptr1=Y+y*Y_stride,
*u_ptr=U+(y/uv_y_sample_interval)*UV_stride, *u_ptr=U+(y/uv_y_sample_interval)*UV_stride,
@@ -237,7 +240,8 @@ void STD_FUNCTION_NAME(
} }
/* Catch the last pixel, if needed */ /* Catch the last pixel, if needed */
if (uv_x_sample_interval == 2 && x == (width-1)) #if uv_x_sample_interval == 2
if (x == (width-1))
{ {
// Compute U and V contributions, common to the four pixels // Compute U and V contributions, common to the four pixels
@@ -253,7 +257,9 @@ void STD_FUNCTION_NAME(
int32_t y_tmp = (GET(y_ptr1[0]-param->y_shift)*param->y_factor); int32_t y_tmp = (GET(y_ptr1[0]-param->y_shift)*param->y_factor);
PACK_PIXEL(rgb_ptr1); PACK_PIXEL(rgb_ptr1);
} }
#endif
} }
#endif
#undef y_pixel_stride #undef y_pixel_stride
#undef uv_pixel_stride #undef uv_pixel_stride