4aaab0a3 |
/*
* R210 decoder
*
* Copyright (c) 2009 Reimar Doeffinger <Reimar.Doeffinger@gmx.de>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avcodec.h" |
594d4d5d |
#include "internal.h" |
4aaab0a3 |
#include "libavutil/bswap.h" |
1d9c2dc8 |
#include "libavutil/common.h" |
4aaab0a3 |
static av_cold int decode_init(AVCodecContext *avctx)
{ |
7905bd55 |
if ((avctx->codec_tag & 0xFFFFFF) == MKTAG('r', '1', '0', 0)) {
avctx->pix_fmt = AV_PIX_FMT_BGR48;
} else {
avctx->pix_fmt = AV_PIX_FMT_RGB48;
} |
4aaab0a3 |
avctx->bits_per_raw_sample = 10;
return 0;
}
|
df9b9567 |
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, |
4aaab0a3 |
AVPacket *avpkt)
{ |
39039f24 |
int h, w, ret; |
759001c5 |
AVFrame *pic = data; |
4aaab0a3 |
const uint32_t *src = (const uint32_t *)avpkt->data; |
5cd947d8 |
int aligned_width = FFALIGN(avctx->width, |
7a72695c |
avctx->codec_id == AV_CODEC_ID_R10K ? 1 : 64); |
4aaab0a3 |
uint8_t *dst_line; |
7905bd55 |
int r10 = (avctx->codec_tag & 0xFFFFFF) == MKTAG('r', '1', '0', 0); |
a5334d40 |
int le = avctx->codec_tag == MKTAG('R', '1', '0', 'k') &&
avctx->extradata_size >= 12 && !memcmp(&avctx->extradata[4], "DpxE", 4) &&
!avctx->extradata[11]; |
4aaab0a3 |
if (avpkt->size < 4 * aligned_width * avctx->height) {
av_log(avctx, AV_LOG_ERROR, "packet too small\n"); |
39039f24 |
return AVERROR_INVALIDDATA; |
4aaab0a3 |
}
|
759001c5 |
if ((ret = ff_get_buffer(avctx, pic, 0)) < 0) |
39039f24 |
return ret; |
4aaab0a3 |
|
ce5e49b0 |
pic->pict_type = AV_PICTURE_TYPE_I; |
4aaab0a3 |
pic->key_frame = 1;
dst_line = pic->data[0];
for (h = 0; h < avctx->height; h++) {
uint16_t *dst = (uint16_t *)dst_line;
for (w = 0; w < avctx->width; w++) { |
64e4f483 |
uint32_t pixel; |
4aaab0a3 |
uint16_t r, g, b; |
a5334d40 |
if (avctx->codec_id == AV_CODEC_ID_AVRP || r10 || le) { |
64e4f483 |
pixel = av_le2ne32(*src++);
} else {
pixel = av_be2ne32(*src++);
} |
7905bd55 |
if (avctx->codec_id == AV_CODEC_ID_R210 || r10) { |
6639af56 |
b = pixel << 6;
g = (pixel >> 4) & 0xffc0;
r = (pixel >> 14) & 0xffc0; |
43836928 |
} else { |
6a6a0620 |
b = (pixel << 4) & 0xffc0; |
43836928 |
g = (pixel >> 6) & 0xffc0;
r = (pixel >> 16) & 0xffc0;
} |
4aaab0a3 |
*dst++ = r | (r >> 10);
*dst++ = g | (g >> 10);
*dst++ = b | (b >> 10);
}
src += aligned_width - avctx->width;
dst_line += pic->linesize[0];
}
|
df9b9567 |
*got_frame = 1; |
4aaab0a3 |
return avpkt->size;
}
|
43836928 |
#if CONFIG_R210_DECODER |
e7e2df27 |
AVCodec ff_r210_decoder = { |
ec6402b7 |
.name = "r210", |
b2bed932 |
.long_name = NULL_IF_CONFIG_SMALL("Uncompressed RGB 10-bit"), |
ec6402b7 |
.type = AVMEDIA_TYPE_VIDEO, |
36ef5369 |
.id = AV_CODEC_ID_R210, |
ec6402b7 |
.init = decode_init,
.decode = decode_frame, |
def97856 |
.capabilities = AV_CODEC_CAP_DR1, |
91ed4e71 |
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, |
4aaab0a3 |
}; |
43836928 |
#endif
#if CONFIG_R10K_DECODER |
e7e2df27 |
AVCodec ff_r10k_decoder = { |
ec6402b7 |
.name = "r10k", |
b2bed932 |
.long_name = NULL_IF_CONFIG_SMALL("AJA Kona 10-bit RGB Codec"), |
ec6402b7 |
.type = AVMEDIA_TYPE_VIDEO, |
36ef5369 |
.id = AV_CODEC_ID_R10K, |
ec6402b7 |
.init = decode_init,
.decode = decode_frame, |
def97856 |
.capabilities = AV_CODEC_CAP_DR1, |
91ed4e71 |
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, |
43836928 |
};
#endif |
64e4f483 |
#if CONFIG_AVRP_DECODER
AVCodec ff_avrp_decoder = {
.name = "avrp", |
b46f1910 |
.long_name = NULL_IF_CONFIG_SMALL("Avid 1:1 10-bit RGB Packer"), |
64e4f483 |
.type = AVMEDIA_TYPE_VIDEO, |
7a72695c |
.id = AV_CODEC_ID_AVRP, |
64e4f483 |
.init = decode_init,
.decode = decode_frame, |
444e9874 |
.capabilities = AV_CODEC_CAP_DR1, |
91ed4e71 |
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, |
64e4f483 |
};
#endif |