From c545139a6bd720a4652604678387d05a38c0cc5a Mon Sep 17 00:00:00 2001 From: Niceblack Date: Mon, 3 Jul 2017 00:07:59 +0300 Subject: [PATCH] Fix the color components in esLoadTGA TGA uses BGR/BGRA color and therefore we have to swap the color components. --- Common/Source/esUtil.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Common/Source/esUtil.c b/Common/Source/esUtil.c index 3e8ae6b..86d8923 100644 --- a/Common/Source/esUtil.c +++ b/Common/Source/esUtil.c @@ -414,6 +414,18 @@ char *ESUTIL_API esLoadTGA ( void *ioContext, const char *fileName, int *width, { bytesRead = esFileRead ( fp, bytesToRead, buffer ); esFileClose ( fp ); + + // Convert BGR to RGB, BGRA to RGBA + if ( Header.ColorDepth == 24 || Header.ColorDepth == 32 ) + { + int i; + for ( i = 0; i < bytesToRead; i += Header.ColorDepth / 8 ) + { + char tmp = buffer[i]; + buffer[i] = buffer[i + 2]; + buffer[i + 2] = tmp; + } + } return ( buffer ); }