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