Commit fee9386c authored by Laurent Aimar's avatar Laurent Aimar

Added targa support to image demuxer.

parent b7505eeb
......@@ -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 }
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment