Re: BGR->RGB

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



Hi Georgios,

On Tue, 2002-11-26 at 18:07, Georgios Kapetanakis wrote:
> However, all I get is a black picture, no data.

Hm, I know I should have tested it before clicking that 'send' button...

This one has been tested:

static void
bgr32_to_rgb32 (unsigned char *src,
                unsigned char *dest,
                unsigned int   size)
{
  while (size > 3) {
    *((guint32*)dest) = ((*((guint32*)src))&0xff000000)>>24 |
                        ((*((guint32*)src))&0x00ff0000)>>8  |
                        ((*((guint32*)src))&0x0000ff00)<<8  |
                        ((*((guint32*)src))&0x000000ff)<<24;
    dest += 4; src += 4; size -= 4;
  }
}

"works for me". :-).

> Finally, if I don't do the swapping, Mark, I get constant 25fps, with
> precision to the millisecond, so the system can cope with the throughput
> quite well. True, uncompressed rgb24 image is around 1.3MB, but it works so
> far. I'm hoping eventually to move to the 16bit colourdepth, which will
> halve that image size.

For 16-bit, you could adapt the thing a bit to handle 2 bytes at the
same time. This is what libs like hermes or libcolorspace do:

static void
bgr16_to_rgb16 (unsigned char *src,
                unsigned char *dest,
                unsigned int   size)
{
  guint16 temp;
  while (size > 3) {
    temp = ((*((guint16*)src))&0xf800)>>11 |
           ((*((guint16*)src))&0x0770)     |
           ((*((guint16*)src))&0x008f)<<11;
    src += 2;
    *((guint32*)dest) = dest<<16           |
           ((*((guint16*)src))&0xf800)>>11 |
           ((*((guint16*)src))&0x0770)     |
           ((*((guint16*)src))&0x008f)<<11;
    src += 2; dest += 4; size -= 4;
  }

  if (size > 1)
    *((guint16*)dest) = ((*((guint16*)src))&0xf800)>>11 |
                        ((*((guint16*)src))&0x0770)     |
                        ((*((guint16*)src))&0x008f)<<11;
}

Or so... Again, this is untested. ;-). Compiler will do some
optimizations with the temporary variable, so be sure to use -O2 or so
with gcc.

HTH,

-- 
Ronald Bultje <rbultje@xxxxxxxxxxxxxxxxxxx>
Linux Video/Multimedia developer





[Index of Archives]     [Linux DVB]     [Video Disk Recorder]     [Asterisk]     [Photo]     [DCCP]     [Netdev]     [Xorg]     [Util Linux NG]     [Xfree86]     [Free Photo Albums]     [Fedora Users]     [Fedora Women]     [ALSA Users]     [ALSA Devel]     [Linux USB]

Powered by Linux