adding skip_self_index argument to bitmap.blit()
This commit is contained in:
parent
ce3df829e1
commit
abf15125ff
@ -196,7 +196,8 @@ STATIC mp_obj_t bitmap_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t val
|
|||||||
//| y1: int,
|
//| y1: int,
|
||||||
//| x2: int,
|
//| x2: int,
|
||||||
//| y2: int,
|
//| y2: int,
|
||||||
//| skip_index: int
|
//| skip_index: int,
|
||||||
|
//| skip_self_index: int
|
||||||
//| ) -> None:
|
//| ) -> None:
|
||||||
//| """Inserts the source_bitmap region defined by rectangular boundaries
|
//| """Inserts the source_bitmap region defined by rectangular boundaries
|
||||||
//| (x1,y1) and (x2,y2) into the bitmap at the specified (x,y) location.
|
//| (x1,y1) and (x2,y2) into the bitmap at the specified (x,y) location.
|
||||||
@ -211,10 +212,12 @@ STATIC mp_obj_t bitmap_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t val
|
|||||||
//| :param int x2: Maximum x-value (exclusive) for rectangular bounding box to be copied from the source bitmap
|
//| :param int x2: Maximum x-value (exclusive) for rectangular bounding box to be copied from the source bitmap
|
||||||
//| :param int y2: Maximum y-value (exclusive) for rectangular bounding box to be copied from the source bitmap
|
//| :param int y2: Maximum y-value (exclusive) for rectangular bounding box to be copied from the source bitmap
|
||||||
//| :param int skip_index: bitmap palette index in the source that will not be copied,
|
//| :param int skip_index: bitmap palette index in the source that will not be copied,
|
||||||
//| set to None to copy all pixels"""
|
//| set to None to copy all pixels
|
||||||
|
//| :param int skip_self_index: bitmap palette index in the self bitmap that will not get overwritten
|
||||||
|
//| by the pixels from the source"""
|
||||||
//| ...
|
//| ...
|
||||||
STATIC mp_obj_t displayio_bitmap_obj_blit(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
STATIC mp_obj_t displayio_bitmap_obj_blit(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||||
enum {ARG_x, ARG_y, ARG_source, ARG_x1, ARG_y1, ARG_x2, ARG_y2, ARG_skip_index};
|
enum {ARG_x, ARG_y, ARG_source, ARG_x1, ARG_y1, ARG_x2, ARG_y2, ARG_skip_index, ARG_skip_self_index};
|
||||||
static const mp_arg_t allowed_args[] = {
|
static const mp_arg_t allowed_args[] = {
|
||||||
{MP_QSTR_x, MP_ARG_REQUIRED | MP_ARG_INT, {.u_obj = MP_OBJ_NULL} },
|
{MP_QSTR_x, MP_ARG_REQUIRED | MP_ARG_INT, {.u_obj = MP_OBJ_NULL} },
|
||||||
{MP_QSTR_y, MP_ARG_REQUIRED | MP_ARG_INT, {.u_obj = MP_OBJ_NULL} },
|
{MP_QSTR_y, MP_ARG_REQUIRED | MP_ARG_INT, {.u_obj = MP_OBJ_NULL} },
|
||||||
@ -224,6 +227,7 @@ STATIC mp_obj_t displayio_bitmap_obj_blit(size_t n_args, const mp_obj_t *pos_arg
|
|||||||
{MP_QSTR_x2, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, // None convert to source->width
|
{MP_QSTR_x2, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, // None convert to source->width
|
||||||
{MP_QSTR_y2, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, // None convert to source->height
|
{MP_QSTR_y2, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, // None convert to source->height
|
||||||
{MP_QSTR_skip_index, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} },
|
{MP_QSTR_skip_index, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} },
|
||||||
|
{MP_QSTR_skip_self_index, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} },
|
||||||
};
|
};
|
||||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||||
@ -283,7 +287,19 @@ STATIC mp_obj_t displayio_bitmap_obj_blit(size_t n_args, const mp_obj_t *pos_arg
|
|||||||
skip_index_none = false;
|
skip_index_none = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
common_hal_displayio_bitmap_blit(self, x, y, source, x1, y1, x2, y2, skip_index, skip_index_none);
|
uint32_t skip_self_index;
|
||||||
|
bool skip_self_index_none; // flag whether skip_self_value was None
|
||||||
|
|
||||||
|
if (args[ARG_skip_self_index].u_obj == mp_const_none) {
|
||||||
|
skip_self_index = 0;
|
||||||
|
skip_self_index_none = true;
|
||||||
|
} else {
|
||||||
|
skip_self_index = mp_obj_get_int(args[ARG_skip_self_index].u_obj);
|
||||||
|
skip_self_index_none = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
common_hal_displayio_bitmap_blit(self, x, y, source, x1, y1, x2, y2, skip_index, skip_index_none, skip_self_index,
|
||||||
|
skip_self_index_none);
|
||||||
|
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ uint32_t common_hal_displayio_bitmap_get_bits_per_value(displayio_bitmap_t *self
|
|||||||
void common_hal_displayio_bitmap_set_pixel(displayio_bitmap_t *bitmap, int16_t x, int16_t y, uint32_t value);
|
void common_hal_displayio_bitmap_set_pixel(displayio_bitmap_t *bitmap, int16_t x, int16_t y, uint32_t value);
|
||||||
void common_hal_displayio_bitmap_blit(displayio_bitmap_t *self, int16_t x, int16_t y, displayio_bitmap_t *source,
|
void common_hal_displayio_bitmap_blit(displayio_bitmap_t *self, int16_t x, int16_t y, displayio_bitmap_t *source,
|
||||||
int16_t x1, int16_t y1, int16_t x2, int16_t y2,
|
int16_t x1, int16_t y1, int16_t x2, int16_t y2,
|
||||||
uint32_t skip_index, bool skip_index_none);
|
uint32_t skip_index, bool skip_index_none, uint32_t skip_self_index, bool skip_self_index_none);
|
||||||
uint32_t common_hal_displayio_bitmap_get_pixel(displayio_bitmap_t *bitmap, int16_t x, int16_t y);
|
uint32_t common_hal_displayio_bitmap_get_pixel(displayio_bitmap_t *bitmap, int16_t x, int16_t y);
|
||||||
void common_hal_displayio_bitmap_fill(displayio_bitmap_t *bitmap, uint32_t value);
|
void common_hal_displayio_bitmap_fill(displayio_bitmap_t *bitmap, uint32_t value);
|
||||||
int common_hal_displayio_bitmap_get_buffer(displayio_bitmap_t *self, mp_buffer_info_t *bufinfo, mp_uint_t flags);
|
int common_hal_displayio_bitmap_get_buffer(displayio_bitmap_t *self, mp_buffer_info_t *bufinfo, mp_uint_t flags);
|
||||||
|
@ -175,7 +175,8 @@ void displayio_bitmap_write_pixel(displayio_bitmap_t *self, int16_t x, int16_t y
|
|||||||
}
|
}
|
||||||
|
|
||||||
void common_hal_displayio_bitmap_blit(displayio_bitmap_t *self, int16_t x, int16_t y, displayio_bitmap_t *source,
|
void common_hal_displayio_bitmap_blit(displayio_bitmap_t *self, int16_t x, int16_t y, displayio_bitmap_t *source,
|
||||||
int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint32_t skip_index, bool skip_index_none) {
|
int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint32_t skip_index, bool skip_index_none, uint32_t skip_self_index,
|
||||||
|
bool skip_self_index_none) {
|
||||||
if (self->read_only) {
|
if (self->read_only) {
|
||||||
mp_raise_RuntimeError(translate("Read-only"));
|
mp_raise_RuntimeError(translate("Read-only"));
|
||||||
}
|
}
|
||||||
@ -222,8 +223,17 @@ void common_hal_displayio_bitmap_blit(displayio_bitmap_t *self, int16_t x, int16
|
|||||||
|
|
||||||
if ((yd_index >= 0) && (yd_index < self->height)) {
|
if ((yd_index >= 0) && (yd_index < self->height)) {
|
||||||
uint32_t value = common_hal_displayio_bitmap_get_pixel(source, xs_index, ys_index);
|
uint32_t value = common_hal_displayio_bitmap_get_pixel(source, xs_index, ys_index);
|
||||||
if ((skip_index_none) || (value != skip_index)) { // write if skip_value_none is True
|
if (skip_self_index_none) { // if skip_self_index is none, then only check source skip
|
||||||
displayio_bitmap_write_pixel(self, xd_index, yd_index, value);
|
if ((skip_index_none) || (value != skip_index)) { // write if skip_value_none is True
|
||||||
|
displayio_bitmap_write_pixel(self, xd_index, yd_index, value);
|
||||||
|
}
|
||||||
|
} else { // check dest_value index against skip_self_index and skip if they match
|
||||||
|
uint32_t dest_value = common_hal_displayio_bitmap_get_pixel(self, xd_index, yd_index);
|
||||||
|
if (dest_value != skip_self_index) {
|
||||||
|
if ((skip_index_none) || (value != skip_index)) { // write if skip_value_none is True
|
||||||
|
displayio_bitmap_write_pixel(self, xd_index, yd_index, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user