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 v408_decode_init(AVCodecContext *avctx)
00026 {
00027 avctx->pix_fmt = AV_PIX_FMT_YUVA444P;
00028
00029 avctx->coded_frame = avcodec_alloc_frame();
00030
00031 if (!avctx->coded_frame) {
00032 av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n");
00033 return AVERROR(ENOMEM);
00034 }
00035
00036 return 0;
00037 }
00038
00039 static int v408_decode_frame(AVCodecContext *avctx, void *data,
00040 int *got_frame, AVPacket *avpkt)
00041 {
00042 AVFrame *pic = avctx->coded_frame;
00043 const uint8_t *src = avpkt->data;
00044 uint8_t *y, *u, *v, *a;
00045 int i, j;
00046
00047 if (pic->data[0])
00048 avctx->release_buffer(avctx, pic);
00049
00050 if (avpkt->size < 4 * avctx->height * avctx->width) {
00051 av_log(avctx, AV_LOG_ERROR, "Insufficient input data.\n");
00052 return AVERROR(EINVAL);
00053 }
00054
00055 pic->reference = 0;
00056
00057 if (ff_get_buffer(avctx, pic) < 0) {
00058 av_log(avctx, AV_LOG_ERROR, "Could not allocate buffer.\n");
00059 return AVERROR(ENOMEM);
00060 }
00061
00062 pic->key_frame = 1;
00063 pic->pict_type = AV_PICTURE_TYPE_I;
00064
00065 y = pic->data[0];
00066 u = pic->data[1];
00067 v = pic->data[2];
00068 a = pic->data[3];
00069
00070 for (i = 0; i < avctx->height; i++) {
00071 for (j = 0; j < avctx->width; j++) {
00072 if (avctx->codec_id==AV_CODEC_ID_AYUV) {
00073 v[j] = *src++;
00074 u[j] = *src++;
00075 y[j] = *src++;
00076 a[j] = *src++;
00077 } else {
00078 u[j] = *src++;
00079 y[j] = *src++;
00080 v[j] = *src++;
00081 a[j] = *src++;
00082 }
00083 }
00084
00085 y += pic->linesize[0];
00086 u += pic->linesize[1];
00087 v += pic->linesize[2];
00088 a += pic->linesize[3];
00089 }
00090
00091 *got_frame = 1;
00092 *(AVFrame *)data = *pic;
00093
00094 return avpkt->size;
00095 }
00096
00097 static av_cold int v408_decode_close(AVCodecContext *avctx)
00098 {
00099 if (avctx->coded_frame->data[0])
00100 avctx->release_buffer(avctx, avctx->coded_frame);
00101
00102 av_freep(&avctx->coded_frame);
00103
00104 return 0;
00105 }
00106
00107 #if CONFIG_AYUV_DECODER
00108 AVCodec ff_ayuv_decoder = {
00109 .name = "ayuv",
00110 .type = AVMEDIA_TYPE_VIDEO,
00111 .id = AV_CODEC_ID_AYUV,
00112 .init = v408_decode_init,
00113 .decode = v408_decode_frame,
00114 .close = v408_decode_close,
00115 .capabilities = CODEC_CAP_DR1,
00116 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed packed MS 4:4:4:4"),
00117 };
00118 #endif
00119 #if CONFIG_V408_DECODER
00120 AVCodec ff_v408_decoder = {
00121 .name = "v408",
00122 .type = AVMEDIA_TYPE_VIDEO,
00123 .id = AV_CODEC_ID_V408,
00124 .init = v408_decode_init,
00125 .decode = v408_decode_frame,
00126 .close = v408_decode_close,
00127 .capabilities = CODEC_CAP_DR1,
00128 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed packed QT 4:4:4:4"),
00129 };
00130 #endif