lf3 EvalComponentMixing(half3 color, bool j) {
  half4 rgbx = j ? altr_j_mix_rgbx : altr_i_mix_rgbx;
  half4 Mmcx = j ? altr_j_mix_Mmcx : altr_i_mix_Mmcx;
  half M = max(max(color.r, color.g), color.b);
  half m = min(min(color.r, color.g), color.b);
  half common = dot(rgbx.rgb, color) +
                Mmcx[0] * M +
                Mmcx[1] * m;
  return Mmcx[2] * color + half3(common);
}
half EvalGain(half color, bool j) {
  half2 tc = half2(curve_scale * color + 0.5, 0.5);
  half y = j ? altr_j_curve.eval(tc).a : altr_i_curve.eval(tc).a;
  return gain_min + gain_span * y;
}
half4 main(half4 color) {
  half3 G = half3(0.0);
  if (altr_i_weight > 0.0) {
    half3 mixed = EvalComponentMixing(color.rgb, false);
    G += altr_i_weight * half3(EvalGain(mixed.r, false),
                               EvalGain(mixed.g, false),
                               EvalGain(mixed.b, false));
  }
  if (altr_j_weight > 0.0) {
    half3 mixed = EvalComponentMixing(color.rgb, true);
    G += altr_j_weight * half3(EvalGain(mixed.r, true),
                               EvalGain(mixed.g, true),
                               EvalGain(mixed.b, true));
  }
  color.rgb *= exp2(G);
  return color;
}
