drawtext: Remove 8-bit text rendering function

This commit is contained in:
kichikuou
2025-02-19 09:59:22 +09:00
parent 4f3b73c1ac
commit 9c6423bf99
11 changed files with 14 additions and 127 deletions
-1
View File
@@ -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
+2 -2
View File
@@ -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);
+6 -6
View File
@@ -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);
}
// デフォルトで選択される選択肢がある場合、そこへカーソルを移動
+1 -22
View File
@@ -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};
-1
View File
@@ -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__ */
-59
View File
@@ -1,59 +0,0 @@
// color expansion and blending
// 8bppのモノクロをcolでブレンド
#include <SDL.h>
#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;
}}
}
-5
View File
@@ -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);
+2 -9
View File
@@ -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;
}
+1 -2
View File
@@ -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);
+1 -18
View File
@@ -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;
+1 -2
View File
@@ -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__