Browse code

Add decoder for R210 (uncompressed 10-bit RGB) codec.

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

Reimar Döffinger authored on 2009/12/18 03:56:56
Showing 8 changed files
... ...
@@ -45,6 +45,7 @@ version <next>:
45 45
 - -formats option split into -formats, -codecs, -bsfs, and -protocols
46 46
 - IV8 demuxer
47 47
 - CDG demuxer and decoder
48
+- R210 decoder
48 49
 
49 50
 
50 51
 
... ...
@@ -430,6 +430,7 @@ following image formats are supported:
430 430
     @tab fourcc: 'smc '
431 431
 @item QuickTime video (RPZA) @tab     @tab  X
432 432
     @tab fourcc: rpza
433
+@item R210 Quicktime Uncompressed RGB 10-bit     @tab     @tab  X
433 434
 @item Raw Video              @tab  X  @tab  X
434 435
 @item RealVideo 1.0          @tab  X  @tab  X
435 436
 @item RealVideo 2.0          @tab  X  @tab  X
... ...
@@ -247,6 +247,7 @@ OBJS-$(CONFIG_QDRAW_DECODER)           += qdrw.o
247 247
 OBJS-$(CONFIG_QPEG_DECODER)            += qpeg.o
248 248
 OBJS-$(CONFIG_QTRLE_DECODER)           += qtrle.o
249 249
 OBJS-$(CONFIG_QTRLE_ENCODER)           += qtrleenc.o
250
+OBJS-$(CONFIG_R210_DECODER)            += r210dec.o
250 251
 OBJS-$(CONFIG_RA_144_DECODER)          += ra144.o celp_filters.o
251 252
 OBJS-$(CONFIG_RA_288_DECODER)          += ra288.o celp_math.o celp_filters.o
252 253
 OBJS-$(CONFIG_RAWVIDEO_DECODER)        += rawdec.o
... ...
@@ -146,6 +146,7 @@ void avcodec_register_all(void)
146 146
     REGISTER_DECODER (QDRAW, qdraw);
147 147
     REGISTER_DECODER (QPEG, qpeg);
148 148
     REGISTER_ENCDEC  (QTRLE, qtrle);
149
+    REGISTER_DECODER (R210,  r210);
149 150
     REGISTER_ENCDEC  (RAWVIDEO, rawvideo);
150 151
     REGISTER_DECODER (RL2, rl2);
151 152
     REGISTER_ENCDEC  (ROQ, roq);
... ...
@@ -201,6 +201,7 @@ enum CodecID {
201 201
     CODEC_ID_FRWU,
202 202
     CODEC_ID_FLASHSV2,
203 203
     CODEC_ID_CDGRAPHICS,
204
+    CODEC_ID_R210,
204 205
 
205 206
     /* various PCM "codecs" */
206 207
     CODEC_ID_PCM_S16LE= 0x10000,
207 208
new file mode 100644
... ...
@@ -0,0 +1,104 @@
0
+/*
1
+ * R210 decoder
2
+ *
3
+ * Copyright (c) 2009 Reimar Doeffinger <Reimar.Doeffinger@gmx.de>
4
+ *
5
+ * This file is part of FFmpeg.
6
+ *
7
+ * FFmpeg 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
+ * FFmpeg 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 FFmpeg; 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/bswap.h"
24
+
25
+static av_cold int decode_init(AVCodecContext *avctx)
26
+{
27
+    avctx->pix_fmt             = PIX_FMT_RGB48;
28
+    avctx->bits_per_raw_sample = 10;
29
+
30
+    avctx->coded_frame         = avcodec_alloc_frame();
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 uint32_t *src = (const uint32_t *)avpkt->data;
41
+    int aligned_width = FFALIGN(avctx->width, 64);
42
+    uint8_t *dst_line;
43
+
44
+    if (pic->data[0])
45
+        avctx->release_buffer(avctx, pic);
46
+
47
+    if (avpkt->size < 4 * aligned_width * avctx->height) {
48
+        av_log(avctx, AV_LOG_ERROR, "packet too small\n");
49
+        return -1;
50
+    }
51
+
52
+    pic->reference = 0;
53
+    if (avctx->get_buffer(avctx, pic) < 0)
54
+        return -1;
55
+
56
+    pic->pict_type = FF_I_TYPE;
57
+    pic->key_frame = 1;
58
+    dst_line = pic->data[0];
59
+
60
+    for (h = 0; h < avctx->height; h++) {
61
+        uint16_t *dst = (uint16_t *)dst_line;
62
+        for (w = 0; w < avctx->width; w++) {
63
+            uint32_t pixel = be2me_32(*src++);
64
+            uint16_t r, g, b;
65
+            r =  pixel <<  6;
66
+            g = (pixel >>  4) & 0xffc0;
67
+            b = (pixel >> 14) & 0xffc0;
68
+            *dst++ = r | (r >> 10);
69
+            *dst++ = g | (g >> 10);
70
+            *dst++ = b | (b >> 10);
71
+        }
72
+        src += aligned_width - avctx->width;
73
+        dst_line += pic->linesize[0];
74
+    }
75
+
76
+    *data_size = sizeof(AVFrame);
77
+    *(AVFrame*)data = *avctx->coded_frame;
78
+
79
+    return avpkt->size;
80
+}
81
+
82
+static av_cold int decode_close(AVCodecContext *avctx)
83
+{
84
+    AVFrame *pic = avctx->coded_frame;
85
+    if (pic->data[0])
86
+        avctx->release_buffer(avctx, pic);
87
+    av_freep(&avctx->coded_frame);
88
+
89
+    return 0;
90
+}
91
+
92
+AVCodec r210_decoder = {
93
+    "r210",
94
+    CODEC_TYPE_VIDEO,
95
+    CODEC_ID_R210,
96
+    0,
97
+    decode_init,
98
+    NULL,
99
+    decode_close,
100
+    decode_frame,
101
+    CODEC_CAP_DR1,
102
+    .long_name = NULL_IF_CONFIG_SMALL("Uncompressed RGB 10-bit"),
103
+};
... ...
@@ -67,6 +67,7 @@ const AVCodecTag codec_movvideo_tags[] = {
67 67
     { CODEC_ID_RAWVIDEO, MKTAG('2', 'v', 'u', 'y') }, /* UNCOMPRESSED 8BIT 4:2:2 */
68 68
     { CODEC_ID_RAWVIDEO, MKTAG('y', 'u', 'v', 's') }, /* same as 2vuy but byte swapped */
69 69
 
70
+    { CODEC_ID_R210,   MKTAG('r', '2', '1', '0') }, /* UNCOMPRESSED 10BIT RGB */
70 71
     { CODEC_ID_V210,   MKTAG('v', '2', '1', '0') }, /* UNCOMPRESSED 10BIT 4:2:2 */
71 72
 
72 73
     { CODEC_ID_MJPEG,  MKTAG('j', 'p', 'e', 'g') }, /* PhotoJPEG */
... ...
@@ -163,6 +163,7 @@ const AVCodecTag ff_codec_bmp_tags[] = {
163 163
     { CODEC_ID_RAWVIDEO,     MKTAG('H', 'D', 'Y', 'C') },
164 164
     { CODEC_ID_RAWVIDEO,     MKTAG('Y', 'V', 'U', '9') },
165 165
     { CODEC_ID_FRWU,         MKTAG('F', 'R', 'W', 'U') },
166
+    { CODEC_ID_R210,         MKTAG('r', '2', '1', '0') },
166 167
     { CODEC_ID_V210,         MKTAG('v', '2', '1', '0') },
167 168
     { CODEC_ID_INDEO3,       MKTAG('I', 'V', '3', '1') },
168 169
     { CODEC_ID_INDEO3,       MKTAG('I', 'V', '3', '2') },