annotate r210dec.c @ 12522:776789af0304 libavcodec

Move AVOptions from libavcodec to libavutil
author michael
date Sun, 26 Sep 2010 14:25:22 +0000
parents 990f8a5fc8af
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10693
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
1 /*
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
2 * R210 decoder
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
3 *
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
4 * Copyright (c) 2009 Reimar Doeffinger <Reimar.Doeffinger@gmx.de>
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
5 *
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
6 * This file is part of FFmpeg.
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
7 *
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
8 * FFmpeg is free software; you can redistribute it and/or
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
10 * License as published by the Free Software Foundation; either
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
11 * version 2.1 of the License, or (at your option) any later version.
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
12 *
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
13 * FFmpeg is distributed in the hope that it will be useful,
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
16 * Lesser General Public License for more details.
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
17 *
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
19 * License along with FFmpeg; if not, write to the Free Software
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
21 */
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
22
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
23 #include "avcodec.h"
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
24 #include "libavutil/bswap.h"
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
25
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
26 static av_cold int decode_init(AVCodecContext *avctx)
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
27 {
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
28 avctx->pix_fmt = PIX_FMT_RGB48;
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
29 avctx->bits_per_raw_sample = 10;
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
30
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
31 avctx->coded_frame = avcodec_alloc_frame();
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
32
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
33 return 0;
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
34 }
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
35
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
36 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
37 AVPacket *avpkt)
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
38 {
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
39 int h, w;
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
40 AVFrame *pic = avctx->coded_frame;
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
41 const uint32_t *src = (const uint32_t *)avpkt->data;
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
42 int aligned_width = FFALIGN(avctx->width, 64);
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
43 uint8_t *dst_line;
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
44
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
45 if (pic->data[0])
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
46 avctx->release_buffer(avctx, pic);
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
47
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
48 if (avpkt->size < 4 * aligned_width * avctx->height) {
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
49 av_log(avctx, AV_LOG_ERROR, "packet too small\n");
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
50 return -1;
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
51 }
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
52
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
53 pic->reference = 0;
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
54 if (avctx->get_buffer(avctx, pic) < 0)
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
55 return -1;
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
56
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
57 pic->pict_type = FF_I_TYPE;
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
58 pic->key_frame = 1;
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
59 dst_line = pic->data[0];
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
60
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
61 for (h = 0; h < avctx->height; h++) {
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
62 uint16_t *dst = (uint16_t *)dst_line;
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
63 for (w = 0; w < avctx->width; w++) {
12129
8b28e74de2c0 Add av_ prefix to bswap macros
mru
parents: 12128
diff changeset
64 uint32_t pixel = av_be2ne32(*src++);
10693
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
65 uint16_t r, g, b;
12490
e1a4ceb96a07 Add R10k decoder.
cehoyos
parents: 12129
diff changeset
66 if (avctx->codec_id==CODEC_ID_R210) {
12491
990f8a5fc8af Reindent after r25115.
cehoyos
parents: 12490
diff changeset
67 b = pixel << 6;
990f8a5fc8af Reindent after r25115.
cehoyos
parents: 12490
diff changeset
68 g = (pixel >> 4) & 0xffc0;
990f8a5fc8af Reindent after r25115.
cehoyos
parents: 12490
diff changeset
69 r = (pixel >> 14) & 0xffc0;
12490
e1a4ceb96a07 Add R10k decoder.
cehoyos
parents: 12129
diff changeset
70 } else {
e1a4ceb96a07 Add R10k decoder.
cehoyos
parents: 12129
diff changeset
71 b = pixel << 4;
e1a4ceb96a07 Add R10k decoder.
cehoyos
parents: 12129
diff changeset
72 g = (pixel >> 6) & 0xffc0;
e1a4ceb96a07 Add R10k decoder.
cehoyos
parents: 12129
diff changeset
73 r = (pixel >> 16) & 0xffc0;
e1a4ceb96a07 Add R10k decoder.
cehoyos
parents: 12129
diff changeset
74 }
10693
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
75 *dst++ = r | (r >> 10);
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
76 *dst++ = g | (g >> 10);
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
77 *dst++ = b | (b >> 10);
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
78 }
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
79 src += aligned_width - avctx->width;
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
80 dst_line += pic->linesize[0];
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
81 }
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
82
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
83 *data_size = sizeof(AVFrame);
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
84 *(AVFrame*)data = *avctx->coded_frame;
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
85
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
86 return avpkt->size;
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
87 }
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
88
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
89 static av_cold int decode_close(AVCodecContext *avctx)
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
90 {
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
91 AVFrame *pic = avctx->coded_frame;
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
92 if (pic->data[0])
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
93 avctx->release_buffer(avctx, pic);
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
94 av_freep(&avctx->coded_frame);
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
95
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
96 return 0;
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
97 }
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
98
12490
e1a4ceb96a07 Add R10k decoder.
cehoyos
parents: 12129
diff changeset
99 #if CONFIG_R210_DECODER
10693
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
100 AVCodec r210_decoder = {
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
101 "r210",
11560
8a4984c5cacc Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 10694
diff changeset
102 AVMEDIA_TYPE_VIDEO,
10693
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
103 CODEC_ID_R210,
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
104 0,
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
105 decode_init,
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
106 NULL,
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
107 decode_close,
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
108 decode_frame,
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
109 CODEC_CAP_DR1,
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
110 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed RGB 10-bit"),
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
111 };
12490
e1a4ceb96a07 Add R10k decoder.
cehoyos
parents: 12129
diff changeset
112 #endif
e1a4ceb96a07 Add R10k decoder.
cehoyos
parents: 12129
diff changeset
113 #if CONFIG_R10K_DECODER
e1a4ceb96a07 Add R10k decoder.
cehoyos
parents: 12129
diff changeset
114 AVCodec r10k_decoder = {
e1a4ceb96a07 Add R10k decoder.
cehoyos
parents: 12129
diff changeset
115 "r10k",
e1a4ceb96a07 Add R10k decoder.
cehoyos
parents: 12129
diff changeset
116 AVMEDIA_TYPE_VIDEO,
e1a4ceb96a07 Add R10k decoder.
cehoyos
parents: 12129
diff changeset
117 CODEC_ID_R10K,
e1a4ceb96a07 Add R10k decoder.
cehoyos
parents: 12129
diff changeset
118 0,
e1a4ceb96a07 Add R10k decoder.
cehoyos
parents: 12129
diff changeset
119 decode_init,
e1a4ceb96a07 Add R10k decoder.
cehoyos
parents: 12129
diff changeset
120 NULL,
e1a4ceb96a07 Add R10k decoder.
cehoyos
parents: 12129
diff changeset
121 decode_close,
e1a4ceb96a07 Add R10k decoder.
cehoyos
parents: 12129
diff changeset
122 decode_frame,
e1a4ceb96a07 Add R10k decoder.
cehoyos
parents: 12129
diff changeset
123 CODEC_CAP_DR1,
e1a4ceb96a07 Add R10k decoder.
cehoyos
parents: 12129
diff changeset
124 .long_name = NULL_IF_CONFIG_SMALL("AJA Kona 10-bit RGB Codec"),
e1a4ceb96a07 Add R10k decoder.
cehoyos
parents: 12129
diff changeset
125 };
e1a4ceb96a07 Add R10k decoder.
cehoyos
parents: 12129
diff changeset
126 #endif