public void fwdDctNxM(int[][] pixels,double[][] dcts){
  int x=0;
  int y=0;
  int i=0;
  int j=0;
  double t=0.0;
  double cx0=Math.sqrt(1.0 / this.N);
  double cy0=Math.sqrt(1.0 / this.M);
  for (x=0; x < this.N; x++) {
    for (y=0; y < this.M; y++) {
      t+=(pixels[x][y] - 128);
    }
  }
  dcts[0][0]=cx0 * cy0 * t;
  for (i=1; i < this.N; i++) {
    t=0.0;
    for (x=0; x < this.N; x++) {
      for (y=0; y < this.M; y++) {
        t+=(pixels[x][y] - 128) * this.nxmCosTableX[x][i];
      }
    }
    dcts[i][0]=cy0 * t;
  }
  for (j=1; j < this.M; j++) {
    t=0.0;
    for (x=0; x < this.N; x++) {
      for (y=0; y < this.M; y++) {
        t+=(pixels[x][y] - 128) * this.nxmCosTableY[y][j];
      }
    }
    dcts[0][j]=cx0 * t;
  }
  for (i=1; i < this.N; i++) {
    for (j=1; j < this.M; j++) {
      t=0.0;
      for (x=0; x < this.N; x++) {
        for (y=0; y < this.M; y++) {
          t+=(pixels[x][y] - 128) * this.nxmCosTableX[x][i] * this.nxmCosTableY[y][j];
        }
      }
      dcts[i][j]=t;
    }
  }
}

public void fwdDctNxM ( int [ ] [ ] pixels , double [ ] [ ] dcts ) { int x = 0 ; int y = 0 ; int i = 0 ; int j = 0 ; double t = 0.0 ; double cx0 = Math . sqrt ( 1.0 / this . N ) ; double cy0 = Math . sqrt ( 1.0 / this . M ) ; for ( x = 0 ; x < this . N ; x ++ ) { for ( y = 0 ; y < this . M ; y ++ ) { t += ( pixels [ x ] [ y ] - 128 ) ; } } dcts [ 0 ] [ 0 ] = cx0 * cy0 * t ; for ( i = 1 ; i < this . N ; i ++ ) { t = 0.0 ; for ( x = 0 ; x < this . N ; x ++ ) { for ( y = 0 ; y < this . M ; y ++ ) { t += ( pixels [ x ] [ y ] - 128 ) * this . nxmCosTableX [ x ] [ i ] ; } } dcts [ i ] [ 0 ] = cy0 * t ; } for ( j = 1 ; j < this . M ; j ++ ) { t = 0.0 ; for ( x = 0 ; x < this . N ; x ++ ) { for ( y = 0 ; y < this . M ; y ++ ) { t += ( pixels [ x ] [ y ] - 128 ) * this . nxmCosTableY [ y ] [ j ] ; } } dcts [ 0 ] [ j ] = cx0 * t ; } for ( i = 1 ; i < this . N ; i ++ ) { for ( j = 1 ; j < this . M ; j ++ ) { t = 0.0 ; for ( x = 0 ; x < this . N ; x ++ ) { for ( y = 0 ; y < this . M ; y ++ ) { t += ( pixels [ x ] [ y ] - 128 ) * this . nxmCosTableX [ x ] [ i ] * this . nxmCosTableY [ y ] [ j ] ; } } dcts [ i ] [ j ] = t ; } } }
perform forward dct for n x m matrix
