56
56
//| according to the ``weights``. Then a scaling factor ``mul`` and an
57
57
//| offset factor ``add`` are applied.
58
58
//|
59
- //| The ``weights`` must be a tuple of integers. The length of the tuple
59
+ //| The ``weights`` must be a sequence of integers. The length of the tuple
60
60
//| must be the square of an odd number, usually 9 and sometimes 25.
61
61
//| Specific weights create different effects. For instance, these
62
- //| weights represent a 3x3 gaussian blur:
62
+ //| weights represent a 3x3 gaussian blur: ``[1, 2, 1, 2, 4, 2, 1, 2, 1]``
63
63
//|
64
64
//| ``mul`` is number to multiply the convolution pixel results by.
65
65
//| If `None` (the default) is passed, the value of ``1/sum(weights)``
66
- //| is used (or ``1`` if ``sum(weights)`` is 0 ). For most weights, his
66
+ //| is used (or ``1`` if ``sum(weights)`` is ``0`` ). For most weights, his
67
67
//| default value will preserve the overall image brightness.
68
68
//|
69
69
//| ``add`` is a value to add to each convolution pixel result.
@@ -165,9 +165,12 @@ static mp_float_t float_subscr(mp_obj_t o, int i) {
165
165
return mp_obj_get_float (subscr (o , i ));
166
166
}
167
167
168
- //| ChannelScale = namedtuple("ChannelScale", ["r", "g", "b"])
169
- //| """A weight object to use with mix() that scales each channel
170
- //| independently."""
168
+ //| class ChannelScale:
169
+ //| """A weight object to use with mix()"""
170
+ //|
171
+ //| def __init__(self, r: float, g: float, b: float) -> None:
172
+ //| """The parameters each give a scale to apply to the respective image component"""
173
+ //|
171
174
static const mp_obj_namedtuple_type_t bitmapfilter_channel_scale_type = {
172
175
NAMEDTUPLE_TYPE_BASE_AND_SLOTS (MP_QSTR_ChannelScale ),
173
176
.n_fields = 3 ,
@@ -177,9 +180,18 @@ static const mp_obj_namedtuple_type_t bitmapfilter_channel_scale_type = {
177
180
MP_QSTR_b ,
178
181
},
179
182
};
180
- //| ChannelScaleOffset = namedtuple("ChannelScale", ["r", "g", "b", "r_add", "g_add", "b_add"])
181
- //| """A weight object to use with mix() that scales each channel
182
- //| independently and adds an offset."""
183
+ //| class ChannelScaleOffset:
184
+ //| """A weight object to use with mix()"""
185
+ //|
186
+ //| def __init__(
187
+ //| self, r: float, r_add: float, g: float, g_add: float, b: float, b_add: float
188
+ //| ) -> None:
189
+ //| """Scale and offset each channel independently.
190
+ //|
191
+ //| The ``r``, ``g``, and ``b`` parameters each give a scale to apply
192
+ //| to the respective image component, while the ``r_add``,
193
+ //| ``g_add``, and ``b_add`` parameters give an offset value to add."""
194
+ //|
183
195
static const mp_obj_namedtuple_type_t bitmapfilter_channel_scale_offset_type = {
184
196
NAMEDTUPLE_TYPE_BASE_AND_SLOTS (MP_QSTR_ChannelScaleOffset ),
185
197
.n_fields = 6 ,
@@ -193,11 +205,28 @@ static const mp_obj_namedtuple_type_t bitmapfilter_channel_scale_offset_type = {
193
205
},
194
206
};
195
207
196
- //| ChannelMixer = namedtuple(
197
- //| "ChannelMixer", ["rr", "rg", "rb", "gr", "gg", "gb", "br", "bg", "bb"]
198
- //| )
199
- //| """A weight object to use with mix() that mixes in portions of each
200
- //| channel into every other channel. For instance ``rg`` gives the portion of the green channel to mix into red."""
208
+ //| class ChannelMixer:
209
+ //| """A weight object to use with mix()"""
210
+ //|
211
+ //| def __init__(
212
+ //| self,
213
+ //| rr: float,
214
+ //| rg: float,
215
+ //| rb: float,
216
+ //| gr: float,
217
+ //| gg: float,
218
+ //| gb: float,
219
+ //| br: float,
220
+ //| bg: float,
221
+ //| bb: float,
222
+ //| ) -> None:
223
+ //| """Perform a mixing operation where each channel can receive a fraction of every other channel.
224
+ //|
225
+ //| The parameters with names like ``rb`` give the fraction of
226
+ //| each channel to mix into every other channel. For instance,
227
+ //| ``rb`` gives the fraction of blue to mix into red, and ``gg``
228
+ //| gives the fraction of green to mix into green."""
229
+ //|
201
230
static const mp_obj_namedtuple_type_t bitmapfilter_channel_mixer_type = {
202
231
NAMEDTUPLE_TYPE_BASE_AND_SLOTS (MP_QSTR_ChannelMixer ),
203
232
.n_fields = 9 ,
@@ -214,12 +243,31 @@ static const mp_obj_namedtuple_type_t bitmapfilter_channel_mixer_type = {
214
243
},
215
244
};
216
245
217
- //| ChannelMixerOffset = namedtuple(
218
- //| "ChannelMixerOffset",
219
- //| ["rr", "rg", "rb", "r_add", "gr", "gg", "gb", "g_add", "br", "bg", "bb", "b_add"],
220
- //| )
221
- //| """A weight object to use with mix() that mixes in portions of each
222
- //| channel into every other channel and adds an offset. For instance ``rg`` gives the portion of the green channel to mix into red."""
246
+ //| class ChannelMixerOffset:
247
+ //| """A weight object to use with mix()"""
248
+ //|
249
+ //| def __init__(
250
+ //| self,
251
+ //| rr: float,
252
+ //| rg: float,
253
+ //| rb: float,
254
+ //| r_add: float,
255
+ //| gr: float,
256
+ //| gg: float,
257
+ //| gb: float,
258
+ //| g_add: float,
259
+ //| br: float,
260
+ //| bg: float,
261
+ //| bb: float,
262
+ //| b_add: float,
263
+ //| ) -> None:
264
+ //| """Perform a mixing operation where each channel can receive a fraction of every other channel, plus an offset value.
265
+ //|
266
+ //| The parameters with names like ``rb`` give the fraction of
267
+ //| each channel to mix into every other channel. For instance,
268
+ //| ``rb`` gives the fraction of blue to mix into red, and ``gg``
269
+ //| gives the fraction of green to mix into green. The ``_add``
270
+ //| parameters give an offset value to add to the channel."""
223
271
//|
224
272
static const mp_obj_namedtuple_type_t bitmapfilter_channel_mixer_offset_type = {
225
273
NAMEDTUPLE_TYPE_BASE_AND_SLOTS (MP_QSTR_ChannelMixerOffset ),
@@ -368,7 +416,10 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitmapfilter_solarize_obj, 0, bitmapfilter_solarize);
368
416
369
417
370
418
//| LookupFunction = Callable[[float], float]
419
+ //| """Any function which takes a number and returns a number. The input
420
+ //| and output values should be in the range from 0 to 1 inclusive."""
371
421
//| ThreeLookupFunctions = Tuple[LookupFunction, LookupFunction, LookupFunction]
422
+ //| """Any sequenceof three `LookupFunction` objects"""
372
423
//|
373
424
//| def lookup(
374
425
//| bitmap: displayio.Bitmap,
0 commit comments