@@ -135,7 +135,7 @@ MP_PROPERTY_GETTER(pixelmap_pixelmap_byteorder_obj,
135135 (mp_obj_t )& pixelmap_pixelmap_get_byteorder );
136136
137137//|
138- //| def fill(self, color: PixelType, / ) -> None:
138+ //| def fill(self, color: PixelType) -> None:
139139//| """Fill all the pixels in the map with the given color"""
140140STATIC mp_obj_t pixelmap_pixelmap_fill (const mp_obj_t self_in , const mp_obj_t color ) {
141141 pixelmap_pixelmap_obj_t * self = MP_OBJ_TO_PTR (self_in );
@@ -146,7 +146,7 @@ STATIC mp_obj_t pixelmap_pixelmap_fill(const mp_obj_t self_in, const mp_obj_t co
146146MP_DEFINE_CONST_FUN_OBJ_2 (pixelmap_pixelmap_fill_obj , pixelmap_pixelmap_fill );
147147
148148//|
149- //| def indices(self, index: int, / ) -> Tuple[int]:
149+ //| def indices(self, index: int) -> Tuple[int]:
150150//| """Return the PixelBuf indices for a PixelMap index"""
151151STATIC mp_obj_t pixelmap_pixelmap_indices (const mp_obj_t self_in , const mp_obj_t index ) {
152152 pixelmap_pixelmap_obj_t * self = MP_OBJ_TO_PTR (self_in );
@@ -157,10 +157,14 @@ STATIC mp_obj_t pixelmap_pixelmap_indices(const mp_obj_t self_in, const mp_obj_t
157157MP_DEFINE_CONST_FUN_OBJ_2 (pixelmap_pixelmap_indices_obj , pixelmap_pixelmap_indices );
158158
159159
160+ //| @overload
161+ //| def __getitem__(self, index: slice) -> PixelReturnSequence:
162+ //| """Retrieve the value of the underlying pixels."""
163+ //| ...
164+ //| @overload
160165//| def __getitem__(self, index: int) -> PixelReturnType:
161- //| """Retrieve the value of one of the underlying pixels at 'index'.
162- //|
163- //| Note that slices are not supported by PixelMap.__getitem__"""
166+ //| """Retrieve the value of one of the underlying pixels at 'index'."""
167+ //| ...
164168//| @overload
165169//| def __setitem__(self, index: slice, value: PixelSequence) -> None: ...
166170//| @overload
@@ -176,21 +180,41 @@ STATIC mp_obj_t pixelmap_pixelmap_subscr(mp_obj_t self_in, mp_obj_t index_in, mp
176180 if (value == MP_OBJ_NULL ) {
177181 // delete
178182 return MP_OBJ_NULL ; // op not supported
179- } else if (value == MP_OBJ_SENTINEL ) {
180- int index = mp_obj_get_int (index_in );
181- return shared_module_pixelmap_pixelmap_getitem (self , index );
182183 }
183184
184- // get
185185 if (0 ) {
186186 #if MICROPY_PY_BUILTINS_SLICE
187187 } else if (mp_obj_is_type (index_in , & mp_type_slice )) {
188- shared_module_pixelmap_pixelmap_setslice (self , index_in , value );
188+ mp_bound_slice_t slice ;
189+ mp_seq_get_fast_slice_indexes (self -> len , index_in , & slice );
190+ size_t slice_len ;
191+ if (slice .step > 0 ) {
192+ slice_len = slice .stop - slice .start ;
193+ } else {
194+ slice_len = 1 + slice .start - slice .stop ;
195+ }
196+ if (slice .step > 1 || slice .step < -1 ) {
197+ size_t step = slice .step > 0 ? slice .step : slice .step * -1 ;
198+ slice_len = (slice_len / step ) + (slice_len % step ? 1 : 0 );
199+ }
200+
201+ if (value == MP_OBJ_SENTINEL ) { // Get
202+ return shared_module_pixelmap_pixelmap_getslice (self , slice , slice_len );
203+ } else { // Set
204+ shared_module_pixelmap_pixelmap_setslice (self , value , slice , slice_len );
205+ return mp_const_none ;
206+ }
189207 #endif
190- } else {
191- shared_module_pixelmap_pixelmap_setitem (self , mp_obj_get_int (index_in ), value );
208+ } else { // single index
209+ int index = mp_obj_get_int (index_in );
210+
211+ if (value == MP_OBJ_SENTINEL ) { // Get
212+ return shared_module_pixelmap_pixelmap_getitem (self , index );
213+ } else {
214+ shared_module_pixelmap_pixelmap_setitem (self , mp_obj_get_int (index_in ), value );
215+ return mp_const_none ;
216+ }
192217 }
193- return mp_const_none ;
194218}
195219
196220//| def __len__(self) -> int:
0 commit comments