Jelajahi Sumber

Align BC image mips to block size.

Branimir Karadžić 7 tahun lalu
induk
melakukan
1b71e2d86d
3 mengubah file dengan 15 tambahan dan 9 penghapusan
  1. 2 0
      include/bimg/bimg.h
  2. 10 8
      src/image.cpp
  3. 3 1
      tools/texturec/texturec.cpp

+ 2 - 0
include/bimg/bimg.h

@@ -291,6 +291,7 @@ namespace bimg
 		, uint32_t _height
 		, uint32_t _height
 		, uint32_t _depth
 		, uint32_t _depth
 		, uint32_t _srcPitch
 		, uint32_t _srcPitch
+		, uint32_t _dstPitch
 		, const void* _src
 		, const void* _src
 		);
 		);
 
 
@@ -330,6 +331,7 @@ namespace bimg
 		, uint32_t _width
 		, uint32_t _width
 		, uint32_t _height
 		, uint32_t _height
 		, uint32_t _srcPitch
 		, uint32_t _srcPitch
+		, uint32_t _dstPitch
 		, const void* _src
 		, const void* _src
 		);
 		);
 
 

+ 10 - 8
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 dstWidth  = _width/2;
 		const uint32_t dstHeight = _height/2;
 		const uint32_t dstHeight = _height/2;
@@ -351,13 +351,13 @@ namespace bimg
 			return;
 			return;
 		}
 		}
 
 
-		uint8_t* dst = (uint8_t*)_dst;
 		const uint8_t* src = (const uint8_t*)_src;
 		const uint8_t* src = (const uint8_t*)_src;
 
 
 		for (uint32_t zz = 0; zz < _depth; ++zz)
 		for (uint32_t zz = 0; zz < _depth; ++zz)
 		{
 		{
 			for (uint32_t yy = 0, ystep = _srcPitch*2; yy < dstHeight; ++yy, src += ystep)
 			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;
 				const uint8_t* rgba = src;
 				for (uint32_t xx = 0; xx < dstWidth; ++xx, rgba += 8, dst += 4)
 				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 dstWidth  = _width/2;
 		const uint32_t dstHeight = _height/2;
 		const uint32_t dstHeight = _height/2;
@@ -405,7 +405,6 @@ namespace bimg
 			return;
 			return;
 		}
 		}
 
 
-		uint8_t* dst = (uint8_t*)_dst;
 		const uint8_t* src = (const uint8_t*)_src;
 		const uint8_t* src = (const uint8_t*)_src;
 
 
 		using namespace bx;
 		using namespace bx;
@@ -423,6 +422,7 @@ namespace bimg
 		{
 		{
 			for (uint32_t yy = 0, ystep = _srcPitch*2; yy < dstHeight; ++yy, src += ystep)
 			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;
 				const uint8_t* rgba = src;
 				for (uint32_t xx = 0; xx < dstWidth; ++xx, rgba += 8, dst += 4)
 				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);
 		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 dstWidth  = _width/2;
 		const uint32_t dstHeight = _height/2;
 		const uint32_t dstHeight = _height/2;
@@ -598,12 +598,14 @@ namespace bimg
 		}
 		}
 
 
 		const uint8_t* src = (const uint8_t*)_src;
 		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)
 		for (uint32_t yy = 0, ystep = _srcPitch*2; yy < dstHeight; ++yy, src += ystep)
 		{
 		{
 			const float* rgba0 = (const float*)&src[0];
 			const float* rgba0 = (const float*)&src[0];
 			const float* rgba1 = (const float*)&src[_srcPitch];
 			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)
 			for (uint32_t xx = 0; xx < dstWidth; ++xx, rgba0 += 8, rgba1 += 8, dst += 16)
 			{
 			{
 				float xyz[3];
 				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)
 	void imageSwizzleBgra8Ref(void* _dst, uint32_t _dstPitch, uint32_t _width, uint32_t _height, const void* _src, uint32_t _srcPitch)

+ 3 - 1
tools/texturec/texturec.cpp

@@ -26,7 +26,7 @@
 #include <string>
 #include <string>
 
 
 #define BIMG_TEXTUREC_VERSION_MAJOR 1
 #define BIMG_TEXTUREC_VERSION_MAJOR 1
-#define BIMG_TEXTUREC_VERSION_MINOR 12
+#define BIMG_TEXTUREC_VERSION_MINOR 13
 
 
 struct Options
 struct Options
 {
 {
@@ -331,6 +331,7 @@ bimg::ImageContainer* convert(bx::AllocatorI* _allocator, const void* _inputData
 							, dstMip.m_width
 							, dstMip.m_width
 							, dstMip.m_height
 							, dstMip.m_height
 							, dstMip.m_width*16
 							, dstMip.m_width*16
+							, bx::strideAlign(dstMip.m_width/2, blockWidth)*16
 							, rgba
 							, rgba
 							);
 							);
 
 
@@ -544,6 +545,7 @@ bimg::ImageContainer* convert(bx::AllocatorI* _allocator, const void* _inputData
 							, dstMip.m_height
 							, dstMip.m_height
 							, dstMip.m_depth
 							, dstMip.m_depth
 							, dstMip.m_width*4
 							, dstMip.m_width*4
+							, bx::strideAlign(dstMip.m_width/2, blockWidth)*4
 							, rgba
 							, rgba
 							);
 							);