Name that spline!

Can someone please tell me the formula used to fit the piecewise curve to the control points:

Are they cubic? quadratic?

You can achieve this through cubic or quadratic interpolation. The only problem is that these interpolations tend to swing around the points and thus create overshoots which might cross the boundaries of the box. Hence there are special modifications of these interpolations which get rid of the overshoots.

Well when you bring control points close together, the local minima/maxima quickly go outside the box. Photoshop handles this by just clamping the output to [0, ]1

Yep, I think that’s the answer. I found this interesting Javascript applet:

The behavior of the control points in Photoshop’s “Contour” dialog is exactly like in this applet. The Javascript applet is doing simple Newton form polynomial interpolation through N points (up to degree 10). So, to replicate this functionality I would only need implement N degree polynomial interpolation (Numerical Recipes has a few of these).

By marking a control point as a “corner” it breaks the polynomial in half, piecewise, into two smaller degree polynomials passing through the left and right set of points, with 1 point shared (the corner point). Two adjacent corner points implement a straight line piece.