1 /*
2 * H.26L/H.264/AVC/JVT/14496-10/... decoder
3 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #undef FUNC
23 #undef PIXEL_SHIFT
24
25 #if SIMPLE
26 # define FUNC(n) AV_JOIN(n ## _simple_, BITS)
27 # define PIXEL_SHIFT (BITS >> 4)
28 #else
29 # define FUNC(n) n ## _complex
30 # define PIXEL_SHIFT h->pixel_shift
31 #endif
32
33 #undef CHROMA_IDC
34 #define CHROMA_IDC 1
36
37 #undef CHROMA_IDC
38 #define CHROMA_IDC 2
40
42 {
43 const int mb_x = h->mb_x;
44 const int mb_y = h->mb_y;
45 const int mb_xy = h->mb_xy;
46 const int mb_type = h->cur_pic.mb_type[
mb_xy];
47 uint8_t *dest_y, *dest_cb, *dest_cr;
49 int i, j;
51 const int transform_bypass = !
SIMPLE && (h->qscale == 0 && h->sps.transform_bypass);
52 /* is_h264 should always be true if SVQ3 is disabled. */
55 const int block_h = 16 >> h->chroma_y_shift;
57
58 dest_y = h->cur_pic.f.data[0] + ((mb_x <<
PIXEL_SHIFT) + mb_y * h->linesize) * 16;
59 dest_cb = h->cur_pic.f.data[1] + (mb_x <<
PIXEL_SHIFT) * 8 + mb_y * h->uvlinesize * block_h;
60 dest_cr = h->cur_pic.f.data[2] + (mb_x <<
PIXEL_SHIFT) * 8 + mb_y * h->uvlinesize * block_h;
61
62 h->vdsp.prefetch(dest_y + (h->mb_x & 3) * 4 * h->linesize + (64 <<
PIXEL_SHIFT), h->linesize, 4);
63 h->vdsp.prefetch(dest_cb + (h->mb_x & 7) * h->uvlinesize + (64 <<
PIXEL_SHIFT), dest_cr - dest_cb, 2);
64
65 h->list_counts[
mb_xy] = h->list_count;
66
68 linesize = h->mb_linesize = h->linesize * 2;
69 uvlinesize = h->mb_uvlinesize = h->uvlinesize * 2;
70 block_offset = &h->block_offset[48];
71 if (mb_y & 1) { // FIXME move out of this function?
72 dest_y -= h->linesize * 15;
73 dest_cb -= h->uvlinesize * (block_h - 1);
74 dest_cr -= h->uvlinesize * (block_h - 1);
75 }
77 int list;
78 for (list = 0; list < h->list_count; list++) {
80 continue;
82 int8_t *ref = &h->ref_cache[list][
scan8[0]];
84 } else {
85 for (i = 0; i < 16; i += 4) {
86 int ref = h->ref_cache[list][
scan8[i]];
87 if (ref >= 0)
89 8, (16 + ref) ^ (h->mb_y & 1), 1);
90 }
91 }
92 }
93 }
94 } else {
95 linesize = h->mb_linesize = h->linesize;
96 uvlinesize = h->mb_uvlinesize = h->uvlinesize;
97 // dct_offset = s->linesize * 16;
98 }
99
101 const int bit_depth = h->sps.bit_depth_luma;
103 int j;
107
108 for (i = 0; i < 16; i++) {
109 uint16_t *tmp_y = (uint16_t *)(dest_y + i * linesize);
110 for (j = 0; j < 16; j++)
111 tmp_y[j] =
get_bits(&gb, bit_depth);
112 }
114 if (!h->sps.chroma_format_idc) {
115 for (i = 0; i < block_h; i++) {
116 uint16_t *tmp_cb = (uint16_t *)(dest_cb + i * uvlinesize);
117 uint16_t *tmp_cr = (uint16_t *)(dest_cr + i * uvlinesize);
118 for (j = 0; j < 8; j++) {
119 tmp_cb[j] = tmp_cr[j] = 1 << (bit_depth - 1);
120 }
121 }
122 } else {
123 for (i = 0; i < block_h; i++) {
124 uint16_t *tmp_cb = (uint16_t *)(dest_cb + i * uvlinesize);
125 for (j = 0; j < 8; j++)
126 tmp_cb[j] =
get_bits(&gb, bit_depth);
127 }
128 for (i = 0; i < block_h; i++) {
129 uint16_t *tmp_cr = (uint16_t *)(dest_cr + i * uvlinesize);
130 for (j = 0; j < 8; j++)
131 tmp_cr[j] =
get_bits(&gb, bit_depth);
132 }
133 }
134 }
135 } else {
136 for (i = 0; i < 16; i++)
137 memcpy(dest_y + i * linesize, h->intra_pcm_ptr + i * 16, 16);
139 if (!h->sps.chroma_format_idc) {
140 for (i = 0; i < 8; i++) {
141 memset(dest_cb + i*uvlinesize, 1 << (bit_depth - 1), 8);
142 memset(dest_cr + i*uvlinesize, 1 << (bit_depth - 1), 8);
143 }
144 } else {
145 const uint8_t *src_cb = h->intra_pcm_ptr + 256;
146 const uint8_t *src_cr = h->intra_pcm_ptr + 256 + block_h * 8;
147 for (i = 0; i < block_h; i++) {
148 memcpy(dest_cb + i * uvlinesize, src_cb + i * 8, 8);
149 memcpy(dest_cr + i * uvlinesize, src_cr + i * 8, 8);
150 }
151 }
152 }
153 }
154 } else {
156 if (h->deblocking_filter)
159
161 h->hpc.pred8x8[h->chroma_pred_mode](dest_cb,
uvlinesize);
162 h->hpc.pred8x8[h->chroma_pred_mode](dest_cr,
uvlinesize);
163 }
164
167 block_offset, linesize, dest_y, 0);
168
169 if (h->deblocking_filter)
172 } else if (is_h264) {
173 if (chroma422) {
174 FUNC(hl_motion_422)(h, dest_y, dest_cb, dest_cr,
175 h->me.qpel_put, h->h264chroma.put_h264_chroma_pixels_tab,
176 h->me.qpel_avg, h->h264chroma.avg_h264_chroma_pixels_tab,
177 h->h264dsp.weight_h264_pixels_tab,
178 h->h264dsp.biweight_h264_pixels_tab);
179 } else {
180 FUNC(hl_motion_420)(h, dest_y, dest_cb, dest_cr,
181 h->me.qpel_put, h->h264chroma.put_h264_chroma_pixels_tab,
182 h->me.qpel_avg, h->h264chroma.avg_h264_chroma_pixels_tab,
183 h->h264dsp.weight_h264_pixels_tab,
184 h->h264dsp.biweight_h264_pixels_tab);
185 }
186 }
187
190
192 (h->cbp & 0x30)) {
193 uint8_t *dest[2] = { dest_cb, dest_cr };
194 if (transform_bypass) {
195 if (
IS_INTRA(mb_type) && h->sps.profile_idc == 244 &&
198 h->hpc.pred8x8_add[h->chroma_pred_mode](dest[0],
199 block_offset + 16,
201 uvlinesize);
202 h->hpc.pred8x8_add[h->chroma_pred_mode](dest[1],
203 block_offset + 32,
205 uvlinesize);
206 } else {
207 idct_add = h->h264dsp.h264_add_pixels4_clear;
208 for (j = 1; j < 3; j++) {
209 for (i = j * 16; i < j * 16 + 4; i++)
210 if (h->non_zero_count_cache[
scan8[i]] ||
212 idct_add(dest[j - 1] + block_offset[i],
215 if (chroma422) {
216 for (i = j * 16 + 4; i < j * 16 + 8; i++)
217 if (h->non_zero_count_cache[
scan8[i + 4]] ||
219 idct_add(dest[j - 1] + block_offset[i + 4],
222 }
223 }
224 }
225 } else {
226 if (is_h264) {
227 int qp[2];
228 if (chroma422) {
229 qp[0] = h->chroma_qp[0] + 3;
230 qp[1] = h->chroma_qp[1] + 3;
231 } else {
232 qp[0] = h->chroma_qp[0];
233 qp[1] = h->chroma_qp[1];
234 }
236 h->h264dsp.h264_chroma_dc_dequant_idct(h->mb + (16 * 16 * 1 <<
PIXEL_SHIFT),
237 h->dequant4_coeff[
IS_INTRA(mb_type) ? 1 : 4][qp[0]][0]);
239 h->h264dsp.h264_chroma_dc_dequant_idct(h->mb + (16 * 16 * 2 <<
PIXEL_SHIFT),
240 h->dequant4_coeff[
IS_INTRA(mb_type) ? 2 : 5][qp[1]][0]);
241 h->h264dsp.h264_idct_add8(dest, block_offset,
242 h->mb, uvlinesize,
243 h->non_zero_count_cache);
244 } else if (CONFIG_SVQ3_DECODER) {
245 h->h264dsp.h264_chroma_dc_dequant_idct(h->mb + 16 * 16 * 1,
246 h->dequant4_coeff[
IS_INTRA(mb_type) ? 1 : 4][h->chroma_qp[0]][0]);
247 h->h264dsp.h264_chroma_dc_dequant_idct(h->mb + 16 * 16 * 2,
248 h->dequant4_coeff[
IS_INTRA(mb_type) ? 2 : 5][h->chroma_qp[1]][0]);
249 for (j = 1; j < 3; j++) {
250 for (i = j * 16; i < j * 16 + 4; i++)
251 if (h->non_zero_count_cache[
scan8[i]] || h->mb[i * 16]) {
252 uint8_t *
const ptr = dest[j - 1] + block_offset[i];
254 uvlinesize,
256 }
257 }
258 }
259 }
260 }
261 }
262 }
263
264 #if !SIMPLE || BITS == 8
265
266 #undef CHROMA_IDC
269
271 {
272 const int mb_x = h->mb_x;
273 const int mb_y = h->mb_y;
274 const int mb_xy = h->mb_xy;
275 const int mb_type = h->cur_pic.mb_type[
mb_xy];
278 int i, j, p;
280 const int transform_bypass = !
SIMPLE && (h->qscale == 0 && h->sps.transform_bypass);
282
283 for (p = 0; p < plane_count; p++) {
284 dest[p] = h->cur_pic.f.data[p] +
286 h->vdsp.prefetch(dest[p] + (h->mb_x & 3) * 4 * h->linesize + (64 <<
PIXEL_SHIFT),
287 h->linesize, 4);
288 }
289
290 h->list_counts[
mb_xy] = h->list_count;
291
293 linesize = h->mb_linesize = h->mb_uvlinesize = h->linesize * 2;
294 block_offset = &h->block_offset[48];
295 if (mb_y & 1) // FIXME move out of this function?
296 for (p = 0; p < 3; p++)
297 dest[p] -= h->linesize * 15;
299 int list;
300 for (list = 0; list < h->list_count; list++) {
302 continue;
304 int8_t *ref = &h->ref_cache[list][
scan8[0]];
306 } else {
307 for (i = 0; i < 16; i += 4) {
308 int ref = h->ref_cache[list][
scan8[i]];
309 if (ref >= 0)
311 8, (16 + ref) ^ (h->mb_y & 1), 1);
312 }
313 }
314 }
315 }
316 } else {
317 linesize = h->mb_linesize = h->mb_uvlinesize = h->linesize;
318 }
319
322 const int bit_depth = h->sps.bit_depth_luma;
325
326 for (p = 0; p < plane_count; p++)
327 for (i = 0; i < 16; i++) {
328 uint16_t *tmp = (uint16_t *)(dest[p] + i * linesize);
329 for (j = 0; j < 16; j++)
331 }
332 } else {
333 for (p = 0; p < plane_count; p++)
334 for (i = 0; i < 16; i++)
335 memcpy(dest[p] + i * linesize,
336 h->intra_pcm_ptr + p * 256 + i * 16, 16);
337 }
338 } else {
340 if (h->deblocking_filter)
343
344 for (p = 0; p < plane_count; p++)
347 block_offset, linesize, dest[p], p);
348
349 if (h->deblocking_filter)
352 } else {
353 FUNC(hl_motion_444)(h, dest[0], dest[1], dest[2],
354 h->me.qpel_put, h->h264chroma.put_h264_chroma_pixels_tab,
355 h->me.qpel_avg, h->h264chroma.avg_h264_chroma_pixels_tab,
356 h->h264dsp.weight_h264_pixels_tab,
357 h->h264dsp.biweight_h264_pixels_tab);
358 }
359
360 for (p = 0; p < plane_count; p++)
363 dest[p], p);
364 }
365 }
366
367 #endif