asfdec: also read Metadata Library Object
[FFMpeg-mirror/mplayer-patches.git] / libavcodec / r210dec.c
blob7fd663b9a35089acfa5beb84c1c0c9e14a0a38c7
1 /*
2 * R210 decoder
4 * Copyright (c) 2009 Reimar Doeffinger <Reimar.Doeffinger@gmx.de>
6 * This file is part of Libav.
8 * Libav is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * Libav is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with Libav; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "avcodec.h"
24 #include "internal.h"
25 #include "libavutil/bswap.h"
26 #include "libavutil/common.h"
28 static av_cold int decode_init(AVCodecContext *avctx)
30 avctx->pix_fmt = AV_PIX_FMT_RGB48;
31 avctx->bits_per_raw_sample = 10;
33 avctx->coded_frame = avcodec_alloc_frame();
35 return 0;
38 static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
39 AVPacket *avpkt)
41 int h, w, ret;
42 AVFrame *pic = avctx->coded_frame;
43 const uint32_t *src = (const uint32_t *)avpkt->data;
44 int aligned_width = FFALIGN(avctx->width, 64);
45 uint8_t *dst_line;
47 if (pic->data[0])
48 avctx->release_buffer(avctx, pic);
50 if (avpkt->size < 4 * aligned_width * avctx->height) {
51 av_log(avctx, AV_LOG_ERROR, "packet too small\n");
52 return AVERROR_INVALIDDATA;
55 pic->reference = 0;
56 if ((ret = ff_get_buffer(avctx, pic)) < 0)
57 return ret;
59 pic->pict_type = AV_PICTURE_TYPE_I;
60 pic->key_frame = 1;
61 dst_line = pic->data[0];
63 for (h = 0; h < avctx->height; h++) {
64 uint16_t *dst = (uint16_t *)dst_line;
65 for (w = 0; w < avctx->width; w++) {
66 uint32_t pixel = av_be2ne32(*src++);
67 uint16_t r, g, b;
68 if (avctx->codec_id==AV_CODEC_ID_R210) {
69 b = pixel << 6;
70 g = (pixel >> 4) & 0xffc0;
71 r = (pixel >> 14) & 0xffc0;
72 } else {
73 b = pixel << 4;
74 g = (pixel >> 6) & 0xffc0;
75 r = (pixel >> 16) & 0xffc0;
77 *dst++ = r | (r >> 10);
78 *dst++ = g | (g >> 10);
79 *dst++ = b | (b >> 10);
81 src += aligned_width - avctx->width;
82 dst_line += pic->linesize[0];
85 *got_frame = 1;
86 *(AVFrame*)data = *avctx->coded_frame;
88 return avpkt->size;
91 static av_cold int decode_close(AVCodecContext *avctx)
93 AVFrame *pic = avctx->coded_frame;
94 if (pic->data[0])
95 avctx->release_buffer(avctx, pic);
96 av_freep(&avctx->coded_frame);
98 return 0;
101 #if CONFIG_R210_DECODER
102 AVCodec ff_r210_decoder = {
103 .name = "r210",
104 .type = AVMEDIA_TYPE_VIDEO,
105 .id = AV_CODEC_ID_R210,
106 .init = decode_init,
107 .close = decode_close,
108 .decode = decode_frame,
109 .capabilities = CODEC_CAP_DR1,
110 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed RGB 10-bit"),
112 #endif
113 #if CONFIG_R10K_DECODER
114 AVCodec ff_r10k_decoder = {
115 .name = "r10k",
116 .type = AVMEDIA_TYPE_VIDEO,
117 .id = AV_CODEC_ID_R10K,
118 .init = decode_init,
119 .close = decode_close,
120 .decode = decode_frame,
121 .capabilities = CODEC_CAP_DR1,
122 .long_name = NULL_IF_CONFIG_SMALL("AJA Kona 10-bit RGB Codec"),
124 #endif