WIP: extend bitmap to y direction

This commit is contained in:
Jonas Diemer 2026-01-12 18:36:07 +01:00
parent 52995fa722
commit 9dc839c244
3 changed files with 39 additions and 12 deletions

View File

@ -152,8 +152,17 @@ void GfxRenderer::drawImage(const uint8_t bitmap[], const int x, const int y, co
einkDisplay.drawImage(bitmap, rotatedX, rotatedY, width, height); einkDisplay.drawImage(bitmap, rotatedX, rotatedY, width, height);
} }
void GfxRenderer::drawVal(const int x, const int y, const uint8_t val) const {
if (renderMode == BW && val < 3) {
drawPixel(x, y);
} else if (renderMode == GRAYSCALE_MSB && (val == 1 || val == 2)) {
drawPixel(x, y, false);
} else if (renderMode == GRAYSCALE_LSB && val == 1) {
drawPixel(x, y, false);
}
}
void GfxRenderer::drawBitmap(const Bitmap& bitmap, const int x, const int y, const int maxWidth, const int maxHeight, void GfxRenderer::drawBitmap(const Bitmap& bitmap, const int x, const int y, const int maxWidth, const int maxHeight,
const float cropX, const float cropY) const { const float cropX, const float cropY, bool extend) const {
float scale = 1.0f; float scale = 1.0f;
bool isScaled = false; bool isScaled = false;
int cropPixX = std::floor(bitmap.getWidth() * cropX / 2.0f); int cropPixX = std::floor(bitmap.getWidth() * cropX / 2.0f);
@ -220,12 +229,29 @@ void GfxRenderer::drawBitmap(const Bitmap& bitmap, const int x, const int y, con
const uint8_t val = outputRow[bmpX / 4] >> (6 - ((bmpX * 2) % 8)) & 0x3; const uint8_t val = outputRow[bmpX / 4] >> (6 - ((bmpX * 2) % 8)) & 0x3;
if (renderMode == BW && val < 3) { drawVal(screenX, screenY, val);
drawPixel(screenX, screenY);
} else if (renderMode == GRAYSCALE_MSB && (val == 1 || val == 2)) { // draw extended pixels
drawPixel(screenX, screenY, false); /// amount of pixels taken from bitmap and repeated to extend
} else if (renderMode == GRAYSCALE_LSB && val == 1) { int extendY = 10; // TODO: fix rounding errors if this is not a divisor of height?
drawPixel(screenX, screenY, false); // don't draw MSB for darker extended area
// if (extend && renderMode != GRAYSCALE_MSB) {
if (extend) {
if (bmpY < extendY) {
for (int ny = 0; ny < extendY; ny++) {
// TODO: handle when extendY > y
const uint8_t rval = val + random(2);
drawVal(screenX, y - (bmpY + (extendY - 3) * (ny)), renderMode == GRAYSCALE_MSB ? rval : val);
}
// drawVal(screenX, 2*y - screenY, val);
}
int endY = y + bitmap.getHeight();
// Serial.printf("[%lu] [GFX] Drawing bottom extension: screenY=%d, endY=%d\n", millis(), screenY, endY);
if (bmpY >= bitmap.getHeight() - extendY) {
for (int ny = 0; ny < extendY; ny++) {
drawVal(screenX, screenY + (ny + 1) * (extendY - 2), val);
}
}
} }
} }
} }

View File

@ -62,12 +62,13 @@ class GfxRenderer {
// Drawing // Drawing
void drawPixel(int x, int y, bool state = true) const; void drawPixel(int x, int y, bool state = true) const;
void drawVal(const int x, const int y, const uint8_t val) const;
void drawLine(int x1, int y1, int x2, int y2, bool state = true) const; void drawLine(int x1, int y1, int x2, int y2, bool state = true) const;
void drawRect(int x, int y, int width, int height, bool state = true) const; void drawRect(int x, int y, int width, int height, bool state = true) const;
void fillRect(int x, int y, int width, int height, bool state = true) const; void fillRect(int x, int y, int width, int height, bool state = true) const;
void drawImage(const uint8_t bitmap[], int x, int y, int width, int height) const; void drawImage(const uint8_t bitmap[], int x, int y, int width, int height) const;
void drawBitmap(const Bitmap& bitmap, int x, int y, int maxWidth, int maxHeight, float cropX = 0, void drawBitmap(const Bitmap& bitmap, int x, int y, int maxWidth, int maxHeight, float cropX = 0, float cropY = 0,
float cropY = 0) const; bool extend = false) const;
// Text // Text
int getTextWidth(int fontId, const char* text, EpdFontFamily::Style style = EpdFontFamily::REGULAR) const; int getTextWidth(int fontId, const char* text, EpdFontFamily::Style style = EpdFontFamily::REGULAR) const;

View File

@ -172,20 +172,20 @@ void SleepActivity::renderBitmapSleepScreen(const Bitmap& bitmap) const {
Serial.printf("[%lu] [SLP] drawing to %d x %d\n", millis(), x, y); Serial.printf("[%lu] [SLP] drawing to %d x %d\n", millis(), x, y);
renderer.clearScreen(); renderer.clearScreen();
renderer.drawBitmap(bitmap, x, y, pageWidth, pageHeight, cropX, cropY); renderer.drawBitmap(bitmap, x, y, pageWidth, pageHeight, cropX, cropY, true);
renderer.displayBuffer(EInkDisplay::HALF_REFRESH); renderer.displayBuffer(EInkDisplay::HALF_REFRESH);
if (bitmap.hasGreyscale()) { if (bitmap.hasGreyscale()) {
bitmap.rewindToData(); bitmap.rewindToData();
renderer.clearScreen(0x00); renderer.clearScreen(0x00);
renderer.setRenderMode(GfxRenderer::GRAYSCALE_LSB); renderer.setRenderMode(GfxRenderer::GRAYSCALE_LSB);
renderer.drawBitmap(bitmap, x, y, pageWidth, pageHeight, cropX, cropY); renderer.drawBitmap(bitmap, x, y, pageWidth, pageHeight, cropX, cropY, true);
renderer.copyGrayscaleLsbBuffers(); renderer.copyGrayscaleLsbBuffers();
bitmap.rewindToData(); bitmap.rewindToData();
renderer.clearScreen(0x00); renderer.clearScreen(0x00);
renderer.setRenderMode(GfxRenderer::GRAYSCALE_MSB); renderer.setRenderMode(GfxRenderer::GRAYSCALE_MSB);
renderer.drawBitmap(bitmap, x, y, pageWidth, pageHeight, cropX, cropY); renderer.drawBitmap(bitmap, x, y, pageWidth, pageHeight, cropX, cropY, true);
renderer.copyGrayscaleMsbBuffers(); renderer.copyGrayscaleMsbBuffers();
renderer.displayGrayBuffer(); renderer.displayGrayBuffer();