2 # -*- coding: utf-8 -*-
5 Defines various package utilities objects.
8 from __future__ import division
13 from collections import OrderedDict
15 import PyOpenColorIO as ocio
17 __author__ = 'ACES Developers'
18 __copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers'
20 __maintainer__ = 'ACES Developers'
21 __email__ = 'aces@oscars.org'
22 __status__ = 'Production'
24 __all__ = ['ColorSpace',
31 'colorspace_prefixed_name',
35 class ColorSpace(object):
37 A container for data needed to define an *OCIO* *ColorSpace*.
44 bit_depth=ocio.Constants.BIT_DEPTH_F32,
48 to_reference_transforms=[],
49 from_reference_transforms=[],
50 allocation_type=ocio.Constants.ALLOCATION_UNIFORM,
51 allocation_vars=[0, 1],
52 aces_transform_id=None):
59 Parameter description.
64 Return value description.
68 self.aliases = aliases
69 self.bit_depth = bit_depth
70 self.description = description
71 self.equality_group = equality_group
73 self.is_data = is_data
74 self.to_reference_transforms = to_reference_transforms
75 self.from_reference_transforms = from_reference_transforms
76 self.allocation_type = allocation_type
77 self.allocation_vars = allocation_vars
78 self.aces_transform_id = aces_transform_id
81 def mat44_from_mat33(mat33):
83 Creates a 4x4 matrix from given 3x3 matrix.
88 Parameter description.
93 Return value description.
96 return [mat33[0], mat33[1], mat33[2], 0,
97 mat33[3], mat33[4], mat33[5], 0,
98 mat33[6], mat33[7], mat33[8], 0,
102 def filter_words(words, filters_in=None, filters_out=None, flags=0):
109 Parameter description.
114 Return value description.
120 filter_matched = False
121 for filter in filters_in:
122 if re.search(filter, word, flags):
123 filter_matched = True
125 if not filter_matched:
129 filter_matched = False
130 for filter in filters_out:
131 if re.search(filter, word, flags):
132 filter_matched = True
136 filtered_words.append(word)
137 return filtered_words
140 def files_walker(directory, filters_in=None, filters_out=None, flags=0):
147 Parameter description.
152 Return value description.
155 for parent_directory, directories, files in os.walk(
156 directory, topdown=False, followlinks=True):
158 path = os.path.join(parent_directory, file)
159 if os.path.isfile(path):
160 if not filter_words((path,), filters_in, filters_out, flags):
166 def replace(string, data):
168 Replaces the data occurrences in the string.
172 string : str or unicode
173 String to manipulate.
175 Replacement occurrences.
184 >>> patterns = {"John" : "Luke",
185 ... "Jane" : "Anakin",
186 ... "Doe" : "Skywalker",
188 >>> data = "Users are: John Doe, Jane Doe, Z6PO."
189 >>> replace(data,patterns )
190 u'Users are: Luke Skywalker, Anakin Skywalker, R2D2.'
193 for old, new in data.iteritems():
194 string = string.replace(old, new)
205 Parameter description.
210 Return value description.
213 return replace(path, {' ': '_', ')': '_', '(': '_'})
218 Removes blanks, underscores, dashes and parentheses.
222 string : str or unicode
228 A compact version of that string.
231 return replace(string.lower(),
232 OrderedDict(((' ', '_'),
242 def colorspace_prefixed_name(colorspace):
244 Returns given *OCIO* colorspace prefixed name with its family name.
248 colorspace : Colorspace
249 Colorspace to prefix.
254 Family prefixed *OCIO* colorspace name.
256 prefix = colorspace.family.replace('/', ' - ')
258 return '%s - %s' % (prefix, colorspace.name)
261 def unpack_default(iterable, length=3, default=None):
263 Unpacks given iterable maintaining given length and filling missing
264 entries with given default.
273 Filling default object.
280 return itertools.islice(itertools.chain(iter(iterable),
281 itertools.repeat(default)),