clamp colorArray values to [0,1] range.
Add color space conversions.

Convert a sRGB color to linear and vice versa.
Interpolate assuming input in sRGB color space.

Convert each pixel from the input image from sRGB to linear color space, perform interpolation, and convert the resulting color back to sRGB.