FFmpeg
vvcdsp_template.c
Go to the documentation of this file.
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"
24 
25 #include "vvcdec.h"
26 #include "vvc_data.h"
27 
28 #include "vvc_inter_template.c"
29 #include "vvc_intra_template.c"
30 #include "vvc_filter_template.c"
31 
32 static void FUNC(add_residual)(uint8_t *_dst, const int *res,
33  const int w, const int h, const ptrdiff_t _stride)
34 {
35  pixel *dst = (pixel *)_dst;
36 
37  const int stride = _stride / sizeof(pixel);
38 
39  for (int y = 0; y < h; y++) {
40  for (int x = 0; x < w; x++) {
41  dst[x] = av_clip_pixel(dst[x] + *res);
42  res++;
43  }
44  dst += stride;
45  }
46 }
47 
48 static void FUNC(add_residual_joint)(uint8_t *_dst, const int *res,
49  const int w, const int h, const ptrdiff_t _stride, const int c_sign, const int shift)
50 {
51  pixel *dst = (pixel *)_dst;
52 
53  const int stride = _stride / sizeof(pixel);
54 
55  for (int y = 0; y < h; y++) {
56  for (int x = 0; x < w; x++) {
57  const int r = ((*res) * c_sign) >> shift;
58  dst[x] = av_clip_pixel(dst[x] + r);
59  res++;
60  }
61  dst += stride;
62  }
63 }
64 
65 static void FUNC(pred_residual_joint)(int *buf, const int w, const int h,
66  const int c_sign, const int shift)
67 {
68  for (int y = 0; y < h; y++) {
69  for (int x = 0; x < w; x++) {
70  *buf = ((*buf) * c_sign) >> shift;
71  buf++;
72  }
73  }
74 }
75 
76 static void FUNC(transform_bdpcm)(int *coeffs, const int width, const int height,
77  const int vertical, const int log2_transform_range)
78 {
79  int x, y;
80 
81  if (vertical) {
82  coeffs += width;
83  for (y = 0; y < height - 1; y++) {
84  for (x = 0; x < width; x++)
85  coeffs[x] = av_clip_intp2(coeffs[x] + coeffs[x - width], log2_transform_range);
86  coeffs += width;
87  }
88  } else {
89  for (y = 0; y < height; y++) {
90  for (x = 1; x < width; x++)
91  coeffs[x] = av_clip_intp2(coeffs[x] + coeffs[x - 1], log2_transform_range);
92  coeffs += width;
93  }
94  }
95 }
96 
97 static void FUNC(ff_vvc_itx_dsp_init)(VVCItxDSPContext *const itx)
98 {
99 #define VVC_ITX(TYPE, type, s) \
100  itx->itx[TYPE][TX_SIZE_##s] = ff_vvc_inv_##type##_##s; \
101 
102 #define VVC_ITX_COMMON(TYPE, type) \
103  VVC_ITX(TYPE, type, 4); \
104  VVC_ITX(TYPE, type, 8); \
105  VVC_ITX(TYPE, type, 16); \
106  VVC_ITX(TYPE, type, 32);
107 
108  itx->add_residual = FUNC(add_residual);
109  itx->add_residual_joint = FUNC(add_residual_joint);
110  itx->pred_residual_joint = FUNC(pred_residual_joint);
111  itx->transform_bdpcm = FUNC(transform_bdpcm);
112  VVC_ITX(DCT2, dct2, 2)
113  VVC_ITX(DCT2, dct2, 64)
114  VVC_ITX_COMMON(DCT2, dct2)
115  VVC_ITX_COMMON(DCT8, dct8)
116  VVC_ITX_COMMON(DST7, dst7)
117 
118 #undef VVC_ITX
119 #undef VVC_ITX_COMMON
120 }
pred_residual_joint
static void FUNC() pred_residual_joint(int *buf, const int w, const int h, const int c_sign, const int shift)
Definition: vvcdsp_template.c:65
DCT8
@ DCT8
Definition: vvcdsp.h:33
r
const char * r
Definition: vf_curves.c:126
vvc_intra_template.c
w
uint8_t w
Definition: llviddspenc.c:38
_stride
ptrdiff_t _stride
Definition: h264pred_template.c:411
VVC_ITX_COMMON
#define VVC_ITX_COMMON(TYPE, type)
VVCItxDSPContext
Definition: vvcdsp.h:112
VVC_ITX
#define VVC_ITX(TYPE, type, s)
vvc_data.h
width
#define width
vvcdec.h
DCT2
@ DCT2
Definition: vvcdsp.h:31
av_clip_intp2
#define av_clip_intp2
Definition: common.h:119
pixel
uint8_t pixel
Definition: tiny_ssim.c:41
bit_depth_template.c
add_residual
static void FUNC() add_residual(uint8_t *_dst, const int *res, const int w, const int h, const ptrdiff_t _stride)
Definition: vvcdsp_template.c:32
shift
static int shift(int a, int b)
Definition: bonk.c:262
frame.h
height
#define height
add_residual_joint
static void FUNC() add_residual_joint(uint8_t *_dst, const int *res, const int w, const int h, const ptrdiff_t _stride, const int c_sign, const int shift)
Definition: vvcdsp_template.c:48
vvc_inter_template.c
DST7
@ DST7
Definition: vvcdsp.h:32
vvc_filter_template.c
stride
#define stride
Definition: h264pred_template.c:537
av_clip_pixel
#define av_clip_pixel(a)
Definition: bit_depth_template.c:98
ff_vvc_itx_dsp_init
static void FUNC() ff_vvc_itx_dsp_init(VVCItxDSPContext *const itx)
Definition: vvcdsp_template.c:97
FUNC
#define FUNC(a)
Definition: bit_depth_template.c:104
h
h
Definition: vp9dsp_template.c:2038
transform_bdpcm
static void FUNC() transform_bdpcm(int *coeffs, const int width, const int height, const int vertical, const int log2_transform_range)
Definition: vvcdsp_template.c:76