Skip to content

Commit aa6ee82

Browse files
committed
Add drawPngFromBuffer
1 parent 281f828 commit aa6ee82

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

src/include/Image.h

+2
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ class Image : virtual public NetworkClient, virtual public Adafruit_GFX
9696
bool drawJpegFromWeb(const char *url, int x, int y, bool dither = 0, bool invert = 0);
9797
bool drawJpegFromWeb(WiFiClient *s, int x, int y, int32_t len, bool dither = 0, bool invert = 0);
9898

99+
bool drawPngFromBuffer(uint8_t *buf, int32_t len, int x, int y, bool dither, bool invert);
100+
99101
bool drawPngFromSd(const char *fileName, int x, int y, bool dither = 0, bool invert = 0);
100102
bool drawPngFromSd(SdFile *p, int x, int y, bool dither = 0, bool invert = 0);
101103

src/include/ImagePNG.cpp

+47
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,53 @@ bool Image::drawPngFromWeb(const char *url, int x, int y, bool dither, bool inve
244244
return ret;
245245
}
246246

247+
/**
248+
* @brief drawPngFromBuffer function draws png image from buffer
249+
*
250+
* @param int32_t len
251+
* size of buffer
252+
* @param int x
253+
* x position for top left image corner
254+
* @param int y
255+
* y position for top left image corner
256+
* @param bool dither
257+
* 1 if using dither, 0 if not
258+
* @param bool invert
259+
* 1 if using invert, 0 if not
260+
*
261+
* @return 1 if drawn successfully, 0 if not
262+
*/
263+
bool Image::drawPngFromBuffer(uint8_t *buf, int32_t len, int x, int y, bool dither, bool invert)
264+
{
265+
if (!buf)
266+
return 0;
267+
268+
_pngDither = dither;
269+
_pngInvert = invert;
270+
lastY = y;
271+
272+
bool ret = 1;
273+
274+
if (dither)
275+
memset(ditherBuffer, 0, sizeof ditherBuffer);
276+
277+
pngle_t *pngle = pngle_new();
278+
_pngX = x;
279+
_pngY = y;
280+
pngle_set_draw_callback(pngle, pngle_on_draw);
281+
282+
if (!buf)
283+
return 0;
284+
285+
if (pngle_feed(pngle, buf, len) < 0)
286+
ret = 0;
287+
288+
pngle_destroy(pngle);
289+
free(buf);
290+
return ret;
291+
}
292+
293+
247294
/**
248295
* @brief drawPngFromWeb function draws png image from sd file
249296
*

0 commit comments

Comments
 (0)