image_compress_basisu.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. /**************************************************************************/
  2. /* image_compress_basisu.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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 "image_compress_basisu.h"
  31. #include "core/config/project_settings.h"
  32. #include "core/io/image.h"
  33. #include "core/os/os.h"
  34. #include "core/string/print_string.h"
  35. #include "servers/rendering_server.h"
  36. #include <transcoder/basisu_transcoder.h>
  37. #ifdef TOOLS_ENABLED
  38. #include <encoder/basisu_comp.h>
  39. static Mutex init_mutex;
  40. static bool initialized = false;
  41. #endif
  42. void basis_universal_init() {
  43. basist::basisu_transcoder_init();
  44. }
  45. #ifdef TOOLS_ENABLED
  46. template <typename T>
  47. inline void _basisu_pad_mipmap(const uint8_t *p_image_mip_data, Vector<uint8_t> &r_mip_data_padded, int p_next_width, int p_next_height, int p_width, int p_height, int64_t p_size) {
  48. // Source mip's data interpreted as 32-bit RGBA blocks to help with copying pixel data.
  49. const T *mip_src_data = reinterpret_cast<const T *>(p_image_mip_data);
  50. // Reserve space in the padded buffer.
  51. r_mip_data_padded.resize(p_next_width * p_next_height * sizeof(T));
  52. T *data_padded_ptr = reinterpret_cast<T *>(r_mip_data_padded.ptrw());
  53. // Pad mipmap to the nearest block by smearing.
  54. int x = 0, y = 0;
  55. for (y = 0; y < p_height; y++) {
  56. for (x = 0; x < p_width; x++) {
  57. data_padded_ptr[p_next_width * y + x] = mip_src_data[p_width * y + x];
  58. }
  59. // First, smear in x.
  60. for (; x < p_next_width; x++) {
  61. data_padded_ptr[p_next_width * y + x] = data_padded_ptr[p_next_width * y + x - 1];
  62. }
  63. }
  64. // Then, smear in y.
  65. for (; y < p_next_height; y++) {
  66. for (x = 0; x < p_next_width; x++) {
  67. data_padded_ptr[p_next_width * y + x] = data_padded_ptr[p_next_width * y + x - p_next_width];
  68. }
  69. }
  70. }
  71. Vector<uint8_t> basis_universal_packer(const Ref<Image> &p_image, Image::UsedChannels p_channels, const Image::BasisUniversalPackerParams &p_basisu_params) {
  72. init_mutex.lock();
  73. if (!initialized) {
  74. basisu::basisu_encoder_init();
  75. initialized = true;
  76. }
  77. init_mutex.unlock();
  78. uint64_t start_time = OS::get_singleton()->get_ticks_msec();
  79. Ref<Image> image = p_image->duplicate();
  80. bool is_hdr = false;
  81. if (image->get_format() <= Image::FORMAT_RGB565) {
  82. image->convert(Image::FORMAT_RGBA8);
  83. } else if (image->get_format() <= Image::FORMAT_RGBE9995) {
  84. image->convert(Image::FORMAT_RGBAF);
  85. is_hdr = true;
  86. }
  87. int rdo_dict_size = GLOBAL_GET_CACHED(int, "rendering/textures/basis_universal/rdo_dict_size");
  88. bool zstd_supercompression = GLOBAL_GET_CACHED(bool, "rendering/textures/basis_universal/zstd_supercompression");
  89. int zstd_supercompression_level = GLOBAL_GET_CACHED(int, "rendering/textures/basis_universal/zstd_supercompression_level");
  90. basisu::basis_compressor_params params;
  91. params.m_uastc = true;
  92. params.m_pack_uastc_ldr_4x4_flags &= ~basisu::cPackUASTCLevelMask;
  93. params.m_pack_uastc_ldr_4x4_flags |= p_basisu_params.uastc_level;
  94. params.m_rdo_uastc_ldr_4x4 = p_basisu_params.rdo_quality_loss >= 0.01;
  95. params.m_rdo_uastc_ldr_4x4_quality_scalar = p_basisu_params.rdo_quality_loss;
  96. params.m_rdo_uastc_ldr_4x4_dict_size = rdo_dict_size;
  97. params.m_create_ktx2_file = true;
  98. params.m_ktx2_uastc_supercompression = zstd_supercompression ? basist::KTX2_SS_ZSTANDARD : basist::KTX2_SS_NONE;
  99. params.m_ktx2_zstd_supercompression_level = zstd_supercompression_level;
  100. params.m_mip_fast = true;
  101. params.m_multithreading = true;
  102. params.m_check_for_alpha = false;
  103. if (!OS::get_singleton()->is_stdout_verbose()) {
  104. params.m_print_stats = false;
  105. params.m_compute_stats = false;
  106. params.m_status_output = false;
  107. }
  108. basisu::job_pool job_pool(OS::get_singleton()->get_processor_count());
  109. params.m_pJob_pool = &job_pool;
  110. BasisDecompressFormat decompress_format = BASIS_DECOMPRESS_MAX;
  111. if (is_hdr) {
  112. decompress_format = BASIS_DECOMPRESS_HDR_RGB;
  113. params.m_hdr = true;
  114. params.m_uastc_hdr_4x4_options.set_quality_level(p_basisu_params.uastc_level);
  115. } else {
  116. switch (p_channels) {
  117. case Image::USED_CHANNELS_L: {
  118. decompress_format = BASIS_DECOMPRESS_RGB;
  119. } break;
  120. case Image::USED_CHANNELS_LA: {
  121. params.m_force_alpha = true;
  122. decompress_format = BASIS_DECOMPRESS_RGBA;
  123. } break;
  124. case Image::USED_CHANNELS_R: {
  125. decompress_format = BASIS_DECOMPRESS_R;
  126. } break;
  127. case Image::USED_CHANNELS_RG: {
  128. params.m_force_alpha = true;
  129. image->convert_rg_to_ra_rgba8();
  130. decompress_format = BASIS_DECOMPRESS_RG;
  131. } break;
  132. case Image::USED_CHANNELS_RGB: {
  133. decompress_format = BASIS_DECOMPRESS_RGB;
  134. } break;
  135. case Image::USED_CHANNELS_RGBA: {
  136. params.m_force_alpha = true;
  137. decompress_format = BASIS_DECOMPRESS_RGBA;
  138. } break;
  139. }
  140. }
  141. ERR_FAIL_COND_V(decompress_format == BASIS_DECOMPRESS_MAX, Vector<uint8_t>());
  142. // Copy the source image data with mipmaps into BasisU.
  143. {
  144. const int orig_width = image->get_width();
  145. const int orig_height = image->get_height();
  146. bool is_res_div_4 = (orig_width % 4 == 0) && (orig_height % 4 == 0);
  147. // Image's resolution rounded up to the nearest values divisible by 4.
  148. int next_width = orig_width <= 2 ? orig_width : (orig_width + 3) & ~3;
  149. int next_height = orig_height <= 2 ? orig_height : (orig_height + 3) & ~3;
  150. Vector<uint8_t> image_data = image->get_data();
  151. basisu::vector<basisu::image> basisu_mipmaps;
  152. basisu::vector<basisu::imagef> basisu_mipmaps_hdr;
  153. // Buffer for storing padded mipmap data.
  154. Vector<uint8_t> mip_data_padded;
  155. for (int32_t i = 0; i <= image->get_mipmap_count(); i++) {
  156. int64_t ofs, size;
  157. int width, height;
  158. image->get_mipmap_offset_size_and_dimensions(i, ofs, size, width, height);
  159. const uint8_t *image_mip_data = image_data.ptr() + ofs;
  160. // Pad the mipmap's data if its resolution isn't divisible by 4.
  161. if (image->has_mipmaps() && !is_res_div_4 && (width > 2 && height > 2) && (width != next_width || height != next_height)) {
  162. if (is_hdr) {
  163. _basisu_pad_mipmap<BasisRGBAF>(image_mip_data, mip_data_padded, next_width, next_height, width, height, size);
  164. } else {
  165. _basisu_pad_mipmap<uint32_t>(image_mip_data, mip_data_padded, next_width, next_height, width, height, size);
  166. }
  167. // Override the image_mip_data pointer with our temporary Vector.
  168. image_mip_data = reinterpret_cast<const uint8_t *>(mip_data_padded.ptr());
  169. // Override the mipmap's properties.
  170. width = next_width;
  171. height = next_height;
  172. size = mip_data_padded.size();
  173. }
  174. // Get the next mipmap's resolution.
  175. next_width /= 2;
  176. next_height /= 2;
  177. // Copy the source mipmap's data to a BasisU image.
  178. if (is_hdr) {
  179. basisu::imagef basisu_image(width, height);
  180. memcpy(reinterpret_cast<uint8_t *>(basisu_image.get_ptr()), image_mip_data, size);
  181. if (i == 0) {
  182. params.m_source_images_hdr.push_back(basisu_image);
  183. } else {
  184. basisu_mipmaps_hdr.push_back(basisu_image);
  185. }
  186. } else {
  187. basisu::image basisu_image(width, height);
  188. memcpy(basisu_image.get_ptr(), image_mip_data, size);
  189. if (i == 0) {
  190. params.m_source_images.push_back(basisu_image);
  191. } else {
  192. basisu_mipmaps.push_back(basisu_image);
  193. }
  194. }
  195. }
  196. if (is_hdr) {
  197. params.m_source_mipmap_images_hdr.push_back(basisu_mipmaps_hdr);
  198. } else {
  199. params.m_source_mipmap_images.push_back(basisu_mipmaps);
  200. }
  201. }
  202. // Encode the image data.
  203. basisu::basis_compressor compressor;
  204. compressor.init(params);
  205. int basisu_err = compressor.process();
  206. ERR_FAIL_COND_V(basisu_err != basisu::basis_compressor::cECSuccess, Vector<uint8_t>());
  207. const basisu::uint8_vec &basisu_encoded = compressor.get_output_ktx2_file();
  208. Vector<uint8_t> basisu_data;
  209. basisu_data.resize(basisu_encoded.size() + 4);
  210. uint8_t *basisu_data_ptr = basisu_data.ptrw();
  211. // Copy the encoded BasisU data into the output buffer.
  212. *(uint32_t *)basisu_data_ptr = decompress_format | BASIS_DECOMPRESS_FLAG_KTX2;
  213. memcpy(basisu_data_ptr + 4, basisu_encoded.get_ptr(), basisu_encoded.size());
  214. print_verbose(vformat("BasisU: Encoding a %dx%d image with %d mipmaps took %d ms.", p_image->get_width(), p_image->get_height(), p_image->get_mipmap_count(), OS::get_singleton()->get_ticks_msec() - start_time));
  215. return basisu_data;
  216. }
  217. #endif // TOOLS_ENABLED
  218. Ref<Image> basis_universal_unpacker_ptr(const uint8_t *p_data, int p_size) {
  219. uint64_t start_time = OS::get_singleton()->get_ticks_msec();
  220. Ref<Image> image;
  221. ERR_FAIL_NULL_V_MSG(p_data, image, "Cannot unpack invalid BasisUniversal data.");
  222. const uint8_t *src_ptr = p_data;
  223. int src_size = p_size;
  224. basist::transcoder_texture_format basisu_format = basist::transcoder_texture_format::cTFTotalTextureFormats;
  225. Image::Format image_format = Image::FORMAT_MAX;
  226. // Get supported compression formats.
  227. bool bptc_supported = RS::get_singleton()->has_os_feature("bptc");
  228. bool astc_supported = RS::get_singleton()->has_os_feature("astc");
  229. bool rgtc_supported = RS::get_singleton()->has_os_feature("rgtc");
  230. bool s3tc_supported = RS::get_singleton()->has_os_feature("s3tc");
  231. bool etc2_supported = RS::get_singleton()->has_os_feature("etc2");
  232. bool astc_hdr_supported = RS::get_singleton()->has_os_feature("astc_hdr");
  233. bool needs_ra_rg_swap = false;
  234. bool needs_rg_trim = false;
  235. uint32_t decompress_format = *(uint32_t *)(src_ptr);
  236. bool is_ktx2 = decompress_format & BASIS_DECOMPRESS_FLAG_KTX2;
  237. decompress_format &= ~BASIS_DECOMPRESS_FLAG_KTX2;
  238. switch (decompress_format) {
  239. case BASIS_DECOMPRESS_R: {
  240. if (rgtc_supported) {
  241. basisu_format = basist::transcoder_texture_format::cTFBC4_R;
  242. image_format = Image::FORMAT_RGTC_R;
  243. } else if (s3tc_supported) {
  244. basisu_format = basist::transcoder_texture_format::cTFBC1;
  245. image_format = Image::FORMAT_DXT1;
  246. } else if (etc2_supported) {
  247. basisu_format = basist::transcoder_texture_format::cTFETC2_EAC_R11;
  248. image_format = Image::FORMAT_ETC2_R11;
  249. } else {
  250. // No supported VRAM compression formats, decompress.
  251. basisu_format = basist::transcoder_texture_format::cTFRGBA32;
  252. image_format = Image::FORMAT_RGBA8;
  253. needs_rg_trim = true;
  254. }
  255. } break;
  256. case BASIS_DECOMPRESS_RG: {
  257. if (rgtc_supported) {
  258. basisu_format = basist::transcoder_texture_format::cTFBC5_RG;
  259. image_format = Image::FORMAT_RGTC_RG;
  260. } else if (s3tc_supported) {
  261. basisu_format = basist::transcoder_texture_format::cTFBC3;
  262. image_format = Image::FORMAT_DXT5_RA_AS_RG;
  263. } else if (etc2_supported) {
  264. basisu_format = basist::transcoder_texture_format::cTFETC2_EAC_RG11;
  265. image_format = Image::FORMAT_ETC2_RG11;
  266. } else {
  267. // No supported VRAM compression formats, decompress.
  268. basisu_format = basist::transcoder_texture_format::cTFRGBA32;
  269. image_format = Image::FORMAT_RGBA8;
  270. needs_ra_rg_swap = true;
  271. needs_rg_trim = true;
  272. }
  273. } break;
  274. case BASIS_DECOMPRESS_RG_AS_RA: {
  275. if (s3tc_supported) {
  276. basisu_format = basist::transcoder_texture_format::cTFBC3;
  277. image_format = Image::FORMAT_DXT5_RA_AS_RG;
  278. } else if (etc2_supported) {
  279. basisu_format = basist::transcoder_texture_format::cTFETC2;
  280. image_format = Image::FORMAT_ETC2_RA_AS_RG;
  281. } else {
  282. // No supported VRAM compression formats, decompress.
  283. basisu_format = basist::transcoder_texture_format::cTFRGBA32;
  284. image_format = Image::FORMAT_RGBA8;
  285. needs_ra_rg_swap = true;
  286. needs_rg_trim = true;
  287. }
  288. } break;
  289. case BASIS_DECOMPRESS_RGB: {
  290. if (bptc_supported) {
  291. basisu_format = basist::transcoder_texture_format::cTFBC7_M6_OPAQUE_ONLY;
  292. image_format = Image::FORMAT_BPTC_RGBA;
  293. } else if (astc_supported) {
  294. basisu_format = basist::transcoder_texture_format::cTFASTC_4x4_RGBA;
  295. image_format = Image::FORMAT_ASTC_4x4;
  296. } else if (s3tc_supported) {
  297. basisu_format = basist::transcoder_texture_format::cTFBC1;
  298. image_format = Image::FORMAT_DXT1;
  299. } else if (etc2_supported) {
  300. basisu_format = basist::transcoder_texture_format::cTFETC1;
  301. image_format = Image::FORMAT_ETC2_RGB8;
  302. } else {
  303. // No supported VRAM compression formats, decompress.
  304. basisu_format = basist::transcoder_texture_format::cTFRGBA32;
  305. image_format = Image::FORMAT_RGBA8;
  306. }
  307. } break;
  308. case BASIS_DECOMPRESS_RGBA: {
  309. if (bptc_supported) {
  310. basisu_format = basist::transcoder_texture_format::cTFBC7_M5;
  311. image_format = Image::FORMAT_BPTC_RGBA;
  312. } else if (astc_supported) {
  313. basisu_format = basist::transcoder_texture_format::cTFASTC_4x4_RGBA;
  314. image_format = Image::FORMAT_ASTC_4x4;
  315. } else if (s3tc_supported) {
  316. basisu_format = basist::transcoder_texture_format::cTFBC3;
  317. image_format = Image::FORMAT_DXT5;
  318. } else if (etc2_supported) {
  319. basisu_format = basist::transcoder_texture_format::cTFETC2;
  320. image_format = Image::FORMAT_ETC2_RGBA8;
  321. } else {
  322. // No supported VRAM compression formats, decompress.
  323. basisu_format = basist::transcoder_texture_format::cTFRGBA32;
  324. image_format = Image::FORMAT_RGBA8;
  325. }
  326. } break;
  327. case BASIS_DECOMPRESS_HDR_RGB: {
  328. if (bptc_supported) {
  329. basisu_format = basist::transcoder_texture_format::cTFBC6H;
  330. image_format = Image::FORMAT_BPTC_RGBFU;
  331. } else if (astc_hdr_supported) {
  332. basisu_format = basist::transcoder_texture_format::cTFASTC_HDR_4x4_RGBA;
  333. image_format = Image::FORMAT_ASTC_4x4_HDR;
  334. } else {
  335. // No supported VRAM compression formats, decompress.
  336. basisu_format = basist::transcoder_texture_format::cTFRGB_9E5;
  337. image_format = Image::FORMAT_RGBE9995;
  338. }
  339. } break;
  340. default: {
  341. ERR_FAIL_V(image);
  342. } break;
  343. }
  344. src_ptr += 4;
  345. src_size -= 4;
  346. if (is_ktx2) {
  347. basist::ktx2_transcoder transcoder;
  348. ERR_FAIL_COND_V(!transcoder.init(src_ptr, src_size), image);
  349. transcoder.start_transcoding();
  350. // Create the buffer for transcoded/decompressed data.
  351. Vector<uint8_t> out_data;
  352. out_data.resize(Image::get_image_data_size(transcoder.get_width(), transcoder.get_height(), image_format, transcoder.get_levels() > 1));
  353. uint8_t *dst = out_data.ptrw();
  354. memset(dst, 0, out_data.size());
  355. for (uint32_t i = 0; i < transcoder.get_levels(); i++) {
  356. basist::ktx2_image_level_info basisu_level;
  357. transcoder.get_image_level_info(basisu_level, i, 0, 0);
  358. uint32_t mip_block_or_pixel_count = Image::is_format_compressed(image_format) ? basisu_level.m_total_blocks : basisu_level.m_orig_width * basisu_level.m_orig_height;
  359. int64_t ofs = Image::get_image_mipmap_offset(transcoder.get_width(), transcoder.get_height(), image_format, i);
  360. bool result = transcoder.transcode_image_level(i, 0, 0, dst + ofs, mip_block_or_pixel_count, basisu_format);
  361. if (!result) {
  362. print_line(vformat("BasisUniversal cannot unpack level %d.", i));
  363. break;
  364. }
  365. }
  366. image = Image::create_from_data(transcoder.get_width(), transcoder.get_height(), transcoder.get_levels() > 1, image_format, out_data);
  367. } else {
  368. basist::basisu_transcoder transcoder;
  369. ERR_FAIL_COND_V(!transcoder.validate_header(src_ptr, src_size), image);
  370. transcoder.start_transcoding(src_ptr, src_size);
  371. basist::basisu_image_info basisu_info;
  372. transcoder.get_image_info(src_ptr, src_size, basisu_info, 0);
  373. // Create the buffer for transcoded/decompressed data.
  374. Vector<uint8_t> out_data;
  375. out_data.resize(Image::get_image_data_size(basisu_info.m_width, basisu_info.m_height, image_format, basisu_info.m_total_levels > 1));
  376. uint8_t *dst = out_data.ptrw();
  377. memset(dst, 0, out_data.size());
  378. for (uint32_t i = 0; i < basisu_info.m_total_levels; i++) {
  379. basist::basisu_image_level_info basisu_level;
  380. transcoder.get_image_level_info(src_ptr, src_size, basisu_level, 0, i);
  381. uint32_t mip_block_or_pixel_count = Image::is_format_compressed(image_format) ? basisu_level.m_total_blocks : basisu_level.m_orig_width * basisu_level.m_orig_height;
  382. int64_t ofs = Image::get_image_mipmap_offset(basisu_info.m_width, basisu_info.m_height, image_format, i);
  383. bool result = transcoder.transcode_image_level(src_ptr, src_size, 0, i, dst + ofs, mip_block_or_pixel_count, basisu_format);
  384. if (!result) {
  385. print_line(vformat("BasisUniversal cannot unpack level %d.", i));
  386. break;
  387. }
  388. }
  389. image = Image::create_from_data(basisu_info.m_width, basisu_info.m_height, basisu_info.m_total_levels > 1, image_format, out_data);
  390. }
  391. if (needs_ra_rg_swap) {
  392. // Swap uncompressed RA-as-RG texture's color channels.
  393. image->convert_ra_rgba8_to_rg();
  394. }
  395. if (needs_rg_trim) {
  396. // Remove unnecessary color channels from uncompressed textures.
  397. if (decompress_format == BASIS_DECOMPRESS_R) {
  398. image->convert(Image::FORMAT_R8);
  399. } else if (decompress_format == BASIS_DECOMPRESS_RG || decompress_format == BASIS_DECOMPRESS_RG_AS_RA) {
  400. image->convert(Image::FORMAT_RG8);
  401. }
  402. }
  403. print_verbose(vformat("BasisU: Transcoding a %dx%d image with %d mipmaps into %s took %d ms.",
  404. image->get_width(), image->get_height(), image->get_mipmap_count(), Image::get_format_name(image_format), OS::get_singleton()->get_ticks_msec() - start_time));
  405. return image;
  406. }
  407. Ref<Image> basis_universal_unpacker(const Vector<uint8_t> &p_buffer) {
  408. return basis_universal_unpacker_ptr(p_buffer.ptr(), p_buffer.size());
  409. }