Просмотр исходного кода

texturec: Added --linear option.

Branimir Karadžić 7 лет назад
Родитель
Сommit
8a7d5589c2
4 измененных файлов с 67 добавлено и 2 удалено
  1. 6 0
      include/bimg/bimg.h
  2. 44 0
      src/image.cpp
  3. 1 1
      src/image_encode.cpp
  4. 16 1
      tools/texturec/texturec.cpp

+ 6 - 0
include/bimg/bimg.h

@@ -314,6 +314,9 @@ namespace bimg
 		, const void* _src
 		, const void* _src
 		);
 		);
 
 
+	///
+	void imageRgba32fToLinear(ImageContainer* _imageContainer);
+
 	///
 	///
 	void imageRgba32fToGamma(
 	void imageRgba32fToGamma(
 		  void* _dst
 		  void* _dst
@@ -324,6 +327,9 @@ namespace bimg
 		, const void* _src
 		, const void* _src
 		);
 		);
 
 
+	///
+	void imageRgba32fToGamma(ImageContainer* _imageContainer);
+
 	///
 	///
 	void imageRgba32fLinearDownsample2x2(
 	void imageRgba32fLinearDownsample2x2(
 		  void* _dst
 		  void* _dst

+ 44 - 0
src/image.cpp

@@ -560,6 +560,28 @@ namespace bimg
 		}
 		}
 	}
 	}
 
 
+	void imageRgba32fToLinear(ImageContainer* _imageContainer)
+	{
+		const uint16_t numSides = _imageContainer->m_numLayers * (_imageContainer->m_cubeMap ? 6 : 1);
+
+		for (uint16_t side = 0; side < numSides; ++side)
+		{
+			bimg::ImageMip mip;
+			bimg::imageGetRawData(*_imageContainer, side, 0, _imageContainer->m_data, _imageContainer->m_size, mip);
+
+			const uint32_t pitch = _imageContainer->m_width*16;
+			const uint32_t slice = _imageContainer->m_height*pitch;
+
+			for (uint32_t zz = 0, depth = _imageContainer->m_depth; zz < depth; ++zz)
+			{
+				const uint32_t srcDataStep = uint32_t(bx::floor(zz * _imageContainer->m_depth / float(depth) ) );
+				const uint8_t* srcData = &mip.m_data[srcDataStep*slice];
+
+				imageRgba32fToLinear(const_cast<uint8_t*>(srcData), mip.m_width, mip.m_height, 1, pitch, srcData);
+			}
+		}
+	}
+
 	void imageRgba32fToGamma(void* _dst, uint32_t _width, uint32_t _height, uint32_t _depth, uint32_t _srcPitch, const void* _src)
 	void imageRgba32fToGamma(void* _dst, uint32_t _width, uint32_t _height, uint32_t _depth, uint32_t _srcPitch, const void* _src)
 	{
 	{
 		      uint8_t* dst = (      uint8_t*)_dst;
 		      uint8_t* dst = (      uint8_t*)_dst;
@@ -584,6 +606,28 @@ namespace bimg
 		}
 		}
 	}
 	}
 
 
+	void imageRgba32fToGamma(ImageContainer* _imageContainer)
+	{
+		const uint16_t numSides = _imageContainer->m_numLayers * (_imageContainer->m_cubeMap ? 6 : 1);
+
+		for (uint16_t side = 0; side < numSides; ++side)
+		{
+			bimg::ImageMip mip;
+			bimg::imageGetRawData(*_imageContainer, side, 0, _imageContainer->m_data, _imageContainer->m_size, mip);
+
+			const uint32_t pitch = _imageContainer->m_width*16;
+			const uint32_t slice = _imageContainer->m_height*pitch;
+
+			for (uint32_t zz = 0, depth = _imageContainer->m_depth; zz < depth; ++zz)
+			{
+				const uint32_t srcDataStep = uint32_t(bx::floor(zz * _imageContainer->m_depth / float(depth) ) );
+				const uint8_t* srcData = &mip.m_data[srcDataStep*slice];
+
+				imageRgba32fToGamma(const_cast<uint8_t*>(srcData), mip.m_width, mip.m_height, 1, pitch, srcData);
+			}
+		}
+	}
+
 	void imageRgba32fLinearDownsample2x2Ref(void* _dst, uint32_t _width, uint32_t _height, uint32_t _depth, uint32_t _srcPitch, const void* _src)
 	void imageRgba32fLinearDownsample2x2Ref(void* _dst, uint32_t _width, uint32_t _height, uint32_t _depth, uint32_t _srcPitch, const void* _src)
 	{
 	{
 		const uint32_t dstWidth  = _width/2;
 		const uint32_t dstWidth  = _width/2;

+ 1 - 1
src/image_encode.cpp

@@ -467,7 +467,7 @@ namespace bimg
 					, 4, 3
 					, 4, 3
 					, STBIR_FLAG_ALPHA_PREMULTIPLIED
 					, STBIR_FLAG_ALPHA_PREMULTIPLIED
 					, STBIR_EDGE_CLAMP
 					, STBIR_EDGE_CLAMP
-					, STBIR_FILTER_CUBICBSPLINE
+					, STBIR_FILTER_BOX
 					, STBIR_COLORSPACE_LINEAR
 					, STBIR_COLORSPACE_LINEAR
 					, NULL
 					, NULL
 					);
 					);

+ 16 - 1
tools/texturec/texturec.cpp

@@ -25,7 +25,7 @@
 #include <string>
 #include <string>
 
 
 #define BIMG_TEXTUREC_VERSION_MAJOR 1
 #define BIMG_TEXTUREC_VERSION_MAJOR 1
-#define BIMG_TEXTUREC_VERSION_MINOR 17
+#define BIMG_TEXTUREC_VERSION_MINOR 18
 
 
 BX_ERROR_RESULT(TEXTRUREC_ERROR, BX_MAKEFOURCC('t', 'c', 0, 0) );
 BX_ERROR_RESULT(TEXTRUREC_ERROR, BX_MAKEFOURCC('t', 'c', 0, 0) );
 
 
@@ -46,6 +46,7 @@ struct Options
 			"\t radiance: %s\n"
 			"\t radiance: %s\n"
 			"\t equirect: %s\n"
 			"\t equirect: %s\n"
 			"\t    strip: %s\n"
 			"\t    strip: %s\n"
+			"\t   linear: %s\n"
 			, maxSize
 			, maxSize
 			, mipSkip
 			, mipSkip
 			, edge
 			, edge
@@ -58,6 +59,7 @@ struct Options
 			, radiance  ? "true" : "false"
 			, radiance  ? "true" : "false"
 			, equirect  ? "true" : "false"
 			, equirect  ? "true" : "false"
 			, strip     ? "true" : "false"
 			, strip     ? "true" : "false"
+			, linear    ? "true" : "false"
 			);
 			);
 	}
 	}
 
 
@@ -75,6 +77,7 @@ struct Options
 	bool pma       = false;
 	bool pma       = false;
 	bool sdf       = false;
 	bool sdf       = false;
 	bool alphaTest = false;
 	bool alphaTest = false;
+	bool linear    = false;
 };
 };
 
 
 void imageRgba32fNormalize(void* _dst, uint32_t _width, uint32_t _height, uint32_t _srcPitch, const void* _src)
 void imageRgba32fNormalize(void* _dst, uint32_t _width, uint32_t _height, uint32_t _srcPitch, const void* _src)
@@ -272,8 +275,18 @@ bimg::ImageContainer* convert(bx::AllocatorI* _allocator, const void* _inputData
 				, false
 				, false
 				);
 				);
 
 
+			if (!_options.linear)
+			{
+				bimg::imageRgba32fToLinear(src);
+			}
+
 			bimg::imageResizeRgba32fLinear(dst, src);
 			bimg::imageResizeRgba32fLinear(dst, src);
 
 
+			if (!_options.linear)
+			{
+				bimg::imageRgba32fToGamma(dst);
+			}
+
 			bimg::imageFree(src);
 			bimg::imageFree(src);
 			bimg::imageFree(input);
 			bimg::imageFree(input);
 
 
@@ -852,6 +865,7 @@ void help(const char* _error = NULL, bool _showHelp = true)
 		  "      --ref <alpha>        Alpha reference value.\n"
 		  "      --ref <alpha>        Alpha reference value.\n"
 		  "      --iqa                Image Quality Assessment\n"
 		  "      --iqa                Image Quality Assessment\n"
 		  "      --pma                Premultiply alpha into RGB channel.\n"
 		  "      --pma                Premultiply alpha into RGB channel.\n"
+		  "      --linear             Input and output texture is linear color space (gamma correction won't be applied).\n"
 		  "      --max <max size>     Maximum width/height (image will be scaled down and\n"
 		  "      --max <max size>     Maximum width/height (image will be scaled down and\n"
 		  "                           aspect ratio will be preserved.\n"
 		  "                           aspect ratio will be preserved.\n"
 		  "      --radiance <model>   Radiance cubemap filter. (Lighting model: Phong, PhongBrdf, Blinn, BlinnBrdf, GGX)\n"
 		  "      --radiance <model>   Radiance cubemap filter. (Lighting model: Phong, PhongBrdf, Blinn, BlinnBrdf, GGX)\n"
@@ -987,6 +1001,7 @@ int main(int _argc, const char* _argv[])
 	options.strip     = cmdLine.hasArg("strip");
 	options.strip     = cmdLine.hasArg("strip");
 	options.iqa       = cmdLine.hasArg("iqa");
 	options.iqa       = cmdLine.hasArg("iqa");
 	options.pma       = cmdLine.hasArg("pma");
 	options.pma       = cmdLine.hasArg("pma");
+	options.linear    = cmdLine.hasArg("linear");
 
 
 	if (options.equirect
 	if (options.equirect
 	&&  options.strip)
 	&&  options.strip)