Coverage Report

Created: 2022-08-24 06:11

/src/aom/av1/decoder/detokenize.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 "config/aom_config.h"
13
14
#include "aom_mem/aom_mem.h"
15
#include "aom_ports/mem.h"
16
#include "av1/common/blockd.h"
17
#include "av1/decoder/detokenize.h"
18
19
#define ACCT_STR __func__
20
21
#include "av1/common/common.h"
22
#include "av1/common/entropy.h"
23
#include "av1/common/idct.h"
24
25
0
static void decode_color_map_tokens(Av1ColorMapParam *param, aom_reader *r) {
26
0
  uint8_t color_order[PALETTE_MAX_SIZE];
27
0
  const int n = param->n_colors;
28
0
  uint8_t *const color_map = param->color_map;
29
0
  MapCdf color_map_cdf = param->map_cdf;
30
0
  int plane_block_width = param->plane_width;
31
0
  int plane_block_height = param->plane_height;
32
0
  int rows = param->rows;
33
0
  int cols = param->cols;
34
35
  // The first color index.
36
0
  color_map[0] = av1_read_uniform(r, n);
37
0
  assert(color_map[0] < n);
38
39
  // Run wavefront on the palette map index decoding.
40
0
  for (int i = 1; i < rows + cols - 1; ++i) {
41
0
    for (int j = AOMMIN(i, cols - 1); j >= AOMMAX(0, i - rows + 1); --j) {
42
0
      const int color_ctx = av1_get_palette_color_index_context(
43
0
          color_map, plane_block_width, (i - j), j, n, color_order, NULL);
44
0
      const int color_idx = aom_read_symbol(
45
0
          r, color_map_cdf[n - PALETTE_MIN_SIZE][color_ctx], n, ACCT_STR);
46
0
      assert(color_idx >= 0 && color_idx < n);
47
0
      color_map[(i - j) * plane_block_width + j] = color_order[color_idx];
48
0
    }
49
0
  }
50
  // Copy last column to extra columns.
51
0
  if (cols < plane_block_width) {
52
0
    for (int i = 0; i < rows; ++i) {
53
0
      memset(color_map + i * plane_block_width + cols,
54
0
             color_map[i * plane_block_width + cols - 1],
55
0
             (plane_block_width - cols));
56
0
    }
57
0
  }
58
  // Copy last row to extra rows.
59
0
  for (int i = rows; i < plane_block_height; ++i) {
60
0
    memcpy(color_map + i * plane_block_width,
61
0
           color_map + (rows - 1) * plane_block_width, plane_block_width);
62
0
  }
63
0
}
64
65
void av1_decode_palette_tokens(MACROBLOCKD *const xd, int plane,
66
0
                               aom_reader *r) {
67
0
  assert(plane == 0 || plane == 1);
68
0
  Av1ColorMapParam params;
69
0
  params.color_map =
70
0
      xd->plane[plane].color_index_map + xd->color_index_map_offset[plane];
71
0
  params.map_cdf = plane ? xd->tile_ctx->palette_uv_color_index_cdf
72
0
                         : xd->tile_ctx->palette_y_color_index_cdf;
73
0
  const MB_MODE_INFO *const mbmi = xd->mi[0];
74
0
  params.n_colors = mbmi->palette_mode_info.palette_size[plane];
75
0
  av1_get_block_dimensions(mbmi->bsize, plane, xd, &params.plane_width,
76
0
                           &params.plane_height, &params.rows, &params.cols);
77
0
  decode_color_map_tokens(&params, r);
78
0
}