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

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



I'm trying to convert a color string buffer, and looking for the fastest way
to do so.
I'm capturing a 2 screen desktop (h=1080, w=3840), but it comes in as BGRA,
and I don't see an obvious way to convert that to RGBA or RGB.

The fastest way I have so far is ~1.78 sec, but I'm sure there must be
something faster.

def toRGBA(BGRA_str):
        buf = bytearray(BGRA_str)
        for x in xrange(0,len(buf),4):
                buf[x], buf[x+2] = buf[x+2], buf[x]
        return buf

Slower methods include: 
- starting with an empty array, and via loop, appending to create RGB. (~3.8
sec)
- turn the buffer to a list of chars, swap and return the joined results.
(~2.14 sec)



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