copyWith method

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

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
@nonVirtual
int copyWith(
  int pixel, {
  int? red,
  int? green,
  int? blue,
  int? alpha,
}) {
  var output = pixel;
  if (red != null) {
    output &= ~_maskRed;
    output |= (red & 0xFF) << _offsetRed;
  }
  if (green != null) {
    output &= ~_maskGreen;
    output |= (green & 0xFF) << _offsetGreen;
  }
  if (blue != null) {
    output &= ~_maskBlue;
    output |= (blue & 0xFF) << _offsetBlue;
  }
  if (alpha != null) {
    output &= ~_maskAlpha;
    output |= (alpha & 0xFF) << _offsetAlpha;
  }
  return output;
}