WIP: SnapmaticPicture using RagePhoto now
	
		
			
	
		
	
	
		
	
		
			Some checks failed
		
		
	
	
		
			
				
	
				continuous-integration/drone/push Build is failing
				
			
		
		
	
	
				
					
				
			
		
			Some checks failed
		
		
	
	continuous-integration/drone/push Build is failing
				
			This commit is contained in:
		
							parent
							
								
									b3e1520a8f
								
							
						
					
					
						commit
						186df05cea
					
				
					 5 changed files with 285 additions and 791 deletions
				
			
		|  | @ -24,20 +24,23 @@ | |||
| 
 | ||||
| RagePhoto::RagePhoto(const QByteArray &data) : p_fileData(data) | ||||
| { | ||||
|     p_inputMode = 0; | ||||
|     p_photoFormat = PhotoFormat::Undefined; | ||||
|     p_isLoaded = false; | ||||
|     p_inputMode = 0; | ||||
| } | ||||
| 
 | ||||
| RagePhoto::RagePhoto(const QString &filePath) : p_filePath(filePath) | ||||
| { | ||||
|     p_inputMode = 1; | ||||
|     p_photoFormat = PhotoFormat::Undefined; | ||||
|     p_isLoaded = false; | ||||
|     p_inputMode = 1; | ||||
| } | ||||
| 
 | ||||
| RagePhoto::RagePhoto(QIODevice *ioDevice) : p_ioDevice(ioDevice) | ||||
| { | ||||
|     p_inputMode = 2; | ||||
|     p_photoFormat = PhotoFormat::Undefined; | ||||
|     p_isLoaded = false; | ||||
|     p_inputMode = 2; | ||||
| } | ||||
| 
 | ||||
| bool RagePhoto::isLoaded() | ||||
|  | @ -74,7 +77,7 @@ bool RagePhoto::load() | |||
|         return false; | ||||
|     quint32 format = charToUInt32LE(formatHeader); | ||||
| 
 | ||||
|     if (format == PhotoFormat::GTA5) { | ||||
|     if (format == static_cast<quint32>(PhotoFormat::GTA5)) { | ||||
|         char photoHeader[256]; | ||||
|         size = dataBuffer.read(photoHeader, 256); | ||||
|         if (size != 256) | ||||
|  | @ -138,7 +141,7 @@ bool RagePhoto::load() | |||
|         size = dataBuffer.read(photoData, p_photoSize); | ||||
|         if (size != p_photoSize) | ||||
|             return false; | ||||
|         p_photoData = QByteArray::fromRawData(photoData, p_photoSize); | ||||
|         p_photoData = QByteArray(photoData, p_photoSize); | ||||
| 
 | ||||
|         dataBuffer.seek(p_jsonOffset + 264); | ||||
|         char jsonMarker[4]; | ||||
|  | @ -158,13 +161,12 @@ bool RagePhoto::load() | |||
|         size = dataBuffer.read(jsonBytes, i_jsonSize); | ||||
|         if (size != i_jsonSize) | ||||
|             return false; | ||||
|         QByteArray t_jsonBytes; | ||||
|         for (quint32 i = 0; i != i_jsonSize; i++) { | ||||
|             if (jsonBytes[i] == '\x00') | ||||
|                 break; | ||||
|             t_jsonBytes += jsonBytes[i]; | ||||
|             p_jsonData += jsonBytes[i]; | ||||
|         } | ||||
|         QJsonDocument t_jsonDocument = QJsonDocument::fromJson(t_jsonBytes); | ||||
|         QJsonDocument t_jsonDocument = QJsonDocument::fromJson(p_jsonData); | ||||
|         if (t_jsonDocument.isNull()) | ||||
|             return false; | ||||
|         p_jsonObject = t_jsonDocument.object(); | ||||
|  | @ -225,17 +227,20 @@ bool RagePhoto::load() | |||
|         if (strncmp(jendMarker, "JEND", 4) != 0) | ||||
|             return false; | ||||
| 
 | ||||
|         if (p_photoFormat != PhotoFormat::G5EX) | ||||
|             p_photoFormat = PhotoFormat::GTA5; | ||||
| 
 | ||||
|         p_fileData.clear(); | ||||
|         p_isLoaded = true; | ||||
|         return true; | ||||
|     } | ||||
|     else if (format == PhotoFormat::G5EX) { | ||||
|     else if (format == static_cast<quint32>(PhotoFormat::G5EX)) { | ||||
|         char formatHeader[4]; | ||||
|         size = dataBuffer.read(formatHeader, 4); | ||||
|         if (size != 4) | ||||
|             return false; | ||||
|         quint32 format = charToUInt32LE(formatHeader); | ||||
|         if (format == ExportFormat::G5E3P) { | ||||
|         if (format == static_cast<quint32>(ExportFormat::G5E3P)) { | ||||
|             char photoHeaderSize[4]; | ||||
|             size = dataBuffer.peek(photoHeaderSize, 4); | ||||
|             if (size != 4) | ||||
|  | @ -293,8 +298,8 @@ bool RagePhoto::load() | |||
|             if (size != i_jsonSize) | ||||
|                 return false; | ||||
|             QByteArray t_jsonBytes = QByteArray::fromRawData(compressedJson, i_jsonSize); | ||||
|             t_jsonBytes = qUncompress(t_jsonBytes); | ||||
|             QJsonDocument t_jsonDocument = QJsonDocument::fromJson(t_jsonBytes); | ||||
|             p_jsonData = qUncompress(t_jsonBytes); | ||||
|             QJsonDocument t_jsonDocument = QJsonDocument::fromJson(p_jsonData); | ||||
|             if (t_jsonDocument.isNull()) | ||||
|                 return false; | ||||
|             p_jsonObject = t_jsonDocument.object(); | ||||
|  | @ -345,11 +350,14 @@ bool RagePhoto::load() | |||
|                 return false; | ||||
|             p_endOfFile = charToUInt32LE(endOfFile); | ||||
| 
 | ||||
|             p_photoFormat = PhotoFormat::G5EX; | ||||
| 
 | ||||
|             p_fileData.clear(); | ||||
|             p_isLoaded = true; | ||||
|             return true; | ||||
|         } | ||||
|         else if (format == ExportFormat::G5E2P) { | ||||
|         else if (format == static_cast<quint32>(ExportFormat::G5E2P)) { | ||||
|             p_photoFormat = PhotoFormat::G5EX; | ||||
|             p_fileData = dataBuffer.readAll(); | ||||
|             p_inputMode = 0; | ||||
|             return load(); | ||||
|  | @ -365,8 +373,10 @@ bool RagePhoto::load() | |||
| 
 | ||||
| void RagePhoto::clear() | ||||
| { | ||||
|     p_photoFormat = PhotoFormat::Undefined; | ||||
|     p_jsonObject = QJsonObject(); | ||||
|     p_descriptionString.clear(); | ||||
|     p_jsonData.clear(); | ||||
|     p_photoData.clear(); | ||||
|     p_photoString.clear(); | ||||
|     p_titleString.clear(); | ||||
|  | @ -379,20 +389,47 @@ void RagePhoto::setDescription(const QString &description) | |||
|     p_descriptionString = description; | ||||
| } | ||||
| 
 | ||||
| void RagePhoto::setFilePath(const QString &filePath) | ||||
| void RagePhoto::setFileData(const QByteArray &data) | ||||
| { | ||||
|     p_filePath = filePath; | ||||
|     p_fileData = data; | ||||
|     p_inputMode = 0; | ||||
| } | ||||
| 
 | ||||
| void RagePhoto::setPhotoData(const QByteArray &data) | ||||
| void RagePhoto::setFilePath(const QString &filePath) | ||||
| { | ||||
|     p_photoData = data; | ||||
|     p_filePath = filePath; | ||||
|     p_inputMode = 1; | ||||
| } | ||||
| 
 | ||||
| void RagePhoto::setPhotoData(const char *data, int size) | ||||
| bool RagePhoto::setJsonData(const QByteArray &data) | ||||
| { | ||||
|     p_photoData = QByteArray::fromRawData(data, size); | ||||
|     QJsonDocument t_jsonDocument = QJsonDocument::fromJson(data); | ||||
|     if (t_jsonDocument.isNull()) | ||||
|         return false; | ||||
|     p_jsonObject = t_jsonDocument.object(); | ||||
|     p_jsonData = data; | ||||
|     return true; | ||||
| } | ||||
| 
 | ||||
| bool RagePhoto::setPhotoData(const QByteArray &data) | ||||
| { | ||||
|     if ((quint32)data.size() > p_photoSize) | ||||
|         return false; | ||||
|     p_photoData = data; | ||||
|     return true; | ||||
| } | ||||
| 
 | ||||
| bool RagePhoto::setPhotoData(const char *data, int size) | ||||
| { | ||||
|     if ((quint32)size > p_photoSize) | ||||
|         return false; | ||||
|     p_photoData = QByteArray(data, size); | ||||
|     return true; | ||||
| } | ||||
| 
 | ||||
| void RagePhoto::setPhotoFormat(PhotoFormat photoFormat) | ||||
| { | ||||
|     p_photoFormat = photoFormat; | ||||
| } | ||||
| 
 | ||||
| void RagePhoto::setTitle(const QString &title) | ||||
|  | @ -400,6 +437,16 @@ void RagePhoto::setTitle(const QString &title) | |||
|     p_titleString = title; | ||||
| } | ||||
| 
 | ||||
| const QByteArray RagePhoto::jsonData() | ||||
| { | ||||
|     return p_jsonData; | ||||
| } | ||||
| 
 | ||||
| const QJsonObject RagePhoto::jsonObject() | ||||
| { | ||||
|     return p_jsonObject; | ||||
| } | ||||
| 
 | ||||
| const QByteArray RagePhoto::photoData() | ||||
| { | ||||
|     return p_photoData; | ||||
|  | @ -420,6 +467,16 @@ const QString RagePhoto::title() | |||
|     return p_titleString; | ||||
| } | ||||
| 
 | ||||
| quint32 RagePhoto::photoBuffer() | ||||
| { | ||||
|     return p_jpegBuffer; | ||||
| } | ||||
| 
 | ||||
| RagePhoto::PhotoFormat RagePhoto::photoFormat() | ||||
| { | ||||
|     return p_photoFormat; | ||||
| } | ||||
| 
 | ||||
| RagePhoto* RagePhoto::loadFile(const QString &filePath) | ||||
| { | ||||
|     RagePhoto *ragePhoto = new RagePhoto(filePath); | ||||
|  |  | |||
							
								
								
									
										19
									
								
								RagePhoto.h
									
										
									
									
									
								
							
							
						
						
									
										19
									
								
								RagePhoto.h
									
										
									
									
									
								
							|  | @ -27,16 +27,18 @@ class RagePhoto : public QObject | |||
| { | ||||
|     Q_OBJECT | ||||
| public: | ||||
|     enum ExportFormat { | ||||
|     enum class ExportFormat : quint32 { | ||||
|         G5E2P = 0x01000032U, | ||||
|         G5E2S = 0x02000032U, | ||||
|         G5E3P = 0x01000033U, | ||||
|         G5E3S = 0x02000033U, | ||||
|         Undefined = 0, | ||||
|     }; | ||||
|     enum PhotoFormat { | ||||
|     enum class PhotoFormat : quint32 { | ||||
|         G5EX = 0x45354700U, | ||||
|         GTA5 = 0x01000000U, | ||||
|         RDR2 = 0x04000000U, | ||||
|         Undefined = 0, | ||||
|     }; | ||||
|     explicit RagePhoto(const QByteArray &data); | ||||
|     explicit RagePhoto(const QString &filePath = QString()); | ||||
|  | @ -45,14 +47,21 @@ public: | |||
|     bool load(); | ||||
|     void clear(); | ||||
|     void setDescription(const QString &description); | ||||
|     void setFileData(const QByteArray &data); | ||||
|     void setFilePath(const QString &filePath); | ||||
|     void setPhotoData(const QByteArray &data); | ||||
|     void setPhotoData(const char *data, int size); | ||||
|     bool setJsonData(const QByteArray &data); | ||||
|     bool setPhotoData(const QByteArray &data); | ||||
|     bool setPhotoData(const char *data, int size); | ||||
|     void setPhotoFormat(PhotoFormat photoFormat); | ||||
|     void setTitle(const QString &title); | ||||
|     const QJsonObject jsonObject(); | ||||
|     const QByteArray jsonData(); | ||||
|     const QByteArray photoData(); | ||||
|     const QString description(); | ||||
|     const QString photoString(); | ||||
|     const QString title(); | ||||
|     quint32 photoBuffer(); | ||||
|     PhotoFormat photoFormat(); | ||||
|     static RagePhoto* loadFile(const QString &filePath); | ||||
| 
 | ||||
| private: | ||||
|  | @ -60,8 +69,10 @@ private: | |||
|     inline quint32 charToUInt32LE(char *x); | ||||
|     inline void uInt32ToCharBE(quint32 *x, char *y); | ||||
|     inline void uInt32ToCharLE(quint32 *x, char *y); | ||||
|     PhotoFormat p_photoFormat; | ||||
|     QJsonObject p_jsonObject; | ||||
|     QByteArray p_fileData; | ||||
|     QByteArray p_jsonData; | ||||
|     QByteArray p_photoData; | ||||
|     QIODevice *p_ioDevice; | ||||
|     QString p_descriptionString; | ||||
|  |  | |||
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							|  | @ -19,6 +19,7 @@ | |||
| #ifndef SNAPMATICPICTURE_H | ||||
| #define SNAPMATICPICTURE_H | ||||
| 
 | ||||
| #include "RagePhoto.h" | ||||
| #include <QStringList> | ||||
| #include <QDateTime> | ||||
| #include <QObject> | ||||
|  | @ -65,16 +66,13 @@ public: | |||
|     QByteArray getPictureStream(); | ||||
|     QString getLastStep(bool readable = true); | ||||
|     QString getPictureStr(); | ||||
|     QString getPictureHead(); | ||||
|     QString getPictureTitl(); | ||||
|     QString getPictureDesc(); | ||||
|     QString getPictureSortStr(); | ||||
|     QString getPictureFileName(); | ||||
|     QString getPictureFilePath(); | ||||
|     QString getExportPictureFileName(); | ||||
|     QString getOriginalPictureFileName(); | ||||
|     QString getOriginalPictureFilePath(); | ||||
|     int getContentMaxLength(); | ||||
|     bool setImage(const QImage &picture); | ||||
|     bool setPictureTitl(const QString &newTitle); // Please use setPictureTitle instead
 | ||||
|     bool setPictureStream(const QByteArray &streamArray); | ||||
|  | @ -106,7 +104,6 @@ public: | |||
|     QString getPictureJson() { return getJsonStr(); } | ||||
|     QString getPictureTitle() { return getPictureTitl(); } | ||||
|     QString getPictureString() { return getPictureStr(); } | ||||
|     QString getPictureDescription() { return getPictureDesc(); } | ||||
|     bool setJsonString(const QString &jsonString, bool updateProperties = false) { return setJsonStr(jsonString, updateProperties); } // Please use setPictureJson instead
 | ||||
|     bool setPictureJson(const QString &json, bool updateProperties = false) { return setJsonStr(json, updateProperties); } | ||||
|     bool setPictureTitle(const QString &title) { return setPictureTitl(title); } | ||||
|  | @ -122,10 +119,6 @@ public: | |||
|     // PREDEFINED PROPERTIES
 | ||||
|     static QSize getSnapmaticResolution(); | ||||
| 
 | ||||
|     // SNAPMATIC DEFAULTS
 | ||||
|     bool isSnapmaticDefaultsEnforced(); | ||||
|     void setSnapmaticDefaultsEnforced(bool enforced); | ||||
| 
 | ||||
|     // SNAPMATIC FORMAT
 | ||||
|     SnapmaticFormat getSnapmaticFormat(); | ||||
|     void setSnapmaticFormat(SnapmaticFormat format); | ||||
|  | @ -140,43 +133,28 @@ public: | |||
|     static QString convertLogStringForDraw(const QString &inputStr); | ||||
| 
 | ||||
| private: | ||||
|     QString getSnapmaticHeaderString(const QByteArray &snapmaticHeader); | ||||
|     QString getSnapmaticJSONString(const QByteArray &jsonBytes); | ||||
|     QString getSnapmaticTIDEString(const QByteArray &tideBytes); | ||||
|     QImage cachePicture; | ||||
|     QString picExportFileName; | ||||
|     QString picFileName; | ||||
|     QString picFilePath; | ||||
|     QString pictureHead; | ||||
|     QString pictureStr; | ||||
|     QString lastStep; | ||||
|     QString sortStr; | ||||
|     QString titlStr; | ||||
|     QString descStr; | ||||
|     bool picOk; | ||||
|     bool lowRamMode; | ||||
|     bool writeEnabled; | ||||
|     bool cacheEnabled; | ||||
|     bool isLoadedInRAM; | ||||
|     bool isCustomFormat; | ||||
|     bool isFormatSwitch; | ||||
|     bool isModernFormat; | ||||
|     bool careSnapDefault; | ||||
|     int jpegRawContentSize; | ||||
|     int jpegRawContentSizeE; | ||||
| 
 | ||||
|     // PICTURE STREAM
 | ||||
|     QByteArray rawPicContent; | ||||
| 
 | ||||
|     // JSON
 | ||||
|     void parseJsonContent(); | ||||
|     bool jsonOk; | ||||
|     QString jsonStr; | ||||
|     SnapmaticProperties localProperties; | ||||
| 
 | ||||
|     // VERIFY CONTENT
 | ||||
|     static bool verifyTitleChar(const QChar &titleChar); | ||||
| 
 | ||||
|     // RAGEPHOTO
 | ||||
|     RagePhoto ragePhoto; | ||||
| 
 | ||||
| signals: | ||||
|     void customSignal(QString signal); | ||||
|     void preloaded(); | ||||
|  |  | |||
|  | @ -50,6 +50,7 @@ SOURCES += main.cpp \ | |||
|     ProfileInterface.cpp \ | ||||
|     ProfileLoader.cpp \ | ||||
|     ProfileWidget.cpp \ | ||||
|     RagePhoto.cpp \ | ||||
|     SavegameCopy.cpp \ | ||||
|     SavegameData.cpp \ | ||||
|     SavegameDialog.cpp \ | ||||
|  | @ -92,6 +93,7 @@ HEADERS += \ | |||
|     ProfileInterface.h \ | ||||
|     ProfileLoader.h \ | ||||
|     ProfileWidget.h \ | ||||
|     RagePhoto.h \ | ||||
|     SavegameCopy.h \ | ||||
|     SavegameData.h \ | ||||
|     SavegameDialog.h \ | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue