mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2025-12-16 14:17:40 +03:00
Fixed light gray text rendering
This commit is contained in:
parent
6989035ef8
commit
449b3ca161
@ -207,14 +207,20 @@ void GfxRenderer::renderChar(const EpdFontFamily& fontFamily, const uint32_t cp,
|
||||
if (is2Bit) {
|
||||
const uint8_t byte = bitmap[pixelPosition / 4];
|
||||
const uint8_t bit_index = (3 - pixelPosition % 4) * 2;
|
||||
// the direct bit from the font is 0 -> white, 1 -> light gray, 2 -> dark gray, 3 -> black
|
||||
// we swap this to better match the way images and screen think about colors:
|
||||
// 0 -> black, 1 -> dark grey, 2 -> light grey, 3 -> white
|
||||
const uint8_t bmpVal = 3 - (byte >> bit_index) & 0x3;
|
||||
|
||||
const uint8_t val = (byte >> bit_index) & 0x3;
|
||||
if (fontRenderMode == BW && val > 0) {
|
||||
if (renderMode == BW && bmpVal < 3) {
|
||||
// Black (also paints over the grays in BW mode)
|
||||
drawPixel(screenX, screenY, pixelState);
|
||||
} else if (fontRenderMode == GRAYSCALE_MSB && val == 1) {
|
||||
// TODO: Not sure how this anti-aliasing goes on black backgrounds
|
||||
} else if (renderMode == GRAYSCALE_MSB && (bmpVal == 1 || bmpVal == 2)) {
|
||||
// Light gray (also mark the MSB if it's going to be a dark gray too)
|
||||
// We have to flag pixels in reverse for the gray buffers, as 0 leave alone, 1 update
|
||||
drawPixel(screenX, screenY, false);
|
||||
} else if (fontRenderMode == GRAYSCALE_LSB && val == 2) {
|
||||
} else if (renderMode == GRAYSCALE_LSB && bmpVal == 1) {
|
||||
// Dark gray
|
||||
drawPixel(screenX, screenY, false);
|
||||
}
|
||||
} else {
|
||||
|
||||
@ -7,17 +7,17 @@
|
||||
|
||||
class GfxRenderer {
|
||||
public:
|
||||
enum FontRenderMode { BW, GRAYSCALE_LSB, GRAYSCALE_MSB };
|
||||
enum RenderMode { BW, GRAYSCALE_LSB, GRAYSCALE_MSB };
|
||||
|
||||
private:
|
||||
EInkDisplay& einkDisplay;
|
||||
FontRenderMode fontRenderMode;
|
||||
RenderMode renderMode;
|
||||
std::map<int, EpdFontFamily> fontMap;
|
||||
void renderChar(const EpdFontFamily& fontFamily, uint32_t cp, int* x, const int* y, bool pixelState,
|
||||
EpdFontStyle style) const;
|
||||
|
||||
public:
|
||||
explicit GfxRenderer(EInkDisplay& einkDisplay) : einkDisplay(einkDisplay), fontRenderMode(BW) {}
|
||||
explicit GfxRenderer(EInkDisplay& einkDisplay) : einkDisplay(einkDisplay), renderMode(BW) {}
|
||||
~GfxRenderer() = default;
|
||||
|
||||
// Setup
|
||||
@ -41,15 +41,17 @@ class GfxRenderer {
|
||||
int getTextWidth(int fontId, const char* text, EpdFontStyle style = REGULAR) const;
|
||||
void drawCenteredText(int fontId, int y, const char* text, bool black = true, EpdFontStyle style = REGULAR) const;
|
||||
void drawText(int fontId, int x, int y, const char* text, bool black = true, EpdFontStyle style = REGULAR) const;
|
||||
void setFontRenderMode(const FontRenderMode mode) { this->fontRenderMode = mode; }
|
||||
int getSpaceWidth(int fontId) const;
|
||||
int getLineHeight(int fontId) const;
|
||||
|
||||
// Grayscale functions
|
||||
void setRenderMode(const RenderMode mode) { this->renderMode = mode; }
|
||||
void copyGrayscaleLsbBuffers() const;
|
||||
void copyGrayscaleMsbBuffers() const;
|
||||
void displayGrayBuffer() const;
|
||||
|
||||
// Low level functions
|
||||
uint8_t* getFrameBuffer() const;
|
||||
void swapBuffers() const;
|
||||
void grayscaleRevert() const;
|
||||
void copyGrayscaleLsbBuffers() const;
|
||||
void copyGrayscaleMsbBuffers() const;
|
||||
void displayGrayBuffer() const;
|
||||
};
|
||||
|
||||
@ -301,19 +301,19 @@ void EpubReaderScreen::renderContents(std::unique_ptr<Page> page) {
|
||||
// TODO: Only do this if font supports it
|
||||
{
|
||||
renderer.clearScreen(0x00);
|
||||
renderer.setFontRenderMode(GfxRenderer::GRAYSCALE_LSB);
|
||||
renderer.setRenderMode(GfxRenderer::GRAYSCALE_LSB);
|
||||
page->render(renderer, READER_FONT_ID);
|
||||
renderer.copyGrayscaleLsbBuffers();
|
||||
|
||||
// Render and copy to MSB buffer
|
||||
renderer.clearScreen(0x00);
|
||||
renderer.setFontRenderMode(GfxRenderer::GRAYSCALE_MSB);
|
||||
renderer.setRenderMode(GfxRenderer::GRAYSCALE_MSB);
|
||||
page->render(renderer, READER_FONT_ID);
|
||||
renderer.copyGrayscaleMsbBuffers();
|
||||
|
||||
// display grayscale part
|
||||
renderer.displayGrayBuffer();
|
||||
renderer.setFontRenderMode(GfxRenderer::BW);
|
||||
renderer.setRenderMode(GfxRenderer::BW);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user