This commit is contained in:
2025-08-27 15:09:05 +09:00
parent 57961d84de
commit a13f66d917
9896 changed files with 2193048 additions and 730 deletions
@@ -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;
}
}
@@ -0,0 +1,577 @@
/*
* inter prediction template for HEVC/VVC
*
* Copyright (C) 2022 Nuo Mi
* Copyright (C) 2024 Wu Jianhua
*
* 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
*/
#define CHROMA_EXTRA_BEFORE 1
#define CHROMA_EXTRA 3
#define LUMA_EXTRA_BEFORE 3
#define LUMA_EXTRA 7
static void FUNC(put_pixels)(int16_t *dst,
const uint8_t *_src, const ptrdiff_t _src_stride,
const int height, const int8_t *hf, const int8_t *vf, const int width)
{
const pixel *src = (const pixel *)_src;
const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++)
dst[x] = src[x] << (14 - BIT_DEPTH);
src += src_stride;
dst += MAX_PB_SIZE;
}
}
static void FUNC(put_uni_pixels)(uint8_t *_dst, const ptrdiff_t _dst_stride,
const uint8_t *_src, const ptrdiff_t _src_stride, const int height,
const int8_t *hf, const int8_t *vf, const int width)
{
const pixel *src = (const pixel *)_src;
pixel *dst = (pixel *)_dst;
const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
for (int y = 0; y < height; y++) {
memcpy(dst, src, width * sizeof(pixel));
src += src_stride;
dst += dst_stride;
}
}
static void FUNC(put_uni_w_pixels)(uint8_t *_dst, const ptrdiff_t _dst_stride,
const uint8_t *_src, const ptrdiff_t _src_stride, const int height,
const int denom, const int wx, const int _ox, const int8_t *hf, const int8_t *vf,
const int width)
{
const pixel *src = (const pixel *)_src;
pixel *dst = (pixel *)_dst;
const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
const int shift = denom + 14 - BIT_DEPTH;
#if BIT_DEPTH < 14
const int offset = 1 << (shift - 1);
#else
const int offset = 0;
#endif
const int ox = _ox * (1 << (BIT_DEPTH - 8));
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
const int v = (src[x] << (14 - BIT_DEPTH));
dst[x] = av_clip_pixel(((v * wx + offset) >> shift) + ox);
}
src += src_stride;
dst += dst_stride;
}
}
#define LUMA_FILTER(src, stride) \
(filter[0] * src[x - 3 * stride] + \
filter[1] * src[x - 2 * stride] + \
filter[2] * src[x - stride] + \
filter[3] * src[x ] + \
filter[4] * src[x + stride] + \
filter[5] * src[x + 2 * stride] + \
filter[6] * src[x + 3 * stride] + \
filter[7] * src[x + 4 * stride])
static void FUNC(put_luma_h)(int16_t *dst, const uint8_t *_src, const ptrdiff_t _src_stride,
const int height, const int8_t *hf, const int8_t *vf, const int width)
{
const pixel *src = (const pixel*)_src;
const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
const int8_t *filter = hf;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++)
dst[x] = LUMA_FILTER(src, 1) >> (BIT_DEPTH - 8);
src += src_stride;
dst += MAX_PB_SIZE;
}
}
static void FUNC(put_luma_v)(int16_t *dst, const uint8_t *_src, const ptrdiff_t _src_stride,
const int height, const int8_t *hf, const int8_t *vf, const int width)
{
const pixel *src = (pixel*)_src;
const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
const int8_t *filter = vf;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++)
dst[x] = LUMA_FILTER(src, src_stride) >> (BIT_DEPTH - 8);
src += src_stride;
dst += MAX_PB_SIZE;
}
}
static void FUNC(put_luma_hv)(int16_t *dst, const uint8_t *_src, const ptrdiff_t _src_stride,
const int height, const int8_t *hf, const int8_t *vf, const int width)
{
int16_t tmp_array[(MAX_PB_SIZE + LUMA_EXTRA) * MAX_PB_SIZE];
int16_t *tmp = tmp_array;
const pixel *src = (const pixel*)_src;
const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
const int8_t *filter = hf;
src -= LUMA_EXTRA_BEFORE * src_stride;
for (int y = 0; y < height + LUMA_EXTRA; y++) {
for (int x = 0; x < width; x++)
tmp[x] = LUMA_FILTER(src, 1) >> (BIT_DEPTH - 8);
src += src_stride;
tmp += MAX_PB_SIZE;
}
tmp = tmp_array + LUMA_EXTRA_BEFORE * MAX_PB_SIZE;
filter = vf;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++)
dst[x] = LUMA_FILTER(tmp, MAX_PB_SIZE) >> 6;
tmp += MAX_PB_SIZE;
dst += MAX_PB_SIZE;
}
}
static void FUNC(put_uni_luma_h)(uint8_t *_dst, const ptrdiff_t _dst_stride,
const uint8_t *_src, const ptrdiff_t _src_stride,
const int height, const int8_t *hf, const int8_t *vf, const int width)
{
const pixel *src = (const pixel*)_src;
pixel *dst = (pixel *)_dst;
const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
const int8_t *filter = hf;
const int shift = 14 - BIT_DEPTH;
#if BIT_DEPTH < 14
const int offset = 1 << (shift - 1);
#else
const int offset = 0;
#endif
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
const int val = LUMA_FILTER(src, 1) >> (BIT_DEPTH - 8);
dst[x] = av_clip_pixel((val + offset) >> shift);
}
src += src_stride;
dst += dst_stride;
}
}
static void FUNC(put_uni_luma_v)(uint8_t *_dst, const ptrdiff_t _dst_stride,
const uint8_t *_src, const ptrdiff_t _src_stride,
const int height, const int8_t *hf, const int8_t *vf, const int width)
{
const pixel *src = (const pixel*)_src;
pixel *dst = (pixel *)_dst;
const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
const int8_t *filter = vf;
const int shift = 14 - BIT_DEPTH;
#if BIT_DEPTH < 14
const int offset = 1 << (shift - 1);
#else
const int offset = 0;
#endif
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
const int val = LUMA_FILTER(src, src_stride) >> (BIT_DEPTH - 8);
dst[x] = av_clip_pixel((val + offset) >> shift);
}
src += src_stride;
dst += dst_stride;
}
}
static void FUNC(put_uni_luma_hv)(uint8_t *_dst, const ptrdiff_t _dst_stride,
const uint8_t *_src, const ptrdiff_t _src_stride,
const int height, const int8_t *hf, const int8_t *vf, const int width)
{
int16_t tmp_array[(MAX_PB_SIZE + LUMA_EXTRA) * MAX_PB_SIZE];
int16_t *tmp = tmp_array;
const pixel *src = (const pixel*)_src;
pixel *dst = (pixel *)_dst;
const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
const int8_t *filter = hf;
const int shift = 14 - BIT_DEPTH;
#if BIT_DEPTH < 14
const int offset = 1 << (shift - 1);
#else
const int offset = 0;
#endif
src -= LUMA_EXTRA_BEFORE * src_stride;
for (int y = 0; y < height + LUMA_EXTRA; y++) {
for (int x = 0; x < width; x++)
tmp[x] = LUMA_FILTER(src, 1) >> (BIT_DEPTH - 8);
src += src_stride;
tmp += MAX_PB_SIZE;
}
tmp = tmp_array + LUMA_EXTRA_BEFORE * MAX_PB_SIZE;
filter = vf;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
const int val = LUMA_FILTER(tmp, MAX_PB_SIZE) >> 6;
dst[x] = av_clip_pixel((val + offset) >> shift);
}
tmp += MAX_PB_SIZE;
dst += dst_stride;
}
}
static void FUNC(put_uni_luma_w_h)(uint8_t *_dst, const ptrdiff_t _dst_stride,
const uint8_t *_src, const ptrdiff_t _src_stride, int height,
const int denom, const int wx, const int _ox, const int8_t *hf, const int8_t *vf,
const int width)
{
const pixel *src = (const pixel*)_src;
pixel *dst = (pixel *)_dst;
const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
const int8_t *filter = hf;
const int ox = _ox * (1 << (BIT_DEPTH - 8));
const int shift = denom + 14 - BIT_DEPTH;
#if BIT_DEPTH < 14
const int offset = 1 << (shift - 1);
#else
const int offset = 0;
#endif
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++)
dst[x] = av_clip_pixel((((LUMA_FILTER(src, 1) >> (BIT_DEPTH - 8)) * wx + offset) >> shift) + ox);
src += src_stride;
dst += dst_stride;
}
}
static void FUNC(put_uni_luma_w_v)(uint8_t *_dst, const ptrdiff_t _dst_stride,
const uint8_t *_src, const ptrdiff_t _src_stride, const int height,
const int denom, const int wx, const int _ox, const int8_t *hf, const int8_t *vf,
const int width)
{
const pixel *src = (const pixel*)_src;
pixel *dst = (pixel *)_dst;
const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
const int8_t *filter = vf;
const int ox = _ox * (1 << (BIT_DEPTH - 8));
const int shift = denom + 14 - BIT_DEPTH;
#if BIT_DEPTH < 14
const int offset = 1 << (shift - 1);
#else
const int offset = 0;
#endif
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++)
dst[x] = av_clip_pixel((((LUMA_FILTER(src, src_stride) >> (BIT_DEPTH - 8)) * wx + offset) >> shift) + ox);
src += src_stride;
dst += dst_stride;
}
}
static void FUNC(put_uni_luma_w_hv)(uint8_t *_dst, const ptrdiff_t _dst_stride,
const uint8_t *_src, const ptrdiff_t _src_stride, const int height, const int denom,
const int wx, const int _ox, const int8_t *hf, const int8_t *vf, const int width)
{
int16_t tmp_array[(MAX_PB_SIZE + LUMA_EXTRA) * MAX_PB_SIZE];
int16_t *tmp = tmp_array;
const pixel *src = (const pixel*)_src;
pixel *dst = (pixel *)_dst;
const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
const int8_t *filter = hf;
const int ox = _ox * (1 << (BIT_DEPTH - 8));
const int shift = denom + 14 - BIT_DEPTH;
#if BIT_DEPTH < 14
const int offset = 1 << (shift - 1);
#else
const int offset = 0;
#endif
src -= LUMA_EXTRA_BEFORE * src_stride;
for (int y = 0; y < height + LUMA_EXTRA; y++) {
for (int x = 0; x < width; x++)
tmp[x] = LUMA_FILTER(src, 1) >> (BIT_DEPTH - 8);
src += src_stride;
tmp += MAX_PB_SIZE;
}
tmp = tmp_array + LUMA_EXTRA_BEFORE * MAX_PB_SIZE;
filter = vf;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++)
dst[x] = av_clip_pixel((((LUMA_FILTER(tmp, MAX_PB_SIZE) >> 6) * wx + offset) >> shift) + ox);
tmp += MAX_PB_SIZE;
dst += dst_stride;
}
}
#define CHROMA_FILTER(src, stride) \
(filter[0] * src[x - stride] + \
filter[1] * src[x] + \
filter[2] * src[x + stride] + \
filter[3] * src[x + 2 * stride])
static void FUNC(put_chroma_h)(int16_t *dst, const uint8_t *_src, const ptrdiff_t _src_stride,
const int height, const int8_t *hf, const int8_t *vf, const int width)
{
const pixel *src = (const pixel *)_src;
const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
const int8_t *filter = hf;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++)
dst[x] = CHROMA_FILTER(src, 1) >> (BIT_DEPTH - 8);
src += src_stride;
dst += MAX_PB_SIZE;
}
}
static void FUNC(put_chroma_v)(int16_t *dst, const uint8_t *_src, const ptrdiff_t _src_stride,
const int height, const int8_t *hf, const int8_t *vf, const int width)
{
const pixel *src = (const pixel *)_src;
const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
const int8_t *filter = vf;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++)
dst[x] = CHROMA_FILTER(src, src_stride) >> (BIT_DEPTH - 8);
src += src_stride;
dst += MAX_PB_SIZE;
}
}
static void FUNC(put_chroma_hv)(int16_t *dst, const uint8_t *_src, const ptrdiff_t _src_stride,
const int height, const int8_t *hf, const int8_t *vf, const int width)
{
int16_t tmp_array[(MAX_PB_SIZE + CHROMA_EXTRA) * MAX_PB_SIZE];
int16_t *tmp = tmp_array;
const pixel *src = (const pixel *)_src;
const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
const int8_t *filter = hf;
src -= CHROMA_EXTRA_BEFORE * src_stride;
for (int y = 0; y < height + CHROMA_EXTRA; y++) {
for (int x = 0; x < width; x++)
tmp[x] = CHROMA_FILTER(src, 1) >> (BIT_DEPTH - 8);
src += src_stride;
tmp += MAX_PB_SIZE;
}
tmp = tmp_array + CHROMA_EXTRA_BEFORE * MAX_PB_SIZE;
filter = vf;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++)
dst[x] = CHROMA_FILTER(tmp, MAX_PB_SIZE) >> 6;
tmp += MAX_PB_SIZE;
dst += MAX_PB_SIZE;
}
}
static void FUNC(put_uni_chroma_h)(uint8_t *_dst, const ptrdiff_t _dst_stride,
const uint8_t *_src, const ptrdiff_t _src_stride,
const int height, const int8_t *hf, const int8_t *vf, const int width)
{
const pixel *src = (const pixel *)_src;
pixel *dst = (pixel *)_dst;
const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
const int8_t *filter = hf;
const int shift = 14 - BIT_DEPTH;
#if BIT_DEPTH < 14
const int offset = 1 << (shift - 1);
#else
const int offset = 0;
#endif
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++)
dst[x] = av_clip_pixel(((CHROMA_FILTER(src, 1) >> (BIT_DEPTH - 8)) + offset) >> shift);
src += src_stride;
dst += dst_stride;
}
}
static void FUNC(put_uni_chroma_v)(uint8_t *_dst, const ptrdiff_t _dst_stride,
const uint8_t *_src, const ptrdiff_t _src_stride,
const int height, const int8_t *hf, const int8_t *vf, const int width)
{
const pixel *src = (const pixel *)_src;
pixel *dst = (pixel *)_dst;
const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
const int8_t *filter = vf;
const int shift = 14 - BIT_DEPTH;
#if BIT_DEPTH < 14
const int offset = 1 << (shift - 1);
#else
const int offset = 0;
#endif
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++)
dst[x] = av_clip_pixel(((CHROMA_FILTER(src, src_stride) >> (BIT_DEPTH - 8)) + offset) >> shift);
src += src_stride;
dst += dst_stride;
}
}
static void FUNC(put_uni_chroma_hv)(uint8_t *_dst, const ptrdiff_t _dst_stride,
const uint8_t *_src, const ptrdiff_t _src_stride,
const int height, const int8_t *hf, const int8_t *vf, const int width)
{
int16_t tmp_array[(MAX_PB_SIZE + CHROMA_EXTRA) * MAX_PB_SIZE];
int16_t *tmp = tmp_array;
const pixel *src = (const pixel *)_src;
pixel *dst = (pixel *)_dst;
const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
const int8_t *filter = hf;
const int shift = 14 - BIT_DEPTH;
#if BIT_DEPTH < 14
const int offset = 1 << (shift - 1);
#else
const int offset = 0;
#endif
src -= CHROMA_EXTRA_BEFORE * src_stride;
for (int y = 0; y < height + CHROMA_EXTRA; y++) {
for (int x = 0; x < width; x++)
tmp[x] = CHROMA_FILTER(src, 1) >> (BIT_DEPTH - 8);
src += src_stride;
tmp += MAX_PB_SIZE;
}
tmp = tmp_array + CHROMA_EXTRA_BEFORE * MAX_PB_SIZE;
filter = vf;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++)
dst[x] = av_clip_pixel(((CHROMA_FILTER(tmp, MAX_PB_SIZE) >> 6) + offset) >> shift);
tmp += MAX_PB_SIZE;
dst += dst_stride;
}
}
static void FUNC(put_uni_chroma_w_h)(uint8_t *_dst, ptrdiff_t _dst_stride,
const uint8_t *_src, ptrdiff_t _src_stride, int height, int denom, int wx, int ox,
const int8_t *hf, const int8_t *vf, int width)
{
const pixel *src = (const pixel *)_src;
pixel *dst = (pixel *)_dst;
const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
const int8_t *filter = hf;
const int shift = denom + 14 - BIT_DEPTH;
#if BIT_DEPTH < 14
const int offset = 1 << (shift - 1);
#else
const int offset = 0;
#endif
ox = ox * (1 << (BIT_DEPTH - 8));
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
dst[x] = av_clip_pixel((((CHROMA_FILTER(src, 1) >> (BIT_DEPTH - 8)) * wx + offset) >> shift) + ox);
}
dst += dst_stride;
src += src_stride;
}
}
static void FUNC(put_uni_chroma_w_v)(uint8_t *_dst, const ptrdiff_t _dst_stride,
const uint8_t *_src, const ptrdiff_t _src_stride, const int height,
const int denom, const int wx, const int _ox, const int8_t *hf, const int8_t *vf,
const int width)
{
const pixel *src = (const pixel *)_src;
pixel *dst = (pixel *)_dst;
const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
const int8_t *filter = vf;
const int shift = denom + 14 - BIT_DEPTH;
const int ox = _ox * (1 << (BIT_DEPTH - 8));
#if BIT_DEPTH < 14
int offset = 1 << (shift - 1);
#else
int offset = 0;
#endif
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
dst[x] = av_clip_pixel((((CHROMA_FILTER(src, src_stride) >> (BIT_DEPTH - 8)) * wx + offset) >> shift) + ox);
}
dst += dst_stride;
src += src_stride;
}
}
static void FUNC(put_uni_chroma_w_hv)(uint8_t *_dst, ptrdiff_t _dst_stride,
const uint8_t *_src, ptrdiff_t _src_stride, int height, int denom, int wx, int ox,
const int8_t *hf, const int8_t *vf, int width)
{
int16_t tmp_array[(MAX_PB_SIZE + CHROMA_EXTRA) * MAX_PB_SIZE];
int16_t *tmp = tmp_array;
const pixel *src = (const pixel *)_src;
pixel *dst = (pixel *)_dst;
const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
const int8_t *filter = hf;
const int shift = denom + 14 - BIT_DEPTH;
#if BIT_DEPTH < 14
const int offset = 1 << (shift - 1);
#else
const int offset = 0;
#endif
src -= CHROMA_EXTRA_BEFORE * src_stride;
for (int y = 0; y < height + CHROMA_EXTRA; y++) {
for (int x = 0; x < width; x++)
tmp[x] = CHROMA_FILTER(src, 1) >> (BIT_DEPTH - 8);
src += src_stride;
tmp += MAX_PB_SIZE;
}
tmp = tmp_array + CHROMA_EXTRA_BEFORE * MAX_PB_SIZE;
filter = vf;
ox = ox * (1 << (BIT_DEPTH - 8));
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++)
dst[x] = av_clip_pixel((((CHROMA_FILTER(tmp, MAX_PB_SIZE) >> 6) * wx + offset) >> shift) + ox);
tmp += MAX_PB_SIZE;
dst += dst_stride;
}
}
+217
View File
@@ -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