* [FFmpeg-devel] [PATCH 1/4] hevcdec: move sao template to xvc_sao_template.c
[not found] <20240103153238.18678-1-nuomi2021@gmail.com>
@ 2024-01-03 15:32 ` Nuo Mi
2024-01-06 10:51 ` [FFmpeg-devel] [PATCH v2 1/4] hevcdec: move sao template to h26x/h2656_sao_template.c Nuo Mi
[not found] ` <20240106105132.31509-1-nuomi2021@gmail.com>
2024-01-03 15:32 ` [FFmpeg-devel] [PATCH 2/4] vvcdec: reuse xvc_sao_template.c Nuo Mi
` (2 subsequent siblings)
3 siblings, 2 replies; 13+ messages in thread
From: Nuo Mi @ 2024-01-03 15:32 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Nuo Mi
---
libavcodec/hevcdsp_template.c | 196 +-----------------------------
libavcodec/xvc_sao_template.c | 217 ++++++++++++++++++++++++++++++++++
2 files changed, 218 insertions(+), 195 deletions(-)
create mode 100644 libavcodec/xvc_sao_template.c
diff --git a/libavcodec/hevcdsp_template.c b/libavcodec/hevcdsp_template.c
index 725fab99ed..00786bb2f8 100644
--- a/libavcodec/hevcdsp_template.c
+++ b/libavcodec/hevcdsp_template.c
@@ -25,6 +25,7 @@
#include "bit_depth_template.c"
#include "hevcdsp.h"
+#include "xvc_sao_template.c"
static void FUNC(put_pcm)(uint8_t *_dst, ptrdiff_t stride, int width, int height,
GetBitContext *gb, int pcm_bit_depth)
@@ -295,201 +296,6 @@ IDCT_DC(32)
#undef SET
#undef SCALE
-static void FUNC(sao_band_filter)(uint8_t *_dst, const uint8_t *_src,
- ptrdiff_t stride_dst, ptrdiff_t stride_src,
- const int16_t *sao_offset_val, int sao_left_class,
- int width, int height)
-{
- pixel *dst = (pixel *)_dst;
- const pixel *src = (const pixel *)_src;
- int offset_table[32] = { 0 };
- int k, y, x;
- int shift = BIT_DEPTH - 5;
-
- stride_dst /= sizeof(pixel);
- stride_src /= sizeof(pixel);
-
- for (k = 0; k < 4; k++)
- offset_table[(k + sao_left_class) & 31] = sao_offset_val[k + 1];
- for (y = 0; y < height; y++) {
- for (x = 0; x < width; x++)
- dst[x] = av_clip_pixel(src[x] + offset_table[(src[x] >> shift) & 31]);
- dst += stride_dst;
- src += stride_src;
- }
-}
-
-#define CMP(a, b) (((a) > (b)) - ((a) < (b)))
-
-static void FUNC(sao_edge_filter)(uint8_t *_dst, const uint8_t *_src, ptrdiff_t stride_dst, const int16_t *sao_offset_val,
- int eo, int width, int height) {
-
- static const uint8_t edge_idx[] = { 1, 2, 0, 3, 4 };
- static const int8_t pos[4][2][2] = {
- { { -1, 0 }, { 1, 0 } }, // horizontal
- { { 0, -1 }, { 0, 1 } }, // vertical
- { { -1, -1 }, { 1, 1 } }, // 45 degree
- { { 1, -1 }, { -1, 1 } }, // 135 degree
- };
- pixel *dst = (pixel *)_dst;
- const pixel *src = (const pixel *)_src;
- int a_stride, b_stride;
- int x, y;
- ptrdiff_t stride_src = (2*MAX_PB_SIZE + AV_INPUT_BUFFER_PADDING_SIZE) / sizeof(pixel);
- stride_dst /= sizeof(pixel);
-
- a_stride = pos[eo][0][0] + pos[eo][0][1] * stride_src;
- b_stride = pos[eo][1][0] + pos[eo][1][1] * stride_src;
- for (y = 0; y < height; y++) {
- for (x = 0; x < width; x++) {
- int diff0 = CMP(src[x], src[x + a_stride]);
- int diff1 = CMP(src[x], src[x + b_stride]);
- int offset_val = edge_idx[2 + diff0 + diff1];
- dst[x] = av_clip_pixel(src[x] + sao_offset_val[offset_val]);
- }
- src += stride_src;
- dst += stride_dst;
- }
-}
-
-static void FUNC(sao_edge_restore_0)(uint8_t *_dst, const uint8_t *_src,
- ptrdiff_t stride_dst, ptrdiff_t stride_src, const SAOParams *sao,
- const int *borders, int _width, int _height,
- int c_idx, const uint8_t *vert_edge,
- const uint8_t *horiz_edge, const uint8_t *diag_edge)
-{
- int x, y;
- pixel *dst = (pixel *)_dst;
- const pixel *src = (const pixel *)_src;
- const int16_t *sao_offset_val = sao->offset_val[c_idx];
- int sao_eo_class = sao->eo_class[c_idx];
- int init_x = 0, width = _width, height = _height;
-
- stride_dst /= sizeof(pixel);
- stride_src /= sizeof(pixel);
-
- if (sao_eo_class != SAO_EO_VERT) {
- if (borders[0]) {
- int offset_val = sao_offset_val[0];
- for (y = 0; y < height; y++) {
- dst[y * stride_dst] = av_clip_pixel(src[y * stride_src] + offset_val);
- }
- init_x = 1;
- }
- if (borders[2]) {
- int offset_val = sao_offset_val[0];
- int offset = width - 1;
- for (x = 0; x < height; x++) {
- dst[x * stride_dst + offset] = av_clip_pixel(src[x * stride_src + offset] + offset_val);
- }
- width--;
- }
- }
- if (sao_eo_class != SAO_EO_HORIZ) {
- if (borders[1]) {
- int offset_val = sao_offset_val[0];
- for (x = init_x; x < width; x++)
- dst[x] = av_clip_pixel(src[x] + offset_val);
- }
- if (borders[3]) {
- int offset_val = sao_offset_val[0];
- ptrdiff_t y_stride_dst = stride_dst * (height - 1);
- ptrdiff_t y_stride_src = stride_src * (height - 1);
- for (x = init_x; x < width; x++)
- dst[x + y_stride_dst] = av_clip_pixel(src[x + y_stride_src] + offset_val);
- height--;
- }
- }
-}
-
-static void FUNC(sao_edge_restore_1)(uint8_t *_dst, const uint8_t *_src,
- ptrdiff_t stride_dst, ptrdiff_t stride_src, const SAOParams *sao,
- const int *borders, int _width, int _height,
- int c_idx, const uint8_t *vert_edge,
- const uint8_t *horiz_edge, const uint8_t *diag_edge)
-{
- int x, y;
- pixel *dst = (pixel *)_dst;
- const pixel *src = (const pixel *)_src;
- const int16_t *sao_offset_val = sao->offset_val[c_idx];
- int sao_eo_class = sao->eo_class[c_idx];
- int init_x = 0, init_y = 0, width = _width, height = _height;
-
- stride_dst /= sizeof(pixel);
- stride_src /= sizeof(pixel);
-
- if (sao_eo_class != SAO_EO_VERT) {
- if (borders[0]) {
- int offset_val = sao_offset_val[0];
- for (y = 0; y < height; y++) {
- dst[y * stride_dst] = av_clip_pixel(src[y * stride_src] + offset_val);
- }
- init_x = 1;
- }
- if (borders[2]) {
- int offset_val = sao_offset_val[0];
- int offset = width - 1;
- for (x = 0; x < height; x++) {
- dst[x * stride_dst + offset] = av_clip_pixel(src[x * stride_src + offset] + offset_val);
- }
- width--;
- }
- }
- if (sao_eo_class != SAO_EO_HORIZ) {
- if (borders[1]) {
- int offset_val = sao_offset_val[0];
- for (x = init_x; x < width; x++)
- dst[x] = av_clip_pixel(src[x] + offset_val);
- init_y = 1;
- }
- if (borders[3]) {
- int offset_val = sao_offset_val[0];
- ptrdiff_t y_stride_dst = stride_dst * (height - 1);
- ptrdiff_t y_stride_src = stride_src * (height - 1);
- for (x = init_x; x < width; x++)
- dst[x + y_stride_dst] = av_clip_pixel(src[x + y_stride_src] + offset_val);
- height--;
- }
- }
-
- {
- int save_upper_left = !diag_edge[0] && sao_eo_class == SAO_EO_135D && !borders[0] && !borders[1];
- int save_upper_right = !diag_edge[1] && sao_eo_class == SAO_EO_45D && !borders[1] && !borders[2];
- int save_lower_right = !diag_edge[2] && sao_eo_class == SAO_EO_135D && !borders[2] && !borders[3];
- int save_lower_left = !diag_edge[3] && sao_eo_class == SAO_EO_45D && !borders[0] && !borders[3];
-
- // Restore pixels that can't be modified
- if(vert_edge[0] && sao_eo_class != SAO_EO_VERT) {
- for(y = init_y+save_upper_left; y< height-save_lower_left; y++)
- dst[y*stride_dst] = src[y*stride_src];
- }
- if(vert_edge[1] && sao_eo_class != SAO_EO_VERT) {
- for(y = init_y+save_upper_right; y< height-save_lower_right; y++)
- dst[y*stride_dst+width-1] = src[y*stride_src+width-1];
- }
-
- if(horiz_edge[0] && sao_eo_class != SAO_EO_HORIZ) {
- for(x = init_x+save_upper_left; x < width-save_upper_right; x++)
- dst[x] = src[x];
- }
- if(horiz_edge[1] && sao_eo_class != SAO_EO_HORIZ) {
- for(x = init_x+save_lower_left; x < width-save_lower_right; x++)
- dst[(height-1)*stride_dst+x] = src[(height-1)*stride_src+x];
- }
- if(diag_edge[0] && sao_eo_class == SAO_EO_135D)
- dst[0] = src[0];
- if(diag_edge[1] && sao_eo_class == SAO_EO_45D)
- dst[width-1] = src[width-1];
- if(diag_edge[2] && sao_eo_class == SAO_EO_135D)
- dst[stride_dst*(height-1)+width-1] = src[stride_src*(height-1)+width-1];
- if(diag_edge[3] && sao_eo_class == SAO_EO_45D)
- dst[stride_dst*(height-1)] = src[stride_src*(height-1)];
-
- }
-}
-
-#undef CMP
-
////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////
diff --git a/libavcodec/xvc_sao_template.c b/libavcodec/xvc_sao_template.c
new file mode 100644
index 0000000000..b3eb8a3deb
--- /dev/null
+++ b/libavcodec/xvc_sao_template.c
@@ -0,0 +1,217 @@
+/*
+ * HEVC/VVC SAO template
+ *
+ * Copyright (C) 2024 Nuo Mi
+ * Copyright (C) 2012 - 2013 Guillaume Martres
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+static void FUNC(sao_band_filter)(uint8_t *_dst, const uint8_t *_src,
+ ptrdiff_t stride_dst, ptrdiff_t stride_src,
+ const int16_t *sao_offset_val, int sao_left_class,
+ int width, int height)
+{
+ pixel *dst = (pixel *)_dst;
+ const pixel *src = (const pixel *)_src;
+ int offset_table[32] = { 0 };
+ int k, y, x;
+ int shift = BIT_DEPTH - 5;
+
+ stride_dst /= sizeof(pixel);
+ stride_src /= sizeof(pixel);
+
+ for (k = 0; k < 4; k++)
+ offset_table[(k + sao_left_class) & 31] = sao_offset_val[k + 1];
+ for (y = 0; y < height; y++) {
+ for (x = 0; x < width; x++)
+ dst[x] = av_clip_pixel(src[x] + offset_table[(src[x] >> shift) & 31]);
+ dst += stride_dst;
+ src += stride_src;
+ }
+}
+
+#define CMP(a, b) (((a) > (b)) - ((a) < (b)))
+
+static void FUNC(sao_edge_filter)(uint8_t *_dst, const uint8_t *_src, ptrdiff_t stride_dst, const int16_t *sao_offset_val,
+ int eo, int width, int height) {
+
+ static const uint8_t edge_idx[] = { 1, 2, 0, 3, 4 };
+ static const int8_t pos[4][2][2] = {
+ { { -1, 0 }, { 1, 0 } }, // horizontal
+ { { 0, -1 }, { 0, 1 } }, // vertical
+ { { -1, -1 }, { 1, 1 } }, // 45 degree
+ { { 1, -1 }, { -1, 1 } }, // 135 degree
+ };
+ pixel *dst = (pixel *)_dst;
+ const pixel *src = (const pixel *)_src;
+ int a_stride, b_stride;
+ int x, y;
+ ptrdiff_t stride_src = (2*MAX_PB_SIZE + AV_INPUT_BUFFER_PADDING_SIZE) / sizeof(pixel);
+ stride_dst /= sizeof(pixel);
+
+ a_stride = pos[eo][0][0] + pos[eo][0][1] * stride_src;
+ b_stride = pos[eo][1][0] + pos[eo][1][1] * stride_src;
+ for (y = 0; y < height; y++) {
+ for (x = 0; x < width; x++) {
+ int diff0 = CMP(src[x], src[x + a_stride]);
+ int diff1 = CMP(src[x], src[x + b_stride]);
+ int offset_val = edge_idx[2 + diff0 + diff1];
+ dst[x] = av_clip_pixel(src[x] + sao_offset_val[offset_val]);
+ }
+ src += stride_src;
+ dst += stride_dst;
+ }
+}
+
+static void FUNC(sao_edge_restore_0)(uint8_t *_dst, const uint8_t *_src,
+ ptrdiff_t stride_dst, ptrdiff_t stride_src, const SAOParams *sao,
+ const int *borders, int _width, int _height,
+ int c_idx, const uint8_t *vert_edge,
+ const uint8_t *horiz_edge, const uint8_t *diag_edge)
+{
+ int x, y;
+ pixel *dst = (pixel *)_dst;
+ const pixel *src = (const pixel *)_src;
+ const int16_t *sao_offset_val = sao->offset_val[c_idx];
+ int sao_eo_class = sao->eo_class[c_idx];
+ int init_x = 0, width = _width, height = _height;
+
+ stride_dst /= sizeof(pixel);
+ stride_src /= sizeof(pixel);
+
+ if (sao_eo_class != SAO_EO_VERT) {
+ if (borders[0]) {
+ int offset_val = sao_offset_val[0];
+ for (y = 0; y < height; y++) {
+ dst[y * stride_dst] = av_clip_pixel(src[y * stride_src] + offset_val);
+ }
+ init_x = 1;
+ }
+ if (borders[2]) {
+ int offset_val = sao_offset_val[0];
+ int offset = width - 1;
+ for (x = 0; x < height; x++) {
+ dst[x * stride_dst + offset] = av_clip_pixel(src[x * stride_src + offset] + offset_val);
+ }
+ width--;
+ }
+ }
+ if (sao_eo_class != SAO_EO_HORIZ) {
+ if (borders[1]) {
+ int offset_val = sao_offset_val[0];
+ for (x = init_x; x < width; x++)
+ dst[x] = av_clip_pixel(src[x] + offset_val);
+ }
+ if (borders[3]) {
+ int offset_val = sao_offset_val[0];
+ ptrdiff_t y_stride_dst = stride_dst * (height - 1);
+ ptrdiff_t y_stride_src = stride_src * (height - 1);
+ for (x = init_x; x < width; x++)
+ dst[x + y_stride_dst] = av_clip_pixel(src[x + y_stride_src] + offset_val);
+ height--;
+ }
+ }
+}
+
+static void FUNC(sao_edge_restore_1)(uint8_t *_dst, const uint8_t *_src,
+ ptrdiff_t stride_dst, ptrdiff_t stride_src, const SAOParams *sao,
+ const int *borders, int _width, int _height,
+ int c_idx, const uint8_t *vert_edge,
+ const uint8_t *horiz_edge, const uint8_t *diag_edge)
+{
+ int x, y;
+ pixel *dst = (pixel *)_dst;
+ const pixel *src = (const pixel *)_src;
+ const int16_t *sao_offset_val = sao->offset_val[c_idx];
+ int sao_eo_class = sao->eo_class[c_idx];
+ int init_x = 0, init_y = 0, width = _width, height = _height;
+
+ stride_dst /= sizeof(pixel);
+ stride_src /= sizeof(pixel);
+
+ if (sao_eo_class != SAO_EO_VERT) {
+ if (borders[0]) {
+ int offset_val = sao_offset_val[0];
+ for (y = 0; y < height; y++) {
+ dst[y * stride_dst] = av_clip_pixel(src[y * stride_src] + offset_val);
+ }
+ init_x = 1;
+ }
+ if (borders[2]) {
+ int offset_val = sao_offset_val[0];
+ int offset = width - 1;
+ for (x = 0; x < height; x++) {
+ dst[x * stride_dst + offset] = av_clip_pixel(src[x * stride_src + offset] + offset_val);
+ }
+ width--;
+ }
+ }
+ if (sao_eo_class != SAO_EO_HORIZ) {
+ if (borders[1]) {
+ int offset_val = sao_offset_val[0];
+ for (x = init_x; x < width; x++)
+ dst[x] = av_clip_pixel(src[x] + offset_val);
+ init_y = 1;
+ }
+ if (borders[3]) {
+ int offset_val = sao_offset_val[0];
+ ptrdiff_t y_stride_dst = stride_dst * (height - 1);
+ ptrdiff_t y_stride_src = stride_src * (height - 1);
+ for (x = init_x; x < width; x++)
+ dst[x + y_stride_dst] = av_clip_pixel(src[x + y_stride_src] + offset_val);
+ height--;
+ }
+ }
+
+ {
+ int save_upper_left = !diag_edge[0] && sao_eo_class == SAO_EO_135D && !borders[0] && !borders[1];
+ int save_upper_right = !diag_edge[1] && sao_eo_class == SAO_EO_45D && !borders[1] && !borders[2];
+ int save_lower_right = !diag_edge[2] && sao_eo_class == SAO_EO_135D && !borders[2] && !borders[3];
+ int save_lower_left = !diag_edge[3] && sao_eo_class == SAO_EO_45D && !borders[0] && !borders[3];
+
+ // Restore pixels that can't be modified
+ if(vert_edge[0] && sao_eo_class != SAO_EO_VERT) {
+ for(y = init_y+save_upper_left; y< height-save_lower_left; y++)
+ dst[y*stride_dst] = src[y*stride_src];
+ }
+ if(vert_edge[1] && sao_eo_class != SAO_EO_VERT) {
+ for(y = init_y+save_upper_right; y< height-save_lower_right; y++)
+ dst[y*stride_dst+width-1] = src[y*stride_src+width-1];
+ }
+
+ if(horiz_edge[0] && sao_eo_class != SAO_EO_HORIZ) {
+ for(x = init_x+save_upper_left; x < width-save_upper_right; x++)
+ dst[x] = src[x];
+ }
+ if(horiz_edge[1] && sao_eo_class != SAO_EO_HORIZ) {
+ for(x = init_x+save_lower_left; x < width-save_lower_right; x++)
+ dst[(height-1)*stride_dst+x] = src[(height-1)*stride_src+x];
+ }
+ if(diag_edge[0] && sao_eo_class == SAO_EO_135D)
+ dst[0] = src[0];
+ if(diag_edge[1] && sao_eo_class == SAO_EO_45D)
+ dst[width-1] = src[width-1];
+ if(diag_edge[2] && sao_eo_class == SAO_EO_135D)
+ dst[stride_dst*(height-1)+width-1] = src[stride_src*(height-1)+width-1];
+ if(diag_edge[3] && sao_eo_class == SAO_EO_45D)
+ dst[stride_dst*(height-1)] = src[stride_src*(height-1)];
+
+ }
+}
+
+#undef CMP
--
2.25.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 13+ messages in thread
* [FFmpeg-devel] [PATCH v2 1/4] hevcdec: move sao template to h26x/h2656_sao_template.c
2024-01-03 15:32 ` [FFmpeg-devel] [PATCH 1/4] hevcdec: move sao template to xvc_sao_template.c Nuo Mi
@ 2024-01-06 10:51 ` Nuo Mi
[not found] ` <20240106105132.31509-1-nuomi2021@gmail.com>
1 sibling, 0 replies; 13+ messages in thread
From: Nuo Mi @ 2024-01-06 10:51 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Nuo Mi
---
libavcodec/h26x/h2656_sao_template.c | 217 +++++++++++++++++++++++++++
libavcodec/hevcdsp_template.c | 196 +-----------------------
2 files changed, 218 insertions(+), 195 deletions(-)
create mode 100644 libavcodec/h26x/h2656_sao_template.c
diff --git a/libavcodec/h26x/h2656_sao_template.c b/libavcodec/h26x/h2656_sao_template.c
new file mode 100644
index 0000000000..b3eb8a3deb
--- /dev/null
+++ b/libavcodec/h26x/h2656_sao_template.c
@@ -0,0 +1,217 @@
+/*
+ * HEVC/VVC SAO template
+ *
+ * Copyright (C) 2024 Nuo Mi
+ * Copyright (C) 2012 - 2013 Guillaume Martres
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+static void FUNC(sao_band_filter)(uint8_t *_dst, const uint8_t *_src,
+ ptrdiff_t stride_dst, ptrdiff_t stride_src,
+ const int16_t *sao_offset_val, int sao_left_class,
+ int width, int height)
+{
+ pixel *dst = (pixel *)_dst;
+ const pixel *src = (const pixel *)_src;
+ int offset_table[32] = { 0 };
+ int k, y, x;
+ int shift = BIT_DEPTH - 5;
+
+ stride_dst /= sizeof(pixel);
+ stride_src /= sizeof(pixel);
+
+ for (k = 0; k < 4; k++)
+ offset_table[(k + sao_left_class) & 31] = sao_offset_val[k + 1];
+ for (y = 0; y < height; y++) {
+ for (x = 0; x < width; x++)
+ dst[x] = av_clip_pixel(src[x] + offset_table[(src[x] >> shift) & 31]);
+ dst += stride_dst;
+ src += stride_src;
+ }
+}
+
+#define CMP(a, b) (((a) > (b)) - ((a) < (b)))
+
+static void FUNC(sao_edge_filter)(uint8_t *_dst, const uint8_t *_src, ptrdiff_t stride_dst, const int16_t *sao_offset_val,
+ int eo, int width, int height) {
+
+ static const uint8_t edge_idx[] = { 1, 2, 0, 3, 4 };
+ static const int8_t pos[4][2][2] = {
+ { { -1, 0 }, { 1, 0 } }, // horizontal
+ { { 0, -1 }, { 0, 1 } }, // vertical
+ { { -1, -1 }, { 1, 1 } }, // 45 degree
+ { { 1, -1 }, { -1, 1 } }, // 135 degree
+ };
+ pixel *dst = (pixel *)_dst;
+ const pixel *src = (const pixel *)_src;
+ int a_stride, b_stride;
+ int x, y;
+ ptrdiff_t stride_src = (2*MAX_PB_SIZE + AV_INPUT_BUFFER_PADDING_SIZE) / sizeof(pixel);
+ stride_dst /= sizeof(pixel);
+
+ a_stride = pos[eo][0][0] + pos[eo][0][1] * stride_src;
+ b_stride = pos[eo][1][0] + pos[eo][1][1] * stride_src;
+ for (y = 0; y < height; y++) {
+ for (x = 0; x < width; x++) {
+ int diff0 = CMP(src[x], src[x + a_stride]);
+ int diff1 = CMP(src[x], src[x + b_stride]);
+ int offset_val = edge_idx[2 + diff0 + diff1];
+ dst[x] = av_clip_pixel(src[x] + sao_offset_val[offset_val]);
+ }
+ src += stride_src;
+ dst += stride_dst;
+ }
+}
+
+static void FUNC(sao_edge_restore_0)(uint8_t *_dst, const uint8_t *_src,
+ ptrdiff_t stride_dst, ptrdiff_t stride_src, const SAOParams *sao,
+ const int *borders, int _width, int _height,
+ int c_idx, const uint8_t *vert_edge,
+ const uint8_t *horiz_edge, const uint8_t *diag_edge)
+{
+ int x, y;
+ pixel *dst = (pixel *)_dst;
+ const pixel *src = (const pixel *)_src;
+ const int16_t *sao_offset_val = sao->offset_val[c_idx];
+ int sao_eo_class = sao->eo_class[c_idx];
+ int init_x = 0, width = _width, height = _height;
+
+ stride_dst /= sizeof(pixel);
+ stride_src /= sizeof(pixel);
+
+ if (sao_eo_class != SAO_EO_VERT) {
+ if (borders[0]) {
+ int offset_val = sao_offset_val[0];
+ for (y = 0; y < height; y++) {
+ dst[y * stride_dst] = av_clip_pixel(src[y * stride_src] + offset_val);
+ }
+ init_x = 1;
+ }
+ if (borders[2]) {
+ int offset_val = sao_offset_val[0];
+ int offset = width - 1;
+ for (x = 0; x < height; x++) {
+ dst[x * stride_dst + offset] = av_clip_pixel(src[x * stride_src + offset] + offset_val);
+ }
+ width--;
+ }
+ }
+ if (sao_eo_class != SAO_EO_HORIZ) {
+ if (borders[1]) {
+ int offset_val = sao_offset_val[0];
+ for (x = init_x; x < width; x++)
+ dst[x] = av_clip_pixel(src[x] + offset_val);
+ }
+ if (borders[3]) {
+ int offset_val = sao_offset_val[0];
+ ptrdiff_t y_stride_dst = stride_dst * (height - 1);
+ ptrdiff_t y_stride_src = stride_src * (height - 1);
+ for (x = init_x; x < width; x++)
+ dst[x + y_stride_dst] = av_clip_pixel(src[x + y_stride_src] + offset_val);
+ height--;
+ }
+ }
+}
+
+static void FUNC(sao_edge_restore_1)(uint8_t *_dst, const uint8_t *_src,
+ ptrdiff_t stride_dst, ptrdiff_t stride_src, const SAOParams *sao,
+ const int *borders, int _width, int _height,
+ int c_idx, const uint8_t *vert_edge,
+ const uint8_t *horiz_edge, const uint8_t *diag_edge)
+{
+ int x, y;
+ pixel *dst = (pixel *)_dst;
+ const pixel *src = (const pixel *)_src;
+ const int16_t *sao_offset_val = sao->offset_val[c_idx];
+ int sao_eo_class = sao->eo_class[c_idx];
+ int init_x = 0, init_y = 0, width = _width, height = _height;
+
+ stride_dst /= sizeof(pixel);
+ stride_src /= sizeof(pixel);
+
+ if (sao_eo_class != SAO_EO_VERT) {
+ if (borders[0]) {
+ int offset_val = sao_offset_val[0];
+ for (y = 0; y < height; y++) {
+ dst[y * stride_dst] = av_clip_pixel(src[y * stride_src] + offset_val);
+ }
+ init_x = 1;
+ }
+ if (borders[2]) {
+ int offset_val = sao_offset_val[0];
+ int offset = width - 1;
+ for (x = 0; x < height; x++) {
+ dst[x * stride_dst + offset] = av_clip_pixel(src[x * stride_src + offset] + offset_val);
+ }
+ width--;
+ }
+ }
+ if (sao_eo_class != SAO_EO_HORIZ) {
+ if (borders[1]) {
+ int offset_val = sao_offset_val[0];
+ for (x = init_x; x < width; x++)
+ dst[x] = av_clip_pixel(src[x] + offset_val);
+ init_y = 1;
+ }
+ if (borders[3]) {
+ int offset_val = sao_offset_val[0];
+ ptrdiff_t y_stride_dst = stride_dst * (height - 1);
+ ptrdiff_t y_stride_src = stride_src * (height - 1);
+ for (x = init_x; x < width; x++)
+ dst[x + y_stride_dst] = av_clip_pixel(src[x + y_stride_src] + offset_val);
+ height--;
+ }
+ }
+
+ {
+ int save_upper_left = !diag_edge[0] && sao_eo_class == SAO_EO_135D && !borders[0] && !borders[1];
+ int save_upper_right = !diag_edge[1] && sao_eo_class == SAO_EO_45D && !borders[1] && !borders[2];
+ int save_lower_right = !diag_edge[2] && sao_eo_class == SAO_EO_135D && !borders[2] && !borders[3];
+ int save_lower_left = !diag_edge[3] && sao_eo_class == SAO_EO_45D && !borders[0] && !borders[3];
+
+ // Restore pixels that can't be modified
+ if(vert_edge[0] && sao_eo_class != SAO_EO_VERT) {
+ for(y = init_y+save_upper_left; y< height-save_lower_left; y++)
+ dst[y*stride_dst] = src[y*stride_src];
+ }
+ if(vert_edge[1] && sao_eo_class != SAO_EO_VERT) {
+ for(y = init_y+save_upper_right; y< height-save_lower_right; y++)
+ dst[y*stride_dst+width-1] = src[y*stride_src+width-1];
+ }
+
+ if(horiz_edge[0] && sao_eo_class != SAO_EO_HORIZ) {
+ for(x = init_x+save_upper_left; x < width-save_upper_right; x++)
+ dst[x] = src[x];
+ }
+ if(horiz_edge[1] && sao_eo_class != SAO_EO_HORIZ) {
+ for(x = init_x+save_lower_left; x < width-save_lower_right; x++)
+ dst[(height-1)*stride_dst+x] = src[(height-1)*stride_src+x];
+ }
+ if(diag_edge[0] && sao_eo_class == SAO_EO_135D)
+ dst[0] = src[0];
+ if(diag_edge[1] && sao_eo_class == SAO_EO_45D)
+ dst[width-1] = src[width-1];
+ if(diag_edge[2] && sao_eo_class == SAO_EO_135D)
+ dst[stride_dst*(height-1)+width-1] = src[stride_src*(height-1)+width-1];
+ if(diag_edge[3] && sao_eo_class == SAO_EO_45D)
+ dst[stride_dst*(height-1)] = src[stride_src*(height-1)];
+
+ }
+}
+
+#undef CMP
diff --git a/libavcodec/hevcdsp_template.c b/libavcodec/hevcdsp_template.c
index 725fab99ed..2ff1776b92 100644
--- a/libavcodec/hevcdsp_template.c
+++ b/libavcodec/hevcdsp_template.c
@@ -25,6 +25,7 @@
#include "bit_depth_template.c"
#include "hevcdsp.h"
+#include "h26x/h2656_sao_template.c"
static void FUNC(put_pcm)(uint8_t *_dst, ptrdiff_t stride, int width, int height,
GetBitContext *gb, int pcm_bit_depth)
@@ -295,201 +296,6 @@ IDCT_DC(32)
#undef SET
#undef SCALE
-static void FUNC(sao_band_filter)(uint8_t *_dst, const uint8_t *_src,
- ptrdiff_t stride_dst, ptrdiff_t stride_src,
- const int16_t *sao_offset_val, int sao_left_class,
- int width, int height)
-{
- pixel *dst = (pixel *)_dst;
- const pixel *src = (const pixel *)_src;
- int offset_table[32] = { 0 };
- int k, y, x;
- int shift = BIT_DEPTH - 5;
-
- stride_dst /= sizeof(pixel);
- stride_src /= sizeof(pixel);
-
- for (k = 0; k < 4; k++)
- offset_table[(k + sao_left_class) & 31] = sao_offset_val[k + 1];
- for (y = 0; y < height; y++) {
- for (x = 0; x < width; x++)
- dst[x] = av_clip_pixel(src[x] + offset_table[(src[x] >> shift) & 31]);
- dst += stride_dst;
- src += stride_src;
- }
-}
-
-#define CMP(a, b) (((a) > (b)) - ((a) < (b)))
-
-static void FUNC(sao_edge_filter)(uint8_t *_dst, const uint8_t *_src, ptrdiff_t stride_dst, const int16_t *sao_offset_val,
- int eo, int width, int height) {
-
- static const uint8_t edge_idx[] = { 1, 2, 0, 3, 4 };
- static const int8_t pos[4][2][2] = {
- { { -1, 0 }, { 1, 0 } }, // horizontal
- { { 0, -1 }, { 0, 1 } }, // vertical
- { { -1, -1 }, { 1, 1 } }, // 45 degree
- { { 1, -1 }, { -1, 1 } }, // 135 degree
- };
- pixel *dst = (pixel *)_dst;
- const pixel *src = (const pixel *)_src;
- int a_stride, b_stride;
- int x, y;
- ptrdiff_t stride_src = (2*MAX_PB_SIZE + AV_INPUT_BUFFER_PADDING_SIZE) / sizeof(pixel);
- stride_dst /= sizeof(pixel);
-
- a_stride = pos[eo][0][0] + pos[eo][0][1] * stride_src;
- b_stride = pos[eo][1][0] + pos[eo][1][1] * stride_src;
- for (y = 0; y < height; y++) {
- for (x = 0; x < width; x++) {
- int diff0 = CMP(src[x], src[x + a_stride]);
- int diff1 = CMP(src[x], src[x + b_stride]);
- int offset_val = edge_idx[2 + diff0 + diff1];
- dst[x] = av_clip_pixel(src[x] + sao_offset_val[offset_val]);
- }
- src += stride_src;
- dst += stride_dst;
- }
-}
-
-static void FUNC(sao_edge_restore_0)(uint8_t *_dst, const uint8_t *_src,
- ptrdiff_t stride_dst, ptrdiff_t stride_src, const SAOParams *sao,
- const int *borders, int _width, int _height,
- int c_idx, const uint8_t *vert_edge,
- const uint8_t *horiz_edge, const uint8_t *diag_edge)
-{
- int x, y;
- pixel *dst = (pixel *)_dst;
- const pixel *src = (const pixel *)_src;
- const int16_t *sao_offset_val = sao->offset_val[c_idx];
- int sao_eo_class = sao->eo_class[c_idx];
- int init_x = 0, width = _width, height = _height;
-
- stride_dst /= sizeof(pixel);
- stride_src /= sizeof(pixel);
-
- if (sao_eo_class != SAO_EO_VERT) {
- if (borders[0]) {
- int offset_val = sao_offset_val[0];
- for (y = 0; y < height; y++) {
- dst[y * stride_dst] = av_clip_pixel(src[y * stride_src] + offset_val);
- }
- init_x = 1;
- }
- if (borders[2]) {
- int offset_val = sao_offset_val[0];
- int offset = width - 1;
- for (x = 0; x < height; x++) {
- dst[x * stride_dst + offset] = av_clip_pixel(src[x * stride_src + offset] + offset_val);
- }
- width--;
- }
- }
- if (sao_eo_class != SAO_EO_HORIZ) {
- if (borders[1]) {
- int offset_val = sao_offset_val[0];
- for (x = init_x; x < width; x++)
- dst[x] = av_clip_pixel(src[x] + offset_val);
- }
- if (borders[3]) {
- int offset_val = sao_offset_val[0];
- ptrdiff_t y_stride_dst = stride_dst * (height - 1);
- ptrdiff_t y_stride_src = stride_src * (height - 1);
- for (x = init_x; x < width; x++)
- dst[x + y_stride_dst] = av_clip_pixel(src[x + y_stride_src] + offset_val);
- height--;
- }
- }
-}
-
-static void FUNC(sao_edge_restore_1)(uint8_t *_dst, const uint8_t *_src,
- ptrdiff_t stride_dst, ptrdiff_t stride_src, const SAOParams *sao,
- const int *borders, int _width, int _height,
- int c_idx, const uint8_t *vert_edge,
- const uint8_t *horiz_edge, const uint8_t *diag_edge)
-{
- int x, y;
- pixel *dst = (pixel *)_dst;
- const pixel *src = (const pixel *)_src;
- const int16_t *sao_offset_val = sao->offset_val[c_idx];
- int sao_eo_class = sao->eo_class[c_idx];
- int init_x = 0, init_y = 0, width = _width, height = _height;
-
- stride_dst /= sizeof(pixel);
- stride_src /= sizeof(pixel);
-
- if (sao_eo_class != SAO_EO_VERT) {
- if (borders[0]) {
- int offset_val = sao_offset_val[0];
- for (y = 0; y < height; y++) {
- dst[y * stride_dst] = av_clip_pixel(src[y * stride_src] + offset_val);
- }
- init_x = 1;
- }
- if (borders[2]) {
- int offset_val = sao_offset_val[0];
- int offset = width - 1;
- for (x = 0; x < height; x++) {
- dst[x * stride_dst + offset] = av_clip_pixel(src[x * stride_src + offset] + offset_val);
- }
- width--;
- }
- }
- if (sao_eo_class != SAO_EO_HORIZ) {
- if (borders[1]) {
- int offset_val = sao_offset_val[0];
- for (x = init_x; x < width; x++)
- dst[x] = av_clip_pixel(src[x] + offset_val);
- init_y = 1;
- }
- if (borders[3]) {
- int offset_val = sao_offset_val[0];
- ptrdiff_t y_stride_dst = stride_dst * (height - 1);
- ptrdiff_t y_stride_src = stride_src * (height - 1);
- for (x = init_x; x < width; x++)
- dst[x + y_stride_dst] = av_clip_pixel(src[x + y_stride_src] + offset_val);
- height--;
- }
- }
-
- {
- int save_upper_left = !diag_edge[0] && sao_eo_class == SAO_EO_135D && !borders[0] && !borders[1];
- int save_upper_right = !diag_edge[1] && sao_eo_class == SAO_EO_45D && !borders[1] && !borders[2];
- int save_lower_right = !diag_edge[2] && sao_eo_class == SAO_EO_135D && !borders[2] && !borders[3];
- int save_lower_left = !diag_edge[3] && sao_eo_class == SAO_EO_45D && !borders[0] && !borders[3];
-
- // Restore pixels that can't be modified
- if(vert_edge[0] && sao_eo_class != SAO_EO_VERT) {
- for(y = init_y+save_upper_left; y< height-save_lower_left; y++)
- dst[y*stride_dst] = src[y*stride_src];
- }
- if(vert_edge[1] && sao_eo_class != SAO_EO_VERT) {
- for(y = init_y+save_upper_right; y< height-save_lower_right; y++)
- dst[y*stride_dst+width-1] = src[y*stride_src+width-1];
- }
-
- if(horiz_edge[0] && sao_eo_class != SAO_EO_HORIZ) {
- for(x = init_x+save_upper_left; x < width-save_upper_right; x++)
- dst[x] = src[x];
- }
- if(horiz_edge[1] && sao_eo_class != SAO_EO_HORIZ) {
- for(x = init_x+save_lower_left; x < width-save_lower_right; x++)
- dst[(height-1)*stride_dst+x] = src[(height-1)*stride_src+x];
- }
- if(diag_edge[0] && sao_eo_class == SAO_EO_135D)
- dst[0] = src[0];
- if(diag_edge[1] && sao_eo_class == SAO_EO_45D)
- dst[width-1] = src[width-1];
- if(diag_edge[2] && sao_eo_class == SAO_EO_135D)
- dst[stride_dst*(height-1)+width-1] = src[stride_src*(height-1)+width-1];
- if(diag_edge[3] && sao_eo_class == SAO_EO_45D)
- dst[stride_dst*(height-1)] = src[stride_src*(height-1)];
-
- }
-}
-
-#undef CMP
-
////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////
--
2.25.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 13+ messages in thread
[parent not found: <20240106105132.31509-1-nuomi2021@gmail.com>]
* [FFmpeg-devel] [PATCH v2 2/4] vvcdec: reuse h26x/h2656_sao_template.c
[not found] ` <20240106105132.31509-1-nuomi2021@gmail.com>
@ 2024-01-06 10:51 ` Nuo Mi
2024-01-06 10:51 ` [FFmpeg-devel] [PATCH v2 3/4] hevcdec: move deblock template to h26x/h2656_deblock_template.c Nuo Mi
2024-01-06 10:51 ` [FFmpeg-devel] [PATCH v2 4/4] vvcdec: reuse h26x/h2656_deblock_template.c Nuo Mi
2 siblings, 0 replies; 13+ messages in thread
From: Nuo Mi @ 2024-01-06 10:51 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Nuo Mi
---
libavcodec/vvc/vvc_filter_template.c | 193 +--------------------------
1 file changed, 2 insertions(+), 191 deletions(-)
diff --git a/libavcodec/vvc/vvc_filter_template.c b/libavcodec/vvc/vvc_filter_template.c
index a4f1792ec4..9418980c33 100644
--- a/libavcodec/vvc/vvc_filter_template.c
+++ b/libavcodec/vvc/vvc_filter_template.c
@@ -20,6 +20,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "libavcodec/h26x/h2656_sao_template.c"
+
static void FUNC(lmcs_filter_luma)(uint8_t *_dst, ptrdiff_t dst_stride, const int width, const int height, const uint8_t *_lut)
{
const pixel *lut = (const pixel *)_lut;
@@ -33,197 +35,6 @@ static void FUNC(lmcs_filter_luma)(uint8_t *_dst, ptrdiff_t dst_stride, const in
}
}
-static void FUNC(sao_band_filter)(uint8_t *_dst, const uint8_t *_src, ptrdiff_t dst_stride, ptrdiff_t src_stride,
- const int16_t *sao_offset_val, const int sao_left_class, const int width, const int height)
-{
- pixel *dst = (pixel *)_dst;
- const pixel *src = (pixel *)_src;
- int offset_table[32] = { 0 };
- int k, y, x;
- int shift = BIT_DEPTH - 5;
-
- dst_stride /= sizeof(pixel);
- src_stride /= sizeof(pixel);
-
- for (k = 0; k < 4; k++)
- offset_table[(k + sao_left_class) & 31] = sao_offset_val[k + 1];
- for (y = 0; y < height; y++) {
- for (x = 0; x < width; x++)
- dst[x] = av_clip_pixel(src[x] + offset_table[src[x] >> shift]);
- dst += dst_stride;
- src += src_stride;
- }
-}
-
-#define CMP(a, b) (((a) > (b)) - ((a) < (b)))
-
-static void FUNC(sao_edge_filter)(uint8_t *_dst, const uint8_t *_src, ptrdiff_t dst_stride,
- const int16_t *sao_offset_val, const int eo, const int width, const int height)
-{
- static const uint8_t edge_idx[] = { 1, 2, 0, 3, 4 };
- static const int8_t pos[4][2][2] = {
- { { -1, 0 }, { 1, 0 } }, // horizontal
- { { 0, -1 }, { 0, 1 } }, // vertical
- { { -1, -1 }, { 1, 1 } }, // 45 degree
- { { 1, -1 }, { -1, 1 } }, // 135 degree
- };
- pixel *dst = (pixel *)_dst;
- const pixel *src = (pixel *)_src;
- int a_stride, b_stride;
- int x, y;
- ptrdiff_t src_stride = (2 * MAX_PB_SIZE + AV_INPUT_BUFFER_PADDING_SIZE) / sizeof(pixel);
- dst_stride /= sizeof(pixel);
-
- a_stride = pos[eo][0][0] + pos[eo][0][1] * src_stride;
- b_stride = pos[eo][1][0] + pos[eo][1][1] * src_stride;
- for (y = 0; y < height; y++) {
- for (x = 0; x < width; x++) {
- int diff0 = CMP(src[x], src[x + a_stride]);
- int diff1 = CMP(src[x], src[x + b_stride]);
- int offset_val = edge_idx[2 + diff0 + diff1];
- dst[x] = av_clip_pixel(src[x] + sao_offset_val[offset_val]);
- }
- src += src_stride;
- dst += dst_stride;
- }
-}
-
-static void FUNC(sao_edge_restore_0)(uint8_t *_dst, const uint8_t *_src,
- ptrdiff_t dst_stride, ptrdiff_t src_stride, const SAOParams *sao,
- const int *borders, const int _width, const int _height, const int c_idx,
- const uint8_t *vert_edge, const uint8_t *horiz_edge, const uint8_t *diag_edge)
-{
- int x, y;
- pixel *dst = (pixel *)_dst;
- const pixel *src = (pixel *)_src;
- const int16_t *sao_offset_val = sao->offset_val[c_idx];
- const int sao_eo_class = sao->eo_class[c_idx];
- int init_x = 0, width = _width, height = _height;
-
- dst_stride /= sizeof(pixel);
- src_stride /= sizeof(pixel);
-
- if (sao_eo_class != SAO_EO_VERT) {
- if (borders[0]) {
- int offset_val = sao_offset_val[0];
- for (y = 0; y < height; y++) {
- dst[y * dst_stride] = av_clip_pixel(src[y * src_stride] + offset_val);
- }
- init_x = 1;
- }
- if (borders[2]) {
- int offset_val = sao_offset_val[0];
- int offset = width - 1;
- for (x = 0; x < height; x++) {
- dst[x * dst_stride + offset] = av_clip_pixel(src[x * src_stride + offset] + offset_val);
- }
- width--;
- }
- }
- if (sao_eo_class != SAO_EO_HORIZ) {
- if (borders[1]) {
- int offset_val = sao_offset_val[0];
- for (x = init_x; x < width; x++)
- dst[x] = av_clip_pixel(src[x] + offset_val);
- }
- if (borders[3]) {
- int offset_val = sao_offset_val[0];
- ptrdiff_t y_dst_stride = dst_stride * (height - 1);
- ptrdiff_t y_src_stride = src_stride * (height - 1);
- for (x = init_x; x < width; x++)
- dst[x + y_dst_stride] = av_clip_pixel(src[x + y_src_stride] + offset_val);
- height--;
- }
- }
-}
-
-static void FUNC(sao_edge_restore_1)(uint8_t *_dst, const uint8_t *_src,
- ptrdiff_t dst_stride, ptrdiff_t src_stride, const SAOParams *sao,
- const int *borders, const int _width, const int _height, const int c_idx,
- const uint8_t *vert_edge, const uint8_t *horiz_edge, const uint8_t *diag_edge)
-{
- int x, y;
- pixel *dst = (pixel *)_dst;
- const pixel *src = (pixel *)_src;
- const int16_t *sao_offset_val = sao->offset_val[c_idx];
- const int sao_eo_class = sao->eo_class[c_idx];
- int init_x = 0, init_y = 0, width = _width, height = _height;
-
- dst_stride /= sizeof(pixel);
- src_stride /= sizeof(pixel);
-
- if (sao_eo_class != SAO_EO_VERT) {
- if (borders[0]) {
- int offset_val = sao_offset_val[0];
- for (y = 0; y < height; y++) {
- dst[y * dst_stride] = av_clip_pixel(src[y * src_stride] + offset_val);
- }
- init_x = 1;
- }
- if (borders[2]) {
- int offset_val = sao_offset_val[0];
- int offset = width - 1;
- for (x = 0; x < height; x++) {
- dst[x * dst_stride + offset] = av_clip_pixel(src[x * src_stride + offset] + offset_val);
- }
- width--;
- }
- }
- if (sao_eo_class != SAO_EO_HORIZ) {
- if (borders[1]) {
- int offset_val = sao_offset_val[0];
- for (x = init_x; x < width; x++)
- dst[x] = av_clip_pixel(src[x] + offset_val);
- init_y = 1;
- }
- if (borders[3]) {
- int offset_val = sao_offset_val[0];
- ptrdiff_t y_dst_stride = dst_stride * (height - 1);
- ptrdiff_t y_src_stride = src_stride * (height - 1);
- for (x = init_x; x < width; x++)
- dst[x + y_dst_stride] = av_clip_pixel(src[x + y_src_stride] + offset_val);
- height--;
- }
- }
-
- {
- int save_upper_left = !diag_edge[0] && sao_eo_class == SAO_EO_135D && !borders[0] && !borders[1];
- int save_upper_right = !diag_edge[1] && sao_eo_class == SAO_EO_45D && !borders[1] && !borders[2];
- int save_lower_right = !diag_edge[2] && sao_eo_class == SAO_EO_135D && !borders[2] && !borders[3];
- int save_lower_left = !diag_edge[3] && sao_eo_class == SAO_EO_45D && !borders[0] && !borders[3];
-
- // Restore pixels that can't be modified
- if (vert_edge[0] && sao_eo_class != SAO_EO_VERT) {
- for (y = init_y + save_upper_left; y < height - save_lower_left; y++)
- dst[y * dst_stride] = src[y * src_stride];
- }
- if (vert_edge[1] && sao_eo_class != SAO_EO_VERT) {
- for (y = init_y + save_upper_right; y < height - save_lower_right; y++)
- dst[y * dst_stride + width - 1] = src[y * src_stride + width - 1];
- }
-
- if (horiz_edge[0] && sao_eo_class != SAO_EO_HORIZ) {
- for (x = init_x + save_upper_left; x < width - save_upper_right; x++)
- dst[x] = src[x];
- }
- if (horiz_edge[1] && sao_eo_class != SAO_EO_HORIZ) {
- for (x = init_x + save_lower_left; x < width - save_lower_right; x++)
- dst[(height - 1) * dst_stride + x] = src[(height - 1) * src_stride + x];
- }
- if (diag_edge[0] && sao_eo_class == SAO_EO_135D)
- dst[0] = src[0];
- if (diag_edge[1] && sao_eo_class == SAO_EO_45D)
- dst[width - 1] = src[width - 1];
- if (diag_edge[2] && sao_eo_class == SAO_EO_135D)
- dst[dst_stride * (height - 1) + width - 1] = src[src_stride * (height - 1) + width - 1];
- if (diag_edge[3] && sao_eo_class == SAO_EO_45D)
- dst[dst_stride * (height - 1)] = src[src_stride * (height - 1)];
-
- }
-}
-
-#undef CMP
-
static av_always_inline int16_t FUNC(alf_clip)(pixel curr, pixel v0, pixel v1, int16_t clip)
{
return av_clip(v0 - curr, -clip, clip) + av_clip(v1 - curr, -clip, clip);
--
2.25.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 13+ messages in thread
* [FFmpeg-devel] [PATCH v2 3/4] hevcdec: move deblock template to h26x/h2656_deblock_template.c
[not found] ` <20240106105132.31509-1-nuomi2021@gmail.com>
2024-01-06 10:51 ` [FFmpeg-devel] [PATCH v2 2/4] vvcdec: reuse h26x/h2656_sao_template.c Nuo Mi
@ 2024-01-06 10:51 ` Nuo Mi
2024-01-06 10:51 ` [FFmpeg-devel] [PATCH v2 4/4] vvcdec: reuse h26x/h2656_deblock_template.c Nuo Mi
2 siblings, 0 replies; 13+ messages in thread
From: Nuo Mi @ 2024-01-06 10:51 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Nuo Mi
---
libavcodec/h26x/h2656_deblock_template.c | 99 ++++++++++++++++++++++++
libavcodec/hevcdsp_template.c | 96 ++++-------------------
2 files changed, 116 insertions(+), 79 deletions(-)
create mode 100644 libavcodec/h26x/h2656_deblock_template.c
diff --git a/libavcodec/h26x/h2656_deblock_template.c b/libavcodec/h26x/h2656_deblock_template.c
new file mode 100644
index 0000000000..8ed95e754d
--- /dev/null
+++ b/libavcodec/h26x/h2656_deblock_template.c
@@ -0,0 +1,99 @@
+
+/*
+ * HEVC/VVC deblocking dsp template
+ *
+ * Copyright (C) 2024 Nuo Mi
+ * Copyright (C) 2012 - 2013 Guillaume Martres
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+static void FUNC(loop_filter_luma_strong)(pixel *pix, const ptrdiff_t xstride, const ptrdiff_t ystride,
+ const int32_t tc, const int32_t tc2, const int tc3,
+ const uint8_t no_p, const uint8_t no_q)
+{
+ for (int d = 0; d < 4; d++) {
+ const int p3 = P3;
+ const int p2 = P2;
+ const int p1 = P1;
+ const int p0 = P0;
+ const int q0 = Q0;
+ const int q1 = Q1;
+ const int q2 = Q2;
+ const int q3 = Q3;
+ if (!no_p) {
+ P0 = p0 + av_clip(((p2 + 2 * p1 + 2 * p0 + 2 * q0 + q1 + 4) >> 3) - p0, -tc3, tc3);
+ P1 = p1 + av_clip(((p2 + p1 + p0 + q0 + 2) >> 2) - p1, -tc2, tc2);
+ P2 = p2 + av_clip(((2 * p3 + 3 * p2 + p1 + p0 + q0 + 4) >> 3) - p2, -tc, tc);
+ }
+ if (!no_q) {
+ Q0 = q0 + av_clip(((p1 + 2 * p0 + 2 * q0 + 2 * q1 + q2 + 4) >> 3) - q0, -tc3, tc3);
+ Q1 = q1 + av_clip(((p0 + q0 + q1 + q2 + 2) >> 2) - q1, -tc2, tc2);
+ Q2 = q2 + av_clip(((2 * q3 + 3 * q2 + q1 + q0 + p0 + 4) >> 3) - q2, -tc, tc);
+ }
+ pix += ystride;
+ }
+}
+
+static void FUNC(loop_filter_luma_weak)(pixel *pix, const ptrdiff_t xstride, const ptrdiff_t ystride,
+ const int32_t tc, const int32_t beta, const uint8_t no_p, const uint8_t no_q, const int nd_p, const int nd_q)
+{
+ const int tc_2 = tc >> 1;
+ for (int d = 0; d < 4; d++) {
+ const int p2 = P2;
+ const int p1 = P1;
+ const int p0 = P0;
+ const int q0 = Q0;
+ const int q1 = Q1;
+ const int q2 = Q2;
+ int delta0 = (9 * (q0 - p0) - 3 * (q1 - p1) + 8) >> 4;
+ if (abs(delta0) < 10 * tc) {
+ delta0 = av_clip(delta0, -tc, tc);
+ if (!no_p)
+ P0 = av_clip_pixel(p0 + delta0);
+ if (!no_q)
+ Q0 = av_clip_pixel(q0 - delta0);
+ if (!no_p && nd_p > 1) {
+ const int deltap1 = av_clip((((p2 + p0 + 1) >> 1) - p1 + delta0) >> 1, -tc_2, tc_2);
+ P1 = av_clip_pixel(p1 + deltap1);
+ }
+ if (!no_q && nd_q > 1) {
+ const int deltaq1 = av_clip((((q2 + q0 + 1) >> 1) - q1 - delta0) >> 1, -tc_2, tc_2);
+ Q1 = av_clip_pixel(q1 + deltaq1);
+ }
+ }
+ pix += ystride;
+ }
+}
+
+static void FUNC(loop_filter_chroma_weak)(pixel *pix, const ptrdiff_t xstride, const ptrdiff_t ystride,
+ const int size, const int32_t tc, const uint8_t no_p, const uint8_t no_q)
+{
+ for (int d = 0; d < size; d++) {
+ int delta0;
+ const int p1 = P1;
+ const int p0 = P0;
+ const int q0 = Q0;
+ const int q1 = Q1;
+ delta0 = av_clip((((q0 - p0) * 4) + p1 - q1 + 4) >> 3, -tc, tc);
+ if (!no_p)
+ P0 = av_clip_pixel(p0 + delta0);
+ if (!no_q)
+ Q0 = av_clip_pixel(q0 - delta0);
+ pix += ystride;
+ }
+}
diff --git a/libavcodec/hevcdsp_template.c b/libavcodec/hevcdsp_template.c
index 2ff1776b92..0de14e9dcf 100644
--- a/libavcodec/hevcdsp_template.c
+++ b/libavcodec/hevcdsp_template.c
@@ -1319,19 +1319,20 @@ static void FUNC(put_hevc_epel_bi_w_hv)(uint8_t *_dst, ptrdiff_t _dststride,
#define TQ2 pix[2 * xstride + 3 * ystride]
#define TQ3 pix[3 * xstride + 3 * ystride]
+#include "h26x/h2656_deblock_template.c"
+
static void FUNC(hevc_loop_filter_luma)(uint8_t *_pix,
ptrdiff_t _xstride, ptrdiff_t _ystride,
int beta, const int *_tc,
const uint8_t *_no_p, const uint8_t *_no_q)
{
- int d, j;
- pixel *pix = (pixel *)_pix;
ptrdiff_t xstride = _xstride / sizeof(pixel);
ptrdiff_t ystride = _ystride / sizeof(pixel);
beta <<= BIT_DEPTH - 8;
- for (j = 0; j < 2; j++) {
+ for (int j = 0; j < 2; j++) {
+ pixel* pix = (pixel*)_pix + j * 4 * ystride;
const int dp0 = abs(P2 - 2 * P1 + P0);
const int dq0 = abs(Q2 - 2 * Q1 + Q0);
const int dp3 = abs(TP2 - 2 * TP1 + TP0);
@@ -1342,10 +1343,7 @@ static void FUNC(hevc_loop_filter_luma)(uint8_t *_pix,
const int no_p = _no_p[j];
const int no_q = _no_q[j];
- if (d0 + d3 >= beta) {
- pix += 4 * ystride;
- continue;
- } else {
+ if (d0 + d3 < beta) {
const int beta_3 = beta >> 3;
const int beta_2 = beta >> 2;
const int tc25 = ((tc * 5 + 1) >> 1);
@@ -1353,63 +1351,16 @@ static void FUNC(hevc_loop_filter_luma)(uint8_t *_pix,
if (abs(P3 - P0) + abs(Q3 - Q0) < beta_3 && abs(P0 - Q0) < tc25 &&
abs(TP3 - TP0) + abs(TQ3 - TQ0) < beta_3 && abs(TP0 - TQ0) < tc25 &&
(d0 << 1) < beta_2 && (d3 << 1) < beta_2) {
- // strong filtering
const int tc2 = tc << 1;
- for (d = 0; d < 4; d++) {
- const int p3 = P3;
- const int p2 = P2;
- const int p1 = P1;
- const int p0 = P0;
- const int q0 = Q0;
- const int q1 = Q1;
- const int q2 = Q2;
- const int q3 = Q3;
- if (!no_p) {
- P0 = p0 + av_clip(((p2 + 2 * p1 + 2 * p0 + 2 * q0 + q1 + 4) >> 3) - p0, -tc2, tc2);
- P1 = p1 + av_clip(((p2 + p1 + p0 + q0 + 2) >> 2) - p1, -tc2, tc2);
- P2 = p2 + av_clip(((2 * p3 + 3 * p2 + p1 + p0 + q0 + 4) >> 3) - p2, -tc2, tc2);
- }
- if (!no_q) {
- Q0 = q0 + av_clip(((p1 + 2 * p0 + 2 * q0 + 2 * q1 + q2 + 4) >> 3) - q0, -tc2, tc2);
- Q1 = q1 + av_clip(((p0 + q0 + q1 + q2 + 2) >> 2) - q1, -tc2, tc2);
- Q2 = q2 + av_clip(((2 * q3 + 3 * q2 + q1 + q0 + p0 + 4) >> 3) - q2, -tc2, tc2);
- }
- pix += ystride;
- }
- } else { // normal filtering
+ FUNC(loop_filter_luma_strong)(pix, xstride, ystride, tc2, tc2, tc2, no_p, no_q);
+ } else {
int nd_p = 1;
int nd_q = 1;
- const int tc_2 = tc >> 1;
if (dp0 + dp3 < ((beta + (beta >> 1)) >> 3))
nd_p = 2;
if (dq0 + dq3 < ((beta + (beta >> 1)) >> 3))
nd_q = 2;
-
- for (d = 0; d < 4; d++) {
- const int p2 = P2;
- const int p1 = P1;
- const int p0 = P0;
- const int q0 = Q0;
- const int q1 = Q1;
- const int q2 = Q2;
- int delta0 = (9 * (q0 - p0) - 3 * (q1 - p1) + 8) >> 4;
- if (abs(delta0) < 10 * tc) {
- delta0 = av_clip(delta0, -tc, tc);
- if (!no_p)
- P0 = av_clip_pixel(p0 + delta0);
- if (!no_q)
- Q0 = av_clip_pixel(q0 - delta0);
- if (!no_p && nd_p > 1) {
- const int deltap1 = av_clip((((p2 + p0 + 1) >> 1) - p1 + delta0) >> 1, -tc_2, tc_2);
- P1 = av_clip_pixel(p1 + deltap1);
- }
- if (!no_q && nd_q > 1) {
- const int deltaq1 = av_clip((((q2 + q0 + 1) >> 1) - q1 - delta0) >> 1, -tc_2, tc_2);
- Q1 = av_clip_pixel(q1 + deltaq1);
- }
- }
- pix += ystride;
- }
+ FUNC(loop_filter_luma_weak)(pix, xstride, ystride, tc, beta, no_p, no_q, nd_p, nd_q);
}
}
}
@@ -1419,32 +1370,19 @@ static void FUNC(hevc_loop_filter_chroma)(uint8_t *_pix, ptrdiff_t _xstride,
ptrdiff_t _ystride, const int *_tc,
const uint8_t *_no_p, const uint8_t *_no_q)
{
- int d, j, no_p, no_q;
- pixel *pix = (pixel *)_pix;
+ int no_p, no_q;
ptrdiff_t xstride = _xstride / sizeof(pixel);
ptrdiff_t ystride = _ystride / sizeof(pixel);
+ const int size = 4;
- for (j = 0; j < 2; j++) {
+ for (int j = 0; j < 2; j++) {
+ pixel *pix = (pixel *)_pix + j * size * ystride;
const int tc = _tc[j] << (BIT_DEPTH - 8);
- if (tc <= 0) {
- pix += 4 * ystride;
- continue;
- }
- no_p = _no_p[j];
- no_q = _no_q[j];
-
- for (d = 0; d < 4; d++) {
- int delta0;
- const int p1 = P1;
- const int p0 = P0;
- const int q0 = Q0;
- const int q1 = Q1;
- delta0 = av_clip((((q0 - p0) * 4) + p1 - q1 + 4) >> 3, -tc, tc);
- if (!no_p)
- P0 = av_clip_pixel(p0 + delta0);
- if (!no_q)
- Q0 = av_clip_pixel(q0 - delta0);
- pix += ystride;
+ if (tc > 0) {
+ no_p = _no_p[j];
+ no_q = _no_q[j];
+
+ FUNC(loop_filter_chroma_weak)(pix, xstride, ystride, size, tc, no_p, no_q);
}
}
}
--
2.25.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 13+ messages in thread
* [FFmpeg-devel] [PATCH v2 4/4] vvcdec: reuse h26x/h2656_deblock_template.c
[not found] ` <20240106105132.31509-1-nuomi2021@gmail.com>
2024-01-06 10:51 ` [FFmpeg-devel] [PATCH v2 2/4] vvcdec: reuse h26x/h2656_sao_template.c Nuo Mi
2024-01-06 10:51 ` [FFmpeg-devel] [PATCH v2 3/4] hevcdec: move deblock template to h26x/h2656_deblock_template.c Nuo Mi
@ 2024-01-06 10:51 ` Nuo Mi
2024-01-09 1:02 ` Nuo Mi
2 siblings, 1 reply; 13+ messages in thread
From: Nuo Mi @ 2024-01-06 10:51 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Nuo Mi
---
libavcodec/vvc/vvc_filter_template.c | 82 +---------------------------
1 file changed, 3 insertions(+), 79 deletions(-)
diff --git a/libavcodec/vvc/vvc_filter_template.c b/libavcodec/vvc/vvc_filter_template.c
index 9418980c33..671ed7de4e 100644
--- a/libavcodec/vvc/vvc_filter_template.c
+++ b/libavcodec/vvc/vvc_filter_template.c
@@ -461,6 +461,8 @@ static void FUNC(alf_recon_coeff_and_clip)(int16_t *coeff, int16_t *clip,
#define FQ2 pix[2 * xstride + 1 * ystride]
#define FQ3 pix[3 * xstride + 1 * ystride]
+#include "libavcodec/h26x/h2656_deblock_template.c"
+
static void FUNC(loop_filter_luma_large)(pixel *pix, const ptrdiff_t xstride, const ptrdiff_t ystride, const int32_t tc,
const uint8_t no_p, const uint8_t no_q, const uint8_t max_len_p, const uint8_t max_len_q)
{
@@ -541,66 +543,6 @@ static void FUNC(loop_filter_luma_large)(pixel *pix, const ptrdiff_t xstride, co
}
}
-static void FUNC(loop_filter_luma_strong)(pixel *pix, const ptrdiff_t xstride, const ptrdiff_t ystride, const int32_t tc,
- const uint8_t no_p, const uint8_t no_q)
-{
- const int tc2 = tc << 1;
- const int tc3 = tc * 3;
- for (int d = 0; d < 4; d++) {
- const int p3 = P3;
- const int p2 = P2;
- const int p1 = P1;
- const int p0 = P0;
- const int q0 = Q0;
- const int q1 = Q1;
- const int q2 = Q2;
- const int q3 = Q3;
- if (!no_p) {
- P0 = p0 + av_clip(((p2 + 2 * p1 + 2 * p0 + 2 * q0 + q1 + 4) >> 3) - p0, -tc3, tc3);
- P1 = p1 + av_clip(((p2 + p1 + p0 + q0 + 2) >> 2) - p1, -tc2, tc2);
- P2 = p2 + av_clip(((2 * p3 + 3 * p2 + p1 + p0 + q0 + 4) >> 3) - p2, -tc, tc);
- }
- if (!no_q) {
- Q0 = q0 + av_clip(((p1 + 2 * p0 + 2 * q0 + 2 * q1 + q2 + 4) >> 3) - q0, -tc3, tc3);
- Q1 = q1 + av_clip(((p0 + q0 + q1 + q2 + 2) >> 2) - q1, -tc2, tc2);
- Q2 = q2 + av_clip(((2 * q3 + 3 * q2 + q1 + q0 + p0 + 4) >> 3) - q2, -tc, tc);
- }
- pix += ystride;
- }
-}
-
-static void FUNC(loop_filter_luma_weak)(pixel *pix, const ptrdiff_t xstride, const ptrdiff_t ystride,
- const int32_t tc, const int32_t beta, const uint8_t no_p, const uint8_t no_q, const int nd_p, const int nd_q)
-{
- const int tc_2 = tc >> 1;
- for (int d = 0; d < 4; d++) {
- const int p2 = P2;
- const int p1 = P1;
- const int p0 = P0;
- const int q0 = Q0;
- const int q1 = Q1;
- const int q2 = Q2;
- int delta0 = (9 * (q0 - p0) - 3 * (q1 - p1) + 8) >> 4;
- if (abs(delta0) < 10 * tc) {
- delta0 = av_clip(delta0, -tc, tc);
- if (!no_p)
- P0 = av_clip_pixel(p0 + delta0);
- if (!no_q)
- Q0 = av_clip_pixel(q0 - delta0);
- if (!no_p && nd_p > 1) {
- const int deltap1 = av_clip((((p2 + p0 + 1) >> 1) - p1 + delta0) >> 1, -tc_2, tc_2);
- P1 = av_clip_pixel(p1 + deltap1);
- }
- if (!no_q && nd_q > 1) {
- const int deltaq1 = av_clip((((q2 + q0 + 1) >> 1) - q1 - delta0) >> 1, -tc_2, tc_2);
- Q1 = av_clip_pixel(q1 + deltaq1);
- }
- }
- pix += ystride;
- }
-
-}
-
static void FUNC(vvc_loop_filter_luma)(uint8_t* _pix, ptrdiff_t _xstride, ptrdiff_t _ystride,
const int32_t *_beta, const int32_t *_tc, const uint8_t *_no_p, const uint8_t *_no_q,
const uint8_t *_max_len_p, const uint8_t *_max_len_q, int hor_ctu_edge)
@@ -673,7 +615,7 @@ static void FUNC(vvc_loop_filter_luma)(uint8_t* _pix, ptrdiff_t _xstride, ptrdif
abs(P3 - P0) + abs(Q3 - Q0) < beta_3 && abs(P0 - Q0) < tc25 &&
abs(TP3 - TP0) + abs(TQ3 - TQ0) < beta_3 && abs(TP0 - TQ0) < tc25 &&
(d0 << 1) < beta_2 && (d3 << 1) < beta_2) {
- FUNC(loop_filter_luma_strong)(pix, xstride, ystride, tc, no_p, no_q);
+ FUNC(loop_filter_luma_strong)(pix, xstride, ystride, tc, tc << 1, tc * 3, no_p, no_q);
} else { // weak filtering
int nd_p = 1;
int nd_q = 1;
@@ -737,24 +679,6 @@ static void FUNC(loop_filter_chroma_strong_one_side)(pixel *pix, const ptrdiff_t
}
}
-static void FUNC(loop_filter_chroma_weak)(pixel *pix, const ptrdiff_t xstride, const ptrdiff_t ystride,
- const int size, const int32_t tc, const uint8_t no_p, const uint8_t no_q)
-{
- for (int d = 0; d < size; d++) {
- int delta0;
- const int p1 = P1;
- const int p0 = P0;
- const int q0 = Q0;
- const int q1 = Q1;
- delta0 = av_clip((((q0 - p0) * 4) + p1 - q1 + 4) >> 3, -tc, tc);
- if (!no_p)
- P0 = av_clip_pixel(p0 + delta0);
- if (!no_q)
- Q0 = av_clip_pixel(q0 - delta0);
- pix += ystride;
- }
-}
-
static void FUNC(vvc_loop_filter_chroma)(uint8_t *_pix, const ptrdiff_t _xstride, const ptrdiff_t _ystride,
const int32_t *_beta, const int32_t *_tc, const uint8_t *_no_p, const uint8_t *_no_q,
const uint8_t *_max_len_p, const uint8_t *_max_len_q, const int shift)
--
2.25.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 4/4] vvcdec: reuse h26x/h2656_deblock_template.c
2024-01-06 10:51 ` [FFmpeg-devel] [PATCH v2 4/4] vvcdec: reuse h26x/h2656_deblock_template.c Nuo Mi
@ 2024-01-09 1:02 ` Nuo Mi
2024-01-09 1:22 ` Ronald S. Bultje
0 siblings, 1 reply; 13+ messages in thread
From: Nuo Mi @ 2024-01-09 1:02 UTC (permalink / raw)
To: ffmpeg-devel
On Sat, Jan 6, 2024 at 6:52 PM Nuo Mi <nuomi2021@gmail.com> wrote:
> ---
> libavcodec/vvc/vvc_filter_template.c | 82 +---------------------------
> 1 file changed, 3 insertions(+), 79 deletions(-)
>
> diff --git a/libavcodec/vvc/vvc_filter_template.c
> b/libavcodec/vvc/vvc_filter_template.c
> index 9418980c33..671ed7de4e 100644
> --- a/libavcodec/vvc/vvc_filter_template.c
> +++ b/libavcodec/vvc/vvc_filter_template.c
> @@ -461,6 +461,8 @@ static void FUNC(alf_recon_coeff_and_clip)(int16_t
> *coeff, int16_t *clip,
> #define FQ2 pix[2 * xstride + 1 * ystride]
> #define FQ3 pix[3 * xstride + 1 * ystride]
>
> +#include "libavcodec/h26x/h2656_deblock_template.c"
>
Will merge this in two days if there are no objections to the file and
directory names.
Thank you
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 4/4] vvcdec: reuse h26x/h2656_deblock_template.c
2024-01-09 1:02 ` Nuo Mi
@ 2024-01-09 1:22 ` Ronald S. Bultje
2024-01-09 3:05 ` Nuo Mi
0 siblings, 1 reply; 13+ messages in thread
From: Ronald S. Bultje @ 2024-01-09 1:22 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Hi,
On Mon, Jan 8, 2024 at 8:03 PM Nuo Mi <nuomi2021@gmail.com> wrote:
> On Sat, Jan 6, 2024 at 6:52 PM Nuo Mi <nuomi2021@gmail.com> wrote:
>
> > ---
> > libavcodec/vvc/vvc_filter_template.c | 82 +---------------------------
> > 1 file changed, 3 insertions(+), 79 deletions(-)
> >
> > diff --git a/libavcodec/vvc/vvc_filter_template.c
> > b/libavcodec/vvc/vvc_filter_template.c
> > index 9418980c33..671ed7de4e 100644
> > --- a/libavcodec/vvc/vvc_filter_template.c
> > +++ b/libavcodec/vvc/vvc_filter_template.c
> > @@ -461,6 +461,8 @@ static void FUNC(alf_recon_coeff_and_clip)(int16_t
> > *coeff, int16_t *clip,
> > #define FQ2 pix[2 * xstride + 1 * ystride]
> > #define FQ3 pix[3 * xstride + 1 * ystride]
> >
> > +#include "libavcodec/h26x/h2656_deblock_template.c"
> >
> Will merge this in two days if there are no objections to the file and
> directory names.
>
Are there options to share the actual generated binary code? The C code
admittedly is not so important, but it would be great if there was some way
to ensure that optimizations written for HEVC in some instruction set, work
for VVC also - or vice versa.
Ronald
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 4/4] vvcdec: reuse h26x/h2656_deblock_template.c
2024-01-09 1:22 ` Ronald S. Bultje
@ 2024-01-09 3:05 ` Nuo Mi
2024-01-09 12:50 ` Ronald S. Bultje
0 siblings, 1 reply; 13+ messages in thread
From: Nuo Mi @ 2024-01-09 3:05 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Tue, Jan 9, 2024 at 9:23 AM Ronald S. Bultje <rsbultje@gmail.com> wrote:
> Hi,
>
> On Mon, Jan 8, 2024 at 8:03 PM Nuo Mi <nuomi2021@gmail.com> wrote:
>
> > On Sat, Jan 6, 2024 at 6:52 PM Nuo Mi <nuomi2021@gmail.com> wrote:
> >
> > > ---
> > > libavcodec/vvc/vvc_filter_template.c | 82 +---------------------------
> > > 1 file changed, 3 insertions(+), 79 deletions(-)
> > >
> > > diff --git a/libavcodec/vvc/vvc_filter_template.c
> > > b/libavcodec/vvc/vvc_filter_template.c
> > > index 9418980c33..671ed7de4e 100644
> > > --- a/libavcodec/vvc/vvc_filter_template.c
> > > +++ b/libavcodec/vvc/vvc_filter_template.c
> > > @@ -461,6 +461,8 @@ static void FUNC(alf_recon_coeff_and_clip)(int16_t
> > > *coeff, int16_t *clip,
> > > #define FQ2 pix[2 * xstride + 1 * ystride]
> > > #define FQ3 pix[3 * xstride + 1 * ystride]
> > >
> > > +#include "libavcodec/h26x/h2656_deblock_template.c"
> > >
> > Will merge this in two days if there are no objections to the file and
> > directory names.
> >
>
> Are there options to share the actual generated binary code? The C code
> admittedly is not so important, but it would be great if there was some way
> to ensure that optimizations written for HEVC in some instruction set, work
> for VVC also - or vice versa.
>
Yes. After we merge this, we will send out the mc x86 asm code for review.
It will share the same binary with HEVC.
For SAO/Deblock, we will follow a similar approach, but it needs to be a
little later than mc.
For C code, we can share the binary as well, but it involves some interface
changes, better to do it after all asm is ready.
>
> Ronald
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 4/4] vvcdec: reuse h26x/h2656_deblock_template.c
2024-01-09 3:05 ` Nuo Mi
@ 2024-01-09 12:50 ` Ronald S. Bultje
2024-01-11 15:05 ` Nuo Mi
0 siblings, 1 reply; 13+ messages in thread
From: Ronald S. Bultje @ 2024-01-09 12:50 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Hi,
On Mon, Jan 8, 2024 at 10:05 PM Nuo Mi <nuomi2021@gmail.com> wrote:
> On Tue, Jan 9, 2024 at 9:23 AM Ronald S. Bultje <rsbultje@gmail.com>
> wrote:
>
> > Hi,
> >
> > On Mon, Jan 8, 2024 at 8:03 PM Nuo Mi <nuomi2021@gmail.com> wrote:
> >
> > > On Sat, Jan 6, 2024 at 6:52 PM Nuo Mi <nuomi2021@gmail.com> wrote:
> > >
> > > > ---
> > > > libavcodec/vvc/vvc_filter_template.c | 82
> +---------------------------
> > > > 1 file changed, 3 insertions(+), 79 deletions(-)
> > > >
> > > > diff --git a/libavcodec/vvc/vvc_filter_template.c
> > > > b/libavcodec/vvc/vvc_filter_template.c
> > > > index 9418980c33..671ed7de4e 100644
> > > > --- a/libavcodec/vvc/vvc_filter_template.c
> > > > +++ b/libavcodec/vvc/vvc_filter_template.c
> > > > @@ -461,6 +461,8 @@ static void
> FUNC(alf_recon_coeff_and_clip)(int16_t
> > > > *coeff, int16_t *clip,
> > > > #define FQ2 pix[2 * xstride + 1 * ystride]
> > > > #define FQ3 pix[3 * xstride + 1 * ystride]
> > > >
> > > > +#include "libavcodec/h26x/h2656_deblock_template.c"
> > > >
> > > Will merge this in two days if there are no objections to the file and
> > > directory names.
> > >
> >
> > Are there options to share the actual generated binary code? The C code
> > admittedly is not so important, but it would be great if there was some
> way
> > to ensure that optimizations written for HEVC in some instruction set,
> work
> > for VVC also - or vice versa.
> >
> Yes. After we merge this, we will send out the mc x86 asm code for review.
> It will share the same binary with HEVC.
> For SAO/Deblock, we will follow a similar approach, but it needs to be a
> little later than mc.
> For C code, we can share the binary as well, but it involves some interface
> changes, better to do it after all asm is ready.
>
OK, that sounds reasonable to me.
Ronald
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 4/4] vvcdec: reuse h26x/h2656_deblock_template.c
2024-01-09 12:50 ` Ronald S. Bultje
@ 2024-01-11 15:05 ` Nuo Mi
0 siblings, 0 replies; 13+ messages in thread
From: Nuo Mi @ 2024-01-11 15:05 UTC (permalink / raw)
To: FFmpeg development discussions and patches
>
>
>
> > Yes. After we merge this, we will send out the mc x86 asm code for
> review.
> > It will share the same binary with HEVC.
> > For SAO/Deblock, we will follow a similar approach, but it needs to be a
> > little later than mc.
> > For C code, we can share the binary as well, but it involves some
> interface
> > changes, better to do it after all asm is ready.
> >
>
> OK, that sounds reasonable to me.
>
Thank you, Ronald.
Pushed.
>
> Ronald
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 13+ messages in thread
* [FFmpeg-devel] [PATCH 2/4] vvcdec: reuse xvc_sao_template.c
[not found] <20240103153238.18678-1-nuomi2021@gmail.com>
2024-01-03 15:32 ` [FFmpeg-devel] [PATCH 1/4] hevcdec: move sao template to xvc_sao_template.c Nuo Mi
@ 2024-01-03 15:32 ` Nuo Mi
2024-01-03 15:32 ` [FFmpeg-devel] [PATCH 3/4] hevcdec: move deblock template to xvc_deblock_template.c Nuo Mi
2024-01-03 15:32 ` [FFmpeg-devel] [PATCH 4/4] vvcdec: reuse xvc_deblock_template.c Nuo Mi
3 siblings, 0 replies; 13+ messages in thread
From: Nuo Mi @ 2024-01-03 15:32 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Nuo Mi
---
libavcodec/vvc/vvc_filter_template.c | 193 +--------------------------
1 file changed, 2 insertions(+), 191 deletions(-)
diff --git a/libavcodec/vvc/vvc_filter_template.c b/libavcodec/vvc/vvc_filter_template.c
index a4f1792ec4..04eb9702dc 100644
--- a/libavcodec/vvc/vvc_filter_template.c
+++ b/libavcodec/vvc/vvc_filter_template.c
@@ -20,6 +20,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "libavcodec/xvc_sao_template.c"
+
static void FUNC(lmcs_filter_luma)(uint8_t *_dst, ptrdiff_t dst_stride, const int width, const int height, const uint8_t *_lut)
{
const pixel *lut = (const pixel *)_lut;
@@ -33,197 +35,6 @@ static void FUNC(lmcs_filter_luma)(uint8_t *_dst, ptrdiff_t dst_stride, const in
}
}
-static void FUNC(sao_band_filter)(uint8_t *_dst, const uint8_t *_src, ptrdiff_t dst_stride, ptrdiff_t src_stride,
- const int16_t *sao_offset_val, const int sao_left_class, const int width, const int height)
-{
- pixel *dst = (pixel *)_dst;
- const pixel *src = (pixel *)_src;
- int offset_table[32] = { 0 };
- int k, y, x;
- int shift = BIT_DEPTH - 5;
-
- dst_stride /= sizeof(pixel);
- src_stride /= sizeof(pixel);
-
- for (k = 0; k < 4; k++)
- offset_table[(k + sao_left_class) & 31] = sao_offset_val[k + 1];
- for (y = 0; y < height; y++) {
- for (x = 0; x < width; x++)
- dst[x] = av_clip_pixel(src[x] + offset_table[src[x] >> shift]);
- dst += dst_stride;
- src += src_stride;
- }
-}
-
-#define CMP(a, b) (((a) > (b)) - ((a) < (b)))
-
-static void FUNC(sao_edge_filter)(uint8_t *_dst, const uint8_t *_src, ptrdiff_t dst_stride,
- const int16_t *sao_offset_val, const int eo, const int width, const int height)
-{
- static const uint8_t edge_idx[] = { 1, 2, 0, 3, 4 };
- static const int8_t pos[4][2][2] = {
- { { -1, 0 }, { 1, 0 } }, // horizontal
- { { 0, -1 }, { 0, 1 } }, // vertical
- { { -1, -1 }, { 1, 1 } }, // 45 degree
- { { 1, -1 }, { -1, 1 } }, // 135 degree
- };
- pixel *dst = (pixel *)_dst;
- const pixel *src = (pixel *)_src;
- int a_stride, b_stride;
- int x, y;
- ptrdiff_t src_stride = (2 * MAX_PB_SIZE + AV_INPUT_BUFFER_PADDING_SIZE) / sizeof(pixel);
- dst_stride /= sizeof(pixel);
-
- a_stride = pos[eo][0][0] + pos[eo][0][1] * src_stride;
- b_stride = pos[eo][1][0] + pos[eo][1][1] * src_stride;
- for (y = 0; y < height; y++) {
- for (x = 0; x < width; x++) {
- int diff0 = CMP(src[x], src[x + a_stride]);
- int diff1 = CMP(src[x], src[x + b_stride]);
- int offset_val = edge_idx[2 + diff0 + diff1];
- dst[x] = av_clip_pixel(src[x] + sao_offset_val[offset_val]);
- }
- src += src_stride;
- dst += dst_stride;
- }
-}
-
-static void FUNC(sao_edge_restore_0)(uint8_t *_dst, const uint8_t *_src,
- ptrdiff_t dst_stride, ptrdiff_t src_stride, const SAOParams *sao,
- const int *borders, const int _width, const int _height, const int c_idx,
- const uint8_t *vert_edge, const uint8_t *horiz_edge, const uint8_t *diag_edge)
-{
- int x, y;
- pixel *dst = (pixel *)_dst;
- const pixel *src = (pixel *)_src;
- const int16_t *sao_offset_val = sao->offset_val[c_idx];
- const int sao_eo_class = sao->eo_class[c_idx];
- int init_x = 0, width = _width, height = _height;
-
- dst_stride /= sizeof(pixel);
- src_stride /= sizeof(pixel);
-
- if (sao_eo_class != SAO_EO_VERT) {
- if (borders[0]) {
- int offset_val = sao_offset_val[0];
- for (y = 0; y < height; y++) {
- dst[y * dst_stride] = av_clip_pixel(src[y * src_stride] + offset_val);
- }
- init_x = 1;
- }
- if (borders[2]) {
- int offset_val = sao_offset_val[0];
- int offset = width - 1;
- for (x = 0; x < height; x++) {
- dst[x * dst_stride + offset] = av_clip_pixel(src[x * src_stride + offset] + offset_val);
- }
- width--;
- }
- }
- if (sao_eo_class != SAO_EO_HORIZ) {
- if (borders[1]) {
- int offset_val = sao_offset_val[0];
- for (x = init_x; x < width; x++)
- dst[x] = av_clip_pixel(src[x] + offset_val);
- }
- if (borders[3]) {
- int offset_val = sao_offset_val[0];
- ptrdiff_t y_dst_stride = dst_stride * (height - 1);
- ptrdiff_t y_src_stride = src_stride * (height - 1);
- for (x = init_x; x < width; x++)
- dst[x + y_dst_stride] = av_clip_pixel(src[x + y_src_stride] + offset_val);
- height--;
- }
- }
-}
-
-static void FUNC(sao_edge_restore_1)(uint8_t *_dst, const uint8_t *_src,
- ptrdiff_t dst_stride, ptrdiff_t src_stride, const SAOParams *sao,
- const int *borders, const int _width, const int _height, const int c_idx,
- const uint8_t *vert_edge, const uint8_t *horiz_edge, const uint8_t *diag_edge)
-{
- int x, y;
- pixel *dst = (pixel *)_dst;
- const pixel *src = (pixel *)_src;
- const int16_t *sao_offset_val = sao->offset_val[c_idx];
- const int sao_eo_class = sao->eo_class[c_idx];
- int init_x = 0, init_y = 0, width = _width, height = _height;
-
- dst_stride /= sizeof(pixel);
- src_stride /= sizeof(pixel);
-
- if (sao_eo_class != SAO_EO_VERT) {
- if (borders[0]) {
- int offset_val = sao_offset_val[0];
- for (y = 0; y < height; y++) {
- dst[y * dst_stride] = av_clip_pixel(src[y * src_stride] + offset_val);
- }
- init_x = 1;
- }
- if (borders[2]) {
- int offset_val = sao_offset_val[0];
- int offset = width - 1;
- for (x = 0; x < height; x++) {
- dst[x * dst_stride + offset] = av_clip_pixel(src[x * src_stride + offset] + offset_val);
- }
- width--;
- }
- }
- if (sao_eo_class != SAO_EO_HORIZ) {
- if (borders[1]) {
- int offset_val = sao_offset_val[0];
- for (x = init_x; x < width; x++)
- dst[x] = av_clip_pixel(src[x] + offset_val);
- init_y = 1;
- }
- if (borders[3]) {
- int offset_val = sao_offset_val[0];
- ptrdiff_t y_dst_stride = dst_stride * (height - 1);
- ptrdiff_t y_src_stride = src_stride * (height - 1);
- for (x = init_x; x < width; x++)
- dst[x + y_dst_stride] = av_clip_pixel(src[x + y_src_stride] + offset_val);
- height--;
- }
- }
-
- {
- int save_upper_left = !diag_edge[0] && sao_eo_class == SAO_EO_135D && !borders[0] && !borders[1];
- int save_upper_right = !diag_edge[1] && sao_eo_class == SAO_EO_45D && !borders[1] && !borders[2];
- int save_lower_right = !diag_edge[2] && sao_eo_class == SAO_EO_135D && !borders[2] && !borders[3];
- int save_lower_left = !diag_edge[3] && sao_eo_class == SAO_EO_45D && !borders[0] && !borders[3];
-
- // Restore pixels that can't be modified
- if (vert_edge[0] && sao_eo_class != SAO_EO_VERT) {
- for (y = init_y + save_upper_left; y < height - save_lower_left; y++)
- dst[y * dst_stride] = src[y * src_stride];
- }
- if (vert_edge[1] && sao_eo_class != SAO_EO_VERT) {
- for (y = init_y + save_upper_right; y < height - save_lower_right; y++)
- dst[y * dst_stride + width - 1] = src[y * src_stride + width - 1];
- }
-
- if (horiz_edge[0] && sao_eo_class != SAO_EO_HORIZ) {
- for (x = init_x + save_upper_left; x < width - save_upper_right; x++)
- dst[x] = src[x];
- }
- if (horiz_edge[1] && sao_eo_class != SAO_EO_HORIZ) {
- for (x = init_x + save_lower_left; x < width - save_lower_right; x++)
- dst[(height - 1) * dst_stride + x] = src[(height - 1) * src_stride + x];
- }
- if (diag_edge[0] && sao_eo_class == SAO_EO_135D)
- dst[0] = src[0];
- if (diag_edge[1] && sao_eo_class == SAO_EO_45D)
- dst[width - 1] = src[width - 1];
- if (diag_edge[2] && sao_eo_class == SAO_EO_135D)
- dst[dst_stride * (height - 1) + width - 1] = src[src_stride * (height - 1) + width - 1];
- if (diag_edge[3] && sao_eo_class == SAO_EO_45D)
- dst[dst_stride * (height - 1)] = src[src_stride * (height - 1)];
-
- }
-}
-
-#undef CMP
-
static av_always_inline int16_t FUNC(alf_clip)(pixel curr, pixel v0, pixel v1, int16_t clip)
{
return av_clip(v0 - curr, -clip, clip) + av_clip(v1 - curr, -clip, clip);
--
2.25.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 13+ messages in thread
* [FFmpeg-devel] [PATCH 3/4] hevcdec: move deblock template to xvc_deblock_template.c
[not found] <20240103153238.18678-1-nuomi2021@gmail.com>
2024-01-03 15:32 ` [FFmpeg-devel] [PATCH 1/4] hevcdec: move sao template to xvc_sao_template.c Nuo Mi
2024-01-03 15:32 ` [FFmpeg-devel] [PATCH 2/4] vvcdec: reuse xvc_sao_template.c Nuo Mi
@ 2024-01-03 15:32 ` Nuo Mi
2024-01-03 15:32 ` [FFmpeg-devel] [PATCH 4/4] vvcdec: reuse xvc_deblock_template.c Nuo Mi
3 siblings, 0 replies; 13+ messages in thread
From: Nuo Mi @ 2024-01-03 15:32 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Nuo Mi
---
libavcodec/hevcdsp_template.c | 96 ++++++------------------------
libavcodec/xvc_deblock_template.c | 99 +++++++++++++++++++++++++++++++
2 files changed, 116 insertions(+), 79 deletions(-)
create mode 100644 libavcodec/xvc_deblock_template.c
diff --git a/libavcodec/hevcdsp_template.c b/libavcodec/hevcdsp_template.c
index 00786bb2f8..fb7d2ebb60 100644
--- a/libavcodec/hevcdsp_template.c
+++ b/libavcodec/hevcdsp_template.c
@@ -1319,19 +1319,20 @@ static void FUNC(put_hevc_epel_bi_w_hv)(uint8_t *_dst, ptrdiff_t _dststride,
#define TQ2 pix[2 * xstride + 3 * ystride]
#define TQ3 pix[3 * xstride + 3 * ystride]
+#include "xvc_deblock_template.c"
+
static void FUNC(hevc_loop_filter_luma)(uint8_t *_pix,
ptrdiff_t _xstride, ptrdiff_t _ystride,
int beta, const int *_tc,
const uint8_t *_no_p, const uint8_t *_no_q)
{
- int d, j;
- pixel *pix = (pixel *)_pix;
ptrdiff_t xstride = _xstride / sizeof(pixel);
ptrdiff_t ystride = _ystride / sizeof(pixel);
beta <<= BIT_DEPTH - 8;
- for (j = 0; j < 2; j++) {
+ for (int j = 0; j < 2; j++) {
+ pixel* pix = (pixel*)_pix + j * 4 * ystride;
const int dp0 = abs(P2 - 2 * P1 + P0);
const int dq0 = abs(Q2 - 2 * Q1 + Q0);
const int dp3 = abs(TP2 - 2 * TP1 + TP0);
@@ -1342,10 +1343,7 @@ static void FUNC(hevc_loop_filter_luma)(uint8_t *_pix,
const int no_p = _no_p[j];
const int no_q = _no_q[j];
- if (d0 + d3 >= beta) {
- pix += 4 * ystride;
- continue;
- } else {
+ if (d0 + d3 < beta) {
const int beta_3 = beta >> 3;
const int beta_2 = beta >> 2;
const int tc25 = ((tc * 5 + 1) >> 1);
@@ -1353,63 +1351,16 @@ static void FUNC(hevc_loop_filter_luma)(uint8_t *_pix,
if (abs(P3 - P0) + abs(Q3 - Q0) < beta_3 && abs(P0 - Q0) < tc25 &&
abs(TP3 - TP0) + abs(TQ3 - TQ0) < beta_3 && abs(TP0 - TQ0) < tc25 &&
(d0 << 1) < beta_2 && (d3 << 1) < beta_2) {
- // strong filtering
const int tc2 = tc << 1;
- for (d = 0; d < 4; d++) {
- const int p3 = P3;
- const int p2 = P2;
- const int p1 = P1;
- const int p0 = P0;
- const int q0 = Q0;
- const int q1 = Q1;
- const int q2 = Q2;
- const int q3 = Q3;
- if (!no_p) {
- P0 = p0 + av_clip(((p2 + 2 * p1 + 2 * p0 + 2 * q0 + q1 + 4) >> 3) - p0, -tc2, tc2);
- P1 = p1 + av_clip(((p2 + p1 + p0 + q0 + 2) >> 2) - p1, -tc2, tc2);
- P2 = p2 + av_clip(((2 * p3 + 3 * p2 + p1 + p0 + q0 + 4) >> 3) - p2, -tc2, tc2);
- }
- if (!no_q) {
- Q0 = q0 + av_clip(((p1 + 2 * p0 + 2 * q0 + 2 * q1 + q2 + 4) >> 3) - q0, -tc2, tc2);
- Q1 = q1 + av_clip(((p0 + q0 + q1 + q2 + 2) >> 2) - q1, -tc2, tc2);
- Q2 = q2 + av_clip(((2 * q3 + 3 * q2 + q1 + q0 + p0 + 4) >> 3) - q2, -tc2, tc2);
- }
- pix += ystride;
- }
- } else { // normal filtering
+ FUNC(loop_filter_luma_strong)(pix, xstride, ystride, tc2, tc2, tc2, no_p, no_q);
+ } else {
int nd_p = 1;
int nd_q = 1;
- const int tc_2 = tc >> 1;
if (dp0 + dp3 < ((beta + (beta >> 1)) >> 3))
nd_p = 2;
if (dq0 + dq3 < ((beta + (beta >> 1)) >> 3))
nd_q = 2;
-
- for (d = 0; d < 4; d++) {
- const int p2 = P2;
- const int p1 = P1;
- const int p0 = P0;
- const int q0 = Q0;
- const int q1 = Q1;
- const int q2 = Q2;
- int delta0 = (9 * (q0 - p0) - 3 * (q1 - p1) + 8) >> 4;
- if (abs(delta0) < 10 * tc) {
- delta0 = av_clip(delta0, -tc, tc);
- if (!no_p)
- P0 = av_clip_pixel(p0 + delta0);
- if (!no_q)
- Q0 = av_clip_pixel(q0 - delta0);
- if (!no_p && nd_p > 1) {
- const int deltap1 = av_clip((((p2 + p0 + 1) >> 1) - p1 + delta0) >> 1, -tc_2, tc_2);
- P1 = av_clip_pixel(p1 + deltap1);
- }
- if (!no_q && nd_q > 1) {
- const int deltaq1 = av_clip((((q2 + q0 + 1) >> 1) - q1 - delta0) >> 1, -tc_2, tc_2);
- Q1 = av_clip_pixel(q1 + deltaq1);
- }
- }
- pix += ystride;
- }
+ FUNC(loop_filter_luma_weak)(pix, xstride, ystride, tc, beta, no_p, no_q, nd_p, nd_q);
}
}
}
@@ -1419,32 +1370,19 @@ static void FUNC(hevc_loop_filter_chroma)(uint8_t *_pix, ptrdiff_t _xstride,
ptrdiff_t _ystride, const int *_tc,
const uint8_t *_no_p, const uint8_t *_no_q)
{
- int d, j, no_p, no_q;
- pixel *pix = (pixel *)_pix;
+ int no_p, no_q;
ptrdiff_t xstride = _xstride / sizeof(pixel);
ptrdiff_t ystride = _ystride / sizeof(pixel);
+ const int size = 4;
- for (j = 0; j < 2; j++) {
+ for (int j = 0; j < 2; j++) {
+ pixel *pix = (pixel *)_pix + j * size * ystride;
const int tc = _tc[j] << (BIT_DEPTH - 8);
- if (tc <= 0) {
- pix += 4 * ystride;
- continue;
- }
- no_p = _no_p[j];
- no_q = _no_q[j];
-
- for (d = 0; d < 4; d++) {
- int delta0;
- const int p1 = P1;
- const int p0 = P0;
- const int q0 = Q0;
- const int q1 = Q1;
- delta0 = av_clip((((q0 - p0) * 4) + p1 - q1 + 4) >> 3, -tc, tc);
- if (!no_p)
- P0 = av_clip_pixel(p0 + delta0);
- if (!no_q)
- Q0 = av_clip_pixel(q0 - delta0);
- pix += ystride;
+ if (tc > 0) {
+ no_p = _no_p[j];
+ no_q = _no_q[j];
+
+ FUNC(loop_filter_chroma_weak)(pix, xstride, ystride, size, tc, no_p, no_q);
}
}
}
diff --git a/libavcodec/xvc_deblock_template.c b/libavcodec/xvc_deblock_template.c
new file mode 100644
index 0000000000..8ed95e754d
--- /dev/null
+++ b/libavcodec/xvc_deblock_template.c
@@ -0,0 +1,99 @@
+
+/*
+ * HEVC/VVC deblocking dsp template
+ *
+ * Copyright (C) 2024 Nuo Mi
+ * Copyright (C) 2012 - 2013 Guillaume Martres
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+static void FUNC(loop_filter_luma_strong)(pixel *pix, const ptrdiff_t xstride, const ptrdiff_t ystride,
+ const int32_t tc, const int32_t tc2, const int tc3,
+ const uint8_t no_p, const uint8_t no_q)
+{
+ for (int d = 0; d < 4; d++) {
+ const int p3 = P3;
+ const int p2 = P2;
+ const int p1 = P1;
+ const int p0 = P0;
+ const int q0 = Q0;
+ const int q1 = Q1;
+ const int q2 = Q2;
+ const int q3 = Q3;
+ if (!no_p) {
+ P0 = p0 + av_clip(((p2 + 2 * p1 + 2 * p0 + 2 * q0 + q1 + 4) >> 3) - p0, -tc3, tc3);
+ P1 = p1 + av_clip(((p2 + p1 + p0 + q0 + 2) >> 2) - p1, -tc2, tc2);
+ P2 = p2 + av_clip(((2 * p3 + 3 * p2 + p1 + p0 + q0 + 4) >> 3) - p2, -tc, tc);
+ }
+ if (!no_q) {
+ Q0 = q0 + av_clip(((p1 + 2 * p0 + 2 * q0 + 2 * q1 + q2 + 4) >> 3) - q0, -tc3, tc3);
+ Q1 = q1 + av_clip(((p0 + q0 + q1 + q2 + 2) >> 2) - q1, -tc2, tc2);
+ Q2 = q2 + av_clip(((2 * q3 + 3 * q2 + q1 + q0 + p0 + 4) >> 3) - q2, -tc, tc);
+ }
+ pix += ystride;
+ }
+}
+
+static void FUNC(loop_filter_luma_weak)(pixel *pix, const ptrdiff_t xstride, const ptrdiff_t ystride,
+ const int32_t tc, const int32_t beta, const uint8_t no_p, const uint8_t no_q, const int nd_p, const int nd_q)
+{
+ const int tc_2 = tc >> 1;
+ for (int d = 0; d < 4; d++) {
+ const int p2 = P2;
+ const int p1 = P1;
+ const int p0 = P0;
+ const int q0 = Q0;
+ const int q1 = Q1;
+ const int q2 = Q2;
+ int delta0 = (9 * (q0 - p0) - 3 * (q1 - p1) + 8) >> 4;
+ if (abs(delta0) < 10 * tc) {
+ delta0 = av_clip(delta0, -tc, tc);
+ if (!no_p)
+ P0 = av_clip_pixel(p0 + delta0);
+ if (!no_q)
+ Q0 = av_clip_pixel(q0 - delta0);
+ if (!no_p && nd_p > 1) {
+ const int deltap1 = av_clip((((p2 + p0 + 1) >> 1) - p1 + delta0) >> 1, -tc_2, tc_2);
+ P1 = av_clip_pixel(p1 + deltap1);
+ }
+ if (!no_q && nd_q > 1) {
+ const int deltaq1 = av_clip((((q2 + q0 + 1) >> 1) - q1 - delta0) >> 1, -tc_2, tc_2);
+ Q1 = av_clip_pixel(q1 + deltaq1);
+ }
+ }
+ pix += ystride;
+ }
+}
+
+static void FUNC(loop_filter_chroma_weak)(pixel *pix, const ptrdiff_t xstride, const ptrdiff_t ystride,
+ const int size, const int32_t tc, const uint8_t no_p, const uint8_t no_q)
+{
+ for (int d = 0; d < size; d++) {
+ int delta0;
+ const int p1 = P1;
+ const int p0 = P0;
+ const int q0 = Q0;
+ const int q1 = Q1;
+ delta0 = av_clip((((q0 - p0) * 4) + p1 - q1 + 4) >> 3, -tc, tc);
+ if (!no_p)
+ P0 = av_clip_pixel(p0 + delta0);
+ if (!no_q)
+ Q0 = av_clip_pixel(q0 - delta0);
+ pix += ystride;
+ }
+}
--
2.25.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 13+ messages in thread
* [FFmpeg-devel] [PATCH 4/4] vvcdec: reuse xvc_deblock_template.c
[not found] <20240103153238.18678-1-nuomi2021@gmail.com>
` (2 preceding siblings ...)
2024-01-03 15:32 ` [FFmpeg-devel] [PATCH 3/4] hevcdec: move deblock template to xvc_deblock_template.c Nuo Mi
@ 2024-01-03 15:32 ` Nuo Mi
3 siblings, 0 replies; 13+ messages in thread
From: Nuo Mi @ 2024-01-03 15:32 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Nuo Mi
---
libavcodec/vvc/vvc_filter_template.c | 82 +---------------------------
1 file changed, 3 insertions(+), 79 deletions(-)
diff --git a/libavcodec/vvc/vvc_filter_template.c b/libavcodec/vvc/vvc_filter_template.c
index 04eb9702dc..98a9005674 100644
--- a/libavcodec/vvc/vvc_filter_template.c
+++ b/libavcodec/vvc/vvc_filter_template.c
@@ -461,6 +461,8 @@ static void FUNC(alf_recon_coeff_and_clip)(int16_t *coeff, int16_t *clip,
#define FQ2 pix[2 * xstride + 1 * ystride]
#define FQ3 pix[3 * xstride + 1 * ystride]
+#include "libavcodec/xvc_deblock_template.c"
+
static void FUNC(loop_filter_luma_large)(pixel *pix, const ptrdiff_t xstride, const ptrdiff_t ystride, const int32_t tc,
const uint8_t no_p, const uint8_t no_q, const uint8_t max_len_p, const uint8_t max_len_q)
{
@@ -541,66 +543,6 @@ static void FUNC(loop_filter_luma_large)(pixel *pix, const ptrdiff_t xstride, co
}
}
-static void FUNC(loop_filter_luma_strong)(pixel *pix, const ptrdiff_t xstride, const ptrdiff_t ystride, const int32_t tc,
- const uint8_t no_p, const uint8_t no_q)
-{
- const int tc2 = tc << 1;
- const int tc3 = tc * 3;
- for (int d = 0; d < 4; d++) {
- const int p3 = P3;
- const int p2 = P2;
- const int p1 = P1;
- const int p0 = P0;
- const int q0 = Q0;
- const int q1 = Q1;
- const int q2 = Q2;
- const int q3 = Q3;
- if (!no_p) {
- P0 = p0 + av_clip(((p2 + 2 * p1 + 2 * p0 + 2 * q0 + q1 + 4) >> 3) - p0, -tc3, tc3);
- P1 = p1 + av_clip(((p2 + p1 + p0 + q0 + 2) >> 2) - p1, -tc2, tc2);
- P2 = p2 + av_clip(((2 * p3 + 3 * p2 + p1 + p0 + q0 + 4) >> 3) - p2, -tc, tc);
- }
- if (!no_q) {
- Q0 = q0 + av_clip(((p1 + 2 * p0 + 2 * q0 + 2 * q1 + q2 + 4) >> 3) - q0, -tc3, tc3);
- Q1 = q1 + av_clip(((p0 + q0 + q1 + q2 + 2) >> 2) - q1, -tc2, tc2);
- Q2 = q2 + av_clip(((2 * q3 + 3 * q2 + q1 + q0 + p0 + 4) >> 3) - q2, -tc, tc);
- }
- pix += ystride;
- }
-}
-
-static void FUNC(loop_filter_luma_weak)(pixel *pix, const ptrdiff_t xstride, const ptrdiff_t ystride,
- const int32_t tc, const int32_t beta, const uint8_t no_p, const uint8_t no_q, const int nd_p, const int nd_q)
-{
- const int tc_2 = tc >> 1;
- for (int d = 0; d < 4; d++) {
- const int p2 = P2;
- const int p1 = P1;
- const int p0 = P0;
- const int q0 = Q0;
- const int q1 = Q1;
- const int q2 = Q2;
- int delta0 = (9 * (q0 - p0) - 3 * (q1 - p1) + 8) >> 4;
- if (abs(delta0) < 10 * tc) {
- delta0 = av_clip(delta0, -tc, tc);
- if (!no_p)
- P0 = av_clip_pixel(p0 + delta0);
- if (!no_q)
- Q0 = av_clip_pixel(q0 - delta0);
- if (!no_p && nd_p > 1) {
- const int deltap1 = av_clip((((p2 + p0 + 1) >> 1) - p1 + delta0) >> 1, -tc_2, tc_2);
- P1 = av_clip_pixel(p1 + deltap1);
- }
- if (!no_q && nd_q > 1) {
- const int deltaq1 = av_clip((((q2 + q0 + 1) >> 1) - q1 - delta0) >> 1, -tc_2, tc_2);
- Q1 = av_clip_pixel(q1 + deltaq1);
- }
- }
- pix += ystride;
- }
-
-}
-
static void FUNC(vvc_loop_filter_luma)(uint8_t* _pix, ptrdiff_t _xstride, ptrdiff_t _ystride,
const int32_t *_beta, const int32_t *_tc, const uint8_t *_no_p, const uint8_t *_no_q,
const uint8_t *_max_len_p, const uint8_t *_max_len_q, int hor_ctu_edge)
@@ -673,7 +615,7 @@ static void FUNC(vvc_loop_filter_luma)(uint8_t* _pix, ptrdiff_t _xstride, ptrdif
abs(P3 - P0) + abs(Q3 - Q0) < beta_3 && abs(P0 - Q0) < tc25 &&
abs(TP3 - TP0) + abs(TQ3 - TQ0) < beta_3 && abs(TP0 - TQ0) < tc25 &&
(d0 << 1) < beta_2 && (d3 << 1) < beta_2) {
- FUNC(loop_filter_luma_strong)(pix, xstride, ystride, tc, no_p, no_q);
+ FUNC(loop_filter_luma_strong)(pix, xstride, ystride, tc, tc << 1, tc * 3, no_p, no_q);
} else { // weak filtering
int nd_p = 1;
int nd_q = 1;
@@ -737,24 +679,6 @@ static void FUNC(loop_filter_chroma_strong_one_side)(pixel *pix, const ptrdiff_t
}
}
-static void FUNC(loop_filter_chroma_weak)(pixel *pix, const ptrdiff_t xstride, const ptrdiff_t ystride,
- const int size, const int32_t tc, const uint8_t no_p, const uint8_t no_q)
-{
- for (int d = 0; d < size; d++) {
- int delta0;
- const int p1 = P1;
- const int p0 = P0;
- const int q0 = Q0;
- const int q1 = Q1;
- delta0 = av_clip((((q0 - p0) * 4) + p1 - q1 + 4) >> 3, -tc, tc);
- if (!no_p)
- P0 = av_clip_pixel(p0 + delta0);
- if (!no_q)
- Q0 = av_clip_pixel(q0 - delta0);
- pix += ystride;
- }
-}
-
static void FUNC(vvc_loop_filter_chroma)(uint8_t *_pix, const ptrdiff_t _xstride, const ptrdiff_t _ystride,
const int32_t *_beta, const int32_t *_tc, const uint8_t *_no_p, const uint8_t *_no_q,
const uint8_t *_max_len_p, const uint8_t *_max_len_q, const int shift)
--
2.25.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 13+ messages in thread