]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/targa.c
doc/ffmpeg: s/avserver/ffserver/
[ffmpeg] / libavcodec / targa.c
index 41741ff9c58590757654b1bcc2cc9ad758bbff0e..884bae6cc948034bf75a19ae1bfe072896866dc5 100644 (file)
@@ -22,6 +22,7 @@
 #include "libavutil/intreadwrite.h"
 #include "libavutil/imgutils.h"
 #include "avcodec.h"
+#include "bytestream.h"
 #include "targa.h"
 
 typedef struct TargaContext {
@@ -108,21 +109,26 @@ static int decode_frame(AVCodecContext *avctx,
     AVFrame * const p= (AVFrame*)&s->picture;
     uint8_t *dst;
     int stride;
-    int idlen, compr, y, w, h, bpp, flags;
+    int idlen, pal, compr, y, w, h, bpp, flags;
     int first_clr, colors, csize;
 
     /* parse image header */
     CHECK_BUFFER_SIZE(buf, buf_end, 18, "header");
     idlen = *buf++;
-    buf++; /* pal */
+    pal = *buf++;
     compr = *buf++;
-    first_clr = AV_RL16(buf); buf += 2;
-    colors = AV_RL16(buf); buf += 2;
+    first_clr = bytestream_get_le16(&buf);
+    colors = bytestream_get_le16(&buf);
     csize = *buf++;
+    if (!pal && (first_clr || colors || csize)) {
+        av_log(avctx, AV_LOG_WARNING, "File without colormap has colormap information set.\n");
+        // specification says we should ignore those value in this case
+        first_clr = colors = csize = 0;
+    }
     buf += 2; /* x */
-    y = AV_RL16(buf); buf += 2;
-    w = AV_RL16(buf); buf += 2;
-    h = AV_RL16(buf); buf += 2;
+    y = bytestream_get_le16(&buf);
+    w = bytestream_get_le16(&buf);
+    h = bytestream_get_le16(&buf);
     bpp = *buf++;
     flags = *buf++;
     //skip identifier if any
@@ -186,13 +192,10 @@ static int decode_frame(AVCodecContext *avctx,
         if(avctx->pix_fmt != PIX_FMT_PAL8)//should not occur but skip palette anyway
             buf += pal_size;
         else{
-            int r, g, b, t;
+            int t;
             int32_t *pal = ((int32_t*)p->data[1]) + first_clr;
             for(t = 0; t < colors; t++){
-                b = *buf++;
-                g = *buf++;
-                r = *buf++;
-                *pal++ = (0xff<<24) | (r << 16) | (g << 8) | b;
+                *pal++ = (0xff<<24) | bytestream_get_le24(&buf);
             }
             p->palette_has_changed = 1;
         }
@@ -254,15 +257,13 @@ static av_cold int targa_end(AVCodecContext *avctx){
 }
 
 AVCodec ff_targa_decoder = {
-    "targa",
-    AVMEDIA_TYPE_VIDEO,
-    CODEC_ID_TARGA,
-    sizeof(TargaContext),
-    targa_init,
-    NULL,
-    targa_end,
-    decode_frame,
-    CODEC_CAP_DR1,
-    NULL,
+    .name           = "targa",
+    .type           = AVMEDIA_TYPE_VIDEO,
+    .id             = CODEC_ID_TARGA,
+    .priv_data_size = sizeof(TargaContext),
+    .init           = targa_init,
+    .close          = targa_end,
+    .decode         = decode_frame,
+    .capabilities   = CODEC_CAP_DR1,
     .long_name = NULL_IF_CONFIG_SMALL("Truevision Targa image"),
 };