[FFmpeg-devel] [PATCH 1/4] avcodec/aom_film_grain: add AOM film grain synthesis
Andreas Rheinhardt
andreas.rheinhardt at outlook.com
Wed Feb 28 17:45:50 EET 2024
Niklas Haas:
> From: Niklas Haas <git at haasn.dev>
>
> Implementation copied wholesale from dav1d, sans SIMD, under permissive
> license. This implementation was extensively verified to be bit-exact,
> so it serves as a much better starting point than trying to re-engineer
> this from scratch for no reason. (I also authored the original
> implementation in dav1d, so any "clean room" implementation would end up
> looking much the same, anyway)
>
> The notable changes I had to make while adapting this from the dav1d
> code-base to the FFmpeg codebase include:
>
> - replacing bitdepth parameters by preprocessor symbol (BITDEPTH)
> - reordering variable declarations to avoid triggering warnings
> - replacing several inline helpers by avutil equivalents
> - changing code that accesses frame metadata
> - replacing raw plane copying logic by av_image_copy_plane
>
> Apart from this, the implementation is basically unmodified.
> ---
> libavcodec/aom_film_grain.c | 288 +++++++++++++
> libavcodec/aom_film_grain.h | 38 ++
> libavcodec/aom_film_grain_template.c | 599 +++++++++++++++++++++++++++
> 3 files changed, 925 insertions(+)
> create mode 100644 libavcodec/aom_film_grain.c
> create mode 100644 libavcodec/aom_film_grain.h
> create mode 100644 libavcodec/aom_film_grain_template.c
>
> diff --git a/libavcodec/aom_film_grain.c b/libavcodec/aom_film_grain.c
> new file mode 100644
> index 00000000000..1bdaafc39f7
> --- /dev/null
> +++ b/libavcodec/aom_film_grain.c
> @@ -0,0 +1,288 @@
> +/*
> + * AOM film grain synthesis
> + * Copyright (c) 2023 Niklas Haas <ffmpeg at haasn.xyz>
> + *
> + * 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
> + */
> +
> +/**
> + * @file
> + * AOM film grain synthesis.
> + * @author Niklas Haas <ffmpeg at haasn.xyz>
> + */
> +
> +#include "libavutil/avassert.h"
> +#include "libavutil/imgutils.h"
> +
> +#include "aom_film_grain.h"
> +
> +// Common/shared helpers (not dependent on BITDEPTH)
> +static inline int get_random_number(const int bits, unsigned *const state) {
> + const int r = *state;
> + unsigned bit = ((r >> 0) ^ (r >> 1) ^ (r >> 3) ^ (r >> 12)) & 1;
> + *state = (r >> 1) | (bit << 15);
> +
> + return (*state >> (16 - bits)) & ((1 << bits) - 1);
> +}
> +
> +static inline int round2(const int x, const uint64_t shift) {
> + return (x + ((1 << shift) >> 1)) >> shift;
> +}
> +
> +static const int16_t gaussian_sequence[2048];
> +
> +#define BITDEPTH 12
> +#include "aom_film_grain_template.c"
> +#undef BITDEPTH
> +
> +#define BITDEPTH 10
> +#include "aom_film_grain_template.c"
> +#undef BITDEPTH
> +
> +#define BITDEPTH 9
> +#include "aom_film_grain_template.c"
> +#undef BITDEPTH
> +
> +#define BITDEPTH 8
> +#include "aom_film_grain_template.c"
> +#undef BITDEPTH
I don't think this should be duplicated for every bitdepth.
- Andreas
More information about the ffmpeg-devel
mailing list