Re: MMX speedup for Floyd Steinberg error diffusion
- From: "Maarten Kronenburg" <spamtrap@xxxxxxxxxx>
- Date: Wed, 7 May 2008 19:56:39 +0200
"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.
Then you copy and shift left and add/subtract, because
7 = 8 - 1 = 2^3 - 1 and 5 = 4 + 1 = 2^2 + 1 etc.
Then you shift right because 16 = 2^4.
The shift is the PSLLD/PSRLD and the add/subtract is the PADDD/PSUBD.
The reference for these instructions are in:
http://developer.intel.com/products/processor/manuals/index.htm
see instruction set reference.
The timings can be found in:
http://agner.org/optimize/
Maarten.
.
- Follow-Ups:
- Re: MMX speedup for Floyd Steinberg error diffusion
- From: James Harris
- Re: MMX speedup for Floyd Steinberg error diffusion
- From: Maarten Kronenburg
- Re: MMX speedup for Floyd Steinberg error diffusion
- From: Maarten Kronenburg
- Re: MMX speedup for Floyd Steinberg error diffusion
- References:
- MMX speedup for Floyd Steinberg error diffusion
- From: rep_movsd
- MMX speedup for Floyd Steinberg error diffusion
- Prev by Date: Having trouble posting?
- Next by Date: Re: MMX speedup for Floyd Steinberg error diffusion
- Previous by thread: MMX speedup for Floyd Steinberg error diffusion
- Next by thread: Re: MMX speedup for Floyd Steinberg error diffusion
- Index(es):
Relevant Pages
|