+ // Start
+ out[0] = stops.comps[0].red;
+ out[1] = stops.comps[0].green;
+ out[2] = stops.comps[0].blue;
+ out[3] = stops.comps[0].alpha;
+ }
+ else if (f >= 1.0)
+ {
+ // end
+ out[0] = stops.comps[stops.count - 1].red;
+ out[1] = stops.comps[stops.count - 1].green;
+ out[2] = stops.comps[stops.count - 1].blue;
+ out[3] = stops.comps[stops.count - 1].alpha;
+ }
+ else
+ {
+ // Find first component with position greater than f
+ unsigned i;
+ for ( i = 0; i < stops.count; i++ )
+ {
+ if (stops.comps[i].pos > f)
+ break;
+ }
+
+ // Interpolated between stops
+ CGFloat diff = (f - stops.comps[i-1].pos);
+ CGFloat range = (stops.comps[i].pos - stops.comps[i-1].pos);
+ CGFloat fact = diff / range;
+
+ out[0] = stops.comps[i - 1].red + (stops.comps[i].red - stops.comps[i - 1].red) * fact;
+ out[1] = stops.comps[i - 1].green + (stops.comps[i].green - stops.comps[i - 1].green) * fact;
+ out[2] = stops.comps[i - 1].blue + (stops.comps[i].blue - stops.comps[i - 1].blue) * fact;
+ out[3] = stops.comps[i - 1].alpha + (stops.comps[i].alpha - stops.comps[i - 1].alpha) * fact;