## liboilmacros

liboilmacros —

##

# Synopsis

    #define     oil_min                         (x,y)
    #define     oil_max                         (x,y)
    #define     oil_divide_255                  (x)
    #define     oil_argb                        (a,r,g,b)
    #define     oil_argb_noclamp                (a,r,g,b)
    #define     oil_argb_A                      (color)
    #define     oil_argb_G                      (color)
    #define     oil_argb_B                      (color)
    #define     oil_argb_R                      (color)
    #define     oil_muldiv_255                  (a,b)
    #define     oil_clamp_255                   (x)
    #define     OIL_GET                         (ptr, offset, type)
    #define     OIL_OFFSET                      (ptr, offset)
    #define     OIL_INCREMENT                   (ptr, offset)

## Description

## Details

### oil_min()

    #define oil_min(x,y) ((x)<(y)?(x):(y))

Evaluates to the minimum of `x` and `y`.

`x` : | a value
`y` : | a value

### oil_max()

    #define oil_max(x,y) ((x)>(y)?(x):(y))

Evaluates to the maximum of `x` and `y`.

`x` : | a value
`y` : | a value

### oil_divide_255()

    #define oil_divide_255(x) ((((x)+128) + (((x)+128)>>8))>>8)

Divides `x` by 255 in a way that is compatible with the pixel operations in Liboil. The number 65025 is 255*255.

Evaluates to `x` divided by 255.

`x` : | a value in the range [0,65025]

### oil_argb()

    #define     oil_argb(a,r,g,b)

Creates a Liboil ARGB value from individual components. Clamps each component to [0,255].

Evaluates to the ARGB value

`a` : | alpha component
`r` : | red component
`g` : | green component
`b` : | blue component

### oil_argb_noclamp()

    #define     oil_argb_noclamp(a,r,g,b)

Creates a Liboil ARGB value from individual components. Does not clamp components.

Evaluates to the ARGB value

`a` : | alpha component
`r` : | red component
`g` : | green component
`b` : | blue component

### oil_argb_A()

    #define oil_argb_A(color) (((color)>>24)&0xff)

Extracts the alpha component from `color`.

Evaluates to the alpha component

`color` : | an ARGB value

### oil_argb_G()

    #define oil_argb_G(color) (((color)>>8)&0xff)

Extracts the green component from `color`.

Evaluates to the green component

`color` : | an ARGB value

### oil_argb_B()

    #define oil_argb_B(color) (((color)>>0)&0xff)

Extracts the blue component from `color`.

Evaluates to the blue component

`color` : | an ARGB value

### oil_argb_R()

    #define oil_argb_R(color) (((color)>>16)&0xff)

Extracts the red component from `color`.

Evaluates to the red component

`color` : | an ARGB value

### oil_muldiv_255()

    #define oil_muldiv_255(a,b) oil_divide_255((a)*(b))

Multiplies `a` and `b` and divides the result by 255 in a way that is compatible with the pixel operations in Liboil.

Evaluates to the result.

`a` : | a value in the range [0,255]
`b` : | a value in the range [0,255]

### oil_clamp_255()

    #define oil_clamp_255(x) oil_max(0,oil_min((x),255))

Clamps `x` to the range [0,255].

Evaluates to the clamped value.

`x` : | a value

### OIL_GET()

    #define OIL_GET(ptr, offset, type) (*(type *)((uint8_t *)(ptr) + (offset)) )

Offsets `ptr` by `offset` number of bytes, and dereferences it as type `type`. Note that the offset is in bytes, and not in the size of the pointer type.

`ptr` : |
`offset` : |
`type` : |

### OIL_OFFSET()

    #define OIL_OFFSET(ptr, offset) ((void *)((uint8_t *)(ptr) + (offset)) )

Add `offset` bytes to the pointer `ptr`.

`ptr` : |
`offset` : |

### OIL_INCREMENT()

    #define OIL_INCREMENT(ptr, offset) (ptr = (void *)((uint8_t *)ptr + (offset)) )

Increments the pointer `ptr` by `offset` number of bytes.

`ptr` : |
`offset` : |