소스 검색

Fixed SDF.

Branimir Karadžić 8 년 전
부모
커밋
39a8c56545
3개의 변경된 파일87개의 추가작업 그리고 2개의 파일을 삭제
  1. 12 0
      include/bimg/bimg.h
  2. 25 0
      src/image.cpp
  3. 50 2
      tools/texturec/texturec.cpp

+ 12 - 0
include/bimg/bimg.h

@@ -533,6 +533,18 @@ namespace bimg
 		, bx::Error* _err
 		);
 
+	///
+	void imageDecodeToR8(
+		  bx::AllocatorI* _allocator
+		, void* _dst
+		, const void* _src
+		, uint32_t _width
+		, uint32_t _height
+		, uint32_t _depth
+		, uint32_t _dstPitch
+		, TextureFormat::Enum _srcFormat
+	);
+
 	///
 	void imageDecodeToBgra8(
 		  void* _dst

+ 25 - 0
src/image.cpp

@@ -2775,6 +2775,31 @@ namespace bimg
 		return imageParse(_imageContainer, &reader, _err);
 	}
 
+	void imageDecodeToR8(bx::AllocatorI* _allocator, void* _dst, const void* _src, uint32_t _width, uint32_t _height, uint32_t _depth, uint32_t _dstPitch, TextureFormat::Enum _srcFormat)
+	{
+		const uint8_t* src = (const uint8_t*)_src;
+		uint8_t* dst = (uint8_t*)_dst;
+
+		const uint32_t srcBpp = s_imageBlockInfo[_srcFormat].bitsPerPixel;
+		const uint32_t srcPitch = _width*srcBpp/8;
+
+		for (uint32_t zz = 0; zz < _depth; ++zz, src += _height*srcPitch, dst += _height*_dstPitch)
+		{
+			if (isCompressed(_srcFormat))
+			{
+				uint32_t size = imageGetSize(NULL, uint16_t(_width), uint16_t(_height), 0, false, false, 1, TextureFormat::RGBA8);
+				void* temp = BX_ALLOC(_allocator, size);
+				imageDecodeToRgba8(temp, _src, _width, _height, _width*4, _srcFormat);
+				imageConvert(dst, TextureFormat::R8, temp, TextureFormat::RGBA8, _width, _height, 1, _width*4);
+				BX_FREE(_allocator, temp);
+			}
+			else
+			{
+				imageConvert(dst, TextureFormat::R8, src, _srcFormat, _width, _height, 1, srcPitch);
+			}
+		}
+	}
+
 	void imageDecodeToBgra8(void* _dst, const void* _src, uint32_t _width, uint32_t _height, uint32_t _dstPitch, TextureFormat::Enum _srcFormat)
 	{
 		const uint8_t* src = (const uint8_t*)_src;

+ 50 - 2
tools/texturec/texturec.cpp

@@ -118,6 +118,11 @@ bimg::ImageContainer* convert(bx::AllocatorI* _allocator, const void* _inputData
 			outputFormat = _options.format;
 		}
 
+		if (_options.sdf)
+		{
+			outputFormat = bimg::TextureFormat::R8;
+		}
+
 		const bimg::ImageBlockInfo&  inputBlockInfo  = bimg::getBlockInfo(inputFormat);
 		const bimg::ImageBlockInfo&  outputBlockInfo = bimg::getBlockInfo(outputFormat);
 		const uint32_t blockWidth  = outputBlockInfo.blockWidth;
@@ -410,6 +415,43 @@ bimg::ImageContainer* convert(bx::AllocatorI* _allocator, const void* _inputData
 
 					BX_FREE(_allocator, rgbaDst);
 				}
+				else if (_options.sdf)
+				{
+					uint32_t size = bimg::imageGetSize(
+						  NULL
+						, uint16_t(dstMip.m_width)
+						, uint16_t(dstMip.m_height)
+						, uint16_t(dstMip.m_depth)
+						, false
+						, false
+						, 1
+						, bimg::TextureFormat::R8
+						);
+					temp = BX_ALLOC(_allocator, size);
+					uint8_t* rgba = (uint8_t*)temp;
+
+					bimg::imageDecodeToR8(_allocator
+						, rgba
+						, mip.m_data
+						, mip.m_width
+						, mip.m_height
+						, mip.m_depth
+						, mip.m_width
+						, mip.m_format
+						);
+
+					bimg::imageGetRawData(*output, side, 0, output->m_data, output->m_size, dstMip);
+					dstData = const_cast<uint8_t*>(dstMip.m_data);
+
+					bimg::imageMakeDist(_allocator
+						, dstData
+						, mip.m_width
+						, mip.m_height
+						, mip.m_width
+						, _options.edge
+						, rgba
+						);
+				}
 				else
 				{
 					uint32_t size = bimg::imageGetSize(
@@ -666,7 +708,10 @@ int main(int _argc, const char* _argv[])
 	if (NULL != edgeOpt)
 	{
 		options.sdf  = true;
-		options.edge = (float)atof(edgeOpt);
+		if (!bx::fromString(&options.edge, edgeOpt) )
+		{
+			options.edge = 255.0f;
+		}
 	}
 	else
 	{
@@ -674,7 +719,10 @@ int main(int _argc, const char* _argv[])
 		if (NULL != alphaRef)
 		{
 			options.alphaTest = true;
-			options.edge      = (float)atof(alphaRef);
+			if (!bx::fromString(&options.edge, alphaRef))
+			{
+				options.edge = 0.5f;
+			}
 		}
 	}