package yi.iu.processor.texture;

import java.awt.*;
import yi.iu.LawsAttrs;
import yi.iu.ui.*;
import yi.util.io.*;
import yi.iu.processor.channel.*;

public class DiffMaker extends yi.iu.processor.channel.ChannelMaker
{

    public int[] getProcessedPseudoColor(int[] source, Dimension d)
    {
        int[][] diff=getProcessed_ex(source, d);
        int[] img=new int[diff.length];
        for (int i=0;i<img.length;i++) img[i]=Math.abs(diff[i][0])+Math.abs(diff[i][1]);
        yi.util.ImageUtil.makeImageFromGray(img);
        return img;
    }

    public int[] getProcessed(int source[], Dimension d)
    {
        return null;
    }

    //return format:
    //[index_of_pixel][index_of_attribute]
    //index_of_pixel: [0..image_size]
    //index_of_attribute: [0, 1]   0->diff_x, 1->diff_y
    public int[][] getProcessed_ex(int rgb[], Dimension d)
    {
        int w=d.width, h=d.height;
            int size=w*h;

            //int[] gray= (new CYMaker()).getProcessed(rgb, d);
            int[] gray= (new IntensityMaker()).getProcessed(rgb, d);

            int[][] rst= new int[size][2];
            int index=0;
            for (int y=0; y<h; y++) {
                    for (int x=0; x<w; x++) {
                        if (x>0) rst[index][0]=Math.abs(gray[index]-gray[index-1]);
                        else rst[index][0]=Math.abs(gray[index+1]-gray[index]);
                        if (y>0) rst[index][1]=Math.abs(gray[index]-gray[index-w]);
                        else rst[index][1]=Math.abs(gray[index+w]-gray[index]);
                        index++;
                    }
                }
                gray=null;
                System.gc();
                return rst;
    }
}