Re: Reverse order of bit in repeating seqence of byte string



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.

.



Relevant Pages

  • Re: Reverse order of bit in repeating seqence of byte string
    ... 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 ... I realized the the C.types string buffer is/was mutable so ...
    (comp.lang.python)
  • Re: RIP difficulties
    ... It's a setting about converting color spaces. ... Do you keep your images in RGB or were there RGB images in some embedded ... I'd be very careful of turning on color management for cmyk images since ...
    (comp.publish.prepress)
  • RE: changing color brightness
    ... As for the converting HSV/HSB format color to RGB format problem, ...
    (microsoft.public.dotnet.languages.csharp)
  • RGB to VGA conversion?
    ... current status of converting from RGB to a PC monitor is today? ... The specifics is that I would like to convert a Gorf RGB signal to an LCD PC ...
    (rec.games.video.arcade.collecting)
  • Re: Colour gradient
    ... This is based on converting V to a value between 0 and 360 and ... And did you also apply a linear RGB --> device RGB transformation, ... Hue in HSV. ... It seems to be a tricky business getting a good gradient and it will ...
    (comp.graphics.algorithms)