Add a pixelate (mosaic) filter — average each N×N block of pixels into one colour. Classic, visually satisfying, great first PR.
Spec
- Name:
pixelate
- Usage:
pixelate=SIZE (block size in px; default 8, minimum 1)
- For each SIZE×SIZE block, average R/G/B/A over the covered pixels (clip at the right/bottom edges), then write that average back to every pixel in the block.
- Write
f_pixelate. Block size via argd(a, n, 0, 8.0) (clamp to ≥ 1). Loop blocks over in->h/in->w in steps of SIZE; sum channels of covered pixels, divide by count, write back. Pixels are RGBA, 4 bytes each at in->px + i*4 — see any existing filter for the addressing.
- Register in
FILTERS[]:
{"pixelate", "pixelate=SIZE average SIZE×SIZE blocks", f_pixelate},
- Document it: add
pixelate to the README Filters list (README.md) under its family. Per CONTRIBUTING.md ("Adding or changing a filter", step 5), a new filter must be listed there.
Done when
- builds clean,
imgcli -filters lists it
pixelate appears in the README filter list
imgcli -y -i testsrc=256x256 -vf "pixelate=16" out.png is blocky
- edges handled: dims not divisible by SIZE must not read out of bounds
Difficulty: easy–medium (the only trick is clipping blocks at the right/bottom edges).
Add a
pixelate(mosaic) filter — average each N×N block of pixels into one colour. Classic, visually satisfying, great first PR.Spec
pixelatepixelate=SIZE(block size in px; default 8, minimum 1)Where — mostly in
src/filters.cf_pixelate. Block size viaargd(a, n, 0, 8.0)(clamp to ≥ 1). Loop blocks overin->h/in->win steps of SIZE; sum channels of covered pixels, divide by count, write back. Pixels are RGBA, 4 bytes each atin->px + i*4— see any existing filter for the addressing.FILTERS[]:{"pixelate", "pixelate=SIZE average SIZE×SIZE blocks", f_pixelate},pixelateto the README Filters list (README.md) under its family. Per CONTRIBUTING.md ("Adding or changing a filter", step 5), a new filter must be listed there.Done when
imgcli -filterslists itpixelateappears in the README filter listimgcli -y -i testsrc=256x256 -vf "pixelate=16" out.pngis blockyDifficulty: easy–medium (the only trick is clipping blocks at the right/bottom edges).