Skip to content

Commit

Permalink
piuGIF constructor accepts buffer as alternative to path
Browse files Browse the repository at this point in the history
  • Loading branch information
phoddie committed Apr 13, 2021
1 parent 4dcdb8f commit 1502614
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
18 changes: 15 additions & 3 deletions modules/piu/MC/gif/piuGIFImage.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct PiuGIFImageStruct {
PiuBehaviorPart;
PiuContentPart;
xsSlot* path;
xsSlot* buffer;
PiuColorRecord color;
xsSlot* gif;
PiuDimension gifWidth;
Expand Down Expand Up @@ -82,11 +83,14 @@ const xsHostHooks ICACHE_FLASH_ATTR PiuGIFImageHooks = {
void PiuGIFImageBind(void* it, PiuApplication* application, PiuView* view)
{
PiuGIFImage* self = it;
if ((*self)->path) {
if ((*self)->path || (*self)->buffer) {
xsBeginHost((*self)->the);
xsVars(2);
xsVar(0) = xsReference((*self)->reference);
xsVar(1) = *((*self)->path);
if ((*self)->path)
xsVar(1) = *((*self)->path);
else
xsVar(1) = xsReference((*self)->buffer);
xsResult = xsCall2(xsVar(0), xsID_load, xsVar(1), ((*self)->flags & piuColorized) ? xsTrue : xsFalse);
(*self)->gif = xsToReference(xsResult);
(*self)->gifWidth = xsToInteger(xsGet(xsResult, xsID_width));
Expand All @@ -106,6 +110,11 @@ void PiuGIFImageDictionary(xsMachine* the, void* it)
xsSlot* path = PiuString(xsResult);
(*self)->path = path;
}
else
if (xsFindResult(xsArg(1), xsID_buffer)) {
xsSlot* buffer = xsToReference(xsResult);
(*self)->buffer = buffer;
}
if (xsFindResult(xsArg(1), xsID_color)) {
PiuColorRecord color;
PiuColorDictionary(the, &xsResult, &color);
Expand Down Expand Up @@ -151,7 +160,10 @@ void PiuGIFImageMark(xsMachine* the, void* it, xsMarkRoot markRoot)
{
PiuGIFImage self = it;
PiuContentMark(the, it, markRoot);
PiuMarkString(the, self->path);
if (self->path)
PiuMarkString(the, self->path);
if (self->buffer)
PiuMarkReference(the, self->buffer);
PiuMarkReference(the, self->gif);
}

Expand Down
2 changes: 1 addition & 1 deletion modules/piu/MC/gif/piuGIFImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const gifImage = {
_create($, it) @ "PiuGIFImage_create",

load(path, colorized) {
const gif = new ReadGIF(new Resource(path), colorized ? {pixelFormat: Bitmap.Gray16} : {});
const gif = new ReadGIF(("string" === typeof path) ? new Resource(path) : path, colorized ? {pixelFormat: Bitmap.Gray16} : {});
this.duration = gif.duration;
this.time = 0;
return gif;
Expand Down

0 comments on commit 1502614

Please sign in to comment.