From 60a896f51365b68c7618c8a75d3cfc99c9b32af7 Mon Sep 17 00:00:00 2001 From: Alberto Torres Date: Fri, 13 Sep 2024 02:18:37 +0200 Subject: [PATCH] Workaround for images with less channels than the supposed texture format. --- src/gpu_formats/texture_decode.nim | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/gpu_formats/texture_decode.nim b/src/gpu_formats/texture_decode.nim index 183aa53..ef81b31 100644 --- a/src/gpu_formats/texture_decode.nim +++ b/src/gpu_formats/texture_decode.nim @@ -142,6 +142,10 @@ proc loadFileFromSlices*(tex: Texture, slices: seq[SliceMem[byte]], tex.format else: tex.format.resize(min_channels) + # TODO: Don't do this!! + # Change the format when the decoder has detected less channels!! + let min_channels = format.channel_count + let layer_stride = tex.width * tex.height * format.stride var multilayer_buffer: ArrRef[byte] assert tex.depth == slices.len @@ -197,8 +201,10 @@ proc loadFileFromSlices*(tex: Texture, slices: seq[SliceMem[byte]], image = loadFromMemory(slice.toOpenArrayByte, w,h,c, min_channels) pixels_ptr = image.data pixels_len = image.len - assert layer_stride == pixels_len, - &"Image '{tex.name}' has a length of {pixels_len}, expected {layer_stride}" + if layer_stride != pixels_len: + echo "Format: ", format + raise Defect.newException &"Image '{tex.name}' has a length" & + &" of {pixels_len}, expected {layer_stride}" if flip: swap_lines(pixels_ptr, tex.width * format.stride, tex.height) if tex.depth == 1: