LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

BGR to RGB conversion

Hi
I'm using the activeX graph in cwui and need to change the plot color.
As far as I know the color code must be given in BGR format.
 
I do have a conversion function RGBtoBGR() but I'm in need of the oposite BGRtoRGB()
Anyone ?
 
For info the RGBtoBGR() function pasted in below :
 
long RGBtoBGR(long rgb)
{
    long blueval = 0;
    long greenval = 0;
    long redval = 0;
    long bgr = 0;
    long bluemask = 0x0000ff;
    long greenmask = 0x00ff00;
    long redmask = 0xff0000;
    blueval = bluemask & rgb;
    greenval = greenmask & rgb;
    redval = redmask & rgb;
    blueval = blueval << 16;
    redval = redval >> 16;
    bgr = blueval | greenval | redval;                        
    return bgr;
}
0 Kudos
Message 1 of 3
(4,396 Views)
long BGRtoRGB(long bgr)
{
return RGBtoBGR(bgr);
}
 
🙂

 
--
Martin
Certified CVI Developer
Message 2 of 3
(4,391 Views)

Good spot, Martin. As such a routine is likely to be handling tens or hundreds of thousands of pixels at a time, I would tend to use a logically equivalent but more efficient byte swapping approach, for both ( Smiley Wink ) functions:

long RGBtoBGR (long patt) {

    char tmp;
    union {long word; char byte [4];} u;

    u.word = patt;
    tmp = u.byte [0];
    u.byte [0] = u.byte [2];
    u.byte [2] = tmp;
    return u.word;
}

JR

Message Edited by jr_2005 on 07-27-2007 09:16 AM

0 Kudos
Message 3 of 3
(4,355 Views)