38
38
39
39
STATIC int16_t validate_point (mp_obj_t point , int16_t default_value ) {
40
40
// Checks if point is None and returns default_value, otherwise decodes integer value
41
- if ( point == mp_const_none ) {
41
+ if (point == mp_const_none ) {
42
42
return default_value ;
43
43
}
44
44
return mp_obj_get_int (point );
@@ -47,21 +47,21 @@ STATIC int16_t validate_point(mp_obj_t point, int16_t default_value) {
47
47
STATIC void extract_tuple (mp_obj_t xy_tuple , int16_t * x , int16_t * y , int16_t x_default , int16_t y_default ) {
48
48
// Helper function for rotozoom
49
49
// Extract x,y values from a tuple or default if None
50
- if ( xy_tuple == mp_const_none ) {
50
+ if (xy_tuple == mp_const_none ) {
51
51
* x = x_default ;
52
52
* y = y_default ;
53
- } else if ( !MP_OBJ_IS_OBJ (xy_tuple ) ) {
53
+ } else if (!MP_OBJ_IS_OBJ (xy_tuple )) {
54
54
mp_raise_ValueError (translate ("clip point must be (x,y) tuple" ));
55
55
} else {
56
- mp_obj_t * items ;
56
+ mp_obj_t * items ;
57
57
mp_obj_get_array_fixed_n (xy_tuple , 2 , & items );
58
58
* x = mp_obj_get_int (items [0 ]);
59
59
* y = mp_obj_get_int (items [1 ]);
60
60
}
61
61
}
62
62
63
63
STATIC void validate_clip_region (displayio_bitmap_t * bitmap , mp_obj_t clip0_tuple , int16_t * clip0_x , int16_t * clip0_y ,
64
- mp_obj_t clip1_tuple , int16_t * clip1_x , int16_t * clip1_y ) {
64
+ mp_obj_t clip1_tuple , int16_t * clip1_x , int16_t * clip1_y ) {
65
65
// Helper function for rotozoom
66
66
// 1. Extract the clip x,y points from the two clip tuples
67
67
// 2. Rearrange values such that clip0_ < clip1_
@@ -71,12 +71,12 @@ STATIC void validate_clip_region(displayio_bitmap_t *bitmap, mp_obj_t clip0_tupl
71
71
extract_tuple (clip1_tuple , clip1_x , clip1_y , bitmap -> width , bitmap -> height );
72
72
73
73
// Ensure the value for clip0 is less than clip1 (for both x and y)
74
- if ( * clip0_x > * clip1_x ) {
74
+ if (* clip0_x > * clip1_x ) {
75
75
int16_t temp_value = * clip0_x ; // swap values
76
76
* clip0_x = * clip1_x ;
77
77
* clip1_x = temp_value ;
78
78
}
79
- if ( * clip0_y > * clip1_y ) {
79
+ if (* clip0_y > * clip1_y ) {
80
80
int16_t temp_value = * clip0_y ; // swap values
81
81
* clip0_y = * clip1_y ;
82
82
* clip1_y = temp_value ;
@@ -144,11 +144,11 @@ STATIC void validate_clip_region(displayio_bitmap_t *bitmap, mp_obj_t clip0_tupl
144
144
//| set to None to copy all pixels"""
145
145
//| ...
146
146
//|
147
- STATIC mp_obj_t bitmaptools_obj_rotozoom (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ){
147
+ STATIC mp_obj_t bitmaptools_obj_rotozoom (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
148
148
enum {ARG_dest_bitmap , ARG_source_bitmap ,
149
- ARG_ox , ARG_oy , ARG_dest_clip0 , ARG_dest_clip1 ,
150
- ARG_px , ARG_py , ARG_source_clip0 , ARG_source_clip1 ,
151
- ARG_angle , ARG_scale , ARG_skip_index };
149
+ ARG_ox , ARG_oy , ARG_dest_clip0 , ARG_dest_clip1 ,
150
+ ARG_px , ARG_py , ARG_source_clip0 , ARG_source_clip1 ,
151
+ ARG_angle , ARG_scale , ARG_skip_index };
152
152
153
153
static const mp_arg_t allowed_args [] = {
154
154
{MP_QSTR_dest_bitmap , MP_ARG_REQUIRED | MP_ARG_OBJ },
@@ -166,7 +166,7 @@ STATIC mp_obj_t bitmaptools_obj_rotozoom(size_t n_args, const mp_obj_t *pos_args
166
166
167
167
{MP_QSTR_angle , MP_ARG_KW_ONLY | MP_ARG_OBJ , {.u_obj = mp_const_none } }, // None convert to 0.0
168
168
{MP_QSTR_scale , MP_ARG_KW_ONLY | MP_ARG_OBJ , {.u_obj = mp_const_none } }, // None convert to 1.0
169
- {MP_QSTR_skip_index , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = mp_const_none } },
169
+ {MP_QSTR_skip_index , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = mp_const_none } },
170
170
};
171
171
172
172
mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
@@ -183,35 +183,35 @@ STATIC mp_obj_t bitmaptools_obj_rotozoom(size_t n_args, const mp_obj_t *pos_args
183
183
184
184
// Confirm the destination location target (ox,oy); if None, default to bitmap midpoint
185
185
int16_t ox , oy ;
186
- ox = validate_point (args [ARG_ox ].u_obj , destination -> width / 2 );
186
+ ox = validate_point (args [ARG_ox ].u_obj , destination -> width / 2 );
187
187
oy = validate_point (args [ARG_oy ].u_obj , destination -> height / 2 );
188
188
189
189
// Confirm the source location target (px,py); if None, default to bitmap midpoint
190
190
int16_t px , py ;
191
- px = validate_point (args [ARG_px ].u_obj , source -> width / 2 );
191
+ px = validate_point (args [ARG_px ].u_obj , source -> width / 2 );
192
192
py = validate_point (args [ARG_py ].u_obj , source -> height / 2 );
193
193
194
194
// Validate the clipping regions for the destination bitmap
195
195
int16_t dest_clip0_x , dest_clip0_y , dest_clip1_x , dest_clip1_y ;
196
196
197
197
validate_clip_region (destination , args [ARG_dest_clip0 ].u_obj , & dest_clip0_x , & dest_clip0_y ,
198
- args [ARG_dest_clip1 ].u_obj , & dest_clip1_x , & dest_clip1_y );
198
+ args [ARG_dest_clip1 ].u_obj , & dest_clip1_x , & dest_clip1_y );
199
199
200
200
// Validate the clipping regions for the source bitmap
201
201
int16_t source_clip0_x , source_clip0_y , source_clip1_x , source_clip1_y ;
202
202
203
203
validate_clip_region (source , args [ARG_source_clip0 ].u_obj , & source_clip0_x , & source_clip0_y ,
204
- args [ARG_source_clip1 ].u_obj , & source_clip1_x , & source_clip1_y );
204
+ args [ARG_source_clip1 ].u_obj , & source_clip1_x , & source_clip1_y );
205
205
206
206
// Confirm the angle value
207
- float angle = 0.0 ;
208
- if ( args [ARG_angle ].u_obj != mp_const_none ) {
207
+ float angle = 0.0 ;
208
+ if (args [ARG_angle ].u_obj != mp_const_none ) {
209
209
angle = mp_obj_get_float (args [ARG_angle ].u_obj );
210
210
}
211
211
212
212
// Confirm the scale value
213
- float scale = 1.0 ;
214
- if ( args [ARG_scale ].u_obj != mp_const_none ) {
213
+ float scale = 1.0 ;
214
+ if (args [ARG_scale ].u_obj != mp_const_none ) {
215
215
scale = mp_obj_get_float (args [ARG_scale ].u_obj );
216
216
}
217
217
if (scale < 0 ) { // ensure scale >= 0
@@ -220,7 +220,7 @@ STATIC mp_obj_t bitmaptools_obj_rotozoom(size_t n_args, const mp_obj_t *pos_args
220
220
221
221
uint32_t skip_index ;
222
222
bool skip_index_none ; // Flag whether input skip_value was None
223
- if (args [ARG_skip_index ].u_obj == mp_const_none ) {
223
+ if (args [ARG_skip_index ].u_obj == mp_const_none ) {
224
224
skip_index = 0 ;
225
225
skip_index_none = true;
226
226
} else {
@@ -229,14 +229,14 @@ STATIC mp_obj_t bitmaptools_obj_rotozoom(size_t n_args, const mp_obj_t *pos_args
229
229
}
230
230
231
231
common_hal_bitmaptools_rotozoom (destination , ox , oy ,
232
- dest_clip0_x , dest_clip0_y ,
233
- dest_clip1_x , dest_clip1_y ,
234
- source , px , py ,
235
- source_clip0_x , source_clip0_y ,
236
- source_clip1_x , source_clip1_y ,
237
- angle ,
238
- scale ,
239
- skip_index , skip_index_none );
232
+ dest_clip0_x , dest_clip0_y ,
233
+ dest_clip1_x , dest_clip1_y ,
234
+ source , px , py ,
235
+ source_clip0_x , source_clip0_y ,
236
+ source_clip1_x , source_clip1_y ,
237
+ angle ,
238
+ scale ,
239
+ skip_index , skip_index_none );
240
240
241
241
return mp_const_none ;
242
242
}
@@ -262,7 +262,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitmaptools_rotozoom_obj, 0, bitmaptools_obj_rotozoom
262
262
//| fill region in the destination bitmap"""
263
263
//| ...
264
264
//|
265
- STATIC mp_obj_t bitmaptools_obj_fill_region (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ){
265
+ STATIC mp_obj_t bitmaptools_obj_fill_region (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
266
266
enum {ARG_dest_bitmap , ARG_x1 , ARG_y1 , ARG_x2 , ARG_y2 , ARG_value };
267
267
268
268
static const mp_arg_t allowed_args [] = {
@@ -282,8 +282,8 @@ STATIC mp_obj_t bitmaptools_obj_fill_region(size_t n_args, const mp_obj_t *pos_a
282
282
value = args [ARG_value ].u_int ;
283
283
color_depth = (1 << destination -> bits_per_value );
284
284
if (color_depth <= value ) {
285
- mp_raise_ValueError (translate ("out of range of target" ));
286
- }
285
+ mp_raise_ValueError (translate ("out of range of target" ));
286
+ }
287
287
288
288
int16_t x1 = args [ARG_x1 ].u_int ;
289
289
int16_t y1 = args [ARG_y1 ].u_int ;
@@ -315,7 +315,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitmaptools_fill_region_obj, 0, bitmaptools_obj_fill_
315
315
//| line in the destination bitmap"""
316
316
//| ...
317
317
//|
318
- STATIC mp_obj_t bitmaptools_obj_draw_line (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ){
318
+ STATIC mp_obj_t bitmaptools_obj_draw_line (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
319
319
enum {ARG_dest_bitmap , ARG_x1 , ARG_y1 , ARG_x2 , ARG_y2 , ARG_value };
320
320
321
321
static const mp_arg_t allowed_args [] = {
@@ -335,18 +335,18 @@ STATIC mp_obj_t bitmaptools_obj_draw_line(size_t n_args, const mp_obj_t *pos_arg
335
335
value = args [ARG_value ].u_int ;
336
336
color_depth = (1 << destination -> bits_per_value );
337
337
if (color_depth <= value ) {
338
- mp_raise_ValueError (translate ("out of range of target" ));
339
- }
338
+ mp_raise_ValueError (translate ("out of range of target" ));
339
+ }
340
340
341
341
int16_t x1 = args [ARG_x1 ].u_int ;
342
342
int16_t y1 = args [ARG_y1 ].u_int ;
343
343
int16_t x2 = args [ARG_x2 ].u_int ;
344
344
int16_t y2 = args [ARG_y2 ].u_int ;
345
345
346
346
// verify points are within the bitmap boundary (inclusive)
347
- if ( (x1 < 0 ) || (x2 < 0 ) || (y1 < 0 ) || (y2 < 0 ) ||
348
- (x1 >= destination -> width ) || (x2 >= destination -> width ) ||
349
- (y1 >= destination -> height ) || (y2 >= destination -> height ) ) {
347
+ if ((x1 < 0 ) || (x2 < 0 ) || (y1 < 0 ) || (y2 < 0 ) ||
348
+ (x1 >= destination -> width ) || (x2 >= destination -> width ) ||
349
+ (y1 >= destination -> height ) || (y2 >= destination -> height )) {
350
350
mp_raise_ValueError (translate ("out of range of target" ));
351
351
}
352
352
@@ -399,7 +399,7 @@ STATIC mp_obj_t bitmaptools_arrayblit(size_t n_args, const mp_obj_t *pos_args, m
399
399
{ MP_QSTR_y2 , MP_ARG_INT , {.u_int = -1 } },
400
400
{ MP_QSTR_skip_index , MP_ARG_OBJ , {.u_obj = mp_const_none } },
401
401
}
402
- ;
402
+ ;
403
403
mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
404
404
mp_arg_parse_all (n_args , pos_args , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
405
405
@@ -420,7 +420,7 @@ STATIC mp_obj_t bitmaptools_arrayblit(size_t n_args, const mp_obj_t *pos_args, m
420
420
mp_raise_IndexError (translate ("pixel coordinates out of bounds" ));
421
421
}
422
422
423
- size_t output_element_count = (x2 - x1 ) * (y2 - y1 );
423
+ size_t output_element_count = (x2 - x1 ) * (y2 - y1 );
424
424
size_t element_size = mp_binary_get_size ('@' , bufinfo .typecode , NULL );
425
425
size_t input_element_count = bufinfo .len / element_size ;
426
426
@@ -477,11 +477,11 @@ STATIC mp_obj_t bitmaptools_readinto(size_t n_args, const mp_obj_t *pos_args, mp
477
477
if (!MP_OBJ_IS_TYPE (args [ARG_file ].u_obj , & mp_type_fileio )) {
478
478
mp_raise_TypeError (NULL );
479
479
}
480
- pyb_file_obj_t * file = MP_OBJ_TO_PTR (args [ARG_file ].u_obj );
480
+ pyb_file_obj_t * file = MP_OBJ_TO_PTR (args [ARG_file ].u_obj );
481
481
482
482
int element_size = args [ARG_element_size ].u_int ;
483
483
if (element_size != 1 && element_size != 2 && element_size != 4 ) {
484
- mp_raise_ValueError_varg (translate ("invalid element_size %d, must be, 1, 2, or 4" ), element_size );
484
+ mp_raise_ValueError_varg (translate ("invalid element_size %d, must be, 1, 2, or 4" ), element_size );
485
485
}
486
486
487
487
int bits_per_pixel = args [ARG_bits_per_pixel ].u_int ;
@@ -523,5 +523,5 @@ STATIC MP_DEFINE_CONST_DICT(bitmaptools_module_globals, bitmaptools_module_globa
523
523
524
524
const mp_obj_module_t bitmaptools_module = {
525
525
.base = {& mp_type_module },
526
- .globals = (mp_obj_dict_t * )& bitmaptools_module_globals ,
526
+ .globals = (mp_obj_dict_t * )& bitmaptools_module_globals ,
527
527
};
0 commit comments