MCPcopy Create free account
hub / github.com/GDRETools/gdsdecomp / load_image_from_fileV3

Method load_image_from_fileV3

compat/texture_loader_compat.cpp:275–429  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

273}
274
275Error TextureLoaderCompat::load_image_from_fileV3(Ref<FileAccess> f, int tw, int th, int tw_custom, int th_custom, int flags, int p_size_limit, uint32_t df, Ref<Image> &image) {
276 Image::Format format;
277 if (!(df & FORMAT_BIT_STREAM)) {
278 // do something??
279 }
280 if (df & FORMAT_BIT_PNG || df & FORMAT_BIT_WEBP) {
281 //look for a PNG or WEBP file inside
282
283 int sw = tw;
284 int sh = th;
285
286 uint32_t mipmaps = f->get_32();
287 uint32_t size = f->get_32();
288
289 //print_line("mipmaps: " + itos(mipmaps));
290
291 // This is dead code; p_size_limit is always 0, and Godot 3.x never uses it
292 while (mipmaps > 1 && p_size_limit > 0 && (sw > p_size_limit || sh > p_size_limit)) {
293 f->seek(f->get_position() + size);
294 mipmaps = f->get_32();
295 size = f->get_32();
296
297 sw = MAX(sw >> 1, 1);
298 sh = MAX(sh >> 1, 1);
299 mipmaps--;
300 }
301
302 // mipmaps need to be read independently, they will be later combined
303 Vector<Ref<Image>> mipmap_images;
304 int total_size = 0;
305
306 for (uint32_t i = 0; i < mipmaps; i++) {
307 if (i) {
308 size = f->get_32();
309 }
310 if (size == 0) {
311 ERR_FAIL_V_MSG(ERR_FILE_EOF, "Texture is empty");
312 }
313 Vector<uint8_t> pv;
314 pv.resize(size);
315 {
316 uint8_t *wr = pv.ptrw();
317 f->get_buffer(wr, size);
318 }
319
320 Ref<Image> img;
321 if (df & FORMAT_BIT_PNG) {
322 img = Image::png_unpacker(pv);
323 } else {
324 img = WebPCompat::webp_unpack_v2v3(pv);
325 }
326 ERR_FAIL_COND_V_MSG(img.is_null() || img->is_empty(), ERR_FILE_CORRUPT, "File is corrupt");
327
328 if (i != 0) {
329 img->convert(mipmap_images[0]->get_format()); // ensure the same format for all mipmaps
330 }
331
332 total_size += img->get_data().size();

Callers

nothing calls this directly

Calls 10

webp_unpack_v2v3Function · 0.85
FormatEnum · 0.85
push_backMethod · 0.80
seekMethod · 0.45
get_positionMethod · 0.45
resizeMethod · 0.45
get_bufferMethod · 0.45
convertMethod · 0.45
sizeMethod · 0.45
get_dataMethod · 0.45

Tested by

no test coverage detected