WIP: SnapmaticPicture using RagePhoto now
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Syping 2020-11-09 01:08:51 +01:00
parent b3e1520a8f
commit 186df05cea
5 changed files with 285 additions and 791 deletions

View file

@ -24,20 +24,23 @@
RagePhoto::RagePhoto(const QByteArray &data) : p_fileData(data) RagePhoto::RagePhoto(const QByteArray &data) : p_fileData(data)
{ {
p_inputMode = 0; p_photoFormat = PhotoFormat::Undefined;
p_isLoaded = false; p_isLoaded = false;
p_inputMode = 0;
} }
RagePhoto::RagePhoto(const QString &filePath) : p_filePath(filePath) RagePhoto::RagePhoto(const QString &filePath) : p_filePath(filePath)
{ {
p_inputMode = 1; p_photoFormat = PhotoFormat::Undefined;
p_isLoaded = false; p_isLoaded = false;
p_inputMode = 1;
} }
RagePhoto::RagePhoto(QIODevice *ioDevice) : p_ioDevice(ioDevice) RagePhoto::RagePhoto(QIODevice *ioDevice) : p_ioDevice(ioDevice)
{ {
p_inputMode = 2; p_photoFormat = PhotoFormat::Undefined;
p_isLoaded = false; p_isLoaded = false;
p_inputMode = 2;
} }
bool RagePhoto::isLoaded() bool RagePhoto::isLoaded()
@ -74,7 +77,7 @@ bool RagePhoto::load()
return false; return false;
quint32 format = charToUInt32LE(formatHeader); quint32 format = charToUInt32LE(formatHeader);
if (format == PhotoFormat::GTA5) { if (format == static_cast<quint32>(PhotoFormat::GTA5)) {
char photoHeader[256]; char photoHeader[256];
size = dataBuffer.read(photoHeader, 256); size = dataBuffer.read(photoHeader, 256);
if (size != 256) if (size != 256)
@ -138,7 +141,7 @@ bool RagePhoto::load()
size = dataBuffer.read(photoData, p_photoSize); size = dataBuffer.read(photoData, p_photoSize);
if (size != p_photoSize) if (size != p_photoSize)
return false; return false;
p_photoData = QByteArray::fromRawData(photoData, p_photoSize); p_photoData = QByteArray(photoData, p_photoSize);
dataBuffer.seek(p_jsonOffset + 264); dataBuffer.seek(p_jsonOffset + 264);
char jsonMarker[4]; char jsonMarker[4];
@ -158,13 +161,12 @@ bool RagePhoto::load()
size = dataBuffer.read(jsonBytes, i_jsonSize); size = dataBuffer.read(jsonBytes, i_jsonSize);
if (size != i_jsonSize) if (size != i_jsonSize)
return false; return false;
QByteArray t_jsonBytes;
for (quint32 i = 0; i != i_jsonSize; i++) { for (quint32 i = 0; i != i_jsonSize; i++) {
if (jsonBytes[i] == '\x00') if (jsonBytes[i] == '\x00')
break; 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()) if (t_jsonDocument.isNull())
return false; return false;
p_jsonObject = t_jsonDocument.object(); p_jsonObject = t_jsonDocument.object();
@ -225,17 +227,20 @@ bool RagePhoto::load()
if (strncmp(jendMarker, "JEND", 4) != 0) if (strncmp(jendMarker, "JEND", 4) != 0)
return false; return false;
if (p_photoFormat != PhotoFormat::G5EX)
p_photoFormat = PhotoFormat::GTA5;
p_fileData.clear(); p_fileData.clear();
p_isLoaded = true; p_isLoaded = true;
return true; return true;
} }
else if (format == PhotoFormat::G5EX) { else if (format == static_cast<quint32>(PhotoFormat::G5EX)) {
char formatHeader[4]; char formatHeader[4];
size = dataBuffer.read(formatHeader, 4); size = dataBuffer.read(formatHeader, 4);
if (size != 4) if (size != 4)
return false; return false;
quint32 format = charToUInt32LE(formatHeader); quint32 format = charToUInt32LE(formatHeader);
if (format == ExportFormat::G5E3P) { if (format == static_cast<quint32>(ExportFormat::G5E3P)) {
char photoHeaderSize[4]; char photoHeaderSize[4];
size = dataBuffer.peek(photoHeaderSize, 4); size = dataBuffer.peek(photoHeaderSize, 4);
if (size != 4) if (size != 4)
@ -293,8 +298,8 @@ bool RagePhoto::load()
if (size != i_jsonSize) if (size != i_jsonSize)
return false; return false;
QByteArray t_jsonBytes = QByteArray::fromRawData(compressedJson, i_jsonSize); QByteArray t_jsonBytes = QByteArray::fromRawData(compressedJson, i_jsonSize);
t_jsonBytes = qUncompress(t_jsonBytes); p_jsonData = qUncompress(t_jsonBytes);
QJsonDocument t_jsonDocument = QJsonDocument::fromJson(t_jsonBytes); QJsonDocument t_jsonDocument = QJsonDocument::fromJson(p_jsonData);
if (t_jsonDocument.isNull()) if (t_jsonDocument.isNull())
return false; return false;
p_jsonObject = t_jsonDocument.object(); p_jsonObject = t_jsonDocument.object();
@ -345,11 +350,14 @@ bool RagePhoto::load()
return false; return false;
p_endOfFile = charToUInt32LE(endOfFile); p_endOfFile = charToUInt32LE(endOfFile);
p_photoFormat = PhotoFormat::G5EX;
p_fileData.clear(); p_fileData.clear();
p_isLoaded = true; p_isLoaded = true;
return 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_fileData = dataBuffer.readAll();
p_inputMode = 0; p_inputMode = 0;
return load(); return load();
@ -365,8 +373,10 @@ bool RagePhoto::load()
void RagePhoto::clear() void RagePhoto::clear()
{ {
p_photoFormat = PhotoFormat::Undefined;
p_jsonObject = QJsonObject(); p_jsonObject = QJsonObject();
p_descriptionString.clear(); p_descriptionString.clear();
p_jsonData.clear();
p_photoData.clear(); p_photoData.clear();
p_photoString.clear(); p_photoString.clear();
p_titleString.clear(); p_titleString.clear();
@ -379,20 +389,47 @@ void RagePhoto::setDescription(const QString &description)
p_descriptionString = 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; 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) void RagePhoto::setTitle(const QString &title)
@ -400,6 +437,16 @@ void RagePhoto::setTitle(const QString &title)
p_titleString = title; p_titleString = title;
} }
const QByteArray RagePhoto::jsonData()
{
return p_jsonData;
}
const QJsonObject RagePhoto::jsonObject()
{
return p_jsonObject;
}
const QByteArray RagePhoto::photoData() const QByteArray RagePhoto::photoData()
{ {
return p_photoData; return p_photoData;
@ -420,6 +467,16 @@ const QString RagePhoto::title()
return p_titleString; return p_titleString;
} }
quint32 RagePhoto::photoBuffer()
{
return p_jpegBuffer;
}
RagePhoto::PhotoFormat RagePhoto::photoFormat()
{
return p_photoFormat;
}
RagePhoto* RagePhoto::loadFile(const QString &filePath) RagePhoto* RagePhoto::loadFile(const QString &filePath)
{ {
RagePhoto *ragePhoto = new RagePhoto(filePath); RagePhoto *ragePhoto = new RagePhoto(filePath);

View file

@ -27,16 +27,18 @@ class RagePhoto : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
enum ExportFormat { enum class ExportFormat : quint32 {
G5E2P = 0x01000032U, G5E2P = 0x01000032U,
G5E2S = 0x02000032U, G5E2S = 0x02000032U,
G5E3P = 0x01000033U, G5E3P = 0x01000033U,
G5E3S = 0x02000033U, G5E3S = 0x02000033U,
Undefined = 0,
}; };
enum PhotoFormat { enum class PhotoFormat : quint32 {
G5EX = 0x45354700U, G5EX = 0x45354700U,
GTA5 = 0x01000000U, GTA5 = 0x01000000U,
RDR2 = 0x04000000U, RDR2 = 0x04000000U,
Undefined = 0,
}; };
explicit RagePhoto(const QByteArray &data); explicit RagePhoto(const QByteArray &data);
explicit RagePhoto(const QString &filePath = QString()); explicit RagePhoto(const QString &filePath = QString());
@ -45,14 +47,21 @@ public:
bool load(); bool load();
void clear(); void clear();
void setDescription(const QString &description); void setDescription(const QString &description);
void setFileData(const QByteArray &data);
void setFilePath(const QString &filePath); void setFilePath(const QString &filePath);
void setPhotoData(const QByteArray &data); bool setJsonData(const QByteArray &data);
void setPhotoData(const char *data, int size); bool setPhotoData(const QByteArray &data);
bool setPhotoData(const char *data, int size);
void setPhotoFormat(PhotoFormat photoFormat);
void setTitle(const QString &title); void setTitle(const QString &title);
const QJsonObject jsonObject();
const QByteArray jsonData();
const QByteArray photoData(); const QByteArray photoData();
const QString description(); const QString description();
const QString photoString(); const QString photoString();
const QString title(); const QString title();
quint32 photoBuffer();
PhotoFormat photoFormat();
static RagePhoto* loadFile(const QString &filePath); static RagePhoto* loadFile(const QString &filePath);
private: private:
@ -60,8 +69,10 @@ private:
inline quint32 charToUInt32LE(char *x); inline quint32 charToUInt32LE(char *x);
inline void uInt32ToCharBE(quint32 *x, char *y); inline void uInt32ToCharBE(quint32 *x, char *y);
inline void uInt32ToCharLE(quint32 *x, char *y); inline void uInt32ToCharLE(quint32 *x, char *y);
PhotoFormat p_photoFormat;
QJsonObject p_jsonObject; QJsonObject p_jsonObject;
QByteArray p_fileData; QByteArray p_fileData;
QByteArray p_jsonData;
QByteArray p_photoData; QByteArray p_photoData;
QIODevice *p_ioDevice; QIODevice *p_ioDevice;
QString p_descriptionString; QString p_descriptionString;

File diff suppressed because it is too large Load diff

View file

@ -19,6 +19,7 @@
#ifndef SNAPMATICPICTURE_H #ifndef SNAPMATICPICTURE_H
#define SNAPMATICPICTURE_H #define SNAPMATICPICTURE_H
#include "RagePhoto.h"
#include <QStringList> #include <QStringList>
#include <QDateTime> #include <QDateTime>
#include <QObject> #include <QObject>
@ -65,16 +66,13 @@ public:
QByteArray getPictureStream(); QByteArray getPictureStream();
QString getLastStep(bool readable = true); QString getLastStep(bool readable = true);
QString getPictureStr(); QString getPictureStr();
QString getPictureHead();
QString getPictureTitl(); QString getPictureTitl();
QString getPictureDesc();
QString getPictureSortStr(); QString getPictureSortStr();
QString getPictureFileName(); QString getPictureFileName();
QString getPictureFilePath(); QString getPictureFilePath();
QString getExportPictureFileName(); QString getExportPictureFileName();
QString getOriginalPictureFileName(); QString getOriginalPictureFileName();
QString getOriginalPictureFilePath(); QString getOriginalPictureFilePath();
int getContentMaxLength();
bool setImage(const QImage &picture); bool setImage(const QImage &picture);
bool setPictureTitl(const QString &newTitle); // Please use setPictureTitle instead bool setPictureTitl(const QString &newTitle); // Please use setPictureTitle instead
bool setPictureStream(const QByteArray &streamArray); bool setPictureStream(const QByteArray &streamArray);
@ -106,7 +104,6 @@ public:
QString getPictureJson() { return getJsonStr(); } QString getPictureJson() { return getJsonStr(); }
QString getPictureTitle() { return getPictureTitl(); } QString getPictureTitle() { return getPictureTitl(); }
QString getPictureString() { return getPictureStr(); } 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 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 setPictureJson(const QString &json, bool updateProperties = false) { return setJsonStr(json, updateProperties); }
bool setPictureTitle(const QString &title) { return setPictureTitl(title); } bool setPictureTitle(const QString &title) { return setPictureTitl(title); }
@ -122,10 +119,6 @@ public:
// PREDEFINED PROPERTIES // PREDEFINED PROPERTIES
static QSize getSnapmaticResolution(); static QSize getSnapmaticResolution();
// SNAPMATIC DEFAULTS
bool isSnapmaticDefaultsEnforced();
void setSnapmaticDefaultsEnforced(bool enforced);
// SNAPMATIC FORMAT // SNAPMATIC FORMAT
SnapmaticFormat getSnapmaticFormat(); SnapmaticFormat getSnapmaticFormat();
void setSnapmaticFormat(SnapmaticFormat format); void setSnapmaticFormat(SnapmaticFormat format);
@ -140,43 +133,28 @@ public:
static QString convertLogStringForDraw(const QString &inputStr); static QString convertLogStringForDraw(const QString &inputStr);
private: private:
QString getSnapmaticHeaderString(const QByteArray &snapmaticHeader);
QString getSnapmaticJSONString(const QByteArray &jsonBytes);
QString getSnapmaticTIDEString(const QByteArray &tideBytes);
QImage cachePicture; QImage cachePicture;
QString picExportFileName; QString picExportFileName;
QString picFileName; QString picFileName;
QString picFilePath; QString picFilePath;
QString pictureHead;
QString pictureStr; QString pictureStr;
QString lastStep; QString lastStep;
QString sortStr; QString sortStr;
QString titlStr;
QString descStr;
bool picOk; bool picOk;
bool lowRamMode;
bool writeEnabled;
bool cacheEnabled; bool cacheEnabled;
bool isLoadedInRAM;
bool isCustomFormat;
bool isFormatSwitch; bool isFormatSwitch;
bool isModernFormat;
bool careSnapDefault;
int jpegRawContentSize;
int jpegRawContentSizeE;
// PICTURE STREAM
QByteArray rawPicContent;
// JSON // JSON
void parseJsonContent(); void parseJsonContent();
bool jsonOk; bool jsonOk;
QString jsonStr;
SnapmaticProperties localProperties; SnapmaticProperties localProperties;
// VERIFY CONTENT // VERIFY CONTENT
static bool verifyTitleChar(const QChar &titleChar); static bool verifyTitleChar(const QChar &titleChar);
// RAGEPHOTO
RagePhoto ragePhoto;
signals: signals:
void customSignal(QString signal); void customSignal(QString signal);
void preloaded(); void preloaded();

View file

@ -50,6 +50,7 @@ SOURCES += main.cpp \
ProfileInterface.cpp \ ProfileInterface.cpp \
ProfileLoader.cpp \ ProfileLoader.cpp \
ProfileWidget.cpp \ ProfileWidget.cpp \
RagePhoto.cpp \
SavegameCopy.cpp \ SavegameCopy.cpp \
SavegameData.cpp \ SavegameData.cpp \
SavegameDialog.cpp \ SavegameDialog.cpp \
@ -92,6 +93,7 @@ HEADERS += \
ProfileInterface.h \ ProfileInterface.h \
ProfileLoader.h \ ProfileLoader.h \
ProfileWidget.h \ ProfileWidget.h \
RagePhoto.h \
SavegameCopy.h \ SavegameCopy.h \
SavegameData.h \ SavegameData.h \
SavegameDialog.h \ SavegameDialog.h \