Re: image data



"mike7411@xxxxxxxxx" <mike7411@xxxxxxxxx> writes:

Anyone know the fastest way to convert 24 bpp BGR image data to 24 bpp
RGB image data in C/C++?

Depends on how these types are declared.

If you have
typedef int RGB;
typedef int BGR;
then:
BGR bgr;
RGB rgb;
rgb=(bgr&0xff00)|(bgr>>16)|((bgr<<16)&&0xff0000);

On the other hand, if you have:
typedef struct { unsigned char r,g,b } RGB;
typedef struct { unsigned char b,g,r } RGB;
then:
BGR bgr;
RGB rgb;
bgr.r=rgb.r;
bgr.g=rgb.g;
bgr.b=rgb.b;

But if you have:
typedef unsigned char RGB[3];
typedef unsigned char BGR[3];
then:
BGR bgr;
RGB rgb;
bgr[0]=rgb[2];
bgr[1]=rgb[1];
bgr[2]=rgb[0];

etc...
--
__Pascal Bourguignon__ http://www.informatimago.com/
Until real software engineering is developed, the next best practice
is to develop with a dynamic system that has extreme late binding in
all aspects. The first system to really do this in an important way
is Lisp. -- Alan Kay
.



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 ... then converting back again. ...
    (comp.lang.python)
  • Re: ImageMagick and converting TIF to JPG problems
    ... conversion ability. ... that they often produce BGR data. ... There are a couple of ways to convert from BGR to RGB. ... in the tiff image, and reverse each BGR data set, you will get the ...
    (comp.os.linux.misc)
  • Re: Displaying DICOM RGB files
    ... any directions as to how go about displaying the RGB file. ... DICOM never stores samples in BGR order. ... do, and this may be the cause of your problem, if you are converting DICOM ...
    (comp.protocols.dicom)
  • Re: Passing BackColor Values Between .NET and VB6 applications
    ... > to convert from argb to rgb? ... I don't have VB6 here so I can't check, but from the value you give it ... appears the order in VB6 is actually BGR, not RGB! ... Dim BGR as Integer ...
    (microsoft.public.dotnet.languages.vb)