texture_loader_pvr.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. /*************************************************************************/
  2. /* texture_loader_pvr.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "texture_loader_pvr.h"
  31. #include "core/os/file_access.h"
  32. static void _pvrtc_decompress(Image *p_img);
  33. enum PVRFLags {
  34. PVR_HAS_MIPMAPS = 0x00000100,
  35. PVR_TWIDDLED = 0x00000200,
  36. PVR_NORMAL_MAP = 0x00000400,
  37. PVR_BORDER = 0x00000800,
  38. PVR_CUBE_MAP = 0x00001000,
  39. PVR_FALSE_MIPMAPS = 0x00002000,
  40. PVR_VOLUME_TEXTURES = 0x00004000,
  41. PVR_HAS_ALPHA = 0x00008000,
  42. PVR_VFLIP = 0x00010000
  43. };
  44. RES ResourceFormatPVR::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) {
  45. if (r_error) {
  46. *r_error = ERR_CANT_OPEN;
  47. }
  48. Error err;
  49. FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
  50. if (!f) {
  51. return RES();
  52. }
  53. FileAccessRef faref(f);
  54. ERR_FAIL_COND_V(err, RES());
  55. if (r_error) {
  56. *r_error = ERR_FILE_CORRUPT;
  57. }
  58. uint32_t hsize = f->get_32();
  59. ERR_FAIL_COND_V(hsize != 52, RES());
  60. uint32_t height = f->get_32();
  61. uint32_t width = f->get_32();
  62. uint32_t mipmaps = f->get_32();
  63. uint32_t flags = f->get_32();
  64. uint32_t surfsize = f->get_32();
  65. f->seek(f->get_position() + 20); // bpp, rmask, gmask, bmask, amask
  66. uint8_t pvrid[5] = { 0, 0, 0, 0, 0 };
  67. f->get_buffer(pvrid, 4);
  68. ERR_FAIL_COND_V(String((char *)pvrid) != "PVR!", RES());
  69. f->get_32(); // surfcount
  70. /*
  71. print_line("height: "+itos(height));
  72. print_line("width: "+itos(width));
  73. print_line("mipmaps: "+itos(mipmaps));
  74. print_line("flags: "+itos(flags));
  75. print_line("surfsize: "+itos(surfsize));
  76. print_line("bpp: "+itos(bpp));
  77. print_line("rmask: "+itos(rmask));
  78. print_line("gmask: "+itos(gmask));
  79. print_line("bmask: "+itos(bmask));
  80. print_line("amask: "+itos(amask));
  81. print_line("surfcount: "+itos(surfcount));
  82. */
  83. Vector<uint8_t> data;
  84. data.resize(surfsize);
  85. ERR_FAIL_COND_V(data.size() == 0, RES());
  86. uint8_t *w = data.ptrw();
  87. f->get_buffer(&w[0], surfsize);
  88. err = f->get_error();
  89. ERR_FAIL_COND_V(err != OK, RES());
  90. Image::Format format = Image::FORMAT_MAX;
  91. switch (flags & 0xFF) {
  92. case 0x18:
  93. case 0xC:
  94. format = (flags & PVR_HAS_ALPHA) ? Image::FORMAT_PVRTC1_2A : Image::FORMAT_PVRTC1_2;
  95. break;
  96. case 0x19:
  97. case 0xD:
  98. format = (flags & PVR_HAS_ALPHA) ? Image::FORMAT_PVRTC1_4A : Image::FORMAT_PVRTC1_4;
  99. break;
  100. case 0x16:
  101. format = Image::FORMAT_L8;
  102. break;
  103. case 0x17:
  104. format = Image::FORMAT_LA8;
  105. break;
  106. case 0x20:
  107. case 0x80:
  108. case 0x81:
  109. format = Image::FORMAT_DXT1;
  110. break;
  111. case 0x21:
  112. case 0x22:
  113. case 0x82:
  114. case 0x83:
  115. format = Image::FORMAT_DXT3;
  116. break;
  117. case 0x23:
  118. case 0x24:
  119. case 0x84:
  120. case 0x85:
  121. format = Image::FORMAT_DXT5;
  122. break;
  123. case 0x4:
  124. case 0x15:
  125. format = Image::FORMAT_RGB8;
  126. break;
  127. case 0x5:
  128. case 0x12:
  129. format = Image::FORMAT_RGBA8;
  130. break;
  131. case 0x36:
  132. format = Image::FORMAT_ETC;
  133. break;
  134. default:
  135. ERR_FAIL_V_MSG(RES(), "Unsupported format in PVR texture: " + itos(flags & 0xFF) + ".");
  136. }
  137. Ref<Image> image = memnew(Image(width, height, mipmaps, format, data));
  138. ERR_FAIL_COND_V(image->is_empty(), RES());
  139. Ref<ImageTexture> texture = memnew(ImageTexture);
  140. texture->create_from_image(image);
  141. if (r_error) {
  142. *r_error = OK;
  143. }
  144. return texture;
  145. }
  146. void ResourceFormatPVR::get_recognized_extensions(List<String> *p_extensions) const {
  147. p_extensions->push_back("pvr");
  148. }
  149. bool ResourceFormatPVR::handles_type(const String &p_type) const {
  150. return ClassDB::is_parent_class(p_type, "Texture2D");
  151. }
  152. String ResourceFormatPVR::get_resource_type(const String &p_path) const {
  153. if (p_path.get_extension().to_lower() == "pvr") {
  154. return "Texture2D";
  155. }
  156. return "";
  157. }
  158. ResourceFormatPVR::ResourceFormatPVR() {
  159. Image::_image_decompress_pvrtc = _pvrtc_decompress;
  160. }
  161. /////////////////////////////////////////////////////////
  162. //PVRTC decompressor, Based on PVRTC decompressor by IMGTEC.
  163. /////////////////////////////////////////////////////////
  164. #define PT_INDEX 2
  165. #define BLK_Y_SIZE 4
  166. #define BLK_X_MAX 8
  167. #define BLK_X_2BPP 8
  168. #define BLK_X_4BPP 4
  169. #define WRAP_COORD(Val, Size) ((Val) & ((Size)-1))
  170. /*
  171. Define an expression to either wrap or clamp large or small vals to the
  172. legal coordinate range
  173. */
  174. #define LIMIT_COORD(Val, Size, p_tiled) \
  175. ((p_tiled) ? WRAP_COORD((Val), (Size)) : CLAMP((Val), 0, (Size)-1))
  176. struct PVRTCBlock {
  177. //blocks are 64 bits
  178. uint32_t data[2] = {};
  179. };
  180. _FORCE_INLINE_ bool is_po2(uint32_t p_input) {
  181. if (p_input == 0) {
  182. return false;
  183. }
  184. uint32_t minus1 = p_input - 1;
  185. return ((p_input | minus1) == (p_input ^ minus1)) ? true : false;
  186. }
  187. static void unpack_5554(const PVRTCBlock *p_block, int p_ab_colors[2][4]) {
  188. uint32_t raw_bits[2];
  189. raw_bits[0] = p_block->data[1] & (0xFFFE);
  190. raw_bits[1] = p_block->data[1] >> 16;
  191. for (int i = 0; i < 2; i++) {
  192. if (raw_bits[i] & (1 << 15)) {
  193. p_ab_colors[i][0] = (raw_bits[i] >> 10) & 0x1F;
  194. p_ab_colors[i][1] = (raw_bits[i] >> 5) & 0x1F;
  195. p_ab_colors[i][2] = raw_bits[i] & 0x1F;
  196. if (i == 0) {
  197. p_ab_colors[0][2] |= p_ab_colors[0][2] >> 4;
  198. }
  199. p_ab_colors[i][3] = 0xF;
  200. } else {
  201. p_ab_colors[i][0] = (raw_bits[i] >> (8 - 1)) & 0x1E;
  202. p_ab_colors[i][1] = (raw_bits[i] >> (4 - 1)) & 0x1E;
  203. p_ab_colors[i][0] |= p_ab_colors[i][0] >> 4;
  204. p_ab_colors[i][1] |= p_ab_colors[i][1] >> 4;
  205. p_ab_colors[i][2] = (raw_bits[i] & 0xF) << 1;
  206. if (i == 0) {
  207. p_ab_colors[0][2] |= p_ab_colors[0][2] >> 3;
  208. } else {
  209. p_ab_colors[0][2] |= p_ab_colors[0][2] >> 4;
  210. }
  211. p_ab_colors[i][3] = (raw_bits[i] >> 11) & 0xE;
  212. }
  213. }
  214. }
  215. static void unpack_modulations(const PVRTCBlock *p_block, const int p_2bit, int p_modulation[8][16], int p_modulation_modes[8][16], int p_x, int p_y) {
  216. int block_mod_mode = p_block->data[1] & 1;
  217. uint32_t modulation_bits = p_block->data[0];
  218. if (p_2bit && block_mod_mode) {
  219. for (int y = 0; y < BLK_Y_SIZE; y++) {
  220. for (int x = 0; x < BLK_X_2BPP; x++) {
  221. p_modulation_modes[y + p_y][x + p_x] = block_mod_mode;
  222. if (((x ^ y) & 1) == 0) {
  223. p_modulation[y + p_y][x + p_x] = modulation_bits & 3;
  224. modulation_bits >>= 2;
  225. }
  226. }
  227. }
  228. } else if (p_2bit) {
  229. for (int y = 0; y < BLK_Y_SIZE; y++) {
  230. for (int x = 0; x < BLK_X_2BPP; x++) {
  231. p_modulation_modes[y + p_y][x + p_x] = block_mod_mode;
  232. if (modulation_bits & 1) {
  233. p_modulation[y + p_y][x + p_x] = 0x3;
  234. } else {
  235. p_modulation[y + p_y][x + p_x] = 0x0;
  236. }
  237. modulation_bits >>= 1;
  238. }
  239. }
  240. } else {
  241. for (int y = 0; y < BLK_Y_SIZE; y++) {
  242. for (int x = 0; x < BLK_X_4BPP; x++) {
  243. p_modulation_modes[y + p_y][x + p_x] = block_mod_mode;
  244. p_modulation[y + p_y][x + p_x] = modulation_bits & 3;
  245. modulation_bits >>= 2;
  246. }
  247. }
  248. }
  249. ERR_FAIL_COND(modulation_bits != 0);
  250. }
  251. static void interpolate_colors(const int p_colorp[4], const int p_colorq[4], const int p_colorr[4], const int p_colors[4], bool p_2bit, const int x, const int y, int r_result[4]) {
  252. int u, v, uscale;
  253. int k;
  254. int tmp1, tmp2;
  255. int P[4], Q[4], R[4], S[4];
  256. for (k = 0; k < 4; k++) {
  257. P[k] = p_colorp[k];
  258. Q[k] = p_colorq[k];
  259. R[k] = p_colorr[k];
  260. S[k] = p_colors[k];
  261. }
  262. v = (y & 0x3) | ((~y & 0x2) << 1);
  263. if (p_2bit) {
  264. u = (x & 0x7) | ((~x & 0x4) << 1);
  265. } else {
  266. u = (x & 0x3) | ((~x & 0x2) << 1);
  267. }
  268. v = v - BLK_Y_SIZE / 2;
  269. if (p_2bit) {
  270. u = u - BLK_X_2BPP / 2;
  271. uscale = 8;
  272. } else {
  273. u = u - BLK_X_4BPP / 2;
  274. uscale = 4;
  275. }
  276. for (k = 0; k < 4; k++) {
  277. tmp1 = P[k] * uscale + u * (Q[k] - P[k]);
  278. tmp2 = R[k] * uscale + u * (S[k] - R[k]);
  279. tmp1 = tmp1 * 4 + v * (tmp2 - tmp1);
  280. r_result[k] = tmp1;
  281. }
  282. if (p_2bit) {
  283. for (k = 0; k < 3; k++) {
  284. r_result[k] >>= 2;
  285. }
  286. r_result[3] >>= 1;
  287. } else {
  288. for (k = 0; k < 3; k++) {
  289. r_result[k] >>= 1;
  290. }
  291. }
  292. for (k = 0; k < 4; k++) {
  293. ERR_FAIL_COND(r_result[k] >= 256);
  294. }
  295. for (k = 0; k < 3; k++) {
  296. r_result[k] += r_result[k] >> 5;
  297. }
  298. r_result[3] += r_result[3] >> 4;
  299. for (k = 0; k < 4; k++) {
  300. ERR_FAIL_COND(r_result[k] >= 256);
  301. }
  302. }
  303. static void get_modulation_value(int x, int y, const int p_2bit, const int p_modulation[8][16], const int p_modulation_modes[8][16], int *r_mod, int *p_dopt) {
  304. static const int rep_vals0[4] = { 0, 3, 5, 8 };
  305. static const int rep_vals1[4] = { 0, 4, 4, 8 };
  306. int mod_val;
  307. y = (y & 0x3) | ((~y & 0x2) << 1);
  308. if (p_2bit) {
  309. x = (x & 0x7) | ((~x & 0x4) << 1);
  310. } else {
  311. x = (x & 0x3) | ((~x & 0x2) << 1);
  312. }
  313. *p_dopt = 0;
  314. if (p_modulation_modes[y][x] == 0) {
  315. mod_val = rep_vals0[p_modulation[y][x]];
  316. } else if (p_2bit) {
  317. if (((x ^ y) & 1) == 0) {
  318. mod_val = rep_vals0[p_modulation[y][x]];
  319. } else if (p_modulation_modes[y][x] == 1) {
  320. mod_val = (rep_vals0[p_modulation[y - 1][x]] +
  321. rep_vals0[p_modulation[y + 1][x]] +
  322. rep_vals0[p_modulation[y][x - 1]] +
  323. rep_vals0[p_modulation[y][x + 1]] + 2) /
  324. 4;
  325. } else if (p_modulation_modes[y][x] == 2) {
  326. mod_val = (rep_vals0[p_modulation[y][x - 1]] +
  327. rep_vals0[p_modulation[y][x + 1]] + 1) /
  328. 2;
  329. } else {
  330. mod_val = (rep_vals0[p_modulation[y - 1][x]] +
  331. rep_vals0[p_modulation[y + 1][x]] + 1) /
  332. 2;
  333. }
  334. } else {
  335. mod_val = rep_vals1[p_modulation[y][x]];
  336. *p_dopt = p_modulation[y][x] == PT_INDEX;
  337. }
  338. *r_mod = mod_val;
  339. }
  340. static int disable_twiddling = 0;
  341. static uint32_t twiddle_uv(uint32_t p_height, uint32_t p_width, uint32_t p_y, uint32_t p_x) {
  342. uint32_t twiddled;
  343. uint32_t min_dimension;
  344. uint32_t max_value;
  345. uint32_t scr_bit_pos;
  346. uint32_t dst_bit_pos;
  347. int shift_count;
  348. ERR_FAIL_COND_V(p_y >= p_height, 0);
  349. ERR_FAIL_COND_V(p_x >= p_width, 0);
  350. ERR_FAIL_COND_V(!is_po2(p_height), 0);
  351. ERR_FAIL_COND_V(!is_po2(p_width), 0);
  352. if (p_height < p_width) {
  353. min_dimension = p_height;
  354. max_value = p_x;
  355. } else {
  356. min_dimension = p_width;
  357. max_value = p_y;
  358. }
  359. if (disable_twiddling) {
  360. return (p_y * p_width + p_x);
  361. }
  362. scr_bit_pos = 1;
  363. dst_bit_pos = 1;
  364. twiddled = 0;
  365. shift_count = 0;
  366. while (scr_bit_pos < min_dimension) {
  367. if (p_y & scr_bit_pos) {
  368. twiddled |= dst_bit_pos;
  369. }
  370. if (p_x & scr_bit_pos) {
  371. twiddled |= (dst_bit_pos << 1);
  372. }
  373. scr_bit_pos <<= 1;
  374. dst_bit_pos <<= 2;
  375. shift_count += 1;
  376. }
  377. max_value >>= shift_count;
  378. twiddled |= (max_value << (2 * shift_count));
  379. return twiddled;
  380. }
  381. static void decompress_pvrtc(PVRTCBlock *p_comp_img, const int p_2bit, const int p_width, const int p_height, const int p_tiled, unsigned char *p_dst) {
  382. int x, y;
  383. int i, j;
  384. int block_x, blk_y;
  385. int block_xp1, blk_yp1;
  386. int x_block_size;
  387. int block_width, block_height;
  388. int p_x, p_y;
  389. int p_modulation[8][16] = { { 0 } };
  390. int p_modulation_modes[8][16] = { { 0 } };
  391. int Mod, DoPT;
  392. unsigned int u_pos;
  393. // local neighbourhood of blocks
  394. PVRTCBlock *p_blocks[2][2];
  395. PVRTCBlock *prev[2][2] = { { nullptr, nullptr }, { nullptr, nullptr } };
  396. struct
  397. {
  398. int Reps[2][4];
  399. } colors5554[2][2];
  400. int ASig[4], BSig[4];
  401. int r_result[4];
  402. if (p_2bit) {
  403. x_block_size = BLK_X_2BPP;
  404. } else {
  405. x_block_size = BLK_X_4BPP;
  406. }
  407. block_width = MAX(2, p_width / x_block_size);
  408. block_height = MAX(2, p_height / BLK_Y_SIZE);
  409. for (y = 0; y < p_height; y++) {
  410. for (x = 0; x < p_width; x++) {
  411. block_x = (x - x_block_size / 2);
  412. blk_y = (y - BLK_Y_SIZE / 2);
  413. block_x = LIMIT_COORD(block_x, p_width, p_tiled);
  414. blk_y = LIMIT_COORD(blk_y, p_height, p_tiled);
  415. block_x /= x_block_size;
  416. blk_y /= BLK_Y_SIZE;
  417. block_xp1 = LIMIT_COORD(block_x + 1, block_width, p_tiled);
  418. blk_yp1 = LIMIT_COORD(blk_y + 1, block_height, p_tiled);
  419. p_blocks[0][0] = p_comp_img + twiddle_uv(block_height, block_width, blk_y, block_x);
  420. p_blocks[0][1] = p_comp_img + twiddle_uv(block_height, block_width, blk_y, block_xp1);
  421. p_blocks[1][0] = p_comp_img + twiddle_uv(block_height, block_width, blk_yp1, block_x);
  422. p_blocks[1][1] = p_comp_img + twiddle_uv(block_height, block_width, blk_yp1, block_xp1);
  423. if (memcmp(prev, p_blocks, 4 * sizeof(void *)) != 0) {
  424. p_y = 0;
  425. for (i = 0; i < 2; i++) {
  426. p_x = 0;
  427. for (j = 0; j < 2; j++) {
  428. unpack_5554(p_blocks[i][j], colors5554[i][j].Reps);
  429. unpack_modulations(
  430. p_blocks[i][j],
  431. p_2bit,
  432. p_modulation,
  433. p_modulation_modes,
  434. p_x, p_y);
  435. p_x += x_block_size;
  436. }
  437. p_y += BLK_Y_SIZE;
  438. }
  439. memcpy(prev, p_blocks, 4 * sizeof(void *));
  440. }
  441. interpolate_colors(
  442. colors5554[0][0].Reps[0],
  443. colors5554[0][1].Reps[0],
  444. colors5554[1][0].Reps[0],
  445. colors5554[1][1].Reps[0],
  446. p_2bit, x, y,
  447. ASig);
  448. interpolate_colors(
  449. colors5554[0][0].Reps[1],
  450. colors5554[0][1].Reps[1],
  451. colors5554[1][0].Reps[1],
  452. colors5554[1][1].Reps[1],
  453. p_2bit, x, y,
  454. BSig);
  455. get_modulation_value(x, y, p_2bit, (const int(*)[16])p_modulation, (const int(*)[16])p_modulation_modes,
  456. &Mod, &DoPT);
  457. for (i = 0; i < 4; i++) {
  458. r_result[i] = ASig[i] * 8 + Mod * (BSig[i] - ASig[i]);
  459. r_result[i] >>= 3;
  460. }
  461. if (DoPT) {
  462. r_result[3] = 0;
  463. }
  464. u_pos = (x + y * p_width) << 2;
  465. p_dst[u_pos + 0] = (uint8_t)r_result[0];
  466. p_dst[u_pos + 1] = (uint8_t)r_result[1];
  467. p_dst[u_pos + 2] = (uint8_t)r_result[2];
  468. p_dst[u_pos + 3] = (uint8_t)r_result[3];
  469. }
  470. }
  471. }
  472. static void _pvrtc_decompress(Image *p_img) {
  473. ERR_FAIL_COND(p_img->get_format() != Image::FORMAT_PVRTC1_2 && p_img->get_format() != Image::FORMAT_PVRTC1_2A && p_img->get_format() != Image::FORMAT_PVRTC1_4 && p_img->get_format() != Image::FORMAT_PVRTC1_4A);
  474. bool _2bit = (p_img->get_format() == Image::FORMAT_PVRTC1_2 || p_img->get_format() == Image::FORMAT_PVRTC1_2A);
  475. Vector<uint8_t> data = p_img->get_data();
  476. const uint8_t *r = data.ptr();
  477. Vector<uint8_t> newdata;
  478. newdata.resize(p_img->get_width() * p_img->get_height() * 4);
  479. uint8_t *w = newdata.ptrw();
  480. decompress_pvrtc((PVRTCBlock *)r, _2bit, p_img->get_width(), p_img->get_height(), 0, (unsigned char *)w);
  481. bool make_mipmaps = p_img->has_mipmaps();
  482. p_img->create(p_img->get_width(), p_img->get_height(), false, Image::FORMAT_RGBA8, newdata);
  483. if (make_mipmaps) {
  484. p_img->generate_mipmaps();
  485. }
  486. }