/src/aom/av1/decoder/detokenize.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 "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 | 161k | static void decode_color_map_tokens(Av1ColorMapParam *param, aom_reader *r) { |
26 | 161k | uint8_t color_order[PALETTE_MAX_SIZE]; |
27 | 161k | const int n = param->n_colors; |
28 | 161k | uint8_t *const color_map = param->color_map; |
29 | 161k | MapCdf color_map_cdf = param->map_cdf; |
30 | 161k | int plane_block_width = param->plane_width; |
31 | 161k | int plane_block_height = param->plane_height; |
32 | 161k | int rows = param->rows; |
33 | 161k | int cols = param->cols; |
34 | | |
35 | | // The first color index. |
36 | 161k | color_map[0] = av1_read_uniform(r, n); |
37 | 161k | assert(color_map[0] < n); |
38 | | |
39 | | // Run wavefront on the palette map index decoding. |
40 | 3.88M | for (int i = 1; i < rows + cols - 1; ++i) { |
41 | 29.9M | for (int j = AOMMIN(i, cols - 1); j >= AOMMAX(0, i - rows + 1); --j) { |
42 | 26.2M | const int color_ctx = av1_get_palette_color_index_context( |
43 | 26.2M | color_map, plane_block_width, (i - j), j, n, color_order, NULL); |
44 | 26.2M | const int color_idx = aom_read_symbol( |
45 | 26.2M | r, color_map_cdf[n - PALETTE_MIN_SIZE][color_ctx], n, ACCT_STR); |
46 | 26.2M | assert(color_idx >= 0 && color_idx < n); |
47 | 26.2M | color_map[(i - j) * plane_block_width + j] = color_order[color_idx]; |
48 | 26.2M | } |
49 | 3.72M | } |
50 | | // Copy last column to extra columns. |
51 | 156k | if (cols < plane_block_width) { |
52 | 9.31k | for (int i = 0; i < rows; ++i) { |
53 | 9.02k | memset(color_map + i * plane_block_width + cols, |
54 | 9.02k | color_map[i * plane_block_width + cols - 1], |
55 | 9.02k | (plane_block_width - cols)); |
56 | 9.02k | } |
57 | 288 | } |
58 | | // Copy last row to extra rows. |
59 | 167k | for (int i = rows; i < plane_block_height; ++i) { |
60 | 11.4k | memcpy(color_map + i * plane_block_width, |
61 | 11.4k | color_map + (rows - 1) * plane_block_width, plane_block_width); |
62 | 11.4k | } |
63 | 156k | } |
64 | | |
65 | | void av1_decode_palette_tokens(MACROBLOCKD *const xd, int plane, |
66 | 161k | aom_reader *r) { |
67 | 161k | assert(plane == 0 || plane == 1); |
68 | 161k | Av1ColorMapParam params; |
69 | 161k | params.color_map = |
70 | 161k | xd->plane[plane].color_index_map + xd->color_index_map_offset[plane]; |
71 | 161k | params.map_cdf = plane ? xd->tile_ctx->palette_uv_color_index_cdf |
72 | 161k | : xd->tile_ctx->palette_y_color_index_cdf; |
73 | 161k | const MB_MODE_INFO *const mbmi = xd->mi[0]; |
74 | 161k | params.n_colors = mbmi->palette_mode_info.palette_size[plane]; |
75 | 161k | av1_get_block_dimensions(mbmi->bsize, plane, xd, ¶ms.plane_width, |
76 | 161k | ¶ms.plane_height, ¶ms.rows, ¶ms.cols); |
77 | 161k | decode_color_map_tokens(¶ms, r); |
78 | 161k | } |