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 "internal.h"
00025
00026 static av_cold int y41p_decode_init(AVCodecContext *avctx)
00027 {
00028 avctx->pix_fmt = AV_PIX_FMT_YUV411P;
00029 avctx->bits_per_raw_sample = 12;
00030
00031 if (avctx->width & 7) {
00032 av_log(avctx, AV_LOG_WARNING, "y41p requires width to be divisible by 8.\n");
00033 }
00034
00035 avctx->coded_frame = avcodec_alloc_frame();
00036 if (!avctx->coded_frame) {
00037 av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n");
00038 return AVERROR(ENOMEM);
00039 }
00040
00041 return 0;
00042 }
00043
00044 static int y41p_decode_frame(AVCodecContext *avctx, void *data,
00045 int *got_frame, AVPacket *avpkt)
00046 {
00047 AVFrame *pic = avctx->coded_frame;
00048 uint8_t *src = avpkt->data;
00049 uint8_t *y, *u, *v;
00050 int i, j;
00051
00052 if (pic->data[0])
00053 avctx->release_buffer(avctx, pic);
00054
00055 if (avpkt->size < 1.5 * avctx->height * avctx->width) {
00056 av_log(avctx, AV_LOG_ERROR, "Insufficient input data.\n");
00057 return AVERROR(EINVAL);
00058 }
00059
00060 pic->reference = 0;
00061
00062 if (ff_get_buffer(avctx, pic) < 0) {
00063 av_log(avctx, AV_LOG_ERROR, "Could not allocate buffer.\n");
00064 return AVERROR(ENOMEM);
00065 }
00066
00067 pic->key_frame = 1;
00068 pic->pict_type = AV_PICTURE_TYPE_I;
00069
00070 for (i = avctx->height - 1; i >= 0 ; i--) {
00071 y = &pic->data[0][i * pic->linesize[0]];
00072 u = &pic->data[1][i * pic->linesize[1]];
00073 v = &pic->data[2][i * pic->linesize[2]];
00074 for (j = 0; j < avctx->width; j += 8) {
00075 *(u++) = *src++;
00076 *(y++) = *src++;
00077 *(v++) = *src++;
00078 *(y++) = *src++;
00079
00080 *(u++) = *src++;
00081 *(y++) = *src++;
00082 *(v++) = *src++;
00083 *(y++) = *src++;
00084
00085 *(y++) = *src++;
00086 *(y++) = *src++;
00087 *(y++) = *src++;
00088 *(y++) = *src++;
00089 }
00090 }
00091
00092 *got_frame = 1;
00093 *(AVFrame *)data = *pic;
00094
00095 return avpkt->size;
00096 }
00097
00098 static av_cold int y41p_decode_close(AVCodecContext *avctx)
00099 {
00100 if (avctx->coded_frame->data[0])
00101 avctx->release_buffer(avctx, avctx->coded_frame);
00102
00103 av_freep(&avctx->coded_frame);
00104
00105 return 0;
00106 }
00107
00108 AVCodec ff_y41p_decoder = {
00109 .name = "y41p",
00110 .type = AVMEDIA_TYPE_VIDEO,
00111 .id = AV_CODEC_ID_Y41P,
00112 .init = y41p_decode_init,
00113 .decode = y41p_decode_frame,
00114 .close = y41p_decode_close,
00115 .capabilities = CODEC_CAP_DR1,
00116 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed YUV 4:1:1 12-bit"),
00117 };