Originally committed as revision 18273 to svn://svn.ffmpeg.org/ffmpeg/trunk
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,121 @@ |
| 0 |
+/* |
|
| 1 |
+ * reference discrete cosine transform (double precision) |
|
| 2 |
+ * Copyright (C) 2009 Dylan Yudaken |
|
| 3 |
+ * |
|
| 4 |
+ * This file is part of FFmpeg. |
|
| 5 |
+ * |
|
| 6 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
| 7 |
+ * modify it under the terms of the GNU Lesser General Public |
|
| 8 |
+ * License as published by the Free Software Foundation; either |
|
| 9 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
| 10 |
+ * |
|
| 11 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
| 12 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 13 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 14 |
+ * Lesser General Public License for more details. |
|
| 15 |
+ * |
|
| 16 |
+ * You should have received a copy of the GNU Lesser General Public |
|
| 17 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
| 18 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
| 19 |
+ */ |
|
| 20 |
+ |
|
| 21 |
+/** |
|
| 22 |
+ * @file libavcodec/dctref.c |
|
| 23 |
+ * reference discrete cosine transform (double precision) |
|
| 24 |
+ * |
|
| 25 |
+ * @author Dylan Yudaken (dyudaken at gmail) |
|
| 26 |
+ * |
|
| 27 |
+ * @note This file could be optimized a lot, but is for |
|
| 28 |
+ * reference and so readability is better. |
|
| 29 |
+ */ |
|
| 30 |
+ |
|
| 31 |
+#include "libavutil/mathematics.h" |
|
| 32 |
+static double coefficients[8 * 8]; |
|
| 33 |
+ |
|
| 34 |
+/** |
|
| 35 |
+ * Initialize the double precision discrete cosine transform |
|
| 36 |
+ * functions fdct & idct. |
|
| 37 |
+ */ |
|
| 38 |
+av_cold void ff_ref_dct_init(void) |
|
| 39 |
+{
|
|
| 40 |
+ unsigned int i, j; |
|
| 41 |
+ |
|
| 42 |
+ for (j = 0; j < 8; ++j) {
|
|
| 43 |
+ coefficients[j] = sqrt(0.125); |
|
| 44 |
+ for (i = 8; i < 64; i += 8) {
|
|
| 45 |
+ coefficients[i + j] = 0.5 * cos(i * (j + 0.5) * M_PI / 64.0); |
|
| 46 |
+ } |
|
| 47 |
+ } |
|
| 48 |
+} |
|
| 49 |
+ |
|
| 50 |
+/** |
|
| 51 |
+ * Transform 8x8 block of data with a double precision forward DCT <br> |
|
| 52 |
+ * This is a reference implementation. |
|
| 53 |
+ * |
|
| 54 |
+ * @param block pointer to 8x8 block of data to transform |
|
| 55 |
+ */ |
|
| 56 |
+void ff_ref_fdct(short *block) |
|
| 57 |
+{
|
|
| 58 |
+ /* implement the equation: block = coefficients * block * coefficients' */ |
|
| 59 |
+ |
|
| 60 |
+ unsigned int i, j, k; |
|
| 61 |
+ double out[8 * 8]; |
|
| 62 |
+ |
|
| 63 |
+ /* out = coefficients * block */ |
|
| 64 |
+ for (i = 0; i < 64; i += 8) {
|
|
| 65 |
+ for (j = 0; j < 8; ++j) {
|
|
| 66 |
+ double tmp = 0; |
|
| 67 |
+ for (k = 0; k < 8; ++k) {
|
|
| 68 |
+ tmp += coefficients[i + k] * block[k * 8 + j]; |
|
| 69 |
+ } |
|
| 70 |
+ out[i + j] = tmp * 8; |
|
| 71 |
+ } |
|
| 72 |
+ } |
|
| 73 |
+ |
|
| 74 |
+ /* block = out * (coefficients') */ |
|
| 75 |
+ for (j = 0; j < 8; ++j) {
|
|
| 76 |
+ for (i = 0; i < 64; i += 8) {
|
|
| 77 |
+ double tmp = 0; |
|
| 78 |
+ for (k = 0; k < 8; ++k) {
|
|
| 79 |
+ tmp += out[i + k] * coefficients[j * 8 + k]; |
|
| 80 |
+ } |
|
| 81 |
+ block[i + j] = floor(tmp + 0.499999999999); |
|
| 82 |
+ } |
|
| 83 |
+ } |
|
| 84 |
+} |
|
| 85 |
+ |
|
| 86 |
+/** |
|
| 87 |
+ * Transform 8x8 block of data with a double precision inverse DCT <br> |
|
| 88 |
+ * This is a reference implementation. |
|
| 89 |
+ * |
|
| 90 |
+ * @param block pointer to 8x8 block of data to transform |
|
| 91 |
+ */ |
|
| 92 |
+void ff_ref_idct(short *block) |
|
| 93 |
+{
|
|
| 94 |
+ /* implement the equation: block = (coefficients') * block * coefficients */ |
|
| 95 |
+ |
|
| 96 |
+ unsigned int i, j, k; |
|
| 97 |
+ double out[8 * 8]; |
|
| 98 |
+ |
|
| 99 |
+ /* out = block * coefficients */ |
|
| 100 |
+ for (i = 0; i < 64; i += 8) {
|
|
| 101 |
+ for (j = 0; j < 8; ++j) {
|
|
| 102 |
+ double tmp = 0; |
|
| 103 |
+ for (k = 0; k < 8; ++k) {
|
|
| 104 |
+ tmp += block[i + k] * coefficients[k * 8 + j]; |
|
| 105 |
+ } |
|
| 106 |
+ out[i + j] = tmp; |
|
| 107 |
+ } |
|
| 108 |
+ } |
|
| 109 |
+ |
|
| 110 |
+ /* block = (coefficients') * out */ |
|
| 111 |
+ for (i = 0; i < 8; ++i) {
|
|
| 112 |
+ for (j = 0; j < 8; ++j) {
|
|
| 113 |
+ double tmp = 0; |
|
| 114 |
+ for (k = 0; k < 64; k += 8) {
|
|
| 115 |
+ tmp += coefficients[k + i] * out[k + j]; |
|
| 116 |
+ } |
|
| 117 |
+ block[i * 8 + j] = floor(tmp + 0.5); |
|
| 118 |
+ } |
|
| 119 |
+ } |
|
| 120 |
+} |