After tracing through ColorFunction, I found the gradients live in the list
DataPaclets`ColorDataDump`gradientSchemeMain
and "RedBlueTones" corresponds to the 14th position.
DataPaclets`ColorDataDump`gradientSchemeMain[[14, 5]]
(* {RGBColor[0.450385,0.157961,0.217975],RGBColor[0.599449,0.262748,0.294618],
RGBColor[0.721701,0.434448,0.400225],RGBColor[0.813151,0.617722,0.507726],
RGBColor[0.865768,0.767491,0.623596],RGBColor[0.857126,0.848339,0.734867],
RGBColor[0.771923,0.848195,0.811697],RGBColor[0.61971,0.781131,0.831119],
RGBColor[0.433786,0.670834,0.793785],RGBColor[0.256859,0.523007,0.711644],
RGBColor[0.139681,0.311666,0.550652]} *)
After some more investigating, it appears ColorFunction just interpolates linearly between these:
ColorData["RedBlueTones"][.02]
(* RGBColor[0.4801978`,0.17891839999999998`,0.2333036`] *)
Blend[DataPaclets`ColorDataDump`gradientSchemeMain[[14, 5, 1;;2]], .2]
(* RGBColor[0.4801978`,0.17891839999999998`,0.2333036`] *)
So we can use this to write a function that inverts a gradient ColorFunction:
InverseColorData[grad_String, color_RGBColor] := Module[{pos, knots, step, interpdata, interp, sol, x, y, z},
pos = Position[DataPaclets`ColorDataDump`gradientSchemeMain, grad][[1, 1]];
knots = DataPaclets`ColorDataDump`gradientSchemeMain[[pos, 5]];
step = 1/(Length[knots]-1);
interpdata = Transpose[{Range[0., 1, step], #}]& /@ Transpose[List @@@ knots];
interp = MapThread[LineBetween, {interpdata, {x, y, z}}];
sol = MapThread[#3 /. Solve[#1 == #2 && 0 <= #3 <= 1, #3]&, {interp, List @@ color, {x, y, z}}];
First[Intersection[##, SameTest -> (Chop[#1 - #2] == 0&)]& @@ sol]
]
LineBetween[lis_, x_] := Module[{par = Partition[lis, 2, 1], x1, y1, x2, y2},
Piecewise[
(
{{x1, y1}, {x2, y2}} = #;
{(y2-y1)/(x2-x1)*(x - x1) + y1, x1 <= x <= x2}
)& /@ par
]
]
and now we test:
With[{rand = RandomReal[{0, 1}, 10]},
Transpose[{
rand,
InverseColorData["RedBlueTones", ColorData["RedBlueTones"][#]]& /@ rand
}]
]
(* {{0.244535,0.244535}, {0.470216,0.470216}, {0.65504,0.65504}, {0.729637,0.729637},
{0.205673,0.205673}, {0.664396,0.664396}, {0.363139,0.363139}, {0.671589,0.671589},
{0.329273,0.329273}, {0.119555,0.119555}} *)
Bonus:
Since ColorFunction linearly interpolates, we can easily visualize the channels of "RedBlueTones":
With[{knots = DataPaclets`ColorDataDump`gradientSchemeMain[[14, 5]]},
Labeled[
ListLinePlot[
Transpose[{Range[0, 1, .1], #}]& /@ Transpose[List @@@ knots],
PlotStyle -> {Red, Blue, Green}
],
"RedBlueTones"
]
]
