84b43e9d9cc1f5671a997beadf8d658f0fabb8be
[OpenColorIO-Configs.git] / aces_1.0.0 / python / aces_ocio / util.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 import os
5 import re
6
7 import PyOpenColorIO as OCIO
8
9 #
10 # Utility classes and functions
11 #
12 class ColorSpace:
13     """
14     A container for data needed to define an OCIO 'Color Space'
15     """
16
17     def __init__(self,
18                  name,
19                  description=None,
20                  bitDepth=OCIO.Constants.BIT_DEPTH_F32,
21                  equalityGroup=None,
22                  family=None,
23                  isData=False,
24                  toReferenceTransforms=[],
25                  fromReferenceTransforms=[],
26                  allocationType=OCIO.Constants.ALLOCATION_UNIFORM,
27                  allocationVars=[0.0, 1.0]):
28         """
29         Initialize the standard class variables
30         """
31         self.name = name
32         self.bitDepth = bitDepth
33         self.description = description
34         self.equalityGroup = equalityGroup
35         self.family = family
36         self.isData = isData
37         self.toReferenceTransforms = toReferenceTransforms
38         self.fromReferenceTransforms = fromReferenceTransforms
39         self.allocationType = allocationType
40         self.allocationVars = allocationVars
41
42
43 # Create a 4x4 matrix (list) based on a 3x3 matrix (list) input
44 def mat44FromMat33(mat33):
45     return [mat33[0], mat33[1], mat33[2], 0.0,
46             mat33[3], mat33[4], mat33[5], 0.0,
47             mat33[6], mat33[7], mat33[8], 0.0,
48             0, 0, 0, 1.0]
49
50
51 # TODO: Worth moving to *util.py*.
52 def filter_words(words, filters_in=None, filters_out=None, flags=0):
53     """
54     """
55
56     filtered_words = []
57     for word in words:
58         if filters_in:
59             filter_matched = False
60             for filter in filters_in:
61                 if re.search(filter, word, flags):
62                     filter_matched = True
63                     break
64             if not filter_matched:
65                 continue
66
67         if filters_out:
68             filter_matched = False
69             for filter in filters_out:
70                 if re.search(filter, word, flags):
71                     filter_matched = True
72                     break
73             if filter_matched:
74                 continue
75         filtered_words.append(word)
76     return filtered_words
77
78
79 def files_walker(directory, filters_in=None, filters_out=None, flags=0):
80     """
81     """
82
83     for parent_directory, directories, files in os.walk(directory,
84                                                         topdown=False,
85                                                         followlinks=True):
86         for file in files:
87             path = os.path.join(parent_directory, file)
88             if os.path.isfile(path):
89                 if not filter_words((path,), filters_in, filters_out, flags):
90                     continue
91
92                 yield path
93
94
95
96