@@ -377,12 +377,16 @@ bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self, const _displayio_c
377377 }
378378
379379 uint8_t pixels_per_byte = 8 / colorspace -> depth ;
380- for (int16_t y = start_y ; y < end_y ; y ++ ) {
381- int16_t row_start = start + (y - start_y + y_shift ) * y_stride ; // in pixels
382- int16_t local_y = y / self -> absolute_transform -> scale ;
383- for (int16_t x = start_x ; x < end_x ; x ++ ) {
380+
381+ displayio_input_pixel_t input_pixel ;
382+ displayio_output_pixel_t output_pixel ;
383+
384+ for (input_pixel .y = start_y ; input_pixel .y < end_y ; ++ input_pixel .y ) {
385+ int16_t row_start = start + (input_pixel .y - start_y + y_shift ) * y_stride ; // in pixels
386+ int16_t local_y = input_pixel .y / self -> absolute_transform -> scale ;
387+ for (input_pixel .x = start_x ; input_pixel .x < end_x ; ++ input_pixel .x ) {
384388 // Compute the destination pixel in the buffer and mask based on the transformations.
385- int16_t offset = row_start + (x - start_x + x_shift ) * x_stride ; // in pixels
389+ int16_t offset = row_start + (input_pixel . x - start_x + x_shift ) * x_stride ; // in pixels
386390
387391 // This is super useful for debugging out of range accesses. Uncomment to use.
388392 // if (offset < 0 || offset >= (int32_t) displayio_area_size(area)) {
@@ -393,41 +397,43 @@ bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self, const _displayio_c
393397 if ((mask [offset / 32 ] & (1 << (offset % 32 ))) != 0 ) {
394398 continue ;
395399 }
396- int16_t local_x = x / self -> absolute_transform -> scale ;
400+ int16_t local_x = input_pixel . x / self -> absolute_transform -> scale ;
397401 uint16_t tile_location = ((local_y / self -> tile_height + self -> top_left_y ) % self -> height_in_tiles ) * self -> width_in_tiles + (local_x / self -> tile_width + self -> top_left_x ) % self -> width_in_tiles ;
398- uint8_t tile = tiles [tile_location ];
399- uint16_t tile_x = (tile % self -> bitmap_width_in_tiles ) * self -> tile_width + local_x % self -> tile_width ;
400- uint16_t tile_y = (tile / self -> bitmap_width_in_tiles ) * self -> tile_height + local_y % self -> tile_height ;
402+ input_pixel .tile = tiles [tile_location ];
403+ input_pixel .tile_x = (input_pixel .tile % self -> bitmap_width_in_tiles ) * self -> tile_width + local_x % self -> tile_width ;
404+ input_pixel .tile_y = (input_pixel .tile / self -> bitmap_width_in_tiles ) * self -> tile_height + local_y % self -> tile_height ;
405+
406+ //uint32_t value = 0;
407+ output_pixel .pixel = 0 ;
408+ input_pixel .pixel = 0 ;
401409
402- uint32_t value = 0 ;
403410 // We always want to read bitmap pixels by row first and then transpose into the destination
404411 // buffer because most bitmaps are row associated.
405412 if (MP_OBJ_IS_TYPE (self -> bitmap , & displayio_bitmap_type )) {
406- value = common_hal_displayio_bitmap_get_pixel (self -> bitmap , tile_x , tile_y );
413+ input_pixel . pixel = common_hal_displayio_bitmap_get_pixel (self -> bitmap , input_pixel . tile_x , input_pixel . tile_y );
407414 } else if (MP_OBJ_IS_TYPE (self -> bitmap , & displayio_shape_type )) {
408- value = common_hal_displayio_shape_get_pixel (self -> bitmap , tile_x , tile_y );
415+ input_pixel . pixel = common_hal_displayio_shape_get_pixel (self -> bitmap , input_pixel . tile_x , input_pixel . tile_y );
409416 } else if (MP_OBJ_IS_TYPE (self -> bitmap , & displayio_ondiskbitmap_type )) {
410- value = common_hal_displayio_ondiskbitmap_get_pixel (self -> bitmap , tile_x , tile_y );
417+ input_pixel . pixel = common_hal_displayio_ondiskbitmap_get_pixel (self -> bitmap , input_pixel . tile_x , input_pixel . tile_y );
411418 }
412-
413- uint32_t pixel ;
414- bool opaque = true;
419+
420+ output_pixel .opaque = true;
415421 if (self -> pixel_shader == mp_const_none ) {
416- pixel = value ;
422+ output_pixel . pixel = input_pixel . pixel ;
417423 } else if (MP_OBJ_IS_TYPE (self -> pixel_shader , & displayio_palette_type )) {
418- opaque = displayio_palette_get_color (self -> pixel_shader , colorspace , value , & pixel );
424+ output_pixel . opaque = displayio_palette_get_color (self -> pixel_shader , colorspace , input_pixel . pixel , & output_pixel . pixel );
419425 } else if (MP_OBJ_IS_TYPE (self -> pixel_shader , & displayio_colorconverter_type )) {
420- opaque = displayio_colorconverter_convert (self -> pixel_shader , colorspace , value , & pixel );
426+ displayio_colorconverter_convert (self -> pixel_shader , colorspace , & input_pixel , & output_pixel );
421427 }
422- if (!opaque ) {
428+ if (!output_pixel . opaque ) {
423429 // A pixel is transparent so we haven't fully covered the area ourselves.
424430 full_coverage = false;
425431 } else {
426432 mask [offset / 32 ] |= 1 << (offset % 32 );
427433 if (colorspace -> depth == 16 ) {
428- * (((uint16_t * ) buffer ) + offset ) = pixel ;
434+ * (((uint16_t * ) buffer ) + offset ) = output_pixel . pixel ;
429435 } else if (colorspace -> depth == 8 ) {
430- * (((uint8_t * ) buffer ) + offset ) = pixel ;
436+ * (((uint8_t * ) buffer ) + offset ) = output_pixel . pixel ;
431437 } else if (colorspace -> depth < 8 ) {
432438 // Reorder the offsets to pack multiple rows into a byte (meaning they share a column).
433439 if (!colorspace -> pixels_in_byte_share_row ) {
@@ -446,7 +452,7 @@ bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self, const _displayio_c
446452 // Reverse the shift by subtracting it from the leftmost shift.
447453 shift = (pixels_per_byte - 1 ) * colorspace -> depth - shift ;
448454 }
449- ((uint8_t * )buffer )[offset / pixels_per_byte ] |= pixel << shift ;
455+ ((uint8_t * )buffer )[offset / pixels_per_byte ] |= output_pixel . pixel << shift ;
450456 }
451457 }
452458 }
0 commit comments