Skip to content

Commit ff3947a

Browse files
committed
bitmapfilter: improve documentation
1 parent 2ed31b6 commit ff3947a

File tree

1 file changed

+37
-9
lines changed

1 file changed

+37
-9
lines changed

shared-bindings/bitmapfilter/__init__.c

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
//|
4848
//| The name of the function comes from
4949
//| `OpenMV <https://docs.openmv.io/library/omv.image.html#image.Image.morph>`_.
50+
//| ImageMagick calls this "-morphology" ("-morph" is an unrelated image blending
51+
//| algorithm). PIL calls this "kernel".
5052
//|
5153
//| For background on how this kind of image processing, including some
5254
//| useful ``weights`` values, see `wikipedia's article on the
@@ -289,33 +291,37 @@ static const mp_obj_namedtuple_type_t bitmapfilter_channel_mixer_offset_type = {
289291
};
290292

291293
//| def mix(
292-
//| bitmap: displayio.Bitmap, weights: Sequence[int], mask: displayio.Bitmap | None = None
294+
//| bitmap: displayio.Bitmap,
295+
//| weights: ChannelScale | ChannelScaleOffset | ChannelMixer | ChannelMixerOffset,
296+
//| mask: displayio.Bitmap | None = None,
293297
//| ) -> displayio.Bitmap:
294298
//| """Perform a channel mixing operation on the bitmap
295299
//|
296300
//| This is similar to the "channel mixer" tool in popular photo editing software.
301+
//| Imagemagick calls this "-color-matrix". In PIL, this is accomplished with the
302+
//| ``convert`` method's ``matrix`` argument.
297303
//|
298304
//| The ``bitmap``, which must be in RGB565_SWAPPED format, is modified
299305
//| according to the ``weights``.
300306
//|
301-
//| If ``weights`` is a list of length 3 (or a `ChannelScale`
302-
//| object), then each channel is scaled independently: The
307+
//| If ``weights`` is a `ChannelScale`
308+
//| object, then each channel is scaled independently: The
303309
//| numbers are the red, green, and blue channel scales.
304310
//|
305-
//| If ``weights`` is a list of length 6 (or a `ChannelScaleOffset`
306-
//| object), then each channel is scaled and offset independently:
311+
//| If ``weights`` is a `ChannelScaleOffset`
312+
//| object, then each channel is scaled and offset independently:
307313
//| The first two numbers are applied to the red channel: scale and
308314
//| offset. The second two number are applied to the green channel,
309315
//| and the last two numbers to the blue channel.
310316
//|
311-
//| If ``weights`` is a list of length 9 (or a `ChannelMixer`
312-
//| object), then channels are mixed. The first three
317+
//| If ``weights`` is a `ChannelMixer`
318+
//| object, then channels are mixed. The first three
313319
//| numbers are the fraction of red, green and blue input channels
314320
//| mixed into the red output channel. The next 3 numbers are for
315321
//| green, and the final 3 are for blue.
316322
//|
317-
//| If ``weights`` is a list of length 12 (or a `ChannelMixerOffest`
318-
//| object), then channels are mixed with an offset.
323+
//| If ``weights`` `ChannelMixerOffset`
324+
//| object, then channels are mixed with an offset.
319325
//| Every fourth value is the offset value.
320326
//|
321327
//| ``mask`` is another image to use as a pixel level mask for the operation.
@@ -394,6 +400,20 @@ STATIC mp_obj_t bitmapfilter_mix(size_t n_args, const mp_obj_t *pos_args, mp_map
394400
}
395401
MP_DEFINE_CONST_FUN_OBJ_KW(bitmapfilter_mix_obj, 0, bitmapfilter_mix);
396402

403+
//| def solarize(bitmap, threshold: float = 0.5, mask: displayio.Bitmap | None = None):
404+
//| """Creat a "solarization" effect on an image
405+
//|
406+
//| This filter inverts pixels with brightness values above ``threshold``, while leaving
407+
//| lower brightness pixels alone.
408+
//|
409+
//| This effect is similar to `an effect observed in real life film
410+
//| <https://en.wikipedia.org/wiki/Solarization_(photography)>`_ which can also be
411+
//| `produced during the printmaking process
412+
//| <https://en.wikipedia.org/wiki/Sabattier_effect>`_
413+
//|
414+
//| PIL and ImageMagic both call this "solarize".
415+
//| """
416+
//|
397417
STATIC mp_obj_t bitmapfilter_solarize(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
398418
enum { ARG_bitmap, ARG_threshold, ARG_mask };
399419
static const mp_arg_t allowed_args[] = {
@@ -438,6 +458,9 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitmapfilter_solarize_obj, 0, bitmapfilter_solarize);
438458
//| This can be used to implement non-linear transformations of color values,
439459
//| such as gamma curves.
440460
//|
461+
//| This is similar to, but more limiting than, PIL's "LUT3D" facility. It is not
462+
//| directly available in OpenMV or ImageMagic.
463+
//|
441464
//| The ``bitmap``, which must be in RGB565_SWAPPED format, is modified
442465
//| according to the values of the ``lookup`` function or functions.
443466
//|
@@ -515,6 +538,11 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitmapfilter_lookup_obj, 0, bitmapfilter_lookup);
515538
//| ) -> displayio.Bitmap:
516539
//| """Convert the image to false color using the given palette
517540
//|
541+
//| In OpenMV this is accomplished via the ``ironbow`` function, which uses a default
542+
//| palette known as "ironbow". Imagemagic produces a similar effect with ``-clut``.
543+
//| PIL can accomplish this by converting an image to "L" format, then applying a
544+
//| palette to convert it into "P" mode.
545+
//|
518546
//| The ``bitmap``, which must be in RGB565_SWAPPED format, is converted into false color.
519547
//|
520548
//| The ``palette``, which must be of length 256, is used as a look-up table.

0 commit comments

Comments
 (0)