[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] some surfarray questions...
Not the fastest way to use surfarray, but this is about twice as fast on
my computer than the Python loop (and as a bonus, twice as obscure ;-)
import Numeric as N
class ColorSelector(Dialog_OK):
# a bunch of other methods snipped...
def set_color_square(self):
image = self.color_square.image
h = self.hue
r, g, b = colorsys.hsv_to_rgb(h, 1, 1)
x,y = N.indices((256,256), N.Float)
y /= 256.0
row_mul = 1-y
y *= x
x *= row_mul
rgb = N.zeros((256,256,3), N.Float)
rgb[...,0] = x * r + y
rgb[...,1] = x * g + y
rgb[...,2] = x * b + y
a = pygame.surfarray.pixels3d(image)
a[...] = rgb.astype(N.UnsignedInt8)
self.color_square.udraw()
# etc, etc...
On Mon, 1 Sep 2003, Lee Harr wrote:
> Hi;
>
> My ultimate goal here is to make a color selector box, kind of like you
> might see in the GIMP. I have one that works, but it is pretty slow
> when you change which hue you want to use. (it basically goes through
> a surface and does set_at everywhere)
>
<snip>
>
>
> This works, but on a fairly fast machine it takes about half a second
> to repaint the color square.
>
> I have tried a few different approaches using surfarray, but every
> way I tried actually made it slower. I am sure I am doing something
> wrong there, plus I am concerned that surfarray is a non-standard
> part of pygame and so I would have to make some way to fall back
> to a non-surfarray method anyhow.
>
> So. Two questions:
>
> - is surfarray still considered non-standard? Or does pretty much
> everyone who has pygame have surfarray?
>
> - do you see a faster way to do this? :o)
>
> Thanks for your time.
>
> _________________________________________________________________
> MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*.
> http://join.msn.com/?page=features/virus
>
--
Sami Hangaslammi