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