MCPcopy Create free account
hub / github.com/GPUOpen-Tools/compressonator / CMP_SaveTexture

Function CMP_SaveTexture

cmp_framework/compute_base.cpp:783–836  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

781}
782
783CMP_ERROR CMP_API CMP_SaveTexture(const char* DestFile, CMP_MipSet* MipSetIn)
784{
785 CMP_RegisterHostPlugins(); // Keep for legacy, user should now use CMP_InitFramework
786
787 bool filesaved = false;
788 CMIPS m_CMIPS;
789
790 const std::string& fn = DestFile;
791
792 std::string file_extension = fn.substr(fn.find_last_of('.') + 1);
793
794 std::transform(file_extension.begin(), file_extension.end(), file_extension.begin(), toupperChar);
795
796 //if (((((file_extension.compare("DDS") == 0)
797 // || file_extension.compare("KTX") == 0)
798 // || file_extension.compare("KTX2") == 0))
799 // != TRUE)
800 // {
801 // return CMP_ERR_INVALID_DEST_TEXTURE;
802 //}
803
804 PluginInterface_Image* plugin_Image;
805 plugin_Image = reinterpret_cast<PluginInterface_Image*>(g_pluginManager.GetPlugin("IMAGE", (char*)file_extension.c_str()));
806
807 if (plugin_Image)
808 {
809 bool holdswizzle = MipSetIn->m_swizzle;
810
811 plugin_Image->TC_PluginSetSharedIO(&m_CMIPS);
812 if (plugin_Image->TC_PluginFileSaveTexture(DestFile, (MipSet*)MipSetIn) == 0)
813 {
814 filesaved = true;
815 }
816
817 MipSetIn->m_swizzle = holdswizzle;
818
819 delete plugin_Image;
820 plugin_Image = NULL;
821 }
822
823 if (!filesaved)
824 { // ToDo create a stb_save()
825 if (file_extension.compare("PNG") == 0)
826 stbi_write_png(DestFile, MipSetIn->m_nWidth, MipSetIn->m_nHeight, 4, MipSetIn->pData, MipSetIn->m_nWidth * 4);
827 else if (file_extension.compare("BMP") == 0)
828 stbi_write_bmp(DestFile, MipSetIn->m_nWidth, MipSetIn->m_nHeight, 4, MipSetIn->pData);
829 else if (file_extension.compare("JPG") == 0)
830 stbi_write_jpg(DestFile, MipSetIn->m_nWidth, MipSetIn->m_nHeight, 4, MipSetIn->pData, 100);
831 else
832 return CMP_ERR_GENERIC;
833 }
834
835 return CMP_OK;
836}
837
838CMP_INT CMP_API CMP_NumberOfProcessors(void)
839{

Callers 5

mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 10

CMP_RegisterHostPluginsFunction · 0.85
stbi_write_pngFunction · 0.85
stbi_write_bmpFunction · 0.85
stbi_write_jpgFunction · 0.85
GetPluginMethod · 0.80
transformFunction · 0.50
beginMethod · 0.45
endMethod · 0.45
TC_PluginSetSharedIOMethod · 0.45

Tested by

no test coverage detected