diff --git a/src/imageJPEG.cpp b/src/imageJPEG.cpp index 2cabb5b..ebff6e8 100644 --- a/src/imageJPEG.cpp +++ b/src/imageJPEG.cpp @@ -5,16 +5,16 @@ #include "imageJPEG.h" #include "display.h" -#define DEBUG = 1 +//#define DEBUG = 1 File tmpFileBuffer; bool tft_output(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t *bitmap); static constexpr int MAX_WIDTH = 640; -static constexpr uint8_t BLOCK_SIZE = 15; +static constexpr uint8_t BLOCK_SIZE = 16; static uint8_t blockDelta[BLOCK_SIZE * MAX_WIDTH + 1]; -static int16_t curRowDeltaJ[MAX_WIDTH + 1]; +//static int16_t curRowDeltaJ[MAX_WIDTH + 1]; unsigned int pixelCount = 0; @@ -24,13 +24,6 @@ void setupImageJPEG() { Serial.println("setupJPEG"); - // The jpeg image can be scaled by a factor of 1, 2, 4, or 8 - //TJpgDec.setJpgScale(1); - - // The decoder must be given the exact name of the rendering function above - //TJpgDec.setCallback(tft_output); - - //memset(blockDelta, 0, sizeof(blockDelta)); } void jpegOpenFramebuffer() @@ -137,7 +130,7 @@ void renderJPEG(int xpos, int ypos) win_h = min_h; // calculate how many pixels must be drawn - uint32_t mcu_pixels = win_w * win_h; + //uint32_t mcu_pixels = win_w * win_h; // draw image block if it will fit on the screen if ((mcu_x + win_w) <= display.width() && (mcu_y + win_h) <= display.height()) @@ -194,29 +187,57 @@ void jpegFlushFramebuffer() jpegInfo(); // render the image onto the screen at coordinate 0,0 - renderJPEG(0, 0); - - /* - uint16_t w = 0, h = 0; - TJpgDec.getFsJpgSize(&w, &h, "/tmp.jpeg"); - Serial.print("Image size: "); - Serial.print(w); - Serial.print("x"); - Serial.println(h); - TJpgDec.drawFsJpg(0, 0, "/tmp.jpeg"); - */ + if (JpegDec.width > 0 && JpegDec.height) { + renderJPEG(0, 0); + } else { + Serial.println("!!!! unkown jpeg format !!!!"); + } } } void on_drawPixel(uint32_t x, uint32_t y, uint32_t color) { - pixelCount++; - - uint32_t blockPageY = y - ((y / 16) * 16); + // fill block + uint32_t blockPageY = y - ((y / JpegDec.MCUHeight) * JpegDec.MCUHeight); blockDelta[(blockPageY * MAX_WIDTH) + x] = color; + + // wir sind im letzten mcu block + // letzter pixel + if (x == JpegDec.width -1 && (y +1) % JpegDec.MCUHeight == 0) { + // mcu block complete + //Serial.println("letzter pixel :-), der ganze block ist jetzt fertig und bereit zur ausgabe"); + + uint32_t originOffsetY = ((y / JpegDec.MCUHeight) * JpegDec.MCUHeight); + + Serial.printf("render block: y: %d - %d \n", originOffsetY, originOffsetY + 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; // + (blockPageY * JpegDec.MCUHeight); + uint8_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; + uint8_t b = (((originColor & 0x1F) * 527) + 23) >> 6; + + uint8_t rgba[4] = {r, g, b, 0}; + ImageProcessPixel(originX, originY, rgba); + } + } + + // clean buffer + memset(blockDelta, 0, sizeof(blockDelta)); + } + + + pixelCount++; // TODO bessere lösung finden ! - if (pixelCount == 10240) + // MCU größen: 8x8, 16x8 or 16x16 + if (false && pixelCount == 10240) // 10240 / 640 = JpegDec.MCUWidth * JpegDec.MCUSPerRow { // new block uint32_t originOffsetY = ((y / 16) * 16); @@ -262,7 +283,7 @@ void on_drawPixel(uint32_t x, uint32_t y, uint32_t color) } // clean buffer - memset(blockDelta, 0, sizeof(blockDelta)); + //memset(blockDelta, 0, sizeof(blockDelta)); pixelCount = 0; } @@ -273,6 +294,8 @@ void on_drawPixel(uint32_t x, uint32_t y, uint32_t color) // you will need to adapt this function to suit. bool tft_output(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t *bitmap) { + //Serial.printf("tft_output, x: %d, y: %d, w: %d, h: %d\n", x, y, w, h); + if (false && y == 0) { //tft_output: x = 0 y = 0 w = 16 h = 16 @@ -302,34 +325,61 @@ bool tft_output(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t *bitmap) for (int16_t i = 0; i < w; i++) { // debug - if (_y == 10 && x + i >= 200 && x + i <= 250) + /* + if (false && _y == 10 && x + i <= 130) { uint32_t originColor = bitmap[j * w + i]; - uint8_t b = originColor & 0x001F; // 5 bits blue - uint8_t g = originColor & 0x07E0; // 6 bits green - uint8_t r = originColor & 0xF800; // 5 bits red +/* +geht + uint8_t b = (originColor & 0x001F); // 5 bits blue + uint8_t g = (originColor & 0x07E0) >> 5; // 6 bits green + uint8_t r = (originColor & 0xF800) >> 11; // 5 bits red Serial.print("Pixel @ y: "); Serial.print(_y); Serial.print(" x: "); Serial.print(x + i); + Serial.print(" Color, R:"); + Serial.print(r * 255 / 31); + Serial.print(", G:"); + Serial.print(g * 255 / 63); + Serial.print(", B:"); + Serial.print(b * 255 / 31); +* + //Serial.print(", color:"); + //Serial.println(originColor); + + + // geht auch + uint8_t r = ((((originColor >> 11) & 0x1F) * 527) + 23) >> 6; + uint8_t g = ((((originColor >> 5) & 0x3F) * 259) + 33) >> 6; + uint8_t b = (((originColor & 0x1F) * 527) + 23) >> 6; + Serial.print("Pixel @ y: "); + Serial.print(_y); + Serial.print(" x: "); + Serial.print(x + i); + Serial.print(" Color, R:"); Serial.print(r); Serial.print(", G:"); Serial.print(g); Serial.print(", B:"); Serial.println(b); + +/* + unsigned _r = (originColor & 0xF800) >> 8; // rrrrr... ........ -> rrrrr000 + unsigned _g = (originColor & 0x07E0) >> 3; // .....ggg ggg..... -> gggggg00 + unsigned _b = (originColor & 0x1F) << 3; // ............bbbbb -> bbbbb000 + Serial.printf("r: %d, g: %d, b: %d\n", _r, _g, _b); + } + */ on_drawPixel(x + i, _y, bitmap[j * w + i]); } } - if (false && y == 0) - { - Serial.println(pixelCount); - } // Return 1 to decode next block return 1;