Colors Module¶
This module provides functions and constants to manage all kinds of colors in DXF documents.
Converter Functions¶
- ezdxf.colors.rgb2int(rgb: RGB | tuple[int, int, int]) int ¶
Combined integer value from (r, g, b) tuple.
- ezdxf.colors.aci2rgb(index: int) RGB ¶
Convert AutoCAD Color Index (ACI) into (r, g, b) tuple, based on default AutoCAD colors.
- ezdxf.colors.luminance(color: Sequence[float]) float ¶
Returns perceived luminance for an RGB color in the range [0.0, 1.0] from dark to light.
- ezdxf.colors.decode_raw_color(value: int) tuple[int, int | RGB] ¶
Decode raw-color value as tuple(type, Union[aci, (r, g, b)]), the true color value is a (r, g, b) tuple.
- ezdxf.colors.decode_raw_color_int(value: int) tuple[int, int] ¶
Decode raw-color value as tuple(type, int), the true color value is a 24-bit int value.
- ezdxf.colors.encode_raw_color(value: int | RGB) int ¶
Encode true-color value or AutoCAD Color Index (ACI) color value into a :term: raw color value.
- ezdxf.colors.transparency2float(value: int) float ¶
Returns transparency value as float from 0 to 1, 0 for no transparency (opaque) and 1 for 100% transparency.
- Parameters:
value – DXF integer transparency value, 0 for 100% transparency and 255 for opaque
- ezdxf.colors.float2transparency(value: float) int ¶
Returns DXF transparency value as integer in the range from 0 to 255, where 0 is 100% transparent and 255 is opaque.
- Parameters:
value – transparency value as float in the range from 0 to 1, where 0 is opaque and 1 is 100% transparent.
RGB Class¶
- class ezdxf.colors.RGB(r: int, g: int, b: int)¶
Named tuple representing an RGB color value.
- r¶
red channel in range [0, 255]
- Type:
int
- g¶
green channel in range [0, 255]
- Type:
int
- b¶
blue channel in range [0, 255]
- Type:
int
- property luminance: float¶
Returns perceived luminance for an RGB color in range [0.0, 1.0] from dark to light.
- to_hex() str ¶
Returns the color value as hex string “#RRGGBB”.
- classmethod from_hex(color: str) Self ¶
Returns an
RGB
instance from a hex color string, the color string is a hex string “RRGGBB” with an optional leading “#”, an appended alpha channel is ignore.
- to_floats() tuple[float, float, float] ¶
Returns the color value as a tuple of floats in range [0, 1].
RGBA Class¶
- class ezdxf.colors.RGBA(r: int, g: int, b: int, a: int = 255)¶
Named tuple representing an RGBA color value. The default alpha channel is 255 (opaque).
- r¶
red channel in range [0, 255]
- Type:
int
- g¶
green channel in range [0, 255]
- Type:
int
- b¶
blue channel in range [0, 255]
- Type:
int
- a¶
alpha channel in range [0, 255], where 0 is transparent and 255 is opaque
- Type:
int
- property luminance: float¶
Returns perceived luminance for an RGB color in range [0.0, 1.0] from dark to light.
- to_hex() str ¶
Returns the color value as hex string “#RRGGBBAA”.
- classmethod from_hex(color: str) Self ¶
Returns an
RGBA
instance from a hex color string, the color string is a hex string “RRGGBBAA” with an optional leading “#”. The alpha channel is optional. The default alpha channel is 255 (opaque).
- to_floats() tuple[float, float, float, float] ¶
Returns the color value as a tuple of floats in range [0, 1].
ACI Color Values¶
Common AutoCAD Color Index (ACI) values, also accessible as IntEnum ezdxf.enums.ACI
BYBLOCK |
0 |
BYLAYER |
256 |
BYOBJECT |
257 |
RED |
1 |
YELLOW |
2 |
GREEN |
3 |
CYAN |
4 |
BLUE |
5 |
MAGENTA |
6 |
BLACK (on light background) |
7 |
WHITE (on dark background) |
7 |
GRAY |
8 |
LIGHT_GRAY |
9 |
Default Palettes¶
Default color mappings from AutoCAD Color Index (ACI) to true-color values.
model space |
DXF_DEFAULT_COLORS |
paper space |
DXF_DEFAULT_PAPERSPACE_COLORS |
Raw Color Types¶
COLOR_TYPE_BY_LAYER |
0xC0 |
COLOR_TYPE_BY_BLOCK |
0xC1 |
COLOR_TYPE_RGB |
0xC2 |
COLOR_TYPE_ACI |
0xC3 |
COLOR_TYPE_WINDOW_BG |
0xC8 |
Raw Color Vales¶
BY_LAYER_RAW_VALUE |
-1073741824 |
BY_BLOCK_RAW_VALUE |
-1056964608 |
WINDOW_BG_RAW_VALUE |
-939524096 |
Transparency Values¶
OPAQUE |
0x20000FF |
TRANSPARENCY_10 |
0x20000E5 |
TRANSPARENCY_20 |
0x20000CC |
TRANSPARENCY_30 |
0x20000B2 |
TRANSPARENCY_40 |
0x2000099 |
TRANSPARENCY_50 |
0x200007F |
TRANSPARENCY_60 |
0x2000066 |
TRANSPARENCY_70 |
0x200004C |
TRANSPARENCY_80 |
0x2000032 |
TRANSPARENCY_90 |
0x2000019 |
TRANSPARENCY_BYBLOCK |
0x1000000 |