00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "avcodec.h"
00023 #include "internal.h"
00024
00025 static av_cold int y216_decode_init(AVCodecContext *avctx)
00026 {
00027 avctx->pix_fmt = AV_PIX_FMT_YUV422P16;
00028 avctx->bits_per_raw_sample = 14;
00029
00030 avctx->coded_frame = avcodec_alloc_frame();
00031
00032 if (!avctx->coded_frame) {
00033 av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n");
00034 return AVERROR(ENOMEM);
00035 }
00036
00037 return 0;
00038 }
00039
00040 static int y216_decode_frame(AVCodecContext *avctx, void *data,
00041 int *got_frame, AVPacket *avpkt)
00042 {
00043 AVFrame *pic = avctx->coded_frame;
00044 const uint16_t *src = (uint16_t *)avpkt->data;
00045 uint16_t *y, *u, *v, aligned_width = FFALIGN(avctx->width, 4);
00046 int i, j;
00047
00048 if (pic->data[0])
00049 avctx->release_buffer(avctx, pic);
00050
00051 if (avpkt->size < 4 * avctx->height * aligned_width) {
00052 av_log(avctx, AV_LOG_ERROR, "Insufficient input data.\n");
00053 return AVERROR(EINVAL);
00054 }
00055
00056 pic->reference = 0;
00057
00058 if (ff_get_buffer(avctx, pic) < 0) {
00059 av_log(avctx, AV_LOG_ERROR, "Could not allocate buffer.\n");
00060 return AVERROR(ENOMEM);
00061 }
00062
00063 pic->key_frame = 1;
00064 pic->pict_type = AV_PICTURE_TYPE_I;
00065
00066 y = (uint16_t *)pic->data[0];
00067 u = (uint16_t *)pic->data[1];
00068 v = (uint16_t *)pic->data[2];
00069
00070 for (i = 0; i < avctx->height; i++) {
00071 for (j = 0; j < avctx->width >> 1; j++) {
00072 u[ j ] = src[4 * j ] << 2 | src[4 * j ] >> 14;
00073 y[2 * j ] = src[4 * j + 1] << 2 | src[4 * j + 1] >> 14;
00074 v[ j ] = src[4 * j + 2] << 2 | src[4 * j + 2] >> 14;
00075 y[2 * j + 1] = src[4 * j + 3] << 2 | src[4 * j + 3] >> 14;
00076 }
00077
00078 y += pic->linesize[0] >> 1;
00079 u += pic->linesize[1] >> 1;
00080 v += pic->linesize[2] >> 1;
00081 src += aligned_width << 1;
00082 }
00083
00084 *got_frame = 1;
00085 *(AVFrame *)data = *pic;
00086
00087 return avpkt->size;
00088 }
00089
00090 static av_cold int y216_decode_close(AVCodecContext *avctx)
00091 {
00092 if (avctx->coded_frame->data[0])
00093 avctx->release_buffer(avctx, avctx->coded_frame);
00094
00095 av_freep(&avctx->coded_frame);
00096
00097 return 0;
00098 }
00099
00100 AVCodec ff_targa_y216_decoder = {
00101 .name = "targa_y216",
00102 .type = AVMEDIA_TYPE_VIDEO,
00103 .id = AV_CODEC_ID_TARGA_Y216,
00104 .init = y216_decode_init,
00105 .decode = y216_decode_frame,
00106 .close = y216_decode_close,
00107 .capabilities = CODEC_CAP_DR1,
00108 .long_name = NULL_IF_CONFIG_SMALL("Pinnacle TARGA CineWave YUV16"),
00109 };