From 1e635111d0bc14132a6ce79269de083a06773ca5 Mon Sep 17 00:00:00 2001 From: nitko12 Date: Mon, 21 Sep 2020 15:21:25 +0200 Subject: [PATCH] Fixed double freeing. --- .../5-Inkplate_Maze_Generator.ino | 4 ++-- src/include/Image.h | 5 +---- src/include/ImageBMP.cpp | 6 +++--- test/drawImage/drawImage.ino | 2 +- test/test.ino | 11 +++-------- 5 files changed, 10 insertions(+), 18 deletions(-) diff --git a/examples/4. Others/5-Inkplate_Maze_Generator/5-Inkplate_Maze_Generator.ino b/examples/4. Others/5-Inkplate_Maze_Generator/5-Inkplate_Maze_Generator.ino index 5c2fad7..0f87341 100644 --- a/examples/4. Others/5-Inkplate_Maze_Generator/5-Inkplate_Maze_Generator.ino +++ b/examples/4. Others/5-Inkplate_Maze_Generator/5-Inkplate_Maze_Generator.ino @@ -26,8 +26,8 @@ void loop() // Display the maze void showMaze(const char *maze, int width, int height) { - for (int y = 0; y < height; y++) - for (int x = 0; x < width; x++) + for (int y = 0; y < height; ++y) + for (int x = 0; x < width; ++x) if (maze[x + y * width] == 1) for (int i = 0; i < 4; ++i) { diff --git a/src/include/Image.h b/src/include/Image.h index c630995..e8d827a 100644 --- a/src/include/Image.h +++ b/src/include/Image.h @@ -37,10 +37,7 @@ class Image : virtual public NetworkClient, virtual public Adafruit_GFX const char *fileName, int x, int y, bool dither = 0, bool invert = 0); bool drawBitmapFromSd(SdFile *p, int x, int y, bool dither = 0, bool invert = 0); - [[deprecated("Use drawImage, as this will soon become a private method.")]] bool drawBitmapFromWeb(const char *url, - int x, int y, - bool dither = 0, - bool invert = 0); + bool drawBitmapFromWeb(const char *url, int x, int y, bool dither = 0, bool invert = 0); bool drawBitmapFromWeb(WiFiClient *s, int x, int y, int32_t len, bool dither = 0, bool invert = 0); bool drawJpegFromBuffer(uint8_t *buf, int32_t len, int x, int y, bool dither, bool invert); diff --git a/src/include/ImageBMP.cpp b/src/include/ImageBMP.cpp index 9d88797..9aa7f97 100644 --- a/src/include/ImageBMP.cpp +++ b/src/include/ImageBMP.cpp @@ -109,7 +109,7 @@ bool Image::drawBitmapFromSd(SdFile *p, int x, int y, bool dither, bool invert) bool Image::drawBitmapFromWeb(const char *url, int x, int y, bool dither, bool invert) { bool ret = 0; - int32_t defaultLen = 800 * 600 * 4; + int32_t defaultLen = 800 * 600 * 4 + 150; uint8_t *buf = downloadFile(url, &defaultLen); ret = drawBitmapFromBuffer(buf, x, y, dither, invert); @@ -132,6 +132,7 @@ bool Image::drawBitmapFromWeb(WiFiClient *s, int x, int y, int32_t len, bool dit bool Image::drawBitmapFromBuffer(uint8_t *buf, int x, int y, bool dither, bool invert) { bitmapHeader bmpHeader; + readBmpHeader(buf, &bmpHeader); if (!legalBmp(&bmpHeader)) @@ -148,7 +149,6 @@ bool Image::drawBitmapFromBuffer(uint8_t *buf, int x, int y, bool dither, bool i bufferPtr += ROWSIZE(bmpHeader.width, bmpHeader.color); } - free(buf); return 1; } @@ -163,7 +163,7 @@ void Image::displayBmpLine(int16_t x, int16_t y, bitmapHeader *bmpHeader, bool d switch (c) { case 1: - writePixel(x + j, y, (invert ^ (palette[0] < palette[1])) ^ !!(pixelBuffer[j >> 3] & (1 << (7 - (j & 7))))); + writePixel(x + j, y, (invert ^ (palette[0] > palette[1])) ^ !!(pixelBuffer[j >> 3] & (1 << (7 - (j & 7))))); break; // as for 2 bit, literally cannot find an example online or in PS, so skipped case 4: { diff --git a/test/drawImage/drawImage.ino b/test/drawImage/drawImage.ino index 6bd3e72..433a24b 100644 --- a/test/drawImage/drawImage.ino +++ b/test/drawImage/drawImage.ino @@ -29,7 +29,7 @@ void setup() display.begin(); - display.joinAP("", ""); + display.joinAP("e-radionica.com", "croduino"); Serial.println(); delay(500); diff --git a/test/test.ino b/test/test.ino index f6d5832..7b1b31e 100644 --- a/test/test.ino +++ b/test/test.ino @@ -1,17 +1,13 @@ #include "Inkplate.h" -#include "SdFat.h" -const int n = 500; - -Inkplate display(INKPLATE_3BIT); +Inkplate display(INKPLATE_1BIT); void setup() { Serial.begin(115200); display.begin(); - - display.joinAP("", ""); + Serial.println(display.joinAP("e-radionica.com", "croduino")); delay(500); } @@ -20,8 +16,7 @@ void loop() { display.clearDisplay(); - display.sdCardInit(); - display.drawPngFromSd("png.png", 0, 0, 1, 0); + Serial.println(display.drawBitmapFromWeb("http://img.cale.es/bmp/fasani/5e5ff140694ee", 0, 0, 1, 0)); display.display(); delay(5000);