[FFmpeg-cvslog] imgconvert: add macro pixdesc_has_alpha for checking if a pixel format has an alpha component

Stefano Sabatini git at videolan.org
Sat Mar 10 00:12:32 CET 2012


ffmpeg | branch: master | Stefano Sabatini <stefasab at gmail.com> | Thu Mar  8 14:40:30 2012 +0100| [1a3d4b88a4c5cf74b4f1ab4b812e460b4ae0679b] | committer: Stefano Sabatini

imgconvert: add macro pixdesc_has_alpha for checking if a pixel format has an alpha component

Reduce redundancy and simplify.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1a3d4b88a4c5cf74b4f1ab4b812e460b4ae0679b
---

 libavcodec/imgconvert.c |   20 +++++---------------
 1 files changed, 5 insertions(+), 15 deletions(-)

diff --git a/libavcodec/imgconvert.c b/libavcodec/imgconvert.c
index 058a0d5..c26e5b6 100644
--- a/libavcodec/imgconvert.c
+++ b/libavcodec/imgconvert.c
@@ -55,9 +55,11 @@
 #define deinterlace_line         deinterlace_line_c
 #endif
 
+#define pixdesc_has_alpha(pixdesc) \
+    ((pixdesc)->nb_components == 2 || (pixdesc)->nb_components == 4 || (pixdesc)->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 +111,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 +140,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 +149,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 +188,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 +199,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 +214,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 +271,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 +435,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;



More information about the ffmpeg-cvslog mailing list