3030#include "shared-bindings/displayio/ColorConverter.h"
3131#include "shared-module/displayio/Bitmap.h"
3232
33- #include "py/runtime.h"
3433#include "py/mperrno.h"
34+ #include "py/runtime.h"
35+ #include "py/stream.h"
3536
3637#include <math.h>
3738#include <stdlib.h>
@@ -513,9 +514,11 @@ void common_hal_bitmaptools_arrayblit(displayio_bitmap_t *self, void *data, int
513514 displayio_bitmap_set_dirty_area (self , & area );
514515}
515516
516- void common_hal_bitmaptools_readinto (displayio_bitmap_t * self , pyb_file_obj_t * file , int element_size , int bits_per_pixel , bool reverse_pixels_in_element , bool swap_bytes , bool reverse_rows ) {
517+ void common_hal_bitmaptools_readinto (displayio_bitmap_t * self , mp_obj_t * file , int element_size , int bits_per_pixel , bool reverse_pixels_in_element , bool swap_bytes , bool reverse_rows ) {
517518 uint32_t mask = (1 << common_hal_displayio_bitmap_get_bits_per_value (self )) - 1 ;
518519
520+ const mp_stream_p_t * file_proto = mp_get_stream_raise (file , MP_STREAM_OP_READ );
521+
519522 displayio_area_t a = {0 , 0 , self -> width , self -> height , NULL };
520523 displayio_bitmap_set_dirty_area (self , & a );
521524
@@ -530,9 +533,14 @@ void common_hal_bitmaptools_readinto(displayio_bitmap_t *self, pyb_file_obj_t *f
530533 uint8_t * rowdata8 = (uint8_t * )rowdata32 ;
531534 const int y_draw = reverse_rows ? (self -> height ) - 1 - y : y ;
532535
533- UINT bytes_read = 0 ;
534- if (f_read (& file -> fp , rowdata32 , rowsize , & bytes_read ) != FR_OK || bytes_read != rowsize ) {
535- mp_raise_OSError (MP_EIO );
536+
537+ int error = 0 ;
538+ mp_uint_t bytes_read = file_proto -> read (file , rowdata32 , rowsize , & error );
539+ if (error ) {
540+ mp_raise_OSError (error );
541+ }
542+ if (bytes_read != rowsize ) {
543+ mp_raise_msg (& mp_type_EOFError , NULL );
536544 }
537545
538546 if (swap_bytes ) {
0 commit comments