From 454030f54228f04ef743b5117274749839015a74 Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Thu, 23 Mar 2023 15:30:12 +0100 Subject: [PATCH 1/3] Fix: Targa using a palette can display as grayscale in Viewport. Viewport assumes that when the number of planes of the image buffer is less or equal to 8 it is a gray scale image. In that case it will optimize the texture to be stored as a grayscale image on the GPU. When using a targa file with a palette, the bitplanes were not extracted from the actual colors, but from the number of colors that were present in the palette. Image buffers don't support palettes so that doesn't make sense. This PR uses the bitdepth of the actual colors inside the palette to identify the number of planes to use in the image buffer. Fix: #105976 --- source/blender/imbuf/intern/targa.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/source/blender/imbuf/intern/targa.c b/source/blender/imbuf/intern/targa.c index ed6e6e9866d..0a9423eb432 100644 --- a/source/blender/imbuf/intern/targa.c +++ b/source/blender/imbuf/intern/targa.c @@ -676,11 +676,10 @@ ImBuf *imb_loadtarga(const uchar *mem, size_t mem_size, int flags, char colorspa cmap[count] = cp_data; } - size = 0; - for (int cmap_index = cmap_max - 1; cmap_index > 0; cmap_index >>= 1) { - size++; - } - ibuf->planes = size; + /* Set the planes based on the number of planes of the palette. Planes are + * used to optimize the storage on the GPU. When planes are not set correctly the image can + * draw as if it was a grayscale image. */ + ibuf->planes = (tga.mapbits >> 3) * 8; if (tga.mapbits != 32) { /* Set alpha bits. */ cmap[0] &= BIG_LONG(0x00ffffffl); -- 2.30.2 From df6dde1834eaf7855aa32812973224f5c3019d02 Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Thu, 23 Mar 2023 15:36:16 +0100 Subject: [PATCH 2/3] Don't be stupid and remove shift left/right. --- source/blender/imbuf/intern/targa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/imbuf/intern/targa.c b/source/blender/imbuf/intern/targa.c index 0a9423eb432..3d5ece5828a 100644 --- a/source/blender/imbuf/intern/targa.c +++ b/source/blender/imbuf/intern/targa.c @@ -679,7 +679,7 @@ ImBuf *imb_loadtarga(const uchar *mem, size_t mem_size, int flags, char colorspa /* Set the planes based on the number of planes of the palette. Planes are * used to optimize the storage on the GPU. When planes are not set correctly the image can * draw as if it was a grayscale image. */ - ibuf->planes = (tga.mapbits >> 3) * 8; + ibuf->planes = tga.mapbits; if (tga.mapbits != 32) { /* Set alpha bits. */ cmap[0] &= BIG_LONG(0x00ffffffl); -- 2.30.2 From ded52ca25f978cafa8b94103e54d5887fec0eecc Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Fri, 24 Mar 2023 07:45:25 +0100 Subject: [PATCH 3/3] Remove unneeded comment. --- source/blender/imbuf/intern/targa.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/source/blender/imbuf/intern/targa.c b/source/blender/imbuf/intern/targa.c index 3d5ece5828a..6c2f1eb6dd2 100644 --- a/source/blender/imbuf/intern/targa.c +++ b/source/blender/imbuf/intern/targa.c @@ -676,11 +676,7 @@ ImBuf *imb_loadtarga(const uchar *mem, size_t mem_size, int flags, char colorspa cmap[count] = cp_data; } - /* Set the planes based on the number of planes of the palette. Planes are - * used to optimize the storage on the GPU. When planes are not set correctly the image can - * draw as if it was a grayscale image. */ ibuf->planes = tga.mapbits; - if (tga.mapbits != 32) { /* Set alpha bits. */ cmap[0] &= BIG_LONG(0x00ffffffl); } -- 2.30.2