diff mbox series

[FFmpeg-devel] avformat/frmdec: Simplify finding pixel format

Message ID 20210303153108.698933-1-andreas.rheinhardt@gmail.com
State Accepted
Commit 6a3f345c1ab78428b970775a6632362b8515dd04
Headers show
Series [FFmpeg-devel] avformat/frmdec: Simplify finding pixel format | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt March 3, 2021, 3:31 p.m. UTC
The fourccs used by the Megalux Frame format to determine the pixel
format are actually no fourccs at all as they are a single byte.
Furthermore, their range is continuous (1-5), so they are actually
ordinary indices. So treat them as such and don't use PixelFormatTags
for them.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/frmdec.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

Comments

Paul B Mahol March 3, 2021, 3:34 p.m. UTC | #1
lgtm
diff mbox series

Patch

diff --git a/libavformat/frmdec.c b/libavformat/frmdec.c
index 9a962f37fa..1bc3a83e11 100644
--- a/libavformat/frmdec.c
+++ b/libavformat/frmdec.c
@@ -29,13 +29,12 @@ 
 #include "libavutil/intreadwrite.h"
 #include "avformat.h"
 
-static const PixelFormatTag frm_pix_fmt_tags[] = {
-    { AV_PIX_FMT_RGB555, 1 },
-    { AV_PIX_FMT_RGB0,   2 },
-    { AV_PIX_FMT_RGB24,  3 },
-    { AV_PIX_FMT_BGR0,   4 },
-    { AV_PIX_FMT_BGRA,   5 },
-    { AV_PIX_FMT_NONE,   0 },
+static const enum AVPixelFormat frm_pix_fmt_tags[] = {
+    AV_PIX_FMT_RGB555,
+    AV_PIX_FMT_RGB0,
+    AV_PIX_FMT_RGB24,
+    AV_PIX_FMT_BGR0,
+    AV_PIX_FMT_BGRA,
 };
 
 typedef struct {
@@ -55,6 +54,8 @@  static int frm_read_header(AVFormatContext *avctx)
 {
     AVIOContext *pb = avctx->pb;
     AVStream *st = avformat_new_stream(avctx, 0);
+    unsigned idx;
+
     if (!st)
         return AVERROR(ENOMEM);
 
@@ -62,9 +63,10 @@  static int frm_read_header(AVFormatContext *avctx)
     st->codecpar->codec_id   = AV_CODEC_ID_RAWVIDEO;
     avio_skip(pb, 3);
 
-    st->codecpar->format    = avpriv_find_pix_fmt(frm_pix_fmt_tags, avio_r8(pb));
-    if (!st->codecpar->format)
+    idx = avio_r8(pb) - 1;
+    if (idx >= FF_ARRAY_ELEMS(frm_pix_fmt_tags))
         return AVERROR_INVALIDDATA;
+    st->codecpar->format = frm_pix_fmt_tags[idx];
 
     st->codecpar->codec_tag  = 0;
     st->codecpar->width      = avio_rl16(pb);