From 9c6423bf9991e99fdaa8e046bc2d61e6e01cc84f Mon Sep 17 00:00:00 2001 From: kichikuou Date: Wed, 19 Feb 2025 08:45:23 +0900 Subject: [PATCH] drawtext: Remove 8-bit text rendering function --- modules/CMakeLists.txt | 1 - modules/SACT/sactcg.c | 4 +- modules/SACT/sprite_sel.c | 12 +++--- modules/lib/drawtext.c | 23 +---------- modules/lib/drawtext.h | 1 - modules/lib/graph_expandcolor_blend.c | 59 --------------------------- modules/lib/ngraph.h | 5 --- src/ags.c | 11 +---- src/ags.h | 3 +- src/font.c | 19 +-------- src/font.h | 3 +- 11 files changed, 14 insertions(+), 127 deletions(-) delete mode 100644 modules/lib/graph_expandcolor_blend.c diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index 486eaa2..eb1097f 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -65,7 +65,6 @@ add_library(modules STATIC lib/list.c lib/surface.c lib/cg.c - lib/graph_expandcolor_blend.c lib/graph_fillrect_amap.c lib/graph_copy_amap.c lib/graph_blend_amap.c diff --git a/modules/SACT/sactcg.c b/modules/SACT/sactcg.c index 732201a..c77944c 100644 --- a/modules/SACT/sactcg.c +++ b/modules/SACT/sactcg.c @@ -213,7 +213,7 @@ void scg_create_text(int wNumCG, int wSize, int wR, int wG, int wB, int wText) { if (svar_length(wText) == 0) return; ags_setFont(FONT_GOTHIC, wSize); - SDL_Surface *glyph = ags_drawStringToRGBASurface(svar_get(wText), wR, wG, wB); + SDL_Surface *glyph = ags_drawStringToSurface(svar_get(wText), wR, wG, wB); SDL_Surface *sf = SDL_CreateRGBSurfaceWithFormat(0, glyph->w, wSize, 32, SDL_PIXELFORMAT_ARGB8888); SDL_SetSurfaceBlendMode(glyph, SDL_BLENDMODE_NONE); @@ -238,7 +238,7 @@ void scg_create_textnum(int wNumCG, int wSize, int wR, int wG, int wB, int wFigs sprintf(s, ss, wValue); ags_setFont(FONT_GOTHIC, wSize); - SDL_Surface *glyph = ags_drawStringToRGBASurface(s, wR, wG, wB); + SDL_Surface *glyph = ags_drawStringToSurface(s, wR, wG, wB); SDL_Surface *sf = SDL_CreateRGBSurfaceWithFormat(0, glyph->w, wSize, 32, SDL_PIXELFORMAT_ARGB8888); SDL_SetSurfaceBlendMode(glyph, SDL_BLENDMODE_NONE); diff --git a/modules/SACT/sprite_sel.c b/modules/SACT/sprite_sel.c index a9487a5..ddba66b 100644 --- a/modules/SACT/sprite_sel.c +++ b/modules/SACT/sprite_sel.c @@ -160,9 +160,8 @@ static void update_selwindow(sprite_t *sp) { } // 選択肢文字列 - gr_expandcolor_blend(sf0, x0, y0, - sact.sel.charcanvas, 0, 0, - sact.sel.charcanvas->w, sact.sel.charcanvas->h, 255, 255, 255); + SDL_BlitSurface(sact.sel.charcanvas, NULL, sf0->sdl_surface, + &(SDL_Rect){x0, y0, sact.sel.charcanvas->w, sact.sel.charcanvas->h}); } // 選択ウィンドの準備 @@ -171,7 +170,8 @@ static void setup_selwindow() { int i; // 選択肢文字用 canvas - sact.sel.charcanvas = SDL_CreateRGBSurfaceWithFormat(0, sp->cg1->sf->w, sp->cg1->sf->h, 8, SDL_PIXELFORMAT_INDEX8); + sact.sel.charcanvas = SDL_CreateRGBSurfaceWithFormat(0, sp->cg1->sf->w, sp->cg1->sf->h, 32, SDL_PIXELFORMAT_ARGB8888); + SDL_SetSurfaceBlendMode(sact.sel.charcanvas, SDL_BLENDMODE_BLEND); dt_setfont(sact.sel.font_type, sact.sel.font_size); @@ -182,9 +182,9 @@ static void setup_selwindow() { // 文字の場所計算 x = 0; // 行そろえは無し y = (i - 1) * (sact.sel.font_size + sact.sel.linespace); - dt_drawtext(sact.sel.charcanvas, + dt_drawtext_col(sact.sel.charcanvas, x + sact.sel.frame_dot, y + sact.sel.frame_dot, - sact.sel.elem[i]); + sact.sel.elem[i], 255, 255, 255); } // デフォルトで選択される選択肢がある場合、そこへカーソルを移動 diff --git a/modules/lib/drawtext.c b/modules/lib/drawtext.c index be2d251..67d08d3 100644 --- a/modules/lib/drawtext.c +++ b/modules/lib/drawtext.c @@ -54,27 +54,6 @@ void dt_setfont(FontType type, int size) { fsize = size; } -/** - * surface にモノクロ文字を描画。アンチエイリアスされており256階調 - * 書き出すsurfaceは8ビットである必要あり - * - * @param sf: 描画する surface - * @param x: 描画位置X座標 - * @param y: 描画位置Y座標 - * @param buf: 描画文字列 (SJIS) - * @return: 実際に描画した幅 -*/ -int dt_drawtext(SDL_Surface *sf, int x, int y, char *buf) { - ags_setFont(ftype, fsize); - SDL_Surface *glyph = ags_drawStringToSurface(buf); - if (glyph == NULL) return 0; - - SDL_Rect rect = {x, y, glyph->w, glyph->h}; - SDL_BlitSurface(glyph, NULL, sf, &rect); - SDL_FreeSurface(glyph); - return rect.w; -} - /** * surface にカラー文字を描画。alphamap に256階調のアンチエイリアスされた * 文字を描き、pixelmap には、色情報を矩形で描く @@ -90,7 +69,7 @@ int dt_drawtext(SDL_Surface *sf, int x, int y, char *buf) { */ int dt_drawtext_col(SDL_Surface *sf, int x, int y, char *buf, int r, int g, int b) { ags_setFont(ftype, fsize); - SDL_Surface *glyph = ags_drawStringToRGBASurface(buf, r, g, b); + SDL_Surface *glyph = ags_drawStringToSurface(buf, r, g, b); if (glyph == NULL) return 0; SDL_Rect rect = {x, y, glyph->w, glyph->h}; diff --git a/modules/lib/drawtext.h b/modules/lib/drawtext.h index 1c74903..09072a7 100644 --- a/modules/lib/drawtext.h +++ b/modules/lib/drawtext.h @@ -29,7 +29,6 @@ struct SDL_Surface; void dt_setfont(FontType type, int size); -int dt_drawtext(struct SDL_Surface *sf, int x, int y, char *buf); int dt_drawtext_col(struct SDL_Surface *sf, int x, int y, char *buf, int r, int g, int b); #endif /* __DRAWTEXT_H__ */ diff --git a/modules/lib/graph_expandcolor_blend.c b/modules/lib/graph_expandcolor_blend.c deleted file mode 100644 index c5e4e5d..0000000 --- a/modules/lib/graph_expandcolor_blend.c +++ /dev/null @@ -1,59 +0,0 @@ -// color expansion and blending -// 8bppのモノクロをcolでブレンド - -#include -#include "portab.h" -#include "surface.h" -#include "ngraph.h" -#include "ags.h" - -void gr_expandcolor_blend(surface_t *dst, int dx, int dy, SDL_Surface *src, int sx, int sy, int sw, int sh, int r, int g, int b) { - uint8_t *sp, *dp; - int x, y; - int col; - - MyRectangle src_window = { 0, 0, src->w, src->h }; - MyRectangle dst_window = { 0, 0, dst->width, dst->height }; - if (!ags_clipCopyRect(&src_window, &dst_window, &sx, &sy, &dx, &dy, &sw, &sh)) { - return; - } - - sp = PIXEL_AT(src, sx, sy); - dp = GETOFFSET_PIXEL(dst, dx, dy); - - switch(dst->depth) { - case 16: - col = PIX16(r, g, b); - { - uint16_t *yd; - uint8_t *ys; - for (y = 0; y < sh; y++) { - ys = (uint8_t *)(sp + y * src->pitch); - yd = (uint16_t *)(dp + y * dst->bytes_per_line); - for (x = 0; x < sw; x++) { - if (*ys) { - *yd = ALPHABLEND16(col, *yd, (uint8_t)*ys); - } - ys++; yd++; - } - } - } - break; - case 32: - case 24: { - uint32_t *yd; - uint8_t *ys; - col = PIX24(r, g, b); - for (y = 0; y < sh; y++) { - ys = (uint8_t *)(sp + y * src->pitch); - yd = (uint32_t *)(dp + y * dst->bytes_per_line); - for (x = 0; x < sw; x++) { - if (*ys) { - *yd = ALPHABLEND24(col, *yd, (uint8_t)*ys); - } - ys++; yd++; - } - } - break; - }} -} diff --git a/modules/lib/ngraph.h b/modules/lib/ngraph.h index 71a9f3d..acb0b76 100644 --- a/modules/lib/ngraph.h +++ b/modules/lib/ngraph.h @@ -17,11 +17,6 @@ struct SDL_Surface; bool gr_clip(surface_t *ss, int *sx, int *sy, int *sw, int *sh, surface_t *ds, int *dx, int *dy); bool gr_clip_xywh(surface_t *ss, int *sx, int *sy, int *sw, int *sh); - -/* in graph_expandcolor_blend.c */ -// 8bppのモノクロをcolでブレンド -void gr_expandcolor_blend(surface_t *dst, int dx, int dy, struct SDL_Surface *src, int sx, int sy, int sw, int sh, int r, int g, int b); - /* in graph_fillrect_amap.c */ void gr_fill_alpha_map(surface_t *dst, int dx, int dy, int dw, int dh, int lv); diff --git a/src/ags.c b/src/ags.c index 6259c01..a26b789 100644 --- a/src/ags.c +++ b/src/ags.c @@ -448,16 +448,9 @@ int ags_drawString(int x, int y, const char *src, int col, MyRectangle *rect_out return r.w; } -SDL_Surface *ags_drawStringToSurface(const char *str) { +SDL_Surface *ags_drawStringToSurface(const char *str, int r, int g, int b) { char *utf8 = toUTF8(str); - SDL_Surface *sf = font_get_glyph(utf8); - free(utf8); - return sf; -} - -SDL_Surface *ags_drawStringToRGBASurface(const char *str, int r, int g, int b) { - char *utf8 = toUTF8(str); - SDL_Surface *sf = font_get_glyph_rgb(utf8, r, g, b); + SDL_Surface *sf = font_get_glyph(utf8, r, g, b); free(utf8); return sf; } diff --git a/src/ags.h b/src/ags.h index cd4bca3..e6ad3ef 100644 --- a/src/ags.h +++ b/src/ags.h @@ -221,8 +221,7 @@ extern void ags_setFont(FontType type, int size); extern void ags_setFontWithWeight(FontType type, int size, int weight); extern void ags_setTextDecorationType(TextDecorationType type); extern void ags_setTextDecorationColor(int color); -extern struct SDL_Surface *ags_drawStringToSurface(const char *str); -extern struct SDL_Surface *ags_drawStringToRGBASurface(const char *str, int r, int g, int b); +extern struct SDL_Surface *ags_drawStringToSurface(const char *str, int r, int g, int b); /* カーソル関係 */ extern void ags_setCursorType(int type); diff --git a/src/font.c b/src/font.c index 4ddb60e..edc4c9b 100644 --- a/src/font.c +++ b/src/font.c @@ -116,24 +116,7 @@ void font_select(FontType type, int size, int weight) { TTF_SetFontStyle(fontset->id, weight > 5 ? TTF_STYLE_BOLD : TTF_STYLE_NORMAL); } -SDL_Surface *font_get_glyph(const char *str_utf8) { - if (!fontset) - return NULL; - - SDL_Surface *fs; - SDL_Color color = {255, 255, 255, 0}; - if (this.antialiase_on) { - fs = TTF_RenderUTF8_Shaded(fontset->id, str_utf8, color, color); - } else { - fs = TTF_RenderUTF8_Solid(fontset->id, str_utf8, color); - } - if (!fs) - WARNING("Text rendering failed: %s", TTF_GetError()); - - return fs; -} - -SDL_Surface *font_get_glyph_rgb(const char *str_utf8, int r, int g, int b) { +SDL_Surface *font_get_glyph(const char *str_utf8, int r, int g, int b) { if (!fontset) return NULL; diff --git a/src/font.h b/src/font.h index 6060659..a6a6a2e 100644 --- a/src/font.h +++ b/src/font.h @@ -37,8 +37,7 @@ extern void font_set_name_and_index(FontType type, const char *name, int index); extern void font_set_antialias(bool enable); extern bool font_get_antialias(void); extern void font_select(FontType type, int size, int weight); -extern struct SDL_Surface *font_get_glyph(const char *str_utf8); -extern struct SDL_Surface *font_get_glyph_rgb(const char *str_utf8, int r, int g, int b); +extern struct SDL_Surface *font_get_glyph(const char *str_utf8, int r, int g, int b); extern SDL_Rect font_draw_glyph(int x, int y, const char *str_utf8, uint8_t col); #ifdef __EMSCRIPTEN__