MCPcopy Create free account
hub / github.com/BinomialLLC/basis_universal / load_tga

Function load_tga

encoder/basisu_enc.cpp:417–467  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

415 const uint32_t MAX_32BIT_ALLOC_SIZE = 250000000;
416
417 bool load_tga(const char* pFilename, image& img)
418 {
419 int w = 0, h = 0, n_chans = 0;
420 uint8_t* pImage_data = read_tga(pFilename, w, h, n_chans);
421
422 if ((!pImage_data) || (!w) || (!h) || ((n_chans != 3) && (n_chans != 4)))
423 {
424 error_printf("Failed loading .TGA image \"%s\"!\n", pFilename);
425
426 if (pImage_data)
427 free(pImage_data);
428
429 return false;
430 }
431
432 if (sizeof(void *) == sizeof(uint32_t))
433 {
434 if (((uint64_t)w * h * n_chans) > MAX_32BIT_ALLOC_SIZE)
435 {
436 error_printf("Image \"%s\" is too large (%ux%u) to process in a 32-bit build!\n", pFilename, w, h);
437
438 if (pImage_data)
439 free(pImage_data);
440
441 return false;
442 }
443 }
444
445 img.resize(w, h);
446
447 const uint8_t *pSrc = pImage_data;
448 for (int y = 0; y < h; y++)
449 {
450 color_rgba *pDst = &img(0, y);
451
452 for (int x = 0; x < w; x++)
453 {
454 pDst->r = pSrc[0];
455 pDst->g = pSrc[1];
456 pDst->b = pSrc[2];
457 pDst->a = (n_chans == 3) ? 255 : pSrc[3];
458
459 pSrc += n_chans;
460 ++pDst;
461 }
462 }
463
464 free(pImage_data);
465
466 return true;
467 }
468
469 bool load_qoi(const char* pFilename, image& img)
470 {

Callers 1

load_imageFunction · 0.70

Calls 3

read_tgaFunction · 0.85
error_printfFunction · 0.85
resizeMethod · 0.45

Tested by

no test coverage detected