Skip to content

Commit 29e91e0

Browse files
committed
Fix for changing frame size and disposal method issues
1 parent da9b6fb commit 29e91e0

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

shared-module/displayio/OnDiskGif.c

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,16 @@ static void GIFDraw(GIFDRAW *pDraw) {
7979
uint8_t *s;
8080
uint16_t *d;
8181

82-
int32_t row_start = pDraw->y * bitmap->stride;
82+
int iWidth = pDraw->iWidth;
83+
if (iWidth + pDraw->iX > bitmap->width) {
84+
iWidth = bitmap->width - pDraw->iX;
85+
}
86+
87+
if (pDraw->iY + pDraw->y >= bitmap->height || pDraw->iX >= bitmap->width || iWidth < 1) {
88+
return;
89+
}
90+
91+
int32_t row_start = (pDraw->y + pDraw->iY) * bitmap->stride;
8392
uint32_t *row = bitmap->data + row_start;
8493
s = pDraw->pPixels;
8594
d = (uint16_t *)row;
@@ -88,20 +97,30 @@ static void GIFDraw(GIFDRAW *pDraw) {
8897
pPal = (uint16_t *)pDraw->pPalette;
8998

9099
if (pDraw->ucDisposalMethod == 2) { // restore to background color
91-
memset(d, pDraw->ucBackground, pDraw->iWidth);
100+
// Not supported currently. Need to reset the area the previous frame occupied
101+
// to the background color before the previous frame was drawn
102+
// See: https://github.com/bitbank2/AnimatedGIF/issues/3
103+
104+
// To workaround clear the gif.bitmap object yourself as required.
92105
}
93106

94-
// We always check for transpancy even if the gif does not have it
95-
// as we also convert the color to the palette here
96-
// Could separate it but would not sure it would be much a speed up
97107
uint8_t c, ucTransparent = pDraw->ucTransparent;
98-
for (int x = 0; x < pDraw->iWidth; x++)
99-
{
100-
c = *s++;
101-
if (c != ucTransparent) {
102-
*d = pPal[c];
108+
d += pDraw->iX;
109+
if (pDraw->ucHasTransparency == 1) {
110+
for (int x = 0; x < iWidth; x++)
111+
{
112+
c = *s++;
113+
if (c != ucTransparent) {
114+
*d = pPal[c];
115+
}
116+
d++;
117+
}
118+
} else {
119+
for (int x = 0; x < iWidth; x++)
120+
{
121+
c = *s++;
122+
*d++ = pPal[c];
103123
}
104-
d++;
105124
}
106125
}
107126

0 commit comments

Comments
 (0)