1cabdff1aSopenharmony_ci/*
2cabdff1aSopenharmony_ci * H.274 film grain synthesis
3cabdff1aSopenharmony_ci * Copyright (c) 2021 Niklas Haas <ffmpeg@haasn.xyz>
4cabdff1aSopenharmony_ci *
5cabdff1aSopenharmony_ci * This file is part of FFmpeg.
6cabdff1aSopenharmony_ci *
7cabdff1aSopenharmony_ci * FFmpeg is free software; you can redistribute it and/or
8cabdff1aSopenharmony_ci * modify it under the terms of the GNU Lesser General Public
9cabdff1aSopenharmony_ci * License as published by the Free Software Foundation; either
10cabdff1aSopenharmony_ci * version 2.1 of the License, or (at your option) any later version.
11cabdff1aSopenharmony_ci *
12cabdff1aSopenharmony_ci * FFmpeg is distributed in the hope that it will be useful,
13cabdff1aSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of
14cabdff1aSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15cabdff1aSopenharmony_ci * Lesser General Public License for more details.
16cabdff1aSopenharmony_ci *
17cabdff1aSopenharmony_ci * You should have received a copy of the GNU Lesser General Public
18cabdff1aSopenharmony_ci * License along with FFmpeg; if not, write to the Free Software
19cabdff1aSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20cabdff1aSopenharmony_ci */
21cabdff1aSopenharmony_ci
22cabdff1aSopenharmony_ci/**
23cabdff1aSopenharmony_ci * @file
24cabdff1aSopenharmony_ci * H.274 film grain synthesis.
25cabdff1aSopenharmony_ci * @author Niklas Haas <ffmpeg@haasn.xyz>
26cabdff1aSopenharmony_ci */
27cabdff1aSopenharmony_ci
28cabdff1aSopenharmony_ci#ifndef AVCODEC_H274_H
29cabdff1aSopenharmony_ci#define AVCODEC_H274_H
30cabdff1aSopenharmony_ci
31cabdff1aSopenharmony_ci#include "libavutil/film_grain_params.h"
32cabdff1aSopenharmony_ci
33cabdff1aSopenharmony_ci// Must be initialized to {0} prior to first usage
34cabdff1aSopenharmony_citypedef struct H274FilmGrainDatabase {
35cabdff1aSopenharmony_ci    // Database of film grain patterns, lazily computed as-needed
36cabdff1aSopenharmony_ci    int8_t db[13 /* h */][13 /* v */][64][64];
37cabdff1aSopenharmony_ci    uint16_t residency[13 /* h */]; // bit field of v
38cabdff1aSopenharmony_ci
39cabdff1aSopenharmony_ci    // Temporary buffer for slice generation
40cabdff1aSopenharmony_ci    int16_t slice_tmp[64][64];
41cabdff1aSopenharmony_ci} H274FilmGrainDatabase;
42cabdff1aSopenharmony_ci
43cabdff1aSopenharmony_ci// Synthesizes film grain on top of `in` and stores the result to `out`. `out`
44cabdff1aSopenharmony_ci// must already have been allocated and set to the same size and format as
45cabdff1aSopenharmony_ci// `in`.
46cabdff1aSopenharmony_ci//
47cabdff1aSopenharmony_ci// Returns a negative error code on error, such as invalid params.
48cabdff1aSopenharmony_ciint ff_h274_apply_film_grain(AVFrame *out, const AVFrame *in,
49cabdff1aSopenharmony_ci                             H274FilmGrainDatabase *db,
50cabdff1aSopenharmony_ci                             const AVFilmGrainParams *params);
51cabdff1aSopenharmony_ci
52cabdff1aSopenharmony_ci#endif /* AVCODEC_H274_H */
53