FUNCTIONS

ditherTo2bppLineLow

ditherTo2bppLineLow()
Input: lined (ptr to beginning of dest line
w (width of image in pixels)
bufs1 (buffer of current source line)
bufs2 (buffer of next source line)
tabval (value to assign for current pixel)
tab38 (excess value to give to neighboring 3/8 pixels)
tab14 (excess value to give to neighboring 1/4 pixel)
lastlineflag (0 if not last dest line, 1 if last dest line)
Return: void
Dispatches error diffusion dithering for
a single line of the image. If lastlineflag == 0,
both source buffers are used; otherwise, only bufs1
is used. We use source buffers because the error
is propagated into them, and we don't want to change
the input src image.
We break dithering out line by line to make it
easier to combine functions like interpolative
scaling and error diffusion dithering, as such a
combination of operations obviates the need to
generate a 2x grayscale image as an intermediary.

ditherTo2bppLow

ditherTo2bppLow()
Low-level function for doing Floyd-Steinberg error diffusion
dithering from 8 bpp (datas) to 2 bpp (datad). Two source
line buffers, bufs1 and bufs2, are provided, along with three
256-entry lookup tables: tabval gives the output pixel value,
tab38 gives the extra (plus or minus) transferred to the pixels
directly to the left and below, and tab14 gives the extra
transferred to the diagonal below. The choice of 3/8 and 1/4
is traditional but arbitrary when you use a lookup table; the
only constraint is that the sum is 1. See other comments
below and in grayquant.c.

ditherToBinaryLUTLow

ditherToBinaryLUTLow()
Low-level function for doing Floyd-Steinberg error diffusion
dithering from 8 bpp (datas) to 1 bpp (datad). Two source
line buffers, bufs1 and bufs2, are provided, along with three
256-entry lookup tables: tabval gives the output pixel value,
tab38 gives the extra (plus or minus) transferred to the pixels
directly to the left and below, and tab14 gives the extra
transferred to the diagonal below. The choice of 3/8 and 1/4
is traditional but arbitrary when you use a lookup table; the
only constraint is that the sum is 1. See other comments below.

ditherToBinaryLineLow

ditherToBinaryLineLow()
Input: lined (ptr to beginning of dest line
w (width of image in pixels)
bufs1 (buffer of current source line)
bufs2 (buffer of next source line)
lowerclip (lower clip distance to black)
upperclip (upper clip distance to white)
lastlineflag (0 if not last dest line, 1 if last dest line)
Return: void
Dispatches FS error diffusion dithering for
a single line of the image. If lastlineflag == 0,
both source buffers are used; otherwise, only bufs1
is used. We use source buffers because the error
is propagated into them, and we don't want to change
the input src image.
We break dithering out line by line to make it
easier to combine functions like interpolative
scaling and error diffusion dithering, as such a
combination of operations obviates the need to
generate a 2x grayscale image as an intermediary.

make8To1DitherTables

make8To1DitherTables()
Input: &tabval (value assigned to output pixel; 0 or 1)
&tab38 (amount propagated to pixels left and below)
&tab14 (amount propagated to pixel to left and down)
lowerclip (values near 0 where the excess is not propagated)
upperclip (values near 255 where the deficit is not propagated)
Return: 0 if OK, 1 on error

make8To2DitherTables

make8To2DitherTables()
Input: &tabval (value assigned to output pixel; 0, 1, 2 or 3)
&tab38 (amount propagated to pixels left and below)
&tab14 (amount propagated to pixel to left and down)
cliptoblack (values near 0 where the excess is not propagated)
cliptowhite (values near 255 where the deficit is not propagated)
Return: 0 if OK, 1 on error

thresholdTo2bppLow

thresholdTo2bppLow()
Low-level function for thresholding from 8 bpp (datas) to
2 bpp (datad), using thresholds implicitly defined through @tab,
a 256-entry lookup table that gives a 2-bit output value
for each possible input.
For each line, unroll the loop so that for each 32 bit src word,
representing four consecutive 8-bit pixels, we compose one byte
of output consisiting of four 2-bit pixels.

thresholdTo4bppLow

thresholdTo4bppLow()
Low-level function for thresholding from 8 bpp (datas) to
4 bpp (datad), using thresholds implicitly defined through @tab,
a 256-entry lookup table that gives a 4-bit output value
for each possible input.
For each line, unroll the loop so that for each 32 bit src word,
representing four consecutive 8-bit pixels, we compose two bytes
of output consisiting of four 4-bit pixels.