[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] Effecient way to 'darken' a surface?



Hi list,

I figure all you smart people'll be able to help me out here.

What I need is to be able to effeciently 'darken' a (section) of a surface. By darken I mean the R, G and B values of every pixel should be reduced with the same value, but never go below 0.

The code I have (see below) so far is pretty slow for 'fullscreen' surfaces (800, 600) so I was wondering if there's a better way... I mean, I'm sure there's a better way to ensure that you don't get underflow on the RGB values, my numeric mojo just isn't good enough to spot it. I thought about using & but that would cap values and not reduce, which means that relatively dimmer pixels would be brighter after the 'grey out' if they happen to have values below the threshold.

arr = surfarray.array3d(surf)
arr = maximum(zeros(arr.shape), arr - 200))
surfarray.blit_array(surf, arr)

I dunno, perhaps there just isn't a significantly faster way of doing this? Please prove me wrong!

Thanks in advance,

/Troels Therkelsen