Browse code

add V.Flash PTX decoder

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

Ivo van Poorten authored on 2007/04/29 18:37:07
Showing 6 changed files
... ...
@@ -81,6 +81,7 @@ version <next>
81 81
 - Bethsoft VID demuxer and video decoder
82 82
 - CRYO APC demuxer
83 83
 - Atrac3 decoder
84
+- V.Flash PTX decoder
84 85
 
85 86
 version 0.4.9-pre1:
86 87
 
... ...
@@ -152,6 +152,7 @@ Codecs:
152 152
   msvideo1.c                            Mike Melanson
153 153
   nuv.c                                 Reimar Doeffinger
154 154
   oggtheora.c                           Mans Rullgard
155
+  ptx.c                                 Ivo van Poorten
155 156
   qdm2.c, qdm2data.h                    Roberto Togni
156 157
   qdrw.c                                Kostya Shishkov
157 158
   qpeg.c                                Kostya Shishkov
... ...
@@ -116,6 +116,7 @@ OBJS-$(CONFIG_MSZH_DECODER)            += lcl.o
116 116
 OBJS-$(CONFIG_NUV_DECODER)             += nuv.o rtjpeg.o
117 117
 OBJS-$(CONFIG_PNG_DECODER)             += png.o
118 118
 OBJS-$(CONFIG_PNG_ENCODER)             += png.o
119
+OBJS-$(CONFIG_PTX_DECODER)             += ptx.o
119 120
 OBJS-$(CONFIG_QDM2_DECODER)            += qdm2.o
120 121
 OBJS-$(CONFIG_QDRAW_DECODER)           += qdrw.o
121 122
 OBJS-$(CONFIG_QPEG_DECODER)            += qpeg.o
... ...
@@ -116,6 +116,7 @@ void avcodec_register_all(void)
116 116
     REGISTER_ENCODER(PGMYUV, pgmyuv);
117 117
     REGISTER_ENCDEC (PNG, png);
118 118
     REGISTER_ENCODER(PPM, ppm);
119
+    REGISTER_DECODER(PTX, ptx);
119 120
     REGISTER_DECODER(QDRAW, qdraw);
120 121
     REGISTER_DECODER(QPEG, qpeg);
121 122
     REGISTER_DECODER(QTRLE, qtrle);
... ...
@@ -162,6 +162,7 @@ enum CodecID {
162 162
     CODEC_ID_SGI,
163 163
     CODEC_ID_C93,
164 164
     CODEC_ID_BETHSOFTVID,
165
+    CODEC_ID_PTX,
165 166
 
166 167
     /* various PCM "codecs" */
167 168
     CODEC_ID_PCM_S16LE= 0x10000,
... ...
@@ -2321,6 +2322,7 @@ extern AVCodec mszh_decoder;
2321 2321
 extern AVCodec nuv_decoder;
2322 2322
 extern AVCodec oggvorbis_decoder;
2323 2323
 extern AVCodec png_decoder;
2324
+extern AVCodec ptx_decoder;
2324 2325
 extern AVCodec qdm2_decoder;
2325 2326
 extern AVCodec qdraw_decoder;
2326 2327
 extern AVCodec qpeg_decoder;
2327 2328
new file mode 100644
... ...
@@ -0,0 +1,119 @@
0
+/*
1
+ * V.Flash PTX (.ptx) image decoder
2
+ * Copyright (c) 2007 Ivo van Poorten
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
+
22
+#include "avcodec.h"
23
+
24
+typedef struct PTXContext {
25
+    AVFrame picture;
26
+} PTXContext;
27
+
28
+static int ptx_init(AVCodecContext *avctx) {
29
+    PTXContext *s = avctx->priv_data;
30
+
31
+    avcodec_get_frame_defaults((AVFrame*)&s->picture);
32
+    avctx->coded_frame= (AVFrame*)&s->picture;
33
+    s->picture.data[0] = NULL;
34
+
35
+    return 0;
36
+}
37
+
38
+static int ptx_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
39
+                            uint8_t *buf, int buf_size) {
40
+    PTXContext * const s = avctx->priv_data;
41
+    AVFrame *picture = data;
42
+    AVFrame * const p = (AVFrame *)&s->picture;
43
+    unsigned int offset, w, h, y, stride, bytes_per_pixel;
44
+    uint8_t *ptr;
45
+
46
+    offset          = AV_RL16(buf);
47
+    w               = AV_RL16(buf+8);
48
+    h               = AV_RL16(buf+10);
49
+    bytes_per_pixel = AV_RL16(buf+12) >> 3;
50
+
51
+    if (bytes_per_pixel != 2) {
52
+        av_log(avctx, AV_LOG_ERROR, "image format is not rgb15, please report on ffmpeg-users mailing list\n");
53
+        return -1;
54
+    }
55
+
56
+    avctx->pix_fmt = PIX_FMT_RGB555;
57
+
58
+    if (offset != 0x2c)
59
+        av_log(avctx, AV_LOG_WARNING, "offset != 0x2c, untested due to lack of sample files\n");
60
+
61
+    buf += offset;
62
+
63
+    if (p->data[0])
64
+        avctx->release_buffer(avctx, p);
65
+
66
+    if (avcodec_check_dimensions(avctx, w, h))
67
+        return -1;
68
+    if (w != avctx->width || h != avctx->height)
69
+        avcodec_set_dimensions(avctx, w, h);
70
+    if (avctx->get_buffer(avctx, p) < 0) {
71
+        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
72
+        return -1;
73
+    }
74
+
75
+    p->pict_type = FF_I_TYPE;
76
+
77
+    ptr    = p->data[0];
78
+    stride = p->linesize[0];
79
+
80
+    for (y=0; y<h; y++) {
81
+#ifdef WORDS_BIGENDIAN
82
+        unsigned int x;
83
+        for (x=0; x<w*bytes_per_pixel; x+=bytes_per_pixel)
84
+            ST16(ptr+x, AV_RL16(buf+x));
85
+#else
86
+        memcpy(ptr, buf, w*bytes_per_pixel);
87
+#endif
88
+        ptr += stride;
89
+        buf += w*bytes_per_pixel;
90
+    }
91
+
92
+    *picture = *(AVFrame *)&s->picture;
93
+    *data_size = sizeof(AVPicture);
94
+
95
+    return offset + w*h*bytes_per_pixel;
96
+}
97
+
98
+static int ptx_end(AVCodecContext *avctx) {
99
+    PTXContext *s = avctx->priv_data;
100
+
101
+    if(s->picture.data[0])
102
+        avctx->release_buffer(avctx, &s->picture);
103
+
104
+    return 0;
105
+}
106
+
107
+AVCodec ptx_decoder = {
108
+    "ptx",
109
+    CODEC_TYPE_VIDEO,
110
+    CODEC_ID_PTX,
111
+    sizeof(PTXContext),
112
+    ptx_init,
113
+    NULL,
114
+    ptx_end,
115
+    ptx_decode_frame,
116
+    0,
117
+    NULL
118
+};