@@ -79,7 +79,16 @@ static void GIFDraw(GIFDRAW *pDraw) {
79
79
uint8_t * s ;
80
80
uint16_t * d ;
81
81
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 ;
83
92
uint32_t * row = bitmap -> data + row_start ;
84
93
s = pDraw -> pPixels ;
85
94
d = (uint16_t * )row ;
@@ -88,20 +97,30 @@ static void GIFDraw(GIFDRAW *pDraw) {
88
97
pPal = (uint16_t * )pDraw -> pPalette ;
89
98
90
99
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.
92
105
}
93
106
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
97
107
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 ];
103
123
}
104
- d ++ ;
105
124
}
106
125
}
107
126
0 commit comments