package yi.iu.processor.symmetry;

import java.awt.*;
import java.util.Vector;
import yi.iu.processor.*;
import yi.iu.ui.DisplayFrame;
import yi.dp.*;

public abstract class SymmetryProcessor extends yi.iu.processor.ImageProcessor
{
    static double maximaSize=0.05;   // the size from which the local maxima be considered
    static double MAXIMATHRESHOLD=0.2;
    
    public int[] getProcessedPseudoColor(int source[], Dimension d)
    {
        /*
        int[] rst= getProcessed(source,d);
        int w=d.width, h=d.height;
        int num=0;
        for (int i=0;i<w;i++)  if (num<rst[i]) num=rst[i];
        for (int i=0;i<w;i++) {
            int temp= rst[i]*h/num;
            for (int j=0;j<j-temp;j++)
                result[j*w+i]=0xffffffff;
            for (int j=h-temp;j<h;j++)
                result[j*w+i]=0xff000000;
        }
            
        return rst;
        */
        int[] result= new int[source.length];
        // record the old data
        int w=d.width, h=d.height;
        for (int i=0;i<w*h;i++) result[i]=source[i];
        
        int[] rst= getProcessed(source,d);
        int nw=d.width, nh=d.height;
        d.width=w; d.height=h;
        // get the maximum
        int num=0;
        for (int i=0;i<nw;i++)  if (num<rst[i]) num=rst[i];
        for (int i=0;i<nw;i++) {
            int temp= rst[i]*(h)/num;
            for (int t=h-1; t>=h-temp;t--)
                for (int j=t*w+i*(w/nw);j<t*w+(i+1)*(w/nw);j++) {
                    int r=(result[j]>>16)&0xff;
                    int g=(result[j]>>8)&0xff;
                    int b=result[j]&0xff;
                    r= r/3;
                    g= g/3;
                    b= b/3;
                    result[j]=255<<24|r<<16|g<<8|b;
                }
            if (temp>0)
                for (int j=(h-temp)*w+i*(w/nw);j<(h-temp)*w+(i+1)*(w/nw);j++)
                    result[j]=0xffffffff;
        }
        
        int[] max= Histogram.getLocalMaxima(rst,maximaSize,MAXIMATHRESHOLD);
        for (int i=0;i<nw;i++) {
            if (max[i]==0) continue;
            for (int j=0;j<h;j++) {
                result[j*w+i*(w/nw)+1]= result[j*w+i*(w/nw)+2]= 0xffff0000;
            }
        }
        
        
        DisplayFrame f= new DisplayFrame("result", result, w, h);
        /*
        DisplayFrame f= new DisplayFrame(result, w, h);
        String st= getClass().getName();
        f.setTitle(st);
        Vector[] info= getInfo(source,d);
        if (info!=null) {
            f.setInfo(info,d.width,d.height);
            d.width=w; d.height=h;
        }
        f.show();
        */
        return result;
    }
    
    Vector[] getInfo(int[] source, Dimension d)
    {
        return null;
    }
}