• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavcodec/y41penc.c

Go to the documentation of this file.
00001 /*
00002  * y41p encoder
00003  *
00004  * Copyright (c) 2012 Paul B Mahol
00005  *
00006  * This file is part of FFmpeg.
00007  *
00008  * FFmpeg is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * FFmpeg is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with FFmpeg; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00021  */
00022 
00023 #include "avcodec.h"
00024 
00025 static av_cold int y41p_encode_init(AVCodecContext *avctx)
00026 {
00027     if (avctx->width & 7) {
00028         av_log(avctx, AV_LOG_ERROR, "y41p requires width to be divisible by 8.\n");
00029         return AVERROR_INVALIDDATA;
00030     }
00031 
00032     avctx->coded_frame = avcodec_alloc_frame();
00033     avctx->bits_per_coded_sample = 12;
00034 
00035     if (!avctx->coded_frame) {
00036         av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n");
00037         return AVERROR(ENOMEM);
00038     }
00039 
00040     return 0;
00041 }
00042 
00043 static int y41p_encode_frame(AVCodecContext *avctx, uint8_t *buf,
00044                              int buf_size, void *data)
00045 {
00046     AVFrame *pic = data;
00047     uint8_t *dst = buf;
00048     uint8_t *y, *u, *v;
00049     int i, j;
00050 
00051     if (buf_size < avctx->width * avctx->height * 1.5) {
00052         av_log(avctx, AV_LOG_ERROR, "Out buffer is too small.\n");
00053         return AVERROR(ENOMEM);
00054     }
00055 
00056     avctx->coded_frame->reference = 0;
00057     avctx->coded_frame->key_frame = 1;
00058     avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
00059 
00060     for (i = avctx->height - 1; i >= 0; i--) {
00061         y = &pic->data[0][i * pic->linesize[0]];
00062         u = &pic->data[1][i * pic->linesize[1]];
00063         v = &pic->data[2][i * pic->linesize[2]];
00064         for (j = 0; j < avctx->width; j += 8) {
00065             *(dst++) = *(u++);
00066             *(dst++) = *(y++);
00067             *(dst++) = *(v++);
00068             *(dst++) = *(y++);
00069 
00070             *(dst++) = *(u++);
00071             *(dst++) = *(y++);
00072             *(dst++) = *(v++);
00073             *(dst++) = *(y++);
00074 
00075             *(dst++) = *(y++);
00076             *(dst++) = *(y++);
00077             *(dst++) = *(y++);
00078             *(dst++) = *(y++);
00079         }
00080     }
00081 
00082     return avctx->width * avctx->height * 1.5;
00083 }
00084 
00085 static av_cold int y41p_encode_close(AVCodecContext *avctx)
00086 {
00087     av_freep(&avctx->coded_frame);
00088 
00089     return 0;
00090 }
00091 
00092 AVCodec ff_y41p_encoder = {
00093     .name         = "y41p",
00094     .type         = AVMEDIA_TYPE_VIDEO,
00095     .id           = CODEC_ID_Y41P,
00096     .init         = y41p_encode_init,
00097     .encode       = y41p_encode_frame,
00098     .close        = y41p_encode_close,
00099     .pix_fmts     = (const enum PixelFormat[]) { PIX_FMT_YUV411P,
00100                                                  PIX_FMT_NONE },
00101     .long_name    = NULL_IF_CONFIG_SMALL("Uncompressed YUV 4:1:1 12-bit"),
00102 };
Generated on Fri Feb 1 2013 14:34:47 for FFmpeg by doxygen 1.7.1