Coverage Report

Created: 2026-11-12 08:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/aom/av1/common/cfl.c
Line
Count
Source
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 "av1/common/av1_common_int.h"
13
#include "av1/common/cfl.h"
14
#include "av1/common/common_data.h"
15
16
#include "config/av1_rtcd.h"
17
18
337k
void cfl_init(CFL_CTX *cfl, const SequenceHeader *seq_params) {
19
337k
  assert(block_size_wide[CFL_MAX_BLOCK_SIZE] == CFL_BUF_LINE);
20
337k
  assert(block_size_high[CFL_MAX_BLOCK_SIZE] == CFL_BUF_LINE);
21
22
337k
  memset(&cfl->recon_buf_q3, 0, sizeof(cfl->recon_buf_q3));
23
337k
  memset(&cfl->ac_buf_q3, 0, sizeof(cfl->ac_buf_q3));
24
337k
  cfl->subsampling_x = seq_params->subsampling_x;
25
337k
  cfl->subsampling_y = seq_params->subsampling_y;
26
337k
  cfl->are_parameters_computed = 0;
27
337k
  cfl->store_y = 0;
28
  // The DC_PRED cache is disabled by default and is only enabled in
29
  // cfl_rd_pick_alpha
30
337k
  clear_cfl_dc_pred_cache_flags(cfl);
31
337k
}
32
33
void cfl_store_dc_pred(MACROBLOCKD *const xd, const uint8_t *input,
34
0
                       CFL_PRED_TYPE pred_plane, int width) {
35
0
  assert(pred_plane < CFL_PRED_PLANES);
36
0
  assert(width <= CFL_BUF_LINE);
37
38
0
  if (is_cur_buf_hbd(xd)) {
39
0
    uint16_t *const input_16 = CONVERT_TO_SHORTPTR(input);
40
0
    memcpy(xd->cfl.dc_pred_cache[pred_plane], input_16, width << 1);
41
0
    return;
42
0
  }
43
44
0
  memcpy(xd->cfl.dc_pred_cache[pred_plane], input, width);
45
0
}
46
47
static void cfl_load_dc_pred_lbd(const int16_t *dc_pred_cache, uint8_t *dst,
48
0
                                 int dst_stride, int width, int height) {
49
  // Load the cached 1D row into scalar registers once and broadcast across all
50
  // height rows to avoid repeated memory reads per row.
51
0
  switch (width) {
52
0
    case 4: {
53
0
      uint32_t v;
54
0
      memcpy(&v, dc_pred_cache, 4);
55
0
      for (int j = 0; j < height; j++) {
56
0
        memcpy(dst, &v, 4);
57
0
        dst += dst_stride;
58
0
      }
59
0
      return;
60
0
    }
61
0
    case 8: {
62
0
      uint64_t v;
63
0
      memcpy(&v, dc_pred_cache, 8);
64
0
      for (int j = 0; j < height; j++) {
65
0
        memcpy(dst, &v, 8);
66
0
        dst += dst_stride;
67
0
      }
68
0
      return;
69
0
    }
70
0
    case 16: {
71
0
      uint64_t v0, v1;
72
0
      memcpy(&v0, (const uint8_t *)dc_pred_cache, 8);
73
0
      memcpy(&v1, (const uint8_t *)dc_pred_cache + 8, 8);
74
0
      for (int j = 0; j < height; j++) {
75
0
        memcpy(dst, &v0, 8);
76
0
        memcpy(dst + 8, &v1, 8);
77
0
        dst += dst_stride;
78
0
      }
79
0
      return;
80
0
    }
81
0
    case 32: {
82
0
      uint64_t v0, v1, v2, v3;
83
0
      memcpy(&v0, (const uint8_t *)dc_pred_cache, 8);
84
0
      memcpy(&v1, (const uint8_t *)dc_pred_cache + 8, 8);
85
0
      memcpy(&v2, (const uint8_t *)dc_pred_cache + 16, 8);
86
0
      memcpy(&v3, (const uint8_t *)dc_pred_cache + 24, 8);
87
0
      for (int j = 0; j < height; j++) {
88
0
        memcpy(dst, &v0, 8);
89
0
        memcpy(dst + 8, &v1, 8);
90
0
        memcpy(dst + 16, &v2, 8);
91
0
        memcpy(dst + 24, &v3, 8);
92
0
        dst += dst_stride;
93
0
      }
94
0
      return;
95
0
    }
96
0
    default:
97
0
      for (int j = 0; j < height; j++) {
98
0
        memcpy(dst, dc_pred_cache, width);
99
0
        dst += dst_stride;
100
0
      }
101
0
      return;
102
0
  }
103
0
}
104
105
static void cfl_load_dc_pred_hbd(const int16_t *dc_pred_cache, uint16_t *dst,
106
0
                                 int dst_stride, int width, int height) {
107
  // Load the cached 1D row into scalar registers once and broadcast across all
108
  // height rows to avoid repeated memory reads per row.
109
0
  switch (width) {
110
0
    case 4: {
111
0
      uint64_t v;
112
0
      memcpy(&v, dc_pred_cache, 8);
113
0
      for (int j = 0; j < height; j++) {
114
0
        memcpy(dst, &v, 8);
115
0
        dst += dst_stride;
116
0
      }
117
0
      return;
118
0
    }
119
0
    case 8: {
120
0
      uint64_t v0, v1;
121
0
      memcpy(&v0, dc_pred_cache, 8);
122
0
      memcpy(&v1, dc_pred_cache + 4, 8);
123
0
      for (int j = 0; j < height; j++) {
124
0
        memcpy(dst, &v0, 8);
125
0
        memcpy(dst + 4, &v1, 8);
126
0
        dst += dst_stride;
127
0
      }
128
0
      return;
129
0
    }
130
0
    case 16: {
131
0
      uint64_t v0, v1, v2, v3;
132
0
      memcpy(&v0, dc_pred_cache, 8);
133
0
      memcpy(&v1, dc_pred_cache + 4, 8);
134
0
      memcpy(&v2, dc_pred_cache + 8, 8);
135
0
      memcpy(&v3, dc_pred_cache + 12, 8);
136
0
      for (int j = 0; j < height; j++) {
137
0
        memcpy(dst, &v0, 8);
138
0
        memcpy(dst + 4, &v1, 8);
139
0
        memcpy(dst + 8, &v2, 8);
140
0
        memcpy(dst + 12, &v3, 8);
141
0
        dst += dst_stride;
142
0
      }
143
0
      return;
144
0
    }
145
0
    default: {
146
0
      const size_t num_bytes = width << 1;
147
0
      for (int j = 0; j < height; j++) {
148
0
        memcpy(dst, dc_pred_cache, num_bytes);
149
0
        dst += dst_stride;
150
0
      }
151
0
      return;
152
0
    }
153
0
  }
154
0
}
155
void cfl_load_dc_pred(MACROBLOCKD *const xd, uint8_t *dst, int dst_stride,
156
0
                      TX_SIZE tx_size, CFL_PRED_TYPE pred_plane) {
157
0
  const int width = tx_size_wide[tx_size];
158
0
  const int height = tx_size_high[tx_size];
159
0
  assert(pred_plane < CFL_PRED_PLANES);
160
0
  assert(width <= CFL_BUF_LINE);
161
0
  assert(height <= CFL_BUF_LINE);
162
0
  if (is_cur_buf_hbd(xd)) {
163
0
    uint16_t *dst_16 = CONVERT_TO_SHORTPTR(dst);
164
0
    cfl_load_dc_pred_hbd(xd->cfl.dc_pred_cache[pred_plane], dst_16, dst_stride,
165
0
                         width, height);
166
0
    return;
167
0
  }
168
0
  cfl_load_dc_pred_lbd(xd->cfl.dc_pred_cache[pred_plane], dst, dst_stride,
169
0
                       width, height);
170
0
}
171
172
// Due to frame boundary issues, it is possible that the total area covered by
173
// chroma exceeds that of luma. When this happens, we fill the missing pixels by
174
// repeating the last columns and/or rows.
175
1.52M
static inline void cfl_pad(CFL_CTX *cfl, int width, int height) {
176
1.52M
  const int diff_width = width - cfl->buf_width;
177
1.52M
  const int diff_height = height - cfl->buf_height;
178
179
1.52M
  if (diff_width > 0) {
180
423
    const int min_height = height - diff_height;
181
423
    uint16_t *recon_buf_q3 = cfl->recon_buf_q3 + (width - diff_width);
182
7.59k
    for (int j = 0; j < min_height; j++) {
183
7.17k
      const uint16_t last_pixel = recon_buf_q3[-1];
184
7.17k
      assert(recon_buf_q3 + diff_width <= cfl->recon_buf_q3 + CFL_BUF_SQUARE);
185
52.6k
      for (int i = 0; i < diff_width; i++) {
186
45.4k
        recon_buf_q3[i] = last_pixel;
187
45.4k
      }
188
7.17k
      recon_buf_q3 += CFL_BUF_LINE;
189
7.17k
    }
190
423
    cfl->buf_width = width;
191
423
  }
192
1.52M
  if (diff_height > 0) {
193
1.38k
    uint16_t *recon_buf_q3 =
194
1.38k
        cfl->recon_buf_q3 + ((height - diff_height) * CFL_BUF_LINE);
195
9.91k
    for (int j = 0; j < diff_height; j++) {
196
8.53k
      const uint16_t *last_row_q3 = recon_buf_q3 - CFL_BUF_LINE;
197
8.53k
      assert(recon_buf_q3 + width <= cfl->recon_buf_q3 + CFL_BUF_SQUARE);
198
84.8k
      for (int i = 0; i < width; i++) {
199
76.3k
        recon_buf_q3[i] = last_row_q3[i];
200
76.3k
      }
201
8.53k
      recon_buf_q3 += CFL_BUF_LINE;
202
8.53k
    }
203
1.38k
    cfl->buf_height = height;
204
1.38k
  }
205
1.52M
}
206
207
static void subtract_average_c(const uint16_t *src, int16_t *dst, int width,
208
0
                               int height, int round_offset, int num_pel_log2) {
209
0
  int sum = round_offset;
210
0
  const uint16_t *recon = src;
211
0
  for (int j = 0; j < height; j++) {
212
0
    for (int i = 0; i < width; i++) {
213
0
      sum += recon[i];
214
0
    }
215
0
    recon += CFL_BUF_LINE;
216
0
  }
217
0
  const int avg = sum >> num_pel_log2;
218
0
  for (int j = 0; j < height; j++) {
219
0
    for (int i = 0; i < width; i++) {
220
0
      dst[i] = src[i] - avg;
221
0
    }
222
0
    src += CFL_BUF_LINE;
223
0
    dst += CFL_BUF_LINE;
224
0
  }
225
0
}
226
227
0
CFL_SUB_AVG_FN(c)
228
229
static inline int cfl_idx_to_alpha(uint8_t alpha_idx, int8_t joint_sign,
230
3.05M
                                   CFL_PRED_TYPE pred_type) {
231
3.05M
  const int alpha_sign = (pred_type == CFL_PRED_U) ? CFL_SIGN_U(joint_sign)
232
3.05M
                                                   : CFL_SIGN_V(joint_sign);
233
3.05M
  if (alpha_sign == CFL_SIGN_ZERO) return 0;
234
2.48M
  const int abs_alpha_q3 =
235
2.48M
      (pred_type == CFL_PRED_U) ? CFL_IDX_U(alpha_idx) : CFL_IDX_V(alpha_idx);
236
2.48M
  return (alpha_sign == CFL_SIGN_POS) ? abs_alpha_q3 + 1 : -abs_alpha_q3 - 1;
237
3.05M
}
238
239
static inline void cfl_predict_lbd_c(const int16_t *ac_buf_q3, uint8_t *dst,
240
                                     int dst_stride, int alpha_q3, int width,
241
0
                                     int height) {
242
0
  for (int j = 0; j < height; j++) {
243
0
    for (int i = 0; i < width; i++) {
244
0
      dst[i] = clip_pixel(get_scaled_luma_q0(alpha_q3, ac_buf_q3[i]) + dst[i]);
245
0
    }
246
0
    dst += dst_stride;
247
0
    ac_buf_q3 += CFL_BUF_LINE;
248
0
  }
249
0
}
250
251
0
CFL_PREDICT_FN(c, lbd)
252
253
#if CONFIG_AV1_HIGHBITDEPTH
254
static inline void cfl_predict_hbd_c(const int16_t *ac_buf_q3, uint16_t *dst,
255
                                     int dst_stride, int alpha_q3,
256
0
                                     int bit_depth, int width, int height) {
257
0
  for (int j = 0; j < height; j++) {
258
0
    for (int i = 0; i < width; i++) {
259
0
      dst[i] = clip_pixel_highbd(
260
0
          get_scaled_luma_q0(alpha_q3, ac_buf_q3[i]) + dst[i], bit_depth);
261
0
    }
262
0
    dst += dst_stride;
263
0
    ac_buf_q3 += CFL_BUF_LINE;
264
0
  }
265
0
}
266
267
0
CFL_PREDICT_FN(c, hbd)
268
#endif
269
270
1.52M
static void cfl_compute_parameters(MACROBLOCKD *const xd, TX_SIZE tx_size) {
271
1.52M
  CFL_CTX *const cfl = &xd->cfl;
272
  // Do not call cfl_compute_parameters multiple time on the same values.
273
1.52M
  assert(cfl->are_parameters_computed == 0);
274
275
1.52M
  cfl_pad(cfl, tx_size_wide[tx_size], tx_size_high[tx_size]);
276
1.52M
  cfl_get_subtract_average_fn(tx_size)(cfl->recon_buf_q3, cfl->ac_buf_q3);
277
1.52M
  cfl->are_parameters_computed = 1;
278
1.52M
}
279
280
void av1_cfl_predict_block(MACROBLOCKD *const xd, uint8_t *dst, int dst_stride,
281
3.05M
                           TX_SIZE tx_size, int plane) {
282
3.05M
  CFL_CTX *const cfl = &xd->cfl;
283
3.05M
  MB_MODE_INFO *mbmi = xd->mi[0];
284
3.05M
  assert(is_cfl_allowed(xd));
285
286
3.05M
  if (!cfl->are_parameters_computed) cfl_compute_parameters(xd, tx_size);
287
288
3.05M
  const int alpha_q3 =
289
3.05M
      cfl_idx_to_alpha(mbmi->cfl_alpha_idx, mbmi->cfl_alpha_signs, plane - 1);
290
3.05M
  assert((tx_size_high[tx_size] - 1) * CFL_BUF_LINE + tx_size_wide[tx_size] <=
291
3.05M
         CFL_BUF_SQUARE);
292
3.05M
#if CONFIG_AV1_HIGHBITDEPTH
293
3.05M
  if (is_cur_buf_hbd(xd)) {
294
1.66M
    uint16_t *dst_16 = CONVERT_TO_SHORTPTR(dst);
295
1.66M
    cfl_get_predict_hbd_fn(tx_size)(cfl->ac_buf_q3, dst_16, dst_stride,
296
1.66M
                                    alpha_q3, xd->bd);
297
1.66M
    return;
298
1.66M
  }
299
1.38M
#endif
300
1.38M
  cfl_get_predict_lbd_fn(tx_size)(cfl->ac_buf_q3, dst, dst_stride, alpha_q3);
301
1.38M
}
302
303
static void cfl_luma_subsampling_420_lbd_c(const uint8_t *input,
304
                                           int input_stride,
305
                                           uint16_t *output_q3, int width,
306
0
                                           int height) {
307
0
  for (int j = 0; j < height; j += 2) {
308
0
    for (int i = 0; i < width; i += 2) {
309
0
      const int bot = i + input_stride;
310
0
      output_q3[i >> 1] =
311
0
          (input[i] + input[i + 1] + input[bot] + input[bot + 1]) << 1;
312
0
    }
313
0
    input += input_stride << 1;
314
0
    output_q3 += CFL_BUF_LINE;
315
0
  }
316
0
}
317
318
static void cfl_luma_subsampling_422_lbd_c(const uint8_t *input,
319
                                           int input_stride,
320
                                           uint16_t *output_q3, int width,
321
0
                                           int height) {
322
0
  assert((height - 1) * CFL_BUF_LINE + width <= CFL_BUF_SQUARE);
323
0
  for (int j = 0; j < height; j++) {
324
0
    for (int i = 0; i < width; i += 2) {
325
0
      output_q3[i >> 1] = (input[i] + input[i + 1]) << 2;
326
0
    }
327
0
    input += input_stride;
328
0
    output_q3 += CFL_BUF_LINE;
329
0
  }
330
0
}
331
332
static void cfl_luma_subsampling_444_lbd_c(const uint8_t *input,
333
                                           int input_stride,
334
                                           uint16_t *output_q3, int width,
335
0
                                           int height) {
336
0
  assert((height - 1) * CFL_BUF_LINE + width <= CFL_BUF_SQUARE);
337
0
  for (int j = 0; j < height; j++) {
338
0
    for (int i = 0; i < width; i++) {
339
0
      output_q3[i] = input[i] << 3;
340
0
    }
341
0
    input += input_stride;
342
0
    output_q3 += CFL_BUF_LINE;
343
0
  }
344
0
}
345
346
#if CONFIG_AV1_HIGHBITDEPTH
347
static void cfl_luma_subsampling_420_hbd_c(const uint16_t *input,
348
                                           int input_stride,
349
                                           uint16_t *output_q3, int width,
350
0
                                           int height) {
351
0
  for (int j = 0; j < height; j += 2) {
352
0
    for (int i = 0; i < width; i += 2) {
353
0
      const int bot = i + input_stride;
354
0
      output_q3[i >> 1] =
355
0
          (input[i] + input[i + 1] + input[bot] + input[bot + 1]) << 1;
356
0
    }
357
0
    input += input_stride << 1;
358
0
    output_q3 += CFL_BUF_LINE;
359
0
  }
360
0
}
361
362
static void cfl_luma_subsampling_422_hbd_c(const uint16_t *input,
363
                                           int input_stride,
364
                                           uint16_t *output_q3, int width,
365
0
                                           int height) {
366
0
  assert((height - 1) * CFL_BUF_LINE + width <= CFL_BUF_SQUARE);
367
0
  for (int j = 0; j < height; j++) {
368
0
    for (int i = 0; i < width; i += 2) {
369
0
      output_q3[i >> 1] = (input[i] + input[i + 1]) << 2;
370
0
    }
371
0
    input += input_stride;
372
0
    output_q3 += CFL_BUF_LINE;
373
0
  }
374
0
}
375
376
static void cfl_luma_subsampling_444_hbd_c(const uint16_t *input,
377
                                           int input_stride,
378
                                           uint16_t *output_q3, int width,
379
0
                                           int height) {
380
0
  assert((height - 1) * CFL_BUF_LINE + width <= CFL_BUF_SQUARE);
381
0
  for (int j = 0; j < height; j++) {
382
0
    for (int i = 0; i < width; i++) {
383
0
      output_q3[i] = input[i] << 3;
384
0
    }
385
0
    input += input_stride;
386
0
    output_q3 += CFL_BUF_LINE;
387
0
  }
388
0
}
389
#endif
390
391
0
CFL_GET_SUBSAMPLE_FUNCTION(c)
Unexecuted instantiation: cfl_get_luma_subsampling_420_lbd_c
Unexecuted instantiation: cfl_get_luma_subsampling_422_lbd_c
Unexecuted instantiation: cfl_get_luma_subsampling_444_lbd_c
Unexecuted instantiation: cfl_get_luma_subsampling_420_hbd_c
Unexecuted instantiation: cfl_get_luma_subsampling_422_hbd_c
Unexecuted instantiation: cfl_get_luma_subsampling_444_hbd_c
392
0
393
0
#if CONFIG_AV1_HIGHBITDEPTH
394
0
static inline cfl_subsample_hbd_fn cfl_subsampling_hbd(TX_SIZE tx_size,
395
1.67M
                                                       int sub_x, int sub_y) {
396
1.67M
  if (sub_x == 1) {
397
882k
    if (sub_y == 1) {
398
877k
      return cfl_get_luma_subsampling_420_hbd(tx_size);
399
877k
    }
400
4.54k
    return cfl_get_luma_subsampling_422_hbd(tx_size);
401
882k
  }
402
793k
  return cfl_get_luma_subsampling_444_hbd(tx_size);
403
1.67M
}
404
#endif
405
406
static inline cfl_subsample_lbd_fn cfl_subsampling_lbd(TX_SIZE tx_size,
407
1.36M
                                                       int sub_x, int sub_y) {
408
1.36M
  if (sub_x == 1) {
409
923k
    if (sub_y == 1) {
410
917k
      return cfl_get_luma_subsampling_420_lbd(tx_size);
411
917k
    }
412
5.86k
    return cfl_get_luma_subsampling_422_lbd(tx_size);
413
923k
  }
414
442k
  return cfl_get_luma_subsampling_444_lbd(tx_size);
415
1.36M
}
416
417
static void cfl_store(CFL_CTX *cfl, const uint8_t *input, int input_stride,
418
3.04M
                      int row, int col, TX_SIZE tx_size, int use_hbd) {
419
3.04M
  const int width = tx_size_wide[tx_size];
420
3.04M
  const int height = tx_size_high[tx_size];
421
3.04M
  const int tx_off_log2 = MI_SIZE_LOG2;
422
3.04M
  const int sub_x = cfl->subsampling_x;
423
3.04M
  const int sub_y = cfl->subsampling_y;
424
3.04M
  const int store_row = row << (tx_off_log2 - sub_y);
425
3.04M
  const int store_col = col << (tx_off_log2 - sub_x);
426
3.04M
  const int store_height = height >> sub_y;
427
3.04M
  const int store_width = width >> sub_x;
428
429
  // Invalidate current parameters
430
3.04M
  cfl->are_parameters_computed = 0;
431
432
  // Store the surface of the pixel buffer that was written to, this way we
433
  // can manage chroma overrun (e.g. when the chroma surfaces goes beyond the
434
  // frame boundary)
435
3.04M
  if (col == 0 && row == 0) {
436
2.40M
    cfl->buf_width = store_width;
437
2.40M
    cfl->buf_height = store_height;
438
2.40M
  } else {
439
636k
    cfl->buf_width = OD_MAXI(store_col + store_width, cfl->buf_width);
440
636k
    cfl->buf_height = OD_MAXI(store_row + store_height, cfl->buf_height);
441
636k
  }
442
443
  // Check that we will remain inside the pixel buffer.
444
3.04M
  assert(store_row + store_height <= CFL_BUF_LINE);
445
3.04M
  assert(store_col + store_width <= CFL_BUF_LINE);
446
447
  // Store the input into the CfL pixel buffer
448
3.04M
  uint16_t *recon_buf_q3 =
449
3.04M
      cfl->recon_buf_q3 + (store_row * CFL_BUF_LINE + store_col);
450
3.04M
#if CONFIG_AV1_HIGHBITDEPTH
451
3.04M
  if (use_hbd) {
452
1.67M
    cfl_subsampling_hbd(tx_size, sub_x, sub_y)(CONVERT_TO_SHORTPTR(input),
453
1.67M
                                               input_stride, recon_buf_q3);
454
1.67M
  } else {
455
1.36M
    cfl_subsampling_lbd(tx_size, sub_x, sub_y)(input, input_stride,
456
1.36M
                                               recon_buf_q3);
457
1.36M
  }
458
#else
459
  (void)use_hbd;
460
  cfl_subsampling_lbd(tx_size, sub_x, sub_y)(input, input_stride, recon_buf_q3);
461
#endif
462
3.04M
}
463
464
// Adjust the row and column of blocks smaller than 8X8, as chroma-referenced
465
// and non-chroma-referenced blocks are stored together in the CfL buffer.
466
static inline void sub8x8_adjust_offset(const CFL_CTX *cfl, int mi_row,
467
                                        int mi_col, int *row_out,
468
1.82M
                                        int *col_out) {
469
  // Increment row index for bottom: 8x4, 16x4 or both bottom 4x4s.
470
1.82M
  if ((mi_row & 0x01) && cfl->subsampling_y) {
471
155k
    assert(*row_out == 0);
472
155k
    (*row_out)++;
473
155k
  }
474
475
  // Increment col index for right: 4x8, 4x16 or both right 4x4s.
476
1.82M
  if ((mi_col & 0x01) && cfl->subsampling_x) {
477
147k
    assert(*col_out == 0);
478
147k
    (*col_out)++;
479
147k
  }
480
1.82M
}
481
482
void cfl_store_tx(MACROBLOCKD *const xd, int row, int col, TX_SIZE tx_size,
483
2.37M
                  BLOCK_SIZE bsize) {
484
2.37M
  CFL_CTX *const cfl = &xd->cfl;
485
2.37M
  struct macroblockd_plane *const pd = &xd->plane[AOM_PLANE_Y];
486
2.37M
  uint8_t *dst = &pd->dst.buf[(row * pd->dst.stride + col) << MI_SIZE_LOG2];
487
488
2.37M
  if (block_size_high[bsize] == 4 || block_size_wide[bsize] == 4) {
489
    // Only dimensions of size 4 can have an odd offset.
490
1.15M
    assert(!((col & 1) && tx_size_wide[tx_size] != 4));
491
1.15M
    assert(!((row & 1) && tx_size_high[tx_size] != 4));
492
1.15M
    sub8x8_adjust_offset(cfl, xd->mi_row, xd->mi_col, &row, &col);
493
1.15M
  }
494
2.37M
  cfl_store(cfl, dst, pd->dst.stride, row, col, tx_size, is_cur_buf_hbd(xd));
495
2.37M
}
496
497
static inline int max_intra_block_width(const MACROBLOCKD *xd,
498
                                        BLOCK_SIZE plane_bsize, int plane,
499
670k
                                        TX_SIZE tx_size) {
500
670k
  const int max_blocks_wide = max_block_wide(xd, plane_bsize, plane)
501
670k
                              << MI_SIZE_LOG2;
502
670k
  return ALIGN_POWER_OF_TWO(max_blocks_wide, tx_size_wide_log2[tx_size]);
503
670k
}
504
505
static inline int max_intra_block_height(const MACROBLOCKD *xd,
506
                                         BLOCK_SIZE plane_bsize, int plane,
507
670k
                                         TX_SIZE tx_size) {
508
670k
  const int max_blocks_high = max_block_high(xd, plane_bsize, plane)
509
670k
                              << MI_SIZE_LOG2;
510
670k
  return ALIGN_POWER_OF_TWO(max_blocks_high, tx_size_high_log2[tx_size]);
511
670k
}
512
513
670k
void cfl_store_block(MACROBLOCKD *const xd, BLOCK_SIZE bsize, TX_SIZE tx_size) {
514
670k
  CFL_CTX *const cfl = &xd->cfl;
515
670k
  struct macroblockd_plane *const pd = &xd->plane[AOM_PLANE_Y];
516
670k
  int row = 0;
517
670k
  int col = 0;
518
519
670k
  if (block_size_high[bsize] == 4 || block_size_wide[bsize] == 4) {
520
670k
    sub8x8_adjust_offset(cfl, xd->mi_row, xd->mi_col, &row, &col);
521
670k
  }
522
670k
  const int width = max_intra_block_width(xd, bsize, AOM_PLANE_Y, tx_size);
523
670k
  const int height = max_intra_block_height(xd, bsize, AOM_PLANE_Y, tx_size);
524
670k
  tx_size = get_tx_size(width, height);
525
670k
  cfl_store(cfl, pd->dst.buf, pd->dst.stride, row, col, tx_size,
526
670k
            is_cur_buf_hbd(xd));
527
670k
}