libvips / libvips

A fast image processing library with low memory needs.

Home Page:https://libvips.github.io/libvips/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Writing to multiple output pixels using vips_image_generate

DDoS opened this issue · comments

For an operation I'm trying to implement I need to write multiple pixels for each input pixel (error diffusion). I saw mentioned in the doc that you can change the size of the input region, but can that also be done for the output region? Is there a way to make sure that the out_region is always NxM pixels bigger than the input region?

Really I just want to implement "Floyd–Steinberg" dithering, and I'm not sure who to correctly write to neighbouring pixels.

Hi @DDoS,

I think enlarging the output would mean that a pixel could be written more than once at overlaps, which wouldn't work.

You need a dither algorithm with limited context, ie. each output pixel can be computed from a bounded set of input pixels, ie. you have some term that stops errors being diffused too far. Now you can just enlarge the input by the appropriate amount and compute the output area.

libvips has a built-in dither, I guess you saw? If you save a GIF or an 8-bit PNG it'll be dithered for you:

vips copy nina.jpg x.png[palette,bitdepth=4]

To make a 16-colour dithered PNG:

x