From d0f0f1f1cb1ef5478b3ac3b00597c8b17974ffc4 Mon Sep 17 00:00:00 2001 From: "Andrii Doroshenko (Xrayez)" Date: Sun, 21 Apr 2019 14:29:40 +0300 Subject: [PATCH] Fix TGA indexed images loaded with flipped color table This fixes incorrect color table lookup where red and blue channels were flipped. --- modules/tga/image_loader_tga.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/tga/image_loader_tga.cpp b/modules/tga/image_loader_tga.cpp index 419229677be..a3c0f5ded75 100644 --- a/modules/tga/image_loader_tga.cpp +++ b/modules/tga/image_loader_tga.cpp @@ -148,9 +148,11 @@ Error ImageLoaderTGA::convert_to_image(Ref p_image, const uint8_t *p_buff uint8_t a = 0xff; if (p_header.color_map_depth == 24) { - r = (p_palette[(index * 3) + 0]); + // Due to low-high byte order, the color table must be + // read in the same order as image data (little endian) + r = (p_palette[(index * 3) + 2]); g = (p_palette[(index * 3) + 1]); - b = (p_palette[(index * 3) + 2]); + b = (p_palette[(index * 3) + 0]); } else { return ERR_INVALID_DATA; }