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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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