Colors Module¶
This module provides functions and constants to manage all kinds of colors in DXF documents.
Converter Functions¶
-
ezdxf.colors.
rgb2int
(rgb: Tuple[int, int, int]) → int¶ Combined integer value from (r, g, b) tuple.
-
ezdxf.colors.
int2rgb
(value: int) → Tuple[int, int, int]¶ Split RGB integer value into (r, g, b) tuple.
-
ezdxf.colors.
aci2rgb
(index: int) → Tuple[int, int, int]¶ Convert AutoCAD Color Index (ACI) into (r, g, b) tuple, based on default AutoCAD colors.
-
ezdxf.colors.
luminance
(color: Tuple[int, int, int]) → 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, Union[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: Union[int, Tuple[int, int, int]]) → 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.
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 |