clean big font stuff

This commit is contained in:
tTh 2022-09-15 20:14:59 +02:00
parent e5ecb0eb13
commit 01e6b0103f
4 changed files with 6447 additions and 52 deletions

1
.gitignore vendored
View File

@ -9,6 +9,7 @@ Lib/testtga
Lib/t_png
Lib/t_t16x24
Lib/testbmp
Lib/*.tga
Tests/*.tga
Tests/*.gif

6400
Datas/16x24thin Normal file

File diff suppressed because it is too large Load Diff

View File

@ -10,5 +10,10 @@ int main(int argc, char *argv[])
Image_print_version(2);
Image_print_sizeof_structs("foo");
if (2==argc)
Image_t16x24_essai("16x24thin", argv[1], "16x24.tga");
else
Image_t16x24_essai("16x24thin", "0123456789abcdef", "16x24.tga");
return 0;
}

View File

@ -16,20 +16,24 @@ typedef struct {
} Char_16x24;
/* go, go, go, have a global var */
Char_16x24 chars_16x24[256];
/* 14 septembre 2020, make it static */
static Char_16x24 chars_16x24[256];
/*::------------------------------------------------------------------::*/
/*
il n'y a encore rien dans cette fonction, car je suis en train
de construire un éditeur de fonte adapté a _mes_ besoins.
dès qu'il commencera à être utilisable, et surtout dès que les
dès qu'il commencera a etre utilisable, et surtout dès que les
spécifications du format de fichier seront relativement figées,
je commencerais à coder la chose.
*/
/* 15 septembre 2022 : rien n'est fait, c'est un scandale ! */
int Image_t16x24_binload(char *fontname, uint8_t *zone, int flag)
{
fprintf(stderr, "Don't know how to load '%s' in binary mode\n", fontname);
fprintf(stderr, " address %p flags 0x%x\n", zone, flag);
return FUNC_NOT_FINISH;
}
@ -40,20 +44,17 @@ int Image_t16x24_txtload(char *fontname, uint8_t *zone, int flags)
{
FILE *fp;
int numchar;
int foo, bar, x, y, eol, mask;
int foo, x, y, eol, mask;
char ligne[20+1];
uint16_t mot;
if ( NULL == (fp=Image_must_fopen(fontname, "r", 0)) )
{
fprintf(stderr, ">>> %s ( '%s' %p 0x%x )\n", __func__, fontname, zone, flags);
if ( NULL == (fp=Image_must_fopen(fontname, "r", 0)) ) {
fprintf(stderr, "can't open %s\n", fontname);
return FILE_NOT_FOUND;
}
#if DEBUG_LEVEL
fprintf(stderr, "%s: trying to load '%s' (%d)\n", __func__, fontname, flags);
#endif
/* 16 juin 2015 : now we can erase the whole font by
setting bit 0 of flags to one */
if (flags & 1) {
@ -61,20 +62,17 @@ if (flags & 1) {
memset(chars_16x24, 0, sizeof(chars_16x24));
}
while ( 1 == fscanf(fp, "%d\n", &numchar) )
{
if ( (numchar<0) || (numchar>255) )
{
while ( 1 == fscanf(fp, "%d\n", &numchar) ) {
if ( (numchar<0) || (numchar>255) ) {
fprintf(stderr, "char %d out of range\n", numchar);
break;
}
#if DEBUG_LEVEL > 1
fprintf(stderr, "------- Char %3d '%c'\n", numchar,
fprintf(stderr, "-- char %3d '%c'\n", numchar,
isprint(numchar) ? numchar : ' ');
#endif
for (y=0; y<24; y++)
{
for (y=0; y<24; y++) {
/* lecture d'une ligne d'ascii-pixels */
memset(ligne, '\0', 20);
if ( NULL==fgets(ligne, 20, fp) )
@ -83,7 +81,7 @@ while ( 1 == fscanf(fp, "%d\n", &numchar) )
}
foo = strlen(ligne);
eol = ligne[16];
if (foo!=17 || eol!='\n')
if (17!=foo || '\n'!=eol)
{
fprintf(stderr, "%s: bad line: %3d %3d %3d\n",
__func__, y, foo, eol);
@ -124,8 +122,8 @@ return 0;
/*::------------------------------------------------------------------::*/
int Image_t16x24_pltch_exp(Image_Desc *img, int lettre, int xpos, int ypos)
{
int x, y;
uint16_t mask;
int x, y;
uint16_t mask;
#if DEBUG_LEVEL > 1
@ -136,13 +134,11 @@ fprintf(stderr, "%s: lettre %3d '%c' %4d %4d\n", __func__, lettre,
for (x=0; x<16; x++)
for (y=0; y<24; y++)
Image_plotRGB(img, x+xpos, y+ypos, 60, 60, 80);
for (y=0; y<24; y++)
{
for (y=0; y<24; y++) {
mask = 0x8000;
for (x=0; x<16; x++)
{
if (chars_16x24[lettre].bits[y] & mask)
{
for (x=0; x<16; x++) {
if (chars_16x24[lettre].bits[y] & mask) {
#if DEBUG_LEVEL > 2
putchar('X');
#endif
@ -164,29 +160,28 @@ return FUNC_IS_BETA;
int Image_t16x24_pltch_1(Image_Desc *img, int lettre, int xpos, int ypos,
RGBA *pap, RGBA *ink, int flags)
{
int x, y, rs, gs, bs;
int rp, gp, bp;
int x2, y2;
int x, y, rs, gs, bs;
int rp, gp, bp;
int x2, y2;
uint16_t mask;
/* safety plug */
if (flags) {
fprintf(stderr, "in %s, useless flags 0x%x is useless\n",
__func__, flags);
}
#if DEBUG_LEVEL > 1
fprintf(stderr, "%s: ltr %3d '%c' %4d %4d\n", __func__, lettre,
isprint(lettre) ? lettre : ' ', xpos, ypos);
#endif
for (y=0; y<24; y++)
{
for (y=0; y<24; y++) {
mask = 0x8000;
y2 = y + ypos;
for (x=0; x<16; x++)
{
for (x=0; x<16; x++) {
x2 = x + xpos;
Image_getRGB(img, x2, y2, &rs, &gs, &bs);
if (chars_16x24[lettre].bits[y] & mask)
{
if (chars_16x24[lettre].bits[y] & mask) {
#if DEBUG_LEVEL > 1
putchar('O');
#endif
@ -194,8 +189,7 @@ for (y=0; y<24; y++)
gp = ((gs*(255-ink->a))+(ink->g*ink->a)) / 255;
bp = ((bs*(255-ink->a))+(ink->b*ink->a)) / 255;
}
else
{
else {
#if DEBUG_LEVEL > 1
putchar('.');
#endif
@ -214,7 +208,6 @@ for (y=0; y<24; y++)
return FUNC_IS_ALPHA;/* BETIC ? */
}
/*::------------------------------------------------------------------::*/
/*::------------------------------------------------------------------::*/
int Image_t16x24_pltstr_1(Image_Desc *img, char *str, int x, int y,
RGBA *paper, RGBA *ink, int flags)
{
@ -225,15 +218,14 @@ len = strlen(str);
fprintf(stderr, "%s: '%s' at %d,%d\n", __func__, str, x, y);
#endif
for (foo=0; foo<len; foo++)
{
for (foo=0; foo<len; foo++) {
#if DEBUG_LEVEL > 1
fprintf(stderr, "%4d %c\n", foo, str[foo]);
#endif
Image_t16x24_pltch_1(img, str[foo], x+(foo*16), y, paper, ink, flags);
}
return FUNC_IS_ALPHA; /* BETIC ? */
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
/*::------------------------------------------------------------------::*/
@ -255,14 +247,13 @@ ltxt = strlen(texte);
largeur = 16 * ltxt;
img = Image_alloc(largeur, 24, 3);
if (NULL == img)
{
if (NULL == img) {
fprintf(stderr, "no mem in %s\n", __func__);
abort();
}
Image_clear(img, 0, 0, 0);
for (foo=0; foo<ltxt; foo++)
{
for (foo=0; foo<ltxt; foo++) {
Image_t16x24_pltch_exp(img, texte[foo], foo*16, 0);
}
@ -288,8 +279,8 @@ foo = Image_t16x24_txtload(fontname, NULL, 1);
Image_print_error("fonte 16x24, txtload", foo);
img = Image_alloc(W_IMG, H_IMG, 3);
if (NULL == img)
{
if (NULL == img) {
fprintf(stderr, "no mem in %s\n", __func__);
abort();
}
Image_clear(img, 0, 0, 0);
@ -300,11 +291,9 @@ paper.r = paper.g = paper.b = paper.a = 0;
ink.r = ink.g = ink.b = 192; ink.a = 255;
ichar = 0;
for (ix=0; ix<16; ix++)
{
for (ix=0; ix<16; ix++) {
px = 4 + (ix * S_X);
for (iy=0; iy<16; iy++)
{
for (iy=0; iy<16; iy++) {
py = 4 + (iy * S_Y);
Image_t16x24_pltch_exp(img, ichar, px+4, py);