From 3792951023a39765957fd53757b8c6ca45803093 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Tue, 2 Jun 2020 23:08:34 +0200 Subject: [PATCH] REVIEWED: GetPixelDataSize() to consider compressed data properly --- src/textures.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/textures.c b/src/textures.c index d73cc1c63..aee5ad972 100644 --- a/src/textures.c +++ b/src/textures.c @@ -3222,6 +3222,14 @@ int GetPixelDataSize(int width, int height, int format) } dataSize = width*height*bpp/8; // Total data size in bytes + + // Most compressed formats works on 4x4 blocks, + // if texture is smaller, minimum dataSize is 8 or 16 + if ((width < 4) && (height < 4)) + { + if ((format >= COMPRESSED_DXT1_RGB) && (format < COMPRESSED_DXT3_RGBA)) dataSize = 8; + else if ((format >= COMPRESSED_DXT3_RGBA) && (format < COMPRESSED_ASTC_8x8_RGBA)) dataSize = 16; + } return dataSize; }