summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Matocha <kmatocha@icloud.com>2020-08-21 14:19:28 -0500
committerKevin Matocha <kmatocha@icloud.com>2020-08-21 14:19:28 -0500
commit24ca133396574dba972baaecf211bdb2f7904469 (patch)
treeabb82098525523ecfddd2b7b645bd728684f548d
parent1e7e42b2217582fcd596dcb737dbf5cd1f7521cb (diff)
parentb6008d0032a49e6b5c332576fa2f141d353b9fd3 (diff)
Updating main to adafruit/main
-rw-r--r--shared-bindings/displayio/Bitmap.c74
-rw-r--r--shared-bindings/displayio/Bitmap.h4
-rw-r--r--shared-module/displayio/Bitmap.c77
3 files changed, 154 insertions, 1 deletions
diff --git a/shared-bindings/displayio/Bitmap.c b/shared-bindings/displayio/Bitmap.c
index 0a45bbdfd..dd336442c 100644
--- a/shared-bindings/displayio/Bitmap.c
+++ b/shared-bindings/displayio/Bitmap.c
@@ -172,7 +172,78 @@ STATIC mp_obj_t bitmap_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t val
return mp_const_none;
}
-//| def fill(self, value: int) -> None:
+//| def insert(self, x: int, y: int, source_bitmap: bitmap, x1: int, y1: int, x2: int, y2:int) -> Any:
+//| """Inserts the source_bitmap region defined by rectangular boundaries
+//| (x1,y1) and (x2,y2) into the bitmap at the specified (x,y) location.
+//| :param int x: Horizontal pixel location in bitmap where source_bitmap upper-left
+//| corner will be placed
+//| :param int y: Vertical pixel location in bitmap where source_bitmap upper-left
+//| corner will be placed
+//| :param bitmap source_bitmap: Source bitmap that contains the graphical region to be copied
+//| : param x1: Minimum x-value for rectangular bounding box to be copied from the source bitmap
+//| : param y1: Minimum y-value for rectangular bounding box to be copied from the source bitmap
+//| : param x2: Maximum x-value for rectangular bounding box to be copied from the source bitmap
+//| : param y2: Maximum y-value for rectangular bounding box to be copied from the source bitmap
+//|
+//| ...
+//|
+
+//STATIC mp_obj_t displayio_bitmap_obj_insert(mp_obj_t self_in, mp_obj_t x_obj, mp_obj_t y_obj, mp_obj_t source_in, mp_obj_t x1_obj, mp_obj_t y1_obj, mp_obj_t x2_obj, mp_obj_t y2_obj){
+STATIC mp_obj_t displayio_bitmap_obj_insert(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args){
+
+ // // convert the inputs into the correct type
+ // displayio_bitmap_t *self = MP_OBJ_TO_PTR(self_in);
+ // int16_t x = mp_obj_get_int(x_obj);
+ // int16_t y = mp_obj_get_int(y_obj);
+ // displayio_bitmap_t *source = MP_OBJ_TO_PTR(source_in);
+ // int16_t x1 = mp_obj_get_int(x1_obj);
+ // int16_t y1 = mp_obj_get_int(y1_obj);
+ // int16_t x2 = mp_obj_get_int(x2_obj);
+ // int16_t y2 = mp_obj_get_int(y2_obj);
+ displayio_bitmap_t *self = MP_OBJ_TO_PTR(pos_args[0]);
+ int16_t x = mp_obj_get_int(pos_args[1]);
+ int16_t y = mp_obj_get_int(pos_args[2]);
+ displayio_bitmap_t *source = MP_OBJ_TO_PTR(pos_args[3]);
+ int16_t x1 = mp_obj_get_int(pos_args[4]);
+ int16_t y1 = mp_obj_get_int(pos_args[5]);
+ int16_t x2 = mp_obj_get_int(pos_args[6]);
+ int16_t y2 = mp_obj_get_int(pos_args[7]);
+
+
+
+
+ if ( (x<0) || (y<0) || (x > self-> width) || (y > self->height) ) {
+ mp_raise_ValueError(translate("(x,y): out of range of target bitmap"));
+ }
+ if ( (x1 < 0) || (x1 > source->width) ||
+ (y1 < 0) || (y1 > source->height) ||
+ (x2 < 0) || (x2 > source->width) ||
+ (y2 < 0) || (y2 > source->height) ) {
+ mp_raise_ValueError(translate("(x1,y1) or (x2,y2): out of range of source bitmap"));
+ }
+
+ // Ensure x1 < x2 and y1 < y2
+ if (x1 > x2) {
+ int16_t temp=x2;
+ x2=x1;
+ x1=temp;
+ }
+ if (y1 > y2) {
+ int16_t temp=y2;
+ y2=y1;
+ y1=temp;
+ }
+
+ common_hal_displayio_bitmap_insert(self, x, y, source, x1, y1, x2, y2);
+
+ return mp_const_none;
+}
+
+MP_DEFINE_CONST_FUN_OBJ_KW(displayio_bitmap_insert_obj, 8, displayio_bitmap_obj_insert);
+/// What should this number value be? ****
+
+
+//| def fill(self, value: Any) -> Any:
//| """Fills the bitmap with the supplied palette index value."""
//| ...
//|
@@ -192,6 +263,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(displayio_bitmap_fill_obj, displayio_bitmap_obj_fill);
STATIC const mp_rom_map_elem_t displayio_bitmap_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&displayio_bitmap_height_obj) },
{ MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&displayio_bitmap_width_obj) },
+ { MP_ROM_QSTR(MP_QSTR_insert), MP_ROM_PTR(&displayio_bitmap_insert_obj) }, // Added insert function 8/7/2020
{ MP_ROM_QSTR(MP_QSTR_fill), MP_ROM_PTR(&displayio_bitmap_fill_obj) },
};
diff --git a/shared-bindings/displayio/Bitmap.h b/shared-bindings/displayio/Bitmap.h
index 46c337329..d6183f7d0 100644
--- a/shared-bindings/displayio/Bitmap.h
+++ b/shared-bindings/displayio/Bitmap.h
@@ -40,6 +40,10 @@ uint16_t common_hal_displayio_bitmap_get_height(displayio_bitmap_t *self);
uint16_t common_hal_displayio_bitmap_get_width(displayio_bitmap_t *self);
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_insert(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);
+// New selective bitmap copy function "insert": KMatocha 8/7/2020
+
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);
diff --git a/shared-module/displayio/Bitmap.c b/shared-module/displayio/Bitmap.c
index 8bcda6086..75f352b30 100644
--- a/shared-module/displayio/Bitmap.c
+++ b/shared-module/displayio/Bitmap.c
@@ -105,6 +105,83 @@ uint32_t common_hal_displayio_bitmap_get_pixel(displayio_bitmap_t *self, int16_t
return 0;
}
+void common_hal_displayio_bitmap_insert(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) {
+ // Copy complete "source" bitmap into "self" bitmap at location x,y in the "self"
+ // Add a boolean to determine if all values are copied, or only if non-zero
+ // Default is copy all values, but for text glyphs this should copy only non-zero values
+
+ if (self->read_only) {
+ mp_raise_RuntimeError(translate("Read-only object"));
+ }
+
+ // If this value is encountered in the source bitmap, it will not be copied (for text glyphs)
+ // This should be added as an optional parameter, and if it is `None`, then all pixels are copied
+ uint32_t skip_value=0;
+
+ //// check for zero width, this would be a single pixel
+ // if (x1_source == x2_source) || (y1_source == y2_source) {
+ // return 0
+ // }
+
+ // Dirty area update is unnecessary with simplest version.
+ // int16_t x_max=x+(x2_source-x1_source);
+ // int16_t y_max=y+(y2_source-y1_source);
+ //
+ //
+ // // Update the dirty area.
+ // if (x < self->dirty_area.x1) {
+ // self->dirty_area.x1 = x;
+ // } else if (x_max >= self->dirty_area.x2) {
+ // self->dirty_area.x2 = x_max);
+ // }
+ // if (y < self->dirty_area.y1) {
+ // self->dirty_area.y1 = y;
+ // } else if (y_max >= self->dirty_area.y2) {
+ // self->dirty_area.y2 = y_max;
+ // }
+
+ // simplest version - use internal functions for get/set pixels
+ for (uint16_t i=0; i<= (x2-x1) ; i++) {
+ for (uint16_t j=0; j<= (y2-y1) ; j++){
+ uint32_t value = common_hal_displayio_bitmap_get_pixel(source, x1+i, y1+j);
+ if (value != skip_value) {
+ if ( (x+i >= 0) && (y+j >= 0) && (x+i <= self->width-1) && (y+j <= self->height-1) ){
+ common_hal_displayio_bitmap_set_pixel(self, x+i, y+j, value);
+ }
+ }
+ }
+ }
+
+ // Would be faster if copying a full word at a time.
+ /// Hard work here!!!!
+ // index into the original row
+ // figure out how to shift the bits into the right location
+ // check the boolean and don't update any zero's
+
+ // // Update our data
+ // int32_t row_start = y * self->stride;
+ // uint32_t bytes_per_value = self->bits_per_value / 8;
+ // if (bytes_per_value < 1) {
+ // uint32_t bit_position = (sizeof(size_t) * 8 - ((x & self->x_mask) + 1) * self->bits_per_value);
+ // uint32_t index = row_start + (x >> self->x_shift);
+ // uint32_t word = self->data[index];
+ // word &= ~(self->bitmask << bit_position);
+ // word |= (value & self->bitmask) << bit_position;
+ // self->data[index] = word;
+ // } else {
+ // size_t* row = self->data + row_start;
+ // if (bytes_per_value == 1) {
+ // ((uint8_t*) row)[x] = value;
+ // } else if (bytes_per_value == 2) {
+ // ((uint16_t*) row)[x] = value;
+ // } else if (bytes_per_value == 4) {
+ // ((uint32_t*) row)[x] = value;
+ // }
+ // }
+}
+
+
void common_hal_displayio_bitmap_set_pixel(displayio_bitmap_t *self, int16_t x, int16_t y, uint32_t value) {
if (self->read_only) {
mp_raise_RuntimeError(translate("Read-only object"));