Re: Reverse order of bit in repeating seqence of byte string
- From: imageguy <imageguy1206@xxxxxxxxx>
- Date: Sat, 3 Jan 2009 12:10:15 -0800 (PST)
On Jan 2, 7:33 pm, John Machin <sjmac...@xxxxxxxxxxx> wrote:
For some very strange definition of "works". You say you have 'bgr'
and want to convert it to 'rbg'. The following code converts 'bgr' to
'rgb', which is somewhat more plausible, but not what you said you
wanted.
Well that's embarrassing ... you are correct. I need to convert from
'bgr' to 'rgb'
Thanks to all others for suggestions
FWIW, I realized the the C.types string buffer is/was mutable so
settled on this;
for start in xrange(0, ctypes.sizeof(buffer), 3):
if buffer[start] != buffer[start+2]:
#only need to swap the bits if they are different. ie if
both are white or black, no change is required.
blue, red = buffer[start], buffer[start+2]
buffer[start], buffer[start+2] = red, blue
This was about 30-40% faster that converting to list, processing and
then converting back again.
Will try the array module too
.... but I think I need to find a new graphic package rather that makes
working with the bits easier.
g.
.
- Follow-Ups:
- Re: Reverse order of bit in repeating seqence of byte string
- From: Scott David Daniels
- Re: Reverse order of bit in repeating seqence of byte string
- From: John Machin
- Re: Reverse order of bit in repeating seqence of byte string
- References:
- Reverse order of bit in repeating seqence of byte string
- From: imageguy
- Re: Reverse order of bit in repeating seqence of byte string
- From: John Machin
- Reverse order of bit in repeating seqence of byte string
- Prev by Date: Re: Returning a string
- Next by Date: ResponseNotReady exception
- Previous by thread: Re: Reverse order of bit in repeating seqence of byte string
- Next by thread: Re: Reverse order of bit in repeating seqence of byte string
- Index(es):
Relevant Pages
|