annotate r210dec.c @ 11338:444401d150d6 libavcodec

Simplify implicit_weight table init.
author michael
date Wed, 03 Mar 2010 10:57:38 +0000
parents d17c26774897
children 8a4984c5cacc
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++) {
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
64 uint32_t pixel = be2me_32(*src++);
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
65 uint16_t r, g, b;
10694
d17c26774897 Swap red and blue when decoding r210.
cehoyos
parents: 10693
diff changeset
66 b = pixel << 6;
10693
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
67 g = (pixel >> 4) & 0xffc0;
10694
d17c26774897 Swap red and blue when decoding r210.
cehoyos
parents: 10693
diff changeset
68 r = (pixel >> 14) & 0xffc0;
10693
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
69 *dst++ = r | (r >> 10);
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
70 *dst++ = g | (g >> 10);
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
71 *dst++ = b | (b >> 10);
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
72 }
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
73 src += aligned_width - avctx->width;
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
74 dst_line += pic->linesize[0];
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
75 }
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
76
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
77 *data_size = sizeof(AVFrame);
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
78 *(AVFrame*)data = *avctx->coded_frame;
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
79
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
80 return avpkt->size;
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 static av_cold int decode_close(AVCodecContext *avctx)
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
84 {
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
85 AVFrame *pic = avctx->coded_frame;
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
86 if (pic->data[0])
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
87 avctx->release_buffer(avctx, pic);
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
88 av_freep(&avctx->coded_frame);
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
89
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
90 return 0;
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
91 }
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
92
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
93 AVCodec r210_decoder = {
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
94 "r210",
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
95 CODEC_TYPE_VIDEO,
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
96 CODEC_ID_R210,
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
97 0,
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
98 decode_init,
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
99 NULL,
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
100 decode_close,
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
101 decode_frame,
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
102 CODEC_CAP_DR1,
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
103 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed RGB 10-bit"),
0aec5a890b83 Add decoder for R210 (uncompressed 10-bit RGB) codec.
reimar
parents:
diff changeset
104 };