nanogui: Conversion of PIXELVALs <-> COLORVALs


Previous by date: 15 Dec 1999 04:17:16 -0000 Re: Possible cause of portrait mode stray line bug - part2, Greg Haerr
Next by date: 15 Dec 1999 04:17:16 -0000 Re: Web interface, Chris Ross
Previous in thread:
Next in thread: 15 Dec 1999 04:17:16 -0000 Re: Conversion of PIXELVALs <-> COLORVALs, Morten Rolland

Subject: Conversion of PIXELVALs <-> COLORVALs
From: "Greg Haerr" ####@####.####
Date: 15 Dec 1999 04:17:16 -0000
Message-Id: <008701bf46a1$9be1aac0$15320cd0@gregh>

Morten,
    I sat down and wrote the conversion macros pertaining to our discussion
about having client capabilities to convert between Microwindows
COLORVALs and PIXELVALs.  These macros allow a client program
to specify in hardware format values, or portable RGB values, and translate
between them.  Note that these are intended for 8/8/8, 5/6/5, and 3/3/2
truecolor systems only; palettized systems will require function calls
that compare system palette entries before using GrArea().  This will
allow fast image processing using either the updated GrArea() call that
works with 8, 16 or 24 bpp PIXELVALs, or the new GrAreaRGB()
call that takes COLORVALs as image bits.

Have fun.

/*
 * Conversion from RGB to PIXELVAL
 */
/* create 24 bit 8/8/8 format pixel (0x00BBGGRR) from RGB triplet*/
#define RGB2PIXEL24(r,g,b) \
 (((b) << 16) | ((g) << 8) | (r))

/* create 16 bit 5/6/5 format pixel from RGB triplet */
#define RGB2PIXEL565(r,g,b) \
 ((((r) & 0xf8) << 8) | (((g) & 0xfc) << 3) | (((b) & 0xf8) >> 3))

/* create 8 bit 3/3/2 format pixel from RGB triplet*/
#define RGB2PIXEL332(r,g,b) \
 (((r) & 0xe0) | (((g) & 0xe0) >> 3) | (((b) & 0xc0) >> 6))

/*
 * Conversion from COLORVAL to PIXELVAL
 */
/* create 24 bit 8/8/8 format pixel (0x00BBGGRR) from RGB colorval(0x00BBGGRR)*/
#define COLOR2PIXEL24(c) \
 ((c) & 0x00ffffff)

/* create 16 bit 5/6/5 format pixel (0x00BBGGRR) from RGB colorval(0x00BBGGRR)*/
#define COLOR2PIXEL565(c) \
 ((((c) & 0xf8) << 8) | (((c) & 0xfc00) >> 5) | (((c) & 0xf80000) >> 19))

/* create 8 bit 3/3/2 format pixel (0x00BBGGRR) from RGB colorval(0x00BBGGRR)*/
#define COLOR2PIXEL332(c) \
 (((c) & 0xe0) | (((c) & 0xe000) >> 11) | (((c) & 0xc00000) >> 22))

/*
 * Conversion from PIXELVAL to red, green or blue components
 */
/* return 8 bit r, g or b component of 24 bit (0x00BBGGRR) pixelval*/
#define PIXEL24RED(pixelval)  ((pixelval) & 0xff)
#define PIXEL24GREEN(pixelval)  (((pixelval) >> 8) & 0xff)
#define PIXEL24BLUE(pixelval)  (((pixelval) >> 16) & 0xff)

/* return 5/6/5 bit r, g or b component of 16 bit pixelval*/
#define PIXEL565RED(pixelval)  (((pixelval) >> 11) & 0x1f)
#define PIXEL565GREEN(pixelval)  (((pixelval) >> 5) & 0x3f)
#define PIXEL565BLUE(pixelval)  ((pixelva) & 0x1f)

/* return 3/3/2 bit r, g or b component of 8 bit pixelval*/
#define PIXEL332RED(pixelval)  (((pixelval) >> 5) & 0x07)
#define PIXEL332GREEN(pixelval)  (((pixelval) >> 2) & 0x07)
#define PIXEL332BLUE(pixelval)  ((pixelval) & 0x03)

Greg



Previous by date: 15 Dec 1999 04:17:16 -0000 Re: Possible cause of portrait mode stray line bug - part2, Greg Haerr
Next by date: 15 Dec 1999 04:17:16 -0000 Re: Web interface, Chris Ross
Previous in thread:
Next in thread: 15 Dec 1999 04:17:16 -0000 Re: Conversion of PIXELVALs <-> COLORVALs, Morten Rolland


Powered by ezmlm-browse 0.20.