|
|
@@ -370,6 +370,7 @@ void help(const char* _error = NULL)
|
|
|
" --iqa Image Quality Assesment\n"
|
|
|
" --max <max size> Maximum width/height (image will be scaled down and\n"
|
|
|
" aspect ratio will be preserved.\n"
|
|
|
+ " --as <extension> Save as.\n"
|
|
|
|
|
|
"\n"
|
|
|
"For additional information, see https://github.com/bkaradzic/bgfx\n"
|
|
|
@@ -400,6 +401,14 @@ int main(int _argc, const char* _argv[])
|
|
|
return EXIT_FAILURE;
|
|
|
}
|
|
|
|
|
|
+ const char* saveAs = cmdLine.findOption("as");
|
|
|
+ saveAs = NULL == saveAs ? bx::strFindI(outputFileName, ".ktx") : saveAs;
|
|
|
+ if (NULL == saveAs)
|
|
|
+ {
|
|
|
+ help("Output file format must be specified.");
|
|
|
+ return EXIT_FAILURE;
|
|
|
+ }
|
|
|
+
|
|
|
Options options;
|
|
|
|
|
|
const char* edgeOpt = cmdLine.findOption("sdf");
|
|
|
@@ -419,13 +428,6 @@ int main(int _argc, const char* _argv[])
|
|
|
options.maxSize = atoi(maxSize);
|
|
|
}
|
|
|
|
|
|
- bx::CrtFileReader reader;
|
|
|
- if (!bx::open(&reader, inputFileName) )
|
|
|
- {
|
|
|
- help("Failed to open input file.");
|
|
|
- return EXIT_FAILURE;
|
|
|
- }
|
|
|
-
|
|
|
options.format = bimg::TextureFormat::Count;
|
|
|
const char* type = cmdLine.findOption('t');
|
|
|
if (NULL != type)
|
|
|
@@ -439,14 +441,28 @@ int main(int _argc, const char* _argv[])
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ bx::CrtFileReader reader;
|
|
|
+ if (!bx::open(&reader, inputFileName) )
|
|
|
+ {
|
|
|
+ help("Failed to open input file.");
|
|
|
+ return EXIT_FAILURE;
|
|
|
+ }
|
|
|
+
|
|
|
bx::CrtAllocator allocator;
|
|
|
|
|
|
uint32_t inputSize = (uint32_t)bx::getSize(&reader);
|
|
|
uint8_t* inputData = (uint8_t*)BX_ALLOC(&allocator, inputSize);
|
|
|
|
|
|
- bx::read(&reader, inputData, inputSize);
|
|
|
+ bx::Error err;
|
|
|
+ bx::read(&reader, inputData, inputSize, &err);
|
|
|
bx::close(&reader);
|
|
|
|
|
|
+ if (!err.isOk() )
|
|
|
+ {
|
|
|
+ help("Failed to read input file.");
|
|
|
+ return EXIT_FAILURE;
|
|
|
+ }
|
|
|
+
|
|
|
bimg::ImageContainer* output = convert(&allocator, inputData, inputSize, options);
|
|
|
|
|
|
BX_FREE(&allocator, inputData);
|
|
|
@@ -456,7 +472,7 @@ int main(int _argc, const char* _argv[])
|
|
|
bx::CrtFileWriter writer;
|
|
|
if (bx::open(&writer, outputFileName) )
|
|
|
{
|
|
|
- if (NULL != bx::stristr(outputFileName, ".ktx") )
|
|
|
+ if (NULL != bx::strFindI(saveAs, "ktx") )
|
|
|
{
|
|
|
bimg::imageWriteKtx(&writer, *output, output->m_data, output->m_size);
|
|
|
}
|