[FFmpeg-devel] [PATCHv2 4/4] Use AV_PIX_FMT_FLAG_ALPHA for detecting transparency where nb_components was used
Marton Balint
cus at passwd.hu
Fri Apr 20 00:25:54 EEST 2018
Signed-off-by: Marton Balint <cus at passwd.hu>
---
fftools/ffmpeg_filter.c | 2 +-
libavcodec/ffv1enc.c | 4 ++--
libavfilter/avfiltergraph.c | 2 +-
libavutil/pixdesc.c | 2 +-
4 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 877fd670e6..fff2e55027 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -65,7 +65,7 @@ enum AVPixelFormat choose_pixel_fmt(AVStream *st, AVCodecContext *enc_ctx, AVCod
if (codec && codec->pix_fmts) {
const enum AVPixelFormat *p = codec->pix_fmts;
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(target);
- int has_alpha = desc ? desc->nb_components % 2 == 0 : 0;
+ int has_alpha = desc ? !!(desc->flags & AV_PIX_FMT_FLAG_ALPHA) : 0;
enum AVPixelFormat best= AV_PIX_FMT_NONE;
if (enc_ctx->strict_std_compliance <= FF_COMPLIANCE_UNOFFICIAL) {
diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index dd4d7429f5..b7b4edb858 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -620,7 +620,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
case AV_PIX_FMT_YUVA420P:
s->chroma_planes = desc->nb_components < 3 ? 0 : 1;
s->colorspace = 0;
- s->transparency = desc->nb_components == 4 || desc->nb_components == 2;
+ s->transparency = !!(desc->flags & AV_PIX_FMT_FLAG_ALPHA);
if (!avctx->bits_per_raw_sample && !s->bits_per_raw_sample)
s->bits_per_raw_sample = 8;
else if (!s->bits_per_raw_sample)
@@ -672,7 +672,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
s->bits_per_raw_sample = 16;
else if (!s->bits_per_raw_sample)
s->bits_per_raw_sample = avctx->bits_per_raw_sample;
- s->transparency = desc->nb_components == 4 || desc->nb_components == 2;
+ s->transparency = !!(desc->flags & AV_PIX_FMT_FLAG_ALPHA);
s->colorspace = 1;
s->chroma_planes = 1;
if (s->bits_per_raw_sample >= 16) {
diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index e18f733e23..a37d4ddf53 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -679,7 +679,7 @@ static int pick_format(AVFilterLink *link, AVFilterLink *ref)
if (link->type == AVMEDIA_TYPE_VIDEO) {
if(ref && ref->type == AVMEDIA_TYPE_VIDEO){
- int has_alpha= av_pix_fmt_desc_get(ref->format)->nb_components % 2 == 0 || (av_pix_fmt_desc_get(ref->format)->flags & AV_PIX_FMT_FLAG_PAL);
+ int has_alpha = !!(av_pix_fmt_desc_get(ref->format)->flags & AV_PIX_FMT_FLAG_ALPHA);
enum AVPixelFormat best= AV_PIX_FMT_NONE;
int i;
for (i=0; i<link->in_formats->nb_formats; i++) {
diff --git a/libavutil/pixdesc.c b/libavutil/pixdesc.c
index a8be7b66e6..df03b3372d 100644
--- a/libavutil/pixdesc.c
+++ b/libavutil/pixdesc.c
@@ -2482,7 +2482,7 @@ enum AVPixelFormat av_pix_fmt_swap_endianness(enum AVPixelFormat pix_fmt)
#define FF_COLOR_XYZ 4
#define pixdesc_has_alpha(pixdesc) \
- ((pixdesc)->nb_components == 2 || (pixdesc)->nb_components == 4 || (pixdesc)->flags & AV_PIX_FMT_FLAG_PAL)
+ ((pixdesc)->flags & AV_PIX_FMT_FLAG_ALPHA)
static int get_color_type(const AVPixFmtDescriptor *desc) {
--
2.13.6
More information about the ffmpeg-devel
mailing list