@@ -373,81 +373,46 @@ const mp_obj_property_t displayio_display_bus_obj = {
373373};
374374
375375
376-
377-
378376#include "py/objarray.h"
379377mp_obj_array_t * array_new (char typecode , size_t n );
380378mp_obj_t array_subscr (mp_obj_t self_in , mp_obj_t index_in , mp_obj_t value );
381379
382- //| .. method:: fill_area(x, y, w, h )
380+ //| .. method:: fill_row( y, buffer )
383381//|
384- //| Switches to displaying the given group of layers. When group is None, the default
385- //| CircuitPython terminal will be shown.
382+ //| Extract the pixels fro a single row
386383//|
387- //| :param int x: The left edge of the area
388384//| :param int y: The top edge of the area
389- //| :param int w: The width of the area
390- //| :param int h: The height of the area
391- STATIC mp_obj_t displayio_display_obj_fill_area (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
392- enum { ARG_x , ARG_y , ARG_width , ARG_height , ARG_buffer };
385+ //| :param bytearray buffer: The buffer in which to place the pixel data
386+ STATIC mp_obj_t displayio_display_obj_fill_row (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
387+ enum { ARG_y , ARG_buffer };
393388 static const mp_arg_t allowed_args [] = {
394- { MP_QSTR_x , MP_ARG_INT | MP_ARG_KW_ONLY , {.u_int = -1 } },
395389 { MP_QSTR_y , MP_ARG_INT | MP_ARG_KW_ONLY , {.u_int = -1 } },
396- { MP_QSTR_width , MP_ARG_INT | MP_ARG_KW_ONLY , {.u_int = -1 } },
397- { MP_QSTR_height , MP_ARG_INT | MP_ARG_KW_ONLY , {.u_int = -1 } },
398390 { MP_QSTR_buffer , MP_ARG_OBJ | MP_ARG_KW_ONLY , {} },
399391 };
400392 mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
401393 mp_arg_parse_all (n_args - 1 , pos_args + 1 , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
402-
403394 displayio_display_obj_t * self = native_display (pos_args [0 ]);
404- mp_int_t x = args [ARG_x ].u_int ;
405395 mp_int_t y = args [ARG_y ].u_int ;
406- mp_int_t w = args [ARG_width ].u_int ;
407- mp_int_t h = args [ARG_height ].u_int ;
408396 mp_obj_array_t * result = (mp_obj_array_t * )(args [ARG_buffer ].u_obj );
409397
410398 if (result -> typecode != BYTEARRAY_TYPECODE ) {
411- mp_raise_ValueError (translate ("Buffer is not a bytearray" ));
399+ mp_raise_ValueError (translate ("Buffer is not a bytearray." ));
400+ }
401+ if (self -> colorspace .depth != 16 ) {
402+ mp_raise_ValueError (translate ("Display must have a 16 bit colorspace." ));
412403 }
413404
414- uint16_t buffer_size = 128 ; // In uint32_ts
415405 displayio_area_t area = {
416- .x1 = x ,
406+ .x1 = 0 ,
417407 .y1 = y ,
418- .x2 = x + w ,
419- .y2 = y + h
408+ .x2 = self -> width ,
409+ .y2 = y + 1
420410 };
421- displayio_area_t clipped ;
422- // Clip the area to the display by overlapping the areas. If there is no overlap then we're done.
423- if (!displayio_display_clip_area (self , & area , & clipped )) {
424- return mp_const_none ;
425- }
426- uint16_t subrectangles = 1 ;
427- uint16_t rows_per_buffer = displayio_area_height (& clipped );
428411 uint8_t pixels_per_word = (sizeof (uint32_t ) * 8 ) / self -> colorspace .depth ;
429- uint16_t pixels_per_buffer = displayio_area_size (& clipped );
430- if (displayio_area_size (& clipped ) > buffer_size * pixels_per_word ) {
431- rows_per_buffer = buffer_size * pixels_per_word / displayio_area_width (& clipped );
432- if (rows_per_buffer == 0 ) {
433- rows_per_buffer = 1 ;
434- }
435- // If pixels are packed by column then ensure rows_per_buffer is on a byte boundary.
436- if (self -> colorspace .depth < 8 && !self -> colorspace .pixels_in_byte_share_row ) {
437- uint8_t pixels_per_byte = 8 / self -> colorspace .depth ;
438- if (rows_per_buffer % pixels_per_byte != 0 ) {
439- rows_per_buffer -= rows_per_buffer % pixels_per_byte ;
440- }
441- }
442- subrectangles = displayio_area_height (& clipped ) / rows_per_buffer ;
443- if (displayio_area_height (& clipped ) % rows_per_buffer != 0 ) {
444- subrectangles ++ ;
445- }
446- pixels_per_buffer = rows_per_buffer * displayio_area_width (& clipped );
447- buffer_size = pixels_per_buffer / pixels_per_word ;
448- if (pixels_per_buffer % pixels_per_word ) {
449- buffer_size += 1 ;
450- }
412+ uint16_t buffer_size = self -> width / pixels_per_word ;
413+ uint16_t pixels_per_buffer = displayio_area_size (& area );
414+ if (pixels_per_buffer % pixels_per_word ) {
415+ buffer_size += 1 ;
451416 }
452417
453418 // Allocated and shared as a uint32_t array so the compiler knows the
@@ -480,7 +445,7 @@ STATIC mp_obj_t displayio_display_obj_fill_area(size_t n_args, const mp_obj_t *p
480445 mp_raise_ValueError (translate ("Buffer is too small" ));
481446 }
482447}
483- MP_DEFINE_CONST_FUN_OBJ_KW (displayio_display_fill_area_obj , 1 , displayio_display_obj_fill_area );
448+ MP_DEFINE_CONST_FUN_OBJ_KW (displayio_display_fill_row_obj , 1 , displayio_display_obj_fill_row );
484449
485450
486451
@@ -489,7 +454,7 @@ STATIC const mp_rom_map_elem_t displayio_display_locals_dict_table[] = {
489454 { MP_ROM_QSTR (MP_QSTR_show ), MP_ROM_PTR (& displayio_display_show_obj ) },
490455 { MP_ROM_QSTR (MP_QSTR_refresh_soon ), MP_ROM_PTR (& displayio_display_refresh_soon_obj ) },
491456 { MP_ROM_QSTR (MP_QSTR_wait_for_frame ), MP_ROM_PTR (& displayio_display_wait_for_frame_obj ) },
492- { MP_ROM_QSTR (MP_QSTR_fill_area ), MP_ROM_PTR (& displayio_display_fill_area_obj ) },
457+ { MP_ROM_QSTR (MP_QSTR_fill_row ), MP_ROM_PTR (& displayio_display_fill_row_obj ) },
493458
494459 { MP_ROM_QSTR (MP_QSTR_brightness ), MP_ROM_PTR (& displayio_display_brightness_obj ) },
495460 { MP_ROM_QSTR (MP_QSTR_auto_brightness ), MP_ROM_PTR (& displayio_display_auto_brightness_obj ) },
@@ -498,7 +463,6 @@ STATIC const mp_rom_map_elem_t displayio_display_locals_dict_table[] = {
498463 { MP_ROM_QSTR (MP_QSTR_height ), MP_ROM_PTR (& displayio_display_height_obj ) },
499464 { MP_ROM_QSTR (MP_QSTR_rotation ), MP_ROM_PTR (& displayio_display_rotation_obj ) },
500465 { MP_ROM_QSTR (MP_QSTR_bus ), MP_ROM_PTR (& displayio_display_bus_obj ) },
501- // { MP_ROM_QSTR(MP_QSTR_screenshot), MP_ROM_PTR(&displayio_display_screenshot_obj) },
502466};
503467STATIC MP_DEFINE_CONST_DICT (displayio_display_locals_dict , displayio_display_locals_dict_table );
504468
0 commit comments