That might be exactly what I need, actually (thanks!!). I wonder if that gamut.limit function is equivalent to a perceptual rendering intent or a relative chromatic, etc.
Now I just wish it was already ported to python.
Edit: Now I’m not quite sure if the gamut.limit function is exactly what I want to do. In my example, I want to take a Blue sRGB(0,0,1) and manipulate it to the nearest color with CIECAM hue angle 0. I don’t want to interpolate or modify h-- only J and C. That is, I want the resulting hue to be 0 and J and C adjusted if necessary to stay within sRGB. I suppose my assumption is that all hue angles are going to be possible as long as the illuminant is somewhere within the sRGB locus.
edit. It dawned on me that really Lightness and Hue are the two dimensions that are always going to be possible, and it is only Chromacity that is going to have to be adjusted to stay within the sRGB gamut. So, I should be able to build a loop where CIECAM—>sRGB and reduce chroma some small amount between loops until all sRGB values are 0-1. Once within a certain small threshold I could then clip it to account for rounding errors. edit: I guess there is a name for this kind of thing: Newton’s method.
I wonder what happens if you make the illuminant sRGB(0,0,1) (XYZ[0.18049265, 0.0722005 , 0.95049713])? Does that make a lot of hue angles out-of-gamut? Or, does that simply mean that a lot of hue angles are identical to sRGB(0,0,1) but perfectly valid?
Getting back to the red apple example… if I paint a red apple under a warm light, it seems that as the apple turns to face the light the color is going to be desaturated by the illuminant. So, choosing a warm illuminant (like A) might be very helpful to get this gradient. The shadow side of the apple must also have an illuminant if we are to see it, obviously. This is where it gets more confusing. In my red gradient example above, the saturated reds are sRGB red colors, so I suppose that implies a D65 illuminant. If I painted a red apple using this gradient, would that imply that the ambient/shadow side is a D65 light source and the lit side is an “A” light source? 