Libav 0.7.1
|
00001 /* 00002 * R210 decoder 00003 * 00004 * Copyright (c) 2009 Reimar Doeffinger <Reimar.Doeffinger@gmx.de> 00005 * 00006 * This file is part of Libav. 00007 * 00008 * Libav is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Lesser General Public 00010 * License as published by the Free Software Foundation; either 00011 * version 2.1 of the License, or (at your option) any later version. 00012 * 00013 * Libav is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with Libav; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 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 = av_be2ne32(*src++); 00065 uint16_t r, g, b; 00066 if (avctx->codec_id==CODEC_ID_R210) { 00067 b = pixel << 6; 00068 g = (pixel >> 4) & 0xffc0; 00069 r = (pixel >> 14) & 0xffc0; 00070 } else { 00071 b = pixel << 4; 00072 g = (pixel >> 6) & 0xffc0; 00073 r = (pixel >> 16) & 0xffc0; 00074 } 00075 *dst++ = r | (r >> 10); 00076 *dst++ = g | (g >> 10); 00077 *dst++ = b | (b >> 10); 00078 } 00079 src += aligned_width - avctx->width; 00080 dst_line += pic->linesize[0]; 00081 } 00082 00083 *data_size = sizeof(AVFrame); 00084 *(AVFrame*)data = *avctx->coded_frame; 00085 00086 return avpkt->size; 00087 } 00088 00089 static av_cold int decode_close(AVCodecContext *avctx) 00090 { 00091 AVFrame *pic = avctx->coded_frame; 00092 if (pic->data[0]) 00093 avctx->release_buffer(avctx, pic); 00094 av_freep(&avctx->coded_frame); 00095 00096 return 0; 00097 } 00098 00099 #if CONFIG_R210_DECODER 00100 AVCodec ff_r210_decoder = { 00101 "r210", 00102 AVMEDIA_TYPE_VIDEO, 00103 CODEC_ID_R210, 00104 0, 00105 decode_init, 00106 NULL, 00107 decode_close, 00108 decode_frame, 00109 CODEC_CAP_DR1, 00110 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed RGB 10-bit"), 00111 }; 00112 #endif 00113 #if CONFIG_R10K_DECODER 00114 AVCodec ff_r10k_decoder = { 00115 "r10k", 00116 AVMEDIA_TYPE_VIDEO, 00117 CODEC_ID_R10K, 00118 0, 00119 decode_init, 00120 NULL, 00121 decode_close, 00122 decode_frame, 00123 CODEC_CAP_DR1, 00124 .long_name = NULL_IF_CONFIG_SMALL("AJA Kona 10-bit RGB Codec"), 00125 }; 00126 #endif