getPixelLinear method
Get the pixel using linear interpolation for non-integer pixel coordinates.
Implementation
Color 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;
num linear(num icc, num inc, num icn, num inn) =>
icc +
dx * (inc - icc + dy * (icc + inn - icn - inc)) +
dy * (icn - icc);
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(icc.r, inc.r, icn.r, inn.r),
linear(icc.g, inc.g, icn.g, inn.g),
linear(icc.b, inc.b, icn.b, inn.b),
linear(icc.a, inc.a, icn.a, inn.a));
}