applyEffect method

  1. @override
void applyEffect(
  1. Buffer target,
  2. Rect bounds
)
override

Applies the effect directly to the target buffer within bounds.

Implementation

@override
void applyEffect(Buffer target, Rect bounds) {
  final mutator = ColorMutator(scalar);
  final startY = max(0, bounds.y);
  final endY = min(target.height, bounds.y + bounds.height);
  final startX = max(0, bounds.x);
  final endX = min(target.width, bounds.x + bounds.width);

  if (startX >= endX || startY >= endY) return;

  for (var y = startY; y < endY; y++) {
    final rowOffset = y * target.width;
    for (var x = startX; x < endX; x++) {
      final idx = rowOffset + x;
      final attrIdx = idx * 3;
      if ((target.attributes[attrIdx + 2] & Modifier.transparent) != 0) {
        continue;
      }

      final fg = target.attributes[attrIdx + 0];
      if (fg != 0) {
        target.attributes[attrIdx + 0] = mutator.dimPacked(fg);
      }

      final bg = target.attributes[attrIdx + 1];
      if (bg != 0) {
        target.attributes[attrIdx + 1] = mutator.dimPacked(bg);
      }
    }
  }
}