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

Re: [pygame] BGRA to RGB/RGBA, fastest way to do so



Silver wrote
> 
> or you could import/export it from pygame:
> 
> ARGB = BGRA[::-1]
> ARGB_image = pygame.image.fromstring(ARGB, size, "ARGB")
> RGBA_str = pygame.image.tostring(ARGB_image, "RGBA")
> 

I saw this trick for BGR, but didn't see how I could get it to work with
BGRA, but here it is.  Thanks!
The results are flipped, but that's easy to take care of.  
Even with the flip code added in, the speed results are wonderful.  ~0.2
sec.

---------------------------------------

def toRGBA(BGRA_str, w, h):
	ARGB = BGRA_str[::-1] 
	size = (w, h)
	ARGB_image = pygame.image.fromstring(ARGB, size, "ARGB") 
	RGBA_str = pygame.image.tostring(ARGB_image, "RGBA") 
	return RGBA_str	

# bmpstr: is the ColorStringBuffer,  w,h: is the width and height of the
image in the buffer
bmpstr = toRGBA(bmpstr, w, h)
surface = pygame.image.frombuffer(bmpstr, (w,h), "RGBA")
surface = pygame.transform.flip(surface, True, True) 





--
View this message in context: http://pygame-users.25799.n6.nabble.com/BGRA-to-RGB-RGBA-fastest-way-to-do-so-tp163p166.html
Sent from the pygame-users mailing list archive at Nabble.com.