Skip to content

Commit

Permalink
Add drawPngFromBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjtwomey committed Jul 6, 2023
1 parent 281f828 commit aa6ee82
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/include/Image.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ class Image : virtual public NetworkClient, virtual public Adafruit_GFX
bool drawJpegFromWeb(const char *url, int x, int y, bool dither = 0, bool invert = 0);
bool drawJpegFromWeb(WiFiClient *s, int x, int y, int32_t len, bool dither = 0, bool invert = 0);

bool drawPngFromBuffer(uint8_t *buf, int32_t len, int x, int y, bool dither, bool invert);

bool drawPngFromSd(const char *fileName, int x, int y, bool dither = 0, bool invert = 0);
bool drawPngFromSd(SdFile *p, int x, int y, bool dither = 0, bool invert = 0);

Expand Down
47 changes: 47 additions & 0 deletions src/include/ImagePNG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,53 @@ bool Image::drawPngFromWeb(const char *url, int x, int y, bool dither, bool inve
return ret;
}

/**
* @brief drawPngFromBuffer function draws png image from buffer
*
* @param int32_t len
* size of buffer
* @param int x
* x position for top left image corner
* @param int y
* y position for top left image corner
* @param bool dither
* 1 if using dither, 0 if not
* @param bool invert
* 1 if using invert, 0 if not
*
* @return 1 if drawn successfully, 0 if not
*/
bool Image::drawPngFromBuffer(uint8_t *buf, int32_t len, int x, int y, bool dither, bool invert)
{
if (!buf)
return 0;

_pngDither = dither;
_pngInvert = invert;
lastY = y;

bool ret = 1;

if (dither)
memset(ditherBuffer, 0, sizeof ditherBuffer);

pngle_t *pngle = pngle_new();
_pngX = x;
_pngY = y;
pngle_set_draw_callback(pngle, pngle_on_draw);

if (!buf)
return 0;

if (pngle_feed(pngle, buf, len) < 0)
ret = 0;

pngle_destroy(pngle);
free(buf);
return ret;
}


/**
* @brief drawPngFromWeb function draws png image from sd file
*
Expand Down

0 comments on commit aa6ee82

Please sign in to comment.