Skip to content

Commit ce5c108

Browse files
committed
bitmapfilter: Doc improvements.
1 parent 1ff6e1a commit ce5c108

File tree

1 file changed

+71
-20
lines changed

1 file changed

+71
-20
lines changed

shared-bindings/bitmapfilter/__init__.c

Lines changed: 71 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@
5656
//| according to the ``weights``. Then a scaling factor ``mul`` and an
5757
//| offset factor ``add`` are applied.
5858
//|
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
6060
//| must be the square of an odd number, usually 9 and sometimes 25.
6161
//| 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]``
6363
//|
6464
//| ``mul`` is number to multiply the convolution pixel results by.
6565
//| 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
6767
//| default value will preserve the overall image brightness.
6868
//|
6969
//| ``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) {
165165
return mp_obj_get_float(subscr(o, i));
166166
}
167167

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+
//|
171174
static const mp_obj_namedtuple_type_t bitmapfilter_channel_scale_type = {
172175
NAMEDTUPLE_TYPE_BASE_AND_SLOTS(MP_QSTR_ChannelScale),
173176
.n_fields = 3,
@@ -177,9 +180,18 @@ static const mp_obj_namedtuple_type_t bitmapfilter_channel_scale_type = {
177180
MP_QSTR_b,
178181
},
179182
};
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+
//|
183195
static const mp_obj_namedtuple_type_t bitmapfilter_channel_scale_offset_type = {
184196
NAMEDTUPLE_TYPE_BASE_AND_SLOTS(MP_QSTR_ChannelScaleOffset),
185197
.n_fields = 6,
@@ -193,11 +205,28 @@ static const mp_obj_namedtuple_type_t bitmapfilter_channel_scale_offset_type = {
193205
},
194206
};
195207

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+
//|
201230
static const mp_obj_namedtuple_type_t bitmapfilter_channel_mixer_type = {
202231
NAMEDTUPLE_TYPE_BASE_AND_SLOTS(MP_QSTR_ChannelMixer),
203232
.n_fields = 9,
@@ -214,12 +243,31 @@ static const mp_obj_namedtuple_type_t bitmapfilter_channel_mixer_type = {
214243
},
215244
};
216245

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."""
223271
//|
224272
static const mp_obj_namedtuple_type_t bitmapfilter_channel_mixer_offset_type = {
225273
NAMEDTUPLE_TYPE_BASE_AND_SLOTS(MP_QSTR_ChannelMixerOffset),
@@ -368,7 +416,10 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitmapfilter_solarize_obj, 0, bitmapfilter_solarize);
368416

369417

370418
//| 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."""
371421
//| ThreeLookupFunctions = Tuple[LookupFunction, LookupFunction, LookupFunction]
422+
//| """Any sequenceof three `LookupFunction` objects"""
372423
//|
373424
//| def lookup(
374425
//| bitmap: displayio.Bitmap,

0 commit comments

Comments
 (0)