Skip to content

Commit

Permalink
Force JPEG compression option
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbui78 committed Oct 21, 2023
1 parent c9a1eb6 commit fbf01a8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/DzBridgeAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ namespace DzBridgeNameSpace

// Texture Settings
bool m_bConvertToPng = false;
bool m_bConvertToJpg = false; // m_bConvertToJpg will override m_bConvertToPng
bool m_bExportAllTextures = false;
bool m_bCombineDiffuseAndAlphaMaps = false;
bool m_bResizeTextures = false;
Expand Down
17 changes: 14 additions & 3 deletions src/DzBridgeAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2412,6 +2412,8 @@ QString DzBridgeAction::exportAssetWithDtu(QString sFilename, QString sAssetMate

}

// TODO: This method will fail because uncompressed textures of the same dimension
// will have the same file size. Instead, must use a file content hash function.
QString DzBridgeAction::makeUniqueFilename(QString sFilename)
{
if (QFileInfo(sFilename).exists() != true)
Expand Down Expand Up @@ -2675,9 +2677,10 @@ void DzBridgeAction::writeMaterialProperty(DzNode* Node, DzJsonWriter& Writer, Q
if (TextureName != "")
{
// DB 2023-Oct-5: Save to PNG, Export all Textures
if (m_bConvertToPng)
if (m_bConvertToPng || m_bConvertToJpg)
{
if (TextureName.endsWith(".png", Qt::CaseInsensitive) == false &&
if ( m_bConvertToJpg ||
TextureName.endsWith(".png", Qt::CaseInsensitive) == false &&
TextureName.endsWith(".jpg", Qt::CaseInsensitive) == false &&
TextureName.endsWith(".jpeg", Qt::CaseInsensitive) == false)
{
Expand All @@ -2687,7 +2690,15 @@ void DzBridgeAction::writeMaterialProperty(DzNode* Node, DzJsonWriter& Writer, Q
QString cleanedTempPath = dzApp->getTempPath().toLower().replace("\\", "/");
QString filestem = QFileInfo(TextureName).fileName();
QString pngFilename = cleanedTempPath + "/" + filestem + ".png";
imageMgr->saveImage(pngFilename, image);
if (m_bConvertToJpg)
{
pngFilename = cleanedTempPath + "/" + filestem + ".jpg";
image.save(pngFilename, "jpg", 95);
}
else
{
imageMgr->saveImage(pngFilename, image);
}
dtuTextureName = TextureName = pngFilename;
}
}
Expand Down

0 comments on commit fbf01a8

Please sign in to comment.