Browse Source

Fix image importer bugs

Panagiotis Christopoulos Charitos 4 years ago
parent
commit
f7a67e01b8
2 changed files with 22 additions and 12 deletions
  1. 7 6
      AnKi/Importer/ImageImporter.cpp
  2. 15 6
      Tools/Image/ImageImporterMain.cpp

+ 7 - 6
AnKi/Importer/ImageImporter.cpp

@@ -135,7 +135,7 @@ static ANKI_USE_RESULT Error checkConfig(const ImageImporterConfig& config)
 					"Can't compress 3D textures");
 
 	// Mip size
-	ANKI_CFG_ASSERT(config.m_minMipmapDimension > 4, "Mimpap min dimension can be less than 4");
+	ANKI_CFG_ASSERT(config.m_minMipmapDimension >= 4, "Mimpap min dimension can be less than 4");
 
 #undef ANKI_CFG_ASSERT
 	return Error::NONE;
@@ -322,7 +322,7 @@ static ANKI_USE_RESULT Error compressS3tc(GenericMemoryPoolAllocator<U8> alloc,
 
 	// Create a BMP image to feed to the compressor
 	StringAuto bmpFilename(alloc);
-	bmpFilename.sprintf("%s/%u_.bmp", tempDirectory.cstr(), U32(std::rand()));
+	bmpFilename.sprintf("%s/AnKiImageImporter_%u.bmp", tempDirectory.cstr(), U32(std::rand()));
 	if(!stbi_write_bmp(bmpFilename.cstr(), inWidth, inHeight, channelCount, inPixels.getBegin()))
 	{
 		ANKI_IMPORTER_LOGE("STB failed to create: %s", bmpFilename.cstr());
@@ -332,7 +332,7 @@ static ANKI_USE_RESULT Error compressS3tc(GenericMemoryPoolAllocator<U8> alloc,
 
 	// Invoke the compressor process
 	StringAuto ddsFilename(alloc);
-	ddsFilename.sprintf("%s/%u_.dds", tempDirectory.cstr(), U32(std::rand()));
+	ddsFilename.sprintf("%s/AnKiImageImporter_%u.dds", tempDirectory.cstr(), U32(std::rand()));
 	Process proc;
 	Array<CString, 5> args;
 	U32 argCount = 0;
@@ -478,9 +478,10 @@ static ANKI_USE_RESULT Error importImageInternal(const ImageImporterConfig& conf
 	ANKI_CHECK(loadFirstMipmap(config, ctx));
 
 	// Generate mipmaps
-	const U32 mipCount = (config.m_type == ImageBinaryType::_3D)
-							 ? computeMaxMipmapCount3d(width, height, ctx.m_depth, config.m_minMipmapDimension)
-							 : computeMaxMipmapCount2d(width, height, config.m_minMipmapDimension);
+	const U32 mipCount =
+		min(config.m_mipmapCount, (config.m_type == ImageBinaryType::_3D)
+									  ? computeMaxMipmapCount3d(width, height, ctx.m_depth, config.m_minMipmapDimension)
+									  : computeMaxMipmapCount2d(width, height, config.m_minMipmapDimension));
 	for(U32 mip = 1; mip < mipCount; ++mip)
 	{
 		ctx.m_mipmaps.emplaceBack(alloc);

+ 15 - 6
Tools/Image/ImageImporterMain.cpp

@@ -4,6 +4,7 @@
 // http://www.anki3d.org/LICENSE
 
 #include <AnKi/Importer/ImageImporter.h>
+#include <AnKi/Util/Filesystem.h>
 
 using namespace anki;
 
@@ -17,9 +18,9 @@ Options:
 )";
 
 static Error parseCommandLineArgs(int argc, char** argv, ImageImporterConfig& config,
-								  DynamicArrayAuto<StringAuto>& filenames)
+								  DynamicArrayAuto<StringAuto>& filenames, DynamicArrayAuto<CString>& cfilenames)
 {
-	config.m_compressions = ImageBinaryDataCompression::NONE;
+	config.m_compressions = ImageBinaryDataCompression::S3TC;
 	config.m_noAlpha = false;
 
 	// Parse config
@@ -113,13 +114,12 @@ static Error parseCommandLineArgs(int argc, char** argv, ImageImporterConfig& co
 		}
 	}
 
-	const PtrSize listSize = filenames.getSize();
-	if(listSize < 3)
+	if(filenames.getSize() < 2)
 	{
 		return Error::USER_DATA;
 	}
 
-	DynamicArrayAuto<CString> cfilenames(filenames.getAllocator(), filenames.getSize());
+	cfilenames.create(filenames.getSize());
 	for(U32 i = 0; i < filenames.getSize(); ++i)
 	{
 		cfilenames[i] = filenames[i];
@@ -138,12 +138,21 @@ int main(int argc, char** argv)
 	ImageImporterConfig config;
 	config.m_allocator = alloc;
 	DynamicArrayAuto<StringAuto> filenames(alloc);
-	if(parseCommandLineArgs(argc, argv, config, filenames))
+	DynamicArrayAuto<CString> cfilenames(alloc);
+	if(parseCommandLineArgs(argc, argv, config, filenames, cfilenames))
 	{
 		ANKI_IMPORTER_LOGE(USAGE, argv[0]);
 		return 1;
 	}
 
+	StringAuto tmp(alloc);
+	if(getTempDirectory(tmp))
+	{
+		ANKI_IMPORTER_LOGE("getTempDirectory() failed");
+		return 1;
+	}
+	config.m_tempDirectory = tmp;
+
 	if(importImage(config))
 	{
 		ANKI_IMPORTER_LOGE("Importing failed");