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

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



Title: Re: [pygame] Effecient way to 'darken' a surface?
Yes, but isn’t alpha blending slower?  And instead of lowering the luminance value of each r,g,b pixel you need to increase the alpha values, so I wouldn’t think this would give rise to a substantial speed increase if you’re using numeric.




On 12/20/05 5:00 PM, "Knapp" <magick.crow@xxxxxxxxx> wrote:

I have no clue if this is true so it is an answer to your question but also a question for those who really know.

Could you just combine your surface using alpha channel with a surface that is black?

On 12/20/05, Troels Therkelsen < tt@xxxxxxxxxxxxxx <mailto:tt@xxxxxxxxxxxxxx> > wrote:
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