From e5047dfbdf51523ae103da8916b0f69d417f6b9b Mon Sep 17 00:00:00 2001 From: kichikuou Date: Sun, 6 Jan 2019 16:08:20 +0900 Subject: [PATCH] Image16: alpha level support --- src/image.c | 12 ++++++------ src/image.h | 2 ++ src/sdl_image.c | 12 ++++++++++++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/image.c b/src/image.c index 1189e21..baf55db 100644 --- a/src/image.c +++ b/src/image.c @@ -268,7 +268,7 @@ static int trans_index2pixel(int depth, int i) { } /* 16bitCGの ALPHALEVELを指定 */ -static WORD *changeImageAlphaLevel(cgdata *cg) { +BYTE *changeImage16AlphaLevel(cgdata *cg) { WORD *new_pic = malloc(sizeof(WORD) * cg->width * cg->height), *new_pic_; WORD *pic = (WORD *)cg->pic; int pixels = cg->width * cg->height; @@ -279,7 +279,7 @@ static WORD *changeImageAlphaLevel(cgdata *cg) { *new_pic = RGB_ALPHALEVEL16(*pic, cg->alphalevel); new_pic++; pic++; } - return new_pic_; + return (BYTE *)new_pic_; } @@ -528,12 +528,12 @@ void image_drawImage8_fromData(agsurface_t *dib, cgdata *cg, int dx, int dy, int * dibに16bitCGの描画 */ void image_drawImage16_fromData(agsurface_t *dib, cgdata *cg, int x, int y, int w, int h) { - WORD *pic_save = NULL; + BYTE *pic_save = NULL; /* set alpha Level */ if (cg->alphalevel != 255) { - pic_save = (WORD *)cg->pic; - cg->pic = (BYTE *)changeImageAlphaLevel(cg); + pic_save = cg->pic; + cg->pic = changeImage16AlphaLevel(cg); } if (cg->spritecolor >= 0) { @@ -544,7 +544,7 @@ void image_drawImage16_fromData(agsurface_t *dib, cgdata *cg, int x, int y, int if (cg->alphalevel != 255) { free(cg->pic); - cg->pic = (BYTE *)pic_save; + cg->pic = pic_save; } } diff --git a/src/image.h b/src/image.h index 844cc05..6ea6e65 100644 --- a/src/image.h +++ b/src/image.h @@ -67,5 +67,7 @@ extern void image_trans_pixel_24to24p(agsurface_t *src, agsurface_t *dst); extern void image_Mosaic(agsurface_t *dib, int sx, int sy, int w, int h, int dx, int dy, int slice); extern void image_fillRectangleNeg(agsurface_t *dib, int x, int y, int w, int h, int col); +extern BYTE *changeImage16AlphaLevel(cgdata *cg); + #endif /* __IMAGE__ */ diff --git a/src/sdl_image.c b/src/sdl_image.c index f6bde68..a0722bb 100644 --- a/src/sdl_image.c +++ b/src/sdl_image.c @@ -154,6 +154,13 @@ void sdl_drawImage16_fromData(cgdata *cg, int dx, int dy, int w, int h) { /* draw alpha pixel */ SDL_Surface *s; SDL_Rect r_src,r_dst; + BYTE *pic_save = NULL; + + /* set alpha Level */ + if (cg->alphalevel != 255) { + pic_save = cg->pic; + cg->pic = changeImage16AlphaLevel(cg); + } if (cg->alpha != NULL && cg->spritecolor != -1) { unsigned short *p_src = (WORD *)(cg->pic + cg->data_offset); @@ -208,6 +215,11 @@ void sdl_drawImage16_fromData(cgdata *cg, int dx, int dy, int w, int h) { setRect(r_dst, dx, dy, w, h); SDL_BlitSurface(s, &r_src, sdl_dib, &r_dst); SDL_FreeSurface(s); + + if (cg->alphalevel != 255) { + free(cg->pic); + cg->pic = pic_save; + } } /*