-
Notifications
You must be signed in to change notification settings - Fork 17
/
parse.py
798 lines (615 loc) · 25.6 KB
/
parse.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
#!/usr/bin/env python
"""
CDL Convert Parse
=================
Contains parser functions for converting files to cdl_convert objects.
## Public Functions
parse_ale()
Parses an ALE EDL file into a ColorCollection set to ccc.
parse_cc()
Parses an XML CC file into a ColorCorrection.
parse_ccc()
Parses an XML CCC file into a ColorCollection set to ccc.
parse_cdl
Parses an XML CDL file into a ColorCollection set to cdl.
parse_file()
Determines which parse function to call based on file extension (or
provided ext arg) and calls that function. Returns result.
parse_flex()
Parses a FLEx EDL into a ColorCollection set to ccc.
parse_rnh_cdl
Parses a Rhythm & Hues Space Separated cdl file, which is based on a
very early ASC CDL spec, into a single ColorCorrection.
## GLOBALS
INPUT_FORMATS
A dictionary whose keys are file extensions and values are the above
functions. Used by ``parse_file()`` to determine what parser to call.
## License
The MIT License (MIT)
cdl_convert
Copyright (c) 2015 Sean Wallitsch
http://github.com/shidarin/cdl_convert/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
# ==============================================================================
# IMPORTS
# ==============================================================================
from __future__ import absolute_import, print_function
# Standard Imports
from ast import literal_eval
import os
import re
from xml.etree import ElementTree
# cdl_convert imports
from . import collection, correction
# ==============================================================================
# EXPORTS
# ==============================================================================
__all__ = [
'parse_ale',
'parse_cc',
'parse_ccc',
'parse_cdl',
'parse_cmx',
'parse_file',
'parse_flex',
'parse_rnh_cdl'
]
# ==============================================================================
# FUNCTIONS
# ==============================================================================
def parse_ale(input_file): # pylint: disable=R0914
"""Parses an Avid Log Exchange (ALE) file for CDLs
**Args:**
input_file : (str)
The filepath to the ALE EDL
**Returns:**
(:class:`ColorCollection`)
A collection that contains all found ColorCorrections
**Raises:**
N/A
An ALE file is traditionally gathered during a telecine transfer using
standard ASCII characters. Each line theoretically represents a single
clip/take/shot.
Each field of data is tab delineated. We'll be searching for the ASC_SOP,
ASC_SAT fields, alone with the standard Scan Filename fields.
The Data line indicates that all the following lines are comprised of
shot information.
"""
# When we enter a section, we're store the section name
section = {
'column': False,
'data': False
}
# We'll store the correlation between index and field name
ale_indexes = {}
cdls = []
with open(input_file, 'r') as edl:
lines = edl.readlines()
for line in lines:
if line.startswith('Column'):
section['column'] = True
continue
elif line.startswith('Data'):
section['data'] = True
continue
elif section['column']:
for i, field in enumerate(line.split('\t')):
ale_indexes[field.strip()] = i
section['column'] = False
elif section['data']:
cdl_data = line.split('\t')
sat = cdl_data[ale_indexes['ASC_SAT']]
sop = cdl_data[ale_indexes['ASC_SOP']]
try:
cc_id = cdl_data[ale_indexes['Scan Filename']]
except KeyError:
# Scan Filename is usually more descriptive, but we can
# fall back on the always present 'Name' field if
# Scan Filename is missing.
cc_id = cdl_data[ale_indexes['Name']]
# Determine slope, offset and power from sop
# sop should look like:
# (1.4 1.9 1.7)(-0.1 -0.26 -0.20)(0.87 1.0 1.32)
sop = sop.replace(' ', ', ')
sop = sop.replace(')(', ')|(')
sop = sop.split('|')
sop_values = {
'slope': literal_eval(sop[0]),
'offset': literal_eval(sop[1]),
'power': literal_eval(sop[2])
}
cdl = correction.ColorCorrection(cc_id, input_file)
cdl.sat = sat
cdl.slope = sop_values['slope']
cdl.offset = sop_values['offset']
cdl.power = sop_values['power']
cdls.append(cdl)
ccc = collection.ColorCollection()
ccc.file_in = input_file
ccc.append_children(cdls)
return ccc
# ==============================================================================
def parse_cc(input_file): # pylint: disable=R0912
"""Parses a .cc file for ASC CDL information
**Args:**
input_file : (str|<ElementTree.Element>)
The filepath to the CC or the ``ElementTree.Element`` object.
**Returns:**
(:class:`ColorCorrection`)
The :class:`ColorCorrection` described within.
**Raises:**
ValueError:
Bad XML formatting can raise ValueError is missing required
elements.
A CC file is really only a single element of a larger CDL or CCC XML file,
but this element has become a popular way of passing around single shot
CDLs, rather than the much bulkier CDL file.
A sample CC XML file has text like:
::
<ColorCorrection id="cc03340">
<SOPNode>
<Description>change +1 red, contrast boost</Description>
<Slope>1.2 1.3 1.4</Slope>
<Offset>0.3 0.0 0.0</Offset>
<Power>1.0 1.0 1.0</Power>
</SOPNode>
<SatNode>
<Saturation>1.2</Saturation>
</SatNode>
</ColorCorrection>
Additional elements can include multiple descriptions at every level,
a description of the input colorspace, and a description of the viewing
colorspace and equipment.
"""
if type(input_file) is str:
root = _remove_xmlns(input_file)
file_in = input_file
else:
root = input_file
file_in = None
if not root.tag == 'ColorCorrection':
# This is not a CC file...
raise ValueError('CC parsed but no ColorCorrection found')
try:
cc_id = root.attrib['id']
except KeyError:
raise ValueError('No id found on ColorCorrection')
cdl = correction.ColorCorrection(cc_id)
if file_in:
cdl.file_in = file_in
# Grab our descriptions and add them to the cdl.
cdl.parse_xml_descs(root)
# See if we have a viewing description.
cdl.parse_xml_viewing_desc(root)
# See if we have an input description.
cdl.parse_xml_input_desc(root)
def find_required(elem, names):
"""Finds the required element and returns the found value.
Args:
root : <ElementTree.Element>
The element to search in.
names : [str]
A list of names the element might be under.
Raises:
ValueError:
If element does not contain the required name.
Returns:
<ElementTree.Element>
"""
found_element = None
for possibility in names:
found_element = elem.find(possibility)
if found_element is not None:
break
# element might never have been triggered.
if found_element is None:
raise ValueError(
'The ColorCorrection element could not be parsed because the '
'XML is missing required elements: {elems}'.format(
elems=str(names)
)
)
else:
return found_element
try:
sop_xml = find_required(root, correction.SopNode.element_names)
except ValueError:
sop_xml = None
try:
sat_xml = find_required(root, correction.SatNode.element_names)
except ValueError:
sat_xml = None
if sop_xml is None and sat_xml is None:
raise ValueError(
'The ColorCorrection element requires either a Sop node or a Sat '
'node, and it is missing both.'
)
if sop_xml is not None:
cdl.slope = find_required(sop_xml, ['Slope']).text.split()
cdl.offset = find_required(sop_xml, ['Offset']).text.split()
cdl.power = find_required(sop_xml, ['Power']).text.split()
# Calling the slope, offset and power attributes on the cdl will have
# created an instance of SopNode on cdl.sop_node, so we can populate
# those descriptions.
cdl.sop_node.parse_xml_descs(sop_xml)
if sat_xml is not None:
cdl.sat = find_required(sat_xml, ['Saturation']).text
# In the same manor of sop, we can call the sat node now to set the
# desc descriptions.
cdl.sat_node.parse_xml_descs(sat_xml)
return cdl
# ==============================================================================
def parse_ccc(input_file):
"""Parses a .ccc file into a :class:`ColorCollection` with type 'ccc'
**Args:**
input_file : (str)
The filepath to the CCC.
**Returns:**
(:class:`ColorCollection`)
A collection of all the found :class:`ColorCorrection` as well
as any metadata within the XML
**Raises:**
ValueError:
Bad XML formatting can raise ValueError is missing required
elements.
A ColorCorrectionCollection is just that- a collection of ColorCorrection
elements. It does not contain any ColorDecision or MediaRef elements,
but is free to contain as many Description elements as someone adds in.
It should also contain an InputDescription element, describing the color
space and other properties of the incoming image, as well as a
ViewingDescription which describes the viewing environment as well
as any relevant hardware devices used to view or grade.
"""
root = _remove_xmlns(input_file)
if root.tag != 'ColorCorrectionCollection':
# This is not a CCC file...
raise ValueError('CCC parsed but no ColorCorrectionCollection found')
ccc = collection.ColorCollection()
ccc.set_to_ccc()
ccc.file_in = input_file
# Grab our descriptions and add them to the ccc.
ccc.parse_xml_descs(root)
# See if we have a viewing description.
ccc.parse_xml_viewing_desc(root)
# See if we have an input description.
ccc.parse_xml_input_desc(root)
# Add all of our found color corrections. If the parse_xml returns False,
# (for no CCs found) we raise a value error.
if not ccc.parse_xml_color_corrections(root):
raise ValueError(
'ColorCorrectionCollections require at least one ColorCorrection '
'node, but no ColorCorrection nodes were found.'
)
return ccc
# ==============================================================================
def parse_cdl(input_file):
"""Parses a .cdl file into a :class:`ColorCollection` with type 'cdl'
**Args:**
input_file : (str)
The filepath to the CDL.
**Returns:**
(:class:`ColorCollection`)
A collection of all the found :class:`ColorDecisions` as well
as any metadata within the XML
**Raises:**
ValueError:
Bad XML formatting can raise ValueError is missing required
elements.
A ColorDecicionList is just that- a list of ColorDecision elements. It does
not directly contain any ColorCorrections or Media Ref, only
ColorDecisions, but is free to contain as many Description elements as
someone adds in.
It should also contain an InputDescription element, describing the color
space and other properties of the incoming image, as well as a
ViewingDescription which describes the viewing environment as well
as any relevant hardware devices used to view or grade.
"""
root = _remove_xmlns(input_file)
if root.tag != 'ColorDecisionList':
# This is not a CDL file...
raise ValueError('CDL parsed but no ColorDecisionList found')
cdl = collection.ColorCollection()
cdl.set_to_cdl()
cdl.file_in = input_file
# Grab our descriptions and add them to the ccc.
cdl.parse_xml_descs(root)
# See if we have a viewing description.
cdl.parse_xml_viewing_desc(root)
# See if we have an input description.
cdl.parse_xml_input_desc(root)
# Add all of our found color decisions. If the parse_xml returns False,
# (for no CDs found) we raise a value error.
if not cdl.parse_xml_color_decisions(root):
raise ValueError(
'ColorDecisionLists require at least one ColorDecision node, but '
'no ColorDecision nodes were found.'
)
return cdl
# ==============================================================================
def parse_cmx(input_file): # pylint: disable=R0912,R0914
"""Parses a CMX EDL file for ASC CDL information.
**Args:**
input_file : (str)
The filepath to the CMX EDL
**Returns:**
(:class:`ColorCollection`)
A collection that contains all the ColorCorrection objects found
within this EDL
**Raises:**
N/A
001 DS0010.bg1 V C 00:08:07:23 00:08:16:10 01:00:00:00 01:00:08:11
*ASC_SOP (1.45 1.22 1.15)(-0.14 -0.11 -0.11)(1.00 1.00 1.00)
*ASC_SAT 0.773000
"""
cdls = []
with open(input_file, 'rb') as edl:
lines = '\n'.join(edl.readlines())
filename = os.path.basename(input_file).split('.')[0]
def parse_cmx_clip(cmx_tuple):
"""Parses a three line cmx clip tuple."""
if len(cmx_tuple) != 3:
print(cmx_tuple)
return
title = cmx_tuple[0].split(': ')[1]
sop = re.match(
r'^\*ASC_SOP \(([\d\. -]+)\)\(([\d\. -]+)\)\(([\d\. -]+)\)',
cmx_tuple[1]
)
if not sop:
print(cmx_tuple)
return
else:
cc = correction.ColorCorrection(title, filename)
cc.desc = cmx_tuple[0].strip()
cc.slope = sop.group(1).split()
cc.offset = sop.group(2).split()
cc.power = sop.group(3).split()
cc.sat = cmx_tuple[2].split()[1]
return cc
#This regex will avoid caring about extra stuff between the important lines we care about as long as the
#important lines we care about are in the right order
ccMatcher = re.compile(r'(\d*.+)(\n*.*)(\*\ *FROM.+)(\n*.*)(\*\ *ASC_(SOP|SAT).+)(\n*.*)(\*\ *ASC_(SOP|SAT).+)')
clipEntries = ccMatcher.findall(lines)
for entry in clipEntries:
clip = entry[2]
sop = None
sat = None
i=0
for group in entry:
if group == 'SOP':
sop = entry[i-1]
if group == 'SAT':
sat = entry[i-1]
i += 1
if clip is not None and sop is not None and sat is not None:
cc = parse_cmx_clip((clip, sop, sat))
cdls.append(cc)
else:
continue
ccc = collection.ColorCollection()
ccc.file_in = input_file
ccc.append_children(cdls)
return ccc
# ==============================================================================
def parse_flex(input_file): # pylint: disable=R0912,R0914
"""Parses a DaVinci FLEx telecine EDL for ASC CDL information.
**Args:**
input_file : (str)
The filepath to the FLEx EDL
**Returns:**
(:class:`ColorCollection`)
A collection that contains all the ColorCorrection objects found
within this EDL
**Raises:**
N/A
The DaVinci FLEx EDL is an odd duck, it's information conveyed via an
extremely strict line & character addressing system.
Each line must begin with a line number header that indicated what type
of information the line contains, with line number 100 indicating the
start of a new shot/take. Lines 000-099 contain session information.
Within each line, important information is constricted to a certain
range of characters, rather than space or comma separated like in an
ALE EDL.
Some line numbers we care about, and the character indexes:
+--------+---------------+------------+---------------------------------+
| Line # | Line Name | Char Index | Data Type |
+========+===============+============+=================================+
| 010 | Project Title | 10-79 | Title |
+--------+---------------+------------+---------------------------------+
| 100 | Slate Info | 10-17 | Scene |
+--------+---------------+------------+---------------------------------+
| | | 24-31 | Take ID |
+--------+---------------+------------+---------------------------------+
| | | 42-49 | Camera Reel ID |
+--------+---------------+------------+---------------------------------+
| 701 | ASC SOP | (This entry can be safely space separated) |
+--------+---------------+------------+---------------------------------+
| 702 | ASC SAT | (This entry can be safely space separated) |
+--------+---------------+------------+---------------------------------+
We'll try and default to using the Slate information to derive the
resultant filename, however that information is optional. If no
slate information is found, we'll iterate up at the end of the title.
If no title information is found, we'll have to iterate up on the
actual input filename, which is far from ideal.
"""
cdls = []
with open(input_file, 'r') as edl:
lines = edl.readlines()
filename = os.path.basename(input_file).split('.')[0]
title = None
# Metadata will store, in order, the various scene, take, reel fields
# it finds.
metadata = []
sop = {}
sat = None
def build_cc(line_id, edl_path, sop_dict, sat_value, title_line):
"""Builds and returns a cc if sop/sat values found"""
col_cor = correction.ColorCorrection(line_id, edl_path)
if title_line:
col_cor.desc = title_line
if sop_dict:
# If it finds the 701 line, it will have all three
col_cor.slope = sop_dict['slope']
col_cor.offset = sop_dict['offset']
col_cor.power = sop_dict['power']
if sat_value:
col_cor.sat = sat_value
return col_cor
for line in lines:
if line.startswith('100'):
# This is the start of a take/shot
# We need to dump the previous records to a CDL
# Then clear the records.
# Note that the first data line will also hit this.
metadata = [i for i in metadata if i != '']
if metadata:
cc_id = '_'.join(metadata)
else:
field = title if title else filename
cc_id = field + str(len(cdls) + 1).rjust(3, '0')
# If we already have values:
if sop or sat:
cdl = build_cc(cc_id, input_file, sop, sat, title)
cdls.append(cdl)
metadata = []
sop = {}
sat = None
elif line.startswith('010'):
# Title Line
# 10-79 Title
title = line[10:80].strip()
elif line.startswith('110'):
# Slate Information
# 10-17 Scene
# 24-31 Take ID
# 42-49 Camera Reel ID
metadata = [
line[10:18].strip(), # Scene
line[24:32].strip(), # Take
line[42:50].strip(), # Reel
]
elif line.startswith('701'):
# ASC SOP
# 701 ASC_SOP(# # #)(-# -# -#)(# # #)
sop = {
'slope': line[12:32].split(),
'offset': line[34:57].split(),
'power': line[59:79].split()
}
elif line.startswith('702'):
# ASC SAT
# 702 ASC_SAT ######
sat = line.split()[-1]
# We need to dump the last record to the cdl list
metadata = [i for i in metadata if i != '']
if metadata:
cc_id = '_'.join(metadata)
else:
field = title if title else filename
cc_id = field + str(len(cdls) + 1).rjust(3, '0')
# If we found values at all:
if sop or sat:
cdl = build_cc(cc_id, input_file, sop, sat, title)
cdls.append(cdl)
ccc = collection.ColorCollection()
ccc.file_in = input_file
ccc.append_children(cdls)
return ccc
# ==============================================================================
def parse_rnh_cdl(input_file):
"""Parses a space separated .cdl file for ASC CDL information.
**Args:**
input_file : (str)
The filepath to the CDL
**Returns:**
(:class:`ColorCorrection`)
The single ColorCorrection object retrieved from the beta CDL
**Raises:**
N/A
A space separated cdl file is an internal Rhythm & Hues format used by
the Rhythm & Hues for displaying shot level and sequence level within
their internally developed playback software.
The file is a simple file consisting of one line. That line has 10, space
separated elements that correspond to the ten ASC CDL elements in order of
operations.
``SlopeR SlopeG SlopeB OffsetR OffsetG OffsetB PowerR PowerG PowerB Sat``
"""
with open(input_file, 'r') as cdl_f:
# We only need to read the first line
line = cdl_f.readline()
line = line.split()
# The filename without extension will become the id
filename = os.path.basename(input_file).split('.')[0]
slope = [line[0], line[1], line[2]]
offset = [line[3], line[4], line[5]]
power = [line[6], line[7], line[8]]
sat = line[9]
cdl = correction.ColorCorrection(filename, input_file)
cdl.slope = slope
cdl.offset = offset
cdl.power = power
cdl.sat = sat
return cdl
# ==============================================================================
# PRIVATE FUNCTIONS
# ==============================================================================
def _remove_xmlns(input_file):
"""Removes the xmlns attribute from XML files, then returns the element"""
# We're going to open the file as a string and remove the xmlns, as
# it doesn't do a lot for us when working with CDLs, and in fact
# just clutters everything the hell up.
with open(input_file, 'r') as xml_file:
xml_string = xml_file.read()
xml_string = re.sub(' xmlns="[^"]+"', '', xml_string, count=1)
return ElementTree.fromstring(xml_string)
# ==============================================================================
# GLOBALS
# ==============================================================================
INPUT_FORMATS = {
'ale': parse_ale,
'ccc': parse_ccc,
'cc': parse_cc,
'cdl': parse_cdl,
'edl': parse_cmx,
'flex': parse_flex,
'rcdl': parse_rnh_cdl,
}
# ==============================================================================
# PARSE FILE
# ==============================================================================
def parse_file(filepath, filetype=None):
"""Determines & uses the correct parser to use on a CDL file
Args:
filepath : (str)
The filepath to the file. Must exist.
filetype=None : (str)
A file extension corresponding to the CDL type to convert from.
If not provided, we'll derive it from the filepath.
Should not include a '.'
Raises:
N/A
Returns:
:class:`ColorCorrection` or :class:`ColorCollection`
Depending on the type of input file, this function will
either return a single :class:`ColorCorrection` or a full
:class:`ColorCollection` , containing one or more
:class:`ColorCorrection` or :class:`ColorDecision`
"""
if not filetype:
filetype = os.path.basename(filepath).split('.')[-1].lower()
return INPUT_FORMATS[filetype](filepath)