Split the two IDCTs into different files.
authorSteinar H. Gunderson <sesse@debian.org>
Tue, 20 Jan 2009 23:00:53 +0000 (00:00 +0100)
committerSteinar H. Gunderson <sesse@debian.org>
Tue, 20 Jan 2009 23:00:53 +0000 (00:00 +0100)
Makefile
idct.h
idct_float.c [moved from idct.c with 80% similarity]
idct_float.h [new file with mode: 0644]
idct_reference.c [new file with mode: 0644]
idct_reference.h [new file with mode: 0644]
idct_test.c

index c3e6ff7..3fc9768 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -20,7 +20,7 @@ BYTESOURCE_TEST_OBJS=bytesource.o choice.o unstuff.o bytesource_test.o
 bytesource_test: $(BYTESOURCE_TEST_OBJS)
        $(CC) $(LDFLAGS) -o $@ $(BYTESOURCE_TEST_OBJS)
 
-IDCT_TEST_OBJS=idct.o idct_test.o benchmark.o
+IDCT_TEST_OBJS=idct_float.o idct_reference.o idct_test.o benchmark.o
 idct_test: $(IDCT_TEST_OBJS)
        $(CC) $(LDFLAGS) -o $@ $(IDCT_TEST_OBJS)
 
diff --git a/idct.h b/idct.h
index 4a16ea0..944db0d 100644 (file)
--- a/idct.h
+++ b/idct.h
@@ -17,15 +17,4 @@ typedef void (idct_free_t)(void*);
 // userdata is the same as returned by the alloc function.
 typedef void (idct_func_t)(const int16_t*, const void*, uint8_t*);
 
-// Non-factorized reference version (section A.3.3 of the JPEG standard).
-void* idct_reference_alloc(const uint32_t* quant_table);
-void idct_reference_free(void* userdata);
-void idct_reference(const int16_t* input, const void* userdata, uint8_t* output);
-
-// Floating-point IDCT due to Arai, Agui and Nakajima (also known as AA&N).
-// See idct.c for more details.
-void* idct_float_alloc(const uint32_t* quant_table);
-void idct_float_free(void* userdata);
-void idct_float(const int16_t* input, const void* userdata, uint8_t* output);
-
 #endif /* !defined(_IDCT_H) */
similarity index 80%
rename from idct.c
rename to idct_float.c
index c71d599..c8bde1b 100644 (file)
--- a/idct.c
@@ -4,57 +4,6 @@
 
 #include "idct.h"
 
-void* idct_reference_alloc(const uint32_t* quant_table)
-{
-       uint32_t* qt_copy = (uint32_t*)malloc(DCTSIZE2 * sizeof(uint32_t));
-       // FIXME: check for NULL return
-
-       memcpy(qt_copy, quant_table, DCTSIZE2 * sizeof(uint32_t));
-
-       return qt_copy;
-}
-
-void idct_reference_free(void* userdata)
-{
-       free(userdata);
-}
-
-void idct_reference(const int16_t* input, const void* userdata, uint8_t* output)
-{
-       const uint32_t* quant_table = (const uint32_t*)userdata;
-       double temp[DCTSIZE2];
-
-       for (unsigned y = 0; y < 8; ++y) {
-               for (unsigned x = 0; x < 8; ++x) {
-                       double acc = 0.0;
-                       for (unsigned u = 0; u < 8; ++u) {
-                               for (unsigned v = 0; v < 8; ++v) {
-                                       double c_u = (u == 0) ? 1/sqrt(2.0) : 1.0;
-                                       double c_v = (v == 0) ? 1/sqrt(2.0) : 1.0;
-                                       acc += c_u * c_v
-                                               * input[u * DCTSIZE + v] * quant_table[u * DCTSIZE + v]
-                                               * cos((2 * x + 1) * v * M_PI / 16.0)
-                                               * cos((2 * y + 1) * u * M_PI / 16.0);
-                               }
-                       }
-                       temp[y * DCTSIZE + x] = 0.25 * acc;
-               }
-       }
-
-       for (unsigned y = 0; y < 8; ++y) {
-               for (unsigned x = 0; x < 8; ++x) {
-                       double val = temp[y * DCTSIZE + x];
-                       if (val < 0.0) {
-                               output[y * DCTSIZE + x] = 0;
-                       } else if (val >= 255.0) {
-                               output[y * DCTSIZE + x] = 255;
-                       } else {
-                               output[y * DCTSIZE + x] = (uint8_t)(val + 0.5);
-                       }
-               }
-       }
-}
-
 // AA&N (Arai, Agui and Nakajima) floating-point IDCT.
 // This IDCT is based on the same DCT that libjpeg uses -- in fact, exactly the
 // same figure from the same book ("JPEG: Still Image Data Compression Standard",
diff --git a/idct_float.h b/idct_float.h
new file mode 100644 (file)
index 0000000..a0b7c8d
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef _IDCT_FLOAT_H
+#define _IDCT_FLOAT_H
+
+#include "idct.h"
+
+// Floating-point IDCT due to Arai, Agui and Nakajima (also known as AA&N).
+// See idct.c for more details.
+void* idct_float_alloc(const uint32_t* quant_table);
+void idct_float_free(void* userdata);
+void idct_float(const int16_t* input, const void* userdata, uint8_t* output);
+
+#endif /* !defined(_IDCT_FLOAT_H) */
diff --git a/idct_reference.c b/idct_reference.c
new file mode 100644 (file)
index 0000000..e710de3
--- /dev/null
@@ -0,0 +1,56 @@
+#include <math.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "idct_reference.h"
+
+void* idct_reference_alloc(const uint32_t* quant_table)
+{
+       uint32_t* qt_copy = (uint32_t*)malloc(DCTSIZE2 * sizeof(uint32_t));
+       // FIXME: check for NULL return
+
+       memcpy(qt_copy, quant_table, DCTSIZE2 * sizeof(uint32_t));
+
+       return qt_copy;
+}
+
+void idct_reference_free(void* userdata)
+{
+       free(userdata);
+}
+
+void idct_reference(const int16_t* input, const void* userdata, uint8_t* output)
+{
+       const uint32_t* quant_table = (const uint32_t*)userdata;
+       double temp[DCTSIZE2];
+
+       for (unsigned y = 0; y < 8; ++y) {
+               for (unsigned x = 0; x < 8; ++x) {
+                       double acc = 0.0;
+                       for (unsigned u = 0; u < 8; ++u) {
+                               for (unsigned v = 0; v < 8; ++v) {
+                                       double c_u = (u == 0) ? 1/sqrt(2.0) : 1.0;
+                                       double c_v = (v == 0) ? 1/sqrt(2.0) : 1.0;
+                                       acc += c_u * c_v
+                                               * input[u * DCTSIZE + v] * quant_table[u * DCTSIZE + v]
+                                               * cos((2 * x + 1) * v * M_PI / 16.0)
+                                               * cos((2 * y + 1) * u * M_PI / 16.0);
+                               }
+                       }
+                       temp[y * DCTSIZE + x] = 0.25 * acc;
+               }
+       }
+
+       for (unsigned y = 0; y < 8; ++y) {
+               for (unsigned x = 0; x < 8; ++x) {
+                       double val = temp[y * DCTSIZE + x];
+                       if (val < 0.0) {
+                               output[y * DCTSIZE + x] = 0;
+                       } else if (val >= 255.0) {
+                               output[y * DCTSIZE + x] = 255;
+                       } else {
+                               output[y * DCTSIZE + x] = (uint8_t)(val + 0.5);
+                       }
+               }
+       }
+}
diff --git a/idct_reference.h b/idct_reference.h
new file mode 100644 (file)
index 0000000..ca4d015
--- /dev/null
@@ -0,0 +1,11 @@
+#ifndef _IDCT_REFERENCE_H
+#define _IDCT_REFERENCE_H
+
+#include "idct.h"
+
+// Non-factorized reference version (section A.3.3 of the JPEG standard).
+void* idct_reference_alloc(const uint32_t* quant_table);
+void idct_reference_free(void* userdata);
+void idct_reference(const int16_t* input, const void* userdata, uint8_t* output);
+
+#endif /* !defined(_IDCT_REFERENCE_H) */
index 78374f8..dd15270 100644 (file)
@@ -6,6 +6,8 @@
 
 #include "benchmark.h"
 #include "idct.h"
+#include "idct_reference.h"
+#include "idct_float.h"
 
 // Generate random coefficients in the range [-15..15].
 void gen_random_coeffs(int16_t* dst, size_t len)