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