getPixelLinear method

int getPixelLinear(
  1. num fx,
  2. num fy
)

Get the pixel using linear interpolation for non-integer pixel coordinates.

Implementation

int getPixelLinear(num fx, num fy) {
  final x = fx.toInt() - (fx >= 0 ? 0 : 1);
  final nx = x + 1;
  final y = fy.toInt() - (fy >= 0 ? 0 : 1);
  final ny = y + 1;
  final dx = fx - x;
  final dy = fy - y;

  int _linear(int Icc, int Inc, int Icn, int Inn) => (Icc +
          dx * (Inc - Icc + dy * (Icc + Inn - Icn - Inc)) +
          dy * (Icn - Icc))
      .toInt();

  final Icc = getPixelSafe(x, y);
  final Icn = ny >= height ? Icc : getPixelSafe(x, ny);
  final Inc = nx >= width ? Icc : getPixelSafe(nx, y);
  final Inn = nx >= width || ny >= height ? Icc : getPixelSafe(nx, ny);

  return getColor(
      _linear(getRed(Icc), getRed(Inc), getRed(Icn), getRed(Inn)),
      _linear(getGreen(Icc), getGreen(Inc), getGreen(Icn), getGreen(Inn)),
      _linear(getBlue(Icc), getBlue(Inc), getBlue(Icn), getBlue(Inn)),
      _linear(getAlpha(Icc), getAlpha(Inc), getAlpha(Icn), getAlpha(Inn)));
}