cdef.c 15.9 KB
Newer Older
Yaowu Xu's avatar
Yaowu Xu committed
1
/*
Yaowu Xu's avatar
Yaowu Xu committed
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Yaowu Xu's avatar
Yaowu Xu committed
3
 *
Yaowu Xu's avatar
Yaowu Xu committed
4
5
6
7
8
9
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
Yaowu Xu's avatar
Yaowu Xu committed
10
11
 */

12
#include <assert.h>
Yaowu Xu's avatar
Yaowu Xu committed
13
#include <math.h>
14
#include <string.h>
Yaowu Xu's avatar
Yaowu Xu committed
15

Yaowu Xu's avatar
Yaowu Xu committed
16
17
#include "./aom_scale_rtcd.h"
#include "aom/aom_integer.h"
18
19
#include "av1/common/cdef.h"
#include "av1/common/od_dering.h"
20
21
#include "av1/common/onyxc_int.h"
#include "av1/common/reconinter.h"
Yaowu Xu's avatar
Yaowu Xu committed
22

Yaowu Xu's avatar
Yaowu Xu committed
23
int sb_all_skip(const AV1_COMMON *const cm, int mi_row, int mi_col) {
Yaowu Xu's avatar
Yaowu Xu committed
24
25
26
27
28
  int r, c;
  int maxc, maxr;
  int skip = 1;
  maxc = cm->mi_cols - mi_col;
  maxr = cm->mi_rows - mi_row;
29
30
31
32
#if CONFIG_EXT_PARTITION
  if (maxr > cm->mib_size_log2) maxr = cm->mib_size_log2;
  if (maxc > cm->mib_size_log2) maxc = cm->mib_size_log2;
#else
33
34
  if (maxr > MAX_MIB_SIZE) maxr = MAX_MIB_SIZE;
  if (maxc > MAX_MIB_SIZE) maxc = MAX_MIB_SIZE;
35
36
#endif

Yaowu Xu's avatar
Yaowu Xu committed
37
38
39
  for (r = 0; r < maxr; r++) {
    for (c = 0; c < maxc; c++) {
      skip = skip &&
clang-format's avatar
clang-format committed
40
41
             cm->mi_grid_visible[(mi_row + r) * cm->mi_stride + mi_col + c]
                 ->mbmi.skip;
Yaowu Xu's avatar
Yaowu Xu committed
42
43
44
45
46
    }
  }
  return skip;
}

Jingning Han's avatar
Jingning Han committed
47
48
49
50
51
52
53
54
55
56
static int is_8x8_block_skip(MODE_INFO **grid, int mi_row, int mi_col,
                             int mi_stride) {
  int is_skip = 1;
  for (int r = 0; r < mi_size_high[BLOCK_8X8]; ++r)
    for (int c = 0; c < mi_size_wide[BLOCK_8X8]; ++c)
      is_skip &= grid[(mi_row + r) * mi_stride + (mi_col + c)]->mbmi.skip;

  return is_skip;
}

57
int sb_compute_dering_list(const AV1_COMMON *const cm, int mi_row, int mi_col,
58
                           dering_list *dlist) {
Jean-Marc Valin's avatar
Jean-Marc Valin committed
59
60
61
  int r, c;
  int maxc, maxr;
  MODE_INFO **grid;
62
  int count = 0;
Jean-Marc Valin's avatar
Jean-Marc Valin committed
63
64
65
  grid = cm->mi_grid_visible;
  maxc = cm->mi_cols - mi_col;
  maxr = cm->mi_rows - mi_row;
66
67
68
69
#if CONFIG_EXT_PARTITION
  if (maxr > cm->mib_size_log2) maxr = cm->mib_size_log2;
  if (maxc > cm->mib_size_log2) maxc = cm->mib_size_log2;
#else
Jean-Marc Valin's avatar
Jean-Marc Valin committed
70
71
  if (maxr > MAX_MIB_SIZE) maxr = MAX_MIB_SIZE;
  if (maxc > MAX_MIB_SIZE) maxc = MAX_MIB_SIZE;
72
#endif
73
74
75

  const int r_step = mi_size_high[BLOCK_8X8];
  const int c_step = mi_size_wide[BLOCK_8X8];
Jingning Han's avatar
Jingning Han committed
76
77
78
79
80
  const int r_shift = (r_step == 2);
  const int c_shift = (c_step == 2);

  assert(r_step == 1 || r_step == 2);
  assert(c_step == 1 || c_step == 2);
81
82
83

  for (r = 0; r < maxr; r += r_step) {
    for (c = 0; c < maxc; c += c_step) {
Jingning Han's avatar
Jingning Han committed
84
85
86
      if (!is_8x8_block_skip(grid, mi_row + r, mi_col + c, cm->mi_stride)) {
        dlist[count].by = r >> r_shift;
        dlist[count].bx = c >> c_shift;
87
88
        count++;
      }
Jean-Marc Valin's avatar
Jean-Marc Valin committed
89
90
    }
  }
91
  return count;
Jean-Marc Valin's avatar
Jean-Marc Valin committed
92
93
}

Michael Bebenita's avatar
Michael Bebenita committed
94
95
void copy_rect8_8bit_to_16bit_c(uint16_t *dst, int dstride, const uint8_t *src,
                                int sstride, int v, int h) {
96
  int i, j;
Michael Bebenita's avatar
Michael Bebenita committed
97
98
99
  OD_ASSERT((h & 0x7) == 0);
  for (i = 0; i < v; i++) {
    for (j = 0; j < h; j++) {
100
101
102
103
104
      dst[i * dstride + j] = src[i * sstride + j];
    }
  }
}

Michael Bebenita's avatar
Michael Bebenita committed
105
106
107
void copy_rect8_16bit_to_16bit_c(uint16_t *dst, int dstride,
                                 const uint16_t *src, int sstride, int v,
                                 int h) {
108
  int i, j;
Michael Bebenita's avatar
Michael Bebenita committed
109
110
111
  OD_ASSERT((h & 0x7) == 0);
  for (i = 0; i < v; i++) {
    for (j = 0; j < h; j++) {
112
113
114
115
116
117
118
119
      dst[i * dstride + j] = src[i * sstride + j];
    }
  }
}

void copy_sb8_16(UNUSED AV1_COMMON *cm, uint16_t *dst, int dstride,
                 const uint8_t *src, int src_voffset, int src_hoffset,
                 int sstride, int vsize, int hsize) {
120
121
#if CONFIG_AOM_HIGHBITDEPTH
  if (cm->use_highbitdepth) {
122
123
    const uint16_t *base =
        &CONVERT_TO_SHORTPTR(src)[src_voffset * sstride + src_hoffset];
Michael Bebenita's avatar
Michael Bebenita committed
124
    copy_rect8_16bit_to_16bit(dst, dstride, base, sstride, vsize, hsize);
125
  } else {
126
127
#endif
    const uint8_t *base = &src[src_voffset * sstride + src_hoffset];
Michael Bebenita's avatar
Michael Bebenita committed
128
    copy_rect8_8bit_to_16bit(dst, dstride, base, sstride, vsize, hsize);
129
#if CONFIG_AOM_HIGHBITDEPTH
130
  }
131
#endif
132
133
}

Michael Bebenita's avatar
Michael Bebenita committed
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
static INLINE void fill_rect(uint16_t *dst, int dstride, int v, int h,
                             uint16_t x) {
  int i, j;
  OD_ASSERT((h & 0x7) == 0);
  for (i = 0; i < v; i++) {
    for (j = 0; j < h; j += 8) {
      int k = i * dstride + j;
      dst[k + 0] = x;
      dst[k + 1] = x;
      dst[k + 2] = x;
      dst[k + 3] = x;
      dst[k + 4] = x;
      dst[k + 5] = x;
      dst[k + 6] = x;
      dst[k + 7] = x;
    }
  }
}

Michael Bebenita's avatar
Michael Bebenita committed
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
static INLINE void copy_rect(uint16_t *dst, int dstride, const uint16_t *src,
                             int sstride, int v, int h) {
  int i, j;
  OD_ASSERT((h & 0x7) == 0);
  for (i = 0; i < v; i++) {
    for (j = 0; j < h; j += 8) {
      int k = i * dstride + j;
      int l = i * sstride + j;
      dst[k + 0] = src[l + 0];
      dst[k + 1] = src[l + 1];
      dst[k + 2] = src[l + 2];
      dst[k + 3] = src[l + 3];
      dst[k + 4] = src[l + 4];
      dst[k + 5] = src[l + 5];
      dst[k + 6] = src[l + 6];
      dst[k + 7] = src[l + 7];
    }
  }
}

173
174
void av1_cdef_frame(YV12_BUFFER_CONFIG *frame, AV1_COMMON *cm,
                    MACROBLOCKD *xd) {
Yaowu Xu's avatar
Yaowu Xu committed
175
176
  int sbr, sbc;
  int nhsb, nvsb;
177
178
  uint16_t src[OD_DERING_INBUF_SIZE];
  uint16_t *linebuf[3];
Michael Bebenita's avatar
Michael Bebenita committed
179
  uint16_t colbuf[3][(OD_BSIZE_MAX + 2 * OD_FILT_VBORDER) * OD_FILT_HBORDER];
180
  dering_list dlist[MAX_MIB_SIZE * MAX_MIB_SIZE];
181
  unsigned char *row_dering, *prev_row_dering, *curr_row_dering;
182
  int dering_count;
clang-format's avatar
clang-format committed
183
  int dir[OD_DERING_NBLOCKS][OD_DERING_NBLOCKS] = { { 0 } };
184
  int var[OD_DERING_NBLOCKS][OD_DERING_NBLOCKS] = { { 0 } };
Yaowu Xu's avatar
Yaowu Xu committed
185
  int stride;
Jingning Han's avatar
Jingning Han committed
186
187
  int mi_wide_l2[3];
  int mi_high_l2[3];
188
  int dec[3];
Yaowu Xu's avatar
Yaowu Xu committed
189
  int pli;
190
  int dering_left;
Yaowu Xu's avatar
Yaowu Xu committed
191
  int coeff_shift = AOMMAX(cm->bit_depth - 8, 0);
192
193
194
195
  int nplanes = 3;
  int chroma_dering =
      xd->plane[1].subsampling_x == xd->plane[1].subsampling_y &&
      xd->plane[2].subsampling_x == xd->plane[2].subsampling_y;
196
197
  nvsb = (cm->mi_rows + MAX_MIB_SIZE - 1) / MAX_MIB_SIZE;
  nhsb = (cm->mi_cols + MAX_MIB_SIZE - 1) / MAX_MIB_SIZE;
Yaowu Xu's avatar
Yaowu Xu committed
198
  av1_setup_dst_planes(xd->plane, frame, 0, 0);
199
  row_dering = aom_malloc(sizeof(*row_dering) * (nhsb + 2) * 2);
200
201
202
  memset(row_dering, 1, sizeof(*row_dering) * (nhsb + 2) * 2);
  prev_row_dering = row_dering + 1;
  curr_row_dering = prev_row_dering + nhsb + 2;
203
  for (pli = 0; pli < nplanes; pli++) {
204
    dec[pli] = xd->plane[pli].subsampling_x;
Jingning Han's avatar
Jingning Han committed
205
206
    mi_wide_l2[pli] = MI_SIZE_LOG2 - xd->plane[pli].subsampling_x;
    mi_high_l2[pli] = MI_SIZE_LOG2 - xd->plane[pli].subsampling_y;
Yaowu Xu's avatar
Yaowu Xu committed
207
  }
Jingning Han's avatar
Jingning Han committed
208
  stride = (cm->mi_cols << MI_SIZE_LOG2) + 2 * OD_FILT_HBORDER;
209
  for (pli = 0; pli < nplanes; pli++) {
210
    linebuf[pli] = aom_malloc(sizeof(*linebuf) * OD_FILT_VBORDER * stride);
211
212
213
  }
  for (sbr = 0; sbr < nvsb; sbr++) {
    for (pli = 0; pli < nplanes; pli++) {
Jingning Han's avatar
Jingning Han committed
214
215
      const int block_height =
          (MAX_MIB_SIZE << mi_high_l2[pli]) + 2 * OD_FILT_VBORDER;
Michael Bebenita's avatar
Michael Bebenita committed
216
217
      fill_rect(colbuf[pli], OD_FILT_HBORDER, block_height, OD_FILT_HBORDER,
                OD_DERING_VERY_LARGE);
Yaowu Xu's avatar
Yaowu Xu committed
218
    }
219
    dering_left = 1;
Yaowu Xu's avatar
Yaowu Xu committed
220
    for (sbc = 0; sbc < nhsb; sbc++) {
221
      int level, clpf_strength;
222
      int uv_level, uv_clpf_strength;
Yaowu Xu's avatar
Yaowu Xu committed
223
      int nhb, nvb;
224
      int cstart = 0;
225
226
227
228
229
      if (cm->mi_grid_visible[MAX_MIB_SIZE * sbr * cm->mi_stride +
                              MAX_MIB_SIZE * sbc] == NULL) {
        dering_left = 0;
        continue;
      }
230
      if (!dering_left) cstart = -OD_FILT_HBORDER;
Yaowu Xu's avatar
Yaowu Xu committed
231
232
      nhb = AOMMIN(MAX_MIB_SIZE, cm->mi_cols - MAX_MIB_SIZE * sbc);
      nvb = AOMMIN(MAX_MIB_SIZE, cm->mi_rows - MAX_MIB_SIZE * sbr);
Jean-Marc Valin's avatar
Jean-Marc Valin committed
233
234
235
236
237
238
239
240
241
242
243
244
245
      int tile_top, tile_left, tile_bottom, tile_right;
      BOUNDARY_TYPE boundary_tl =
          cm->mi_grid_visible[MAX_MIB_SIZE * sbr * cm->mi_stride +
                              MAX_MIB_SIZE * sbc]
              ->mbmi.boundary_info;
      BOUNDARY_TYPE boundary_br =
          cm->mi_grid_visible[(MAX_MIB_SIZE * sbr + nvb - 1) * cm->mi_stride +
                              MAX_MIB_SIZE * sbc + nhb - 1]
              ->mbmi.boundary_info;
      tile_top = boundary_tl & TILE_ABOVE_BOUNDARY;
      tile_left = boundary_tl & TILE_LEFT_BOUNDARY;
      tile_bottom = boundary_br & TILE_BOTTOM_BOUNDARY;
      tile_right = boundary_br & TILE_RIGHT_BOUNDARY;
246
247
248
249
250
251
      const int mbmi_cdef_strength =
          cm->mi_grid_visible[MAX_MIB_SIZE * sbr * cm->mi_stride +
                              MAX_MIB_SIZE * sbc]
              ->mbmi.cdef_strength;
      level = cm->cdef_strengths[mbmi_cdef_strength] / CLPF_STRENGTHS;
      clpf_strength = cm->cdef_strengths[mbmi_cdef_strength] % CLPF_STRENGTHS;
252
      clpf_strength += clpf_strength == 3;
253
      uv_level = cm->cdef_uv_strengths[mbmi_cdef_strength] / CLPF_STRENGTHS;
254
      uv_clpf_strength =
255
          cm->cdef_uv_strengths[mbmi_cdef_strength] % CLPF_STRENGTHS;
256
      uv_clpf_strength += uv_clpf_strength == 3;
257
      curr_row_dering[sbc] = 0;
258
259
      if ((level == 0 && clpf_strength == 0 && uv_level == 0 &&
           uv_clpf_strength == 0) ||
260
261
          (dering_count = sb_compute_dering_list(
               cm, sbr * MAX_MIB_SIZE, sbc * MAX_MIB_SIZE, dlist)) == 0) {
262
        dering_left = 0;
263
        continue;
264
      }
265

266
      curr_row_dering[sbc] = 1;
267
      for (pli = 0; pli < nplanes; pli++) {
268
        uint16_t dst[OD_BSIZE_MAX * OD_BSIZE_MAX];
269
270
        int coffset;
        int rend, cend;
271
        int clpf_damping = 3 - (pli != AOM_PLANE_Y) + (cm->base_qindex >> 6);
272
273
        int hsize = nhb << mi_wide_l2[pli];
        int vsize = nvb << mi_high_l2[pli];
274
275

        if (pli) {
276
277
278
279
280
          if (chroma_dering)
            level = uv_level;
          else
            level = 0;
          clpf_strength = uv_clpf_strength;
281
        }
Jingning Han's avatar
Jingning Han committed
282

283
        if (sbc == nhsb - 1)
284
          cend = hsize;
285
        else
286
          cend = hsize + OD_FILT_HBORDER;
Jingning Han's avatar
Jingning Han committed
287

288
        if (sbr == nvsb - 1)
289
          rend = vsize;
290
        else
291
          rend = vsize + OD_FILT_VBORDER;
Jingning Han's avatar
Jingning Han committed
292
293

        coffset = sbc * MAX_MIB_SIZE << mi_wide_l2[pli];
294
295
296
        if (sbc == nhsb - 1) {
          /* On the last superblock column, fill in the right border with
             OD_DERING_VERY_LARGE to avoid filtering with the outside. */
Michael Bebenita's avatar
Michael Bebenita committed
297
298
299
          fill_rect(&src[cend + OD_FILT_HBORDER], OD_FILT_BSTRIDE,
                    rend + OD_FILT_VBORDER, hsize + OD_FILT_HBORDER - cend,
                    OD_DERING_VERY_LARGE);
300
301
302
303
        }
        if (sbr == nvsb - 1) {
          /* On the last superblock row, fill in the bottom border with
             OD_DERING_VERY_LARGE to avoid filtering with the outside. */
Michael Bebenita's avatar
Michael Bebenita committed
304
305
306
          fill_rect(&src[(rend + OD_FILT_VBORDER) * OD_FILT_BSTRIDE],
                    OD_FILT_BSTRIDE, OD_FILT_VBORDER,
                    hsize + 2 * OD_FILT_HBORDER, OD_DERING_VERY_LARGE);
307
        }
308
309
        /* Copy in the pixels we need from the current superblock for
           deringing.*/
310
311
312
313
        copy_sb8_16(
            cm,
            &src[OD_FILT_VBORDER * OD_FILT_BSTRIDE + OD_FILT_HBORDER + cstart],
            OD_FILT_BSTRIDE, xd->plane[pli].dst.buf,
Jingning Han's avatar
Jingning Han committed
314
            (MAX_MIB_SIZE << mi_wide_l2[pli]) * sbr, coffset + cstart,
315
            xd->plane[pli].dst.stride, rend, cend - cstart);
316
317
        if (!prev_row_dering[sbc]) {
          copy_sb8_16(cm, &src[OD_FILT_HBORDER], OD_FILT_BSTRIDE,
318
                      xd->plane[pli].dst.buf,
Jingning Han's avatar
Jingning Han committed
319
                      (MAX_MIB_SIZE << mi_wide_l2[pli]) * sbr - OD_FILT_VBORDER,
320
                      coffset, xd->plane[pli].dst.stride, OD_FILT_VBORDER,
321
                      hsize);
322
        } else if (sbr > 0) {
Michael Bebenita's avatar
Michael Bebenita committed
323
324
          copy_rect(&src[OD_FILT_HBORDER], OD_FILT_BSTRIDE,
                    &linebuf[pli][coffset], stride, OD_FILT_VBORDER, hsize);
325
        } else {
Michael Bebenita's avatar
Michael Bebenita committed
326
327
          fill_rect(&src[OD_FILT_HBORDER], OD_FILT_BSTRIDE, OD_FILT_VBORDER,
                    hsize, OD_DERING_VERY_LARGE);
328
329
        }
        if (!prev_row_dering[sbc - 1]) {
330
          copy_sb8_16(cm, src, OD_FILT_BSTRIDE, xd->plane[pli].dst.buf,
Jingning Han's avatar
Jingning Han committed
331
                      (MAX_MIB_SIZE << mi_wide_l2[pli]) * sbr - OD_FILT_VBORDER,
332
333
                      coffset - OD_FILT_HBORDER, xd->plane[pli].dst.stride,
                      OD_FILT_VBORDER, OD_FILT_HBORDER);
334
        } else if (sbr > 0 && sbc > 0) {
Michael Bebenita's avatar
Michael Bebenita committed
335
336
337
          copy_rect(src, OD_FILT_BSTRIDE,
                    &linebuf[pli][coffset - OD_FILT_HBORDER], stride,
                    OD_FILT_VBORDER, OD_FILT_HBORDER);
338
        } else {
Michael Bebenita's avatar
Michael Bebenita committed
339
340
          fill_rect(src, OD_FILT_BSTRIDE, OD_FILT_VBORDER, OD_FILT_HBORDER,
                    OD_DERING_VERY_LARGE);
341
342
        }
        if (!prev_row_dering[sbc + 1]) {
Jingning Han's avatar
Jingning Han committed
343
          copy_sb8_16(cm, &src[OD_FILT_HBORDER + (nhb << mi_high_l2[pli])],
344
                      OD_FILT_BSTRIDE, xd->plane[pli].dst.buf,
Jingning Han's avatar
Jingning Han committed
345
                      (MAX_MIB_SIZE << mi_wide_l2[pli]) * sbr - OD_FILT_VBORDER,
346
347
                      coffset + hsize, xd->plane[pli].dst.stride,
                      OD_FILT_VBORDER, OD_FILT_HBORDER);
348
        } else if (sbr > 0 && sbc < nhsb - 1) {
Michael Bebenita's avatar
Michael Bebenita committed
349
350
351
          copy_rect(&src[hsize + OD_FILT_HBORDER], OD_FILT_BSTRIDE,
                    &linebuf[pli][coffset + hsize], stride, OD_FILT_VBORDER,
                    OD_FILT_HBORDER);
352
        } else {
Michael Bebenita's avatar
Michael Bebenita committed
353
354
          fill_rect(&src[hsize + OD_FILT_HBORDER], OD_FILT_BSTRIDE,
                    OD_FILT_VBORDER, OD_FILT_HBORDER, OD_DERING_VERY_LARGE);
355
        }
356
        if (dering_left) {
357
358
          /* If we deringed the superblock on the left then we need to copy in
             saved pixels. */
Michael Bebenita's avatar
Michael Bebenita committed
359
360
          copy_rect(src, OD_FILT_BSTRIDE, colbuf[pli], OD_FILT_HBORDER,
                    rend + OD_FILT_VBORDER, OD_FILT_HBORDER);
361
        }
Michael Bebenita's avatar
Michael Bebenita committed
362
363
364
365
        /* Saving pixels in case we need to dering the superblock on the
            right. */
        copy_rect(colbuf[pli], OD_FILT_HBORDER, src + hsize, OD_FILT_BSTRIDE,
                  rend + OD_FILT_VBORDER, OD_FILT_HBORDER);
Jingning Han's avatar
Jingning Han committed
366
367
368
        copy_sb8_16(
            cm, &linebuf[pli][coffset], stride, xd->plane[pli].dst.buf,
            (MAX_MIB_SIZE << mi_wide_l2[pli]) * (sbr + 1) - OD_FILT_VBORDER,
369
            coffset, xd->plane[pli].dst.stride, OD_FILT_VBORDER, hsize);
370

371
        if (level == 0 && clpf_strength == 0) continue;
Jean-Marc Valin's avatar
Jean-Marc Valin committed
372
        if (tile_top) {
Michael Bebenita's avatar
Michael Bebenita committed
373
374
          fill_rect(src, OD_FILT_BSTRIDE, OD_FILT_VBORDER,
                    hsize + 2 * OD_FILT_HBORDER, OD_DERING_VERY_LARGE);
Jean-Marc Valin's avatar
Jean-Marc Valin committed
375
376
        }
        if (tile_left) {
Michael Bebenita's avatar
Michael Bebenita committed
377
378
          fill_rect(src, OD_FILT_BSTRIDE, vsize + 2 * OD_FILT_VBORDER,
                    OD_FILT_HBORDER, OD_DERING_VERY_LARGE);
Jean-Marc Valin's avatar
Jean-Marc Valin committed
379
380
        }
        if (tile_bottom) {
Michael Bebenita's avatar
Michael Bebenita committed
381
382
383
          fill_rect(&src[(vsize + OD_FILT_VBORDER) * OD_FILT_BSTRIDE],
                    OD_FILT_BSTRIDE, OD_FILT_VBORDER,
                    hsize + 2 * OD_FILT_HBORDER, OD_DERING_VERY_LARGE);
Jean-Marc Valin's avatar
Jean-Marc Valin committed
384
385
        }
        if (tile_right) {
Michael Bebenita's avatar
Michael Bebenita committed
386
387
388
          fill_rect(&src[hsize + OD_FILT_HBORDER], OD_FILT_BSTRIDE,
                    vsize + 2 * OD_FILT_VBORDER, OD_FILT_HBORDER,
                    OD_DERING_VERY_LARGE);
Jean-Marc Valin's avatar
Jean-Marc Valin committed
389
        }
Yaowu Xu's avatar
Yaowu Xu committed
390
#if CONFIG_AOM_HIGHBITDEPTH
391
        if (cm->use_highbitdepth) {
392
          od_dering(
Jingning Han's avatar
Jingning Han committed
393
394
395
396
397
              (uint8_t *)&CONVERT_TO_SHORTPTR(
                  xd->plane[pli]
                      .dst.buf)[xd->plane[pli].dst.stride *
                                    (MAX_MIB_SIZE * sbr << mi_wide_l2[pli]) +
                                (sbc * MAX_MIB_SIZE << mi_wide_l2[pli])],
398
399
              xd->plane[pli].dst.stride, dst,
              &src[OD_FILT_VBORDER * OD_FILT_BSTRIDE + OD_FILT_HBORDER],
400
              dec[pli], dir, NULL, var, pli, dlist, dering_count, level,
Jingning Han's avatar
Jingning Han committed
401
402
403
404
405
406
407
408
409
410
411
              clpf_strength, clpf_damping, coeff_shift, 0, 1);
        } else {
#endif
          od_dering(&xd->plane[pli]
                         .dst.buf[xd->plane[pli].dst.stride *
                                      (MAX_MIB_SIZE * sbr << mi_wide_l2[pli]) +
                                  (sbc * MAX_MIB_SIZE << mi_wide_l2[pli])],
                    xd->plane[pli].dst.stride, dst,
                    &src[OD_FILT_VBORDER * OD_FILT_BSTRIDE + OD_FILT_HBORDER],
                    dec[pli], dir, NULL, var, pli, dlist, dering_count, level,
                    clpf_strength, clpf_damping, coeff_shift, 0, 0);
412

Yaowu Xu's avatar
Yaowu Xu committed
413
#if CONFIG_AOM_HIGHBITDEPTH
Yaowu Xu's avatar
Yaowu Xu committed
414
        }
415
#endif
Yaowu Xu's avatar
Yaowu Xu committed
416
      }
417
      dering_left = 1;
Yaowu Xu's avatar
Yaowu Xu committed
418
    }
419
420
421
422
423
424
    {
      unsigned char *tmp;
      tmp = prev_row_dering;
      prev_row_dering = curr_row_dering;
      curr_row_dering = tmp;
    }
Yaowu Xu's avatar
Yaowu Xu committed
425
  }
426
  aom_free(row_dering);
427
  for (pli = 0; pli < nplanes; pli++) {
428
    aom_free(linebuf[pli]);
Yaowu Xu's avatar
Yaowu Xu committed
429
430
  }
}