From b11adcd38ed4c6443bde8a7533f23fa858519a57 Mon Sep 17 00:00:00 2001 From: JianjunJiang <8192542@qq.com> Date: Mon, 13 Dec 2021 14:59:39 +0800 Subject: [PATCH] [libcg]fix blend_transformed_argb --- src/cg.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/cg.c b/src/cg.c index 71f6694..622f715 100644 --- a/src/cg.c +++ b/src/cg.c @@ -1938,7 +1938,6 @@ static inline void blend_transformed_argb(struct cg_surface_t * surface, enum cg while(count--) { uint32_t * target = (uint32_t *)(surface->pixels + spans->y * surface->stride) + spans->x; - double cx = spans->x + 0.5; double cy = spans->y + 0.5; int x = (int)((texture->matrix.c * cy + texture->matrix.a * cx + texture->matrix.tx) * FIXED_SCALE); @@ -1952,12 +1951,12 @@ static inline void blend_transformed_argb(struct cg_surface_t * surface, enum cg uint32_t * b = buffer; while(b < end) { - int px = CG_CLAMP(x >> 16, 0, image_width - 1); - int py = CG_CLAMP(y >> 16, 0, image_height - 1); - if((px == (x >> 16)) && (py == (y >> 16))) - *b = ((uint32_t *)(texture->pixels + py * texture->stride))[px]; - else + int px = x >> 16; + int py = y >> 16; + if((px < 0) || (px >= image_width) || (py < 0) || (py >= image_height)) *b = 0; + else + *b = ((uint32_t *)(texture->pixels + py * texture->stride))[px]; x += fdx; y += fdy; ++b;