Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add drawPngFromBuffer #210

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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