From 652f3f8d4b2a3401e1c9c4e064336313e5e14232 Mon Sep 17 00:00:00 2001 From: "K. Lange" Date: Tue, 13 Jun 2023 15:17:41 +0900 Subject: [PATCH] graphics: fix clipping from bad rounding when drawing with transformations --- lib/graphics.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/graphics.c b/lib/graphics.c index f765b043..4364c362 100644 --- a/lib/graphics.c +++ b/lib/graphics.c @@ -976,8 +976,8 @@ void draw_sprite_transform(gfx_context_t * ctx, const sprite_t * sprite, gfx_mat /* Use the corners to calculate bounds within the target context. */ int32_t _left = clamp(fmin(fmin(ul_x, ll_x), fmin(ur_x, lr_x)), 0, ctx->width); int32_t _top = clamp(fmin(fmin(ul_y, ll_y), fmin(ur_y, lr_y)), 0, ctx->height); - int32_t _right = clamp(fmax(fmax(ul_x+1, ll_x+1), fmax(ur_x+1, lr_x+1)), 0, ctx->width); - int32_t _bottom = clamp(fmax(fmax(ul_y+1, ll_y+1), fmax(ur_y+1, lr_y+1)), 0, ctx->height); + int32_t _right = clamp(fmax(fmax(ul_x+2, ll_x+2), fmax(ur_x+2, lr_x+2)), 0, ctx->width); + int32_t _bottom = clamp(fmax(fmax(ul_y+2, ll_y+2), fmax(ur_y+2, lr_y+2)), 0, ctx->height); sprite_t * scanline = create_sprite(_right - _left, 1, ALPHA_EMBEDDED); uint8_t alp = alpha * 255; @@ -1031,8 +1031,8 @@ void draw_sprite_transform_blur(gfx_context_t * ctx, gfx_context_t * blur_ctx, c /* Use the corners to calculate bounds within the target context. */ int32_t _left = clamp(fmin(fmin(ul_x, ll_x), fmin(ur_x, lr_x)), 0, ctx->width); int32_t _top = clamp(fmin(fmin(ul_y, ll_y), fmin(ur_y, lr_y)), 0, ctx->height); - int32_t _right = clamp(fmax(fmax(ul_x+1, ll_x+1), fmax(ur_x+1, lr_x+1)), 0, ctx->width); - int32_t _bottom = clamp(fmax(fmax(ul_y+1, ll_y+1), fmax(ur_y+1, lr_y+1)), 0, ctx->height); + int32_t _right = clamp(fmax(fmax(ul_x+2, ll_x+2), fmax(ur_x+2, lr_x+2)), 0, ctx->width); + int32_t _bottom = clamp(fmax(fmax(ul_y+2, ll_y+2), fmax(ur_y+2, lr_y+2)), 0, ctx->height); blur_ctx->clips_size = ctx->clips_size; blur_ctx->clips = ctx->clips;