annotate dctref.c @ 12530:63edd10ad4bc libavcodec tip

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