MCPcopy Create free account
hub / github.com/crownengine/crown / imageParseStbImage

Function imageParseStbImage

3rdparty/bimg/src/image_decode.cpp:647–701  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

645 }
646
647 static ImageContainer* imageParseStbImage(bx::AllocatorI* _allocator, const void* _data, uint32_t _size, bx::Error* _err)
648 {
649 BX_ERROR_SCOPE(_err);
650
651 const int isHdr = stbi_is_hdr_from_memory( (const uint8_t*)_data, (int)_size);
652
653 void* data;
654 uint32_t width = 0;
655 uint32_t height = 0;
656 int comp = 0;
657 if (isHdr)
658 {
659 data = stbi_loadf_from_memory( (const uint8_t*)_data, (int)_size, (int*)&width, (int*)&height, &comp, 4);
660 }
661 else
662 {
663 data = stbi_load_from_memory ( (const uint8_t*)_data, (int)_size, (int*)&width, (int*)&height, &comp, 0);
664 }
665
666 if (NULL == data)
667 {
668 return NULL;
669 }
670
671 bimg::TextureFormat::Enum format = bimg::TextureFormat::RGBA8;
672
673 if (isHdr)
674 {
675 format = bimg::TextureFormat::RGBA32F;
676 }
677 else
678 {
679 switch (comp)
680 {
681 case 1: format = bimg::TextureFormat::R8; break;
682 case 2: format = bimg::TextureFormat::RG8; break;
683 case 3: format = bimg::TextureFormat::RGB8; break;
684 default: break;
685 }
686 }
687
688 ImageContainer* output = imageAlloc(_allocator
689 , format
690 , bx::narrowCast<uint16_t>(width)
691 , bx::narrowCast<uint16_t>(height)
692 , 0
693 , 1
694 , false
695 , false
696 , data
697 );
698 stbi_image_free(data);
699
700 return output;
701 }
702
703 static ImageContainer* imageParseJpeg(bx::AllocatorI* _allocator, const void* _data, uint32_t _size, bx::Error* _err)
704 {

Callers 2

imageParseJpegFunction · 0.85
imageParseFunction · 0.85

Calls 5

stbi_is_hdr_from_memoryFunction · 0.85
stbi_loadf_from_memoryFunction · 0.85
stbi_load_from_memoryFunction · 0.85
imageAllocFunction · 0.85
stbi_image_freeFunction · 0.85

Tested by

no test coverage detected