Re: MMX speedup for Floyd Steinberg error diffusion
- From: James Harris <spamtrap@xxxxxxxxxx>
- Date: Wed, 7 May 2008 16:26:13 -0700 (PDT)
On 7 May, 18:56, "Maarten Kronenburg" <spamt...@xxxxxxxxxx> wrote:
"rep_movsd" wrote in message
Hi
I recently implemented an animated GIF encoder to convert any video
into a GIF ( I know it doesnt seem really useful, but thats what the
client wanted ).
I implemented floyd steinberg error diffusion to improve quality of
the quantized output.
The code is in Visual C++ and I use 32 bpp pixels for ease in
processing.
The diffusion process takes up about 1/2 the time required to encode a
frame and it seems to be the right place to optimize.
Heres how the algorithm works - pseudocode
for each pixel in the image
{
palColor = Get color in palette thats nearest to current pixel
get signed difference between actual color and palette color for
R G and B components
add difference (with unsigned saturation) to surrounding pixels
with a weightage :
EAST -> 7/16
SOUTHWEST -> 5/16
SOUTH -> 3/16
SOUTHEAST -> 1/16
}
Now I thought I may be able to do this fast with MMX , subtracting the
3 r, g, b bytes at once ( I use 32 bpp pixels, but alpha channel is
ignored )
I can do a packed subtract to get the differences, but thereafter the
multiplication and shifting(for division by 16) seem to be impossible.
Moreover, how can one do a unsigned saturated addition of signed
difference values to the unsigned pixel values?
Any ideas anyone?
The 4 32-bit words can be stored in a single 128-bit xmm register.
The OP asked for MMX which uses 64-bit regs. Are you sure a post-MMX
solution will work for him?
--
.
- References:
- MMX speedup for Floyd Steinberg error diffusion
- From: rep_movsd
- Re: MMX speedup for Floyd Steinberg error diffusion
- From: Maarten Kronenburg
- MMX speedup for Floyd Steinberg error diffusion
- Prev by Date: Re: MMX speedup for Floyd Steinberg error diffusion
- Next by Date: Re: MMX speedup for Floyd Steinberg error diffusion
- Previous by thread: Re: MMX speedup for Floyd Steinberg error diffusion
- Next by thread: Re: MMX speedup for Floyd Steinberg error diffusion
- Index(es):