00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "libavutil/intreadwrite.h"
00024 #include "avcodec.h"
00025 #include "internal.h"
00026
00027 static av_cold int v408_encode_init(AVCodecContext *avctx)
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_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
00040 const AVFrame *pic, int *got_packet)
00041 {
00042 uint8_t *dst;
00043 uint8_t *y, *u, *v, *a;
00044 int i, j, ret;
00045
00046 if ((ret = ff_alloc_packet2(avctx, pkt, avctx->width * avctx->height * 4)) < 0)
00047 return ret;
00048 dst = pkt->data;
00049
00050 avctx->coded_frame->reference = 0;
00051 avctx->coded_frame->key_frame = 1;
00052 avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
00053
00054 y = pic->data[0];
00055 u = pic->data[1];
00056 v = pic->data[2];
00057 a = pic->data[3];
00058
00059 for (i = 0; i < avctx->height; i++) {
00060 for (j = 0; j < avctx->width; j++) {
00061 if (avctx->codec_id==CODEC_ID_AYUV) {
00062 *dst++ = v[j];
00063 *dst++ = u[j];
00064 *dst++ = y[j];
00065 *dst++ = a[j];
00066 } else {
00067 *dst++ = u[j];
00068 *dst++ = y[j];
00069 *dst++ = v[j];
00070 *dst++ = a[j];
00071 }
00072 }
00073 y += pic->linesize[0];
00074 u += pic->linesize[1];
00075 v += pic->linesize[2];
00076 a += pic->linesize[3];
00077 }
00078
00079 pkt->flags |= AV_PKT_FLAG_KEY;
00080 *got_packet = 1;
00081 return 0;
00082 }
00083
00084 static av_cold int v408_encode_close(AVCodecContext *avctx)
00085 {
00086 av_freep(&avctx->coded_frame);
00087
00088 return 0;
00089 }
00090
00091 #if CONFIG_AYUV_ENCODER
00092 AVCodec ff_ayuv_encoder = {
00093 .name = "ayuv",
00094 .type = AVMEDIA_TYPE_VIDEO,
00095 .id = CODEC_ID_AYUV,
00096 .init = v408_encode_init,
00097 .encode2 = v408_encode_frame,
00098 .close = v408_encode_close,
00099 .pix_fmts = (const enum PixelFormat[]){ PIX_FMT_YUVA444P, PIX_FMT_NONE },
00100 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed packed MS 4:4:4:4"),
00101 };
00102 #endif
00103 #if CONFIG_V408_ENCODER
00104 AVCodec ff_v408_encoder = {
00105 .name = "v408",
00106 .type = AVMEDIA_TYPE_VIDEO,
00107 .id = CODEC_ID_V408,
00108 .init = v408_encode_init,
00109 .encode2 = v408_encode_frame,
00110 .close = v408_encode_close,
00111 .pix_fmts = (const enum PixelFormat[]){ PIX_FMT_YUVA444P, PIX_FMT_NONE },
00112 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed packed QT 4:4:4:4"),
00113 };
00114 #endif