FFmpeg
raw_color_params.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2026 Lynne <dev@lynne.ee>
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 AVUTIL_RAW_COLOR_PARAMS_H
22 #define AVUTIL_RAW_COLOR_PARAMS_H
23 
24 #include <stddef.h>
25 #include <stdint.h>
26 
27 #include "frame.h"
28 #include "rational.h"
29 
32 
33  /**
34  * The union is valid when interpreted as AVProResRawColorParams
35  * (codec.prores_raw).
36  */
38 };
39 
40 /**
41  * ProRes RAW per-frame color transform, parsed from the prrf frame header.
42  *
43  * The correct rendering pipeline is:
44  * -> (sample - black_level) / (white_level - black_level)
45  * -> per-channel white balance (wb_red, 1.0 for G, wb_blue) pre-debayer
46  * -> debayer
47  * -> color_matrix (camera RGB -> CIE 1931 XYZ relative to D65)
48  * -> gain (scene-linear scale)
49  *
50  * Black/white levels live on the outer AVRawColorParams. The matrix output
51  * is linear-light CIE XYZ D65; convert to a working RGB space downstream.
52  *
53  * @note The struct must be allocated as part of AVRawColorParams using
54  * av_raw_color_params_alloc(). Its size is not a part of the public ABI.
55  */
56 typedef struct AVProResRawColorParams {
57  /**
58  * White balance multiplier for the red channel, applied pre-debayer.
59  */
61 
62  /**
63  * White balance multiplier for the blue channel, applied pre-debayer.
64  * (The green channel is implicit 1.0 for ProRes RAW)
65  */
67 
68  /**
69  * 3x3 row-major color matrix from camera RGB to linear-light CIE 1931
70  * XYZ relative to the D65 illuminant, applied post-debayer.
71  * out[i] = sum_j color_matrix[i][j] * in[j].
72  */
74 
75  /**
76  * Post-matrix scene-linear scaling factor. Encodes highlight headroom the
77  * encoder reserved; multiply the matrixed values by this to recover
78  * scene-linear light.
79  */
82 
83 /**
84  * Per-frame color information for a RAW camera codec. Carried as side data of
85  * type AV_FRAME_DATA_RAW_COLOR_PARAMS.
86  *
87  * The outer struct carries the fields every RAW codec exposes: the sensor's
88  * valid sample range and the white-balance correlated color temperature.
89  * The codec union holds the codec-specific transform parameters; `type`
90  * selects which member of the union is valid.
91  *
92  * The codec-specific transform (color_matrix or equivalent) always lands in
93  * linear-light CIE 1931 XYZ relative to the D65 illuminant, cameras don't
94  * have standard primaries, so XYZ is the only common target.
95  *
96  * @note The struct must be allocated using av_raw_color_params_alloc() or
97  * av_raw_color_params_create_side_data(). Its size is not a part of the
98  * public ABI.
99  */
100 typedef struct AVRawColorParams {
101  /**
102  * Selects which member of `codec` is valid.
103  */
105 
106  /**
107  * Lowest valid raw sample code (sensor black point)
108  */
110 
111  /**
112  * Highest valid raw sample code (sensor white point)
113  */
115 
116  /**
117  * Color temperature in Kelvin from with the camera's white balance.
118  * Informational; the math uses the codec-specific white-balance fields.
119  * 0 if not signaled.
120  */
121  uint32_t wb_cct;
122 
123  /**
124  * Additional codec-specific fields.
125  */
126  union {
128  } codec;
130 
131 /**
132  * Allocate an AVRawColorParams structure and zero-initialize it.
133  *
134  * @param size if non-NULL, set to sizeof(AVRawColorParams)
135  * @return the newly allocated struct or NULL on failure
136  */
138 
139 /**
140  * Allocate and add an AVRawColorParams structure to an existing AVFrame as
141  * AV_FRAME_DATA_RAW_COLOR_PARAMS side data.
142  *
143  * @return the newly allocated struct, or NULL on failure
144  */
146 
147 #endif /* AVUTIL_RAW_COLOR_PARAMS_H */
AV_RAW_COLOR_PARAMS_NONE
@ AV_RAW_COLOR_PARAMS_NONE
Definition: raw_color_params.h:31
av_raw_color_params_create_side_data
AVRawColorParams * av_raw_color_params_create_side_data(AVFrame *frame)
Allocate and add an AVRawColorParams structure to an existing AVFrame as AV_FRAME_DATA_RAW_COLOR_PARA...
Definition: raw_color_params.c:36
AVRawColorParams::wb_cct
uint32_t wb_cct
Color temperature in Kelvin from with the camera's white balance.
Definition: raw_color_params.h:121
rational.h
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:466
AVRawColorParams::prores_raw
AVProResRawColorParams prores_raw
Definition: raw_color_params.h:127
av_raw_color_params_alloc
AVRawColorParams * av_raw_color_params_alloc(size_t *size)
Allocate an AVRawColorParams structure and zero-initialize it.
Definition: raw_color_params.c:24
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AVProResRawColorParams
ProRes RAW per-frame color transform, parsed from the prrf frame header.
Definition: raw_color_params.h:56
size
int size
Definition: twinvq_data.h:10344
AVRawColorParams
Per-frame color information for a RAW camera codec.
Definition: raw_color_params.h:100
frame.h
AVProResRawColorParams::color_matrix
AVRational color_matrix[3][3]
3x3 row-major color matrix from camera RGB to linear-light CIE 1931 XYZ relative to the D65 illuminan...
Definition: raw_color_params.h:73
AVRawColorParams::type
enum AVRawColorParamsType type
Selects which member of codec is valid.
Definition: raw_color_params.h:104
AVProResRawColorParams::wb_blue
AVRational wb_blue
White balance multiplier for the blue channel, applied pre-debayer.
Definition: raw_color_params.h:66
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:265
AVRawColorParams::black_level
AVRational black_level
Lowest valid raw sample code (sensor black point)
Definition: raw_color_params.h:109
AVRawColorParams::codec
union AVRawColorParams::@548 codec
Additional codec-specific fields.
AVRawColorParamsType
AVRawColorParamsType
Definition: raw_color_params.h:30
AVProResRawColorParams::wb_red
AVRational wb_red
White balance multiplier for the red channel, applied pre-debayer.
Definition: raw_color_params.h:60
AVRawColorParams::white_level
AVRational white_level
Highest valid raw sample code (sensor white point)
Definition: raw_color_params.h:114
AVProResRawColorParams::gain
AVRational gain
Post-matrix scene-linear scaling factor.
Definition: raw_color_params.h:80
AV_RAW_COLOR_PARAMS_PRORES_RAW
@ AV_RAW_COLOR_PARAMS_PRORES_RAW
The union is valid when interpreted as AVProResRawColorParams (codec.prores_raw).
Definition: raw_color_params.h:37