Browse code

Dxtory capture format decoder

Signed-off-by: Anton Khirnov <anton@khirnov.net>

Kostya Shishkov authored on 2011/12/09 19:06:02
Showing 7 changed files
... ...
@@ -106,6 +106,7 @@ easier to use. The changes are:
106 106
 - Playstation Portable PMP format demuxer
107 107
 - PCM format support in OMA demuxer
108 108
 - CLJR encoder
109
+- Dxtory capture format decoder
109 110
 
110 111
 
111 112
 version 0.7:
... ...
@@ -452,6 +452,7 @@ following image formats are supported:
452 452
 @item Duck TrueMotion 2.0    @tab     @tab  X
453 453
     @tab fourcc: TM20
454 454
 @item DV (Digital Video)     @tab  X  @tab  X
455
+@item Dxtory capture format  @tab     @tab  X
455 456
 @item Feeble Files/ScummVM DXA  @tab     @tab  X
456 457
     @tab Codec originally used in Feeble Files game.
457 458
 @item Electronic Arts CMV video  @tab     @tab  X
... ...
@@ -125,6 +125,7 @@ OBJS-$(CONFIG_DVDSUB_ENCODER)          += dvdsubenc.o
125 125
 OBJS-$(CONFIG_DVVIDEO_DECODER)         += dv.o dvdata.o
126 126
 OBJS-$(CONFIG_DVVIDEO_ENCODER)         += dv.o dvdata.o
127 127
 OBJS-$(CONFIG_DXA_DECODER)             += dxa.o
128
+OBJS-$(CONFIG_DXTORY_DECODER)          += dxtory.o
128 129
 OBJS-$(CONFIG_EAC3_DECODER)            += eac3dec.o eac3_data.o
129 130
 OBJS-$(CONFIG_EAC3_ENCODER)            += eac3enc.o ac3enc.o ac3enc_float.o \
130 131
                                           ac3tab.o ac3.o kbdwin.o eac3_data.o
... ...
@@ -96,6 +96,7 @@ void avcodec_register_all(void)
96 96
     REGISTER_DECODER (DSICINVIDEO, dsicinvideo);
97 97
     REGISTER_ENCDEC  (DVVIDEO, dvvideo);
98 98
     REGISTER_DECODER (DXA, dxa);
99
+    REGISTER_DECODER (DXTORY, dxtory);
99 100
     REGISTER_DECODER (EACMV, eacmv);
100 101
     REGISTER_DECODER (EAMAD, eamad);
101 102
     REGISTER_DECODER (EATGQ, eatgq);
... ...
@@ -252,6 +252,7 @@ enum CodecID {
252 252
     CODEC_ID_UTVIDEO,
253 253
     CODEC_ID_BMV_VIDEO,
254 254
     CODEC_ID_VBLE,
255
+    CODEC_ID_DXTORY,
255 256
 
256 257
     /* various PCM "codecs" */
257 258
     CODEC_ID_FIRST_AUDIO = 0x10000,     ///< A dummy id pointing at the start of audio codecs
258 259
new file mode 100644
... ...
@@ -0,0 +1,109 @@
0
+/*
1
+ * Dxtory decoder
2
+ *
3
+ * Copyright (c) 2011 Konstantin Shishkov
4
+ *
5
+ * This file is part of Libav.
6
+ *
7
+ * Libav is free software; you can redistribute it and/or
8
+ * modify it under the terms of the GNU Lesser General Public
9
+ * License as published by the Free Software Foundation; either
10
+ * version 2.1 of the License, or (at your option) any later version.
11
+ *
12
+ * Libav is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+ * Lesser General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public
18
+ * License along with Libav; if not, write to the Free Software
19
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
+ */
21
+
22
+#include "avcodec.h"
23
+#include "libavutil/intreadwrite.h"
24
+
25
+static av_cold int decode_init(AVCodecContext *avctx)
26
+{
27
+    avctx->pix_fmt     = PIX_FMT_YUV420P;
28
+    avctx->coded_frame = avcodec_alloc_frame();
29
+    if (!avctx->coded_frame)
30
+        return AVERROR(ENOMEM);
31
+
32
+    return 0;
33
+}
34
+
35
+static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
36
+                        AVPacket *avpkt)
37
+{
38
+    int h, w;
39
+    AVFrame *pic = avctx->coded_frame;
40
+    const uint8_t *src = avpkt->data;
41
+    uint8_t *Y1, *Y2, *U, *V;
42
+    int ret;
43
+
44
+    if (pic->data[0])
45
+        avctx->release_buffer(avctx, pic);
46
+
47
+    if (avpkt->size < avctx->width * avctx->height * 3 / 2 + 16) {
48
+        av_log(avctx, AV_LOG_ERROR, "packet too small\n");
49
+        return AVERROR_INVALIDDATA;
50
+    }
51
+
52
+    pic->reference = 0;
53
+    if ((ret = avctx->get_buffer(avctx, pic)) < 0)
54
+        return ret;
55
+
56
+    pic->pict_type = AV_PICTURE_TYPE_I;
57
+    pic->key_frame = 1;
58
+
59
+    if (AV_RL32(src) != 0x01000002) {
60
+        av_log_ask_for_sample(avctx, "Unknown frame header %X\n", AV_RL32(src));
61
+        return AVERROR_PATCHWELCOME;
62
+    }
63
+    src += 16;
64
+
65
+    Y1 = pic->data[0];
66
+    Y2 = pic->data[0] + pic->linesize[0];
67
+    U  = pic->data[1];
68
+    V  = pic->data[2];
69
+    for (h = 0; h < avctx->height; h += 2) {
70
+        for (w = 0; w < avctx->width; w += 2) {
71
+            AV_WN16A(Y1 + w, AV_RN16A(src));
72
+            AV_WN16A(Y2 + w, AV_RN16A(src + 2));
73
+            U[w >> 1] = src[4] + 0x80;
74
+            V[w >> 1] = src[5] + 0x80;
75
+            src += 6;
76
+        }
77
+        Y1 += pic->linesize[0] << 1;
78
+        Y2 += pic->linesize[0] << 1;
79
+        U  += pic->linesize[1];
80
+        V  += pic->linesize[2];
81
+    }
82
+
83
+    *data_size      = sizeof(AVFrame);
84
+    *(AVFrame*)data = *pic;
85
+
86
+    return avpkt->size;
87
+}
88
+
89
+static av_cold int decode_close(AVCodecContext *avctx)
90
+{
91
+    AVFrame *pic = avctx->coded_frame;
92
+    if (pic->data[0])
93
+        avctx->release_buffer(avctx, pic);
94
+    av_freep(&avctx->coded_frame);
95
+
96
+    return 0;
97
+}
98
+
99
+AVCodec ff_dxtory_decoder = {
100
+    .name           = "dxtory",
101
+    .long_name      = NULL_IF_CONFIG_SMALL("Dxtory"),
102
+    .type           = AVMEDIA_TYPE_VIDEO,
103
+    .id             = CODEC_ID_DXTORY,
104
+    .init           = decode_init,
105
+    .close          = decode_close,
106
+    .decode         = decode_frame,
107
+    .capabilities   = CODEC_CAP_DR1,
108
+};
... ...
@@ -280,6 +280,7 @@ const AVCodecTag ff_codec_bmp_tags[] = {
280 280
     { CODEC_ID_UTVIDEO,      MKTAG('U', 'L', 'Y', '0') },
281 281
     { CODEC_ID_UTVIDEO,      MKTAG('U', 'L', 'Y', '2') },
282 282
     { CODEC_ID_VBLE,         MKTAG('V', 'B', 'L', 'E') },
283
+    { CODEC_ID_DXTORY,       MKTAG('x', 't', 'o', 'r') },
283 284
     { CODEC_ID_NONE,         0 }
284 285
 };
285 286