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

Re: [pygame] ChangeColor Routine



Hi,
This is what i'm using to change an image's colors with Numeric:

        array  = pygame.surfarray.array3d(image)
        array  = array * color
        array  /= 255
        pygame.surfarray.blit_array(image, array)

where color = (R, G, B);

I'm using this to take a generic greyscale image, and give it its respective player/team's color. The same math should work with adding/subtracting values, check out Numerics stuff for that.

I haven't testing this for speed, as i just use it once and cache the result. surfarray.pixelsNd might be faster, as you would not have to call blit_array after.

Kamilche wrote:
Wow, that is very fast. Thanks for the tip!

I'm now wondering if it would be possible to apply a formula to all pixels in a picture at once, using numeric.

I want to modify the R, G, B, A values of a picture separately - something like 'add 2 to r, subtract 4 from g, leave B and A alone' sort of thing.

Do you know of a way to do that? I wish I knew Numeric better, but it's very confusing.

Thanks in advance for any advice you can lend!