bitmaptools: use stream API
this allows `readinto` to succeed in the unix port, where the VFS is not FAT
This commit is contained in:
parent
dca696dec1
commit
ee5e7161af
|
@ -619,7 +619,7 @@ STATIC mp_obj_t bitmaptools_readinto(size_t n_args, const mp_obj_t *pos_args, mp
|
|||
|
||||
displayio_bitmap_t *bitmap = mp_arg_validate_type(args[ARG_bitmap].u_obj, &displayio_bitmap_type, MP_QSTR_bitmap);
|
||||
|
||||
pyb_file_obj_t *file = mp_arg_validate_type(args[ARG_file].u_obj, &mp_type_fileio, MP_QSTR_file);
|
||||
mp_obj_t *file = args[ARG_file].u_obj;
|
||||
|
||||
int element_size = args[ARG_element_size].u_int;
|
||||
if (element_size != 1 && element_size != 2 && element_size != 4) {
|
||||
|
|
|
@ -64,7 +64,7 @@ void common_hal_bitmaptools_draw_line(displayio_bitmap_t *destination,
|
|||
int16_t x1, int16_t y1,
|
||||
uint32_t value);
|
||||
|
||||
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_word, bool swap_bytes, bool reverse_rows);
|
||||
void common_hal_bitmaptools_readinto(displayio_bitmap_t *self, mp_obj_t *file, int element_size, int bits_per_pixel, bool reverse_pixels_in_word, bool swap_bytes, bool reverse_rows);
|
||||
void common_hal_bitmaptools_arrayblit(displayio_bitmap_t *self, void *data, int element_size, int x1, int y1, int x2, int y2, bool skip_specified, uint32_t skip_index);
|
||||
void common_hal_bitmaptools_dither(displayio_bitmap_t *dest_bitmap, displayio_bitmap_t *source_bitmap, displayio_colorspace_t colorspace, bitmaptools_dither_algorithm_t algorithm);
|
||||
|
||||
|
|
|
@ -30,8 +30,9 @@
|
|||
#include "shared-bindings/displayio/ColorConverter.h"
|
||||
#include "shared-module/displayio/Bitmap.h"
|
||||
|
||||
#include "py/runtime.h"
|
||||
#include "py/mperrno.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/stream.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -513,9 +514,11 @@ void common_hal_bitmaptools_arrayblit(displayio_bitmap_t *self, void *data, int
|
|||
displayio_bitmap_set_dirty_area(self, &area);
|
||||
}
|
||||
|
||||
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) {
|
||||
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) {
|
||||
uint32_t mask = (1 << common_hal_displayio_bitmap_get_bits_per_value(self)) - 1;
|
||||
|
||||
const mp_stream_p_t *file_proto = mp_get_stream_raise(file, MP_STREAM_OP_READ);
|
||||
|
||||
displayio_area_t a = {0, 0, self->width, self->height, NULL};
|
||||
displayio_bitmap_set_dirty_area(self, &a);
|
||||
|
||||
|
@ -530,9 +533,14 @@ void common_hal_bitmaptools_readinto(displayio_bitmap_t *self, pyb_file_obj_t *f
|
|||
uint8_t *rowdata8 = (uint8_t *)rowdata32;
|
||||
const int y_draw = reverse_rows ? (self->height) - 1 - y : y;
|
||||
|
||||
UINT bytes_read = 0;
|
||||
if (f_read(&file->fp, rowdata32, rowsize, &bytes_read) != FR_OK || bytes_read != rowsize) {
|
||||
mp_raise_OSError(MP_EIO);
|
||||
|
||||
int error = 0;
|
||||
mp_uint_t bytes_read = file_proto->read(file, rowdata32, rowsize, &error);
|
||||
if (error) {
|
||||
mp_raise_OSError(error);
|
||||
}
|
||||
if (bytes_read != rowsize) {
|
||||
mp_raise_msg(&mp_type_EOFError, NULL);
|
||||
}
|
||||
|
||||
if (swap_bytes) {
|
||||
|
|
Loading…
Reference in New Issue