Mercurial > libavcodec.hg
annotate snow.c @ 11913:80916e795581 libavcodec
Bump micro version, add changelog entry for DTS-ES extension decoding support
author | mstorsjo |
---|---|
date | Tue, 22 Jun 2010 09:22:21 +0000 |
parents | 8a4984c5cacc |
children | a5c32cb046eb |
rev | line source |
---|---|
2138 | 1 /* |
2 * Copyright (C) 2004 Michael Niedermayer <michaelni@gmx.at> | |
3 * | |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3920
diff
changeset
|
4 * This file is part of FFmpeg. |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3920
diff
changeset
|
5 * |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3920
diff
changeset
|
6 * FFmpeg is free software; you can redistribute it and/or |
2138 | 7 * modify it under the terms of the GNU Lesser General Public |
8 * License as published by the Free Software Foundation; either | |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3920
diff
changeset
|
9 * version 2.1 of the License, or (at your option) any later version. |
2138 | 10 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3920
diff
changeset
|
11 * FFmpeg is distributed in the hope that it will be useful, |
2138 | 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 | |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3920
diff
changeset
|
17 * License along with FFmpeg; if not, write to the Free Software |
3036
0b546eab515d
Update licensing information: The FSF changed postal address.
diego
parents:
3035
diff
changeset
|
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
2138 | 19 */ |
20 | |
11417 | 21 #include "libavutil/intmath.h" |
2138 | 22 #include "avcodec.h" |
23 #include "dsputil.h" | |
11485 | 24 #include "dwt.h" |
3198
6b9f0c4fbdbe
First part of a series of speed-enchancing patches.
gpoirier
parents:
3197
diff
changeset
|
25 #include "snow.h" |
2335 | 26 |
27 #include "rangecoder.h" | |
8627
d6bab465b82c
moves mid_pred() into mathops.h (with arch specific code split by directory)
aurel
parents:
8611
diff
changeset
|
28 #include "mathops.h" |
2138 | 29 |
30 #include "mpegvideo.h" | |
11373 | 31 #include "h263.h" |
2138 | 32 |
33 #undef NDEBUG | |
34 #include <assert.h> | |
35 | |
36 static const int8_t quant3[256]={ | |
37 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
38 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
39 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
40 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
41 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
42 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
43 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
44 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
45 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | |
46 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | |
47 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | |
48 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | |
49 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | |
50 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | |
51 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | |
52 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 0, | |
53 }; | |
54 static const int8_t quant3b[256]={ | |
55 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
56 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
57 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
58 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
59 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
60 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
61 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
62 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
63 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | |
64 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | |
65 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | |
66 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | |
67 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | |
68 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | |
69 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | |
70 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | |
71 }; | |
2596 | 72 static const int8_t quant3bA[256]={ |
73 0, 0, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, | |
74 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, | |
75 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, | |
76 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, | |
77 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, | |
78 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, | |
79 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, | |
80 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, | |
81 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, | |
82 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, | |
83 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, | |
84 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, | |
85 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, | |
86 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, | |
87 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, | |
88 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, | |
89 }; | |
2138 | 90 static const int8_t quant5[256]={ |
91 0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
92 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
93 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
94 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
95 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
96 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
97 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
98 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
99 -2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2, | |
100 -2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2, | |
101 -2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2, | |
102 -2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2, | |
103 -2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2, | |
104 -2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2, | |
105 -2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2, | |
106 -2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-1,-1,-1, | |
107 }; | |
108 static const int8_t quant7[256]={ | |
109 0, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
110 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
111 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, | |
112 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, | |
113 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, | |
114 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, | |
115 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, | |
116 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, | |
117 -3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3, | |
118 -3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3, | |
119 -3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3, | |
120 -3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3, | |
121 -3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3, | |
122 -3,-3,-3,-3,-3,-3,-3,-3,-3,-2,-2,-2,-2,-2,-2,-2, | |
123 -2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2, | |
124 -2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-1,-1, | |
125 }; | |
126 static const int8_t quant9[256]={ | |
127 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, | |
128 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, | |
129 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, | |
130 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, | |
131 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, | |
132 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, | |
133 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, | |
134 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, | |
135 -4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4, | |
136 -4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4, | |
137 -4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4, | |
138 -4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4, | |
139 -4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4, | |
140 -4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4, | |
141 -4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-3,-3,-3,-3, | |
142 -3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-2,-2,-2,-2,-1,-1, | |
143 }; | |
144 static const int8_t quant11[256]={ | |
145 0, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, | |
146 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, | |
147 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, | |
148 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, | |
149 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, | |
150 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, | |
151 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, | |
152 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, | |
153 -5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5, | |
154 -5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5, | |
155 -5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5, | |
156 -5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5, | |
157 -5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5, | |
158 -5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-4,-4, | |
159 -4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4, | |
160 -4,-4,-4,-4,-4,-3,-3,-3,-3,-3,-3,-3,-2,-2,-2,-1, | |
161 }; | |
162 static const int8_t quant13[256]={ | |
163 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, | |
164 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, | |
165 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, | |
166 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | |
167 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | |
168 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | |
169 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | |
170 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | |
171 -6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6, | |
172 -6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6, | |
173 -6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6, | |
174 -6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6, | |
175 -6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-5, | |
176 -5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5, | |
177 -5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5, | |
178 -4,-4,-4,-4,-4,-4,-4,-4,-4,-3,-3,-3,-3,-2,-2,-1, | |
179 }; | |
180 | |
181 #if 0 //64*cubic | |
182 static const uint8_t obmc32[1024]={ | |
5659
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
183 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
184 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
185 0, 0, 0, 4, 4, 4, 4, 8, 8, 12, 12, 12, 16, 16, 16, 16, 16, 16, 16, 16, 12, 12, 12, 8, 8, 4, 4, 4, 4, 0, 0, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
186 0, 0, 4, 4, 8, 8, 12, 16, 16, 20, 24, 24, 28, 28, 32, 32, 32, 32, 28, 28, 24, 24, 20, 16, 16, 12, 8, 8, 4, 4, 0, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
187 0, 0, 4, 8, 8, 12, 16, 24, 28, 32, 36, 40, 44, 48, 48, 48, 48, 48, 48, 44, 40, 36, 32, 28, 24, 16, 12, 8, 8, 4, 0, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
188 0, 4, 4, 8, 12, 20, 24, 32, 40, 44, 52, 56, 60, 64, 68, 72, 72, 68, 64, 60, 56, 52, 44, 40, 32, 24, 20, 12, 8, 4, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
189 0, 4, 4, 12, 16, 24, 32, 40, 52, 60, 68, 76, 80, 88, 88, 92, 92, 88, 88, 80, 76, 68, 60, 52, 40, 32, 24, 16, 12, 4, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
190 0, 4, 8, 16, 24, 32, 40, 52, 64, 76, 84, 92,100,108,112,116,116,112,108,100, 92, 84, 76, 64, 52, 40, 32, 24, 16, 8, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
191 0, 4, 8, 16, 28, 40, 52, 64, 76, 88,100,112,124,132,136,140,140,136,132,124,112,100, 88, 76, 64, 52, 40, 28, 16, 8, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
192 0, 4, 12, 20, 32, 44, 60, 76, 88,104,120,132,144,152,160,164,164,160,152,144,132,120,104, 88, 76, 60, 44, 32, 20, 12, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
193 0, 4, 12, 24, 36, 48, 68, 84,100,120,136,152,164,176,180,184,184,180,176,164,152,136,120,100, 84, 68, 48, 36, 24, 12, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
194 0, 4, 12, 24, 40, 56, 76, 92,112,132,152,168,180,192,204,208,208,204,192,180,168,152,132,112, 92, 76, 56, 40, 24, 12, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
195 0, 4, 16, 28, 44, 60, 80,100,124,144,164,180,196,208,220,224,224,220,208,196,180,164,144,124,100, 80, 60, 44, 28, 16, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
196 0, 8, 16, 28, 48, 64, 88,108,132,152,176,192,208,224,232,240,240,232,224,208,192,176,152,132,108, 88, 64, 48, 28, 16, 8, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
197 0, 4, 16, 32, 48, 68, 88,112,136,160,180,204,220,232,244,248,248,244,232,220,204,180,160,136,112, 88, 68, 48, 32, 16, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
198 1, 8, 16, 32, 48, 72, 92,116,140,164,184,208,224,240,248,255,255,248,240,224,208,184,164,140,116, 92, 72, 48, 32, 16, 8, 1, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
199 1, 8, 16, 32, 48, 72, 92,116,140,164,184,208,224,240,248,255,255,248,240,224,208,184,164,140,116, 92, 72, 48, 32, 16, 8, 1, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
200 0, 4, 16, 32, 48, 68, 88,112,136,160,180,204,220,232,244,248,248,244,232,220,204,180,160,136,112, 88, 68, 48, 32, 16, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
201 0, 8, 16, 28, 48, 64, 88,108,132,152,176,192,208,224,232,240,240,232,224,208,192,176,152,132,108, 88, 64, 48, 28, 16, 8, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
202 0, 4, 16, 28, 44, 60, 80,100,124,144,164,180,196,208,220,224,224,220,208,196,180,164,144,124,100, 80, 60, 44, 28, 16, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
203 0, 4, 12, 24, 40, 56, 76, 92,112,132,152,168,180,192,204,208,208,204,192,180,168,152,132,112, 92, 76, 56, 40, 24, 12, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
204 0, 4, 12, 24, 36, 48, 68, 84,100,120,136,152,164,176,180,184,184,180,176,164,152,136,120,100, 84, 68, 48, 36, 24, 12, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
205 0, 4, 12, 20, 32, 44, 60, 76, 88,104,120,132,144,152,160,164,164,160,152,144,132,120,104, 88, 76, 60, 44, 32, 20, 12, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
206 0, 4, 8, 16, 28, 40, 52, 64, 76, 88,100,112,124,132,136,140,140,136,132,124,112,100, 88, 76, 64, 52, 40, 28, 16, 8, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
207 0, 4, 8, 16, 24, 32, 40, 52, 64, 76, 84, 92,100,108,112,116,116,112,108,100, 92, 84, 76, 64, 52, 40, 32, 24, 16, 8, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
208 0, 4, 4, 12, 16, 24, 32, 40, 52, 60, 68, 76, 80, 88, 88, 92, 92, 88, 88, 80, 76, 68, 60, 52, 40, 32, 24, 16, 12, 4, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
209 0, 4, 4, 8, 12, 20, 24, 32, 40, 44, 52, 56, 60, 64, 68, 72, 72, 68, 64, 60, 56, 52, 44, 40, 32, 24, 20, 12, 8, 4, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
210 0, 0, 4, 8, 8, 12, 16, 24, 28, 32, 36, 40, 44, 48, 48, 48, 48, 48, 48, 44, 40, 36, 32, 28, 24, 16, 12, 8, 8, 4, 0, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
211 0, 0, 4, 4, 8, 8, 12, 16, 16, 20, 24, 24, 28, 28, 32, 32, 32, 32, 28, 28, 24, 24, 20, 16, 16, 12, 8, 8, 4, 4, 0, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
212 0, 0, 0, 4, 4, 4, 4, 8, 8, 12, 12, 12, 16, 16, 16, 16, 16, 16, 16, 16, 12, 12, 12, 8, 8, 4, 4, 4, 4, 0, 0, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
213 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
214 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
2138 | 215 //error:0.000022 |
216 }; | |
217 static const uint8_t obmc16[256]={ | |
5659
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
218 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
219 0, 4, 4, 8, 16, 20, 20, 24, 24, 20, 20, 16, 8, 4, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
220 0, 4, 16, 24, 36, 44, 52, 60, 60, 52, 44, 36, 24, 16, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
221 0, 8, 24, 44, 60, 80, 96,104,104, 96, 80, 60, 44, 24, 8, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
222 0, 16, 36, 60, 92,116,136,152,152,136,116, 92, 60, 36, 16, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
223 0, 20, 44, 80,116,152,180,196,196,180,152,116, 80, 44, 20, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
224 4, 20, 52, 96,136,180,212,228,228,212,180,136, 96, 52, 20, 4, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
225 4, 24, 60,104,152,196,228,248,248,228,196,152,104, 60, 24, 4, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
226 4, 24, 60,104,152,196,228,248,248,228,196,152,104, 60, 24, 4, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
227 4, 20, 52, 96,136,180,212,228,228,212,180,136, 96, 52, 20, 4, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
228 0, 20, 44, 80,116,152,180,196,196,180,152,116, 80, 44, 20, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
229 0, 16, 36, 60, 92,116,136,152,152,136,116, 92, 60, 36, 16, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
230 0, 8, 24, 44, 60, 80, 96,104,104, 96, 80, 60, 44, 24, 8, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
231 0, 4, 16, 24, 36, 44, 52, 60, 60, 52, 44, 36, 24, 16, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
232 0, 4, 4, 8, 16, 20, 20, 24, 24, 20, 20, 16, 8, 4, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
233 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, |
2138 | 234 //error:0.000033 |
235 }; | |
236 #elif 1 // 64*linear | |
237 static const uint8_t obmc32[1024]={ | |
3206 | 238 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, |
239 0, 4, 4, 4, 8, 8, 8, 12, 12, 16, 16, 16, 20, 20, 20, 24, 24, 20, 20, 20, 16, 16, 16, 12, 12, 8, 8, 8, 4, 4, 4, 0, | |
240 0, 4, 8, 8, 12, 12, 16, 20, 20, 24, 28, 28, 32, 32, 36, 40, 40, 36, 32, 32, 28, 28, 24, 20, 20, 16, 12, 12, 8, 8, 4, 0, | |
241 0, 4, 8, 12, 16, 20, 24, 28, 28, 32, 36, 40, 44, 48, 52, 56, 56, 52, 48, 44, 40, 36, 32, 28, 28, 24, 20, 16, 12, 8, 4, 0, | |
242 4, 8, 12, 16, 20, 24, 28, 32, 40, 44, 48, 52, 56, 60, 64, 68, 68, 64, 60, 56, 52, 48, 44, 40, 32, 28, 24, 20, 16, 12, 8, 4, | |
243 4, 8, 12, 20, 24, 32, 36, 40, 48, 52, 56, 64, 68, 76, 80, 84, 84, 80, 76, 68, 64, 56, 52, 48, 40, 36, 32, 24, 20, 12, 8, 4, | |
244 4, 8, 16, 24, 28, 36, 44, 48, 56, 60, 68, 76, 80, 88, 96,100,100, 96, 88, 80, 76, 68, 60, 56, 48, 44, 36, 28, 24, 16, 8, 4, | |
245 4, 12, 20, 28, 32, 40, 48, 56, 64, 72, 80, 88, 92,100,108,116,116,108,100, 92, 88, 80, 72, 64, 56, 48, 40, 32, 28, 20, 12, 4, | |
246 4, 12, 20, 28, 40, 48, 56, 64, 72, 80, 88, 96,108,116,124,132,132,124,116,108, 96, 88, 80, 72, 64, 56, 48, 40, 28, 20, 12, 4, | |
247 4, 16, 24, 32, 44, 52, 60, 72, 80, 92,100,108,120,128,136,148,148,136,128,120,108,100, 92, 80, 72, 60, 52, 44, 32, 24, 16, 4, | |
248 4, 16, 28, 36, 48, 56, 68, 80, 88,100,112,120,132,140,152,164,164,152,140,132,120,112,100, 88, 80, 68, 56, 48, 36, 28, 16, 4, | |
249 4, 16, 28, 40, 52, 64, 76, 88, 96,108,120,132,144,156,168,180,180,168,156,144,132,120,108, 96, 88, 76, 64, 52, 40, 28, 16, 4, | |
250 8, 20, 32, 44, 56, 68, 80, 92,108,120,132,144,156,168,180,192,192,180,168,156,144,132,120,108, 92, 80, 68, 56, 44, 32, 20, 8, | |
251 8, 20, 32, 48, 60, 76, 88,100,116,128,140,156,168,184,196,208,208,196,184,168,156,140,128,116,100, 88, 76, 60, 48, 32, 20, 8, | |
252 8, 20, 36, 52, 64, 80, 96,108,124,136,152,168,180,196,212,224,224,212,196,180,168,152,136,124,108, 96, 80, 64, 52, 36, 20, 8, | |
253 8, 24, 40, 56, 68, 84,100,116,132,148,164,180,192,208,224,240,240,224,208,192,180,164,148,132,116,100, 84, 68, 56, 40, 24, 8, | |
254 8, 24, 40, 56, 68, 84,100,116,132,148,164,180,192,208,224,240,240,224,208,192,180,164,148,132,116,100, 84, 68, 56, 40, 24, 8, | |
255 8, 20, 36, 52, 64, 80, 96,108,124,136,152,168,180,196,212,224,224,212,196,180,168,152,136,124,108, 96, 80, 64, 52, 36, 20, 8, | |
256 8, 20, 32, 48, 60, 76, 88,100,116,128,140,156,168,184,196,208,208,196,184,168,156,140,128,116,100, 88, 76, 60, 48, 32, 20, 8, | |
257 8, 20, 32, 44, 56, 68, 80, 92,108,120,132,144,156,168,180,192,192,180,168,156,144,132,120,108, 92, 80, 68, 56, 44, 32, 20, 8, | |
258 4, 16, 28, 40, 52, 64, 76, 88, 96,108,120,132,144,156,168,180,180,168,156,144,132,120,108, 96, 88, 76, 64, 52, 40, 28, 16, 4, | |
259 4, 16, 28, 36, 48, 56, 68, 80, 88,100,112,120,132,140,152,164,164,152,140,132,120,112,100, 88, 80, 68, 56, 48, 36, 28, 16, 4, | |
260 4, 16, 24, 32, 44, 52, 60, 72, 80, 92,100,108,120,128,136,148,148,136,128,120,108,100, 92, 80, 72, 60, 52, 44, 32, 24, 16, 4, | |
261 4, 12, 20, 28, 40, 48, 56, 64, 72, 80, 88, 96,108,116,124,132,132,124,116,108, 96, 88, 80, 72, 64, 56, 48, 40, 28, 20, 12, 4, | |
262 4, 12, 20, 28, 32, 40, 48, 56, 64, 72, 80, 88, 92,100,108,116,116,108,100, 92, 88, 80, 72, 64, 56, 48, 40, 32, 28, 20, 12, 4, | |
263 4, 8, 16, 24, 28, 36, 44, 48, 56, 60, 68, 76, 80, 88, 96,100,100, 96, 88, 80, 76, 68, 60, 56, 48, 44, 36, 28, 24, 16, 8, 4, | |
264 4, 8, 12, 20, 24, 32, 36, 40, 48, 52, 56, 64, 68, 76, 80, 84, 84, 80, 76, 68, 64, 56, 52, 48, 40, 36, 32, 24, 20, 12, 8, 4, | |
265 4, 8, 12, 16, 20, 24, 28, 32, 40, 44, 48, 52, 56, 60, 64, 68, 68, 64, 60, 56, 52, 48, 44, 40, 32, 28, 24, 20, 16, 12, 8, 4, | |
266 0, 4, 8, 12, 16, 20, 24, 28, 28, 32, 36, 40, 44, 48, 52, 56, 56, 52, 48, 44, 40, 36, 32, 28, 28, 24, 20, 16, 12, 8, 4, 0, | |
267 0, 4, 8, 8, 12, 12, 16, 20, 20, 24, 28, 28, 32, 32, 36, 40, 40, 36, 32, 32, 28, 28, 24, 20, 20, 16, 12, 12, 8, 8, 4, 0, | |
268 0, 4, 4, 4, 8, 8, 8, 12, 12, 16, 16, 16, 20, 20, 20, 24, 24, 20, 20, 20, 16, 16, 16, 12, 12, 8, 8, 8, 4, 4, 4, 0, | |
269 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, | |
2138 | 270 //error:0.000020 |
271 }; | |
272 static const uint8_t obmc16[256]={ | |
3206 | 273 0, 4, 4, 8, 8, 12, 12, 16, 16, 12, 12, 8, 8, 4, 4, 0, |
274 4, 8, 16, 20, 28, 32, 40, 44, 44, 40, 32, 28, 20, 16, 8, 4, | |
275 4, 16, 24, 36, 44, 56, 64, 76, 76, 64, 56, 44, 36, 24, 16, 4, | |
276 8, 20, 36, 48, 64, 76, 92,104,104, 92, 76, 64, 48, 36, 20, 8, | |
277 8, 28, 44, 64, 80,100,116,136,136,116,100, 80, 64, 44, 28, 8, | |
278 12, 32, 56, 76,100,120,144,164,164,144,120,100, 76, 56, 32, 12, | |
279 12, 40, 64, 92,116,144,168,196,196,168,144,116, 92, 64, 40, 12, | |
280 16, 44, 76,104,136,164,196,224,224,196,164,136,104, 76, 44, 16, | |
281 16, 44, 76,104,136,164,196,224,224,196,164,136,104, 76, 44, 16, | |
282 12, 40, 64, 92,116,144,168,196,196,168,144,116, 92, 64, 40, 12, | |
283 12, 32, 56, 76,100,120,144,164,164,144,120,100, 76, 56, 32, 12, | |
284 8, 28, 44, 64, 80,100,116,136,136,116,100, 80, 64, 44, 28, 8, | |
285 8, 20, 36, 48, 64, 76, 92,104,104, 92, 76, 64, 48, 36, 20, 8, | |
286 4, 16, 24, 36, 44, 56, 64, 76, 76, 64, 56, 44, 36, 24, 16, 4, | |
287 4, 8, 16, 20, 28, 32, 40, 44, 44, 40, 32, 28, 20, 16, 8, 4, | |
288 0, 4, 4, 8, 8, 12, 12, 16, 16, 12, 12, 8, 8, 4, 4, 0, | |
2138 | 289 //error:0.000015 |
290 }; | |
291 #else //64*cos | |
292 static const uint8_t obmc32[1024]={ | |
5659
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
293 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
294 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 8, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
295 0, 0, 0, 4, 4, 4, 4, 8, 8, 12, 12, 12, 12, 16, 16, 16, 16, 16, 16, 12, 12, 12, 12, 8, 8, 4, 4, 4, 4, 0, 0, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
296 0, 0, 4, 4, 4, 8, 8, 12, 16, 20, 20, 24, 28, 28, 28, 28, 28, 28, 28, 28, 24, 20, 20, 16, 12, 8, 8, 4, 4, 4, 0, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
297 0, 0, 4, 4, 8, 12, 16, 20, 24, 28, 36, 40, 44, 44, 48, 48, 48, 48, 44, 44, 40, 36, 28, 24, 20, 16, 12, 8, 4, 4, 0, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
298 0, 0, 4, 8, 12, 20, 24, 32, 36, 44, 48, 56, 60, 64, 68, 68, 68, 68, 64, 60, 56, 48, 44, 36, 32, 24, 20, 12, 8, 4, 0, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
299 0, 4, 4, 8, 16, 24, 32, 40, 48, 60, 68, 76, 80, 84, 88, 92, 92, 88, 84, 80, 76, 68, 60, 48, 40, 32, 24, 16, 8, 4, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
300 0, 4, 8, 12, 20, 32, 40, 52, 64, 76, 84, 96,104,108,112,116,116,112,108,104, 96, 84, 76, 64, 52, 40, 32, 20, 12, 8, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
301 0, 4, 8, 16, 24, 36, 48, 64, 76, 92,104,116,124,132,136,140,140,136,132,124,116,104, 92, 76, 64, 48, 36, 24, 16, 8, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
302 0, 4, 12, 20, 28, 44, 60, 76, 92,104,120,136,148,156,160,164,164,160,156,148,136,120,104, 92, 76, 60, 44, 28, 20, 12, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
303 0, 4, 12, 20, 36, 48, 68, 84,104,120,140,152,168,176,184,188,188,184,176,168,152,140,120,104, 84, 68, 48, 36, 20, 12, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
304 0, 4, 12, 24, 36, 56, 76, 96,116,136,152,172,184,196,204,208,208,204,196,184,172,152,136,116, 96, 76, 56, 36, 24, 12, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
305 0, 4, 12, 24, 44, 60, 80,104,124,148,168,184,200,212,224,228,228,224,212,200,184,168,148,124,104, 80, 60, 44, 24, 12, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
306 0, 4, 12, 28, 44, 64, 84,108,132,156,176,196,212,228,236,240,240,236,228,212,196,176,156,132,108, 84, 64, 44, 28, 12, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
307 0, 4, 16, 28, 48, 68, 88,112,136,160,184,204,224,236,244,252,252,244,236,224,204,184,160,136,112, 88, 68, 48, 28, 16, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
308 1, 4, 16, 28, 48, 68, 92,116,140,164,188,208,228,240,252,255,255,252,240,228,208,188,164,140,116, 92, 68, 48, 28, 16, 4, 1, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
309 1, 4, 16, 28, 48, 68, 92,116,140,164,188,208,228,240,252,255,255,252,240,228,208,188,164,140,116, 92, 68, 48, 28, 16, 4, 1, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
310 0, 4, 16, 28, 48, 68, 88,112,136,160,184,204,224,236,244,252,252,244,236,224,204,184,160,136,112, 88, 68, 48, 28, 16, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
311 0, 4, 12, 28, 44, 64, 84,108,132,156,176,196,212,228,236,240,240,236,228,212,196,176,156,132,108, 84, 64, 44, 28, 12, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
312 0, 4, 12, 24, 44, 60, 80,104,124,148,168,184,200,212,224,228,228,224,212,200,184,168,148,124,104, 80, 60, 44, 24, 12, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
313 0, 4, 12, 24, 36, 56, 76, 96,116,136,152,172,184,196,204,208,208,204,196,184,172,152,136,116, 96, 76, 56, 36, 24, 12, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
314 0, 4, 12, 20, 36, 48, 68, 84,104,120,140,152,168,176,184,188,188,184,176,168,152,140,120,104, 84, 68, 48, 36, 20, 12, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
315 0, 4, 12, 20, 28, 44, 60, 76, 92,104,120,136,148,156,160,164,164,160,156,148,136,120,104, 92, 76, 60, 44, 28, 20, 12, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
316 0, 4, 8, 16, 24, 36, 48, 64, 76, 92,104,116,124,132,136,140,140,136,132,124,116,104, 92, 76, 64, 48, 36, 24, 16, 8, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
317 0, 4, 8, 12, 20, 32, 40, 52, 64, 76, 84, 96,104,108,112,116,116,112,108,104, 96, 84, 76, 64, 52, 40, 32, 20, 12, 8, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
318 0, 4, 4, 8, 16, 24, 32, 40, 48, 60, 68, 76, 80, 84, 88, 92, 92, 88, 84, 80, 76, 68, 60, 48, 40, 32, 24, 16, 8, 4, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
319 0, 0, 4, 8, 12, 20, 24, 32, 36, 44, 48, 56, 60, 64, 68, 68, 68, 68, 64, 60, 56, 48, 44, 36, 32, 24, 20, 12, 8, 4, 0, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
320 0, 0, 4, 4, 8, 12, 16, 20, 24, 28, 36, 40, 44, 44, 48, 48, 48, 48, 44, 44, 40, 36, 28, 24, 20, 16, 12, 8, 4, 4, 0, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
321 0, 0, 4, 4, 4, 8, 8, 12, 16, 20, 20, 24, 28, 28, 28, 28, 28, 28, 28, 28, 24, 20, 20, 16, 12, 8, 8, 4, 4, 4, 0, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
322 0, 0, 0, 4, 4, 4, 4, 8, 8, 12, 12, 12, 12, 16, 16, 16, 16, 16, 16, 12, 12, 12, 12, 8, 8, 4, 4, 4, 4, 0, 0, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
323 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 8, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
324 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
2138 | 325 //error:0.000022 |
326 }; | |
327 static const uint8_t obmc16[256]={ | |
5659
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
328 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
329 0, 0, 4, 8, 12, 16, 20, 20, 20, 20, 16, 12, 8, 4, 0, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
330 0, 4, 12, 24, 32, 44, 52, 56, 56, 52, 44, 32, 24, 12, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
331 0, 8, 24, 40, 60, 80, 96,104,104, 96, 80, 60, 40, 24, 8, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
332 0, 12, 32, 64, 92,120,140,152,152,140,120, 92, 64, 32, 12, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
333 4, 16, 44, 80,120,156,184,196,196,184,156,120, 80, 44, 16, 4, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
334 4, 20, 52, 96,140,184,216,232,232,216,184,140, 96, 52, 20, 4, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
335 0, 20, 56,104,152,196,232,252,252,232,196,152,104, 56, 20, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
336 0, 20, 56,104,152,196,232,252,252,232,196,152,104, 56, 20, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
337 4, 20, 52, 96,140,184,216,232,232,216,184,140, 96, 52, 20, 4, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
338 4, 16, 44, 80,120,156,184,196,196,184,156,120, 80, 44, 16, 4, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
339 0, 12, 32, 64, 92,120,140,152,152,140,120, 92, 64, 32, 12, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
340 0, 8, 24, 40, 60, 80, 96,104,104, 96, 80, 60, 40, 24, 8, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
341 0, 4, 12, 24, 32, 44, 52, 56, 56, 52, 44, 32, 24, 12, 4, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
342 0, 0, 4, 8, 12, 16, 20, 20, 20, 20, 16, 12, 8, 4, 0, 0, |
ff44e77914ca
scaling obmc tables under #if 0 also by 4 (yes they where forgotten apparently)
michael
parents:
5652
diff
changeset
|
343 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, |
2138 | 344 //error:0.000022 |
345 }; | |
5910 | 346 #endif /* 0 */ |
2138 | 347 |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
348 //linear *64 |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
349 static const uint8_t obmc8[64]={ |
3206 | 350 4, 12, 20, 28, 28, 20, 12, 4, |
351 12, 36, 60, 84, 84, 60, 36, 12, | |
352 20, 60,100,140,140,100, 60, 20, | |
353 28, 84,140,196,196,140, 84, 28, | |
354 28, 84,140,196,196,140, 84, 28, | |
355 20, 60,100,140,140,100, 60, 20, | |
356 12, 36, 60, 84, 84, 60, 36, 12, | |
357 4, 12, 20, 28, 28, 20, 12, 4, | |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
358 //error:0.000000 |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
359 }; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
360 |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
361 //linear *64 |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
362 static const uint8_t obmc4[16]={ |
3206 | 363 16, 48, 48, 16, |
364 48,144,144, 48, | |
365 48,144,144, 48, | |
366 16, 48, 48, 16, | |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
367 //error:0.000000 |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
368 }; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
369 |
7129 | 370 static const uint8_t * const obmc_tab[4]={ |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
371 obmc32, obmc16, obmc8, obmc4 |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
372 }; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
373 |
3325
c2a017de6bea
Snow: scale predicted mv based on which reference frame the neighbors used.
lorenm
parents:
3324
diff
changeset
|
374 static int scale_mv_ref[MAX_REF_FRAMES][MAX_REF_FRAMES]; |
c2a017de6bea
Snow: scale predicted mv based on which reference frame the neighbors used.
lorenm
parents:
3324
diff
changeset
|
375 |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
376 typedef struct BlockNode{ |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
377 int16_t mx; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
378 int16_t my; |
3314 | 379 uint8_t ref; |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
380 uint8_t color[3]; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
381 uint8_t type; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
382 //#define TYPE_SPLIT 1 |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
383 #define BLOCK_INTRA 1 |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
384 #define BLOCK_OPT 2 |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
385 //#define TYPE_NOCOLOR 4 |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
386 uint8_t level; //FIXME merge into type? |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
387 }BlockNode; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
388 |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
389 static const BlockNode null_block= { //FIXME add border maybe |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
390 .color= {128,128,128}, |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
391 .mx= 0, |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
392 .my= 0, |
3314 | 393 .ref= 0, |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
394 .type= 0, |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
395 .level= 0, |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
396 }; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
397 |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
398 #define LOG2_MB_SIZE 4 |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
399 #define MB_SIZE (1<<LOG2_MB_SIZE) |
5575 | 400 #define ENCODER_EXTRA_BITS 4 |
5652
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
401 #define HTAPS_MAX 8 |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
402 |
2589
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
403 typedef struct x_and_coeff{ |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
404 int16_t x; |
2596 | 405 uint16_t coeff; |
2589
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
406 } x_and_coeff; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
407 |
2138 | 408 typedef struct SubBand{ |
409 int level; | |
410 int stride; | |
411 int width; | |
412 int height; | |
6412 | 413 int qlog; ///< log(qscale)/log[2^(1/6)] |
2138 | 414 DWTELEM *buf; |
5587
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
415 IDWTELEM *ibuf; |
2589
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
416 int buf_x_offset; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
417 int buf_y_offset; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
418 int stride_line; ///< Stride measured in lines, not pixels. |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
419 x_and_coeff * x_coeff; |
2138 | 420 struct SubBand *parent; |
421 uint8_t state[/*7*2*/ 7 + 512][32]; | |
422 }SubBand; | |
423 | |
424 typedef struct Plane{ | |
425 int width; | |
426 int height; | |
427 SubBand band[MAX_DECOMPOSITIONS][4]; | |
5651
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
428 |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
429 int htaps; |
5652
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
430 int8_t hcoeff[HTAPS_MAX/2]; |
5651
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
431 int diag_mc; |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
432 int fast_mc; |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
433 |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
434 int last_htaps; |
5652
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
435 int8_t last_hcoeff[HTAPS_MAX/2]; |
5651
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
436 int last_diag_mc; |
2138 | 437 }Plane; |
438 | |
439 typedef struct SnowContext{ | |
440 | |
441 AVCodecContext *avctx; | |
2335 | 442 RangeCoder c; |
2138 | 443 DSPContext dsp; |
11485 | 444 DWTContext dwt; |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
445 AVFrame new_picture; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
446 AVFrame input_picture; ///< new_picture with the internal linesizes |
2138 | 447 AVFrame current_picture; |
3314 | 448 AVFrame last_picture[MAX_REF_FRAMES]; |
5633
873ea64637d9
code to do halfpel interpolation per frame (unfinished and under ifdef but it
michael
parents:
5627
diff
changeset
|
449 uint8_t *halfpel_plane[MAX_REF_FRAMES][4][4]; |
2138 | 450 AVFrame mconly_picture; |
451 // uint8_t q_context[16]; | |
452 uint8_t header_state[32]; | |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
453 uint8_t block_state[128 + 32*128]; |
2138 | 454 int keyframe; |
2199 | 455 int always_reset; |
2138 | 456 int version; |
457 int spatial_decomposition_type; | |
4331
e571dfe677be
store a few values in the header as difference to the last
michael
parents:
4283
diff
changeset
|
458 int last_spatial_decomposition_type; |
2138 | 459 int temporal_decomposition_type; |
460 int spatial_decomposition_count; | |
5670
2f3431b34f0f
make changing spatial_decomposition_count per frame work
michael
parents:
5668
diff
changeset
|
461 int last_spatial_decomposition_count; |
2138 | 462 int temporal_decomposition_count; |
3314 | 463 int max_ref_frames; |
464 int ref_frames; | |
465 int16_t (*ref_mvs[MAX_REF_FRAMES])[2]; | |
466 uint32_t *ref_scores[MAX_REF_FRAMES]; | |
2138 | 467 DWTELEM *spatial_dwt_buffer; |
5587
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
468 IDWTELEM *spatial_idwt_buffer; |
2138 | 469 int colorspace_type; |
470 int chroma_h_shift; | |
471 int chroma_v_shift; | |
472 int spatial_scalability; | |
473 int qlog; | |
4331
e571dfe677be
store a few values in the header as difference to the last
michael
parents:
4283
diff
changeset
|
474 int last_qlog; |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
475 int lambda; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
476 int lambda2; |
3313 | 477 int pass1_rc; |
2138 | 478 int mv_scale; |
4331
e571dfe677be
store a few values in the header as difference to the last
michael
parents:
4283
diff
changeset
|
479 int last_mv_scale; |
2138 | 480 int qbias; |
4331
e571dfe677be
store a few values in the header as difference to the last
michael
parents:
4283
diff
changeset
|
481 int last_qbias; |
2138 | 482 #define QBIAS_SHIFT 3 |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
483 int b_width; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
484 int b_height; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
485 int block_max_depth; |
4331
e571dfe677be
store a few values in the header as difference to the last
michael
parents:
4283
diff
changeset
|
486 int last_block_max_depth; |
2138 | 487 Plane plane[MAX_PLANES]; |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
488 BlockNode *block; |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
489 #define ME_CACHE_SIZE 1024 |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
490 int me_cache[ME_CACHE_SIZE]; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
491 int me_cache_generation; |
2589
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
492 slice_buffer sb; |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
493 |
6412 | 494 MpegEncContext m; // needed for motion estimation, should not be used for anything else, the idea is to eventually make the motion estimation independent of MpegEncContext, so this will be removed then (FIXME/XXX) |
8214
c5276ad92ff8
snow: move scratch buffer from stack to malloced buffer in context
mru
parents:
7622
diff
changeset
|
495 |
c5276ad92ff8
snow: move scratch buffer from stack to malloced buffer in context
mru
parents:
7622
diff
changeset
|
496 uint8_t *scratchbuf; |
2138 | 497 }SnowContext; |
498 | |
2979 | 499 #ifdef __sgi |
2368
a7ac68734a91
fix for build on IRIX by (Michel Bardiaux {mbardiaux peaktime be})
michael
parents:
2335
diff
changeset
|
500 // Avoid a name clash on SGI IRIX |
2979 | 501 #undef qexp |
2368
a7ac68734a91
fix for build on IRIX by (Michel Bardiaux {mbardiaux peaktime be})
michael
parents:
2335
diff
changeset
|
502 #endif |
2246 | 503 #define QEXPSHIFT (7-FRAC_BITS+8) //FIXME try to change this to 0 |
2600 | 504 static uint8_t qexp[QROOT]; |
2138 | 505 |
2335 | 506 static inline void put_symbol(RangeCoder *c, uint8_t *state, int v, int is_signed){ |
2138 | 507 int i; |
508 | |
509 if(v){ | |
4001 | 510 const int a= FFABS(v); |
2138 | 511 const int e= av_log2(a); |
512 #if 1 | |
2967 | 513 const int el= FFMIN(e, 10); |
2335 | 514 put_rac(c, state+0, 0); |
2138 | 515 |
516 for(i=0; i<el; i++){ | |
2335 | 517 put_rac(c, state+1+i, 1); //1..10 |
2138 | 518 } |
519 for(; i<e; i++){ | |
2335 | 520 put_rac(c, state+1+9, 1); //1..10 |
2138 | 521 } |
2335 | 522 put_rac(c, state+1+FFMIN(i,9), 0); |
2138 | 523 |
524 for(i=e-1; i>=el; i--){ | |
2335 | 525 put_rac(c, state+22+9, (a>>i)&1); //22..31 |
2138 | 526 } |
527 for(; i>=0; i--){ | |
2335 | 528 put_rac(c, state+22+i, (a>>i)&1); //22..31 |
2138 | 529 } |
530 | |
531 if(is_signed) | |
2335 | 532 put_rac(c, state+11 + el, v < 0); //11..21 |
2138 | 533 #else |
2967 | 534 |
2335 | 535 put_rac(c, state+0, 0); |
2138 | 536 if(e<=9){ |
537 for(i=0; i<e; i++){ | |
2335 | 538 put_rac(c, state+1+i, 1); //1..10 |
2138 | 539 } |
2335 | 540 put_rac(c, state+1+i, 0); |
2138 | 541 |
542 for(i=e-1; i>=0; i--){ | |
2335 | 543 put_rac(c, state+22+i, (a>>i)&1); //22..31 |
2138 | 544 } |
545 | |
546 if(is_signed) | |
2335 | 547 put_rac(c, state+11 + e, v < 0); //11..21 |
2138 | 548 }else{ |
549 for(i=0; i<e; i++){ | |
2335 | 550 put_rac(c, state+1+FFMIN(i,9), 1); //1..10 |
2138 | 551 } |
9540 | 552 put_rac(c, state+1+9, 0); |
2138 | 553 |
554 for(i=e-1; i>=0; i--){ | |
2335 | 555 put_rac(c, state+22+FFMIN(i,9), (a>>i)&1); //22..31 |
2138 | 556 } |
557 | |
558 if(is_signed) | |
9540 | 559 put_rac(c, state+11 + 10, v < 0); //11..21 |
2138 | 560 } |
5910 | 561 #endif /* 1 */ |
2138 | 562 }else{ |
2335 | 563 put_rac(c, state+0, 1); |
2138 | 564 } |
565 } | |
566 | |
2335 | 567 static inline int get_symbol(RangeCoder *c, uint8_t *state, int is_signed){ |
568 if(get_rac(c, state+0)) | |
2138 | 569 return 0; |
570 else{ | |
2240
c46fed9b7575
simplify getsymbol patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2232
diff
changeset
|
571 int i, e, a; |
c46fed9b7575
simplify getsymbol patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2232
diff
changeset
|
572 e= 0; |
2335 | 573 while(get_rac(c, state+1 + FFMIN(e,9))){ //1..10 |
2240
c46fed9b7575
simplify getsymbol patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2232
diff
changeset
|
574 e++; |
2138 | 575 } |
576 | |
2240
c46fed9b7575
simplify getsymbol patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2232
diff
changeset
|
577 a= 1; |
c46fed9b7575
simplify getsymbol patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2232
diff
changeset
|
578 for(i=e-1; i>=0; i--){ |
2335 | 579 a += a + get_rac(c, state+22 + FFMIN(i,9)); //22..31 |
2240
c46fed9b7575
simplify getsymbol patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2232
diff
changeset
|
580 } |
c46fed9b7575
simplify getsymbol patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2232
diff
changeset
|
581 |
9546 | 582 e= -(is_signed && get_rac(c, state+11 + FFMIN(e,10))); //11..21 |
583 return (a^e)-e; | |
2138 | 584 } |
585 } | |
586 | |
2335 | 587 static inline void put_symbol2(RangeCoder *c, uint8_t *state, int v, int log2){ |
2155
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
588 int i; |
2159
7f42295c1517
improved magnitude coding, 0.2% lower bitrate (foreman@352x288 qscale 1 and 8)
michael
parents:
2156
diff
changeset
|
589 int r= log2>=0 ? 1<<log2 : 1; |
2155
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
590 |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
591 assert(v>=0); |
2159
7f42295c1517
improved magnitude coding, 0.2% lower bitrate (foreman@352x288 qscale 1 and 8)
michael
parents:
2156
diff
changeset
|
592 assert(log2>=-4); |
7f42295c1517
improved magnitude coding, 0.2% lower bitrate (foreman@352x288 qscale 1 and 8)
michael
parents:
2156
diff
changeset
|
593 |
7f42295c1517
improved magnitude coding, 0.2% lower bitrate (foreman@352x288 qscale 1 and 8)
michael
parents:
2156
diff
changeset
|
594 while(v >= r){ |
2335 | 595 put_rac(c, state+4+log2, 1); |
2159
7f42295c1517
improved magnitude coding, 0.2% lower bitrate (foreman@352x288 qscale 1 and 8)
michael
parents:
2156
diff
changeset
|
596 v -= r; |
2155
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
597 log2++; |
2159
7f42295c1517
improved magnitude coding, 0.2% lower bitrate (foreman@352x288 qscale 1 and 8)
michael
parents:
2156
diff
changeset
|
598 if(log2>0) r+=r; |
2155
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
599 } |
2335 | 600 put_rac(c, state+4+log2, 0); |
2967 | 601 |
2155
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
602 for(i=log2-1; i>=0; i--){ |
2335 | 603 put_rac(c, state+31-i, (v>>i)&1); |
2155
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
604 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
605 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
606 |
2335 | 607 static inline int get_symbol2(RangeCoder *c, uint8_t *state, int log2){ |
2155
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
608 int i; |
2159
7f42295c1517
improved magnitude coding, 0.2% lower bitrate (foreman@352x288 qscale 1 and 8)
michael
parents:
2156
diff
changeset
|
609 int r= log2>=0 ? 1<<log2 : 1; |
2155
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
610 int v=0; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
611 |
2159
7f42295c1517
improved magnitude coding, 0.2% lower bitrate (foreman@352x288 qscale 1 and 8)
michael
parents:
2156
diff
changeset
|
612 assert(log2>=-4); |
7f42295c1517
improved magnitude coding, 0.2% lower bitrate (foreman@352x288 qscale 1 and 8)
michael
parents:
2156
diff
changeset
|
613 |
2335 | 614 while(get_rac(c, state+4+log2)){ |
2159
7f42295c1517
improved magnitude coding, 0.2% lower bitrate (foreman@352x288 qscale 1 and 8)
michael
parents:
2156
diff
changeset
|
615 v+= r; |
2155
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
616 log2++; |
2159
7f42295c1517
improved magnitude coding, 0.2% lower bitrate (foreman@352x288 qscale 1 and 8)
michael
parents:
2156
diff
changeset
|
617 if(log2>0) r+=r; |
2155
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
618 } |
2967 | 619 |
2155
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
620 for(i=log2-1; i>=0; i--){ |
2335 | 621 v+= get_rac(c, state+31-i)<<i; |
2155
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
622 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
623 |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
624 return v; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
625 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
626 |
2589
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
627 static inline void unpack_coeffs(SnowContext *s, SubBand *b, SubBand * parent, int orientation){ |
2138 | 628 const int w= b->width; |
629 const int h= b->height; | |
630 int x,y; | |
2967 | 631 |
10815 | 632 int run, runs; |
633 x_and_coeff *xc= b->x_coeff; | |
634 x_and_coeff *prev_xc= NULL; | |
635 x_and_coeff *prev2_xc= xc; | |
636 x_and_coeff *parent_xc= parent ? parent->x_coeff : NULL; | |
637 x_and_coeff *prev_parent_xc= parent_xc; | |
638 | |
639 runs= get_symbol2(&s->c, b->state[30], 0); | |
640 if(runs-- > 0) run= get_symbol2(&s->c, b->state[1], 3); | |
641 else run= INT_MAX; | |
642 | |
643 for(y=0; y<h; y++){ | |
644 int v=0; | |
645 int lt=0, t=0, rt=0; | |
646 | |
647 if(y && prev_xc->x == 0){ | |
648 rt= prev_xc->coeff; | |
649 } | |
650 for(x=0; x<w; x++){ | |
651 int p=0; | |
652 const int l= v; | |
653 | |
654 lt= t; t= rt; | |
655 | |
656 if(y){ | |
657 if(prev_xc->x <= x) | |
658 prev_xc++; | |
659 if(prev_xc->x == x + 1) | |
660 rt= prev_xc->coeff; | |
661 else | |
662 rt=0; | |
2193 | 663 } |
10815 | 664 if(parent_xc){ |
665 if(x>>1 > parent_xc->x){ | |
666 parent_xc++; | |
2194 | 667 } |
10815 | 668 if(x>>1 == parent_xc->x){ |
669 p= parent_xc->coeff; | |
2138 | 670 } |
2192 | 671 } |
10815 | 672 if(/*ll|*/l|lt|t|rt|p){ |
673 int context= av_log2(/*FFABS(ll) + */3*(l>>1) + (lt>>1) + (t&~1) + (rt>>1) + (p>>1)); | |
674 | |
675 v=get_rac(&s->c, &b->state[0][context]); | |
676 if(v){ | |
677 v= 2*(get_symbol2(&s->c, b->state[context + 2], context-4) + 1); | |
678 v+=get_rac(&s->c, &b->state[0][16 + 1 + 3 + quant3bA[l&0xFF] + 3*quant3bA[t&0xFF]]); | |
679 | |
680 xc->x=x; | |
681 (xc++)->coeff= v; | |
682 } | |
683 }else{ | |
684 if(!run){ | |
685 if(runs-- > 0) run= get_symbol2(&s->c, b->state[1], 3); | |
686 else run= INT_MAX; | |
687 v= 2*(get_symbol2(&s->c, b->state[0 + 2], 0-4) + 1); | |
688 v+=get_rac(&s->c, &b->state[0][16 + 1 + 3]); | |
689 | |
690 xc->x=x; | |
691 (xc++)->coeff= v; | |
2192 | 692 }else{ |
10815 | 693 int max_run; |
694 run--; | |
695 v=0; | |
696 | |
697 if(y) max_run= FFMIN(run, prev_xc->x - x - 2); | |
698 else max_run= FFMIN(run, w-x-1); | |
699 if(parent_xc) | |
700 max_run= FFMIN(max_run, 2*parent_xc->x - x - 1); | |
701 x+= max_run; | |
702 run-= max_run; | |
2138 | 703 } |
704 } | |
705 } | |
2607
fde7b6fe2aaf
replace complicated pointer dereference + index stuff by pointers in unpack_coeffs()
michael
parents:
2606
diff
changeset
|
706 (xc++)->x= w+1; //end marker |
10815 | 707 prev_xc= prev2_xc; |
708 prev2_xc= xc; | |
709 | |
710 if(parent_xc){ | |
711 if(y&1){ | |
712 while(parent_xc->x != parent->width+1) | |
713 parent_xc++; | |
714 parent_xc++; | |
715 prev_parent_xc= parent_xc; | |
716 }else{ | |
717 parent_xc= prev_parent_xc; | |
718 } | |
719 } | |
720 } | |
721 | |
722 (xc++)->x= w+1; //end marker | |
2589
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
723 } |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
724 |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
725 static inline void decode_subband_slice_buffered(SnowContext *s, SubBand *b, slice_buffer * sb, int start_y, int h, int save_state[1]){ |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
726 const int w= b->width; |
2893 | 727 int y; |
4594 | 728 const int qlog= av_clip(s->qlog + b->qlog, 0, QROOT*16); |
2600 | 729 int qmul= qexp[qlog&(QROOT-1)]<<(qlog>>QSHIFT); |
2589
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
730 int qadd= (s->qbias*qmul)>>QBIAS_SHIFT; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
731 int new_index = 0; |
2967 | 732 |
5587
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
733 if(b->ibuf == s->spatial_idwt_buffer || s->qlog == LOSSLESS_QLOG){ |
2589
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
734 qadd= 0; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
735 qmul= 1<<QEXPSHIFT; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
736 } |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
737 |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
738 /* If we are on the second or later slice, restore our index. */ |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
739 if (start_y != 0) |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
740 new_index = save_state[0]; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
741 |
2967 | 742 |
2589
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
743 for(y=start_y; y<h; y++){ |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
744 int x = 0; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
745 int v; |
5587
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
746 IDWTELEM * line = slice_buffer_get_line(sb, y * b->stride_line + b->buf_y_offset) + b->buf_x_offset; |
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
747 memset(line, 0, b->width*sizeof(IDWTELEM)); |
2589
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
748 v = b->x_coeff[new_index].coeff; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
749 x = b->x_coeff[new_index++].x; |
6474
e6995f3fbf7f
cosmetics: Normalize {} placement after for, while, if.
diego
parents:
6437
diff
changeset
|
750 while(x < w){ |
2596 | 751 register int t= ( (v>>1)*qmul + qadd)>>QEXPSHIFT; |
752 register int u= -(v&1); | |
753 line[x] = (t^u) - u; | |
754 | |
2589
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
755 v = b->x_coeff[new_index].coeff; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
756 x = b->x_coeff[new_index++].x; |
2138 | 757 } |
2589
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
758 } |
2967 | 759 |
2589
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
760 /* Save our variables for the next slice. */ |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
761 save_state[0] = new_index; |
2967 | 762 |
2589
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
763 return; |
2138 | 764 } |
765 | |
4331
e571dfe677be
store a few values in the header as difference to the last
michael
parents:
4283
diff
changeset
|
766 static void reset_contexts(SnowContext *s){ //FIXME better initial contexts |
2138 | 767 int plane_index, level, orientation; |
768 | |
2199 | 769 for(plane_index=0; plane_index<3; plane_index++){ |
5665
834f359e7257
perform init after reading the values needed for init
michael
parents:
5664
diff
changeset
|
770 for(level=0; level<MAX_DECOMPOSITIONS; level++){ |
2138 | 771 for(orientation=level ? 1:0; orientation<4; orientation++){ |
2335 | 772 memset(s->plane[plane_index].band[level][orientation].state, MID_STATE, sizeof(s->plane[plane_index].band[level][orientation].state)); |
2138 | 773 } |
774 } | |
775 } | |
2335 | 776 memset(s->header_state, MID_STATE, sizeof(s->header_state)); |
777 memset(s->block_state, MID_STATE, sizeof(s->block_state)); | |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
778 } |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
779 |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
780 static int alloc_blocks(SnowContext *s){ |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
781 int w= -((-s->avctx->width )>>LOG2_MB_SIZE); |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
782 int h= -((-s->avctx->height)>>LOG2_MB_SIZE); |
2967 | 783 |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
784 s->b_width = w; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
785 s->b_height= h; |
2967 | 786 |
9370 | 787 av_free(s->block); |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
788 s->block= av_mallocz(w * h * sizeof(BlockNode) << (s->block_max_depth*2)); |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
789 return 0; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
790 } |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
791 |
2335 | 792 static inline void copy_rac_state(RangeCoder *d, RangeCoder *s){ |
793 uint8_t *bytestream= d->bytestream; | |
794 uint8_t *bytestream_start= d->bytestream_start; | |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
795 *d= *s; |
2335 | 796 d->bytestream= bytestream; |
797 d->bytestream_start= bytestream_start; | |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
798 } |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
799 |
3314 | 800 static inline void set_blocks(SnowContext *s, int level, int x, int y, int l, int cb, int cr, int mx, int my, int ref, int type){ |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
801 const int w= s->b_width << s->block_max_depth; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
802 const int rem_depth= s->block_max_depth - level; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
803 const int index= (x + y*w) << rem_depth; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
804 const int block_w= 1<<rem_depth; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
805 BlockNode block; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
806 int i,j; |
2967 | 807 |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
808 block.color[0]= l; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
809 block.color[1]= cb; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
810 block.color[2]= cr; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
811 block.mx= mx; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
812 block.my= my; |
3314 | 813 block.ref= ref; |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
814 block.type= type; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
815 block.level= level; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
816 |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
817 for(j=0; j<block_w; j++){ |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
818 for(i=0; i<block_w; i++){ |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
819 s->block[index + i + j*w]= block; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
820 } |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
821 } |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
822 } |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
823 |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
824 static inline void init_ref(MotionEstContext *c, uint8_t *src[3], uint8_t *ref[3], uint8_t *ref2[3], int x, int y, int ref_index){ |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
825 const int offset[3]= { |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
826 y*c-> stride + x, |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
827 ((y*c->uvstride + x)>>1), |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
828 ((y*c->uvstride + x)>>1), |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
829 }; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
830 int i; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
831 for(i=0; i<3; i++){ |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
832 c->src[0][i]= src [i]; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
833 c->ref[0][i]= ref [i] + offset[i]; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
834 } |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
835 assert(!ref_index); |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
836 } |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
837 |
3325
c2a017de6bea
Snow: scale predicted mv based on which reference frame the neighbors used.
lorenm
parents:
3324
diff
changeset
|
838 static inline void pred_mv(SnowContext *s, int *mx, int *my, int ref, |
4408
c3be13eac2d6
Bring down the number of snow.c warnings from 27 to 17 by using the const
takis
parents:
4407
diff
changeset
|
839 const BlockNode *left, const BlockNode *top, const BlockNode *tr){ |
3325
c2a017de6bea
Snow: scale predicted mv based on which reference frame the neighbors used.
lorenm
parents:
3324
diff
changeset
|
840 if(s->ref_frames == 1){ |
c2a017de6bea
Snow: scale predicted mv based on which reference frame the neighbors used.
lorenm
parents:
3324
diff
changeset
|
841 *mx = mid_pred(left->mx, top->mx, tr->mx); |
c2a017de6bea
Snow: scale predicted mv based on which reference frame the neighbors used.
lorenm
parents:
3324
diff
changeset
|
842 *my = mid_pred(left->my, top->my, tr->my); |
c2a017de6bea
Snow: scale predicted mv based on which reference frame the neighbors used.
lorenm
parents:
3324
diff
changeset
|
843 }else{ |
c2a017de6bea
Snow: scale predicted mv based on which reference frame the neighbors used.
lorenm
parents:
3324
diff
changeset
|
844 const int *scale = scale_mv_ref[ref]; |
4407
15688bdfe1b5
Brings down the number of snow.c warnings from 33 to 27 by putting parentheses
takis
parents:
4360
diff
changeset
|
845 *mx = mid_pred((left->mx * scale[left->ref] + 128) >>8, |
15688bdfe1b5
Brings down the number of snow.c warnings from 33 to 27 by putting parentheses
takis
parents:
4360
diff
changeset
|
846 (top ->mx * scale[top ->ref] + 128) >>8, |
15688bdfe1b5
Brings down the number of snow.c warnings from 33 to 27 by putting parentheses
takis
parents:
4360
diff
changeset
|
847 (tr ->mx * scale[tr ->ref] + 128) >>8); |
15688bdfe1b5
Brings down the number of snow.c warnings from 33 to 27 by putting parentheses
takis
parents:
4360
diff
changeset
|
848 *my = mid_pred((left->my * scale[left->ref] + 128) >>8, |
15688bdfe1b5
Brings down the number of snow.c warnings from 33 to 27 by putting parentheses
takis
parents:
4360
diff
changeset
|
849 (top ->my * scale[top ->ref] + 128) >>8, |
15688bdfe1b5
Brings down the number of snow.c warnings from 33 to 27 by putting parentheses
takis
parents:
4360
diff
changeset
|
850 (tr ->my * scale[tr ->ref] + 128) >>8); |
3325
c2a017de6bea
Snow: scale predicted mv based on which reference frame the neighbors used.
lorenm
parents:
3324
diff
changeset
|
851 } |
c2a017de6bea
Snow: scale predicted mv based on which reference frame the neighbors used.
lorenm
parents:
3324
diff
changeset
|
852 } |
c2a017de6bea
Snow: scale predicted mv based on which reference frame the neighbors used.
lorenm
parents:
3324
diff
changeset
|
853 |
4283
d6f83e2f8804
rename always_inline to av_always_inline and move to common.h
mru
parents:
4197
diff
changeset
|
854 static av_always_inline int same_block(BlockNode *a, BlockNode *b){ |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
855 if((a->type&BLOCK_INTRA) && (b->type&BLOCK_INTRA)){ |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
856 return !((a->color[0] - b->color[0]) | (a->color[1] - b->color[1]) | (a->color[2] - b->color[2])); |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
857 }else{ |
3314 | 858 return !((a->mx - b->mx) | (a->my - b->my) | (a->ref - b->ref) | ((a->type ^ b->type)&BLOCK_INTRA)); |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
859 } |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
860 } |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
861 |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
862 static void decode_q_branch(SnowContext *s, int level, int x, int y){ |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
863 const int w= s->b_width << s->block_max_depth; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
864 const int rem_depth= s->block_max_depth - level; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
865 const int index= (x + y*w) << rem_depth; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
866 int trx= (x+1)<<rem_depth; |
4408
c3be13eac2d6
Bring down the number of snow.c warnings from 27 to 17 by using the const
takis
parents:
4407
diff
changeset
|
867 const BlockNode *left = x ? &s->block[index-1] : &null_block; |
c3be13eac2d6
Bring down the number of snow.c warnings from 27 to 17 by using the const
takis
parents:
4407
diff
changeset
|
868 const BlockNode *top = y ? &s->block[index-w] : &null_block; |
c3be13eac2d6
Bring down the number of snow.c warnings from 27 to 17 by using the const
takis
parents:
4407
diff
changeset
|
869 const BlockNode *tl = y && x ? &s->block[index-w-1] : left; |
c3be13eac2d6
Bring down the number of snow.c warnings from 27 to 17 by using the const
takis
parents:
4407
diff
changeset
|
870 const BlockNode *tr = y && trx<w && ((x&1)==0 || level==0) ? &s->block[index-w+(1<<rem_depth)] : tl; //FIXME use lt |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
871 int s_context= 2*left->level + 2*top->level + tl->level + tr->level; |
2967 | 872 |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
873 if(s->keyframe){ |
3314 | 874 set_blocks(s, level, x, y, null_block.color[0], null_block.color[1], null_block.color[2], null_block.mx, null_block.my, null_block.ref, BLOCK_INTRA); |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
875 return; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
876 } |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
877 |
2335 | 878 if(level==s->block_max_depth || get_rac(&s->c, &s->block_state[4 + s_context])){ |
4332 | 879 int type, mx, my; |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
880 int l = left->color[0]; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
881 int cb= left->color[1]; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
882 int cr= left->color[2]; |
3314 | 883 int ref = 0; |
884 int ref_context= av_log2(2*left->ref) + av_log2(2*top->ref); | |
4001 | 885 int mx_context= av_log2(2*FFABS(left->mx - top->mx)) + 0*av_log2(2*FFABS(tr->mx - top->mx)); |
886 int my_context= av_log2(2*FFABS(left->my - top->my)) + 0*av_log2(2*FFABS(tr->my - top->my)); | |
2967 | 887 |
2335 | 888 type= get_rac(&s->c, &s->block_state[1 + left->type + top->type]) ? BLOCK_INTRA : 0; |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
889 |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
890 if(type){ |
3325
c2a017de6bea
Snow: scale predicted mv based on which reference frame the neighbors used.
lorenm
parents:
3324
diff
changeset
|
891 pred_mv(s, &mx, &my, 0, left, top, tr); |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
892 l += get_symbol(&s->c, &s->block_state[32], 1); |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
893 cb+= get_symbol(&s->c, &s->block_state[64], 1); |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
894 cr+= get_symbol(&s->c, &s->block_state[96], 1); |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
895 }else{ |
3314 | 896 if(s->ref_frames > 1) |
897 ref= get_symbol(&s->c, &s->block_state[128 + 1024 + 32*ref_context], 0); | |
3325
c2a017de6bea
Snow: scale predicted mv based on which reference frame the neighbors used.
lorenm
parents:
3324
diff
changeset
|
898 pred_mv(s, &mx, &my, ref, left, top, tr); |
3314 | 899 mx+= get_symbol(&s->c, &s->block_state[128 + 32*(mx_context + 16*!!ref)], 1); |
900 my+= get_symbol(&s->c, &s->block_state[128 + 32*(my_context + 16*!!ref)], 1); | |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
901 } |
3314 | 902 set_blocks(s, level, x, y, l, cb, cr, mx, my, ref, type); |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
903 }else{ |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
904 decode_q_branch(s, level+1, 2*x+0, 2*y+0); |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
905 decode_q_branch(s, level+1, 2*x+1, 2*y+0); |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
906 decode_q_branch(s, level+1, 2*x+0, 2*y+1); |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
907 decode_q_branch(s, level+1, 2*x+1, 2*y+1); |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
908 } |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
909 } |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
910 |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
911 static void decode_blocks(SnowContext *s){ |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
912 int x, y; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
913 int w= s->b_width; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
914 int h= s->b_height; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
915 |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
916 for(y=0; y<h; y++){ |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
917 for(x=0; x<w; x++){ |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
918 decode_q_branch(s, 0, x, y); |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
919 } |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
920 } |
2138 | 921 } |
922 | |
5651
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
923 static void mc_block(Plane *p, uint8_t *dst, const uint8_t *src, uint8_t *tmp, int stride, int b_w, int b_h, int dx, int dy){ |
7622 | 924 static const uint8_t weight[64]={ |
5648 | 925 8,7,6,5,4,3,2,1, |
926 7,7,0,0,0,0,0,1, | |
927 6,0,6,0,0,0,2,0, | |
928 5,0,0,5,0,3,0,0, | |
929 4,0,0,0,4,0,0,0, | |
930 3,0,0,5,0,3,0,0, | |
931 2,0,6,0,0,0,2,0, | |
932 1,7,0,0,0,0,0,1, | |
933 }; | |
934 | |
7622 | 935 static const uint8_t brane[256]={ |
5648 | 936 0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x11,0x12,0x12,0x12,0x12,0x12,0x12,0x12, |
937 0x04,0x05,0xcc,0xcc,0xcc,0xcc,0xcc,0x41,0x15,0x16,0xcc,0xcc,0xcc,0xcc,0xcc,0x52, | |
938 0x04,0xcc,0x05,0xcc,0xcc,0xcc,0x41,0xcc,0x15,0xcc,0x16,0xcc,0xcc,0xcc,0x52,0xcc, | |
939 0x04,0xcc,0xcc,0x05,0xcc,0x41,0xcc,0xcc,0x15,0xcc,0xcc,0x16,0xcc,0x52,0xcc,0xcc, | |
940 0x04,0xcc,0xcc,0xcc,0x41,0xcc,0xcc,0xcc,0x15,0xcc,0xcc,0xcc,0x16,0xcc,0xcc,0xcc, | |
941 0x04,0xcc,0xcc,0x41,0xcc,0x05,0xcc,0xcc,0x15,0xcc,0xcc,0x52,0xcc,0x16,0xcc,0xcc, | |
942 0x04,0xcc,0x41,0xcc,0xcc,0xcc,0x05,0xcc,0x15,0xcc,0x52,0xcc,0xcc,0xcc,0x16,0xcc, | |
943 0x04,0x41,0xcc,0xcc,0xcc,0xcc,0xcc,0x05,0x15,0x52,0xcc,0xcc,0xcc,0xcc,0xcc,0x16, | |
944 0x44,0x45,0x45,0x45,0x45,0x45,0x45,0x45,0x55,0x56,0x56,0x56,0x56,0x56,0x56,0x56, | |
945 0x48,0x49,0xcc,0xcc,0xcc,0xcc,0xcc,0x85,0x59,0x5A,0xcc,0xcc,0xcc,0xcc,0xcc,0x96, | |
946 0x48,0xcc,0x49,0xcc,0xcc,0xcc,0x85,0xcc,0x59,0xcc,0x5A,0xcc,0xcc,0xcc,0x96,0xcc, | |
947 0x48,0xcc,0xcc,0x49,0xcc,0x85,0xcc,0xcc,0x59,0xcc,0xcc,0x5A,0xcc,0x96,0xcc,0xcc, | |
948 0x48,0xcc,0xcc,0xcc,0x49,0xcc,0xcc,0xcc,0x59,0xcc,0xcc,0xcc,0x96,0xcc,0xcc,0xcc, | |
949 0x48,0xcc,0xcc,0x85,0xcc,0x49,0xcc,0xcc,0x59,0xcc,0xcc,0x96,0xcc,0x5A,0xcc,0xcc, | |
950 0x48,0xcc,0x85,0xcc,0xcc,0xcc,0x49,0xcc,0x59,0xcc,0x96,0xcc,0xcc,0xcc,0x5A,0xcc, | |
951 0x48,0x85,0xcc,0xcc,0xcc,0xcc,0xcc,0x49,0x59,0x96,0xcc,0xcc,0xcc,0xcc,0xcc,0x5A, | |
952 }; | |
953 | |
7622 | 954 static const uint8_t needs[16]={ |
5648 | 955 0,1,0,0, |
956 2,4,2,0, | |
957 0,1,0,0, | |
958 15 | |
959 }; | |
960 | |
961 int x, y, b, r, l; | |
5652
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
962 int16_t tmpIt [64*(32+HTAPS_MAX)]; |
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
963 uint8_t tmp2t[3][stride*(32+HTAPS_MAX)]; |
5648 | 964 int16_t *tmpI= tmpIt; |
965 uint8_t *tmp2= tmp2t[0]; | |
6205 | 966 const uint8_t *hpel[11]; |
5648 | 967 assert(dx<16 && dy<16); |
968 r= brane[dx + 16*dy]&15; | |
969 l= brane[dx + 16*dy]>>4; | |
970 | |
971 b= needs[l] | needs[r]; | |
5651
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
972 if(p && !p->diag_mc) |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
973 b= 15; |
5648 | 974 |
975 if(b&5){ | |
5652
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
976 for(y=0; y < b_h+HTAPS_MAX-1; y++){ |
5649 | 977 for(x=0; x < b_w; x++){ |
5652
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
978 int a_1=src[x + HTAPS_MAX/2-4]; |
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
979 int a0= src[x + HTAPS_MAX/2-3]; |
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
980 int a1= src[x + HTAPS_MAX/2-2]; |
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
981 int a2= src[x + HTAPS_MAX/2-1]; |
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
982 int a3= src[x + HTAPS_MAX/2+0]; |
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
983 int a4= src[x + HTAPS_MAX/2+1]; |
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
984 int a5= src[x + HTAPS_MAX/2+2]; |
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
985 int a6= src[x + HTAPS_MAX/2+3]; |
5651
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
986 int am=0; |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
987 if(!p || p->fast_mc){ |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
988 am= 20*(a2+a3) - 5*(a1+a4) + (a0+a5); |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
989 tmpI[x]= am; |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
990 am= (am+16)>>5; |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
991 }else{ |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
992 am= p->hcoeff[0]*(a2+a3) + p->hcoeff[1]*(a1+a4) + p->hcoeff[2]*(a0+a5) + p->hcoeff[3]*(a_1+a6); |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
993 tmpI[x]= am; |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
994 am= (am+32)>>6; |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
995 } |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
996 |
5649 | 997 if(am&(~255)) am= ~(am>>31); |
998 tmp2[x]= am; | |
999 } | |
1000 tmpI+= 64; | |
1001 tmp2+= stride; | |
1002 src += stride; | |
2138 | 1003 } |
5649 | 1004 src -= stride*y; |
5648 | 1005 } |
5652
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
1006 src += HTAPS_MAX/2 - 1; |
5648 | 1007 tmp2= tmp2t[1]; |
1008 | |
1009 if(b&2){ | |
5649 | 1010 for(y=0; y < b_h; y++){ |
1011 for(x=0; x < b_w+1; x++){ | |
5652
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
1012 int a_1=src[x + (HTAPS_MAX/2-4)*stride]; |
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
1013 int a0= src[x + (HTAPS_MAX/2-3)*stride]; |
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
1014 int a1= src[x + (HTAPS_MAX/2-2)*stride]; |
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
1015 int a2= src[x + (HTAPS_MAX/2-1)*stride]; |
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
1016 int a3= src[x + (HTAPS_MAX/2+0)*stride]; |
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
1017 int a4= src[x + (HTAPS_MAX/2+1)*stride]; |
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
1018 int a5= src[x + (HTAPS_MAX/2+2)*stride]; |
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
1019 int a6= src[x + (HTAPS_MAX/2+3)*stride]; |
5651
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
1020 int am=0; |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
1021 if(!p || p->fast_mc) |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
1022 am= (20*(a2+a3) - 5*(a1+a4) + (a0+a5) + 16)>>5; |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
1023 else |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
1024 am= (p->hcoeff[0]*(a2+a3) + p->hcoeff[1]*(a1+a4) + p->hcoeff[2]*(a0+a5) + p->hcoeff[3]*(a_1+a6) + 32)>>6; |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
1025 |
5649 | 1026 if(am&(~255)) am= ~(am>>31); |
1027 tmp2[x]= am; | |
1028 } | |
1029 src += stride; | |
1030 tmp2+= stride; | |
5648 | 1031 } |
5649 | 1032 src -= stride*y; |
5648 | 1033 } |
5652
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
1034 src += stride*(HTAPS_MAX/2 - 1); |
5648 | 1035 tmp2= tmp2t[2]; |
1036 tmpI= tmpIt; | |
1037 if(b&4){ | |
1038 for(y=0; y < b_h; y++){ | |
1039 for(x=0; x < b_w; x++){ | |
5652
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
1040 int a_1=tmpI[x + (HTAPS_MAX/2-4)*64]; |
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
1041 int a0= tmpI[x + (HTAPS_MAX/2-3)*64]; |
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
1042 int a1= tmpI[x + (HTAPS_MAX/2-2)*64]; |
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
1043 int a2= tmpI[x + (HTAPS_MAX/2-1)*64]; |
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
1044 int a3= tmpI[x + (HTAPS_MAX/2+0)*64]; |
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
1045 int a4= tmpI[x + (HTAPS_MAX/2+1)*64]; |
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
1046 int a5= tmpI[x + (HTAPS_MAX/2+2)*64]; |
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
1047 int a6= tmpI[x + (HTAPS_MAX/2+3)*64]; |
5651
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
1048 int am=0; |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
1049 if(!p || p->fast_mc) |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
1050 am= (20*(a2+a3) - 5*(a1+a4) + (a0+a5) + 512)>>10; |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
1051 else |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
1052 am= (p->hcoeff[0]*(a2+a3) + p->hcoeff[1]*(a1+a4) + p->hcoeff[2]*(a0+a5) + p->hcoeff[3]*(a_1+a6) + 2048)>>12; |
5648 | 1053 if(am&(~255)) am= ~(am>>31); |
1054 tmp2[x]= am; | |
1055 } | |
1056 tmpI+= 64; | |
1057 tmp2+= stride; | |
2138 | 1058 } |
5648 | 1059 } |
1060 | |
1061 hpel[ 0]= src; | |
5652
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
1062 hpel[ 1]= tmp2t[0] + stride*(HTAPS_MAX/2-1); |
5648 | 1063 hpel[ 2]= src + 1; |
1064 | |
1065 hpel[ 4]= tmp2t[1]; | |
1066 hpel[ 5]= tmp2t[2]; | |
1067 hpel[ 6]= tmp2t[1] + 1; | |
1068 | |
1069 hpel[ 8]= src + stride; | |
1070 hpel[ 9]= hpel[1] + stride; | |
1071 hpel[10]= hpel[8] + 1; | |
1072 | |
1073 if(b==15){ | |
6205 | 1074 const uint8_t *src1= hpel[dx/8 + dy/8*4 ]; |
1075 const uint8_t *src2= hpel[dx/8 + dy/8*4+1]; | |
1076 const uint8_t *src3= hpel[dx/8 + dy/8*4+4]; | |
1077 const uint8_t *src4= hpel[dx/8 + dy/8*4+5]; | |
5648 | 1078 dx&=7; |
1079 dy&=7; | |
1080 for(y=0; y < b_h; y++){ | |
1081 for(x=0; x < b_w; x++){ | |
1082 dst[x]= ((8-dx)*(8-dy)*src1[x] + dx*(8-dy)*src2[x]+ | |
1083 (8-dx)* dy *src3[x] + dx* dy *src4[x]+32)>>6; | |
1084 } | |
1085 src1+=stride; | |
1086 src2+=stride; | |
1087 src3+=stride; | |
1088 src4+=stride; | |
1089 dst +=stride; | |
1090 } | |
1091 }else{ | |
6205 | 1092 const uint8_t *src1= hpel[l]; |
1093 const uint8_t *src2= hpel[r]; | |
5648 | 1094 int a= weight[((dx&7) + (8*(dy&7)))]; |
1095 int b= 8-a; | |
1096 for(y=0; y < b_h; y++){ | |
1097 for(x=0; x < b_w; x++){ | |
1098 dst[x]= (a*src1[x] + b*src2[x] + 4)>>3; | |
1099 } | |
1100 src1+=stride; | |
1101 src2+=stride; | |
1102 dst +=stride; | |
1103 } | |
2138 | 1104 } |
1105 } | |
1106 | |
1107 #define mca(dx,dy,b_w)\ | |
5254 | 1108 static void mc_block_hpel ## dx ## dy ## b_w(uint8_t *dst, const uint8_t *src, int stride, int h){\ |
5652
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
1109 uint8_t tmp[stride*(b_w+HTAPS_MAX-1)];\ |
2138 | 1110 assert(h==b_w);\ |
5652
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
1111 mc_block(NULL, dst, src-(HTAPS_MAX/2-1)-(HTAPS_MAX/2-1)*stride, tmp, stride, b_w, b_w, dx, dy);\ |
2138 | 1112 } |
1113 | |
1114 mca( 0, 0,16) | |
1115 mca( 8, 0,16) | |
1116 mca( 0, 8,16) | |
1117 mca( 8, 8,16) | |
2224
11d54cb7ac4e
100l (forgot to set the 8x8 mc functions, so ME did use the mpeg ones ...)
michael
parents:
2223
diff
changeset
|
1118 mca( 0, 0,8) |
11d54cb7ac4e
100l (forgot to set the 8x8 mc functions, so ME did use the mpeg ones ...)
michael
parents:
2223
diff
changeset
|
1119 mca( 8, 0,8) |
11d54cb7ac4e
100l (forgot to set the 8x8 mc functions, so ME did use the mpeg ones ...)
michael
parents:
2223
diff
changeset
|
1120 mca( 0, 8,8) |
11d54cb7ac4e
100l (forgot to set the 8x8 mc functions, so ME did use the mpeg ones ...)
michael
parents:
2223
diff
changeset
|
1121 mca( 8, 8,8) |
2138 | 1122 |
3314 | 1123 static void pred_block(SnowContext *s, uint8_t *dst, uint8_t *tmp, int stride, int sx, int sy, int b_w, int b_h, BlockNode *block, int plane_index, int w, int h){ |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
1124 if(block->type & BLOCK_INTRA){ |
2206 | 1125 int x, y; |
3018 | 1126 const int color = block->color[plane_index]; |
1127 const int color4= color*0x01010101; | |
3033
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
1128 if(b_w==32){ |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
1129 for(y=0; y < b_h; y++){ |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
1130 *(uint32_t*)&dst[0 + y*stride]= color4; |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
1131 *(uint32_t*)&dst[4 + y*stride]= color4; |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
1132 *(uint32_t*)&dst[8 + y*stride]= color4; |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
1133 *(uint32_t*)&dst[12+ y*stride]= color4; |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
1134 *(uint32_t*)&dst[16+ y*stride]= color4; |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
1135 *(uint32_t*)&dst[20+ y*stride]= color4; |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
1136 *(uint32_t*)&dst[24+ y*stride]= color4; |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
1137 *(uint32_t*)&dst[28+ y*stride]= color4; |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
1138 } |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
1139 }else if(b_w==16){ |
3018 | 1140 for(y=0; y < b_h; y++){ |
1141 *(uint32_t*)&dst[0 + y*stride]= color4; | |
1142 *(uint32_t*)&dst[4 + y*stride]= color4; | |
1143 *(uint32_t*)&dst[8 + y*stride]= color4; | |
1144 *(uint32_t*)&dst[12+ y*stride]= color4; | |
1145 } | |
1146 }else if(b_w==8){ | |
1147 for(y=0; y < b_h; y++){ | |
1148 *(uint32_t*)&dst[0 + y*stride]= color4; | |
1149 *(uint32_t*)&dst[4 + y*stride]= color4; | |
1150 } | |
1151 }else if(b_w==4){ | |
1152 for(y=0; y < b_h; y++){ | |
1153 *(uint32_t*)&dst[0 + y*stride]= color4; | |
1154 } | |
1155 }else{ | |
1156 for(y=0; y < b_h; y++){ | |
1157 for(x=0; x < b_w; x++){ | |
1158 dst[x + y*stride]= color; | |
1159 } | |
2138 | 1160 } |
1161 } | |
1162 }else{ | |
3314 | 1163 uint8_t *src= s->last_picture[block->ref].data[plane_index]; |
2206 | 1164 const int scale= plane_index ? s->mv_scale : 2*s->mv_scale; |
1165 int mx= block->mx*scale; | |
1166 int my= block->my*scale; | |
2223 | 1167 const int dx= mx&15; |
1168 const int dy= my&15; | |
3020
c75fb0747e74
use h264 MC functions for 2xX Xx2 blocks in snow too
michael
parents:
3018
diff
changeset
|
1169 const int tab_index= 3 - (b_w>>2) + (b_w>>4); |
5652
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
1170 sx += (mx>>4) - (HTAPS_MAX/2-1); |
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
1171 sy += (my>>4) - (HTAPS_MAX/2-1); |
2206 | 1172 src += sx + sy*stride; |
5652
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
1173 if( (unsigned)sx >= w - b_w - (HTAPS_MAX-2) |
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
1174 || (unsigned)sy >= h - b_h - (HTAPS_MAX-2)){ |
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
1175 ff_emulated_edge_mc(tmp + MB_SIZE, src, stride, b_w+HTAPS_MAX-1, b_h+HTAPS_MAX-1, sx, sy, w, h); |
2206 | 1176 src= tmp + MB_SIZE; |
2138 | 1177 } |
3189 | 1178 // assert(b_w == b_h || 2*b_w == b_h || b_w == 2*b_h); |
1179 // assert(!(b_w&(b_w-1))); | |
3018 | 1180 assert(b_w>1 && b_h>1); |
6206
ea591bc7522a
add parenthesis, fix warning: snow.c:2413: warning: suggest parentheses around && within ||
bcoudurier
parents:
6205
diff
changeset
|
1181 assert((tab_index>=0 && tab_index<4) || b_w==32); |
5651
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
1182 if((dx&3) || (dy&3) || !(b_w == b_h || 2*b_w == b_h || b_w == 2*b_h) || (b_w&(b_w-1)) || !s->plane[plane_index].fast_mc ) |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
1183 mc_block(&s->plane[plane_index], dst, src, tmp, stride, b_w, b_h, dx, dy); |
3033
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
1184 else if(b_w==32){ |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
1185 int y; |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
1186 for(y=0; y<b_h; y+=16){ |
5651
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
1187 s->dsp.put_h264_qpel_pixels_tab[0][dy+(dx>>2)](dst + y*stride, src + 3 + (y+3)*stride,stride); |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
1188 s->dsp.put_h264_qpel_pixels_tab[0][dy+(dx>>2)](dst + 16 + y*stride, src + 19 + (y+3)*stride,stride); |
3033
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
1189 } |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
1190 }else if(b_w==b_h) |
5651
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
1191 s->dsp.put_h264_qpel_pixels_tab[tab_index ][dy+(dx>>2)](dst,src + 3 + 3*stride,stride); |
3018 | 1192 else if(b_w==2*b_h){ |
5651
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
1193 s->dsp.put_h264_qpel_pixels_tab[tab_index+1][dy+(dx>>2)](dst ,src + 3 + 3*stride,stride); |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
1194 s->dsp.put_h264_qpel_pixels_tab[tab_index+1][dy+(dx>>2)](dst+b_h,src + 3 + b_h + 3*stride,stride); |
3018 | 1195 }else{ |
1196 assert(2*b_w==b_h); | |
5651
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
1197 s->dsp.put_h264_qpel_pixels_tab[tab_index ][dy+(dx>>2)](dst ,src + 3 + 3*stride ,stride); |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
1198 s->dsp.put_h264_qpel_pixels_tab[tab_index ][dy+(dx>>2)](dst+b_w*stride,src + 3 + 3*stride+b_w*stride,stride); |
3018 | 1199 } |
2138 | 1200 } |
1201 } | |
1202 | |
4436
d3e389536b0a
Add the const specifier as needed to reduce the number of warnings.
takis
parents:
4409
diff
changeset
|
1203 void ff_snow_inner_add_yblock(const uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h, |
3198
6b9f0c4fbdbe
First part of a series of speed-enchancing patches.
gpoirier
parents:
3197
diff
changeset
|
1204 int src_x, int src_y, int src_stride, slice_buffer * sb, int add, uint8_t * dst8){ |
6b9f0c4fbdbe
First part of a series of speed-enchancing patches.
gpoirier
parents:
3197
diff
changeset
|
1205 int y, x; |
5587
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
1206 IDWTELEM * dst; |
3198
6b9f0c4fbdbe
First part of a series of speed-enchancing patches.
gpoirier
parents:
3197
diff
changeset
|
1207 for(y=0; y<b_h; y++){ |
5409 | 1208 //FIXME ugly misuse of obmc_stride |
4436
d3e389536b0a
Add the const specifier as needed to reduce the number of warnings.
takis
parents:
4409
diff
changeset
|
1209 const uint8_t *obmc1= obmc + y*obmc_stride; |
d3e389536b0a
Add the const specifier as needed to reduce the number of warnings.
takis
parents:
4409
diff
changeset
|
1210 const uint8_t *obmc2= obmc1+ (obmc_stride>>1); |
d3e389536b0a
Add the const specifier as needed to reduce the number of warnings.
takis
parents:
4409
diff
changeset
|
1211 const uint8_t *obmc3= obmc1+ obmc_stride*(obmc_stride>>1); |
d3e389536b0a
Add the const specifier as needed to reduce the number of warnings.
takis
parents:
4409
diff
changeset
|
1212 const uint8_t *obmc4= obmc3+ (obmc_stride>>1); |
3198
6b9f0c4fbdbe
First part of a series of speed-enchancing patches.
gpoirier
parents:
3197
diff
changeset
|
1213 dst = slice_buffer_get_line(sb, src_y + y); |
6b9f0c4fbdbe
First part of a series of speed-enchancing patches.
gpoirier
parents:
3197
diff
changeset
|
1214 for(x=0; x<b_w; x++){ |
6b9f0c4fbdbe
First part of a series of speed-enchancing patches.
gpoirier
parents:
3197
diff
changeset
|
1215 int v= obmc1[x] * block[3][x + y*src_stride] |
6b9f0c4fbdbe
First part of a series of speed-enchancing patches.
gpoirier
parents:
3197
diff
changeset
|
1216 +obmc2[x] * block[2][x + y*src_stride] |
6b9f0c4fbdbe
First part of a series of speed-enchancing patches.
gpoirier
parents:
3197
diff
changeset
|
1217 +obmc3[x] * block[1][x + y*src_stride] |
6b9f0c4fbdbe
First part of a series of speed-enchancing patches.
gpoirier
parents:
3197
diff
changeset
|
1218 +obmc4[x] * block[0][x + y*src_stride]; |
6b9f0c4fbdbe
First part of a series of speed-enchancing patches.
gpoirier
parents:
3197
diff
changeset
|
1219 |
6b9f0c4fbdbe
First part of a series of speed-enchancing patches.
gpoirier
parents:
3197
diff
changeset
|
1220 v <<= 8 - LOG2_OBMC_MAX; |
6b9f0c4fbdbe
First part of a series of speed-enchancing patches.
gpoirier
parents:
3197
diff
changeset
|
1221 if(FRAC_BITS != 8){ |
6b9f0c4fbdbe
First part of a series of speed-enchancing patches.
gpoirier
parents:
3197
diff
changeset
|
1222 v >>= 8 - FRAC_BITS; |
6b9f0c4fbdbe
First part of a series of speed-enchancing patches.
gpoirier
parents:
3197
diff
changeset
|
1223 } |
6b9f0c4fbdbe
First part of a series of speed-enchancing patches.
gpoirier
parents:
3197
diff
changeset
|
1224 if(add){ |
6b9f0c4fbdbe
First part of a series of speed-enchancing patches.
gpoirier
parents:
3197
diff
changeset
|
1225 v += dst[x + src_x]; |
6b9f0c4fbdbe
First part of a series of speed-enchancing patches.
gpoirier
parents:
3197
diff
changeset
|
1226 v = (v + (1<<(FRAC_BITS-1))) >> FRAC_BITS; |
6b9f0c4fbdbe
First part of a series of speed-enchancing patches.
gpoirier
parents:
3197
diff
changeset
|
1227 if(v&(~255)) v= ~(v>>31); |
6b9f0c4fbdbe
First part of a series of speed-enchancing patches.
gpoirier
parents:
3197
diff
changeset
|
1228 dst8[x + y*src_stride] = v; |
6b9f0c4fbdbe
First part of a series of speed-enchancing patches.
gpoirier
parents:
3197
diff
changeset
|
1229 }else{ |
6b9f0c4fbdbe
First part of a series of speed-enchancing patches.
gpoirier
parents:
3197
diff
changeset
|
1230 dst[x + src_x] -= v; |
6b9f0c4fbdbe
First part of a series of speed-enchancing patches.
gpoirier
parents:
3197
diff
changeset
|
1231 } |
6b9f0c4fbdbe
First part of a series of speed-enchancing patches.
gpoirier
parents:
3197
diff
changeset
|
1232 } |
6b9f0c4fbdbe
First part of a series of speed-enchancing patches.
gpoirier
parents:
3197
diff
changeset
|
1233 } |
6b9f0c4fbdbe
First part of a series of speed-enchancing patches.
gpoirier
parents:
3197
diff
changeset
|
1234 } |
6b9f0c4fbdbe
First part of a series of speed-enchancing patches.
gpoirier
parents:
3197
diff
changeset
|
1235 |
6412 | 1236 //FIXME name cleanup (b_w, block_w, b_width stuff) |
5587
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
1237 static av_always_inline void add_yblock(SnowContext *s, int sliced, slice_buffer *sb, IDWTELEM *dst, uint8_t *dst8, const uint8_t *obmc, int src_x, int src_y, int b_w, int b_h, int w, int h, int dst_stride, int src_stride, int obmc_stride, int b_x, int b_y, int add, int offset_dst, int plane_index){ |
2589
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1238 const int b_width = s->b_width << s->block_max_depth; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1239 const int b_height= s->b_height << s->block_max_depth; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1240 const int b_stride= b_width; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1241 BlockNode *lt= &s->block[b_x + b_y*b_stride]; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1242 BlockNode *rt= lt+1; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1243 BlockNode *lb= lt+b_stride; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1244 BlockNode *rb= lb+1; |
2967 | 1245 uint8_t *block[4]; |
2842 | 1246 int tmp_step= src_stride >= 7*MB_SIZE ? MB_SIZE : MB_SIZE*src_stride; |
8214
c5276ad92ff8
snow: move scratch buffer from stack to malloced buffer in context
mru
parents:
7622
diff
changeset
|
1247 uint8_t *tmp = s->scratchbuf; |
2842 | 1248 uint8_t *ptmp; |
2589
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1249 int x,y; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1250 |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1251 if(b_x<0){ |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1252 lt= rt; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1253 lb= rb; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1254 }else if(b_x + 1 >= b_width){ |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1255 rt= lt; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1256 rb= lb; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1257 } |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1258 if(b_y<0){ |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1259 lt= lb; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1260 rt= rb; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1261 }else if(b_y + 1 >= b_height){ |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1262 lb= lt; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1263 rb= rt; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1264 } |
2967 | 1265 |
6412 | 1266 if(src_x<0){ //FIXME merge with prev & always round internal width up to *16 |
2589
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1267 obmc -= src_x; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1268 b_w += src_x; |
3662
fc714e9a5419
snow cosmetics: merge the sliced and non-sliced versions of add_yblock
lorenm
parents:
3661
diff
changeset
|
1269 if(!sliced && !offset_dst) |
3033
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
1270 dst -= src_x; |
2206 | 1271 src_x=0; |
1272 }else if(src_x + b_w > w){ | |
1273 b_w = w - src_x; | |
1274 } | |
1275 if(src_y<0){ | |
1276 obmc -= src_y*obmc_stride; | |
1277 b_h += src_y; | |
3662
fc714e9a5419
snow cosmetics: merge the sliced and non-sliced versions of add_yblock
lorenm
parents:
3661
diff
changeset
|
1278 if(!sliced && !offset_dst) |
3033
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
1279 dst -= src_y*dst_stride; |
2206 | 1280 src_y=0; |
1281 }else if(src_y + b_h> h){ | |
1282 b_h = h - src_y; | |
1283 } | |
2967 | 1284 |
2206 | 1285 if(b_w<=0 || b_h<=0) return; |
1286 | |
6414 | 1287 assert(src_stride > 2*MB_SIZE + 5); |
1288 | |
3662
fc714e9a5419
snow cosmetics: merge the sliced and non-sliced versions of add_yblock
lorenm
parents:
3661
diff
changeset
|
1289 if(!sliced && offset_dst) |
3033
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
1290 dst += src_x + src_y*dst_stride; |
2249
2b1a5e1fd449
merge predict_plane() with DWTELEM->8bit conversation (21% faster)
michael
parents:
2246
diff
changeset
|
1291 dst8+= src_x + src_y*src_stride; |
2206 | 1292 // src += src_x + src_y*src_stride; |
1293 | |
2842 | 1294 ptmp= tmp + 3*tmp_step; |
1295 block[0]= ptmp; | |
1296 ptmp+=tmp_step; | |
3314 | 1297 pred_block(s, block[0], tmp, src_stride, src_x, src_y, b_w, b_h, lt, plane_index, w, h); |
2206 | 1298 |
1299 if(same_block(lt, rt)){ | |
1300 block[1]= block[0]; | |
1301 }else{ | |
2842 | 1302 block[1]= ptmp; |
1303 ptmp+=tmp_step; | |
3314 | 1304 pred_block(s, block[1], tmp, src_stride, src_x, src_y, b_w, b_h, rt, plane_index, w, h); |
2206 | 1305 } |
2967 | 1306 |
2206 | 1307 if(same_block(lt, lb)){ |
1308 block[2]= block[0]; | |
1309 }else if(same_block(rt, lb)){ | |
1310 block[2]= block[1]; | |
1311 }else{ | |
2842 | 1312 block[2]= ptmp; |
1313 ptmp+=tmp_step; | |
3314 | 1314 pred_block(s, block[2], tmp, src_stride, src_x, src_y, b_w, b_h, lb, plane_index, w, h); |
2206 | 1315 } |
1316 | |
1317 if(same_block(lt, rb) ){ | |
1318 block[3]= block[0]; | |
1319 }else if(same_block(rt, rb)){ | |
1320 block[3]= block[1]; | |
1321 }else if(same_block(lb, rb)){ | |
1322 block[3]= block[2]; | |
1323 }else{ | |
2842 | 1324 block[3]= ptmp; |
3314 | 1325 pred_block(s, block[3], tmp, src_stride, src_x, src_y, b_w, b_h, rb, plane_index, w, h); |
2206 | 1326 } |
1327 #if 0 | |
1328 for(y=0; y<b_h; y++){ | |
1329 for(x=0; x<b_w; x++){ | |
1330 int v= obmc [x + y*obmc_stride] * block[3][x + y*src_stride] * (256/OBMC_MAX); | |
1331 if(add) dst[x + y*dst_stride] += v; | |
1332 else dst[x + y*dst_stride] -= v; | |
1333 } | |
1334 } | |
1335 for(y=0; y<b_h; y++){ | |
1336 uint8_t *obmc2= obmc + (obmc_stride>>1); | |
1337 for(x=0; x<b_w; x++){ | |
1338 int v= obmc2[x + y*obmc_stride] * block[2][x + y*src_stride] * (256/OBMC_MAX); | |
1339 if(add) dst[x + y*dst_stride] += v; | |
1340 else dst[x + y*dst_stride] -= v; | |
1341 } | |
1342 } | |
1343 for(y=0; y<b_h; y++){ | |
1344 uint8_t *obmc3= obmc + obmc_stride*(obmc_stride>>1); | |
1345 for(x=0; x<b_w; x++){ | |
1346 int v= obmc3[x + y*obmc_stride] * block[1][x + y*src_stride] * (256/OBMC_MAX); | |
1347 if(add) dst[x + y*dst_stride] += v; | |
1348 else dst[x + y*dst_stride] -= v; | |
1349 } | |
1350 } | |
1351 for(y=0; y<b_h; y++){ | |
1352 uint8_t *obmc3= obmc + obmc_stride*(obmc_stride>>1); | |
1353 uint8_t *obmc4= obmc3+ (obmc_stride>>1); | |
1354 for(x=0; x<b_w; x++){ | |
1355 int v= obmc4[x + y*obmc_stride] * block[0][x + y*src_stride] * (256/OBMC_MAX); | |
1356 if(add) dst[x + y*dst_stride] += v; | |
1357 else dst[x + y*dst_stride] -= v; | |
1358 } | |
1359 } | |
1360 #else | |
3662
fc714e9a5419
snow cosmetics: merge the sliced and non-sliced versions of add_yblock
lorenm
parents:
3661
diff
changeset
|
1361 if(sliced){ |
11485 | 1362 s->dwt.inner_add_yblock(obmc, obmc_stride, block, b_w, b_h, src_x,src_y, src_stride, sb, add, dst8); |
6475 | 1363 }else{ |
1364 for(y=0; y<b_h; y++){ | |
1365 //FIXME ugly misuse of obmc_stride | |
1366 const uint8_t *obmc1= obmc + y*obmc_stride; | |
1367 const uint8_t *obmc2= obmc1+ (obmc_stride>>1); | |
1368 const uint8_t *obmc3= obmc1+ obmc_stride*(obmc_stride>>1); | |
1369 const uint8_t *obmc4= obmc3+ (obmc_stride>>1); | |
1370 for(x=0; x<b_w; x++){ | |
1371 int v= obmc1[x] * block[3][x + y*src_stride] | |
1372 +obmc2[x] * block[2][x + y*src_stride] | |
1373 +obmc3[x] * block[1][x + y*src_stride] | |
1374 +obmc4[x] * block[0][x + y*src_stride]; | |
1375 | |
1376 v <<= 8 - LOG2_OBMC_MAX; | |
1377 if(FRAC_BITS != 8){ | |
1378 v >>= 8 - FRAC_BITS; | |
1379 } | |
1380 if(add){ | |
1381 v += dst[x + y*dst_stride]; | |
1382 v = (v + (1<<(FRAC_BITS-1))) >> FRAC_BITS; | |
1383 if(v&(~255)) v= ~(v>>31); | |
1384 dst8[x + y*src_stride] = v; | |
1385 }else{ | |
1386 dst[x + y*dst_stride] -= v; | |
1387 } | |
2249
2b1a5e1fd449
merge predict_plane() with DWTELEM->8bit conversation (21% faster)
michael
parents:
2246
diff
changeset
|
1388 } |
2206 | 1389 } |
1390 } | |
5910 | 1391 #endif /* 0 */ |
2206 | 1392 } |
1393 | |
5587
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
1394 static av_always_inline void predict_slice_buffered(SnowContext *s, slice_buffer * sb, IDWTELEM * old_buffer, int plane_index, int add, int mb_y){ |
2589
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1395 Plane *p= &s->plane[plane_index]; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1396 const int mb_w= s->b_width << s->block_max_depth; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1397 const int mb_h= s->b_height << s->block_max_depth; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1398 int x, y, mb_x; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1399 int block_size = MB_SIZE >> s->block_max_depth; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1400 int block_w = plane_index ? block_size/2 : block_size; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1401 const uint8_t *obmc = plane_index ? obmc_tab[s->block_max_depth+1] : obmc_tab[s->block_max_depth]; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1402 int obmc_stride= plane_index ? block_size : 2*block_size; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1403 int ref_stride= s->current_picture.linesize[plane_index]; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1404 uint8_t *dst8= s->current_picture.data[plane_index]; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1405 int w= p->width; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1406 int h= p->height; |
2967 | 1407 |
2589
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1408 if(s->keyframe || (s->avctx->debug&512)){ |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1409 if(mb_y==mb_h) |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1410 return; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1411 |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1412 if(add){ |
6474
e6995f3fbf7f
cosmetics: Normalize {} placement after for, while, if.
diego
parents:
6437
diff
changeset
|
1413 for(y=block_w*mb_y; y<FFMIN(h,block_w*(mb_y+1)); y++){ |
2589
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1414 // DWTELEM * line = slice_buffer_get_line(sb, y); |
5587
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
1415 IDWTELEM * line = sb->line[y]; |
6474
e6995f3fbf7f
cosmetics: Normalize {} placement after for, while, if.
diego
parents:
6437
diff
changeset
|
1416 for(x=0; x<w; x++){ |
2589
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1417 // int v= buf[x + y*w] + (128<<FRAC_BITS) + (1<<(FRAC_BITS-1)); |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1418 int v= line[x] + (128<<FRAC_BITS) + (1<<(FRAC_BITS-1)); |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1419 v >>= FRAC_BITS; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1420 if(v&(~255)) v= ~(v>>31); |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1421 dst8[x + y*ref_stride]= v; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1422 } |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1423 } |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1424 }else{ |
6474
e6995f3fbf7f
cosmetics: Normalize {} placement after for, while, if.
diego
parents:
6437
diff
changeset
|
1425 for(y=block_w*mb_y; y<FFMIN(h,block_w*(mb_y+1)); y++){ |
2589
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1426 // DWTELEM * line = slice_buffer_get_line(sb, y); |
5587
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
1427 IDWTELEM * line = sb->line[y]; |
6474
e6995f3fbf7f
cosmetics: Normalize {} placement after for, while, if.
diego
parents:
6437
diff
changeset
|
1428 for(x=0; x<w; x++){ |
2589
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1429 line[x] -= 128 << FRAC_BITS; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1430 // buf[x + y*w]-= 128<<FRAC_BITS; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1431 } |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1432 } |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1433 } |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1434 |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1435 return; |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1436 } |
2967 | 1437 |
6475 | 1438 for(mb_x=0; mb_x<=mb_w; mb_x++){ |
1439 add_yblock(s, 1, sb, old_buffer, dst8, obmc, | |
1440 block_w*mb_x - block_w/2, | |
1441 block_w*mb_y - block_w/2, | |
1442 block_w, block_w, | |
1443 w, h, | |
1444 w, ref_stride, obmc_stride, | |
1445 mb_x - 1, mb_y - 1, | |
1446 add, 0, plane_index); | |
1447 } | |
2589
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1448 } |
a5a62827f195
Snow Slicing patch by (Yartrebo) yartrebo earthlink net
michael
parents:
2562
diff
changeset
|
1449 |
5587
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
1450 static av_always_inline void predict_slice(SnowContext *s, IDWTELEM *buf, int plane_index, int add, int mb_y){ |
2138 | 1451 Plane *p= &s->plane[plane_index]; |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
1452 const int mb_w= s->b_width << s->block_max_depth; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
1453 const int mb_h= s->b_height << s->block_max_depth; |
2562 | 1454 int x, y, mb_x; |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
1455 int block_size = MB_SIZE >> s->block_max_depth; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
1456 int block_w = plane_index ? block_size/2 : block_size; |
2206 | 1457 const uint8_t *obmc = plane_index ? obmc_tab[s->block_max_depth+1] : obmc_tab[s->block_max_depth]; |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
1458 const int obmc_stride= plane_index ? block_size : 2*block_size; |
2249
2b1a5e1fd449
merge predict_plane() with DWTELEM->8bit conversation (21% faster)
michael
parents:
2246
diff
changeset
|
1459 int ref_stride= s->current_picture.linesize[plane_index]; |
2b1a5e1fd449
merge predict_plane() with DWTELEM->8bit conversation (21% faster)
michael
parents:
2246
diff
changeset
|
1460 uint8_t *dst8= s->current_picture.data[plane_index]; |
2138 | 1461 int w= p->width; |
1462 int h= p->height; | |
2967 | 1463 |
2206 | 1464 if(s->keyframe || (s->avctx->debug&512)){ |
2562 | 1465 if(mb_y==mb_h) |
1466 return; | |
1467 | |
2249
2b1a5e1fd449
merge predict_plane() with DWTELEM->8bit conversation (21% faster)
michael
parents:
2246
diff
changeset
|
1468 if(add){ |
2604
b7e6c3d31c65
Snow segfault bug in revision 1.43 patch by (Yartrebo /yartrebo earthlink net/)
michael
parents:
2602
diff
changeset
|
1469 for(y=block_w*mb_y; y<FFMIN(h,block_w*(mb_y+1)); y++){ |
2249
2b1a5e1fd449
merge predict_plane() with DWTELEM->8bit conversation (21% faster)
michael
parents:
2246
diff
changeset
|
1470 for(x=0; x<w; x++){ |
2b1a5e1fd449
merge predict_plane() with DWTELEM->8bit conversation (21% faster)
michael
parents:
2246
diff
changeset
|
1471 int v= buf[x + y*w] + (128<<FRAC_BITS) + (1<<(FRAC_BITS-1)); |
2b1a5e1fd449
merge predict_plane() with DWTELEM->8bit conversation (21% faster)
michael
parents:
2246
diff
changeset
|
1472 v >>= FRAC_BITS; |
2b1a5e1fd449
merge predict_plane() with DWTELEM->8bit conversation (21% faster)
michael
parents:
2246
diff
changeset
|
1473 if(v&(~255)) v= ~(v>>31); |
2b1a5e1fd449
merge predict_plane() with DWTELEM->8bit conversation (21% faster)
michael
parents:
2246
diff
changeset
|
1474 dst8[x + y*ref_stride]= v; |
2b1a5e1fd449
merge predict_plane() with DWTELEM->8bit conversation (21% faster)
michael
parents:
2246
diff
changeset
|
1475 } |
2b1a5e1fd449
merge predict_plane() with DWTELEM->8bit conversation (21% faster)
michael
parents:
2246
diff
changeset
|
1476 } |
2b1a5e1fd449
merge predict_plane() with DWTELEM->8bit conversation (21% faster)
michael
parents:
2246
diff
changeset
|
1477 }else{ |
2604
b7e6c3d31c65
Snow segfault bug in revision 1.43 patch by (Yartrebo /yartrebo earthlink net/)
michael
parents:
2602
diff
changeset
|
1478 for(y=block_w*mb_y; y<FFMIN(h,block_w*(mb_y+1)); y++){ |
2249
2b1a5e1fd449
merge predict_plane() with DWTELEM->8bit conversation (21% faster)
michael
parents:
2246
diff
changeset
|
1479 for(x=0; x<w; x++){ |
2b1a5e1fd449
merge predict_plane() with DWTELEM->8bit conversation (21% faster)
michael
parents:
2246
diff
changeset
|
1480 buf[x + y*w]-= 128<<FRAC_BITS; |
2b1a5e1fd449
merge predict_plane() with DWTELEM->8bit conversation (21% faster)
michael
parents:
2246
diff
changeset
|
1481 } |
2206 | 1482 } |
2138 | 1483 } |
2206 | 1484 |
1485 return; | |
2138 | 1486 } |
2967 | 1487 |
6414 | 1488 for(mb_x=0; mb_x<=mb_w; mb_x++){ |
1489 add_yblock(s, 0, NULL, buf, dst8, obmc, | |
1490 block_w*mb_x - block_w/2, | |
1491 block_w*mb_y - block_w/2, | |
1492 block_w, block_w, | |
1493 w, h, | |
1494 w, ref_stride, obmc_stride, | |
1495 mb_x - 1, mb_y - 1, | |
1496 add, 1, plane_index); | |
1497 } | |
2562 | 1498 } |
1499 | |
5587
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
1500 static av_always_inline void predict_plane(SnowContext *s, IDWTELEM *buf, int plane_index, int add){ |
2562 | 1501 const int mb_h= s->b_height << s->block_max_depth; |
1502 int mb_y; | |
1503 for(mb_y=0; mb_y<=mb_h; mb_y++) | |
1504 predict_slice(s, buf, plane_index, add, mb_y); | |
2138 | 1505 } |
1506 | |
10188
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1507 static void dequantize_slice_buffered(SnowContext *s, slice_buffer * sb, SubBand *b, IDWTELEM *src, int stride, int start_y, int end_y){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1508 const int w= b->width; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1509 const int qlog= av_clip(s->qlog + b->qlog, 0, QROOT*16); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1510 const int qmul= qexp[qlog&(QROOT-1)]<<(qlog>>QSHIFT); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1511 const int qadd= (s->qbias*qmul)>>QBIAS_SHIFT; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1512 int x,y; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1513 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1514 if(s->qlog == LOSSLESS_QLOG) return; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1515 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1516 for(y=start_y; y<end_y; y++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1517 // DWTELEM * line = slice_buffer_get_line_from_address(sb, src + (y * stride)); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1518 IDWTELEM * line = slice_buffer_get_line(sb, (y * b->stride_line) + b->buf_y_offset) + b->buf_x_offset; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1519 for(x=0; x<w; x++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1520 int i= line[x]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1521 if(i<0){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1522 line[x]= -((-i*qmul + qadd)>>(QEXPSHIFT)); //FIXME try different bias |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1523 }else if(i>0){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1524 line[x]= (( i*qmul + qadd)>>(QEXPSHIFT)); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1525 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1526 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1527 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1528 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1529 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1530 static void correlate_slice_buffered(SnowContext *s, slice_buffer * sb, SubBand *b, IDWTELEM *src, int stride, int inverse, int use_median, int start_y, int end_y){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1531 const int w= b->width; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1532 int x,y; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1533 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1534 IDWTELEM * line=0; // silence silly "could be used without having been initialized" warning |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1535 IDWTELEM * prev; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1536 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1537 if (start_y != 0) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1538 line = slice_buffer_get_line(sb, ((start_y - 1) * b->stride_line) + b->buf_y_offset) + b->buf_x_offset; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1539 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1540 for(y=start_y; y<end_y; y++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1541 prev = line; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1542 // line = slice_buffer_get_line_from_address(sb, src + (y * stride)); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1543 line = slice_buffer_get_line(sb, (y * b->stride_line) + b->buf_y_offset) + b->buf_x_offset; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1544 for(x=0; x<w; x++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1545 if(x){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1546 if(use_median){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1547 if(y && x+1<w) line[x] += mid_pred(line[x - 1], prev[x], prev[x + 1]); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1548 else line[x] += line[x - 1]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1549 }else{ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1550 if(y) line[x] += mid_pred(line[x - 1], prev[x], line[x - 1] + prev[x] - prev[x - 1]); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1551 else line[x] += line[x - 1]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1552 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1553 }else{ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1554 if(y) line[x] += prev[x]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1555 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1556 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1557 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1558 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1559 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1560 static void decode_qlogs(SnowContext *s){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1561 int plane_index, level, orientation; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1562 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1563 for(plane_index=0; plane_index<3; plane_index++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1564 for(level=0; level<s->spatial_decomposition_count; level++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1565 for(orientation=level ? 1:0; orientation<4; orientation++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1566 int q; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1567 if (plane_index==2) q= s->plane[1].band[level][orientation].qlog; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1568 else if(orientation==2) q= s->plane[plane_index].band[level][1].qlog; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1569 else q= get_symbol(&s->c, s->header_state, 1); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1570 s->plane[plane_index].band[level][orientation].qlog= q; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1571 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1572 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1573 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1574 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1575 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1576 #define GET_S(dst, check) \ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1577 tmp= get_symbol(&s->c, s->header_state, 0);\ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1578 if(!(check)){\ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1579 av_log(s->avctx, AV_LOG_ERROR, "Error " #dst " is %d\n", tmp);\ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1580 return -1;\ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1581 }\ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1582 dst= tmp; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1583 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1584 static int decode_header(SnowContext *s){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1585 int plane_index, tmp; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1586 uint8_t kstate[32]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1587 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1588 memset(kstate, MID_STATE, sizeof(kstate)); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1589 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1590 s->keyframe= get_rac(&s->c, kstate); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1591 if(s->keyframe || s->always_reset){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1592 reset_contexts(s); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1593 s->spatial_decomposition_type= |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1594 s->qlog= |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1595 s->qbias= |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1596 s->mv_scale= |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1597 s->block_max_depth= 0; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1598 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1599 if(s->keyframe){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1600 GET_S(s->version, tmp <= 0U) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1601 s->always_reset= get_rac(&s->c, s->header_state); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1602 s->temporal_decomposition_type= get_symbol(&s->c, s->header_state, 0); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1603 s->temporal_decomposition_count= get_symbol(&s->c, s->header_state, 0); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1604 GET_S(s->spatial_decomposition_count, 0 < tmp && tmp <= MAX_DECOMPOSITIONS) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1605 s->colorspace_type= get_symbol(&s->c, s->header_state, 0); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1606 s->chroma_h_shift= get_symbol(&s->c, s->header_state, 0); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1607 s->chroma_v_shift= get_symbol(&s->c, s->header_state, 0); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1608 s->spatial_scalability= get_rac(&s->c, s->header_state); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1609 // s->rate_scalability= get_rac(&s->c, s->header_state); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1610 GET_S(s->max_ref_frames, tmp < (unsigned)MAX_REF_FRAMES) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1611 s->max_ref_frames++; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1612 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1613 decode_qlogs(s); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1614 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1615 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1616 if(!s->keyframe){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1617 if(get_rac(&s->c, s->header_state)){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1618 for(plane_index=0; plane_index<2; plane_index++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1619 int htaps, i, sum=0; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1620 Plane *p= &s->plane[plane_index]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1621 p->diag_mc= get_rac(&s->c, s->header_state); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1622 htaps= get_symbol(&s->c, s->header_state, 0)*2 + 2; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1623 if((unsigned)htaps > HTAPS_MAX || htaps==0) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1624 return -1; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1625 p->htaps= htaps; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1626 for(i= htaps/2; i; i--){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1627 p->hcoeff[i]= get_symbol(&s->c, s->header_state, 0) * (1-2*(i&1)); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1628 sum += p->hcoeff[i]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1629 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1630 p->hcoeff[0]= 32-sum; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1631 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1632 s->plane[2].diag_mc= s->plane[1].diag_mc; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1633 s->plane[2].htaps = s->plane[1].htaps; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1634 memcpy(s->plane[2].hcoeff, s->plane[1].hcoeff, sizeof(s->plane[1].hcoeff)); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1635 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1636 if(get_rac(&s->c, s->header_state)){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1637 GET_S(s->spatial_decomposition_count, 0 < tmp && tmp <= MAX_DECOMPOSITIONS) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1638 decode_qlogs(s); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1639 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1640 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1641 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1642 s->spatial_decomposition_type+= get_symbol(&s->c, s->header_state, 1); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1643 if(s->spatial_decomposition_type > 1U){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1644 av_log(s->avctx, AV_LOG_ERROR, "spatial_decomposition_type %d not supported", s->spatial_decomposition_type); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1645 return -1; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1646 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1647 if(FFMIN(s->avctx-> width>>s->chroma_h_shift, |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1648 s->avctx->height>>s->chroma_v_shift) >> (s->spatial_decomposition_count-1) <= 0){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1649 av_log(s->avctx, AV_LOG_ERROR, "spatial_decomposition_count %d too large for size", s->spatial_decomposition_count); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1650 return -1; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1651 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1652 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1653 s->qlog += get_symbol(&s->c, s->header_state, 1); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1654 s->mv_scale += get_symbol(&s->c, s->header_state, 1); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1655 s->qbias += get_symbol(&s->c, s->header_state, 1); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1656 s->block_max_depth+= get_symbol(&s->c, s->header_state, 1); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1657 if(s->block_max_depth > 1 || s->block_max_depth < 0){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1658 av_log(s->avctx, AV_LOG_ERROR, "block_max_depth= %d is too large", s->block_max_depth); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1659 s->block_max_depth= 0; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1660 return -1; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1661 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1662 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1663 return 0; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1664 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1665 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1666 static void init_qexp(void){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1667 int i; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1668 double v=128; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1669 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1670 for(i=0; i<QROOT; i++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1671 qexp[i]= lrintf(v); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1672 v *= pow(2, 1.0 / QROOT); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1673 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1674 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1675 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1676 static av_cold int common_init(AVCodecContext *avctx){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1677 SnowContext *s = avctx->priv_data; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1678 int width, height; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1679 int i, j; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1680 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1681 s->avctx= avctx; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1682 s->max_ref_frames=1; //just make sure its not an invalid value in case of no initial keyframe |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1683 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1684 dsputil_init(&s->dsp, avctx); |
11485 | 1685 ff_dwt_init(&s->dwt); |
10188
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1686 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1687 #define mcf(dx,dy)\ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1688 s->dsp.put_qpel_pixels_tab [0][dy+dx/4]=\ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1689 s->dsp.put_no_rnd_qpel_pixels_tab[0][dy+dx/4]=\ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1690 s->dsp.put_h264_qpel_pixels_tab[0][dy+dx/4];\ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1691 s->dsp.put_qpel_pixels_tab [1][dy+dx/4]=\ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1692 s->dsp.put_no_rnd_qpel_pixels_tab[1][dy+dx/4]=\ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1693 s->dsp.put_h264_qpel_pixels_tab[1][dy+dx/4]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1694 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1695 mcf( 0, 0) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1696 mcf( 4, 0) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1697 mcf( 8, 0) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1698 mcf(12, 0) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1699 mcf( 0, 4) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1700 mcf( 4, 4) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1701 mcf( 8, 4) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1702 mcf(12, 4) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1703 mcf( 0, 8) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1704 mcf( 4, 8) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1705 mcf( 8, 8) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1706 mcf(12, 8) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1707 mcf( 0,12) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1708 mcf( 4,12) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1709 mcf( 8,12) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1710 mcf(12,12) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1711 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1712 #define mcfh(dx,dy)\ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1713 s->dsp.put_pixels_tab [0][dy/4+dx/8]=\ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1714 s->dsp.put_no_rnd_pixels_tab[0][dy/4+dx/8]=\ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1715 mc_block_hpel ## dx ## dy ## 16;\ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1716 s->dsp.put_pixels_tab [1][dy/4+dx/8]=\ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1717 s->dsp.put_no_rnd_pixels_tab[1][dy/4+dx/8]=\ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1718 mc_block_hpel ## dx ## dy ## 8; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1719 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1720 mcfh(0, 0) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1721 mcfh(8, 0) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1722 mcfh(0, 8) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1723 mcfh(8, 8) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1724 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1725 if(!qexp[0]) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1726 init_qexp(); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1727 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1728 // dec += FFMAX(s->chroma_h_shift, s->chroma_v_shift); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1729 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1730 width= s->avctx->width; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1731 height= s->avctx->height; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1732 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1733 s->spatial_idwt_buffer= av_mallocz(width*height*sizeof(IDWTELEM)); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1734 s->spatial_dwt_buffer= av_mallocz(width*height*sizeof(DWTELEM)); //FIXME this does not belong here |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1735 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1736 for(i=0; i<MAX_REF_FRAMES; i++) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1737 for(j=0; j<MAX_REF_FRAMES; j++) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1738 scale_mv_ref[i][j] = 256*(i+1)/(j+1); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1739 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1740 s->avctx->get_buffer(s->avctx, &s->mconly_picture); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1741 s->scratchbuf = av_malloc(s->mconly_picture.linesize[0]*7*MB_SIZE); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1742 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1743 return 0; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1744 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1745 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1746 static int common_init_after_header(AVCodecContext *avctx){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1747 SnowContext *s = avctx->priv_data; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1748 int plane_index, level, orientation; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1749 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1750 for(plane_index=0; plane_index<3; plane_index++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1751 int w= s->avctx->width; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1752 int h= s->avctx->height; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1753 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1754 if(plane_index){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1755 w>>= s->chroma_h_shift; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1756 h>>= s->chroma_v_shift; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1757 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1758 s->plane[plane_index].width = w; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1759 s->plane[plane_index].height= h; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1760 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1761 for(level=s->spatial_decomposition_count-1; level>=0; level--){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1762 for(orientation=level ? 1 : 0; orientation<4; orientation++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1763 SubBand *b= &s->plane[plane_index].band[level][orientation]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1764 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1765 b->buf= s->spatial_dwt_buffer; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1766 b->level= level; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1767 b->stride= s->plane[plane_index].width << (s->spatial_decomposition_count - level); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1768 b->width = (w + !(orientation&1))>>1; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1769 b->height= (h + !(orientation>1))>>1; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1770 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1771 b->stride_line = 1 << (s->spatial_decomposition_count - level); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1772 b->buf_x_offset = 0; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1773 b->buf_y_offset = 0; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1774 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1775 if(orientation&1){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1776 b->buf += (w+1)>>1; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1777 b->buf_x_offset = (w+1)>>1; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1778 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1779 if(orientation>1){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1780 b->buf += b->stride>>1; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1781 b->buf_y_offset = b->stride_line >> 1; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1782 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1783 b->ibuf= s->spatial_idwt_buffer + (b->buf - s->spatial_dwt_buffer); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1784 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1785 if(level) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1786 b->parent= &s->plane[plane_index].band[level-1][orientation]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1787 //FIXME avoid this realloc |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1788 av_freep(&b->x_coeff); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1789 b->x_coeff=av_mallocz(((b->width+1) * b->height+1)*sizeof(x_and_coeff)); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1790 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1791 w= (w+1)>>1; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1792 h= (h+1)>>1; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1793 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1794 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1795 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1796 return 0; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1797 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1798 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1799 #define QUANTIZE2 0 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1800 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1801 #if QUANTIZE2==1 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1802 #define Q2_STEP 8 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1803 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1804 static void find_sse(SnowContext *s, Plane *p, int *score, int score_stride, IDWTELEM *r0, IDWTELEM *r1, int level, int orientation){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1805 SubBand *b= &p->band[level][orientation]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1806 int x, y; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1807 int xo=0; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1808 int yo=0; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1809 int step= 1 << (s->spatial_decomposition_count - level); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1810 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1811 if(orientation&1) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1812 xo= step>>1; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1813 if(orientation&2) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1814 yo= step>>1; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1815 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1816 //FIXME bias for nonzero ? |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1817 //FIXME optimize |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1818 memset(score, 0, sizeof(*score)*score_stride*((p->height + Q2_STEP-1)/Q2_STEP)); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1819 for(y=0; y<p->height; y++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1820 for(x=0; x<p->width; x++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1821 int sx= (x-xo + step/2) / step / Q2_STEP; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1822 int sy= (y-yo + step/2) / step / Q2_STEP; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1823 int v= r0[x + y*p->width] - r1[x + y*p->width]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1824 assert(sx>=0 && sy>=0 && sx < score_stride); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1825 v= ((v+8)>>4)<<4; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1826 score[sx + sy*score_stride] += v*v; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1827 assert(score[sx + sy*score_stride] >= 0); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1828 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1829 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1830 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1831 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1832 static void dequantize_all(SnowContext *s, Plane *p, IDWTELEM *buffer, int width, int height){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1833 int level, orientation; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1834 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1835 for(level=0; level<s->spatial_decomposition_count; level++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1836 for(orientation=level ? 1 : 0; orientation<4; orientation++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1837 SubBand *b= &p->band[level][orientation]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1838 IDWTELEM *dst= buffer + (b->ibuf - s->spatial_idwt_buffer); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1839 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1840 dequantize(s, b, dst, b->stride); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1841 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1842 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1843 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1844 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1845 static void dwt_quantize(SnowContext *s, Plane *p, DWTELEM *buffer, int width, int height, int stride, int type){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1846 int level, orientation, ys, xs, x, y, pass; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1847 IDWTELEM best_dequant[height * stride]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1848 IDWTELEM idwt2_buffer[height * stride]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1849 const int score_stride= (width + 10)/Q2_STEP; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1850 int best_score[(width + 10)/Q2_STEP * (height + 10)/Q2_STEP]; //FIXME size |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1851 int score[(width + 10)/Q2_STEP * (height + 10)/Q2_STEP]; //FIXME size |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1852 int threshold= (s->m.lambda * s->m.lambda) >> 6; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1853 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1854 //FIXME pass the copy cleanly ? |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1855 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1856 // memcpy(dwt_buffer, buffer, height * stride * sizeof(DWTELEM)); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1857 ff_spatial_dwt(buffer, width, height, stride, type, s->spatial_decomposition_count); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1858 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1859 for(level=0; level<s->spatial_decomposition_count; level++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1860 for(orientation=level ? 1 : 0; orientation<4; orientation++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1861 SubBand *b= &p->band[level][orientation]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1862 IDWTELEM *dst= best_dequant + (b->ibuf - s->spatial_idwt_buffer); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1863 DWTELEM *src= buffer + (b-> buf - s->spatial_dwt_buffer); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1864 assert(src == b->buf); // code does not depend on this but it is true currently |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1865 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1866 quantize(s, b, dst, src, b->stride, s->qbias); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1867 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1868 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1869 for(pass=0; pass<1; pass++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1870 if(s->qbias == 0) //keyframe |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1871 continue; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1872 for(level=0; level<s->spatial_decomposition_count; level++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1873 for(orientation=level ? 1 : 0; orientation<4; orientation++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1874 SubBand *b= &p->band[level][orientation]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1875 IDWTELEM *dst= idwt2_buffer + (b->ibuf - s->spatial_idwt_buffer); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1876 IDWTELEM *best_dst= best_dequant + (b->ibuf - s->spatial_idwt_buffer); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1877 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1878 for(ys= 0; ys<Q2_STEP; ys++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1879 for(xs= 0; xs<Q2_STEP; xs++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1880 memcpy(idwt2_buffer, best_dequant, height * stride * sizeof(IDWTELEM)); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1881 dequantize_all(s, p, idwt2_buffer, width, height); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1882 ff_spatial_idwt(idwt2_buffer, width, height, stride, type, s->spatial_decomposition_count); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1883 find_sse(s, p, best_score, score_stride, idwt2_buffer, s->spatial_idwt_buffer, level, orientation); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1884 memcpy(idwt2_buffer, best_dequant, height * stride * sizeof(IDWTELEM)); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1885 for(y=ys; y<b->height; y+= Q2_STEP){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1886 for(x=xs; x<b->width; x+= Q2_STEP){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1887 if(dst[x + y*b->stride]<0) dst[x + y*b->stride]++; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1888 if(dst[x + y*b->stride]>0) dst[x + y*b->stride]--; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1889 //FIXME try more than just -- |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1890 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1891 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1892 dequantize_all(s, p, idwt2_buffer, width, height); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1893 ff_spatial_idwt(idwt2_buffer, width, height, stride, type, s->spatial_decomposition_count); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1894 find_sse(s, p, score, score_stride, idwt2_buffer, s->spatial_idwt_buffer, level, orientation); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1895 for(y=ys; y<b->height; y+= Q2_STEP){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1896 for(x=xs; x<b->width; x+= Q2_STEP){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1897 int score_idx= x/Q2_STEP + (y/Q2_STEP)*score_stride; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1898 if(score[score_idx] <= best_score[score_idx] + threshold){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1899 best_score[score_idx]= score[score_idx]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1900 if(best_dst[x + y*b->stride]<0) best_dst[x + y*b->stride]++; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1901 if(best_dst[x + y*b->stride]>0) best_dst[x + y*b->stride]--; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1902 //FIXME copy instead |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1903 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1904 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1905 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1906 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1907 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1908 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1909 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1910 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1911 memcpy(s->spatial_idwt_buffer, best_dequant, height * stride * sizeof(IDWTELEM)); //FIXME work with that directly instead of copy at the end |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1912 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1913 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1914 #endif /* QUANTIZE2==1 */ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1915 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1916 #define USE_HALFPEL_PLANE 0 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1917 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1918 static void halfpel_interpol(SnowContext *s, uint8_t *halfpel[4][4], AVFrame *frame){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1919 int p,x,y; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1920 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1921 assert(!(s->avctx->flags & CODEC_FLAG_EMU_EDGE)); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1922 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1923 for(p=0; p<3; p++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1924 int is_chroma= !!p; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1925 int w= s->avctx->width >>is_chroma; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1926 int h= s->avctx->height >>is_chroma; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1927 int ls= frame->linesize[p]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1928 uint8_t *src= frame->data[p]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1929 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1930 halfpel[1][p]= (uint8_t*)av_malloc(ls * (h+2*EDGE_WIDTH)) + EDGE_WIDTH*(1+ls); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1931 halfpel[2][p]= (uint8_t*)av_malloc(ls * (h+2*EDGE_WIDTH)) + EDGE_WIDTH*(1+ls); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1932 halfpel[3][p]= (uint8_t*)av_malloc(ls * (h+2*EDGE_WIDTH)) + EDGE_WIDTH*(1+ls); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1933 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1934 halfpel[0][p]= src; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1935 for(y=0; y<h; y++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1936 for(x=0; x<w; x++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1937 int i= y*ls + x; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1938 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1939 halfpel[1][p][i]= (20*(src[i] + src[i+1]) - 5*(src[i-1] + src[i+2]) + (src[i-2] + src[i+3]) + 16 )>>5; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1940 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1941 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1942 for(y=0; y<h; y++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1943 for(x=0; x<w; x++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1944 int i= y*ls + x; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1945 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1946 halfpel[2][p][i]= (20*(src[i] + src[i+ls]) - 5*(src[i-ls] + src[i+2*ls]) + (src[i-2*ls] + src[i+3*ls]) + 16 )>>5; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1947 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1948 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1949 src= halfpel[1][p]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1950 for(y=0; y<h; y++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1951 for(x=0; x<w; x++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1952 int i= y*ls + x; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1953 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1954 halfpel[3][p][i]= (20*(src[i] + src[i+ls]) - 5*(src[i-ls] + src[i+2*ls]) + (src[i-2*ls] + src[i+3*ls]) + 16 )>>5; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1955 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1956 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1957 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1958 //FIXME border! |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1959 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1960 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1961 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1962 static void release_buffer(AVCodecContext *avctx){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1963 SnowContext *s = avctx->priv_data; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1964 int i; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1965 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1966 if(s->last_picture[s->max_ref_frames-1].data[0]){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1967 avctx->release_buffer(avctx, &s->last_picture[s->max_ref_frames-1]); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1968 for(i=0; i<9; i++) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1969 if(s->halfpel_plane[s->max_ref_frames-1][1+i/3][i%3]) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1970 av_free(s->halfpel_plane[s->max_ref_frames-1][1+i/3][i%3] - EDGE_WIDTH*(1+s->current_picture.linesize[i%3])); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1971 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1972 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1973 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1974 static int frame_start(SnowContext *s){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1975 AVFrame tmp; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1976 int w= s->avctx->width; //FIXME round up to x16 ? |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1977 int h= s->avctx->height; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1978 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1979 if(s->current_picture.data[0]){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1980 s->dsp.draw_edges(s->current_picture.data[0], s->current_picture.linesize[0], w , h , EDGE_WIDTH ); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1981 s->dsp.draw_edges(s->current_picture.data[1], s->current_picture.linesize[1], w>>1, h>>1, EDGE_WIDTH/2); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1982 s->dsp.draw_edges(s->current_picture.data[2], s->current_picture.linesize[2], w>>1, h>>1, EDGE_WIDTH/2); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1983 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1984 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1985 release_buffer(s->avctx); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1986 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1987 tmp= s->last_picture[s->max_ref_frames-1]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1988 memmove(s->last_picture+1, s->last_picture, (s->max_ref_frames-1)*sizeof(AVFrame)); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1989 memmove(s->halfpel_plane+1, s->halfpel_plane, (s->max_ref_frames-1)*sizeof(void*)*4*4); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1990 if(USE_HALFPEL_PLANE && s->current_picture.data[0]) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1991 halfpel_interpol(s, s->halfpel_plane[0], &s->current_picture); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1992 s->last_picture[0]= s->current_picture; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1993 s->current_picture= tmp; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1994 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1995 if(s->keyframe){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1996 s->ref_frames= 0; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1997 }else{ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1998 int i; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
1999 for(i=0; i<s->max_ref_frames && s->last_picture[i].data[0]; i++) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2000 if(i && s->last_picture[i-1].key_frame) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2001 break; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2002 s->ref_frames= i; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2003 if(s->ref_frames==0){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2004 av_log(s->avctx,AV_LOG_ERROR, "No reference frames\n"); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2005 return -1; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2006 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2007 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2008 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2009 s->current_picture.reference= 1; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2010 if(s->avctx->get_buffer(s->avctx, &s->current_picture) < 0){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2011 av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2012 return -1; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2013 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2014 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2015 s->current_picture.key_frame= s->keyframe; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2016 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2017 return 0; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2018 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2019 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2020 static av_cold void common_end(SnowContext *s){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2021 int plane_index, level, orientation, i; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2022 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2023 av_freep(&s->spatial_dwt_buffer); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2024 av_freep(&s->spatial_idwt_buffer); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2025 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2026 s->m.me.temp= NULL; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2027 av_freep(&s->m.me.scratchpad); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2028 av_freep(&s->m.me.map); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2029 av_freep(&s->m.me.score_map); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2030 av_freep(&s->m.obmc_scratchpad); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2031 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2032 av_freep(&s->block); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2033 av_freep(&s->scratchbuf); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2034 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2035 for(i=0; i<MAX_REF_FRAMES; i++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2036 av_freep(&s->ref_mvs[i]); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2037 av_freep(&s->ref_scores[i]); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2038 if(s->last_picture[i].data[0]) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2039 s->avctx->release_buffer(s->avctx, &s->last_picture[i]); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2040 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2041 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2042 for(plane_index=0; plane_index<3; plane_index++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2043 for(level=s->spatial_decomposition_count-1; level>=0; level--){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2044 for(orientation=level ? 1 : 0; orientation<4; orientation++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2045 SubBand *b= &s->plane[plane_index].band[level][orientation]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2046 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2047 av_freep(&b->x_coeff); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2048 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2049 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2050 } |
10806
e58e93f04279
Snow : release buffers allocated using avctx->get_buffer.
jai_menon
parents:
10625
diff
changeset
|
2051 if (s->mconly_picture.data[0]) |
e58e93f04279
Snow : release buffers allocated using avctx->get_buffer.
jai_menon
parents:
10625
diff
changeset
|
2052 s->avctx->release_buffer(s->avctx, &s->mconly_picture); |
e58e93f04279
Snow : release buffers allocated using avctx->get_buffer.
jai_menon
parents:
10625
diff
changeset
|
2053 if (s->current_picture.data[0]) |
e58e93f04279
Snow : release buffers allocated using avctx->get_buffer.
jai_menon
parents:
10625
diff
changeset
|
2054 s->avctx->release_buffer(s->avctx, &s->current_picture); |
10188
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2055 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2056 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2057 static av_cold int decode_init(AVCodecContext *avctx) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2058 { |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2059 avctx->pix_fmt= PIX_FMT_YUV420P; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2060 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2061 common_init(avctx); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2062 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2063 return 0; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2064 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2065 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2066 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2067 const uint8_t *buf = avpkt->data; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2068 int buf_size = avpkt->size; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2069 SnowContext *s = avctx->priv_data; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2070 RangeCoder * const c= &s->c; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2071 int bytes_read; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2072 AVFrame *picture = data; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2073 int level, orientation, plane_index; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2074 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2075 ff_init_range_decoder(c, buf, buf_size); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2076 ff_build_rac_states(c, 0.05*(1LL<<32), 256-8); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2077 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2078 s->current_picture.pict_type= FF_I_TYPE; //FIXME I vs. P |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2079 if(decode_header(s)<0) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2080 return -1; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2081 common_init_after_header(avctx); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2082 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2083 // realloc slice buffer for the case that spatial_decomposition_count changed |
11486 | 2084 ff_slice_buffer_destroy(&s->sb); |
2085 ff_slice_buffer_init(&s->sb, s->plane[0].height, (MB_SIZE >> s->block_max_depth) + s->spatial_decomposition_count * 8 + 1, s->plane[0].width, s->spatial_idwt_buffer); | |
10188
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2086 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2087 for(plane_index=0; plane_index<3; plane_index++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2088 Plane *p= &s->plane[plane_index]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2089 p->fast_mc= p->diag_mc && p->htaps==6 && p->hcoeff[0]==40 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2090 && p->hcoeff[1]==-10 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2091 && p->hcoeff[2]==2; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2092 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2093 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2094 alloc_blocks(s); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2095 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2096 if(frame_start(s) < 0) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2097 return -1; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2098 //keyframe flag duplication mess FIXME |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2099 if(avctx->debug&FF_DEBUG_PICT_INFO) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2100 av_log(avctx, AV_LOG_ERROR, "keyframe:%d qlog:%d\n", s->keyframe, s->qlog); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2101 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2102 decode_blocks(s); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2103 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2104 for(plane_index=0; plane_index<3; plane_index++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2105 Plane *p= &s->plane[plane_index]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2106 int w= p->width; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2107 int h= p->height; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2108 int x, y; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2109 int decode_state[MAX_DECOMPOSITIONS][4][1]; /* Stored state info for unpack_coeffs. 1 variable per instance. */ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2110 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2111 if(s->avctx->debug&2048){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2112 memset(s->spatial_dwt_buffer, 0, sizeof(DWTELEM)*w*h); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2113 predict_plane(s, s->spatial_idwt_buffer, plane_index, 1); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2114 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2115 for(y=0; y<h; y++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2116 for(x=0; x<w; x++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2117 int v= s->current_picture.data[plane_index][y*s->current_picture.linesize[plane_index] + x]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2118 s->mconly_picture.data[plane_index][y*s->mconly_picture.linesize[plane_index] + x]= v; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2119 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2120 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2121 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2122 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2123 { |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2124 for(level=0; level<s->spatial_decomposition_count; level++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2125 for(orientation=level ? 1 : 0; orientation<4; orientation++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2126 SubBand *b= &p->band[level][orientation]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2127 unpack_coeffs(s, b, b->parent, orientation); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2128 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2129 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2130 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2131 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2132 { |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2133 const int mb_h= s->b_height << s->block_max_depth; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2134 const int block_size = MB_SIZE >> s->block_max_depth; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2135 const int block_w = plane_index ? block_size/2 : block_size; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2136 int mb_y; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2137 DWTCompose cs[MAX_DECOMPOSITIONS]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2138 int yd=0, yq=0; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2139 int y; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2140 int end_y; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2141 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2142 ff_spatial_idwt_buffered_init(cs, &s->sb, w, h, 1, s->spatial_decomposition_type, s->spatial_decomposition_count); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2143 for(mb_y=0; mb_y<=mb_h; mb_y++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2144 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2145 int slice_starty = block_w*mb_y; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2146 int slice_h = block_w*(mb_y+1); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2147 if (!(s->keyframe || s->avctx->debug&512)){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2148 slice_starty = FFMAX(0, slice_starty - (block_w >> 1)); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2149 slice_h -= (block_w >> 1); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2150 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2151 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2152 for(level=0; level<s->spatial_decomposition_count; level++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2153 for(orientation=level ? 1 : 0; orientation<4; orientation++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2154 SubBand *b= &p->band[level][orientation]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2155 int start_y; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2156 int end_y; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2157 int our_mb_start = mb_y; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2158 int our_mb_end = (mb_y + 1); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2159 const int extra= 3; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2160 start_y = (mb_y ? ((block_w * our_mb_start) >> (s->spatial_decomposition_count - level)) + s->spatial_decomposition_count - level + extra: 0); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2161 end_y = (((block_w * our_mb_end) >> (s->spatial_decomposition_count - level)) + s->spatial_decomposition_count - level + extra); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2162 if (!(s->keyframe || s->avctx->debug&512)){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2163 start_y = FFMAX(0, start_y - (block_w >> (1+s->spatial_decomposition_count - level))); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2164 end_y = FFMAX(0, end_y - (block_w >> (1+s->spatial_decomposition_count - level))); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2165 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2166 start_y = FFMIN(b->height, start_y); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2167 end_y = FFMIN(b->height, end_y); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2168 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2169 if (start_y != end_y){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2170 if (orientation == 0){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2171 SubBand * correlate_band = &p->band[0][0]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2172 int correlate_end_y = FFMIN(b->height, end_y + 1); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2173 int correlate_start_y = FFMIN(b->height, (start_y ? start_y + 1 : 0)); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2174 decode_subband_slice_buffered(s, correlate_band, &s->sb, correlate_start_y, correlate_end_y, decode_state[0][0]); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2175 correlate_slice_buffered(s, &s->sb, correlate_band, correlate_band->ibuf, correlate_band->stride, 1, 0, correlate_start_y, correlate_end_y); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2176 dequantize_slice_buffered(s, &s->sb, correlate_band, correlate_band->ibuf, correlate_band->stride, start_y, end_y); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2177 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2178 else |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2179 decode_subband_slice_buffered(s, b, &s->sb, start_y, end_y, decode_state[level][orientation]); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2180 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2181 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2182 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2183 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2184 for(; yd<slice_h; yd+=4){ |
11485 | 2185 ff_spatial_idwt_buffered_slice(&s->dwt, cs, &s->sb, w, h, 1, s->spatial_decomposition_type, s->spatial_decomposition_count, yd); |
10188
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2186 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2187 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2188 if(s->qlog == LOSSLESS_QLOG){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2189 for(; yq<slice_h && yq<h; yq++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2190 IDWTELEM * line = slice_buffer_get_line(&s->sb, yq); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2191 for(x=0; x<w; x++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2192 line[x] <<= FRAC_BITS; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2193 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2194 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2195 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2196 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2197 predict_slice_buffered(s, &s->sb, s->spatial_idwt_buffer, plane_index, 1, mb_y); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2198 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2199 y = FFMIN(p->height, slice_starty); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2200 end_y = FFMIN(p->height, slice_h); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2201 while(y < end_y) |
11486 | 2202 ff_slice_buffer_release(&s->sb, y++); |
10188
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2203 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2204 |
11486 | 2205 ff_slice_buffer_flush(&s->sb); |
10188
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2206 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2207 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2208 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2209 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2210 emms_c(); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2211 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2212 release_buffer(avctx); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2213 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2214 if(!(s->avctx->debug&2048)) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2215 *picture= s->current_picture; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2216 else |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2217 *picture= s->mconly_picture; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2218 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2219 *data_size = sizeof(AVFrame); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2220 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2221 bytes_read= c->bytestream - c->bytestream_start; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2222 if(bytes_read ==0) av_log(s->avctx, AV_LOG_ERROR, "error at end of frame\n"); //FIXME |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2223 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2224 return bytes_read; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2225 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2226 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2227 static av_cold int decode_end(AVCodecContext *avctx) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2228 { |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2229 SnowContext *s = avctx->priv_data; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2230 |
11486 | 2231 ff_slice_buffer_destroy(&s->sb); |
10188
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2232 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2233 common_end(s); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2234 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2235 return 0; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2236 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2237 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2238 AVCodec snow_decoder = { |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2239 "snow", |
11560
8a4984c5cacc
Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents:
11486
diff
changeset
|
2240 AVMEDIA_TYPE_VIDEO, |
10188
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2241 CODEC_ID_SNOW, |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2242 sizeof(SnowContext), |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2243 decode_init, |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2244 NULL, |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2245 decode_end, |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2246 decode_frame, |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2247 CODEC_CAP_DR1 /*| CODEC_CAP_DRAW_HORIZ_BAND*/, |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2248 NULL, |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2249 .long_name = NULL_IF_CONFIG_SMALL("Snow"), |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2250 }; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2251 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2252 #if CONFIG_SNOW_ENCODER |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2253 static av_cold int encode_init(AVCodecContext *avctx) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2254 { |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2255 SnowContext *s = avctx->priv_data; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2256 int plane_index; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2257 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2258 if(avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2259 av_log(avctx, AV_LOG_ERROR, "This codec is under development, files encoded with it may not be decodable with future versions!!!\n" |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2260 "Use vstrict=-2 / -strict -2 to use it anyway.\n"); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2261 return -1; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2262 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2263 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2264 if(avctx->prediction_method == DWT_97 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2265 && (avctx->flags & CODEC_FLAG_QSCALE) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2266 && avctx->global_quality == 0){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2267 av_log(avctx, AV_LOG_ERROR, "The 9/7 wavelet is incompatible with lossless mode.\n"); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2268 return -1; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2269 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2270 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2271 s->spatial_decomposition_type= avctx->prediction_method; //FIXME add decorrelator type r transform_type |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2272 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2273 s->mv_scale = (avctx->flags & CODEC_FLAG_QPEL) ? 2 : 4; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2274 s->block_max_depth= (avctx->flags & CODEC_FLAG_4MV ) ? 1 : 0; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2275 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2276 for(plane_index=0; plane_index<3; plane_index++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2277 s->plane[plane_index].diag_mc= 1; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2278 s->plane[plane_index].htaps= 6; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2279 s->plane[plane_index].hcoeff[0]= 40; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2280 s->plane[plane_index].hcoeff[1]= -10; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2281 s->plane[plane_index].hcoeff[2]= 2; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2282 s->plane[plane_index].fast_mc= 1; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2283 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2284 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2285 common_init(avctx); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2286 alloc_blocks(s); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2287 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2288 s->version=0; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2289 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2290 s->m.avctx = avctx; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2291 s->m.flags = avctx->flags; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2292 s->m.bit_rate= avctx->bit_rate; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2293 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2294 s->m.me.temp = |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2295 s->m.me.scratchpad= av_mallocz((avctx->width+64)*2*16*2*sizeof(uint8_t)); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2296 s->m.me.map = av_mallocz(ME_MAP_SIZE*sizeof(uint32_t)); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2297 s->m.me.score_map = av_mallocz(ME_MAP_SIZE*sizeof(uint32_t)); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2298 s->m.obmc_scratchpad= av_mallocz(MB_SIZE*MB_SIZE*12*sizeof(uint32_t)); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2299 h263_encode_init(&s->m); //mv_penalty |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2300 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2301 s->max_ref_frames = FFMAX(FFMIN(avctx->refs, MAX_REF_FRAMES), 1); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2302 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2303 if(avctx->flags&CODEC_FLAG_PASS1){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2304 if(!avctx->stats_out) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2305 avctx->stats_out = av_mallocz(256); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2306 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2307 if((avctx->flags&CODEC_FLAG_PASS2) || !(avctx->flags&CODEC_FLAG_QSCALE)){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2308 if(ff_rate_control_init(&s->m) < 0) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2309 return -1; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2310 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2311 s->pass1_rc= !(avctx->flags & (CODEC_FLAG_QSCALE|CODEC_FLAG_PASS2)); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2312 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2313 avctx->coded_frame= &s->current_picture; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2314 switch(avctx->pix_fmt){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2315 // case PIX_FMT_YUV444P: |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2316 // case PIX_FMT_YUV422P: |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2317 case PIX_FMT_YUV420P: |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2318 case PIX_FMT_GRAY8: |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2319 // case PIX_FMT_YUV411P: |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2320 // case PIX_FMT_YUV410P: |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2321 s->colorspace_type= 0; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2322 break; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2323 /* case PIX_FMT_RGB32: |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2324 s->colorspace= 1; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2325 break;*/ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2326 default: |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2327 av_log(avctx, AV_LOG_ERROR, "pixel format not supported\n"); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2328 return -1; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2329 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2330 // avcodec_get_chroma_sub_sample(avctx->pix_fmt, &s->chroma_h_shift, &s->chroma_v_shift); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2331 s->chroma_h_shift= 1; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2332 s->chroma_v_shift= 1; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2333 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2334 ff_set_cmp(&s->dsp, s->dsp.me_cmp, s->avctx->me_cmp); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2335 ff_set_cmp(&s->dsp, s->dsp.me_sub_cmp, s->avctx->me_sub_cmp); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2336 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2337 s->avctx->get_buffer(s->avctx, &s->input_picture); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2338 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2339 if(s->avctx->me_method == ME_ITER){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2340 int i; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2341 int size= s->b_width * s->b_height << 2*s->block_max_depth; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2342 for(i=0; i<s->max_ref_frames; i++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2343 s->ref_mvs[i]= av_mallocz(size*sizeof(int16_t[2])); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2344 s->ref_scores[i]= av_mallocz(size*sizeof(uint32_t)); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2345 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2346 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2347 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2348 return 0; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2349 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2350 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2351 //near copy & paste from dsputil, FIXME |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2352 static int pix_sum(uint8_t * pix, int line_size, int w) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2353 { |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2354 int s, i, j; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2355 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2356 s = 0; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2357 for (i = 0; i < w; i++) { |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2358 for (j = 0; j < w; j++) { |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2359 s += pix[0]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2360 pix ++; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2361 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2362 pix += line_size - w; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2363 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2364 return s; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2365 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2366 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2367 //near copy & paste from dsputil, FIXME |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2368 static int pix_norm1(uint8_t * pix, int line_size, int w) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2369 { |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2370 int s, i, j; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2371 uint32_t *sq = ff_squareTbl + 256; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2372 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2373 s = 0; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2374 for (i = 0; i < w; i++) { |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2375 for (j = 0; j < w; j ++) { |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2376 s += sq[pix[0]]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2377 pix ++; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2378 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2379 pix += line_size - w; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2380 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2381 return s; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2382 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2383 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2384 //FIXME copy&paste |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2385 #define P_LEFT P[1] |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2386 #define P_TOP P[2] |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2387 #define P_TOPRIGHT P[3] |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2388 #define P_MEDIAN P[4] |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2389 #define P_MV1 P[9] |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2390 #define FLAG_QPEL 1 //must be 1 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2391 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2392 static int encode_q_branch(SnowContext *s, int level, int x, int y){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2393 uint8_t p_buffer[1024]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2394 uint8_t i_buffer[1024]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2395 uint8_t p_state[sizeof(s->block_state)]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2396 uint8_t i_state[sizeof(s->block_state)]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2397 RangeCoder pc, ic; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2398 uint8_t *pbbak= s->c.bytestream; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2399 uint8_t *pbbak_start= s->c.bytestream_start; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2400 int score, score2, iscore, i_len, p_len, block_s, sum, base_bits; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2401 const int w= s->b_width << s->block_max_depth; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2402 const int h= s->b_height << s->block_max_depth; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2403 const int rem_depth= s->block_max_depth - level; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2404 const int index= (x + y*w) << rem_depth; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2405 const int block_w= 1<<(LOG2_MB_SIZE - level); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2406 int trx= (x+1)<<rem_depth; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2407 int try= (y+1)<<rem_depth; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2408 const BlockNode *left = x ? &s->block[index-1] : &null_block; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2409 const BlockNode *top = y ? &s->block[index-w] : &null_block; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2410 const BlockNode *right = trx<w ? &s->block[index+1] : &null_block; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2411 const BlockNode *bottom= try<h ? &s->block[index+w] : &null_block; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2412 const BlockNode *tl = y && x ? &s->block[index-w-1] : left; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2413 const BlockNode *tr = y && trx<w && ((x&1)==0 || level==0) ? &s->block[index-w+(1<<rem_depth)] : tl; //FIXME use lt |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2414 int pl = left->color[0]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2415 int pcb= left->color[1]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2416 int pcr= left->color[2]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2417 int pmx, pmy; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2418 int mx=0, my=0; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2419 int l,cr,cb; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2420 const int stride= s->current_picture.linesize[0]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2421 const int uvstride= s->current_picture.linesize[1]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2422 uint8_t *current_data[3]= { s->input_picture.data[0] + (x + y* stride)*block_w, |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2423 s->input_picture.data[1] + (x + y*uvstride)*block_w/2, |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2424 s->input_picture.data[2] + (x + y*uvstride)*block_w/2}; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2425 int P[10][2]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2426 int16_t last_mv[3][2]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2427 int qpel= !!(s->avctx->flags & CODEC_FLAG_QPEL); //unused |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2428 const int shift= 1+qpel; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2429 MotionEstContext *c= &s->m.me; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2430 int ref_context= av_log2(2*left->ref) + av_log2(2*top->ref); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2431 int mx_context= av_log2(2*FFABS(left->mx - top->mx)); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2432 int my_context= av_log2(2*FFABS(left->my - top->my)); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2433 int s_context= 2*left->level + 2*top->level + tl->level + tr->level; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2434 int ref, best_ref, ref_score, ref_mx, ref_my; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2435 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2436 assert(sizeof(s->block_state) >= 256); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2437 if(s->keyframe){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2438 set_blocks(s, level, x, y, pl, pcb, pcr, 0, 0, 0, BLOCK_INTRA); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2439 return 0; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2440 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2441 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2442 // clip predictors / edge ? |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2443 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2444 P_LEFT[0]= left->mx; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2445 P_LEFT[1]= left->my; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2446 P_TOP [0]= top->mx; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2447 P_TOP [1]= top->my; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2448 P_TOPRIGHT[0]= tr->mx; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2449 P_TOPRIGHT[1]= tr->my; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2450 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2451 last_mv[0][0]= s->block[index].mx; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2452 last_mv[0][1]= s->block[index].my; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2453 last_mv[1][0]= right->mx; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2454 last_mv[1][1]= right->my; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2455 last_mv[2][0]= bottom->mx; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2456 last_mv[2][1]= bottom->my; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2457 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2458 s->m.mb_stride=2; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2459 s->m.mb_x= |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2460 s->m.mb_y= 0; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2461 c->skip= 0; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2462 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2463 assert(c-> stride == stride); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2464 assert(c->uvstride == uvstride); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2465 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2466 c->penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_cmp); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2467 c->sub_penalty_factor= get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_sub_cmp); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2468 c->mb_penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->mb_cmp); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2469 c->current_mv_penalty= c->mv_penalty[s->m.f_code=1] + MAX_MV; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2470 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2471 c->xmin = - x*block_w - 16+3; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2472 c->ymin = - y*block_w - 16+3; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2473 c->xmax = - (x+1)*block_w + (w<<(LOG2_MB_SIZE - s->block_max_depth)) + 16-3; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2474 c->ymax = - (y+1)*block_w + (h<<(LOG2_MB_SIZE - s->block_max_depth)) + 16-3; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2475 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2476 if(P_LEFT[0] > (c->xmax<<shift)) P_LEFT[0] = (c->xmax<<shift); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2477 if(P_LEFT[1] > (c->ymax<<shift)) P_LEFT[1] = (c->ymax<<shift); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2478 if(P_TOP[0] > (c->xmax<<shift)) P_TOP[0] = (c->xmax<<shift); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2479 if(P_TOP[1] > (c->ymax<<shift)) P_TOP[1] = (c->ymax<<shift); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2480 if(P_TOPRIGHT[0] < (c->xmin<<shift)) P_TOPRIGHT[0]= (c->xmin<<shift); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2481 if(P_TOPRIGHT[0] > (c->xmax<<shift)) P_TOPRIGHT[0]= (c->xmax<<shift); //due to pmx no clip |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2482 if(P_TOPRIGHT[1] > (c->ymax<<shift)) P_TOPRIGHT[1]= (c->ymax<<shift); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2483 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2484 P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2485 P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2486 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2487 if (!y) { |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2488 c->pred_x= P_LEFT[0]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2489 c->pred_y= P_LEFT[1]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2490 } else { |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2491 c->pred_x = P_MEDIAN[0]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2492 c->pred_y = P_MEDIAN[1]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2493 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2494 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2495 score= INT_MAX; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2496 best_ref= 0; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2497 for(ref=0; ref<s->ref_frames; ref++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2498 init_ref(c, current_data, s->last_picture[ref].data, NULL, block_w*x, block_w*y, 0); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2499 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2500 ref_score= ff_epzs_motion_search(&s->m, &ref_mx, &ref_my, P, 0, /*ref_index*/ 0, last_mv, |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2501 (1<<16)>>shift, level-LOG2_MB_SIZE+4, block_w); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2502 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2503 assert(ref_mx >= c->xmin); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2504 assert(ref_mx <= c->xmax); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2505 assert(ref_my >= c->ymin); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2506 assert(ref_my <= c->ymax); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2507 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2508 ref_score= c->sub_motion_search(&s->m, &ref_mx, &ref_my, ref_score, 0, 0, level-LOG2_MB_SIZE+4, block_w); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2509 ref_score= ff_get_mb_score(&s->m, ref_mx, ref_my, 0, 0, level-LOG2_MB_SIZE+4, block_w, 0); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2510 ref_score+= 2*av_log2(2*ref)*c->penalty_factor; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2511 if(s->ref_mvs[ref]){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2512 s->ref_mvs[ref][index][0]= ref_mx; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2513 s->ref_mvs[ref][index][1]= ref_my; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2514 s->ref_scores[ref][index]= ref_score; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2515 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2516 if(score > ref_score){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2517 score= ref_score; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2518 best_ref= ref; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2519 mx= ref_mx; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2520 my= ref_my; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2521 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2522 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2523 //FIXME if mb_cmp != SSE then intra cannot be compared currently and mb_penalty vs. lambda2 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2524 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2525 // subpel search |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2526 base_bits= get_rac_count(&s->c) - 8*(s->c.bytestream - s->c.bytestream_start); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2527 pc= s->c; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2528 pc.bytestream_start= |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2529 pc.bytestream= p_buffer; //FIXME end/start? and at the other stoo |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2530 memcpy(p_state, s->block_state, sizeof(s->block_state)); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2531 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2532 if(level!=s->block_max_depth) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2533 put_rac(&pc, &p_state[4 + s_context], 1); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2534 put_rac(&pc, &p_state[1 + left->type + top->type], 0); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2535 if(s->ref_frames > 1) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2536 put_symbol(&pc, &p_state[128 + 1024 + 32*ref_context], best_ref, 0); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2537 pred_mv(s, &pmx, &pmy, best_ref, left, top, tr); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2538 put_symbol(&pc, &p_state[128 + 32*(mx_context + 16*!!best_ref)], mx - pmx, 1); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2539 put_symbol(&pc, &p_state[128 + 32*(my_context + 16*!!best_ref)], my - pmy, 1); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2540 p_len= pc.bytestream - pc.bytestream_start; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2541 score += (s->lambda2*(get_rac_count(&pc)-base_bits))>>FF_LAMBDA_SHIFT; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2542 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2543 block_s= block_w*block_w; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2544 sum = pix_sum(current_data[0], stride, block_w); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2545 l= (sum + block_s/2)/block_s; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2546 iscore = pix_norm1(current_data[0], stride, block_w) - 2*l*sum + l*l*block_s; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2547 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2548 block_s= block_w*block_w>>2; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2549 sum = pix_sum(current_data[1], uvstride, block_w>>1); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2550 cb= (sum + block_s/2)/block_s; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2551 // iscore += pix_norm1(¤t_mb[1][0], uvstride, block_w>>1) - 2*cb*sum + cb*cb*block_s; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2552 sum = pix_sum(current_data[2], uvstride, block_w>>1); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2553 cr= (sum + block_s/2)/block_s; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2554 // iscore += pix_norm1(¤t_mb[2][0], uvstride, block_w>>1) - 2*cr*sum + cr*cr*block_s; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2555 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2556 ic= s->c; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2557 ic.bytestream_start= |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2558 ic.bytestream= i_buffer; //FIXME end/start? and at the other stoo |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2559 memcpy(i_state, s->block_state, sizeof(s->block_state)); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2560 if(level!=s->block_max_depth) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2561 put_rac(&ic, &i_state[4 + s_context], 1); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2562 put_rac(&ic, &i_state[1 + left->type + top->type], 1); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2563 put_symbol(&ic, &i_state[32], l-pl , 1); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2564 put_symbol(&ic, &i_state[64], cb-pcb, 1); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2565 put_symbol(&ic, &i_state[96], cr-pcr, 1); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2566 i_len= ic.bytestream - ic.bytestream_start; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2567 iscore += (s->lambda2*(get_rac_count(&ic)-base_bits))>>FF_LAMBDA_SHIFT; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2568 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2569 // assert(score==256*256*256*64-1); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2570 assert(iscore < 255*255*256 + s->lambda2*10); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2571 assert(iscore >= 0); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2572 assert(l>=0 && l<=255); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2573 assert(pl>=0 && pl<=255); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2574 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2575 if(level==0){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2576 int varc= iscore >> 8; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2577 int vard= score >> 8; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2578 if (vard <= 64 || vard < varc) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2579 c->scene_change_score+= ff_sqrt(vard) - ff_sqrt(varc); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2580 else |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2581 c->scene_change_score+= s->m.qscale; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2582 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2583 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2584 if(level!=s->block_max_depth){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2585 put_rac(&s->c, &s->block_state[4 + s_context], 0); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2586 score2 = encode_q_branch(s, level+1, 2*x+0, 2*y+0); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2587 score2+= encode_q_branch(s, level+1, 2*x+1, 2*y+0); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2588 score2+= encode_q_branch(s, level+1, 2*x+0, 2*y+1); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2589 score2+= encode_q_branch(s, level+1, 2*x+1, 2*y+1); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2590 score2+= s->lambda2>>FF_LAMBDA_SHIFT; //FIXME exact split overhead |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2591 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2592 if(score2 < score && score2 < iscore) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2593 return score2; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2594 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2595 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2596 if(iscore < score){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2597 pred_mv(s, &pmx, &pmy, 0, left, top, tr); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2598 memcpy(pbbak, i_buffer, i_len); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2599 s->c= ic; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2600 s->c.bytestream_start= pbbak_start; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2601 s->c.bytestream= pbbak + i_len; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2602 set_blocks(s, level, x, y, l, cb, cr, pmx, pmy, 0, BLOCK_INTRA); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2603 memcpy(s->block_state, i_state, sizeof(s->block_state)); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2604 return iscore; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2605 }else{ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2606 memcpy(pbbak, p_buffer, p_len); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2607 s->c= pc; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2608 s->c.bytestream_start= pbbak_start; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2609 s->c.bytestream= pbbak + p_len; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2610 set_blocks(s, level, x, y, pl, pcb, pcr, mx, my, best_ref, 0); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2611 memcpy(s->block_state, p_state, sizeof(s->block_state)); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2612 return score; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2613 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2614 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2615 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2616 static void encode_q_branch2(SnowContext *s, int level, int x, int y){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2617 const int w= s->b_width << s->block_max_depth; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2618 const int rem_depth= s->block_max_depth - level; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2619 const int index= (x + y*w) << rem_depth; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2620 int trx= (x+1)<<rem_depth; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2621 BlockNode *b= &s->block[index]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2622 const BlockNode *left = x ? &s->block[index-1] : &null_block; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2623 const BlockNode *top = y ? &s->block[index-w] : &null_block; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2624 const BlockNode *tl = y && x ? &s->block[index-w-1] : left; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2625 const BlockNode *tr = y && trx<w && ((x&1)==0 || level==0) ? &s->block[index-w+(1<<rem_depth)] : tl; //FIXME use lt |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2626 int pl = left->color[0]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2627 int pcb= left->color[1]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2628 int pcr= left->color[2]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2629 int pmx, pmy; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2630 int ref_context= av_log2(2*left->ref) + av_log2(2*top->ref); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2631 int mx_context= av_log2(2*FFABS(left->mx - top->mx)) + 16*!!b->ref; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2632 int my_context= av_log2(2*FFABS(left->my - top->my)) + 16*!!b->ref; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2633 int s_context= 2*left->level + 2*top->level + tl->level + tr->level; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2634 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2635 if(s->keyframe){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2636 set_blocks(s, level, x, y, pl, pcb, pcr, 0, 0, 0, BLOCK_INTRA); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2637 return; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2638 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2639 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2640 if(level!=s->block_max_depth){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2641 if(same_block(b,b+1) && same_block(b,b+w) && same_block(b,b+w+1)){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2642 put_rac(&s->c, &s->block_state[4 + s_context], 1); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2643 }else{ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2644 put_rac(&s->c, &s->block_state[4 + s_context], 0); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2645 encode_q_branch2(s, level+1, 2*x+0, 2*y+0); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2646 encode_q_branch2(s, level+1, 2*x+1, 2*y+0); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2647 encode_q_branch2(s, level+1, 2*x+0, 2*y+1); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2648 encode_q_branch2(s, level+1, 2*x+1, 2*y+1); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2649 return; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2650 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2651 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2652 if(b->type & BLOCK_INTRA){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2653 pred_mv(s, &pmx, &pmy, 0, left, top, tr); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2654 put_rac(&s->c, &s->block_state[1 + (left->type&1) + (top->type&1)], 1); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2655 put_symbol(&s->c, &s->block_state[32], b->color[0]-pl , 1); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2656 put_symbol(&s->c, &s->block_state[64], b->color[1]-pcb, 1); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2657 put_symbol(&s->c, &s->block_state[96], b->color[2]-pcr, 1); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2658 set_blocks(s, level, x, y, b->color[0], b->color[1], b->color[2], pmx, pmy, 0, BLOCK_INTRA); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2659 }else{ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2660 pred_mv(s, &pmx, &pmy, b->ref, left, top, tr); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2661 put_rac(&s->c, &s->block_state[1 + (left->type&1) + (top->type&1)], 0); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2662 if(s->ref_frames > 1) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2663 put_symbol(&s->c, &s->block_state[128 + 1024 + 32*ref_context], b->ref, 0); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2664 put_symbol(&s->c, &s->block_state[128 + 32*mx_context], b->mx - pmx, 1); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2665 put_symbol(&s->c, &s->block_state[128 + 32*my_context], b->my - pmy, 1); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2666 set_blocks(s, level, x, y, pl, pcb, pcr, b->mx, b->my, b->ref, 0); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2667 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2668 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2669 |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2670 static int get_dc(SnowContext *s, int mb_x, int mb_y, int plane_index){ |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2671 int i, x2, y2; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2672 Plane *p= &s->plane[plane_index]; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2673 const int block_size = MB_SIZE >> s->block_max_depth; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2674 const int block_w = plane_index ? block_size/2 : block_size; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2675 const uint8_t *obmc = plane_index ? obmc_tab[s->block_max_depth+1] : obmc_tab[s->block_max_depth]; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2676 const int obmc_stride= plane_index ? block_size : 2*block_size; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2677 const int ref_stride= s->current_picture.linesize[plane_index]; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2678 uint8_t *src= s-> input_picture.data[plane_index]; |
5587
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
2679 IDWTELEM *dst= (IDWTELEM*)s->m.obmc_scratchpad + plane_index*block_size*block_size*4; //FIXME change to unsigned |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2680 const int b_stride = s->b_width << s->block_max_depth; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2681 const int w= p->width; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2682 const int h= p->height; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2683 int index= mb_x + mb_y*b_stride; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2684 BlockNode *b= &s->block[index]; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2685 BlockNode backup= *b; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2686 int ab=0; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2687 int aa=0; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2688 |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2689 b->type|= BLOCK_INTRA; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2690 b->color[plane_index]= 0; |
5587
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
2691 memset(dst, 0, obmc_stride*obmc_stride*sizeof(IDWTELEM)); |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2692 |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2693 for(i=0; i<4; i++){ |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2694 int mb_x2= mb_x + (i &1) - 1; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2695 int mb_y2= mb_y + (i>>1) - 1; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2696 int x= block_w*mb_x2 + block_w/2; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2697 int y= block_w*mb_y2 + block_w/2; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2698 |
3662
fc714e9a5419
snow cosmetics: merge the sliced and non-sliced versions of add_yblock
lorenm
parents:
3661
diff
changeset
|
2699 add_yblock(s, 0, NULL, dst + ((i&1)+(i>>1)*obmc_stride)*block_w, NULL, obmc, |
3033
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
2700 x, y, block_w, block_w, w, h, obmc_stride, ref_stride, obmc_stride, mb_x2, mb_y2, 0, 0, plane_index); |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2701 |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2702 for(y2= FFMAX(y, 0); y2<FFMIN(h, y+block_w); y2++){ |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2703 for(x2= FFMAX(x, 0); x2<FFMIN(w, x+block_w); x2++){ |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2704 int index= x2-(block_w*mb_x - block_w/2) + (y2-(block_w*mb_y - block_w/2))*obmc_stride; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2705 int obmc_v= obmc[index]; |
3033
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
2706 int d; |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2707 if(y<0) obmc_v += obmc[index + block_w*obmc_stride]; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2708 if(x<0) obmc_v += obmc[index + block_w]; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2709 if(y+block_w>h) obmc_v += obmc[index - block_w*obmc_stride]; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2710 if(x+block_w>w) obmc_v += obmc[index - block_w]; |
6412 | 2711 //FIXME precalculate this or simplify it somehow else |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2712 |
3033
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
2713 d = -dst[index] + (1<<(FRAC_BITS-1)); |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
2714 dst[index] = d; |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
2715 ab += (src[x2 + y2*ref_stride] - (d>>FRAC_BITS)) * obmc_v; |
6412 | 2716 aa += obmc_v * obmc_v; //FIXME precalculate this |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2717 } |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2718 } |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2719 } |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2720 *b= backup; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2721 |
5127 | 2722 return av_clip(((ab<<LOG2_OBMC_MAX) + aa/2)/aa, 0, 255); //FIXME we should not need clipping |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2723 } |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2724 |
3051 | 2725 static inline int get_block_bits(SnowContext *s, int x, int y, int w){ |
2726 const int b_stride = s->b_width << s->block_max_depth; | |
2727 const int b_height = s->b_height<< s->block_max_depth; | |
2728 int index= x + y*b_stride; | |
4408
c3be13eac2d6
Bring down the number of snow.c warnings from 27 to 17 by using the const
takis
parents:
4407
diff
changeset
|
2729 const BlockNode *b = &s->block[index]; |
c3be13eac2d6
Bring down the number of snow.c warnings from 27 to 17 by using the const
takis
parents:
4407
diff
changeset
|
2730 const BlockNode *left = x ? &s->block[index-1] : &null_block; |
c3be13eac2d6
Bring down the number of snow.c warnings from 27 to 17 by using the const
takis
parents:
4407
diff
changeset
|
2731 const BlockNode *top = y ? &s->block[index-b_stride] : &null_block; |
c3be13eac2d6
Bring down the number of snow.c warnings from 27 to 17 by using the const
takis
parents:
4407
diff
changeset
|
2732 const BlockNode *tl = y && x ? &s->block[index-b_stride-1] : left; |
c3be13eac2d6
Bring down the number of snow.c warnings from 27 to 17 by using the const
takis
parents:
4407
diff
changeset
|
2733 const BlockNode *tr = y && x+w<b_stride ? &s->block[index-b_stride+w] : tl; |
3051 | 2734 int dmx, dmy; |
4001 | 2735 // int mx_context= av_log2(2*FFABS(left->mx - top->mx)); |
2736 // int my_context= av_log2(2*FFABS(left->my - top->my)); | |
3051 | 2737 |
2738 if(x<0 || x>=b_stride || y>=b_height) | |
2739 return 0; | |
2740 /* | |
2741 1 0 0 | |
2742 01X 1-2 1 | |
2743 001XX 3-6 2-3 | |
2744 0001XXX 7-14 4-7 | |
2745 00001XXXX 15-30 8-15 | |
2746 */ | |
2747 //FIXME try accurate rate | |
6412 | 2748 //FIXME intra and inter predictors if surrounding blocks are not the same type |
3051 | 2749 if(b->type & BLOCK_INTRA){ |
4001 | 2750 return 3+2*( av_log2(2*FFABS(left->color[0] - b->color[0])) |
2751 + av_log2(2*FFABS(left->color[1] - b->color[1])) | |
2752 + av_log2(2*FFABS(left->color[2] - b->color[2]))); | |
3325
c2a017de6bea
Snow: scale predicted mv based on which reference frame the neighbors used.
lorenm
parents:
3324
diff
changeset
|
2753 }else{ |
c2a017de6bea
Snow: scale predicted mv based on which reference frame the neighbors used.
lorenm
parents:
3324
diff
changeset
|
2754 pred_mv(s, &dmx, &dmy, b->ref, left, top, tr); |
c2a017de6bea
Snow: scale predicted mv based on which reference frame the neighbors used.
lorenm
parents:
3324
diff
changeset
|
2755 dmx-= b->mx; |
c2a017de6bea
Snow: scale predicted mv based on which reference frame the neighbors used.
lorenm
parents:
3324
diff
changeset
|
2756 dmy-= b->my; |
4001 | 2757 return 2*(1 + av_log2(2*FFABS(dmx)) //FIXME kill the 2* can be merged in lambda |
2758 + av_log2(2*FFABS(dmy)) | |
3314 | 2759 + av_log2(2*b->ref)); |
3325
c2a017de6bea
Snow: scale predicted mv based on which reference frame the neighbors used.
lorenm
parents:
3324
diff
changeset
|
2760 } |
3051 | 2761 } |
2762 | |
3033
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
2763 static int get_block_rd(SnowContext *s, int mb_x, int mb_y, int plane_index, const uint8_t *obmc_edged){ |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2764 Plane *p= &s->plane[plane_index]; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2765 const int block_size = MB_SIZE >> s->block_max_depth; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2766 const int block_w = plane_index ? block_size/2 : block_size; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2767 const int obmc_stride= plane_index ? block_size : 2*block_size; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2768 const int ref_stride= s->current_picture.linesize[plane_index]; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2769 uint8_t *dst= s->current_picture.data[plane_index]; |
3033
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
2770 uint8_t *src= s-> input_picture.data[plane_index]; |
5587
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
2771 IDWTELEM *pred= (IDWTELEM*)s->m.obmc_scratchpad + plane_index*block_size*block_size*4; |
8214
c5276ad92ff8
snow: move scratch buffer from stack to malloced buffer in context
mru
parents:
7622
diff
changeset
|
2772 uint8_t *cur = s->scratchbuf; |
5652
941e5deeb2a4
rename HTAPS -> HTAPS_MAX (later is correct after the previous change)
michael
parents:
5651
diff
changeset
|
2773 uint8_t tmp[ref_stride*(2*MB_SIZE+HTAPS_MAX-1)]; |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2774 const int b_stride = s->b_width << s->block_max_depth; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2775 const int b_height = s->b_height<< s->block_max_depth; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2776 const int w= p->width; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2777 const int h= p->height; |
3033
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
2778 int distortion; |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2779 int rate= 0; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2780 const int penalty_factor= get_penalty_factor(s->lambda, s->lambda2, s->avctx->me_cmp); |
3033
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
2781 int sx= block_w*mb_x - block_w/2; |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
2782 int sy= block_w*mb_y - block_w/2; |
3206 | 2783 int x0= FFMAX(0,-sx); |
2784 int y0= FFMAX(0,-sy); | |
2785 int x1= FFMIN(block_w*2, w-sx); | |
2786 int y1= FFMIN(block_w*2, h-sy); | |
3033
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
2787 int i,x,y; |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
2788 |
3314 | 2789 pred_block(s, cur, tmp, ref_stride, sx, sy, block_w*2, block_w*2, &s->block[mb_x + mb_y*b_stride], plane_index, w, h); |
3033
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
2790 |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
2791 for(y=y0; y<y1; y++){ |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
2792 const uint8_t *obmc1= obmc_edged + y*obmc_stride; |
5587
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
2793 const IDWTELEM *pred1 = pred + y*obmc_stride; |
3033
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
2794 uint8_t *cur1 = cur + y*ref_stride; |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
2795 uint8_t *dst1 = dst + sx + (sy+y)*ref_stride; |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
2796 for(x=x0; x<x1; x++){ |
5587
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
2797 #if FRAC_BITS >= LOG2_OBMC_MAX |
3033
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
2798 int v = (cur1[x] * obmc1[x]) << (FRAC_BITS - LOG2_OBMC_MAX); |
5587
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
2799 #else |
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
2800 int v = (cur1[x] * obmc1[x] + (1<<(LOG2_OBMC_MAX - FRAC_BITS-1))) >> (LOG2_OBMC_MAX - FRAC_BITS); |
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
2801 #endif |
3033
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
2802 v = (v + pred1[x]) >> FRAC_BITS; |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
2803 if(v&(~255)) v= ~(v>>31); |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
2804 dst1[x] = v; |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2805 } |
3033
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
2806 } |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
2807 |
3206 | 2808 /* copy the regions where obmc[] = (uint8_t)256 */ |
2809 if(LOG2_OBMC_MAX == 8 | |
2810 && (mb_x == 0 || mb_x == b_stride-1) | |
2811 && (mb_y == 0 || mb_y == b_height-1)){ | |
2812 if(mb_x == 0) | |
2813 x1 = block_w; | |
2814 else | |
2815 x0 = block_w; | |
2816 if(mb_y == 0) | |
2817 y1 = block_w; | |
2818 else | |
2819 y0 = block_w; | |
2820 for(y=y0; y<y1; y++) | |
2821 memcpy(dst + sx+x0 + (sy+y)*ref_stride, cur + x0 + y*ref_stride, x1-x0); | |
2822 } | |
2823 | |
3033
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
2824 if(block_w==16){ |
3323
87c54a3f8d19
Snow: fix subband weighting in wavelet cmp functions. use 32x32 cmp in iterative motion estimation.
lorenm
parents:
3322
diff
changeset
|
2825 /* FIXME rearrange dsputil to fit 32x32 cmp functions */ |
87c54a3f8d19
Snow: fix subband weighting in wavelet cmp functions. use 32x32 cmp in iterative motion estimation.
lorenm
parents:
3322
diff
changeset
|
2826 /* FIXME check alignment of the cmp wavelet vs the encoding wavelet */ |
6412 | 2827 /* FIXME cmps overlap but do not cover the wavelet's whole support. |
2828 * So improving the score of one block is not strictly guaranteed | |
2829 * to improve the score of the whole frame, thus iterative motion | |
2830 * estimation does not always converge. */ | |
3323
87c54a3f8d19
Snow: fix subband weighting in wavelet cmp functions. use 32x32 cmp in iterative motion estimation.
lorenm
parents:
3322
diff
changeset
|
2831 if(s->avctx->me_cmp == FF_CMP_W97) |
11486 | 2832 distortion = ff_w97_32_c(&s->m, src + sx + sy*ref_stride, dst + sx + sy*ref_stride, ref_stride, 32); |
3323
87c54a3f8d19
Snow: fix subband weighting in wavelet cmp functions. use 32x32 cmp in iterative motion estimation.
lorenm
parents:
3322
diff
changeset
|
2833 else if(s->avctx->me_cmp == FF_CMP_W53) |
11486 | 2834 distortion = ff_w53_32_c(&s->m, src + sx + sy*ref_stride, dst + sx + sy*ref_stride, ref_stride, 32); |
3323
87c54a3f8d19
Snow: fix subband weighting in wavelet cmp functions. use 32x32 cmp in iterative motion estimation.
lorenm
parents:
3322
diff
changeset
|
2835 else{ |
87c54a3f8d19
Snow: fix subband weighting in wavelet cmp functions. use 32x32 cmp in iterative motion estimation.
lorenm
parents:
3322
diff
changeset
|
2836 distortion = 0; |
87c54a3f8d19
Snow: fix subband weighting in wavelet cmp functions. use 32x32 cmp in iterative motion estimation.
lorenm
parents:
3322
diff
changeset
|
2837 for(i=0; i<4; i++){ |
87c54a3f8d19
Snow: fix subband weighting in wavelet cmp functions. use 32x32 cmp in iterative motion estimation.
lorenm
parents:
3322
diff
changeset
|
2838 int off = sx+16*(i&1) + (sy+16*(i>>1))*ref_stride; |
87c54a3f8d19
Snow: fix subband weighting in wavelet cmp functions. use 32x32 cmp in iterative motion estimation.
lorenm
parents:
3322
diff
changeset
|
2839 distortion += s->dsp.me_cmp[0](&s->m, src + off, dst + off, ref_stride, 16); |
87c54a3f8d19
Snow: fix subband weighting in wavelet cmp functions. use 32x32 cmp in iterative motion estimation.
lorenm
parents:
3322
diff
changeset
|
2840 } |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2841 } |
3033
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
2842 }else{ |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
2843 assert(block_w==8); |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
2844 distortion = s->dsp.me_cmp[0](&s->m, src + sx + sy*ref_stride, dst + sx + sy*ref_stride, ref_stride, block_w*2); |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2845 } |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2846 |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2847 if(plane_index==0){ |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2848 for(i=0; i<4; i++){ |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2849 /* ..RRr |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2850 * .RXx. |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2851 * rxx.. |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2852 */ |
3051 | 2853 rate += get_block_bits(s, mb_x + (i&1) - (i>>1), mb_y + (i>>1), 1); |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2854 } |
3057 | 2855 if(mb_x == b_stride-2) |
2856 rate += get_block_bits(s, mb_x + 1, mb_y + 1, 1); | |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2857 } |
3051 | 2858 return distortion + rate*penalty_factor; |
2859 } | |
2860 | |
2861 static int get_4block_rd(SnowContext *s, int mb_x, int mb_y, int plane_index){ | |
2862 int i, y2; | |
2863 Plane *p= &s->plane[plane_index]; | |
2864 const int block_size = MB_SIZE >> s->block_max_depth; | |
2865 const int block_w = plane_index ? block_size/2 : block_size; | |
2866 const uint8_t *obmc = plane_index ? obmc_tab[s->block_max_depth+1] : obmc_tab[s->block_max_depth]; | |
2867 const int obmc_stride= plane_index ? block_size : 2*block_size; | |
2868 const int ref_stride= s->current_picture.linesize[plane_index]; | |
2869 uint8_t *dst= s->current_picture.data[plane_index]; | |
2870 uint8_t *src= s-> input_picture.data[plane_index]; | |
6426 | 2871 //FIXME zero_dst is const but add_yblock changes dst if add is 0 (this is never the case for dst=zero_dst |
2872 // const has only been removed from zero_dst to suppress a warning | |
2873 static IDWTELEM zero_dst[4096]; //FIXME | |
3051 | 2874 const int b_stride = s->b_width << s->block_max_depth; |
2875 const int w= p->width; | |
2876 const int h= p->height; | |
2877 int distortion= 0; | |
2878 int rate= 0; | |
2879 const int penalty_factor= get_penalty_factor(s->lambda, s->lambda2, s->avctx->me_cmp); | |
2880 | |
2881 for(i=0; i<9; i++){ | |
2882 int mb_x2= mb_x + (i%3) - 1; | |
2883 int mb_y2= mb_y + (i/3) - 1; | |
2884 int x= block_w*mb_x2 + block_w/2; | |
2885 int y= block_w*mb_y2 + block_w/2; | |
2886 | |
3662
fc714e9a5419
snow cosmetics: merge the sliced and non-sliced versions of add_yblock
lorenm
parents:
3661
diff
changeset
|
2887 add_yblock(s, 0, NULL, zero_dst, dst, obmc, |
3051 | 2888 x, y, block_w, block_w, w, h, /*dst_stride*/0, ref_stride, obmc_stride, mb_x2, mb_y2, 1, 1, plane_index); |
2889 | |
2890 //FIXME find a cleaner/simpler way to skip the outside stuff | |
2891 for(y2= y; y2<0; y2++) | |
2892 memcpy(dst + x + y2*ref_stride, src + x + y2*ref_stride, block_w); | |
2893 for(y2= h; y2<y+block_w; y2++) | |
2894 memcpy(dst + x + y2*ref_stride, src + x + y2*ref_stride, block_w); | |
2895 if(x<0){ | |
2896 for(y2= y; y2<y+block_w; y2++) | |
2897 memcpy(dst + x + y2*ref_stride, src + x + y2*ref_stride, -x); | |
2898 } | |
2899 if(x+block_w > w){ | |
2900 for(y2= y; y2<y+block_w; y2++) | |
2901 memcpy(dst + w + y2*ref_stride, src + w + y2*ref_stride, x+block_w - w); | |
2902 } | |
2903 | |
2904 assert(block_w== 8 || block_w==16); | |
2905 distortion += s->dsp.me_cmp[block_w==8](&s->m, src + x + y*ref_stride, dst + x + y*ref_stride, ref_stride, block_w); | |
2906 } | |
2907 | |
2908 if(plane_index==0){ | |
2909 BlockNode *b= &s->block[mb_x+mb_y*b_stride]; | |
2910 int merged= same_block(b,b+1) && same_block(b,b+b_stride) && same_block(b,b+b_stride+1); | |
2911 | |
2912 /* ..RRRr | |
2913 * .RXXx. | |
2914 * .RXXx. | |
2915 * rxxx. | |
2916 */ | |
2917 if(merged) | |
2918 rate = get_block_bits(s, mb_x, mb_y, 2); | |
2919 for(i=merged?4:0; i<9; i++){ | |
2920 static const int dxy[9][2] = {{0,0},{1,0},{0,1},{1,1},{2,0},{2,1},{-1,2},{0,2},{1,2}}; | |
2921 rate += get_block_bits(s, mb_x + dxy[i][0], mb_y + dxy[i][1], 1); | |
2922 } | |
2923 } | |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2924 return distortion + rate*penalty_factor; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2925 } |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
2926 |
10188
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2927 static int encode_subband_c0run(SnowContext *s, SubBand *b, IDWTELEM *src, IDWTELEM *parent, int stride, int orientation){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2928 const int w= b->width; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2929 const int h= b->height; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2930 int x, y; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2931 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2932 if(1){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2933 int run=0; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2934 int runs[w*h]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2935 int run_index=0; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2936 int max_index; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2937 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2938 for(y=0; y<h; y++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2939 for(x=0; x<w; x++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2940 int v, p=0; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2941 int /*ll=0, */l=0, lt=0, t=0, rt=0; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2942 v= src[x + y*stride]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2943 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2944 if(y){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2945 t= src[x + (y-1)*stride]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2946 if(x){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2947 lt= src[x - 1 + (y-1)*stride]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2948 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2949 if(x + 1 < w){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2950 rt= src[x + 1 + (y-1)*stride]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2951 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2952 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2953 if(x){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2954 l= src[x - 1 + y*stride]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2955 /*if(x > 1){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2956 if(orientation==1) ll= src[y + (x-2)*stride]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2957 else ll= src[x - 2 + y*stride]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2958 }*/ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2959 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2960 if(parent){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2961 int px= x>>1; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2962 int py= y>>1; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2963 if(px<b->parent->width && py<b->parent->height) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2964 p= parent[px + py*2*stride]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2965 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2966 if(!(/*ll|*/l|lt|t|rt|p)){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2967 if(v){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2968 runs[run_index++]= run; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2969 run=0; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2970 }else{ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2971 run++; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2972 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2973 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2974 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2975 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2976 max_index= run_index; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2977 runs[run_index++]= run; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2978 run_index=0; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2979 run= runs[run_index++]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2980 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2981 put_symbol2(&s->c, b->state[30], max_index, 0); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2982 if(run_index <= max_index) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2983 put_symbol2(&s->c, b->state[1], run, 3); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2984 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2985 for(y=0; y<h; y++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2986 if(s->c.bytestream_end - s->c.bytestream < w*40){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2987 av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2988 return -1; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2989 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2990 for(x=0; x<w; x++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2991 int v, p=0; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2992 int /*ll=0, */l=0, lt=0, t=0, rt=0; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2993 v= src[x + y*stride]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2994 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2995 if(y){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2996 t= src[x + (y-1)*stride]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2997 if(x){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2998 lt= src[x - 1 + (y-1)*stride]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
2999 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3000 if(x + 1 < w){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3001 rt= src[x + 1 + (y-1)*stride]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3002 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3003 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3004 if(x){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3005 l= src[x - 1 + y*stride]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3006 /*if(x > 1){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3007 if(orientation==1) ll= src[y + (x-2)*stride]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3008 else ll= src[x - 2 + y*stride]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3009 }*/ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3010 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3011 if(parent){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3012 int px= x>>1; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3013 int py= y>>1; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3014 if(px<b->parent->width && py<b->parent->height) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3015 p= parent[px + py*2*stride]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3016 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3017 if(/*ll|*/l|lt|t|rt|p){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3018 int context= av_log2(/*FFABS(ll) + */3*FFABS(l) + FFABS(lt) + 2*FFABS(t) + FFABS(rt) + FFABS(p)); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3019 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3020 put_rac(&s->c, &b->state[0][context], !!v); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3021 }else{ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3022 if(!run){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3023 run= runs[run_index++]; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3024 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3025 if(run_index <= max_index) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3026 put_symbol2(&s->c, b->state[1], run, 3); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3027 assert(v); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3028 }else{ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3029 run--; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3030 assert(!v); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3031 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3032 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3033 if(v){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3034 int context= av_log2(/*FFABS(ll) + */3*FFABS(l) + FFABS(lt) + 2*FFABS(t) + FFABS(rt) + FFABS(p)); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3035 int l2= 2*FFABS(l) + (l<0); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3036 int t2= 2*FFABS(t) + (t<0); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3037 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3038 put_symbol2(&s->c, b->state[context + 2], FFABS(v)-1, context-4); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3039 put_rac(&s->c, &b->state[0][16 + 1 + 3 + quant3bA[l2&0xFF] + 3*quant3bA[t2&0xFF]], v<0); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3040 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3041 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3042 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3043 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3044 return 0; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3045 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3046 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3047 static int encode_subband(SnowContext *s, SubBand *b, IDWTELEM *src, IDWTELEM *parent, int stride, int orientation){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3048 // encode_subband_qtree(s, b, src, parent, stride, orientation); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3049 // encode_subband_z0run(s, b, src, parent, stride, orientation); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3050 return encode_subband_c0run(s, b, src, parent, stride, orientation); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3051 // encode_subband_dzr(s, b, src, parent, stride, orientation); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3052 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3053 |
4283
d6f83e2f8804
rename always_inline to av_always_inline and move to common.h
mru
parents:
4197
diff
changeset
|
3054 static av_always_inline int check_block(SnowContext *s, int mb_x, int mb_y, int p[3], int intra, const uint8_t *obmc_edged, int *best_rd){ |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3055 const int b_stride= s->b_width << s->block_max_depth; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3056 BlockNode *block= &s->block[mb_x + mb_y * b_stride]; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3057 BlockNode backup= *block; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3058 int rd, index, value; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3059 |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3060 assert(mb_x>=0 && mb_y>=0); |
2994 | 3061 assert(mb_x<b_stride); |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3062 |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3063 if(intra){ |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3064 block->color[0] = p[0]; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3065 block->color[1] = p[1]; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3066 block->color[2] = p[2]; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3067 block->type |= BLOCK_INTRA; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3068 }else{ |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3069 index= (p[0] + 31*p[1]) & (ME_CACHE_SIZE-1); |
3314 | 3070 value= s->me_cache_generation + (p[0]>>10) + (p[1]<<6) + (block->ref<<12); |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3071 if(s->me_cache[index] == value) |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3072 return 0; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3073 s->me_cache[index]= value; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3074 |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3075 block->mx= p[0]; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3076 block->my= p[1]; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3077 block->type &= ~BLOCK_INTRA; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3078 } |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3079 |
3033
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3080 rd= get_block_rd(s, mb_x, mb_y, 0, obmc_edged); |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3081 |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3082 //FIXME chroma |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3083 if(rd < *best_rd){ |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3084 *best_rd= rd; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3085 return 1; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3086 }else{ |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3087 *block= backup; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3088 return 0; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3089 } |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3090 } |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3091 |
6412 | 3092 /* special case for int[2] args we discard afterwards, |
3093 * fixes compilation problem with gcc 2.95 */ | |
4283
d6f83e2f8804
rename always_inline to av_always_inline and move to common.h
mru
parents:
4197
diff
changeset
|
3094 static av_always_inline int check_block_inter(SnowContext *s, int mb_x, int mb_y, int p0, int p1, const uint8_t *obmc_edged, int *best_rd){ |
2999
bc83e7a080a5
this fixes compilation with gcc 2.95 which seems to not like array casting... special case inline of check_block which makes the array and passes it
mmu_man
parents:
2998
diff
changeset
|
3095 int p[2] = {p0, p1}; |
3197 | 3096 return check_block(s, mb_x, mb_y, p, 0, obmc_edged, best_rd); |
2999
bc83e7a080a5
this fixes compilation with gcc 2.95 which seems to not like array casting... special case inline of check_block which makes the array and passes it
mmu_man
parents:
2998
diff
changeset
|
3097 } |
bc83e7a080a5
this fixes compilation with gcc 2.95 which seems to not like array casting... special case inline of check_block which makes the array and passes it
mmu_man
parents:
2998
diff
changeset
|
3098 |
4283
d6f83e2f8804
rename always_inline to av_always_inline and move to common.h
mru
parents:
4197
diff
changeset
|
3099 static av_always_inline int check_4block_inter(SnowContext *s, int mb_x, int mb_y, int p0, int p1, int ref, int *best_rd){ |
3051 | 3100 const int b_stride= s->b_width << s->block_max_depth; |
3101 BlockNode *block= &s->block[mb_x + mb_y * b_stride]; | |
3102 BlockNode backup[4]= {block[0], block[1], block[b_stride], block[b_stride+1]}; | |
3103 int rd, index, value; | |
3104 | |
3105 assert(mb_x>=0 && mb_y>=0); | |
3106 assert(mb_x<b_stride); | |
3107 assert(((mb_x|mb_y)&1) == 0); | |
3108 | |
3109 index= (p0 + 31*p1) & (ME_CACHE_SIZE-1); | |
3314 | 3110 value= s->me_cache_generation + (p0>>10) + (p1<<6) + (block->ref<<12); |
3051 | 3111 if(s->me_cache[index] == value) |
3112 return 0; | |
3113 s->me_cache[index]= value; | |
3114 | |
3115 block->mx= p0; | |
3116 block->my= p1; | |
3314 | 3117 block->ref= ref; |
3051 | 3118 block->type &= ~BLOCK_INTRA; |
3119 block[1]= block[b_stride]= block[b_stride+1]= *block; | |
3120 | |
3121 rd= get_4block_rd(s, mb_x, mb_y, 0); | |
3122 | |
3123 //FIXME chroma | |
3124 if(rd < *best_rd){ | |
3125 *best_rd= rd; | |
3126 return 1; | |
3127 }else{ | |
3128 block[0]= backup[0]; | |
3129 block[1]= backup[1]; | |
3130 block[b_stride]= backup[2]; | |
3131 block[b_stride+1]= backup[3]; | |
3132 return 0; | |
3133 } | |
3134 } | |
3135 | |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3136 static void iterative_me(SnowContext *s){ |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3137 int pass, mb_x, mb_y; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3138 const int b_width = s->b_width << s->block_max_depth; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3139 const int b_height= s->b_height << s->block_max_depth; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3140 const int b_stride= b_width; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3141 int color[3]; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3142 |
3194
c30e9bcbb716
seed iterative_me with mvs from conventional search.
lorenm
parents:
3193
diff
changeset
|
3143 { |
c30e9bcbb716
seed iterative_me with mvs from conventional search.
lorenm
parents:
3193
diff
changeset
|
3144 RangeCoder r = s->c; |
c30e9bcbb716
seed iterative_me with mvs from conventional search.
lorenm
parents:
3193
diff
changeset
|
3145 uint8_t state[sizeof(s->block_state)]; |
c30e9bcbb716
seed iterative_me with mvs from conventional search.
lorenm
parents:
3193
diff
changeset
|
3146 memcpy(state, s->block_state, sizeof(s->block_state)); |
c30e9bcbb716
seed iterative_me with mvs from conventional search.
lorenm
parents:
3193
diff
changeset
|
3147 for(mb_y= 0; mb_y<s->b_height; mb_y++) |
c30e9bcbb716
seed iterative_me with mvs from conventional search.
lorenm
parents:
3193
diff
changeset
|
3148 for(mb_x= 0; mb_x<s->b_width; mb_x++) |
c30e9bcbb716
seed iterative_me with mvs from conventional search.
lorenm
parents:
3193
diff
changeset
|
3149 encode_q_branch(s, 0, mb_x, mb_y); |
c30e9bcbb716
seed iterative_me with mvs from conventional search.
lorenm
parents:
3193
diff
changeset
|
3150 s->c = r; |
c30e9bcbb716
seed iterative_me with mvs from conventional search.
lorenm
parents:
3193
diff
changeset
|
3151 memcpy(s->block_state, state, sizeof(s->block_state)); |
c30e9bcbb716
seed iterative_me with mvs from conventional search.
lorenm
parents:
3193
diff
changeset
|
3152 } |
c30e9bcbb716
seed iterative_me with mvs from conventional search.
lorenm
parents:
3193
diff
changeset
|
3153 |
3323
87c54a3f8d19
Snow: fix subband weighting in wavelet cmp functions. use 32x32 cmp in iterative motion estimation.
lorenm
parents:
3322
diff
changeset
|
3154 for(pass=0; pass<25; pass++){ |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3155 int change= 0; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3156 |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3157 for(mb_y= 0; mb_y<b_height; mb_y++){ |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3158 for(mb_x= 0; mb_x<b_width; mb_x++){ |
3314 | 3159 int dia_change, i, j, ref; |
3160 int best_rd= INT_MAX, ref_rd; | |
3161 BlockNode backup, ref_b; | |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3162 const int index= mb_x + mb_y * b_stride; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3163 BlockNode *block= &s->block[index]; |
3324 | 3164 BlockNode *tb = mb_y ? &s->block[index-b_stride ] : NULL; |
3165 BlockNode *lb = mb_x ? &s->block[index -1] : NULL; | |
3166 BlockNode *rb = mb_x+1<b_width ? &s->block[index +1] : NULL; | |
3167 BlockNode *bb = mb_y+1<b_height ? &s->block[index+b_stride ] : NULL; | |
3168 BlockNode *tlb= mb_x && mb_y ? &s->block[index-b_stride-1] : NULL; | |
3169 BlockNode *trb= mb_x+1<b_width && mb_y ? &s->block[index-b_stride+1] : NULL; | |
3170 BlockNode *blb= mb_x && mb_y+1<b_height ? &s->block[index+b_stride-1] : NULL; | |
3171 BlockNode *brb= mb_x+1<b_width && mb_y+1<b_height ? &s->block[index+b_stride+1] : NULL; | |
3033
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3172 const int b_w= (MB_SIZE >> s->block_max_depth); |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3173 uint8_t obmc_edged[b_w*2][b_w*2]; |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3174 |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3175 if(pass && (block->type & BLOCK_OPT)) |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3176 continue; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3177 block->type |= BLOCK_OPT; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3178 |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3179 backup= *block; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3180 |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3181 if(!s->me_cache_generation) |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3182 memset(s->me_cache, 0, sizeof(s->me_cache)); |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3183 s->me_cache_generation += 1<<22; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3184 |
6412 | 3185 //FIXME precalculate |
3033
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3186 { |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3187 int x, y; |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3188 memcpy(obmc_edged, obmc_tab[s->block_max_depth], b_w*b_w*4); |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3189 if(mb_x==0) |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3190 for(y=0; y<b_w*2; y++) |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3191 memset(obmc_edged[y], obmc_edged[y][0] + obmc_edged[y][b_w-1], b_w); |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3192 if(mb_x==b_stride-1) |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3193 for(y=0; y<b_w*2; y++) |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3194 memset(obmc_edged[y]+b_w, obmc_edged[y][b_w] + obmc_edged[y][b_w*2-1], b_w); |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3195 if(mb_y==0){ |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3196 for(x=0; x<b_w*2; x++) |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3197 obmc_edged[0][x] += obmc_edged[b_w-1][x]; |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3198 for(y=1; y<b_w; y++) |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3199 memcpy(obmc_edged[y], obmc_edged[0], b_w*2); |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3200 } |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3201 if(mb_y==b_height-1){ |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3202 for(x=0; x<b_w*2; x++) |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3203 obmc_edged[b_w*2-1][x] += obmc_edged[b_w][x]; |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3204 for(y=b_w; y<b_w*2-1; y++) |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3205 memcpy(obmc_edged[y], obmc_edged[b_w*2-1], b_w*2); |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3206 } |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3207 } |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3208 |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3209 //skip stuff outside the picture |
6474
e6995f3fbf7f
cosmetics: Normalize {} placement after for, while, if.
diego
parents:
6437
diff
changeset
|
3210 if(mb_x==0 || mb_y==0 || mb_x==b_width-1 || mb_y==b_height-1){ |
3033
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3211 uint8_t *src= s-> input_picture.data[0]; |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3212 uint8_t *dst= s->current_picture.data[0]; |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3213 const int stride= s->current_picture.linesize[0]; |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3214 const int block_w= MB_SIZE >> s->block_max_depth; |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3215 const int sx= block_w*mb_x - block_w/2; |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3216 const int sy= block_w*mb_y - block_w/2; |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3217 const int w= s->plane[0].width; |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3218 const int h= s->plane[0].height; |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3219 int y; |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3220 |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3221 for(y=sy; y<0; y++) |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3222 memcpy(dst + sx + y*stride, src + sx + y*stride, block_w*2); |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3223 for(y=h; y<sy+block_w*2; y++) |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3224 memcpy(dst + sx + y*stride, src + sx + y*stride, block_w*2); |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3225 if(sx<0){ |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3226 for(y=sy; y<sy+block_w*2; y++) |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3227 memcpy(dst + sx + y*stride, src + sx + y*stride, -sx); |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3228 } |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3229 if(sx+block_w*2 > w){ |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3230 for(y=sy; y<sy+block_w*2; y++) |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3231 memcpy(dst + w + y*stride, src + w + y*stride, sx+block_w*2 - w); |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3232 } |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3233 } |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3234 |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3235 // intra(black) = neighbors' contribution to the current block |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3236 for(i=0; i<3; i++) |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3237 color[i]= get_dc(s, mb_x, mb_y, i); |
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3238 |
5127 | 3239 // get previous score (cannot be cached due to OBMC) |
3057 | 3240 if(pass > 0 && (block->type&BLOCK_INTRA)){ |
3241 int color0[3]= {block->color[0], block->color[1], block->color[2]}; | |
3242 check_block(s, mb_x, mb_y, color0, 1, *obmc_edged, &best_rd); | |
3243 }else | |
3197 | 3244 check_block_inter(s, mb_x, mb_y, block->mx, block->my, *obmc_edged, &best_rd); |
3245 | |
3314 | 3246 ref_b= *block; |
3247 ref_rd= best_rd; | |
3248 for(ref=0; ref < s->ref_frames; ref++){ | |
3249 int16_t (*mvr)[2]= &s->ref_mvs[ref][index]; | |
3250 if(s->ref_scores[ref][index] > s->ref_scores[ref_b.ref][index]*3/2) //FIXME tune threshold | |
3251 continue; | |
3252 block->ref= ref; | |
3253 best_rd= INT_MAX; | |
3254 | |
3255 check_block_inter(s, mb_x, mb_y, mvr[0][0], mvr[0][1], *obmc_edged, &best_rd); | |
3256 check_block_inter(s, mb_x, mb_y, 0, 0, *obmc_edged, &best_rd); | |
3324 | 3257 if(tb) |
3314 | 3258 check_block_inter(s, mb_x, mb_y, mvr[-b_stride][0], mvr[-b_stride][1], *obmc_edged, &best_rd); |
3324 | 3259 if(lb) |
3314 | 3260 check_block_inter(s, mb_x, mb_y, mvr[-1][0], mvr[-1][1], *obmc_edged, &best_rd); |
3324 | 3261 if(rb) |
3314 | 3262 check_block_inter(s, mb_x, mb_y, mvr[1][0], mvr[1][1], *obmc_edged, &best_rd); |
3324 | 3263 if(bb) |
3314 | 3264 check_block_inter(s, mb_x, mb_y, mvr[b_stride][0], mvr[b_stride][1], *obmc_edged, &best_rd); |
3265 | |
3266 /* fullpel ME */ | |
6412 | 3267 //FIXME avoid subpel interpolation / round to nearest integer |
3314 | 3268 do{ |
3269 dia_change=0; | |
3270 for(i=0; i<FFMAX(s->avctx->dia_size, 1); i++){ | |
3271 for(j=0; j<i; j++){ | |
3272 dia_change |= check_block_inter(s, mb_x, mb_y, block->mx+4*(i-j), block->my+(4*j), *obmc_edged, &best_rd); | |
3273 dia_change |= check_block_inter(s, mb_x, mb_y, block->mx-4*(i-j), block->my-(4*j), *obmc_edged, &best_rd); | |
3274 dia_change |= check_block_inter(s, mb_x, mb_y, block->mx+4*(i-j), block->my-(4*j), *obmc_edged, &best_rd); | |
3275 dia_change |= check_block_inter(s, mb_x, mb_y, block->mx-4*(i-j), block->my+(4*j), *obmc_edged, &best_rd); | |
3276 } | |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3277 } |
3314 | 3278 }while(dia_change); |
3279 /* subpel ME */ | |
3280 do{ | |
3281 static const int square[8][2]= {{+1, 0},{-1, 0},{ 0,+1},{ 0,-1},{+1,+1},{-1,-1},{+1,-1},{-1,+1},}; | |
3282 dia_change=0; | |
3283 for(i=0; i<8; i++) | |
3284 dia_change |= check_block_inter(s, mb_x, mb_y, block->mx+square[i][0], block->my+square[i][1], *obmc_edged, &best_rd); | |
3285 }while(dia_change); | |
3286 //FIXME or try the standard 2 pass qpel or similar | |
3287 | |
3288 mvr[0][0]= block->mx; | |
3289 mvr[0][1]= block->my; | |
3290 if(ref_rd > best_rd){ | |
3291 ref_rd= best_rd; | |
3292 ref_b= *block; | |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3293 } |
3314 | 3294 } |
3295 best_rd= ref_rd; | |
3296 *block= ref_b; | |
2998 | 3297 #if 1 |
3033
e8599ab02b38
faster iterative_me: avoid duplicate mc of neighboring blocks.
lorenm
parents:
3020
diff
changeset
|
3298 check_block(s, mb_x, mb_y, color, 1, *obmc_edged, &best_rd); |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3299 //FIXME RD style color selection |
2998 | 3300 #endif |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3301 if(!same_block(block, &backup)){ |
3324 | 3302 if(tb ) tb ->type &= ~BLOCK_OPT; |
3303 if(lb ) lb ->type &= ~BLOCK_OPT; | |
3304 if(rb ) rb ->type &= ~BLOCK_OPT; | |
3305 if(bb ) bb ->type &= ~BLOCK_OPT; | |
3306 if(tlb) tlb->type &= ~BLOCK_OPT; | |
3307 if(trb) trb->type &= ~BLOCK_OPT; | |
3308 if(blb) blb->type &= ~BLOCK_OPT; | |
3309 if(brb) brb->type &= ~BLOCK_OPT; | |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3310 change ++; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3311 } |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3312 } |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3313 } |
10810 | 3314 av_log(s->avctx, AV_LOG_ERROR, "pass:%d changed:%d\n", pass, change); |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3315 if(!change) |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3316 break; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3317 } |
3051 | 3318 |
3319 if(s->block_max_depth == 1){ | |
3320 int change= 0; | |
3321 for(mb_y= 0; mb_y<b_height; mb_y+=2){ | |
3322 for(mb_x= 0; mb_x<b_width; mb_x+=2){ | |
3324 | 3323 int i; |
3051 | 3324 int best_rd, init_rd; |
3325 const int index= mb_x + mb_y * b_stride; | |
3326 BlockNode *b[4]; | |
3327 | |
3328 b[0]= &s->block[index]; | |
3329 b[1]= b[0]+1; | |
3330 b[2]= b[0]+b_stride; | |
3331 b[3]= b[2]+1; | |
3332 if(same_block(b[0], b[1]) && | |
3333 same_block(b[0], b[2]) && | |
3334 same_block(b[0], b[3])) | |
3335 continue; | |
3336 | |
3337 if(!s->me_cache_generation) | |
3338 memset(s->me_cache, 0, sizeof(s->me_cache)); | |
3339 s->me_cache_generation += 1<<22; | |
3340 | |
3341 init_rd= best_rd= get_4block_rd(s, mb_x, mb_y, 0); | |
3342 | |
3314 | 3343 //FIXME more multiref search? |
3051 | 3344 check_4block_inter(s, mb_x, mb_y, |
3345 (b[0]->mx + b[1]->mx + b[2]->mx + b[3]->mx + 2) >> 2, | |
3314 | 3346 (b[0]->my + b[1]->my + b[2]->my + b[3]->my + 2) >> 2, 0, &best_rd); |
3051 | 3347 |
3348 for(i=0; i<4; i++) | |
3349 if(!(b[i]->type&BLOCK_INTRA)) | |
3314 | 3350 check_4block_inter(s, mb_x, mb_y, b[i]->mx, b[i]->my, b[i]->ref, &best_rd); |
3051 | 3351 |
3352 if(init_rd != best_rd) | |
3353 change++; | |
3354 } | |
3355 } | |
10810 | 3356 av_log(s->avctx, AV_LOG_ERROR, "pass:4mv changed:%d\n", change*4); |
3051 | 3357 } |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3358 } |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3359 |
10188
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3360 static void encode_blocks(SnowContext *s, int search){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3361 int x, y; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3362 int w= s->b_width; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3363 int h= s->b_height; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3364 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3365 if(s->avctx->me_method == ME_ITER && !s->keyframe && search) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3366 iterative_me(s); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3367 |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3368 for(y=0; y<h; y++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3369 if(s->c.bytestream_end - s->c.bytestream < w*MB_SIZE*MB_SIZE*3){ //FIXME nicer limit |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3370 av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3371 return; |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3372 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3373 for(x=0; x<w; x++){ |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3374 if(s->avctx->me_method == ME_ITER || !search) |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3375 encode_q_branch2(s, 0, x, y); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3376 else |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3377 encode_q_branch (s, 0, x, y); |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3378 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3379 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3380 } |
404026d9adb5
Reorder functions so that encoding functions are disabled by the preprocessor.
diego
parents:
9808
diff
changeset
|
3381 |
5587
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
3382 static void quantize(SnowContext *s, SubBand *b, IDWTELEM *dst, DWTELEM *src, int stride, int bias){ |
2138 | 3383 const int w= b->width; |
3384 const int h= b->height; | |
4594 | 3385 const int qlog= av_clip(s->qlog + b->qlog, 0, QROOT*16); |
5575 | 3386 const int qmul= qexp[qlog&(QROOT-1)]<<((qlog>>QSHIFT) + ENCODER_EXTRA_BITS); |
2150 | 3387 int x,y, thres1, thres2; |
2138 | 3388 |
5587
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
3389 if(s->qlog == LOSSLESS_QLOG){ |
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
3390 for(y=0; y<h; y++) |
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
3391 for(x=0; x<w; x++) |
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
3392 dst[x + y*stride]= src[x + y*stride]; |
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
3393 return; |
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
3394 } |
2967 | 3395 |
2138 | 3396 bias= bias ? 0 : (3*qmul)>>3; |
2150 | 3397 thres1= ((qmul - bias)>>QEXPSHIFT) - 1; |
3398 thres2= 2*thres1; | |
2967 | 3399 |
2138 | 3400 if(!bias){ |
3401 for(y=0; y<h; y++){ | |
3402 for(x=0; x<w; x++){ | |
2150 | 3403 int i= src[x + y*stride]; |
2967 | 3404 |
2150 | 3405 if((unsigned)(i+thres1) > thres2){ |
3406 if(i>=0){ | |
3407 i<<= QEXPSHIFT; | |
3408 i/= qmul; //FIXME optimize | |
5587
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
3409 dst[x + y*stride]= i; |
2150 | 3410 }else{ |
3411 i= -i; | |
3412 i<<= QEXPSHIFT; | |
3413 i/= qmul; //FIXME optimize | |
5587
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
3414 dst[x + y*stride]= -i; |
2150 | 3415 } |
3416 }else | |
5587
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
3417 dst[x + y*stride]= 0; |
2138 | 3418 } |
3419 } | |
3420 }else{ | |
3421 for(y=0; y<h; y++){ | |
3422 for(x=0; x<w; x++){ | |
2967 | 3423 int i= src[x + y*stride]; |
3424 | |
2150 | 3425 if((unsigned)(i+thres1) > thres2){ |
3426 if(i>=0){ | |
3427 i<<= QEXPSHIFT; | |
3428 i= (i + bias) / qmul; //FIXME optimize | |
5587
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
3429 dst[x + y*stride]= i; |
2150 | 3430 }else{ |
3431 i= -i; | |
3432 i<<= QEXPSHIFT; | |
3433 i= (i + bias) / qmul; //FIXME optimize | |
5587
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
3434 dst[x + y*stride]= -i; |
2150 | 3435 } |
3436 }else | |
5587
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
3437 dst[x + y*stride]= 0; |
2138 | 3438 } |
3439 } | |
3440 } | |
3441 } | |
3442 | |
5587
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
3443 static void dequantize(SnowContext *s, SubBand *b, IDWTELEM *src, int stride){ |
2138 | 3444 const int w= b->width; |
3445 const int h= b->height; | |
4594 | 3446 const int qlog= av_clip(s->qlog + b->qlog, 0, QROOT*16); |
2600 | 3447 const int qmul= qexp[qlog&(QROOT-1)]<<(qlog>>QSHIFT); |
2138 | 3448 const int qadd= (s->qbias*qmul)>>QBIAS_SHIFT; |
3449 int x,y; | |
2967 | 3450 |
2161 | 3451 if(s->qlog == LOSSLESS_QLOG) return; |
2967 | 3452 |
2138 | 3453 for(y=0; y<h; y++){ |
3454 for(x=0; x<w; x++){ | |
3455 int i= src[x + y*stride]; | |
3456 if(i<0){ | |
3457 src[x + y*stride]= -((-i*qmul + qadd)>>(QEXPSHIFT)); //FIXME try different bias | |
3458 }else if(i>0){ | |
3459 src[x + y*stride]= (( i*qmul + qadd)>>(QEXPSHIFT)); | |
3460 } | |
3461 } | |
3462 } | |
3463 } | |
3464 | |
5587
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
3465 static void decorrelate(SnowContext *s, SubBand *b, IDWTELEM *src, int stride, int inverse, int use_median){ |
2138 | 3466 const int w= b->width; |
3467 const int h= b->height; | |
3468 int x,y; | |
2967 | 3469 |
2138 | 3470 for(y=h-1; y>=0; y--){ |
3471 for(x=w-1; x>=0; x--){ | |
3472 int i= x + y*stride; | |
2967 | 3473 |
2138 | 3474 if(x){ |
3475 if(use_median){ | |
3476 if(y && x+1<w) src[i] -= mid_pred(src[i - 1], src[i - stride], src[i - stride + 1]); | |
3477 else src[i] -= src[i - 1]; | |
3478 }else{ | |
3479 if(y) src[i] -= mid_pred(src[i - 1], src[i - stride], src[i - 1] + src[i - stride] - src[i - 1 - stride]); | |
3480 else src[i] -= src[i - 1]; | |
3481 } | |
3482 }else{ | |
3483 if(y) src[i] -= src[i - stride]; | |
3484 } | |
3485 } | |
3486 } | |
3487 } | |
3488 | |
5587
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
3489 static void correlate(SnowContext *s, SubBand *b, IDWTELEM *src, int stride, int inverse, int use_median){ |
2138 | 3490 const int w= b->width; |
3491 const int h= b->height; | |
3492 int x,y; | |
2967 | 3493 |
2138 | 3494 for(y=0; y<h; y++){ |
3495 for(x=0; x<w; x++){ | |
3496 int i= x + y*stride; | |
2967 | 3497 |
2138 | 3498 if(x){ |
3499 if(use_median){ | |
3500 if(y && x+1<w) src[i] += mid_pred(src[i - 1], src[i - stride], src[i - stride + 1]); | |
3501 else src[i] += src[i - 1]; | |
3502 }else{ | |
3503 if(y) src[i] += mid_pred(src[i - 1], src[i - stride], src[i - 1] + src[i - stride] - src[i - 1 - stride]); | |
3504 else src[i] += src[i - 1]; | |
3505 } | |
3506 }else{ | |
3507 if(y) src[i] += src[i - stride]; | |
3508 } | |
3509 } | |
3510 } | |
3511 } | |
3512 | |
5666
b5c137f3f53a
allow changing of the spatial_decomposition_count and quantization tables
michael
parents:
5665
diff
changeset
|
3513 static void encode_qlogs(SnowContext *s){ |
b5c137f3f53a
allow changing of the spatial_decomposition_count and quantization tables
michael
parents:
5665
diff
changeset
|
3514 int plane_index, level, orientation; |
b5c137f3f53a
allow changing of the spatial_decomposition_count and quantization tables
michael
parents:
5665
diff
changeset
|
3515 |
b5c137f3f53a
allow changing of the spatial_decomposition_count and quantization tables
michael
parents:
5665
diff
changeset
|
3516 for(plane_index=0; plane_index<2; plane_index++){ |
b5c137f3f53a
allow changing of the spatial_decomposition_count and quantization tables
michael
parents:
5665
diff
changeset
|
3517 for(level=0; level<s->spatial_decomposition_count; level++){ |
b5c137f3f53a
allow changing of the spatial_decomposition_count and quantization tables
michael
parents:
5665
diff
changeset
|
3518 for(orientation=level ? 1:0; orientation<4; orientation++){ |
b5c137f3f53a
allow changing of the spatial_decomposition_count and quantization tables
michael
parents:
5665
diff
changeset
|
3519 if(orientation==2) continue; |
b5c137f3f53a
allow changing of the spatial_decomposition_count and quantization tables
michael
parents:
5665
diff
changeset
|
3520 put_symbol(&s->c, s->header_state, s->plane[plane_index].band[level][orientation].qlog, 1); |
b5c137f3f53a
allow changing of the spatial_decomposition_count and quantization tables
michael
parents:
5665
diff
changeset
|
3521 } |
b5c137f3f53a
allow changing of the spatial_decomposition_count and quantization tables
michael
parents:
5665
diff
changeset
|
3522 } |
b5c137f3f53a
allow changing of the spatial_decomposition_count and quantization tables
michael
parents:
5665
diff
changeset
|
3523 } |
b5c137f3f53a
allow changing of the spatial_decomposition_count and quantization tables
michael
parents:
5665
diff
changeset
|
3524 } |
b5c137f3f53a
allow changing of the spatial_decomposition_count and quantization tables
michael
parents:
5665
diff
changeset
|
3525 |
2138 | 3526 static void encode_header(SnowContext *s){ |
5666
b5c137f3f53a
allow changing of the spatial_decomposition_count and quantization tables
michael
parents:
5665
diff
changeset
|
3527 int plane_index, i; |
2967 | 3528 uint8_t kstate[32]; |
3529 | |
3530 memset(kstate, MID_STATE, sizeof(kstate)); | |
2138 | 3531 |
2335 | 3532 put_rac(&s->c, kstate, s->keyframe); |
4331
e571dfe677be
store a few values in the header as difference to the last
michael
parents:
4283
diff
changeset
|
3533 if(s->keyframe || s->always_reset){ |
2199 | 3534 reset_contexts(s); |
4331
e571dfe677be
store a few values in the header as difference to the last
michael
parents:
4283
diff
changeset
|
3535 s->last_spatial_decomposition_type= |
e571dfe677be
store a few values in the header as difference to the last
michael
parents:
4283
diff
changeset
|
3536 s->last_qlog= |
e571dfe677be
store a few values in the header as difference to the last
michael
parents:
4283
diff
changeset
|
3537 s->last_qbias= |
e571dfe677be
store a few values in the header as difference to the last
michael
parents:
4283
diff
changeset
|
3538 s->last_mv_scale= |
e571dfe677be
store a few values in the header as difference to the last
michael
parents:
4283
diff
changeset
|
3539 s->last_block_max_depth= 0; |
5651
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
3540 for(plane_index=0; plane_index<2; plane_index++){ |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
3541 Plane *p= &s->plane[plane_index]; |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
3542 p->last_htaps=0; |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
3543 p->last_diag_mc=0; |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
3544 memset(p->last_hcoeff, 0, sizeof(p->last_hcoeff)); |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
3545 } |
4331
e571dfe677be
store a few values in the header as difference to the last
michael
parents:
4283
diff
changeset
|
3546 } |
2138 | 3547 if(s->keyframe){ |
3548 put_symbol(&s->c, s->header_state, s->version, 0); | |
2335 | 3549 put_rac(&s->c, s->header_state, s->always_reset); |
2138 | 3550 put_symbol(&s->c, s->header_state, s->temporal_decomposition_type, 0); |
3551 put_symbol(&s->c, s->header_state, s->temporal_decomposition_count, 0); | |
3552 put_symbol(&s->c, s->header_state, s->spatial_decomposition_count, 0); | |
3553 put_symbol(&s->c, s->header_state, s->colorspace_type, 0); | |
3554 put_symbol(&s->c, s->header_state, s->chroma_h_shift, 0); | |
3555 put_symbol(&s->c, s->header_state, s->chroma_v_shift, 0); | |
2335 | 3556 put_rac(&s->c, s->header_state, s->spatial_scalability); |
3557 // put_rac(&s->c, s->header_state, s->rate_scalability); | |
3314 | 3558 put_symbol(&s->c, s->header_state, s->max_ref_frames-1, 0); |
2138 | 3559 |
5666
b5c137f3f53a
allow changing of the spatial_decomposition_count and quantization tables
michael
parents:
5665
diff
changeset
|
3560 encode_qlogs(s); |
2138 | 3561 } |
5651
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
3562 |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
3563 if(!s->keyframe){ |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
3564 int update_mc=0; |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
3565 for(plane_index=0; plane_index<2; plane_index++){ |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
3566 Plane *p= &s->plane[plane_index]; |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
3567 update_mc |= p->last_htaps != p->htaps; |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
3568 update_mc |= p->last_diag_mc != p->diag_mc; |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
3569 update_mc |= !!memcmp(p->last_hcoeff, p->hcoeff, sizeof(p->hcoeff)); |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
3570 } |
5667
9242e125395f
do not force the halfpel filter coeffs to be retransmitted on every frame
michael
parents:
5666
diff
changeset
|
3571 put_rac(&s->c, s->header_state, update_mc); |
5651
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
3572 if(update_mc){ |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
3573 for(plane_index=0; plane_index<2; plane_index++){ |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
3574 Plane *p= &s->plane[plane_index]; |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
3575 put_rac(&s->c, s->header_state, p->diag_mc); |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
3576 put_symbol(&s->c, s->header_state, p->htaps/2-1, 0); |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
3577 for(i= p->htaps/2; i; i--) |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
3578 put_symbol(&s->c, s->header_state, FFABS(p->hcoeff[i]), 0); |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
3579 } |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
3580 } |
5670
2f3431b34f0f
make changing spatial_decomposition_count per frame work
michael
parents:
5668
diff
changeset
|
3581 if(s->last_spatial_decomposition_count != s->spatial_decomposition_count){ |
2f3431b34f0f
make changing spatial_decomposition_count per frame work
michael
parents:
5668
diff
changeset
|
3582 put_rac(&s->c, s->header_state, 1); |
5666
b5c137f3f53a
allow changing of the spatial_decomposition_count and quantization tables
michael
parents:
5665
diff
changeset
|
3583 put_symbol(&s->c, s->header_state, s->spatial_decomposition_count, 0); |
b5c137f3f53a
allow changing of the spatial_decomposition_count and quantization tables
michael
parents:
5665
diff
changeset
|
3584 encode_qlogs(s); |
5670
2f3431b34f0f
make changing spatial_decomposition_count per frame work
michael
parents:
5668
diff
changeset
|
3585 }else |
2f3431b34f0f
make changing spatial_decomposition_count per frame work
michael
parents:
5668
diff
changeset
|
3586 put_rac(&s->c, s->header_state, 0); |
5651
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
3587 } |
ab023c9f03d0
store halfpel filter coefficients in the header as well as the
michael
parents:
5650
diff
changeset
|
3588 |
4331
e571dfe677be
store a few values in the header as difference to the last
michael
parents:
4283
diff
changeset
|
3589 put_symbol(&s->c, s->header_state, s->spatial_decomposition_type - s->last_spatial_decomposition_type, 1); |
e571dfe677be
store a few values in the header as difference to the last
michael
parents:
4283
diff
changeset
|
3590 put_symbol(&s->c, s->header_state, s->qlog - s->last_qlog , 1); |
e571dfe677be
store a few values in the header as difference to the last
michael
parents:
4283
diff
changeset
|
3591 put_symbol(&s->c, s->header_state, s->mv_scale - s->last_mv_scale, 1); |
e571dfe677be
store a few values in the header as difference to the last
michael
parents:
4283
diff
changeset
|
3592 put_symbol(&s->c, s->header_state, s->qbias - s->last_qbias , 1); |
e571dfe677be
store a few values in the header as difference to the last
michael
parents:
4283
diff
changeset
|
3593 put_symbol(&s->c, s->header_state, s->block_max_depth - s->last_block_max_depth, 1); |
e571dfe677be
store a few values in the header as difference to the last
michael
parents:
4283
diff
changeset
|
3594 |
6144 | 3595 } |
3596 | |
3597 static void update_last_header_values(SnowContext *s){ | |
3598 int plane_index; | |
3599 | |
3600 if(!s->keyframe){ | |
3601 for(plane_index=0; plane_index<2; plane_index++){ | |
3602 Plane *p= &s->plane[plane_index]; | |
3603 p->last_diag_mc= p->diag_mc; | |
3604 p->last_htaps = p->htaps; | |
3605 memcpy(p->last_hcoeff, p->hcoeff, sizeof(p->hcoeff)); | |
3606 } | |
3607 } | |
3608 | |
6414 | 3609 s->last_spatial_decomposition_type = s->spatial_decomposition_type; |
3610 s->last_qlog = s->qlog; | |
3611 s->last_qbias = s->qbias; | |
3612 s->last_mv_scale = s->mv_scale; | |
3613 s->last_block_max_depth = s->block_max_depth; | |
3614 s->last_spatial_decomposition_count = s->spatial_decomposition_count; | |
2138 | 3615 } |
3616 | |
3322
0b4f548dfb44
Snow: 10l. 1pass ratecontrol failed to set snow's internal quant.
lorenm
parents:
3314
diff
changeset
|
3617 static int qscale2qlog(int qscale){ |
0b4f548dfb44
Snow: 10l. 1pass ratecontrol failed to set snow's internal quant.
lorenm
parents:
3314
diff
changeset
|
3618 return rint(QROOT*log(qscale / (float)FF_QP2LAMBDA)/log(2)) |
0b4f548dfb44
Snow: 10l. 1pass ratecontrol failed to set snow's internal quant.
lorenm
parents:
3314
diff
changeset
|
3619 + 61*QROOT/8; //<64 >60 |
0b4f548dfb44
Snow: 10l. 1pass ratecontrol failed to set snow's internal quant.
lorenm
parents:
3314
diff
changeset
|
3620 } |
0b4f548dfb44
Snow: 10l. 1pass ratecontrol failed to set snow's internal quant.
lorenm
parents:
3314
diff
changeset
|
3621 |
3661
b4425339894b
fix snow 1pass rc: the qlog used and the one written to the bitstream weren't always the same.
lorenm
parents:
3556
diff
changeset
|
3622 static int ratecontrol_1pass(SnowContext *s, AVFrame *pict) |
3313 | 3623 { |
6412 | 3624 /* Estimate the frame's complexity as a sum of weighted dwt coefficients. |
3313 | 3625 * FIXME we know exact mv bits at this point, |
3626 * but ratecontrol isn't set up to include them. */ | |
3627 uint32_t coef_sum= 0; | |
3661
b4425339894b
fix snow 1pass rc: the qlog used and the one written to the bitstream weren't always the same.
lorenm
parents:
3556
diff
changeset
|
3628 int level, orientation, delta_qlog; |
3313 | 3629 |
3630 for(level=0; level<s->spatial_decomposition_count; level++){ | |
3631 for(orientation=level ? 1 : 0; orientation<4; orientation++){ | |
3632 SubBand *b= &s->plane[0].band[level][orientation]; | |
5587
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
3633 IDWTELEM *buf= b->ibuf; |
3313 | 3634 const int w= b->width; |
3635 const int h= b->height; | |
3636 const int stride= b->stride; | |
4594 | 3637 const int qlog= av_clip(2*QROOT + b->qlog, 0, QROOT*16); |
3313 | 3638 const int qmul= qexp[qlog&(QROOT-1)]<<(qlog>>QSHIFT); |
3639 const int qdiv= (1<<16)/qmul; | |
3640 int x, y; | |
5587
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
3641 //FIXME this is ugly |
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
3642 for(y=0; y<h; y++) |
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
3643 for(x=0; x<w; x++) |
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
3644 buf[x+y*stride]= b->buf[x+y*stride]; |
3313 | 3645 if(orientation==0) |
3646 decorrelate(s, b, buf, stride, 1, 0); | |
3647 for(y=0; y<h; y++) | |
3648 for(x=0; x<w; x++) | |
3649 coef_sum+= abs(buf[x+y*stride]) * qdiv >> 16; | |
3650 } | |
3651 } | |
3652 | |
3653 /* ugly, ratecontrol just takes a sqrt again */ | |
3654 coef_sum = (uint64_t)coef_sum * coef_sum >> 16; | |
3655 assert(coef_sum < INT_MAX); | |
3656 | |
6481 | 3657 if(pict->pict_type == FF_I_TYPE){ |
3313 | 3658 s->m.current_picture.mb_var_sum= coef_sum; |
3659 s->m.current_picture.mc_mb_var_sum= 0; | |
3660 }else{ | |
3661 s->m.current_picture.mc_mb_var_sum= coef_sum; | |
3662 s->m.current_picture.mb_var_sum= 0; | |
3663 } | |
3664 | |
3665 pict->quality= ff_rate_estimate_qscale(&s->m, 1); | |
3766 | 3666 if (pict->quality < 0) |
4011
5bce97c30a69
-1 is a valid return value in ratecontrol_1pass() -> 100l for takis
michael
parents:
4001
diff
changeset
|
3667 return INT_MIN; |
3313 | 3668 s->lambda= pict->quality * 3/2; |
3661
b4425339894b
fix snow 1pass rc: the qlog used and the one written to the bitstream weren't always the same.
lorenm
parents:
3556
diff
changeset
|
3669 delta_qlog= qscale2qlog(pict->quality) - s->qlog; |
b4425339894b
fix snow 1pass rc: the qlog used and the one written to the bitstream weren't always the same.
lorenm
parents:
3556
diff
changeset
|
3670 s->qlog+= delta_qlog; |
b4425339894b
fix snow 1pass rc: the qlog used and the one written to the bitstream weren't always the same.
lorenm
parents:
3556
diff
changeset
|
3671 return delta_qlog; |
3313 | 3672 } |
2138 | 3673 |
5909 | 3674 static void calculate_visual_weight(SnowContext *s, Plane *p){ |
2138 | 3675 int width = p->width; |
3676 int height= p->height; | |
2198 | 3677 int level, orientation, x, y; |
2138 | 3678 |
3679 for(level=0; level<s->spatial_decomposition_count; level++){ | |
3680 for(orientation=level ? 1 : 0; orientation<4; orientation++){ | |
3681 SubBand *b= &p->band[level][orientation]; | |
5587
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
3682 IDWTELEM *ibuf= b->ibuf; |
2138 | 3683 int64_t error=0; |
2967 | 3684 |
5587
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
3685 memset(s->spatial_idwt_buffer, 0, sizeof(*s->spatial_idwt_buffer)*width*height); |
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
3686 ibuf[b->width/2 + b->height/2*b->stride]= 256*16; |
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
3687 ff_spatial_idwt(s->spatial_idwt_buffer, width, height, width, s->spatial_decomposition_type, s->spatial_decomposition_count); |
2138 | 3688 for(y=0; y<height; y++){ |
3689 for(x=0; x<width; x++){ | |
5587
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
3690 int64_t d= s->spatial_idwt_buffer[x + y*width]*16; |
2138 | 3691 error += d*d; |
3692 } | |
3693 } | |
3694 | |
3695 b->qlog= (int)(log(352256.0/sqrt(error)) / log(pow(2.0, 1.0/QROOT))+0.5); | |
3696 } | |
3697 } | |
3698 } | |
3699 | |
3700 static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){ | |
3701 SnowContext *s = avctx->priv_data; | |
2335 | 3702 RangeCoder * const c= &s->c; |
2138 | 3703 AVFrame *pict = data; |
3704 const int width= s->avctx->width; | |
3705 const int height= s->avctx->height; | |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3706 int level, orientation, plane_index, i, y; |
3661
b4425339894b
fix snow 1pass rc: the qlog used and the one written to the bitstream weren't always the same.
lorenm
parents:
3556
diff
changeset
|
3707 uint8_t rc_header_bak[sizeof(s->header_state)]; |
b4425339894b
fix snow 1pass rc: the qlog used and the one written to the bitstream weren't always the same.
lorenm
parents:
3556
diff
changeset
|
3708 uint8_t rc_block_bak[sizeof(s->block_state)]; |
2138 | 3709 |
2335 | 3710 ff_init_range_encoder(c, buf, buf_size); |
3711 ff_build_rac_states(c, 0.05*(1LL<<32), 256-8); | |
2967 | 3712 |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3713 for(i=0; i<3; i++){ |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3714 int shift= !!i; |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3715 for(y=0; y<(height>>shift); y++) |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3716 memcpy(&s->input_picture.data[i][y * s->input_picture.linesize[i]], |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3717 &pict->data[i][y * pict->linesize[i]], |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3718 width>>shift); |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3719 } |
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3720 s->new_picture = *pict; |
2138 | 3721 |
3313 | 3722 s->m.picture_number= avctx->frame_number; |
2608
4fb7fa34050b
allow 2pass ratecontrol. also fixes psnr displayed by mencoder.
lorenm
parents:
2607
diff
changeset
|
3723 if(avctx->flags&CODEC_FLAG_PASS2){ |
4fb7fa34050b
allow 2pass ratecontrol. also fixes psnr displayed by mencoder.
lorenm
parents:
2607
diff
changeset
|
3724 s->m.pict_type = |
4fb7fa34050b
allow 2pass ratecontrol. also fixes psnr displayed by mencoder.
lorenm
parents:
2607
diff
changeset
|
3725 pict->pict_type= s->m.rc_context.entry[avctx->frame_number].new_pict_type; |
4fb7fa34050b
allow 2pass ratecontrol. also fixes psnr displayed by mencoder.
lorenm
parents:
2607
diff
changeset
|
3726 s->keyframe= pict->pict_type==FF_I_TYPE; |
3766 | 3727 if(!(avctx->flags&CODEC_FLAG_QSCALE)) { |
3193 | 3728 pict->quality= ff_rate_estimate_qscale(&s->m, 0); |
3766 | 3729 if (pict->quality < 0) |
3730 return -1; | |
3731 } | |
2608
4fb7fa34050b
allow 2pass ratecontrol. also fixes psnr displayed by mencoder.
lorenm
parents:
2607
diff
changeset
|
3732 }else{ |
4fb7fa34050b
allow 2pass ratecontrol. also fixes psnr displayed by mencoder.
lorenm
parents:
2607
diff
changeset
|
3733 s->keyframe= avctx->gop_size==0 || avctx->frame_number % avctx->gop_size == 0; |
3313 | 3734 s->m.pict_type= |
2608
4fb7fa34050b
allow 2pass ratecontrol. also fixes psnr displayed by mencoder.
lorenm
parents:
2607
diff
changeset
|
3735 pict->pict_type= s->keyframe ? FF_I_TYPE : FF_P_TYPE; |
4fb7fa34050b
allow 2pass ratecontrol. also fixes psnr displayed by mencoder.
lorenm
parents:
2607
diff
changeset
|
3736 } |
2967 | 3737 |
3313 | 3738 if(s->pass1_rc && avctx->frame_number == 0) |
3739 pict->quality= 2*FF_QP2LAMBDA; | |
2161 | 3740 if(pict->quality){ |
3322
0b4f548dfb44
Snow: 10l. 1pass ratecontrol failed to set snow's internal quant.
lorenm
parents:
3314
diff
changeset
|
3741 s->qlog= qscale2qlog(pict->quality); |
3313 | 3742 s->lambda = pict->quality * 3/2; |
3743 } | |
3744 if(s->qlog < 0 || (!pict->quality && (avctx->flags & CODEC_FLAG_QSCALE))){ | |
2161 | 3745 s->qlog= LOSSLESS_QLOG; |
3313 | 3746 s->lambda = 0; |
6412 | 3747 }//else keep previous frame's qlog until after motion estimation |
2138 | 3748 |
3749 frame_start(s); | |
3750 | |
2608
4fb7fa34050b
allow 2pass ratecontrol. also fixes psnr displayed by mencoder.
lorenm
parents:
2607
diff
changeset
|
3751 s->m.current_picture_ptr= &s->m.current_picture; |
10625 | 3752 s->m.last_picture.pts= s->m.current_picture.pts; |
3753 s->m.current_picture.pts= pict->pts; | |
6481 | 3754 if(pict->pict_type == FF_P_TYPE){ |
2138 | 3755 int block_width = (width +15)>>4; |
3756 int block_height= (height+15)>>4; | |
3757 int stride= s->current_picture.linesize[0]; | |
2967 | 3758 |
2138 | 3759 assert(s->current_picture.data[0]); |
3314 | 3760 assert(s->last_picture[0].data[0]); |
2967 | 3761 |
2138 | 3762 s->m.avctx= s->avctx; |
3763 s->m.current_picture.data[0]= s->current_picture.data[0]; | |
3314 | 3764 s->m. last_picture.data[0]= s->last_picture[0].data[0]; |
2138 | 3765 s->m. new_picture.data[0]= s-> input_picture.data[0]; |
3766 s->m. last_picture_ptr= &s->m. last_picture; | |
3767 s->m.linesize= | |
3768 s->m. last_picture.linesize[0]= | |
3769 s->m. new_picture.linesize[0]= | |
3770 s->m.current_picture.linesize[0]= stride; | |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
3771 s->m.uvlinesize= s->current_picture.linesize[1]; |
2138 | 3772 s->m.width = width; |
3773 s->m.height= height; | |
3774 s->m.mb_width = block_width; | |
3775 s->m.mb_height= block_height; | |
3776 s->m.mb_stride= s->m.mb_width+1; | |
3777 s->m.b8_stride= 2*s->m.mb_width+1; | |
3778 s->m.f_code=1; | |
3779 s->m.pict_type= pict->pict_type; | |
3780 s->m.me_method= s->avctx->me_method; | |
3781 s->m.me.scene_change_score=0; | |
3782 s->m.flags= s->avctx->flags; | |
3783 s->m.quarter_sample= (s->avctx->flags & CODEC_FLAG_QPEL)!=0; | |
3784 s->m.out_format= FMT_H263; | |
3785 s->m.unrestricted_mv= 1; | |
3786 | |
3313 | 3787 s->m.lambda = s->lambda; |
2138 | 3788 s->m.qscale= (s->m.lambda*139 + FF_LAMBDA_SCALE*64) >> (FF_LAMBDA_SHIFT + 7); |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
3789 s->lambda2= s->m.lambda2= (s->m.lambda*s->m.lambda + FF_LAMBDA_SCALE/2) >> FF_LAMBDA_SHIFT; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
3790 |
2138 | 3791 s->m.dsp= s->dsp; //move |
3792 ff_init_me(&s->m); | |
2993
cb0e26759cca
iterative overlapped block based motion estimation for snow
michael
parents:
2979
diff
changeset
|
3793 s->dsp= s->m.dsp; |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
3794 } |
2967 | 3795 |
3661
b4425339894b
fix snow 1pass rc: the qlog used and the one written to the bitstream weren't always the same.
lorenm
parents:
3556
diff
changeset
|
3796 if(s->pass1_rc){ |
b4425339894b
fix snow 1pass rc: the qlog used and the one written to the bitstream weren't always the same.
lorenm
parents:
3556
diff
changeset
|
3797 memcpy(rc_header_bak, s->header_state, sizeof(s->header_state)); |
b4425339894b
fix snow 1pass rc: the qlog used and the one written to the bitstream weren't always the same.
lorenm
parents:
3556
diff
changeset
|
3798 memcpy(rc_block_bak, s->block_state, sizeof(s->block_state)); |
b4425339894b
fix snow 1pass rc: the qlog used and the one written to the bitstream weren't always the same.
lorenm
parents:
3556
diff
changeset
|
3799 } |
b4425339894b
fix snow 1pass rc: the qlog used and the one written to the bitstream weren't always the same.
lorenm
parents:
3556
diff
changeset
|
3800 |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2187
diff
changeset
|
3801 redo_frame: |
2967 | 3802 |
6481 | 3803 if(pict->pict_type == FF_I_TYPE) |
5670
2f3431b34f0f
make changing spatial_decomposition_count per frame work
michael
parents:
5668
diff
changeset
|
3804 s->spatial_decomposition_count= 5; |
2f3431b34f0f
make changing spatial_decomposition_count per frame work
michael
parents:
5668
diff
changeset
|
3805 else |
2f3431b34f0f
make changing spatial_decomposition_count per frame work
michael
parents:
5668
diff
changeset
|
3806 s->spatial_decomposition_count= 5; |
2f3431b34f0f
make changing spatial_decomposition_count per frame work
michael
parents:
5668
diff
changeset
|
3807 |
3313 | 3808 s->m.pict_type = pict->pict_type; |
6481 | 3809 s->qbias= pict->pict_type == FF_P_TYPE ? 2 : 0; |
2138 | 3810 |
5670
2f3431b34f0f
make changing spatial_decomposition_count per frame work
michael
parents:
5668
diff
changeset
|
3811 common_init_after_header(avctx); |
2f3431b34f0f
make changing spatial_decomposition_count per frame work
michael
parents:
5668
diff
changeset
|
3812 |
2f3431b34f0f
make changing spatial_decomposition_count per frame work
michael
parents:
5668
diff
changeset
|
3813 if(s->last_spatial_decomposition_count != s->spatial_decomposition_count){ |
2f3431b34f0f
make changing spatial_decomposition_count per frame work
michael
parents:
5668
diff
changeset
|
3814 for(plane_index=0; plane_index<3; plane_index++){ |
5909 | 3815 calculate_visual_weight(s, &s->plane[plane_index]); |
5670
2f3431b34f0f
make changing spatial_decomposition_count per frame work
michael
parents:
5668
diff
changeset
|
3816 } |
2f3431b34f0f
make changing spatial_decomposition_count per frame work
michael
parents:
5668
diff
changeset
|
3817 } |
2f3431b34f0f
make changing spatial_decomposition_count per frame work
michael
parents:
5668
diff
changeset
|
3818 |
2138 | 3819 encode_header(s); |
2608
4fb7fa34050b
allow 2pass ratecontrol. also fixes psnr displayed by mencoder.
lorenm
parents:
2607
diff
changeset
|
3820 s->m.misc_bits = 8*(s->c.bytestream - s->c.bytestream_start); |
3661
b4425339894b
fix snow 1pass rc: the qlog used and the one written to the bitstream weren't always the same.
lorenm
parents:
3556
diff
changeset
|
3821 encode_blocks(s, 1); |
2608
4fb7fa34050b
allow 2pass ratecontrol. also fixes psnr displayed by mencoder.
lorenm
parents:
2607
diff
changeset
|
3822 s->m.mv_bits = 8*(s->c.bytestream - s->c.bytestream_start) - s->m.misc_bits; |
2967 | 3823 |
2138 | 3824 for(plane_index=0; plane_index<3; plane_index++){ |
3825 Plane *p= &s->plane[plane_index]; | |
3826 int w= p->width; | |
3827 int h= p->height; | |
3828 int x, y; | |
2198 | 3829 // int bits= put_bits_count(&s->c.pb); |
2138 | 3830 |
6414 | 3831 if(!(avctx->flags2 & CODEC_FLAG2_MEMC_ONLY)){ |
3832 //FIXME optimize | |
3833 if(pict->data[plane_index]) //FIXME gray hack | |
3834 for(y=0; y<h; y++){ | |
3835 for(x=0; x<w; x++){ | |
3836 s->spatial_idwt_buffer[y*w + x]= pict->data[plane_index][y*pict->linesize[plane_index] + x]<<FRAC_BITS; | |
3837 } | |
3838 } | |
3839 predict_plane(s, s->spatial_idwt_buffer, plane_index, 0); | |
3840 | |
3841 if( plane_index==0 | |
6481 | 3842 && pict->pict_type == FF_P_TYPE |
6414 | 3843 && !(avctx->flags&CODEC_FLAG_PASS2) |
3844 && s->m.me.scene_change_score > s->avctx->scenechange_threshold){ | |
3845 ff_init_range_encoder(c, buf, buf_size); | |
3846 ff_build_rac_states(c, 0.05*(1LL<<32), 256-8); | |
3847 pict->pict_type= FF_I_TYPE; | |
3848 s->keyframe=1; | |
3849 s->current_picture.key_frame=1; | |
3850 goto redo_frame; | |
2138 | 3851 } |
6414 | 3852 |
3853 if(s->qlog == LOSSLESS_QLOG){ | |
3854 for(y=0; y<h; y++){ | |
3855 for(x=0; x<w; x++){ | |
3856 s->spatial_dwt_buffer[y*w + x]= (s->spatial_idwt_buffer[y*w + x] + (1<<(FRAC_BITS-1))-1)>>FRAC_BITS; | |
3857 } | |
2161 | 3858 } |
6414 | 3859 }else{ |
3860 for(y=0; y<h; y++){ | |
3861 for(x=0; x<w; x++){ | |
3862 s->spatial_dwt_buffer[y*w + x]=s->spatial_idwt_buffer[y*w + x]<<ENCODER_EXTRA_BITS; | |
3863 } | |
5575 | 3864 } |
3865 } | |
6414 | 3866 |
3867 /* if(QUANTIZE2) | |
3868 dwt_quantize(s, p, s->spatial_dwt_buffer, w, h, w, s->spatial_decomposition_type); | |
3869 else*/ | |
3870 ff_spatial_dwt(s->spatial_dwt_buffer, w, h, w, s->spatial_decomposition_type, s->spatial_decomposition_count); | |
3871 | |
3872 if(s->pass1_rc && plane_index==0){ | |
3873 int delta_qlog = ratecontrol_1pass(s, pict); | |
3874 if (delta_qlog <= INT_MIN) | |
3875 return -1; | |
3876 if(delta_qlog){ | |
3877 //reordering qlog in the bitstream would eliminate this reset | |
3878 ff_init_range_encoder(c, buf, buf_size); | |
3879 memcpy(s->header_state, rc_header_bak, sizeof(s->header_state)); | |
3880 memcpy(s->block_state, rc_block_bak, sizeof(s->block_state)); | |
3881 encode_header(s); | |
3882 encode_blocks(s, 0); | |
2161 | 3883 } |
3884 } | |
6414 | 3885 |
3886 for(level=0; level<s->spatial_decomposition_count; level++){ | |
3887 for(orientation=level ? 1 : 0; orientation<4; orientation++){ | |
3888 SubBand *b= &p->band[level][orientation]; | |
3889 | |
3890 if(!QUANTIZE2) | |
3891 quantize(s, b, b->ibuf, b->buf, b->stride, s->qbias); | |
3892 if(orientation==0) | |
6481 | 3893 decorrelate(s, b, b->ibuf, b->stride, pict->pict_type == FF_P_TYPE, 0); |
6414 | 3894 encode_subband(s, b, b->ibuf, b->parent ? b->parent->ibuf : NULL, b->stride, orientation); |
3895 assert(b->parent==NULL || b->parent->stride == b->stride*2); | |
3896 if(orientation==0) | |
3897 correlate(s, b, b->ibuf, b->stride, 1, 0); | |
3898 } | |
3899 } | |
3900 | |
3901 for(level=0; level<s->spatial_decomposition_count; level++){ | |
3902 for(orientation=level ? 1 : 0; orientation<4; orientation++){ | |
3903 SubBand *b= &p->band[level][orientation]; | |
3904 | |
3905 dequantize(s, b, b->ibuf, b->stride); | |
3906 } | |
3907 } | |
3908 | |
3909 ff_spatial_idwt(s->spatial_idwt_buffer, w, h, w, s->spatial_decomposition_type, s->spatial_decomposition_count); | |
3910 if(s->qlog == LOSSLESS_QLOG){ | |
3911 for(y=0; y<h; y++){ | |
3912 for(x=0; x<w; x++){ | |
3913 s->spatial_idwt_buffer[y*w + x]<<=FRAC_BITS; | |
3914 } | |
3915 } | |
3916 } | |
3917 predict_plane(s, s->spatial_idwt_buffer, plane_index, 1); | |
3918 }else{ | |
3338
937f14bb0f23
support doing motion estimation and compensation without any residual transform or coding
michael
parents:
3327
diff
changeset
|
3919 //ME/MC only |
6481 | 3920 if(pict->pict_type == FF_I_TYPE){ |
3338
937f14bb0f23
support doing motion estimation and compensation without any residual transform or coding
michael
parents:
3327
diff
changeset
|
3921 for(y=0; y<h; y++){ |
937f14bb0f23
support doing motion estimation and compensation without any residual transform or coding
michael
parents:
3327
diff
changeset
|
3922 for(x=0; x<w; x++){ |
937f14bb0f23
support doing motion estimation and compensation without any residual transform or coding
michael
parents:
3327
diff
changeset
|
3923 s->current_picture.data[plane_index][y*s->current_picture.linesize[plane_index] + x]= |
937f14bb0f23
support doing motion estimation and compensation without any residual transform or coding
michael
parents:
3327
diff
changeset
|
3924 pict->data[plane_index][y*pict->linesize[plane_index] + x]; |
937f14bb0f23
support doing motion estimation and compensation without any residual transform or coding
michael
parents:
3327
diff
changeset
|
3925 } |
937f14bb0f23
support doing motion estimation and compensation without any residual transform or coding
michael
parents:
3327
diff
changeset
|
3926 } |
937f14bb0f23
support doing motion estimation and compensation without any residual transform or coding
michael
parents:
3327
diff
changeset
|
3927 }else{ |
5587
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
3928 memset(s->spatial_idwt_buffer, 0, sizeof(IDWTELEM)*w*h); |
3ae03eacbe9f
use 16bit IDWT (a SIMD implementation of it should be >2x faster then with
michael
parents:
5575
diff
changeset
|
3929 predict_plane(s, s->spatial_idwt_buffer, plane_index, 1); |
3338
937f14bb0f23
support doing motion estimation and compensation without any residual transform or coding
michael
parents:
3327
diff
changeset
|
3930 } |
6414 | 3931 } |
2138 | 3932 if(s->avctx->flags&CODEC_FLAG_PSNR){ |
3933 int64_t error= 0; | |
2967 | 3934 |
6414 | 3935 if(pict->data[plane_index]) //FIXME gray hack |
3936 for(y=0; y<h; y++){ | |
3937 for(x=0; x<w; x++){ | |
3938 int d= s->current_picture.data[plane_index][y*s->current_picture.linesize[plane_index] + x] - pict->data[plane_index][y*pict->linesize[plane_index] + x]; | |
3939 error += d*d; | |
3940 } | |
2138 | 3941 } |
3942 s->avctx->error[plane_index] += error; | |
2232 | 3943 s->current_picture.error[plane_index] = error; |
2138 | 3944 } |
6414 | 3945 |
2138 | 3946 } |
3947 | |
6144 | 3948 update_last_header_values(s); |
3949 | |
9374 | 3950 release_buffer(avctx); |
2138 | 3951 |
2608
4fb7fa34050b
allow 2pass ratecontrol. also fixes psnr displayed by mencoder.
lorenm
parents:
2607
diff
changeset
|
3952 s->current_picture.coded_picture_number = avctx->frame_number; |
4fb7fa34050b
allow 2pass ratecontrol. also fixes psnr displayed by mencoder.
lorenm
parents:
2607
diff
changeset
|
3953 s->current_picture.pict_type = pict->pict_type; |
4fb7fa34050b
allow 2pass ratecontrol. also fixes psnr displayed by mencoder.
lorenm
parents:
2607
diff
changeset
|
3954 s->current_picture.quality = pict->quality; |
3313 | 3955 s->m.frame_bits = 8*(s->c.bytestream - s->c.bytestream_start); |
3956 s->m.p_tex_bits = s->m.frame_bits - s->m.misc_bits - s->m.mv_bits; | |
3957 s->m.current_picture.display_picture_number = | |
3958 s->m.current_picture.coded_picture_number = avctx->frame_number; | |
3959 s->m.current_picture.quality = pict->quality; | |
3960 s->m.total_bits += 8*(s->c.bytestream - s->c.bytestream_start); | |
3961 if(s->pass1_rc) | |
3766 | 3962 if (ff_rate_estimate_qscale(&s->m, 0) < 0) |
3963 return -1; | |
3313 | 3964 if(avctx->flags&CODEC_FLAG_PASS1) |
2608
4fb7fa34050b
allow 2pass ratecontrol. also fixes psnr displayed by mencoder.
lorenm
parents:
2607
diff
changeset
|
3965 ff_write_pass1_stats(&s->m); |
3313 | 3966 s->m.last_pict_type = s->m.pict_type; |
4123
5c86acb39889
outputs bit spent on various encoding functions (motion vectors, overhead, etc)
gpoirier
parents:
4122
diff
changeset
|
3967 avctx->frame_bits = s->m.frame_bits; |
5c86acb39889
outputs bit spent on various encoding functions (motion vectors, overhead, etc)
gpoirier
parents:
4122
diff
changeset
|
3968 avctx->mv_bits = s->m.mv_bits; |
5c86acb39889
outputs bit spent on various encoding functions (motion vectors, overhead, etc)
gpoirier
parents:
4122
diff
changeset
|
3969 avctx->misc_bits = s->m.misc_bits; |
5c86acb39889
outputs bit spent on various encoding functions (motion vectors, overhead, etc)
gpoirier
parents:
4122
diff
changeset
|
3970 avctx->p_tex_bits = s->m.p_tex_bits; |
2608
4fb7fa34050b
allow 2pass ratecontrol. also fixes psnr displayed by mencoder.
lorenm
parents:
2607
diff
changeset
|
3971 |
2138 | 3972 emms_c(); |
2967 | 3973 |
2335 | 3974 return ff_rac_terminate(c); |
2138 | 3975 } |
3976 | |
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6481
diff
changeset
|
3977 static av_cold int encode_end(AVCodecContext *avctx) |
2138 | 3978 { |
3979 SnowContext *s = avctx->priv_data; | |
3980 | |
3981 common_end(s); | |
10806
e58e93f04279
Snow : release buffers allocated using avctx->get_buffer.
jai_menon
parents:
10625
diff
changeset
|
3982 if (s->input_picture.data[0]) |
e58e93f04279
Snow : release buffers allocated using avctx->get_buffer.
jai_menon
parents:
10625
diff
changeset
|
3983 avctx->release_buffer(avctx, &s->input_picture); |
2608
4fb7fa34050b
allow 2pass ratecontrol. also fixes psnr displayed by mencoder.
lorenm
parents:
2607
diff
changeset
|
3984 av_free(avctx->stats_out); |
2138 | 3985 |
3986 return 0; | |
3987 } | |
3988 | |
3989 AVCodec snow_encoder = { | |
3990 "snow", | |
11560
8a4984c5cacc
Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents:
11486
diff
changeset
|
3991 AVMEDIA_TYPE_VIDEO, |
2138 | 3992 CODEC_ID_SNOW, |
3993 sizeof(SnowContext), | |
3994 encode_init, | |
3995 encode_frame, | |
3996 encode_end, | |
7040
e943e1409077
Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents:
6712
diff
changeset
|
3997 .long_name = NULL_IF_CONFIG_SMALL("Snow"), |
2138 | 3998 }; |
2408
a6e4da1c28ee
Disable encoders patch by (Gianluigi Tiesi <mplayer netfarm it>)
michael
parents:
2368
diff
changeset
|
3999 #endif |
2138 | 4000 |
4001 | |
6164
ecaf5226e9b0
Consistently use TEST as the preprocessor condition to enable test code.
diego
parents:
6144
diff
changeset
|
4002 #ifdef TEST |
2138 | 4003 #undef malloc |
4004 #undef free | |
4005 #undef printf | |
9199
ea0e5e9a520f
Replace random() usage in test programs by av_lfg_*().
diego
parents:
9197
diff
changeset
|
4006 |
ea0e5e9a520f
Replace random() usage in test programs by av_lfg_*().
diego
parents:
9197
diff
changeset
|
4007 #include "libavutil/lfg.h" |
2138 | 4008 |
5934 | 4009 int main(void){ |
2138 | 4010 int width=256; |
4011 int height=256; | |
4012 int buffer[2][width*height]; | |
4013 SnowContext s; | |
4014 int i; | |
9388
2313bf51945b
cosmetics: Rename prn variable to prng (Pseudo Random Number Generator).
diego
parents:
9376
diff
changeset
|
4015 AVLFG prng; |
2138 | 4016 s.spatial_decomposition_count=6; |
4017 s.spatial_decomposition_type=1; | |
9199
ea0e5e9a520f
Replace random() usage in test programs by av_lfg_*().
diego
parents:
9197
diff
changeset
|
4018 |
9388
2313bf51945b
cosmetics: Rename prn variable to prng (Pseudo Random Number Generator).
diego
parents:
9376
diff
changeset
|
4019 av_lfg_init(&prng, 1); |
2967 | 4020 |
2138 | 4021 printf("testing 5/3 DWT\n"); |
4022 for(i=0; i<width*height; i++) | |
9388
2313bf51945b
cosmetics: Rename prn variable to prng (Pseudo Random Number Generator).
diego
parents:
9376
diff
changeset
|
4023 buffer[0][i] = buffer[1][i] = av_lfg_get(&prng) % 54321 - 12345; |
2967 | 4024 |
2951 | 4025 ff_spatial_dwt(buffer[0], width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count); |
4026 ff_spatial_idwt(buffer[0], width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count); | |
2967 | 4027 |
2138 | 4028 for(i=0; i<width*height; i++) |
9197 | 4029 if(buffer[0][i]!= buffer[1][i]) printf("fsck: %6d %12d %7d\n",i, buffer[0][i], buffer[1][i]); |
2138 | 4030 |
4031 printf("testing 9/7 DWT\n"); | |
4032 s.spatial_decomposition_type=0; | |
4033 for(i=0; i<width*height; i++) | |
9388
2313bf51945b
cosmetics: Rename prn variable to prng (Pseudo Random Number Generator).
diego
parents:
9376
diff
changeset
|
4034 buffer[0][i] = buffer[1][i] = av_lfg_get(&prng) % 54321 - 12345; |
2967 | 4035 |
2951 | 4036 ff_spatial_dwt(buffer[0], width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count); |
4037 ff_spatial_idwt(buffer[0], width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count); | |
2967 | 4038 |
2138 | 4039 for(i=0; i<width*height; i++) |
9197 | 4040 if(FFABS(buffer[0][i] - buffer[1][i])>20) printf("fsck: %6d %12d %7d\n",i, buffer[0][i], buffer[1][i]); |
2967 | 4041 |
2951 | 4042 #if 0 |
2138 | 4043 printf("testing AC coder\n"); |
4044 memset(s.header_state, 0, sizeof(s.header_state)); | |
2335 | 4045 ff_init_range_encoder(&s.c, buffer[0], 256*256); |
2138 | 4046 ff_init_cabac_states(&s.c, ff_h264_lps_range, ff_h264_mps_state, ff_h264_lps_state, 64); |
2967 | 4047 |
2138 | 4048 for(i=-256; i<256; i++){ |
4001 | 4049 put_symbol(&s.c, s.header_state, i*i*i/3*FFABS(i), 1); |
2138 | 4050 } |
2335 | 4051 ff_rac_terminate(&s.c); |
2138 | 4052 |
4053 memset(s.header_state, 0, sizeof(s.header_state)); | |
2335 | 4054 ff_init_range_decoder(&s.c, buffer[0], 256*256); |
2138 | 4055 ff_init_cabac_states(&s.c, ff_h264_lps_range, ff_h264_mps_state, ff_h264_lps_state, 64); |
2967 | 4056 |
2138 | 4057 for(i=-256; i<256; i++){ |
4058 int j; | |
4059 j= get_symbol(&s.c, s.header_state, 1); | |
4001 | 4060 if(j!=i*i*i/3*FFABS(i)) printf("fsck: %d != %d\n", i, j); |
2138 | 4061 } |
2951 | 4062 #endif |
6414 | 4063 { |
4064 int level, orientation, x, y; | |
4065 int64_t errors[8][4]; | |
4066 int64_t g=0; | |
4067 | |
4068 memset(errors, 0, sizeof(errors)); | |
4069 s.spatial_decomposition_count=3; | |
4070 s.spatial_decomposition_type=0; | |
4071 for(level=0; level<s.spatial_decomposition_count; level++){ | |
4072 for(orientation=level ? 1 : 0; orientation<4; orientation++){ | |
4073 int w= width >> (s.spatial_decomposition_count-level); | |
4074 int h= height >> (s.spatial_decomposition_count-level); | |
4075 int stride= width << (s.spatial_decomposition_count-level); | |
4076 DWTELEM *buf= buffer[0]; | |
4077 int64_t error=0; | |
4078 | |
4079 if(orientation&1) buf+=w; | |
4080 if(orientation>1) buf+=stride>>1; | |
4081 | |
4082 memset(buffer[0], 0, sizeof(int)*width*height); | |
4083 buf[w/2 + h/2*stride]= 256*256; | |
4084 ff_spatial_idwt(buffer[0], width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count); | |
4085 for(y=0; y<height; y++){ | |
4086 for(x=0; x<width; x++){ | |
4087 int64_t d= buffer[0][x + y*width]; | |
4088 error += d*d; | |
4089 if(FFABS(width/2-x)<9 && FFABS(height/2-y)<9 && level==2) printf("%8"PRId64" ", d); | |
4090 } | |
4091 if(FFABS(height/2-y)<9 && level==2) printf("\n"); | |
2138 | 4092 } |
6414 | 4093 error= (int)(sqrt(error)+0.5); |
4094 errors[level][orientation]= error; | |
8611 | 4095 if(g) g=av_gcd(g, error); |
6414 | 4096 else g= error; |
2138 | 4097 } |
4098 } | |
6414 | 4099 printf("static int const visual_weight[][4]={\n"); |
4100 for(level=0; level<s.spatial_decomposition_count; level++){ | |
4101 printf(" {"); | |
4102 for(orientation=0; orientation<4; orientation++){ | |
4103 printf("%8"PRId64",", errors[level][orientation]/g); | |
4104 } | |
4105 printf("},\n"); | |
2138 | 4106 } |
6414 | 4107 printf("};\n"); |
4108 { | |
2138 | 4109 int level=2; |
4110 int w= width >> (s.spatial_decomposition_count-level); | |
6168 | 4111 //int h= height >> (s.spatial_decomposition_count-level); |
2138 | 4112 int stride= width << (s.spatial_decomposition_count-level); |
4113 DWTELEM *buf= buffer[0]; | |
4114 int64_t error=0; | |
4115 | |
4116 buf+=w; | |
4117 buf+=stride>>1; | |
2967 | 4118 |
2138 | 4119 memset(buffer[0], 0, sizeof(int)*width*height); |
4120 #if 1 | |
4121 for(y=0; y<height; y++){ | |
4122 for(x=0; x<width; x++){ | |
4123 int tab[4]={0,2,3,1}; | |
4124 buffer[0][x+width*y]= 256*256*tab[(x&1) + 2*(y&1)]; | |
4125 } | |
4126 } | |
2951 | 4127 ff_spatial_dwt(buffer[0], width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count); |
2138 | 4128 #else |
4129 for(y=0; y<h; y++){ | |
4130 for(x=0; x<w; x++){ | |
4131 buf[x + y*stride ]=169; | |
4132 buf[x + y*stride-w]=64; | |
4133 } | |
4134 } | |
2951 | 4135 ff_spatial_idwt(buffer[0], width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count); |
2138 | 4136 #endif |
4137 for(y=0; y<height; y++){ | |
4138 for(x=0; x<width; x++){ | |
4139 int64_t d= buffer[0][x + y*width]; | |
4140 error += d*d; | |
4122
daae66c03857
Replace most of the %lld and %llx by their (cleaner) PRI*64 counterparts.
diego
parents:
4011
diff
changeset
|
4141 if(FFABS(width/2-x)<9 && FFABS(height/2-y)<9) printf("%8"PRId64" ", d); |
2138 | 4142 } |
4001 | 4143 if(FFABS(height/2-y)<9) printf("\n"); |
2138 | 4144 } |
6414 | 4145 } |
4146 | |
2138 | 4147 } |
4148 return 0; | |
4149 } | |
6164
ecaf5226e9b0
Consistently use TEST as the preprocessor condition to enable test code.
diego
parents:
6144
diff
changeset
|
4150 #endif /* TEST */ |