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