Skip to content

Commit a66ef32

Browse files
committed
Added inclusive indexing for x2,y2, fixed default value handling for x1,y1, added bitmap palette comparison
1 parent 824f47d commit a66ef32

File tree

3 files changed

+58
-31
lines changed

3 files changed

+58
-31
lines changed

locale/circuitpython.pot

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2020-08-14 09:36-0400\n"
11+
"POT-Creation-Date: 2020-08-14 13:10-0500\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <[email protected]>\n"
@@ -82,13 +82,17 @@ msgstr ""
8282
msgid "%q list must be a list"
8383
msgstr ""
8484

85+
#: shared-bindings/memorymonitor/AllocationAlarm 3.c
86+
#: shared-bindings/memorymonitor/AllocationAlarm 4.c
8587
#: shared-bindings/memorymonitor/AllocationAlarm.c
8688
msgid "%q must be >= 0"
8789
msgstr ""
8890

8991
#: shared-bindings/_bleio/CharacteristicBuffer.c
9092
#: shared-bindings/_bleio/PacketBuffer.c shared-bindings/displayio/Group.c
9193
#: shared-bindings/displayio/Shape.c
94+
#: shared-bindings/memorymonitor/AllocationAlarm 3.c
95+
#: shared-bindings/memorymonitor/AllocationAlarm 4.c
9296
#: shared-bindings/memorymonitor/AllocationAlarm.c
9397
#: shared-bindings/vectorio/Circle.c shared-bindings/vectorio/Rectangle.c
9498
msgid "%q must be >= 1"
@@ -252,6 +256,14 @@ msgstr ""
252256
msgid "'yield' outside function"
253257
msgstr ""
254258

259+
#: shared-bindings/displayio/Bitmap.c
260+
msgid "(x,y): out of range of target bitmap"
261+
msgstr ""
262+
263+
#: shared-bindings/displayio/Bitmap.c
264+
msgid "(x1,y1) or (x2,y2): out of range of source bitmap"
265+
msgstr ""
266+
255267
#: py/compile.c
256268
msgid "*x must be assignment target"
257269
msgstr ""
@@ -306,6 +318,7 @@ msgstr ""
306318
msgid "All timers for this pin are in use"
307319
msgstr ""
308320

321+
#: ports/atmel-samd/common-hal/_pew/PewPew 2.c
309322
#: ports/atmel-samd/common-hal/_pew/PewPew.c
310323
#: ports/atmel-samd/common-hal/audioio/AudioOut.c
311324
#: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c
@@ -322,7 +335,11 @@ msgstr ""
322335
msgid "Already advertising."
323336
msgstr ""
324337

338+
#: shared-module/memorymonitor/AllocationAlarm 3.c
339+
#: shared-module/memorymonitor/AllocationAlarm 4.c
325340
#: shared-module/memorymonitor/AllocationAlarm.c
341+
#: shared-module/memorymonitor/AllocationSize 3.c
342+
#: shared-module/memorymonitor/AllocationSize 4.c
326343
#: shared-module/memorymonitor/AllocationSize.c
327344
msgid "Already running"
328345
msgstr ""
@@ -362,6 +379,8 @@ msgstr ""
362379
msgid "At most %d %q may be specified (not %d)"
363380
msgstr ""
364381

382+
#: shared-module/memorymonitor/AllocationAlarm 3.c
383+
#: shared-module/memorymonitor/AllocationAlarm 4.c
365384
#: shared-module/memorymonitor/AllocationAlarm.c
366385
#, c-format
367386
msgid "Attempt to allocate %d blocks"
@@ -491,6 +510,12 @@ msgid "Can't set CCCD on local Characteristic"
491510
msgstr ""
492511

493512
#: shared-bindings/displayio/Bitmap.c
513+
msgid "Cannot blit: source palette too large."
514+
msgstr ""
515+
516+
#: shared-bindings/displayio/Bitmap.c
517+
#: shared-bindings/memorymonitor/AllocationSize 3.c
518+
#: shared-bindings/memorymonitor/AllocationSize 4.c
494519
#: shared-bindings/memorymonitor/AllocationSize.c
495520
#: shared-bindings/pulseio/PulseIn.c
496521
msgid "Cannot delete values"
@@ -1014,6 +1039,7 @@ msgstr ""
10141039
#: ports/atmel-samd/common-hal/busio/I2C.c
10151040
#: ports/atmel-samd/common-hal/busio/SPI.c
10161041
#: ports/atmel-samd/common-hal/busio/UART.c
1042+
#: ports/atmel-samd/common-hal/i2cperipheral/I2CPeripheral 2.c
10171043
#: ports/atmel-samd/common-hal/i2cperipheral/I2CPeripheral.c
10181044
#: ports/cxd56/common-hal/busio/I2C.c ports/cxd56/common-hal/busio/SPI.c
10191045
#: ports/cxd56/common-hal/busio/UART.c ports/cxd56/common-hal/sdioio/SDCard.c
@@ -1370,6 +1396,8 @@ msgstr ""
13701396
msgid "Random number generation error"
13711397
msgstr ""
13721398

1399+
#: shared-bindings/memorymonitor/AllocationSize 3.c
1400+
#: shared-bindings/memorymonitor/AllocationSize 4.c
13731401
#: shared-bindings/memorymonitor/AllocationSize.c
13741402
#: shared-bindings/pulseio/PulseIn.c
13751403
msgid "Read-only"
@@ -1462,6 +1490,8 @@ msgstr ""
14621490

14631491
#: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/Group.c
14641492
#: shared-bindings/displayio/TileGrid.c
1493+
#: shared-bindings/memorymonitor/AllocationSize 3.c
1494+
#: shared-bindings/memorymonitor/AllocationSize 4.c
14651495
#: shared-bindings/memorymonitor/AllocationSize.c
14661496
#: shared-bindings/pulseio/PulseIn.c
14671497
msgid "Slices not supported"
@@ -1791,10 +1821,14 @@ msgstr ""
17911821
msgid "address %08x is not aligned to %d bytes"
17921822
msgstr ""
17931823

1824+
#: shared-bindings/i2cperipheral/I2CPeripheral 3.c
1825+
#: shared-bindings/i2cperipheral/I2CPeripheral 4.c
17941826
#: shared-bindings/i2cperipheral/I2CPeripheral.c
17951827
msgid "address out of bounds"
17961828
msgstr ""
17971829

1830+
#: shared-bindings/i2cperipheral/I2CPeripheral 3.c
1831+
#: shared-bindings/i2cperipheral/I2CPeripheral 4.c
17981832
#: shared-bindings/i2cperipheral/I2CPeripheral.c
17991833
msgid "addresses is empty"
18001834
msgstr ""
@@ -1957,7 +1991,9 @@ msgstr ""
19571991
msgid "can't assign to expression"
19581992
msgstr ""
19591993

1960-
#: py/obj.c py/objint.c shared-bindings/i2cperipheral/I2CPeripheral.c
1994+
#: py/obj.c py/objint.c shared-bindings/i2cperipheral/I2CPeripheral 3.c
1995+
#: shared-bindings/i2cperipheral/I2CPeripheral 4.c
1996+
#: shared-bindings/i2cperipheral/I2CPeripheral.c
19611997
msgid "can't convert %q to %q"
19621998
msgstr ""
19631999

shared-bindings/displayio/Bitmap.c

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ STATIC mp_obj_t bitmap_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t val
172172
return mp_const_none;
173173
}
174174

175-
//| def blit(self, x: int, y: int, source_bitmap: bitmap, x1: int, y1: int, x2: int, y2: int, skip_index: int) -> Any:
175+
//| def blit(self, x: int, y: int, source_bitmap: bitmap, *, x1: int, y1: int, x2: int, y2: int, skip_index: int) -> Any:
176176
//| """Inserts the source_bitmap region defined by rectangular boundaries
177177
//| (x1,y1) and (x2,y2) into the bitmap at the specified (x,y) location.
178178
//| :param int x: Horizontal pixel location in bitmap where source_bitmap upper-left
@@ -193,61 +193,52 @@ STATIC mp_obj_t displayio_bitmap_obj_blit(size_t n_args, const mp_obj_t *pos_arg
193193
static const mp_arg_t allowed_args[] = {
194194
{MP_QSTR_x, MP_ARG_REQUIRED | MP_ARG_INT},
195195
{MP_QSTR_y, MP_ARG_REQUIRED | MP_ARG_INT},
196-
{MP_QSTR_source, MP_ARG_REQUIRED | MP_ARG_OBJ},
197-
{MP_QSTR_x1, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
198-
{MP_QSTR_y1, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
196+
{MP_QSTR_source_bitmap, MP_ARG_REQUIRED | MP_ARG_OBJ},
197+
{MP_QSTR_x1, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = 0} },
198+
{MP_QSTR_y1, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = 0} },
199199
{MP_QSTR_x2, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, // None convert to source->width
200200
{MP_QSTR_y2, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, // None convert to source->height
201201
{MP_QSTR_skip_index, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj=mp_const_none} },
202202
};
203203
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
204204
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
205205

206-
displayio_bitmap_t *self = MP_OBJ_TO_PTR(pos_args[0]); //*******
206+
displayio_bitmap_t *self = MP_OBJ_TO_PTR(pos_args[0]);
207207

208208
int16_t x = args[ARG_x].u_int;
209209
int16_t y = args[ARG_y].u_int;
210210

211211
displayio_bitmap_t *source = MP_OBJ_TO_PTR(args[ARG_source].u_obj);
212212

213-
int16_t x1, y1;
214-
// if x1 or y1 is None, then set as the zero-point of the bitmap
215-
if ( args[ARG_x1].u_obj == mp_const_none ) {
216-
x1 = 0;
217-
} else {
218-
x1 = mp_obj_get_int(args[ARG_x1].u_obj);
219-
}
220-
//int16_t y1;
221-
if ( args[ARG_y1].u_obj == mp_const_none ) {
222-
y1 = 0;
223-
} else {
224-
y1 = mp_obj_get_int(args[ARG_y1].u_obj);
213+
// ensure that the target bitmap (self) has at least as many `bits_per_value` as the source
214+
if (self->bits_per_value < source->bits_per_value) {
215+
mp_raise_ValueError(translate("Cannot blit: source palette too large."));
225216
}
226-
227-
int16_t x2, y2;
217+
218+
int16_t x1, y1, x2, y2;
228219
// if x2 or y2 is None, then set as the maximum size of the source bitmap
229220
if ( args[ARG_x2].u_obj == mp_const_none ) {
230-
x2 = source->width-1;
221+
x2 = source->width;
231222
} else {
232223
x2 = mp_obj_get_int(args[ARG_x2].u_obj);
233224
}
234225
//int16_t y2;
235226
if ( args[ARG_y2].u_obj == mp_const_none ) {
236-
y2 = source->height-1;
227+
y2 = source->height;
237228
} else {
238229
y2 = mp_obj_get_int(args[ARG_y2].u_obj);
239230
}
240231

241232

242233
// Check x,y are within self (target) bitmap boundary
243-
if ( (x < 0) || (y < 0) || (x >= self->width) || (y >= self->height) ) {
234+
if ( (x < 0) || (y < 0) || (x > self->width) || (y > self->height) ) {
244235
mp_raise_ValueError(translate("(x,y): out of range of target bitmap"));
245236
}
246237
// Check x1,y1,x2,y2 are within source bitmap boundary
247-
if ( (x1 < 0) || (x1 >= source->width) ||
248-
(y1 < 0) || (y1 >= source->height) ||
249-
(x2 < 0) || (x2 >= source->width) ||
250-
(y2 < 0) || (y2 >= source->height) ) {
238+
if ( (x1 < 0) || (x1 > source->width) ||
239+
(y1 < 0) || (y1 > source->height) ||
240+
(x2 < 0) || (x2 > source->width) ||
241+
(y2 < 0) || (y2 > source->height) ) {
251242
mp_raise_ValueError(translate("(x1,y1) or (x2,y2): out of range of source bitmap"));
252243
}
253244

@@ -272,7 +263,7 @@ STATIC mp_obj_t displayio_bitmap_obj_blit(size_t n_args, const mp_obj_t *pos_arg
272263
} else {
273264
skip_index = mp_obj_get_int(args[ARG_skip_index].u_obj);
274265
skip_index_none = false;
275-
}
266+
}
276267

277268
common_hal_displayio_bitmap_blit(self, x, y, source, x1, y1, x2, y2, skip_index, skip_index_none);
278269

shared-module/displayio/Bitmap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ void common_hal_displayio_bitmap_blit(displayio_bitmap_t *self, int16_t x, int16
118118
}
119119

120120
// simplest version - use internal functions for get/set pixels
121-
for (int16_t i=0; i<= (x2-x1) ; i++) {
121+
for (int16_t i=0; i < (x2-x1) ; i++) {
122122
if ( (x+i >= 0) && (x+i < self->width) ) {
123-
for (int16_t j=0; j<= (y2-y1) ; j++){
123+
for (int16_t j=0; j < (y2-y1) ; j++){
124124
if ((y+j >= 0) && (y+j < self->height) ) {
125125
uint32_t value = common_hal_displayio_bitmap_get_pixel(source, x1+i, y1+j);
126126
if ( (skip_index_none) || (value != skip_index) ) { // write if skip_value_none is True

0 commit comments

Comments
 (0)