X-Git-Url: http://git.dev.opencascade.org/gitweb/?p=occt.git;a=blobdiff_plain;f=src%2FGraphic3d%2FGraphic3d_TextureRoot.cxx;h=21ec53ff5a7930c479352e4620930f475c6b6e26;hb=faff37677c2293ad207e6ad3e308aa65ffcd6375;hpb=691711cd3e118643fc475c59d6eb83f410de5c65 diff --git a/src/Graphic3d/Graphic3d_TextureRoot.cxx b/src/Graphic3d/Graphic3d_TextureRoot.cxx index 919086c5c3..21ec53ff5a 100644 --- a/src/Graphic3d/Graphic3d_TextureRoot.cxx +++ b/src/Graphic3d/Graphic3d_TextureRoot.cxx @@ -19,9 +19,12 @@ #include #include #include +#include +#include #include #include #include +#include #include #include @@ -90,7 +93,8 @@ Graphic3d_TextureRoot::Graphic3d_TextureRoot (const TCollection_AsciiString& the myPath (theFileName), myRevision (0), myType (theType), - myIsColorMap (true) + myIsColorMap (true), + myIsTopDown (true) { generateId(); } @@ -105,7 +109,8 @@ Graphic3d_TextureRoot::Graphic3d_TextureRoot (const Handle(Image_PixMap)& theP myPixMap (thePixMap), myRevision (0), myType (theType), - myIsColorMap (true) + myIsColorMap (true), + myIsTopDown (true) { generateId(); } @@ -129,15 +134,57 @@ void Graphic3d_TextureRoot::generateId() + TCollection_AsciiString (Standard_Atomic_Increment (&THE_TEXTURE_COUNTER)); } +// ======================================================================= +// function : GetCompressedImage +// purpose : +// ======================================================================= +Handle(Image_CompressedPixMap) Graphic3d_TextureRoot::GetCompressedImage (const Handle(Image_SupportedFormats)& theSupported) +{ + if (!myPixMap.IsNull()) + { + return Handle(Image_CompressedPixMap)(); + } + + // Case 2: texture source is specified as path + TCollection_AsciiString aFilePath; + myPath.SystemName (aFilePath); + if (aFilePath.IsEmpty()) + { + return Handle(Image_CompressedPixMap)(); + } + + TCollection_AsciiString aFilePathLower = aFilePath; + aFilePathLower.LowerCase(); + if (!aFilePathLower.EndsWith (".dds")) + { + // do not waste time on file system access in case of wrong file extension + return Handle(Image_CompressedPixMap)(); + } + + if (Handle(Image_CompressedPixMap) anImage = Image_DDSParser::Load (theSupported, aFilePath, 0)) + { + myIsTopDown = anImage->IsTopDown(); + return anImage; + } + return Handle(Image_CompressedPixMap)(); +} + // ======================================================================= // function : GetImage // purpose : // ======================================================================= -Handle(Image_PixMap) Graphic3d_TextureRoot::GetImage() const +Handle(Image_PixMap) Graphic3d_TextureRoot::GetImage (const Handle(Image_SupportedFormats)& theSupported) { + if (Handle(Image_PixMap) anOldImage = GetImage()) + { + myIsTopDown = anOldImage->IsTopDown(); + return anOldImage; // compatibility with old API + } + // Case 1: texture source is specified as pixmap if (!myPixMap.IsNull()) { + myIsTopDown = myPixMap->IsTopDown(); return myPixMap; } @@ -150,12 +197,38 @@ Handle(Image_PixMap) Graphic3d_TextureRoot::GetImage() const } Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap(); - if (!anImage->Load (aFilePath)) + if (anImage->Load (aFilePath)) { - return Handle(Image_PixMap)(); + myIsTopDown = anImage->IsTopDown(); + convertToCompatible (theSupported, anImage); + return anImage; + } + + return Handle(Image_PixMap)(); +} + +// ======================================================================= +// function : convertToCompatible +// purpose : +// ======================================================================= +void Graphic3d_TextureRoot::convertToCompatible (const Handle(Image_SupportedFormats)& theSupported, + const Handle(Image_PixMap)& theImage) +{ + if (theSupported.IsNull() + || theSupported->IsSupported (theImage->Format()) + || theImage.IsNull()) + { + return; } - return anImage; + if ((theImage->Format() == Image_Format_BGR32 + || theImage->Format() == Image_Format_BGR32)) + { + Image_PixMap::SwapRgbaBgra (*theImage); + theImage->SetFormat (theImage->Format() == Image_Format_BGR32 + ? Image_Format_RGB32 + : Image_Format_RGBA); + } } // =======================================================================