Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions OgreMain/include/OgreCodec.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ namespace Ogre {
@return A blank string if the magic number was unknown, or a file extension.
*/
virtual String magicNumberToFileExt(const char *magicNumberPtr, size_t maxbytes) const = 0;

virtual bool setParameter(const String& name, const String& value) { return false; }
};
/** @} */
/** @} */
Expand Down
65 changes: 48 additions & 17 deletions OgreMain/src/OgreDDSCodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,12 @@ namespace {
}
//---------------------------------------------------------------------
DDSCodec::DDSCodec():
mType("dds")
mType("dds"),
mDecodeEnforce(false)
{
}
//---------------------------------------------------------------------
void DDSCodec::encodeToFile(const Any& input, const String& outFileName) const
DataStreamPtr DDSCodec::encode(const Any& input) const
{
Image* image = any_cast<Image*>(input);

Expand Down Expand Up @@ -402,21 +403,42 @@ namespace {
dataPtr = tmpData;
}

try
{
// Write the file
std::ofstream of;
of.open(outFileName.c_str(), std::ios_base::binary|std::ios_base::out);
of.write((const char *)&ddsMagic, sizeof(uint32));
of.write((const char *)&ddsHeader, DDS_HEADER_SIZE);
// XXX flipEndian on each pixel chunk written unless isFloat32r ?
of.write(dataPtr, image->getSize());
of.close();
}
catch(...)
{
}
size_t totalSize = sizeof(uint32) + DDS_HEADER_SIZE + image->getSize();
auto pMemStream = OGRE_NEW Ogre::MemoryDataStream(totalSize);

pMemStream->write(&ddsMagic, sizeof(uint32));
pMemStream->write(&ddsHeader, DDS_HEADER_SIZE);
pMemStream->write(dataPtr, image->getSize());
pMemStream->seek(0);

delete [] tmpData;

return Ogre::DataStreamPtr(pMemStream);
}
}
//---------------------------------------------------------------------
void DDSCodec::encodeToFile(const Any& input, const String& outFileName) const
{
DataStreamPtr strm = encode(input);

try
{
// Write the file
std::ofstream of;
of.open(outFileName.c_str(), std::ios_base::binary | std::ios_base::out);

const size_t buffSize = 4096;
char buffer[buffSize];

while (!strm->eof()) {
size_t bytesRead = strm->read(buffer, buffSize);
of.write(buffer, bytesRead);
}

of.close();
}
catch(...)
{
}
}
//---------------------------------------------------------------------
Expand Down Expand Up @@ -824,7 +846,8 @@ namespace {
if (PixelUtil::isCompressed(sourceFormat))
{
if (Root::getSingleton().getRenderSystem() == NULL ||
!Root::getSingleton().getRenderSystem()->getCapabilities()->hasCapability(RSC_TEXTURE_COMPRESSION_DXT))
!Root::getSingleton().getRenderSystem()->getCapabilities()->hasCapability(RSC_TEXTURE_COMPRESSION_DXT) ||
mDecodeEnforce)
{
// We'll need to decompress
decompressDXT = true;
Expand Down Expand Up @@ -1043,6 +1066,14 @@ namespace {
return BLANKSTRING;

}
//---------------------------------------------------------------------
bool DDSCodec::setParameter(const String& name, const String& value)
{
if (name == "decode_enforce")
return StringConverter::parse(value, mDecodeEnforce);

return false;
}

}

5 changes: 5 additions & 0 deletions OgreMain/src/OgreDDSCodec.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ namespace Ogre {
struct DXTExplicitAlphaBlock;
struct DXTInterpolatedAlphaBlock;


/** Codec specialized in loading DDS (Direct Draw Surface) images.

We implement our own codec here since we need to be able to keep DXT
Expand All @@ -53,6 +54,7 @@ namespace Ogre {
{
private:
String mType;
bool mDecodeEnforce;

PixelFormat convertFourCCFormat(uint32 fourcc) const;
PixelFormat convertDXToOgreFormat(uint32 fourcc) const;
Expand All @@ -72,6 +74,7 @@ namespace Ogre {
DDSCodec();
virtual ~DDSCodec() { }

DataStreamPtr encode(const Any& input) const override;
void encodeToFile(const Any& input, const String& outFileName) const override;
void decode(const DataStreamPtr& input, const Any& output) const override;
String magicNumberToFileExt(const char *magicNumberPtr, size_t maxbytes) const override;
Expand All @@ -82,6 +85,8 @@ namespace Ogre {
/// Static method to shutdown and unregister the DDS codec
static void shutdown(void);

bool setParameter(const String& name, const String& value) override;

};
/** @} */
/** @} */
Expand Down