Classes | Defines

gfxColor.h File Reference

#include "gfxTypes.h"
#include "prbit.h"
#include "prio.h"
Include dependency graph for gfxColor.h:
This graph shows which files directly or indirectly include this file:

Classes

struct  gfxRGBA
 A color value, storing red, green, blue and alpha components. More...

Defines

#define GFX_UINT32_FROM_BPTR(pbptr, i)   (((PRUint32*)(pbptr))[i])
#define GFX_NTOHL(x)   ntohl(x)
#define GFX_HAVE_CHEAP_NTOHL
#define GFX_0XFF_PPIXEL_FROM_UINT32(x)   ( (GFX_NTOHL(x) >> 8) | (0xFF << 24) )
 GFX_0XFF_PPIXEL_FROM_BPTR(x).
#define GFX_0XFF_PPIXEL_FROM_BPTR(x)   ( GFX_0XFF_PPIXEL_FROM_UINT32(GFX_UINT32_FROM_BPTR((x),0)) )
#define GFX_BLOCK_RGB_TO_FRGB(from, to)
 GFX_BLOCK_RGB_TO_FRGB(from,to) sizeof(*from) == sizeof(char) sizeof(*to) == sizeof(PRUint32).
#define GFX_DIVIDE_BY_255(v)   (((((unsigned)(v)) << 8) + ((unsigned)(v)) + 255) >> 16)
 Fast approximate division by 255.
#define GFX_PREMULTIPLY(c, a)   GFX_DIVIDE_BY_255((c)*(a))
 Fast premultiply macro.
#define GFX_PACKED_PIXEL(a, r, g, b)
 Macro to pack the 4 8-bit channels (A,R,G,B) into a 32-bit packed premultiplied pixel.

Define Documentation

#define GFX_0XFF_PPIXEL_FROM_BPTR (   x  )     ( GFX_0XFF_PPIXEL_FROM_UINT32(GFX_UINT32_FROM_BPTR((x),0)) )
#define GFX_0XFF_PPIXEL_FROM_UINT32 (   x  )     ( (GFX_NTOHL(x) >> 8) | (0xFF << 24) )

GFX_0XFF_PPIXEL_FROM_BPTR(x).

Avoid tortured construction of 32-bit ARGB pixel from 3 individual bytes of memory plus constant 0xFF. RGB bytes are already contiguous! Equivalent to: GFX_PACKED_PIXEL(0xff,r,g,b)

Attempt to use fast byte-swapping instruction(s), e.g. bswap on x86, in preference to a sequence of shift/or operations.

#define GFX_BLOCK_RGB_TO_FRGB (   from,
  to 
)
Value:
PR_BEGIN_MACRO \
    PRUint32 m0 = GFX_UINT32_FROM_BPTR(from,0), \
             m1 = GFX_UINT32_FROM_BPTR(from,1), \
             m2 = GFX_UINT32_FROM_BPTR(from,2), \
             rgbr = GFX_NTOHL(m0), \
             gbrg = GFX_NTOHL(m1), \
             brgb = GFX_NTOHL(m2), \
             p0, p1, p2, p3; \
    p0 = 0xFF000000 | ((rgbr) >>  8); \
    p1 = 0xFF000000 | ((rgbr) << 16) | ((gbrg) >> 16); \
    p2 = 0xFF000000 | ((gbrg) <<  8) | ((brgb) >> 24); \
    p3 = 0xFF000000 | (brgb); \
    to[0] = p0; to[1] = p1; to[2] = p2; to[3] = p3; \
  PR_END_MACRO

GFX_BLOCK_RGB_TO_FRGB(from,to) sizeof(*from) == sizeof(char) sizeof(*to) == sizeof(PRUint32).

Copy 4 pixels at a time, reading blocks of 12 bytes (RGB x4) and writing blocks of 16 bytes (FRGB x4)

#define GFX_DIVIDE_BY_255 (   v  )     (((((unsigned)(v)) << 8) + ((unsigned)(v)) + 255) >> 16)

Fast approximate division by 255.

It has the property that for all 0 <= n <= 255*255, GFX_DIVIDE_BY_255(n) == n/255. But it only uses two adds and two shifts instead of an integer division (which is expensive on many processors).

equivalent to ((v)/255)

#define GFX_HAVE_CHEAP_NTOHL
#define GFX_NTOHL (   x  )     ntohl(x)
#define GFX_PACKED_PIXEL (   a,
  r,
  g,
  b 
)
Value:
((a) == 0x00) ? 0x00000000 :                                        \
    ((a) == 0xFF) ? ((0xFF << 24) | ((r) << 16) | ((g) << 8) | (b))     \
                  : ((a) << 24) |                                       \
                    (GFX_PREMULTIPLY(r,a) << 16) |                      \
                    (GFX_PREMULTIPLY(g,a) << 8) |                       \
                    (GFX_PREMULTIPLY(b,a))

Macro to pack the 4 8-bit channels (A,R,G,B) into a 32-bit packed premultiplied pixel.

The checks for 0 alpha or max alpha ensure that the compiler selects the quicked calculation when alpha is constant.

#define GFX_PREMULTIPLY (   c,
  a 
)    GFX_DIVIDE_BY_255((c)*(a))

Fast premultiply macro.

equivalent to (((c)*(a))/255)

#define GFX_UINT32_FROM_BPTR (   pbptr,
  i 
)    (((PRUint32*)(pbptr))[i])