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 yuv4_decode_init(AVCodecContext *avctx)
00027 {
00028 avctx->pix_fmt = AV_PIX_FMT_YUV420P;
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 yuv4_decode_frame(AVCodecContext *avctx, void *data,
00041 int *got_frame, AVPacket *avpkt)
00042 {
00043 AVFrame *pic = avctx->coded_frame;
00044 const uint8_t *src = avpkt->data;
00045 uint8_t *y, *u, *v;
00046 int i, j;
00047
00048 if (pic->data[0])
00049 avctx->release_buffer(avctx, pic);
00050
00051 if (avpkt->size < 6 * (avctx->width + 1 >> 1) * (avctx->height + 1 >> 1)) {
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 = pic->data[0];
00067 u = pic->data[1];
00068 v = pic->data[2];
00069
00070 for (i = 0; i < (avctx->height + 1) >> 1; i++) {
00071 for (j = 0; j < (avctx->width + 1) >> 1; j++) {
00072 u[j] = *src++ ^ 0x80;
00073 v[j] = *src++ ^ 0x80;
00074 y[ 2 * j ] = *src++;
00075 y[ 2 * j + 1] = *src++;
00076 y[pic->linesize[0] + 2 * j ] = *src++;
00077 y[pic->linesize[0] + 2 * j + 1] = *src++;
00078 }
00079
00080 y += 2 * pic->linesize[0];
00081 u += pic->linesize[1];
00082 v += pic->linesize[2];
00083 }
00084
00085 *got_frame = 1;
00086 *(AVFrame *)data = *pic;
00087
00088 return avpkt->size;
00089 }
00090
00091 static av_cold int yuv4_decode_close(AVCodecContext *avctx)
00092 {
00093 if (avctx->coded_frame->data[0])
00094 avctx->release_buffer(avctx, avctx->coded_frame);
00095
00096 av_freep(&avctx->coded_frame);
00097
00098 return 0;
00099 }
00100
00101 AVCodec ff_yuv4_decoder = {
00102 .name = "yuv4",
00103 .type = AVMEDIA_TYPE_VIDEO,
00104 .id = AV_CODEC_ID_YUV4,
00105 .init = yuv4_decode_init,
00106 .decode = yuv4_decode_frame,
00107 .close = yuv4_decode_close,
00108 .capabilities = CODEC_CAP_DR1,
00109 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed packed 4:2:0"),
00110 };