comparison Meerwald/dct.c @ 12:6f5fea21a43c

NxM DCT speedup
author Peter Meerwald <pmeerw@cosy.sbg.ac.at>
date Thu, 01 May 2008 19:12:21 +0200
parents f83ef905a63d
children bd669312f068
comparison
equal deleted inserted replaced
11:a5249f7d45f7 12:6f5fea21a43c
386 t += ((int) pixels[y][x] - 128); 386 t += ((int) pixels[y][x] - 128);
387 dcts[0][0] = cx0 * cy0 * t; 387 dcts[0][0] = cx0 * cy0 * t;
388 388
389 for (i = 1; i < N; i++) { 389 for (i = 1; i < N; i++) {
390 t = 0.0; 390 t = 0.0;
391 for (x = 0; x < N; x++) 391 for (x = 0; x < N; x++) {
392 for (y = 0; y < M; y++) 392 double s = 0.0;
393 t += ((int) pixels[y][x] - 128) * dct_NxM_costable_x[x][i]; 393 for (y = 0; y < M; y++) {
394 s += ((int) pixels[y][x] - 128);
395 }
396 t += s * dct_NxM_costable_x[x][i];
397 }
394 dcts[0][i] = cy0 * t; 398 dcts[0][i] = cy0 * t;
395 } 399 }
396 400
397 for (j = 1; j < M; j++) { 401 for (j = 1; j < M; j++) {
398 t = 0.0; 402 t = 0.0;
399 for (x = 0; x < N; x++) 403 for (y = 0; y < M; y++) {
400 for (y = 0; y < M; y++) 404 double s = 0.0;
401 t += ((int) pixels[y][x] - 128) * dct_NxM_costable_y[y][j]; 405 for (x = 0; x < N; x++) {
406 s += ((int) pixels[y][x] - 128);
407 }
408 t += s * dct_NxM_costable_y[y][j];
409 }
402 dcts[j][0] = cx0 * t; 410 dcts[j][0] = cx0 * t;
403 } 411 }
404 412
405 for (i = 1; i < N; i++) 413 for (i = 1; i < N; i++) {
406 for (j = 1; j < M; j++) { 414 for (j = 1; j < M; j++) {
407 t = 0.0; 415 t = 0.0;
408 for (x = 0; x < N; x++) 416 for (x = 0; x < N; x++) {
409 for (y = 0; y < M; y++) 417 double s = 0;
410 t += ((int) pixels[y][x] - 128) * dct_NxM_costable_x[x][i] * dct_NxM_costable_y[y][j]; 418 for (y = 0; y < M; y++) {
419 s += ((int) pixels[y][x] - 128) * dct_NxM_costable_y[y][j];
420 }
421 t += s * dct_NxM_costable_x[x][i];
422 }
411 dcts[j][i] = t; 423 dcts[j][i] = t;
412 } 424 }
425 }
413 } 426 }
414 427
415 void idct_NxM(double **dcts, gray **pixels) { 428 void idct_NxM(double **dcts, gray **pixels) {
416 int x, y; 429 int x, y;
417 int i, j; 430 int i, j;
428 t += cy0 * dcts[0][i] * dct_NxM_costable_x[x][i]; 441 t += cy0 * dcts[0][i] * dct_NxM_costable_x[x][i];
429 442
430 for (j = 1; j < M; j++) 443 for (j = 1; j < M; j++)
431 t += cx0 * dcts[j][0] * dct_NxM_costable_y[y][j]; 444 t += cx0 * dcts[j][0] * dct_NxM_costable_y[y][j];
432 445
433 for (i = 1; i < N; i++) 446 for (i = 1; i < N; i++) {
434 for (j = 1; j < M; j++) 447 double s = 0.0;
435 t += dcts[j][i] * dct_NxM_costable_x[x][i] * dct_NxM_costable_y[y][j]; 448 for (j = 1; j < M; j++) {
449 s += dcts[j][i] * dct_NxM_costable_y[y][j];
450 }
451 t += s * dct_NxM_costable_x[x][i];
452 }
436 453
437 pixels[y][x] = PIXELRANGE((int) (t + 128.5)); 454 pixels[y][x] = PIXELRANGE((int) (t + 128.5));
438 } 455 }
439 } 456 }
440 } 457 }

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