Class InterpolationNearest
- All Implemented Interfaces:
Serializable
Note that this interpolator does not actually select the "nearest" pixel, but only uses the truncated integer pixel location (floor). This is an optimization reflecting an assumption about the implementation of the resampler. It is assumed that the conversion of continuous source image coordinates to discrete pixel indices drops the final subtraction of 0.5 for the case of a nearest-neighbor interpolator.
Neighborhoods of sizes 2x1, 1x2, 2x2, 4x1, 1x4, 4x4, Nx1 and 1xN, that is, all the interpolate() methods defined in the Interpolation class, are supported in the interest of simplifying code that handles a number of types of interpolation. In each case, the central sample is returned and the rest are ignored.
The class is marked 'final' so that it may be more easily inlined.
- See Also:
-
Field Summary
Fields inherited from class Interpolation
INTERP_BICUBIC, INTERP_BICUBIC_2, INTERP_BILINEAR, INTERP_NEAREST -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoubleinterpolate(double[][] samples, float xfrac, float yfrac) Performs interpolation on a two-dimensional array of double samples.doubleinterpolate(double s__, double s_0, double s_1, double s_2, double s0_, double s00, double s01, double s02, double s1_, double s10, double s11, double s12, double s2_, double s20, double s21, double s22, float xfrac, float yfrac) Performs interpolation on a 4x4 grid of double samples.doubleinterpolate(double s00, double s01, double s10, double s11, float xfrac, float yfrac) Performs interpolation on a 2x2 grid of double samples.floatinterpolate(float[][] samples, float xfrac, float yfrac) Performs interpolation on a two-dimensional array of floating-point samples.floatinterpolate(float s00, float s01, float s10, float s11, float xfrac, float yfrac) Performs interpolation on a 2x2 grid of floating-point samples.floatinterpolate(float s__, float s_0, float s_1, float s_2, float s0_, float s00, float s01, float s02, float s1_, float s10, float s11, float s12, float s2_, float s20, float s21, float s22, float xfrac, float yfrac) Performs interpolation on a 4x4 grid of floating-point samples.intinterpolate(int[][] samples, int xfrac, int yfrac) Performs interpolation on a two-dimensional array of integral samples.intinterpolate(int s00, int s01, int s10, int s11, int xfrac, int yfrac) Performs interpolation on a 2x2 grid of integral samples.intinterpolate(int s__, int s_0, int s_1, int s_2, int s0_, int s00, int s01, int s02, int s1_, int s10, int s11, int s12, int s2_, int s20, int s21, int s22, int xfrac, int yfrac) Performs interpolation on a 4x4 grid of integral samples.doubleinterpolateH(double[] samples, float xfrac) Performs horizontal interpolation on a one-dimensional array of double samples.doubleinterpolateH(double s0, double s1, float xfrac) Performs horizontal interpolation on a pair of double samples.floatinterpolateH(float[] samples, float xfrac) Performs horizontal interpolation on a one-dimensional array of floating-point samples.floatinterpolateH(float s0, float s1, float xfrac) Performs horizontal interpolation on a pair of floating-point samples.intinterpolateH(int[] samples, int xfrac) Performs horizontal interpolation on a one-dimensional array of integral samples.intinterpolateH(int s0, int s1, int xfrac) Performs horizontal interpolation on a pair of integral samples.doubleinterpolateV(double[] samples, float yfrac) Performs vertical interpolation on a one-dimensional array of double samples.doubleinterpolateV(double s0, double s1, float yfrac) Performs vertical interpolation on a pair of double samples.floatinterpolateV(float[] samples, float yfrac) Performs vertical interpolation on a one-dimensional array of floating-point samples.floatinterpolateV(float s0, float s1, float yfrac) Performs vertical interpolation on a pair of floating-point samples.intinterpolateV(int[] samples, int yfrac) Performs vertical interpolation on a one-dimensional array of integral samples.intinterpolateV(int s0, int s1, int yfrac) Performs vertical interpolation on a pair of integral samples.Methods inherited from class Interpolation
getBottomPadding, getHeight, getInstance, getLeftPadding, getRightPadding, getSubsampleBitsH, getSubsampleBitsV, getTopPadding, getWidth, interpolateH, interpolateH, interpolateH, interpolateV, interpolateV, interpolateV, isSeparable
-
Constructor Details
-
InterpolationNearest
public InterpolationNearest()Constructs anInterpolationNearest. The return value ofgetSubsampleBitsH()andgetSubsampleBitsV()will be 0.
-
-
Method Details
-
interpolateH
public int interpolateH(int[] samples, int xfrac) Performs horizontal interpolation on a one-dimensional array of integral samples. The central sample (samples[0]) is returned.- Specified by:
interpolateHin classInterpolation- Parameters:
samples- an array of ints.xfrac- the subsample position, multiplied by 2(subsampleBitsH).- Returns:
- the interpolated value as an int.
-
interpolateV
public int interpolateV(int[] samples, int yfrac) Performs vertical interpolation on a one-dimensional array of integral samples. The central sample (samples[0]) is returned.- Overrides:
interpolateVin classInterpolation- Parameters:
samples- an array of ints.yfrac- the Y subsample position, multiplied by 2(subsampleBitsV).- Returns:
- the interpolated value as an int.
- See Also:
-
interpolate
public int interpolate(int[][] samples, int xfrac, int yfrac) Performs interpolation on a two-dimensional array of integral samples. The central sample (samples[0][0]) is returned.- Overrides:
interpolatein classInterpolation- Parameters:
samples- a two-dimensional array of ints.xfrac- the X subsample position, multiplied by 2(subsampleBitsH).yfrac- the Y subsample position, multiplied by 2(subsampleBitsV).- Returns:
- the interpolated value as an int.
- See Also:
-
interpolateH
public int interpolateH(int s0, int s1, int xfrac) Performs horizontal interpolation on a pair of integral samples. The central sample (s0) is returned.- Overrides:
interpolateHin classInterpolation- Parameters:
s0- the central sample.s1- the sample to the right of the central sample.xfrac- the subsample position, ranging from zero to 2(subsampleBitsH) - 1.- Returns:
- the interpolated value as an int.
- See Also:
-
interpolateV
public int interpolateV(int s0, int s1, int yfrac) Performs vertical interpolation on a pair of integral samples. The central sample (s0) is returned.- Overrides:
interpolateVin classInterpolation- Parameters:
s0- the central sample.s1- the sample below the central sample.yfrac- the Y subsample position, multiplied by 2(subsampleBitsV).- Returns:
- the interpolated value as an int.
- See Also:
-
interpolate
public int interpolate(int s00, int s01, int s10, int s11, int xfrac, int yfrac) Performs interpolation on a 2x2 grid of integral samples. The central sample (s00) is returned.- Overrides:
interpolatein classInterpolation- Parameters:
s00- the central sample.s01- the sample to the right of the central sample.s10- the sample below the central sample.s11- the sample below and to the right of the central sample.xfrac- the X subsample position, multiplied by 2(subsampleBitsH).yfrac- the Y subsample position, multiplied by 2(subsampleBitsV).- Returns:
- the interpolated value as an int.
- See Also:
-
interpolate
public int interpolate(int s__, int s_0, int s_1, int s_2, int s0_, int s00, int s01, int s02, int s1_, int s10, int s11, int s12, int s2_, int s20, int s21, int s22, int xfrac, int yfrac) Performs interpolation on a 4x4 grid of integral samples. The central sample (s00) is returned.- Overrides:
interpolatein classInterpolation- Parameters:
s__- the sample above and to the left of the central sample.s_0- the sample above the central sample.s_1- the sample above and one to the right of the central sample.s_2- the sample above and two to the right of the central sample.s0_- the sample to the left of the central sample.s00- the central sample.s01- the sample to the right of the central sample.s02- the sample two to the right of the central sample.s1_- the sample below and one to the left of the central sample.s10- the sample below the central sample.s11- the sample below and one to the right of the central sample.s12- the sample below and two to the right of the central sample.s2_- the sample two below and one to the left of the central sample.s20- the sample two below the central sample.s21- the sample two below and one to the right of the central sample.s22- the sample two below and two to the right of the central sample.xfrac- the X subsample position, multiplied by 2(subsampleBitsH).yfrac- the Y subsample position, multiplied by 2(subsampleBitsV).- Returns:
- the interpolated value as an int.
- See Also:
-
interpolateH
public float interpolateH(float[] samples, float xfrac) Performs horizontal interpolation on a one-dimensional array of floating-point samples. The central sample (s0) is returned.- Specified by:
interpolateHin classInterpolation- Parameters:
samples- an array of floats.xfrac- the X subsample position, in the range [0.0F, 1.0F).- Returns:
- the interpolated value as a float.
-
interpolateV
public float interpolateV(float[] samples, float yfrac) Performs vertical interpolation on a one-dimensional array of floating-point samples. The central sample (s0) is returned.- Overrides:
interpolateVin classInterpolation- Parameters:
samples- an array of floats.yfrac- the Y subsample position, in the range [0.0F, 1.0F).- Returns:
- the interpolated value as a float.
-
interpolate
public float interpolate(float[][] samples, float xfrac, float yfrac) Performs interpolation on a two-dimensional array of floating-point samples. The central sample (samples[0][0]) is returned.- Overrides:
interpolatein classInterpolation- Parameters:
samples- an array of floats.xfrac- the X subsample position, in the range [0.0F, 1.0F).yfrac- the Y subsample position, in the range [0.0F, 1.0F).- Returns:
- the interpolated value as a float.
-
interpolateH
public float interpolateH(float s0, float s1, float xfrac) Performs horizontal interpolation on a pair of floating-point samples. The central sample (s0) is returned.- Overrides:
interpolateHin classInterpolation- Parameters:
s0- the central sample.s1- the sample to the right of the central sample.xfrac- the subsample position, in the range [0.0F, 1.0F).- Returns:
- the interpolated value as a float.
-
interpolateV
public float interpolateV(float s0, float s1, float yfrac) Performs vertical interpolation on a pair of floating-point samples. The central sample (s0) is returned.- Overrides:
interpolateVin classInterpolation- Parameters:
s0- the central sample.s1- the sample below the central sample.yfrac- the Y subsample position, in the range [0.0F, 1.0F).- Returns:
- the interpolated value as a float.
-
interpolate
public float interpolate(float s00, float s01, float s10, float s11, float xfrac, float yfrac) Performs interpolation on a 2x2 grid of floating-point samples. The central sample (s00) is returned.- Overrides:
interpolatein classInterpolation- Parameters:
s00- the central sample.s01- the sample to the right of the central sample.s10- the sample below the central sample.s11- the sample below and to the right of the central sample.xfrac- the X subsample position, in the range [0.0F, 1.0F).yfrac- the Y subsample position, in the range [0.0F, 1.0F).- Returns:
- the interpolated value as a float.
-
interpolate
public float interpolate(float s__, float s_0, float s_1, float s_2, float s0_, float s00, float s01, float s02, float s1_, float s10, float s11, float s12, float s2_, float s20, float s21, float s22, float xfrac, float yfrac) Performs interpolation on a 4x4 grid of floating-point samples. The central sample (s00) is returned.- Overrides:
interpolatein classInterpolation- Parameters:
s__- the sample above and to the left of the central sample.s_0- the sample above the central sample.s_1- the sample above and one to the right of the central sample.s_2- the sample above and two to the right of the central sample.s0_- the sample to the left of the central sample.s00- the central sample.s01- the sample to the right of the central sample.s02- the sample two to the right of the central sample.s1_- the sample below and one to the left of the central sample.s10- the sample below the central sample.s11- the sample below and one to the right of the central sample.s12- the sample below and two to the right of the central sample.s2_- the sample two below and one to the left of the central sample.s20- the sample two below the central sample.s21- the sample two below and one to the right of the central sample.s22- the sample two below and two to the right of the central sample.xfrac- the X subsample position, in the range [0.0F, 1.0F).yfrac- the Y subsample position, in the range [0.0F, 1.0F).- Returns:
- the interpolated value as a float.
-
interpolateH
public double interpolateH(double[] samples, float xfrac) Performs horizontal interpolation on a one-dimensional array of double samples. The central sample (s0) is returned.- Specified by:
interpolateHin classInterpolation- Parameters:
samples- an array of doubles.xfrac- the X subsample position, in the range [0.0F, 1.0F).- Returns:
- the interpolated value as a double.
-
interpolateV
public double interpolateV(double[] samples, float yfrac) Performs vertical interpolation on a one-dimensional array of double samples. The central sample (s0) is returned.- Overrides:
interpolateVin classInterpolation- Parameters:
samples- an array of doubles.yfrac- the Y subsample position, in the range [0.0F, 1.0F).- Returns:
- the interpolated value as a double.
-
interpolate
public double interpolate(double[][] samples, float xfrac, float yfrac) Performs interpolation on a two-dimensional array of double samples. The central sample (samples[0][0]) is returned.- Overrides:
interpolatein classInterpolation- Parameters:
samples- an array of doubles.xfrac- the X subsample position, in the range [0.0F, 1.0F).yfrac- the Y subsample position, in the range [0.0F, 1.0F).- Returns:
- the interpolated value as a double.
-
interpolateH
public double interpolateH(double s0, double s1, float xfrac) Performs horizontal interpolation on a pair of double samples. The central sample (s0) is returned.- Overrides:
interpolateHin classInterpolation- Parameters:
s0- the central sample.s1- the sample to the right of the central sample.xfrac- the subsample position, in the range [0.0F, 1.0F).- Returns:
- the interpolated value as a double.
-
interpolateV
public double interpolateV(double s0, double s1, float yfrac) Performs vertical interpolation on a pair of double samples. The central sample (s0) is returned.- Overrides:
interpolateVin classInterpolation- Parameters:
s0- the central sample.s1- the sample below the central sample.yfrac- the Y subsample position, in the range [0.0F, 1.0F).- Returns:
- the interpolated value as a double.
-
interpolate
public double interpolate(double s00, double s01, double s10, double s11, float xfrac, float yfrac) Performs interpolation on a 2x2 grid of double samples. The central sample (s00) is returned.- Overrides:
interpolatein classInterpolation- Parameters:
s00- the central sample.s01- the sample to the right of the central sample.s10- the sample below the central sample.s11- the sample below and to the right of the central sample.xfrac- the X subsample position, in the range [0.0F, 1.0F).yfrac- the Y subsample position, in the range [0.0F, 1.0F).- Returns:
- the interpolated value as a double.
-
interpolate
public double interpolate(double s__, double s_0, double s_1, double s_2, double s0_, double s00, double s01, double s02, double s1_, double s10, double s11, double s12, double s2_, double s20, double s21, double s22, float xfrac, float yfrac) Performs interpolation on a 4x4 grid of double samples. The central sample (s00) is returned.- Overrides:
interpolatein classInterpolation- Parameters:
s__- the sample above and to the left of the central sample.s_0- the sample above the central sample.s_1- the sample above and one to the right of the central sample.s_2- the sample above and two to the right of the central sample.s0_- the sample to the left of the central sample.s00- the central sample.s01- the sample to the right of the central sample.s02- the sample two to the right of the central sample.s1_- the sample below and one to the left of the central sample.s10- the sample below the central sample.s11- the sample below and one to the right of the central sample.s12- the sample below and two to the right of the central sample.s2_- the sample two below and one to the left of the central sample.s20- the sample two below the central sample.s21- the sample two below and one to the right of the central sample.s22- the sample two below and two to the right of the central sample.xfrac- the X subsample position, in the range [0.0F, 1.0F).yfrac- the Y subsample position, in the range [0.0F, 1.0F).- Returns:
- the interpolated value as a double.
-