diff mbox

[FFmpeg-devel] bug in avcodec_find_best_pix_fmt_of_list

Message ID 3d6b0130-2135-5c20-b934-2b09cb5d20db@ngs.ru
State Accepted
Commit 354b26a3945eadd4ed8fcd801dfefad2566241de
Headers show

Commit Message

Александр Чирятьев March 31, 2018, 1:09 p.m. UTC
Hello!

Let me propose to review my patch for avcodec_find_best_pix_fmt_of_list.
It's very old bug. Here is example:

AVPixelFormat pixFmts[] = { AV_PIX_FMT_RGB24, AV_PIX_FMT_RGBA };
int loss = 0;
AVPixelFormat best_fmt = avcodec_find_best_pix_fmt_of_list(pixFmts, 
AV_PIX_FMT_BGRA, 1, &loss);

Now best_fmt is AV_PIX_FMT_RGB24. But AV_PIX_FMT_RGBA is better.


Regards,
Alexander Chiryatev.
From 4e9caf7d208a6de065ba0ee9f164ccf577fb7e89 Mon Sep 17 00:00:00 2001
From: heimdallr <heimdallr@ngs.ru>
Date: Sat, 31 Mar 2018 19:37:23 +0700
Subject: [PATCH] bug in avcodec_find_best_pix_fmt_of_list

example:

AVPixelFormat pixFmts[] = { AV_PIX_FMT_RGB24, AV_PIX_FMT_RGBA };
int loss = 0;
AVPixelFormat best = avcodec_find_best_pix_fmt_of_list(pixFmts, AV_PIX_FMT_BGRA, 1, &loss);

best is AV_PIX_FMT_RGB24. But AV_PIX_FMT_RGBA is better.
---
 libavcodec/imgconvert.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Michael Niedermayer April 1, 2018, 2:25 p.m. UTC | #1
On Sat, Mar 31, 2018 at 08:09:38PM +0700, Александр Чирятьев wrote:
> Hello!
> 
> Let me propose to review my patch for avcodec_find_best_pix_fmt_of_list.
> It's very old bug. Here is example:
> 
> AVPixelFormat pixFmts[] = { AV_PIX_FMT_RGB24, AV_PIX_FMT_RGBA };
> int loss = 0;
> AVPixelFormat best_fmt = avcodec_find_best_pix_fmt_of_list(pixFmts,
> AV_PIX_FMT_BGRA, 1, &loss);
> 
> Now best_fmt is AV_PIX_FMT_RGB24. But AV_PIX_FMT_RGBA is better.
> 
> 
> Regards,
> Alexander Chiryatev.
> 

>  imgconvert.c |    8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> f342eb7977f6a7c59ea68c2d091f855e18a566ef  bug-in-avcodec_find_best_pix_fmt_of_list.patch
> From 4e9caf7d208a6de065ba0ee9f164ccf577fb7e89 Mon Sep 17 00:00:00 2001
> From: heimdallr <heimdallr@ngs.ru>
> Date: Sat, 31 Mar 2018 19:37:23 +0700
> Subject: [PATCH] bug in avcodec_find_best_pix_fmt_of_list

will apply

thanks

[...]
diff mbox

Patch

diff --git a/libavcodec/imgconvert.c b/libavcodec/imgconvert.c
index 1547f18966..7b0005b308 100644
--- a/libavcodec/imgconvert.c
+++ b/libavcodec/imgconvert.c
@@ -69,10 +69,14 @@  enum AVPixelFormat avcodec_find_best_pix_fmt_of_list(const enum AVPixelFormat *p
     int i;
 
     enum AVPixelFormat best = AV_PIX_FMT_NONE;
+    int loss;
 
-    for(i=0; pix_fmt_list[i] != AV_PIX_FMT_NONE; i++)
-        best = avcodec_find_best_pix_fmt_of_2(best, pix_fmt_list[i], src_pix_fmt, has_alpha, loss_ptr);
+    for (i=0; pix_fmt_list[i] != AV_PIX_FMT_NONE; i++) {
+        loss = *loss_ptr;
+        best = avcodec_find_best_pix_fmt_of_2(best, pix_fmt_list[i], src_pix_fmt, has_alpha, &loss);
+    }
 
+    *loss_ptr = loss;
     return best;
 }