| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * VVC transform and residual DSP | ||
| 3 | * | ||
| 4 | * Copyright (C) 2021 Nuo Mi | ||
| 5 | * | ||
| 6 | * This file is part of FFmpeg. | ||
| 7 | * | ||
| 8 | * FFmpeg is free software; you can redistribute it and/or | ||
| 9 | * modify it under the terms of the GNU Lesser General Public | ||
| 10 | * License as published by the Free Software Foundation; either | ||
| 11 | * version 2.1 of the License, or (at your option) any later version. | ||
| 12 | * | ||
| 13 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 16 | * Lesser General Public License for more details. | ||
| 17 | * | ||
| 18 | * You should have received a copy of the GNU Lesser General Public | ||
| 19 | * License along with FFmpeg; if not, write to the Free Software | ||
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 21 | */ | ||
| 22 | #include "libavutil/frame.h" | ||
| 23 | #include "libavcodec/bit_depth_template.c" | ||
| 24 | |||
| 25 | #include "dec.h" | ||
| 26 | #include "data.h" | ||
| 27 | |||
| 28 | #include "inter_template.c" | ||
| 29 | #include "intra_template.c" | ||
| 30 | #include "filter_template.c" | ||
| 31 | |||
| 32 | 2166158 | static void FUNC(add_residual)(uint8_t *_dst, const int *res, | |
| 33 | const int w, const int h, const ptrdiff_t _stride) | ||
| 34 | { | ||
| 35 | 2166158 | pixel *dst = (pixel *)_dst; | |
| 36 | |||
| 37 | 2166158 | const int stride = _stride / sizeof(pixel); | |
| 38 | |||
| 39 |
2/2✓ Branch 0 taken 11111750 times.
✓ Branch 1 taken 1083079 times.
|
24389658 | for (int y = 0; y < h; y++) { |
| 40 |
2/2✓ Branch 0 taken 187150692 times.
✓ Branch 1 taken 11111750 times.
|
396524884 | for (int x = 0; x < w; x++) { |
| 41 | 374301384 | dst[x] = av_clip_pixel(dst[x] + *res); | |
| 42 | 374301384 | res++; | |
| 43 | } | ||
| 44 | 22223500 | dst += stride; | |
| 45 | } | ||
| 46 | 2166158 | } | |
| 47 | |||
| 48 | 108450 | static void FUNC(pred_residual_joint)(int *dst, const int *src, const int w, const int h, | |
| 49 | const int c_sign, const int shift) | ||
| 50 | { | ||
| 51 | 108450 | const int size = w * h; | |
| 52 |
2/2✓ Branch 0 taken 6797408 times.
✓ Branch 1 taken 54225 times.
|
13703266 | for (int i = 0; i < size; i++) |
| 53 | 13594816 | dst[i] = (src[i] * c_sign) >> shift; | |
| 54 | 108450 | } | |
| 55 | |||
| 56 | 4410 | static void FUNC(transform_bdpcm)(int *coeffs, const int width, const int height, | |
| 57 | const int vertical, const int log2_transform_range) | ||
| 58 | { | ||
| 59 | int x, y; | ||
| 60 | |||
| 61 |
2/2✓ Branch 0 taken 1418 times.
✓ Branch 1 taken 787 times.
|
4410 | if (vertical) { |
| 62 | 2836 | coeffs += width; | |
| 63 |
2/2✓ Branch 0 taken 12614 times.
✓ Branch 1 taken 1418 times.
|
28064 | for (y = 0; y < height - 1; y++) { |
| 64 |
2/2✓ Branch 0 taken 120676 times.
✓ Branch 1 taken 12614 times.
|
266580 | for (x = 0; x < width; x++) |
| 65 | 241352 | coeffs[x] = av_clip_intp2(coeffs[x] + coeffs[x - width], log2_transform_range); | |
| 66 | 25228 | coeffs += width; | |
| 67 | } | ||
| 68 | } else { | ||
| 69 |
2/2✓ Branch 0 taken 6252 times.
✓ Branch 1 taken 787 times.
|
14078 | for (y = 0; y < height; y++) { |
| 70 |
2/2✓ Branch 0 taken 49140 times.
✓ Branch 1 taken 6252 times.
|
110784 | for (x = 1; x < width; x++) |
| 71 | 98280 | coeffs[x] = av_clip_intp2(coeffs[x] + coeffs[x - 1], log2_transform_range); | |
| 72 | 12504 | coeffs += width; | |
| 73 | } | ||
| 74 | } | ||
| 75 | 4410 | } | |
| 76 | |||
| 77 | // 8.7.4.6 Residual modification process for blocks using colour space conversion | ||
| 78 | 30308 | static void FUNC(adaptive_color_transform)(int *y, int *u, int *v, const int width, const int height) | |
| 79 | { | ||
| 80 | 30308 | const int size = width * height; | |
| 81 | 30308 | const int bits = BIT_DEPTH + 1; | |
| 82 | |||
| 83 |
2/2✓ Branch 0 taken 3064832 times.
✓ Branch 1 taken 15154 times.
|
6159972 | for (int i = 0; i < size; i++) { |
| 84 | 6129664 | const int y0 = av_clip_intp2(y[i], bits); | |
| 85 | 6129664 | const int cg = av_clip_intp2(u[i], bits); | |
| 86 | 6129664 | const int co = av_clip_intp2(v[i], bits); | |
| 87 | 6129664 | const int t = y0 - (cg >> 1); | |
| 88 | |||
| 89 | 6129664 | y[i] = cg + t; | |
| 90 | 6129664 | u[i] = t - (co >> 1); | |
| 91 | 6129664 | v[i] = co + u[i]; | |
| 92 | } | ||
| 93 | 30308 | } | |
| 94 | |||
| 95 | 2860 | static void FUNC(ff_vvc_itx_dsp_init)(VVCItxDSPContext *const itx) | |
| 96 | { | ||
| 97 | #define VVC_ITX(TYPE, type, s) \ | ||
| 98 | itx->itx[VVC_##TYPE][VVC_##TX_SIZE_##s] = ff_vvc_inv_##type##_##s; \ | ||
| 99 | |||
| 100 | #define VVC_ITX_COMMON(TYPE, type) \ | ||
| 101 | VVC_ITX(TYPE, type, 4); \ | ||
| 102 | VVC_ITX(TYPE, type, 8); \ | ||
| 103 | VVC_ITX(TYPE, type, 16); \ | ||
| 104 | VVC_ITX(TYPE, type, 32); | ||
| 105 | |||
| 106 | 2860 | itx->add_residual = FUNC(add_residual); | |
| 107 | 2860 | itx->pred_residual_joint = FUNC(pred_residual_joint); | |
| 108 | 2860 | itx->transform_bdpcm = FUNC(transform_bdpcm); | |
| 109 | 2860 | VVC_ITX(DCT2, dct2, 2) | |
| 110 | 2860 | VVC_ITX(DCT2, dct2, 64) | |
| 111 | 2860 | VVC_ITX_COMMON(DCT2, dct2) | |
| 112 | 2860 | VVC_ITX_COMMON(DCT8, dct8) | |
| 113 | 2860 | VVC_ITX_COMMON(DST7, dst7) | |
| 114 | |||
| 115 | 2860 | itx->adaptive_color_transform = FUNC(adaptive_color_transform); | |
| 116 | |||
| 117 | #undef VVC_ITX | ||
| 118 | #undef VVC_ITX_COMMON | ||
| 119 | 2860 | } | |
| 120 |