Skip to content

Commit

Permalink
optimization and fix to win_font
Browse files Browse the repository at this point in the history
  • Loading branch information
codewitch-honey-crisis committed Jan 23, 2025
1 parent 41416eb commit 2d9de49
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "htcw_gfx",
"version": "2.0.5",
"version": "2.0.6",
"description": "A device independent graphics library for embedded and IoT devices",
"keywords": ["tft", "lcd","e-paper","e-ink", "graphics", "spi", "parallel", "i2c", "drawing", "jpg", "ttf","vlw", "font", "svg","2d", "vector"],
"authors": {
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=htcw_gfx
version=2.0.5
version=2.0.6
author=honey the codewitch
maintainer=honey the codewitch
sentence=Provides cross platform graphics
Expand Down
4 changes: 2 additions & 2 deletions src/gfx_draw_icon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class xdraw_icon {
return r;
}
int w = srcr.x2 - srcr.x1 + 1, h = srcr.y2 - srcr.y1 + 1;
if (!Destination::caps::blt) {
if (!Destination::caps::blt && !Destination::caps::blt_spans) {
auto full_bmp = create_bitmap_from(destination, dstr.dimensions());
if (full_bmp.begin() != nullptr) {
r = copy_to_fast<decltype(full_bmp), Destination, Destination::caps::copy_to>::do_copy(full_bmp, destination, dstr, {0, 0});
Expand Down Expand Up @@ -139,7 +139,7 @@ class xdraw_icon {
return r;
}
if (a != oa || obgpx.native_value != bgpx.native_value) {
dpx = fgpx.blend(bgpx, a * alpha_factor);
dpx = fgpx.blend(bgpx, af);
}

//r=xdraw_point::point(full_bmp,(spoint16)dpt,dpx);
Expand Down
16 changes: 10 additions & 6 deletions src/source/gfx_win_font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ gfx_result win_font::initialize() {
}
uint16_t shift=bits::from_le(m_stream->read<uint16_t>());
size_t ii = 0;
while(true) {
while(m_font_offset<0) {
uint16_t rtype=bits::from_le(m_stream->read<uint16_t>());
if(0==rtype)
break; // end of resource table
Expand Down Expand Up @@ -117,6 +117,7 @@ gfx_result win_font::initialize() {
}
m_stream->seek(m_font_offset);
uint16_t version = bits::from_le(m_stream->read<uint16_t>());
m_stream->seek(m_font_offset+0x42);
uint16_t ftype = bits::from_le(m_stream->read<uint16_t>());
if(ftype & 1) {
// Font is a vector font
Expand Down Expand Up @@ -195,7 +196,6 @@ gfx_result win_font::on_measure(int32_t codepoint1,int32_t codepoint2, font_glyp
return gfx_result::success;
}
gfx_result win_font::on_draw(bitmap<alpha_pixel<8>>& destination,int32_t codepoint, int32_t glyph_index) const {
//return gfx_result::success;
if(codepoint<0||codepoint>255) {
return gfx_result::invalid_argument;
}
Expand All @@ -204,17 +204,21 @@ gfx_result win_font::on_draw(bitmap<alpha_pixel<8>>& destination,int32_t codepoi
return res;
}
uint16_t width = bits::from_le(m_stream->read<uint16_t>());
size_t width_bytes = bitmap<gsc_pixel<1>>::sizeof_buffer(size16(width,1));
size_t width_bytes = (width+7)/8;

long long offs = (m_char_table_len==4)?bits::from_le(m_stream->read<uint16_t>()):bits::from_le(m_stream->read<uint32_t>());
for(size_t j=0;j<m_line_height;++j) {
uint32_t accum = 0;
uint32_t m = ((uint32_t)1) << (width - 1);
uint8_t* paccum = (uint8_t*)&accum;
for (size_t i = 0; i < width_bytes; ++i) {
unsigned long long bytepos = offs+i*m_line_height+j;

m_stream->seek(bytepos+m_font_offset);
(*paccum++) = m_stream->read<uint8_t>();
accum<<=8;
accum|=m_stream->read<uint8_t>();;
}
int shift = (width_bytes*8)-width;
accum>>=shift;
uint32_t m = ((uint32_t)1) << (width - 1);
for(int i = 0;i<width;++i) {
if(accum & m) {
destination.point(point16(i,j),alpha_pixel<8>(255));
Expand Down

0 comments on commit 2d9de49

Please sign in to comment.