2013-10-12 12:55:48 +03:00
|
|
|
/*
|
2013-11-02 13:59:02 +03:00
|
|
|
* HEVC video decoder
|
2013-10-12 12:55:48 +03:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "get_bits.h"
|
2016-08-21 17:14:24 +02:00
|
|
|
#include "hevcdec.h"
|
2013-11-02 13:59:02 +03:00
|
|
|
|
2013-10-12 12:55:48 +03:00
|
|
|
#include "bit_depth_template.c"
|
2024-05-29 09:50:48 +02:00
|
|
|
#include "dsp.h"
|
2024-01-06 12:51:29 +02:00
|
|
|
#include "h26x/h2656_sao_template.c"
|
2024-01-23 20:17:05 +02:00
|
|
|
#include "h26x/h2656_inter_template.c"
|
2013-11-02 02:31:49 +03:00
|
|
|
|
2014-07-15 01:16:53 +03:00
|
|
|
static void FUNC(put_pcm)(uint8_t *_dst, ptrdiff_t stride, int width, int height,
|
2013-10-12 12:55:48 +03:00
|
|
|
GetBitContext *gb, int pcm_bit_depth)
|
|
|
|
{
|
|
|
|
int x, y;
|
2013-11-02 13:59:02 +03:00
|
|
|
pixel *dst = (pixel *)_dst;
|
|
|
|
|
2013-11-02 13:59:02 +03:00
|
|
|
stride /= sizeof(pixel);
|
2013-10-12 12:55:48 +03:00
|
|
|
|
2014-07-15 01:16:53 +03:00
|
|
|
for (y = 0; y < height; y++) {
|
|
|
|
for (x = 0; x < width; x++)
|
2013-10-12 12:55:48 +03:00
|
|
|
dst[x] = get_bits(gb, pcm_bit_depth) << (BIT_DEPTH - pcm_bit_depth);
|
|
|
|
dst += stride;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-22 06:10:59 +02:00
|
|
|
static av_always_inline void FUNC(add_residual)(uint8_t *_dst, const int16_t *res,
|
2016-07-03 17:38:56 +02:00
|
|
|
ptrdiff_t stride, int size)
|
2013-10-12 12:55:48 +03:00
|
|
|
{
|
|
|
|
int x, y;
|
2013-11-02 13:59:02 +03:00
|
|
|
pixel *dst = (pixel *)_dst;
|
|
|
|
|
2013-11-02 13:59:02 +03:00
|
|
|
stride /= sizeof(pixel);
|
2013-10-12 12:55:48 +03:00
|
|
|
|
2014-11-15 23:31:27 +02:00
|
|
|
for (y = 0; y < size; y++) {
|
|
|
|
for (x = 0; x < size; x++) {
|
2016-07-03 17:38:56 +02:00
|
|
|
dst[x] = av_clip_pixel(dst[x] + *res);
|
|
|
|
res++;
|
2013-10-12 12:55:48 +03:00
|
|
|
}
|
|
|
|
dst += stride;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-22 06:10:59 +02:00
|
|
|
static void FUNC(add_residual4x4)(uint8_t *_dst, const int16_t *res,
|
2016-07-03 17:38:56 +02:00
|
|
|
ptrdiff_t stride)
|
2013-10-12 12:55:48 +03:00
|
|
|
{
|
2016-07-03 17:38:56 +02:00
|
|
|
FUNC(add_residual)(_dst, res, stride, 4);
|
2014-11-15 23:31:27 +02:00
|
|
|
}
|
2013-10-12 12:55:48 +03:00
|
|
|
|
2022-07-22 06:10:59 +02:00
|
|
|
static void FUNC(add_residual8x8)(uint8_t *_dst, const int16_t *res,
|
2016-07-03 17:38:56 +02:00
|
|
|
ptrdiff_t stride)
|
2014-11-15 23:31:27 +02:00
|
|
|
{
|
2016-07-03 17:38:56 +02:00
|
|
|
FUNC(add_residual)(_dst, res, stride, 8);
|
2013-10-12 12:55:48 +03:00
|
|
|
}
|
|
|
|
|
2022-07-22 06:10:59 +02:00
|
|
|
static void FUNC(add_residual16x16)(uint8_t *_dst, const int16_t *res,
|
2016-07-03 17:38:56 +02:00
|
|
|
ptrdiff_t stride)
|
2013-10-12 12:55:48 +03:00
|
|
|
{
|
2016-07-03 17:38:56 +02:00
|
|
|
FUNC(add_residual)(_dst, res, stride, 16);
|
2013-10-12 12:55:48 +03:00
|
|
|
}
|
|
|
|
|
2022-07-22 06:10:59 +02:00
|
|
|
static void FUNC(add_residual32x32)(uint8_t *_dst, const int16_t *res,
|
2016-07-03 17:38:56 +02:00
|
|
|
ptrdiff_t stride)
|
2013-10-12 12:55:48 +03:00
|
|
|
{
|
2016-07-03 17:38:56 +02:00
|
|
|
FUNC(add_residual)(_dst, res, stride, 32);
|
2013-10-12 12:55:48 +03:00
|
|
|
}
|
|
|
|
|
2014-07-15 01:20:22 +03:00
|
|
|
static void FUNC(transform_rdpcm)(int16_t *_coeffs, int16_t log2_size, int mode)
|
|
|
|
{
|
|
|
|
int16_t *coeffs = (int16_t *) _coeffs;
|
|
|
|
int x, y;
|
|
|
|
int size = 1 << log2_size;
|
|
|
|
|
|
|
|
if (mode) {
|
|
|
|
coeffs += size;
|
|
|
|
for (y = 0; y < size - 1; y++) {
|
|
|
|
for (x = 0; x < size; x++)
|
|
|
|
coeffs[x] += coeffs[x - size];
|
|
|
|
coeffs += size;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (y = 0; y < size; y++) {
|
|
|
|
for (x = 1; x < size; x++)
|
|
|
|
coeffs[x] += coeffs[x - 1];
|
|
|
|
coeffs += size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-31 12:20:54 +02:00
|
|
|
static void FUNC(dequant)(int16_t *coeffs, int16_t log2_size)
|
2013-10-12 12:55:48 +03:00
|
|
|
{
|
2014-07-14 22:17:33 +03:00
|
|
|
int shift = 15 - BIT_DEPTH - log2_size;
|
2013-10-12 12:55:48 +03:00
|
|
|
int x, y;
|
2014-07-14 22:17:33 +03:00
|
|
|
int size = 1 << log2_size;
|
2013-11-02 13:59:02 +03:00
|
|
|
|
2014-07-14 22:17:33 +03:00
|
|
|
if (shift > 0) {
|
|
|
|
int offset = 1 << (shift - 1);
|
|
|
|
for (y = 0; y < size; y++) {
|
|
|
|
for (x = 0; x < size; x++) {
|
|
|
|
*coeffs = (*coeffs + offset) >> shift;
|
|
|
|
coeffs++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (y = 0; y < size; y++) {
|
|
|
|
for (x = 0; x < size; x++) {
|
2017-12-22 04:12:03 +02:00
|
|
|
*coeffs = *(uint16_t*)coeffs << -shift;
|
2014-07-14 22:17:33 +03:00
|
|
|
coeffs++;
|
|
|
|
}
|
|
|
|
}
|
2013-10-12 12:55:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-02 13:59:02 +03:00
|
|
|
#define SET(dst, x) (dst) = (x)
|
|
|
|
#define SCALE(dst, x) (dst) = av_clip_int16(((x) + add) >> shift)
|
|
|
|
|
|
|
|
#define TR_4x4_LUMA(dst, src, step, assign) \
|
|
|
|
do { \
|
|
|
|
int c0 = src[0 * step] + src[2 * step]; \
|
|
|
|
int c1 = src[2 * step] + src[3 * step]; \
|
|
|
|
int c2 = src[0 * step] - src[3 * step]; \
|
|
|
|
int c3 = 74 * src[1 * step]; \
|
|
|
|
\
|
|
|
|
assign(dst[2 * step], 74 * (src[0 * step] - \
|
|
|
|
src[2 * step] + \
|
|
|
|
src[3 * step])); \
|
|
|
|
assign(dst[0 * step], 29 * c0 + 55 * c1 + c3); \
|
|
|
|
assign(dst[1 * step], 55 * c2 - 29 * c1 + c3); \
|
|
|
|
assign(dst[3 * step], 55 * c0 + 29 * c2 - c3); \
|
2013-10-12 12:55:48 +03:00
|
|
|
} while (0)
|
|
|
|
|
2014-07-14 22:17:33 +03:00
|
|
|
static void FUNC(transform_4x4_luma)(int16_t *coeffs)
|
2013-11-02 13:59:02 +03:00
|
|
|
{
|
2013-10-12 12:55:48 +03:00
|
|
|
int i;
|
2013-11-02 13:59:02 +03:00
|
|
|
int shift = 7;
|
2013-11-02 13:59:02 +03:00
|
|
|
int add = 1 << (shift - 1);
|
2013-10-12 12:55:48 +03:00
|
|
|
int16_t *src = coeffs;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
TR_4x4_LUMA(src, src, 4, SCALE);
|
|
|
|
src++;
|
|
|
|
}
|
|
|
|
|
|
|
|
shift = 20 - BIT_DEPTH;
|
2013-11-02 13:59:02 +03:00
|
|
|
add = 1 << (shift - 1);
|
2013-10-12 12:55:48 +03:00
|
|
|
for (i = 0; i < 4; i++) {
|
2014-07-14 22:17:33 +03:00
|
|
|
TR_4x4_LUMA(coeffs, coeffs, 1, SCALE);
|
2013-10-12 12:55:48 +03:00
|
|
|
coeffs += 4;
|
|
|
|
}
|
2013-11-02 13:59:02 +03:00
|
|
|
}
|
2013-10-12 12:55:48 +03:00
|
|
|
|
|
|
|
#undef TR_4x4_LUMA
|
|
|
|
|
2017-01-31 16:47:58 +02:00
|
|
|
#define TR_4(dst, src, dstep, sstep, assign, end) \
|
|
|
|
do { \
|
|
|
|
const int e0 = 64 * src[0 * sstep] + 64 * src[2 * sstep]; \
|
|
|
|
const int e1 = 64 * src[0 * sstep] - 64 * src[2 * sstep]; \
|
|
|
|
const int o0 = 83 * src[1 * sstep] + 36 * src[3 * sstep]; \
|
|
|
|
const int o1 = 36 * src[1 * sstep] - 83 * src[3 * sstep]; \
|
|
|
|
\
|
|
|
|
assign(dst[0 * dstep], e0 + o0); \
|
|
|
|
assign(dst[1 * dstep], e1 + o1); \
|
|
|
|
assign(dst[2 * dstep], e1 - o1); \
|
|
|
|
assign(dst[3 * dstep], e0 - o0); \
|
2013-10-12 12:55:48 +03:00
|
|
|
} while (0)
|
|
|
|
|
2017-01-31 16:47:58 +02:00
|
|
|
#define TR_8(dst, src, dstep, sstep, assign, end) \
|
2013-08-11 10:02:07 +03:00
|
|
|
do { \
|
|
|
|
int i, j; \
|
|
|
|
int e_8[4]; \
|
|
|
|
int o_8[4] = { 0 }; \
|
|
|
|
for (i = 0; i < 4; i++) \
|
2017-01-31 16:47:58 +02:00
|
|
|
for (j = 1; j < end; j += 2) \
|
2013-08-11 10:02:07 +03:00
|
|
|
o_8[i] += transform[4 * j][i] * src[j * sstep]; \
|
2017-01-31 16:47:58 +02:00
|
|
|
TR_4(e_8, src, 1, 2 * sstep, SET, 4); \
|
2013-08-11 10:02:07 +03:00
|
|
|
\
|
|
|
|
for (i = 0; i < 4; i++) { \
|
|
|
|
assign(dst[i * dstep], e_8[i] + o_8[i]); \
|
|
|
|
assign(dst[(7 - i) * dstep], e_8[i] - o_8[i]); \
|
|
|
|
} \
|
2013-10-12 12:55:48 +03:00
|
|
|
} while (0)
|
2013-11-02 02:31:49 +03:00
|
|
|
|
2017-01-31 16:47:58 +02:00
|
|
|
#define TR_16(dst, src, dstep, sstep, assign, end) \
|
2013-08-11 10:02:07 +03:00
|
|
|
do { \
|
|
|
|
int i, j; \
|
|
|
|
int e_16[8]; \
|
|
|
|
int o_16[8] = { 0 }; \
|
|
|
|
for (i = 0; i < 8; i++) \
|
2017-01-31 16:47:58 +02:00
|
|
|
for (j = 1; j < end; j += 2) \
|
2013-08-11 10:02:07 +03:00
|
|
|
o_16[i] += transform[2 * j][i] * src[j * sstep]; \
|
2017-01-31 16:47:58 +02:00
|
|
|
TR_8(e_16, src, 1, 2 * sstep, SET, 8); \
|
2013-08-11 10:02:07 +03:00
|
|
|
\
|
|
|
|
for (i = 0; i < 8; i++) { \
|
|
|
|
assign(dst[i * dstep], e_16[i] + o_16[i]); \
|
|
|
|
assign(dst[(15 - i) * dstep], e_16[i] - o_16[i]); \
|
|
|
|
} \
|
2013-10-12 12:55:48 +03:00
|
|
|
} while (0)
|
2013-11-02 02:31:49 +03:00
|
|
|
|
2017-01-31 16:47:58 +02:00
|
|
|
#define TR_32(dst, src, dstep, sstep, assign, end) \
|
2013-08-11 10:02:07 +03:00
|
|
|
do { \
|
|
|
|
int i, j; \
|
|
|
|
int e_32[16]; \
|
|
|
|
int o_32[16] = { 0 }; \
|
|
|
|
for (i = 0; i < 16; i++) \
|
2017-01-31 16:47:58 +02:00
|
|
|
for (j = 1; j < end; j += 2) \
|
2013-08-11 10:02:07 +03:00
|
|
|
o_32[i] += transform[j][i] * src[j * sstep]; \
|
2016-07-05 18:52:38 +02:00
|
|
|
TR_16(e_32, src, 1, 2 * sstep, SET, end / 2); \
|
2013-08-11 10:02:07 +03:00
|
|
|
\
|
|
|
|
for (i = 0; i < 16; i++) { \
|
|
|
|
assign(dst[i * dstep], e_32[i] + o_32[i]); \
|
|
|
|
assign(dst[(31 - i) * dstep], e_32[i] - o_32[i]); \
|
|
|
|
} \
|
2013-10-12 12:55:48 +03:00
|
|
|
} while (0)
|
|
|
|
|
2017-01-31 16:47:58 +02:00
|
|
|
#define IDCT_VAR4(H) \
|
2016-07-05 18:52:38 +02:00
|
|
|
int limit2 = FFMIN(col_limit + 4, H)
|
2017-01-31 16:47:58 +02:00
|
|
|
#define IDCT_VAR8(H) \
|
2016-07-05 18:52:38 +02:00
|
|
|
int limit = FFMIN(col_limit, H); \
|
|
|
|
int limit2 = FFMIN(col_limit + 4, H)
|
2014-07-14 22:17:33 +03:00
|
|
|
#define IDCT_VAR16(H) IDCT_VAR8(H)
|
|
|
|
#define IDCT_VAR32(H) IDCT_VAR8(H)
|
|
|
|
|
2016-07-04 15:31:16 +02:00
|
|
|
#define IDCT(H) \
|
2017-01-31 16:47:58 +02:00
|
|
|
static void FUNC(idct_ ## H ## x ## H )(int16_t *coeffs, \
|
2016-07-05 18:52:38 +02:00
|
|
|
int col_limit) \
|
2016-07-04 15:31:16 +02:00
|
|
|
{ \
|
|
|
|
int i; \
|
|
|
|
int shift = 7; \
|
|
|
|
int add = 1 << (shift - 1); \
|
|
|
|
int16_t *src = coeffs; \
|
2016-07-05 18:52:38 +02:00
|
|
|
IDCT_VAR ## H(H); \
|
2016-07-04 15:31:16 +02:00
|
|
|
\
|
|
|
|
for (i = 0; i < H; i++) { \
|
2017-01-31 16:47:58 +02:00
|
|
|
TR_ ## H(src, src, H, H, SCALE, limit2); \
|
|
|
|
if (limit2 < H && i%4 == 0 && !!i) \
|
|
|
|
limit2 -= 4; \
|
2016-07-04 15:31:16 +02:00
|
|
|
src++; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
shift = 20 - BIT_DEPTH; \
|
|
|
|
add = 1 << (shift - 1); \
|
|
|
|
for (i = 0; i < H; i++) { \
|
2017-01-31 16:47:58 +02:00
|
|
|
TR_ ## H(coeffs, coeffs, 1, 1, SCALE, limit); \
|
2016-07-04 15:31:16 +02:00
|
|
|
coeffs += H; \
|
|
|
|
} \
|
2013-10-12 12:55:48 +03:00
|
|
|
}
|
|
|
|
|
2016-07-04 15:37:52 +02:00
|
|
|
#define IDCT_DC(H) \
|
|
|
|
static void FUNC(idct_ ## H ## x ## H ## _dc)(int16_t *coeffs) \
|
|
|
|
{ \
|
|
|
|
int i, j; \
|
|
|
|
int shift = 14 - BIT_DEPTH; \
|
|
|
|
int add = 1 << (shift - 1); \
|
|
|
|
int coeff = (((coeffs[0] + 1) >> 1) + add) >> shift; \
|
|
|
|
\
|
|
|
|
for (j = 0; j < H; j++) { \
|
|
|
|
for (i = 0; i < H; i++) { \
|
|
|
|
coeffs[i + j * H] = coeff; \
|
|
|
|
} \
|
|
|
|
} \
|
2013-10-12 12:55:48 +03:00
|
|
|
}
|
|
|
|
|
2014-07-14 22:17:33 +03:00
|
|
|
IDCT( 4)
|
|
|
|
IDCT( 8)
|
|
|
|
IDCT(16)
|
|
|
|
IDCT(32)
|
|
|
|
|
|
|
|
IDCT_DC( 4)
|
|
|
|
IDCT_DC( 8)
|
|
|
|
IDCT_DC(16)
|
|
|
|
IDCT_DC(32)
|
|
|
|
|
|
|
|
#undef TR_4
|
|
|
|
#undef TR_8
|
|
|
|
#undef TR_16
|
|
|
|
#undef TR_32
|
2013-10-12 12:55:48 +03:00
|
|
|
|
2014-07-14 22:17:33 +03:00
|
|
|
#undef SET
|
|
|
|
#undef SCALE
|
2013-11-02 13:59:02 +03:00
|
|
|
|
2014-04-26 16:35:23 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2024-01-23 20:17:05 +02:00
|
|
|
#define ff_hevc_pel_filters ff_hevc_qpel_filters
|
2024-02-11 10:23:02 +02:00
|
|
|
#define DECL_HV_FILTER(f) \
|
|
|
|
const uint8_t *hf = ff_hevc_ ## f ## _filters[mx]; \
|
|
|
|
const uint8_t *vf = ff_hevc_ ## f ## _filters[my];
|
2024-01-23 20:17:05 +02:00
|
|
|
|
|
|
|
#define FW_PUT(p, f, t) \
|
|
|
|
static void FUNC(put_hevc_## f)(int16_t *dst, const uint8_t *src, ptrdiff_t srcstride, int height, \
|
|
|
|
intptr_t mx, intptr_t my, int width) \
|
|
|
|
{ \
|
|
|
|
DECL_HV_FILTER(p) \
|
|
|
|
FUNC(put_ ## t)(dst, src, srcstride, height, hf, vf, width); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define FW_PUT_UNI(p, f, t) \
|
|
|
|
static void FUNC(put_hevc_ ## f)(uint8_t *dst, ptrdiff_t dststride, const uint8_t *src, \
|
|
|
|
ptrdiff_t srcstride, int height, intptr_t mx, intptr_t my, int width) \
|
|
|
|
{ \
|
|
|
|
DECL_HV_FILTER(p) \
|
|
|
|
FUNC(put_ ## t)(dst, dststride, src, srcstride, height, hf, vf, width); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define FW_PUT_UNI_W(p, f, t) \
|
|
|
|
static void FUNC(put_hevc_ ## f)(uint8_t *dst, ptrdiff_t dststride, const uint8_t *src, \
|
|
|
|
ptrdiff_t srcstride,int height, int denom, int wx, int ox, \
|
|
|
|
intptr_t mx, intptr_t my, int width) \
|
|
|
|
{ \
|
|
|
|
DECL_HV_FILTER(p) \
|
|
|
|
FUNC(put_ ## t)(dst, dststride, src, srcstride, height, denom, wx, ox, hf, vf, width); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define FW_PUT_FUNCS(f, t, dir) \
|
|
|
|
FW_PUT(f, f ## _ ## dir, t ## _ ## dir) \
|
|
|
|
FW_PUT_UNI(f, f ## _uni_ ## dir, uni_ ## t ## _ ## dir) \
|
|
|
|
FW_PUT_UNI_W(f, f ## _uni_w_ ## dir, uni_## t ## _w_ ## dir)
|
|
|
|
|
|
|
|
FW_PUT(pel, pel_pixels, pixels)
|
|
|
|
FW_PUT_UNI(pel, pel_uni_pixels, uni_pixels)
|
|
|
|
FW_PUT_UNI_W(pel, pel_uni_w_pixels, uni_w_pixels)
|
|
|
|
|
|
|
|
FW_PUT_FUNCS(qpel, luma, h )
|
|
|
|
FW_PUT_FUNCS(qpel, luma, v )
|
|
|
|
FW_PUT_FUNCS(qpel, luma, hv )
|
|
|
|
FW_PUT_FUNCS(epel, chroma, h )
|
|
|
|
FW_PUT_FUNCS(epel, chroma, v )
|
|
|
|
FW_PUT_FUNCS(epel, chroma, hv )
|
2014-04-26 16:35:23 +03:00
|
|
|
|
2022-07-22 06:10:59 +02:00
|
|
|
static void FUNC(put_hevc_pel_bi_pixels)(uint8_t *_dst, ptrdiff_t _dststride, const uint8_t *_src, ptrdiff_t _srcstride,
|
|
|
|
const int16_t *src2,
|
2014-04-26 16:35:23 +03:00
|
|
|
int height, intptr_t mx, intptr_t my, int width)
|
|
|
|
{
|
|
|
|
int x, y;
|
2022-07-22 06:10:59 +02:00
|
|
|
const pixel *src = (const pixel *)_src;
|
2014-04-26 16:35:23 +03:00
|
|
|
ptrdiff_t srcstride = _srcstride / sizeof(pixel);
|
|
|
|
pixel *dst = (pixel *)_dst;
|
|
|
|
ptrdiff_t dststride = _dststride / sizeof(pixel);
|
|
|
|
|
|
|
|
int shift = 14 + 1 - BIT_DEPTH;
|
|
|
|
#if BIT_DEPTH < 14
|
|
|
|
int offset = 1 << (shift - 1);
|
|
|
|
#else
|
|
|
|
int offset = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (y = 0; y < height; y++) {
|
|
|
|
for (x = 0; x < width; x++)
|
|
|
|
dst[x] = av_clip_pixel(((src[x] << (14 - BIT_DEPTH)) + src2[x] + offset) >> shift);
|
|
|
|
src += srcstride;
|
|
|
|
dst += dststride;
|
2014-07-28 13:13:06 +03:00
|
|
|
src2 += MAX_PB_SIZE;
|
2014-04-26 16:35:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-22 06:10:59 +02:00
|
|
|
static void FUNC(put_hevc_pel_bi_w_pixels)(uint8_t *_dst, ptrdiff_t _dststride, const uint8_t *_src, ptrdiff_t _srcstride,
|
|
|
|
const int16_t *src2,
|
2014-04-26 16:35:23 +03:00
|
|
|
int height, int denom, int wx0, int wx1,
|
|
|
|
int ox0, int ox1, intptr_t mx, intptr_t my, int width)
|
|
|
|
{
|
|
|
|
int x, y;
|
2022-07-22 06:10:59 +02:00
|
|
|
const pixel *src = (const pixel *)_src;
|
2014-04-26 16:35:23 +03:00
|
|
|
ptrdiff_t srcstride = _srcstride / sizeof(pixel);
|
|
|
|
pixel *dst = (pixel *)_dst;
|
|
|
|
ptrdiff_t dststride = _dststride / sizeof(pixel);
|
|
|
|
|
|
|
|
int shift = 14 + 1 - BIT_DEPTH;
|
|
|
|
int log2Wd = denom + shift - 1;
|
|
|
|
|
|
|
|
ox0 = ox0 * (1 << (BIT_DEPTH - 8));
|
|
|
|
ox1 = ox1 * (1 << (BIT_DEPTH - 8));
|
|
|
|
for (y = 0; y < height; y++) {
|
|
|
|
for (x = 0; x < width; x++) {
|
2017-09-10 01:32:51 +02:00
|
|
|
dst[x] = av_clip_pixel(( (src[x] << (14 - BIT_DEPTH)) * wx1 + src2[x] * wx0 + (ox0 + ox1 + 1) * (1 << log2Wd)) >> (log2Wd + 1));
|
2014-04-26 16:35:23 +03:00
|
|
|
}
|
|
|
|
src += srcstride;
|
|
|
|
dst += dststride;
|
2014-07-28 13:13:06 +03:00
|
|
|
src2 += MAX_PB_SIZE;
|
2014-04-26 16:35:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#define QPEL_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])
|
|
|
|
|
2022-07-22 06:10:59 +02:00
|
|
|
static void FUNC(put_hevc_qpel_bi_h)(uint8_t *_dst, ptrdiff_t _dststride, const uint8_t *_src, ptrdiff_t _srcstride,
|
|
|
|
const int16_t *src2,
|
2014-04-26 16:35:23 +03:00
|
|
|
int height, intptr_t mx, intptr_t my, int width)
|
|
|
|
{
|
|
|
|
int x, y;
|
2022-07-22 06:10:59 +02:00
|
|
|
const pixel *src = (const pixel*)_src;
|
2014-04-26 16:35:23 +03:00
|
|
|
ptrdiff_t srcstride = _srcstride / sizeof(pixel);
|
|
|
|
pixel *dst = (pixel *)_dst;
|
|
|
|
ptrdiff_t dststride = _dststride / sizeof(pixel);
|
|
|
|
|
2024-02-11 10:23:02 +02:00
|
|
|
const int8_t *filter = ff_hevc_qpel_filters[mx];
|
2014-04-26 16:35:23 +03:00
|
|
|
|
|
|
|
int shift = 14 + 1 - BIT_DEPTH;
|
|
|
|
#if BIT_DEPTH < 14
|
|
|
|
int offset = 1 << (shift - 1);
|
|
|
|
#else
|
|
|
|
int offset = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (y = 0; y < height; y++) {
|
|
|
|
for (x = 0; x < width; x++)
|
|
|
|
dst[x] = av_clip_pixel(((QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) + src2[x] + offset) >> shift);
|
|
|
|
src += srcstride;
|
|
|
|
dst += dststride;
|
2014-07-28 13:13:06 +03:00
|
|
|
src2 += MAX_PB_SIZE;
|
2014-04-26 16:35:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-22 06:10:59 +02:00
|
|
|
static void FUNC(put_hevc_qpel_bi_v)(uint8_t *_dst, ptrdiff_t _dststride,
|
|
|
|
const uint8_t *_src, ptrdiff_t _srcstride, const int16_t *src2,
|
2014-04-26 16:35:23 +03:00
|
|
|
int height, intptr_t mx, intptr_t my, int width)
|
|
|
|
{
|
|
|
|
int x, y;
|
2022-07-22 06:10:59 +02:00
|
|
|
const pixel *src = (const pixel*)_src;
|
2014-04-26 16:35:23 +03:00
|
|
|
ptrdiff_t srcstride = _srcstride / sizeof(pixel);
|
|
|
|
pixel *dst = (pixel *)_dst;
|
|
|
|
ptrdiff_t dststride = _dststride / sizeof(pixel);
|
|
|
|
|
2024-02-11 10:23:02 +02:00
|
|
|
const int8_t *filter = ff_hevc_qpel_filters[my];
|
2014-04-26 16:35:23 +03:00
|
|
|
|
|
|
|
int shift = 14 + 1 - BIT_DEPTH;
|
|
|
|
#if BIT_DEPTH < 14
|
|
|
|
int offset = 1 << (shift - 1);
|
|
|
|
#else
|
|
|
|
int offset = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (y = 0; y < height; y++) {
|
|
|
|
for (x = 0; x < width; x++)
|
|
|
|
dst[x] = av_clip_pixel(((QPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) + src2[x] + offset) >> shift);
|
|
|
|
src += srcstride;
|
|
|
|
dst += dststride;
|
2014-07-28 13:13:06 +03:00
|
|
|
src2 += MAX_PB_SIZE;
|
2014-04-26 16:35:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-22 06:10:59 +02:00
|
|
|
static void FUNC(put_hevc_qpel_bi_hv)(uint8_t *_dst, ptrdiff_t _dststride,
|
|
|
|
const uint8_t *_src, ptrdiff_t _srcstride, const int16_t *src2,
|
2014-04-26 16:35:23 +03:00
|
|
|
int height, intptr_t mx, intptr_t my, int width)
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
const int8_t *filter;
|
2022-07-22 06:10:59 +02:00
|
|
|
const pixel *src = (const pixel*)_src;
|
2014-04-26 16:35:23 +03:00
|
|
|
ptrdiff_t srcstride = _srcstride / sizeof(pixel);
|
|
|
|
pixel *dst = (pixel *)_dst;
|
|
|
|
ptrdiff_t dststride = _dststride / sizeof(pixel);
|
|
|
|
int16_t tmp_array[(MAX_PB_SIZE + QPEL_EXTRA) * MAX_PB_SIZE];
|
|
|
|
int16_t *tmp = tmp_array;
|
|
|
|
int shift = 14 + 1 - BIT_DEPTH;
|
|
|
|
#if BIT_DEPTH < 14
|
|
|
|
int offset = 1 << (shift - 1);
|
|
|
|
#else
|
|
|
|
int offset = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
src -= QPEL_EXTRA_BEFORE * srcstride;
|
2024-02-11 10:23:02 +02:00
|
|
|
filter = ff_hevc_qpel_filters[mx];
|
2014-04-26 16:35:23 +03:00
|
|
|
for (y = 0; y < height + QPEL_EXTRA; y++) {
|
|
|
|
for (x = 0; x < width; x++)
|
|
|
|
tmp[x] = QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
|
|
|
|
src += srcstride;
|
|
|
|
tmp += MAX_PB_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = tmp_array + QPEL_EXTRA_BEFORE * MAX_PB_SIZE;
|
2024-02-11 10:23:02 +02:00
|
|
|
filter = ff_hevc_qpel_filters[my];
|
2014-04-26 16:35:23 +03:00
|
|
|
|
|
|
|
for (y = 0; y < height; y++) {
|
|
|
|
for (x = 0; x < width; x++)
|
|
|
|
dst[x] = av_clip_pixel(((QPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) + src2[x] + offset) >> shift);
|
|
|
|
tmp += MAX_PB_SIZE;
|
|
|
|
dst += dststride;
|
2014-07-28 13:13:06 +03:00
|
|
|
src2 += MAX_PB_SIZE;
|
2014-04-26 16:35:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-22 06:10:59 +02:00
|
|
|
static void FUNC(put_hevc_qpel_bi_w_h)(uint8_t *_dst, ptrdiff_t _dststride,
|
|
|
|
const uint8_t *_src, ptrdiff_t _srcstride, const int16_t *src2,
|
2014-04-26 16:35:23 +03:00
|
|
|
int height, int denom, int wx0, int wx1,
|
|
|
|
int ox0, int ox1, intptr_t mx, intptr_t my, int width)
|
|
|
|
{
|
|
|
|
int x, y;
|
2022-07-22 06:10:59 +02:00
|
|
|
const pixel *src = (const pixel*)_src;
|
2014-04-26 16:35:23 +03:00
|
|
|
ptrdiff_t srcstride = _srcstride / sizeof(pixel);
|
|
|
|
pixel *dst = (pixel *)_dst;
|
|
|
|
ptrdiff_t dststride = _dststride / sizeof(pixel);
|
|
|
|
|
2024-02-11 10:23:02 +02:00
|
|
|
const int8_t *filter = ff_hevc_qpel_filters[mx];
|
2014-04-26 16:35:23 +03:00
|
|
|
|
|
|
|
int shift = 14 + 1 - BIT_DEPTH;
|
|
|
|
int log2Wd = denom + shift - 1;
|
|
|
|
|
|
|
|
ox0 = ox0 * (1 << (BIT_DEPTH - 8));
|
|
|
|
ox1 = ox1 * (1 << (BIT_DEPTH - 8));
|
|
|
|
for (y = 0; y < height; y++) {
|
|
|
|
for (x = 0; x < width; x++)
|
|
|
|
dst[x] = av_clip_pixel(((QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) * wx1 + src2[x] * wx0 +
|
2017-12-27 00:24:45 +02:00
|
|
|
((ox0 + ox1 + 1) * (1 << log2Wd))) >> (log2Wd + 1));
|
2014-04-26 16:35:23 +03:00
|
|
|
src += srcstride;
|
|
|
|
dst += dststride;
|
2014-07-28 13:13:06 +03:00
|
|
|
src2 += MAX_PB_SIZE;
|
2014-04-26 16:35:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-22 06:10:59 +02:00
|
|
|
static void FUNC(put_hevc_qpel_bi_w_v)(uint8_t *_dst, ptrdiff_t _dststride,
|
|
|
|
const uint8_t *_src, ptrdiff_t _srcstride, const int16_t *src2,
|
2014-04-26 16:35:23 +03:00
|
|
|
int height, int denom, int wx0, int wx1,
|
|
|
|
int ox0, int ox1, intptr_t mx, intptr_t my, int width)
|
|
|
|
{
|
|
|
|
int x, y;
|
2022-07-22 06:10:59 +02:00
|
|
|
const pixel *src = (const pixel*)_src;
|
2014-04-26 16:35:23 +03:00
|
|
|
ptrdiff_t srcstride = _srcstride / sizeof(pixel);
|
|
|
|
pixel *dst = (pixel *)_dst;
|
|
|
|
ptrdiff_t dststride = _dststride / sizeof(pixel);
|
|
|
|
|
2024-02-11 10:23:02 +02:00
|
|
|
const int8_t *filter = ff_hevc_qpel_filters[my];
|
2014-04-26 16:35:23 +03:00
|
|
|
|
|
|
|
int shift = 14 + 1 - BIT_DEPTH;
|
|
|
|
int log2Wd = denom + shift - 1;
|
|
|
|
|
|
|
|
ox0 = ox0 * (1 << (BIT_DEPTH - 8));
|
|
|
|
ox1 = ox1 * (1 << (BIT_DEPTH - 8));
|
|
|
|
for (y = 0; y < height; y++) {
|
|
|
|
for (x = 0; x < width; x++)
|
|
|
|
dst[x] = av_clip_pixel(((QPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) * wx1 + src2[x] * wx0 +
|
2017-12-27 00:24:45 +02:00
|
|
|
((ox0 + ox1 + 1) * (1 << log2Wd))) >> (log2Wd + 1));
|
2014-04-26 16:35:23 +03:00
|
|
|
src += srcstride;
|
|
|
|
dst += dststride;
|
2014-07-28 13:13:06 +03:00
|
|
|
src2 += MAX_PB_SIZE;
|
2014-04-26 16:35:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-22 06:10:59 +02:00
|
|
|
static void FUNC(put_hevc_qpel_bi_w_hv)(uint8_t *_dst, ptrdiff_t _dststride,
|
|
|
|
const uint8_t *_src, ptrdiff_t _srcstride, const int16_t *src2,
|
2014-04-26 16:35:23 +03:00
|
|
|
int height, int denom, int wx0, int wx1,
|
|
|
|
int ox0, int ox1, intptr_t mx, intptr_t my, int width)
|
2013-10-12 12:55:48 +03:00
|
|
|
{
|
|
|
|
int x, y;
|
2014-04-26 16:35:23 +03:00
|
|
|
const int8_t *filter;
|
2022-07-22 06:10:59 +02:00
|
|
|
const pixel *src = (const pixel*)_src;
|
2013-10-12 12:55:48 +03:00
|
|
|
ptrdiff_t srcstride = _srcstride / sizeof(pixel);
|
2014-04-26 16:35:23 +03:00
|
|
|
pixel *dst = (pixel *)_dst;
|
|
|
|
ptrdiff_t dststride = _dststride / sizeof(pixel);
|
|
|
|
int16_t tmp_array[(MAX_PB_SIZE + QPEL_EXTRA) * MAX_PB_SIZE];
|
|
|
|
int16_t *tmp = tmp_array;
|
|
|
|
int shift = 14 + 1 - BIT_DEPTH;
|
|
|
|
int log2Wd = denom + shift - 1;
|
2013-10-12 12:55:48 +03:00
|
|
|
|
2014-04-26 16:35:23 +03:00
|
|
|
src -= QPEL_EXTRA_BEFORE * srcstride;
|
2024-02-11 10:23:02 +02:00
|
|
|
filter = ff_hevc_qpel_filters[mx];
|
2014-04-26 16:35:23 +03:00
|
|
|
for (y = 0; y < height + QPEL_EXTRA; y++) {
|
2013-11-02 13:59:02 +03:00
|
|
|
for (x = 0; x < width; x++)
|
2014-04-26 16:35:23 +03:00
|
|
|
tmp[x] = QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
|
2013-10-12 12:55:48 +03:00
|
|
|
src += srcstride;
|
2014-04-26 16:35:23 +03:00
|
|
|
tmp += MAX_PB_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = tmp_array + QPEL_EXTRA_BEFORE * MAX_PB_SIZE;
|
2024-02-11 10:23:02 +02:00
|
|
|
filter = ff_hevc_qpel_filters[my];
|
2014-04-26 16:35:23 +03:00
|
|
|
|
|
|
|
ox0 = ox0 * (1 << (BIT_DEPTH - 8));
|
|
|
|
ox1 = ox1 * (1 << (BIT_DEPTH - 8));
|
|
|
|
for (y = 0; y < height; y++) {
|
|
|
|
for (x = 0; x < width; x++)
|
|
|
|
dst[x] = av_clip_pixel(((QPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) * wx1 + src2[x] * wx0 +
|
2017-12-15 14:06:30 +02:00
|
|
|
((ox0 + ox1 + 1) * (1 << log2Wd))) >> (log2Wd + 1));
|
2014-04-26 16:35:23 +03:00
|
|
|
tmp += MAX_PB_SIZE;
|
|
|
|
dst += dststride;
|
2014-07-28 13:13:06 +03:00
|
|
|
src2 += MAX_PB_SIZE;
|
2013-10-12 12:55:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-26 16:35:23 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#define EPEL_FILTER(src, stride) \
|
|
|
|
(filter[0] * src[x - stride] + \
|
|
|
|
filter[1] * src[x] + \
|
|
|
|
filter[2] * src[x + stride] + \
|
|
|
|
filter[3] * src[x + 2 * stride])
|
2013-10-12 12:55:48 +03:00
|
|
|
|
2022-07-22 06:10:59 +02:00
|
|
|
static void FUNC(put_hevc_epel_bi_h)(uint8_t *_dst, ptrdiff_t _dststride,
|
|
|
|
const uint8_t *_src, ptrdiff_t _srcstride, const int16_t *src2,
|
2014-04-26 16:35:23 +03:00
|
|
|
int height, intptr_t mx, intptr_t my, int width)
|
|
|
|
{
|
|
|
|
int x, y;
|
2022-07-22 06:10:59 +02:00
|
|
|
const pixel *src = (const pixel *)_src;
|
2014-04-26 16:35:23 +03:00
|
|
|
ptrdiff_t srcstride = _srcstride / sizeof(pixel);
|
|
|
|
pixel *dst = (pixel *)_dst;
|
|
|
|
ptrdiff_t dststride = _dststride / sizeof(pixel);
|
2024-02-11 10:23:02 +02:00
|
|
|
const int8_t *filter = ff_hevc_epel_filters[mx];
|
2014-04-26 16:35:23 +03:00
|
|
|
int shift = 14 + 1 - BIT_DEPTH;
|
|
|
|
#if BIT_DEPTH < 14
|
|
|
|
int offset = 1 << (shift - 1);
|
|
|
|
#else
|
|
|
|
int offset = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (y = 0; y < height; y++) {
|
|
|
|
for (x = 0; x < width; x++) {
|
|
|
|
dst[x] = av_clip_pixel(((EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) + src2[x] + offset) >> shift);
|
|
|
|
}
|
|
|
|
dst += dststride;
|
|
|
|
src += srcstride;
|
2014-07-28 13:13:06 +03:00
|
|
|
src2 += MAX_PB_SIZE;
|
2013-10-12 12:55:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-22 06:10:59 +02:00
|
|
|
static void FUNC(put_hevc_epel_bi_v)(uint8_t *_dst, ptrdiff_t _dststride,
|
|
|
|
const uint8_t *_src, ptrdiff_t _srcstride, const int16_t *src2,
|
2014-04-26 16:35:23 +03:00
|
|
|
int height, intptr_t mx, intptr_t my, int width)
|
|
|
|
{
|
|
|
|
int x, y;
|
2022-07-22 06:10:59 +02:00
|
|
|
const pixel *src = (const pixel *)_src;
|
2014-04-26 16:35:23 +03:00
|
|
|
ptrdiff_t srcstride = _srcstride / sizeof(pixel);
|
2024-02-11 10:23:02 +02:00
|
|
|
const int8_t *filter = ff_hevc_epel_filters[my];
|
2014-04-26 16:35:23 +03:00
|
|
|
pixel *dst = (pixel *)_dst;
|
|
|
|
ptrdiff_t dststride = _dststride / sizeof(pixel);
|
2013-10-12 12:55:48 +03:00
|
|
|
int shift = 14 + 1 - BIT_DEPTH;
|
|
|
|
#if BIT_DEPTH < 14
|
|
|
|
int offset = 1 << (shift - 1);
|
|
|
|
#else
|
|
|
|
int offset = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (y = 0; y < height; y++) {
|
2013-11-02 13:59:02 +03:00
|
|
|
for (x = 0; x < width; x++)
|
2014-04-26 16:35:23 +03:00
|
|
|
dst[x] = av_clip_pixel(((EPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) + src2[x] + offset) >> shift);
|
2013-10-12 12:55:48 +03:00
|
|
|
dst += dststride;
|
2014-04-26 16:35:23 +03:00
|
|
|
src += srcstride;
|
2014-07-28 13:13:06 +03:00
|
|
|
src2 += MAX_PB_SIZE;
|
2014-04-26 16:35:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-22 06:10:59 +02:00
|
|
|
static void FUNC(put_hevc_epel_bi_hv)(uint8_t *_dst, ptrdiff_t _dststride,
|
|
|
|
const uint8_t *_src, ptrdiff_t _srcstride, const int16_t *src2,
|
2014-04-26 16:35:23 +03:00
|
|
|
int height, intptr_t mx, intptr_t my, int width)
|
2013-10-12 12:55:48 +03:00
|
|
|
{
|
2014-04-26 16:35:23 +03:00
|
|
|
int x, y;
|
2022-07-22 06:10:59 +02:00
|
|
|
const pixel *src = (const pixel *)_src;
|
2014-04-26 16:35:23 +03:00
|
|
|
ptrdiff_t srcstride = _srcstride / sizeof(pixel);
|
2013-11-02 02:31:49 +03:00
|
|
|
pixel *dst = (pixel *)_dst;
|
2013-10-12 12:55:48 +03:00
|
|
|
ptrdiff_t dststride = _dststride / sizeof(pixel);
|
2024-02-11 10:23:02 +02:00
|
|
|
const int8_t *filter = ff_hevc_epel_filters[mx];
|
2014-04-26 16:35:23 +03:00
|
|
|
int16_t tmp_array[(MAX_PB_SIZE + EPEL_EXTRA) * MAX_PB_SIZE];
|
|
|
|
int16_t *tmp = tmp_array;
|
|
|
|
int shift = 14 + 1 - BIT_DEPTH;
|
|
|
|
#if BIT_DEPTH < 14
|
|
|
|
int offset = 1 << (shift - 1);
|
|
|
|
#else
|
|
|
|
int offset = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
src -= EPEL_EXTRA_BEFORE * srcstride;
|
|
|
|
|
|
|
|
for (y = 0; y < height + EPEL_EXTRA; y++) {
|
|
|
|
for (x = 0; x < width; x++)
|
|
|
|
tmp[x] = EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
|
|
|
|
src += srcstride;
|
|
|
|
tmp += MAX_PB_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = tmp_array + EPEL_EXTRA_BEFORE * MAX_PB_SIZE;
|
2024-02-11 10:23:02 +02:00
|
|
|
filter = ff_hevc_epel_filters[my];
|
2014-04-26 16:35:23 +03:00
|
|
|
|
|
|
|
for (y = 0; y < height; y++) {
|
|
|
|
for (x = 0; x < width; x++)
|
|
|
|
dst[x] = av_clip_pixel(((EPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) + src2[x] + offset) >> shift);
|
|
|
|
tmp += MAX_PB_SIZE;
|
|
|
|
dst += dststride;
|
2014-07-28 13:13:06 +03:00
|
|
|
src2 += MAX_PB_SIZE;
|
2014-04-26 16:35:23 +03:00
|
|
|
}
|
|
|
|
}
|
2013-10-12 12:55:48 +03:00
|
|
|
|
2022-07-22 06:10:59 +02:00
|
|
|
static void FUNC(put_hevc_epel_bi_w_h)(uint8_t *_dst, ptrdiff_t _dststride,
|
|
|
|
const uint8_t *_src, ptrdiff_t _srcstride, const int16_t *src2,
|
2014-04-26 16:35:23 +03:00
|
|
|
int height, int denom, int wx0, int wx1,
|
|
|
|
int ox0, int ox1, intptr_t mx, intptr_t my, int width)
|
2013-10-12 12:55:48 +03:00
|
|
|
{
|
2014-04-26 16:35:23 +03:00
|
|
|
int x, y;
|
2022-07-22 06:10:59 +02:00
|
|
|
const pixel *src = (const pixel *)_src;
|
2014-04-26 16:35:23 +03:00
|
|
|
ptrdiff_t srcstride = _srcstride / sizeof(pixel);
|
|
|
|
pixel *dst = (pixel *)_dst;
|
|
|
|
ptrdiff_t dststride = _dststride / sizeof(pixel);
|
2024-02-11 10:23:02 +02:00
|
|
|
const int8_t *filter = ff_hevc_epel_filters[mx];
|
2014-04-26 16:35:23 +03:00
|
|
|
int shift = 14 + 1 - BIT_DEPTH;
|
|
|
|
int log2Wd = denom + shift - 1;
|
|
|
|
|
|
|
|
ox0 = ox0 * (1 << (BIT_DEPTH - 8));
|
|
|
|
ox1 = ox1 * (1 << (BIT_DEPTH - 8));
|
|
|
|
for (y = 0; y < height; y++) {
|
|
|
|
for (x = 0; x < width; x++)
|
|
|
|
dst[x] = av_clip_pixel(((EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) * wx1 + src2[x] * wx0 +
|
2017-11-30 22:27:37 +02:00
|
|
|
((ox0 + ox1 + 1) * (1 << log2Wd))) >> (log2Wd + 1));
|
2014-04-26 16:35:23 +03:00
|
|
|
src += srcstride;
|
|
|
|
dst += dststride;
|
2014-07-28 13:13:06 +03:00
|
|
|
src2 += MAX_PB_SIZE;
|
2014-04-26 16:35:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-22 06:10:59 +02:00
|
|
|
static void FUNC(put_hevc_epel_bi_w_v)(uint8_t *_dst, ptrdiff_t _dststride,
|
|
|
|
const uint8_t *_src, ptrdiff_t _srcstride, const int16_t *src2,
|
2014-04-26 16:35:23 +03:00
|
|
|
int height, int denom, int wx0, int wx1,
|
|
|
|
int ox0, int ox1, intptr_t mx, intptr_t my, int width)
|
|
|
|
{
|
|
|
|
int x, y;
|
2022-07-22 06:10:59 +02:00
|
|
|
const pixel *src = (const pixel *)_src;
|
2014-04-26 16:35:23 +03:00
|
|
|
ptrdiff_t srcstride = _srcstride / sizeof(pixel);
|
2024-02-11 10:23:02 +02:00
|
|
|
const int8_t *filter = ff_hevc_epel_filters[my];
|
2014-04-26 16:35:23 +03:00
|
|
|
pixel *dst = (pixel *)_dst;
|
|
|
|
ptrdiff_t dststride = _dststride / sizeof(pixel);
|
|
|
|
int shift = 14 + 1 - BIT_DEPTH;
|
|
|
|
int log2Wd = denom + shift - 1;
|
2013-10-12 12:55:48 +03:00
|
|
|
|
2014-04-26 16:35:23 +03:00
|
|
|
ox0 = ox0 * (1 << (BIT_DEPTH - 8));
|
|
|
|
ox1 = ox1 * (1 << (BIT_DEPTH - 8));
|
2013-10-12 12:55:48 +03:00
|
|
|
for (y = 0; y < height; y++) {
|
2013-11-02 13:59:02 +03:00
|
|
|
for (x = 0; x < width; x++)
|
2014-04-26 16:35:23 +03:00
|
|
|
dst[x] = av_clip_pixel(((EPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) * wx1 + src2[x] * wx0 +
|
2017-11-17 23:01:29 +02:00
|
|
|
((ox0 + ox1 + 1) * (1 << log2Wd))) >> (log2Wd + 1));
|
2014-04-26 16:35:23 +03:00
|
|
|
src += srcstride;
|
2013-10-12 12:55:48 +03:00
|
|
|
dst += dststride;
|
2014-07-28 13:13:06 +03:00
|
|
|
src2 += MAX_PB_SIZE;
|
2014-04-26 16:35:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-22 06:10:59 +02:00
|
|
|
static void FUNC(put_hevc_epel_bi_w_hv)(uint8_t *_dst, ptrdiff_t _dststride,
|
|
|
|
const uint8_t *_src, ptrdiff_t _srcstride, const int16_t *src2,
|
2014-04-26 16:35:23 +03:00
|
|
|
int height, int denom, int wx0, int wx1,
|
|
|
|
int ox0, int ox1, intptr_t mx, intptr_t my, int width)
|
|
|
|
{
|
|
|
|
int x, y;
|
2022-07-22 06:10:59 +02:00
|
|
|
const pixel *src = (const pixel *)_src;
|
2014-04-26 16:35:23 +03:00
|
|
|
ptrdiff_t srcstride = _srcstride / sizeof(pixel);
|
|
|
|
pixel *dst = (pixel *)_dst;
|
|
|
|
ptrdiff_t dststride = _dststride / sizeof(pixel);
|
2024-02-11 10:23:02 +02:00
|
|
|
const int8_t *filter = ff_hevc_epel_filters[mx];
|
2014-04-26 16:35:23 +03:00
|
|
|
int16_t tmp_array[(MAX_PB_SIZE + EPEL_EXTRA) * MAX_PB_SIZE];
|
|
|
|
int16_t *tmp = tmp_array;
|
|
|
|
int shift = 14 + 1 - BIT_DEPTH;
|
|
|
|
int log2Wd = denom + shift - 1;
|
|
|
|
|
|
|
|
src -= EPEL_EXTRA_BEFORE * srcstride;
|
|
|
|
|
|
|
|
for (y = 0; y < height + EPEL_EXTRA; y++) {
|
|
|
|
for (x = 0; x < width; x++)
|
|
|
|
tmp[x] = EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
|
|
|
|
src += srcstride;
|
|
|
|
tmp += MAX_PB_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = tmp_array + EPEL_EXTRA_BEFORE * MAX_PB_SIZE;
|
2024-02-11 10:23:02 +02:00
|
|
|
filter = ff_hevc_epel_filters[my];
|
2014-04-26 16:35:23 +03:00
|
|
|
|
|
|
|
ox0 = ox0 * (1 << (BIT_DEPTH - 8));
|
|
|
|
ox1 = ox1 * (1 << (BIT_DEPTH - 8));
|
|
|
|
for (y = 0; y < height; y++) {
|
|
|
|
for (x = 0; x < width; x++)
|
|
|
|
dst[x] = av_clip_pixel(((EPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) * wx1 + src2[x] * wx0 +
|
2017-10-02 04:18:21 +02:00
|
|
|
((ox0 + ox1 + 1) * (1 << log2Wd))) >> (log2Wd + 1));
|
2014-04-26 16:35:23 +03:00
|
|
|
tmp += MAX_PB_SIZE;
|
|
|
|
dst += dststride;
|
2014-07-28 13:13:06 +03:00
|
|
|
src2 += MAX_PB_SIZE;
|
2014-04-26 16:35:23 +03:00
|
|
|
}
|
2017-01-30 12:50:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// line zero
|
2013-11-02 02:31:49 +03:00
|
|
|
#define P3 pix[-4 * xstride]
|
|
|
|
#define P2 pix[-3 * xstride]
|
|
|
|
#define P1 pix[-2 * xstride]
|
2013-11-02 13:59:02 +03:00
|
|
|
#define P0 pix[-1 * xstride]
|
2013-11-02 13:59:02 +03:00
|
|
|
#define Q0 pix[0 * xstride]
|
2013-11-02 13:59:02 +03:00
|
|
|
#define Q1 pix[1 * xstride]
|
2013-11-02 02:31:49 +03:00
|
|
|
#define Q2 pix[2 * xstride]
|
|
|
|
#define Q3 pix[3 * xstride]
|
2013-10-12 12:55:48 +03:00
|
|
|
|
|
|
|
// line three. used only for deblocking decision
|
2013-11-02 02:31:49 +03:00
|
|
|
#define TP3 pix[-4 * xstride + 3 * ystride]
|
|
|
|
#define TP2 pix[-3 * xstride + 3 * ystride]
|
|
|
|
#define TP1 pix[-2 * xstride + 3 * ystride]
|
2013-11-02 13:59:02 +03:00
|
|
|
#define TP0 pix[-1 * xstride + 3 * ystride]
|
2013-11-02 13:59:02 +03:00
|
|
|
#define TQ0 pix[0 * xstride + 3 * ystride]
|
2013-11-02 13:59:02 +03:00
|
|
|
#define TQ1 pix[1 * xstride + 3 * ystride]
|
2013-11-02 02:31:49 +03:00
|
|
|
#define TQ2 pix[2 * xstride + 3 * ystride]
|
|
|
|
#define TQ3 pix[3 * xstride + 3 * ystride]
|
|
|
|
|
2024-01-06 12:51:31 +02:00
|
|
|
#include "h26x/h2656_deblock_template.c"
|
|
|
|
|
2013-11-02 02:31:49 +03:00
|
|
|
static void FUNC(hevc_loop_filter_luma)(uint8_t *_pix,
|
|
|
|
ptrdiff_t _xstride, ptrdiff_t _ystride,
|
2022-07-22 06:10:59 +02:00
|
|
|
int beta, const int *_tc,
|
|
|
|
const uint8_t *_no_p, const uint8_t *_no_q)
|
2013-10-12 12:55:48 +03:00
|
|
|
{
|
|
|
|
ptrdiff_t xstride = _xstride / sizeof(pixel);
|
|
|
|
ptrdiff_t ystride = _ystride / sizeof(pixel);
|
|
|
|
|
2014-07-19 15:50:11 +03:00
|
|
|
beta <<= BIT_DEPTH - 8;
|
|
|
|
|
2024-01-06 12:51:31 +02:00
|
|
|
for (int j = 0; j < 2; j++) {
|
|
|
|
pixel* pix = (pixel*)_pix + j * 4 * ystride;
|
2013-11-02 02:31:49 +03:00
|
|
|
const int dp0 = abs(P2 - 2 * P1 + P0);
|
|
|
|
const int dq0 = abs(Q2 - 2 * Q1 + Q0);
|
2013-10-12 12:55:48 +03:00
|
|
|
const int dp3 = abs(TP2 - 2 * TP1 + TP0);
|
|
|
|
const int dq3 = abs(TQ2 - 2 * TQ1 + TQ0);
|
|
|
|
const int d0 = dp0 + dq0;
|
|
|
|
const int d3 = dp3 + dq3;
|
2013-11-02 02:31:49 +03:00
|
|
|
const int tc = _tc[j] << (BIT_DEPTH - 8);
|
2013-10-12 12:55:48 +03:00
|
|
|
const int no_p = _no_p[j];
|
|
|
|
const int no_q = _no_q[j];
|
|
|
|
|
2024-01-06 12:51:31 +02:00
|
|
|
if (d0 + d3 < beta) {
|
2013-10-12 12:55:48 +03:00
|
|
|
const int beta_3 = beta >> 3;
|
|
|
|
const int beta_2 = beta >> 2;
|
2013-11-02 02:31:49 +03:00
|
|
|
const int tc25 = ((tc * 5 + 1) >> 1);
|
2013-10-12 12:55:48 +03:00
|
|
|
|
2013-11-02 02:31:49 +03:00
|
|
|
if (abs(P3 - P0) + abs(Q3 - Q0) < beta_3 && abs(P0 - Q0) < tc25 &&
|
2013-10-12 12:55:48 +03:00
|
|
|
abs(TP3 - TP0) + abs(TQ3 - TQ0) < beta_3 && abs(TP0 - TQ0) < tc25 &&
|
|
|
|
(d0 << 1) < beta_2 && (d3 << 1) < beta_2) {
|
|
|
|
const int tc2 = tc << 1;
|
2024-01-06 12:51:31 +02:00
|
|
|
FUNC(loop_filter_luma_strong)(pix, xstride, ystride, tc2, tc2, tc2, no_p, no_q);
|
|
|
|
} else {
|
2013-10-12 12:55:48 +03:00
|
|
|
int nd_p = 1;
|
|
|
|
int nd_q = 1;
|
|
|
|
if (dp0 + dp3 < ((beta + (beta >> 1)) >> 3))
|
|
|
|
nd_p = 2;
|
|
|
|
if (dq0 + dq3 < ((beta + (beta >> 1)) >> 3))
|
|
|
|
nd_q = 2;
|
2024-01-06 12:51:31 +02:00
|
|
|
FUNC(loop_filter_luma_weak)(pix, xstride, ystride, tc, beta, no_p, no_q, nd_p, nd_q);
|
2013-10-12 12:55:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void FUNC(hevc_loop_filter_chroma)(uint8_t *_pix, ptrdiff_t _xstride,
|
2022-07-22 06:10:59 +02:00
|
|
|
ptrdiff_t _ystride, const int *_tc,
|
|
|
|
const uint8_t *_no_p, const uint8_t *_no_q)
|
2013-10-12 12:55:48 +03:00
|
|
|
{
|
2024-01-06 12:51:31 +02:00
|
|
|
int no_p, no_q;
|
2013-10-12 12:55:48 +03:00
|
|
|
ptrdiff_t xstride = _xstride / sizeof(pixel);
|
|
|
|
ptrdiff_t ystride = _ystride / sizeof(pixel);
|
2024-01-06 12:51:31 +02:00
|
|
|
const int size = 4;
|
2013-10-12 12:55:48 +03:00
|
|
|
|
2024-01-06 12:51:31 +02:00
|
|
|
for (int j = 0; j < 2; j++) {
|
|
|
|
pixel *pix = (pixel *)_pix + j * size * ystride;
|
2013-10-12 12:55:48 +03:00
|
|
|
const int tc = _tc[j] << (BIT_DEPTH - 8);
|
2024-01-06 12:51:31 +02:00
|
|
|
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);
|
2013-10-12 12:55:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void FUNC(hevc_h_loop_filter_chroma)(uint8_t *pix, ptrdiff_t stride,
|
2022-07-22 06:10:59 +02:00
|
|
|
const int32_t *tc, const uint8_t *no_p,
|
|
|
|
const uint8_t *no_q)
|
2013-10-12 12:55:48 +03:00
|
|
|
{
|
|
|
|
FUNC(hevc_loop_filter_chroma)(pix, stride, sizeof(pixel), tc, no_p, no_q);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void FUNC(hevc_v_loop_filter_chroma)(uint8_t *pix, ptrdiff_t stride,
|
2022-07-22 06:10:59 +02:00
|
|
|
const int32_t *tc, const uint8_t *no_p,
|
|
|
|
const uint8_t *no_q)
|
2013-10-12 12:55:48 +03:00
|
|
|
{
|
|
|
|
FUNC(hevc_loop_filter_chroma)(pix, sizeof(pixel), stride, tc, no_p, no_q);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void FUNC(hevc_h_loop_filter_luma)(uint8_t *pix, ptrdiff_t stride,
|
2022-07-22 06:10:59 +02:00
|
|
|
int beta, const int32_t *tc, const uint8_t *no_p,
|
|
|
|
const uint8_t *no_q)
|
2013-10-12 12:55:48 +03:00
|
|
|
{
|
2013-11-02 02:31:49 +03:00
|
|
|
FUNC(hevc_loop_filter_luma)(pix, stride, sizeof(pixel),
|
|
|
|
beta, tc, no_p, no_q);
|
2013-10-12 12:55:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void FUNC(hevc_v_loop_filter_luma)(uint8_t *pix, ptrdiff_t stride,
|
2022-07-22 06:10:59 +02:00
|
|
|
int beta, const int32_t *tc, const uint8_t *no_p,
|
|
|
|
const uint8_t *no_q)
|
2013-10-12 12:55:48 +03:00
|
|
|
{
|
2013-11-02 02:31:49 +03:00
|
|
|
FUNC(hevc_loop_filter_luma)(pix, sizeof(pixel), stride,
|
|
|
|
beta, tc, no_p, no_q);
|
2013-10-12 12:55:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#undef P3
|
|
|
|
#undef P2
|
|
|
|
#undef P1
|
|
|
|
#undef P0
|
|
|
|
#undef Q0
|
|
|
|
#undef Q1
|
|
|
|
#undef Q2
|
|
|
|
#undef Q3
|
|
|
|
|
|
|
|
#undef TP3
|
|
|
|
#undef TP2
|
|
|
|
#undef TP1
|
|
|
|
#undef TP0
|
|
|
|
#undef TQ0
|
|
|
|
#undef TQ1
|
|
|
|
#undef TQ2
|
|
|
|
#undef TQ3
|