Skip to content

Commit

Permalink
Update README and output formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelMauderer committed Mar 6, 2025
1 parent 67d13bb commit 13d5bbc
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 14 deletions.
51 changes: 39 additions & 12 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,44 @@ The main entry point of the library is the ``read_clf`` function in the main nam
import colour_clf_io
example = """
<?xml version="1.0" ?>
<ProcessList xmlns="urn:AMPAS:CLF:v3.0" id="Example Wrapper" compCLFversion="2.0">
<LUT3D id="lut-24" name="green look" interpolation="trilinear" inBitDepth="12i" outBitDepth="16f">
example = """<?xml version="1.0" ?>
<ProcessList xmlns="urn:AMPAS:CLF:v3.0" id="Example Wrapper" compCLFversion="2.0">
<LUT3D id="lut-24" name="green look" interpolation="trilinear" inBitDepth="12i" outBitDepth="16f">
<Description>3D LUT</Description>
<Array dim="2 2 2 3">
0.0 0.0 0.0
0.0 0.0 1.0
0.0 1.0 0.0
0.0 1.0 1.0
1.0 0.0 0.0
1.0 0.0 1.0
1.0 1.0 0.0
1.0 1.0 1.0
</Array>
</LUT3D>
</ProcessList>
""" # noqa: E501
clf_doc = colour_clf_io.parse_clf(example)
print(clf_doc)
.. code-block:: text
ProcessList(id='Example Wrapper', compatible_CLF_version='3.0', process_nodes=[LUT3D(id='lut-24', name='green look', in_bit_depth=<BitDepth.i12: '12i'>, out_bit_depth=<BitDepth.f16: '16f'>, description='3D LUT', array=Array(values=[0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0], dim=(2, 2, 2, 3)), half_domain=False, raw_halfs=False, interpolation=<Interpolation3D.TRILINEAR: 'trilinear'>)], name=None, inverse_of=None, description=[], input_descriptor='', output_descriptor='', info=Info(app_release=None, copyright=None, revision=None, aces_transform_id=None, aces_user_name=None, calibration_info=None))
and for writing a CLF file the ``write_clf`` function can be used to serialise a ``ProcessList`` back to XML


.. code-block:: python
xml = colour_clf_io.write_clf(clf_doc)
print(xml)
.. code-block:: text
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<ProcessList xmlns="urn:AMPAS:CLF:v3.0" compCLFversion="3.0" id="Example Wrapper">
<Info/>
<LUT3D id="lut-24" inBitDepth="12i" interpolation="trilinear" name="green look" outBitDepth="16f">
<Description>3D LUT</Description>
<Array dim="2 2 2 3">
0.0 0.0 0.0
Expand All @@ -73,15 +107,8 @@ The main entry point of the library is the ``read_clf`` function in the main nam
1.0 1.0 0.0
1.0 1.0 1.0
</Array>
</LUT3D>
</LUT3D>
</ProcessList>
""" # noqa: E501
clf_doc = colour_clf_io.read_clf(EXAMPLE_WRAPPER.format(example))
print(clf_doc)
.. code-block:: text
ProcessList(id='Example Wrapper', compatible_CLF_version='3.0', process_nodes=[LUT3D(id='lut-24', name='green look', in_bit_depth=<BitDepth.i12: '12i'>, out_bit_depth=<BitDepth.f16: '16f'>, description='3D LUT', array=Array(values=[0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0], dim=(2, 2, 2, 3)), half_domain=False, raw_halfs=False, interpolation=<Interpolation3D.TRILINEAR: 'trilinear'>)], name=None, inverse_of=None, description=[], input_descriptor='', output_descriptor='', info=Info(app_release=None, copyright=None, revision=None, aces_transform_id=None, aces_user_name=None, calibration_info=None))
User Guide
----------
Expand Down
8 changes: 6 additions & 2 deletions colour_clf_io/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,18 @@ def to_xml(self) -> lxml.etree._Element:
"""
xml = lxml.etree.Element("Array")
xml.set("dim", " ".join(map(str, self.dim)))

def wrap_with_newlines(s: str) -> str:
return f"\n{s}\n"

if len(self.dim) <= 1:
xml.text = "\n".join(map(str, self.values))
text = "\n".join(map(str, self.values))
else:
row_length = self.dim[-1]
text = "\n".join(
" ".join(map(str, row)) for row in batched(self.values, row_length)
)
xml.text = text
xml.text = wrap_with_newlines(text)
return xml

def as_array(self) -> npt.NDArray:
Expand Down
5 changes: 5 additions & 0 deletions colour_clf_io/process_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from colour_clf_io.elements import Info
from colour_clf_io.errors import ParsingError
from colour_clf_io.parsing import (
NAMESPACE_NAME,
ParserConfig,
check_none,
element_as_text,
Expand Down Expand Up @@ -212,12 +213,16 @@ def to_xml(self) -> lxml.etree._Element:
:class:`lxml.etree._Element`
"""
xml = lxml.etree.Element("ProcessList")

xml.set("xmlns", NAMESPACE_NAME)

set_attr_if_not_none(xml, "id", self.id)
set_attr_if_not_none(xml, "compCLFversion", self.compatible_CLF_version)
set_attr_if_not_none(xml, "name", self.name)
set_attr_if_not_none(xml, "inverseOf", self.inverse_of)
set_element_if_not_none(xml, "InputDescriptor", self.input_descriptor)
set_element_if_not_none(xml, "OutputDescriptor", self.output_descriptor)

if self.info:
xml.append(self.info.to_xml())
for description_text in self.description:
Expand Down

0 comments on commit 13d5bbc

Please sign in to comment.