PPGe: Support 8-bit text bitmaps from TextDrawer.

This commit is contained in:
Unknown W. Brackets 2020-03-10 09:29:13 -07:00
parent 5141dc7e91
commit fbf4769ea6
3 changed files with 30 additions and 1 deletions

View file

@ -191,7 +191,6 @@ void TextDrawerAndroid::DrawStringBitmap(std::vector<uint8_t> &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<uint8_t> &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);

View file

@ -125,7 +125,15 @@ void TextDrawerQt::DrawStringBitmap(std::vector<uint8_t> &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);
}
}

View file

@ -1,3 +1,4 @@
#include <cassert>
#include "base/display.h"
#include "base/logging.h"
#include "base/stringutil.h"
@ -271,6 +272,17 @@ void TextDrawerWin32::DrawStringBitmap(std::vector<uint8_t> &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);
}
}