add res cache, fix size bug, support 8K exports

This commit is contained in:
Syping 2023-05-10 17:59:30 +02:00
parent 0e6a6ae34a
commit bb06af8a79
8 changed files with 46 additions and 54 deletions

View file

@ -49,30 +49,24 @@ void ExportThread::run()
// Quality Settings // Quality Settings
settings.beginGroup("Pictures"); settings.beginGroup("Pictures");
int defaultQuality = 100; int defaultQuality = 100;
QSize defExportSize = SnapmaticPicture::getSnapmaticResolution();
int customQuality = settings.value("CustomQuality", defaultQuality).toInt(); int customQuality = settings.value("CustomQuality", defaultQuality).toInt();
if (customQuality < 1 || customQuality > 100) if (customQuality < 1 || customQuality > 100)
{
customQuality = 100; customQuality = 100;
}
bool useCustomQuality = settings.value("CustomQualityEnabled", false).toBool(); bool useCustomQuality = settings.value("CustomQualityEnabled", false).toBool();
// Size Settings // Size Settings
const QSize defExportSize = QSize(960, 536);
QSize cusExportSize = settings.value("CustomSize", defExportSize).toSize(); QSize cusExportSize = settings.value("CustomSize", defExportSize).toSize();
if (cusExportSize.width() > 3840) if (cusExportSize.width() > 7680) {
{ cusExportSize.setWidth(7680);
cusExportSize.setWidth(3840);
} }
else if (cusExportSize.height() > 2160) else if (cusExportSize.height() > 4320) {
{ cusExportSize.setHeight(4320);
cusExportSize.setHeight(2160);
} }
if (cusExportSize.width() < 1) if (cusExportSize.width() < 1) {
{
cusExportSize.setWidth(1); cusExportSize.setWidth(1);
} }
else if (cusExportSize.height() < 1) else if (cusExportSize.height() < 1) {
{
cusExportSize.setHeight(1); cusExportSize.setHeight(1);
} }
QString sizeMode = settings.value("ExportSizeMode", "Default").toString(); QString sizeMode = settings.value("ExportSizeMode", "Default").toString();

View file

@ -84,8 +84,7 @@ ImportDialog::ImportDialog(QString profileName, QWidget *parent) :
ui->cmdBackgroundWipe->setVisible(false); ui->cmdBackgroundWipe->setVisible(false);
// Snapmatic Resolution // Snapmatic Resolution
snapmaticResolution = SnapmaticPicture::getSnapmaticResolution(); ui->cbResolution->addItem("GTA V", QSize(960, 536));
ui->cbResolution->addItem("GTA V", snapmaticResolution);
ui->cbResolution->addItem("FiveM", QSize(1920, 1072)); ui->cbResolution->addItem("FiveM", QSize(1920, 1072));
ui->cbResolution->addItem("1280x720", QSize(1280, 720)); ui->cbResolution->addItem("1280x720", QSize(1280, 720));
ui->cbResolution->addItem("1920x1080", QSize(1920, 1080)); ui->cbResolution->addItem("1920x1080", QSize(1920, 1080));
@ -371,7 +370,7 @@ void ImportDialog::processSettings(QString settingsProfile, bool setDefault)
ui->cbForceAvatarColour->setChecked(settings.value("ForceAvatarColour", false).toBool()); ui->cbForceAvatarColour->setChecked(settings.value("ForceAvatarColour", false).toBool());
ui->cbUnlimited->setChecked(settings.value("UnlimitedBuffer", false).toBool()); ui->cbUnlimited->setChecked(settings.value("UnlimitedBuffer", false).toBool());
ui->cbImportAsIs->setChecked(settings.value("ImportAsIs", false).toBool()); ui->cbImportAsIs->setChecked(settings.value("ImportAsIs", false).toBool());
const QVariant data = settings.value("Resolution", SnapmaticPicture::getSnapmaticResolution()); const QVariant data = settings.value("Resolution", QSize(960, 536));
#if QT_VERSION >= 0x060000 #if QT_VERSION >= 0x060000
if (data.typeId() == QMetaType::QSize) if (data.typeId() == QMetaType::QSize)
#else #else
@ -431,7 +430,7 @@ void ImportDialog::saveSettings(QString settingsProfile)
settings.setValue("Resolution", data); settings.setValue("Resolution", data);
} }
else { else {
settings.setValue("Resolution", SnapmaticPicture::getSnapmaticResolution()); settings.setValue("Resolution", QSize(960, 536));
} }
settings.setValue("UnlimitedBuffer", ui->cbUnlimited->isChecked()); settings.setValue("UnlimitedBuffer", ui->cbUnlimited->isChecked());
settings.setValue("ImportAsIs", ui->cbImportAsIs->isChecked()); settings.setValue("ImportAsIs", ui->cbImportAsIs->isChecked());
@ -945,7 +944,7 @@ void ImportDialog::on_cbResolution_currentIndexChanged(int index)
#endif #endif
{ {
const QSize dataSize = data.toSize(); const QSize dataSize = data.toSize();
if (dataSize == SnapmaticPicture::getSnapmaticResolution()) { if (dataSize == QSize(960, 536)) {
ui->cbAvatar->setEnabled(true); ui->cbAvatar->setEnabled(true);
snapmaticResolution = dataSize; snapmaticResolution = dataSize;
reworkImage(); reworkImage();

View file

@ -69,7 +69,7 @@ OptionsDialog::OptionsDialog(ProfileDatabase *profileDB, QWidget *parent) :
int desktopSizeWidth = qRound((double)desktopResolution.width() * screenRatioPR); int desktopSizeWidth = qRound((double)desktopResolution.width() * screenRatioPR);
int desktopSizeHeight = qRound((double)desktopResolution.height() * screenRatioPR); int desktopSizeHeight = qRound((double)desktopResolution.height() * screenRatioPR);
aspectRatio = Qt::KeepAspectRatio; aspectRatio = Qt::KeepAspectRatio;
defExportSize = SnapmaticPicture::getSnapmaticResolution(); defExportSize = QSize(960, 536);
cusExportSize = defExportSize; cusExportSize = defExportSize;
defaultQuality = 100; defaultQuality = 100;
customQuality = 100; customQuality = 100;
@ -519,19 +519,18 @@ void OptionsDialog::setupPictureSettings()
// Quality Settings // Quality Settings
customQuality = settings->value("CustomQuality", defaultQuality).toInt(); customQuality = settings->value("CustomQuality", defaultQuality).toInt();
if (customQuality < 1 || customQuality > 100) { if (customQuality < 1 || customQuality > 100)
customQuality = 100; customQuality = 100;
}
ui->hsPicQuality->setValue(customQuality); ui->hsPicQuality->setValue(customQuality);
ui->cbPicCustomQuality->setChecked(settings->value("CustomQualityEnabled", false).toBool()); ui->cbPicCustomQuality->setChecked(settings->value("CustomQualityEnabled", false).toBool());
// Size Settings // Size Settings
cusExportSize = settings->value("CustomSize", defExportSize).toSize(); cusExportSize = settings->value("CustomSize", defExportSize).toSize();
if (cusExportSize.width() > 3840) { if (cusExportSize.width() > 7680) {
cusExportSize.setWidth(3840); cusExportSize.setWidth(7680);
} }
else if (cusExportSize.height() > 2160) { else if (cusExportSize.height() > 4320) {
cusExportSize.setHeight(2160); cusExportSize.setHeight(4320);
} }
if (cusExportSize.width() < 1) { if (cusExportSize.width() < 1) {
cusExportSize.setWidth(1); cusExportSize.setWidth(1);
@ -539,7 +538,9 @@ void OptionsDialog::setupPictureSettings()
else if (cusExportSize.height() < 1) { else if (cusExportSize.height() < 1) {
cusExportSize.setHeight(1); cusExportSize.setHeight(1);
} }
ui->sbPicExportWidth->setMaximum(7680);
ui->sbPicExportWidth->setValue(cusExportSize.width()); ui->sbPicExportWidth->setValue(cusExportSize.width());
ui->sbPicExportHeight->setMaximum(4320);
ui->sbPicExportHeight->setValue(cusExportSize.height()); ui->sbPicExportHeight->setValue(cusExportSize.height());
QString sizeMode = settings->value("ExportSizeMode", "Default").toString(); QString sizeMode = settings->value("ExportSizeMode", "Default").toString();

View file

@ -141,8 +141,8 @@ void PictureDialog::setupPictureDialog()
smpic = nullptr; smpic = nullptr;
crewStr = ""; crewStr = "";
// Get Snapmatic Resolution // Set default Snapmatic resolution (960x536)
const QSize snapmaticResolution = SnapmaticPicture::getSnapmaticResolution(); const QSize snapmaticResolution = QSize(960, 536);
// Avatar area // Avatar area
qreal screenRatio = AppEnv::screenRatio(); qreal screenRatio = AppEnv::screenRatio();
@ -232,7 +232,7 @@ void PictureDialog::addPreviousNextButtons()
void PictureDialog::adaptDialogSize() void PictureDialog::adaptDialogSize()
{ {
int newDialogHeight = (SnapmaticPicture::getSnapmaticResolution().height() * AppEnv::screenRatio()) + ui->jsonFrame->heightForWidth(width()); int newDialogHeight = (960 * AppEnv::screenRatio()) + ui->jsonFrame->heightForWidth(width());
if (naviEnabled) if (naviEnabled)
newDialogHeight = newDialogHeight + layout()->menuBar()->height(); newDialogHeight = newDialogHeight + layout()->menuBar()->height();
const QSize windowSize(width(), newDialogHeight); const QSize windowSize(width(), newDialogHeight);
@ -533,7 +533,7 @@ void PictureDialog::renderPicture()
{ {
const qreal screenRatio = AppEnv::screenRatio(); const qreal screenRatio = AppEnv::screenRatio();
const qreal screenRatioPR = AppEnv::screenRatioPR(); const qreal screenRatioPR = AppEnv::screenRatioPR();
const QSize snapmaticResolution(SnapmaticPicture::getSnapmaticResolution()); const QSize snapmaticResolution = QSize(960, 536);
const QSize renderResolution(snapmaticResolution.width() * screenRatio * screenRatioPR, snapmaticResolution.height() * screenRatio * screenRatioPR); const QSize renderResolution(snapmaticResolution.width() * screenRatio * screenRatioPR, snapmaticResolution.height() * screenRatio * screenRatioPR);
QPixmap shownImagePixmap(renderResolution); QPixmap shownImagePixmap(renderResolution);
shownImagePixmap.fill(Qt::black); shownImagePixmap.fill(Qt::black);
@ -783,6 +783,7 @@ void PictureDialog::editSnapmaticImage()
importDialog->setModal(true); importDialog->setModal(true);
importDialog->exec(); importDialog->exec();
if (importDialog->isImportAgreed()) { if (importDialog->isImportAgreed()) {
const QSize previousSize = smpic->getPictureResolution();
const QByteArray previousPicture = smpic->getPictureStream(); const QByteArray previousPicture = smpic->getPictureStream();
bool success = smpic->setImage(importDialog->image(), importDialog->isUnlimitedBuffer()); bool success = smpic->setImage(importDialog->image(), importDialog->isUnlimitedBuffer());
if (success) { if (success) {
@ -793,8 +794,7 @@ void PictureDialog::editSnapmaticImage()
QFile::copy(currentFilePath, backupFileName); QFile::copy(currentFilePath, backupFileName);
} }
if (!smpic->exportPicture(currentFilePath)) { if (!smpic->exportPicture(currentFilePath)) {
// TODO: Find a way to cache the image width and height smpic->setPictureStream(previousPicture, previousSize.width(), previousSize.height());
smpic->setPictureStream(previousPicture, 0, 0);
QMessageBox::warning(this, QApplication::translate("ImageEditorDialog", "Snapmatic Image Editor"), QApplication::translate("ImageEditorDialog", "Patching of Snapmatic Image failed because of I/O Error")); QMessageBox::warning(this, QApplication::translate("ImageEditorDialog", "Snapmatic Image Editor"), QApplication::translate("ImageEditorDialog", "Patching of Snapmatic Image failed because of I/O Error"));
return; return;
} }

View file

@ -50,20 +50,19 @@ void PictureExport::exportAsPicture(QWidget *parent, SnapmaticPicture *picture)
// Quality Settings // Quality Settings
settings.beginGroup("Pictures"); settings.beginGroup("Pictures");
int defaultQuality = 100; int defaultQuality = 100;
QSize defExportSize = SnapmaticPicture::getSnapmaticResolution();
int customQuality = settings.value("CustomQuality", defaultQuality).toInt(); int customQuality = settings.value("CustomQuality", defaultQuality).toInt();
if (customQuality < 1 || customQuality > 100) { if (customQuality < 1 || customQuality > 100)
customQuality = 100; customQuality = 100;
}
bool useCustomQuality = settings.value("CustomQualityEnabled", false).toBool(); bool useCustomQuality = settings.value("CustomQualityEnabled", false).toBool();
// Size Settings // Size Settings
const QSize defExportSize = QSize(960, 536);
QSize cusExportSize = settings.value("CustomSize", defExportSize).toSize(); QSize cusExportSize = settings.value("CustomSize", defExportSize).toSize();
if (cusExportSize.width() > 3840) { if (cusExportSize.width() > 7680) {
cusExportSize.setWidth(3840); cusExportSize.setWidth(7680);
} }
else if (cusExportSize.height() > 2160) { else if (cusExportSize.height() > 4320) {
cusExportSize.setHeight(2160); cusExportSize.setHeight(4320);
} }
if (cusExportSize.width() < 1) { if (cusExportSize.width() < 1) {
cusExportSize.setWidth(1); cusExportSize.setWidth(1);

View file

@ -36,11 +36,6 @@
#endif #endif
#include <QSaveFile> #include <QSaveFile>
// IMAGES VALUES
#define snapmaticResolutionW 960
#define snapmaticResolutionH 536
#define snapmaticResolution QSize(snapmaticResolutionW, snapmaticResolutionH)
// GTA5VIEW RELATED INTERNAL FUNCTIONS // GTA5VIEW RELATED INTERNAL FUNCTIONS
inline quint32 gta5view_charToUInt32LE(char *x) inline quint32 gta5view_charToUInt32LE(char *x)
{ {
@ -601,11 +596,14 @@ bool SnapmaticPicture::readingPicture(bool cacheEnabled_)
if (!ok) if (!ok)
return false; return false;
if (cacheEnabled) if (cacheEnabled) {
picOk = cachePicture.loadFromData(QByteArray::fromRawData(p_ragePhoto.jpegData(), p_ragePhoto.jpegSize()), "JPEG"); picOk = cachePicture.loadFromData(QByteArray::fromRawData(p_ragePhoto.jpegData(), p_ragePhoto.jpegSize()), "JPEG");
picRes = cachePicture.size();
}
else { else {
QImage tempPicture; QImage tempPicture;
picOk = tempPicture.loadFromData(QByteArray::fromRawData(p_ragePhoto.jpegData(), p_ragePhoto.jpegSize()), "JPEG"); picOk = tempPicture.loadFromData(QByteArray::fromRawData(p_ragePhoto.jpegData(), p_ragePhoto.jpegSize()), "JPEG");
picRes = tempPicture.size();
} }
parseJsonContent(); // JSON parsing is own function parseJsonContent(); // JSON parsing is own function
@ -712,13 +710,17 @@ bool SnapmaticPicture::setPictureStream(const QByteArray &streamArray, int width
} }
else if (gta5view_isRDR2Format(photoFormat)) { else if (gta5view_isRDR2Format(photoFormat)) {
snapmaticJson.jsonObject["sign"] = p_ragePhoto.jpegSign(RagePhoto::PhotoFormat::RDR2); snapmaticJson.jsonObject["sign"] = p_ragePhoto.jpegSign(RagePhoto::PhotoFormat::RDR2);
snapmaticJson.jsonObject["size"] = jpegPicStreamLength; snapmaticJson.jsonObject["size"] = streamArray.size();
snapmaticJson.jsonObject["width"] = width; snapmaticJson.jsonObject["width"] = width;
snapmaticJson.jsonObject["height"] = height; snapmaticJson.jsonObject["height"] = height;
const std::string json = SnapmaticJson::serialize(snapmaticJson.jsonObject); const std::string json = SnapmaticJson::serialize(snapmaticJson.jsonObject);
p_ragePhoto.setJson(json.c_str()); p_ragePhoto.setJson(json.c_str());
} }
// Update resolution
picRes = QSize(width, height);
// Update cache
if (cacheEnabled) { if (cacheEnabled) {
QImage replacedPicture; QImage replacedPicture;
replacedPicture.loadFromData(streamArray); replacedPicture.loadFromData(streamArray);
@ -1216,11 +1218,9 @@ bool SnapmaticPicture::setPictureVisible()
return true; return true;
} }
// PREDEFINED PROPERTIES const QSize SnapmaticPicture::getPictureResolution()
QSize SnapmaticPicture::getSnapmaticResolution()
{ {
return snapmaticResolution; return picRes;
} }
// SNAPMATIC FORMAT // SNAPMATIC FORMAT

View file

@ -80,6 +80,7 @@ public:
void clearCache(); void clearCache();
const QImage getImage(); const QImage getImage();
const QByteArray getPictureStream(); const QByteArray getPictureStream();
const QSize getPictureResolution();
const QString getLastStep(bool readable = true); const QString getLastStep(bool readable = true);
const QString getPictureStr(); const QString getPictureStr();
const QString getPictureTitl(); const QString getPictureTitl();
@ -134,9 +135,6 @@ public:
inline bool setHidden() { return setPictureHidden(); } inline bool setHidden() { return setPictureHidden(); }
inline bool setVisible() { return setPictureVisible(); } inline bool setVisible() { return setPictureVisible(); }
// PREDEFINED PROPERTIES
static QSize getSnapmaticResolution();
// SNAPMATIC FORMAT // SNAPMATIC FORMAT
SnapmaticFormat getSnapmaticFormat(); SnapmaticFormat getSnapmaticFormat();
void setSnapmaticFormat(SnapmaticFormat format); void setSnapmaticFormat(SnapmaticFormat format);
@ -161,6 +159,7 @@ private:
QString pictureStr; QString pictureStr;
QString lastStep; QString lastStep;
QString sortStr; QString sortStr;
QSize picRes;
bool picOk; bool picOk;
bool cacheEnabled; bool cacheEnabled;
bool isFormatSwitch; bool isFormatSwitch;

View file

@ -356,6 +356,7 @@ void SnapmaticWidget::editSnapmaticImage()
importDialog->setModal(true); importDialog->setModal(true);
importDialog->exec(); importDialog->exec();
if (importDialog->isImportAgreed()) { if (importDialog->isImportAgreed()) {
const QSize previousSize = smpic->getPictureResolution();
const QByteArray previousPicture = smpic->getPictureStream(); const QByteArray previousPicture = smpic->getPictureStream();
bool success = smpic->setImage(importDialog->image(), importDialog->isUnlimitedBuffer()); bool success = smpic->setImage(importDialog->image(), importDialog->isUnlimitedBuffer());
if (success) { if (success) {
@ -366,8 +367,7 @@ void SnapmaticWidget::editSnapmaticImage()
QFile::copy(currentFilePath, backupFileName); QFile::copy(currentFilePath, backupFileName);
} }
if (!smpic->exportPicture(currentFilePath)) { if (!smpic->exportPicture(currentFilePath)) {
// TODO: Find a way to cache the image width and height smpic->setPictureStream(previousPicture, previousSize.width(), previousSize.height());
smpic->setPictureStream(previousPicture, 0, 0);
QMessageBox::warning(this, QApplication::translate("ImageEditorDialog", "Snapmatic Image Editor"), QApplication::translate("ImageEditorDialog", "Patching of Snapmatic Image failed because of I/O Error")); QMessageBox::warning(this, QApplication::translate("ImageEditorDialog", "Snapmatic Image Editor"), QApplication::translate("ImageEditorDialog", "Patching of Snapmatic Image failed because of I/O Error"));
return; return;
} }