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=None,
49 from_reference_transforms=None,
50 allocation_type=ocio.Constants.ALLOCATION_UNIFORM,
52 aces_transform_id=None):
59 Parameter description.
64 Return value description.
70 if to_reference_transforms is None:
71 to_reference_transforms = []
73 if from_reference_transforms is None:
74 from_reference_transforms = []
76 if allocation_vars is None:
77 allocation_vars = [0, 1]
80 self.aliases = aliases
81 self.bit_depth = bit_depth
82 self.description = description
83 self.equality_group = equality_group
85 self.is_data = is_data
86 self.to_reference_transforms = to_reference_transforms
87 self.from_reference_transforms = from_reference_transforms
88 self.allocation_type = allocation_type
89 self.allocation_vars = allocation_vars
90 self.aces_transform_id = aces_transform_id
93 def mat44_from_mat33(mat33):
95 Creates a 4x4 matrix from given 3x3 matrix.
100 Parameter description.
105 Return value description.
108 return [mat33[0], mat33[1], mat33[2], 0,
109 mat33[3], mat33[4], mat33[5], 0,
110 mat33[6], mat33[7], mat33[8], 0,
114 def filter_words(words, filters_in=None, filters_out=None, flags=0):
121 Parameter description.
126 Return value description.
132 filter_matched = False
133 for filter in filters_in:
134 if re.search(filter, word, flags):
135 filter_matched = True
137 if not filter_matched:
141 filter_matched = False
142 for filter in filters_out:
143 if re.search(filter, word, flags):
144 filter_matched = True
148 filtered_words.append(word)
149 return filtered_words
152 def files_walker(directory, filters_in=None, filters_out=None, flags=0):
159 Parameter description.
164 Return value description.
167 for parent_directory, directories, files in os.walk(
168 directory, topdown=False, followlinks=True):
170 path = os.path.join(parent_directory, file)
171 if os.path.isfile(path):
172 if not filter_words((path,), filters_in, filters_out, flags):
178 def replace(string, data):
180 Replaces the data occurrences in the string.
184 string : str or unicode
185 String to manipulate.
187 Replacement occurrences.
196 >>> patterns = {'John' : 'Luke',
197 ... 'Jane' : 'Anakin',
198 ... 'Doe' : 'Skywalker',
200 >>> data = 'Users are: John Doe, Jane Doe, Z6PO.'
201 >>> replace(data,patterns )
202 u'Users are: Luke Skywalker, Anakin Skywalker, R2D2.'
205 for old, new in data.iteritems():
206 string = string.replace(old, new)
217 Parameter description.
222 Return value description.
225 return replace(path, {' ': '_', ')': '_', '(': '_'})
230 Removes blanks, underscores, dashes and parentheses.
234 string : str or unicode
240 A compact version of that string.
243 return replace(string.lower(),
244 OrderedDict(((' ', '_'),
254 def colorspace_prefixed_name(colorspace):
256 Returns given *OCIO* colorspace prefixed name with its family name.
260 colorspace : Colorspace
261 Colorspace to prefix.
266 Family prefixed *OCIO* colorspace name.
268 prefix = colorspace.family.replace('/', ' - ')
270 return '%s - %s' % (prefix, colorspace.name)
273 def unpack_default(iterable, length=3, default=None):
275 Unpacks given iterable maintaining given length and filling missing
276 entries with given default.
285 Filling default object.
292 return itertools.islice(itertools.chain(iter(iterable),
293 itertools.repeat(default)),