package yi.iu.processor.resample;

import java.awt.*;

/**
 * Resample the image only use the clo
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2002</p>
 * <p>Company: </p>
 * @author unascribed
 * @version 1.0
 */
public class SimpleResampler extends Resampler{

    public SimpleResampler () {
        super();
    }

    public SimpleResampler(int w, int h) {
        super(w,h);
    }

    /**
     * Dumb method (useless for SimpleResampler)
     * @param value
     * @return
     */
    public double filter(double value)
    {
      return 0;
    }

    public int[] getProcessed(int source[], Dimension d)
    {
      int[] rst = new int[dstHeight * dstWidth];

      double w_scale = (double)(d.width - 1) / (dstWidth - 1);
      double h_scale = (double)(d.height - 1) / (dstHeight - 1);

      int count = 0;
      for (int h = 0; h < dstHeight; h++) {
        for (int w = 0; w < dstWidth; w++) {
          int from_w = (int)Math.round(w * w_scale);
          int from_h = (int)Math.round(h * h_scale);
          rst[count ++] = source[from_h * d.width + from_w];
        }
      }
      return rst;
    }

    public double[] getProcessed(double source[], Dimension d)
    {
      double[] rst = new double[dstHeight * dstWidth];

      double w_scale = (double)(d.width - 1) / (dstWidth - 1);
      double h_scale = (double)(d.height - 1) / (dstHeight - 1);

      int count = 0;
      for (int h = 0; h < dstHeight; h++) {
        for (int w = 0; w < dstWidth; w++) {
          int from_w = (int)Math.round(w * w_scale);
          int from_h = (int)Math.round(h * h_scale);
          rst[count ++] = source[from_h * d.width + from_w];
        }
      }
      return rst;
    }
}