[FFmpeg-devel] [PATCH] imgconvert: add macro pixdesc_has_alpha for checking if a pixel format has an alpha component
Stefano Sabatini
stefasab at gmail.com
Thu Mar 8 14:44:47 CET 2012
Reduce redundancy and simplify.
---
libavcodec/imgconvert.c | 21 ++++++---------------
1 files changed, 6 insertions(+), 15 deletions(-)
diff --git a/libavcodec/imgconvert.c b/libavcodec/imgconvert.c
index 058a0d5..0d1ce3f 100644
--- a/libavcodec/imgconvert.c
+++ b/libavcodec/imgconvert.c
@@ -55,9 +55,12 @@
#define deinterlace_line deinterlace_line_c
#endif
+#define pixdesc_has_alpha(pix_desc) \
+ (pix_desc->nb_components == 2 || pix_desc->nb_components == 4 \
+ || pix_desc->flags & PIX_FMT_PAL)
+
typedef struct PixFmtInfo {
uint8_t color_type; /**< color type (see FF_COLOR_xxx constants) */
- uint8_t is_alpha : 1; /**< true if alpha can be specified */
uint8_t padded_size; /**< padded size in bits if different from the non-padded size */
} PixFmtInfo;
@@ -109,12 +112,10 @@ static const PixFmtInfo pix_fmt_info[PIX_FMT_NB] = {
/* YUV formats with alpha plane */
[PIX_FMT_YUVA420P] = {
- .is_alpha = 1,
.color_type = FF_COLOR_YUV,
},
[PIX_FMT_YUVA444P] = {
- .is_alpha = 1,
.color_type = FF_COLOR_YUV,
},
@@ -140,7 +141,6 @@ static const PixFmtInfo pix_fmt_info[PIX_FMT_NB] = {
.color_type = FF_COLOR_RGB,
},
[PIX_FMT_ARGB] = {
- .is_alpha = 1,
.color_type = FF_COLOR_RGB,
},
[PIX_FMT_RGB48BE] = {
@@ -150,11 +150,9 @@ static const PixFmtInfo pix_fmt_info[PIX_FMT_NB] = {
.color_type = FF_COLOR_RGB,
},
[PIX_FMT_RGBA64BE] = {
- .is_alpha = 1,
.color_type = FF_COLOR_RGB,
},
[PIX_FMT_RGBA64LE] = {
- .is_alpha = 1,
.color_type = FF_COLOR_RGB,
},
[PIX_FMT_RGB565BE] = {
@@ -191,7 +189,6 @@ static const PixFmtInfo pix_fmt_info[PIX_FMT_NB] = {
.color_type = FF_COLOR_GRAY,
},
[PIX_FMT_GRAY8A] = {
- .is_alpha = 1,
.color_type = FF_COLOR_GRAY,
},
[PIX_FMT_MONOWHITE] = {
@@ -203,14 +200,12 @@ static const PixFmtInfo pix_fmt_info[PIX_FMT_NB] = {
/* paletted formats */
[PIX_FMT_PAL8] = {
- .is_alpha = 1,
.color_type = FF_COLOR_RGB,
},
[PIX_FMT_UYYVYY411] = {
.color_type = FF_COLOR_YUV,
},
[PIX_FMT_ABGR] = {
- .is_alpha = 1,
.color_type = FF_COLOR_RGB,
},
[PIX_FMT_BGR48BE] = {
@@ -220,11 +215,9 @@ static const PixFmtInfo pix_fmt_info[PIX_FMT_NB] = {
.color_type = FF_COLOR_RGB,
},
[PIX_FMT_BGRA64BE] = {
- .is_alpha = 1,
.color_type = FF_COLOR_RGB,
},
[PIX_FMT_BGRA64LE] = {
- .is_alpha = 1,
.color_type = FF_COLOR_RGB,
},
[PIX_FMT_BGR565BE] = {
@@ -279,11 +272,9 @@ static const PixFmtInfo pix_fmt_info[PIX_FMT_NB] = {
},
[PIX_FMT_BGRA] = {
- .is_alpha = 1,
.color_type = FF_COLOR_RGB,
},
[PIX_FMT_RGBA] = {
- .is_alpha = 1,
.color_type = FF_COLOR_RGB,
},
};
@@ -445,10 +436,10 @@ int avcodec_get_pix_fmt_loss(enum PixelFormat dst_pix_fmt, enum PixelFormat src_
if (pf->color_type == FF_COLOR_GRAY &&
ps->color_type != FF_COLOR_GRAY)
loss |= FF_LOSS_CHROMA;
- if (!pf->is_alpha && (ps->is_alpha && has_alpha))
+ if (!pixdesc_has_alpha(dst_desc) && (pixdesc_has_alpha(src_desc) && has_alpha))
loss |= FF_LOSS_ALPHA;
if (dst_pix_fmt == PIX_FMT_PAL8 &&
- (src_pix_fmt != PIX_FMT_PAL8 && (ps->color_type != FF_COLOR_GRAY || (ps->is_alpha && has_alpha))))
+ (src_pix_fmt != PIX_FMT_PAL8 && (ps->color_type != FF_COLOR_GRAY || (pixdesc_has_alpha(src_desc) && has_alpha))))
loss |= FF_LOSS_COLORQUANT;
return loss;
--
1.7.5.4
More information about the ffmpeg-devel
mailing list