summaryrefslogtreecommitdiff
path: root/libavcodec/imgconvert.c
diff options
context:
space:
mode:
authorStefano Sabatini <stefasab@gmail.com>2012-03-08 14:40:30 +0100
committerStefano Sabatini <stefasab@gmail.com>2012-03-10 00:10:09 +0100
commit1a3d4b88a4c5cf74b4f1ab4b812e460b4ae0679b (patch)
tree312b852d91fd70a74763177b287aac295f607f97 /libavcodec/imgconvert.c
parent174678ff5bb74e481c25377c6ae509755bb8e8a2 (diff)
imgconvert: add macro pixdesc_has_alpha for checking if a pixel format has an alpha component
Reduce redundancy and simplify.
Diffstat (limited to 'libavcodec/imgconvert.c')
-rw-r--r--libavcodec/imgconvert.c20
1 files changed, 5 insertions, 15 deletions
diff --git a/libavcodec/imgconvert.c b/libavcodec/imgconvert.c
index 058a0d5c48..c26e5b6479 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;