Bladeren bron

Nothing very important

Panagiotis Christopoulos Charitos 4 jaren geleden
bovenliggende
commit
6b90e7a523
2 gewijzigde bestanden met toevoegingen van 88 en 3 verwijderingen
  1. 76 0
      AnKi/Importer/ImageImporter.cpp
  2. 12 3
      AnKi/Importer/ImageImporter.h

+ 76 - 0
AnKi/Importer/ImageImporter.cpp

@@ -4,3 +4,79 @@
 // http://www.anki3d.org/LICENSE
 // http://www.anki3d.org/LICENSE
 
 
 #include <AnKi/Importer/ImageImporter.h>
 #include <AnKi/Importer/ImageImporter.h>
+
+#define STBI_ASSERT(x) ANKI_ASSERT(x)
+#if ANKI_COMPILER_GCC_COMPATIBLE
+#	pragma GCC diagnostic push
+#	pragma GCC diagnostic ignored "-Wfloat-conversion"
+#	pragma GCC diagnostic ignored "-Wconversion"
+#	pragma GCC diagnostic ignored "-Wtype-limits"
+#endif
+#include <Stb/stb_image.h>
+#if ANKI_COMPILER_GCC_COMPATIBLE
+#	pragma GCC diagnostic pop
+#endif
+
+namespace anki
+{
+
+static Bool checkConfig(const ImageImporterConfig& config)
+{
+#define ANKI_CFG_ASSERT(x) \
+	do \
+	{ \
+		if(!(x)) \
+		{ \
+			return false; \
+		} \
+	} while(false)
+
+	// Filenames
+	ANKI_CFG_ASSERT(config.m_outFilename.getLength() > 0);
+
+	for(CString in : config.m_inputFilenames)
+	{
+		ANKI_CFG_ASSERT(in.getLength() > 0);
+	}
+
+	// Type
+	ANKI_CFG_ASSERT(config.m_type != ImageBinaryType::NONE);
+	ANKI_CFG_ASSERT(config.m_inputFilenames.getSize() == 1 || config.m_type != ImageBinaryType::_2D);
+	ANKI_CFG_ASSERT(config.m_inputFilenames.getSize() != 1 || config.m_type != ImageBinaryType::_2D_ARRAY);
+	ANKI_CFG_ASSERT(config.m_inputFilenames.getSize() != 1 || config.m_type != ImageBinaryType::_3D);
+	ANKI_CFG_ASSERT(config.m_inputFilenames.getSize() != 6 || config.m_type != ImageBinaryType::CUBE);
+
+	// Compressions
+	ANKI_CFG_ASSERT(config.m_compressions != ImageBinaryDataCompression::NONE);
+
+	// Mip size
+	ANKI_CFG_ASSERT(config.m_minMipmapDimension > 4);
+
+#undef ANKI_CFG_ASSERT
+	return true;
+}
+
+static Error importImageInternal(const ImageImporterConfig& config)
+{
+	if(!checkConfig(config))
+	{
+		ANKI_IMPORTER_LOGE("Config parameters are wrong");
+		return Error::USER_DATA;
+	}
+
+	return Error::NONE;
+}
+
+Error importImage(const ImageImporterConfig& config)
+{
+	const Error err = importImageInternal(config);
+	if(err)
+	{
+		ANKI_IMPORTER_LOGE("Image importing failed");
+		return err;
+	}
+
+	return Error::NONE;
+}
+
+} // end namespace anki

+ 12 - 3
AnKi/Importer/ImageImporter.h

@@ -4,7 +4,9 @@
 // http://www.anki3d.org/LICENSE
 // http://www.anki3d.org/LICENSE
 
 
 #include <AnKi/Importer/Common.h>
 #include <AnKi/Importer/Common.h>
-#include <AnKi/Util/Allocator.h>
+#include <AnKi/Util/String.h>
+#include <AnKi/Util/WeakArray.h>
+#include <AnKi/Resource/ImageBinary.h>
 
 
 namespace anki
 namespace anki
 {
 {
@@ -12,14 +14,21 @@ namespace anki
 /// @addtogroup importer
 /// @addtogroup importer
 /// @{
 /// @{
 
 
-class ImageImporterInfo
+class ImageImporterConfig
 {
 {
 public:
 public:
 	GenericMemoryPoolAllocator<U8> m_allocator;
 	GenericMemoryPoolAllocator<U8> m_allocator;
+	ConstWeakArray<CString> m_inputFilenames;
+	CString m_outFilename;
+	ImageBinaryType m_type = ImageBinaryType::_2D;
+	ImageBinaryDataCompression m_compressions = ImageBinaryDataCompression::S3TC;
+	U32 m_minMipmapDimension = 4;
+	U32 m_mipmapCount = MAX_U32;
+	Bool m_noAlpha = true;
 };
 };
 
 
 /// Converts images to AnKi's specific format.
 /// Converts images to AnKi's specific format.
-ANKI_USE_RESULT Error importImage(const ImageImporterInfo& info);
+ANKI_USE_RESULT Error importImage(const ImageImporterConfig& config);
 /// @}
 /// @}
 
 
 } // end namespace anki
 } // end namespace anki