From 0e6a6ae34a8289daf3ec0e3facc16b44eebfee73 Mon Sep 17 00:00:00 2001 From: Syping Date: Wed, 10 May 2023 15:17:19 +0200 Subject: [PATCH] SnapmaticPicture: update size, width and height for RDR 2 --- src/PictureDialog.cpp | 3 ++- src/SnapmaticPicture.cpp | 34 +++++++++++++++++++++------------- src/SnapmaticPicture.h | 2 +- src/SnapmaticWidget.cpp | 3 ++- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/PictureDialog.cpp b/src/PictureDialog.cpp index 53f3f72..0196935 100644 --- a/src/PictureDialog.cpp +++ b/src/PictureDialog.cpp @@ -793,7 +793,8 @@ void PictureDialog::editSnapmaticImage() QFile::copy(currentFilePath, backupFileName); } if (!smpic->exportPicture(currentFilePath)) { - smpic->setPictureStream(previousPicture); + // TODO: Find a way to cache the image width and 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")); return; } diff --git a/src/SnapmaticPicture.cpp b/src/SnapmaticPicture.cpp index b38a421..16cec50 100644 --- a/src/SnapmaticPicture.cpp +++ b/src/SnapmaticPicture.cpp @@ -650,11 +650,14 @@ bool SnapmaticPicture::readingPictureFromFile(const QString &fileName, bool cach bool SnapmaticPicture::setImage(const QImage &picture, bool eXtendMode) { -#ifdef GTA5SYNC_DYNAMIC_PHOTOBUFFER // It's not properly implemented yet, please don't define - quint32 jpegPicStreamLength = p_ragePhoto.data()->photoBuffer(); -#else - quint32 jpegPicStreamLength = RagePhoto::DEFAULT_GTA5_PHOTOBUFFER; -#endif + quint32 photoFormat = p_ragePhoto.format(); + quint32 jpegPicStreamLength = 0; + if (gta5view_isGTAVFormat(photoFormat)) { + jpegPicStreamLength = RagePhoto::DEFAULT_GTA5_PHOTOBUFFER; + } + else if (gta5view_isRDR2Format(photoFormat)) { + jpegPicStreamLength = RagePhoto::DEFAULT_RDR2_PHOTOBUFFER; + } QByteArray picByteArray; int comLvl = 100; bool saveSuccess = false; @@ -679,17 +682,20 @@ bool SnapmaticPicture::setImage(const QImage &picture, bool eXtendMode) } } if (saveSuccess) - return setPictureStream(picByteArray); + return setPictureStream(picByteArray, picture.width(), picture.height()); return false; } -bool SnapmaticPicture::setPictureStream(const QByteArray &streamArray) // clean method +bool SnapmaticPicture::setPictureStream(const QByteArray &streamArray, int width, int height) { -#ifdef GTA5SYNC_DYNAMIC_PHOTOBUFFER // It's not properly implemented yet, please don't define - quint32 jpegPicStreamLength = p_ragePhoto.data()->photoBuffer(); -#else - quint32 jpegPicStreamLength = RagePhoto::DEFAULT_GTA5_PHOTOBUFFER; -#endif + quint32 photoFormat = p_ragePhoto.format(); + quint32 jpegPicStreamLength = 0; + if (gta5view_isGTAVFormat(photoFormat)) { + jpegPicStreamLength = RagePhoto::DEFAULT_GTA5_PHOTOBUFFER; + } + else if (gta5view_isRDR2Format(photoFormat)) { + jpegPicStreamLength = RagePhoto::DEFAULT_RDR2_PHOTOBUFFER; + } if (streamArray.size() > jpegPicStreamLength) jpegPicStreamLength = streamArray.size(); #ifdef GTA5SYNC_COMPACT_PHOTOBUFFER // Experiment to save less than the default photo buffer @@ -699,7 +705,6 @@ bool SnapmaticPicture::setPictureStream(const QByteArray &streamArray) // clean bool success = p_ragePhoto.setJpeg(streamArray.constData(), streamArray.size(), jpegPicStreamLength); if (success) { // Update JPEG signature - uint32_t photoFormat = p_ragePhoto.format(); if (gta5view_isGTAVFormat(photoFormat)) { snapmaticJson.jsonObject["sign"] = p_ragePhoto.jpegSign(RagePhoto::PhotoFormat::GTA5); const std::string json = SnapmaticJson::serialize(snapmaticJson.jsonObject); @@ -707,6 +712,9 @@ bool SnapmaticPicture::setPictureStream(const QByteArray &streamArray) // clean } else if (gta5view_isRDR2Format(photoFormat)) { snapmaticJson.jsonObject["sign"] = p_ragePhoto.jpegSign(RagePhoto::PhotoFormat::RDR2); + snapmaticJson.jsonObject["size"] = jpegPicStreamLength; + snapmaticJson.jsonObject["width"] = width; + snapmaticJson.jsonObject["height"] = height; const std::string json = SnapmaticJson::serialize(snapmaticJson.jsonObject); p_ragePhoto.setJson(json.c_str()); } diff --git a/src/SnapmaticPicture.h b/src/SnapmaticPicture.h index 2d24d00..fb60574 100644 --- a/src/SnapmaticPicture.h +++ b/src/SnapmaticPicture.h @@ -91,7 +91,7 @@ public: const QString getOriginalPictureFilePath(); bool setImage(const QImage &picture, bool eXtendMode = false); bool setPictureTitl(const QString &newTitle); // Please use setPictureTitle instead - bool setPictureStream(const QByteArray &streamArray); + bool setPictureStream(const QByteArray &streamArray, int width, int height); void updateStrings(); void emitUpdate(); void emitCustomSignal(const QString &signal); diff --git a/src/SnapmaticWidget.cpp b/src/SnapmaticWidget.cpp index 23f325c..24d8dc1 100644 --- a/src/SnapmaticWidget.cpp +++ b/src/SnapmaticWidget.cpp @@ -366,7 +366,8 @@ void SnapmaticWidget::editSnapmaticImage() QFile::copy(currentFilePath, backupFileName); } if (!smpic->exportPicture(currentFilePath)) { - smpic->setPictureStream(previousPicture); + // TODO: Find a way to cache the image width and 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")); return; }