Package nukescripts :: Module flipbooking
[hide private]
[frames] | no frames]

Source Code for Module nukescripts.flipbooking

  1  # Copyright (c) 2010 The Foundry Visionmongers Ltd.  All Rights Reserved. 
  2  ############################################################################### 
3 -class FlipbookApplication(object):
4 """An interface, for so far as Python supports it. To add support for a 5 flipbook this needs to be subclassed and the 3 methods implemented. The 6 default implementation just raises an exception so any sub implementer 7 will soon find out whether his implementation works."""
8 - def __init__(self):
9 return
10
11 - def name(self):
12 """ Return the name of the flipbook. 13 @return: String""" 14 raise NotImplementedError
15
16 - def path(self):
17 """Return the executable path required to run a flipbook. 18 @return: String""" 19 raise NotImplementedError
20
21 - def cacheDir(self):
22 """Return the preferred directory for rendering. 23 @return: String""" 24 raise NotImplementedError
25
26 - def run(self, path, frameRanges, views, options):
27 """Execute the flipbook on a path. 28 @param path: The path to run the flipbook on. This will be similar to /path/to/foo%03d.exr 29 @param frameRanges: A FrameRanges object representing the range that should be flipbooked. Note that in 6.2v1-2 this was a FrameRange object. 30 @param views: A list of strings comprising of the views to flipbook. Willnot be more than the maximum supported by the flipbook. 31 @param options: A dictionary of options to use. This may contain the keys pixelAspect, roi, dimensions, audio and lut. These contain a float, a dict with bounding box dimensions, a dict with width and height, a path to audio file and a string indicating the LUT conversion to apply. 32 @return: None""" 33 raise NotImplementedError
34
35 - def capabilities(self):
36 """Return the capabilities of the flipbook application. Currently used are: 37 proxyScale: bool, whether the flipbook supports proxies 38 crop: bool, whether the flipbook supports crops 39 canPreLaunch: bool, whether the flipbook can display a frames that are still being rendered by Nuke. 40 maximumViews: int, the number of views supported by this flipbook, should be 1 or higher. 41 fileTypes: list, the extensions of the file types supported by this format. Must all be lowercase, e.g ["exr", "jpg", ...] 42 @return: dict with the capabilities above.""" 43 raise NotImplementedError
44
45 -class FlipbookFactory(object):
46 - def __init__(self):
47 self._flipbookApplications = {}
48
49 - def isRegistered(self, flipbook):
50 """ Return whether a flipbook app with that name has already been registered. 51 @param flipbook: FlipBookApplication object that's tested for. 52 @return: bool""" 53 return self._flipbookApplications.has_key(flipbook.name())
54
55 - def register(self, flipbookApplication):
56 """Register a flipbook app. It will fail if the flipbook app name isn't unique. 57 @param flipbook: FlipBookApplication object to register 58 @return: None""" 59 if not self.isRegistered(flipbookApplication): 60 self._flipbookApplications[flipbookApplication.name()] = flipbookApplication 61 else: 62 raise RuntimeError("Already registered a flipbook application with this name")
63
64 - def getNames(self):
65 """Returns a list of the names of all available flipbook apps. 66 @return: list""" 67 return self._flipbookApplications.keys()
68
69 - def getApplication(self, name):
70 """Returns the flipbook app implementation with the given name, raises an exception if none could be found. 71 @param name: The name of a flipbook that was registered. 72 @return: FlipBookApplication""" 73 if self._flipbookApplications.has_key(name): 74 return self._flipbookApplications[name] 75 else: 76 raise RuntimeError("Requested flipbook not registered")
77
78 -class FlipbookLUTPathRegistry(object):
79 """A registery of all LUT files against LUTs for each specific flipbook."""
80 - def __init__(self):
81 self._luts = {}
82
83 - def registerLUTPathForFlipbook(self, flipbook, lut, path):
84 """Register the given LUT file. 85 @param flipbook: The unique name of the flipbook 86 @param lut: The unique name for the LUT, e.g. 'sRGB' and 'rec709' 87 @param path: Location of the flipbook specific file.""" 88 if not self._luts.has_key(flipbook): 89 self._luts[flipbook] = {} 90 self._luts[flipbook][lut] = path
91
92 - def getLUTPathForFlipbook(self, flipbook, lut):
93 """Return the path for the given flipbook and lut. May return an empty string if none registered. 94 @param flipbook: The unique name of the flipbook 95 @param lut: The unique name for the LUT, e.g. 'sRGB' and 'rec709'""" 96 return self._luts.get(flipbook, {}).get(lut, "")
97 98 # Global registry of flipbooks. 99 gFlipbookFactory = FlipbookFactory() 100 # Global registry of user specified LUTs 101 gFlipbookLUTPathRegistry = FlipbookLUTPathRegistry() 102 103 # Convenience functions that make access to the globals a few key strokes less.
104 -def register(flipbookApplication):
105 """Register a flipbook. Convenience function that simple calls register() on the FlipbookFactory.""" 106 gFlipbookFactory.register(flipbookApplication)
107
108 -def registerLUTPath(flipbookApplication, lut, path):
109 """Register a LUT for a specific flipbook. The path should refer to a file that contains the LUT for the given flipbook identified by the name in flipbookApplication. It is up to the flipbook subimplementation to actually use this file and the format may vary. 110 @param flipbook: The unique name of the flipbook 111 @param lut: The unique name for the LUT, e.g. 'sRGB' and 'rec709' 112 @param path: Location of the flipbook specific file.""" 113 gFlipbookLUTPathRegistry.registerLUTPathForFlipbook(flipbookApplication, lut, path)
114
115 -def getLUTPath(flipbookAppliction, lut):
116 """Returns a path to a LUT file for the given flipbook. The contents of the file will be different for each flipbook application. Please see the relevant documentation for the specific flipbook applications. 117 @param flipbook: The unique name of the flipbook 118 @param lut: The unique name for the LUT, e.g. 'sRGB' and 'rec709'""" 119 return gFlipbookLUTPathRegistry.getLUTPathForFlipbook(flipbookAppliction, lut)
120