colorBlend method

  1. @defineMethodSkip
Color colorBlend(
  1. Function fMode,
  2. Color color1,
  3. Color color2
)

Mix two colors color1 and color2 according fMode function

double fMmode(double cb, double cs)

Implementation

@defineMethodSkip
Color colorBlend(Function fMode, Color color1, Color color2) {
  final ab = color1.alpha.toDouble(); // backdrop
  double cb;
  final as = color2.alpha.toDouble(); // source
  double cs;
  double ar; // alpha result
  double cr; // channel result
  final r = <num>[0, 0, 0];

  ar = as + ab * (1 - as);

  for (var i = 0; i < 3; i++) {
    cb = color1.rgb[i] / 255;
    cs = color2.rgb[i] / 255;
    cr = fMode(cb, cs) as double;
    if (ar != 0) cr = (as * cs + ab * (cb - as * (cb + cs - cr))) / ar;
    r[i] = cr * 255;
  }
  return Color.fromList(r, ar);

//    function colorBlend(mode, color1, color2) {
//        var ab = color1.alpha, cb, // backdrop
//            as = color2.alpha, cs, // source
//            ar, cr, r = [];        // result
//
//        ar = as + ab * (1 - as);
//        for (var i = 0; i < 3; i++) {
//            cb = color1.rgb[i] / 255;
//            cs = color2.rgb[i] / 255;
//            cr = mode(cb, cs);
//            if (ar) {
//                cr = (as * cs + ab * (cb -
//                      as * (cb + cs - cr))) / ar;
//            }
//            r[i] = cr * 255;
//        }
//
//        return new Color(r, ar);
//    }
}