mirror of https://github.com/encounter/SDL.git
SDL_BlitScaled: better and safer fix clipping bug #2687
And re-use SDL_round(), since it's been re-added (remove in https://hg.libsdl.org/SDL/rev/34043108b7e4 )
This commit is contained in:
parent
2127ed2574
commit
c005267fb1
|
@ -874,23 +874,32 @@ SDL_PrivateUpperBlitScaled(SDL_Surface * src, const SDL_Rect * srcrect,
|
||||||
dst_y0 += dst->clip_rect.y;
|
dst_y0 += dst->clip_rect.y;
|
||||||
dst_y1 += dst->clip_rect.y;
|
dst_y1 += dst->clip_rect.y;
|
||||||
|
|
||||||
final_src.x = (int)SDL_floor(src_x0 + 0.5);
|
final_src.x = (int)SDL_round(src_x0);
|
||||||
final_src.y = (int)SDL_floor(src_y0 + 0.5);
|
final_src.y = (int)SDL_round(src_y0);
|
||||||
final_src.w = (int)SDL_floor(src_x1 + 0.5) - (int)SDL_floor(src_x0 + 0.5);
|
final_src.w = (int)SDL_round(src_x1 - src_x0);
|
||||||
final_src.h = (int)SDL_floor(src_y1 + 0.5) - (int)SDL_floor(src_y0 + 0.5);
|
final_src.h = (int)SDL_round(src_y1 - src_y0);
|
||||||
|
|
||||||
final_dst.x = (int)SDL_floor(dst_x0 + 0.5);
|
final_dst.x = (int)SDL_round(dst_x0);
|
||||||
final_dst.y = (int)SDL_floor(dst_y0 + 0.5);
|
final_dst.y = (int)SDL_round(dst_y0);
|
||||||
final_dst.w = (int)SDL_floor(dst_x1 - dst_x0 + 0.5);
|
final_dst.w = (int)SDL_round(dst_x1 - dst_x0);
|
||||||
final_dst.h = (int)SDL_floor(dst_y1 - dst_y0 + 0.5);
|
final_dst.h = (int)SDL_round(dst_y1 - dst_y0);
|
||||||
|
|
||||||
if (final_dst.w < 0)
|
/* Clip again */
|
||||||
final_dst.w = 0;
|
{
|
||||||
if (final_dst.h < 0)
|
SDL_Rect tmp;
|
||||||
final_dst.h = 0;
|
tmp.x = 0;
|
||||||
|
tmp.y = 0;
|
||||||
|
tmp.w = src->w;
|
||||||
|
tmp.h = src->h;
|
||||||
|
SDL_IntersectRect(&tmp, &final_src, &final_src);
|
||||||
|
}
|
||||||
|
|
||||||
if (dstrect)
|
/* Clip again */
|
||||||
|
SDL_IntersectRect(&dst->clip_rect, &final_dst, &final_dst);
|
||||||
|
|
||||||
|
if (dstrect) {
|
||||||
*dstrect = final_dst;
|
*dstrect = final_dst;
|
||||||
|
}
|
||||||
|
|
||||||
if (final_dst.w == 0 || final_dst.h == 0 ||
|
if (final_dst.w == 0 || final_dst.h == 0 ||
|
||||||
final_src.w <= 0 || final_src.h <= 0) {
|
final_src.w <= 0 || final_src.h <= 0) {
|
||||||
|
|
Loading…
Reference in New Issue