[FFmpeg-cvslog] avcodec_find_best_pix_fmt_of_2: favor formats with fewer components if it does not incur a loss.
Michael Niedermayer
git at videolan.org
Wed Nov 21 17:11:37 CET 2012
ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Wed Nov 21 16:59:37 2012 +0100| [0880f26bbe89a8621416efdac2c32ee26a570f28] | committer: Michael Niedermayer
avcodec_find_best_pix_fmt_of_2: favor formats with fewer components if it does not incur a loss.
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=0880f26bbe89a8621416efdac2c32ee26a570f28
---
libavcodec/imgconvert.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/libavcodec/imgconvert.c b/libavcodec/imgconvert.c
index ac40adb..38bf2e7 100644
--- a/libavcodec/imgconvert.c
+++ b/libavcodec/imgconvert.c
@@ -551,6 +551,8 @@ enum AVPixelFormat avcodec_find_best_pix_fmt_of_2(enum AVPixelFormat dst_pix_fmt
{
enum AVPixelFormat dst_pix_fmt;
int loss1, loss2, loss_order1, loss_order2, i, loss_mask;
+ const AVPixFmtDescriptor *desc1 = av_pix_fmt_desc_get(dst_pix_fmt1);
+ const AVPixFmtDescriptor *desc2 = av_pix_fmt_desc_get(dst_pix_fmt2);
static const int loss_mask_order[] = {
~0, /* no loss first */
~FF_LOSS_ALPHA,
@@ -577,7 +579,11 @@ enum AVPixelFormat avcodec_find_best_pix_fmt_of_2(enum AVPixelFormat dst_pix_fmt
loss_order2 = loss2 & loss_mask_order[i];
if (loss_order1 == 0 && loss_order2 == 0 && dst_pix_fmt2 != AV_PIX_FMT_NONE && dst_pix_fmt1 != AV_PIX_FMT_NONE){ /* use format with smallest depth */
- dst_pix_fmt = avg_bits_per_pixel(dst_pix_fmt2) < avg_bits_per_pixel(dst_pix_fmt1) ? dst_pix_fmt2 : dst_pix_fmt1;
+ if(avg_bits_per_pixel(dst_pix_fmt2) != avg_bits_per_pixel(dst_pix_fmt1)) {
+ dst_pix_fmt = avg_bits_per_pixel(dst_pix_fmt2) < avg_bits_per_pixel(dst_pix_fmt1) ? dst_pix_fmt2 : dst_pix_fmt1;
+ } else {
+ dst_pix_fmt = desc2->nb_components < desc1->nb_components ? dst_pix_fmt2 : dst_pix_fmt1;
+ }
} else if (loss_order1 == 0 || loss_order2 == 0) { /* use format with no loss */
dst_pix_fmt = loss_order2 ? dst_pix_fmt1 : dst_pix_fmt2;
}
More information about the ffmpeg-cvslog
mailing list