convertColor function
Implementation
Color convertColor(Color c,
{Color? to, Format? format, int? numChannels, num? alpha}) {
final fromFormat = c.palette?.format ?? c.format;
format = to?.format ?? format ?? c.format;
numChannels = to?.length ?? numChannels ?? c.length;
alpha ??= 0;
if (format == fromFormat && numChannels == c.length) {
if (to == null) {
return c.clone();
}
to.set(c);
return to;
}
switch (format) {
case Format.uint8:
final c2 = to ?? ColorUint8(numChannels);
return _convertColor(c, c2, alpha);
case Format.uint1:
final c2 = to ?? ColorUint1(numChannels);
return _convertColor(c, c2, alpha);
case Format.uint2:
final c2 = to ?? ColorUint2(numChannels);
return _convertColor(c, c2, alpha);
case Format.uint4:
final c2 = to ?? ColorUint4(numChannels);
return _convertColor(c, c2, alpha);
case Format.uint16:
final c2 = to ?? ColorUint16(numChannels);
return _convertColor(c, c2, alpha);
case Format.uint32:
final c2 = to ?? ColorUint32(numChannels);
return _convertColor(c, c2, alpha);
case Format.int8:
final c2 = to ?? ColorInt8(numChannels);
return _convertColor(c, c2, alpha);
case Format.int16:
final c2 = to ?? ColorInt16(numChannels);
return _convertColor(c, c2, alpha);
case Format.int32:
final c2 = to ?? ColorInt32(numChannels);
return _convertColor(c, c2, alpha);
case Format.float16:
final c2 = to ?? ColorFloat16(numChannels);
return _convertColor(c, c2, alpha);
case Format.float32:
final c2 = to ?? ColorFloat32(numChannels);
return _convertColor(c, c2, alpha);
case Format.float64:
final c2 = to ?? ColorFloat64(numChannels);
return _convertColor(c, c2, alpha);
}
}