changeset 4677:47237f2638b2 libavcodec

Move the encoding of the image data to its own function. patch by Bobby Bingham, uhmmmm gmail com
author diego
date Sat, 17 Mar 2007 13:16:18 +0000
parents 046456cf7d31
children ae5abc4dc946
files targaenc.c
diffstat 1 files changed, 19 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/targaenc.c	Sat Mar 17 12:56:34 2007 +0000
+++ b/targaenc.c	Sat Mar 17 13:16:18 2007 +0000
@@ -21,12 +21,27 @@
  */
 #include "avcodec.h"
 
+static int targa_encode_normal(uint8_t *outbuf, AVFrame *pic, int bpp, int w, int h)
+{
+    int i, n = bpp * w;
+    uint8_t *out = outbuf;
+    uint8_t *ptr = pic->data[0];
+
+    for(i=0; i < h; i++) {
+        memcpy(out, ptr, n);
+        out += n;
+        ptr += pic->linesize[0];
+    }
+
+    return out - outbuf;
+}
+
 static int targa_encode_frame(AVCodecContext *avctx,
                               unsigned char *outbuf,
                               int buf_size, void *data){
     AVFrame *p = data;
-    int i, n, linesize;
-    uint8_t *ptr, *out;
+    int bpp;
+    uint8_t *out;
 
     if(avctx->width > 0xffff || avctx->height > 0xffff) {
         av_log(avctx, AV_LOG_ERROR, "image dimensions too large\n");
@@ -51,31 +66,23 @@
     case PIX_FMT_GRAY8:
         outbuf[2] = 3;           /* uncompressed grayscale image */
         outbuf[16] = 8;          /* bpp */
-        n = avctx->width;
         break;
     case PIX_FMT_RGB555:
         outbuf[2] = 2;           /* uncompresses true-color image */
         outbuf[16] = 16;         /* bpp */
-        n = 2 * avctx->width;
         break;
     case PIX_FMT_BGR24:
         outbuf[2] = 2;           /* uncompressed true-color image */
         outbuf[16] = 24;         /* bpp */
-        n = 3 * avctx->width;
         break;
     default:
         return -1;
     }
+    bpp = outbuf[16] >> 3;
 
     out = outbuf + 18;  /* skip past the header we just output */
-    ptr = p->data[0];
-    linesize = p->linesize[0];
 
-    for(i=0; i < avctx->height; i++) {
-        memcpy(out, ptr, n);
-        out += n;
-        ptr += linesize;
-    }
+    out += targa_encode_normal(out, p, bpp, avctx->width, avctx->height);
 
     /* The standard recommends including this section, even if we don't use
      * any of the features it affords. TODO: take advantage of the pixel