copyWith method

  1. @override
int copyWith(
  1. int pixel, {
  2. int? red,
  3. int? green,
  4. int? blue,
})
override

Returns a copy of the pixel.

Subclasses override this method to provide named parameters for channels.

Example

print(abgr8888.copyWith(0x12345678, red: 0x9A)); // 0x9A345678
print(floatRgba.copyWith(Float32x4(0.1, 0.2, 0.3, 0.4), red: 0.5)); // [0.5, 0.2, 0.3, 0.4]

Implementation

@override
int copyWith(
  int pixel, {
  int? red,
  int? green,
  int? blue,
}) {
  var output = pixel;
  if (red != null) {
    output = (output & 0x00FFFF) | ((red & 0xFF) << 16);
  }
  if (green != null) {
    output = (output & 0xFF00FF) | ((green & 0xFF) << 8);
  }
  if (blue != null) {
    output = (output & 0xFFFF00) | (blue & 0xFF);
  }
  return output;
}