By now, we can get the function of a curve that interpolates arbitrary control points. However, this function might be expensive. We don't want to run it once-per-channel, per -pixel (for example, 921,600 times per frame if applied to three channels of 640 x 480 video). Fortunately, we are typically dealing with just 256 possible input values (in 8 bits per channel) and we can cheaply precompute and store that many output values. Then, our per-channel, per-pixel cost is just a lookup of the cached output value.
Let's edit the utils.py file and add a function that will create a lookup array for a given function:
def createLookupArray(func, length=256):
"""Return a lookup for whole-number inputs to a function.
The lookup values are clamped to [0, length - 1].
"""
if func is None:
return None
...