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 = FF_I_TYPE;
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 = be2me_32(*src++);
00065 uint16_t r, g, b;
00066 b = pixel << 6;
00067 g = (pixel >> 4) & 0xffc0;
00068 r = (pixel >> 14) & 0xffc0;
00069 *dst++ = r | (r >> 10);
00070 *dst++ = g | (g >> 10);
00071 *dst++ = b | (b >> 10);
00072 }
00073 src += aligned_width - avctx->width;
00074 dst_line += pic->linesize[0];
00075 }
00076
00077 *data_size = sizeof(AVFrame);
00078 *(AVFrame*)data = *avctx->coded_frame;
00079
00080 return avpkt->size;
00081 }
00082
00083 static av_cold int decode_close(AVCodecContext *avctx)
00084 {
00085 AVFrame *pic = avctx->coded_frame;
00086 if (pic->data[0])
00087 avctx->release_buffer(avctx, pic);
00088 av_freep(&avctx->coded_frame);
00089
00090 return 0;
00091 }
00092
00093 AVCodec r210_decoder = {
00094 "r210",
00095 AVMEDIA_TYPE_VIDEO,
00096 CODEC_ID_R210,
00097 0,
00098 decode_init,
00099 NULL,
00100 decode_close,
00101 decode_frame,
00102 CODEC_CAP_DR1,
00103 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed RGB 10-bit"),
00104 };