From 215de5511eb3206afb7acb8df652cebba69487d6 Mon Sep 17 00:00:00 2001 From: kichikuou Date: Wed, 19 Feb 2025 10:16:10 +0900 Subject: [PATCH] Simplify gre_BlendUseAMap() --- modules/CMakeLists.txt | 1 - modules/lib/graph.c | 5 -- modules/lib/graph_blend_amap.c | 36 ++++++++++- modules/lib/gre_blend_useamap.c | 102 -------------------------------- modules/lib/ngraph.h | 3 - 5 files changed, 35 insertions(+), 112 deletions(-) delete mode 100644 modules/lib/gre_blend_useamap.c diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index eb1097f..c20b556 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -70,7 +70,6 @@ add_library(modules STATIC lib/graph_blend_amap.c lib/graph_draw_amap.c lib/graph_cg.c - lib/gre_blend_useamap.c nDEMO/nDEMO.c nDEMOE/nDEMOE.c oDEMO/oDEMO.c diff --git a/modules/lib/graph.c b/modules/lib/graph.c index e9b1975..31bf6ff 100644 --- a/modules/lib/graph.c +++ b/modules/lib/graph.c @@ -13,11 +13,6 @@ #include "ags.h" #include "sdl_core.h" -/* - gr_xxxx はクリッピングあり - gre_xxxx はクリッピングなし -*/ - /** * surface から surface にコピーなどをする際に、転送元と転送先のsurface * の大きさや、転送元・転送先座標、転送する領域の大きさなどから、実際に diff --git a/modules/lib/graph_blend_amap.c b/modules/lib/graph_blend_amap.c index 1fd5d62..5dd9698 100644 --- a/modules/lib/graph_blend_amap.c +++ b/modules/lib/graph_blend_amap.c @@ -9,6 +9,40 @@ #include "ngraph.h" #include "ags.h" +static void gre_BlendUseAMap(surface_t *dst, int dx, int dy, surface_t *src, int sx, int sy, int width, int height) { + uint8_t *sp = GETOFFSET_PIXEL(src, sx, sy); + uint8_t *dp = GETOFFSET_PIXEL(dst, dx, dy); + uint8_t *ap = GETOFFSET_ALPHA(src, sx, sy); + + switch(dst->depth) { + case 16: + for (int y = 0; y < height; y++) { + uint16_t *yls = (uint16_t *)(sp + y * src->bytes_per_line); + uint16_t *yld = (uint16_t *)(dp + y * dst->bytes_per_line); + uint8_t *yla = (uint8_t *)(ap + y * src->width); + + for (int x = 0; x < width; x++) { + *yld = ALPHABLEND16(*yls, *yld, *yla); + yls++; yld++; yla++; + } + } + break; + case 24: + case 32: + for (int y = 0; y < height; y++) { + uint32_t *yls = (uint32_t *)(sp + y * src->bytes_per_line); + uint32_t *yld = (uint32_t *)(dp + y * dst->bytes_per_line); + uint8_t *yla = (uint8_t *)(ap + y * src->width); + + for (int x = 0; x < width; x++) { + *yld = ALPHABLEND24(*yls, *yld, *yla); + yls++; yld++; yla++; + } + } + break; + } +} + void gr_blend_alpha_map(surface_t *dst, int dx, int dy, surface_t *src, int sx, int sy, int sw, int sh) { if (src == NULL || dst == NULL) return; if (!gr_clip(src, &sx, &sy, &sw, &sh, dst, &dx, &dy)) return; @@ -18,6 +52,6 @@ void gr_blend_alpha_map(surface_t *dst, int dx, int dy, surface_t *src, int sx, return; } - gre_BlendUseAMap(dst, dx, dy, dst, dx, dy, src, sx, sy, sw, sh, src, sx, sy, 255); + gre_BlendUseAMap(dst, dx, dy, src, sx, sy, sw, sh); } diff --git a/modules/lib/gre_blend_useamap.c b/modules/lib/gre_blend_useamap.c deleted file mode 100644 index 3c31333..0000000 --- a/modules/lib/gre_blend_useamap.c +++ /dev/null @@ -1,102 +0,0 @@ -// dst の上に src をalphamapを参照しつつ、ブレンド率 lv でブレンド -// したものを write へ書き出し - -#include "config.h" - -#include "portab.h" -#include "surface.h" -#include "ngraph.h" -#include "ags.h" - -void gre_BlendUseAMap(surface_t *write, int wx, int wy, surface_t *dst, int dx, int dy, surface_t *src, int sx, int sy, int width, int height, surface_t *alpha, int ax, int ay, int lv) { - uint8_t *sp, *dp, *wp, *ap; - int x, y; - - wp = GETOFFSET_PIXEL(write, wx, wy); - sp = GETOFFSET_PIXEL(src, sx, sy); - dp = GETOFFSET_PIXEL(dst, dx, dy); - ap = GETOFFSET_ALPHA(alpha, ax, ay); - - if (lv == 255) { - switch(dst->depth) { - case 16: - { - uint16_t *yls, *yld, *ylw; - uint8_t *yla; - - for (y = 0; y < height; y++) { - yls = (uint16_t *)(sp + y * src->bytes_per_line); - yld = (uint16_t *)(dp + y * dst->bytes_per_line); - ylw = (uint16_t *)(wp + y * write->bytes_per_line); - yla = (uint8_t *)(ap + y * alpha->width); - - for (x = 0; x < width; x++) { - *ylw = ALPHABLEND16(*yls, *yld, *yla); - yls++; yld++; ylw++; yla++; - } - } - } - break; - case 24: - case 32: - { - uint32_t *yls, *yld, *ylw; - uint8_t *yla; - - for (y = 0; y < height; y++) { - yls = (uint32_t *)(sp + y * src->bytes_per_line); - yld = (uint32_t *)(dp + y * dst->bytes_per_line); - ylw = (uint32_t *)(wp + y * write->bytes_per_line); - yla = (uint8_t *)(ap + y * alpha->width); - - for (x = 0; x < width; x++) { - *ylw = ALPHABLEND24(*yls, *yld, *yla); - yls++; yld++; ylw++; yla++; - } - } - break; - } - } - - } else { - switch(dst->depth) { - case 16: - { - uint16_t *yls, *yld, *ylw; - uint8_t *yla; - - for (y = 0; y < height; y++) { - yls = (uint16_t *)(sp + y * src->bytes_per_line); - yld = (uint16_t *)(dp + y * dst->bytes_per_line); - ylw = (uint16_t *)(wp + y * write->bytes_per_line); - yla = (uint8_t *)(ap + y * alpha->width); - - for (x = 0; x < width; x++) { - *ylw = ALPHABLEND16(*yls, *yld, (*yla * lv) / 255); - yls++; yld++; ylw++; yla++; - } - } - } - break; - case 24: - case 32: - { - uint32_t *yls, *yld, *ylw; - uint8_t *yla; - - for (y = 0; y < height; y++) { - yls = (uint32_t *)(sp + y * src->bytes_per_line); - yld = (uint32_t *)(dp + y * dst->bytes_per_line); - ylw = (uint32_t *)(wp + y * write->bytes_per_line); - yla = (uint8_t *)(ap + y * alpha->width); - - for (x = 0; x < width; x++) { - *ylw = ALPHABLEND24(*yls, *yld, (*yla * lv) / 255); - yls++; yld++; ylw++; yla++; - } - } - break; - } - } - } -} diff --git a/modules/lib/ngraph.h b/modules/lib/ngraph.h index d77bf5b..622c460 100644 --- a/modules/lib/ngraph.h +++ b/modules/lib/ngraph.h @@ -33,9 +33,6 @@ void gr_draw_amap(surface_t *dst, int dx, int dy, uint8_t *src, int width, int h #define gr_bright_dst_only(dst,dx,dy,w,h,lv) gr_copy_bright(dst,dx,dy,dst,dx,dy,w,h,lv) // void gr_bright_dst_only(surface_t *dst, int dx, int dy, int w, int h, int lv); -/* in gre_blend_useamap.c */ -void gre_BlendUseAMap(surface_t *write, int wx, int wy, surface_t *dst, int dx, int dy, surface_t *src, int sx, int sy, int width, int height, surface_t *alpha, int ax, int ay, int lv); - /* in graph_cg.c */ void gr_drawimage24(surface_t *ds, cgdata *cg, int x, int y); void gr_drawimage16(surface_t *ds, cgdata *cg, int x, int y);