Add font rendering

This commit is contained in:
iabdalkader 2014-09-01 23:41:37 +02:00
parent ee2ba469d8
commit 5fdd6e09a3
9 changed files with 1131 additions and 2 deletions

View File

@ -134,6 +134,7 @@ OBJ += $(addprefix $(BUILD)/$(OMV_DIR)/img/,\
fast.o \
freak.o \
template.o \
font.o \
)
OBJ += $(addprefix $(BUILD)/$(OMV_DIR)/py/, \

@ -1 +1 @@
Subproject commit 84078f85a5135bf83d6bdd655740ac89a97145fd
Subproject commit 33375af4e1e441ad6767102439fe9fe829b3b596

View File

@ -42,6 +42,7 @@ SRCS += $(addprefix img/, \
fast.c \
freak.c \
template.c \
font.c \
)
SRCS += $(addprefix py/, \

1073
src/omv/img/font.c Normal file

File diff suppressed because it is too large Load Diff

9
src/omv/img/font.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef __FONT_H__
#define __FONT_H__
typedef struct {
int w;
int h;
uint8_t data[10];
} glyph_t;
extern const glyph_t font[95];
#endif //__FONT_H__

View File

@ -7,6 +7,7 @@
#include "ff.h"
#include "xalloc.h"
#include "mdefs.h"
#include "font.h"
#define MIN(a,b) \
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
@ -600,7 +601,6 @@ void imlib_draw_rectangle(struct image *image, struct rectangle *r)
image->pixels[(y+i)*col + x + w+1] = c;
}
}
}
void imlib_draw_circle(struct image *image, int cx, int cy, int r)
@ -647,6 +647,27 @@ void imlib_draw_line(image_t *src, int x0, int y0, int x1, int y1)
}
}
// TODO check image bounds
void imlib_draw_string(image_t *image, int x_off, int y_off, const char *str)
{
const glyph_t *g;
uint16_t *data = (uint16_t*)image->pixels;
for(char c; (c=*str); str++) {
if (c < ' ' || c > '~') {
continue;
}
g = &font[c-' '];
for (int y=0; y<g->h; y++) {
for (int x=0; x<g->w; x++) {
if (g->data[y] & (0x80>>x)){
data[(y_off+y)*image->w+x_off+x]=0xFFFF;
}
}
}
x_off += g->w;
}
}
void imlib_histeq(struct image *src)
{
int i, sum;

View File

@ -196,6 +196,7 @@ int16_t *freak_match_keypoints(kp_t *kpts1, int kpts1_size, kp_t *kpts2, int kpt
void imlib_draw_rectangle(struct image *image, struct rectangle *r);
void imlib_draw_circle(struct image *image, int cx, int cy, int r);
void imlib_draw_line(image_t *src, int x0, int y0, int x1, int y1);
void imlib_draw_string(image_t *src, int x, int y, const char *str);
/* Misc */
void imlib_scale(struct image *src, struct image *dst, interp_t interp);

View File

@ -353,6 +353,27 @@ static mp_obj_t py_image_draw_circle(mp_obj_t image_obj, mp_obj_t c_obj, mp_obj_
return mp_const_none;
}
static mp_obj_t py_image_draw_string(mp_obj_t image_obj, mp_obj_t offset_obj, mp_obj_t str_obj)
{
int x,y;
image_t *image = NULL;
// get image pointer
image = py_image_cobj(image_obj);
// get x,y offset
mp_obj_t *array;
mp_obj_get_array_fixed_n(offset_obj, 2, &array);
x = mp_obj_get_int(array[0]);
y = mp_obj_get_int(array[1]);
// get string to draw
const char *str = mp_obj_str_get_str(str_obj);
imlib_draw_string(image, x, y, str);
return mp_const_none;
}
static mp_obj_t py_image_erode(mp_obj_t image_obj, mp_obj_t ksize_obj)
{
image_t *image = NULL;
@ -713,6 +734,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(py_image_morph_obj, py_image_morph);
STATIC MP_DEFINE_CONST_FUN_OBJ_3(py_image_draw_circle_obj, py_image_draw_circle);
STATIC MP_DEFINE_CONST_FUN_OBJ_2(py_image_draw_rectangle_obj, py_image_draw_rectangle);
STATIC MP_DEFINE_CONST_FUN_OBJ_2(py_image_draw_keypoints_obj, py_image_draw_keypoints);
STATIC MP_DEFINE_CONST_FUN_OBJ_3(py_image_draw_string_obj, py_image_draw_string);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_image_find_blobs_obj, py_image_find_blobs);
STATIC MP_DEFINE_CONST_FUN_OBJ_3(py_image_find_template_obj, py_image_find_template);
@ -741,6 +763,7 @@ static const mp_map_elem_t locals_dict_table[] = {
{MP_OBJ_NEW_QSTR(MP_QSTR_draw_circle), (mp_obj_t)&py_image_draw_circle_obj},
{MP_OBJ_NEW_QSTR(MP_QSTR_draw_rectangle), (mp_obj_t)&py_image_draw_rectangle_obj},
{MP_OBJ_NEW_QSTR(MP_QSTR_draw_keypoints), (mp_obj_t)&py_image_draw_keypoints_obj},
{MP_OBJ_NEW_QSTR(MP_QSTR_draw_string), (mp_obj_t)&py_image_draw_string_obj},
/* objects/feature detection */
{MP_OBJ_NEW_QSTR(MP_QSTR_find_blobs), (mp_obj_t)&py_image_find_blobs_obj},

Binary file not shown.