Colors

Macros

#define RGB(r, v, b)   ((r) | ((v)<<8) | ((b)<<16) | (0xff<<24))
 
#define RGBA(r, v, b, a)   ((r) | ((v)<<8) | ((b)<<16) | ((a)<<24))
 
#define RGB12(r, v, b)   ((((b)>>4)<<8) | (((v)>>4)<<4) | ((r)>>4) | (0xf<<12))
 
#define RGBA12(r, v, b, a)   ((((a)>>4)<<12) | (((b)>>4)<<8) | (((v)>>4)<<4) | ((r)>>4))
 
#define RGB15(r, v, b)   ((((b)>>3)<<10) | (((v)>>3)<<5) | ((r)>>3) | (1<<15))
 
#define RGBA15(r, v, b, a)   ((((a)>>7)<<15) | (((b)>>3)<<10) | (((v)>>3)<<5) | ((r)>>3))
 
#define RGB16(r, v, b)   ((((b)>>3)<<11) | (((v)>>2)<<5) | ((r)>>3))
 
#define oslRgbaGet8888(data, r, g, b, a)   ((r)=((data)&0xff), (g)=(((data)>>8)&0xff), (b)=(((data)>>16)&0xff), (a)=(((data)>>24)&0xff))
 
#define oslRgbaGet4444(data, r, g, b, a)   ((r)=((data)&0xf)<<4, (g)=(((data)>>4)&0xf)<<4, (b)=(((data)>>8)&0xf)<<4, (a)=(((data)>>12)&0xf)<<4)
 
#define oslRgbaGet5551(data, r, g, b, a)   ((r)=((data)&0x1f)<<3, (g)=(((data)>>5)&0x1f)<<3, (b)=(((data)>>10)&0x1f)<<3, (a)=(((data)>>15)&0x1)<<7)
 
#define oslRgbGet5650(data, r, g, b)   ((r)=((data)&0x1f)<<3, (g)=(((data)>>5)&0x3f)<<2, (b)=(((data)>>11)&0x1f)<<3)
 
#define oslRgbaGet4444f(data, r, g, b, a)   ((r)=((data)&0xf)<<4 | ((data)&0xf), (g)=(((data)>>4)&0xf)<<4 | (((data)>>4)&0xf), (b)=(((data)>>8)&0xf)<<4 | (((data)>>8)&0xf), (a)=(((data)>>12)&0xf)<<4 | (((data)>>12)&0xf))
 
#define oslRgbaGet5551f(data, r, g, b, a)   ((r)=((data)&0x1f)<<3 | ((data)&0x1f)>>2, (g)=(((data)>>5)&0x1f)<<3 | (((data)>>5)&0x1f)>>2, (b)=(((data)>>10)&0x1f)<<3 | (((data)>>10)&0x1f)>>2, (a)=(((data)>>15)&0x1)*255)
 
#define oslRgbGet5650f(data, r, g, b)   ((r)=((data)&0x1f)<<3 | ((data)&0x1f)>>2, (g)=(((data)>>5)&0x3f)<<2 | (((data)>>5)&0x3f)>>4, (b)=(((data)>>11)&0x1f)<<3 | (((data)>>10)&0x1f)>>2)
 

Typedefs

typedef unsigned long OSL_COLOR
 

Detailed Description

Color manipulation.

Macro Definition Documentation

#define RGB (   r,
  v,
 
)    ((r) | ((v)<<8) | ((b)<<16) | (0xff<<24))

Creates a 32-bit opaque color.

#define RGBA (   r,
  v,
  b,
 
)    ((r) | ((v)<<8) | ((b)<<16) | ((a)<<24))

Creates a 32-bit color. 32-bit colors is what all OSLib calls asking for a color want. Use RGB if you don't want to bother about alpha (semi transparency).

#define RGB12 (   r,
  v,
 
)    ((((b)>>4)<<8) | (((v)>>4)<<4) | ((r)>>4) | (0xf<<12))

Creates a 12-bit color with 3 coefficients (red, green, blue). Alpha is set to the maximum (opaque). The r, v, b values can be from 0 to 255, they're divided to match the 12-bit pixel format.

#define RGBA12 (   r,
  v,
  b,
 
)    ((((a)>>4)<<12) | (((b)>>4)<<8) | (((v)>>4)<<4) | ((r)>>4))

Creates a 12-bit color with 4 coefficients (red, green, blue, alpha).

#define RGB15 (   r,
  v,
 
)    ((((b)>>3)<<10) | (((v)>>3)<<5) | ((r)>>3) | (1<<15))

Creates a 15-bit opaque color.

#define RGBA15 (   r,
  v,
  b,
 
)    ((((a)>>7)<<15) | (((b)>>3)<<10) | (((v)>>3)<<5) | ((r)>>3))

Creates a 15-bit color with alpha.

#define RGB16 (   r,
  v,
 
)    ((((b)>>3)<<11) | (((v)>>2)<<5) | ((r)>>3))

Creates a 16-bit color.

#define oslRgbaGet8888 (   data,
  r,
  g,
  b,
 
)    ((r)=((data)&0xff), (g)=(((data)>>8)&0xff), (b)=(((data)>>16)&0xff), (a)=(((data)>>24)&0xff))

Gets R, G, B, A (Red, Green, Blue, Alpha) component values from a 32-bit color. Stores the 8-bit values to the variables indicated by the 2nd to 5th argument. Example:

u32 color = RGBA(1, 2, 3, 4);
u8 red, green, blue, alpha;
oslRgbaGet8888(color, red, green, blue, alpha);
oslPrintf("%i %i %i %i", red, green, blue, alpha);

This will print 1 2 3 4.

#define oslRgbaGet4444 (   data,
  r,
  g,
  b,
 
)    ((r)=((data)&0xf)<<4, (g)=(((data)>>4)&0xf)<<4, (b)=(((data)>>8)&0xf)<<4, (a)=(((data)>>12)&0xf)<<4)

Gets R, G, B, A values from a 4444 color. The values are always 8 bit, so they are expanded with a multiplication! Example:

u32 color = RGBA12(255, 128, 0, 1);
u8 red, green, blue, alpha;
oslRgbGet4444(color, red, green, blue, alpha);
oslPrintf("%i %i %i %i", red, green, blue, alpha);

This will print 240 128 0 0. The alpha was 1 but was lost because of precision in 12-bit mode (it can only store coefficients from 0 to 15 instead of 0 to 255). The red color was 255 but it has lost precision due to 12-bit conversion. It has passed from 255 to 15 (integer division by 16), and then was multiplicated by 16, making it 240 instead of 255. This can be problematic because you will no more get bright and vibrant color after conversion. However you can use the 'f' alternate routines which give more precise results (but they are slightly slower), in this case the result of oslRgbaGet4444f would be 255 136 0 0, which is brighter and nicer.

#define oslRgbaGet5551 (   data,
  r,
  g,
  b,
 
)    ((r)=((data)&0x1f)<<3, (g)=(((data)>>5)&0x1f)<<3, (b)=(((data)>>10)&0x1f)<<3, (a)=(((data)>>15)&0x1)<<7)

Get components from a 5551 (15-bit) color. Same remarks as oslRgbGet4444 apply.

#define oslRgbGet5650 (   data,
  r,
  g,
 
)    ((r)=((data)&0x1f)<<3, (g)=(((data)>>5)&0x3f)<<2, (b)=(((data)>>11)&0x1f)<<3)

Get components from a 5650 (16-bit) color. Same remarks as oslRgbGet4444 apply.

#define oslRgbaGet4444f (   data,
  r,
  g,
  b,
 
)    ((r)=((data)&0xf)<<4 | ((data)&0xf), (g)=(((data)>>4)&0xf)<<4 | (((data)>>4)&0xf), (b)=(((data)>>8)&0xf)<<4 | (((data)>>8)&0xf), (a)=(((data)>>12)&0xf)<<4 | (((data)>>12)&0xf))

Look at oslRgbaGet4444 to find out why these are useful.

#define oslRgbaGet5551f (   data,
  r,
  g,
  b,
 
)    ((r)=((data)&0x1f)<<3 | ((data)&0x1f)>>2, (g)=(((data)>>5)&0x1f)<<3 | (((data)>>5)&0x1f)>>2, (b)=(((data)>>10)&0x1f)<<3 | (((data)>>10)&0x1f)>>2, (a)=(((data)>>15)&0x1)*255)

Same remark as oslRgbaGet4444f.

#define oslRgbGet5650f (   data,
  r,
  g,
 
)    ((r)=((data)&0x1f)<<3 | ((data)&0x1f)>>2, (g)=(((data)>>5)&0x3f)<<2 | (((data)>>5)&0x3f)>>4, (b)=(((data)>>11)&0x1f)<<3 | (((data)>>10)&0x1f)>>2)

Same remark as oslRgbaGet4444f.

Typedef Documentation

typedef unsigned long OSL_COLOR