| 595 | } |
| 596 | |
| 597 | static void UpdateGlyphTexture(HFontMap font_map, FontGlyph* g, int32_t x, int32_t y, int offset_y) |
| 598 | { |
| 599 | uint32_t glyph_image_width = g->m_Bitmap.m_Width; |
| 600 | uint32_t glyph_image_height = g->m_Bitmap.m_Height; |
| 601 | uint32_t glyph_image_channels = g->m_Bitmap.m_Channels; |
| 602 | uint8_t* glyph_data = g->m_Bitmap.m_Data; |
| 603 | uint32_t glyph_data_flags = g->m_Bitmap.m_Flags; // E.g. FONT_GLYPH_COMPRESSION_NONE; |
| 604 | uint32_t glyph_data_size = g->m_Bitmap.m_DataSize; |
| 605 | |
| 606 | void* data = 0; |
| 607 | if ((FONT_GLYPH_COMPRESSION_DEFLATE & glyph_data_flags)) |
| 608 | { |
| 609 | // When if came to choosing between the different algorithms, here are some speed/compression tests |
| 610 | // Decoding 100 glyphs |
| 611 | // lz4: 0.1060 ms compression: 72% |
| 612 | // deflate: 0.2190 ms compression: 66% |
| 613 | // png: 0.6930 ms compression: 67% |
| 614 | // webp: 1.5170 ms compression: 55% |
| 615 | // further improvements (different test, Android, 92 glyphs) |
| 616 | // webp 2.9440 ms compression: 55% |
| 617 | // deflate 0.7110 ms compression: 66% |
| 618 | // deflate+delta 0.7680 ms compression: 62% |
| 619 | |
| 620 | FontGlyphInflaterContext deflate_context; |
| 621 | deflate_context.m_Output = font_map->m_CellTempData; |
| 622 | deflate_context.m_Cursor = 0; |
| 623 | dmZlib::Result zlib_result = dmZlib::InflateBuffer(glyph_data, glyph_data_size, &deflate_context, FontGlyphInflater); |
| 624 | if (zlib_result != dmZlib::RESULT_OK) |
| 625 | { |
| 626 | dmLogError("Failed to decompress glyph (%c / %u) in font %s: %d", g->m_Codepoint, g->m_GlyphIndex, dmHashReverseSafe64(font_map->m_NameHash), zlib_result); |
| 627 | return; |
| 628 | } |
| 629 | |
| 630 | uint32_t uncompressed_size = deflate_context.m_Cursor; |
| 631 | delta_decode(font_map->m_CellTempData, uncompressed_size); |
| 632 | |
| 633 | data = font_map->m_CellTempData; |
| 634 | } |
| 635 | else |
| 636 | { |
| 637 | uint32_t num_out_channels; |
| 638 | switch(font_map->m_CacheFormat) |
| 639 | { |
| 640 | case dmGraphics::TEXTURE_FORMAT_LUMINANCE: num_out_channels = 1; break; |
| 641 | case dmGraphics::TEXTURE_FORMAT_RGB: num_out_channels = 3; break; |
| 642 | case dmGraphics::TEXTURE_FORMAT_RGBA: num_out_channels = 4; break; |
| 643 | default: |
| 644 | dmLogWarning("Unknown texture format: %d", font_map->m_CacheFormat); |
| 645 | num_out_channels = glyph_image_channels; |
| 646 | } |
| 647 | |
| 648 | data = glyph_data; |
| 649 | if (glyph_image_channels != num_out_channels) |
| 650 | { |
| 651 | data = font_map->m_CellTempData; |
| 652 | |
| 653 | uint32_t cursor = 0; |
| 654 | uint8_t* tmp = font_map->m_CellTempData;; |
no test coverage detected