History

avcodec: add M101 decoder

Fixes Ticket 2611

Michael Niedermayer committed 10 years ago

Commit 4155d5e1 parent 31ce01b6 files · +127 −1Browse files

Unified · Split

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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t