From de5fdbc0101e5f8f327868da7735b5726f1657c9 Mon Sep 17 00:00:00 2001 From: ftrvxmtrx Date: Mon, 21 Jan 2013 01:05:00 +0100 Subject: file: detect tga images --- sys/src/cmd/file.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'sys/src/cmd/file.c') diff --git a/sys/src/cmd/file.c b/sys/src/cmd/file.c index cbc2227d8..dd0c69737 100644 --- a/sys/src/cmd/file.c +++ b/sys/src/cmd/file.c @@ -150,6 +150,7 @@ int ishtml(void); int isrfc822(void); int ismbox(void); int islimbo(void); +int istga(void); int ismp3(void); int ismung(void); int isp9bit(void); @@ -196,6 +197,7 @@ int (*call[])(void) = ismsdos, /* msdos exe (virus file attachement) */ isicocur, /* windows icon or cursor file */ isface, /* ascii face file */ + istga, ismp3, /* last resorts */ @@ -1197,6 +1199,26 @@ isas(void) return 1; } +int +istga(void) +{ + uchar *p; + + p = buf; + if(nbuf < 14) + return 0; + if(((p[2]|(1<<3)) & (~3)) != (1<<3)) /* rle flag */ + return 0; + if(p[1] == 0 && ((p[2]&3) != 2 && (p[2]&3) != 3)) /* non color-mapped */ + return 0; + if(p[1] == 1 && ((p[2]&3) != 1 || p[7] == 0)) /* color-mapped */ + return 0; + if(p[16] != 8 && p[16] != 16 && p[16] != 24 && p[16] != 32) /* bpp */ + return 0; + print("%s\n", mime ? "image/tga" : "targa image"); + return 1; +} + int ismp3(void) { -- cgit v1.2.3