Skip to content

Commit

Permalink
skip space rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
nihui committed Dec 8, 2023
1 parent 8393c79 commit 04f680c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 50 deletions.
42 changes: 34 additions & 8 deletions src/mat_pixel_drawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1316,10 +1316,10 @@ void resize_bilinear_font(const unsigned char* font_bitmap, unsigned char* resiz
short* rows1 = (short*)rowsbuf1;

{
short* rows0p = rows0;
short* rows1p = rows1;
for (int dx = 0; dx < w; dx++)
{
rows0p[dx] = 0;
rows1p[dx] = 0;
}
}

Expand Down Expand Up @@ -1580,11 +1580,18 @@ void draw_text_c1(unsigned char* pixels, int w, int h, int stride, const char* t
// newline
cursor_x = x;
cursor_y += fontpixelsize * 2;
continue;
}

if (ch == ' ')
{
cursor_x += fontpixelsize;
continue;
}

if (isprint(ch) != 0)
{
const unsigned char* font_bitmap = mono_font_data[ch - ' '];
const unsigned char* font_bitmap = mono_font_data[ch - '!'];

// draw resized character
resize_bilinear_font(font_bitmap, resized_font_bitmap, fontpixelsize);
Expand Down Expand Up @@ -1640,12 +1647,18 @@ void draw_text_c2(unsigned char* pixels, int w, int h, int stride, const char* t
// newline
cursor_x = x;
cursor_y += fontpixelsize * 2;
continue;
}

if (ch == ' ')
{
cursor_x += fontpixelsize;
continue;
}

if (isprint(ch) != 0)
{
int font_bitmap_index = ch - ' ';
const unsigned char* font_bitmap = mono_font_data[font_bitmap_index];
const unsigned char* font_bitmap = mono_font_data[ch - '!'];

// draw resized character
resize_bilinear_font(font_bitmap, resized_font_bitmap, fontpixelsize);
Expand Down Expand Up @@ -1702,12 +1715,18 @@ void draw_text_c3(unsigned char* pixels, int w, int h, int stride, const char* t
// newline
cursor_x = x;
cursor_y += fontpixelsize * 2;
continue;
}

if (ch == ' ')
{
cursor_x += fontpixelsize;
continue;
}

if (isprint(ch) != 0)
{
int font_bitmap_index = ch - ' ';
const unsigned char* font_bitmap = mono_font_data[font_bitmap_index];
const unsigned char* font_bitmap = mono_font_data[ch - '!'];

// draw resized character
resize_bilinear_font(font_bitmap, resized_font_bitmap, fontpixelsize);
Expand Down Expand Up @@ -1765,11 +1784,18 @@ void draw_text_c4(unsigned char* pixels, int w, int h, int stride, const char* t
// newline
cursor_x = x;
cursor_y += fontpixelsize * 2;
continue;
}

if (ch == ' ')
{
cursor_x += fontpixelsize;
continue;
}

if (isprint(ch) != 0)
{
const unsigned char* font_bitmap = mono_font_data[ch - ' '];
const unsigned char* font_bitmap = mono_font_data[ch - '!'];

// draw resized character
resize_bilinear_font(font_bitmap, resized_font_bitmap, fontpixelsize);
Expand Down
43 changes: 1 addition & 42 deletions src/mat_pixel_drawing_font.h
Original file line number Diff line number Diff line change
@@ -1,45 +1,4 @@
static const unsigned char mono_font_data[95][40 * 10] = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0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