public void initDctNxM(int cols,int rows) throws IllegalArgumentException {
  if (cols <= 0 || rows <= 0) {
    throw new IllegalArgumentException("Dimensions out of range");
  }
  int i=0;
  int j=0;
  double cx=Math.sqrt(2.0 / cols);
  double cy=Math.sqrt(2.0 / rows);
  if (this.nxmCosTableX != null && this.N != cols) {
    this.nxmCosTableX=null;
  }
  if (this.nxmCosTableY != null && this.M != rows) {
    this.nxmCosTableY=null;
  }
  if (this.nxmCosTableX == null) {
    this.nxmCosTableX=new double[cols][cols];
  }
  if (this.nxmCosTableY == null) {
    this.nxmCosTableY=new double[rows][rows];
  }
  this.N=cols;
  this.M=rows;
  for (i=0; i < cols; i++) {
    for (j=0; j < cols; j++) {
      this.nxmCosTableX[i][j]=cx * Math.cos((Math.PI * ((2 * i + 1) * j)) / (2 * this.N));
    }
  }
  for (i=0; i < rows; i++) {
    for (j=0; j < rows; j++) {
      this.nxmCosTableY[i][j]=cy * Math.cos((Math.PI * ((2 * i + 1) * j)) / (2 * this.M));
    }
  }
}

public void initDctNxM ( int cols , int rows ) throws IllegalArgumentException { if ( cols <= 0 || rows <= 0 ) { throw new IllegalArgumentException ( "Dimensions out of range" ) ; } int i = 0 ; int j = 0 ; double cx = Math . sqrt ( 2.0 / cols ) ; double cy = Math . sqrt ( 2.0 / rows ) ; if ( this . nxmCosTableX != null && this . N != cols ) { this . nxmCosTableX = null ; } if ( this . nxmCosTableY != null && this . M != rows ) { this . nxmCosTableY = null ; } if ( this . nxmCosTableX == null ) { this . nxmCosTableX = new double [ cols ] [ cols ] ; } if ( this . nxmCosTableY == null ) { this . nxmCosTableY = new double [ rows ] [ rows ] ; } this . N = cols ; this . M = rows ; for ( i = 0 ; i < cols ; i ++ ) { for ( j = 0 ; j < cols ; j ++ ) { this . nxmCosTableX [ i ] [ j ] = cx * Math . cos ( ( Math . PI * ( ( 2 * i + 1 ) * j ) ) / ( 2 * this . N ) ) ; } } for ( i = 0 ; i < rows ; i ++ ) { for ( j = 0 ; j < rows ; j ++ ) { this . nxmCosTableY [ i ] [ j ] = cy * Math . cos ( ( Math . PI * ( ( 2 * i + 1 ) * j ) ) / ( 2 * this . M ) ) ; } } }
initialize dct mechanism for n x m matrix
