MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / decode_header

Function decode_header

Source/ThirdParty/ddspp/ddspp.h:731–995  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

729 }
730
731 inline Result decode_header(const unsigned char* sourceData, Descriptor& desc)
732 {
733 unsigned int magic = *reinterpret_cast<const unsigned int*>(sourceData); // First 4 bytes are the magic DDS number
734
735 if (magic != DDS_MAGIC)
736 {
737 return ddspp::Error;
738 }
739
740 const Header header = *reinterpret_cast<const Header*>(sourceData + sizeof(DDS_MAGIC));
741 const PixelFormat& ddspf = header.ddspf;
742 bool dxt10Extension = is_dxt10(header);
743 const HeaderDXT10 dxt10Header = *reinterpret_cast<const HeaderDXT10*>(sourceData + sizeof(DDS_MAGIC) + sizeof(Header));
744
745 // Read basic data from the header
746 desc.width = header.width > 0 ? header.width : 1;
747 desc.height = header.height > 0 ? header.height : 1;
748 desc.depth = header.depth > 0 ? header.depth : 1;
749 desc.numMips = header.mipMapCount > 0 ? header.mipMapCount : 1;
750
751 // Set some sensible defaults
752 desc.arraySize = 1;
753 desc.srgb = false;
754 desc.type = Texture2D;
755 desc.format = UNKNOWN;
756
757 if (dxt10Extension)
758 {
759 desc.format = dxt10Header.dxgiFormat;
760
761 desc.arraySize = dxt10Header.arraySize;
762
763 switch(dxt10Header.resourceDimension)
764 {
765 case DXGI_Texture1D:
766 desc.depth = 1;
767 desc.type = Texture1D;
768 break;
769 case DXGI_Texture2D:
770 desc.depth = 1;
771
772 if(dxt10Header.miscFlag & DXGI_MISC_FLAG_CUBEMAP)
773 {
774 desc.type = Cubemap;
775 }
776 else
777 {
778 desc.type = Texture2D;
779 }
780
781 break;
782 case DXGI_Texture3D:
783 desc.type = Texture3D;
784 desc.arraySize = 1; // There are no 3D texture arrays
785 break;
786 default:
787 break;
788 }

Callers 1

ImportTextureStbMethod · 0.85

Calls 8

is_dxt10Function · 0.85
is_rgba_maskFunction · 0.85
is_rgb_maskFunction · 0.85
is_compressedFunction · 0.85
is_srgbFunction · 0.85
get_block_sizeFunction · 0.85
get_row_pitchFunction · 0.85

Tested by

no test coverage detected