Coverage Report

Created: 2025-07-23 08:18

/src/aom/av1/common/cdef.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3
 *
4
 * This source code is subject to the terms of the BSD 2 Clause License and
5
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6
 * was not distributed with this source code in the LICENSE file, you can
7
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8
 * Media Patent License 1.0 was not distributed with this source code in the
9
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10
 */
11
12
#include <assert.h>
13
#include <math.h>
14
#include <string.h>
15
16
#include "config/aom_scale_rtcd.h"
17
18
#include "aom/aom_integer.h"
19
#include "av1/common/av1_common_int.h"
20
#include "av1/common/cdef.h"
21
#include "av1/common/cdef_block.h"
22
#include "av1/common/reconinter.h"
23
24
static int is_8x8_block_skip(MB_MODE_INFO **grid, int mi_row, int mi_col,
25
3.11M
                             int mi_stride) {
26
3.11M
  MB_MODE_INFO **mbmi = grid + mi_row * mi_stride + mi_col;
27
6.73M
  for (int r = 0; r < mi_size_high[BLOCK_8X8]; ++r, mbmi += mi_stride) {
28
12.1M
    for (int c = 0; c < mi_size_wide[BLOCK_8X8]; ++c) {
29
8.54M
      if (!mbmi[c]->skip_txfm) return 0;
30
8.54M
    }
31
4.92M
  }
32
33
1.80M
  return 1;
34
3.11M
}
35
36
int av1_cdef_compute_sb_list(const CommonModeInfoParams *const mi_params,
37
                             int mi_row, int mi_col, cdef_list *dlist,
38
57.7k
                             BLOCK_SIZE bs) {
39
57.7k
  MB_MODE_INFO **grid = mi_params->mi_grid_base;
40
57.7k
  int maxc = mi_params->mi_cols - mi_col;
41
57.7k
  int maxr = mi_params->mi_rows - mi_row;
42
43
57.7k
  if (bs == BLOCK_128X128 || bs == BLOCK_128X64)
44
0
    maxc = AOMMIN(maxc, MI_SIZE_128X128);
45
57.7k
  else
46
57.7k
    maxc = AOMMIN(maxc, MI_SIZE_64X64);
47
57.7k
  if (bs == BLOCK_128X128 || bs == BLOCK_64X128)
48
0
    maxr = AOMMIN(maxr, MI_SIZE_128X128);
49
57.7k
  else
50
57.7k
    maxr = AOMMIN(maxr, MI_SIZE_64X64);
51
52
57.7k
  const int r_step = 2;  // mi_size_high[BLOCK_8X8]
53
57.7k
  const int c_step = 2;  // mi_size_wide[BLOCK_8X8]
54
57.7k
  const int r_shift = 1;
55
57.7k
  const int c_shift = 1;
56
57.7k
  int count = 0;
57
492k
  for (int r = 0; r < maxr; r += r_step) {
58
3.55M
    for (int c = 0; c < maxc; c += c_step) {
59
3.11M
      if (!is_8x8_block_skip(grid, mi_row + r, mi_col + c,
60
3.11M
                             mi_params->mi_stride)) {
61
1.31M
        dlist[count].by = r >> r_shift;
62
1.31M
        dlist[count].bx = c >> c_shift;
63
1.31M
        count++;
64
1.31M
      }
65
3.11M
    }
66
434k
  }
67
57.7k
  return count;
68
57.7k
}
69
70
void cdef_copy_rect8_8bit_to_16bit_c(uint16_t *dst, int dstride,
71
                                     const uint8_t *src, int sstride, int v,
72
36.9k
                                     int h) {
73
853k
  for (int i = 0; i < v; i++) {
74
64.5M
    for (int j = 0; j < h; j++) {
75
63.7M
      dst[i * dstride + j] = src[i * sstride + j];
76
63.7M
    }
77
816k
  }
78
36.9k
}
79
80
void cdef_copy_rect8_16bit_to_16bit_c(uint16_t *dst, int dstride,
81
                                      const uint16_t *src, int sstride, int v,
82
25.2k
                                      int h) {
83
742k
  for (int i = 0; i < v; i++) {
84
50.6M
    for (int j = 0; j < h; j++) {
85
49.9M
      dst[i * dstride + j] = src[i * sstride + j];
86
49.9M
    }
87
717k
  }
88
25.2k
}
89
90
void av1_cdef_copy_sb8_16(const AV1_COMMON *const cm, uint16_t *const dst,
91
                          int dstride, const uint8_t *src, int src_voffset,
92
62.2k
                          int src_hoffset, int sstride, int vsize, int hsize) {
93
62.2k
  if (cm->seq_params->use_highbitdepth) {
94
25.2k
    const uint16_t *base =
95
25.2k
        &CONVERT_TO_SHORTPTR(src)[src_voffset * sstride + src_hoffset];
96
25.2k
    cdef_copy_rect8_16bit_to_16bit(dst, dstride, base, sstride, vsize, hsize);
97
36.9k
  } else {
98
36.9k
    const uint8_t *base = &src[src_voffset * sstride + src_hoffset];
99
36.9k
    cdef_copy_rect8_8bit_to_16bit(dst, dstride, base, sstride, vsize, hsize);
100
36.9k
  }
101
62.2k
}
102
103
static INLINE void fill_rect(uint16_t *dst, int dstride, int v, int h,
104
84.3k
                             uint16_t x) {
105
980k
  for (int i = 0; i < v; i++) {
106
9.60M
    for (int j = 0; j < h; j++) {
107
8.71M
      dst[i * dstride + j] = x;
108
8.71M
    }
109
896k
  }
110
84.3k
}
111
112
static INLINE void copy_rect(uint16_t *dst, int dstride, const uint16_t *src,
113
152k
                             int sstride, int v, int h) {
114
3.32M
  for (int i = 0; i < v; i++) {
115
31.9M
    for (int j = 0; j < h; j++) {
116
28.7M
      dst[i * dstride + j] = src[i * sstride + j];
117
28.7M
    }
118
3.17M
  }
119
152k
}
120
121
// Prepares intermediate input buffer for CDEF.
122
// Inputs:
123
//   cm: Pointer to common structure.
124
//   fb_info: Pointer to the CDEF block-level parameter structure.
125
//   colbuf: Left column buffer for CDEF.
126
//   cdef_left: Left block is filtered or not.
127
//   fbc, fbr: col and row index of a block.
128
//   plane: plane index Y/CB/CR.
129
// Returns:
130
//   Nothing will be returned.
131
static void cdef_prepare_fb(const AV1_COMMON *const cm, CdefBlockInfo *fb_info,
132
                            uint16_t **const colbuf, const int *cdef_left,
133
28.1k
                            int fbc, int fbr, int plane) {
134
28.1k
  const CommonModeInfoParams *const mi_params = &cm->mi_params;
135
28.1k
  uint16_t *src = fb_info->src;
136
28.1k
  const int luma_stride =
137
28.1k
      ALIGN_POWER_OF_TWO(mi_params->mi_cols << MI_SIZE_LOG2, 4);
138
28.1k
  const int nvfb = (mi_params->mi_rows + MI_SIZE_64X64 - 1) / MI_SIZE_64X64;
139
28.1k
  const int nhfb = (mi_params->mi_cols + MI_SIZE_64X64 - 1) / MI_SIZE_64X64;
140
28.1k
  int cstart = 0;
141
28.1k
  if (!*cdef_left) cstart = -CDEF_HBORDER;
142
28.1k
  int rend, cend;
143
28.1k
  const int nhb =
144
28.1k
      AOMMIN(MI_SIZE_64X64, mi_params->mi_cols - MI_SIZE_64X64 * fbc);
145
28.1k
  const int nvb =
146
28.1k
      AOMMIN(MI_SIZE_64X64, mi_params->mi_rows - MI_SIZE_64X64 * fbr);
147
28.1k
  const int hsize = nhb << fb_info->mi_wide_l2;
148
28.1k
  const int vsize = nvb << fb_info->mi_high_l2;
149
28.1k
  const uint16_t *top_linebuf = fb_info->top_linebuf[plane];
150
28.1k
  const uint16_t *bot_linebuf = fb_info->bot_linebuf[plane];
151
28.1k
  const int bot_offset = (vsize + CDEF_VBORDER) * CDEF_BSTRIDE;
152
28.1k
  const int stride =
153
28.1k
      luma_stride >> (plane == AOM_PLANE_Y ? 0 : cm->seq_params->subsampling_x);
154
155
28.1k
  if (fbc == nhfb - 1)
156
6.09k
    cend = hsize;
157
22.0k
  else
158
22.0k
    cend = hsize + CDEF_HBORDER;
159
160
28.1k
  if (fbr == nvfb - 1)
161
8.46k
    rend = vsize;
162
19.7k
  else
163
19.7k
    rend = vsize + CDEF_VBORDER;
164
165
  /* Copy in the pixels we need from the current superblock for
166
  deringing.*/
167
28.1k
  av1_cdef_copy_sb8_16(
168
28.1k
      cm, &src[CDEF_VBORDER * CDEF_BSTRIDE + CDEF_HBORDER + cstart],
169
28.1k
      CDEF_BSTRIDE, fb_info->dst, fb_info->roffset, fb_info->coffset + cstart,
170
28.1k
      fb_info->dst_stride, vsize, cend - cstart);
171
172
  /* Copy in the pixels we need for the current superblock from bottom buffer.*/
173
28.1k
  if (fbr < nvfb - 1) {
174
19.7k
    copy_rect(&src[bot_offset + CDEF_HBORDER], CDEF_BSTRIDE,
175
19.7k
              &bot_linebuf[fb_info->coffset], stride, CDEF_VBORDER, hsize);
176
19.7k
  } else {
177
8.46k
    fill_rect(&src[bot_offset + CDEF_HBORDER], CDEF_BSTRIDE, CDEF_VBORDER,
178
8.46k
              hsize, CDEF_VERY_LARGE);
179
8.46k
  }
180
28.1k
  if (fbr < nvfb - 1 && fbc > 0) {
181
14.6k
    copy_rect(&src[bot_offset], CDEF_BSTRIDE,
182
14.6k
              &bot_linebuf[fb_info->coffset - CDEF_HBORDER], stride,
183
14.6k
              CDEF_VBORDER, CDEF_HBORDER);
184
14.6k
  } else {
185
13.5k
    fill_rect(&src[bot_offset], CDEF_BSTRIDE, CDEF_VBORDER, CDEF_HBORDER,
186
13.5k
              CDEF_VERY_LARGE);
187
13.5k
  }
188
28.1k
  if (fbr < nvfb - 1 && fbc < nhfb - 1) {
189
16.2k
    copy_rect(&src[bot_offset + hsize + CDEF_HBORDER], CDEF_BSTRIDE,
190
16.2k
              &bot_linebuf[fb_info->coffset + hsize], stride, CDEF_VBORDER,
191
16.2k
              CDEF_HBORDER);
192
16.2k
  } else {
193
11.9k
    fill_rect(&src[bot_offset + hsize + CDEF_HBORDER], CDEF_BSTRIDE,
194
11.9k
              CDEF_VBORDER, CDEF_HBORDER, CDEF_VERY_LARGE);
195
11.9k
  }
196
197
  /* Copy in the pixels we need from the current superblock from top buffer.*/
198
28.1k
  if (fbr > 0) {
199
18.9k
    copy_rect(&src[CDEF_HBORDER], CDEF_BSTRIDE, &top_linebuf[fb_info->coffset],
200
18.9k
              stride, CDEF_VBORDER, hsize);
201
18.9k
  } else {
202
9.22k
    fill_rect(&src[CDEF_HBORDER], CDEF_BSTRIDE, CDEF_VBORDER, hsize,
203
9.22k
              CDEF_VERY_LARGE);
204
9.22k
  }
205
28.1k
  if (fbr > 0 && fbc > 0) {
206
13.9k
    copy_rect(src, CDEF_BSTRIDE, &top_linebuf[fb_info->coffset - CDEF_HBORDER],
207
13.9k
              stride, CDEF_VBORDER, CDEF_HBORDER);
208
14.2k
  } else {
209
14.2k
    fill_rect(src, CDEF_BSTRIDE, CDEF_VBORDER, CDEF_HBORDER, CDEF_VERY_LARGE);
210
14.2k
  }
211
28.1k
  if (fbr > 0 && fbc < nhfb - 1) {
212
15.4k
    copy_rect(&src[hsize + CDEF_HBORDER], CDEF_BSTRIDE,
213
15.4k
              &top_linebuf[fb_info->coffset + hsize], stride, CDEF_VBORDER,
214
15.4k
              CDEF_HBORDER);
215
15.4k
  } else {
216
12.6k
    fill_rect(&src[hsize + CDEF_HBORDER], CDEF_BSTRIDE, CDEF_VBORDER,
217
12.6k
              CDEF_HBORDER, CDEF_VERY_LARGE);
218
12.6k
  }
219
28.1k
  if (*cdef_left) {
220
    /* If we deringed the superblock on the left then we need to copy in
221
    saved pixels. */
222
25.3k
    copy_rect(src, CDEF_BSTRIDE, colbuf[plane], CDEF_HBORDER,
223
25.3k
              rend + CDEF_VBORDER, CDEF_HBORDER);
224
25.3k
  }
225
  /* Saving pixels in case we need to dering the superblock on the
226
  right. */
227
28.1k
  copy_rect(colbuf[plane], CDEF_HBORDER, src + hsize, CDEF_BSTRIDE,
228
28.1k
            rend + CDEF_VBORDER, CDEF_HBORDER);
229
230
28.1k
  if (fb_info->frame_boundary[LEFT]) {
231
8.26k
    fill_rect(src, CDEF_BSTRIDE, vsize + 2 * CDEF_VBORDER, CDEF_HBORDER,
232
8.26k
              CDEF_VERY_LARGE);
233
8.26k
  }
234
28.1k
  if (fb_info->frame_boundary[RIGHT]) {
235
6.09k
    fill_rect(&src[hsize + CDEF_HBORDER], CDEF_BSTRIDE,
236
6.09k
              vsize + 2 * CDEF_VBORDER, CDEF_HBORDER, CDEF_VERY_LARGE);
237
6.09k
  }
238
28.1k
}
239
240
static INLINE void cdef_filter_fb(CdefBlockInfo *const fb_info, int plane,
241
28.1k
                                  uint8_t use_highbitdepth) {
242
28.1k
  int offset = fb_info->dst_stride * fb_info->roffset + fb_info->coffset;
243
28.1k
  if (use_highbitdepth) {
244
13.7k
    av1_cdef_filter_fb(
245
13.7k
        NULL, CONVERT_TO_SHORTPTR(fb_info->dst + offset), fb_info->dst_stride,
246
13.7k
        &fb_info->src[CDEF_VBORDER * CDEF_BSTRIDE + CDEF_HBORDER],
247
13.7k
        fb_info->xdec, fb_info->ydec, fb_info->dir, NULL, fb_info->var, plane,
248
13.7k
        fb_info->dlist, fb_info->cdef_count, fb_info->level,
249
13.7k
        fb_info->sec_strength, fb_info->damping, fb_info->coeff_shift);
250
14.3k
  } else {
251
14.3k
    av1_cdef_filter_fb(
252
14.3k
        fb_info->dst + offset, NULL, fb_info->dst_stride,
253
14.3k
        &fb_info->src[CDEF_VBORDER * CDEF_BSTRIDE + CDEF_HBORDER],
254
14.3k
        fb_info->xdec, fb_info->ydec, fb_info->dir, NULL, fb_info->var, plane,
255
14.3k
        fb_info->dlist, fb_info->cdef_count, fb_info->level,
256
14.3k
        fb_info->sec_strength, fb_info->damping, fb_info->coeff_shift);
257
14.3k
  }
258
28.1k
}
259
260
// Initializes block-level parameters for CDEF.
261
static INLINE void cdef_init_fb_col(const MACROBLOCKD *const xd,
262
                                    const CdefInfo *const cdef_info,
263
                                    CdefBlockInfo *const fb_info,
264
                                    int mbmi_cdef_strength, int fbc, int fbr,
265
59.2k
                                    int plane) {
266
59.2k
  if (plane == AOM_PLANE_Y) {
267
40.5k
    fb_info->level =
268
40.5k
        cdef_info->cdef_strengths[mbmi_cdef_strength] / CDEF_SEC_STRENGTHS;
269
40.5k
    fb_info->sec_strength =
270
40.5k
        cdef_info->cdef_strengths[mbmi_cdef_strength] % CDEF_SEC_STRENGTHS;
271
40.5k
    fb_info->sec_strength += fb_info->sec_strength == 3;
272
40.5k
    int uv_level =
273
40.5k
        cdef_info->cdef_uv_strengths[mbmi_cdef_strength] / CDEF_SEC_STRENGTHS;
274
40.5k
    int uv_sec_strength =
275
40.5k
        cdef_info->cdef_uv_strengths[mbmi_cdef_strength] % CDEF_SEC_STRENGTHS;
276
40.5k
    uv_sec_strength += uv_sec_strength == 3;
277
40.5k
    fb_info->is_zero_level = (fb_info->level == 0) &&
278
40.5k
                             (fb_info->sec_strength == 0) && (uv_level == 0) &&
279
40.5k
                             (uv_sec_strength == 0);
280
40.5k
  } else {
281
18.6k
    fb_info->level =
282
18.6k
        cdef_info->cdef_uv_strengths[mbmi_cdef_strength] / CDEF_SEC_STRENGTHS;
283
18.6k
    fb_info->sec_strength =
284
18.6k
        cdef_info->cdef_uv_strengths[mbmi_cdef_strength] % CDEF_SEC_STRENGTHS;
285
18.6k
    fb_info->sec_strength += fb_info->sec_strength == 3;
286
18.6k
  }
287
59.2k
  fb_info->dst = xd->plane[plane].dst.buf;
288
59.2k
  fb_info->dst_stride = xd->plane[plane].dst.stride;
289
290
59.2k
  fb_info->xdec = xd->plane[plane].subsampling_x;
291
59.2k
  fb_info->ydec = xd->plane[plane].subsampling_y;
292
59.2k
  fb_info->mi_wide_l2 = MI_SIZE_LOG2 - xd->plane[plane].subsampling_x;
293
59.2k
  fb_info->mi_high_l2 = MI_SIZE_LOG2 - xd->plane[plane].subsampling_y;
294
59.2k
  fb_info->roffset = MI_SIZE_64X64 * fbr << fb_info->mi_high_l2;
295
59.2k
  fb_info->coffset = MI_SIZE_64X64 * fbc << fb_info->mi_wide_l2;
296
59.2k
}
297
298
static void cdef_fb_col(const AV1_COMMON *const cm, const MACROBLOCKD *const xd,
299
                        CdefBlockInfo *const fb_info, uint16_t **const colbuf,
300
40.5k
                        int *cdef_left, int fbc, int fbr) {
301
40.5k
  const CommonModeInfoParams *const mi_params = &cm->mi_params;
302
40.5k
  const int mbmi_cdef_strength =
303
40.5k
      mi_params
304
40.5k
          ->mi_grid_base[MI_SIZE_64X64 * fbr * mi_params->mi_stride +
305
40.5k
                         MI_SIZE_64X64 * fbc]
306
40.5k
          ->cdef_strength;
307
40.5k
  const int num_planes = av1_num_planes(cm);
308
309
40.5k
  if (mi_params->mi_grid_base[MI_SIZE_64X64 * fbr * mi_params->mi_stride +
310
40.5k
                              MI_SIZE_64X64 * fbc] == NULL ||
311
40.5k
      mbmi_cdef_strength == -1) {
312
0
    *cdef_left = 0;
313
0
    return;
314
0
  }
315
68.7k
  for (int plane = 0; plane < num_planes; plane++) {
316
59.2k
    cdef_init_fb_col(xd, &cm->cdef_info, fb_info, mbmi_cdef_strength, fbc, fbr,
317
59.2k
                     plane);
318
59.2k
    if (fb_info->is_zero_level ||
319
59.2k
        (fb_info->cdef_count = av1_cdef_compute_sb_list(
320
57.7k
             mi_params, fbr * MI_SIZE_64X64, fbc * MI_SIZE_64X64,
321
57.7k
             fb_info->dlist, BLOCK_64X64)) == 0) {
322
31.0k
      *cdef_left = 0;
323
31.0k
      return;
324
31.0k
    }
325
28.1k
    cdef_prepare_fb(cm, fb_info, colbuf, cdef_left, fbc, fbr, plane);
326
28.1k
    cdef_filter_fb(fb_info, plane, cm->seq_params->use_highbitdepth);
327
28.1k
  }
328
9.49k
  *cdef_left = 1;
329
9.49k
}
330
331
// Initializes row-level parameters for CDEF frame.
332
void av1_cdef_init_fb_row(const AV1_COMMON *const cm,
333
                          const MACROBLOCKD *const xd,
334
                          CdefBlockInfo *const fb_info,
335
                          uint16_t **const linebuf, uint16_t *const src,
336
7.12k
                          struct AV1CdefSyncData *const cdef_sync, int fbr) {
337
7.12k
  (void)cdef_sync;
338
7.12k
  const int num_planes = av1_num_planes(cm);
339
7.12k
  const int nvfb = (cm->mi_params.mi_rows + MI_SIZE_64X64 - 1) / MI_SIZE_64X64;
340
7.12k
  const int luma_stride =
341
7.12k
      ALIGN_POWER_OF_TWO(cm->mi_params.mi_cols << MI_SIZE_LOG2, 4);
342
7.12k
  const bool ping_pong = fbr & 1;
343
  // for the current filter block, it's top left corner mi structure (mi_tl)
344
  // is first accessed to check whether the top and left boundaries are
345
  // frame boundaries. Then bottom-left and top-right mi structures are
346
  // accessed to check whether the bottom and right boundaries
347
  // (respectively) are frame boundaries.
348
  //
349
  // Note that we can't just check the bottom-right mi structure - eg. if
350
  // we're at the right-hand edge of the frame but not the bottom, then
351
  // the bottom-right mi is NULL but the bottom-left is not.
352
7.12k
  fb_info->frame_boundary[TOP] = (MI_SIZE_64X64 * fbr == 0) ? 1 : 0;
353
7.12k
  if (fbr != nvfb - 1)
354
5.69k
    fb_info->frame_boundary[BOTTOM] =
355
5.69k
        (MI_SIZE_64X64 * (fbr + 1) == cm->mi_params.mi_rows) ? 1 : 0;
356
1.43k
  else
357
1.43k
    fb_info->frame_boundary[BOTTOM] = 1;
358
359
7.12k
  fb_info->src = src;
360
7.12k
  fb_info->damping = cm->cdef_info.cdef_damping;
361
7.12k
  fb_info->coeff_shift = AOMMAX(cm->seq_params->bit_depth - 8, 0);
362
7.12k
  av1_zero(fb_info->dir);
363
7.12k
  av1_zero(fb_info->var);
364
365
28.2k
  for (int plane = 0; plane < num_planes; plane++) {
366
21.0k
    const int mi_high_l2 = MI_SIZE_LOG2 - xd->plane[plane].subsampling_y;
367
21.0k
    const int offset = MI_SIZE_64X64 * (fbr + 1) << mi_high_l2;
368
21.0k
    const int stride = luma_stride >> xd->plane[plane].subsampling_x;
369
    // here ping-pong buffers are maintained for top linebuf
370
    // to avoid linebuf over-write by consecutive row.
371
21.0k
    uint16_t *const top_linebuf =
372
21.0k
        &linebuf[plane][ping_pong * CDEF_VBORDER * stride];
373
21.0k
    fb_info->bot_linebuf[plane] = &linebuf[plane][(CDEF_VBORDER << 1) * stride];
374
375
21.0k
    if (fbr != nvfb - 1)  // top line buffer copy
376
17.0k
      av1_cdef_copy_sb8_16(cm, top_linebuf, stride, xd->plane[plane].dst.buf,
377
17.0k
                           offset - CDEF_VBORDER, 0,
378
17.0k
                           xd->plane[plane].dst.stride, CDEF_VBORDER, stride);
379
21.0k
    fb_info->top_linebuf[plane] =
380
21.0k
        &linebuf[plane][(!ping_pong) * CDEF_VBORDER * stride];
381
382
21.0k
    if (fbr != nvfb - 1)  // bottom line buffer copy
383
17.0k
      av1_cdef_copy_sb8_16(cm, fb_info->bot_linebuf[plane], stride,
384
17.0k
                           xd->plane[plane].dst.buf, offset, 0,
385
17.0k
                           xd->plane[plane].dst.stride, CDEF_VBORDER, stride);
386
21.0k
  }
387
7.12k
}
388
389
void av1_cdef_fb_row(const AV1_COMMON *const cm, MACROBLOCKD *xd,
390
                     uint16_t **const linebuf, uint16_t **const colbuf,
391
                     uint16_t *const src, int fbr,
392
                     cdef_init_fb_row_t cdef_init_fb_row_fn,
393
7.12k
                     struct AV1CdefSyncData *const cdef_sync) {
394
7.12k
  CdefBlockInfo fb_info;
395
7.12k
  int cdef_left = 1;
396
7.12k
  const int nhfb = (cm->mi_params.mi_cols + MI_SIZE_64X64 - 1) / MI_SIZE_64X64;
397
398
7.12k
  cdef_init_fb_row_fn(cm, xd, &fb_info, linebuf, src, cdef_sync, fbr);
399
47.7k
  for (int fbc = 0; fbc < nhfb; fbc++) {
400
40.5k
    fb_info.frame_boundary[LEFT] = (MI_SIZE_64X64 * fbc == 0) ? 1 : 0;
401
40.5k
    if (fbc != nhfb - 1)
402
33.4k
      fb_info.frame_boundary[RIGHT] =
403
33.4k
          (MI_SIZE_64X64 * (fbc + 1) == cm->mi_params.mi_cols) ? 1 : 0;
404
7.12k
    else
405
7.12k
      fb_info.frame_boundary[RIGHT] = 1;
406
40.5k
    cdef_fb_col(cm, xd, &fb_info, colbuf, &cdef_left, fbc, fbr);
407
40.5k
  }
408
7.12k
}
409
410
// Perform CDEF on input frame.
411
// Inputs:
412
//   frame: Pointer to input frame buffer.
413
//   cm: Pointer to common structure.
414
//   xd: Pointer to common current coding block structure.
415
// Returns:
416
//   Nothing will be returned.
417
void av1_cdef_frame(YV12_BUFFER_CONFIG *frame, AV1_COMMON *const cm,
418
1.43k
                    MACROBLOCKD *xd, cdef_init_fb_row_t cdef_init_fb_row_fn) {
419
1.43k
  const int num_planes = av1_num_planes(cm);
420
1.43k
  const int nvfb = (cm->mi_params.mi_rows + MI_SIZE_64X64 - 1) / MI_SIZE_64X64;
421
422
1.43k
  av1_setup_dst_planes(xd->plane, cm->seq_params->sb_size, frame, 0, 0, 0,
423
1.43k
                       num_planes);
424
425
8.55k
  for (int fbr = 0; fbr < nvfb; fbr++)
426
7.12k
    av1_cdef_fb_row(cm, xd, cm->cdef_info.linebuf, cm->cdef_info.colbuf,
427
7.12k
                    cm->cdef_info.srcbuf, fbr, cdef_init_fb_row_fn, NULL);
428
1.43k
}