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.3850, +0.5000, -0.1150 },
46 { -0.4540, -0.0460, +0.5000 } },
47 { { +0.5900, +0.1100, +0.3000 },
48 { -0.3310, +0.5000, -0.1690 },
49 { -0.4210, -0.0790, +0.5000 } },
50 { { +0.5870, +0.1140, +0.2990 },
51 { -0.3313, +0.5000, -0.1687 },
52 { -0.4187, -0.0813, +0.5000 } },
53 { { +0.7010, +0.0870, +0.2120 },
54 { -0.3840, +0.5000, -0.1160 },
55 { -0.4450, -0.0550, +0.5000 } },
69 int yuv_convert[16][3][3];
87 #define OFFSET(x) offsetof(ColorMatrixContext, x)
88 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
143 for (i = 0; i < 3; i++)
144 for (j = 0; j < 3; j++)
145 cm[i][j] = yuv[i][0] * rgb[0][j] + yuv[i][1] * rgb[1][j] + yuv[i][2] * rgb[2][j];
151 double rgb_coeffd[4][3][3];
152 double yuv_convertd[16][3][3];
156 for (i = 0; i < 4; i++)
158 for (i = 0; i < 4; i++) {
159 for (j = 0; j < 4; j++) {
161 for (k = 0; k < 3; k++) {
175 static const char *
const color_modes[] = {
"bt709",
"fcc",
"bt601",
"smpte240m"};
187 av_log(ctx,
AV_LOG_ERROR,
"Source and destination color space must not be identical\n");
205 const int slice_start = (height * jobnr ) / nb_jobs;
206 const int slice_end = (height * (jobnr+1)) / nb_jobs;
209 const int c2 = td->
c2;
210 const int c3 = td->
c3;
211 const int c4 = td->
c4;
212 const int c5 = td->
c5;
213 const int c6 = td->
c6;
214 const int c7 = td->
c7;
217 for (y = slice_start; y <
slice_end; y++) {
218 for (x = 0; x <
width; x += 4) {
219 const int u = srcp[x + 0] - 128;
220 const int v = srcp[x + 2] - 128;
221 const int uvval = c2 * u + c3 * v + 1081344;
222 dstp[x + 0] =
CB((c4 * u + c5 * v + 8421376) >> 16);
223 dstp[x + 1] =
CB((65536 * (srcp[x + 1] - 16) + uvval) >> 16);
224 dstp[x + 2] =
CB((c6 * u + c7 * v + 8421376) >> 16);
225 dstp[x + 3] =
CB((65536 * (srcp[x + 3] - 16) + uvval) >> 16);
241 const int slice_start = (height * jobnr ) / nb_jobs;
242 const int slice_end = (height * (jobnr+1)) / nb_jobs;
243 const int src_pitchY = src->
linesize[0];
244 const int src_pitchUV = src->
linesize[1];
245 const unsigned char *srcpU = src->
data[1] + slice_start * src_pitchUV;
246 const unsigned char *srcpV = src->
data[2] + slice_start * src_pitchUV;
247 const unsigned char *srcpY = src->
data[0] + slice_start * src_pitchY;
248 const int dst_pitchY = dst->
linesize[0];
249 const int dst_pitchUV = dst->
linesize[1];
250 unsigned char *dstpU = dst->
data[1] + slice_start * dst_pitchUV;
251 unsigned char *dstpV = dst->
data[2] + slice_start * dst_pitchUV;
252 unsigned char *dstpY = dst->
data[0] + slice_start * dst_pitchY;
253 const int c2 = td->
c2;
254 const int c3 = td->
c3;
255 const int c4 = td->
c4;
256 const int c5 = td->
c5;
257 const int c6 = td->
c6;
258 const int c7 = td->
c7;
261 for (y = slice_start; y <
slice_end; y++) {
262 for (x = 0; x <
width; x++) {
263 const int u = srcpU[x] - 128;
264 const int v = srcpV[x] - 128;
265 const int uvval = c2 * u + c3 * v + 1081344;
266 dstpY[x] =
CB((65536 * (srcpY[x] - 16) + uvval) >> 16);
267 dstpU[x] =
CB((c4 * u + c5 * v + 8421376) >> 16);
268 dstpV[x] =
CB((c6 * u + c7 * v + 8421376) >> 16);
272 srcpU += src_pitchUV;
273 srcpV += src_pitchUV;
274 dstpU += dst_pitchUV;
275 dstpV += dst_pitchUV;
288 const int slice_start = (height * jobnr ) / nb_jobs;
289 const int slice_end = (height * (jobnr+1)) / nb_jobs;
290 const int src_pitchY = src->
linesize[0];
291 const int src_pitchUV = src->
linesize[1];
292 const unsigned char *srcpU = src->
data[1] + slice_start * src_pitchUV;
293 const unsigned char *srcpV = src->
data[2] + slice_start * src_pitchUV;
294 const unsigned char *srcpY = src->
data[0] + slice_start * src_pitchY;
295 const int dst_pitchY = dst->
linesize[0];
296 const int dst_pitchUV = dst->
linesize[1];
297 unsigned char *dstpU = dst->
data[1] + slice_start * dst_pitchUV;
298 unsigned char *dstpV = dst->
data[2] + slice_start * dst_pitchUV;
299 unsigned char *dstpY = dst->
data[0] + slice_start * dst_pitchY;
300 const int c2 = td->
c2;
301 const int c3 = td->
c3;
302 const int c4 = td->
c4;
303 const int c5 = td->
c5;
304 const int c6 = td->
c6;
305 const int c7 = td->
c7;
308 for (y = slice_start; y <
slice_end; y++) {
309 for (x = 0; x <
width; x += 2) {
310 const int u = srcpU[x >> 1] - 128;
311 const int v = srcpV[x >> 1] - 128;
312 const int uvval = c2 * u + c3 * v + 1081344;
313 dstpY[x + 0] =
CB((65536 * (srcpY[x + 0] - 16) + uvval) >> 16);
314 dstpY[x + 1] =
CB((65536 * (srcpY[x + 1] - 16) + uvval) >> 16);
315 dstpU[x >> 1] =
CB((c4 * u + c5 * v + 8421376) >> 16);
316 dstpV[x >> 1] =
CB((c6 * u + c7 * v + 8421376) >> 16);
320 srcpU += src_pitchUV;
321 srcpV += src_pitchUV;
322 dstpU += dst_pitchUV;
323 dstpV += dst_pitchUV;
336 const int slice_start = ((height * jobnr ) / nb_jobs) << 1;
337 const int slice_end = ((height * (jobnr+1)) / nb_jobs) << 1;
338 const int src_pitchY = src->
linesize[0];
339 const int src_pitchUV = src->
linesize[1];
340 const int dst_pitchY = dst->
linesize[0];
341 const int dst_pitchUV = dst->
linesize[1];
342 const unsigned char *srcpY = src->
data[0] + src_pitchY * slice_start;
343 const unsigned char *srcpU = src->
data[1] + src_pitchUV * (slice_start >> 1);
344 const unsigned char *srcpV = src->
data[2] + src_pitchUV * (slice_start >> 1);
345 const unsigned char *srcpN = src->
data[0] + src_pitchY * (slice_start + 1);
346 unsigned char *dstpU = dst->
data[1] + dst_pitchUV * (slice_start >> 1);
347 unsigned char *dstpV = dst->
data[2] + dst_pitchUV * (slice_start >> 1);
348 unsigned char *dstpY = dst->
data[0] + dst_pitchY * slice_start;
349 unsigned char *dstpN = dst->
data[0] + dst_pitchY * (slice_start + 1);
350 const int c2 = td->
c2;
351 const int c3 = td->
c3;
352 const int c4 = td->
c4;
353 const int c5 = td->
c5;
354 const int c6 = td->
c6;
355 const int c7 = td->
c7;
358 for (y = slice_start; y <
slice_end; y += 2) {
359 for (x = 0; x <
width; x += 2) {
360 const int u = srcpU[x >> 1] - 128;
361 const int v = srcpV[x >> 1] - 128;
362 const int uvval = c2 * u + c3 * v + 1081344;
363 dstpY[x + 0] =
CB((65536 * (srcpY[x + 0] - 16) + uvval) >> 16);
364 dstpY[x + 1] =
CB((65536 * (srcpY[x + 1] - 16) + uvval) >> 16);
365 dstpN[x + 0] =
CB((65536 * (srcpN[x + 0] - 16) + uvval) >> 16);
366 dstpN[x + 1] =
CB((65536 * (srcpN[x + 1] - 16) + uvval) >> 16);
367 dstpU[x >> 1] =
CB((c4 * u + c5 * v + 8421376) >> 16);
368 dstpV[x >> 1] =
CB((c6 * u + c7 * v + 8421376) >> 16);
370 srcpY += src_pitchY << 1;
371 dstpY += dst_pitchY << 1;
372 srcpN += src_pitchY << 1;
373 dstpN += dst_pitchY << 1;
374 srcpU += src_pitchUV;
375 srcpV += src_pitchUV;
376 dstpU += dst_pitchUV;
377 dstpV += dst_pitchUV;
439 av_log(ctx,
AV_LOG_ERROR,
"Input frame does not specify a supported colorspace, and none has been specified as source either\n");
443 color->
mode = source * 4 + color->
dest;
447 switch(color->
dest) {
499 .
name =
"colormatrix",
504 .
inputs = colormatrix_inputs,
505 .
outputs = colormatrix_outputs,
506 .priv_class = &colormatrix_class,
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
static av_cold int init(AVFilterContext *ctx)
static const char *const color_modes[]
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
This structure describes decoded (raw) audio or video data.
BYTE int const BYTE int src_pitch
static int filter_frame(AVFilterLink *link, AVFrame *in)
static const double yuv_coeff[4][3][3]
static void solve_coefficients(double cm[3][3], double rgb[3][3], const double yuv[3][3])
int yuv_convert[16][3][3]
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Main libavfilter public API header.
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601 ...
int h
agreed upon image height
static int process_slice_yuv444p(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above ...
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
static int query_formats(AVFilterContext *ctx)
struct AVFilterGraph * graph
filtergraph this filter belongs to
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
BYTE int const BYTE * srcp
const char * name
Pad name.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
AVColorSpace
YUV colorspace type.
static const AVFilterPad colormatrix_inputs[]
int nb_threads
Maximum number of threads used by filters in this graph.
#define AV_LOG_VERBOSE
Detailed information.
static int config_input(AVFilterLink *inlink)
A filter pad used for either input or output.
A link between two filters.
static int process_slice_yuv422p(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
int width
width and height of the video frame
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
void av_frame_set_colorspace(AVFrame *frame, enum AVColorSpace val)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static int process_slice_uyvy422(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
void * priv
private data for use by the filter
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
AVFILTER_DEFINE_CLASS(colormatrix)
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
static void inverse3x3(double im[3][3], const double m[3][3])
int w
agreed upon image width
static const AVFilterPad outputs[]
FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
int format
agreed upon media format
static void calc_coefficients(AVFilterContext *ctx)
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
static const AVFilterPad inputs[]
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;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);returnNULL;}returnac;}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;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->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);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
BYTE int const BYTE int int int height
enum AVColorSpace av_frame_get_colorspace(const AVFrame *frame)
Describe the class of an AVClass context structure.
const char * name
Filter name.
AVFilterLink ** outputs
array of pointers to output links
static enum AVPixelFormat pix_fmts[]
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
avfilter_execute_func * execute
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
AVFilterContext * dst
dest filter
static int process_slice_yuv420p(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static const AVFilterPad colormatrix_outputs[]
AVFilter ff_vf_colormatrix
AVPixelFormat
Pixel format.
static const AVOption colormatrix_options[]
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.