Browse code

v308 Quicktim Uncompressed 4:4:4 encoder and decoder.

Reviewed-by: Derek Buitenhuis
Reviewed-by: Paul B Mahol

Carl Eugen Hoyos authored on 2012/01/04 23:24:38
Showing 10 changed files
... ...
@@ -17,6 +17,7 @@ version next:
17 17
 - y41p Brooktree Uncompressed 4:1:1 12-bit encoder and decoder
18 18
 - ffprobe -show_error option
19 19
 - Avid 1:1 10-bit RGB Packer decoder
20
+- v308 Quicktime Uncompressed 4:4:4 encoder and decoder
20 21
 
21 22
 
22 23
 version 0.9:
... ...
@@ -609,6 +609,7 @@ following image formats are supported:
609 609
     @tab Codec used in DOS CD-ROM FlashBack game.
610 610
 @item Ut Video               @tab     @tab  X
611 611
 @item v210 QuickTime uncompressed 4:2:2 10-bit     @tab  X  @tab  X
612
+@item v308 QuickTime uncompressed 4:4:4            @tab  X  @tab  X
612 613
 @item v410 QuickTime uncompressed 4:4:4 10-bit     @tab  X  @tab  X
613 614
 @item VBLE Lossless Codec    @tab     @tab  X
614 615
 @item VMware Screen Codec / VMware Video  @tab     @tab  X
... ...
@@ -416,6 +416,8 @@ OBJS-$(CONFIG_ULTI_DECODER)            += ulti.o
416 416
 OBJS-$(CONFIG_UTVIDEO_DECODER)         += utvideo.o
417 417
 OBJS-$(CONFIG_V210_DECODER)            += v210dec.o
418 418
 OBJS-$(CONFIG_V210_ENCODER)            += v210enc.o
419
+OBJS-$(CONFIG_V308_DECODER)            += v308dec.o
420
+OBJS-$(CONFIG_V308_ENCODER)            += v308enc.o
419 421
 OBJS-$(CONFIG_V410_DECODER)            += v410dec.o
420 422
 OBJS-$(CONFIG_V410_ENCODER)            += v410enc.o
421 423
 OBJS-$(CONFIG_V210X_DECODER)           += v210x.o
... ...
@@ -217,6 +217,7 @@ void avcodec_register_all(void)
217 217
     REGISTER_DECODER (UTVIDEO, utvideo);
218 218
     REGISTER_ENCDEC  (V210,  v210);
219 219
     REGISTER_DECODER (V210X, v210x);
220
+    REGISTER_ENCDEC  (V308, v308);
220 221
     REGISTER_ENCDEC  (V410, v410);
221 222
     REGISTER_DECODER (VB, vb);
222 223
     REGISTER_DECODER (VBLE, vble);
... ...
@@ -261,6 +261,7 @@ enum CodecID {
261 261
     CODEC_ID_AVRP       = MKBETAG('A','V','R','P'),
262 262
 
263 263
     CODEC_ID_G2M        = MKBETAG( 0 ,'G','2','M'),
264
+    CODEC_ID_V308       = MKBETAG('V','3','0','8'),
264 265
 
265 266
     /* various PCM "codecs" */
266 267
     CODEC_ID_FIRST_AUDIO = 0x10000,     ///< A dummy id pointing at the start of audio codecs
267 268
new file mode 100644
... ...
@@ -0,0 +1,108 @@
0
+/*
1
+ * v308 decoder
2
+ * Copyright (c) 2011 Carl Eugen Hoyos
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 "avcodec.h"
22
+
23
+static av_cold int v308_decode_init(AVCodecContext *avctx)
24
+{
25
+    avctx->pix_fmt = PIX_FMT_YUV444P;
26
+
27
+    if (avctx->width & 1)
28
+        av_log(avctx, AV_LOG_WARNING, "v308 requires width to be even.\n");
29
+
30
+    avctx->coded_frame = avcodec_alloc_frame();
31
+
32
+    if (!avctx->coded_frame) {
33
+        av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n");
34
+        return AVERROR(ENOMEM);
35
+    }
36
+
37
+    return 0;
38
+}
39
+
40
+static int v308_decode_frame(AVCodecContext *avctx, void *data,
41
+                             int *data_size, AVPacket *avpkt)
42
+{
43
+    AVFrame *pic = avctx->coded_frame;
44
+    const uint8_t *src = avpkt->data;
45
+    uint8_t *y, *u, *v;
46
+    int i, j;
47
+
48
+    if (pic->data[0])
49
+        avctx->release_buffer(avctx, pic);
50
+
51
+    if (avpkt->size < 3 * avctx->height * avctx->width) {
52
+        av_log(avctx, AV_LOG_ERROR, "Insufficient input data.\n");
53
+        return AVERROR(EINVAL);
54
+    }
55
+
56
+    pic->reference = 0;
57
+
58
+    if (avctx->get_buffer(avctx, pic) < 0) {
59
+        av_log(avctx, AV_LOG_ERROR, "Could not allocate buffer.\n");
60
+        return AVERROR(ENOMEM);
61
+    }
62
+
63
+    pic->key_frame = 1;
64
+    pic->pict_type = FF_I_TYPE;
65
+
66
+    y = pic->data[0];
67
+    u = pic->data[1];
68
+    v = pic->data[2];
69
+
70
+    for (i = 0; i < avctx->height; i++) {
71
+        for (j = 0; j < avctx->width; j++) {
72
+            v[j] = *src++;
73
+            y[j] = *src++;
74
+            u[j] = *src++;
75
+        }
76
+
77
+        y += pic->linesize[0];
78
+        u += pic->linesize[1];
79
+        v += pic->linesize[2];
80
+    }
81
+
82
+    *data_size = sizeof(AVFrame);
83
+    *(AVFrame *)data = *pic;
84
+
85
+    return avpkt->size;
86
+}
87
+
88
+static av_cold int v308_decode_close(AVCodecContext *avctx)
89
+{
90
+    if (avctx->coded_frame->data[0])
91
+        avctx->release_buffer(avctx, avctx->coded_frame);
92
+
93
+    av_freep(&avctx->coded_frame);
94
+
95
+    return 0;
96
+}
97
+
98
+AVCodec ff_v308_decoder = {
99
+    .name         = "v308",
100
+    .type         = AVMEDIA_TYPE_VIDEO,
101
+    .id           = CODEC_ID_V308,
102
+    .init         = v308_decode_init,
103
+    .decode       = v308_decode_frame,
104
+    .close        = v308_decode_close,
105
+    .capabilities = CODEC_CAP_DR1,
106
+    .long_name    = NULL_IF_CONFIG_SMALL("Uncompressed packed 4:4:4"),
107
+};
0 108
new file mode 100644
... ...
@@ -0,0 +1,96 @@
0
+/*
1
+ * v308 encoder
2
+ *
3
+ * Copyright (c) 2011 Carl Eugen Hoyos
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 "libavutil/intreadwrite.h"
23
+#include "avcodec.h"
24
+
25
+static av_cold int v308_encode_init(AVCodecContext *avctx)
26
+{
27
+    if (avctx->width & 1) {
28
+        av_log(avctx, AV_LOG_ERROR, "v308 requires width to be even.\n");
29
+        return AVERROR_INVALIDDATA;
30
+    }
31
+
32
+    avctx->coded_frame = avcodec_alloc_frame();
33
+
34
+    if (!avctx->coded_frame) {
35
+        av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n");
36
+        return AVERROR(ENOMEM);
37
+    }
38
+
39
+    return 0;
40
+}
41
+
42
+static int v308_encode_frame(AVCodecContext *avctx, uint8_t *buf,
43
+                             int buf_size, void *data)
44
+{
45
+    AVFrame *pic = data;
46
+    uint8_t *dst = buf;
47
+    uint8_t *y, *u, *v;
48
+    int i, j;
49
+    int output_size = 0;
50
+
51
+    if (buf_size < avctx->width * avctx->height * 3) {
52
+        av_log(avctx, AV_LOG_ERROR, "Out buffer is too small.\n");
53
+        return AVERROR(ENOMEM);
54
+    }
55
+
56
+    avctx->coded_frame->reference = 0;
57
+    avctx->coded_frame->key_frame = 1;
58
+    avctx->coded_frame->pict_type = FF_I_TYPE;
59
+
60
+    y = pic->data[0];
61
+    u = pic->data[1];
62
+    v = pic->data[2];
63
+
64
+    for (i = 0; i < avctx->height; i++) {
65
+        for (j = 0; j < avctx->width; j++) {
66
+            *dst++ = v[j];
67
+            *dst++ = y[j];
68
+            *dst++ = u[j];
69
+            output_size += 3;
70
+        }
71
+        y += pic->linesize[0];
72
+        u += pic->linesize[1];
73
+        v += pic->linesize[2];
74
+    }
75
+
76
+    return output_size;
77
+}
78
+
79
+static av_cold int v308_encode_close(AVCodecContext *avctx)
80
+{
81
+    av_freep(&avctx->coded_frame);
82
+
83
+    return 0;
84
+}
85
+
86
+AVCodec ff_v308_encoder = {
87
+    .name         = "v308",
88
+    .type         = AVMEDIA_TYPE_VIDEO,
89
+    .id           = CODEC_ID_V308,
90
+    .init         = v308_encode_init,
91
+    .encode       = v308_encode_frame,
92
+    .close        = v308_encode_close,
93
+    .pix_fmts     = (const enum PixelFormat[]){ PIX_FMT_YUV444P, PIX_FMT_NONE },
94
+    .long_name    = NULL_IF_CONFIG_SMALL("Uncompressed packed 4:4:4"),
95
+};
... ...
@@ -21,7 +21,7 @@
21 21
 #define AVCODEC_VERSION_H
22 22
 
23 23
 #define LIBAVCODEC_VERSION_MAJOR 53
24
-#define LIBAVCODEC_VERSION_MINOR 51
24
+#define LIBAVCODEC_VERSION_MINOR 52
25 25
 #define LIBAVCODEC_VERSION_MICRO 100
26 26
 
27 27
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
... ...
@@ -91,6 +91,7 @@ const AVCodecTag codec_movvideo_tags[] = {
91 91
     { CODEC_ID_R210,   MKTAG('r', '2', '1', '0') }, /* UNCOMPRESSED 10BIT RGB */
92 92
     { CODEC_ID_AVRP,   MKTAG('A', 'V', 'r', 'p') }, /* Avid 1:1 10-bit RGB Packer */
93 93
     { CODEC_ID_V210,   MKTAG('v', '2', '1', '0') }, /* UNCOMPRESSED 10BIT 4:2:2 */
94
+    { CODEC_ID_V308,   MKTAG('v', '3', '0', '8') }, /* UNCOMPRESSED 4:4:4 */
94 95
     { CODEC_ID_V410,   MKTAG('v', '4', '1', '0') }, /* UNCOMPRESSED 10BIT 4:4:4 */
95 96
     { CODEC_ID_Y41P,   MKTAG('Y', '4', '1', 'P') }, /* UNCOMPRESSED 12BIT 4:1:1 */
96 97
 
... ...
@@ -199,6 +199,7 @@ const AVCodecTag ff_codec_bmp_tags[] = {
199 199
     { CODEC_ID_R10K,         MKTAG('R', '1', '0', 'k') },
200 200
     { CODEC_ID_R210,         MKTAG('r', '2', '1', '0') },
201 201
     { CODEC_ID_V210,         MKTAG('v', '2', '1', '0') },
202
+    { CODEC_ID_V308,         MKTAG('v', '3', '0', '8') },
202 203
     { CODEC_ID_V410,         MKTAG('v', '4', '1', '0') },
203 204
     { CODEC_ID_INDEO3,       MKTAG('I', 'V', '3', '1') },
204 205
     { CODEC_ID_INDEO3,       MKTAG('I', 'V', '3', '2') },