| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
- // All rights reserved.
- // Code licensed under the BSD License.
- // http://www.anki3d.org/LICENSE
- #include <AnKi/Importer/ImageImporter.h>
- using namespace anki;
- static const char* USAGE = R"(Usage: %s in_files out_file [options]
- Options:
- -t <type> : Image type. One of: 2D, 3D, Cube, 2DArray
- -no-alpha : If the image has alpha don't store it. By default it stores it
- -store-s3tc <0|1> : Store S3TC images. Default is 1
- -store-raw <0|1> : Store RAW images. Default is 0
- -mip-count <number> : Max number of mipmaps. By default store until 4x4
- )";
- static Error parseCommandLineArgs(int argc, char** argv, ImageImporterConfig& config,
- DynamicArrayAuto<StringAuto>& filenames)
- {
- config.m_compressions = ImageBinaryDataCompression::NONE;
- config.m_noAlpha = false;
- // Parse config
- if(argc < 3)
- {
- return Error::USER_DATA;
- }
- for(I i = 1; i < argc; i++)
- {
- if(CString(argv[i]) == "-t")
- {
- ++i;
- if(i >= argc)
- {
- return Error::USER_DATA;
- }
- if(CString(argv[i]) == "2D")
- {
- config.m_type = ImageBinaryType::_2D;
- }
- else if(CString(argv[i]) == "3D")
- {
- config.m_type = ImageBinaryType::_3D;
- }
- else if(CString(argv[i]) == "Cube")
- {
- config.m_type = ImageBinaryType::CUBE;
- }
- else if(CString(argv[i]) == "2DArray")
- {
- config.m_type = ImageBinaryType::_2D_ARRAY;
- }
- else
- {
- return Error::USER_DATA;
- }
- }
- else if(CString(argv[i]) == "-no-alpha")
- {
- config.m_noAlpha = true;
- }
- else if(CString(argv[i]) == "-store-s3tc")
- {
- ++i;
- if(i >= argc)
- {
- return Error::USER_DATA;
- }
- if(CString(argv[i]) == "1")
- {
- config.m_compressions |= ImageBinaryDataCompression::S3TC;
- }
- else if(CString(argv[i]) != "0")
- {
- return Error::USER_DATA;
- }
- }
- else if(CString(argv[i]) == "-store-raw")
- {
- ++i;
- if(i >= argc)
- {
- return Error::USER_DATA;
- }
- if(CString(argv[i]) == "1")
- {
- config.m_compressions |= ImageBinaryDataCompression::RAW;
- }
- else if(CString(argv[i]) != "0")
- {
- return Error::USER_DATA;
- }
- }
- else if(CString(argv[i]) == "-mip-count")
- {
- ++i;
- if(i >= argc)
- {
- return Error::USER_DATA;
- }
- ANKI_CHECK(CString(argv[i]).toNumber(config.m_mipmapCount));
- }
- else
- {
- filenames.emplaceBack(filenames.getAllocator(), argv[i]);
- }
- }
- const PtrSize listSize = filenames.getSize();
- if(listSize < 3)
- {
- return Error::USER_DATA;
- }
- DynamicArrayAuto<CString> cfilenames(filenames.getAllocator(), filenames.getSize());
- for(U32 i = 0; i < filenames.getSize(); ++i)
- {
- cfilenames[i] = filenames[i];
- }
- config.m_inputFilenames = ConstWeakArray<CString>(&cfilenames[0], cfilenames.getSize() - 1);
- config.m_outFilename = cfilenames.getBack();
- return Error::NONE;
- }
- int main(int argc, char** argv)
- {
- HeapAllocator<U8> alloc(allocAligned, nullptr);
- ImageImporterConfig config;
- config.m_allocator = alloc;
- DynamicArrayAuto<StringAuto> filenames(alloc);
- if(parseCommandLineArgs(argc, argv, config, filenames))
- {
- ANKI_IMPORTER_LOGE(USAGE, argv[0]);
- return 1;
- }
- if(importImage(config))
- {
- ANKI_IMPORTER_LOGE("Importing failed");
- return 1;
- }
- return 0;
- }
|