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@gmail.com>
Signed-off-by: Stefano Sabatini <stefano.sabatini-lala@poste.it>
This commit is contained in:
Matthew Einhorn 2011-08-17 01:58:33 -04:00 committed by Stefano Sabatini
parent dc6c36ce46
commit 39f9601c10
2 changed files with 3 additions and 1 deletions

View File

@ -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);

View File

@ -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) {