Add reverse_rows option to bitmaptools.readinto
This commit is contained in:
parent
542fb58673
commit
227ac67463
@ -456,7 +456,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitmaptools_arrayblit_obj, 0, bitmaptools_arrayblit);
|
|||||||
//|
|
//|
|
||||||
|
|
||||||
STATIC mp_obj_t bitmaptools_readinto(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
STATIC mp_obj_t bitmaptools_readinto(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||||
enum { ARG_bitmap, ARG_file, ARG_bits_per_pixel, ARG_element_size, ARG_reverse_pixels_in_element, ARG_swap_bytes_in_element };
|
enum { ARG_bitmap, ARG_file, ARG_bits_per_pixel, ARG_element_size, ARG_reverse_pixels_in_element, ARG_swap_bytes_in_element, ARG_reverse_rows };
|
||||||
static const mp_arg_t allowed_args[] = {
|
static const mp_arg_t allowed_args[] = {
|
||||||
{ MP_QSTR_bitmap, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
{ MP_QSTR_bitmap, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||||
{ MP_QSTR_file, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
{ MP_QSTR_file, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||||
@ -464,6 +464,7 @@ STATIC mp_obj_t bitmaptools_readinto(size_t n_args, const mp_obj_t *pos_args, mp
|
|||||||
{ MP_QSTR_element_size, MP_ARG_INT, { .u_int = 1 } },
|
{ MP_QSTR_element_size, MP_ARG_INT, { .u_int = 1 } },
|
||||||
{ MP_QSTR_reverse_pixels_in_element, MP_ARG_BOOL, { .u_bool = false } },
|
{ MP_QSTR_reverse_pixels_in_element, MP_ARG_BOOL, { .u_bool = false } },
|
||||||
{ MP_QSTR_swap_bytes_in_element, MP_ARG_BOOL, { .u_bool = false } },
|
{ MP_QSTR_swap_bytes_in_element, MP_ARG_BOOL, { .u_bool = false } },
|
||||||
|
{ MP_QSTR_reverse_rows, MP_ARG_BOOL, { .u_bool = false } },
|
||||||
};
|
};
|
||||||
|
|
||||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||||
@ -504,8 +505,9 @@ STATIC mp_obj_t bitmaptools_readinto(size_t n_args, const mp_obj_t *pos_args, mp
|
|||||||
|
|
||||||
bool reverse_pixels_in_element = args[ARG_reverse_pixels_in_element].u_bool;
|
bool reverse_pixels_in_element = args[ARG_reverse_pixels_in_element].u_bool;
|
||||||
bool swap_bytes_in_element = args[ARG_swap_bytes_in_element].u_bool;
|
bool swap_bytes_in_element = args[ARG_swap_bytes_in_element].u_bool;
|
||||||
|
bool reverse_rows = args[ARG_reverse_rows].u_bool;
|
||||||
|
|
||||||
common_hal_bitmaptools_readinto(bitmap, file, element_size, bits_per_pixel, reverse_pixels_in_element, swap_bytes_in_element);
|
common_hal_bitmaptools_readinto(bitmap, file, element_size, bits_per_pixel, reverse_pixels_in_element, swap_bytes_in_element, reverse_rows);
|
||||||
|
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ void common_hal_bitmaptools_draw_line(displayio_bitmap_t *destination,
|
|||||||
int16_t x1, int16_t y1,
|
int16_t x1, int16_t y1,
|
||||||
uint32_t value);
|
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);
|
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_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_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);
|
||||||
|
|
||||||
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BITMAPTOOLS__INIT__H
|
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BITMAPTOOLS__INIT__H
|
||||||
|
@ -367,7 +367,7 @@ void common_hal_bitmaptools_arrayblit(displayio_bitmap_t *self, void *data, int
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
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) {
|
||||||
uint32_t mask = (1 << common_hal_displayio_bitmap_get_bits_per_value(self)) - 1;
|
uint32_t mask = (1 << common_hal_displayio_bitmap_get_bits_per_value(self)) - 1;
|
||||||
|
|
||||||
if (self->read_only) {
|
if (self->read_only) {
|
||||||
@ -378,10 +378,12 @@ void common_hal_bitmaptools_readinto(displayio_bitmap_t *self, pyb_file_obj_t* f
|
|||||||
size_t rowsize = element_size * elements_per_row;
|
size_t rowsize = element_size * elements_per_row;
|
||||||
size_t rowsize_in_u32 = (rowsize + sizeof(uint32_t) - 1) / sizeof(uint32_t);
|
size_t rowsize_in_u32 = (rowsize + sizeof(uint32_t) - 1) / sizeof(uint32_t);
|
||||||
size_t rowsize_in_u16 = (rowsize + sizeof(uint16_t) - 1) / sizeof(uint16_t);
|
size_t rowsize_in_u16 = (rowsize + sizeof(uint16_t) - 1) / sizeof(uint16_t);
|
||||||
|
|
||||||
for(int y=0; y<self->height; y++) {
|
for(int y=0; y<self->height; y++) {
|
||||||
uint32_t rowdata32[rowsize_in_u32];
|
uint32_t rowdata32[rowsize_in_u32];
|
||||||
uint16_t *rowdata16 = (uint16_t*)rowdata32;
|
uint16_t *rowdata16 = (uint16_t*)rowdata32;
|
||||||
uint8_t *rowdata8 = (uint8_t*)rowdata32;
|
uint8_t *rowdata8 = (uint8_t*)rowdata32;
|
||||||
|
const int y_draw = reverse_rows ? (self->height) - 1 - y : y;
|
||||||
|
|
||||||
UINT bytes_read = 0;
|
UINT bytes_read = 0;
|
||||||
if (f_read(&file->fp, rowdata32, rowsize, &bytes_read) != FR_OK || bytes_read != rowsize) {
|
if (f_read(&file->fp, rowdata32, rowsize, &bytes_read) != FR_OK || bytes_read != rowsize) {
|
||||||
@ -447,8 +449,7 @@ void common_hal_bitmaptools_readinto(displayio_bitmap_t *self, pyb_file_obj_t* f
|
|||||||
value = rowdata32[x];
|
value = rowdata32[x];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
displayio_bitmap_write_pixel(self, x, y_draw, value & mask);
|
||||||
displayio_bitmap_write_pixel(self, x, y, value & mask);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user