Skip to content

Commit 1502614

Browse files
committed
piuGIF constructor accepts buffer as alternative to path
1 parent 4dcdb8f commit 1502614

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

modules/piu/MC/gif/piuGIFImage.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct PiuGIFImageStruct {
2828
PiuBehaviorPart;
2929
PiuContentPart;
3030
xsSlot* path;
31+
xsSlot* buffer;
3132
PiuColorRecord color;
3233
xsSlot* gif;
3334
PiuDimension gifWidth;
@@ -82,11 +83,14 @@ const xsHostHooks ICACHE_FLASH_ATTR PiuGIFImageHooks = {
8283
void PiuGIFImageBind(void* it, PiuApplication* application, PiuView* view)
8384
{
8485
PiuGIFImage* self = it;
85-
if ((*self)->path) {
86+
if ((*self)->path || (*self)->buffer) {
8687
xsBeginHost((*self)->the);
8788
xsVars(2);
8889
xsVar(0) = xsReference((*self)->reference);
89-
xsVar(1) = *((*self)->path);
90+
if ((*self)->path)
91+
xsVar(1) = *((*self)->path);
92+
else
93+
xsVar(1) = xsReference((*self)->buffer);
9094
xsResult = xsCall2(xsVar(0), xsID_load, xsVar(1), ((*self)->flags & piuColorized) ? xsTrue : xsFalse);
9195
(*self)->gif = xsToReference(xsResult);
9296
(*self)->gifWidth = xsToInteger(xsGet(xsResult, xsID_width));
@@ -106,6 +110,11 @@ void PiuGIFImageDictionary(xsMachine* the, void* it)
106110
xsSlot* path = PiuString(xsResult);
107111
(*self)->path = path;
108112
}
113+
else
114+
if (xsFindResult(xsArg(1), xsID_buffer)) {
115+
xsSlot* buffer = xsToReference(xsResult);
116+
(*self)->buffer = buffer;
117+
}
109118
if (xsFindResult(xsArg(1), xsID_color)) {
110119
PiuColorRecord color;
111120
PiuColorDictionary(the, &xsResult, &color);
@@ -151,7 +160,10 @@ void PiuGIFImageMark(xsMachine* the, void* it, xsMarkRoot markRoot)
151160
{
152161
PiuGIFImage self = it;
153162
PiuContentMark(the, it, markRoot);
154-
PiuMarkString(the, self->path);
163+
if (self->path)
164+
PiuMarkString(the, self->path);
165+
if (self->buffer)
166+
PiuMarkReference(the, self->buffer);
155167
PiuMarkReference(the, self->gif);
156168
}
157169

modules/piu/MC/gif/piuGIFImage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const gifImage = {
77
_create($, it) @ "PiuGIFImage_create",
88

99
load(path, colorized) {
10-
const gif = new ReadGIF(new Resource(path), colorized ? {pixelFormat: Bitmap.Gray16} : {});
10+
const gif = new ReadGIF(("string" === typeof path) ? new Resource(path) : path, colorized ? {pixelFormat: Bitmap.Gray16} : {});
1111
this.duration = gif.duration;
1212
this.time = 0;
1313
return gif;

0 commit comments

Comments
 (0)