diff options
author | Kim Woelders <kim@woelders.dk> | 2019-11-16 08:57:05 +0100 |
---|---|---|
committer | Kim Woelders <kim@woelders.dk> | 2019-11-16 12:18:33 +0100 |
commit | 9cdd1bc007d777dff6de5d94fb0e6bdcd78046c8 (patch) | |
tree | 5ba843b1a0f68750ce9ac34d27438f2d365e08b0 | |
parent | f01353d1554bda8f331266df3baab3c361cea95f (diff) | |
download | imlib2-9cdd1bc007d777dff6de5d94fb0e6bdcd78046c8.tar.gz |
TGA loader: More mostly cosmetic changes
-rw-r--r-- | src/modules/loaders/loader_tga.c | 60 |
1 files changed, 31 insertions, 29 deletions
diff --git a/src/modules/loaders/loader_tga.c b/src/modules/loaders/loader_tga.c index ce724dd..7516e5b 100644 --- a/src/modules/loaders/loader_tga.c +++ b/src/modules/loaders/loader_tga.c @@ -185,17 +185,14 @@ load(ImlibImage * im, ImlibProgressFunction progress, int fd, rc; void *seg, *filedata; struct stat ss; - int bpp, vinverted = 0; - int rle = 0, footer_present = 0; - tga_header *header; tga_footer *footer; - + int footer_present; + int rle, bpp, hasa, vinverted; unsigned long datasize; unsigned char *bufptr, *bufend, *palette = 0; DATA32 *dataptr; - - int y, palcnt = 0, palbpp = 0; + int palcnt = 0, palbpp = 0; unsigned char a, r, g, b; fd = open(im->real_file, O_RDONLY); @@ -221,12 +218,8 @@ load(ImlibImage * im, ImlibProgressFunction progress, footer = (tga_footer *) ((char *)filedata + ss.st_size - sizeof(tga_footer)); /* check the footer to see if we have a v2.0 TGA file */ - if (memcmp(footer->signature, TGA_SIGNATURE, sizeof(footer->signature)) == 0) - footer_present = 1; - - if (!footer_present) - { - } + footer_present = + memcmp(footer->signature, TGA_SIGNATURE, sizeof(footer->signature)) == 0; if ((size_t)ss.st_size < sizeof(tga_header) + header->idLength + (footer_present ? sizeof(tga_footer) : 0)) @@ -244,30 +237,42 @@ load(ImlibImage * im, ImlibProgressFunction progress, /* this flag indicated bottom-up pixel storage */ vinverted = !(header->descriptor & TGA_DESC_VERTICAL); + rle = 0; /* RLE compressed */ + switch (header->imageType) { + default: + goto quit; + + case TGA_TYPE_MAPPED: + case TGA_TYPE_COLOR: + case TGA_TYPE_GRAY: + break; + case TGA_TYPE_MAPPED_RLE: case TGA_TYPE_COLOR_RLE: case TGA_TYPE_GRAY_RLE: rle = 1; break; + } - case TGA_TYPE_MAPPED: - case TGA_TYPE_COLOR: - case TGA_TYPE_GRAY: - rle = 0; - break; + bpp = header->bpp; /* Bits per pixel */ + hasa = 0; /* Has alpha */ + switch (bpp) + { default: goto quit; + case 32: + if (header->descriptor & TGA_DESC_ABITS) + hasa = 1; + break; + case 24: + break; + case 8: + break; } - /* bits per pixel */ - bpp = header->bpp; - - if (!((bpp == 32) || (bpp == 24) || (bpp == 8))) - goto quit; - /* endian-safe loading of 16-bit sizes */ im->w = (header->widthHi << 8) | header->widthLo; im->h = (header->heightHi << 8) | header->heightLo; @@ -275,7 +280,7 @@ load(ImlibImage * im, ImlibProgressFunction progress, if (!IMAGE_DIMENSIONS_OK(im->w, im->h)) goto quit; - if (bpp == 32) + if (hasa) SET_FLAG(im->flags, F_HAS_ALPHA); else UNSET_FLAG(im->flags, F_HAS_ALPHA); @@ -292,9 +297,6 @@ load(ImlibImage * im, ImlibProgressFunction progress, if (!__imlib_AllocateData(im, im->w, im->h)) goto quit; - /* first we read the file data into a buffer for parsing */ - /* then we decode from RAM */ - /* find out how much data must be read from the file */ /* (this is NOT simply width*height*4, due to compression) */ @@ -328,11 +330,11 @@ load(ImlibImage * im, ImlibProgressFunction progress, if (!rle) { + int x, y; + /* decode uncompressed BGRA data */ for (y = 0; y < im->h; y++) /* for each row */ { - int x; - /* point dataptr at the beginning of the row */ if (vinverted) /* some TGA's are stored upside-down! */ |