Mercurial > libavcodec.hg
annotate snow.c @ 2197:ffa4fa6bebe9 libavcodec
10l
more benchmarking code
inline
author | michael |
---|---|
date | Sat, 28 Aug 2004 14:08:50 +0000 |
parents | df3079d7806f |
children | 970c2de19b2e |
rev | line source |
---|---|
2138 | 1 /* |
2 * Copyright (C) 2004 Michael Niedermayer <michaelni@gmx.at> | |
3 * | |
4 * This library is free software; you can redistribute it and/or | |
5 * modify it under the terms of the GNU Lesser General Public | |
6 * License as published by the Free Software Foundation; either | |
7 * version 2 of the License, or (at your option) any later version. | |
8 * | |
9 * This library is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 * Lesser General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU Lesser General Public | |
15 * License along with this library; if not, write to the Free Software | |
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
17 */ | |
18 | |
19 #include "avcodec.h" | |
20 #include "common.h" | |
21 #include "dsputil.h" | |
22 #include "cabac.h" | |
23 | |
24 #include "mpegvideo.h" | |
25 | |
26 #undef NDEBUG | |
27 #include <assert.h> | |
28 | |
29 #define MAX_DECOMPOSITIONS 8 | |
30 #define MAX_PLANES 4 | |
31 #define DWTELEM int | |
32 #define QROOT 8 | |
2161 | 33 #define LOSSLESS_QLOG -128 |
2138 | 34 |
35 static const int8_t quant3[256]={ | |
36 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
37 1, 1, 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, 0, | |
52 }; | |
53 static const int8_t quant3b[256]={ | |
54 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
55 1, 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 }; | |
71 static const int8_t quant5[256]={ | |
72 0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
73 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
74 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
75 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
76 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
77 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
78 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
79 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
80 -2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2, | |
81 -2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2, | |
82 -2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2, | |
83 -2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2, | |
84 -2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2, | |
85 -2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2, | |
86 -2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2, | |
87 -2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-1,-1,-1, | |
88 }; | |
89 static const int8_t quant7[256]={ | |
90 0, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
91 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
92 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, | |
93 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, | |
94 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, | |
95 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, | |
96 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, | |
97 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, | |
98 -3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3, | |
99 -3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3, | |
100 -3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3, | |
101 -3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3, | |
102 -3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3, | |
103 -3,-3,-3,-3,-3,-3,-3,-3,-3,-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,-1,-1, | |
106 }; | |
107 static const int8_t quant9[256]={ | |
108 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, | |
109 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, | |
110 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, | |
111 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, | |
112 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, | |
113 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, | |
114 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, | |
115 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, | |
116 -4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4, | |
117 -4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4, | |
118 -4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4, | |
119 -4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4, | |
120 -4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4, | |
121 -4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4, | |
122 -4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-3,-3,-3,-3, | |
123 -3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-2,-2,-2,-2,-1,-1, | |
124 }; | |
125 static const int8_t quant11[256]={ | |
126 0, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, | |
127 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, | |
128 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, | |
129 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, | |
130 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, | |
131 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, | |
132 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, | |
133 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, | |
134 -5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5, | |
135 -5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5, | |
136 -5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5, | |
137 -5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5, | |
138 -5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5, | |
139 -5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-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,-3,-3,-3,-3,-3,-3,-3,-2,-2,-2,-1, | |
142 }; | |
143 static const int8_t quant13[256]={ | |
144 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, | |
145 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, | |
146 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, | |
147 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | |
148 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | |
149 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | |
150 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | |
151 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | |
152 -6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6, | |
153 -6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6, | |
154 -6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6, | |
155 -6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6, | |
156 -6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-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,-5,-5, | |
159 -4,-4,-4,-4,-4,-4,-4,-4,-4,-3,-3,-3,-3,-2,-2,-1, | |
160 }; | |
161 | |
162 #define OBMC_MAX 64 | |
163 #if 0 //64*cubic | |
164 static const uint8_t obmc32[1024]={ | |
165 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, | |
166 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, | |
167 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0, | |
168 0, 0, 1, 1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 7, 8, 8, 8, 8, 7, 7, 6, 6, 5, 4, 4, 3, 2, 2, 1, 1, 0, 0, | |
169 0, 0, 1, 2, 2, 3, 4, 6, 7, 8, 9,10,11,12,12,12,12,12,12,11,10, 9, 8, 7, 6, 4, 3, 2, 2, 1, 0, 0, | |
170 0, 1, 1, 2, 3, 5, 6, 8,10,11,13,14,15,16,17,18,18,17,16,15,14,13,11,10, 8, 6, 5, 3, 2, 1, 1, 0, | |
171 0, 1, 1, 3, 4, 6, 8,10,13,15,17,19,20,22,22,23,23,22,22,20,19,17,15,13,10, 8, 6, 4, 3, 1, 1, 0, | |
172 0, 1, 2, 4, 6, 8,10,13,16,19,21,23,25,27,28,29,29,28,27,25,23,21,19,16,13,10, 8, 6, 4, 2, 1, 0, | |
173 0, 1, 2, 4, 7,10,13,16,19,22,25,28,31,33,34,35,35,34,33,31,28,25,22,19,16,13,10, 7, 4, 2, 1, 0, | |
174 0, 1, 3, 5, 8,11,15,19,22,26,30,33,36,38,40,41,41,40,38,36,33,30,26,22,19,15,11, 8, 5, 3, 1, 0, | |
175 0, 1, 3, 6, 9,12,17,21,25,30,34,38,41,44,45,46,46,45,44,41,38,34,30,25,21,17,12, 9, 6, 3, 1, 0, | |
176 0, 1, 3, 6,10,14,19,23,28,33,38,42,45,48,51,52,52,51,48,45,42,38,33,28,23,19,14,10, 6, 3, 1, 0, | |
177 0, 1, 4, 7,11,15,20,25,31,36,41,45,49,52,55,56,56,55,52,49,45,41,36,31,25,20,15,11, 7, 4, 1, 0, | |
178 0, 2, 4, 7,12,16,22,27,33,38,44,48,52,56,58,60,60,58,56,52,48,44,38,33,27,22,16,12, 7, 4, 2, 0, | |
179 0, 1, 4, 8,12,17,22,28,34,40,45,51,55,58,61,62,62,61,58,55,51,45,40,34,28,22,17,12, 8, 4, 1, 0, | |
180 0, 2, 4, 8,12,18,23,29,35,41,46,52,56,60,62,64,64,62,60,56,52,46,41,35,29,23,18,12, 8, 4, 2, 0, | |
181 0, 2, 4, 8,12,18,23,29,35,41,46,52,56,60,62,64,64,62,60,56,52,46,41,35,29,23,18,12, 8, 4, 2, 0, | |
182 0, 1, 4, 8,12,17,22,28,34,40,45,51,55,58,61,62,62,61,58,55,51,45,40,34,28,22,17,12, 8, 4, 1, 0, | |
183 0, 2, 4, 7,12,16,22,27,33,38,44,48,52,56,58,60,60,58,56,52,48,44,38,33,27,22,16,12, 7, 4, 2, 0, | |
184 0, 1, 4, 7,11,15,20,25,31,36,41,45,49,52,55,56,56,55,52,49,45,41,36,31,25,20,15,11, 7, 4, 1, 0, | |
185 0, 1, 3, 6,10,14,19,23,28,33,38,42,45,48,51,52,52,51,48,45,42,38,33,28,23,19,14,10, 6, 3, 1, 0, | |
186 0, 1, 3, 6, 9,12,17,21,25,30,34,38,41,44,45,46,46,45,44,41,38,34,30,25,21,17,12, 9, 6, 3, 1, 0, | |
187 0, 1, 3, 5, 8,11,15,19,22,26,30,33,36,38,40,41,41,40,38,36,33,30,26,22,19,15,11, 8, 5, 3, 1, 0, | |
188 0, 1, 2, 4, 7,10,13,16,19,22,25,28,31,33,34,35,35,34,33,31,28,25,22,19,16,13,10, 7, 4, 2, 1, 0, | |
189 0, 1, 2, 4, 6, 8,10,13,16,19,21,23,25,27,28,29,29,28,27,25,23,21,19,16,13,10, 8, 6, 4, 2, 1, 0, | |
190 0, 1, 1, 3, 4, 6, 8,10,13,15,17,19,20,22,22,23,23,22,22,20,19,17,15,13,10, 8, 6, 4, 3, 1, 1, 0, | |
191 0, 1, 1, 2, 3, 5, 6, 8,10,11,13,14,15,16,17,18,18,17,16,15,14,13,11,10, 8, 6, 5, 3, 2, 1, 1, 0, | |
192 0, 0, 1, 2, 2, 3, 4, 6, 7, 8, 9,10,11,12,12,12,12,12,12,11,10, 9, 8, 7, 6, 4, 3, 2, 2, 1, 0, 0, | |
193 0, 0, 1, 1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 7, 8, 8, 8, 8, 7, 7, 6, 6, 5, 4, 4, 3, 2, 2, 1, 1, 0, 0, | |
194 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0, | |
195 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, | |
196 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, | |
197 //error:0.000022 | |
198 }; | |
199 static const uint8_t obmc16[256]={ | |
200 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, | |
201 0, 1, 1, 2, 4, 5, 5, 6, 6, 5, 5, 4, 2, 1, 1, 0, | |
202 0, 1, 4, 6, 9,11,13,15,15,13,11, 9, 6, 4, 1, 0, | |
203 0, 2, 6,11,15,20,24,26,26,24,20,15,11, 6, 2, 0, | |
204 0, 4, 9,15,23,29,34,38,38,34,29,23,15, 9, 4, 0, | |
205 0, 5,11,20,29,38,45,49,49,45,38,29,20,11, 5, 0, | |
206 1, 5,13,24,34,45,53,57,57,53,45,34,24,13, 5, 1, | |
207 1, 6,15,26,38,49,57,62,62,57,49,38,26,15, 6, 1, | |
208 1, 6,15,26,38,49,57,62,62,57,49,38,26,15, 6, 1, | |
209 1, 5,13,24,34,45,53,57,57,53,45,34,24,13, 5, 1, | |
210 0, 5,11,20,29,38,45,49,49,45,38,29,20,11, 5, 0, | |
211 0, 4, 9,15,23,29,34,38,38,34,29,23,15, 9, 4, 0, | |
212 0, 2, 6,11,15,20,24,26,26,24,20,15,11, 6, 2, 0, | |
213 0, 1, 4, 6, 9,11,13,15,15,13,11, 9, 6, 4, 1, 0, | |
214 0, 1, 1, 2, 4, 5, 5, 6, 6, 5, 5, 4, 2, 1, 1, 0, | |
215 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, | |
216 //error:0.000033 | |
217 }; | |
218 #elif 1 // 64*linear | |
219 static const uint8_t obmc32[1024]={ | |
220 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, | |
221 0, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 5, 5, 5, 4, 4, 4, 3, 3, 2, 2, 2, 1, 1, 1, 0, | |
222 0, 1, 2, 2, 3, 3, 4, 5, 5, 6, 7, 7, 8, 8, 9,10,10, 9, 8, 8, 7, 7, 6, 5, 5, 4, 3, 3, 2, 2, 1, 0, | |
223 0, 1, 2, 3, 4, 5, 6, 7, 7, 8, 9,10,11,12,13,14,14,13,12,11,10, 9, 8, 7, 7, 6, 5, 4, 3, 2, 1, 0, | |
224 1, 2, 3, 4, 5, 6, 7, 8,10,11,12,13,14,15,16,17,17,16,15,14,13,12,11,10, 8, 7, 6, 5, 4, 3, 2, 1, | |
225 1, 2, 3, 5, 6, 8, 9,10,12,13,14,16,17,19,20,21,21,20,19,17,16,14,13,12,10, 9, 8, 6, 5, 3, 2, 1, | |
226 1, 2, 4, 6, 7, 9,11,12,14,15,17,19,20,22,24,25,25,24,22,20,19,17,15,14,12,11, 9, 7, 6, 4, 2, 1, | |
227 1, 3, 5, 7, 8,10,12,14,16,18,20,22,23,25,27,29,29,27,25,23,22,20,18,16,14,12,10, 8, 7, 5, 3, 1, | |
228 1, 3, 5, 7,10,12,14,16,18,20,22,24,27,29,31,33,33,31,29,27,24,22,20,18,16,14,12,10, 7, 5, 3, 1, | |
229 1, 4, 6, 8,11,13,15,18,20,23,25,27,30,32,34,37,37,34,32,30,27,25,23,20,18,15,13,11, 8, 6, 4, 1, | |
230 1, 4, 7, 9,12,14,17,20,22,25,28,30,33,35,38,41,41,38,35,33,30,28,25,22,20,17,14,12, 9, 7, 4, 1, | |
231 1, 4, 7,10,13,16,19,22,24,27,30,33,36,39,42,45,45,42,39,36,33,30,27,24,22,19,16,13,10, 7, 4, 1, | |
232 2, 5, 8,11,14,17,20,23,27,30,33,36,39,42,45,48,48,45,42,39,36,33,30,27,23,20,17,14,11, 8, 5, 2, | |
233 2, 5, 8,12,15,19,22,25,29,32,35,39,42,46,49,52,52,49,46,42,39,35,32,29,25,22,19,15,12, 8, 5, 2, | |
234 2, 5, 9,13,16,20,24,27,31,34,38,42,45,49,53,56,56,53,49,45,42,38,34,31,27,24,20,16,13, 9, 5, 2, | |
235 2, 6,10,14,17,21,25,29,33,37,41,45,48,52,56,60,60,56,52,48,45,41,37,33,29,25,21,17,14,10, 6, 2, | |
236 2, 6,10,14,17,21,25,29,33,37,41,45,48,52,56,60,60,56,52,48,45,41,37,33,29,25,21,17,14,10, 6, 2, | |
237 2, 5, 9,13,16,20,24,27,31,34,38,42,45,49,53,56,56,53,49,45,42,38,34,31,27,24,20,16,13, 9, 5, 2, | |
238 2, 5, 8,12,15,19,22,25,29,32,35,39,42,46,49,52,52,49,46,42,39,35,32,29,25,22,19,15,12, 8, 5, 2, | |
239 2, 5, 8,11,14,17,20,23,27,30,33,36,39,42,45,48,48,45,42,39,36,33,30,27,23,20,17,14,11, 8, 5, 2, | |
240 1, 4, 7,10,13,16,19,22,24,27,30,33,36,39,42,45,45,42,39,36,33,30,27,24,22,19,16,13,10, 7, 4, 1, | |
241 1, 4, 7, 9,12,14,17,20,22,25,28,30,33,35,38,41,41,38,35,33,30,28,25,22,20,17,14,12, 9, 7, 4, 1, | |
242 1, 4, 6, 8,11,13,15,18,20,23,25,27,30,32,34,37,37,34,32,30,27,25,23,20,18,15,13,11, 8, 6, 4, 1, | |
243 1, 3, 5, 7,10,12,14,16,18,20,22,24,27,29,31,33,33,31,29,27,24,22,20,18,16,14,12,10, 7, 5, 3, 1, | |
244 1, 3, 5, 7, 8,10,12,14,16,18,20,22,23,25,27,29,29,27,25,23,22,20,18,16,14,12,10, 8, 7, 5, 3, 1, | |
245 1, 2, 4, 6, 7, 9,11,12,14,15,17,19,20,22,24,25,25,24,22,20,19,17,15,14,12,11, 9, 7, 6, 4, 2, 1, | |
246 1, 2, 3, 5, 6, 8, 9,10,12,13,14,16,17,19,20,21,21,20,19,17,16,14,13,12,10, 9, 8, 6, 5, 3, 2, 1, | |
247 1, 2, 3, 4, 5, 6, 7, 8,10,11,12,13,14,15,16,17,17,16,15,14,13,12,11,10, 8, 7, 6, 5, 4, 3, 2, 1, | |
248 0, 1, 2, 3, 4, 5, 6, 7, 7, 8, 9,10,11,12,13,14,14,13,12,11,10, 9, 8, 7, 7, 6, 5, 4, 3, 2, 1, 0, | |
249 0, 1, 2, 2, 3, 3, 4, 5, 5, 6, 7, 7, 8, 8, 9,10,10, 9, 8, 8, 7, 7, 6, 5, 5, 4, 3, 3, 2, 2, 1, 0, | |
250 0, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 5, 5, 5, 4, 4, 4, 3, 3, 2, 2, 2, 1, 1, 1, 0, | |
251 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, | |
252 //error:0.000020 | |
253 }; | |
254 static const uint8_t obmc16[256]={ | |
255 0, 1, 1, 2, 2, 3, 3, 4, 4, 3, 3, 2, 2, 1, 1, 0, | |
256 1, 2, 4, 5, 7, 8,10,11,11,10, 8, 7, 5, 4, 2, 1, | |
257 1, 4, 6, 9,11,14,16,19,19,16,14,11, 9, 6, 4, 1, | |
258 2, 5, 9,12,16,19,23,26,26,23,19,16,12, 9, 5, 2, | |
259 2, 7,11,16,20,25,29,34,34,29,25,20,16,11, 7, 2, | |
260 3, 8,14,19,25,30,36,41,41,36,30,25,19,14, 8, 3, | |
261 3,10,16,23,29,36,42,49,49,42,36,29,23,16,10, 3, | |
262 4,11,19,26,34,41,49,56,56,49,41,34,26,19,11, 4, | |
263 4,11,19,26,34,41,49,56,56,49,41,34,26,19,11, 4, | |
264 3,10,16,23,29,36,42,49,49,42,36,29,23,16,10, 3, | |
265 3, 8,14,19,25,30,36,41,41,36,30,25,19,14, 8, 3, | |
266 2, 7,11,16,20,25,29,34,34,29,25,20,16,11, 7, 2, | |
267 2, 5, 9,12,16,19,23,26,26,23,19,16,12, 9, 5, 2, | |
268 1, 4, 6, 9,11,14,16,19,19,16,14,11, 9, 6, 4, 1, | |
269 1, 2, 4, 5, 7, 8,10,11,11,10, 8, 7, 5, 4, 2, 1, | |
270 0, 1, 1, 2, 2, 3, 3, 4, 4, 3, 3, 2, 2, 1, 1, 0, | |
271 //error:0.000015 | |
272 }; | |
273 #else //64*cos | |
274 static const uint8_t obmc32[1024]={ | |
275 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, | |
276 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, | |
277 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0, | |
278 0, 0, 1, 1, 1, 2, 2, 3, 4, 5, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 6, 5, 5, 4, 3, 2, 2, 1, 1, 1, 0, 0, | |
279 0, 0, 1, 1, 2, 3, 4, 5, 6, 7, 9,10,11,11,12,12,12,12,11,11,10, 9, 7, 6, 5, 4, 3, 2, 1, 1, 0, 0, | |
280 0, 0, 1, 2, 3, 5, 6, 8, 9,11,12,14,15,16,17,17,17,17,16,15,14,12,11, 9, 8, 6, 5, 3, 2, 1, 0, 0, | |
281 0, 1, 1, 2, 4, 6, 8,10,12,15,17,19,20,21,22,23,23,22,21,20,19,17,15,12,10, 8, 6, 4, 2, 1, 1, 0, | |
282 0, 1, 2, 3, 5, 8,10,13,16,19,21,24,26,27,28,29,29,28,27,26,24,21,19,16,13,10, 8, 5, 3, 2, 1, 0, | |
283 0, 1, 2, 4, 6, 9,12,16,19,23,26,29,31,33,34,35,35,34,33,31,29,26,23,19,16,12, 9, 6, 4, 2, 1, 0, | |
284 0, 1, 3, 5, 7,11,15,19,23,26,30,34,37,39,40,41,41,40,39,37,34,30,26,23,19,15,11, 7, 5, 3, 1, 0, | |
285 0, 1, 3, 5, 9,12,17,21,26,30,35,38,42,44,46,47,47,46,44,42,38,35,30,26,21,17,12, 9, 5, 3, 1, 0, | |
286 0, 1, 3, 6, 9,14,19,24,29,34,38,43,46,49,51,52,52,51,49,46,43,38,34,29,24,19,14, 9, 6, 3, 1, 0, | |
287 0, 1, 3, 6,11,15,20,26,31,37,42,46,50,53,56,57,57,56,53,50,46,42,37,31,26,20,15,11, 6, 3, 1, 0, | |
288 0, 1, 3, 7,11,16,21,27,33,39,44,49,53,57,59,60,60,59,57,53,49,44,39,33,27,21,16,11, 7, 3, 1, 0, | |
289 0, 1, 4, 7,12,17,22,28,34,40,46,51,56,59,61,63,63,61,59,56,51,46,40,34,28,22,17,12, 7, 4, 1, 0, | |
290 0, 1, 4, 7,12,17,23,29,35,41,47,52,57,60,63,64,64,63,60,57,52,47,41,35,29,23,17,12, 7, 4, 1, 0, | |
291 0, 1, 4, 7,12,17,23,29,35,41,47,52,57,60,63,64,64,63,60,57,52,47,41,35,29,23,17,12, 7, 4, 1, 0, | |
292 0, 1, 4, 7,12,17,22,28,34,40,46,51,56,59,61,63,63,61,59,56,51,46,40,34,28,22,17,12, 7, 4, 1, 0, | |
293 0, 1, 3, 7,11,16,21,27,33,39,44,49,53,57,59,60,60,59,57,53,49,44,39,33,27,21,16,11, 7, 3, 1, 0, | |
294 0, 1, 3, 6,11,15,20,26,31,37,42,46,50,53,56,57,57,56,53,50,46,42,37,31,26,20,15,11, 6, 3, 1, 0, | |
295 0, 1, 3, 6, 9,14,19,24,29,34,38,43,46,49,51,52,52,51,49,46,43,38,34,29,24,19,14, 9, 6, 3, 1, 0, | |
296 0, 1, 3, 5, 9,12,17,21,26,30,35,38,42,44,46,47,47,46,44,42,38,35,30,26,21,17,12, 9, 5, 3, 1, 0, | |
297 0, 1, 3, 5, 7,11,15,19,23,26,30,34,37,39,40,41,41,40,39,37,34,30,26,23,19,15,11, 7, 5, 3, 1, 0, | |
298 0, 1, 2, 4, 6, 9,12,16,19,23,26,29,31,33,34,35,35,34,33,31,29,26,23,19,16,12, 9, 6, 4, 2, 1, 0, | |
299 0, 1, 2, 3, 5, 8,10,13,16,19,21,24,26,27,28,29,29,28,27,26,24,21,19,16,13,10, 8, 5, 3, 2, 1, 0, | |
300 0, 1, 1, 2, 4, 6, 8,10,12,15,17,19,20,21,22,23,23,22,21,20,19,17,15,12,10, 8, 6, 4, 2, 1, 1, 0, | |
301 0, 0, 1, 2, 3, 5, 6, 8, 9,11,12,14,15,16,17,17,17,17,16,15,14,12,11, 9, 8, 6, 5, 3, 2, 1, 0, 0, | |
302 0, 0, 1, 1, 2, 3, 4, 5, 6, 7, 9,10,11,11,12,12,12,12,11,11,10, 9, 7, 6, 5, 4, 3, 2, 1, 1, 0, 0, | |
303 0, 0, 1, 1, 1, 2, 2, 3, 4, 5, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 6, 5, 5, 4, 3, 2, 2, 1, 1, 1, 0, 0, | |
304 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0, | |
305 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, | |
306 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, | |
307 //error:0.000022 | |
308 }; | |
309 static const uint8_t obmc16[256]={ | |
310 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, | |
311 0, 0, 1, 2, 3, 4, 5, 5, 5, 5, 4, 3, 2, 1, 0, 0, | |
312 0, 1, 3, 6, 8,11,13,14,14,13,11, 8, 6, 3, 1, 0, | |
313 0, 2, 6,10,15,20,24,26,26,24,20,15,10, 6, 2, 0, | |
314 0, 3, 8,16,23,30,35,38,38,35,30,23,16, 8, 3, 0, | |
315 1, 4,11,20,30,39,46,49,49,46,39,30,20,11, 4, 1, | |
316 1, 5,13,24,35,46,54,58,58,54,46,35,24,13, 5, 1, | |
317 0, 5,14,26,38,49,58,63,63,58,49,38,26,14, 5, 0, | |
318 0, 5,14,26,38,49,58,63,63,58,49,38,26,14, 5, 0, | |
319 1, 5,13,24,35,46,54,58,58,54,46,35,24,13, 5, 1, | |
320 1, 4,11,20,30,39,46,49,49,46,39,30,20,11, 4, 1, | |
321 0, 3, 8,16,23,30,35,38,38,35,30,23,16, 8, 3, 0, | |
322 0, 2, 6,10,15,20,24,26,26,24,20,15,10, 6, 2, 0, | |
323 0, 1, 3, 6, 8,11,13,14,14,13,11, 8, 6, 3, 1, 0, | |
324 0, 0, 1, 2, 3, 4, 5, 5, 5, 5, 4, 3, 2, 1, 0, 0, | |
325 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, | |
326 //error:0.000022 | |
327 }; | |
328 #endif | |
329 | |
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
|
330 //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
|
331 static const uint8_t obmc8[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
|
332 1, 3, 5, 7, 7, 5, 3, 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
|
333 3, 9,15,21,21,15, 9, 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
|
334 5,15,25,35,35,25,15, 5, |
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
|
335 7,21,35,49,49,35,21, 7, |
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
|
336 7,21,35,49,49,35,21, 7, |
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
|
337 5,15,25,35,35,25,15, 5, |
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
|
338 3, 9,15,21,21,15, 9, 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
|
339 1, 3, 5, 7, 7, 5, 3, 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
|
340 //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
|
341 }; |
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
|
342 |
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
|
343 //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
|
344 static const uint8_t obmc4[16]={ |
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
|
345 4,12,12, 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
|
346 12,36,36,12, |
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
|
347 12,36,36,12, |
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 4,12,12, 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
|
349 //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
|
350 }; |
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
|
351 |
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
|
352 static const uint8_t *obmc_tab[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
|
353 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
|
354 }; |
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
|
355 |
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
|
356 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
|
357 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
|
358 int16_t my; |
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 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
|
360 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
|
361 //#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
|
362 #define BLOCK_INTRA 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
|
363 //#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
|
364 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
|
365 }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
|
366 |
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 #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
|
368 #define MB_SIZE (1<<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
|
369 |
2138 | 370 typedef struct SubBand{ |
371 int level; | |
372 int stride; | |
373 int width; | |
374 int height; | |
375 int qlog; ///< log(qscale)/log[2^(1/6)] | |
376 DWTELEM *buf; | |
2192 | 377 int16_t *x; |
2193 | 378 DWTELEM *coeff; |
2138 | 379 struct SubBand *parent; |
380 uint8_t state[/*7*2*/ 7 + 512][32]; | |
381 }SubBand; | |
382 | |
383 typedef struct Plane{ | |
384 int width; | |
385 int height; | |
386 SubBand band[MAX_DECOMPOSITIONS][4]; | |
387 }Plane; | |
388 | |
389 typedef struct SnowContext{ | |
390 // MpegEncContext m; // needed for motion estimation, should not be used for anything else, the idea is to make the motion estimation eventually independant of MpegEncContext, so this will be removed then (FIXME/XXX) | |
391 | |
392 AVCodecContext *avctx; | |
393 CABACContext c; | |
394 DSPContext dsp; | |
395 AVFrame input_picture; | |
396 AVFrame current_picture; | |
397 AVFrame last_picture; | |
398 AVFrame mconly_picture; | |
399 // uint8_t q_context[16]; | |
400 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
|
401 uint8_t block_state[128 + 32*128]; |
2138 | 402 int keyframe; |
403 int version; | |
404 int spatial_decomposition_type; | |
405 int temporal_decomposition_type; | |
406 int spatial_decomposition_count; | |
407 int temporal_decomposition_count; | |
408 DWTELEM *spatial_dwt_buffer; | |
409 DWTELEM *pred_buffer; | |
410 int colorspace_type; | |
411 int chroma_h_shift; | |
412 int chroma_v_shift; | |
413 int spatial_scalability; | |
414 int 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
|
415 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
|
416 int lambda2; |
2138 | 417 int mv_scale; |
418 int qbias; | |
419 #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
|
420 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
|
421 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
|
422 int block_max_depth; |
2138 | 423 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
|
424 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
|
425 |
2138 | 426 MpegEncContext m; // needed for motion estimation, should not be used for anything else, the idea is to make the motion estimation eventually independant of MpegEncContext, so this will be removed then (FIXME/XXX) |
427 }SnowContext; | |
428 | |
429 #define QEXPSHIFT 7 //FIXME try to change this to 0 | |
430 static const uint8_t qexp[8]={ | |
431 128, 140, 152, 166, 181, 197, 215, 235 | |
432 // 64, 70, 76, 83, 91, 99, 108, 117 | |
433 // 32, 35, 38, 41, 45, 49, 54, 59 | |
434 // 16, 17, 19, 21, 23, 25, 27, 29 | |
435 // 8, 9, 10, 10, 11, 12, 13, 15 | |
436 }; | |
437 | |
438 static inline int mirror(int v, int m){ | |
439 if (v<0) return -v; | |
440 else if(v>m) return 2*m-v; | |
441 else return v; | |
442 } | |
443 | |
444 static inline void put_symbol(CABACContext *c, uint8_t *state, int v, int is_signed){ | |
445 int i; | |
446 | |
447 if(v){ | |
448 const int a= ABS(v); | |
449 const int e= av_log2(a); | |
450 #if 1 | |
451 const int el= FFMIN(e, 10); | |
452 put_cabac(c, state+0, 0); | |
453 | |
454 for(i=0; i<el; i++){ | |
455 put_cabac(c, state+1+i, 1); //1..10 | |
456 } | |
457 for(; i<e; i++){ | |
458 put_cabac(c, state+1+9, 1); //1..10 | |
459 } | |
460 put_cabac(c, state+1+FFMIN(i,9), 0); | |
461 | |
462 for(i=e-1; i>=el; i--){ | |
463 put_cabac(c, state+22+9, (a>>i)&1); //22..31 | |
464 } | |
465 for(; i>=0; i--){ | |
466 put_cabac(c, state+22+i, (a>>i)&1); //22..31 | |
467 } | |
468 | |
469 if(is_signed) | |
470 put_cabac(c, state+11 + el, v < 0); //11..21 | |
471 #else | |
472 | |
473 put_cabac(c, state+0, 0); | |
474 if(e<=9){ | |
475 for(i=0; i<e; i++){ | |
476 put_cabac(c, state+1+i, 1); //1..10 | |
477 } | |
478 put_cabac(c, state+1+i, 0); | |
479 | |
480 for(i=e-1; i>=0; i--){ | |
481 put_cabac(c, state+22+i, (a>>i)&1); //22..31 | |
482 } | |
483 | |
484 if(is_signed) | |
485 put_cabac(c, state+11 + e, v < 0); //11..21 | |
486 }else{ | |
487 for(i=0; i<e; i++){ | |
488 put_cabac(c, state+1+FFMIN(i,9), 1); //1..10 | |
489 } | |
490 put_cabac(c, state+1+FFMIN(i,9), 0); | |
491 | |
492 for(i=e-1; i>=0; i--){ | |
493 put_cabac(c, state+22+FFMIN(i,9), (a>>i)&1); //22..31 | |
494 } | |
495 | |
496 if(is_signed) | |
497 put_cabac(c, state+11 + FFMIN(e,10), v < 0); //11..21 | |
498 } | |
499 #endif | |
500 }else{ | |
501 put_cabac(c, state+0, 1); | |
502 } | |
503 } | |
504 | |
505 static inline int get_symbol(CABACContext *c, uint8_t *state, int is_signed){ | |
506 if(get_cabac(c, state+0)) | |
507 return 0; | |
508 else{ | |
509 int i, e, a, el; | |
510 //FIXME try to merge loops with FFMIN() maybe they are equally fast and they are surly cuter | |
511 for(e=0; e<10; e++){ | |
512 if(get_cabac(c, state + 1 + e)==0) // 1..10 | |
513 break; | |
514 } | |
515 el= e; | |
516 | |
517 if(e==10){ | |
518 while(get_cabac(c, state + 1 + 9)) //10 | |
519 e++; | |
520 } | |
521 a= 1; | |
522 for(i=e-1; i>=el; i--){ | |
523 a += a + get_cabac(c, state+22+9); //31 | |
524 } | |
525 for(; i>=0; i--){ | |
526 a += a + get_cabac(c, state+22+i); //22..31 | |
527 } | |
528 | |
529 if(is_signed && get_cabac(c, state+11 + el)) //11..21 | |
530 return -a; | |
531 else | |
532 return a; | |
533 } | |
534 } | |
535 | |
2155
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
536 static inline void put_symbol2(CABACContext *c, uint8_t *state, int v, int log2){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
537 int i; |
2159
7f42295c1517
improved magnitude coding, 0.2% lower bitrate (foreman@352x288 qscale 1 and 8)
michael
parents:
2156
diff
changeset
|
538 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
|
539 |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
540 assert(v>=0); |
2159
7f42295c1517
improved magnitude coding, 0.2% lower bitrate (foreman@352x288 qscale 1 and 8)
michael
parents:
2156
diff
changeset
|
541 assert(log2>=-4); |
7f42295c1517
improved magnitude coding, 0.2% lower bitrate (foreman@352x288 qscale 1 and 8)
michael
parents:
2156
diff
changeset
|
542 |
7f42295c1517
improved magnitude coding, 0.2% lower bitrate (foreman@352x288 qscale 1 and 8)
michael
parents:
2156
diff
changeset
|
543 while(v >= r){ |
7f42295c1517
improved magnitude coding, 0.2% lower bitrate (foreman@352x288 qscale 1 and 8)
michael
parents:
2156
diff
changeset
|
544 put_cabac(c, state+4+log2, 1); |
7f42295c1517
improved magnitude coding, 0.2% lower bitrate (foreman@352x288 qscale 1 and 8)
michael
parents:
2156
diff
changeset
|
545 v -= r; |
2155
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
546 log2++; |
2159
7f42295c1517
improved magnitude coding, 0.2% lower bitrate (foreman@352x288 qscale 1 and 8)
michael
parents:
2156
diff
changeset
|
547 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
|
548 } |
2159
7f42295c1517
improved magnitude coding, 0.2% lower bitrate (foreman@352x288 qscale 1 and 8)
michael
parents:
2156
diff
changeset
|
549 put_cabac(c, state+4+log2, 0); |
2155
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
550 |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
551 for(i=log2-1; i>=0; i--){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
552 put_cabac(c, state+31-i, (v>>i)&1); |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
553 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
554 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
555 |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
556 static inline int get_symbol2(CABACContext *c, uint8_t *state, int log2){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
557 int i; |
2159
7f42295c1517
improved magnitude coding, 0.2% lower bitrate (foreman@352x288 qscale 1 and 8)
michael
parents:
2156
diff
changeset
|
558 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
|
559 int v=0; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
560 |
2159
7f42295c1517
improved magnitude coding, 0.2% lower bitrate (foreman@352x288 qscale 1 and 8)
michael
parents:
2156
diff
changeset
|
561 assert(log2>=-4); |
7f42295c1517
improved magnitude coding, 0.2% lower bitrate (foreman@352x288 qscale 1 and 8)
michael
parents:
2156
diff
changeset
|
562 |
7f42295c1517
improved magnitude coding, 0.2% lower bitrate (foreman@352x288 qscale 1 and 8)
michael
parents:
2156
diff
changeset
|
563 while(get_cabac(c, state+4+log2)){ |
7f42295c1517
improved magnitude coding, 0.2% lower bitrate (foreman@352x288 qscale 1 and 8)
michael
parents:
2156
diff
changeset
|
564 v+= r; |
2155
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
565 log2++; |
2159
7f42295c1517
improved magnitude coding, 0.2% lower bitrate (foreman@352x288 qscale 1 and 8)
michael
parents:
2156
diff
changeset
|
566 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
|
567 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
568 |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
569 for(i=log2-1; i>=0; i--){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
570 v+= get_cabac(c, state+31-i)<<i; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
571 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
572 |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
573 return v; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
574 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
575 |
2138 | 576 static always_inline void lift(DWTELEM *dst, DWTELEM *src, DWTELEM *ref, int dst_step, int src_step, int ref_step, int width, int mul, int add, int shift, int highpass, int inverse){ |
577 const int mirror_left= !highpass; | |
578 const int mirror_right= (width&1) ^ highpass; | |
579 const int w= (width>>1) - 1 + (highpass & width); | |
580 int i; | |
581 | |
582 #define LIFT(src, ref, inv) ((src) + ((inv) ? - (ref) : + (ref))) | |
583 if(mirror_left){ | |
584 dst[0] = LIFT(src[0], ((mul*2*ref[0]+add)>>shift), inverse); | |
585 dst += dst_step; | |
586 src += src_step; | |
587 } | |
588 | |
589 for(i=0; i<w; i++){ | |
590 dst[i*dst_step] = LIFT(src[i*src_step], ((mul*(ref[i*ref_step] + ref[(i+1)*ref_step])+add)>>shift), inverse); | |
591 } | |
592 | |
593 if(mirror_right){ | |
594 dst[w*dst_step] = LIFT(src[w*src_step], ((mul*2*ref[w*ref_step]+add)>>shift), inverse); | |
595 } | |
596 } | |
597 | |
598 static always_inline void lift5(DWTELEM *dst, DWTELEM *src, DWTELEM *ref, int dst_step, int src_step, int ref_step, int width, int mul, int add, int shift, int highpass, int inverse){ | |
599 const int mirror_left= !highpass; | |
600 const int mirror_right= (width&1) ^ highpass; | |
601 const int w= (width>>1) - 1 + (highpass & width); | |
602 int i; | |
603 | |
604 if(mirror_left){ | |
605 int r= 3*2*ref[0]; | |
606 r += r>>4; | |
607 r += r>>8; | |
608 dst[0] = LIFT(src[0], ((r+add)>>shift), inverse); | |
609 dst += dst_step; | |
610 src += src_step; | |
611 } | |
612 | |
613 for(i=0; i<w; i++){ | |
614 int r= 3*(ref[i*ref_step] + ref[(i+1)*ref_step]); | |
615 r += r>>4; | |
616 r += r>>8; | |
617 dst[i*dst_step] = LIFT(src[i*src_step], ((r+add)>>shift), inverse); | |
618 } | |
619 | |
620 if(mirror_right){ | |
621 int r= 3*2*ref[w*ref_step]; | |
622 r += r>>4; | |
623 r += r>>8; | |
624 dst[w*dst_step] = LIFT(src[w*src_step], ((r+add)>>shift), inverse); | |
625 } | |
626 } | |
627 | |
628 | |
629 static void inplace_lift(int *dst, int width, int *coeffs, int n, int shift, int start, int inverse){ | |
630 int x, i; | |
631 | |
632 for(x=start; x<width; x+=2){ | |
633 int64_t sum=0; | |
634 | |
635 for(i=0; i<n; i++){ | |
636 int x2= x + 2*i - n + 1; | |
637 if (x2< 0) x2= -x2; | |
638 else if(x2>=width) x2= 2*width-x2-2; | |
639 sum += coeffs[i]*(int64_t)dst[x2]; | |
640 } | |
641 if(inverse) dst[x] -= (sum + (1<<shift)/2)>>shift; | |
642 else dst[x] += (sum + (1<<shift)/2)>>shift; | |
643 } | |
644 } | |
645 | |
646 static void inplace_liftV(int *dst, int width, int height, int stride, int *coeffs, int n, int shift, int start, int inverse){ | |
647 int x, y, i; | |
648 for(y=start; y<height; y+=2){ | |
649 for(x=0; x<width; x++){ | |
650 int64_t sum=0; | |
651 | |
652 for(i=0; i<n; i++){ | |
653 int y2= y + 2*i - n + 1; | |
654 if (y2< 0) y2= -y2; | |
655 else if(y2>=height) y2= 2*height-y2-2; | |
656 sum += coeffs[i]*(int64_t)dst[x + y2*stride]; | |
657 } | |
658 if(inverse) dst[x + y*stride] -= (sum + (1<<shift)/2)>>shift; | |
659 else dst[x + y*stride] += (sum + (1<<shift)/2)>>shift; | |
660 } | |
661 } | |
662 } | |
663 | |
664 #define SCALEX 1 | |
665 #define LX0 0 | |
666 #define LX1 1 | |
667 | |
2139 | 668 #if 0 // more accurate 9/7 |
2138 | 669 #define N1 2 |
670 #define SHIFT1 14 | |
671 #define COEFFS1 (int[]){-25987,-25987} | |
672 #define N2 2 | |
673 #define SHIFT2 19 | |
674 #define COEFFS2 (int[]){-27777,-27777} | |
675 #define N3 2 | |
676 #define SHIFT3 15 | |
677 #define COEFFS3 (int[]){28931,28931} | |
678 #define N4 2 | |
679 #define SHIFT4 15 | |
680 #define COEFFS4 (int[]){14533,14533} | |
681 #elif 1 // 13/7 CRF | |
682 #define N1 4 | |
683 #define SHIFT1 4 | |
684 #define COEFFS1 (int[]){1,-9,-9,1} | |
2139 | 685 #define N2 4 |
2138 | 686 #define SHIFT2 4 |
687 #define COEFFS2 (int[]){-1,5,5,-1} | |
688 #define N3 0 | |
689 #define SHIFT3 1 | |
690 #define COEFFS3 NULL | |
691 #define N4 0 | |
692 #define SHIFT4 1 | |
693 #define COEFFS4 NULL | |
694 #elif 1 // 3/5 | |
695 #define LX0 1 | |
696 #define LX1 0 | |
697 #define SCALEX 0.5 | |
698 #define N1 2 | |
699 #define SHIFT1 1 | |
700 #define COEFFS1 (int[]){1,1} | |
701 #define N2 2 | |
702 #define SHIFT2 2 | |
703 #define COEFFS2 (int[]){-1,-1} | |
704 #define N3 0 | |
705 #define SHIFT3 0 | |
706 #define COEFFS3 NULL | |
707 #define N4 0 | |
708 #define SHIFT4 0 | |
709 #define COEFFS4 NULL | |
710 #elif 1 // 11/5 | |
711 #define N1 0 | |
712 #define SHIFT1 1 | |
713 #define COEFFS1 NULL | |
714 #define N2 2 | |
715 #define SHIFT2 2 | |
716 #define COEFFS2 (int[]){-1,-1} | |
717 #define N3 2 | |
718 #define SHIFT3 0 | |
719 #define COEFFS3 (int[]){-1,-1} | |
720 #define N4 4 | |
721 #define SHIFT4 7 | |
722 #define COEFFS4 (int[]){-5,29,29,-5} | |
723 #define SCALEX 4 | |
724 #elif 1 // 9/7 CDF | |
725 #define N1 2 | |
726 #define SHIFT1 7 | |
727 #define COEFFS1 (int[]){-203,-203} | |
728 #define N2 2 | |
729 #define SHIFT2 12 | |
730 #define COEFFS2 (int[]){-217,-217} | |
731 #define N3 2 | |
732 #define SHIFT3 7 | |
733 #define COEFFS3 (int[]){113,113} | |
734 #define N4 2 | |
735 #define SHIFT4 9 | |
736 #define COEFFS4 (int[]){227,227} | |
737 #define SCALEX 1 | |
738 #elif 1 // 7/5 CDF | |
739 #define N1 0 | |
740 #define SHIFT1 1 | |
741 #define COEFFS1 NULL | |
742 #define N2 2 | |
743 #define SHIFT2 2 | |
744 #define COEFFS2 (int[]){-1,-1} | |
745 #define N3 2 | |
746 #define SHIFT3 0 | |
747 #define COEFFS3 (int[]){-1,-1} | |
748 #define N4 2 | |
749 #define SHIFT4 4 | |
750 #define COEFFS4 (int[]){3,3} | |
751 #elif 1 // 9/7 MN | |
752 #define N1 4 | |
753 #define SHIFT1 4 | |
754 #define COEFFS1 (int[]){1,-9,-9,1} | |
755 #define N2 2 | |
756 #define SHIFT2 2 | |
757 #define COEFFS2 (int[]){1,1} | |
758 #define N3 0 | |
759 #define SHIFT3 1 | |
760 #define COEFFS3 NULL | |
761 #define N4 0 | |
762 #define SHIFT4 1 | |
763 #define COEFFS4 NULL | |
764 #else // 13/7 CRF | |
765 #define N1 4 | |
766 #define SHIFT1 4 | |
767 #define COEFFS1 (int[]){1,-9,-9,1} | |
768 #define N2 4 | |
769 #define SHIFT2 4 | |
770 #define COEFFS2 (int[]){-1,5,5,-1} | |
771 #define N3 0 | |
772 #define SHIFT3 1 | |
773 #define COEFFS3 NULL | |
774 #define N4 0 | |
775 #define SHIFT4 1 | |
776 #define COEFFS4 NULL | |
777 #endif | |
778 static void horizontal_decomposeX(int *b, int width){ | |
779 int temp[width]; | |
780 const int width2= width>>1; | |
781 const int w2= (width+1)>>1; | |
782 int A1,A2,A3,A4, x; | |
783 | |
784 inplace_lift(b, width, COEFFS1, N1, SHIFT1, LX1, 0); | |
785 inplace_lift(b, width, COEFFS2, N2, SHIFT2, LX0, 0); | |
786 inplace_lift(b, width, COEFFS3, N3, SHIFT3, LX1, 0); | |
787 inplace_lift(b, width, COEFFS4, N4, SHIFT4, LX0, 0); | |
788 | |
789 for(x=0; x<width2; x++){ | |
790 temp[x ]= b[2*x ]; | |
791 temp[x+w2]= b[2*x + 1]; | |
792 } | |
793 if(width&1) | |
794 temp[x ]= b[2*x ]; | |
795 memcpy(b, temp, width*sizeof(int)); | |
796 } | |
797 | |
798 static void horizontal_composeX(int *b, int width){ | |
799 int temp[width]; | |
800 const int width2= width>>1; | |
801 int A1,A2,A3,A4, x; | |
802 const int w2= (width+1)>>1; | |
803 | |
804 memcpy(temp, b, width*sizeof(int)); | |
805 for(x=0; x<width2; x++){ | |
806 b[2*x ]= temp[x ]; | |
807 b[2*x + 1]= temp[x+w2]; | |
808 } | |
809 if(width&1) | |
810 b[2*x ]= temp[x ]; | |
811 | |
812 inplace_lift(b, width, COEFFS4, N4, SHIFT4, LX0, 1); | |
813 inplace_lift(b, width, COEFFS3, N3, SHIFT3, LX1, 1); | |
814 inplace_lift(b, width, COEFFS2, N2, SHIFT2, LX0, 1); | |
815 inplace_lift(b, width, COEFFS1, N1, SHIFT1, LX1, 1); | |
816 } | |
817 | |
818 static void spatial_decomposeX(int *buffer, int width, int height, int stride){ | |
819 int x, y; | |
820 | |
821 for(y=0; y<height; y++){ | |
822 for(x=0; x<width; x++){ | |
823 buffer[y*stride + x] *= SCALEX; | |
824 } | |
825 } | |
826 | |
827 for(y=0; y<height; y++){ | |
828 horizontal_decomposeX(buffer + y*stride, width); | |
829 } | |
830 | |
831 inplace_liftV(buffer, width, height, stride, COEFFS1, N1, SHIFT1, LX1, 0); | |
832 inplace_liftV(buffer, width, height, stride, COEFFS2, N2, SHIFT2, LX0, 0); | |
833 inplace_liftV(buffer, width, height, stride, COEFFS3, N3, SHIFT3, LX1, 0); | |
834 inplace_liftV(buffer, width, height, stride, COEFFS4, N4, SHIFT4, LX0, 0); | |
835 } | |
836 | |
837 static void spatial_composeX(int *buffer, int width, int height, int stride){ | |
838 int x, y; | |
839 | |
840 inplace_liftV(buffer, width, height, stride, COEFFS4, N4, SHIFT4, LX0, 1); | |
841 inplace_liftV(buffer, width, height, stride, COEFFS3, N3, SHIFT3, LX1, 1); | |
842 inplace_liftV(buffer, width, height, stride, COEFFS2, N2, SHIFT2, LX0, 1); | |
843 inplace_liftV(buffer, width, height, stride, COEFFS1, N1, SHIFT1, LX1, 1); | |
844 | |
845 for(y=0; y<height; y++){ | |
846 horizontal_composeX(buffer + y*stride, width); | |
847 } | |
848 | |
849 for(y=0; y<height; y++){ | |
850 for(x=0; x<width; x++){ | |
851 buffer[y*stride + x] /= SCALEX; | |
852 } | |
853 } | |
854 } | |
855 | |
856 static void horizontal_decompose53i(int *b, int width){ | |
857 int temp[width]; | |
858 const int width2= width>>1; | |
859 int A1,A2,A3,A4, x; | |
860 const int w2= (width+1)>>1; | |
861 | |
862 for(x=0; x<width2; x++){ | |
863 temp[x ]= b[2*x ]; | |
864 temp[x+w2]= b[2*x + 1]; | |
865 } | |
866 if(width&1) | |
867 temp[x ]= b[2*x ]; | |
868 #if 0 | |
869 A2= temp[1 ]; | |
870 A4= temp[0 ]; | |
871 A1= temp[0+width2]; | |
872 A1 -= (A2 + A4)>>1; | |
873 A4 += (A1 + 1)>>1; | |
874 b[0+width2] = A1; | |
875 b[0 ] = A4; | |
876 for(x=1; x+1<width2; x+=2){ | |
877 A3= temp[x+width2]; | |
878 A4= temp[x+1 ]; | |
879 A3 -= (A2 + A4)>>1; | |
880 A2 += (A1 + A3 + 2)>>2; | |
881 b[x+width2] = A3; | |
882 b[x ] = A2; | |
883 | |
884 A1= temp[x+1+width2]; | |
885 A2= temp[x+2 ]; | |
886 A1 -= (A2 + A4)>>1; | |
887 A4 += (A1 + A3 + 2)>>2; | |
888 b[x+1+width2] = A1; | |
889 b[x+1 ] = A4; | |
890 } | |
891 A3= temp[width-1]; | |
892 A3 -= A2; | |
893 A2 += (A1 + A3 + 2)>>2; | |
894 b[width -1] = A3; | |
895 b[width2-1] = A2; | |
896 #else | |
897 lift(b+w2, temp+w2, temp, 1, 1, 1, width, -1, 0, 1, 1, 0); | |
898 lift(b , temp , b+w2, 1, 1, 1, width, 1, 2, 2, 0, 0); | |
899 #endif | |
900 } | |
901 | |
902 static void vertical_decompose53iH0(int *b0, int *b1, int *b2, int width){ | |
903 int i; | |
904 | |
905 for(i=0; i<width; i++){ | |
906 b1[i] -= (b0[i] + b2[i])>>1; | |
907 } | |
908 } | |
909 | |
910 static void vertical_decompose53iL0(int *b0, int *b1, int *b2, int width){ | |
911 int i; | |
912 | |
913 for(i=0; i<width; i++){ | |
914 b1[i] += (b0[i] + b2[i] + 2)>>2; | |
915 } | |
916 } | |
917 | |
918 static void spatial_decompose53i(int *buffer, int width, int height, int stride){ | |
919 int x, y; | |
920 DWTELEM *b0= buffer + mirror(-2-1, height-1)*stride; | |
921 DWTELEM *b1= buffer + mirror(-2 , height-1)*stride; | |
922 | |
923 for(y=-2; y<height; y+=2){ | |
924 DWTELEM *b2= buffer + mirror(y+1, height-1)*stride; | |
925 DWTELEM *b3= buffer + mirror(y+2, height-1)*stride; | |
926 | |
927 {START_TIMER | |
928 if(b1 <= b3) horizontal_decompose53i(b2, width); | |
929 if(y+2 < height) horizontal_decompose53i(b3, width); | |
930 STOP_TIMER("horizontal_decompose53i")} | |
931 | |
932 {START_TIMER | |
933 if(b1 <= b3) vertical_decompose53iH0(b1, b2, b3, width); | |
934 if(b0 <= b2) vertical_decompose53iL0(b0, b1, b2, width); | |
935 STOP_TIMER("vertical_decompose53i*")} | |
936 | |
937 b0=b2; | |
938 b1=b3; | |
939 } | |
940 } | |
941 | |
942 #define lift5 lift | |
943 #if 1 | |
944 #define W_AM 3 | |
945 #define W_AO 0 | |
946 #define W_AS 1 | |
947 | |
948 #define W_BM 1 | |
949 #define W_BO 8 | |
950 #define W_BS 4 | |
951 | |
952 #undef lift5 | |
953 #define W_CM 9999 | |
954 #define W_CO 2 | |
955 #define W_CS 2 | |
956 | |
957 #define W_DM 15 | |
958 #define W_DO 16 | |
959 #define W_DS 5 | |
960 #elif 0 | |
961 #define W_AM 55 | |
962 #define W_AO 16 | |
963 #define W_AS 5 | |
964 | |
965 #define W_BM 3 | |
966 #define W_BO 32 | |
967 #define W_BS 6 | |
968 | |
969 #define W_CM 127 | |
970 #define W_CO 64 | |
971 #define W_CS 7 | |
972 | |
973 #define W_DM 7 | |
974 #define W_DO 8 | |
975 #define W_DS 4 | |
976 #elif 0 | |
977 #define W_AM 97 | |
978 #define W_AO 32 | |
979 #define W_AS 6 | |
980 | |
981 #define W_BM 63 | |
982 #define W_BO 512 | |
983 #define W_BS 10 | |
984 | |
985 #define W_CM 13 | |
986 #define W_CO 8 | |
987 #define W_CS 4 | |
988 | |
989 #define W_DM 15 | |
990 #define W_DO 16 | |
991 #define W_DS 5 | |
992 | |
993 #else | |
994 | |
995 #define W_AM 203 | |
996 #define W_AO 64 | |
997 #define W_AS 7 | |
998 | |
999 #define W_BM 217 | |
1000 #define W_BO 2048 | |
1001 #define W_BS 12 | |
1002 | |
1003 #define W_CM 113 | |
1004 #define W_CO 64 | |
1005 #define W_CS 7 | |
1006 | |
1007 #define W_DM 227 | |
1008 #define W_DO 128 | |
1009 #define W_DS 9 | |
1010 #endif | |
1011 static void horizontal_decompose97i(int *b, int width){ | |
1012 int temp[width]; | |
1013 const int w2= (width+1)>>1; | |
1014 | |
1015 lift (temp+w2, b +1, b , 1, 2, 2, width, -W_AM, W_AO, W_AS, 1, 0); | |
1016 lift (temp , b , temp+w2, 1, 2, 1, width, -W_BM, W_BO, W_BS, 0, 0); | |
1017 lift5(b +w2, temp+w2, temp , 1, 1, 1, width, W_CM, W_CO, W_CS, 1, 0); | |
1018 lift (b , temp , b +w2, 1, 1, 1, width, W_DM, W_DO, W_DS, 0, 0); | |
1019 } | |
1020 | |
1021 | |
1022 static void vertical_decompose97iH0(int *b0, int *b1, int *b2, int width){ | |
1023 int i; | |
1024 | |
1025 for(i=0; i<width; i++){ | |
1026 b1[i] -= (W_AM*(b0[i] + b2[i])+W_AO)>>W_AS; | |
1027 } | |
1028 } | |
1029 | |
1030 static void vertical_decompose97iH1(int *b0, int *b1, int *b2, int width){ | |
1031 int i; | |
1032 | |
1033 for(i=0; i<width; i++){ | |
1034 #ifdef lift5 | |
1035 b1[i] += (W_CM*(b0[i] + b2[i])+W_CO)>>W_CS; | |
1036 #else | |
1037 int r= 3*(b0[i] + b2[i]); | |
1038 r+= r>>4; | |
1039 r+= r>>8; | |
1040 b1[i] += (r+W_CO)>>W_CS; | |
1041 #endif | |
1042 } | |
1043 } | |
1044 | |
1045 static void vertical_decompose97iL0(int *b0, int *b1, int *b2, int width){ | |
1046 int i; | |
1047 | |
1048 for(i=0; i<width; i++){ | |
1049 b1[i] -= (W_BM*(b0[i] + b2[i])+W_BO)>>W_BS; | |
1050 } | |
1051 } | |
1052 | |
1053 static void vertical_decompose97iL1(int *b0, int *b1, int *b2, int width){ | |
1054 int i; | |
1055 | |
1056 for(i=0; i<width; i++){ | |
1057 b1[i] += (W_DM*(b0[i] + b2[i])+W_DO)>>W_DS; | |
1058 } | |
1059 } | |
1060 | |
1061 static void spatial_decompose97i(int *buffer, int width, int height, int stride){ | |
1062 int x, y; | |
1063 DWTELEM *b0= buffer + mirror(-4-1, height-1)*stride; | |
1064 DWTELEM *b1= buffer + mirror(-4 , height-1)*stride; | |
1065 DWTELEM *b2= buffer + mirror(-4+1, height-1)*stride; | |
1066 DWTELEM *b3= buffer + mirror(-4+2, height-1)*stride; | |
1067 | |
1068 for(y=-4; y<height; y+=2){ | |
1069 DWTELEM *b4= buffer + mirror(y+3, height-1)*stride; | |
1070 DWTELEM *b5= buffer + mirror(y+4, height-1)*stride; | |
1071 | |
1072 {START_TIMER | |
1073 if(b3 <= b5) horizontal_decompose97i(b4, width); | |
1074 if(y+4 < height) horizontal_decompose97i(b5, width); | |
1075 if(width>400){ | |
1076 STOP_TIMER("horizontal_decompose97i") | |
1077 }} | |
1078 | |
1079 {START_TIMER | |
1080 if(b3 <= b5) vertical_decompose97iH0(b3, b4, b5, width); | |
1081 if(b2 <= b4) vertical_decompose97iL0(b2, b3, b4, width); | |
1082 if(b1 <= b3) vertical_decompose97iH1(b1, b2, b3, width); | |
1083 if(b0 <= b2) vertical_decompose97iL1(b0, b1, b2, width); | |
1084 | |
1085 if(width>400){ | |
1086 STOP_TIMER("vertical_decompose97i") | |
1087 }} | |
1088 | |
1089 b0=b2; | |
1090 b1=b3; | |
1091 b2=b4; | |
1092 b3=b5; | |
1093 } | |
1094 } | |
1095 | |
2164 | 1096 void ff_spatial_dwt(int *buffer, int width, int height, int stride, int type, int decomposition_count){ |
2138 | 1097 int level; |
1098 | |
2164 | 1099 for(level=0; level<decomposition_count; level++){ |
1100 switch(type){ | |
2138 | 1101 case 0: spatial_decompose97i(buffer, width>>level, height>>level, stride<<level); break; |
1102 case 1: spatial_decompose53i(buffer, width>>level, height>>level, stride<<level); break; | |
1103 case 2: spatial_decomposeX (buffer, width>>level, height>>level, stride<<level); break; | |
1104 } | |
1105 } | |
1106 } | |
1107 | |
1108 static void horizontal_compose53i(int *b, int width){ | |
1109 int temp[width]; | |
1110 const int width2= width>>1; | |
1111 const int w2= (width+1)>>1; | |
1112 int A1,A2,A3,A4, x; | |
1113 | |
1114 #if 0 | |
1115 A2= temp[1 ]; | |
1116 A4= temp[0 ]; | |
1117 A1= temp[0+width2]; | |
1118 A1 -= (A2 + A4)>>1; | |
1119 A4 += (A1 + 1)>>1; | |
1120 b[0+width2] = A1; | |
1121 b[0 ] = A4; | |
1122 for(x=1; x+1<width2; x+=2){ | |
1123 A3= temp[x+width2]; | |
1124 A4= temp[x+1 ]; | |
1125 A3 -= (A2 + A4)>>1; | |
1126 A2 += (A1 + A3 + 2)>>2; | |
1127 b[x+width2] = A3; | |
1128 b[x ] = A2; | |
1129 | |
1130 A1= temp[x+1+width2]; | |
1131 A2= temp[x+2 ]; | |
1132 A1 -= (A2 + A4)>>1; | |
1133 A4 += (A1 + A3 + 2)>>2; | |
1134 b[x+1+width2] = A1; | |
1135 b[x+1 ] = A4; | |
1136 } | |
1137 A3= temp[width-1]; | |
1138 A3 -= A2; | |
1139 A2 += (A1 + A3 + 2)>>2; | |
1140 b[width -1] = A3; | |
1141 b[width2-1] = A2; | |
1142 #else | |
1143 lift(temp , b , b+w2, 1, 1, 1, width, 1, 2, 2, 0, 1); | |
1144 lift(temp+w2, b+w2, temp, 1, 1, 1, width, -1, 0, 1, 1, 1); | |
1145 #endif | |
1146 for(x=0; x<width2; x++){ | |
1147 b[2*x ]= temp[x ]; | |
1148 b[2*x + 1]= temp[x+w2]; | |
1149 } | |
1150 if(width&1) | |
1151 b[2*x ]= temp[x ]; | |
1152 } | |
1153 | |
1154 static void vertical_compose53iH0(int *b0, int *b1, int *b2, int width){ | |
1155 int i; | |
1156 | |
1157 for(i=0; i<width; i++){ | |
1158 b1[i] += (b0[i] + b2[i])>>1; | |
1159 } | |
1160 } | |
1161 | |
1162 static void vertical_compose53iL0(int *b0, int *b1, int *b2, int width){ | |
1163 int i; | |
1164 | |
1165 for(i=0; i<width; i++){ | |
1166 b1[i] -= (b0[i] + b2[i] + 2)>>2; | |
1167 } | |
1168 } | |
1169 | |
1170 static void spatial_compose53i(int *buffer, int width, int height, int stride){ | |
1171 int x, y; | |
1172 DWTELEM *b0= buffer + mirror(-1-1, height-1)*stride; | |
1173 DWTELEM *b1= buffer + mirror(-1 , height-1)*stride; | |
1174 | |
1175 for(y=-1; y<=height; y+=2){ | |
1176 DWTELEM *b2= buffer + mirror(y+1, height-1)*stride; | |
1177 DWTELEM *b3= buffer + mirror(y+2, height-1)*stride; | |
1178 | |
1179 {START_TIMER | |
1180 if(b1 <= b3) vertical_compose53iL0(b1, b2, b3, width); | |
1181 if(b0 <= b2) vertical_compose53iH0(b0, b1, b2, width); | |
1182 STOP_TIMER("vertical_compose53i*")} | |
1183 | |
1184 {START_TIMER | |
1185 if(y-1 >= 0) horizontal_compose53i(b0, width); | |
1186 if(b0 <= b2) horizontal_compose53i(b1, width); | |
1187 STOP_TIMER("horizontal_compose53i")} | |
1188 | |
1189 b0=b2; | |
1190 b1=b3; | |
1191 } | |
1192 } | |
1193 | |
1194 | |
1195 static void horizontal_compose97i(int *b, int width){ | |
1196 int temp[width]; | |
1197 const int w2= (width+1)>>1; | |
1198 | |
1199 lift (temp , b , b +w2, 1, 1, 1, width, W_DM, W_DO, W_DS, 0, 1); | |
1200 lift5(temp+w2, b +w2, temp , 1, 1, 1, width, W_CM, W_CO, W_CS, 1, 1); | |
1201 lift (b , temp , temp+w2, 2, 1, 1, width, -W_BM, W_BO, W_BS, 0, 1); | |
1202 lift (b+1 , temp+w2, b , 2, 1, 2, width, -W_AM, W_AO, W_AS, 1, 1); | |
1203 } | |
1204 | |
1205 static void vertical_compose97iH0(int *b0, int *b1, int *b2, int width){ | |
1206 int i; | |
1207 | |
1208 for(i=0; i<width; i++){ | |
1209 b1[i] += (W_AM*(b0[i] + b2[i])+W_AO)>>W_AS; | |
1210 } | |
1211 } | |
1212 | |
1213 static void vertical_compose97iH1(int *b0, int *b1, int *b2, int width){ | |
1214 int i; | |
1215 | |
1216 for(i=0; i<width; i++){ | |
1217 #ifdef lift5 | |
1218 b1[i] -= (W_CM*(b0[i] + b2[i])+W_CO)>>W_CS; | |
1219 #else | |
1220 int r= 3*(b0[i] + b2[i]); | |
1221 r+= r>>4; | |
1222 r+= r>>8; | |
1223 b1[i] -= (r+W_CO)>>W_CS; | |
1224 #endif | |
1225 } | |
1226 } | |
1227 | |
1228 static void vertical_compose97iL0(int *b0, int *b1, int *b2, int width){ | |
1229 int i; | |
1230 | |
1231 for(i=0; i<width; i++){ | |
1232 b1[i] += (W_BM*(b0[i] + b2[i])+W_BO)>>W_BS; | |
1233 } | |
1234 } | |
1235 | |
1236 static void vertical_compose97iL1(int *b0, int *b1, int *b2, int width){ | |
1237 int i; | |
1238 | |
1239 for(i=0; i<width; i++){ | |
1240 b1[i] -= (W_DM*(b0[i] + b2[i])+W_DO)>>W_DS; | |
1241 } | |
1242 } | |
1243 | |
1244 static void spatial_compose97i(int *buffer, int width, int height, int stride){ | |
1245 int x, y; | |
1246 DWTELEM *b0= buffer + mirror(-3-1, height-1)*stride; | |
1247 DWTELEM *b1= buffer + mirror(-3 , height-1)*stride; | |
1248 DWTELEM *b2= buffer + mirror(-3+1, height-1)*stride; | |
1249 DWTELEM *b3= buffer + mirror(-3+2, height-1)*stride; | |
1250 | |
1251 for(y=-3; y<=height; y+=2){ | |
1252 DWTELEM *b4= buffer + mirror(y+3, height-1)*stride; | |
1253 DWTELEM *b5= buffer + mirror(y+4, height-1)*stride; | |
1254 | |
1255 if(stride == width && y+4 < height && 0){ | |
1256 int x; | |
1257 for(x=0; x<width/2; x++) | |
1258 b5[x] += 64*2; | |
1259 for(; x<width; x++) | |
1260 b5[x] += 169*2; | |
1261 } | |
1262 | |
1263 {START_TIMER | |
1264 if(b3 <= b5) vertical_compose97iL1(b3, b4, b5, width); | |
1265 if(b2 <= b4) vertical_compose97iH1(b2, b3, b4, width); | |
1266 if(b1 <= b3) vertical_compose97iL0(b1, b2, b3, width); | |
1267 if(b0 <= b2) vertical_compose97iH0(b0, b1, b2, width); | |
1268 if(width>400){ | |
1269 STOP_TIMER("vertical_compose97i")}} | |
1270 | |
1271 {START_TIMER | |
1272 if(y-1>= 0) horizontal_compose97i(b0, width); | |
1273 if(b0 <= b2) horizontal_compose97i(b1, width); | |
1274 if(width>400 && b0 <= b2){ | |
1275 STOP_TIMER("horizontal_compose97i")}} | |
1276 | |
1277 b0=b2; | |
1278 b1=b3; | |
1279 b2=b4; | |
1280 b3=b5; | |
1281 } | |
1282 } | |
1283 | |
2164 | 1284 void ff_spatial_idwt(int *buffer, int width, int height, int stride, int type, int decomposition_count){ |
2138 | 1285 int level; |
1286 | |
2164 | 1287 for(level=decomposition_count-1; level>=0; level--){ |
1288 switch(type){ | |
2138 | 1289 case 0: spatial_compose97i(buffer, width>>level, height>>level, stride<<level); break; |
1290 case 1: spatial_compose53i(buffer, width>>level, height>>level, stride<<level); break; | |
1291 case 2: spatial_composeX (buffer, width>>level, height>>level, stride<<level); break; | |
1292 } | |
1293 } | |
1294 } | |
1295 | |
1296 static const int hilbert[16][2]={ | |
1297 {0,0}, {1,0}, {1,1}, {0,1}, | |
1298 {0,2}, {0,3}, {1,3}, {1,2}, | |
1299 {2,2}, {2,3}, {3,3}, {3,2}, | |
1300 {3,1}, {2,1}, {2,0}, {3,0}, | |
1301 }; | |
1302 #if 0 | |
1303 -o o- | |
1304 | | | |
1305 o-o | |
1306 | |
1307 -o-o o-o- | |
1308 | | | |
1309 o-o o-o | |
1310 | | | |
1311 o o-o o | |
1312 | | | | | |
1313 o-o o-o | |
1314 | |
1315 0112122312232334122323342334 | |
1316 0123456789ABCDEF0123456789AB | |
1317 RLLRMRRLLRRMRLLMLRRLMLLRRLLM | |
1318 | |
1319 4 B F 14 1B | |
1320 4 11 15 20 27 | |
1321 | |
1322 -o o-o-o o-o-o o- | |
1323 | | | | | | | |
1324 o-o o-o o-o o-o | |
1325 | | | |
1326 o-o o-o o-o o-o | |
1327 | | | | | | | |
1328 o o-o-o o-o-o o | |
1329 | | | |
1330 o-o o-o-o-o o-o | |
1331 | | | | | |
1332 o-o o-o o-o o-o | |
1333 | | | | | |
1334 o o-o o o o-o o | |
1335 | | | | | | | | | |
1336 o-o o-o o-o o-o | |
1337 | |
1338 #endif | |
1339 | |
1340 #define SVI(a, i, x, y) \ | |
1341 {\ | |
1342 a[i][0]= x;\ | |
1343 a[i][1]= y;\ | |
1344 i++;\ | |
1345 } | |
1346 | |
1347 static int sig_cmp(const void *a, const void *b){ | |
1348 const int16_t* da = (const int16_t *) a; | |
1349 const int16_t* db = (const int16_t *) b; | |
1350 | |
1351 if(da[1] != db[1]) return da[1] - db[1]; | |
1352 else return da[0] - db[0]; | |
1353 } | |
1354 | |
2155
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1355 static int deint(unsigned int a){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1356 a &= 0x55555555; //0 1 2 3 4 5 6 7 8 9 A B C D E F |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1357 a += a & 0x11111111; // 01 23 45 67 89 AB CD EF |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1358 a += 3*(a & 0x0F0F0F0F);// 0123 4567 89AB CDEF |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1359 a += 15*(a & 0x00FF00FF);// 01234567 89ABCDEF |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1360 a +=255*(a & 0x0000FFFF);// 0123456789ABCDEF |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1361 return a>>15; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1362 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1363 |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1364 static void encode_subband_z0run(SnowContext *s, SubBand *b, DWTELEM *src, DWTELEM *parent, int stride, int orientation){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1365 const int level= b->level; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1366 const int w= b->width; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1367 const int h= b->height; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1368 int x, y, pos; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1369 |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1370 if(1){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1371 int run=0; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1372 int runs[w*h]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1373 int run_index=0; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1374 int count=0; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1375 |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1376 for(pos=0; ; pos++){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1377 int x= deint(pos ); |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1378 int y= deint(pos>>1); |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1379 int v, p=0, pr=0, pd=0; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1380 int /*ll=0, */l=0, lt=0, t=0/*, rt=0*/; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1381 |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1382 if(x>=w || y>=h){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1383 if(x>=w && y>=h) |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1384 break; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1385 continue; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1386 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1387 count++; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1388 |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1389 v= src[x + y*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1390 |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1391 if(y){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1392 t= src[x + (y-1)*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1393 if(x){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1394 lt= src[x - 1 + (y-1)*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1395 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1396 if(x + 1 < w){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1397 /*rt= src[x + 1 + (y-1)*stride]*/; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1398 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1399 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1400 if(x){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1401 l= src[x - 1 + y*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1402 /*if(x > 1){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1403 if(orientation==1) ll= src[y + (x-2)*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1404 else ll= src[x - 2 + y*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1405 }*/ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1406 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1407 if(parent){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1408 int px= x>>1; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1409 int py= y>>1; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1410 if(px<b->parent->width && py<b->parent->height){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1411 p= parent[px + py*2*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1412 /*if(px+1<b->parent->width) |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1413 pr= parent[px + 1 + py*2*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1414 if(py+1<b->parent->height) |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1415 pd= parent[px + (py+1)*2*stride];*/ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1416 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1417 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1418 if(!(/*ll|*/l|lt|t|/*rt|*/p)){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1419 if(v){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1420 runs[run_index++]= run; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1421 run=0; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1422 }else{ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1423 run++; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1424 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1425 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1426 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1427 assert(count==w*h); |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1428 runs[run_index++]= run; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1429 run_index=0; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1430 run= runs[run_index++]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1431 |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1432 put_symbol(&s->c, b->state[1], run, 0); |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1433 |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1434 for(pos=0; ; pos++){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1435 int x= deint(pos ); |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1436 int y= deint(pos>>1); |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1437 int v, p=0, pr=0, pd=0; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1438 int /*ll=0, */l=0, lt=0, t=0/*, rt=0*/; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1439 |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1440 if(x>=w || y>=h){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1441 if(x>=w && y>=h) |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1442 break; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1443 continue; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1444 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1445 v= src[x + y*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1446 |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1447 if(y){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1448 t= src[x + (y-1)*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1449 if(x){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1450 lt= src[x - 1 + (y-1)*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1451 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1452 if(x + 1 < w){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1453 // rt= src[x + 1 + (y-1)*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1454 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1455 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1456 if(x){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1457 l= src[x - 1 + y*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1458 /*if(x > 1){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1459 if(orientation==1) ll= src[y + (x-2)*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1460 else ll= src[x - 2 + y*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1461 }*/ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1462 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1463 |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1464 if(parent){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1465 int px= x>>1; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1466 int py= y>>1; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1467 if(px<b->parent->width && py<b->parent->height){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1468 p= parent[px + py*2*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1469 /* if(px+1<b->parent->width) |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1470 pr= parent[px + 1 + py*2*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1471 if(py+1<b->parent->height) |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1472 pd= parent[px + (py+1)*2*stride];*/ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1473 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1474 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1475 if(/*ll|*/l|lt|t|/*rt|*/p){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1476 int context= av_log2(/*ABS(ll) + */2*(3*ABS(l) + ABS(lt) + 2*ABS(t) + /*ABS(rt) +*/ ABS(p))); |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1477 |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1478 put_cabac(&s->c, &b->state[0][context], !!v); |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1479 }else{ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1480 if(!run){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1481 run= runs[run_index++]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1482 put_symbol(&s->c, b->state[1], run, 0); |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1483 assert(v); |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1484 }else{ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1485 run--; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1486 assert(!v); |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1487 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1488 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1489 if(v){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1490 int context= av_log2(/*ABS(ll) + */3*ABS(l) + ABS(lt) + 2*ABS(t) + /*ABS(rt) +*/ ABS(p)); |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1491 |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1492 put_symbol(&s->c, b->state[context + 2], ABS(v)-1, 0); |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1493 put_cabac(&s->c, &b->state[0][16 + 1 + 3 + quant3b[l&0xFF] + 3*quant3b[t&0xFF]], v<0); |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1494 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1495 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1496 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1497 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1498 |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1499 static void encode_subband_bp(SnowContext *s, SubBand *b, DWTELEM *src, DWTELEM *parent, int stride, int orientation){ |
2138 | 1500 const int level= b->level; |
1501 const int w= b->width; | |
1502 const int h= b->height; | |
1503 int x, y; | |
2155
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1504 |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1505 #if 0 |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1506 int plane; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1507 for(plane=24; plane>=0; plane--){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1508 int run=0; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1509 int runs[w*h]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1510 int run_index=0; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1511 |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1512 for(y=0; y<h; y++){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1513 for(x=0; x<w; x++){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1514 int v, lv, p=0; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1515 int d=0, r=0, rd=0, ld=0; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1516 int /*ll=0, */l=0, lt=0, t=0, rt=0; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1517 v= src[x + y*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1518 |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1519 if(y){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1520 t= src[x + (y-1)*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1521 if(x){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1522 lt= src[x - 1 + (y-1)*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1523 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1524 if(x + 1 < w){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1525 rt= src[x + 1 + (y-1)*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1526 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1527 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1528 if(x){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1529 l= src[x - 1 + y*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1530 /*if(x > 1){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1531 if(orientation==1) ll= src[y + (x-2)*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1532 else ll= src[x - 2 + y*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1533 }*/ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1534 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1535 if(y+1<h){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1536 d= src[x + (y+1)*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1537 if(x) ld= src[x - 1 + (y+1)*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1538 if(x + 1 < w) rd= src[x + 1 + (y+1)*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1539 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1540 if(x + 1 < w) |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1541 r= src[x + 1 + y*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1542 if(parent){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1543 int px= x>>1; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1544 int py= y>>1; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1545 if(px<b->parent->width && py<b->parent->height) |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1546 p= parent[px + py*2*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1547 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1548 #define HIDE(c, plane) c= c>=0 ? c&((-1)<<(plane)) : -((-c)&((-1)<<(plane))); |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1549 lv=v; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1550 HIDE( v, plane) |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1551 HIDE(lv, plane+1) |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1552 HIDE( p, plane) |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1553 HIDE( l, plane) |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1554 HIDE(lt, plane) |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1555 HIDE( t, plane) |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1556 HIDE(rt, plane) |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1557 HIDE( r, plane+1) |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1558 HIDE(rd, plane+1) |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1559 HIDE( d, plane+1) |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1560 HIDE(ld, plane+1) |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1561 if(!(/*ll|*/l|lt|t|rt|r|rd|ld|d|p|lv)){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1562 if(v){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1563 runs[run_index++]= run; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1564 run=0; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1565 }else{ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1566 run++; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1567 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1568 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1569 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1570 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1571 runs[run_index++]= run; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1572 run_index=0; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1573 run= runs[run_index++]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1574 |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1575 put_symbol(&s->c, b->state[1], run, 0); |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1576 |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1577 for(y=0; y<h; y++){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1578 for(x=0; x<w; x++){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1579 int v, p=0, lv; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1580 int /*ll=0, */l=0, lt=0, t=0, rt=0; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1581 int d=0, r=0, rd=0, ld=0; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1582 v= src[x + y*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1583 |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1584 if(y){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1585 t= src[x + (y-1)*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1586 if(x){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1587 lt= src[x - 1 + (y-1)*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1588 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1589 if(x + 1 < w){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1590 rt= src[x + 1 + (y-1)*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1591 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1592 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1593 if(x){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1594 l= src[x - 1 + y*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1595 /*if(x > 1){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1596 if(orientation==1) ll= src[y + (x-2)*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1597 else ll= src[x - 2 + y*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1598 }*/ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1599 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1600 if(y+1<h){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1601 d= src[x + (y+1)*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1602 if(x) ld= src[x - 1 + (y+1)*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1603 if(x + 1 < w) rd= src[x + 1 + (y+1)*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1604 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1605 if(x + 1 < w) |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1606 r= src[x + 1 + y*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1607 |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1608 if(parent){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1609 int px= x>>1; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1610 int py= y>>1; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1611 if(px<b->parent->width && py<b->parent->height) |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1612 p= parent[px + py*2*stride]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1613 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1614 lv=v; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1615 HIDE( v, plane) |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1616 HIDE(lv, plane+1) |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1617 HIDE( p, plane) |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1618 HIDE( l, plane) |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1619 HIDE(lt, plane) |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1620 HIDE( t, plane) |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1621 HIDE(rt, plane) |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1622 HIDE( r, plane+1) |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1623 HIDE(rd, plane+1) |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1624 HIDE( d, plane+1) |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1625 HIDE(ld, plane+1) |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1626 if(/*ll|*/l|lt|t|rt|r|rd|ld|d|p|lv){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1627 int context= av_log2(/*ABS(ll) + */3*ABS(l) + ABS(lt) + 2*ABS(t) + ABS(rt) + ABS(p) |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1628 +3*ABS(r) + ABS(rd) + 2*ABS(d) + ABS(ld)); |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1629 |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1630 if(lv) put_cabac(&s->c, &b->state[99][context + 8*(av_log2(ABS(lv))-plane)], !!(v-lv)); |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1631 else put_cabac(&s->c, &b->state[ 0][context], !!v); |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1632 }else{ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1633 assert(!lv); |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1634 if(!run){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1635 run= runs[run_index++]; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1636 put_symbol(&s->c, b->state[1], run, 0); |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1637 assert(v); |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1638 }else{ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1639 run--; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1640 assert(!v); |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1641 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1642 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1643 if(v && !lv){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1644 int context= clip(quant3b[l&0xFF] + quant3b[r&0xFF], -1,1) |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1645 + 3*clip(quant3b[t&0xFF] + quant3b[d&0xFF], -1,1); |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1646 put_cabac(&s->c, &b->state[0][16 + 1 + 3 + context], v<0); |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1647 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1648 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1649 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1650 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1651 return; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1652 #endif |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1653 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1654 |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1655 static void encode_subband_X(SnowContext *s, SubBand *b, DWTELEM *src, DWTELEM *parent, int stride, int orientation){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1656 const int level= b->level; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1657 const int w= b->width; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1658 const int h= b->height; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1659 int x, y; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1660 |
2149 | 1661 #if 0 |
2138 | 1662 if(orientation==3 && parent && 0){ |
1663 int16_t candidate[w*h][2]; | |
1664 uint8_t state[w*h]; | |
1665 int16_t boarder[3][w*h*4][2]; | |
1666 int16_t significant[w*h][2]; | |
1667 int candidate_count=0; | |
1668 int boarder_count[3]={0,0,0}; | |
1669 int significant_count=0; | |
1670 int rle_pos=0; | |
1671 int v, last_v; | |
1672 int primary= orientation==1; | |
1673 | |
1674 memset(candidate, 0, sizeof(candidate)); | |
1675 memset(state, 0, sizeof(state)); | |
1676 memset(boarder, 0, sizeof(boarder)); | |
1677 | |
1678 for(y=0; y<h; y++){ | |
1679 for(x=0; x<w; x++){ | |
1680 if(parent[(x>>1) + (y>>1)*2*stride]) | |
1681 SVI(candidate, candidate_count, x, y) | |
1682 } | |
1683 } | |
1684 | |
1685 for(;;){ | |
1686 while(candidate_count && !boarder_count[0] && !boarder_count[1] && !boarder_count[2]){ | |
1687 candidate_count--; | |
1688 x= candidate[ candidate_count][0]; | |
1689 y= candidate[ candidate_count][1]; | |
1690 if(state[x + y*w]) | |
1691 continue; | |
1692 state[x + y*w]= 1; | |
1693 v= !!src[x + y*stride]; | |
1694 put_cabac(&s->c, &b->state[0][0], v); | |
1695 if(v){ | |
1696 SVI(significant, significant_count, x,y) | |
1697 if(x && !state[x - 1 + y *w]) SVI(boarder[0],boarder_count[0],x-1,y ) | |
1698 if(y && !state[x + (y-1)*w]) SVI(boarder[1],boarder_count[1],x ,y-1) | |
1699 if(x+1<w && !state[x + 1 + y *w]) SVI(boarder[0],boarder_count[0],x+1,y ) | |
1700 if(y+1<h && !state[x + (y+1)*w]) SVI(boarder[1],boarder_count[1],x ,y+1) | |
1701 if(x && y && !state[x - 1 + (y-1)*w]) SVI(boarder[2],boarder_count[2],x-1,y-1) | |
1702 if(x && y+1<h && !state[x - 1 + (y+1)*w]) SVI(boarder[2],boarder_count[2],x-1,y+1) | |
1703 if(x+1<w && y+1<h && !state[x + 1 + (y+1)*w]) SVI(boarder[2],boarder_count[2],x+1,y+1) | |
1704 if(x+1<w && y && !state[x + 1 + (y-1)*w]) SVI(boarder[2],boarder_count[2],x+1,y-1) | |
1705 } | |
1706 } | |
1707 while(!boarder_count[0] && !boarder_count[1] && !boarder_count[2] && rle_pos < w*h){ | |
1708 int run=0; | |
1709 for(; rle_pos < w*h;){ | |
1710 x= rle_pos % w; //FIXME speed | |
1711 y= rle_pos / w; | |
1712 rle_pos++; | |
1713 if(state[x + y*w]) | |
1714 continue; | |
1715 state[x + y*w]= 1; | |
1716 v= !!src[x + y*stride]; | |
1717 if(v){ | |
1718 put_symbol(&s->c, b->state[1], run, 0); | |
1719 SVI(significant, significant_count, x,y) | |
1720 if(x && !state[x - 1 + y *w]) SVI(boarder[0],boarder_count[0],x-1,y ) | |
1721 if(y && !state[x + (y-1)*w]) SVI(boarder[1],boarder_count[1],x ,y-1) | |
1722 if(x+1<w && !state[x + 1 + y *w]) SVI(boarder[0],boarder_count[0],x+1,y ) | |
1723 if(y+1<h && !state[x + (y+1)*w]) SVI(boarder[1],boarder_count[1],x ,y+1) | |
1724 if(x && y && !state[x - 1 + (y-1)*w]) SVI(boarder[2],boarder_count[2],x-1,y-1) | |
1725 if(x && y+1<h && !state[x - 1 + (y+1)*w]) SVI(boarder[2],boarder_count[2],x-1,y+1) | |
1726 if(x+1<w && y+1<h && !state[x + 1 + (y+1)*w]) SVI(boarder[2],boarder_count[2],x+1,y+1) | |
1727 if(x+1<w && y && !state[x + 1 + (y-1)*w]) SVI(boarder[2],boarder_count[2],x+1,y-1) | |
1728 break; | |
1729 //FIXME note only right & down can be boarders | |
1730 } | |
1731 run++; | |
1732 } | |
1733 } | |
1734 if(!boarder_count[0] && !boarder_count[1] && !boarder_count[2]) | |
1735 break; | |
1736 | |
1737 while(boarder_count[0] || boarder_count[1] || boarder_count[2]){ | |
1738 int index; | |
1739 | |
1740 if (boarder_count[ primary]) index= primary; | |
1741 else if(boarder_count[1-primary]) index=1-primary; | |
1742 else index=2; | |
1743 | |
1744 boarder_count[index]--; | |
1745 x= boarder[index][ boarder_count[index] ][0]; | |
1746 y= boarder[index][ boarder_count[index] ][1]; | |
1747 if(state[x + y*w]) //FIXME maybe check earlier | |
1748 continue; | |
1749 state[x + y*w]= 1; | |
1750 v= !!src[x + y*stride]; | |
1751 put_cabac(&s->c, &b->state[0][index+1], v); | |
1752 if(v){ | |
1753 SVI(significant, significant_count, x,y) | |
1754 if(x && !state[x - 1 + y *w]) SVI(boarder[0],boarder_count[0],x-1,y ) | |
1755 if(y && !state[x + (y-1)*w]) SVI(boarder[1],boarder_count[1],x ,y-1) | |
1756 if(x+1<w && !state[x + 1 + y *w]) SVI(boarder[0],boarder_count[0],x+1,y ) | |
1757 if(y+1<h && !state[x + (y+1)*w]) SVI(boarder[1],boarder_count[1],x ,y+1) | |
1758 if(x && y && !state[x - 1 + (y-1)*w]) SVI(boarder[2],boarder_count[2],x-1,y-1) | |
1759 if(x && y+1<h && !state[x - 1 + (y+1)*w]) SVI(boarder[2],boarder_count[2],x-1,y+1) | |
1760 if(x+1<w && y+1<h && !state[x + 1 + (y+1)*w]) SVI(boarder[2],boarder_count[2],x+1,y+1) | |
1761 if(x+1<w && y && !state[x + 1 + (y-1)*w]) SVI(boarder[2],boarder_count[2],x+1,y-1) | |
1762 } | |
1763 } | |
1764 } | |
1765 //FIXME sort significant coeffs maybe | |
1766 if(1){ | |
1767 qsort(significant, significant_count, sizeof(int16_t[2]), sig_cmp); | |
1768 } | |
1769 | |
1770 last_v=1; | |
1771 while(significant_count){ | |
1772 int context= 3 + quant7[last_v&0xFF]; //use significance of suroundings | |
1773 significant_count--; | |
1774 x= significant[significant_count][0];//FIXME try opposit direction | |
1775 y= significant[significant_count][1]; | |
1776 v= src[x + y*stride]; | |
1777 put_symbol(&s->c, b->state[context + 2], v, 1); //FIXME try to avoid first bit, try this with the old code too!! | |
1778 last_v= v; | |
1779 } | |
1780 } | |
1781 #endif | |
2155
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1782 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1783 |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1784 static void encode_subband_c0run(SnowContext *s, SubBand *b, DWTELEM *src, DWTELEM *parent, int stride, int orientation){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1785 const int level= b->level; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1786 const int w= b->width; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1787 const int h= b->height; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1788 int x, y; |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1789 |
2138 | 1790 if(1){ |
1791 int run=0; | |
2149 | 1792 int runs[w*h]; |
2138 | 1793 int run_index=0; |
1794 | |
1795 for(y=0; y<h; y++){ | |
1796 for(x=0; x<w; x++){ | |
2148
678be5a8f282
use parent sample to predict significance & magnitude
michael
parents:
2146
diff
changeset
|
1797 int v, p=0; |
2144 | 1798 int /*ll=0, */l=0, lt=0, t=0, rt=0; |
2149 | 1799 v= src[x + y*stride]; |
2138 | 1800 |
1801 if(y){ | |
2149 | 1802 t= src[x + (y-1)*stride]; |
2138 | 1803 if(x){ |
2149 | 1804 lt= src[x - 1 + (y-1)*stride]; |
2138 | 1805 } |
1806 if(x + 1 < w){ | |
2149 | 1807 rt= src[x + 1 + (y-1)*stride]; |
2138 | 1808 } |
1809 } | |
1810 if(x){ | |
2149 | 1811 l= src[x - 1 + y*stride]; |
2144 | 1812 /*if(x > 1){ |
1813 if(orientation==1) ll= src[y + (x-2)*stride]; | |
1814 else ll= src[x - 2 + y*stride]; | |
2138 | 1815 }*/ |
1816 } | |
2148
678be5a8f282
use parent sample to predict significance & magnitude
michael
parents:
2146
diff
changeset
|
1817 if(parent){ |
2149 | 1818 int px= x>>1; |
1819 int py= y>>1; | |
2148
678be5a8f282
use parent sample to predict significance & magnitude
michael
parents:
2146
diff
changeset
|
1820 if(px<b->parent->width && py<b->parent->height) |
678be5a8f282
use parent sample to predict significance & magnitude
michael
parents:
2146
diff
changeset
|
1821 p= parent[px + py*2*stride]; |
678be5a8f282
use parent sample to predict significance & magnitude
michael
parents:
2146
diff
changeset
|
1822 } |
678be5a8f282
use parent sample to predict significance & magnitude
michael
parents:
2146
diff
changeset
|
1823 if(!(/*ll|*/l|lt|t|rt|p)){ |
2138 | 1824 if(v){ |
1825 runs[run_index++]= run; | |
1826 run=0; | |
1827 }else{ | |
1828 run++; | |
1829 } | |
1830 } | |
1831 } | |
1832 } | |
1833 runs[run_index++]= run; | |
1834 run_index=0; | |
1835 run= runs[run_index++]; | |
1836 | |
2155
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1837 put_symbol2(&s->c, b->state[1], run, 3); |
2138 | 1838 |
1839 for(y=0; y<h; y++){ | |
1840 for(x=0; x<w; x++){ | |
2148
678be5a8f282
use parent sample to predict significance & magnitude
michael
parents:
2146
diff
changeset
|
1841 int v, p=0; |
2144 | 1842 int /*ll=0, */l=0, lt=0, t=0, rt=0; |
2149 | 1843 v= src[x + y*stride]; |
2138 | 1844 |
1845 if(y){ | |
2149 | 1846 t= src[x + (y-1)*stride]; |
2138 | 1847 if(x){ |
2149 | 1848 lt= src[x - 1 + (y-1)*stride]; |
2138 | 1849 } |
1850 if(x + 1 < w){ | |
2149 | 1851 rt= src[x + 1 + (y-1)*stride]; |
2138 | 1852 } |
1853 } | |
1854 if(x){ | |
2149 | 1855 l= src[x - 1 + y*stride]; |
2144 | 1856 /*if(x > 1){ |
1857 if(orientation==1) ll= src[y + (x-2)*stride]; | |
1858 else ll= src[x - 2 + y*stride]; | |
2138 | 1859 }*/ |
1860 } | |
2148
678be5a8f282
use parent sample to predict significance & magnitude
michael
parents:
2146
diff
changeset
|
1861 if(parent){ |
2149 | 1862 int px= x>>1; |
1863 int py= y>>1; | |
2148
678be5a8f282
use parent sample to predict significance & magnitude
michael
parents:
2146
diff
changeset
|
1864 if(px<b->parent->width && py<b->parent->height) |
678be5a8f282
use parent sample to predict significance & magnitude
michael
parents:
2146
diff
changeset
|
1865 p= parent[px + py*2*stride]; |
678be5a8f282
use parent sample to predict significance & magnitude
michael
parents:
2146
diff
changeset
|
1866 } |
678be5a8f282
use parent sample to predict significance & magnitude
michael
parents:
2146
diff
changeset
|
1867 if(/*ll|*/l|lt|t|rt|p){ |
678be5a8f282
use parent sample to predict significance & magnitude
michael
parents:
2146
diff
changeset
|
1868 int context= av_log2(/*ABS(ll) + */3*ABS(l) + ABS(lt) + 2*ABS(t) + ABS(rt) + ABS(p)); |
2144 | 1869 |
1870 put_cabac(&s->c, &b->state[0][context], !!v); | |
2138 | 1871 }else{ |
1872 if(!run){ | |
1873 run= runs[run_index++]; | |
2155
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1874 |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1875 put_symbol2(&s->c, b->state[1], run, 3); |
2138 | 1876 assert(v); |
1877 }else{ | |
1878 run--; | |
1879 assert(!v); | |
1880 } | |
1881 } | |
1882 if(v){ | |
2148
678be5a8f282
use parent sample to predict significance & magnitude
michael
parents:
2146
diff
changeset
|
1883 int context= av_log2(/*ABS(ll) + */3*ABS(l) + ABS(lt) + 2*ABS(t) + ABS(rt) + ABS(p)); |
2144 | 1884 |
2159
7f42295c1517
improved magnitude coding, 0.2% lower bitrate (foreman@352x288 qscale 1 and 8)
michael
parents:
2156
diff
changeset
|
1885 put_symbol2(&s->c, b->state[context + 2], ABS(v)-1, context-4); |
2138 | 1886 put_cabac(&s->c, &b->state[0][16 + 1 + 3 + quant3b[l&0xFF] + 3*quant3b[t&0xFF]], v<0); |
1887 } | |
1888 } | |
1889 } | |
1890 } | |
1891 } | |
1892 | |
2155
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1893 static void encode_subband(SnowContext *s, SubBand *b, DWTELEM *src, DWTELEM *parent, int stride, int orientation){ |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1894 // encode_subband_qtree(s, b, src, parent, stride, orientation); |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1895 // encode_subband_z0run(s, b, src, parent, stride, orientation); |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1896 encode_subband_c0run(s, b, src, parent, stride, orientation); |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1897 // encode_subband_dzr(s, b, src, parent, stride, orientation); |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1898 } |
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1899 |
2149 | 1900 static inline void decode_subband(SnowContext *s, SubBand *b, DWTELEM *src, DWTELEM *parent, int stride, int orientation){ |
2138 | 1901 const int level= b->level; |
1902 const int w= b->width; | |
1903 const int h= b->height; | |
1904 int x,y; | |
2195 | 1905 const int qlog= clip(s->qlog + b->qlog, 0, 128); |
1906 int qmul= qexp[qlog&7]<<(qlog>>3); | |
1907 int qadd= (s->qbias*qmul)>>QBIAS_SHIFT; | |
1908 | |
2197 | 1909 START_TIMER |
1910 | |
2195 | 1911 if(b->buf == s->spatial_dwt_buffer || s->qlog == LOSSLESS_QLOG){ |
1912 qadd= 0; | |
1913 qmul= 1<<QEXPSHIFT; | |
1914 } | |
2138 | 1915 |
1916 if(1){ | |
1917 int run; | |
2192 | 1918 int index=0; |
1919 int prev_index=-1; | |
1920 int prev2_index=0; | |
1921 int parent_index= 0; | |
1922 int prev_parent_index= 0; | |
1923 | |
2138 | 1924 for(y=0; y<b->height; y++) |
1925 memset(&src[y*stride], 0, b->width*sizeof(DWTELEM)); | |
1926 | |
2155
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1927 run= get_symbol2(&s->c, b->state[1], 3); |
2138 | 1928 for(y=0; y<h; y++){ |
2193 | 1929 int v=0; |
1930 int lt=0, t=0, rt=0; | |
1931 | |
2194 | 1932 if(y && b->x[prev_index] == 0){ |
1933 rt= b->coeff[prev_index]; | |
2193 | 1934 } |
2138 | 1935 for(x=0; x<w; x++){ |
2193 | 1936 int p=0; |
1937 const int l= v; | |
1938 | |
1939 lt= t; t= rt; | |
1940 | |
2194 | 1941 if(y){ |
2195 | 1942 if(b->x[prev_index] <= x) |
2194 | 1943 prev_index++; |
1944 if(b->x[prev_index] == x + 1) | |
1945 rt= b->coeff[prev_index]; | |
1946 else | |
1947 rt=0; | |
1948 } | |
2148
678be5a8f282
use parent sample to predict significance & magnitude
michael
parents:
2146
diff
changeset
|
1949 if(parent){ |
2192 | 1950 if(x>>1 > b->parent->x[parent_index]){ |
1951 parent_index++; | |
1952 } | |
2194 | 1953 if(x>>1 == b->parent->x[parent_index]){ |
1954 p= b->parent->coeff[parent_index]; | |
1955 } | |
2148
678be5a8f282
use parent sample to predict significance & magnitude
michael
parents:
2146
diff
changeset
|
1956 } |
678be5a8f282
use parent sample to predict significance & magnitude
michael
parents:
2146
diff
changeset
|
1957 if(/*ll|*/l|lt|t|rt|p){ |
678be5a8f282
use parent sample to predict significance & magnitude
michael
parents:
2146
diff
changeset
|
1958 int context= av_log2(/*ABS(ll) + */3*ABS(l) + ABS(lt) + 2*ABS(t) + ABS(rt) + ABS(p)); |
2144 | 1959 |
1960 v=get_cabac(&s->c, &b->state[0][context]); | |
2138 | 1961 }else{ |
1962 if(!run){ | |
2155
274a01d80f4a
various subband encoders (all either worse or complicated so they are commented out)
michael
parents:
2152
diff
changeset
|
1963 run= get_symbol2(&s->c, b->state[1], 3); |
2138 | 1964 v=1; |
1965 }else{ | |
1966 run--; | |
1967 v=0; | |
2191 | 1968 |
2192 | 1969 if(y && parent){ |
1970 int max_run; | |
1971 | |
1972 max_run= FFMIN(run, b->x[prev_index] - x - 2); | |
1973 max_run= FFMIN(max_run, 2*b->parent->x[parent_index] - x - 1); | |
1974 x+= max_run; | |
1975 run-= max_run; | |
2191 | 1976 } |
2138 | 1977 } |
1978 } | |
1979 if(v){ | |
2148
678be5a8f282
use parent sample to predict significance & magnitude
michael
parents:
2146
diff
changeset
|
1980 int context= av_log2(/*ABS(ll) + */3*ABS(l) + ABS(lt) + 2*ABS(t) + ABS(rt) + ABS(p)); |
2159
7f42295c1517
improved magnitude coding, 0.2% lower bitrate (foreman@352x288 qscale 1 and 8)
michael
parents:
2156
diff
changeset
|
1981 v= get_symbol2(&s->c, b->state[context + 2], context-4) + 1; |
2195 | 1982 if(get_cabac(&s->c, &b->state[0][16 + 1 + 3 + quant3b[l&0xFF] + 3*quant3b[t&0xFF]])){ |
1983 src[x + y*stride]=-(( v*qmul + qadd)>>(QEXPSHIFT)); | |
2138 | 1984 v= -v; |
2195 | 1985 }else{ |
1986 src[x + y*stride]= (( v*qmul + qadd)>>(QEXPSHIFT)); | |
1987 } | |
2194 | 1988 b->x[index]=x; //FIXME interleave x/coeff |
1989 b->coeff[index++]= v; | |
2192 | 1990 } |
1991 } | |
1992 b->x[index++]= w+1; //end marker | |
1993 prev_index= prev2_index; | |
1994 prev2_index= index; | |
1995 | |
1996 if(parent){ | |
1997 while(b->parent->x[parent_index] != b->parent->width+1) | |
1998 parent_index++; | |
1999 parent_index++; | |
2000 if(y&1){ | |
2001 prev_parent_index= parent_index; | |
2002 }else{ | |
2003 parent_index= prev_parent_index; | |
2138 | 2004 } |
2005 } | |
2006 } | |
2192 | 2007 b->x[index++]= w+1; //end marker |
2191 | 2008 if(w > 200 /*level+1 == s->spatial_decomposition_count*/){ |
2138 | 2009 STOP_TIMER("decode_subband") |
2010 } | |
2011 | |
2012 return; | |
2013 } | |
2014 } | |
2015 | |
2016 static void reset_contexts(SnowContext *s){ | |
2017 int plane_index, level, orientation; | |
2018 | |
2019 for(plane_index=0; plane_index<2; plane_index++){ | |
2020 for(level=0; level<s->spatial_decomposition_count; level++){ | |
2021 for(orientation=level ? 1:0; orientation<4; orientation++){ | |
2022 memset(s->plane[plane_index].band[level][orientation].state, 0, sizeof(s->plane[plane_index].band[level][orientation].state)); | |
2023 } | |
2024 } | |
2025 } | |
2026 memset(s->header_state, 0, sizeof(s->header_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
|
2027 memset(s->block_state, 0, sizeof(s->block_state)); |
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
|
2028 } |
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
|
2029 |
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
|
2030 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
|
2031 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
|
2032 int h= -((-s->avctx->height)>>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
|
2033 |
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
|
2034 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
|
2035 s->b_height= h; |
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
|
2036 |
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
|
2037 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
|
2038 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
|
2039 } |
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
|
2040 |
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
|
2041 static inline void copy_cabac_state(CABACContext *d, CABACContext *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
|
2042 PutBitContext bak= d->pb; |
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
|
2043 *d= *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
|
2044 d->pb= bak; |
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
|
2045 } |
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
|
2046 |
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
|
2047 //near copy & paste from dsputil, FIXME |
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
|
2048 static int pix_sum(uint8_t * pix, int line_size, int 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
|
2049 { |
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
|
2050 int s, i, 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
|
2051 |
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
|
2052 s = 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
|
2053 for (i = 0; i < 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
|
2054 for (j = 0; j < 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
|
2055 s += pix[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
|
2056 pix ++; |
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
|
2057 } |
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
|
2058 pix += line_size - 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
|
2059 } |
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
|
2060 return 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
|
2061 } |
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
|
2062 |
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
|
2063 //near copy & paste from dsputil, FIXME |
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
|
2064 static int pix_norm1(uint8_t * pix, int line_size, int 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
|
2065 { |
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
|
2066 int s, i, 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
|
2067 uint32_t *sq = squareTbl + 256; |
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
|
2068 |
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
|
2069 s = 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
|
2070 for (i = 0; i < 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
|
2071 for (j = 0; j < 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
|
2072 s += sq[pix[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
|
2073 pix ++; |
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
|
2074 } |
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
|
2075 pix += line_size - 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
|
2076 } |
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
|
2077 return 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
|
2078 } |
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
|
2079 |
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
|
2080 static inline void set_blocks(SnowContext *s, int level, int x, int y, int l, int cb, int cr, int mx, int my, int 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
|
2081 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
|
2082 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
|
2083 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
|
2084 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
|
2085 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
|
2086 int i,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
|
2087 |
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
|
2088 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
|
2089 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
|
2090 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
|
2091 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
|
2092 block.my= my; |
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
|
2093 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
|
2094 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
|
2095 |
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
|
2096 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
|
2097 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
|
2098 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
|
2099 } |
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
|
2100 } |
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
|
2101 } |
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
|
2102 |
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
|
2103 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
|
2104 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
|
2105 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
|
2106 ((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
|
2107 ((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
|
2108 }; |
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
|
2109 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
|
2110 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
|
2111 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
|
2112 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
|
2113 } |
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
|
2114 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
|
2115 } |
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
|
2116 |
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
|
2117 //FIXME copy&paste |
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
|
2118 #define P_LEFT P[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
|
2119 #define P_TOP P[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
|
2120 #define P_TOPRIGHT P[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
|
2121 #define P_MEDIAN P[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
|
2122 #define P_MV1 P[9] |
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
|
2123 #define FLAG_QPEL 1 //must be 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
|
2124 |
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
|
2125 static int encode_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
|
2126 uint8_t p_buffer[1024]; |
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
|
2127 uint8_t i_buffer[1024]; |
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
|
2128 uint8_t p_state[sizeof(s->block_state)]; |
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
|
2129 uint8_t i_state[sizeof(s->block_state)]; |
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
|
2130 CABACContext pc, ic; |
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
|
2131 PutBitContext pbbak= s->c.pb; |
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
|
2132 int score, score2, iscore, i_len, p_len, block_s, sum; |
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
|
2133 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
|
2134 const int h= s->b_height << 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
|
2135 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
|
2136 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
|
2137 const int block_w= 1<<(LOG2_MB_SIZE - 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
|
2138 static BlockNode null_block= { //FIXME add border maybe |
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
|
2139 .color= {128,128,128}, |
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
|
2140 .mx= 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
|
2141 .my= 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
|
2142 .type= 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
|
2143 .level= 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
|
2144 }; |
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
|
2145 int trx= (x+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
|
2146 int try= (y+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
|
2147 BlockNode *left = x ? &s->block[index-1] : &null_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
|
2148 BlockNode *top = y ? &s->block[index-w] : &null_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
|
2149 BlockNode *right = trx<w ? &s->block[index+1] : &null_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
|
2150 BlockNode *bottom= try<h ? &s->block[index+w] : &null_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
|
2151 BlockNode *tl = y && x ? &s->block[index-w-1] : left; |
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
|
2152 BlockNode *tr = y && trx<w && ((x&1)==0 || level==0) ? &s->block[index-w+(1<<rem_depth)] : tl; //FIXME use lt |
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
|
2153 int pl = 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
|
2154 int pcb= 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
|
2155 int pcr= left->color[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
|
2156 int pmx= mid_pred(left->mx, top->mx, tr->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
|
2157 int pmy= mid_pred(left->my, top->my, tr->my); |
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
|
2158 int mx=0, my=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
|
2159 int l,cr,cb, 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
|
2160 const int stride= s->current_picture.linesize[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
|
2161 const int uvstride= s->current_picture.linesize[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
|
2162 const int instride= s->input_picture.linesize[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
|
2163 const int uvinstride= s->input_picture.linesize[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
|
2164 uint8_t *new_l = s->input_picture.data[0] + (x + y* instride)*block_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
|
2165 uint8_t *new_cb= s->input_picture.data[1] + (x + y*uvinstride)*block_w/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
|
2166 uint8_t *new_cr= s->input_picture.data[2] + (x + y*uvinstride)*block_w/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
|
2167 uint8_t current_mb[3][stride*block_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
|
2168 uint8_t *current_data[3]= {¤t_mb[0][0], ¤t_mb[1][0], ¤t_mb[2][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
|
2169 int P[10][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
|
2170 int16_t last_mv[3][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
|
2171 int qpel= !!(s->avctx->flags & CODEC_FLAG_QPEL); //unused |
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
|
2172 const int shift= 1+qpel; |
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
|
2173 MotionEstContext *c= &s->m.me; |
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
|
2174 int mx_context= av_log2(2*ABS(left->mx - top->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
|
2175 int my_context= av_log2(2*ABS(left->my - top->my)); |
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
|
2176 int s_context= 2*left->level + 2*top->level + tl->level + tr->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
|
2177 |
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
|
2178 assert(sizeof(s->block_state) >= 256); |
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
|
2179 if(s->keyframe){ |
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
|
2180 set_blocks(s, level, x, y, pl, pcb, pcr, pmx, pmy, BLOCK_INTRA); |
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
|
2181 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
|
2182 } |
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
|
2183 |
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
|
2184 //FIXME optimize |
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
|
2185 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
|
2186 memcpy(¤t_mb[0][0] + stride*i, new_l + instride*i, block_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
|
2187 for(i=0; i<block_w>>1; 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
|
2188 memcpy(¤t_mb[1][0] + uvstride*i, new_cb + uvinstride*i, block_w>>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
|
2189 for(i=0; i<block_w>>1; 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
|
2190 memcpy(¤t_mb[2][0] + uvstride*i, new_cr + uvinstride*i, block_w>>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
|
2191 |
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
|
2192 // clip predictors / edge ? |
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
|
2193 |
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
|
2194 P_LEFT[0]= left->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
|
2195 P_LEFT[1]= left->my; |
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
|
2196 P_TOP [0]= top->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
|
2197 P_TOP [1]= top->my; |
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
|
2198 P_TOPRIGHT[0]= tr->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
|
2199 P_TOPRIGHT[1]= tr->my; |
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
|
2200 |
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
|
2201 last_mv[0][0]= s->block[index].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
|
2202 last_mv[0][1]= s->block[index].my; |
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
|
2203 last_mv[1][0]= right->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
|
2204 last_mv[1][1]= right->my; |
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
|
2205 last_mv[2][0]= bottom->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
|
2206 last_mv[2][1]= bottom->my; |
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
|
2207 |
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
|
2208 s->m.mb_stride=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
|
2209 s->m.mb_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
|
2210 s->m.mb_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
|
2211 s->m.me.skip= 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
|
2212 |
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
|
2213 init_ref(c, current_data, s->last_picture.data, NULL, block_w*x, block_w*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
|
2214 |
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
|
2215 assert(s->m.me. stride == stride); |
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
|
2216 assert(s->m.me.uvstride == uvstride); |
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
|
2217 |
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
|
2218 c->penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_cmp); |
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
|
2219 c->sub_penalty_factor= get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_sub_cmp); |
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
|
2220 c->mb_penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->mb_cmp); |
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
|
2221 c->current_mv_penalty= c->mv_penalty[s->m.f_code=1] + MAX_MV; |
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
|
2222 |
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
|
2223 c->xmin = - x*block_w - 16; |
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
|
2224 c->ymin = - y*block_w - 16; |
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
|
2225 c->xmax = - (x+1)*block_w + (w<<(LOG2_MB_SIZE - s->block_max_depth)) + 16; |
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
|
2226 c->ymax = - (y+1)*block_w + (h<<(LOG2_MB_SIZE - s->block_max_depth)) + 16; |
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
|
2227 |
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
|
2228 if(P_LEFT[0] > (c->xmax<<shift)) P_LEFT[0] = (c->xmax<<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
|
2229 if(P_LEFT[1] > (c->ymax<<shift)) P_LEFT[1] = (c->ymax<<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
|
2230 if(P_TOP[0] > (c->xmax<<shift)) P_TOP[0] = (c->xmax<<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
|
2231 if(P_TOP[1] > (c->ymax<<shift)) P_TOP[1] = (c->ymax<<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
|
2232 if(P_TOPRIGHT[0] < (c->xmin<<shift)) P_TOPRIGHT[0]= (c->xmin<<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
|
2233 if(P_TOPRIGHT[0] > (c->xmax<<shift)) P_TOPRIGHT[0]= (c->xmax<<shift); //due to pmx no clip |
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
|
2234 if(P_TOPRIGHT[1] > (c->ymax<<shift)) P_TOPRIGHT[1]= (c->ymax<<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
|
2235 |
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
|
2236 P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[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
|
2237 P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[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
|
2238 |
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
|
2239 if (!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
|
2240 c->pred_x= P_LEFT[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
|
2241 c->pred_y= P_LEFT[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
|
2242 } 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
|
2243 c->pred_x = P_MEDIAN[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
|
2244 c->pred_y = P_MEDIAN[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
|
2245 } |
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
|
2246 |
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
|
2247 score= ff_epzs_motion_search(&s->m, &mx, &my, P, 0, /*ref_index*/ 0, last_mv, |
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
|
2248 (1<<16)>>shift, level-LOG2_MB_SIZE+4, block_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
|
2249 |
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
|
2250 assert(mx >= c->xmin); |
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
|
2251 assert(mx <= c->xmax); |
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
|
2252 assert(my >= c->ymin); |
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
|
2253 assert(my <= c->ymax); |
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
|
2254 |
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
|
2255 score= s->m.me.sub_motion_search(&s->m, &mx, &my, score, 0, 0, level-LOG2_MB_SIZE+4, block_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
|
2256 score= ff_get_mb_score(&s->m, mx, my, 0, 0, level-LOG2_MB_SIZE+4, block_w, 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
|
2257 //FIXME if mb_cmp != SSE then intra cant be compared currently and mb_penalty vs. lambda2 |
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
|
2258 |
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
|
2259 // subpel search |
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
|
2260 pc= s->c; |
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
|
2261 init_put_bits(&pc.pb, p_buffer, sizeof(p_buffer)); |
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
|
2262 memcpy(p_state, s->block_state, sizeof(s->block_state)); |
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
|
2263 |
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
|
2264 if(level!=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
|
2265 put_cabac(&pc, &p_state[4 + s_context], 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
|
2266 put_cabac(&pc, &p_state[1 + left->type + top->type], 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
|
2267 put_symbol(&pc, &p_state[128 + 32*mx_context], mx - pmx, 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
|
2268 put_symbol(&pc, &p_state[128 + 32*my_context], my - pmy, 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
|
2269 p_len= put_bits_count(&pc.pb); |
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
|
2270 score += (s->lambda2*(p_len + pc.outstanding_count - s->c.outstanding_count))>>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
|
2271 |
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
|
2272 block_s= block_w*block_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
|
2273 sum = pix_sum(¤t_mb[0][0], stride, block_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
|
2274 l= (sum + block_s/2)/block_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
|
2275 iscore = pix_norm1(¤t_mb[0][0], stride, block_w) - 2*l*sum + l*l*block_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
|
2276 |
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
|
2277 block_s= block_w*block_w>>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
|
2278 sum = pix_sum(¤t_mb[1][0], uvstride, block_w>>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
|
2279 cb= (sum + block_s/2)/block_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
|
2280 // iscore += pix_norm1(¤t_mb[1][0], uvstride, block_w>>1) - 2*cb*sum + cb*cb*block_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
|
2281 sum = pix_sum(¤t_mb[2][0], uvstride, block_w>>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
|
2282 cr= (sum + block_s/2)/block_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
|
2283 // iscore += pix_norm1(¤t_mb[2][0], uvstride, block_w>>1) - 2*cr*sum + cr*cr*block_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
|
2284 |
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
|
2285 ic= s->c; |
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
|
2286 init_put_bits(&ic.pb, i_buffer, sizeof(i_buffer)); |
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
|
2287 memcpy(i_state, s->block_state, sizeof(s->block_state)); |
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
|
2288 if(level!=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
|
2289 put_cabac(&ic, &i_state[4 + s_context], 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
|
2290 put_cabac(&ic, &i_state[1 + left->type + top->type], 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
|
2291 put_symbol(&ic, &i_state[32], l-pl , 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
|
2292 put_symbol(&ic, &i_state[64], cb-pcb, 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
|
2293 put_symbol(&ic, &i_state[96], cr-pcr, 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
|
2294 i_len= put_bits_count(&ic.pb); |
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
|
2295 iscore += (s->lambda2*(i_len + ic.outstanding_count - s->c.outstanding_count))>>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
|
2296 |
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
|
2297 // assert(score==256*256*256*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
|
2298 assert(iscore < 255*255*256 + s->lambda2*10); |
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
|
2299 assert(iscore >= 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
|
2300 assert(l>=0 && l<=255); |
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
|
2301 assert(pl>=0 && pl<=255); |
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
|
2302 |
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
|
2303 if(level==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
|
2304 int varc= iscore >> 8; |
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
|
2305 int vard= score >> 8; |
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
|
2306 if (vard <= 64 || vard < varc) |
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
|
2307 c->scene_change_score+= ff_sqrt(vard) - ff_sqrt(varc); |
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
|
2308 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
|
2309 c->scene_change_score+= s->m.qscale; |
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
|
2310 } |
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
|
2311 |
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
|
2312 if(level!=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
|
2313 put_cabac(&s->c, &s->block_state[4 + s_context], 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
|
2314 score2 = encode_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
|
2315 score2+= encode_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
|
2316 score2+= encode_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
|
2317 score2+= encode_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
|
2318 score2+= s->lambda2>>FF_LAMBDA_SHIFT; //FIXME exact split overhead |
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
|
2319 |
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
|
2320 if(score2 < score && score2 < iscore) |
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
|
2321 return score2; |
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
|
2322 } |
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
|
2323 |
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
|
2324 if(iscore < score){ |
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
|
2325 flush_put_bits(&ic.pb); |
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
|
2326 ff_copy_bits(&pbbak, i_buffer, i_len); |
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
|
2327 s->c= ic; |
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
|
2328 s->c.pb= pbbak; |
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
|
2329 set_blocks(s, level, x, y, l, cb, cr, pmx, pmy, BLOCK_INTRA); |
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
|
2330 memcpy(s->block_state, i_state, sizeof(s->block_state)); |
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
|
2331 return iscore; |
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
|
2332 }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
|
2333 flush_put_bits(&pc.pb); |
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
|
2334 ff_copy_bits(&pbbak, p_buffer, p_len); |
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
|
2335 s->c= pc; |
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
|
2336 s->c.pb= pbbak; |
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
|
2337 set_blocks(s, level, x, y, pl, pcb, pcr, mx, my, 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
|
2338 memcpy(s->block_state, p_state, sizeof(s->block_state)); |
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
|
2339 return score; |
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
|
2340 } |
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
|
2341 } |
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
|
2342 |
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
|
2343 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
|
2344 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
|
2345 const int h= s->b_height<< 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
|
2346 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
|
2347 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
|
2348 static BlockNode null_block= { //FIXME add border maybe |
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
|
2349 .color= {128,128,128}, |
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
|
2350 .mx= 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
|
2351 .my= 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
|
2352 .type= 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
|
2353 .level= 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
|
2354 }; |
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
|
2355 int trx= (x+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
|
2356 int try= (y+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
|
2357 BlockNode *left = x ? &s->block[index-1] : &null_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
|
2358 BlockNode *top = y ? &s->block[index-w] : &null_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
|
2359 BlockNode *tl = y && x ? &s->block[index-w-1] : left; |
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
|
2360 BlockNode *tr = y && trx<w && ((x&1)==0 || level==0) ? &s->block[index-w+(1<<rem_depth)] : tl; //FIXME use lt |
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
|
2361 int s_context= 2*left->level + 2*top->level + tl->level + tr->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
|
2362 |
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
|
2363 if(s->keyframe){ |
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
|
2364 set_blocks(s, level, x, y, null_block.color[0], null_block.color[1], null_block.color[2], null_block.mx, null_block.my, BLOCK_INTRA); |
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
|
2365 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
|
2366 } |
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
|
2367 |
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
|
2368 if(level==s->block_max_depth || get_cabac(&s->c, &s->block_state[4 + s_context])){ |
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
|
2369 int 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
|
2370 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
|
2371 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
|
2372 int cr= left->color[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
|
2373 int mx= mid_pred(left->mx, top->mx, tr->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
|
2374 int my= mid_pred(left->my, top->my, tr->my); |
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
|
2375 int mx_context= av_log2(2*ABS(left->mx - top->mx)) + 0*av_log2(2*ABS(tr->mx - top->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
|
2376 int my_context= av_log2(2*ABS(left->my - top->my)) + 0*av_log2(2*ABS(tr->my - top->my)); |
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
|
2377 |
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
|
2378 type= get_cabac(&s->c, &s->block_state[1 + left->type + top->type]) ? BLOCK_INTRA : 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
|
2379 |
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
|
2380 if(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
|
2381 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
|
2382 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
|
2383 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
|
2384 }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
|
2385 mx+= get_symbol(&s->c, &s->block_state[128 + 32*mx_context], 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
|
2386 my+= get_symbol(&s->c, &s->block_state[128 + 32*my_context], 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
|
2387 } |
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
|
2388 set_blocks(s, level, x, y, l, cb, cr, mx, my, 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
|
2389 }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
|
2390 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
|
2391 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
|
2392 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
|
2393 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
|
2394 } |
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
|
2395 } |
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
|
2396 |
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
|
2397 static void encode_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
|
2398 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
|
2399 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
|
2400 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
|
2401 |
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
|
2402 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
|
2403 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
|
2404 encode_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
|
2405 } |
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
|
2406 } |
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
|
2407 } |
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
|
2408 |
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
|
2409 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
|
2410 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
|
2411 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
|
2412 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
|
2413 |
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
|
2414 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
|
2415 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
|
2416 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
|
2417 } |
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
|
2418 } |
2138 | 2419 } |
2420 | |
2421 static void mc_block(uint8_t *dst, uint8_t *src, uint8_t *tmp, int stride, int b_w, int b_h, int dx, int dy){ | |
2422 int x, y; | |
2423 | |
2424 for(y=0; y < b_h+5; y++){ | |
2425 for(x=0; x < b_w; x++){ | |
2426 int a0= src[x + y*stride]; | |
2427 int a1= src[x + 1 + y*stride]; | |
2428 int a2= src[x + 2 + y*stride]; | |
2429 int a3= src[x + 3 + y*stride]; | |
2430 int a4= src[x + 4 + y*stride]; | |
2431 int a5= src[x + 5 + y*stride]; | |
2432 // int am= 9*(a1+a2) - (a0+a3); | |
2433 int am= 20*(a2+a3) - 5*(a1+a4) + (a0+a5); | |
2434 // int am= 18*(a2+a3) - 2*(a1+a4); | |
2435 // int aL= (-7*a0 + 105*a1 + 35*a2 - 5*a3)>>3; | |
2436 // int aR= (-7*a3 + 105*a2 + 35*a1 - 5*a0)>>3; | |
2437 | |
2438 // if(b_w==16) am= 8*(a1+a2); | |
2439 | |
2440 if(dx<8) tmp[x + y*stride]= (32*a2*( 8-dx) + am* dx + 128)>>8; | |
2441 else tmp[x + y*stride]= ( am*(16-dx) + 32*a3*(dx-8) + 128)>>8; | |
2442 | |
2443 /* if (dx< 4) tmp[x + y*stride]= (16*a1*( 4-dx) + aL* dx + 32)>>6; | |
2444 else if(dx< 8) tmp[x + y*stride]= ( aL*( 8-dx) + am*(dx- 4) + 32)>>6; | |
2445 else if(dx<12) tmp[x + y*stride]= ( am*(12-dx) + aR*(dx- 8) + 32)>>6; | |
2446 else tmp[x + y*stride]= ( aR*(16-dx) + 16*a2*(dx-12) + 32)>>6;*/ | |
2447 } | |
2448 } | |
2449 for(y=0; y < b_h; y++){ | |
2450 for(x=0; x < b_w; x++){ | |
2451 int a0= tmp[x + y *stride]; | |
2452 int a1= tmp[x + (y + 1)*stride]; | |
2453 int a2= tmp[x + (y + 2)*stride]; | |
2454 int a3= tmp[x + (y + 3)*stride]; | |
2455 int a4= tmp[x + (y + 4)*stride]; | |
2456 int a5= tmp[x + (y + 5)*stride]; | |
2457 int am= 20*(a2+a3) - 5*(a1+a4) + (a0+a5); | |
2458 // int am= 18*(a2+a3) - 2*(a1+a4); | |
2459 /* int aL= (-7*a0 + 105*a1 + 35*a2 - 5*a3)>>3; | |
2460 int aR= (-7*a3 + 105*a2 + 35*a1 - 5*a0)>>3;*/ | |
2461 | |
2462 // if(b_w==16) am= 8*(a1+a2); | |
2463 | |
2464 if(dy<8) dst[x + y*stride]= (32*a2*( 8-dy) + am* dy + 128)>>8; | |
2465 else dst[x + y*stride]= ( am*(16-dy) + 32*a3*(dy-8) + 128)>>8; | |
2466 | |
2467 /* if (dy< 4) tmp[x + y*stride]= (16*a1*( 4-dy) + aL* dy + 32)>>6; | |
2468 else if(dy< 8) tmp[x + y*stride]= ( aL*( 8-dy) + am*(dy- 4) + 32)>>6; | |
2469 else if(dy<12) tmp[x + y*stride]= ( am*(12-dy) + aR*(dy- 8) + 32)>>6; | |
2470 else tmp[x + y*stride]= ( aR*(16-dy) + 16*a2*(dy-12) + 32)>>6;*/ | |
2471 } | |
2472 } | |
2473 } | |
2474 | |
2475 #define mcb(dx,dy,b_w)\ | |
2476 static void mc_block ## dx ## dy(uint8_t *dst, uint8_t *src, int stride){\ | |
2477 uint8_t tmp[stride*(b_w+5)];\ | |
2478 mc_block(dst, src-2-2*stride, tmp, stride, b_w, b_w, dx, dy);\ | |
2479 } | |
2480 | |
2481 mcb( 0, 0,16) | |
2482 mcb( 4, 0,16) | |
2483 mcb( 8, 0,16) | |
2484 mcb(12, 0,16) | |
2485 mcb( 0, 4,16) | |
2486 mcb( 4, 4,16) | |
2487 mcb( 8, 4,16) | |
2488 mcb(12, 4,16) | |
2489 mcb( 0, 8,16) | |
2490 mcb( 4, 8,16) | |
2491 mcb( 8, 8,16) | |
2492 mcb(12, 8,16) | |
2493 mcb( 0,12,16) | |
2494 mcb( 4,12,16) | |
2495 mcb( 8,12,16) | |
2496 mcb(12,12,16) | |
2497 | |
2498 #define mca(dx,dy,b_w)\ | |
2499 static void mc_block_hpel ## dx ## dy(uint8_t *dst, uint8_t *src, int stride, int h){\ | |
2500 uint8_t tmp[stride*(b_w+5)];\ | |
2501 assert(h==b_w);\ | |
2502 mc_block(dst, src-2-2*stride, tmp, stride, b_w, b_w, dx, dy);\ | |
2503 } | |
2504 | |
2505 mca( 0, 0,16) | |
2506 mca( 8, 0,16) | |
2507 mca( 0, 8,16) | |
2508 mca( 8, 8,16) | |
2509 | |
2197 | 2510 static always_inline void add_xblock(SnowContext *s, DWTELEM *dst, uint8_t *src, uint8_t *obmc, int s_x, int s_y, int b_w, int b_h, int mv_x, int mv_y, int w, int h, int dst_stride, int src_stride, int obmc_stride, int mb_type, int add, int color){ |
2138 | 2511 uint8_t tmp[src_stride*(b_h+5)]; //FIXME move to context to gurantee alignment |
2512 int x,y; | |
2513 | |
2514 if(s_x<0){ | |
2515 obmc -= s_x; | |
2516 b_w += s_x; | |
2517 s_x=0; | |
2518 }else if(s_x + b_w > w){ | |
2519 b_w = w - s_x; | |
2520 } | |
2521 if(s_y<0){ | |
2522 obmc -= s_y*obmc_stride; | |
2523 b_h += s_y; | |
2524 s_y=0; | |
2525 }else if(s_y + b_h> h){ | |
2526 b_h = h - s_y; | |
2527 } | |
2528 | |
2152 | 2529 if(b_w<=0 || b_h<=0) return; |
2530 | |
2138 | 2531 dst += s_x + s_y*dst_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
|
2532 |
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
|
2533 if(mb_type==BLOCK_INTRA){ |
2138 | 2534 for(y=0; y < b_h; y++){ |
2535 for(x=0; x < b_w; 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
|
2536 if(add) dst[x + y*dst_stride] += obmc[x + y*obmc_stride] * color * (256/OBMC_MAX); |
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
|
2537 else dst[x + y*dst_stride] -= obmc[x + y*obmc_stride] * color * (256/OBMC_MAX); |
2138 | 2538 } |
2539 } | |
2540 }else{ | |
2541 int dx= mv_x&15; | |
2542 int dy= mv_y&15; | |
2543 // int dxy= (mv_x&1) + 2*(mv_y&1); | |
2544 | |
2545 s_x += (mv_x>>4) - 2; | |
2546 s_y += (mv_y>>4) - 2; | |
2547 src += s_x + s_y*src_stride; | |
2548 //use dsputil | |
2549 | |
2550 if( (unsigned)s_x >= w - b_w - 4 | |
2551 || (unsigned)s_y >= h - b_h - 4){ | |
2552 ff_emulated_edge_mc(tmp + 32, src, src_stride, b_w+5, b_h+5, s_x, s_y, w, h); | |
2553 src= tmp + 32; | |
2554 } | |
2555 | |
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
|
2556 assert(mb_type==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
|
2557 mc_block(tmp, src, tmp + 64+8, src_stride, b_w, b_h, dx, dy); |
2138 | 2558 for(y=0; y < b_h; y++){ |
2559 for(x=0; x < b_w; x++){ | |
2560 if(add) dst[x + y*dst_stride] += obmc[x + y*obmc_stride] * tmp[x + y*src_stride] * (256/OBMC_MAX); | |
2561 else dst[x + y*dst_stride] -= obmc[x + y*obmc_stride] * tmp[x + y*src_stride] * (256/OBMC_MAX); | |
2562 } | |
2563 } | |
2564 } | |
2565 } | |
2566 | |
2567 static void predict_plane(SnowContext *s, DWTELEM *buf, int plane_index, int add){ | |
2568 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
|
2569 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
|
2570 const int mb_h= s->b_height << 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
|
2571 const int mb_stride= mb_w; |
2138 | 2572 int x, y, mb_x, mb_y; |
2573 int scale = plane_index ? s->mv_scale : 2*s->mv_scale; | |
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
|
2574 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
|
2575 int block_w = plane_index ? block_size/2 : block_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
|
2576 uint8_t *obmc = plane_index ? obmc_tab[s->block_max_depth+1] : obmc_tab[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
|
2577 int obmc_stride= plane_index ? block_size : 2*block_size; |
2138 | 2578 int ref_stride= s->last_picture.linesize[plane_index]; |
2579 uint8_t *ref = s->last_picture.data[plane_index]; | |
2580 int w= p->width; | |
2581 int h= p->height; | |
2197 | 2582 START_TIMER |
2138 | 2583 |
2584 if(s->avctx->debug&512){ | |
2585 for(y=0; y<h; y++){ | |
2586 for(x=0; x<w; x++){ | |
2587 if(add) buf[x + y*w]+= 128*256; | |
2588 else buf[x + y*w]-= 128*256; | |
2589 } | |
2590 } | |
2591 | |
2592 return; | |
2593 } | |
2594 for(mb_y=-1; mb_y<=mb_h; mb_y++){ | |
2595 for(mb_x=-1; mb_x<=mb_w; mb_x++){ | |
2596 int index= clip(mb_x, 0, mb_w-1) + clip(mb_y, 0, mb_h-1)*mb_stride; | |
2597 | |
2197 | 2598 START_TIMER |
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
|
2599 add_xblock(s, buf, ref, obmc, |
2138 | 2600 block_w*mb_x - block_w/2, |
2601 block_w*mb_y - block_w/2, | |
2602 2*block_w, 2*block_w, | |
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
|
2603 s->block[index].mx*scale, s->block[index].my*scale, |
2138 | 2604 w, h, |
2605 w, ref_stride, obmc_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
|
2606 s->block[index].type, add, s->block[index].color[plane_index]); |
2138 | 2607 |
2197 | 2608 STOP_TIMER("add_xblock") |
2138 | 2609 } |
2610 } | |
2197 | 2611 |
2612 STOP_TIMER("predict_plane") | |
2138 | 2613 } |
2614 | |
2615 static void quantize(SnowContext *s, SubBand *b, DWTELEM *src, int stride, int bias){ | |
2616 const int level= b->level; | |
2617 const int w= b->width; | |
2618 const int h= b->height; | |
2619 const int qlog= clip(s->qlog + b->qlog, 0, 128); | |
2620 const int qmul= qexp[qlog&7]<<(qlog>>3); | |
2150 | 2621 int x,y, thres1, thres2; |
2622 START_TIMER | |
2138 | 2623 |
2624 assert(QROOT==8); | |
2625 | |
2161 | 2626 if(s->qlog == LOSSLESS_QLOG) return; |
2627 | |
2138 | 2628 bias= bias ? 0 : (3*qmul)>>3; |
2150 | 2629 thres1= ((qmul - bias)>>QEXPSHIFT) - 1; |
2630 thres2= 2*thres1; | |
2138 | 2631 |
2632 if(!bias){ | |
2633 for(y=0; y<h; y++){ | |
2634 for(x=0; x<w; x++){ | |
2150 | 2635 int i= src[x + y*stride]; |
2636 | |
2637 if((unsigned)(i+thres1) > thres2){ | |
2638 if(i>=0){ | |
2639 i<<= QEXPSHIFT; | |
2640 i/= qmul; //FIXME optimize | |
2641 src[x + y*stride]= i; | |
2642 }else{ | |
2643 i= -i; | |
2644 i<<= QEXPSHIFT; | |
2645 i/= qmul; //FIXME optimize | |
2646 src[x + y*stride]= -i; | |
2647 } | |
2648 }else | |
2649 src[x + y*stride]= 0; | |
2138 | 2650 } |
2651 } | |
2652 }else{ | |
2653 for(y=0; y<h; y++){ | |
2654 for(x=0; x<w; x++){ | |
2655 int i= src[x + y*stride]; | |
2656 | |
2150 | 2657 if((unsigned)(i+thres1) > thres2){ |
2658 if(i>=0){ | |
2659 i<<= QEXPSHIFT; | |
2660 i= (i + bias) / qmul; //FIXME optimize | |
2661 src[x + y*stride]= i; | |
2662 }else{ | |
2663 i= -i; | |
2664 i<<= QEXPSHIFT; | |
2665 i= (i + bias) / qmul; //FIXME optimize | |
2666 src[x + y*stride]= -i; | |
2667 } | |
2668 }else | |
2669 src[x + y*stride]= 0; | |
2138 | 2670 } |
2671 } | |
2672 } | |
2150 | 2673 if(level+1 == s->spatial_decomposition_count){ |
2674 // STOP_TIMER("quantize") | |
2675 } | |
2138 | 2676 } |
2677 | |
2678 static void dequantize(SnowContext *s, SubBand *b, DWTELEM *src, int stride){ | |
2679 const int level= b->level; | |
2680 const int w= b->width; | |
2681 const int h= b->height; | |
2682 const int qlog= clip(s->qlog + b->qlog, 0, 128); | |
2683 const int qmul= qexp[qlog&7]<<(qlog>>3); | |
2684 const int qadd= (s->qbias*qmul)>>QBIAS_SHIFT; | |
2685 int x,y; | |
2195 | 2686 START_TIMER |
2138 | 2687 |
2161 | 2688 if(s->qlog == LOSSLESS_QLOG) return; |
2689 | |
2138 | 2690 assert(QROOT==8); |
2691 | |
2692 for(y=0; y<h; y++){ | |
2693 for(x=0; x<w; x++){ | |
2694 int i= src[x + y*stride]; | |
2695 if(i<0){ | |
2696 src[x + y*stride]= -((-i*qmul + qadd)>>(QEXPSHIFT)); //FIXME try different bias | |
2697 }else if(i>0){ | |
2698 src[x + y*stride]= (( i*qmul + qadd)>>(QEXPSHIFT)); | |
2699 } | |
2700 } | |
2701 } | |
2195 | 2702 if(w > 200 /*level+1 == s->spatial_decomposition_count*/){ |
2703 STOP_TIMER("dquant") | |
2704 } | |
2138 | 2705 } |
2706 | |
2707 static void decorrelate(SnowContext *s, SubBand *b, DWTELEM *src, int stride, int inverse, int use_median){ | |
2708 const int w= b->width; | |
2709 const int h= b->height; | |
2710 int x,y; | |
2711 | |
2712 for(y=h-1; y>=0; y--){ | |
2713 for(x=w-1; x>=0; x--){ | |
2714 int i= x + y*stride; | |
2715 | |
2716 if(x){ | |
2717 if(use_median){ | |
2718 if(y && x+1<w) src[i] -= mid_pred(src[i - 1], src[i - stride], src[i - stride + 1]); | |
2719 else src[i] -= src[i - 1]; | |
2720 }else{ | |
2721 if(y) src[i] -= mid_pred(src[i - 1], src[i - stride], src[i - 1] + src[i - stride] - src[i - 1 - stride]); | |
2722 else src[i] -= src[i - 1]; | |
2723 } | |
2724 }else{ | |
2725 if(y) src[i] -= src[i - stride]; | |
2726 } | |
2727 } | |
2728 } | |
2729 } | |
2730 | |
2731 static void correlate(SnowContext *s, SubBand *b, DWTELEM *src, int stride, int inverse, int use_median){ | |
2732 const int w= b->width; | |
2733 const int h= b->height; | |
2734 int x,y; | |
2735 | |
2736 for(y=0; y<h; y++){ | |
2737 for(x=0; x<w; x++){ | |
2738 int i= x + y*stride; | |
2739 | |
2740 if(x){ | |
2741 if(use_median){ | |
2742 if(y && x+1<w) src[i] += mid_pred(src[i - 1], src[i - stride], src[i - stride + 1]); | |
2743 else src[i] += src[i - 1]; | |
2744 }else{ | |
2745 if(y) src[i] += mid_pred(src[i - 1], src[i - stride], src[i - 1] + src[i - stride] - src[i - 1 - stride]); | |
2746 else src[i] += src[i - 1]; | |
2747 } | |
2748 }else{ | |
2749 if(y) src[i] += src[i - stride]; | |
2750 } | |
2751 } | |
2752 } | |
2753 } | |
2754 | |
2755 static void encode_header(SnowContext *s){ | |
2756 int plane_index, level, orientation; | |
2757 | |
2758 put_cabac(&s->c, s->header_state, s->keyframe); // state clearing stuff? | |
2759 if(s->keyframe){ | |
2760 put_symbol(&s->c, s->header_state, s->version, 0); | |
2761 put_symbol(&s->c, s->header_state, s->temporal_decomposition_type, 0); | |
2762 put_symbol(&s->c, s->header_state, s->temporal_decomposition_count, 0); | |
2763 put_symbol(&s->c, s->header_state, s->spatial_decomposition_count, 0); | |
2764 put_symbol(&s->c, s->header_state, s->colorspace_type, 0); | |
2765 put_symbol(&s->c, s->header_state, s->chroma_h_shift, 0); | |
2766 put_symbol(&s->c, s->header_state, s->chroma_v_shift, 0); | |
2767 put_cabac(&s->c, s->header_state, s->spatial_scalability); | |
2768 // put_cabac(&s->c, s->header_state, s->rate_scalability); | |
2769 | |
2770 for(plane_index=0; plane_index<2; plane_index++){ | |
2771 for(level=0; level<s->spatial_decomposition_count; level++){ | |
2772 for(orientation=level ? 1:0; orientation<4; orientation++){ | |
2773 if(orientation==2) continue; | |
2774 put_symbol(&s->c, s->header_state, s->plane[plane_index].band[level][orientation].qlog, 1); | |
2775 } | |
2776 } | |
2777 } | |
2778 } | |
2779 put_symbol(&s->c, s->header_state, s->spatial_decomposition_type, 0); | |
2780 put_symbol(&s->c, s->header_state, s->qlog, 1); | |
2781 put_symbol(&s->c, s->header_state, s->mv_scale, 0); | |
2782 put_symbol(&s->c, s->header_state, s->qbias, 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
|
2783 put_symbol(&s->c, s->header_state, s->block_max_depth, 0); |
2138 | 2784 } |
2785 | |
2786 static int decode_header(SnowContext *s){ | |
2787 int plane_index, level, orientation; | |
2788 | |
2789 s->keyframe= get_cabac(&s->c, s->header_state); | |
2790 if(s->keyframe){ | |
2791 s->version= get_symbol(&s->c, s->header_state, 0); | |
2792 if(s->version>0){ | |
2793 av_log(s->avctx, AV_LOG_ERROR, "version %d not supported", s->version); | |
2794 return -1; | |
2795 } | |
2796 s->temporal_decomposition_type= get_symbol(&s->c, s->header_state, 0); | |
2797 s->temporal_decomposition_count= get_symbol(&s->c, s->header_state, 0); | |
2798 s->spatial_decomposition_count= get_symbol(&s->c, s->header_state, 0); | |
2799 s->colorspace_type= get_symbol(&s->c, s->header_state, 0); | |
2800 s->chroma_h_shift= get_symbol(&s->c, s->header_state, 0); | |
2801 s->chroma_v_shift= get_symbol(&s->c, s->header_state, 0); | |
2802 s->spatial_scalability= get_cabac(&s->c, s->header_state); | |
2803 // s->rate_scalability= get_cabac(&s->c, s->header_state); | |
2804 | |
2805 for(plane_index=0; plane_index<3; plane_index++){ | |
2806 for(level=0; level<s->spatial_decomposition_count; level++){ | |
2807 for(orientation=level ? 1:0; orientation<4; orientation++){ | |
2808 int q; | |
2809 if (plane_index==2) q= s->plane[1].band[level][orientation].qlog; | |
2810 else if(orientation==2) q= s->plane[plane_index].band[level][1].qlog; | |
2811 else q= get_symbol(&s->c, s->header_state, 1); | |
2812 s->plane[plane_index].band[level][orientation].qlog= q; | |
2813 } | |
2814 } | |
2815 } | |
2816 } | |
2817 | |
2818 s->spatial_decomposition_type= get_symbol(&s->c, s->header_state, 0); | |
2819 if(s->spatial_decomposition_type > 2){ | |
2820 av_log(s->avctx, AV_LOG_ERROR, "spatial_decomposition_type %d not supported", s->spatial_decomposition_type); | |
2821 return -1; | |
2822 } | |
2823 | |
2824 s->qlog= get_symbol(&s->c, s->header_state, 1); | |
2825 s->mv_scale= get_symbol(&s->c, s->header_state, 0); | |
2826 s->qbias= get_symbol(&s->c, s->header_state, 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
|
2827 s->block_max_depth= get_symbol(&s->c, s->header_state, 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
|
2828 |
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
|
2829 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
|
2830 } |
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
|
2831 |
2138 | 2832 static int common_init(AVCodecContext *avctx){ |
2833 SnowContext *s = avctx->priv_data; | |
2834 int width, height; | |
2835 int level, orientation, plane_index, dec; | |
2836 | |
2837 s->avctx= avctx; | |
2838 | |
2839 dsputil_init(&s->dsp, avctx); | |
2840 | |
2841 #define mcf(dx,dy)\ | |
2842 s->dsp.put_qpel_pixels_tab [0][dy+dx/4]=\ | |
2843 s->dsp.put_no_rnd_qpel_pixels_tab[0][dy+dx/4]=\ | |
2844 mc_block ## dx ## dy; | |
2845 | |
2846 mcf( 0, 0) | |
2847 mcf( 4, 0) | |
2848 mcf( 8, 0) | |
2849 mcf(12, 0) | |
2850 mcf( 0, 4) | |
2851 mcf( 4, 4) | |
2852 mcf( 8, 4) | |
2853 mcf(12, 4) | |
2854 mcf( 0, 8) | |
2855 mcf( 4, 8) | |
2856 mcf( 8, 8) | |
2857 mcf(12, 8) | |
2858 mcf( 0,12) | |
2859 mcf( 4,12) | |
2860 mcf( 8,12) | |
2861 mcf(12,12) | |
2862 | |
2863 #define mcfh(dx,dy)\ | |
2864 s->dsp.put_pixels_tab [0][dy/4+dx/8]=\ | |
2865 s->dsp.put_no_rnd_pixels_tab[0][dy/4+dx/8]=\ | |
2866 mc_block_hpel ## dx ## dy; | |
2867 | |
2868 mcfh(0, 0) | |
2869 mcfh(8, 0) | |
2870 mcfh(0, 8) | |
2871 mcfh(8, 8) | |
2872 | |
2873 dec= s->spatial_decomposition_count= 5; | |
2874 s->spatial_decomposition_type= avctx->prediction_method; //FIXME add decorrelator type r transform_type | |
2875 | |
2876 s->chroma_h_shift= 1; //FIXME XXX | |
2877 s->chroma_v_shift= 1; | |
2878 | |
2879 // dec += FFMAX(s->chroma_h_shift, s->chroma_v_shift); | |
2880 | |
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
|
2881 width= s->avctx->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
|
2882 height= s->avctx->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
|
2883 |
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
|
2884 s->spatial_dwt_buffer= av_mallocz(width*height*sizeof(DWTELEM)); |
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
|
2885 s->pred_buffer= av_mallocz(width*height*sizeof(DWTELEM)); |
2138 | 2886 |
2887 s->mv_scale= (s->avctx->flags & CODEC_FLAG_QPEL) ? 2 : 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
|
2888 s->block_max_depth= (s->avctx->flags & CODEC_FLAG_4MV) ? 1 : 0; |
2138 | 2889 |
2890 for(plane_index=0; plane_index<3; plane_index++){ | |
2891 int w= s->avctx->width; | |
2892 int h= s->avctx->height; | |
2893 | |
2894 if(plane_index){ | |
2895 w>>= s->chroma_h_shift; | |
2896 h>>= s->chroma_v_shift; | |
2897 } | |
2898 s->plane[plane_index].width = w; | |
2899 s->plane[plane_index].height= h; | |
2160 | 2900 //av_log(NULL, AV_LOG_DEBUG, "%d %d\n", w, h); |
2138 | 2901 for(level=s->spatial_decomposition_count-1; level>=0; level--){ |
2902 for(orientation=level ? 1 : 0; orientation<4; orientation++){ | |
2903 SubBand *b= &s->plane[plane_index].band[level][orientation]; | |
2904 | |
2905 b->buf= s->spatial_dwt_buffer; | |
2906 b->level= level; | |
2907 b->stride= s->plane[plane_index].width << (s->spatial_decomposition_count - level); | |
2908 b->width = (w + !(orientation&1))>>1; | |
2909 b->height= (h + !(orientation>1))>>1; | |
2910 | |
2911 if(orientation&1) b->buf += (w+1)>>1; | |
2912 if(orientation>1) b->buf += b->stride>>1; | |
2913 | |
2914 if(level) | |
2915 b->parent= &s->plane[plane_index].band[level-1][orientation]; | |
2193 | 2916 b->x = av_mallocz(((b->width+1) * b->height+1)*sizeof(int16_t)); |
2917 b->coeff= av_mallocz(((b->width+1) * b->height+1)*sizeof(DWTELEM)); | |
2138 | 2918 } |
2919 w= (w+1)>>1; | |
2920 h= (h+1)>>1; | |
2921 } | |
2922 } | |
2923 | |
2924 reset_contexts(s); | |
2925 /* | |
2926 width= s->width= avctx->width; | |
2927 height= s->height= avctx->height; | |
2928 | |
2929 assert(width && height); | |
2930 */ | |
2931 s->avctx->get_buffer(s->avctx, &s->mconly_picture); | |
2932 | |
2933 return 0; | |
2934 } | |
2935 | |
2936 | |
2937 static void calculate_vissual_weight(SnowContext *s, Plane *p){ | |
2938 int width = p->width; | |
2939 int height= p->height; | |
2940 int i, level, orientation, x, y; | |
2941 | |
2942 for(level=0; level<s->spatial_decomposition_count; level++){ | |
2943 for(orientation=level ? 1 : 0; orientation<4; orientation++){ | |
2944 SubBand *b= &p->band[level][orientation]; | |
2945 DWTELEM *buf= b->buf; | |
2946 int64_t error=0; | |
2947 | |
2948 memset(s->spatial_dwt_buffer, 0, sizeof(int)*width*height); | |
2949 buf[b->width/2 + b->height/2*b->stride]= 256*256; | |
2164 | 2950 ff_spatial_idwt(s->spatial_dwt_buffer, width, height, width, s->spatial_decomposition_type, s->spatial_decomposition_count); |
2138 | 2951 for(y=0; y<height; y++){ |
2952 for(x=0; x<width; x++){ | |
2953 int64_t d= s->spatial_dwt_buffer[x + y*width]; | |
2954 error += d*d; | |
2955 } | |
2956 } | |
2957 | |
2958 b->qlog= (int)(log(352256.0/sqrt(error)) / log(pow(2.0, 1.0/QROOT))+0.5); | |
2164 | 2959 // av_log(NULL, AV_LOG_DEBUG, "%d %d %d\n", level, orientation, b->qlog/*, sqrt(error)*/); |
2138 | 2960 } |
2961 } | |
2962 } | |
2963 | |
2964 static int encode_init(AVCodecContext *avctx) | |
2965 { | |
2966 SnowContext *s = avctx->priv_data; | |
2967 int i; | |
2968 int level, orientation, plane_index; | |
2969 | |
2151 | 2970 if(avctx->strict_std_compliance >= 0){ |
2971 av_log(avctx, AV_LOG_ERROR, "this codec is under development, files encoded with it wont be decodeable with future versions!!!\n" | |
2972 "use vstrict=-1 to use it anyway\n"); | |
2973 return -1; | |
2974 } | |
2975 | |
2138 | 2976 common_init(avctx); |
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
|
2977 alloc_blocks(s); |
2138 | 2978 |
2979 s->version=0; | |
2980 | |
2981 s->m.me.scratchpad= av_mallocz((avctx->width+64)*2*16*2*sizeof(uint8_t)); | |
2982 s->m.me.map = av_mallocz(ME_MAP_SIZE*sizeof(uint32_t)); | |
2983 s->m.me.score_map = av_mallocz(ME_MAP_SIZE*sizeof(uint32_t)); | |
2984 h263_encode_init(&s->m); //mv_penalty | |
2985 | |
2986 for(plane_index=0; plane_index<3; plane_index++){ | |
2987 calculate_vissual_weight(s, &s->plane[plane_index]); | |
2988 } | |
2989 | |
2990 | |
2991 avctx->coded_frame= &s->current_picture; | |
2992 switch(avctx->pix_fmt){ | |
2993 // case PIX_FMT_YUV444P: | |
2994 // case PIX_FMT_YUV422P: | |
2995 case PIX_FMT_YUV420P: | |
2996 case PIX_FMT_GRAY8: | |
2997 // case PIX_FMT_YUV411P: | |
2998 // case PIX_FMT_YUV410P: | |
2999 s->colorspace_type= 0; | |
3000 break; | |
3001 /* case PIX_FMT_RGBA32: | |
3002 s->colorspace= 1; | |
3003 break;*/ | |
3004 default: | |
3005 av_log(avctx, AV_LOG_ERROR, "format not supported\n"); | |
3006 return -1; | |
3007 } | |
3008 // avcodec_get_chroma_sub_sample(avctx->pix_fmt, &s->chroma_h_shift, &s->chroma_v_shift); | |
3009 s->chroma_h_shift= 1; | |
3010 s->chroma_v_shift= 1; | |
3011 return 0; | |
3012 } | |
3013 | |
3014 static int frame_start(SnowContext *s){ | |
3015 AVFrame tmp; | |
2187 | 3016 int w= s->avctx->width; //FIXME round up to x16 ? |
3017 int h= s->avctx->height; | |
2138 | 3018 |
3019 if(s->keyframe) | |
3020 reset_contexts(s); | |
3021 | |
2187 | 3022 if(s->current_picture.data[0]){ |
3023 draw_edges(s->current_picture.data[0], s->current_picture.linesize[0], w , h , EDGE_WIDTH ); | |
3024 draw_edges(s->current_picture.data[1], s->current_picture.linesize[1], w>>1, h>>1, EDGE_WIDTH/2); | |
3025 draw_edges(s->current_picture.data[2], s->current_picture.linesize[2], w>>1, h>>1, EDGE_WIDTH/2); | |
3026 } | |
3027 | |
2138 | 3028 tmp= s->last_picture; |
3029 s->last_picture= s->current_picture; | |
3030 s->current_picture= tmp; | |
3031 | |
3032 s->current_picture.reference= 1; | |
3033 if(s->avctx->get_buffer(s->avctx, &s->current_picture) < 0){ | |
3034 av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); | |
3035 return -1; | |
3036 } | |
3037 | |
3038 return 0; | |
3039 } | |
3040 | |
3041 static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){ | |
3042 SnowContext *s = avctx->priv_data; | |
3043 CABACContext * const c= &s->c; | |
3044 AVFrame *pict = data; | |
3045 const int width= s->avctx->width; | |
3046 const int height= s->avctx->height; | |
3047 int used_count= 0; | |
3048 int log2_threshold, level, orientation, plane_index, i; | |
3049 | |
3050 ff_init_cabac_encoder(c, buf, buf_size); | |
3051 ff_init_cabac_states(c, ff_h264_lps_range, ff_h264_mps_state, ff_h264_lps_state, 64); | |
3052 | |
3053 s->input_picture = *pict; | |
3054 | |
3055 memset(s->header_state, 0, sizeof(s->header_state)); | |
3056 | |
3057 s->keyframe=avctx->gop_size==0 || avctx->frame_number % avctx->gop_size == 0; | |
3058 pict->pict_type= s->keyframe ? FF_I_TYPE : FF_P_TYPE; | |
3059 | |
2161 | 3060 if(pict->quality){ |
3061 s->qlog= rint(QROOT*log(pict->quality / (float)FF_QP2LAMBDA)/log(2)); | |
3062 //<64 >60 | |
3063 s->qlog += 61; | |
3064 }else{ | |
3065 s->qlog= LOSSLESS_QLOG; | |
3066 } | |
2138 | 3067 |
3068 frame_start(s); | |
3069 | |
3070 if(pict->pict_type == P_TYPE){ | |
3071 int block_width = (width +15)>>4; | |
3072 int block_height= (height+15)>>4; | |
3073 int stride= s->current_picture.linesize[0]; | |
3074 uint8_t *src_plane= s->input_picture.data[0]; | |
3075 int src_stride= s->input_picture.linesize[0]; | |
3076 int x,y; | |
3077 | |
3078 assert(s->current_picture.data[0]); | |
3079 assert(s->last_picture.data[0]); | |
3080 | |
3081 s->m.avctx= s->avctx; | |
3082 s->m.current_picture.data[0]= s->current_picture.data[0]; | |
3083 s->m. last_picture.data[0]= s-> last_picture.data[0]; | |
3084 s->m. new_picture.data[0]= s-> input_picture.data[0]; | |
3085 s->m.current_picture_ptr= &s->m.current_picture; | |
3086 s->m. last_picture_ptr= &s->m. last_picture; | |
3087 s->m.linesize= | |
3088 s->m. last_picture.linesize[0]= | |
3089 s->m. new_picture.linesize[0]= | |
3090 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
|
3091 s->m.uvlinesize= s->current_picture.linesize[1]; |
2138 | 3092 s->m.width = width; |
3093 s->m.height= height; | |
3094 s->m.mb_width = block_width; | |
3095 s->m.mb_height= block_height; | |
3096 s->m.mb_stride= s->m.mb_width+1; | |
3097 s->m.b8_stride= 2*s->m.mb_width+1; | |
3098 s->m.f_code=1; | |
3099 s->m.pict_type= pict->pict_type; | |
3100 s->m.me_method= s->avctx->me_method; | |
3101 s->m.me.scene_change_score=0; | |
3102 s->m.flags= s->avctx->flags; | |
3103 s->m.quarter_sample= (s->avctx->flags & CODEC_FLAG_QPEL)!=0; | |
3104 s->m.out_format= FMT_H263; | |
3105 s->m.unrestricted_mv= 1; | |
3106 | |
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
|
3107 s->lambda = s->m.lambda= pict->quality * 3/2; //FIXME bug somewhere else |
2138 | 3108 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
|
3109 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
|
3110 |
2138 | 3111 s->m.dsp= s->dsp; //move |
3112 ff_init_me(&s->m); | |
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
|
3113 } |
2138 | 3114 |
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
|
3115 redo_frame: |
2138 | 3116 |
3117 s->qbias= pict->pict_type == P_TYPE ? 2 : 0; | |
3118 | |
3119 encode_header(s); | |
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
|
3120 encode_blocks(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
|
3121 |
2138 | 3122 for(plane_index=0; plane_index<3; plane_index++){ |
3123 Plane *p= &s->plane[plane_index]; | |
3124 int w= p->width; | |
3125 int h= p->height; | |
3126 int x, y; | |
3127 int bits= put_bits_count(&s->c.pb); | |
3128 | |
3129 //FIXME optimize | |
3130 if(pict->data[plane_index]) //FIXME gray hack | |
3131 for(y=0; y<h; y++){ | |
3132 for(x=0; x<w; x++){ | |
3133 s->spatial_dwt_buffer[y*w + x]= pict->data[plane_index][y*pict->linesize[plane_index] + x]<<8; | |
3134 } | |
3135 } | |
3136 predict_plane(s, s->spatial_dwt_buffer, plane_index, 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
|
3137 |
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
|
3138 if( plane_index==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
|
3139 && pict->pict_type == P_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
|
3140 && s->m.me.scene_change_score > s->avctx->scenechange_threshold){ |
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
|
3141 ff_init_cabac_encoder(c, buf, buf_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
|
3142 ff_init_cabac_states(c, ff_h264_lps_range, ff_h264_mps_state, ff_h264_lps_state, 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
|
3143 pict->pict_type= FF_I_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
|
3144 s->keyframe=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
|
3145 reset_contexts(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
|
3146 goto redo_frame; |
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
|
3147 } |
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
|
3148 |
2161 | 3149 if(s->qlog == LOSSLESS_QLOG){ |
3150 for(y=0; y<h; y++){ | |
3151 for(x=0; x<w; x++){ | |
3152 s->spatial_dwt_buffer[y*w + x]= (s->spatial_dwt_buffer[y*w + x] + 127)>>8; | |
3153 } | |
3154 } | |
3155 } | |
3156 | |
2164 | 3157 ff_spatial_dwt(s->spatial_dwt_buffer, w, h, w, s->spatial_decomposition_type, s->spatial_decomposition_count); |
2161 | 3158 |
2138 | 3159 for(level=0; level<s->spatial_decomposition_count; level++){ |
3160 for(orientation=level ? 1 : 0; orientation<4; orientation++){ | |
3161 SubBand *b= &p->band[level][orientation]; | |
3162 | |
3163 quantize(s, b, b->buf, b->stride, s->qbias); | |
3164 if(orientation==0) | |
3165 decorrelate(s, b, b->buf, b->stride, pict->pict_type == P_TYPE, 0); | |
3166 encode_subband(s, b, b->buf, b->parent ? b->parent->buf : NULL, b->stride, orientation); | |
3167 assert(b->parent==NULL || b->parent->stride == b->stride*2); | |
3168 if(orientation==0) | |
3169 correlate(s, b, b->buf, b->stride, 1, 0); | |
3170 } | |
3171 } | |
3172 // av_log(NULL, AV_LOG_DEBUG, "plane:%d bits:%d\n", plane_index, put_bits_count(&s->c.pb) - bits); | |
3173 | |
3174 for(level=0; level<s->spatial_decomposition_count; level++){ | |
3175 for(orientation=level ? 1 : 0; orientation<4; orientation++){ | |
3176 SubBand *b= &p->band[level][orientation]; | |
3177 | |
3178 dequantize(s, b, b->buf, b->stride); | |
3179 } | |
3180 } | |
2161 | 3181 |
2164 | 3182 ff_spatial_idwt(s->spatial_dwt_buffer, w, h, w, s->spatial_decomposition_type, s->spatial_decomposition_count); |
2161 | 3183 if(s->qlog == LOSSLESS_QLOG){ |
3184 for(y=0; y<h; y++){ | |
3185 for(x=0; x<w; x++){ | |
3186 s->spatial_dwt_buffer[y*w + x]<<=8; | |
3187 } | |
3188 } | |
3189 } | |
2138 | 3190 predict_plane(s, s->spatial_dwt_buffer, plane_index, 1); |
3191 //FIXME optimize | |
3192 for(y=0; y<h; y++){ | |
3193 for(x=0; x<w; x++){ | |
3194 int v= (s->spatial_dwt_buffer[y*w + x]+128)>>8; | |
3195 if(v&(~255)) v= ~(v>>31); | |
3196 s->current_picture.data[plane_index][y*s->current_picture.linesize[plane_index] + x]= v; | |
3197 } | |
3198 } | |
3199 if(s->avctx->flags&CODEC_FLAG_PSNR){ | |
3200 int64_t error= 0; | |
3201 | |
3202 if(pict->data[plane_index]) //FIXME gray hack | |
3203 for(y=0; y<h; y++){ | |
3204 for(x=0; x<w; x++){ | |
2161 | 3205 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]; |
2138 | 3206 error += d*d; |
3207 } | |
3208 } | |
3209 s->avctx->error[plane_index] += error; | |
3210 s->avctx->error[3] += error; | |
3211 } | |
3212 } | |
3213 | |
3214 if(s->last_picture.data[0]) | |
3215 avctx->release_buffer(avctx, &s->last_picture); | |
3216 | |
3217 emms_c(); | |
3218 | |
3219 return put_cabac_terminate(c, 1); | |
3220 } | |
3221 | |
3222 static void common_end(SnowContext *s){ | |
2192 | 3223 int plane_index, level, orientation; |
3224 | |
2138 | 3225 av_freep(&s->spatial_dwt_buffer); |
3226 | |
3227 av_freep(&s->m.me.scratchpad); | |
3228 av_freep(&s->m.me.map); | |
3229 av_freep(&s->m.me.score_map); | |
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
|
3230 |
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
|
3231 av_freep(&s->block); |
2192 | 3232 |
3233 for(plane_index=0; plane_index<3; plane_index++){ | |
3234 for(level=s->spatial_decomposition_count-1; level>=0; level--){ | |
3235 for(orientation=level ? 1 : 0; orientation<4; orientation++){ | |
3236 SubBand *b= &s->plane[plane_index].band[level][orientation]; | |
3237 | |
3238 av_freep(&b->x); | |
2193 | 3239 av_freep(&b->coeff); |
2192 | 3240 } |
3241 } | |
3242 } | |
2138 | 3243 } |
3244 | |
3245 static int encode_end(AVCodecContext *avctx) | |
3246 { | |
3247 SnowContext *s = avctx->priv_data; | |
3248 | |
3249 common_end(s); | |
3250 | |
3251 return 0; | |
3252 } | |
3253 | |
3254 static int decode_init(AVCodecContext *avctx) | |
3255 { | |
3256 // SnowContext *s = avctx->priv_data; | |
3257 | |
3258 common_init(avctx); | |
3259 | |
3260 return 0; | |
3261 } | |
3262 | |
3263 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size){ | |
3264 SnowContext *s = avctx->priv_data; | |
3265 CABACContext * const c= &s->c; | |
3266 const int width= s->avctx->width; | |
3267 const int height= s->avctx->height; | |
3268 int bytes_read; | |
3269 AVFrame *picture = data; | |
3270 int log2_threshold, level, orientation, plane_index; | |
3271 | |
3272 | |
3273 /* no supplementary picture */ | |
3274 if (buf_size == 0) | |
3275 return 0; | |
3276 | |
3277 ff_init_cabac_decoder(c, buf, buf_size); | |
3278 ff_init_cabac_states(c, ff_h264_lps_range, ff_h264_mps_state, ff_h264_lps_state, 64); | |
3279 | |
3280 memset(s->header_state, 0, sizeof(s->header_state)); | |
3281 | |
3282 s->current_picture.pict_type= FF_I_TYPE; //FIXME I vs. P | |
3283 decode_header(s); | |
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
|
3284 if(!s->block) alloc_blocks(s); |
2138 | 3285 |
3286 frame_start(s); | |
3287 //keyframe flag dupliaction mess FIXME | |
3288 if(avctx->debug&FF_DEBUG_PICT_INFO) | |
3289 av_log(avctx, AV_LOG_ERROR, "keyframe:%d qlog:%d\n", s->keyframe, s->qlog); | |
3290 | |
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
|
3291 decode_blocks(s); |
2138 | 3292 |
3293 for(plane_index=0; plane_index<3; plane_index++){ | |
3294 Plane *p= &s->plane[plane_index]; | |
3295 int w= p->width; | |
3296 int h= p->height; | |
3297 int x, y; | |
3298 | |
3299 if(s->avctx->debug&2048){ | |
3300 memset(s->spatial_dwt_buffer, 0, sizeof(DWTELEM)*w*h); | |
3301 predict_plane(s, s->spatial_dwt_buffer, plane_index, 1); | |
3302 | |
3303 for(y=0; y<h; y++){ | |
3304 for(x=0; x<w; x++){ | |
3305 int v= (s->spatial_dwt_buffer[y*w + x]+128)>>8; | |
3306 if(v&(~255)) v= ~(v>>31); | |
3307 s->mconly_picture.data[plane_index][y*s->mconly_picture.linesize[plane_index] + x]= v; | |
3308 } | |
3309 } | |
3310 } | |
3311 for(level=0; level<s->spatial_decomposition_count; level++){ | |
3312 for(orientation=level ? 1 : 0; orientation<4; orientation++){ | |
3313 SubBand *b= &p->band[level][orientation]; | |
3314 | |
3315 decode_subband(s, b, b->buf, b->parent ? b->parent->buf : NULL, b->stride, orientation); | |
2195 | 3316 if(orientation==0){ |
2138 | 3317 correlate(s, b, b->buf, b->stride, 1, 0); |
2195 | 3318 dequantize(s, b, b->buf, b->stride); |
3319 assert(b->buf == s->spatial_dwt_buffer); | |
3320 } | |
2138 | 3321 } |
3322 } | |
3323 | |
2164 | 3324 ff_spatial_idwt(s->spatial_dwt_buffer, w, h, w, s->spatial_decomposition_type, s->spatial_decomposition_count); |
2161 | 3325 if(s->qlog == LOSSLESS_QLOG){ |
3326 for(y=0; y<h; y++){ | |
3327 for(x=0; x<w; x++){ | |
3328 s->spatial_dwt_buffer[y*w + x]<<=8; | |
3329 } | |
3330 } | |
3331 } | |
2138 | 3332 predict_plane(s, s->spatial_dwt_buffer, plane_index, 1); |
3333 | |
3334 //FIXME optimize | |
3335 for(y=0; y<h; y++){ | |
3336 for(x=0; x<w; x++){ | |
3337 int v= (s->spatial_dwt_buffer[y*w + x]+128)>>8; | |
3338 if(v&(~255)) v= ~(v>>31); | |
3339 s->current_picture.data[plane_index][y*s->current_picture.linesize[plane_index] + x]= v; | |
3340 } | |
3341 } | |
3342 } | |
3343 | |
3344 emms_c(); | |
3345 | |
3346 if(s->last_picture.data[0]) | |
3347 avctx->release_buffer(avctx, &s->last_picture); | |
3348 | |
3349 if(!(s->avctx->debug&2048)) | |
3350 *picture= s->current_picture; | |
3351 else | |
3352 *picture= s->mconly_picture; | |
3353 | |
3354 *data_size = sizeof(AVFrame); | |
3355 | |
3356 bytes_read= get_cabac_terminate(c); | |
3357 if(bytes_read ==0) av_log(s->avctx, AV_LOG_ERROR, "error at end of frame\n"); | |
3358 | |
3359 return bytes_read; | |
3360 } | |
3361 | |
3362 static int decode_end(AVCodecContext *avctx) | |
3363 { | |
3364 SnowContext *s = avctx->priv_data; | |
3365 | |
3366 common_end(s); | |
3367 | |
3368 return 0; | |
3369 } | |
3370 | |
3371 AVCodec snow_decoder = { | |
3372 "snow", | |
3373 CODEC_TYPE_VIDEO, | |
3374 CODEC_ID_SNOW, | |
3375 sizeof(SnowContext), | |
3376 decode_init, | |
3377 NULL, | |
3378 decode_end, | |
3379 decode_frame, | |
3380 0 /*CODEC_CAP_DR1*/ /*| CODEC_CAP_DRAW_HORIZ_BAND*/, | |
3381 NULL | |
3382 }; | |
3383 | |
3384 AVCodec snow_encoder = { | |
3385 "snow", | |
3386 CODEC_TYPE_VIDEO, | |
3387 CODEC_ID_SNOW, | |
3388 sizeof(SnowContext), | |
3389 encode_init, | |
3390 encode_frame, | |
3391 encode_end, | |
3392 }; | |
3393 | |
3394 | |
3395 #if 0 | |
3396 #undef malloc | |
3397 #undef free | |
3398 #undef printf | |
3399 | |
3400 int main(){ | |
3401 int width=256; | |
3402 int height=256; | |
3403 int buffer[2][width*height]; | |
3404 SnowContext s; | |
3405 int i; | |
3406 s.spatial_decomposition_count=6; | |
3407 s.spatial_decomposition_type=1; | |
3408 | |
3409 printf("testing 5/3 DWT\n"); | |
3410 for(i=0; i<width*height; i++) | |
3411 buffer[0][i]= buffer[1][i]= random()%54321 - 12345; | |
3412 | |
2164 | 3413 ff_spatial_dwt(buffer[0], width, height, width, s->spatial_decomposition_type, s->spatial_decomposition_count); |
3414 ff_spatial_idwt(buffer[0], width, height, width, s->spatial_decomposition_type, s->spatial_decomposition_count); | |
2138 | 3415 |
3416 for(i=0; i<width*height; i++) | |
3417 if(buffer[0][i]!= buffer[1][i]) printf("fsck: %d %d %d\n",i, buffer[0][i], buffer[1][i]); | |
3418 | |
3419 printf("testing 9/7 DWT\n"); | |
3420 s.spatial_decomposition_type=0; | |
3421 for(i=0; i<width*height; i++) | |
3422 buffer[0][i]= buffer[1][i]= random()%54321 - 12345; | |
3423 | |
2164 | 3424 ff_spatial_dwt(buffer[0], width, height, width, s->spatial_decomposition_type, s->spatial_decomposition_count); |
3425 ff_spatial_idwt(buffer[0], width, height, width, s->spatial_decomposition_type, s->spatial_decomposition_count); | |
2138 | 3426 |
3427 for(i=0; i<width*height; i++) | |
3428 if(buffer[0][i]!= buffer[1][i]) printf("fsck: %d %d %d\n",i, buffer[0][i], buffer[1][i]); | |
3429 | |
3430 printf("testing AC coder\n"); | |
3431 memset(s.header_state, 0, sizeof(s.header_state)); | |
3432 ff_init_cabac_encoder(&s.c, buffer[0], 256*256); | |
3433 ff_init_cabac_states(&s.c, ff_h264_lps_range, ff_h264_mps_state, ff_h264_lps_state, 64); | |
3434 | |
3435 for(i=-256; i<256; i++){ | |
3436 START_TIMER | |
3437 put_symbol(&s.c, s.header_state, i*i*i/3*ABS(i), 1); | |
3438 STOP_TIMER("put_symbol") | |
3439 } | |
3440 put_cabac_terminate(&s.c, 1); | |
3441 | |
3442 memset(s.header_state, 0, sizeof(s.header_state)); | |
3443 ff_init_cabac_decoder(&s.c, buffer[0], 256*256); | |
3444 ff_init_cabac_states(&s.c, ff_h264_lps_range, ff_h264_mps_state, ff_h264_lps_state, 64); | |
3445 | |
3446 for(i=-256; i<256; i++){ | |
3447 int j; | |
3448 START_TIMER | |
3449 j= get_symbol(&s.c, s.header_state, 1); | |
3450 STOP_TIMER("get_symbol") | |
3451 if(j!=i*i*i/3*ABS(i)) printf("fsck: %d != %d\n", i, j); | |
3452 } | |
3453 { | |
3454 int level, orientation, x, y; | |
3455 int64_t errors[8][4]; | |
3456 int64_t g=0; | |
3457 | |
3458 memset(errors, 0, sizeof(errors)); | |
3459 s.spatial_decomposition_count=3; | |
3460 s.spatial_decomposition_type=0; | |
3461 for(level=0; level<s.spatial_decomposition_count; level++){ | |
3462 for(orientation=level ? 1 : 0; orientation<4; orientation++){ | |
3463 int w= width >> (s.spatial_decomposition_count-level); | |
3464 int h= height >> (s.spatial_decomposition_count-level); | |
3465 int stride= width << (s.spatial_decomposition_count-level); | |
3466 DWTELEM *buf= buffer[0]; | |
3467 int64_t error=0; | |
3468 | |
3469 if(orientation&1) buf+=w; | |
3470 if(orientation>1) buf+=stride>>1; | |
3471 | |
3472 memset(buffer[0], 0, sizeof(int)*width*height); | |
3473 buf[w/2 + h/2*stride]= 256*256; | |
2164 | 3474 ff_spatial_idwt(buffer[0], width, height, width, s->spatial_decomposition_type, s->spatial_decomposition_count); |
2138 | 3475 for(y=0; y<height; y++){ |
3476 for(x=0; x<width; x++){ | |
3477 int64_t d= buffer[0][x + y*width]; | |
3478 error += d*d; | |
3479 if(ABS(width/2-x)<9 && ABS(height/2-y)<9 && level==2) printf("%8lld ", d); | |
3480 } | |
3481 if(ABS(height/2-y)<9 && level==2) printf("\n"); | |
3482 } | |
3483 error= (int)(sqrt(error)+0.5); | |
3484 errors[level][orientation]= error; | |
3485 if(g) g=ff_gcd(g, error); | |
3486 else g= error; | |
3487 } | |
3488 } | |
3489 printf("static int const visual_weight[][4]={\n"); | |
3490 for(level=0; level<s.spatial_decomposition_count; level++){ | |
3491 printf(" {"); | |
3492 for(orientation=0; orientation<4; orientation++){ | |
3493 printf("%8lld,", errors[level][orientation]/g); | |
3494 } | |
3495 printf("},\n"); | |
3496 } | |
3497 printf("};\n"); | |
3498 { | |
3499 int level=2; | |
3500 int orientation=3; | |
3501 int w= width >> (s.spatial_decomposition_count-level); | |
3502 int h= height >> (s.spatial_decomposition_count-level); | |
3503 int stride= width << (s.spatial_decomposition_count-level); | |
3504 DWTELEM *buf= buffer[0]; | |
3505 int64_t error=0; | |
3506 | |
3507 buf+=w; | |
3508 buf+=stride>>1; | |
3509 | |
3510 memset(buffer[0], 0, sizeof(int)*width*height); | |
3511 #if 1 | |
3512 for(y=0; y<height; y++){ | |
3513 for(x=0; x<width; x++){ | |
3514 int tab[4]={0,2,3,1}; | |
3515 buffer[0][x+width*y]= 256*256*tab[(x&1) + 2*(y&1)]; | |
3516 } | |
3517 } | |
2164 | 3518 ff_spatial_dwt(buffer[0], width, height, width, s->spatial_decomposition_type, s->spatial_decomposition_count); |
2138 | 3519 #else |
3520 for(y=0; y<h; y++){ | |
3521 for(x=0; x<w; x++){ | |
3522 buf[x + y*stride ]=169; | |
3523 buf[x + y*stride-w]=64; | |
3524 } | |
3525 } | |
2164 | 3526 ff_spatial_idwt(buffer[0], width, height, width, s->spatial_decomposition_type, s->spatial_decomposition_count); |
2138 | 3527 #endif |
3528 for(y=0; y<height; y++){ | |
3529 for(x=0; x<width; x++){ | |
3530 int64_t d= buffer[0][x + y*width]; | |
3531 error += d*d; | |
3532 if(ABS(width/2-x)<9 && ABS(height/2-y)<9) printf("%8lld ", d); | |
3533 } | |
3534 if(ABS(height/2-y)<9) printf("\n"); | |
3535 } | |
3536 } | |
3537 | |
3538 } | |
3539 return 0; | |
3540 } | |
3541 #endif | |
3542 |