/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.mapawarenesstest;

import java.awt.Image;
import java.awt.image.PixelGrabber;
import org.encog.EncogError;
import org.encog.util.downsample.RGBDownsample;

/**
 *
 * @author Michal
 */
public class RBDownsample extends RGBDownsample {

    @Override
    public double[] downSample(Image image, int height, int width) {
        processImage(image);
		final double[] result = new double[height * width * 2];

		final PixelGrabber grabber = new PixelGrabber(image, 0, 0,
				this.getImageWidth(), this.getImageHeight(), true);

		try {
			grabber.grabPixels();
		} catch (final InterruptedException e) {
			throw new EncogError(e);
		}

		this.setPixelMap((int[]) grabber.getPixels());

		// now downsample


		int index = 0;
		for (int y = 0; y < height; y++) {
			for (int x = 0; x < width; x++) {
				downSampleRegion(x, y);
				result[index++] = this.getCurrentRed();
				result[index++] = this.getCurrentBlue();
			}
		}

		return result;
    }
    
}
