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