Utility Functions¶
reset_all¶
Resets all the class level lists and dictionaries of cdl_convert. Calling this is the same as calling each individual reset_members method.
- cdl_convert.reset_all() None[source]¶
Reset all class level member lists and dictionaries.
This function clears all registered ColorCorrection, ColorCollection, ColorDecision, and related class instances. Useful for testing or when you need to start with a clean state.
Example
>>> from cdl_convert import ColorCorrection, reset_all >>> cc1 = ColorCorrection("test1") >>> cc2 = ColorCorrection("test2") >>> print(len(ColorCorrection.members)) # 2 >>> reset_all() >>> print(len(ColorCorrection.members)) # 0
sanity_check¶
Check ColorCorrection values for potentially invalid numbers.
- cdl_convert.utils.sanity_check(colcor: ColorCorrection) bool[source]¶
Check ColorCorrection values against reasonable ranges.
Validates CDL parameter values against typical ranges used in color correction workflows. Prints warnings to stdout for values that fall outside normal ranges, but does not prevent their use since extreme values may be intentional for creative looks.
Validation ranges: - Slope, Power, Saturation: 0.1 to 3.0 - Offset: -1.0 to 1.0
- Parameters:
colcor (ColorCorrection) – ColorCorrection instance to validate.
- Returns:
- True if all values are within normal ranges, False if any
values triggered warnings.
- Return type:
Example
>>> cc = ColorCorrection("test") >>> cc.slope = [2.5, 1.0, 0.8] # High red slope >>> is_sane = sanity_check(cc) # Prints warning for 2.5 slope >>> print(is_sane) # False
to_decimal¶
This is the function we use to convert ints, floats and strings to Decimal objects. This lets us avoid writing scientific notation to files and maintain values in to values out.
- cdl_convert.utils.to_decimal(value: Decimal | str | float | int, name: str = 'Value') Decimal[source]¶
Convert numeric value to Decimal with validation and error handling.
Converts various numeric types to Decimal format with appropriate formatting for CDL values. Handles type conversion, string parsing, and ensures proper decimal representation for color correction values.
Conversion behavior: - float: Converted to string then Decimal to avoid precision issues - int: Appended with ‘.0’ for proper decimal format - str: Validated and parsed, ‘.0’ added if no decimal point - Decimal: Returned as-is
- Parameters:
- Returns:
Converted value as Decimal instance.
- Return type:
Decimal
- Raises:
ValidationError – If value cannot be converted to a valid number or is an unsupported type.
Example
>>> slope_val = to_decimal(1.2, "slope") >>> print(slope_val) # Decimal('1.2') >>> offset_val = to_decimal("0.5", "offset") >>> print(offset_val) # Decimal('0.5')