

/**
 *
 * @author  jwr
 */

public class Jpeg2000Data{
    
    public boolean [] BP7;
    public int noOfBanks;
    public byte[][] qData;
    public int w;
    public int h;

    public Jpeg2000Data(byte [][] data, int nB){
            qData=data;
            w=data.length;
            h=data[0].length;
            noOfBanks=nB;
    }
    public Jpeg2000Data( int nB){
            noOfBanks=nB;
    }



public boolean[][] getBP(byte [][] data, int BPno){
    boolean [] []bp=null;
    int mask=255;
    switch(BPno){
            case 0: mask=0x1;
            case 1: mask=0x2;
            case 2: mask=0x4;
            case 3: mask=0x8;
            case 4: mask=16;
            case 5: mask=32;
            case 6: mask=64;
            case 7: mask=128;
    }
    for(int i=0; i<w;i++){
            for(int j=0;j<h;j++){
            if((qData[i][j]&mask)!=0)
                    bp[i][j]=true;
            else	
                    bp[i][j]=false;

            }
    }
    return bp;
}//end of boolean[][] getBP(byte [][] data, int BPno){

public byte [][]getBanksData(int noBanks){
    if(noBanks>noOfBanks){
    System.out.println("Not enough data");
    return null;
    }
    int sizeW;
    int sizeH;

    if(noBanks==noOfBanks){
     sizeW=w;
     sizeH=h;
    } else{
    sizeW=w/((noOfBanks-noBanks)*2); sizeH=h/((noOfBanks-noBanks)*2);

    }

    byte [][] rData=new byte[sizeW][sizeH];
    for(int i=0; i<sizeW;i++){
            for(int j=0;j<sizeH;j++){
            rData[i][j]=qData[i][j];
            }
    }
    return rData;

}//end of Public getBanksData()

/*
 quarterNo= 1 [gorny, prawy]=2 [dolny, lewy], =3[dolny, prawy]
*/
public byte[][] getAddBanksData(int noBanks, int quarterNo){
    if(noBanks>noOfBanks){
    System.out.println("Not enough data");
    return null;
    }
    int sizeW;
    int sizeH;
    int dif=(noOfBanks-noBanks);
    if(dif==0){
     sizeW=w/2;
     sizeH=h/2;
    } else{
     sizeW=(int)(w*Math.pow(0.5,dif+1));
     sizeH=(int)(h*Math.pow(0.5,dif+1));
    }
    //w*Math.pow(0.5,dif+1);

    byte [][] rData=new byte[sizeW][sizeH];
    for(int i=0; i<sizeW;i++){
            for(int j=0;j<sizeH;j++){
                switch(quarterNo){
                    case 1: 
                            rData[i][j]=qData[i+sizeW][j];
                            break;
                    case 2: 
                            rData[i][j]=qData[i][j+sizeH];

                            break;
                    case 3: 
                            rData[i][j]=qData[i+sizeW][j+sizeH];

                            break;

                }//end of switch
            }//end of for j
    }//end of for i
    return rData;



}//end of Public byte[][] getAddBanksData()


public static double [][] getBank(double [][] data, int bankNo){
    if (bankNo==0) return null;
    int bankH=data.length/(int)Math.pow(2.0,(double)bankNo);  //(bankNo*2);
    int bankW=data[0].length/(int)Math.pow(2.0,(double)bankNo); //(bankNo*2);
    double [][] bankData = new double[bankH][bankW];
    for(int i=0; i<bankH; i++){
        for(int j=0; j<bankW; j++){
            bankData[i][j]=data[i][j];
        }
    }
    return bankData;
}

public static double [][] setBank(double [][] fullData, double [][] bankData){
    //if (bankNo==0) return null;
    int bankH=bankData.length;
    int bankW=bankData[0].length;
    int dataH=fullData.length;
    int dataW=fullData[0].length;
    for(int i=0; i<bankH; i++){
        for(int j=0; j<bankW; j++){
            fullData[i][j]=bankData[i][j];
        }
    }
    return fullData;
    
}


}//end of class Jpeg2000Data

