Browse code

Winnov WNV1 video decoder, courtesy of Konstantin Shishkov

Originally committed as revision 4083 to svn://svn.ffmpeg.org/ffmpeg/trunk

Mike Melanson authored on 2005/03/27 05:32:55
Showing 7 changed files
... ...
@@ -12,6 +12,7 @@ version <next>
12 12
 - Shorten audio decoder
13 13
 - LOCO video decoder
14 14
 - Apple Lossless Audio Codec (ALAC) decoder 
15
+- Winnov WNV1 video decoder
15 16
 
16 17
 version 0.4.9-pre1:
17 18
 
... ...
@@ -773,6 +773,7 @@ following image formats are supported:
773 773
 @item Miro VideoXL           @tab     @tab  X @tab fourcc: VIXL
774 774
 @item QPEG                   @tab     @tab  X @tab fourccs: QPEG, Q1.0, Q1.1
775 775
 @item LOCO                   @tab     @tab  X @tab 
776
+@item Winnov WNV1            @tab     @tab  X @tab 
776 777
 @end multitable
777 778
 
778 779
 @code{X} means that the encoding (resp. decoding) is supported.
... ...
@@ -23,7 +23,7 @@ OBJS= bitstream.o utils.o mem.o allcodecs.o \
23 23
       flac.o vp3dsp.o integer.o snow.o tscc.o sonic.o ulti.o h264idct.o \
24 24
       qdrw.o xl.o rangecoder.o png.o pnm.o qpeg.o vc9.o h263.o h261.o \
25 25
       msmpeg4.o h263dec.o svq1.o rv10.o wmadec.o indeo3.o shorten.o loco.o \
26
-      alac.o
26
+      alac.o wnv1.o
27 27
 
28 28
 AMROBJS=
29 29
 ifeq ($(AMR_NB),yes)
... ...
@@ -129,6 +129,7 @@ void avcodec_register_all(void)
129 129
     register_avcodec(&xl_decoder);
130 130
     register_avcodec(&qpeg_decoder);
131 131
     register_avcodec(&loco_decoder);
132
+    register_avcodec(&wnv1_decoder);
132 133
 #ifdef CONFIG_FAAD
133 134
     register_avcodec(&aac_decoder);
134 135
     register_avcodec(&mpeg4aac_decoder);
... ...
@@ -17,7 +17,7 @@ extern "C" {
17 17
 
18 18
 #define FFMPEG_VERSION_INT     0x000409
19 19
 #define FFMPEG_VERSION         "0.4.9-pre1"
20
-#define LIBAVCODEC_BUILD       4748
20
+#define LIBAVCODEC_BUILD       4749
21 21
 
22 22
 #define LIBAVCODEC_VERSION_INT FFMPEG_VERSION_INT
23 23
 #define LIBAVCODEC_VERSION     FFMPEG_VERSION
... ...
@@ -105,6 +105,7 @@ enum CodecID {
105 105
     CODEC_ID_VC9,
106 106
     CODEC_ID_WMV3,
107 107
     CODEC_ID_LOCO,
108
+    CODEC_ID_WNV1,
108 109
 
109 110
     /* various pcm "codecs" */
110 111
     CODEC_ID_PCM_S16LE= 0x10000,
... ...
@@ -2005,6 +2006,7 @@ extern AVCodec xl_decoder;
2005 2005
 extern AVCodec qpeg_decoder;
2006 2006
 extern AVCodec shorten_decoder;
2007 2007
 extern AVCodec loco_decoder;
2008
+extern AVCodec wnv1_decoder;
2008 2009
 extern AVCodec alac_decoder;
2009 2010
 
2010 2011
 /* pcm codecs */
2011 2012
new file mode 100644
... ...
@@ -0,0 +1,169 @@
0
+/*
1
+ * Winnov WNV1 codec
2
+ * Copyright (c) 2005 Konstantin Shishkov
3
+ *
4
+ * This library is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU Lesser General Public
6
+ * License as published by the Free Software Foundation; either
7
+ * version 2 of the License, or (at your option) any later version.
8
+ *
9
+ * This library is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * Lesser General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Lesser General Public
15
+ * License along with this library; if not, write to the Free Software
16
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
+ *
18
+ */
19
+ 
20
+/**
21
+ * @file wnv1.c
22
+ * Winnov WNV1 codec.
23
+ */
24
+ 
25
+#include "avcodec.h"
26
+#include "common.h"
27
+
28
+
29
+typedef struct WNV1Context{
30
+    AVCodecContext *avctx;
31
+    AVFrame pic;
32
+
33
+    int shift;
34
+    /* bit buffer */
35
+    unsigned long bitbuf;
36
+    int bits;
37
+    uint8_t *buf;
38
+} WNV1Context;
39
+
40
+/* returns modified base_value */
41
+static inline int wnv1_get_code(WNV1Context *w, int base_value)
42
+{
43
+    int v = 0;
44
+            
45
+    if (w->bits < 16) { /* need to fill bit buffer */
46
+        w->bitbuf |= LE_16(w->buf) << w->bits;
47
+        w->buf += 2;
48
+        w->bits += 16;
49
+    }
50
+
51
+    /* escape code */
52
+    if ((w->bitbuf & 0xFF) == 0xFF) {
53
+        w->bitbuf >>= 8;
54
+        w->bits -= 8;
55
+        if (w->bits < 16) { /* need to fill bit buffer */
56
+            w->bitbuf |= LE_16(w->buf) << w->bits;
57
+            w->buf += 2;
58
+            w->bits += 16;
59
+        }
60
+        v = w->bitbuf & (0xFF >> w->shift);
61
+        w->bitbuf >>= 8 - w->shift;
62
+        w->bits -= 8 - w->shift;
63
+        return v << w->shift;
64
+    }
65
+
66
+    /* zero code */
67
+    if (!(w->bitbuf & 1)) {
68
+        w->bitbuf >>= 1;
69
+        w->bits--;
70
+        return base_value;
71
+    }
72
+    
73
+    /* reversed unary code and sign */
74
+    while (w->bits && w->bitbuf & 1) {
75
+        w->bitbuf >>= 1;
76
+        w->bits--;
77
+        v++;
78
+    }
79
+    w->bitbuf >>= 1;
80
+    w->bits--;
81
+    if(w->bitbuf & 1)
82
+        v = -v;
83
+    w->bitbuf >>= 1;
84
+    w->bits--;
85
+    v <<= w->shift;
86
+    return base_value + v;
87
+}
88
+
89
+static int decode_frame(AVCodecContext *avctx, 
90
+                        void *data, int *data_size,
91
+                        uint8_t *buf, int buf_size)
92
+{
93
+    WNV1Context * const l = avctx->priv_data;
94
+    AVFrame * const p= (AVFrame*)&l->pic;
95
+    unsigned char *Y,*U,*V;
96
+    int i, j;
97
+    int prev_y = 0, prev_u = 0, prev_v = 0;
98
+
99
+    if(p->data[0])
100
+        avctx->release_buffer(avctx, p);
101
+
102
+    p->reference = 0;
103
+    if(avctx->get_buffer(avctx, p) < 0){
104
+        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
105
+        return -1;
106
+    }
107
+    p->key_frame = 1;
108
+    
109
+    l->bitbuf = 0;
110
+    l->bits = 0;
111
+    l->buf = buf + 8;
112
+    
113
+    if (buf[2] >> 4 == 6)
114
+        l->shift = 2;
115
+    else {
116
+        l->shift = 8 - (buf[2] >> 4);
117
+        if (l->shift > 4) {
118
+            av_log(avctx, AV_LOG_ERROR, "Unknown WNV1 frame header value %i, please upload file for study\n", buf[2] >> 4);
119
+            l->shift = 4;
120
+        }
121
+        if (l->shift < 1) {
122
+            av_log(avctx, AV_LOG_ERROR, "Unknown WNV1 frame header value %i, please upload file for study\n", buf[2] >> 4);
123
+            l->shift = 1;
124
+        }
125
+    }
126
+    
127
+    Y = p->data[0];
128
+    U = p->data[1];
129
+    V = p->data[2];
130
+    for (j = 0; j < avctx->height; j++) {
131
+        for (i = 0; i < avctx->width / 2; i++) {
132
+            Y[i * 2] = wnv1_get_code(l, prev_y);
133
+            prev_u = U[i] = wnv1_get_code(l, prev_u);
134
+            prev_y = Y[(i * 2) + 1] = wnv1_get_code(l, Y[i * 2]);
135
+            prev_v = V[i] = wnv1_get_code(l, prev_v);
136
+        }
137
+        Y += p->linesize[0];
138
+        U += p->linesize[1];
139
+        V += p->linesize[2];
140
+    }
141
+
142
+    
143
+    *data_size = sizeof(AVFrame);
144
+    *(AVFrame*)data = l->pic;
145
+    
146
+    return buf_size;
147
+}
148
+
149
+static int decode_init(AVCodecContext *avctx){
150
+    WNV1Context * const l = avctx->priv_data;
151
+
152
+    l->avctx = avctx;
153
+    avctx->pix_fmt = PIX_FMT_YUV422P;
154
+
155
+    return 0;
156
+}
157
+
158
+AVCodec wnv1_decoder = {
159
+    "wnv1",
160
+    CODEC_TYPE_VIDEO,
161
+    CODEC_ID_WNV1,
162
+    sizeof(WNV1Context),
163
+    decode_init,
164
+    NULL,
165
+    NULL,
166
+    decode_frame,
167
+    CODEC_CAP_DR1,
168
+};
... ...
@@ -178,6 +178,7 @@ const CodecTag codec_bmp_tags[] = {
178 178
     { CODEC_ID_QPEG, MKTAG('Q', '1', '.', '1') },
179 179
     { CODEC_ID_WMV3, MKTAG('W', 'M', 'V', '3') },
180 180
     { CODEC_ID_LOCO, MKTAG('L', 'O', 'C', 'O') },
181
+    { CODEC_ID_WNV1, MKTAG('W', 'N', 'V', '1') },
181 182
     { CODEC_ID_RAWVIDEO, 0 },
182 183
     { 0, 0 },
183 184
 };