[Ffmpeg-devel] [PATCH] Targa encoder

Michael Niedermayer michaelni
Sun Mar 11 22:21:23 CET 2007


Hi

On Mon, Mar 12, 2007 at 03:58:46AM +0900, Bobby Bingham wrote:
> Hi,
> 
> I saw the Summer of Code page on the multimedia wiki, and decided to 
> tackle the targa encoder, both because I'm interested in participating 
> in the Summer of Code this year, and because I thought it'd be a good 
> chance to start getting used to some of the API.
> 
> Right now it only handles 24-bit BGR and 8-bit grayscale.  It doesn't 
> implement RLE at the moment either, but I'm not sure about how effective 
> that'd be on most video anyway.
> 
> -- 
> Bobby Bingham
> ??????????????????????????????????????????????????????????????????

[...]
> Index: libavcodec/targa.c
> ===================================================================
> --- libavcodec/targa.c	(revision 8322)
> +++ libavcodec/targa.c	(working copy)
> @@ -221,6 +221,68 @@
>      return buf_size;
>  }
>  
> +static int encode_frame(AVCodecContext *avctx, unsigned char *outbuf, int buf_size, void *data){

please place the encoder into its own source file



> +    AVFrame *p = data;
> +    int i, n, linesize;
> +    uint8_t *ptr, *out;
> +
> +    if(avctx->width > 0xffff || avctx->height > 0xffff) {
> +        av_log(avctx, AV_LOG_ERROR, "image dimensions too large\n");
> +        return -1;
> +    }
> +    if(buf_size < avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height) + 45) {
> +        av_log(avctx, AV_LOG_ERROR, "encoded frame too large\n");
> +        return -1;
> +    }
> +
> +    p->pict_type= FF_I_TYPE;
> +    p->key_frame= 1;
> +
> +    /* zero out the header and only set applicable fields */
> +    memset(outbuf, 0, 18);

12..18 are writen too anyway so theres no sense in memseting them


> +    AV_WL16(outbuf+12, avctx->width);
> +    AV_WL16(outbuf+14, avctx->height);
> +    outbuf[17] = 0x20;           /* origin is top-left. no alpha */
> +
> +    /* TODO: support alpha channel and other bit-depths.  and RLE? */
> +    switch(avctx->pix_fmt) {
> +    case PIX_FMT_GRAY8:
> +        outbuf[2] = 3;           /* uncompressed grayscale image */
> +        outbuf[16] = 8;          /* bpp */

avctx->bits_per_sample

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

While the State exists there can be no freedom; when there is freedom there
will be no State. -- Vladimir Lenin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070311/73417d44/attachment.pgp>



More information about the ffmpeg-devel mailing list