RagePhoto: add setPhotoBuffer
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				continuous-integration/drone/push Build is passing
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	continuous-integration/drone/push Build is passing
				
			This commit is contained in:
		
							parent
							
								
									2cf9119c54
								
							
						
					
					
						commit
						c0a3e08527
					
				
					 4 changed files with 56 additions and 34 deletions
				
			
		|  | @ -455,6 +455,20 @@ bool RagePhoto::setJsonData(const QByteArray &data) | ||||||
|     return true; |     return true; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | bool RagePhoto::setPhotoBuffer(quint32 size, bool moveOffsets) | ||||||
|  | { | ||||||
|  |     if (size < static_cast<quint32>(p_photoData.size())) | ||||||
|  |         return false; | ||||||
|  |     p_photoBuffer = size; | ||||||
|  |     if (moveOffsets) { | ||||||
|  |         p_jsonOffset = size + 28; | ||||||
|  |         p_titlOffset = p_jsonOffset + p_jsonBuffer + 8; | ||||||
|  |         p_descOffset = p_titlOffset + p_titlBuffer + 8; | ||||||
|  |         p_endOfFile = p_descOffset + p_descBuffer + 12; | ||||||
|  |     } | ||||||
|  |     return true; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| bool RagePhoto::setPhotoData(const QByteArray &data) | bool RagePhoto::setPhotoData(const QByteArray &data) | ||||||
| { | { | ||||||
|     quint32 size = data.size(); |     quint32 size = data.size(); | ||||||
|  |  | ||||||
|  | @ -58,6 +58,7 @@ public: | ||||||
|     void setFilePath(const QString &filePath); |     void setFilePath(const QString &filePath); | ||||||
|     void setIODevice(QIODevice *ioDevice); |     void setIODevice(QIODevice *ioDevice); | ||||||
|     bool setJsonData(const QByteArray &data); |     bool setJsonData(const QByteArray &data); | ||||||
|  |     bool setPhotoBuffer(quint32 size, bool moveOffsets = true); | ||||||
|     bool setPhotoData(const QByteArray &data); |     bool setPhotoData(const QByteArray &data); | ||||||
|     bool setPhotoData(const char *data, int size); |     bool setPhotoData(const char *data, int size); | ||||||
|     void setPhotoFormat(PhotoFormat photoFormat); |     void setPhotoFormat(PhotoFormat photoFormat); | ||||||
|  |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| /*****************************************************************************
 | /*****************************************************************************
 | ||||||
| * gta5spv Grand Theft Auto Snapmatic Picture Viewer | * gta5spv Grand Theft Auto Snapmatic Picture Viewer | ||||||
| * Copyright (C) 2016-2018 Syping | * Copyright (C) 2016-2020 Syping | ||||||
| * | * | ||||||
| * This program is free software: you can redistribute it and/or modify | * This program is free software: you can redistribute it and/or modify | ||||||
| * it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||||
|  | @ -59,7 +59,7 @@ SnapmaticPicture::~SnapmaticPicture() | ||||||
| void SnapmaticPicture::reset() | void SnapmaticPicture::reset() | ||||||
| { | { | ||||||
|     // INIT PIC
 |     // INIT PIC
 | ||||||
|     ragePhoto.clear(); |     p_ragePhoto.clear(); | ||||||
|     cachePicture = QImage(); |     cachePicture = QImage(); | ||||||
|     picExportFileName = QString(); |     picExportFileName = QString(); | ||||||
|     pictureStr = QString(); |     pictureStr = QString(); | ||||||
|  | @ -91,8 +91,8 @@ bool SnapmaticPicture::preloadFile() | ||||||
|         return false; |         return false; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     ragePhoto.setIODevice(picFile); |     p_ragePhoto.setIODevice(picFile); | ||||||
|     bool ok = ragePhoto.load(); |     bool ok = p_ragePhoto.load(); | ||||||
|     picFile->close(); |     picFile->close(); | ||||||
|     delete picFile; |     delete picFile; | ||||||
|     if (!ok) |     if (!ok) | ||||||
|  | @ -100,7 +100,7 @@ bool SnapmaticPicture::preloadFile() | ||||||
| 
 | 
 | ||||||
|     if (picFilePath.right(4) != QLatin1String(".g5e")) |     if (picFilePath.right(4) != QLatin1String(".g5e")) | ||||||
|     { |     { | ||||||
|         if (ragePhoto.photoFormat() == RagePhoto::PhotoFormat::G5EX) |         if (p_ragePhoto.photoFormat() == RagePhoto::PhotoFormat::G5EX) | ||||||
|             isFormatSwitch = true; |             isFormatSwitch = true; | ||||||
|     } |     } | ||||||
|     emit preloaded(); |     emit preloaded(); | ||||||
|  | @ -116,17 +116,17 @@ bool SnapmaticPicture::readingPicture(bool cacheEnabled_) | ||||||
|     cacheEnabled = cacheEnabled_; |     cacheEnabled = cacheEnabled_; | ||||||
| 
 | 
 | ||||||
|     bool ok = true; |     bool ok = true; | ||||||
|     if (!ragePhoto.isLoaded()) |     if (!p_ragePhoto.isLoaded()) | ||||||
|         ok = preloadFile(); |         ok = preloadFile(); | ||||||
| 
 | 
 | ||||||
|     if (!ok) |     if (!ok) | ||||||
|         return false; |         return false; | ||||||
| 
 | 
 | ||||||
|     if (cacheEnabled) picOk = cachePicture.loadFromData(ragePhoto.photoData(), "JPEG"); |     if (cacheEnabled) picOk = cachePicture.loadFromData(p_ragePhoto.photoData(), "JPEG"); | ||||||
|     if (!cacheEnabled) |     if (!cacheEnabled) | ||||||
|     { |     { | ||||||
|         QImage tempPicture; |         QImage tempPicture; | ||||||
|         picOk = tempPicture.loadFromData(ragePhoto.photoData(), "JPEG"); |         picOk = tempPicture.loadFromData(p_ragePhoto.photoData(), "JPEG"); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     parseJsonContent(); // JSON parsing is own function
 |     parseJsonContent(); // JSON parsing is own function
 | ||||||
|  | @ -138,7 +138,7 @@ bool SnapmaticPicture::readingPicture(bool cacheEnabled_) | ||||||
| 
 | 
 | ||||||
| void SnapmaticPicture::updateStrings() | void SnapmaticPicture::updateStrings() | ||||||
| { | { | ||||||
|     QString cmpPicTitl = ragePhoto.title(); |     QString cmpPicTitl = p_ragePhoto.title(); | ||||||
|     cmpPicTitl.replace('\"', "''"); |     cmpPicTitl.replace('\"', "''"); | ||||||
|     cmpPicTitl.replace(' ', '_'); |     cmpPicTitl.replace(' ', '_'); | ||||||
|     cmpPicTitl.replace(':', '-'); |     cmpPicTitl.replace(':', '-'); | ||||||
|  | @ -173,7 +173,7 @@ bool SnapmaticPicture::readingPictureFromFile(const QString &fileName, bool cach | ||||||
| 
 | 
 | ||||||
| bool SnapmaticPicture::setImage(const QImage &picture) | bool SnapmaticPicture::setImage(const QImage &picture) | ||||||
| { | { | ||||||
|     quint32 jpegPicStreamLength = ragePhoto.photoBuffer(); |     quint32 jpegPicStreamLength = p_ragePhoto.photoBuffer(); | ||||||
|     QByteArray picByteArray; |     QByteArray picByteArray; | ||||||
|     int comLvl = 100; |     int comLvl = 100; | ||||||
|     bool saveSuccess = false; |     bool saveSuccess = false; | ||||||
|  | @ -200,7 +200,7 @@ bool SnapmaticPicture::setImage(const QImage &picture) | ||||||
| 
 | 
 | ||||||
| bool SnapmaticPicture::setPictureStream(const QByteArray &streamArray) // clean method
 | bool SnapmaticPicture::setPictureStream(const QByteArray &streamArray) // clean method
 | ||||||
| { | { | ||||||
|     bool success = ragePhoto.setPhotoData(streamArray); |     bool success = p_ragePhoto.setPhotoData(streamArray); | ||||||
|     if (success) { |     if (success) { | ||||||
|         if (cacheEnabled) { |         if (cacheEnabled) { | ||||||
|             QImage replacedPicture; |             QImage replacedPicture; | ||||||
|  | @ -220,13 +220,13 @@ bool SnapmaticPicture::setPictureTitl(const QString &newTitle_) | ||||||
|     if (newTitle.length() > 39) { |     if (newTitle.length() > 39) { | ||||||
|         newTitle = newTitle.left(39); |         newTitle = newTitle.left(39); | ||||||
|     } |     } | ||||||
|     ragePhoto.setTitle(newTitle); |     p_ragePhoto.setTitle(newTitle); | ||||||
|     return true; |     return true; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| int SnapmaticPicture::getContentMaxLength() | int SnapmaticPicture::getContentMaxLength() | ||||||
| { | { | ||||||
|     return ragePhoto.photoBuffer(); |     return p_ragePhoto.photoBuffer(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| QString SnapmaticPicture::getExportPictureFileName() | QString SnapmaticPicture::getExportPictureFileName() | ||||||
|  | @ -279,7 +279,7 @@ QString SnapmaticPicture::getPictureSortStr() | ||||||
| 
 | 
 | ||||||
| QString SnapmaticPicture::getPictureTitl() | QString SnapmaticPicture::getPictureTitl() | ||||||
| { | { | ||||||
|     return ragePhoto.title(); |     return p_ragePhoto.title(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| QString SnapmaticPicture::getPictureStr() | QString SnapmaticPicture::getPictureStr() | ||||||
|  | @ -294,8 +294,6 @@ QString SnapmaticPicture::getLastStep(bool readable) | ||||||
|         QStringList lastStepList = lastStep.split(";/"); |         QStringList lastStepList = lastStep.split(";/"); | ||||||
|         if (lastStepList.length() < 2) { return lastStep; } |         if (lastStepList.length() < 2) { return lastStep; } | ||||||
|         bool intOk; |         bool intOk; | ||||||
|         //int stepNumber = lastStepList.at(0).toInt(&intOk);
 |  | ||||||
|         //if (!intOk) { return lastStep; }
 |  | ||||||
|         QStringList descStepList = lastStepList.at(1).split(","); |         QStringList descStepList = lastStepList.at(1).split(","); | ||||||
|         if (descStepList.length() < 1) { return lastStep; } |         if (descStepList.length() < 1) { return lastStep; } | ||||||
|         int argsCount = descStepList.at(0).toInt(&intOk); |         int argsCount = descStepList.at(0).toInt(&intOk); | ||||||
|  | @ -313,7 +311,6 @@ QString SnapmaticPicture::getLastStep(bool readable) | ||||||
|         { |         { | ||||||
|             QString currentAction = descStepList.at(1); |             QString currentAction = descStepList.at(1); | ||||||
|             QString actionFile = descStepList.at(2); |             QString actionFile = descStepList.at(2); | ||||||
|             //QString actionStep = descStepList.at(3);
 |  | ||||||
|             QString actionError = descStepList.at(4); |             QString actionError = descStepList.at(4); | ||||||
|             QString actionError2; |             QString actionError2; | ||||||
|             if (argsCount == 4) { actionError2 = descStepList.at(5); } |             if (argsCount == 4) { actionError2 = descStepList.at(5); } | ||||||
|  | @ -381,14 +378,14 @@ QImage SnapmaticPicture::getImage(bool fastLoad) | ||||||
|     } |     } | ||||||
|     else |     else | ||||||
|     { |     { | ||||||
|         return QImage::fromData(ragePhoto.photoData(), "JPEG"); |         return QImage::fromData(p_ragePhoto.photoData(), "JPEG"); | ||||||
|     } |     } | ||||||
|     return QImage(); |     return QImage(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| QByteArray SnapmaticPicture::getPictureStream() | QByteArray SnapmaticPicture::getPictureStream() | ||||||
| { | { | ||||||
|     return ragePhoto.photoData(); |     return p_ragePhoto.photoData(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool SnapmaticPicture::isPicOk() | bool SnapmaticPicture::isPicOk() | ||||||
|  | @ -421,7 +418,7 @@ bool SnapmaticPicture::isJsonOk() | ||||||
| 
 | 
 | ||||||
| QString SnapmaticPicture::getJsonStr() | QString SnapmaticPicture::getJsonStr() | ||||||
| { | { | ||||||
|     return QString::fromUtf8(ragePhoto.jsonData()); |     return QString::fromUtf8(p_ragePhoto.jsonData()); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| SnapmaticProperties SnapmaticPicture::getSnapmaticProperties() | SnapmaticProperties SnapmaticPicture::getSnapmaticProperties() | ||||||
|  | @ -431,7 +428,7 @@ SnapmaticProperties SnapmaticPicture::getSnapmaticProperties() | ||||||
| 
 | 
 | ||||||
| void SnapmaticPicture::parseJsonContent() | void SnapmaticPicture::parseJsonContent() | ||||||
| { | { | ||||||
|     QJsonObject jsonObject = ragePhoto.jsonObject(); |     QJsonObject jsonObject = p_ragePhoto.jsonObject(); | ||||||
|     QVariantMap jsonMap = jsonObject.toVariantMap(); |     QVariantMap jsonMap = jsonObject.toVariantMap(); | ||||||
| 
 | 
 | ||||||
|     bool jsonIncomplete = false; |     bool jsonIncomplete = false; | ||||||
|  | @ -565,7 +562,7 @@ void SnapmaticPicture::parseJsonContent() | ||||||
| 
 | 
 | ||||||
| bool SnapmaticPicture::setSnapmaticProperties(SnapmaticProperties properties) | bool SnapmaticPicture::setSnapmaticProperties(SnapmaticProperties properties) | ||||||
| { | { | ||||||
|     QJsonObject jsonObject = ragePhoto.jsonObject(); |     QJsonObject jsonObject = p_ragePhoto.jsonObject(); | ||||||
| 
 | 
 | ||||||
|     QJsonObject locObject; |     QJsonObject locObject; | ||||||
|     locObject["x"] = properties.location.x; |     locObject["x"] = properties.location.x; | ||||||
|  | @ -596,7 +593,7 @@ bool SnapmaticPicture::setSnapmaticProperties(SnapmaticProperties properties) | ||||||
| 
 | 
 | ||||||
| bool SnapmaticPicture::setJsonStr(const QString &newJsonStr, bool updateProperties) | bool SnapmaticPicture::setJsonStr(const QString &newJsonStr, bool updateProperties) | ||||||
| { | { | ||||||
|     if (ragePhoto.setJsonData(newJsonStr.toUtf8())) { |     if (p_ragePhoto.setJsonData(newJsonStr.toUtf8())) { | ||||||
|         if (updateProperties) |         if (updateProperties) | ||||||
|             parseJsonContent(); |             parseJsonContent(); | ||||||
|         return true; |         return true; | ||||||
|  | @ -614,7 +611,7 @@ bool SnapmaticPicture::exportPicture(const QString &fileName, SnapmaticFormat fo | ||||||
|     SnapmaticFormat format = format_; |     SnapmaticFormat format = format_; | ||||||
|     if (format_ == SnapmaticFormat::Auto_Format) |     if (format_ == SnapmaticFormat::Auto_Format) | ||||||
|     { |     { | ||||||
|         if (ragePhoto.photoFormat() == RagePhoto::PhotoFormat::G5EX) |         if (p_ragePhoto.photoFormat() == RagePhoto::PhotoFormat::G5EX) | ||||||
|         { |         { | ||||||
|             format = SnapmaticFormat::G5E_Format; |             format = SnapmaticFormat::G5E_Format; | ||||||
|         } |         } | ||||||
|  | @ -634,7 +631,7 @@ bool SnapmaticPicture::exportPicture(const QString &fileName, SnapmaticFormat fo | ||||||
|     { |     { | ||||||
|         if (format == SnapmaticFormat::G5E_Format) |         if (format == SnapmaticFormat::G5E_Format) | ||||||
|         { |         { | ||||||
|             ragePhoto.save(picFile, RagePhoto::PhotoFormat::G5EX); |             p_ragePhoto.save(picFile, RagePhoto::PhotoFormat::G5EX); | ||||||
| #if QT_VERSION >= 0x050000 | #if QT_VERSION >= 0x050000 | ||||||
|             saveSuccess = picFile->commit(); |             saveSuccess = picFile->commit(); | ||||||
| #else | #else | ||||||
|  | @ -645,7 +642,7 @@ bool SnapmaticPicture::exportPicture(const QString &fileName, SnapmaticFormat fo | ||||||
|         } |         } | ||||||
|         else if (format == SnapmaticFormat::JPEG_Format) |         else if (format == SnapmaticFormat::JPEG_Format) | ||||||
|         { |         { | ||||||
|             picFile->write(ragePhoto.photoData()); |             picFile->write(p_ragePhoto.photoData()); | ||||||
| #if QT_VERSION >= 0x050000 | #if QT_VERSION >= 0x050000 | ||||||
|             saveSuccess = picFile->commit(); |             saveSuccess = picFile->commit(); | ||||||
| #else | #else | ||||||
|  | @ -656,7 +653,7 @@ bool SnapmaticPicture::exportPicture(const QString &fileName, SnapmaticFormat fo | ||||||
|         } |         } | ||||||
|         else |         else | ||||||
|         { |         { | ||||||
|             ragePhoto.save(picFile, RagePhoto::PhotoFormat::GTA5); |             p_ragePhoto.save(picFile, RagePhoto::PhotoFormat::GTA5); | ||||||
| #if QT_VERSION >= 0x050000 | #if QT_VERSION >= 0x050000 | ||||||
|             saveSuccess = picFile->commit(); |             saveSuccess = picFile->commit(); | ||||||
| #else | #else | ||||||
|  | @ -749,7 +746,7 @@ bool SnapmaticPicture::isVisible() | ||||||
| 
 | 
 | ||||||
| bool SnapmaticPicture::setPictureHidden() | bool SnapmaticPicture::setPictureHidden() | ||||||
| { | { | ||||||
|     if (ragePhoto.photoFormat() == RagePhoto::PhotoFormat::G5EX) |     if (p_ragePhoto.photoFormat() == RagePhoto::PhotoFormat::G5EX) | ||||||
|     { |     { | ||||||
|         return false; |         return false; | ||||||
|     } |     } | ||||||
|  | @ -768,7 +765,7 @@ bool SnapmaticPicture::setPictureHidden() | ||||||
| 
 | 
 | ||||||
| bool SnapmaticPicture::setPictureVisible() | bool SnapmaticPicture::setPictureVisible() | ||||||
| { | { | ||||||
|     if (ragePhoto.photoFormat() == RagePhoto::PhotoFormat::G5EX) |     if (p_ragePhoto.photoFormat() == RagePhoto::PhotoFormat::G5EX) | ||||||
|     { |     { | ||||||
|         return false; |         return false; | ||||||
|     } |     } | ||||||
|  | @ -796,7 +793,7 @@ QSize SnapmaticPicture::getSnapmaticResolution() | ||||||
| 
 | 
 | ||||||
| SnapmaticFormat SnapmaticPicture::getSnapmaticFormat() | SnapmaticFormat SnapmaticPicture::getSnapmaticFormat() | ||||||
| { | { | ||||||
|     if (ragePhoto.photoFormat() == RagePhoto::PhotoFormat::G5EX) |     if (p_ragePhoto.photoFormat() == RagePhoto::PhotoFormat::G5EX) | ||||||
|     { |     { | ||||||
|         return SnapmaticFormat::G5E_Format; |         return SnapmaticFormat::G5E_Format; | ||||||
|     } |     } | ||||||
|  | @ -807,12 +804,12 @@ void SnapmaticPicture::setSnapmaticFormat(SnapmaticFormat format) | ||||||
| { | { | ||||||
|     if (format == SnapmaticFormat::G5E_Format) |     if (format == SnapmaticFormat::G5E_Format) | ||||||
|     { |     { | ||||||
|         ragePhoto.setPhotoFormat(RagePhoto::PhotoFormat::G5EX); |         p_ragePhoto.setPhotoFormat(RagePhoto::PhotoFormat::G5EX); | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|     else if (format == SnapmaticFormat::PGTA_Format) |     else if (format == SnapmaticFormat::PGTA_Format) | ||||||
|     { |     { | ||||||
|         ragePhoto.setPhotoFormat(RagePhoto::PhotoFormat::GTA5); |         p_ragePhoto.setPhotoFormat(RagePhoto::PhotoFormat::GTA5); | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|     qDebug() << "setSnapmaticFormat: Invalid SnapmaticFormat defined, valid SnapmaticFormats are G5E_Format and PGTA_Format"; |     qDebug() << "setSnapmaticFormat: Invalid SnapmaticFormat defined, valid SnapmaticFormats are G5E_Format and PGTA_Format"; | ||||||
|  | @ -877,3 +874,10 @@ QString SnapmaticPicture::convertLogStringForDraw(const QString &inputStr) | ||||||
|     QString outputStr = inputStr; |     QString outputStr = inputStr; | ||||||
|     return outputStr.replace("&c;",",").replace("&u;", "&"); |     return outputStr.replace("&c;",",").replace("&u;", "&"); | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | // RAGEPHOTO
 | ||||||
|  | 
 | ||||||
|  | RagePhoto* SnapmaticPicture::ragePhoto() | ||||||
|  | { | ||||||
|  |     return &p_ragePhoto; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| /*****************************************************************************
 | /*****************************************************************************
 | ||||||
| * gta5spv Grand Theft Auto Snapmatic Picture Viewer | * gta5spv Grand Theft Auto Snapmatic Picture Viewer | ||||||
| * Copyright (C) 2016-2018 Syping | * Copyright (C) 2016-2020 Syping | ||||||
| * | * | ||||||
| * This program is free software: you can redistribute it and/or modify | * This program is free software: you can redistribute it and/or modify | ||||||
| * it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||||
|  | @ -133,6 +133,9 @@ public: | ||||||
|     static QString convertDrawStringForLog(const QString &inputStr); |     static QString convertDrawStringForLog(const QString &inputStr); | ||||||
|     static QString convertLogStringForDraw(const QString &inputStr); |     static QString convertLogStringForDraw(const QString &inputStr); | ||||||
| 
 | 
 | ||||||
|  |     // RAGEPHOTO
 | ||||||
|  |     RagePhoto* ragePhoto(); | ||||||
|  | 
 | ||||||
| private: | private: | ||||||
|     QImage cachePicture; |     QImage cachePicture; | ||||||
|     QString picExportFileName; |     QString picExportFileName; | ||||||
|  | @ -154,7 +157,7 @@ private: | ||||||
|     static bool verifyTitleChar(const QChar &titleChar); |     static bool verifyTitleChar(const QChar &titleChar); | ||||||
| 
 | 
 | ||||||
|     // RAGEPHOTO
 |     // RAGEPHOTO
 | ||||||
|     RagePhoto ragePhoto; |     RagePhoto p_ragePhoto; | ||||||
| 
 | 
 | ||||||
| signals: | signals: | ||||||
|     void customSignal(QString signal); |     void customSignal(QString signal); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue