CImageLoaderTEX.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. #include "CImageLoaderTEX.h"
  2. #include <irrlicht/irrlicht.h>
  3. #include <lz4.h>
  4. #include <WallpaperEngine/Irrlicht/Irrlicht.h>
  5. #include <string>
  6. using namespace irr::video;
  7. using namespace WallpaperEngine::Irrlicht;
  8. //! returns true if the file maybe is able to be loaded by this class
  9. //! based on the file extension (e.g. ".tga")
  10. bool CImageLoaderTex::isALoadableFileExtension (const io::path &filename) const
  11. {
  12. return core::hasFileExtension (filename, "tex");
  13. }
  14. //! returns true if the file maybe is able to be loaded by this class
  15. bool CImageLoaderTex::isALoadableFileFormat (io::IReadFile *file) const
  16. {
  17. return false;
  18. }
  19. // load in the image data
  20. IImage *CImageLoaderTex::loadImage (io::IReadFile *input) const
  21. {
  22. if (!input)
  23. return nullptr;
  24. video::IImage *image = nullptr;
  25. char buffer [1024];
  26. if (input->read (buffer, 9) != 9)
  27. {
  28. WallpaperEngine::Irrlicht::device->getLogger ()->log ("LOAD TEX: cannot read header\n", input->getFileName ().c_str (), irr::ELL_ERROR);
  29. return nullptr;
  30. }
  31. if (memcmp (buffer, "TEXV0005", 9) != 0)
  32. {
  33. WallpaperEngine::Irrlicht::device->getLogger ()->log ("LOAD TEX: not really a tex\n", input->getFileName ().c_str (), irr::ELL_ERROR);
  34. return nullptr;
  35. }
  36. if (input->read (buffer, 9) != 9)
  37. {
  38. WallpaperEngine::Irrlicht::device->getLogger ()->log ("LOAD TEX: cannot read second header\n", input->getFileName ().c_str (), irr::ELL_ERROR);
  39. return nullptr;
  40. }
  41. if (memcmp (buffer, "TEXI0001", 9) != 0)
  42. {
  43. WallpaperEngine::Irrlicht::device->getLogger ()->log ("LOAD TEX: not really a tex\n", input->getFileName ().c_str (), irr::ELL_ERROR);
  44. return nullptr;
  45. }
  46. u32 width;
  47. u32 height;
  48. u32 texture_width;
  49. u32 texture_height;
  50. u32 format;
  51. u32 imageFormat = FREE_IMAGE_FORMAT::FIF_UNKNOWN;
  52. u8 containerVersion = 0;
  53. input->read (&format, 4);
  54. input->seek (4, true); // ignore bytes
  55. input->read (&texture_width, 4);
  56. input->read (&texture_height, 4);
  57. input->read (&width, 4);
  58. input->read (&height, 4);
  59. input->seek (4, true); // ignore bytes
  60. input->read (buffer, 9);
  61. if (memcmp (buffer, "TEXB0003", 9) == 0)
  62. {
  63. containerVersion = 3;
  64. input->seek (4, true);
  65. input->read (&imageFormat, 4);
  66. }
  67. else if (memcmp (buffer, "TEXB0002", 9) == 0)
  68. {
  69. containerVersion = 2;
  70. input->seek (4, true);
  71. }
  72. else if (memcmp (buffer, "TEXB0001", 9) == 0)
  73. {
  74. containerVersion = 1;
  75. input->seek (4, true);
  76. }
  77. else
  78. {
  79. WallpaperEngine::Irrlicht::device->getLogger ()->log ("LOAD TEX: Unknown container type\n", input->getFileName ().c_str (), irr::ELL_ERROR);
  80. return nullptr;
  81. }
  82. if (format == TextureFormat::A8)
  83. {
  84. WallpaperEngine::Irrlicht::device->getLogger ()-> log ("LOAD TEX: A8 not supported\n", input->getFileName ().c_str (), irr::ELL_ERROR);
  85. return nullptr;
  86. }
  87. if (format == TextureFormat::RA88)
  88. {
  89. WallpaperEngine::Irrlicht::device->getLogger ()->log ("LOAD TEX: RA88 not supported\n", input->getFileName ().c_str (), irr::ELL_ERROR);
  90. return nullptr;
  91. }
  92. u32 mipmap_count = 0;
  93. input->read (&mipmap_count, 4);
  94. u32 mipmap_width = 0;
  95. u32 mipmap_height = 0;
  96. u32 mipmap_compression = 0;
  97. u32 mipmap_uncompressed_size = 0;
  98. u32 mipmap_compressed_size = 0;
  99. input->read (&mipmap_width, 4);
  100. input->read (&mipmap_height, 4);
  101. if (containerVersion > 1)
  102. {
  103. input->read (&mipmap_compression, 4);
  104. input->read (&mipmap_uncompressed_size, 4);
  105. }
  106. input->read (&mipmap_compressed_size, 4);
  107. // TODO: BETTER POSITION FOR THIS
  108. if (mipmap_compression == 0)
  109. {
  110. // this might be better named as mipmap_bytes_size instead of compressed_size
  111. // as in uncompressed files this variable actually holds the file length
  112. mipmap_uncompressed_size = mipmap_compressed_size;
  113. }
  114. char *decompressedBuffer = new char [mipmap_uncompressed_size];
  115. if (mipmap_compression == 1)
  116. {
  117. char *compressedBuffer = new char [mipmap_compressed_size];
  118. input->read (compressedBuffer, mipmap_compressed_size);
  119. int result = LZ4_decompress_safe (compressedBuffer, decompressedBuffer, mipmap_compressed_size, mipmap_uncompressed_size);
  120. if (!result)
  121. {
  122. delete [] decompressedBuffer;
  123. delete [] compressedBuffer;
  124. WallpaperEngine::Irrlicht::device->getLogger ()->log ("LOAD TEX: cannot decompress texture data\n", input->getFileName ().c_str (), irr::ELL_ERROR);
  125. return nullptr;
  126. }
  127. delete [] compressedBuffer;
  128. }
  129. else
  130. {
  131. input->read (decompressedBuffer, mipmap_uncompressed_size);
  132. }
  133. if (imageFormat == FREE_IMAGE_FORMAT::FIF_UNKNOWN)
  134. {
  135. image = WallpaperEngine::Irrlicht::driver->createImage (ECF_A8R8G8B8, irr::core::dimension2d<u32> (width, height));
  136. if (!image)
  137. {
  138. delete [] decompressedBuffer;
  139. delete image;
  140. WallpaperEngine::Irrlicht::device->getLogger ()->log ("LOAD TEX: cannot create destination image\n", input->getFileName ().c_str (), irr::ELL_ERROR);
  141. return nullptr;
  142. }
  143. switch (format)
  144. {
  145. case TextureFormat::ARGB8888:
  146. this->loadImageFromARGB8Data (image, decompressedBuffer, width, height, mipmap_width);
  147. break;
  148. case TextureFormat::DXT5:
  149. this->loadImageFromDXT5 (image, decompressedBuffer, width, height, mipmap_width, mipmap_height);
  150. break;
  151. case TextureFormat::DXT1:
  152. this->loadImageFromDXT1 (image, decompressedBuffer, width, height, mipmap_width, mipmap_height);
  153. break;
  154. case TextureFormat::DXT3:
  155. WallpaperEngine::Irrlicht::device->getLogger ()->log ("LOAD TEX: DXT3 textures not supported yet\n", input->getFileName ().c_str (), irr::ELL_ERROR);
  156. delete [] decompressedBuffer;
  157. delete image;
  158. return nullptr;
  159. }
  160. }
  161. else
  162. {
  163. // copy the buffer to a new address
  164. char* filebuffer = new char [mipmap_uncompressed_size];
  165. char tmpname [TMP_MAX];
  166. // copy file data to the final file buffer to be used
  167. memcpy (filebuffer, decompressedBuffer, mipmap_uncompressed_size);
  168. // generate temporal name
  169. std::tmpnam (tmpname);
  170. // store it in a std::string
  171. std::string filename = tmpname;
  172. irr::io::IReadFile* file;
  173. // free image format
  174. switch (imageFormat)
  175. {
  176. case FREE_IMAGE_FORMAT::FIF_BMP:
  177. // add extension to the file
  178. filename += ".bmp";
  179. file = WallpaperEngine::Irrlicht::device->getFileSystem ()->createMemoryReadFile (filebuffer, mipmap_uncompressed_size, filename.c_str (), true);
  180. break;
  181. case FREE_IMAGE_FORMAT::FIF_PNG:
  182. // add extension to the file
  183. filename += ".png";
  184. file = WallpaperEngine::Irrlicht::device->getFileSystem ()->createMemoryReadFile (filebuffer, mipmap_uncompressed_size, filename.c_str (), true);
  185. break;
  186. case FREE_IMAGE_FORMAT::FIF_JPEG:
  187. // add extension to the file
  188. filename += ".jpg";
  189. WallpaperEngine::Irrlicht::device->getFileSystem ()->createAndWriteFile ("/tmp/test.jpg", false)->write (filebuffer, mipmap_uncompressed_size);
  190. file = WallpaperEngine::Irrlicht::device->getFileSystem ()->createMemoryReadFile (filebuffer, mipmap_uncompressed_size, filename.c_str (), true);
  191. break;
  192. case FREE_IMAGE_FORMAT::FIF_GIF:
  193. filename += ".gif";
  194. file = WallpaperEngine::Irrlicht::device->getFileSystem ()->createMemoryReadFile (filebuffer, mipmap_uncompressed_size, filename.c_str (), true);
  195. break;
  196. default:
  197. WallpaperEngine::Irrlicht::device->getLogger ()->log ("LOAD TEX: detected unsupported free-image format\n", input->getFileName ().c_str (), irr::ELL_ERROR);
  198. delete [] decompressedBuffer;
  199. delete [] filebuffer;
  200. return nullptr;
  201. }
  202. image = WallpaperEngine::Irrlicht::driver->createImageFromFile (file);
  203. if (!image)
  204. {
  205. file->drop ();
  206. delete [] decompressedBuffer;
  207. delete image;
  208. WallpaperEngine::Irrlicht::device->getLogger ()->log ("LOAD TEX: cannot create destination image\n", input->getFileName ().c_str (), irr::ELL_ERROR);
  209. return nullptr;
  210. }
  211. }
  212. delete [] decompressedBuffer;
  213. return image;
  214. }
  215. void CImageLoaderTex::loadImageFromARGB8Data (IImage* output, const char* input, u32 width, u32 height, u32 mipmap_width) const
  216. {
  217. u32 bytesPerPixel = output->getBytesPerPixel ();
  218. char *imagedata = (char *) output->lock ();
  219. for (u32 y = 0; y < height; y ++)
  220. {
  221. u32 baseDestination = y * output->getPitch ();
  222. u32 baseOrigin = y * (mipmap_width * 4);
  223. for (u32 x = 0; x < width; x ++)
  224. {
  225. imagedata [baseDestination + (x * bytesPerPixel) + 2] = input [baseOrigin + ((width - x) * 4) + 0]; // r
  226. imagedata [baseDestination + (x * bytesPerPixel) + 1] = input [baseOrigin + ((width - x) * 4) + 1]; // g
  227. imagedata [baseDestination + (x * bytesPerPixel) + 0] = input [baseOrigin + ((width - x) * 4) + 2]; // b
  228. imagedata [baseDestination + (x * bytesPerPixel) + 3] = input [baseOrigin + ((width - x) * 4) + 3]; // alpha
  229. }
  230. }
  231. output->unlock ();
  232. }
  233. void CImageLoaderTex::loadImageFromDXT1 (IImage* output, const char* input, u32 destination_width, u32 destination_height, u32 origin_width, u32 origin_height) const
  234. {
  235. char* decompressedBuffer = new char [origin_width * origin_height * 4];
  236. this->BlockDecompressImageDXT1 (origin_width, origin_height, (const unsigned char*) input, (unsigned long*) decompressedBuffer);
  237. this->loadImageFromARGB8Data (output, decompressedBuffer, destination_width, destination_height, origin_width);
  238. delete [] decompressedBuffer;
  239. }
  240. void CImageLoaderTex::loadImageFromDXT5 (IImage* output, const char* input, u32 destination_width, u32 destination_height, u32 origin_width, u32 origin_height) const
  241. {
  242. char* decompressedBuffer = new char [origin_width * origin_height * 4];
  243. this->BlockDecompressImageDXT5 (origin_width, origin_height, (const unsigned char*) input, (unsigned long*) decompressedBuffer);
  244. this->loadImageFromARGB8Data (output, decompressedBuffer, destination_width, destination_height, origin_width);
  245. delete [] decompressedBuffer;
  246. }
  247. // ------------------------------------------------------------------------------------
  248. // The following code is a slightly modified version of this repository
  249. // https://github.com/Benjamin-Dobell/s3tc-dxt-decompression
  250. // ------------------------------------------------------------------------------------
  251. // unsigned long PackRGBA(): Helper method that packs RGBA channels into a single 4 byte pixel.
  252. //
  253. // unsigned char r: red channel.
  254. // unsigned char g: green channel.
  255. // unsigned char b: blue channel.
  256. // unsigned char a: alpha channel.
  257. unsigned long CImageLoaderTex::PackRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a) const
  258. {
  259. return ((r << 24) | (g << 16) | (b << 8) | a);
  260. }
  261. // void DecompressBlockDXT1(): Decompresses one block of a DXT1 texture and stores the resulting pixels at the appropriate offset in 'image'.
  262. //
  263. // unsigned long x: x-coordinate of the first pixel in the block.
  264. // unsigned long y: y-coordinate of the first pixel in the block.
  265. // unsigned long width: width of the texture being decompressed.
  266. // unsigned long height: height of the texture being decompressed.
  267. // const unsigned char *blockStorage: pointer to the block to decompress.
  268. // unsigned long *image: pointer to image where the decompressed pixel data should be stored.
  269. void CImageLoaderTex::DecompressBlockDXT1(unsigned long x, unsigned long y, unsigned long width, const unsigned char *blockStorage, unsigned long *image) const
  270. {
  271. unsigned short color0 = *reinterpret_cast<const unsigned short *>(blockStorage);
  272. unsigned short color1 = *reinterpret_cast<const unsigned short *>(blockStorage + 2);
  273. unsigned long temp;
  274. temp = (color0 >> 11) * 255 + 16;
  275. unsigned char r0 = (unsigned char)((temp/32 + temp)/32);
  276. temp = ((color0 & 0x07E0) >> 5) * 255 + 32;
  277. unsigned char g0 = (unsigned char)((temp/64 + temp)/64);
  278. temp = (color0 & 0x001F) * 255 + 16;
  279. unsigned char b0 = (unsigned char)((temp/32 + temp)/32);
  280. temp = (color1 >> 11) * 255 + 16;
  281. unsigned char r1 = (unsigned char)((temp/32 + temp)/32);
  282. temp = ((color1 & 0x07E0) >> 5) * 255 + 32;
  283. unsigned char g1 = (unsigned char)((temp/64 + temp)/64);
  284. temp = (color1 & 0x001F) * 255 + 16;
  285. unsigned char b1 = (unsigned char)((temp/32 + temp)/32);
  286. unsigned long code = *reinterpret_cast<const unsigned long *>(blockStorage + 4);
  287. for (int j=0; j < 4; j++)
  288. {
  289. for (int i=0; i < 4; i++)
  290. {
  291. unsigned long finalColor = 0;
  292. unsigned char positionCode = (code >> 2*(4*j+i)) & 0x03;
  293. if (color0 > color1)
  294. {
  295. switch (positionCode)
  296. {
  297. case 0:
  298. finalColor = PackRGBA(r0, g0, b0, 255);
  299. break;
  300. case 1:
  301. finalColor = PackRGBA(r1, g1, b1, 255);
  302. break;
  303. case 2:
  304. finalColor = PackRGBA((2*r0+r1)/3, (2*g0+g1)/3, (2*b0+b1)/3, 255);
  305. break;
  306. case 3:
  307. finalColor = PackRGBA((r0+2*r1)/3, (g0+2*g1)/3, (b0+2*b1)/3, 255);
  308. break;
  309. }
  310. }
  311. else
  312. {
  313. switch (positionCode)
  314. {
  315. case 0:
  316. finalColor = PackRGBA(r0, g0, b0, 255);
  317. break;
  318. case 1:
  319. finalColor = PackRGBA(r1, g1, b1, 255);
  320. break;
  321. case 2:
  322. finalColor = PackRGBA((r0+r1)/2, (g0+g1)/2, (b0+b1)/2, 255);
  323. break;
  324. case 3:
  325. finalColor = PackRGBA(0, 0, 0, 255);
  326. break;
  327. }
  328. }
  329. if (x + i < width)
  330. image[(y + j)*width + (x + i)] = finalColor;
  331. }
  332. }
  333. }
  334. // void BlockDecompressImageDXT1(): Decompresses all the blocks of a DXT1 compressed texture and stores the resulting pixels in 'image'.
  335. //
  336. // unsigned long width: Texture width.
  337. // unsigned long height: Texture height.
  338. // const unsigned char *blockStorage: pointer to compressed DXT1 blocks.
  339. // unsigned long *image: pointer to the image where the decompressed pixels will be stored.
  340. void CImageLoaderTex::BlockDecompressImageDXT1(unsigned long width, unsigned long height, const unsigned char *blockStorage, unsigned long *image) const
  341. {
  342. unsigned long blockCountX = (width + 3) / 4;
  343. unsigned long blockCountY = (height + 3) / 4;
  344. unsigned long blockWidth = (width < 4) ? width : 4;
  345. unsigned long blockHeight = (height < 4) ? height : 4;
  346. for (unsigned long j = 0; j < blockCountY; j++)
  347. {
  348. for (unsigned long i = 0; i < blockCountX; i++) DecompressBlockDXT1(i*4, j*4, width, blockStorage + i * 8, image);
  349. blockStorage += blockCountX * 8;
  350. }
  351. }
  352. // void DecompressBlockDXT5(): Decompresses one block of a DXT5 texture and stores the resulting pixels at the appropriate offset in 'image'.
  353. //
  354. // unsigned long x: x-coordinate of the first pixel in the block.
  355. // unsigned long y: y-coordinate of the first pixel in the block.
  356. // unsigned long width: width of the texture being decompressed.
  357. // unsigned long height: height of the texture being decompressed.
  358. // const unsigned char *blockStorage: pointer to the block to decompress.
  359. // unsigned long *image: pointer to image where the decompressed pixel data should be stored.
  360. void CImageLoaderTex::DecompressBlockDXT5(unsigned long x, unsigned long y, unsigned long width, const unsigned char *blockStorage, unsigned long *image) const
  361. {
  362. unsigned char alpha0 = *reinterpret_cast<const unsigned char *>(blockStorage);
  363. unsigned char alpha1 = *reinterpret_cast<const unsigned char *>(blockStorage + 1);
  364. const unsigned char *bits = blockStorage + 2;
  365. unsigned long alphaCode1 = bits[2] | (bits[3] << 8) | (bits[4] << 16) | (bits[5] << 24);
  366. unsigned short alphaCode2 = bits[0] | (bits[1] << 8);
  367. unsigned short color0 = *reinterpret_cast<const unsigned short *>(blockStorage + 8);
  368. unsigned short color1 = *reinterpret_cast<const unsigned short *>(blockStorage + 10);
  369. unsigned long temp;
  370. temp = (color0 >> 11) * 255 + 16;
  371. unsigned char r0 = (unsigned char)((temp/32 + temp)/32);
  372. temp = ((color0 & 0x07E0) >> 5) * 255 + 32;
  373. unsigned char g0 = (unsigned char)((temp/64 + temp)/64);
  374. temp = (color0 & 0x001F) * 255 + 16;
  375. unsigned char b0 = (unsigned char)((temp/32 + temp)/32);
  376. temp = (color1 >> 11) * 255 + 16;
  377. unsigned char r1 = (unsigned char)((temp/32 + temp)/32);
  378. temp = ((color1 & 0x07E0) >> 5) * 255 + 32;
  379. unsigned char g1 = (unsigned char)((temp/64 + temp)/64);
  380. temp = (color1 & 0x001F) * 255 + 16;
  381. unsigned char b1 = (unsigned char)((temp/32 + temp)/32);
  382. unsigned long code = *reinterpret_cast<const unsigned long *>(blockStorage + 12);
  383. for (int j=0; j < 4; j++)
  384. {
  385. for (int i=0; i < 4; i++)
  386. {
  387. int alphaCodeIndex = 3*(4*j+i);
  388. int alphaCode;
  389. if (alphaCodeIndex <= 12)
  390. {
  391. alphaCode = (alphaCode2 >> alphaCodeIndex) & 0x07;
  392. }
  393. else if (alphaCodeIndex == 15)
  394. {
  395. alphaCode = (alphaCode2 >> 15) | ((alphaCode1 << 1) & 0x06);
  396. }
  397. else // alphaCodeIndex >= 18 && alphaCodeIndex <= 45
  398. {
  399. alphaCode = (alphaCode1 >> (alphaCodeIndex - 16)) & 0x07;
  400. }
  401. unsigned char finalAlpha;
  402. if (alphaCode == 0)
  403. {
  404. finalAlpha = alpha0;
  405. }
  406. else if (alphaCode == 1)
  407. {
  408. finalAlpha = alpha1;
  409. }
  410. else
  411. {
  412. if (alpha0 > alpha1)
  413. {
  414. finalAlpha = ((8-alphaCode)*alpha0 + (alphaCode-1)*alpha1)/7;
  415. }
  416. else
  417. {
  418. if (alphaCode == 6)
  419. finalAlpha = 0;
  420. else if (alphaCode == 7)
  421. finalAlpha = 255;
  422. else
  423. finalAlpha = ((6-alphaCode)*alpha0 + (alphaCode-1)*alpha1)/5;
  424. }
  425. }
  426. unsigned char colorCode = (code >> 2*(4*j+i)) & 0x03;
  427. unsigned long finalColor;
  428. switch (colorCode)
  429. {
  430. case 0:
  431. finalColor = PackRGBA(r0, g0, b0, finalAlpha);
  432. break;
  433. case 1:
  434. finalColor = PackRGBA(r1, g1, b1, finalAlpha);
  435. break;
  436. case 2:
  437. finalColor = PackRGBA((2*r0+r1)/3, (2*g0+g1)/3, (2*b0+b1)/3, finalAlpha);
  438. break;
  439. case 3:
  440. finalColor = PackRGBA((r0+2*r1)/3, (g0+2*g1)/3, (b0+2*b1)/3, finalAlpha);
  441. break;
  442. }
  443. if (x + i < width)
  444. image[(y + j)*width + (x + i)] = finalColor;
  445. }
  446. }
  447. }
  448. // void BlockDecompressImageDXT5(): Decompresses all the blocks of a DXT5 compressed texture and stores the resulting pixels in 'image'.
  449. //
  450. // unsigned long width: Texture width.
  451. // unsigned long height: Texture height.
  452. // const unsigned char *blockStorage: pointer to compressed DXT5 blocks.
  453. // unsigned long *image: pointer to the image where the decompressed pixels will be stored.
  454. void CImageLoaderTex::BlockDecompressImageDXT5(unsigned long width, unsigned long height, const unsigned char *blockStorage, unsigned long *image) const
  455. {
  456. unsigned long blockCountX = (width + 3) / 4;
  457. unsigned long blockCountY = (height + 3) / 4;
  458. unsigned long blockWidth = (width < 4) ? width : 4;
  459. unsigned long blockHeight = (height < 4) ? height : 4;
  460. for (unsigned long j = 0; j < blockCountY; j++)
  461. {
  462. for (unsigned long i = 0; i < blockCountX; i++) DecompressBlockDXT5(i*4, j*4, width, blockStorage + i * 16, image);
  463. blockStorage += blockCountX * 16;
  464. }
  465. }