From 0621a9b0235197c463f59bef76faf81355943c44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Thu, 6 Jul 2017 18:04:25 -0700 Subject: [PATCH] Fixed .exr decoding. --- src/image_decode.cpp | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/image_decode.cpp b/src/image_decode.cpp index 1ce1497..965f359 100644 --- a/src/image_decode.cpp +++ b/src/image_decode.cpp @@ -338,12 +338,14 @@ namespace bimg uint32_t stepG = 0; uint32_t stepB = 0; uint32_t stepA = 0; + bx::PackFn pack = asFloat ? bx::packR32F : bx::packR16F; if (UINT8_MAX != idxG) { srcBpp += 32; dstBpp = asFloat ? 64 : 32; format = asFloat ? TextureFormat::RG32F : TextureFormat::RG16F; + pack = asFloat ? bx::packRg32F : bx::packRg16F; stepG = 1; } @@ -352,6 +354,7 @@ namespace bimg srcBpp += 32; dstBpp = asFloat ? 128 : 64; format = asFloat ? TextureFormat::RGBA32F : TextureFormat::RGBA16F; + pack = asFloat ? bx::packRgba32F : bx::packRgba16F; stepB = 1; } @@ -360,10 +363,13 @@ namespace bimg srcBpp += 32; dstBpp = asFloat ? 128 : 64; format = asFloat ? TextureFormat::RGBA32F : TextureFormat::RGBA16F; + pack = asFloat ? bx::packRgba32F : bx::packRgba16F; stepA = 1; } - data = (uint8_t*)BX_ALLOC(_allocator, exrImage.width * exrImage.height * dstBpp/8); + data = (uint8_t*)BX_ALLOC(_allocator, exrImage.width * exrImage.height * dstBpp/8); + width = exrImage.width; + height = exrImage.height; const float zero = 0.0f; const float* srcR = UINT8_MAX == idxR ? &zero : (const float*)(exrImage.images)[idxR]; @@ -381,7 +387,7 @@ namespace bimg *srcB, *srcA, }; - bx::memCopy(&data[ii * bytesPerPixel], rgba, bytesPerPixel); + pack(&data[ii * bytesPerPixel], rgba); srcR += stepR; srcG += stepG; @@ -396,17 +402,21 @@ namespace bimg FreeEXRHeader(&exrHeader); } - ImageContainer* output = imageAlloc(_allocator - , format - , uint16_t(width) - , uint16_t(height) - , 0 - , 1 - , false - , false - , data - ); - BX_FREE(_allocator, data); + ImageContainer* output = NULL; + if (NULL != data) + { + output = imageAlloc(_allocator + , format + , uint16_t(width) + , uint16_t(height) + , 0 + , 1 + , false + , false + , data + ); + BX_FREE(_allocator, data); + } return output; }