Browse Source

cleanup manual value clamping: sdl2_to_1_2_backports.cpp (#2580)

* cleanup manual value clamping: sdl2_to_1_2_backports.cpp
* static_cast Sint16 and int in SDL_BlitScaled
pull/2587/head
BC Ko 5 years ago committed by GitHub
parent
commit
b3e002de79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 25
      Source/utils/sdl2_to_1_2_backports.cpp

25
Source/utils/sdl2_to_1_2_backports.cpp

@ -1,6 +1,7 @@
#include "./sdl2_to_1_2_backports.h"
#include <cstddef>
#include <algorithm>
#include "./console.h"
@ -447,26 +448,18 @@ int SDL_BlitScaled(SDL_Surface *src, SDL_Rect *srcrect,
dst_y0 += dst->clip_rect.y;
dst_y1 += dst->clip_rect.y;
final_src.x = (Sint16)SDL_floor(src_x0 + 0.5);
final_src.y = (Sint16)SDL_floor(src_y0 + 0.5);
src_w = (int)SDL_floor(src_x1 + 1 + 0.5) - (int)SDL_floor(src_x0 + 0.5);
src_h = (int)SDL_floor(src_y1 + 1 + 0.5) - (int)SDL_floor(src_y0 + 0.5);
if (src_w < 0)
src_w = 0;
if (src_h < 0)
src_h = 0;
final_src.x = static_cast<Sint16>(SDL_floor(src_x0 + 0.5));
final_src.y = static_cast<Sint16>(SDL_floor(src_y0 + 0.5));
src_w = std::max(static_cast<int>(SDL_floor(src_x1 + 1 + 0.5)) - static_cast<int>(SDL_floor(src_x0 + 0.5)), 0);
src_h = std::max(static_cast<int>(SDL_floor(src_y1 + 1 + 0.5)) - static_cast<int>(SDL_floor(src_y0 + 0.5)), 0);
final_src.w = static_cast<Uint16>(src_w);
final_src.h = static_cast<Uint16>(src_h);
final_dst.x = (Sint16)SDL_floor(dst_x0 + 0.5);
final_dst.y = (Sint16)SDL_floor(dst_y0 + 0.5);
dst_w = (int)SDL_floor(dst_x1 - dst_x0 + 1.5);
dst_h = (int)SDL_floor(dst_y1 - dst_y0 + 1.5);
if (dst_w < 0)
dst_w = 0;
if (dst_h < 0)
dst_h = 0;
final_dst.x = static_cast<Sint16>(SDL_floor(dst_x0 + 0.5));
final_dst.y = static_cast<Sint16>(SDL_floor(dst_y0 + 0.5));
dst_w = std::max(static_cast<int>(SDL_floor(dst_x1 - dst_x0 + 1.5)), 0);
dst_h = std::max(static_cast<int>(SDL_floor(dst_y1 - dst_y0 + 1.5)), 0);
final_dst.w = static_cast<Uint16>(dst_w);
final_dst.h = static_cast<Uint16>(dst_h);

Loading…
Cancel
Save