@@ -76,41 +76,33 @@ static void GIFDraw(GIFDRAW *pDraw) {
7676
7777 displayio_bitmap_t * bitmap = (displayio_bitmap_t * )pDraw -> pUser ;
7878
79- // mp_printf(&mp_plat_print, "GD: y%d iX%d iY%d iW%d iH%d Trans%d hasT%d bk%d pUser %x bmp%x\n",
80- // pDraw->y, pDraw->iX, pDraw->iY, pDraw->iWidth, pDraw->iHeight, pDraw->ucTransparent, pDraw->ucHasTransparency, pDraw->ucBackground, pDraw->pUser, bitmap->data) ;
79+ uint8_t * s ;
80+ uint16_t * d ;
8181
82- /*
83- int iX, iY; // Corner offset of this frame on the canvas
84- int y; // current line being drawn (0 = top line of image)
85- int iWidth, iHeight; // size of this frame
86- void *pUser; // user supplied pointer
87- uint8_t *pPixels; // 8-bit source pixels for this line
88- uint16_t *pPalette; // little or big-endian RGB565 palette entries (default)
89- uint8_t *pPalette24; // RGB888 palette (optional)
90- uint8_t ucTransparent; // transparent color
91- uint8_t ucHasTransparency; // flag indicating the transparent color is in use
92- uint8_t ucDisposalMethod; // frame disposal method
93- uint8_t ucBackground; // background color
94- uint8_t ucIsGlobalPalette; // Flag to indicate that a global palette, rather than a local palette is being used
95- */
96-
97- // For all other lines, just push the pixels to the display
98- // (uint8_t *)pDraw->pPixels, pDraw->iWidth*2);
82+ int32_t row_start = pDraw -> y * bitmap -> stride ;
83+ uint32_t * row = bitmap -> data + row_start ;
84+ s = pDraw -> pPixels ;
85+ d = (uint16_t * )row ;
9986
87+ uint16_t * pPal ;
88+ pPal = (uint16_t * )pDraw -> pPalette ;
10089
90+ if (pDraw -> ucDisposalMethod == 2 ) { // restore to background color
91+ memset (d , pDraw -> ucBackground , pDraw -> iWidth );
92+ }
10193
102- int32_t row_start = pDraw -> y * bitmap -> stride ;
103- uint32_t * row = bitmap -> data + row_start ;
104- uint8_t * d = (uint8_t * )row ;
105- // mp_printf(&mp_plat_print, "rs %d strd %d:\n", row_start, bitmap->stride);
106-
107- uint8_t * p = (uint8_t * )pDraw -> pPixels ;
108- for (int w = 0 ; w < pDraw -> iWidth * 2 ; w ++ ) {
109- // mp_printf(&mp_plat_print, "%x:", *p);
110- * d ++ = * p ;
111- p ++ ;
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+ 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 ];
103+ }
104+ d ++ ;
112105 }
113- // mp_printf(&mp_plat_print, "\n");
114106}
115107
116108void common_hal_displayio_ondiskgif_construct (displayio_ondiskgif_t * self , pyb_file_obj_t * file ) {
@@ -135,48 +127,49 @@ void common_hal_displayio_ondiskgif_construct(displayio_ondiskgif_t *self, pyb_f
135127 mp_arg_error_invalid (MP_QSTR_file );
136128 }
137129
138- self -> frame = m_malloc (self -> gif .iCanvasWidth * self -> gif .iCanvasHeight * sizeof (uint16_t ), false); // MUST FREE LATER?
139- self -> gif .pFrameBuffer = (uint8_t * )self -> frame ;
140- self -> gif .ucDrawType = GIF_DRAW_COOKED ;
141-
142130 displayio_bitmap_t * bitmap = m_new_obj (displayio_bitmap_t );
143131 bitmap -> base .type = & displayio_bitmap_type ;
144132 common_hal_displayio_bitmap_construct (bitmap , self -> gif .iCanvasWidth , self -> gif .iCanvasHeight , 16 );
145133 self -> bitmap = bitmap ;
146134
147- // mp_printf(&mp_plat_print, "GIF_init returned %d %x\n", result, bitmap->data);
148- }
149-
150-
151- uint32_t common_hal_displayio_ondiskgif_get_pixel (displayio_ondiskgif_t * self ,
152- int16_t x , int16_t y ) {
153- if (x < 0 || x >= self -> gif .iCanvasWidth || y < 0 || y >= self -> gif .iCanvasHeight ) {
154- return 0 ;
155- }
135+ GIFINFO info ;
136+ GIF_getInfo (& self -> gif , & info );
137+ self -> duration = info .iDuration ;
138+ self -> frame_count = info .iFrameCount ;
139+ self -> min_delay = info .iMinDelay ;
140+ self -> max_delay = info .iMaxDelay ;
156141
157- return 0 ;
142+ // mp_printf(&mp_plat_print, "GIF_init returned %d %x\n", result, bitmap->data) ;
158143}
159144
160145uint16_t common_hal_displayio_ondiskgif_get_height (displayio_ondiskgif_t * self ) {
161- GIFINFO info ;
162- GIF_getInfo (& self -> gif , & info );
163- mp_printf (& mp_plat_print , "dur %d fc %d max %d min %d\n" , info .iDuration , info .iFrameCount , info .iMaxDelay , info .iMinDelay );
164-
165146 return (uint16_t )self -> gif .iCanvasHeight ;
166147}
167148
168149uint16_t common_hal_displayio_ondiskgif_get_width (displayio_ondiskgif_t * self ) {
169150 return (uint16_t )self -> gif .iCanvasWidth ;
170151}
171152
172- mp_obj_t common_hal_displayio_ondiskgif_get_pixel_shader (displayio_ondiskgif_t * self ) {
173- return MP_OBJ_FROM_PTR (self -> pixel_shader_base );
174- }
175-
176153mp_obj_t common_hal_displayio_ondiskgif_get_bitmap (displayio_ondiskgif_t * self ) {
177154 return MP_OBJ_FROM_PTR (self -> bitmap );
178155}
179156
157+ int32_t common_hal_displayio_ondiskgif_get_duration (displayio_ondiskgif_t * self ) {
158+ return self -> duration ;
159+ }
160+
161+ int32_t common_hal_displayio_ondiskgif_get_frame_count (displayio_ondiskgif_t * self ) {
162+ return self -> frame_count ;
163+ }
164+
165+ int32_t common_hal_displayio_ondiskgif_get_min_delay (displayio_ondiskgif_t * self ) {
166+ return self -> min_delay ;
167+ }
168+
169+ int32_t common_hal_displayio_ondiskgif_get_max_delay (displayio_ondiskgif_t * self ) {
170+ return self -> max_delay ;
171+ }
172+
180173uint8_t common_hal_displayio_ondiskgif_play_frame (displayio_ondiskgif_t * self ) {
181174 int result = GIF_playFrame (& self -> gif , 0 , self -> bitmap );
182175
0 commit comments