@@ -135,7 +135,7 @@ MP_PROPERTY_GETTER(pixelmap_pixelmap_byteorder_obj,
135
135
(mp_obj_t )& pixelmap_pixelmap_get_byteorder );
136
136
137
137
//|
138
- //| def fill(self, color: PixelType, / ) -> None:
138
+ //| def fill(self, color: PixelType) -> None:
139
139
//| """Fill all the pixels in the map with the given color"""
140
140
STATIC mp_obj_t pixelmap_pixelmap_fill (const mp_obj_t self_in , const mp_obj_t color ) {
141
141
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
146
146
MP_DEFINE_CONST_FUN_OBJ_2 (pixelmap_pixelmap_fill_obj , pixelmap_pixelmap_fill );
147
147
148
148
//|
149
- //| def indices(self, index: int, / ) -> Tuple[int]:
149
+ //| def indices(self, index: int) -> Tuple[int]:
150
150
//| """Return the PixelBuf indices for a PixelMap index"""
151
151
STATIC mp_obj_t pixelmap_pixelmap_indices (const mp_obj_t self_in , const mp_obj_t index ) {
152
152
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
157
157
MP_DEFINE_CONST_FUN_OBJ_2 (pixelmap_pixelmap_indices_obj , pixelmap_pixelmap_indices );
158
158
159
159
160
+ //| @overload
161
+ //| def __getitem__(self, index: slice) -> PixelReturnSequence:
162
+ //| """Retrieve the value of the underlying pixels."""
163
+ //| ...
164
+ //| @overload
160
165
//| 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
+
8000
//| """Retrieve the value of one of the underlying pixels at 'index'."""
167
+ //| ...
164
168
//| @overload
165
169
//| def __setitem__(self, index: slice, value: PixelSequence) -> None: ...
166
170
//| @overload
@@ -176,21 +180,41 @@ STATIC mp_obj_t pixelmap_pixelmap_subscr(mp_obj_t self_in, mp_obj_t index_in, mp
176
180
if (value == MP_OBJ_NULL ) {
177
181
// delete
178
182
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 );
182
183
}
183
184
184
- // get
185
185
if (0 ) {
186
186
#if MICROPY_PY_BUILTINS_SLICE
187
187
} 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
+ }
189
207
#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
+ }
192
217
}
193
- return mp_const_none ;
194
218
}
195
219
196
220
//| def __len__(self) -> int:
0 commit comments