diff options
author | Christoph M. Becker <cmbecker69@gmx.de> | 2016-07-12 19:23:13 +0200 |
---|---|---|
committer | Christoph M. Becker <cmbecker69@gmx.de> | 2016-07-13 00:43:10 +0200 |
commit | cb1a0b7e54e9aa118270c23a4a6fe560e4590dc9 (patch) | |
tree | c6bdd47d50a7d4240373409cd458cdd137d6bae6 /src/gd_tga.c | |
parent | 076e0d19d79e8d9a0112eef9eb727187907eac6f (diff) | |
download | libgd-cb1a0b7e54e9aa118270c23a4a6fe560e4590dc9.tar.gz |
Unsupported TGA bpp/alphabit combinations should error gracefully
Currently, only 24bpp without alphabits and 32bpp with 8 alphabits are
really supported. All other combinations will be rejected with a warning.
Diffstat (limited to 'src/gd_tga.c')
-rw-r--r-- | src/gd_tga.c | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/src/gd_tga.c b/src/gd_tga.c index 20fe2d2..b4f8fa6 100644 --- a/src/gd_tga.c +++ b/src/gd_tga.c @@ -99,7 +99,7 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromTgaCtx(gdIOCtx* ctx) if (tga->bits == TGA_BPP_24) { *tpix = gdTrueColor(tga->bitmap[bitmap_caret + 2], tga->bitmap[bitmap_caret + 1], tga->bitmap[bitmap_caret]); bitmap_caret += 3; - } else if (tga->bits == TGA_BPP_32 || tga->alphabits) { + } else if (tga->bits == TGA_BPP_32 && tga->alphabits) { register int a = tga->bitmap[bitmap_caret + 3]; *tpix = gdTrueColorAlpha(tga->bitmap[bitmap_caret + 2], tga->bitmap[bitmap_caret + 1], tga->bitmap[bitmap_caret], gdAlphaMax - (a >> 1)); @@ -159,16 +159,12 @@ int read_header_tga(gdIOCtx *ctx, oTga *tga) printf("wxh: %i %i\n", tga->width, tga->height); #endif - switch(tga->bits) { - case 8: - case 16: - case 24: - case 32: - break; - default: - gd_error("bps %i not supported", tga->bits); + if (!((tga->bits == TGA_BPP_24 && tga->alphabits == 0) + || (tga->bits == TGA_BPP_32 && tga->alphabits == 8))) + { + gd_error_ex(GD_WARNING, "gd-tga: %u bits per pixel with %u alpha bits not supported\n", + tga->bits, tga->alphabits); return -1; - break; } tga->ident = NULL; |