Krita-Plugins 1.6.4

Moritz Moeller mnm at dneg.com
Tue Jan 8 11:37:29 CET 2008


Cyrille,

> It currently only support dithering to 8bit. The only export filter that is 
> capable of creating a palette from an image is PNG, and PNG is limited to 
> 8bits palette. But there is nothing in the algorithm that prevent to use 
> bigger palette when have export filters which can work with higher depth 
> palette.

yep, but try displaying a PNG dithererd to 256 colors chosen from 16.8 
millions on a device (e.g. a mobile phone) that can only display 262144 
colors -- if it has smooth ramps you will likely get horrible banding 
and ugly colors as the device clamps a color to the next available one.

A good feature for starters is hence to allow dithering to 256 out of 
32768/65536/262144 evenly distributed colors (as opposed to 16.8 million 
evenly distributed ones).

The second feature is not dithering to a palette but dithering to a 
lesser number of colors. I.e. dithering from 24 bits to e.g. 15 bits, 5 
red, 5 green 5 blue.

The easiest way of doing this clamping (this is what most hardware does) 
and it looks rather unpleasant.
Next is error diffusion with random(), then comes 'clever' error 
diffusion with an algorithm like Floyd-Steinberg. Alternatively there is 
pattern diffusion with Bayer which gives the nice "8 bit console/game 
graphics" look.

For dithering to n bits via simple error diffusion:

assuming we have a color channel represented as a floating point number 
in 'value' and 'one' contains 2 ^ bits - 1, i.e. the number of colors - 1:

   intvalue = clamp( round( one * value + 0.5 * randfloat() ), 0, one );

with randfloat() returning a number between 0..1:
   float randfloat() {
     return rand() / ( float( RAND_MAX ) + 1 );
   }


Hope that makes more sense. :)

.mm


More information about the kimageshop mailing list