diff --git a/ext/native/gfx_es2/draw_text_android.cpp b/ext/native/gfx_es2/draw_text_android.cpp index fecad36bb9..b5afccbf96 100644 --- a/ext/native/gfx_es2/draw_text_android.cpp +++ b/ext/native/gfx_es2/draw_text_android.cpp @@ -191,7 +191,6 @@ void TextDrawerAndroid::DrawStringBitmap(std::vector &bitmapData, TextS assert(env_->GetArrayLength(imageData) == imageWidth * imageHeight); if (texFormat == Draw::DataFormat::B4G4R4A4_UNORM_PACK16 || texFormat == Draw::DataFormat::R4G4B4A4_UNORM_PACK16) { bitmapData.resize(entry.bmWidth * entry.bmHeight * sizeof(uint16_t)); - uint16_t *bitmapData16 = (uint16_t *)&bitmapData[0]; for (int x = 0; x < entry.bmWidth; x++) { for (int y = 0; y < entry.bmHeight; y++) { @@ -200,7 +199,17 @@ void TextDrawerAndroid::DrawStringBitmap(std::vector &bitmapData, TextS bitmapData16[entry.bmWidth * y + x] = (uint16_t)v; } } + } else if (texFormat == Draw::DataFormat::R8_UNORM) { + bitmapData.resize(entry.bmWidth * entry.bmHeight); + for (int x = 0; x < entry.bmWidth; x++) { + for (int y = 0; y < entry.bmHeight; y++) { + uint32_t v = jimage[imageWidth * y + x]; + v = (v >> 12) & 0xF; // Just grab some bits from the green channel. + bitmapData[entry.bmWidth * y + x] = (uint8_t)(v | (v << 4)); + } + } } else { + ELOG("Bad TextDrawer format"); assert(false); } env_->ReleaseIntArrayElements(imageData, jimage, 0); diff --git a/ext/native/gfx_es2/draw_text_qt.cpp b/ext/native/gfx_es2/draw_text_qt.cpp index a6bcbcebee..406507518f 100644 --- a/ext/native/gfx_es2/draw_text_qt.cpp +++ b/ext/native/gfx_es2/draw_text_qt.cpp @@ -125,7 +125,15 @@ void TextDrawerQt::DrawStringBitmap(std::vector &bitmapData, TextString bitmapData16[entry.bmWidth * y + x] = 0xfff0 | (image.pixel(x, y) >> 28); } } + } else if (texFormat == Draw::DataFormat::R8_UNORM) { + bitmapData.resize(entry.bmWidth * entry.bmHeight); + for (int x = 0; x < entry.bmWidth; x++) { + for (int y = 0; y < entry.bmHeight; y++) { + bitmapData[entry.bmWidth * y + x] = image.pixel(x, y) >> 24; + } + } } else { + ELOG("Bad TextDrawer format"); assert(false); } } diff --git a/ext/native/gfx_es2/draw_text_win.cpp b/ext/native/gfx_es2/draw_text_win.cpp index ddfb144432..9da3cda741 100644 --- a/ext/native/gfx_es2/draw_text_win.cpp +++ b/ext/native/gfx_es2/draw_text_win.cpp @@ -1,3 +1,4 @@ +#include #include "base/display.h" #include "base/logging.h" #include "base/stringutil.h" @@ -271,6 +272,17 @@ void TextDrawerWin32::DrawStringBitmap(std::vector &bitmapData, TextStr bitmapData16[entry.bmWidth * y + x] = (bAlpha << 12) | 0x0fff; } } + } else if (texFormat == Draw::DataFormat::R8_UNORM) { + bitmapData.resize(entry.bmWidth * entry.bmHeight); + for (int y = 0; y < entry.bmHeight; y++) { + for (int x = 0; x < entry.bmWidth; x++) { + uint8_t bAlpha = ctx_->pBitmapBits[MAX_TEXT_WIDTH * y + x] & 0xff; + bitmapData[entry.bmWidth * y + x] = bAlpha; + } + } + } else { + ELOG("Bad TextDrawer format"); + assert(false); } }