00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "avcodec.h"
00024 #include "libavutil/bswap.h"
00025
00026 static av_cold int decode_init(AVCodecContext *avctx)
00027 {
00028 avctx->pix_fmt = PIX_FMT_RGB48;
00029 avctx->bits_per_raw_sample = 10;
00030
00031 avctx->coded_frame = avcodec_alloc_frame();
00032 if (!avctx->coded_frame)
00033 return AVERROR(ENOMEM);
00034
00035 return 0;
00036 }
00037
00038 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
00039 AVPacket *avpkt)
00040 {
00041 int h, w;
00042 AVFrame *pic = avctx->coded_frame;
00043 const uint32_t *src = (const uint32_t *)avpkt->data;
00044 int aligned_width = FFALIGN(avctx->width,
00045 avctx->codec_id == CODEC_ID_R10K ? 1 : 64);
00046 uint8_t *dst_line;
00047
00048 if (pic->data[0])
00049 avctx->release_buffer(avctx, pic);
00050
00051 if (avpkt->size < 4 * aligned_width * avctx->height) {
00052 av_log(avctx, AV_LOG_ERROR, "packet too small\n");
00053 return -1;
00054 }
00055
00056 pic->reference = 0;
00057 if (avctx->get_buffer(avctx, pic) < 0)
00058 return -1;
00059
00060 pic->pict_type = AV_PICTURE_TYPE_I;
00061 pic->key_frame = 1;
00062 dst_line = pic->data[0];
00063
00064 for (h = 0; h < avctx->height; h++) {
00065 uint16_t *dst = (uint16_t *)dst_line;
00066 for (w = 0; w < avctx->width; w++) {
00067 uint32_t pixel;
00068 uint16_t r, g, b;
00069 if (avctx->codec_id==CODEC_ID_AVRP) {
00070 pixel = av_le2ne32(*src++);
00071 } else {
00072 pixel = av_be2ne32(*src++);
00073 }
00074 if (avctx->codec_id==CODEC_ID_R210) {
00075 b = pixel << 6;
00076 g = (pixel >> 4) & 0xffc0;
00077 r = (pixel >> 14) & 0xffc0;
00078 } else {
00079 b = pixel << 4;
00080 g = (pixel >> 6) & 0xffc0;
00081 r = (pixel >> 16) & 0xffc0;
00082 }
00083 *dst++ = r | (r >> 10);
00084 *dst++ = g | (g >> 10);
00085 *dst++ = b | (b >> 10);
00086 }
00087 src += aligned_width - avctx->width;
00088 dst_line += pic->linesize[0];
00089 }
00090
00091 *data_size = sizeof(AVFrame);
00092 *(AVFrame*)data = *avctx->coded_frame;
00093
00094 return avpkt->size;
00095 }
00096
00097 static av_cold int decode_close(AVCodecContext *avctx)
00098 {
00099 AVFrame *pic = avctx->coded_frame;
00100 if (pic->data[0])
00101 avctx->release_buffer(avctx, pic);
00102 av_freep(&avctx->coded_frame);
00103
00104 return 0;
00105 }
00106
00107 #if CONFIG_R210_DECODER
00108 AVCodec ff_r210_decoder = {
00109 .name = "r210",
00110 .type = AVMEDIA_TYPE_VIDEO,
00111 .id = CODEC_ID_R210,
00112 .init = decode_init,
00113 .close = decode_close,
00114 .decode = decode_frame,
00115 .capabilities = CODEC_CAP_DR1,
00116 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed RGB 10-bit"),
00117 };
00118 #endif
00119 #if CONFIG_R10K_DECODER
00120 AVCodec ff_r10k_decoder = {
00121 .name = "r10k",
00122 .type = AVMEDIA_TYPE_VIDEO,
00123 .id = CODEC_ID_R10K,
00124 .init = decode_init,
00125 .close = decode_close,
00126 .decode = decode_frame,
00127 .capabilities = CODEC_CAP_DR1,
00128 .long_name = NULL_IF_CONFIG_SMALL("AJA Kona 10-bit RGB Codec"),
00129 };
00130 #endif
00131 #if CONFIG_AVRP_DECODER
00132 AVCodec ff_avrp_decoder = {
00133 .name = "avrp",
00134 .type = AVMEDIA_TYPE_VIDEO,
00135 .id = CODEC_ID_AVRP,
00136 .init = decode_init,
00137 .close = decode_close,
00138 .decode = decode_frame,
00139 .capabilities = CODEC_CAP_DR1,
00140 .long_name = NULL_IF_CONFIG_SMALL("Avid 1:1 10-bit RGB Packer"),
00141 };
00142 #endif