Skip to content

Add a pixelate filter #56

Description

@swperb

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.

Where — mostly in src/filters.c

  1. 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.
  2. Register in FILTERS[]:
    {"pixelate",    "pixelate=SIZE                   average SIZE×SIZE blocks",   f_pixelate},
  3. 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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions