Go to the documentation of this file.
40 #define NS(n) ((n) < 0 ? (int)((n)*65536.0-0.5+DBL_EPSILON) : (int)((n)*65536.0+0.5))
41 #define CB(n) av_clip_uint8(n)
44 { +0.7152, +0.0722, +0.2126 },
45 { +0.5900, +0.1100, +0.3000 },
46 { +0.5870, +0.1140, +0.2990 },
47 { +0.7010, +0.0870, +0.2120 },
48 { +0.6780, +0.0593, +0.2627 },
81 #define OFFSET(x) offsetof(ColorMatrixContext, x)
82 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
138 for (
i = 0;
i < 3;
i++)
139 for (j = 0; j < 3; j++)
140 cm[
i][j] = yuv[
i][0] * rgb[0][j] + yuv[
i][1] * rgb[1][j] + yuv[
i][2] * rgb[2][j];
146 double yuv_coeff[5][3][3];
147 double rgb_coeffd[5][3][3];
148 double yuv_convertd[25][3][3];
149 double bscale, rscale;
152 for (
i = 0;
i < 5;
i++) {
156 bscale = 0.5 / (yuv_coeff[
i][0][1] - 1.0);
157 rscale = 0.5 / (yuv_coeff[
i][0][2] - 1.0);
158 yuv_coeff[
i][1][0] = bscale * yuv_coeff[
i][0][0];
159 yuv_coeff[
i][1][1] = 0.5;
160 yuv_coeff[
i][1][2] = bscale * yuv_coeff[
i][0][2];
161 yuv_coeff[
i][2][0] = rscale * yuv_coeff[
i][0][0];
162 yuv_coeff[
i][2][1] = rscale * yuv_coeff[
i][0][1];
163 yuv_coeff[
i][2][2] = 0.5;
165 for (
i = 0;
i < 5;
i++)
167 for (
i = 0;
i < 5;
i++) {
168 for (j = 0; j < 5; j++) {
170 for (k = 0; k < 3; k++) {
171 color->yuv_convert[v][k][0] =
NS(yuv_convertd[v][k][0]);
172 color->yuv_convert[v][k][1] =
NS(yuv_convertd[v][k][1]);
173 color->yuv_convert[v][k][2] =
NS(yuv_convertd[v][k][2]);
175 if (
color->yuv_convert[v][0][0] != 65536 ||
color->yuv_convert[v][1][0] != 0 ||
176 color->yuv_convert[v][2][0] != 0) {
184 static const char *
const color_modes[] = {
"bt709",
"fcc",
"bt601",
"smpte240m",
"bt2020"};
212 const int src_pitch =
src->linesize[0];
213 const int dst_pitch = dst->
linesize[0];
214 const int slice_start = (
height * jobnr ) / nb_jobs;
216 const unsigned char *srcp =
src->data[0] + slice_start * src_pitch;
217 unsigned char *dstp = dst->
data[0] + slice_start * dst_pitch;
218 const int c2 =
td->c2;
219 const int c3 =
td->c3;
220 const int c4 =
td->c4;
221 const int c5 =
td->c5;
222 const int c6 =
td->c6;
223 const int c7 =
td->c7;
226 for (y = slice_start; y <
slice_end; y++) {
227 for (x = 0; x <
width; x += 4) {
228 const int u = srcp[x + 0] - 128;
229 const int v = srcp[x + 2] - 128;
230 const int uvval =
c2 *
u + c3 * v + 1081344;
231 dstp[x + 0] =
CB((c4 *
u + c5 * v + 8421376) >> 16);
232 dstp[x + 1] =
CB((65536 * (srcp[x + 1] - 16) + uvval) >> 16);
233 dstp[x + 2] =
CB((c6 *
u + c7 * v + 8421376) >> 16);
234 dstp[x + 3] =
CB((65536 * (srcp[x + 3] - 16) + uvval) >> 16);
250 const int slice_start = (
height * jobnr ) / nb_jobs;
252 const int src_pitchY =
src->linesize[0];
253 const int src_pitchUV =
src->linesize[1];
254 const unsigned char *srcpU =
src->data[1] + slice_start * src_pitchUV;
255 const unsigned char *srcpV =
src->data[2] + slice_start * src_pitchUV;
256 const unsigned char *srcpY =
src->data[0] + slice_start * src_pitchY;
257 const int dst_pitchY = dst->
linesize[0];
258 const int dst_pitchUV = dst->
linesize[1];
259 unsigned char *dstpU = dst->
data[1] + slice_start * dst_pitchUV;
260 unsigned char *dstpV = dst->
data[2] + slice_start * dst_pitchUV;
261 unsigned char *dstpY = dst->
data[0] + slice_start * dst_pitchY;
262 const int c2 =
td->c2;
263 const int c3 =
td->c3;
264 const int c4 =
td->c4;
265 const int c5 =
td->c5;
266 const int c6 =
td->c6;
267 const int c7 =
td->c7;
270 for (y = slice_start; y <
slice_end; y++) {
271 for (x = 0; x <
width; x++) {
272 const int u = srcpU[x] - 128;
273 const int v = srcpV[x] - 128;
274 const int uvval =
c2 *
u + c3 * v + 1081344;
275 dstpY[x] =
CB((65536 * (srcpY[x] - 16) + uvval) >> 16);
276 dstpU[x] =
CB((c4 *
u + c5 * v + 8421376) >> 16);
277 dstpV[x] =
CB((c6 *
u + c7 * v + 8421376) >> 16);
281 srcpU += src_pitchUV;
282 srcpV += src_pitchUV;
283 dstpU += dst_pitchUV;
284 dstpV += dst_pitchUV;
297 const int slice_start = (
height * jobnr ) / nb_jobs;
299 const int src_pitchY =
src->linesize[0];
300 const int src_pitchUV =
src->linesize[1];
301 const unsigned char *srcpU =
src->data[1] + slice_start * src_pitchUV;
302 const unsigned char *srcpV =
src->data[2] + slice_start * src_pitchUV;
303 const unsigned char *srcpY =
src->data[0] + slice_start * src_pitchY;
304 const int dst_pitchY = dst->
linesize[0];
305 const int dst_pitchUV = dst->
linesize[1];
306 unsigned char *dstpU = dst->
data[1] + slice_start * dst_pitchUV;
307 unsigned char *dstpV = dst->
data[2] + slice_start * dst_pitchUV;
308 unsigned char *dstpY = dst->
data[0] + slice_start * dst_pitchY;
309 const int c2 =
td->c2;
310 const int c3 =
td->c3;
311 const int c4 =
td->c4;
312 const int c5 =
td->c5;
313 const int c6 =
td->c6;
314 const int c7 =
td->c7;
317 for (y = slice_start; y <
slice_end; y++) {
318 for (x = 0; x <
width; x += 2) {
319 const int u = srcpU[x >> 1] - 128;
320 const int v = srcpV[x >> 1] - 128;
321 const int uvval =
c2 *
u + c3 * v + 1081344;
322 dstpY[x + 0] =
CB((65536 * (srcpY[x + 0] - 16) + uvval) >> 16);
323 dstpY[x + 1] =
CB((65536 * (srcpY[x + 1] - 16) + uvval) >> 16);
324 dstpU[x >> 1] =
CB((c4 *
u + c5 * v + 8421376) >> 16);
325 dstpV[x >> 1] =
CB((c6 *
u + c7 * v + 8421376) >> 16);
329 srcpU += src_pitchUV;
330 srcpV += src_pitchUV;
331 dstpU += dst_pitchUV;
332 dstpV += dst_pitchUV;
345 const int slice_start = ((
height * jobnr ) / nb_jobs) << 1;
347 const int src_pitchY =
src->linesize[0];
348 const int src_pitchUV =
src->linesize[1];
349 const int dst_pitchY = dst->
linesize[0];
350 const int dst_pitchUV = dst->
linesize[1];
351 const unsigned char *srcpY =
src->data[0] + src_pitchY * slice_start;
352 const unsigned char *srcpU =
src->data[1] + src_pitchUV * (slice_start >> 1);
353 const unsigned char *srcpV =
src->data[2] + src_pitchUV * (slice_start >> 1);
354 const unsigned char *srcpN =
src->data[0] + src_pitchY * (slice_start + 1);
355 unsigned char *dstpU = dst->
data[1] + dst_pitchUV * (slice_start >> 1);
356 unsigned char *dstpV = dst->
data[2] + dst_pitchUV * (slice_start >> 1);
357 unsigned char *dstpY = dst->
data[0] + dst_pitchY * slice_start;
358 unsigned char *dstpN = dst->
data[0] + dst_pitchY * (slice_start + 1);
359 const int c2 =
td->c2;
360 const int c3 =
td->c3;
361 const int c4 =
td->c4;
362 const int c5 =
td->c5;
363 const int c6 =
td->c6;
364 const int c7 =
td->c7;
367 for (y = slice_start; y <
slice_end; y += 2) {
368 for (x = 0; x <
width; x += 2) {
369 const int u = srcpU[x >> 1] - 128;
370 const int v = srcpV[x >> 1] - 128;
371 const int uvval =
c2 *
u + c3 * v + 1081344;
372 dstpY[x + 0] =
CB((65536 * (srcpY[x + 0] - 16) + uvval) >> 16);
373 dstpY[x + 1] =
CB((65536 * (srcpY[x + 1] - 16) + uvval) >> 16);
374 dstpN[x + 0] =
CB((65536 * (srcpN[x + 0] - 16) + uvval) >> 16);
375 dstpN[x + 1] =
CB((65536 * (srcpN[x + 1] - 16) + uvval) >> 16);
376 dstpU[x >> 1] =
CB((c4 *
u + c5 * v + 8421376) >> 16);
377 dstpV[x >> 1] =
CB((c6 *
u + c7 * v + 8421376) >> 16);
379 srcpY += src_pitchY << 1;
380 dstpY += dst_pitchY << 1;
381 srcpN += src_pitchY << 1;
382 dstpN += dst_pitchY << 1;
383 srcpU += src_pitchUV;
384 srcpV += src_pitchUV;
385 dstpU += dst_pitchUV;
386 dstpV += dst_pitchUV;
450 av_log(
ctx,
AV_LOG_ERROR,
"Input frame does not specify a supported colorspace, and none has been specified as source either\n");
458 switch(
color->dest) {
511 .
name =
"colormatrix",
518 .priv_class = &colormatrix_class,
AVFilter ff_vf_colormatrix
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
AVPixelFormat
Pixel format.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
#define u(width, name, range_min, range_max)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
int yuv_convert[25][3][3]
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
This structure describes decoded (raw) audio or video data.
#define AV_LOG_VERBOSE
Detailed information.
static void solve_coefficients(double cm[3][3], double rgb[3][3], double yuv[3][3])
const char * name
Filter name.
AVFormatInternal * internal
An opaque field for libavformat internal usage.
A link between two filters.
@ AVCOL_SPC_BT2020_CL
ITU-R BT2020 constant luminance system.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
@ AVCOL_SPC_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
static int process_slice_uyvy422(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
A filter pad used for either input or output.
static const AVFilterPad colormatrix_inputs[]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int process_slice_yuv420p(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
@ AVCOL_SPC_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
static void calc_coefficients(AVFilterContext *ctx)
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
static const AVFilterPad outputs[]
static enum AVPixelFormat pix_fmts[]
static int filter_frame(AVFilterLink *link, AVFrame *in)
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
static const double yuv_coeff_luma[5][3]
static void inverse3x3(double im[3][3], double m[3][3])
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a link
Describe the class of an AVClass context structure.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
static int process_slice_yuv422p(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
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 inputs
static int process_slice_yuv444p(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
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 source
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static int config_input(AVFilterLink *inlink)
AVFILTER_DEFINE_CLASS(colormatrix)
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
@ AVCOL_SPC_SMPTE240M
functionally identical to above
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
static av_cold int init(AVFilterContext *ctx)
#define i(width, name, range_min, range_max)
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
int w
agreed upon image width
AVColorSpace
YUV colorspace type.
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Used for passing data between threads.
const char * name
Pad name.
static const char *const color_modes[]
static int query_formats(AVFilterContext *ctx)
@ AV_PIX_FMT_UYVY422
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
static const AVFilterPad colormatrix_outputs[]
int h
agreed upon image height
static const AVOption colormatrix_options[]
@ AVCOL_SPC_FCC
FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
#define flags(name, subs,...)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.