diff --git a/include/bimg/bimg.h b/include/bimg/bimg.h index efe8641..a686f7d 100644 --- a/include/bimg/bimg.h +++ b/include/bimg/bimg.h @@ -291,6 +291,7 @@ namespace bimg , uint32_t _height , uint32_t _depth , uint32_t _srcPitch + , uint32_t _dstPitch , const void* _src ); @@ -330,6 +331,7 @@ namespace bimg , uint32_t _width , uint32_t _height , uint32_t _srcPitch + , uint32_t _dstPitch , const void* _src ); diff --git a/src/image.cpp b/src/image.cpp index 79c47b6..cafdb1b 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -340,7 +340,7 @@ namespace bimg } } - void imageRgba8Downsample2x2Ref(void* _dst, uint32_t _width, uint32_t _height, uint32_t _depth, uint32_t _srcPitch, const void* _src) + void imageRgba8Downsample2x2Ref(void* _dst, uint32_t _width, uint32_t _height, uint32_t _depth, uint32_t _srcPitch, uint32_t _dstPitch, const void* _src) { const uint32_t dstWidth = _width/2; const uint32_t dstHeight = _height/2; @@ -351,13 +351,13 @@ namespace bimg return; } - uint8_t* dst = (uint8_t*)_dst; const uint8_t* src = (const uint8_t*)_src; for (uint32_t zz = 0; zz < _depth; ++zz) { for (uint32_t yy = 0, ystep = _srcPitch*2; yy < dstHeight; ++yy, src += ystep) { + uint8_t* dst = (uint8_t*)_dst + _dstPitch*yy; const uint8_t* rgba = src; for (uint32_t xx = 0; xx < dstWidth; ++xx, rgba += 8, dst += 4) { @@ -394,7 +394,7 @@ namespace bimg } } - void imageRgba8Downsample2x2(void* _dst, uint32_t _width, uint32_t _height, uint32_t _depth, uint32_t _srcPitch, const void* _src) + void imageRgba8Downsample2x2(void* _dst, uint32_t _width, uint32_t _height, uint32_t _depth, uint32_t _srcPitch, uint32_t _dstPitch, const void* _src) { const uint32_t dstWidth = _width/2; const uint32_t dstHeight = _height/2; @@ -405,7 +405,6 @@ namespace bimg return; } - uint8_t* dst = (uint8_t*)_dst; const uint8_t* src = (const uint8_t*)_src; using namespace bx; @@ -423,6 +422,7 @@ namespace bimg { for (uint32_t yy = 0, ystep = _srcPitch*2; yy < dstHeight; ++yy, src += ystep) { + uint8_t* dst = (uint8_t*)_dst + _dstPitch*yy; const uint8_t* rgba = src; for (uint32_t xx = 0; xx < dstWidth; ++xx, rgba += 8, dst += 4) { @@ -586,7 +586,7 @@ namespace bimg imageRgba32fLinearDownsample2x2Ref(_dst, _width, _height, _depth, _srcPitch, _src); } - void imageRgba32fDownsample2x2NormalMapRef(void* _dst, uint32_t _width, uint32_t _height, uint32_t _srcPitch, const void* _src) + void imageRgba32fDownsample2x2NormalMapRef(void* _dst, uint32_t _width, uint32_t _height, uint32_t _srcPitch, uint32_t _dstPitch, const void* _src) { const uint32_t dstWidth = _width/2; const uint32_t dstHeight = _height/2; @@ -598,12 +598,14 @@ namespace bimg } const uint8_t* src = (const uint8_t*)_src; - uint8_t* dst = (uint8_t*)_dst; for (uint32_t yy = 0, ystep = _srcPitch*2; yy < dstHeight; ++yy, src += ystep) { const float* rgba0 = (const float*)&src[0]; const float* rgba1 = (const float*)&src[_srcPitch]; + + uint8_t* dst = (uint8_t*)_dst + _dstPitch*yy; + for (uint32_t xx = 0; xx < dstWidth; ++xx, rgba0 += 8, rgba1 += 8, dst += 16) { float xyz[3]; @@ -629,9 +631,9 @@ namespace bimg } } - void imageRgba32fDownsample2x2NormalMap(void* _dst, uint32_t _width, uint32_t _height, uint32_t _srcPitch, const void* _src) + void imageRgba32fDownsample2x2NormalMap(void* _dst, uint32_t _width, uint32_t _height, uint32_t _srcPitch, uint32_t _dstPitch, const void* _src) { - imageRgba32fDownsample2x2NormalMapRef(_dst, _width, _height, _srcPitch, _src); + imageRgba32fDownsample2x2NormalMapRef(_dst, _width, _height, _srcPitch, _dstPitch, _src); } void imageSwizzleBgra8Ref(void* _dst, uint32_t _dstPitch, uint32_t _width, uint32_t _height, const void* _src, uint32_t _srcPitch) diff --git a/tools/texturec/texturec.cpp b/tools/texturec/texturec.cpp index da09ae4..9a12b62 100644 --- a/tools/texturec/texturec.cpp +++ b/tools/texturec/texturec.cpp @@ -26,7 +26,7 @@ #include #define BIMG_TEXTUREC_VERSION_MAJOR 1 -#define BIMG_TEXTUREC_VERSION_MINOR 12 +#define BIMG_TEXTUREC_VERSION_MINOR 13 struct Options { @@ -331,6 +331,7 @@ bimg::ImageContainer* convert(bx::AllocatorI* _allocator, const void* _inputData , dstMip.m_width , dstMip.m_height , dstMip.m_width*16 + , bx::strideAlign(dstMip.m_width/2, blockWidth)*16 , rgba ); @@ -544,6 +545,7 @@ bimg::ImageContainer* convert(bx::AllocatorI* _allocator, const void* _inputData , dstMip.m_height , dstMip.m_depth , dstMip.m_width*4 + , bx::strideAlign(dstMip.m_width/2, blockWidth)*4 , rgba );