texturec.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. /*
  2. * Copyright 2011-2017 Branimir Karadzic. All rights reserved.
  3. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
  4. */
  5. #include <stdio.h>
  6. #include <bx/allocator.h>
  7. #include <bx/readerwriter.h>
  8. #include <bx/endian.h>
  9. #include <bimg/decode.h>
  10. #include <bimg/encode.h>
  11. #if 0
  12. # define DBG(_format, ...) fprintf(stderr, "" _format "\n", ##__VA_ARGS__)
  13. #else
  14. # define DBG(...) BX_NOOP()
  15. #endif // DEBUG
  16. #include <bx/bx.h>
  17. #include <bx/commandline.h>
  18. #include <bx/crtimpl.h>
  19. #include <bx/uint32_t.h>
  20. #include <string>
  21. #define BIMG_TEXTUREC_VERSION_MAJOR 1
  22. #define BIMG_TEXTUREC_VERSION_MINOR 4
  23. struct Options
  24. {
  25. Options()
  26. : maxSize(UINT32_MAX)
  27. , edge(0.0f)
  28. , format(bimg::TextureFormat::Count)
  29. , quality(bimg::Quality::Default)
  30. , mips(false)
  31. , normalMap(false)
  32. , iqa(false)
  33. , sdf(false)
  34. , alphaTest(false)
  35. {
  36. }
  37. void dump()
  38. {
  39. DBG("Options:\n"
  40. "\t maxSize: %d\n"
  41. "\t edge: %f\n"
  42. "\t format: %s\n"
  43. "\t mips: %s\n"
  44. "\tnormalMap: %s\n"
  45. "\t iqa: %s\n"
  46. "\t sdf: %s\n"
  47. , maxSize
  48. , edge
  49. , bimg::getName(format)
  50. , mips ? "true" : "false"
  51. , normalMap ? "true" : "false"
  52. , iqa ? "true" : "false"
  53. , sdf ? "true" : "false"
  54. );
  55. }
  56. uint32_t maxSize;
  57. float edge;
  58. bimg::TextureFormat::Enum format;
  59. bimg::Quality::Enum quality;
  60. bool mips;
  61. bool normalMap;
  62. bool iqa;
  63. bool sdf;
  64. bool alphaTest;
  65. };
  66. bimg::ImageContainer* convert(bx::AllocatorI* _allocator, const void* _inputData, uint32_t _inputSize, const Options& _options, bx::Error* _err)
  67. {
  68. BX_ERROR_SCOPE(_err);
  69. const uint8_t* inputData = (uint8_t*)_inputData;
  70. bimg::ImageContainer* output = NULL;
  71. bimg::ImageContainer* input = bimg::imageParse(_allocator, inputData, _inputSize, bimg::TextureFormat::Count, _err);
  72. if (!_err->isOk() )
  73. {
  74. return NULL;
  75. }
  76. if (NULL != input)
  77. {
  78. const bimg::TextureFormat::Enum inputFormat = input->m_format;
  79. bimg::TextureFormat::Enum outputFormat = input->m_format;
  80. if (bimg::TextureFormat::Count != _options.format)
  81. {
  82. outputFormat = _options.format;
  83. }
  84. const bimg::ImageBlockInfo& inputBlockInfo = bimg::getBlockInfo(inputFormat);
  85. const bimg::ImageBlockInfo& outputBlockInfo = bimg::getBlockInfo(outputFormat);
  86. const uint32_t blockWidth = outputBlockInfo.blockWidth;
  87. const uint32_t blockHeight = outputBlockInfo.blockHeight;
  88. const uint32_t minBlockX = outputBlockInfo.minBlockX;
  89. const uint32_t minBlockY = outputBlockInfo.minBlockY;
  90. uint32_t outputWidth = bx::uint32_max(blockWidth * minBlockX, ( (input->m_width + blockWidth - 1) / blockWidth )*blockWidth);
  91. uint32_t outputHeight = bx::uint32_max(blockHeight * minBlockY, ( (input->m_height + blockHeight - 1) / blockHeight)*blockHeight);
  92. if (outputWidth > _options.maxSize
  93. || outputHeight > _options.maxSize)
  94. {
  95. if (outputWidth > outputHeight)
  96. {
  97. outputHeight = outputHeight * _options.maxSize / outputWidth;
  98. outputWidth = _options.maxSize;
  99. }
  100. else
  101. {
  102. outputWidth = outputWidth * _options.maxSize / outputHeight;
  103. outputHeight = _options.maxSize;
  104. }
  105. }
  106. const bool needResize = false
  107. || input->m_width != outputWidth
  108. || input->m_height != outputHeight
  109. ;
  110. const bool passThru = true
  111. && inputFormat == outputFormat
  112. && !needResize
  113. && (1 < input->m_numMips) == _options.mips
  114. && !_options.sdf
  115. && !_options.alphaTest
  116. && !_options.normalMap
  117. && !_options.iqa
  118. ;
  119. if (needResize)
  120. {
  121. bimg::ImageContainer* src = bimg::imageConvert(_allocator, bimg::TextureFormat::RGBA32F, *input);
  122. bimg::ImageContainer* dst = bimg::imageAlloc(
  123. _allocator
  124. , bimg::TextureFormat::RGBA32F
  125. , uint16_t(outputWidth)
  126. , uint16_t(outputHeight)
  127. , 1
  128. , input->m_numLayers
  129. , input->m_cubeMap
  130. , false
  131. );
  132. bimg::imageResizeRgba32fLinear(dst, src);
  133. bimg::imageFree(src);
  134. bimg::imageFree(input);
  135. input = bimg::imageConvert(_allocator, inputFormat, *dst);
  136. bimg::imageFree(dst);
  137. }
  138. if (passThru)
  139. {
  140. output = bimg::imageConvert(_allocator, outputFormat, *input);
  141. bimg::imageFree(input);
  142. return output;
  143. }
  144. output = bimg::imageAlloc(
  145. _allocator
  146. , outputFormat
  147. , uint16_t(input->m_width)
  148. , uint16_t(input->m_height)
  149. , uint16_t(input->m_depth)
  150. , input->m_numLayers
  151. , input->m_cubeMap
  152. , _options.mips
  153. );
  154. const uint8_t numMips = output->m_numMips;
  155. const uint16_t numSides = output->m_numLayers * (output->m_cubeMap ? 6 : 1);
  156. for (uint16_t side = 0; side < numSides && _err->isOk(); ++side)
  157. {
  158. bimg::ImageMip mip;
  159. if (bimg::imageGetRawData(*input, side, 0, input->m_data, input->m_size, mip) )
  160. {
  161. bimg::ImageMip dstMip;
  162. bimg::imageGetRawData(*output, side, 0, output->m_data, output->m_size, dstMip);
  163. uint8_t* dstData = const_cast<uint8_t*>(dstMip.m_data);
  164. void* temp = NULL;
  165. if (_options.normalMap)
  166. {
  167. uint32_t size = bimg::imageGetSize(
  168. NULL
  169. , uint16_t(dstMip.m_width)
  170. , uint16_t(dstMip.m_height)
  171. , 0
  172. , false
  173. , false
  174. , 1
  175. , bimg::TextureFormat::RGBA32F
  176. );
  177. temp = BX_ALLOC(_allocator, size);
  178. float* rgba = (float*)temp;
  179. float* rgbaDst = (float*)BX_ALLOC(_allocator, size);
  180. bimg::imageDecodeToRgba32f(_allocator
  181. , rgba
  182. , mip.m_data
  183. , dstMip.m_width
  184. , dstMip.m_height
  185. , dstMip.m_width*16
  186. , mip.m_format
  187. );
  188. if (bimg::TextureFormat::BC5 != mip.m_format)
  189. {
  190. for (uint32_t yy = 0; yy < mip.m_height; ++yy)
  191. {
  192. for (uint32_t xx = 0; xx < mip.m_width; ++xx)
  193. {
  194. const uint32_t offset = (yy*mip.m_width + xx) * 4;
  195. float* inout = &rgba[offset];
  196. inout[0] = inout[0] * 2.0f - 1.0f;
  197. inout[1] = inout[1] * 2.0f - 1.0f;
  198. inout[2] = inout[2] * 2.0f - 1.0f;
  199. inout[3] = inout[3] * 2.0f - 1.0f;
  200. }
  201. }
  202. }
  203. bimg::imageRgba32f11to01(rgbaDst
  204. , dstMip.m_width
  205. , dstMip.m_height
  206. , dstMip.m_width*16
  207. , rgba
  208. );
  209. bimg::imageEncodeFromRgba32f(_allocator
  210. , dstData
  211. , rgbaDst
  212. , dstMip.m_width
  213. , dstMip.m_height
  214. , outputFormat
  215. , _options.quality
  216. , _err
  217. );
  218. for (uint8_t lod = 1; lod < numMips && _err->isOk(); ++lod)
  219. {
  220. bimg::imageRgba32fDownsample2x2NormalMap(rgba
  221. , dstMip.m_width
  222. , dstMip.m_height
  223. , dstMip.m_width*16
  224. , rgba
  225. );
  226. bimg::imageRgba32f11to01(rgbaDst
  227. , dstMip.m_width
  228. , dstMip.m_height
  229. , dstMip.m_width*16
  230. , rgba
  231. );
  232. bimg::imageGetRawData(*output, side, lod, output->m_data, output->m_size, dstMip);
  233. dstData = const_cast<uint8_t*>(dstMip.m_data);
  234. bimg::imageEncodeFromRgba32f(_allocator
  235. , dstData
  236. , rgbaDst
  237. , dstMip.m_width
  238. , dstMip.m_height
  239. , outputFormat
  240. , _options.quality
  241. , _err
  242. );
  243. }
  244. BX_FREE(_allocator, rgbaDst);
  245. }
  246. else if (!bimg::isCompressed(input->m_format)
  247. && 8 != inputBlockInfo.rBits)
  248. {
  249. uint32_t size = bimg::imageGetSize(
  250. NULL
  251. , uint16_t(dstMip.m_width)
  252. , uint16_t(dstMip.m_height)
  253. , 0
  254. , false
  255. , false
  256. , 1
  257. , bimg::TextureFormat::RGBA32F
  258. );
  259. temp = BX_ALLOC(_allocator, size);
  260. float* rgba32f = (float*)temp;
  261. float* rgbaDst = (float*)BX_ALLOC(_allocator, size);
  262. bimg::imageDecodeToRgba32f(_allocator
  263. , rgba32f
  264. , mip.m_data
  265. , mip.m_width
  266. , mip.m_height
  267. , mip.m_width*16
  268. , mip.m_format
  269. );
  270. bimg::imageEncodeFromRgba32f(_allocator
  271. , dstData
  272. , rgba32f
  273. , dstMip.m_width
  274. , dstMip.m_height
  275. , outputFormat
  276. , _options.quality
  277. , _err
  278. );
  279. if (1 < numMips
  280. && _err->isOk() )
  281. {
  282. bimg::imageRgba32fToLinear(rgba32f
  283. , mip.m_width
  284. , mip.m_height
  285. , mip.m_width*16
  286. , rgba32f
  287. );
  288. for (uint8_t lod = 1; lod < numMips && _err->isOk(); ++lod)
  289. {
  290. bimg::imageRgba32fLinearDownsample2x2(rgba32f
  291. , dstMip.m_width
  292. , dstMip.m_height
  293. , dstMip.m_width*16
  294. , rgba32f
  295. );
  296. bimg::imageGetRawData(*output, side, lod, output->m_data, output->m_size, dstMip);
  297. dstData = const_cast<uint8_t*>(dstMip.m_data);
  298. bimg::imageRgba32fToGamma(rgbaDst
  299. , mip.m_width
  300. , mip.m_height
  301. , mip.m_width*16
  302. , rgba32f
  303. );
  304. bimg::imageEncodeFromRgba32f(_allocator
  305. , dstData
  306. , rgbaDst
  307. , dstMip.m_width
  308. , dstMip.m_height
  309. , outputFormat
  310. , _options.quality
  311. , _err
  312. );
  313. }
  314. }
  315. BX_FREE(_allocator, rgbaDst);
  316. }
  317. else
  318. {
  319. uint32_t size = bimg::imageGetSize(
  320. NULL
  321. , uint16_t(dstMip.m_width)
  322. , uint16_t(dstMip.m_height)
  323. , 0
  324. , false
  325. , false
  326. , 1
  327. , bimg::TextureFormat::RGBA8
  328. );
  329. temp = BX_ALLOC(_allocator, size);
  330. uint8_t* rgba = (uint8_t*)temp;
  331. bimg::imageDecodeToRgba8(rgba
  332. , mip.m_data
  333. , mip.m_width
  334. , mip.m_height
  335. , mip.m_width*4
  336. , mip.m_format
  337. );
  338. float coverage = 0.0f;
  339. if (_options.alphaTest)
  340. {
  341. coverage = bimg::imageAlphaTestCoverage(bimg::TextureFormat::RGBA8
  342. , mip.m_width
  343. , mip.m_height
  344. , mip.m_width*4
  345. , rgba
  346. , _options.edge
  347. );
  348. }
  349. void* ref = NULL;
  350. if (_options.iqa)
  351. {
  352. ref = BX_ALLOC(_allocator, size);
  353. bx::memCopy(ref, rgba, size);
  354. }
  355. bimg::imageGetRawData(*output, side, 0, output->m_data, output->m_size, dstMip);
  356. dstData = const_cast<uint8_t*>(dstMip.m_data);
  357. bimg::imageEncodeFromRgba8(dstData
  358. , rgba
  359. , dstMip.m_width
  360. , dstMip.m_height
  361. , outputFormat
  362. , _options.quality
  363. , _err
  364. );
  365. for (uint8_t lod = 1; lod < numMips && _err->isOk(); ++lod)
  366. {
  367. bimg::imageRgba8Downsample2x2(rgba
  368. , dstMip.m_width
  369. , dstMip.m_height
  370. , dstMip.m_width*4
  371. , rgba
  372. );
  373. if (_options.alphaTest)
  374. {
  375. bimg::imageScaleAlphaToCoverage(bimg::TextureFormat::RGBA8
  376. , dstMip.m_width
  377. , dstMip.m_height
  378. , dstMip.m_width*4
  379. , rgba
  380. , coverage
  381. , _options.edge
  382. );
  383. }
  384. bimg::imageGetRawData(*output, side, lod, output->m_data, output->m_size, dstMip);
  385. dstData = const_cast<uint8_t*>(dstMip.m_data);
  386. bimg::imageEncodeFromRgba8(dstData
  387. , rgba
  388. , dstMip.m_width
  389. , dstMip.m_height
  390. , outputFormat
  391. , _options.quality
  392. , _err
  393. );
  394. }
  395. if (NULL != ref)
  396. {
  397. bimg::imageDecodeToRgba8(rgba
  398. , output->m_data
  399. , mip.m_width
  400. , mip.m_height
  401. , mip.m_width*mip.m_bpp/8
  402. , outputFormat
  403. );
  404. float result = bimg::imageQualityRgba8(
  405. ref
  406. , rgba
  407. , uint16_t(mip.m_width)
  408. , uint16_t(mip.m_height)
  409. );
  410. printf("%f\n", result);
  411. BX_FREE(_allocator, ref);
  412. }
  413. }
  414. BX_FREE(_allocator, temp);
  415. }
  416. }
  417. bimg::imageFree(input);
  418. }
  419. if (!_err->isOk()
  420. && NULL != output)
  421. {
  422. bimg::imageFree(output);
  423. output = NULL;
  424. }
  425. return output;
  426. }
  427. void help(const char* _error = NULL, bool _showHelp = true)
  428. {
  429. if (NULL != _error)
  430. {
  431. fprintf(stderr, "Error:\n%s\n\n", _error);
  432. if (!_showHelp)
  433. {
  434. return;
  435. }
  436. }
  437. fprintf(stderr
  438. , "texturec, bgfx texture compiler tool, version %d.%d.%d.\n"
  439. "Copyright 2011-2017 Branimir Karadzic. All rights reserved.\n"
  440. "License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause\n\n"
  441. , BIMG_TEXTUREC_VERSION_MAJOR
  442. , BIMG_TEXTUREC_VERSION_MINOR
  443. , BIMG_API_VERSION
  444. );
  445. fprintf(stderr
  446. , "Usage: texturec -f <in> -o <out> [-t <texture format>]\n"
  447. "\n"
  448. "Supported file formats:\n"
  449. " *.bmp (input) Windows Bitmap.\n"
  450. " *.dds (input, output) Direct Draw Surface.\n"
  451. " *.exr (input) OpenEXR.\n"
  452. " *.gif (input) Graphics Interchange Format.\n"
  453. " *.jpg (input) JPEG Interchange Format.\n"
  454. " *.hdr (input) Radiance RGBE.\n"
  455. " *.ktx (input, output) Khronos Texture.\n"
  456. " *.png (input) Portable Network Graphics.\n"
  457. " *.psd (input) Photoshop Document.\n"
  458. " *.pvr (input) PowerVR.\n"
  459. " *.tga (input) Targa.\n"
  460. "\n"
  461. "Options:\n"
  462. " -h, --help Help.\n"
  463. " -v, --version Version information only.\n"
  464. " -f <file path> Input file path.\n"
  465. " -o <file path> Output file path.\n"
  466. " -t <format> Output format type (BC1/2/3/4/5, ETC1, PVR14, etc.).\n"
  467. " -q <quality> Encoding quality (default, fastest, highest).\n"
  468. " -m, --mips Generate mip-maps.\n"
  469. " -n, --normalmap Input texture is normal map.\n"
  470. " --sdf <edge> Compute SDF texture.\n"
  471. " --ref <alpha> Alpha reference value.\n"
  472. " --iqa Image Quality Assessment\n"
  473. " --max <max size> Maximum width/height (image will be scaled down and\n"
  474. " aspect ratio will be preserved.\n"
  475. " --as <extension> Save as.\n"
  476. "\n"
  477. "For additional information, see https://github.com/bkaradzic/bgfx\n"
  478. );
  479. }
  480. void help(const char* _str, const bx::Error& _err)
  481. {
  482. std::string str;
  483. if (_str != NULL)
  484. {
  485. str.append(_str);
  486. str.append(" ");
  487. }
  488. const bx::StringView& sv = _err.getMessage();
  489. str.append(sv.getPtr(), sv.getTerm() - sv.getPtr() );
  490. help(str.c_str(), false);
  491. }
  492. int main(int _argc, const char* _argv[])
  493. {
  494. bx::CommandLine cmdLine(_argc, _argv);
  495. if (cmdLine.hasArg('v', "version") )
  496. {
  497. fprintf(stderr
  498. , "texturec, bgfx texture compiler tool, version %d.%d.%d.\n"
  499. , BIMG_TEXTUREC_VERSION_MAJOR
  500. , BIMG_TEXTUREC_VERSION_MINOR
  501. , BIMG_API_VERSION
  502. );
  503. return bx::kExitSuccess;
  504. }
  505. if (cmdLine.hasArg('h', "help") )
  506. {
  507. help();
  508. return bx::kExitFailure;
  509. }
  510. const char* inputFileName = cmdLine.findOption('f');
  511. if (NULL == inputFileName)
  512. {
  513. help("Input file must be specified.");
  514. return bx::kExitFailure;
  515. }
  516. const char* outputFileName = cmdLine.findOption('o');
  517. if (NULL == outputFileName)
  518. {
  519. help("Output file must be specified.");
  520. return bx::kExitFailure;
  521. }
  522. const char* saveAs = cmdLine.findOption("as");
  523. saveAs = NULL == saveAs ? bx::strFindI(outputFileName, ".ktx") : saveAs;
  524. saveAs = NULL == saveAs ? bx::strFindI(outputFileName, ".dds") : saveAs;
  525. if (NULL == saveAs)
  526. {
  527. help("Output file format must be specified.");
  528. return bx::kExitFailure;
  529. }
  530. Options options;
  531. const char* edgeOpt = cmdLine.findOption("sdf");
  532. if (NULL != edgeOpt)
  533. {
  534. options.sdf = true;
  535. options.edge = (float)atof(edgeOpt);
  536. }
  537. else
  538. {
  539. const char* alphaRef = cmdLine.findOption("ref");
  540. if (NULL != alphaRef)
  541. {
  542. options.alphaTest = true;
  543. options.edge = (float)atof(alphaRef);
  544. }
  545. }
  546. options.mips = cmdLine.hasArg('m', "mips");
  547. options.normalMap = cmdLine.hasArg('n', "normalmap");
  548. options.iqa = cmdLine.hasArg('\0', "iqa");
  549. const char* maxSize = cmdLine.findOption("max");
  550. if (NULL != maxSize)
  551. {
  552. options.maxSize = atoi(maxSize);
  553. }
  554. options.format = bimg::TextureFormat::Count;
  555. const char* type = cmdLine.findOption('t');
  556. if (NULL != type)
  557. {
  558. options.format = bimg::getFormat(type);
  559. if (!bimg::isValid(options.format) )
  560. {
  561. help("Invalid format specified.");
  562. return bx::kExitFailure;
  563. }
  564. }
  565. const char* quality = cmdLine.findOption('q');
  566. if (NULL != quality)
  567. {
  568. switch (bx::toLower(quality[0]) )
  569. {
  570. case 'h': options.quality = bimg::Quality::Highest; break;
  571. case 'f': options.quality = bimg::Quality::Fastest; break;
  572. case 'd': options.quality = bimg::Quality::Default; break;
  573. default:
  574. help("Invalid quality specified.");
  575. return bx::kExitFailure;
  576. }
  577. }
  578. bx::Error err;
  579. bx::FileReader reader;
  580. if (!bx::open(&reader, inputFileName, &err) )
  581. {
  582. help("Failed to open input file.", err);
  583. return bx::kExitFailure;
  584. }
  585. uint32_t inputSize = (uint32_t)bx::getSize(&reader);
  586. if (0 == inputSize)
  587. {
  588. help("Failed to read input file.", err);
  589. return bx::kExitFailure;
  590. }
  591. bx::DefaultAllocator allocator;
  592. uint8_t* inputData = (uint8_t*)BX_ALLOC(&allocator, inputSize);
  593. bx::read(&reader, inputData, inputSize, &err);
  594. bx::close(&reader);
  595. if (!err.isOk() )
  596. {
  597. help("Failed to read input file.", err);
  598. return bx::kExitFailure;
  599. }
  600. bimg::ImageContainer* output = convert(&allocator, inputData, inputSize, options, &err);
  601. BX_FREE(&allocator, inputData);
  602. if (NULL != output)
  603. {
  604. bx::FileWriter writer;
  605. if (bx::open(&writer, outputFileName, false, &err) )
  606. {
  607. if (NULL != bx::strFindI(saveAs, "ktx") )
  608. {
  609. bimg::imageWriteKtx(&writer, *output, output->m_data, output->m_size, &err);
  610. }
  611. else if (NULL != bx::strFindI(saveAs, "dds") )
  612. {
  613. bimg::imageWriteDds(&writer, *output, output->m_data, output->m_size, &err);
  614. }
  615. bx::close(&writer);
  616. if (!err.isOk() )
  617. {
  618. help(NULL, err);
  619. return bx::kExitFailure;
  620. }
  621. }
  622. else
  623. {
  624. help("Failed to open output file.", err);
  625. return bx::kExitFailure;
  626. }
  627. bimg::imageFree(output);
  628. }
  629. else
  630. {
  631. help(NULL, err);
  632. return bx::kExitFailure;
  633. }
  634. return bx::kExitSuccess;
  635. }