mirror of
git://projects.qi-hardware.com/antorcha.git
synced 2024-11-01 07:24:58 +02:00
tools/libtxt/: add image drawing (future <IMG name> directive)
This commit is contained in:
parent
e2eced62a2
commit
2a83110369
@ -17,7 +17,7 @@
|
|||||||
#include "libtxt.h"
|
#include "libtxt.h"
|
||||||
|
|
||||||
|
|
||||||
static int *do_edit(uint8_t *canvas, int width, int height,
|
static int do_edit(uint8_t *canvas, int width, int height,
|
||||||
const struct edit *e, const char **error)
|
const struct edit *e, const char **error)
|
||||||
{
|
{
|
||||||
struct image *img;
|
struct image *img;
|
||||||
@ -48,6 +48,14 @@ static int *do_edit(uint8_t *canvas, int width, int height,
|
|||||||
if (!font)
|
if (!font)
|
||||||
goto fail;
|
goto fail;
|
||||||
break;
|
break;
|
||||||
|
case edit_img:
|
||||||
|
img = load_image(e->u.s, error);
|
||||||
|
if (!img)
|
||||||
|
return 0;
|
||||||
|
xo = draw_image(canvas, width, height, img, x, y);
|
||||||
|
free_image(img);
|
||||||
|
x += xo;
|
||||||
|
break;
|
||||||
case edit_spc:
|
case edit_spc:
|
||||||
spc = e->u.n;
|
spc = e->u.n;
|
||||||
break;
|
break;
|
||||||
@ -73,9 +81,9 @@ static int *do_edit(uint8_t *canvas, int width, int height,
|
|||||||
}
|
}
|
||||||
e = e->next;
|
e = e->next;
|
||||||
}
|
}
|
||||||
|
return 1;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
free_image(img);
|
|
||||||
free_font(font);
|
free_font(font);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -246,34 +246,50 @@ void free_font(struct font *font)
|
|||||||
/* ----- Drawing on a canvas ----------------------------------------------- */
|
/* ----- Drawing on a canvas ----------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
|
static void do_draw(uint8_t *canvas, int width, int heigth,
|
||||||
|
const struct image *img, int ox, int oy, int w, int h, int x, int y)
|
||||||
|
{
|
||||||
|
int ix, iy, xt;
|
||||||
|
|
||||||
|
for (ix = 0; ix != w; ix++) {
|
||||||
|
if (x+ix >= width)
|
||||||
|
continue;
|
||||||
|
for (iy = 0; iy != h; iy++) {
|
||||||
|
if (y+iy >= heigth)
|
||||||
|
continue;
|
||||||
|
xt = ox+ix;
|
||||||
|
if (img->data[(oy+iy)*img->span+(xt >> 3)] &
|
||||||
|
(1 << (xt & 7))) {
|
||||||
|
xt = x+ix;
|
||||||
|
canvas[((y+iy)*width+xt) >> 3] |= 1 << (xt & 7);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int draw_image(void *canvas, int width, int height,
|
||||||
|
const struct image *img, int x, int y)
|
||||||
|
{
|
||||||
|
do_draw(canvas, width, height, img, 0, 0, img->w, img->h, x, y);
|
||||||
|
return img->w;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int draw_char(void *canvas, int width, int height,
|
int draw_char(void *canvas, int width, int height,
|
||||||
const struct font *font, char c, int x, int y)
|
const struct font *font, char c, int x, int y)
|
||||||
{
|
{
|
||||||
const struct image *img = font->img;
|
|
||||||
uint8_t *p = canvas;
|
|
||||||
const char *cp;
|
const char *cp;
|
||||||
const struct sym *sym;
|
const struct sym *sym;
|
||||||
int ix, iy, xt;
|
|
||||||
|
|
||||||
cp = strchr(charset, c);
|
cp = strchr(charset, c);
|
||||||
if (!cp)
|
if (!cp)
|
||||||
return 0;
|
return 0;
|
||||||
sym = font->sym+(cp-charset);
|
sym = font->sym+(cp-charset);
|
||||||
|
|
||||||
for (ix = 0; ix != sym->w; ix++) {
|
do_draw(canvas, width, height,
|
||||||
if (x+ix >= width)
|
font->img, sym->x, sym->y, sym->w, sym->h, x, y);
|
||||||
continue;
|
|
||||||
for (iy = 0; iy != sym->h; iy++) {
|
|
||||||
if (y+iy >= height)
|
|
||||||
continue;
|
|
||||||
xt = sym->x+ix;
|
|
||||||
if (img->data[(sym->y+iy)*img->span+(xt >> 3)] &
|
|
||||||
(1 << (xt & 7))) {
|
|
||||||
xt = x+ix;
|
|
||||||
p[((y+iy)*width+xt) >> 3] |= 1 << (xt & 7);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sym->w;
|
return sym->w;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ struct edit {
|
|||||||
enum edit_type {
|
enum edit_type {
|
||||||
edit_string,
|
edit_string,
|
||||||
edit_font,
|
edit_font,
|
||||||
|
edit_img,
|
||||||
edit_spc,
|
edit_spc,
|
||||||
edit_xoff,
|
edit_xoff,
|
||||||
edit_xpos,
|
edit_xpos,
|
||||||
@ -53,6 +54,9 @@ struct edit {
|
|||||||
struct image *load_image(const char *name, const char **error);
|
struct image *load_image(const char *name, const char **error);
|
||||||
void free_image(struct image *img);
|
void free_image(struct image *img);
|
||||||
|
|
||||||
|
int draw_image(void *canvas, int width, int height,
|
||||||
|
const struct image *img, int x, int y);
|
||||||
|
|
||||||
struct font *make_font(struct image *img, const char **error);
|
struct font *make_font(struct image *img, const char **error);
|
||||||
void free_font(struct font *font);
|
void free_font(struct font *font);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user