30
30
#include "shared-bindings/displayio/ColorConverter.h"
31
31
#include "shared-module/displayio/Bitmap.h"
32
32
33
- #include "py/runtime.h"
34
33
#include "py/mperrno.h"
34
+ #include "py/runtime.h"
35
+ #include "py/stream.h"
35
36
36
37
#include <math.h>
37
38
#include <stdlib.h>
@@ -513,9 +514,11 @@ void common_hal_bitmaptools_arrayblit(displayio_bitmap_t *self, void *data, int
513
514
displayio_bitmap_set_dirty_area (self , & area );
514
515
}
515
516
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 ) {
517
518
uint32_t mask = (1 << common_hal_displayio_bitmap_get_bits_per_value (self )) - 1 ;
518
519
520
+ const mp_stream_p_t * file_proto = mp_get_stream_raise (file , MP_STREAM_OP_READ );
521
+
519
522
displayio_area_t a = {0 , 0 , self -> width , self -> height , NULL };
520
523
displayio_bitmap_set_dirty_area (self , & a );
521
524
@@ -530,9 +533,14 @@ void common_hal_bitmaptools_readinto(displayio_bitmap_t *self, pyb_file_obj_t *f
530
533
uint8_t * rowdata8 = (uint8_t * )rowdata32 ;
531
534
const int y_draw = reverse_rows ? (self -> height ) - 1 - y : y ;
532
535
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 );
536
544
}
537
545
538
546
if (swap_bytes ) {
0 commit comments