mirror of
https://github.com/paperdash/device-epd.git
synced 2024-11-04 12:00:27 +00:00
#36 improve memory usage for image handling
This commit is contained in:
parent
20ddc7dc3e
commit
5a104aba2e
@ -102,7 +102,7 @@ void ImageFlushBuffer()
|
||||
ImageProcess.dithering = false;
|
||||
}
|
||||
|
||||
void ImageProcessPixel(uint32_t x, uint32_t y, uint8_t rgba[4])
|
||||
void ImageProcessPixel(uint16_t x, uint16_t y, uint8_t rgba[4])
|
||||
{
|
||||
uint8_t r = rgba[0]; // 0 - 255
|
||||
uint8_t g = rgba[1]; // 0 - 255
|
||||
|
@ -19,7 +19,7 @@ void ImageNew(int x, int y, int w, int h, bool dithering);
|
||||
void ImageWriteBuffer(uint8_t buff[], size_t c);
|
||||
void ImageFlushBuffer();
|
||||
|
||||
void ImageProcessPixel(uint32_t x, uint32_t y, uint8_t rgba[4]);
|
||||
void ImageProcessPixel(uint16_t x, uint16_t y, uint8_t rgba[4]);
|
||||
|
||||
uint16_t drawRGB24toRGB565(uint8_t r, uint8_t g, uint8_t b);
|
||||
uint32_t drawRGB565toBGRA32(uint16_t color);
|
||||
|
@ -7,9 +7,14 @@
|
||||
File tmpFileBuffer;
|
||||
void renderMcuBlock(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t *bitmap);
|
||||
|
||||
static constexpr int MAX_WIDTH = 640; // TODO get info from display
|
||||
static constexpr uint16_t MAX_WIDTH = 640; // TODO get info from display 800 works :D
|
||||
static constexpr uint8_t BLOCK_SIZE = 16; // max MCU block size
|
||||
static uint32_t blockDelta[BLOCK_SIZE * MAX_WIDTH + 1];
|
||||
static uint16_t blockDelta[BLOCK_SIZE * MAX_WIDTH + 1];
|
||||
|
||||
// TODO uint32_t auf uint16_t ändern um speicher zu sparen
|
||||
// https://os.mbed.com/handbook/C-Data-Types#integer-data-types
|
||||
// image size limit prüfen damit alles in ein int16_t passt !
|
||||
// dann ist genug speicher da :D
|
||||
|
||||
#define minimum(a, b) (((a) < (b)) ? (a) : (b))
|
||||
|
||||
@ -158,8 +163,17 @@ void jpegFlushFramebuffer()
|
||||
// print information about the image to the serial port
|
||||
//jpegInfo();
|
||||
|
||||
// render the image onto the screen at coordinate 0,0
|
||||
renderJPEG(0, 0);
|
||||
// TODO use display size
|
||||
if (JpegDec.width > 800 || JpegDec.height > 480)
|
||||
{
|
||||
Serial.println("image to big! skip rendering");
|
||||
}
|
||||
else
|
||||
{
|
||||
// render the image onto the screen at coordinate 0,0
|
||||
renderJPEG(0, 0);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -171,10 +185,10 @@ void jpegFlushFramebuffer()
|
||||
}
|
||||
}
|
||||
|
||||
void renderMcuBlockPixel(uint32_t x, uint32_t y, uint32_t color)
|
||||
void renderMcuBlockPixel(uint16_t x, uint16_t y, uint16_t color)
|
||||
{
|
||||
// collect all mcu blocks for current row
|
||||
uint32_t blockPageY = y - ((y / JpegDec.MCUHeight) * JpegDec.MCUHeight);
|
||||
uint16_t blockPageY = y - ((y / JpegDec.MCUHeight) * JpegDec.MCUHeight);
|
||||
blockDelta[(blockPageY * MAX_WIDTH) + x] = color;
|
||||
|
||||
// full mcu row is complete now
|
||||
@ -182,15 +196,15 @@ void renderMcuBlockPixel(uint32_t x, uint32_t y, uint32_t color)
|
||||
{
|
||||
// MCU block sizes: 8x8, 16x8 or 16x16
|
||||
|
||||
uint32_t originOffsetY = ((y / JpegDec.MCUHeight) * JpegDec.MCUHeight);
|
||||
uint16_t originOffsetY = ((y / JpegDec.MCUHeight) * JpegDec.MCUHeight);
|
||||
|
||||
for (uint16_t _y = 0; _y < JpegDec.MCUHeight; _y++)
|
||||
{
|
||||
for (uint16_t _x = 0; _x < JpegDec.width; _x++)
|
||||
{
|
||||
uint32_t originX = _x;
|
||||
uint32_t originY = originOffsetY + _y;
|
||||
uint32_t originColor = blockDelta[(_y * MAX_WIDTH) + _x];
|
||||
uint16_t originX = _x;
|
||||
uint16_t originY = originOffsetY + _y;
|
||||
uint16_t originColor = blockDelta[(_y * MAX_WIDTH) + _x];
|
||||
|
||||
uint8_t r = ((((originColor >> 11) & 0x1F) * 527) + 23) >> 6;
|
||||
uint8_t g = ((((originColor >> 5) & 0x3F) * 259) + 33) >> 6;
|
||||
|
Loading…
Reference in New Issue
Block a user