lavc: fix decode_frame() third parameter semantics for video decoders
[libav.git] / libavcodec / r210dec.c
1 /*
2 * R210 decoder
3 *
4 * Copyright (c) 2009 Reimar Doeffinger <Reimar.Doeffinger@gmx.de>
5 *
6 * This file is part of Libav.
7 *
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.
12 *
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.
17 *
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
21 */
22
23 #include "avcodec.h"
24 #include "internal.h"
25 #include "libavutil/bswap.h"
26 #include "libavutil/common.h"
27
28 static av_cold int decode_init(AVCodecContext *avctx)
29 {
30 avctx->pix_fmt = AV_PIX_FMT_RGB48;
31 avctx->bits_per_raw_sample = 10;
32
33 avctx->coded_frame = avcodec_alloc_frame();
34
35 return 0;
36 }
37
38 static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
39 AVPacket *avpkt)
40 {
41 int h, w;
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;
46
47 if (pic->data[0])
48 avctx->release_buffer(avctx, pic);
49
50 if (avpkt->size < 4 * aligned_width * avctx->height) {
51 av_log(avctx, AV_LOG_ERROR, "packet too small\n");
52 return -1;
53 }
54
55 pic->reference = 0;
56 if (ff_get_buffer(avctx, pic) < 0)
57 return -1;
58
59 pic->pict_type = AV_PICTURE_TYPE_I;
60 pic->key_frame = 1;
61 dst_line = pic->data[0];
62
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;
76 }
77 *dst++ = r | (r >> 10);
78 *dst++ = g | (g >> 10);
79 *dst++ = b | (b >> 10);
80 }
81 src += aligned_width - avctx->width;
82 dst_line += pic->linesize[0];
83 }
84
85 *got_frame = 1;
86 *(AVFrame*)data = *avctx->coded_frame;
87
88 return avpkt->size;
89 }
90
91 static av_cold int decode_close(AVCodecContext *avctx)
92 {
93 AVFrame *pic = avctx->coded_frame;
94 if (pic->data[0])
95 avctx->release_buffer(avctx, pic);
96 av_freep(&avctx->coded_frame);
97
98 return 0;
99 }
100
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"),
111 };
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"),
123 };
124 #endif