---
name: "cucul_attributes"
section: "3caca"
platform: "linux"
package: "libcucul-dev"
version: "0.99.beta14-1"
release: "Debian 5.0 (Lenny)"
platforms: ["linux"]
url: "https://new.carta.tech/cucul_attributes"
---

# cucul\_attributes(3caca)

## NAME

libcucul attribute conversions -

### Functions

\_\_extern uint8\_t **cucul\_attr\_to\_ansi** (uint32\_t)\
 *Get DOS ANSI information from attribute.*  \_\_extern uint8\_t **cucul\_attr\_to\_ansi\_fg** (uint32\_t)\
 *Get ANSI foreground information from attribute.*  \_\_extern uint8\_t **cucul\_attr\_to\_ansi\_bg** (uint32\_t)\
 *Get ANSI background information from attribute.*  \_\_extern uint16\_t **cucul\_attr\_to\_rgb12\_fg** (uint32\_t)\
 *Get 12-bit RGB foreground information from attribute.*  \_\_extern uint16\_t **cucul\_attr\_to\_rgb12\_bg** (uint32\_t)\
 *Get 12-bit RGB background information from attribute.*  \_\_extern void **cucul\_attr\_to\_argb64** (uint32\_t, uint8\_t\[8\])\
 *Get 64-bit ARGB information from attribute.*

## Detailed Description

These functions perform conversions between attribute values.

## Function Documentation

### \_\_extern uint8\_t cucul\_attr\_to\_ansi (uint32\_t attr)

Get the ANSI colour pair for a given attribute. The returned value is an 8-bit value whose higher 4 bits are the background colour and lower 4 bits are the foreground colour.

If the attribute has ARGB colours, the nearest colour is used. Special attributes such as *CUCUL\_DEFAULT* and *CUCUL\_TRANSPARENT* are not handled and are both replaced with *CUCUL\_LIGHTGRAY* for the foreground colour and *CUCUL\_BLACK* for the background colour.

This function never fails. If the attribute value is outside the expected 32-bit range, higher order bits are simply ignored.

**Parameters:**

*attr* The requested attribute value.

**Returns:**

The corresponding DOS ANSI value.

References CUCUL\_BLACK, and CUCUL\_LIGHTGRAY.

### \_\_extern uint8\_t cucul\_attr\_to\_ansi\_fg (uint32\_t attr)

Get the ANSI foreground colour value for a given attribute. The returned value is either one of the *CUCUL\_RED*, *CUCUL\_BLACK* etc. predefined colours, or the special value *CUCUL\_DEFAULT* meaning the media's default foreground value, or the special value *CUCUL\_TRANSPARENT*.

If the attribute has ARGB colours, the nearest colour is returned.

This function never fails. If the attribute value is outside the expected 32-bit range, higher order bits are simply ignored.

**Parameters:**

*attr* The requested attribute value.

**Returns:**

The corresponding ANSI foreground value.

### \_\_extern uint8\_t cucul\_attr\_to\_ansi\_bg (uint32\_t attr)

Get the ANSI background colour value for a given attribute. The returned value is either one of the *CUCUL\_RED*, *CUCUL\_BLACK* etc. predefined colours, or the special value *CUCUL\_DEFAULT* meaning the media's default background value, or the special value *CUCUL\_TRANSPARENT*.

If the attribute has ARGB colours, the nearest colour is returned.

This function never fails. If the attribute value is outside the expected 32-bit range, higher order bits are simply ignored.

**Parameters:**

*attr* The requested attribute value.

**Returns:**

The corresponding ANSI background value.

### \_\_extern uint16\_t cucul\_attr\_to\_rgb12\_fg (uint32\_t attr)

Get the 12-bit foreground colour value for a given attribute. The returned value is a native-endian encoded integer with each red, green and blue values encoded on 8 bits in the following order:

- •

  8-11 most significant bits: red

- •

  4-7 most significant bits: green

- •

  least significant bits: blue

This function never fails. If the attribute value is outside the expected 32-bit range, higher order bits are simply ignored.

**Parameters:**

*attr* The requested attribute value.

**Returns:**

The corresponding 12-bit RGB foreground value.

References CUCUL\_DEFAULT, CUCUL\_LIGHTGRAY, and CUCUL\_TRANSPARENT.

### \_\_extern uint16\_t cucul\_attr\_to\_rgb12\_bg (uint32\_t attr)

Get the 12-bit background colour value for a given attribute. The returned value is a native-endian encoded integer with each red, green and blue values encoded on 8 bits in the following order:

- •

  8-11 most significant bits: red

- •

  4-7 most significant bits: green

- •

  least significant bits: blue

This function never fails. If the attribute value is outside the expected 32-bit range, higher order bits are simply ignored.

**Parameters:**

*attr* The requested attribute value.

**Returns:**

The corresponding 12-bit RGB background value.

References CUCUL\_BLACK, CUCUL\_DEFAULT, and CUCUL\_TRANSPARENT.

### \_\_extern void cucul\_attr\_to\_argb64 (uint32\_t attr, uint8\_t argb\[8\])

Get the 64-bit colour and alpha values for a given attribute. The values are written as 8-bit integers in the *argb* array in the following order:

- •

  *argb*\[0\]: background alpha value

- •

  *argb*\[1\]: background red value

- •

  *argb*\[2\]: background green value

- •

  *argb*\[3\]: background blue value

- •

  *argb*\[4\]: foreground alpha value

- •

  *argb*\[5\]: foreground red value

- •

  *argb*\[6\]: foreground green value

- •

  *argb*\[7\]: foreground blue value

This function never fails. If the attribute value is outside the expected 32-bit range, higher order bits are simply ignored.

**Parameters:**

*attr* The requested attribute value. \
 *argb* An array of 8-bit integers.

References CUCUL\_BLACK, CUCUL\_DEFAULT, CUCUL\_LIGHTGRAY, and CUCUL\_TRANSPARENT.

Referenced by cucul\_render\_canvas().
