changeset 12:6f5fea21a43c

NxM DCT speedup
author Peter Meerwald <pmeerw@cosy.sbg.ac.at>
date Thu, 01 May 2008 19:12:21 +0200
parents a5249f7d45f7
children cbecc570129d
files Meerwald/dct.c
diffstat 1 files changed, 31 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/Meerwald/dct.c	Thu May 01 18:19:13 2008 +0200
+++ b/Meerwald/dct.c	Thu May 01 19:12:21 2008 +0200
@@ -388,28 +388,41 @@
 
   for (i = 1; i < N; i++) {
     t = 0.0;
-    for (x = 0; x < N; x++)
-      for (y = 0; y < M; y++)
-        t += ((int) pixels[y][x] - 128) * dct_NxM_costable_x[x][i];
+    for (x = 0; x < N; x++) {
+      double s = 0.0;
+      for (y = 0; y < M; y++) {
+        s += ((int) pixels[y][x] - 128);
+      }
+      t += s * dct_NxM_costable_x[x][i];
+    }
     dcts[0][i] = cy0 * t;
   }
 
   for (j = 1; j < M; j++) {
     t = 0.0;
-    for (x = 0; x < N; x++)
-      for (y = 0; y < M; y++)
-        t += ((int) pixels[y][x] - 128) * dct_NxM_costable_y[y][j];
+    for (y = 0; y < M; y++) {
+      double s = 0.0;
+      for (x = 0; x < N; x++) {
+        s += ((int) pixels[y][x] - 128);
+      }
+      t += s * dct_NxM_costable_y[y][j];
+    }
     dcts[j][0] = cx0 * t;
   }
 
-  for (i = 1; i < N; i++)
-    for (j = 1; j < M; j++) {
+  for (i = 1; i < N; i++) {
+     for (j = 1; j < M; j++) {
       t = 0.0;
-      for (x = 0; x < N; x++)
-        for (y = 0; y < M; y++)
-          t += ((int) pixels[y][x] - 128) * dct_NxM_costable_x[x][i] * dct_NxM_costable_y[y][j];
+      for (x = 0; x < N; x++) {
+        double s = 0;
+        for (y = 0; y < M; y++) {
+          s += ((int) pixels[y][x] - 128) * dct_NxM_costable_y[y][j];
+        }
+        t += s * dct_NxM_costable_x[x][i];
+      }
       dcts[j][i] = t;
     }
+  }
 }
 
 void idct_NxM(double **dcts, gray **pixels) {
@@ -430,9 +443,13 @@
       for (j = 1; j < M; j++)
         t += cx0 * dcts[j][0] * dct_NxM_costable_y[y][j];
 
-      for (i = 1; i < N; i++)
-        for (j = 1; j < M; j++)
-          t += dcts[j][i] * dct_NxM_costable_x[x][i] * dct_NxM_costable_y[y][j];
+      for (i = 1; i < N; i++) {
+        double s = 0.0;
+        for (j = 1; j < M; j++) {
+          s += dcts[j][i] * dct_NxM_costable_y[y][j];
+        }
+        t += s * dct_NxM_costable_x[x][i];
+      }
 
       pixels[y][x] = PIXELRANGE((int) (t + 128.5));
     }

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