[FFmpeg-cvslog] lavc: fix avcodec_find_best_pix_fmt() when there' s more than 64 pixel formats

Matthew Einhorn git at videolan.org
Thu Aug 18 01:05:45 CEST 2011


ffmpeg | branch: master | Matthew Einhorn <moiein2000 at gmail.com> | Wed Aug 17 01:58:33 2011 -0400| [39f9601c10f51fea519f16bccb4509f8ed3c51a7] | committer: Stefano Sabatini

lavc: fix avcodec_find_best_pix_fmt() when there's more than 64 pixel formats

This fixed the problem where if there's more than 64 pixel formats
defined avcodec_find_best_pix_fmt() returns the wrong pixel format.

Signed-off-by: Matthew Einhorn <moiein2000 at gmail.com>
Signed-off-by: Stefano Sabatini <stefano.sabatini-lala at poste.it>

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

 libavcodec/avcodec.h    |    2 ++
 libavcodec/imgconvert.c |    2 +-
 2 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 7c82d73..b0f3fcb 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3499,6 +3499,8 @@ int avcodec_get_pix_fmt_loss(enum PixelFormat dst_pix_fmt, enum PixelFormat src_
  * The pixel formats from which it chooses one, are determined by the
  * pix_fmt_mask parameter.
  *
+ * Note, only the first 64 pixel formats will fit in pix_fmt_mask.
+ *
  * @code
  * src_pix_fmt = PIX_FMT_YUV420P;
  * pix_fmt_mask = (1 << PIX_FMT_YUV422P) || (1 << PIX_FMT_RGB24);
diff --git a/libavcodec/imgconvert.c b/libavcodec/imgconvert.c
index 9efed50..071d312 100644
--- a/libavcodec/imgconvert.c
+++ b/libavcodec/imgconvert.c
@@ -439,7 +439,7 @@ static enum PixelFormat avcodec_find_best_pix_fmt1(int64_t pix_fmt_mask,
     /* find exact color match with smallest size */
     dst_pix_fmt = PIX_FMT_NONE;
     min_dist = 0x7fffffff;
-    for(i = 0;i < PIX_FMT_NB; i++) {
+    for (i = 0; i < FFMIN(PIX_FMT_NB, 64); i++) {
         if (pix_fmt_mask & (1ULL << i)) {
             loss = avcodec_get_pix_fmt_loss(i, src_pix_fmt, has_alpha) & loss_mask;
             if (loss == 0) {



More information about the ffmpeg-cvslog mailing list