<s>
Floyd	B-Algorithm
–	I-Algorithm
Steinberg	I-Algorithm
dithering	I-Algorithm
is	O
an	O
image	O
dithering	O
algorithm	O
first	O
published	O
in	O
1976	O
by	O
Robert	O
W	O
.	O
Floyd	O
and	O
Louis	O
Steinberg	O
.	O
</s>
<s>
The	O
algorithm	O
achieves	O
dithering	O
using	O
error	B-Algorithm
diffusion	I-Algorithm
,	O
meaning	O
it	O
pushes	O
(	O
adds	O
)	O
the	O
residual	O
quantization	O
error	O
of	O
a	O
pixel	B-Algorithm
onto	O
its	O
neighboring	O
pixels	B-Algorithm
,	O
to	O
be	O
dealt	O
with	O
later	O
.	O
</s>
<s>
It	O
spreads	O
the	O
debt	O
out	O
according	O
to	O
the	O
distribution	O
(	O
shown	O
as	O
a	O
map	O
of	O
the	O
neighboring	O
pixels	B-Algorithm
)	O
:	O
</s>
<s>
The	O
pixel	B-Algorithm
indicated	O
with	O
a	O
star	O
( *	O
)	O
indicates	O
the	O
pixel	B-Algorithm
currently	O
being	O
scanned	O
,	O
and	O
the	O
blank	O
pixels	B-Algorithm
are	O
the	O
previously-scanned	O
pixels	B-Algorithm
.	O
</s>
<s>
The	O
algorithm	O
scans	O
the	O
image	O
from	O
left	O
to	O
right	O
,	O
top	O
to	O
bottom	O
,	O
quantizing	O
pixel	B-Algorithm
values	O
one	O
by	O
one	O
.	O
</s>
<s>
Each	O
time	O
the	O
quantization	O
error	O
is	O
transferred	O
to	O
the	O
neighboring	O
pixels	B-Algorithm
,	O
while	O
not	O
affecting	O
the	O
pixels	B-Algorithm
that	O
already	O
have	O
been	O
quantized	O
.	O
</s>
<s>
Hence	O
,	O
if	O
a	O
number	O
of	O
pixels	B-Algorithm
have	O
been	O
rounded	O
downwards	O
,	O
it	O
becomes	O
more	O
likely	O
that	O
the	O
next	O
pixel	B-Algorithm
is	O
rounded	O
upwards	O
,	O
such	O
that	O
on	O
average	O
,	O
the	O
quantization	O
error	O
is	O
close	O
to	O
zero	O
.	O
</s>
<s>
The	O
diffusion	O
coefficients	O
have	O
the	O
property	O
that	O
if	O
the	O
original	O
pixel	B-Algorithm
values	O
are	O
exactly	O
halfway	O
in	O
between	O
the	O
nearest	O
available	O
colors	O
,	O
the	O
dithered	O
result	O
is	O
a	O
checkerboard	O
pattern	O
.	O
</s>
<s>
In	O
some	O
implementations	O
,	O
the	O
horizontal	O
direction	O
of	O
scan	O
alternates	O
between	O
lines	O
;	O
this	O
is	O
called	O
"	O
serpentine	O
scanning	O
"	O
or	O
boustrophedon	B-Algorithm
transform	I-Algorithm
dithering	O
.	O
</s>
<s>
In	O
the	O
following	O
pseudocode	B-Language
we	O
can	O
see	O
the	O
algorithm	O
described	O
above	O
.	O
</s>
<s>
This	O
works	O
for	O
any	O
approximately	O
linear	O
encoding	O
of	O
pixel	B-Algorithm
values	O
,	O
such	O
as	O
8-bit	O
integers	O
,	O
16-bit	O
integers	O
or	O
real	O
numbers	O
in	O
the	O
range	O
 [ 0 , 1 ] 	O
.	O
</s>
<s>
When	O
converting	O
greyscale	O
pixel	B-Algorithm
values	O
from	O
a	O
high	O
to	O
a	O
low	O
bit	O
depth	O
(	O
e.g.	O
</s>
<s>
The	O
pseudocode	B-Language
can	O
result	O
in	O
pixel	B-Algorithm
values	O
exceeding	O
the	O
valid	O
values	O
(	O
such	O
as	O
greater	O
than	O
255	O
in	O
8-bit	O
greyscale	O
images	O
)	O
.	O
</s>
<s>
In	O
such	O
a	O
case	O
,	O
a	O
nearest	B-Algorithm
neighbor	I-Algorithm
search	I-Algorithm
in	O
3D	O
is	O
required	O
.	O
</s>
