RGBDownsample implements Downsample { public double[] downSample(final Image image, final int height, final int width) { processImage(image); final double[] result = new double[height * width * 3]; final PixelGrabber grabber = new PixelGrabber(image, 0, 0, this.imageWidth, this.imageHeight, true); try { grabber.grabPixels(); } catch (final InterruptedException e) { throw new EncogError(e); } this.pixelMap = (int[]) grabber.getPixels(); this.ratioX = (double) (this.downSampleRight - this.downSampleLeft) / (double) width; this.ratioY = (double) (this.downSampleBottom - this.downSampleTop) / (double) height; int index = 0; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { downSampleRegion(x, y); result[index++] = this.currentRed; result[index++] = this.currentGreen; result[index++] = this.currentBlue; } } return result; }  double[] downSample(final Image image, final int height,
			final int width); void downSampleRegion(final int x, final int y); void findBounds(); int getCurrentBlue(); int getCurrentGreen(); int getCurrentRed(); int getDownSampleBottom(); int getDownSampleLeft(); int getDownSampleRight(); int getDownSampleTop(); int getImageHeight(); int getImageWidth(); int[] getPixelMap(); double getRatioX(); double getRatioY(); void processImage(final Image image); void setCurrentBlue(final int currentBlue); void setCurrentGreen(final int currentGreen); void setCurrentRed(final int currentRed); void setPixelMap(final int[] pixelMap);  }
@Test public void testSameSize() { Image image = new BufferedImage(320,200,BufferedImage.TYPE_INT_RGB); RGBDownsample ds = new RGBDownsample(); double[] d = ds.downSample(image, 320, 200); Assert.assertEquals(192000, d.length); }
@Test public void testDifferentSize() { Image image = new BufferedImage(320,200,BufferedImage.TYPE_INT_RGB); RGBDownsample ds = new RGBDownsample(); double[] d = ds.downSample(image, 160, 100); Assert.assertEquals(48000, d.length); }