FFmpeg
utils.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_UTILS_H
22 #define SWSCALE_UTILS_H
23 
24 #include "libavutil/pixdesc.h"
25 
26 #include "swscale.h"
27 
28 enum {
29  FIELD_TOP, /* top/even rows, or progressive */
30  FIELD_BOTTOM, /* bottom/odd rows */
31 };
32 
33 /* Subset of AVFrame parameters that uniquely determine pixel representation */
34 typedef struct SwsFormat {
35  int width, height;
43  const AVPixFmtDescriptor *desc; /* convenience */
44 } SwsFormat;
45 
46 /**
47  * This function also sanitizes and strips the input data, removing irrelevant
48  * fields for certain formats.
49  */
51 
52 static inline int ff_fmt_equal(const SwsFormat *fmt1, const SwsFormat *fmt2)
53 {
54  return fmt1->width == fmt2->width &&
55  fmt1->height == fmt2->height &&
56  fmt1->interlaced == fmt2->interlaced &&
57  fmt1->format == fmt2->format &&
58  fmt1->range == fmt2->range &&
59  fmt1->prim == fmt2->prim &&
60  fmt1->trc == fmt2->trc &&
61  fmt1->csp == fmt2->csp &&
62  fmt1->loc == fmt2->loc;
63 }
64 
65 static inline int ff_fmt_align(enum AVPixelFormat fmt)
66 {
68  if (desc->flags & AV_PIX_FMT_FLAG_BAYER) {
69  return 2;
70  } else {
71  return 1 << desc->log2_chroma_h;
72  }
73 }
74 
75 int ff_test_fmt(const SwsFormat *fmt, int output);
76 
77 #endif /* SWSCALE_UTILS_H */
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
AVColorTransferCharacteristic
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition: pixfmt.h:611
SwsFormat::interlaced
int interlaced
Definition: utils.h:36
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3170
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
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:389
SwsFormat::range
enum AVColorRange range
Definition: utils.h:38
pixdesc.h
ff_test_fmt
int ff_test_fmt(const SwsFormat *fmt, int output)
Definition: utils.c:2769
AVColorPrimaries
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition: pixfmt.h:586
SwsFormat::trc
enum AVColorTransferCharacteristic trc
Definition: utils.h:40
SwsFormat::height
int height
Definition: utils.h:35
ff_fmt_from_frame
SwsFormat ff_fmt_from_frame(const AVFrame *frame, int field)
This function also sanitizes and strips the input data, removing irrelevant fields for certain format...
Definition: utils.c:2667
ff_fmt_equal
static int ff_fmt_equal(const SwsFormat *fmt1, const SwsFormat *fmt2)
Definition: utils.h:52
field
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this field
Definition: writing_filters.txt:78
SwsFormat::prim
enum AVColorPrimaries prim
Definition: utils.h:39
ff_fmt_align
static int ff_fmt_align(enum AVPixelFormat fmt)
Definition: utils.h:65
FIELD_TOP
@ FIELD_TOP
Definition: utils.h:29
SwsFormat
Definition: utils.h:34
SwsFormat::loc
enum AVChromaLocation loc
Definition: utils.h:42
AV_PIX_FMT_FLAG_BAYER
#define AV_PIX_FMT_FLAG_BAYER
The pixel format is following a Bayer pattern.
Definition: pixdesc.h:152
AVChromaLocation
AVChromaLocation
Location of chroma samples.
Definition: pixfmt.h:736
SwsFormat::format
enum AVPixelFormat format
Definition: utils.h:37
AVColorSpace
AVColorSpace
YUV colorspace type.
Definition: pixfmt.h:640
SwsFormat::desc
const AVPixFmtDescriptor * desc
Definition: utils.h:43
SwsFormat::width
int width
Definition: utils.h:35
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:264
SwsFormat::csp
enum AVColorSpace csp
Definition: utils.h:41
desc
const char * desc
Definition: libsvtav1.c:79
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
AVColorRange
AVColorRange
Visual content value range.
Definition: pixfmt.h:682
swscale.h
FIELD_BOTTOM
@ FIELD_BOTTOM
Definition: utils.h:30