[Gllug] Faster maths?
Adrian McMenamin
adrian at newgolddream.dyndns.info
Thu Mar 8 23:11:26 UTC 2007
I have some perl which indexes and dithers a PNG image to a 256 colour
palette.
The indexing is pretty fast - a 59K (compressed) PNG image on a 4000
BogoMIPS machine in about a second.
But I turn on dithering it takes half an hour!!
The bottleneck appears to be calculating the distance of a point in
colourspace (ie the original colour + diffused error) from any point in
the palette (to find the closest match).
I don't use sqrt - just compare square with square (and save a match so
don't have to do the same lookup twice).
But generally this requires several tens of millions of comparisons for
a reasonably large image.
There must be a better way as I know C libraries obviously don't take
this long (do they?) and the difference in speed is so great it cannot
simply be perl versus C that is the issue.
I know this is a bit of a specialist subject - but anybody know of
faster ways to calculate distances in a three dimensional space and/or
work out how to compare with a smaller range of numbers than the whole
24 bit palette?
-------------- next part --------------
--
Gllug mailing list - Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug
More information about the GLLUG
mailing list