Browse code

avcodec: add M101 decoder

Fixes Ticket 2611

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>

Michael Niedermayer authored on 2016/05/06 01:09:24
Showing 6 changed files
... ...
@@ -351,6 +351,7 @@ OBJS-$(CONFIG_KMVC_DECODER)            += kmvc.o
351 351
 OBJS-$(CONFIG_LAGARITH_DECODER)        += lagarith.o lagarithrac.o
352 352
 OBJS-$(CONFIG_LJPEG_ENCODER)           += ljpegenc.o mjpegenc_common.o
353 353
 OBJS-$(CONFIG_LOCO_DECODER)            += loco.o
354
+OBJS-$(CONFIG_M101_DECODER)            += m101.o
354 355
 OBJS-$(CONFIG_MACE3_DECODER)           += mace.o
355 356
 OBJS-$(CONFIG_MACE6_DECODER)           += mace.o
356 357
 OBJS-$(CONFIG_MDEC_DECODER)            += mdec.o mpeg12.o mpeg12data.o
... ...
@@ -218,6 +218,7 @@ void avcodec_register_all(void)
218 218
     REGISTER_DECODER(LAGARITH,          lagarith);
219 219
     REGISTER_ENCODER(LJPEG,             ljpeg);
220 220
     REGISTER_DECODER(LOCO,              loco);
221
+    REGISTER_DECODER(M101,              m101);
221 222
     REGISTER_DECODER(MDEC,              mdec);
222 223
     REGISTER_DECODER(MIMIC,             mimic);
223 224
     REGISTER_ENCDEC (MJPEG,             mjpeg);
... ...
@@ -386,6 +386,7 @@ enum AVCodecID {
386 386
     AV_CODEC_ID_DXV,
387 387
     AV_CODEC_ID_SCREENPRESSO,
388 388
     AV_CODEC_ID_RSCC,
389
+    AV_CODEC_ID_M101,
389 390
 
390 391
     AV_CODEC_ID_Y41P = 0x8000,
391 392
     AV_CODEC_ID_AVRP,
... ...
@@ -948,6 +948,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
948 948
         .props     = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS,
949 949
     },
950 950
     {
951
+        .id        = AV_CODEC_ID_M101,
952
+        .type      = AVMEDIA_TYPE_VIDEO,
953
+        .name      = "m101",
954
+        .long_name = NULL_IF_CONFIG_SMALL("Matrox Uncompressed SD"),
955
+        .props     = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS,
956
+    },
957
+    {
951 958
         .id        = AV_CODEC_ID_MVC1,
952 959
         .type      = AVMEDIA_TYPE_VIDEO,
953 960
         .name      = "mvc1",
954 961
new file mode 100644
... ...
@@ -0,0 +1,116 @@
0
+/*
1
+ * Copyright (c) 2016 Michael Niedermayer
2
+ *
3
+ * This file is part of FFmpeg.
4
+ *
5
+ * FFmpeg is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU Lesser General Public
7
+ * License as published by the Free Software Foundation; either
8
+ * version 2.1 of the License, or (at your option) any later version.
9
+ *
10
+ * FFmpeg is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
+ * Lesser General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public
16
+ * License along with FFmpeg; if not, write to the Free Software
17
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+ */
19
+
20
+#include "libavutil/intreadwrite.h"
21
+
22
+#include "avcodec.h"
23
+#include "internal.h"
24
+
25
+
26
+static av_cold int m101_decode_init(AVCodecContext *avctx)
27
+{
28
+    if (avctx->extradata_size < 6*4)
29
+        return AVERROR_INVALIDDATA;
30
+
31
+    if (avctx->extradata[2*4] == 10)
32
+        avctx->pix_fmt = AV_PIX_FMT_YUV422P10;
33
+    else
34
+        avctx->pix_fmt = AV_PIX_FMT_YUYV422;
35
+
36
+
37
+    return 0;
38
+}
39
+
40
+static int m101_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
41
+                      AVPacket *avpkt)
42
+{
43
+    const uint8_t *buf = avpkt->data;
44
+    int stride, ret;
45
+    int x, y;
46
+    int min_stride = 2 * avctx->width;
47
+    uint8_t *line;
48
+    int bits = avctx->extradata[2*4];
49
+    AVFrame *frame = data;
50
+
51
+    if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
52
+        return ret;
53
+    frame->pict_type = AV_PICTURE_TYPE_I;
54
+    frame->key_frame = 1;
55
+
56
+    stride = AV_RL32(avctx->extradata + 5*4);
57
+
58
+    if (avctx->pix_fmt == AV_PIX_FMT_YUV422P10)
59
+        min_stride = (avctx->width + 15) / 16 * 20;
60
+
61
+    if (stride < min_stride || avpkt->size < stride * (uint64_t)avctx->height) {
62
+        av_log(avctx, AV_LOG_ERROR, "stride (%d) is invalid for packet sized %d\n",
63
+               stride, avpkt->size);
64
+        return AVERROR_INVALIDDATA;
65
+    }
66
+
67
+    line = frame->data[0];
68
+    frame->interlaced_frame = ((avctx->extradata[3*4] & 3) != 3);
69
+    if (frame->interlaced_frame)
70
+        frame->top_field_first = avctx->extradata[3*4] & 1;
71
+
72
+    for (y = 0; y < avctx->height; y++) {
73
+        int src_y = y;
74
+        if (frame->interlaced_frame)
75
+            src_y = ((y&1)^frame->top_field_first) ? y/2 : (y/2 + avctx->height/2);
76
+        if (bits == 8) {
77
+            for (x = 0; x < avctx->width; x++) {
78
+                line[y*frame->linesize[0] + 2*x + 0] = buf[src_y*stride + 2*x + 0];
79
+                line[y*frame->linesize[0] + 2*x + 1] = buf[src_y*stride + 2*x + 1];
80
+            }
81
+        } else {
82
+            int block;
83
+            uint16_t *luma = (uint16_t*)&frame->data[0][y*frame->linesize[0]];
84
+            uint16_t *cb   = (uint16_t*)&frame->data[1][y*frame->linesize[1]];
85
+            uint16_t *cr   = (uint16_t*)&frame->data[2][y*frame->linesize[2]];
86
+            for (block = 0; 16*block < avctx->width; block ++) {
87
+                const uint8_t *buf_src = buf + src_y*stride + 40*block;
88
+                for (x = 0; x < 16 && x + 16*block < avctx->width; x++) {
89
+                    int xd = x + 16*block;
90
+                    if (!(x&1)) {
91
+                        luma [xd] = (4*buf_src[2*x + 0]) +  (buf_src[32 + (x>>1)]    &3);
92
+                        cb[xd>>1] = (4*buf_src[2*x + 1]) + ((buf_src[32 + (x>>1)]>>2)&3);
93
+                        cr[xd>>1] = (4*buf_src[2*x + 3]) +  (buf_src[32 + (x>>1)]>>6);
94
+                    } else {
95
+                        luma [xd] = (4*buf_src[2*x + 0]) + ((buf_src[32 + (x>>1)]>>4)&3);
96
+                    }
97
+                }
98
+            }
99
+        }
100
+    }
101
+
102
+    *got_frame = 1;
103
+    return avpkt->size;
104
+}
105
+
106
+AVCodec ff_m101_decoder = {
107
+    .name           = "m101",
108
+    .long_name      = NULL_IF_CONFIG_SMALL("Matrox Uncompressed SD"),
109
+    .type           = AVMEDIA_TYPE_VIDEO,
110
+    .id             = AV_CODEC_ID_M101,
111
+    .priv_data_size = 0,
112
+    .init           = m101_decode_init,
113
+    .decode         = m101_decode_frame,
114
+    .capabilities   = AV_CODEC_CAP_DR1,
115
+};
... ...
@@ -28,7 +28,7 @@
28 28
 #include "libavutil/version.h"
29 29
 
30 30
 #define LIBAVCODEC_VERSION_MAJOR  57
31
-#define LIBAVCODEC_VERSION_MINOR  38
31
+#define LIBAVCODEC_VERSION_MINOR  39
32 32
 #define LIBAVCODEC_VERSION_MICRO 100
33 33
 
34 34
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \