package yi.iu.processor;

import java.awt.*;
import yi.iu.ui.DisplayFrame;

public abstract class BinaryProcessor extends yi.iu.processor.ImageProcessor
{
    public int[] getProcessedPseudoColor(int source[], Dimension d)
    {
        int[] result=new int[source.length];
        int w=d.width, h=d.height;
        int[] rst=getProcessed(source,d);
        int nw=d.width, nh=d.height;
        d.width=w; d.height=h;
        for (int i=0;i<w*h;i++) {
            int r= source[i]>>16&0xff;
            int g= source[i]>>8&0xff;
            int b= source[i]&0xff;
            r=(512+r)/3;
            g=(512+g)/3;
            b=(512+b)/3;
            result[i]= 255<<24|r<<16|g<<8|b;
        }
        int z=w/nw;
        for (int i=0;i<nh;i++)
            for (int j=0;j<nw;j++) {
                if (rst[i*nw+j]==0) continue;
                for (int m=0;m<z;m++)
                    for (int n=0;n<z;n++) {
                        int temp= source[(i*z+m)*w+j*z+n];
                        int r= temp>>16&0xff;
                        int g= temp>>8&0xff;
                        int b= temp&0xff;
                        //r=r/4; g=g/4; b=b/4;
                        r=b=g=0;
                        result[(i*z+m)*w+j*z+n]= 255<<24|r<<16|g<<8|b;
                    }
            }

        DisplayFrame f= new DisplayFrame(result, w, h);
        f.show();

        return rst;
    }
}