FFmpeg
lut3d.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2024 Niklas Haas
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef SWSCALE_LUT3D_H
22 #define SWSCALE_LUT3D_H
23 
24 #include <stdint.h>
25 
26 #include "libavutil/csp.h"
27 #include "libavutil/pixfmt.h"
28 
29 #include "cms.h"
30 #include "csputils.h"
31 #include "utils.h"
32 
33 enum {
34  /* Input LUT size. This is only calculated once. */
36  INPUT_LUT_SIZE = (1 << INPUT_LUT_BITS) + 1, /* +1 to simplify interpolation */
37 
38  /* Tone mapping LUT size. This is regenerated possibly per frame. */
41 
42  /* Output LUT size (for dynamic tone mapping). This is only calculated once. */
45 
48 };
49 
50 typedef struct SwsLut3D {
52  bool dynamic;
53 
54  /* Gamut mapping 3DLUT(s) */
57 
58  /* Split tone mapping LUT (for dynamic tone mapping) */
59  v2u16_t tone_map[TONE_LUT_SIZE]; /* new luma, desaturation */
60 } SwsLut3D;
61 
63 void ff_sws_lut3d_free(SwsLut3D **lut3d);
64 
65 /**
66  * Test to see if a given format is supported by the 3DLUT input/output code.
67  */
68 bool ff_sws_lut3d_test_fmt(enum AVPixelFormat fmt, int output);
69 
70 /**
71  * Pick the best compatible pixfmt for a given SwsFormat.
72  */
74 
75 /**
76  * Recalculate the (static) 3DLUT state with new settings. This will recompute
77  * everything. To only update per-frame tone mapping state, instead call
78  * ff_sws_lut3d_update().
79  *
80  * Returns 0 or a negative error code.
81  */
82 int ff_sws_lut3d_generate(SwsLut3D *lut3d, enum AVPixelFormat fmt_in,
83  enum AVPixelFormat fmt_out, const SwsColorMap *map);
84 
85 /**
86  * Update the tone mapping state. This will only use per-frame metadata. The
87  * static metadata is ignored.
88  */
89 void ff_sws_lut3d_update(SwsLut3D *lut3d, const SwsColor *new_src);
90 
91 /**
92  * Applies a color transformation to a plane. The format must match the format
93  * provided during ff_sws_lut3d_update().
94  */
95 void ff_sws_lut3d_apply(const SwsLut3D *lut3d, const uint8_t *in, int in_stride,
96  uint8_t *out, int out_stride, int w, int h);
97 
98 #endif /* SWSCALE_LUT3D_H */
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
SwsLut3D::dynamic
bool dynamic
Definition: lut3d.h:52
ff_sws_lut3d_update
void ff_sws_lut3d_update(SwsLut3D *lut3d, const SwsColor *new_src)
Update the tone mapping state.
Definition: lut3d.c:252
out
FILE * out
Definition: movenc.c:55
v3u16_t
Definition: csputils.h:77
SwsLut3D::output
v3u16_t output[OUTPUT_LUT_SIZE_PT][OUTPUT_LUT_SIZE_PT][OUTPUT_LUT_SIZE_I]
Definition: lut3d.h:56
output
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
Definition: filter_design.txt:225
w
uint8_t w
Definition: llviddspenc.c:38
SwsLut3D::tone_map
v2u16_t tone_map[TONE_LUT_SIZE]
Definition: lut3d.h:59
OUTPUT_LUT_SIZE_PT
@ OUTPUT_LUT_SIZE_PT
Definition: lut3d.h:47
SwsColorMap
Definition: cms.h:60
TONE_LUT_SIZE
@ TONE_LUT_SIZE
Definition: lut3d.h:40
utils.h
ff_sws_lut3d_test_fmt
bool ff_sws_lut3d_test_fmt(enum AVPixelFormat fmt, int output)
Test to see if a given format is supported by the 3DLUT input/output code.
Definition: lut3d.c:47
ff_sws_lut3d_generate
int ff_sws_lut3d_generate(SwsLut3D *lut3d, enum AVPixelFormat fmt_in, enum AVPixelFormat fmt_out, const SwsColorMap *map)
Recalculate the (static) 3DLUT state with new settings.
Definition: lut3d.c:224
INPUT_LUT_SIZE
@ INPUT_LUT_SIZE
Definition: lut3d.h:36
ff_sws_lut3d_free
void ff_sws_lut3d_free(SwsLut3D **lut3d)
Definition: lut3d.c:42
ff_sws_lut3d_apply
void ff_sws_lut3d_apply(const SwsLut3D *lut3d, const uint8_t *in, int in_stride, uint8_t *out, int out_stride, int w, int h)
Applies a color transformation to a plane.
Definition: lut3d.c:263
ff_sws_lut3d_pick_pixfmt
enum AVPixelFormat ff_sws_lut3d_pick_pixfmt(SwsFormat fmt, int output)
Pick the best compatible pixfmt for a given SwsFormat.
Definition: lut3d.c:52
v2u16_t
Definition: csputils.h:73
ff_sws_lut3d_alloc
SwsLut3D * ff_sws_lut3d_alloc(void)
Definition: lut3d.c:32
SwsLut3D::input
v3u16_t input[INPUT_LUT_SIZE][INPUT_LUT_SIZE][INPUT_LUT_SIZE]
Definition: lut3d.h:55
SwsFormat
Definition: utils.h:75
csp.h
SwsColor
Definition: utils.h:58
OUTPUT_LUT_BITS_PT
@ OUTPUT_LUT_BITS_PT
Definition: lut3d.h:44
SwsLut3D::map
SwsColorMap map
Definition: lut3d.h:51
OUTPUT_LUT_SIZE_I
@ OUTPUT_LUT_SIZE_I
Definition: lut3d.h:46
SwsLut3D
Definition: lut3d.h:50
OUTPUT_LUT_BITS_I
@ OUTPUT_LUT_BITS_I
Definition: lut3d.h:43
INPUT_LUT_BITS
@ INPUT_LUT_BITS
Definition: lut3d.h:35
pixfmt.h
cms.h
map
const VDPAUPixFmtMap * map
Definition: hwcontext_vdpau.c:71
h
h
Definition: vp9dsp_template.c:2070
TONE_LUT_BITS
@ TONE_LUT_BITS
Definition: lut3d.h:39
csputils.h