[vlc-commits] commit: Added targa support to image demuxer. (Laurent Aimar )

git at videolan.org git at videolan.org
Sat Oct 30 21:06:28 CEST 2010


vlc | branch: master | Laurent Aimar <fenrir at videolan.org> | Sat Oct 30 21:01:42 2010 +0200| [fee9386c0e666b9b1d4c5554af3d0efcf0bd5301] | committer: Laurent Aimar 

Added targa support to image demuxer.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=fee9386c0e666b9b1d4c5554af3d0efcf0bd5301
---

 modules/demux/image.c |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 48 insertions(+), 0 deletions(-)

diff --git a/modules/demux/image.c b/modules/demux/image.c
index eb0af9a..f5280f9 100644
--- a/modules/demux/image.c
+++ b/modules/demux/image.c
@@ -404,6 +404,51 @@ static bool IsSpiff(stream_t *s)
     return true;
 }
 
+static bool IsTarga(stream_t *s)
+{
+    /* The header is not enough to ensure proper detection, we need
+     * to have a look at the footer. But doing so can be slow. So
+     * try to avoid it when possible */
+    const uint8_t *header;
+    if (stream_Peek(s, &header, 18) < 18)   /* Targa fixed header */
+        return false;
+    if (header[1] > 1)                      /* Color Map Type */
+        return false;
+    if ((header[1] != 0 || header[3 + 4] != 0) &&
+        header[3 + 4] != 8  &&
+        header[3 + 4] != 15 && header[3 + 4] != 16 &&
+        header[3 + 4] != 24 && header[3 + 4] != 32)
+        return false;
+    if ((header[2] > 3 && header[2] < 9) || header[2] > 11) /* Image Type */
+        return false;
+    if (GetWLE(&header[8 + 4]) <= 0 ||      /* Width */
+        GetWLE(&header[8 + 6]) <= 0)        /* Height */
+        return false;
+    if (header[8 + 8] != 8  &&
+        header[8 + 8] != 15 && header[8 + 8] != 16 &&
+        header[8 + 8] != 24 && header[8 + 8] != 32)
+        return false;
+    if (header[8 + 9] & 0xc0)               /* Reserved bits */
+        return false;
+
+    const int64_t size = stream_Size(s);
+    if (size <= 18 + 26)
+        return false;
+    bool can_seek;
+    if (stream_Control(s, STREAM_CAN_SEEK, &can_seek) || !can_seek)
+        return false;
+
+    const int64_t position = stream_Tell(s);
+    if (stream_Seek(s, size - 26))
+        return false;
+
+    const uint8_t *footer;
+    bool is_targa = stream_Peek(s, &footer, 26) >= 26 &&
+                    !memcmp(&footer[8], "TRUEVISION-XFILE.\x00", 18);
+    stream_Seek(s, position);
+    return is_targa;
+}
+
 typedef struct {
     vlc_fourcc_t  codec;
     int           marker_size;
@@ -468,6 +513,9 @@ static const image_format_t formats[] = {
     { .codec = VLC_CODEC_JPEG,
       .detect = IsSpiff,
     },
+    { .codec = VLC_CODEC_TARGA,
+      .detect = IsTarga,
+    },
     { .codec = 0 }
 };
 



More information about the vlc-commits mailing list