mirror of
https://github.com/bkaradzic/bimg.git
synced 2026-02-17 20:52:38 +01:00
Fixed crash when resizing image with mips from compressed to uncompressed format.
This commit is contained in:
@@ -427,6 +427,7 @@ namespace bimg
|
||||
bx::AllocatorI* _allocator
|
||||
, TextureFormat::Enum _dstFormat
|
||||
, const ImageContainer& _input
|
||||
, bool _convertMips = true
|
||||
);
|
||||
|
||||
///
|
||||
|
||||
@@ -1017,7 +1017,7 @@ namespace bimg
|
||||
return imageConvert(_allocator, _dst, _dstFormat, _src, _srcFormat, _width, _height, _depth, _width*srcBpp/8);
|
||||
}
|
||||
|
||||
ImageContainer* imageConvert(bx::AllocatorI* _allocator, TextureFormat::Enum _dstFormat, const ImageContainer& _input)
|
||||
ImageContainer* imageConvert(bx::AllocatorI* _allocator, TextureFormat::Enum _dstFormat, const ImageContainer& _input, bool _convertMips)
|
||||
{
|
||||
ImageContainer* output = imageAlloc(_allocator
|
||||
, _dstFormat
|
||||
@@ -1026,14 +1026,14 @@ namespace bimg
|
||||
, uint16_t(_input.m_depth)
|
||||
, _input.m_numLayers
|
||||
, _input.m_cubeMap
|
||||
, 1 < _input.m_numMips
|
||||
, _convertMips && 1 < _input.m_numMips
|
||||
);
|
||||
|
||||
const uint16_t numSides = _input.m_numLayers * (_input.m_cubeMap ? 6 : 1);
|
||||
|
||||
for (uint16_t side = 0; side < numSides; ++side)
|
||||
{
|
||||
for (uint8_t lod = 0, num = _input.m_numMips; lod < num; ++lod)
|
||||
for (uint8_t lod = 0, num = _convertMips ? _input.m_numMips : 1; lod < num; ++lod)
|
||||
{
|
||||
ImageMip mip;
|
||||
if (imageGetRawData(_input, side, lod, _input.m_data, _input.m_size, mip) )
|
||||
@@ -4032,6 +4032,23 @@ namespace bimg
|
||||
}
|
||||
break;
|
||||
|
||||
case TextureFormat::BC6H:
|
||||
{
|
||||
ImageContainer* rgba32f = imageAlloc(_allocator
|
||||
, TextureFormat::RGBA32F
|
||||
, uint16_t(_width)
|
||||
, uint16_t(_height)
|
||||
, uint16_t(1)
|
||||
, 1
|
||||
, false
|
||||
, false
|
||||
);
|
||||
imageDecodeToRgba32f(_allocator, rgba32f->m_data, _src, _width, _height, 1, _width*16, _srcFormat);
|
||||
imageConvert(_allocator, _dst, TextureFormat::BGRA8, rgba32f->m_data, TextureFormat::RGBA32F, _width, _height, 1, _width*16);
|
||||
imageFree(rgba32f);
|
||||
}
|
||||
break;
|
||||
|
||||
case TextureFormat::BC7:
|
||||
for (uint32_t yy = 0; yy < height; ++yy)
|
||||
{
|
||||
@@ -4229,7 +4246,7 @@ namespace bimg
|
||||
const uint8_t* src = (const uint8_t*)_src;
|
||||
|
||||
using namespace bx;
|
||||
const simd128_t unpack = simd_ld(1.0f, 1.0f/256.0f, 1.0f/65536.0f, 1.0f/16777216.0f);
|
||||
const simd128_t unpack = simd_ld(1.0f/256.0f, 1.0f/256.0f/256.0f, 1.0f/65536.0f/256.0f, 1.0f/16777216.0f/256.0f);
|
||||
const simd128_t umask = simd_ild(0xff, 0xff00, 0xff0000, 0xff000000);
|
||||
const simd128_t wflip = simd_ild(0, 0, 0, 0x80000000);
|
||||
const simd128_t wadd = simd_ld(0.0f, 0.0f, 0.0f, 32768.0f*65536.0f);
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include <string>
|
||||
|
||||
#define BIMG_TEXTUREC_VERSION_MAJOR 1
|
||||
#define BIMG_TEXTUREC_VERSION_MINOR 14
|
||||
#define BIMG_TEXTUREC_VERSION_MINOR 15
|
||||
|
||||
struct Options
|
||||
{
|
||||
@@ -145,7 +145,7 @@ bimg::ImageContainer* convert(bx::AllocatorI* _allocator, const void* _inputData
|
||||
|
||||
if (NULL != input)
|
||||
{
|
||||
const bimg::TextureFormat::Enum inputFormat = input->m_format;
|
||||
bimg::TextureFormat::Enum inputFormat = input->m_format;
|
||||
bimg::TextureFormat::Enum outputFormat = input->m_format;
|
||||
|
||||
if (bimg::TextureFormat::Count != _options.format)
|
||||
@@ -211,7 +211,7 @@ bimg::ImageContainer* convert(bx::AllocatorI* _allocator, const void* _inputData
|
||||
|
||||
if (needResize)
|
||||
{
|
||||
bimg::ImageContainer* src = bimg::imageConvert(_allocator, bimg::TextureFormat::RGBA32F, *input);
|
||||
bimg::ImageContainer* src = bimg::imageConvert(_allocator, bimg::TextureFormat::RGBA32F, *input, false);
|
||||
|
||||
bimg::ImageContainer* dst = bimg::imageAlloc(
|
||||
_allocator
|
||||
@@ -229,6 +229,18 @@ bimg::ImageContainer* convert(bx::AllocatorI* _allocator, const void* _inputData
|
||||
bimg::imageFree(src);
|
||||
bimg::imageFree(input);
|
||||
|
||||
if (bimg::isCompressed(inputFormat) )
|
||||
{
|
||||
if (inputFormat == bimg::TextureFormat::BC6H)
|
||||
{
|
||||
inputFormat = bimg::TextureFormat::RGBA32F;
|
||||
}
|
||||
else
|
||||
{
|
||||
inputFormat = bimg::TextureFormat::RGBA8;
|
||||
}
|
||||
}
|
||||
|
||||
input = bimg::imageConvert(_allocator, inputFormat, *dst);
|
||||
bimg::imageFree(dst);
|
||||
}
|
||||
@@ -396,7 +408,7 @@ bimg::ImageContainer* convert(bx::AllocatorI* _allocator, const void* _inputData
|
||||
BX_FREE(_allocator, rgbaDst);
|
||||
}
|
||||
// HDR
|
||||
else if ( (!bimg::isCompressed(input->m_format) && 8 != inputBlockInfo.rBits)
|
||||
else if ( (!bimg::isCompressed(inputFormat) && 8 != inputBlockInfo.rBits)
|
||||
|| outputFormat == bimg::TextureFormat::BC6H
|
||||
|| outputFormat == bimg::TextureFormat::BC7
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user