FFmpeg
pred_template.c
Go to the documentation of this file.
1 /*
2  * HEVC video decoder
3  *
4  * Copyright (C) 2012 - 2013 Guillaume Martres
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include "libavutil/pixdesc.h"
24 
25 #include "bit_depth_template.c"
26 #include "pred.h"
27 
28 #define POS(x, y) src[(x) + stride * (y)]
29 
31  const HEVCPPS *pps,
32  int x0, int y0,
33  int log2_size, int c_idx)
34 {
35 #define PU(x) \
36  ((x) >> sps->log2_min_pu_size)
37 #define MVF(x, y) \
38  (s->cur_frame->tab_mvf[(x) + (y) * min_pu_width])
39 #define MVF_PU(x, y) \
40  MVF(PU(x0 + ((x) * (1 << hshift))), PU(y0 + ((y) * (1 << vshift))))
41 #define IS_INTRA(x, y) \
42  (MVF_PU(x, y).pred_flag == PF_INTRA)
43 #define MIN_TB_ADDR_ZS(x, y) \
44  pps->min_tb_addr_zs[(y) * (sps->tb_mask+2) + (x)]
45 #define EXTEND(ptr, val, len) \
46 do { \
47  pixel4 pix = PIXEL_SPLAT_X4(val); \
48  for (i = 0; i < (len); i += 4) \
49  AV_WN4P(ptr + i, pix); \
50 } while (0)
51 
52 #define EXTEND_RIGHT_CIP(ptr, start, length) \
53  for (i = start; i < (start) + (length); i += 4) \
54  if (!IS_INTRA(i, -1)) \
55  AV_WN4P(&ptr[i], a); \
56  else \
57  a = PIXEL_SPLAT_X4(ptr[i+3])
58 #define EXTEND_LEFT_CIP(ptr, start, length) \
59  for (i = start; i > (start) - (length); i--) \
60  if (!IS_INTRA(i - 1, -1)) \
61  ptr[i - 1] = ptr[i]
62 #define EXTEND_UP_CIP(ptr, start, length) \
63  for (i = (start); i > (start) - (length); i -= 4) \
64  if (!IS_INTRA(-1, i - 3)) \
65  AV_WN4P(&ptr[i - 3], a); \
66  else \
67  a = PIXEL_SPLAT_X4(ptr[i - 3])
68 #define EXTEND_DOWN_CIP(ptr, start, length) \
69  for (i = start; i < (start) + (length); i += 4) \
70  if (!IS_INTRA(-1, i)) \
71  AV_WN4P(&ptr[i], a); \
72  else \
73  a = PIXEL_SPLAT_X4(ptr[i + 3])
74 
75  const HEVCSPS *const sps = pps->sps;
76  const HEVCContext *const s = lc->parent;
77  int i;
78  int hshift = sps->hshift[c_idx];
79  int vshift = sps->vshift[c_idx];
80  int size = (1 << log2_size);
81  int size_in_luma_h = size << hshift;
82  int size_in_tbs_h = size_in_luma_h >> sps->log2_min_tb_size;
83  int size_in_luma_v = size << vshift;
84  int size_in_tbs_v = size_in_luma_v >> sps->log2_min_tb_size;
85  int x = x0 >> hshift;
86  int y = y0 >> vshift;
87  int x_tb = (x0 >> sps->log2_min_tb_size) & sps->tb_mask;
88  int y_tb = (y0 >> sps->log2_min_tb_size) & sps->tb_mask;
89  int spin = c_idx && !size_in_tbs_v && ((2 * y0) & (1 << sps->log2_min_tb_size));
90 
91  int cur_tb_addr = MIN_TB_ADDR_ZS(x_tb, y_tb);
92 
93  ptrdiff_t stride = s->cur_frame->f->linesize[c_idx] / sizeof(pixel);
94  pixel *src = (pixel*)s->cur_frame->f->data[c_idx] + x + y * stride;
95 
96  int min_pu_width = sps->min_pu_width;
97 
98  enum IntraPredMode mode = c_idx ? lc->tu.intra_pred_mode_c :
99  lc->tu.intra_pred_mode;
100  pixel4 a;
101  pixel left_array[2 * MAX_TB_SIZE + 1];
102  pixel filtered_left_array[2 * MAX_TB_SIZE + 1];
103  pixel top_array[2 * MAX_TB_SIZE + 1];
104  pixel filtered_top_array[2 * MAX_TB_SIZE + 1];
105 
106  pixel *left = left_array + 1;
107  pixel *top = top_array + 1;
108  pixel *filtered_left = filtered_left_array + 1;
109  pixel *filtered_top = filtered_top_array + 1;
110  int cand_bottom_left = lc->na.cand_bottom_left && cur_tb_addr > MIN_TB_ADDR_ZS( x_tb - 1, (y_tb + size_in_tbs_v + spin) & sps->tb_mask);
111  int cand_left = lc->na.cand_left;
112  int cand_up_left = lc->na.cand_up_left;
113  int cand_up = lc->na.cand_up;
114  int cand_up_right = lc->na.cand_up_right && !spin && cur_tb_addr > MIN_TB_ADDR_ZS((x_tb + size_in_tbs_h) & sps->tb_mask, y_tb - 1);
115 
116  int bottom_left_size = (FFMIN(y0 + 2 * size_in_luma_v, sps->height) -
117  (y0 + size_in_luma_v)) >> vshift;
118  int top_right_size = (FFMIN(x0 + 2 * size_in_luma_h, sps->width) -
119  (x0 + size_in_luma_h)) >> hshift;
120 
121  if (pps->constrained_intra_pred_flag == 1) {
122  int size_in_luma_pu_v = PU(size_in_luma_v);
123  int size_in_luma_pu_h = PU(size_in_luma_h);
124  int on_pu_edge_x = !av_zero_extend(x0, sps->log2_min_pu_size);
125  int on_pu_edge_y = !av_zero_extend(y0, sps->log2_min_pu_size);
126  if (!size_in_luma_pu_h)
127  size_in_luma_pu_h++;
128  if (cand_bottom_left == 1 && on_pu_edge_x) {
129  int x_left_pu = PU(x0 - 1);
130  int y_bottom_pu = PU(y0 + size_in_luma_v);
131  int max = FFMIN(size_in_luma_pu_v, sps->min_pu_height - y_bottom_pu);
132  cand_bottom_left = 0;
133  for (i = 0; i < max; i += 2)
134  cand_bottom_left |= (MVF(x_left_pu, y_bottom_pu + i).pred_flag == PF_INTRA);
135  }
136  if (cand_left == 1 && on_pu_edge_x) {
137  int x_left_pu = PU(x0 - 1);
138  int y_left_pu = PU(y0);
139  int max = FFMIN(size_in_luma_pu_v, sps->min_pu_height - y_left_pu);
140  cand_left = 0;
141  for (i = 0; i < max; i += 2)
142  cand_left |= (MVF(x_left_pu, y_left_pu + i).pred_flag == PF_INTRA);
143  }
144  if (cand_up_left == 1) {
145  int x_left_pu = PU(x0 - 1);
146  int y_top_pu = PU(y0 - 1);
147  cand_up_left = MVF(x_left_pu, y_top_pu).pred_flag == PF_INTRA;
148  }
149  if (cand_up == 1 && on_pu_edge_y) {
150  int x_top_pu = PU(x0);
151  int y_top_pu = PU(y0 - 1);
152  int max = FFMIN(size_in_luma_pu_h, sps->min_pu_width - x_top_pu);
153  cand_up = 0;
154  for (i = 0; i < max; i += 2)
155  cand_up |= (MVF(x_top_pu + i, y_top_pu).pred_flag == PF_INTRA);
156  }
157  if (cand_up_right == 1 && on_pu_edge_y) {
158  int y_top_pu = PU(y0 - 1);
159  int x_right_pu = PU(x0 + size_in_luma_h);
160  int max = FFMIN(size_in_luma_pu_h, sps->min_pu_width - x_right_pu);
161  cand_up_right = 0;
162  for (i = 0; i < max; i += 2)
163  cand_up_right |= (MVF(x_right_pu + i, y_top_pu).pred_flag == PF_INTRA);
164  }
165  memset(left, 128, 2 * MAX_TB_SIZE*sizeof(pixel));
166  memset(top , 128, 2 * MAX_TB_SIZE*sizeof(pixel));
167  top[-1] = 128;
168  }
169  if (cand_up_left) {
170  left[-1] = POS(-1, -1);
171  top[-1] = left[-1];
172  }
173  if (cand_up)
174  memcpy(top, src - stride, size * sizeof(pixel));
175  if (cand_up_right) {
176  memcpy(top + size, src - stride + size, size * sizeof(pixel));
177  EXTEND(top + size + top_right_size, POS(size + top_right_size - 1, -1),
178  size - top_right_size);
179  }
180  if (cand_left)
181  for (i = 0; i < size; i++)
182  left[i] = POS(-1, i);
183  if (cand_bottom_left) {
184  for (i = size; i < size + bottom_left_size; i++)
185  left[i] = POS(-1, i);
186  EXTEND(left + size + bottom_left_size, POS(-1, size + bottom_left_size - 1),
187  size - bottom_left_size);
188  }
189 
190  if (pps->constrained_intra_pred_flag == 1) {
191  if (cand_bottom_left || cand_left || cand_up_left || cand_up || cand_up_right) {
192  int size_max_x = x0 + ((2 * size) << hshift) < sps->width ?
193  2 * size : (sps->width - x0) >> hshift;
194  int size_max_y = y0 + ((2 * size) << vshift) < sps->height ?
195  2 * size : (sps->height - y0) >> vshift;
196  int j = size + (cand_bottom_left? bottom_left_size: 0) -1;
197  if (!cand_up_right) {
198  size_max_x = x0 + ((size) << hshift) < sps->width ?
199  size : (sps->width - x0) >> hshift;
200  }
201  if (!cand_bottom_left) {
202  size_max_y = y0 + (( size) << vshift) < sps->height ?
203  size : (sps->height - y0) >> vshift;
204  }
205  if (cand_bottom_left || cand_left || cand_up_left) {
206  while (j > -1 && !IS_INTRA(-1, j))
207  j--;
208  if (!IS_INTRA(-1, j)) {
209  j = 0;
210  while (j < size_max_x && !IS_INTRA(j, -1))
211  j++;
212  EXTEND_LEFT_CIP(top, j, j + 1);
213  left[-1] = top[-1];
214  }
215  } else {
216  j = 0;
217  while (j < size_max_x && !IS_INTRA(j, -1))
218  j++;
219  if (j > 0) {
220  EXTEND_LEFT_CIP(top, j, j);
221  top[-1] = top[0];
222  }
223  left[-1] = top[-1];
224  }
225  left[-1] = top[-1];
226  if (cand_bottom_left || cand_left) {
227  a = PIXEL_SPLAT_X4(left[-1]);
228  EXTEND_DOWN_CIP(left, 0, size_max_y);
229  }
230  if (!cand_left)
231  EXTEND(left, left[-1], size);
232  if (!cand_bottom_left)
233  EXTEND(left + size, left[size - 1], size);
234  if (x0 != 0 && y0 != 0) {
235  a = PIXEL_SPLAT_X4(left[size_max_y - 1]);
236  EXTEND_UP_CIP(left, size_max_y - 1, size_max_y);
237  if (!IS_INTRA(-1, - 1))
238  left[-1] = left[0];
239  } else if (x0 == 0) {
240  EXTEND(left, 0, size_max_y);
241  } else {
242  a = PIXEL_SPLAT_X4(left[size_max_y - 1]);
243  EXTEND_UP_CIP(left, size_max_y - 1, size_max_y);
244  }
245  top[-1] = left[-1];
246  if (y0 != 0) {
247  a = PIXEL_SPLAT_X4(left[-1]);
248  EXTEND_RIGHT_CIP(top, 0, size_max_x);
249  }
250  }
251  }
252  // Infer the unavailable samples
253  if (!cand_bottom_left) {
254  if (cand_left) {
255  EXTEND(left + size, left[size - 1], size);
256  } else if (cand_up_left) {
257  EXTEND(left, left[-1], 2 * size);
258  cand_left = 1;
259  } else if (cand_up) {
260  left[-1] = top[0];
261  EXTEND(left, left[-1], 2 * size);
262  cand_up_left = 1;
263  cand_left = 1;
264  } else if (cand_up_right) {
265  EXTEND(top, top[size], size);
266  left[-1] = top[size];
267  EXTEND(left, left[-1], 2 * size);
268  cand_up = 1;
269  cand_up_left = 1;
270  cand_left = 1;
271  } else { // No samples available
272  left[-1] = (1 << (BIT_DEPTH - 1));
273  EXTEND(top, left[-1], 2 * size);
274  EXTEND(left, left[-1], 2 * size);
275  }
276  }
277 
278  if (!cand_left)
279  EXTEND(left, left[size], size);
280  if (!cand_up_left) {
281  left[-1] = left[0];
282  }
283  if (!cand_up)
284  EXTEND(top, left[-1], size);
285  if (!cand_up_right)
286  EXTEND(top + size, top[size - 1], size);
287 
288  top[-1] = left[-1];
289 
290  // Filtering process
291  if (!sps->intra_smoothing_disabled && (c_idx == 0 || sps->chroma_format_idc == 3)) {
292  if (mode != INTRA_DC && size != 4){
293  int intra_hor_ver_dist_thresh[] = { 7, 1, 0 };
294  int min_dist_vert_hor = FFMIN(FFABS((int)(mode - 26U)),
295  FFABS((int)(mode - 10U)));
296  if (min_dist_vert_hor > intra_hor_ver_dist_thresh[log2_size - 3]) {
297  int threshold = 1 << (BIT_DEPTH - 5);
298  if (sps->strong_intra_smoothing_enabled && c_idx == 0 &&
299  log2_size == 5 &&
300  FFABS(top[-1] + top[63] - 2 * top[31]) < threshold &&
301  FFABS(left[-1] + left[63] - 2 * left[31]) < threshold) {
302  // We can't just overwrite values in top because it could be
303  // a pointer into src
304  filtered_top[-1] = top[-1];
305  filtered_top[63] = top[63];
306  for (i = 0; i < 63; i++)
307  filtered_top[i] = ((64 - (i + 1)) * top[-1] +
308  (i + 1) * top[63] + 32) >> 6;
309  for (i = 0; i < 63; i++)
310  left[i] = ((64 - (i + 1)) * left[-1] +
311  (i + 1) * left[63] + 32) >> 6;
312  top = filtered_top;
313  } else {
314  filtered_left[2 * size - 1] = left[2 * size - 1];
315  filtered_top[2 * size - 1] = top[2 * size - 1];
316  for (i = 2 * size - 2; i >= 0; i--)
317  filtered_left[i] = (left[i + 1] + 2 * left[i] +
318  left[i - 1] + 2) >> 2;
319  filtered_top[-1] =
320  filtered_left[-1] = (left[0] + 2 * left[-1] + top[0] + 2) >> 2;
321  for (i = 2 * size - 2; i >= 0; i--)
322  filtered_top[i] = (top[i + 1] + 2 * top[i] +
323  top[i - 1] + 2) >> 2;
324  left = filtered_left;
325  top = filtered_top;
326  }
327  }
328  }
329  }
330 
331  switch (mode) {
332  case INTRA_PLANAR:
333  s->hpc.pred_planar[log2_size - 2]((uint8_t *)src, (uint8_t *)top,
334  (uint8_t *)left, stride);
335  break;
336  case INTRA_DC:
337  s->hpc.pred_dc((uint8_t *)src, (uint8_t *)top,
338  (uint8_t *)left, stride, log2_size, c_idx);
339  break;
340  default:
341  s->hpc.pred_angular[log2_size - 2]((uint8_t *)src, (uint8_t *)top,
342  (uint8_t *)left, stride, c_idx,
343  mode);
344  break;
345  }
346 }
347 
348 #define INTRA_PRED(size) \
349 static void FUNC(intra_pred_ ## size)(HEVCLocalContext *lc, const HEVCPPS *pps, \
350  int x0, int y0, int c_idx) \
351 { \
352  FUNC(intra_pred)(lc, pps, x0, y0, size, c_idx); \
353 }
354 
355 INTRA_PRED(2)
356 INTRA_PRED(3)
357 INTRA_PRED(4)
358 INTRA_PRED(5)
359 
360 #undef INTRA_PRED
361 
362 static av_always_inline void FUNC(pred_planar)(uint8_t *_src, const uint8_t *_top,
363  const uint8_t *_left, ptrdiff_t stride,
364  int trafo_size)
365 {
366  int x, y;
367  pixel *src = (pixel *)_src;
368  const pixel *top = (const pixel *)_top;
369  const pixel *left = (const pixel *)_left;
370  int size = 1 << trafo_size;
371  for (y = 0; y < size; y++)
372  for (x = 0; x < size; x++)
373  POS(x, y) = ((size - 1 - x) * left[y] + (x + 1) * top[size] +
374  (size - 1 - y) * top[x] + (y + 1) * left[size] + size) >> (trafo_size + 1);
375 }
376 
377 #define PRED_PLANAR(size)\
378 static void FUNC(pred_planar_ ## size)(uint8_t *src, const uint8_t *top, \
379  const uint8_t *left, ptrdiff_t stride) \
380 { \
381  FUNC(pred_planar)(src, top, left, stride, size + 2); \
382 }
383 
384 PRED_PLANAR(0)
385 PRED_PLANAR(1)
386 PRED_PLANAR(2)
387 PRED_PLANAR(3)
388 
389 #undef PRED_PLANAR
390 
391 static void FUNC(pred_dc)(uint8_t *_src, const uint8_t *_top,
392  const uint8_t *_left,
393  ptrdiff_t stride, int log2_size, int c_idx)
394 {
395  int i, j, x, y;
396  int size = (1 << log2_size);
397  pixel *src = (pixel *)_src;
398  const pixel *top = (const pixel *)_top;
399  const pixel *left = (const pixel *)_left;
400  int dc = size;
401  pixel4 a;
402  for (i = 0; i < size; i++)
403  dc += left[i] + top[i];
404 
405  dc >>= log2_size + 1;
406 
407  a = PIXEL_SPLAT_X4(dc);
408 
409  for (i = 0; i < size; i++)
410  for (j = 0; j < size; j+=4)
411  AV_WN4P(&POS(j, i), a);
412 
413  if (c_idx == 0 && size < 32) {
414  POS(0, 0) = (left[0] + 2 * dc + top[0] + 2) >> 2;
415  for (x = 1; x < size; x++)
416  POS(x, 0) = (top[x] + 3 * dc + 2) >> 2;
417  for (y = 1; y < size; y++)
418  POS(0, y) = (left[y] + 3 * dc + 2) >> 2;
419  }
420 }
421 
422 static av_always_inline void FUNC(pred_angular)(uint8_t *_src,
423  const uint8_t *_top,
424  const uint8_t *_left,
425  ptrdiff_t stride, int c_idx,
426  int mode, int size)
427 {
428  int x, y;
429  pixel *src = (pixel *)_src;
430  const pixel *top = (const pixel *)_top;
431  const pixel *left = (const pixel *)_left;
432 
433  static const int intra_pred_angle[] = {
434  32, 26, 21, 17, 13, 9, 5, 2, 0, -2, -5, -9, -13, -17, -21, -26, -32,
435  -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32
436  };
437  static const int inv_angle[] = {
438  -4096, -1638, -910, -630, -482, -390, -315, -256, -315, -390, -482,
439  -630, -910, -1638, -4096
440  };
441 
442  int angle = intra_pred_angle[mode - 2];
443  pixel ref_array[3 * MAX_TB_SIZE + 4];
444  pixel *ref_tmp = ref_array + size;
445  const pixel *ref;
446  int last = (size * angle) >> 5;
447 
448  if (mode >= 18) {
449  ref = top - 1;
450  if (angle < 0 && last < -1) {
451  for (x = 0; x <= size; x += 4)
452  AV_WN4P(&ref_tmp[x], AV_RN4P(&top[x - 1]));
453  for (x = last; x <= -1; x++)
454  ref_tmp[x] = left[-1 + ((x * inv_angle[mode - 11] + 128) >> 8)];
455  ref = ref_tmp;
456  }
457 
458  for (y = 0; y < size; y++) {
459  int idx = ((y + 1) * angle) >> 5;
460  int fact = ((y + 1) * angle) & 31;
461  if (fact) {
462  for (x = 0; x < size; x += 4) {
463  POS(x , y) = ((32 - fact) * ref[x + idx + 1] +
464  fact * ref[x + idx + 2] + 16) >> 5;
465  POS(x + 1, y) = ((32 - fact) * ref[x + 1 + idx + 1] +
466  fact * ref[x + 1 + idx + 2] + 16) >> 5;
467  POS(x + 2, y) = ((32 - fact) * ref[x + 2 + idx + 1] +
468  fact * ref[x + 2 + idx + 2] + 16) >> 5;
469  POS(x + 3, y) = ((32 - fact) * ref[x + 3 + idx + 1] +
470  fact * ref[x + 3 + idx + 2] + 16) >> 5;
471  }
472  } else {
473  for (x = 0; x < size; x += 4)
474  AV_WN4P(&POS(x, y), AV_RN4P(&ref[x + idx + 1]));
475  }
476  }
477  if (mode == 26 && c_idx == 0 && size < 32) {
478  for (y = 0; y < size; y++)
479  POS(0, y) = av_clip_pixel(top[0] + ((left[y] - left[-1]) >> 1));
480  }
481  } else {
482  ref = left - 1;
483  if (angle < 0 && last < -1) {
484  for (x = 0; x <= size; x += 4)
485  AV_WN4P(&ref_tmp[x], AV_RN4P(&left[x - 1]));
486  for (x = last; x <= -1; x++)
487  ref_tmp[x] = top[-1 + ((x * inv_angle[mode - 11] + 128) >> 8)];
488  ref = ref_tmp;
489  }
490 
491  for (x = 0; x < size; x++) {
492  int idx = ((x + 1) * angle) >> 5;
493  int fact = ((x + 1) * angle) & 31;
494  if (fact) {
495  for (y = 0; y < size; y++) {
496  POS(x, y) = ((32 - fact) * ref[y + idx + 1] +
497  fact * ref[y + idx + 2] + 16) >> 5;
498  }
499  } else {
500  for (y = 0; y < size; y++)
501  POS(x, y) = ref[y + idx + 1];
502  }
503  }
504  if (mode == 10 && c_idx == 0 && size < 32) {
505  for (x = 0; x < size; x += 4) {
506  POS(x, 0) = av_clip_pixel(left[0] + ((top[x ] - top[-1]) >> 1));
507  POS(x + 1, 0) = av_clip_pixel(left[0] + ((top[x + 1] - top[-1]) >> 1));
508  POS(x + 2, 0) = av_clip_pixel(left[0] + ((top[x + 2] - top[-1]) >> 1));
509  POS(x + 3, 0) = av_clip_pixel(left[0] + ((top[x + 3] - top[-1]) >> 1));
510  }
511  }
512  }
513 }
514 
515 static void FUNC(pred_angular_0)(uint8_t *src, const uint8_t *top,
516  const uint8_t *left,
517  ptrdiff_t stride, int c_idx, int mode)
518 {
519  FUNC(pred_angular)(src, top, left, stride, c_idx, mode, 1 << 2);
520 }
521 
522 static void FUNC(pred_angular_1)(uint8_t *src, const uint8_t *top,
523  const uint8_t *left,
524  ptrdiff_t stride, int c_idx, int mode)
525 {
526  FUNC(pred_angular)(src, top, left, stride, c_idx, mode, 1 << 3);
527 }
528 
529 static void FUNC(pred_angular_2)(uint8_t *src, const uint8_t *top,
530  const uint8_t *left,
531  ptrdiff_t stride, int c_idx, int mode)
532 {
533  FUNC(pred_angular)(src, top, left, stride, c_idx, mode, 1 << 4);
534 }
535 
536 static void FUNC(pred_angular_3)(uint8_t *src, const uint8_t *top,
537  const uint8_t *left,
538  ptrdiff_t stride, int c_idx, int mode)
539 {
540  FUNC(pred_angular)(src, top, left, stride, c_idx, mode, 1 << 5);
541 }
542 
543 #undef EXTEND_LEFT_CIP
544 #undef EXTEND_RIGHT_CIP
545 #undef EXTEND_UP_CIP
546 #undef EXTEND_DOWN_CIP
547 #undef IS_INTRA
548 #undef MVF_PU
549 #undef MVF
550 #undef PU
551 #undef EXTEND
552 #undef MIN_TB_ADDR_ZS
553 #undef POS
HEVCLocalContext
Definition: hevcdec.h:388
pred_angular_3
static void FUNC() pred_angular_3(uint8_t *src, const uint8_t *top, const uint8_t *left, ptrdiff_t stride, int c_idx, int mode)
Definition: pred_template.c:536
AV_RN4P
#define AV_RN4P
Definition: bit_depth_template.c:91
mode
Definition: swscale.c:52
pixdesc.h
INTRA_DC
@ INTRA_DC
Definition: hevcdec.h:124
max
#define max(a, b)
Definition: cuda_runtime.h:33
PRED_PLANAR
#define PRED_PLANAR(size)
Definition: pred_template.c:377
PF_INTRA
@ PF_INTRA
Definition: hevcdec.h:116
_src
uint8_t ptrdiff_t const uint8_t * _src
Definition: dsp.h:52
pixel4
#define pixel4
Definition: bit_depth_template.c:83
EXTEND_LEFT_CIP
#define EXTEND_LEFT_CIP(ptr, start, length)
MIN_TB_ADDR_ZS
#define MIN_TB_ADDR_ZS(x, y)
s
#define s(width, name)
Definition: cbs_vp9.c:198
intra_pred
static av_always_inline void FUNC() intra_pred(HEVCLocalContext *lc, const HEVCPPS *pps, int x0, int y0, int log2_size, int c_idx)
Definition: pred_template.c:30
EXTEND_DOWN_CIP
#define EXTEND_DOWN_CIP(ptr, start, length)
pred_angular_2
static void FUNC() pred_angular_2(uint8_t *src, const uint8_t *top, const uint8_t *left, ptrdiff_t stride, int c_idx, int mode)
Definition: pred_template.c:529
PIXEL_SPLAT_X4
#define PIXEL_SPLAT_X4(x)
Definition: bit_depth_template.c:96
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:74
pred_angular
static av_always_inline void FUNC() pred_angular(uint8_t *_src, const uint8_t *_top, const uint8_t *_left, ptrdiff_t stride, int c_idx, int mode, int size)
Definition: pred_template.c:422
POS
#define POS(x, y)
Definition: pred_template.c:28
pixel
uint8_t pixel
Definition: tiny_ssim.c:41
EXTEND_UP_CIP
#define EXTEND_UP_CIP(ptr, start, length)
bit_depth_template.c
EXTEND_RIGHT_CIP
#define EXTEND_RIGHT_CIP(ptr, start, length)
IS_INTRA
#define IS_INTRA(x, y)
dc
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled top and top right vectors is used as motion vector prediction the used motion vector is the sum of the predictor and(mvx_diff, mvy_diff) *mv_scale Intra DC Prediction block[y][x] dc[1]
Definition: snow.txt:400
PU
#define PU(x)
INTRA_PLANAR
@ INTRA_PLANAR
Definition: hevcdec.h:123
pred_angular_0
static void FUNC() pred_angular_0(uint8_t *src, const uint8_t *top, const uint8_t *left, ptrdiff_t stride, int c_idx, int mode)
Definition: pred_template.c:515
size
int size
Definition: twinvq_data.h:10344
MVF
#define MVF(x, y)
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
fact
static double fact(double i)
Definition: af_aiir.c:935
av_zero_extend
#define av_zero_extend
Definition: common.h:151
pred_dc
static void FUNC() pred_dc(uint8_t *_src, const uint8_t *_top, const uint8_t *_left, ptrdiff_t stride, int log2_size, int c_idx)
Definition: pred_template.c:391
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
av_always_inline
#define av_always_inline
Definition: attributes.h:49
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
pred.h
stride
#define stride
Definition: h264pred_template.c:537
INTRA_PRED
#define INTRA_PRED(size)
Definition: pred_template.c:348
vshift
static int vshift(enum AVPixelFormat fmt, int plane)
Definition: graph.c:97
IntraPredMode
IntraPredMode
Definition: hevcdec.h:122
sps
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
Definition: cbs_h264_syntax_template.c:260
av_clip_pixel
#define av_clip_pixel(a)
Definition: bit_depth_template.c:98
left
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled left
Definition: snow.txt:386
U
#define U(x)
Definition: vpx_arith.h:37
pred_angular_1
static void FUNC() pred_angular_1(uint8_t *src, const uint8_t *top, const uint8_t *left, ptrdiff_t stride, int c_idx, int mode)
Definition: pred_template.c:522
FUNC
#define FUNC(a)
Definition: bit_depth_template.c:104
BIT_DEPTH
#define BIT_DEPTH
Definition: dsp_init.c:38
mode
mode
Definition: ebur128.h:83
HEVCContext
Definition: hevcdec.h:487
AV_WN4P
#define AV_WN4P
Definition: bit_depth_template.c:94
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:117
pps
uint64_t pps
Definition: dovi_rpuenc.c:35
EXTEND
#define EXTEND(ptr, val, len)
HEVCSPS
Definition: ps.h:252
HEVCPPS
Definition: ps.h:371
pred_planar
static av_always_inline void FUNC() pred_planar(uint8_t *_src, const uint8_t *_top, const uint8_t *_left, ptrdiff_t stride, int trafo_size)
Definition: pred_template.c:362
MAX_TB_SIZE
#define MAX_TB_SIZE
Definition: hevcdec.h:49
src
#define src
Definition: vp8dsp.c:248