comparison Meerwald/dct.c @ 3:acb6967ee76d

update to 0.5
author Peter Meerwald <pmeerw@cosy.sbg.ac.at>
date Tue, 14 Aug 2007 21:11:21 +0200
parents be303a3f5ea8
children f83ef905a63d
comparison
equal deleted inserted replaced
2:b92f06d9a967 3:acb6967ee76d
43 fprintf(stderr, "dct_NxN: %d not a power of 2\n", N); 43 fprintf(stderr, "dct_NxN: %d not a power of 2\n", N);
44 exit(1); 44 exit(1);
45 } 45 }
46 }while((1<<dct_NxN_log2N)<N); 46 }while((1<<dct_NxN_log2N)<N);
47 if (dct_NxN_costable) free(dct_NxN_costable); 47 if (dct_NxN_costable) free(dct_NxN_costable);
48 dct_NxN_costable = (double*) malloc(N * sizeof(double)); 48 dct_NxN_costable = malloc(N * sizeof(double));
49 #ifdef DEBUG 49 #ifdef DEBUG
50 if(!dct_NxN_costable){ 50 if(!dct_NxN_costable){
51 fprintf(stderr, "Unable to allocate C array\n"); 51 fprintf(stderr, "Unable to allocate C array\n");
52 exit(1); 52 exit(1);
53 } 53 }
76 free(dct_NxN_tmp); 76 free(dct_NxN_tmp);
77 77
78 N = width; 78 N = width;
79 M = height; 79 M = height;
80 80
81 dct_NxN_tmp = (double *) malloc(height * sizeof(double)); 81 dct_NxN_tmp = malloc(height * sizeof(double));
82 #ifdef DEBUG 82 #ifdef DEBUG
83 if (!dct_NxN_tmp) { 83 if (!dct_NxN_tmp) {
84 fprintf(stderr, "init_dct_NxN(): failed to allocate memory\n"); 84 fprintf(stderr, "init_dct_NxN(): failed to allocate memory\n");
85 exit(1); 85 exit(1);
86 } 86 }
244 int u,v; 244 int u,v;
245 double two_over_sqrtncolsnrows = 2.0/sqrt((double) N*M); 245 double two_over_sqrtncolsnrows = 2.0/sqrt((double) N*M);
246 246
247 for (u=0; u < N; u++) 247 for (u=0; u < N; u++)
248 for (v=0; v < M; v++) 248 for (v=0; v < M; v++)
249 dcts[u][v] = ((int) pixels[u][v]-128); 249 dcts[u][v] = ((int) pixels[u][v] - 128);
250 250
251 for (u=0; u<=M-1; u++){ 251 for (u=0; u<=M-1; u++){
252 fct_noscale(dcts[u]); 252 fct_noscale(dcts[u]);
253 } 253 }
254 for (v=0; v<=N-1; v++){ 254 for (v=0; v<=N-1; v++){
537 /* MatrixMultiply( temp, input, Ct ); */ 537 /* MatrixMultiply( temp, input, Ct ); */
538 for ( i = 0 ; i < NJPEG ; i++ ) { 538 for ( i = 0 ; i < NJPEG ; i++ ) {
539 for ( j = 0 ; j < NJPEG ; j++ ) { 539 for ( j = 0 ; j < NJPEG ; j++ ) {
540 temp[ i ][ j ] = 0.0; 540 temp[ i ][ j ] = 0.0;
541 for ( k = 0 ; k < NJPEG ; k++ ) 541 for ( k = 0 ; k < NJPEG ; k++ )
542 temp[ i ][ j ] += ( (int) input[ i ][ k ]) * 542 temp[ i ][ j ] += ( (int) input[ i ][ k ] - 128 ) *
543 Ct[ k ][ j ]; 543 Ct[ k ][ j ];
544 } 544 }
545 } 545 }
546 546
547 /* MatrixMultiply( output, C, temp ); */ 547 /* MatrixMultiply( output, C, temp ); */
591 for ( i = 0 ; i < NJPEG ; i++ ) { 591 for ( i = 0 ; i < NJPEG ; i++ ) {
592 for ( j = 0 ; j < NJPEG ; j++ ) { 592 for ( j = 0 ; j < NJPEG ; j++ ) {
593 temp1 = 0.0; 593 temp1 = 0.0;
594 for ( k = 0 ; k < NJPEG ; k++ ) 594 for ( k = 0 ; k < NJPEG ; k++ )
595 temp1 += Ct[ i ][ k ] * temp[ k ][ j ]; 595 temp1 += Ct[ i ][ k ] * temp[ k ][ j ];
596 temp1 += 128.0;
596 output[i][j] = PIXELRANGE(ROUND(temp1)); 597 output[i][j] = PIXELRANGE(ROUND(temp1));
597 } 598 }
598 } 599 }
599 } 600 }
600 601

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.