texturec.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. /*
  2. * Copyright 2011-2016 Branimir Karadzic. All rights reserved.
  3. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
  4. */
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. // Just hacking DDS loading code in here.
  9. #include "bgfx_p.h"
  10. #include "image.h"
  11. #include <libsquish/squish.h>
  12. #include <etc1/etc1.h>
  13. #include <etc2/ProcessRGB.hpp>
  14. #include <nvtt/nvtt.h>
  15. #include <pvrtc/PvrTcEncoder.h>
  16. #include <tinyexr/tinyexr.h>
  17. #include <edtaa3/edtaa3func.h>
  18. extern "C" {
  19. #include <iqa.h>
  20. }
  21. #define STB_IMAGE_IMPLEMENTATION
  22. #include <stb/stb_image.c>
  23. #if 0
  24. # define BX_TRACE(_format, ...) fprintf(stderr, "" _format "\n", ##__VA_ARGS__)
  25. #endif // DEBUG
  26. #include <bx/bx.h>
  27. #include <bx/commandline.h>
  28. #include <bx/crtimpl.h>
  29. #include <bx/uint32_t.h>
  30. namespace bgfx
  31. {
  32. const Memory* alloc(uint32_t _size)
  33. {
  34. Memory* mem = (Memory*)::realloc(NULL, sizeof(Memory) + _size);
  35. mem->size = _size;
  36. mem->data = (uint8_t*)mem + sizeof(Memory);
  37. return mem;
  38. }
  39. const Memory* makeRef(const void* _data, uint32_t _size, ReleaseFn _releaseFn, void* _userData)
  40. {
  41. BX_UNUSED(_releaseFn, _userData);
  42. Memory* mem = (Memory*)::realloc(NULL, sizeof(Memory) );
  43. mem->size = _size;
  44. mem->data = (uint8_t*)_data;
  45. return mem;
  46. }
  47. void release(const Memory* _mem)
  48. {
  49. Memory* mem = const_cast<Memory*>(_mem);
  50. ::free(mem);
  51. }
  52. bool imageEncodeFromRgba8(void* _dst, const void* _src, uint32_t _width, uint32_t _height, uint8_t _format)
  53. {
  54. TextureFormat::Enum format = TextureFormat::Enum(_format);
  55. switch (format)
  56. {
  57. case TextureFormat::BC1:
  58. case TextureFormat::BC2:
  59. case TextureFormat::BC3:
  60. case TextureFormat::BC4:
  61. case TextureFormat::BC5:
  62. squish::CompressImage( (const uint8_t*)_src, _width, _height, _dst
  63. , format == TextureFormat::BC2 ? squish::kDxt3
  64. : format == TextureFormat::BC3 ? squish::kDxt5
  65. : format == TextureFormat::BC4 ? squish::kBc4
  66. : format == TextureFormat::BC5 ? squish::kBc5
  67. : squish::kDxt1
  68. );
  69. return true;
  70. case TextureFormat::BC6H:
  71. nvtt::compressBC6H( (const uint8_t*)_src, _width, _height, 4, _dst);
  72. return true;
  73. case TextureFormat::BC7:
  74. nvtt::compressBC7( (const uint8_t*)_src, _width, _height, 4, _dst);
  75. return true;
  76. case TextureFormat::ETC1:
  77. etc1_encode_image( (const uint8_t*)_src, _width, _height, 4, _width*4, (uint8_t*)_dst);
  78. return true;
  79. case TextureFormat::ETC2:
  80. {
  81. const uint32_t blockWidth = (_width +3)/4;
  82. const uint32_t blockHeight = (_height+3)/4;
  83. const uint32_t pitch = _width*4;
  84. const uint8_t* src = (const uint8_t*)_src;
  85. uint64_t* dst = (uint64_t*)_dst;
  86. for (uint32_t yy = 0; yy < blockHeight; ++yy)
  87. {
  88. for (uint32_t xx = 0; xx < blockWidth; ++xx)
  89. {
  90. uint8_t block[4*4*4];
  91. const uint8_t* ptr = &src[(yy*pitch+xx*4)*4];
  92. for (uint32_t ii = 0; ii < 16; ++ii)
  93. { // BGRx
  94. memcpy(&block[ii*4], &ptr[(ii%4)*pitch + (ii&~3)], 4);
  95. bx::xchg(block[ii*4+0], block[ii*4+2]);
  96. }
  97. *dst++ = ProcessRGB_ETC2(block);
  98. }
  99. }
  100. }
  101. return true;
  102. case TextureFormat::PTC14:
  103. {
  104. using namespace Javelin;
  105. RgbaBitmap bmp;
  106. bmp.width = _width;
  107. bmp.height = _height;
  108. bmp.data = (uint8_t*)const_cast<void*>(_src);
  109. PvrTcEncoder::EncodeRgb4Bpp(_dst, bmp);
  110. bmp.data = NULL;
  111. }
  112. return true;
  113. case TextureFormat::PTC14A:
  114. {
  115. using namespace Javelin;
  116. RgbaBitmap bmp;
  117. bmp.width = _width;
  118. bmp.height = _height;
  119. bmp.data = (uint8_t*)const_cast<void*>(_src);
  120. PvrTcEncoder::EncodeRgba4Bpp(_dst, bmp);
  121. bmp.data = NULL;
  122. }
  123. return true;
  124. case TextureFormat::BGRA8:
  125. imageSwizzleBgra8(_width, _height, _width*4, _src, _dst);
  126. return true;
  127. case TextureFormat::RGBA8:
  128. memcpy(_dst, _src, _width*_height*4);
  129. return true;
  130. default:
  131. return imageConvert(_dst, format, _src, TextureFormat::RGBA8, _width, _height);
  132. }
  133. return false;
  134. }
  135. bool imageEncodeFromRgba32f(bx::AllocatorI* _allocator, void* _dst, const void* _src, uint32_t _width, uint32_t _height, uint8_t _format)
  136. {
  137. TextureFormat::Enum format = TextureFormat::Enum(_format);
  138. const uint8_t* src = (const uint8_t*)_src;
  139. switch (format)
  140. {
  141. case TextureFormat::RGBA8:
  142. {
  143. uint8_t* dst = (uint8_t*)_dst;
  144. for (uint32_t yy = 0; yy < _height; ++yy)
  145. {
  146. for (uint32_t xx = 0; xx < _width; ++xx)
  147. {
  148. const uint32_t offset = yy*_width + xx;
  149. const float* input = (const float*)&src[offset * 16];
  150. uint8_t* output = &dst[offset * 4];
  151. output[0] = uint8_t(input[0]*255.0f + 0.5f);
  152. output[1] = uint8_t(input[1]*255.0f + 0.5f);
  153. output[2] = uint8_t(input[2]*255.0f + 0.5f);
  154. output[3] = uint8_t(input[3]*255.0f + 0.5f);
  155. }
  156. }
  157. }
  158. return true;
  159. case TextureFormat::BC5:
  160. {
  161. uint8_t* temp = (uint8_t*)BX_ALLOC(_allocator, _width*_height*4);
  162. for (uint32_t yy = 0; yy < _height; ++yy)
  163. {
  164. for (uint32_t xx = 0; xx < _width; ++xx)
  165. {
  166. const uint32_t offset = yy*_width + xx;
  167. const float* input = (const float*)&src[offset * 16];
  168. uint8_t* output = &temp[offset * 4];
  169. output[0] = uint8_t(input[0]*255.0f + 0.5f);
  170. output[1] = uint8_t(input[1]*255.0f + 0.5f);
  171. output[2] = uint8_t(input[2]*255.0f + 0.5f);
  172. output[3] = uint8_t(input[3]*255.0f + 0.5f);
  173. }
  174. }
  175. imageEncodeFromRgba8(_dst, temp, _width, _height, _format);
  176. BX_FREE(_allocator, temp);
  177. }
  178. return true;
  179. default:
  180. return imageConvert(_dst, format, _src, TextureFormat::RGBA32F, _width, _height);
  181. }
  182. return false;
  183. }
  184. void imageRgba32f11to01(void* _dst, uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _src)
  185. {
  186. const uint8_t* src = (const uint8_t*)_src;
  187. uint8_t* dst = (uint8_t*)_dst;
  188. for (uint32_t yy = 0; yy < _height; ++yy)
  189. {
  190. for (uint32_t xx = 0; xx < _width; ++xx)
  191. {
  192. const uint32_t offset = yy*_pitch + xx * 16;
  193. const float* input = (const float*)&src[offset];
  194. float* output = (float*)&dst[offset];
  195. output[0] = input[0]*0.5f + 0.5f;
  196. output[1] = input[1]*0.5f + 0.5f;
  197. output[2] = input[2]*0.5f + 0.5f;
  198. output[3] = input[3]*0.5f + 0.5f;
  199. }
  200. }
  201. }
  202. static void edtaa3(bx::AllocatorI* _allocator, double* _dst, uint32_t _width, uint32_t _height, double* _src)
  203. {
  204. const uint32_t numPixels = _width*_height;
  205. short* xdist = (short *)BX_ALLOC(_allocator, numPixels*sizeof(short) );
  206. short* ydist = (short *)BX_ALLOC(_allocator, numPixels*sizeof(short) );
  207. double* gx = (double*)BX_ALLOC(_allocator, numPixels*sizeof(double) );
  208. double* gy = (double*)BX_ALLOC(_allocator, numPixels*sizeof(double) );
  209. ::computegradient(_src, _width, _height, gx, gy);
  210. ::edtaa3(_src, gx, gy, _width, _height, xdist, ydist, _dst);
  211. for (uint32_t ii = 0; ii < numPixels; ++ii)
  212. {
  213. if (_dst[ii] < 0.0)
  214. {
  215. _dst[ii] = 0.0;
  216. }
  217. }
  218. BX_FREE(_allocator, xdist);
  219. BX_FREE(_allocator, ydist);
  220. BX_FREE(_allocator, gx);
  221. BX_FREE(_allocator, gy);
  222. }
  223. inline double min(double _a, double _b)
  224. {
  225. return _a > _b ? _b : _a;
  226. }
  227. inline double max(double _a, double _b)
  228. {
  229. return _a > _b ? _a : _b;
  230. }
  231. inline double clamp(double _val, double _min, double _max)
  232. {
  233. return max(min(_val, _max), _min);
  234. }
  235. void imageMakeDist(bx::AllocatorI* _allocator, void* _dst, uint32_t _width, uint32_t _height, uint32_t _pitch, float _edge, const void* _src)
  236. {
  237. const uint32_t numPixels = _width*_height;
  238. double* imgIn = (double*)BX_ALLOC(_allocator, numPixels*sizeof(double) );
  239. double* outside = (double*)BX_ALLOC(_allocator, numPixels*sizeof(double) );
  240. double* inside = (double*)BX_ALLOC(_allocator, numPixels*sizeof(double) );
  241. for (uint32_t yy = 0; yy < _height; ++yy)
  242. {
  243. const uint8_t* src = (const uint8_t*)_src + yy*_pitch;
  244. double* dst = &imgIn[yy*_width];
  245. for (uint32_t xx = 0; xx < _width; ++xx)
  246. {
  247. dst[xx] = double(src[xx])/255.0;
  248. }
  249. }
  250. edtaa3(_allocator, outside, _width, _height, imgIn);
  251. for (uint32_t ii = 0; ii < numPixels; ++ii)
  252. {
  253. imgIn[ii] = 1.0 - imgIn[ii];
  254. }
  255. edtaa3(_allocator, inside, _width, _height, imgIn);
  256. BX_FREE(_allocator, imgIn);
  257. uint8_t* dst = (uint8_t*)_dst;
  258. double edgeOffset = _edge*0.5;
  259. double invEdge = 1.0/_edge;
  260. for (uint32_t ii = 0; ii < numPixels; ++ii)
  261. {
  262. double dist = clamp( ( (outside[ii] - inside[ii])+edgeOffset) * invEdge, 0.0, 1.0);
  263. dst[ii] = 255-uint8_t(dist * 255.0);
  264. }
  265. BX_FREE(_allocator, inside);
  266. BX_FREE(_allocator, outside);
  267. }
  268. } // namespace bgfx
  269. void help(const char* _error = NULL)
  270. {
  271. if (NULL != _error)
  272. {
  273. fprintf(stderr, "Error:\n%s\n\n", _error);
  274. }
  275. fprintf(stderr
  276. , "texturec, bgfx texture compiler tool\n"
  277. "Copyright 2011-2016 Branimir Karadzic. All rights reserved.\n"
  278. "License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause\n\n"
  279. );
  280. fprintf(stderr
  281. , "Usage: texturec -f <in> -o <out> -t <format>\n"
  282. "\n"
  283. "Supported input file types:\n"
  284. " *.png Portable Network Graphics\n"
  285. " *.tga Targa\n"
  286. " *.dds Direct Draw Surface\n"
  287. " *.ktx Khronos Texture\n"
  288. " *.pvr PowerVR\n"
  289. "\n"
  290. "Options:\n"
  291. " -f <file path> Input file path.\n"
  292. " -o <file path> Output file path (file will be written in KTX format).\n"
  293. " -t <format> Output format type (BC1/2/3/4/5, ETC1, PVR14, etc.).\n"
  294. " -m, --mips Generate mip-maps.\n"
  295. " -n, --normalmap Input texture is normal map.\n"
  296. " --sdf <edge> Compute SDF texture.\n"
  297. " --iqa Image Quality Assesment\n"
  298. "\n"
  299. "For additional information, see https://github.com/bkaradzic/bgfx\n"
  300. );
  301. }
  302. int main(int _argc, const char* _argv[])
  303. {
  304. bx::CommandLine cmdLine(_argc, _argv);
  305. if (cmdLine.hasArg('h', "help") )
  306. {
  307. help();
  308. return EXIT_FAILURE;
  309. }
  310. const char* inputFileName = cmdLine.findOption('f');
  311. if (NULL == inputFileName)
  312. {
  313. help("Input file must be specified.");
  314. return EXIT_FAILURE;
  315. }
  316. const char* outputFileName = cmdLine.findOption('o');
  317. if (NULL == outputFileName)
  318. {
  319. help("Output file must be specified.");
  320. return EXIT_FAILURE;
  321. }
  322. bool sdf = false;
  323. double edge = 16.0;
  324. const char* edgeOpt = cmdLine.findOption("sdf");
  325. if (NULL != edgeOpt)
  326. {
  327. sdf = true;
  328. edge = atof(edgeOpt);
  329. }
  330. BX_UNUSED(sdf, edge);
  331. bx::CrtFileReader reader;
  332. if (!bx::open(&reader, inputFileName) )
  333. {
  334. help("Failed to open input file.");
  335. return EXIT_FAILURE;
  336. }
  337. const char* type = cmdLine.findOption('t');
  338. bgfx::TextureFormat::Enum format = bgfx::TextureFormat::BGRA8;
  339. if (NULL != type)
  340. {
  341. format = bgfx::getFormat(type);
  342. if (!isValid(format) )
  343. {
  344. help("Invalid format specified.");
  345. return EXIT_FAILURE;
  346. }
  347. }
  348. const bool mips = cmdLine.hasArg('m', "mips");
  349. const bool normalMap = cmdLine.hasArg('n', "normalmap");
  350. const bool iqa = cmdLine.hasArg('\0', "iqa");
  351. uint32_t size = (uint32_t)bx::getSize(&reader);
  352. const bgfx::Memory* mem = bgfx::alloc(size);
  353. bx::read(&reader, mem->data, mem->size);
  354. bx::close(&reader);
  355. {
  356. using namespace bgfx;
  357. uint8_t* decodedImage = NULL;
  358. ImageContainer imageContainer;
  359. bool loaded = imageParse(imageContainer, mem->data, mem->size);
  360. if (!loaded)
  361. {
  362. int width = 0;
  363. int height = 0;
  364. int comp = 0;
  365. decodedImage = stbi_load_from_memory( (uint8_t*)mem->data, mem->size, &width, &height, &comp, 4);
  366. loaded = NULL != decodedImage;
  367. if (loaded)
  368. {
  369. release(mem);
  370. mem = makeRef(decodedImage, width*height*4);
  371. imageContainer.m_data = mem->data;
  372. imageContainer.m_size = mem->size;
  373. imageContainer.m_offset = 0;
  374. imageContainer.m_width = width;
  375. imageContainer.m_height = height;
  376. imageContainer.m_depth = 1;
  377. imageContainer.m_format = bgfx::TextureFormat::RGBA8;
  378. imageContainer.m_numMips = 1;
  379. imageContainer.m_hasAlpha = true;
  380. imageContainer.m_cubeMap = false;
  381. imageContainer.m_ktx = false;
  382. imageContainer.m_ktxLE = false;
  383. imageContainer.m_srgb = false;
  384. }
  385. }
  386. if (loaded)
  387. {
  388. bx::CrtAllocator allocator;
  389. const Memory* output = NULL;
  390. ImageMip mip;
  391. if (imageGetRawData(imageContainer, 0, 0, mem->data, mem->size, mip) )
  392. {
  393. uint8_t numMips = mips
  394. ? imageGetNumMips(format, mip.m_width, mip.m_height)
  395. : 1
  396. ;
  397. void* temp = NULL;
  398. if (normalMap)
  399. {
  400. output = imageAlloc(imageContainer, format, mip.m_width, mip.m_height, 0, false, mips);
  401. ImageMip dstMip;
  402. imageGetRawData(imageContainer, 0, 0, NULL, 0, dstMip);
  403. if (mip.m_width != dstMip.m_width
  404. && mip.m_height != dstMip.m_height)
  405. {
  406. printf("Invalid input image size %dx%d, it must be at least %dx%d to be converted to %s format.\n"
  407. , mip.m_width
  408. , mip.m_height
  409. , dstMip.m_width
  410. , dstMip.m_height
  411. , getName(format)
  412. );
  413. return EXIT_FAILURE;
  414. }
  415. uint32_t size = imageGetSize(TextureFormat::RGBA32F, dstMip.m_width, dstMip.m_height);
  416. temp = BX_ALLOC(&allocator, size);
  417. float* rgba = (float*)temp;
  418. float* rgbaDst = (float*)BX_ALLOC(&allocator, size);
  419. imageDecodeToRgba32f(&allocator
  420. , rgba
  421. , mip.m_data
  422. , mip.m_width
  423. , mip.m_height
  424. , mip.m_width*mip.m_bpp/8
  425. , mip.m_format
  426. );
  427. if (TextureFormat::BC5 != mip.m_format)
  428. {
  429. for (uint32_t yy = 0; yy < mip.m_height; ++yy)
  430. {
  431. for (uint32_t xx = 0; xx < mip.m_width; ++xx)
  432. {
  433. const uint32_t offset = (yy*mip.m_width + xx) * 4;
  434. float* inout = &rgba[offset];
  435. inout[0] = inout[0] * 2.0f/255.0f - 1.0f;
  436. inout[1] = inout[1] * 2.0f/255.0f - 1.0f;
  437. inout[2] = inout[2] * 2.0f/255.0f - 1.0f;
  438. inout[3] = inout[3] * 2.0f/255.0f - 1.0f;
  439. }
  440. }
  441. }
  442. imageRgba32f11to01(rgbaDst, dstMip.m_width, dstMip.m_height, dstMip.m_width*16, rgba);
  443. imageEncodeFromRgba32f(&allocator, output->data, rgbaDst, dstMip.m_width, dstMip.m_height, format);
  444. for (uint8_t lod = 1; lod < numMips; ++lod)
  445. {
  446. imageRgba32fDownsample2x2NormalMap(dstMip.m_width, dstMip.m_height, dstMip.m_width*16, rgba, rgba);
  447. imageRgba32f11to01(rgbaDst, dstMip.m_width, dstMip.m_height, dstMip.m_width*16, rgba);
  448. imageGetRawData(imageContainer, 0, lod, output->data, output->size, dstMip);
  449. uint8_t* data = const_cast<uint8_t*>(dstMip.m_data);
  450. imageEncodeFromRgba32f(&allocator, data, rgbaDst, dstMip.m_width, dstMip.m_height, format);
  451. }
  452. BX_FREE(&allocator, rgbaDst);
  453. }
  454. else
  455. {
  456. output = imageAlloc(imageContainer, format, mip.m_width, mip.m_height, 0, false, mips);
  457. ImageMip dstMip;
  458. imageGetRawData(imageContainer, 0, 0, NULL, 0, dstMip);
  459. if (mip.m_width != dstMip.m_width
  460. && mip.m_height != dstMip.m_height)
  461. {
  462. printf("Invalid input image size %dx%d, it must be at least %dx%d to be converted to %s format.\n"
  463. , mip.m_width
  464. , mip.m_height
  465. , dstMip.m_width
  466. , dstMip.m_height
  467. , getName(format)
  468. );
  469. return EXIT_FAILURE;
  470. }
  471. uint32_t size = imageGetSize(TextureFormat::RGBA8, dstMip.m_width, dstMip.m_height);
  472. temp = BX_ALLOC(&allocator, size);
  473. memset(temp, 0, size);
  474. uint8_t* rgba = (uint8_t*)temp;
  475. imageDecodeToRgba8(rgba
  476. , mip.m_data
  477. , mip.m_width
  478. , mip.m_height
  479. , mip.m_width*mip.m_bpp/8
  480. , mip.m_format
  481. );
  482. void* ref = NULL;
  483. if (iqa)
  484. {
  485. ref = BX_ALLOC(&allocator, size);
  486. memcpy(ref, rgba, size);
  487. }
  488. imageEncodeFromRgba8(output->data, rgba, dstMip.m_width, dstMip.m_height, format);
  489. for (uint8_t lod = 1; lod < numMips; ++lod)
  490. {
  491. imageRgba8Downsample2x2(dstMip.m_width, dstMip.m_height, dstMip.m_width*4, rgba, rgba);
  492. imageGetRawData(imageContainer, 0, lod, output->data, output->size, dstMip);
  493. uint8_t* data = const_cast<uint8_t*>(dstMip.m_data);
  494. imageEncodeFromRgba8(data, rgba, dstMip.m_width, dstMip.m_height, format);
  495. }
  496. if (NULL != ref)
  497. {
  498. imageDecodeToRgba8(rgba
  499. , output->data
  500. , mip.m_width
  501. , mip.m_height
  502. , mip.m_width*mip.m_bpp/8
  503. , format
  504. );
  505. static const iqa_ssim_args args =
  506. {
  507. 0.39f, // alpha
  508. 0.731f, // beta
  509. 1.12f, // gamma
  510. 187, // L
  511. 0.025987f, // K1
  512. 0.0173f, // K2
  513. 1 // factor
  514. };
  515. float result = iqa_ssim( (uint8_t*)ref
  516. , rgba
  517. , mip.m_width
  518. , mip.m_height
  519. , mip.m_width*mip.m_bpp/8
  520. , 0
  521. , &args
  522. );
  523. printf("%f\n", result);
  524. BX_FREE(&allocator, ref);
  525. }
  526. }
  527. BX_FREE(&allocator, temp);
  528. }
  529. if (NULL != output)
  530. {
  531. bx::CrtFileWriter writer;
  532. if (bx::open(&writer, outputFileName) )
  533. {
  534. if (NULL != bx::stristr(outputFileName, ".ktx") )
  535. {
  536. imageWriteKtx(&writer, imageContainer, output->data, output->size);
  537. }
  538. bx::close(&writer);
  539. }
  540. else
  541. {
  542. help("Failed to open output file.");
  543. return EXIT_FAILURE;
  544. }
  545. imageFree(output);
  546. }
  547. }
  548. release(mem);
  549. }
  550. return EXIT_SUCCESS;
  551. }