Fastest Way To Loop Through Every Pixel

Paul McGuire ptmcg at austin.rr._bogus_.com
Fri Jul 28 04:58:48 EDT 2006


"H J van Rooyen" <mail at microcorp.co.za> wrote in message
news:mailman.8646.1154071426.27775.python-list at python.org...
> "Paul McGuire" <ptmcg at austin.rr._bogus_.com> wrote:
>
> | Even downer-and-dirtier, you could approximate 30 with 32, 59 with 64,
and
> | 11 with 8, and do bit-shifting instead of multiplying:
> |
> | def darkness(img,x,y):
> |     return  (RedVal(img,x,y) << 5) + (GreenVal(img,x,y) << 6) +
> | (BlueVal(img,x,y) << 3)
> |
> |
> | -- Paul
>
> *grin* - a man after my own heart! - how do you multiply by ten? - shift,
save a
> copy, shift twice more and add the copy...
>
> - Hendrik
>
Sadly, my timeit results show this saves only a little time, and
shift-copy-shiftsomemore-and-add is even slower then just doing the original
floating point multiply.  The biggest win is in prelookup of Image.GetXXX
functions.

-- Paul





More information about the Python-list mailing list