cmyk2rgb method Null safety

List<int> cmyk2rgb(
  1. num cyan,
  2. num magenta,
  3. num yellow,
  4. num keyBlack
)

Implementation

static List<int> cmyk2rgb(num cyan, num magenta, num yellow, num keyBlack) {
  if (cyan <= 1 && magenta <= 1 && yellow <= 1 && keyBlack <= 1) {
    // if both <=1 we assume that are 0-1 range, NOTE that means if REALLY
    // want (0.01 then you need to pass it like that and not as 1 in to 100 scale)
    cyan *= 100;
    magenta *= 100;
    yellow *= 100;
    keyBlack *= 100;
  }
  cyan = cyan / 100;
  magenta = magenta / 100;
  yellow = yellow / 100;
  keyBlack = keyBlack / 100;

  var r = 1 - min(1, cyan * (1 - keyBlack) + keyBlack);
  var g = 1 - min(1, magenta * (1 - keyBlack) + keyBlack);
  var b = 1 - min(1, yellow * (1 - keyBlack) + keyBlack);

  return [(r * 255).round(), (g * 255).round(), (b * 255).round()];
}