copyWithNormalized method

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

Returns a copy of the pixel with normalized values.

Subclasses override this method to provide named parameters for channels.

Example

print(abgr8888.copyWithNormalized(0x12345678, red: 1.0)); // 0xFF345678
print(floatRgba.copyWithNormalized(Float32x4(0.1, 0.2, 0.3, 0.4), red: 0.5)); // [0.5, 0.2, 0.3, 0.4]

Implementation

@override
int copyWithNormalized(
  int pixel, {
  double? red,
  double? green,
  double? blue,
}) {
  return copyWith(
    pixel,
    red: red != null ? (red.clamp(0.0, 1.0) * 0xFF).floor() : null,
    green: green != null ? (green.clamp(0.0, 1.0) * 0xFF).floor() : null,
    blue: blue != null ? (blue.clamp(0.0, 1.0) * 0xFF).floor() : null,
  );
}