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