2020-11-08 03:50:06 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* gta5view Grand Theft Auto V Profile Viewer
|
|
|
|
* Copyright (C) 2020 Syping
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "RagePhoto.h"
|
|
|
|
#include <QJsonDocument>
|
|
|
|
#include <QBuffer>
|
|
|
|
#include <QFile>
|
2020-11-11 17:58:15 +01:00
|
|
|
#if QT_VERSION < 0x060000
|
|
|
|
#include <QTextCodec>
|
|
|
|
#endif
|
2020-11-08 03:50:06 +01:00
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
RagePhoto::RagePhoto()
|
|
|
|
{
|
|
|
|
p_photoFormat = PhotoFormat::Undefined;
|
|
|
|
p_isLoaded = false;
|
|
|
|
p_inputMode = -1;
|
|
|
|
}
|
|
|
|
|
2020-11-08 18:05:44 +01:00
|
|
|
RagePhoto::RagePhoto(const QByteArray &data) : p_fileData(data)
|
2020-11-08 03:50:06 +01:00
|
|
|
{
|
2020-11-09 01:08:51 +01:00
|
|
|
p_photoFormat = PhotoFormat::Undefined;
|
2020-11-08 03:50:06 +01:00
|
|
|
p_isLoaded = false;
|
2020-11-09 01:08:51 +01:00
|
|
|
p_inputMode = 0;
|
2020-11-08 03:50:06 +01:00
|
|
|
}
|
|
|
|
|
2020-11-08 18:05:44 +01:00
|
|
|
RagePhoto::RagePhoto(const QString &filePath) : p_filePath(filePath)
|
2020-11-08 03:50:06 +01:00
|
|
|
{
|
2020-11-09 01:08:51 +01:00
|
|
|
p_photoFormat = PhotoFormat::Undefined;
|
2020-11-08 03:50:06 +01:00
|
|
|
p_isLoaded = false;
|
2020-11-09 01:08:51 +01:00
|
|
|
p_inputMode = 1;
|
2020-11-08 03:50:06 +01:00
|
|
|
}
|
|
|
|
|
2020-11-08 18:05:44 +01:00
|
|
|
RagePhoto::RagePhoto(QIODevice *ioDevice) : p_ioDevice(ioDevice)
|
|
|
|
{
|
2020-11-09 01:08:51 +01:00
|
|
|
p_photoFormat = PhotoFormat::Undefined;
|
2020-11-08 18:05:44 +01:00
|
|
|
p_isLoaded = false;
|
2020-11-09 01:08:51 +01:00
|
|
|
p_inputMode = 2;
|
2020-11-08 18:05:44 +01:00
|
|
|
}
|
|
|
|
|
2020-11-08 03:50:06 +01:00
|
|
|
bool RagePhoto::isLoaded()
|
|
|
|
{
|
|
|
|
return p_isLoaded;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RagePhoto::load()
|
|
|
|
{
|
2020-11-11 07:04:39 +01:00
|
|
|
if (p_inputMode == -1)
|
|
|
|
return false;
|
|
|
|
|
2020-11-08 03:50:06 +01:00
|
|
|
if (p_isLoaded)
|
|
|
|
clear();
|
|
|
|
|
2020-11-08 18:05:44 +01:00
|
|
|
if (p_inputMode == 1) {
|
2020-11-08 03:50:06 +01:00
|
|
|
QFile pictureFile(p_filePath);
|
|
|
|
if (pictureFile.open(QIODevice::ReadOnly)) {
|
2020-11-08 18:05:44 +01:00
|
|
|
p_fileData = pictureFile.readAll();
|
2020-11-08 03:50:06 +01:00
|
|
|
}
|
|
|
|
pictureFile.close();
|
|
|
|
}
|
2020-11-08 18:05:44 +01:00
|
|
|
else if (p_inputMode == 2) {
|
2020-11-08 03:50:06 +01:00
|
|
|
if (!p_ioDevice->isOpen()) {
|
|
|
|
if (!p_ioDevice->open(QIODevice::ReadOnly))
|
|
|
|
return false;
|
|
|
|
}
|
2020-11-08 18:05:44 +01:00
|
|
|
p_fileData = p_ioDevice->readAll();
|
2020-11-08 03:50:06 +01:00
|
|
|
}
|
|
|
|
|
2020-11-08 18:05:44 +01:00
|
|
|
QBuffer dataBuffer(&p_fileData);
|
2020-11-08 03:50:06 +01:00
|
|
|
dataBuffer.open(QIODevice::ReadOnly);
|
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
char uInt32Buffer[4];
|
|
|
|
qint64 size = dataBuffer.read(uInt32Buffer, 4);
|
2020-11-08 03:50:06 +01:00
|
|
|
if (size != 4)
|
|
|
|
return false;
|
2020-11-11 07:04:39 +01:00
|
|
|
quint32 format = charToUInt32LE(uInt32Buffer);
|
2020-11-08 18:05:44 +01:00
|
|
|
|
2020-11-09 01:08:51 +01:00
|
|
|
if (format == static_cast<quint32>(PhotoFormat::GTA5)) {
|
2020-11-08 18:05:44 +01:00
|
|
|
char photoHeader[256];
|
|
|
|
size = dataBuffer.read(photoHeader, 256);
|
|
|
|
if (size != 256)
|
|
|
|
return false;
|
2020-11-11 17:58:15 +01:00
|
|
|
for (const QChar &photoChar : utf16LEToString(photoHeader, 256)) {
|
2020-11-08 18:05:44 +01:00
|
|
|
if (photoChar.isNull())
|
|
|
|
break;
|
|
|
|
p_photoString += photoChar;
|
|
|
|
}
|
2020-11-08 03:50:06 +01:00
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
size = dataBuffer.read(uInt32Buffer, 4);
|
2020-11-08 18:05:44 +01:00
|
|
|
if (size != 4)
|
|
|
|
return false;
|
2020-11-11 07:04:39 +01:00
|
|
|
p_headerSum = charToUInt32LE(uInt32Buffer);
|
2020-11-08 18:05:44 +01:00
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
size = dataBuffer.read(uInt32Buffer, 4);
|
2020-11-08 18:05:44 +01:00
|
|
|
if (size != 4)
|
|
|
|
return false;
|
2020-11-11 07:04:39 +01:00
|
|
|
p_endOfFile = charToUInt32LE(uInt32Buffer);
|
2020-11-08 18:05:44 +01:00
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
size = dataBuffer.read(uInt32Buffer, 4);
|
2020-11-08 18:05:44 +01:00
|
|
|
if (size != 4)
|
|
|
|
return false;
|
2020-11-11 07:04:39 +01:00
|
|
|
p_jsonOffset = charToUInt32LE(uInt32Buffer);
|
2020-11-08 18:05:44 +01:00
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
size = dataBuffer.read(uInt32Buffer, 4);
|
2020-11-08 18:05:44 +01:00
|
|
|
if (size != 4)
|
|
|
|
return false;
|
2020-11-11 07:04:39 +01:00
|
|
|
p_titlOffset = charToUInt32LE(uInt32Buffer);
|
2020-11-08 18:05:44 +01:00
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
size = dataBuffer.read(uInt32Buffer, 4);
|
2020-11-08 18:05:44 +01:00
|
|
|
if (size != 4)
|
|
|
|
return false;
|
2020-11-11 07:04:39 +01:00
|
|
|
p_descOffset = charToUInt32LE(uInt32Buffer);
|
2020-11-08 18:05:44 +01:00
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
char markerBuffer[4];
|
|
|
|
size = dataBuffer.read(markerBuffer, 4);
|
2020-11-08 18:05:44 +01:00
|
|
|
if (size != 4)
|
|
|
|
return false;
|
2020-11-11 07:04:39 +01:00
|
|
|
if (strncmp(markerBuffer, "JPEG", 4) != 0)
|
2020-11-08 18:05:44 +01:00
|
|
|
return false;
|
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
size = dataBuffer.read(uInt32Buffer, 4);
|
2020-11-08 18:05:44 +01:00
|
|
|
if (size != 4)
|
|
|
|
return false;
|
2020-11-11 07:04:39 +01:00
|
|
|
p_photoBuffer = charToUInt32LE(uInt32Buffer);
|
2020-11-08 18:05:44 +01:00
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
size = dataBuffer.read(uInt32Buffer, 4);
|
2020-11-08 18:05:44 +01:00
|
|
|
if (size != 4)
|
|
|
|
return false;
|
2020-11-11 07:04:39 +01:00
|
|
|
quint32 t_photoSize = charToUInt32LE(uInt32Buffer);
|
2020-11-08 18:05:44 +01:00
|
|
|
|
2020-11-09 01:42:11 +01:00
|
|
|
char photoData[t_photoSize];
|
|
|
|
size = dataBuffer.read(photoData, t_photoSize);
|
|
|
|
if (size != t_photoSize)
|
2020-11-08 18:05:44 +01:00
|
|
|
return false;
|
2020-11-09 01:42:11 +01:00
|
|
|
p_photoData = QByteArray(photoData, t_photoSize);
|
2020-11-08 18:05:44 +01:00
|
|
|
|
|
|
|
dataBuffer.seek(p_jsonOffset + 264);
|
2020-11-11 07:04:39 +01:00
|
|
|
size = dataBuffer.read(markerBuffer, 4);
|
2020-11-08 18:05:44 +01:00
|
|
|
if (size != 4)
|
|
|
|
return false;
|
2020-11-11 07:04:39 +01:00
|
|
|
if (strncmp(markerBuffer, "JSON", 4) != 0)
|
2020-11-08 18:05:44 +01:00
|
|
|
return false;
|
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
size = dataBuffer.read(uInt32Buffer, 4);
|
2020-11-08 18:05:44 +01:00
|
|
|
if (size != 4)
|
|
|
|
return false;
|
2020-11-11 07:04:39 +01:00
|
|
|
p_jsonBuffer = charToUInt32LE(uInt32Buffer);
|
2020-11-08 18:05:44 +01:00
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
char jsonBytes[p_jsonBuffer];
|
|
|
|
size = dataBuffer.read(jsonBytes, p_jsonBuffer);
|
|
|
|
if (size != p_jsonBuffer)
|
2020-11-08 18:05:44 +01:00
|
|
|
return false;
|
2020-11-11 07:04:39 +01:00
|
|
|
for (quint32 i = 0; i != p_jsonBuffer; i++) {
|
2020-11-08 18:05:44 +01:00
|
|
|
if (jsonBytes[i] == '\x00')
|
|
|
|
break;
|
2020-11-09 01:08:51 +01:00
|
|
|
p_jsonData += jsonBytes[i];
|
2020-11-08 18:05:44 +01:00
|
|
|
}
|
2020-11-09 01:08:51 +01:00
|
|
|
QJsonDocument t_jsonDocument = QJsonDocument::fromJson(p_jsonData);
|
2020-11-08 18:05:44 +01:00
|
|
|
if (t_jsonDocument.isNull())
|
|
|
|
return false;
|
|
|
|
p_jsonObject = t_jsonDocument.object();
|
|
|
|
|
|
|
|
dataBuffer.seek(p_titlOffset + 264);
|
2020-11-11 07:04:39 +01:00
|
|
|
size = dataBuffer.read(markerBuffer, 4);
|
2020-11-08 18:05:44 +01:00
|
|
|
if (size != 4)
|
|
|
|
return false;
|
2020-11-11 07:04:39 +01:00
|
|
|
if (strncmp(markerBuffer, "TITL", 4) != 0)
|
2020-11-08 18:05:44 +01:00
|
|
|
return false;
|
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
size = dataBuffer.read(uInt32Buffer, 4);
|
2020-11-08 18:05:44 +01:00
|
|
|
if (size != 4)
|
|
|
|
return false;
|
2020-11-11 07:04:39 +01:00
|
|
|
p_titlBuffer = charToUInt32LE(uInt32Buffer);
|
2020-11-08 18:05:44 +01:00
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
char titlBytes[p_titlBuffer];
|
|
|
|
size = dataBuffer.read(titlBytes, p_titlBuffer);
|
|
|
|
if (size != p_titlBuffer)
|
2020-11-08 18:05:44 +01:00
|
|
|
return false;
|
2020-11-11 07:04:39 +01:00
|
|
|
for (const QChar &titlChar : QString::fromUtf8(titlBytes, p_titlBuffer)) {
|
2020-11-08 18:05:44 +01:00
|
|
|
if (titlChar.isNull())
|
|
|
|
break;
|
|
|
|
p_titleString += titlChar;
|
|
|
|
}
|
2020-11-08 03:50:06 +01:00
|
|
|
|
2020-11-08 18:05:44 +01:00
|
|
|
dataBuffer.seek(p_descOffset + 264);
|
2020-11-11 07:04:39 +01:00
|
|
|
size = dataBuffer.read(markerBuffer, 4);
|
2020-11-08 18:05:44 +01:00
|
|
|
if (size != 4)
|
|
|
|
return false;
|
2020-11-11 07:04:39 +01:00
|
|
|
if (strncmp(markerBuffer, "DESC", 4) != 0)
|
2020-11-08 18:05:44 +01:00
|
|
|
return false;
|
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
size = dataBuffer.read(uInt32Buffer, 4);
|
2020-11-08 18:05:44 +01:00
|
|
|
if (size != 4)
|
|
|
|
return false;
|
2020-11-11 07:04:39 +01:00
|
|
|
p_descBuffer = charToUInt32LE(uInt32Buffer);
|
2020-11-08 18:05:44 +01:00
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
char descBytes[p_descBuffer];
|
|
|
|
size = dataBuffer.read(descBytes, p_descBuffer);
|
|
|
|
if (size != p_descBuffer)
|
2020-11-08 18:05:44 +01:00
|
|
|
return false;
|
2020-11-11 07:04:39 +01:00
|
|
|
for (const QChar &descChar : QString::fromUtf8(descBytes, p_descBuffer)) {
|
2020-11-08 18:05:44 +01:00
|
|
|
if (descChar.isNull())
|
|
|
|
break;
|
|
|
|
p_descriptionString += descChar;
|
|
|
|
}
|
2020-11-08 03:50:06 +01:00
|
|
|
|
2020-11-08 18:05:44 +01:00
|
|
|
dataBuffer.seek(p_endOfFile + 260);
|
2020-11-11 07:04:39 +01:00
|
|
|
size = dataBuffer.read(markerBuffer, 4);
|
2020-11-08 18:05:44 +01:00
|
|
|
if (size != 4)
|
|
|
|
return false;
|
2020-11-11 07:04:39 +01:00
|
|
|
if (strncmp(markerBuffer, "JEND", 4) != 0)
|
2020-11-08 18:05:44 +01:00
|
|
|
return false;
|
|
|
|
|
2020-11-09 01:08:51 +01:00
|
|
|
if (p_photoFormat != PhotoFormat::G5EX)
|
|
|
|
p_photoFormat = PhotoFormat::GTA5;
|
|
|
|
|
2020-11-08 18:05:44 +01:00
|
|
|
p_fileData.clear();
|
|
|
|
p_isLoaded = true;
|
|
|
|
return true;
|
|
|
|
}
|
2020-11-09 01:08:51 +01:00
|
|
|
else if (format == static_cast<quint32>(PhotoFormat::G5EX)) {
|
2020-11-11 07:04:39 +01:00
|
|
|
size = dataBuffer.read(uInt32Buffer, 4);
|
2020-11-08 18:05:44 +01:00
|
|
|
if (size != 4)
|
|
|
|
return false;
|
2020-11-11 07:04:39 +01:00
|
|
|
format = charToUInt32LE(uInt32Buffer);
|
2020-11-09 01:08:51 +01:00
|
|
|
if (format == static_cast<quint32>(ExportFormat::G5E3P)) {
|
2020-11-11 07:04:39 +01:00
|
|
|
size = dataBuffer.read(uInt32Buffer, 4);
|
2020-11-08 18:05:44 +01:00
|
|
|
if (size != 4)
|
|
|
|
return false;
|
2020-11-11 07:04:39 +01:00
|
|
|
quint32 compressedSize = charToUInt32LE(uInt32Buffer);
|
2020-11-08 03:50:06 +01:00
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
char compressedPhotoHeader[compressedSize];
|
|
|
|
size = dataBuffer.read(compressedPhotoHeader, compressedSize);
|
|
|
|
if (size != compressedSize)
|
2020-11-08 18:05:44 +01:00
|
|
|
return false;
|
2020-11-11 07:04:39 +01:00
|
|
|
QByteArray t_photoHeader = QByteArray::fromRawData(compressedPhotoHeader, compressedSize);
|
|
|
|
t_photoHeader = qUncompress(t_photoHeader);
|
|
|
|
if (t_photoHeader.isEmpty())
|
|
|
|
return false;
|
|
|
|
p_photoString = QString::fromUtf8(t_photoHeader);
|
2020-11-08 03:50:06 +01:00
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
size = dataBuffer.read(uInt32Buffer, 4);
|
2020-11-08 18:05:44 +01:00
|
|
|
if (size != 4)
|
|
|
|
return false;
|
2020-11-11 07:04:39 +01:00
|
|
|
p_headerSum = charToUInt32LE(uInt32Buffer);
|
2020-11-08 03:50:06 +01:00
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
size = dataBuffer.read(uInt32Buffer, 4);
|
2020-11-08 18:05:44 +01:00
|
|
|
if (size != 4)
|
|
|
|
return false;
|
2020-11-11 07:04:39 +01:00
|
|
|
p_photoBuffer = charToUInt32LE(uInt32Buffer);
|
2020-11-08 03:50:06 +01:00
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
size = dataBuffer.read(uInt32Buffer, 4);
|
2020-11-08 18:05:44 +01:00
|
|
|
if (size != 4)
|
|
|
|
return false;
|
2020-11-11 07:04:39 +01:00
|
|
|
compressedSize = charToUInt32LE(uInt32Buffer);
|
2020-11-08 03:50:06 +01:00
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
char compressedPhoto[compressedSize];
|
|
|
|
size = dataBuffer.read(compressedPhoto, compressedSize);
|
|
|
|
if (size != compressedSize)
|
2020-11-08 18:05:44 +01:00
|
|
|
return false;
|
2020-11-11 07:04:39 +01:00
|
|
|
QByteArray t_photoData = QByteArray::fromRawData(compressedPhoto, compressedSize);
|
2020-11-08 18:05:44 +01:00
|
|
|
p_photoData = qUncompress(t_photoData);
|
2020-11-08 03:50:06 +01:00
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
size = dataBuffer.read(uInt32Buffer, 4);
|
|
|
|
if (size != 4)
|
|
|
|
return false;
|
|
|
|
p_jsonOffset = charToUInt32LE(uInt32Buffer);
|
|
|
|
|
|
|
|
size = dataBuffer.read(uInt32Buffer, 4);
|
2020-11-08 18:05:44 +01:00
|
|
|
if (size != 4)
|
|
|
|
return false;
|
2020-11-11 07:04:39 +01:00
|
|
|
p_jsonBuffer = charToUInt32LE(uInt32Buffer);
|
2020-11-08 03:50:06 +01:00
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
size = dataBuffer.read(uInt32Buffer, 4);
|
2020-11-08 18:05:44 +01:00
|
|
|
if (size != 4)
|
|
|
|
return false;
|
2020-11-11 07:04:39 +01:00
|
|
|
compressedSize = charToUInt32LE(uInt32Buffer);
|
2020-11-08 03:50:06 +01:00
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
char compressedJson[compressedSize];
|
|
|
|
size = dataBuffer.read(compressedJson, compressedSize);
|
|
|
|
if (size != compressedSize)
|
2020-11-08 18:05:44 +01:00
|
|
|
return false;
|
2020-11-11 07:04:39 +01:00
|
|
|
QByteArray t_jsonBytes = QByteArray::fromRawData(compressedJson, compressedSize);
|
2020-11-09 01:08:51 +01:00
|
|
|
p_jsonData = qUncompress(t_jsonBytes);
|
2020-11-11 07:04:39 +01:00
|
|
|
if (p_jsonData.isEmpty())
|
|
|
|
return false;
|
2020-11-09 01:08:51 +01:00
|
|
|
QJsonDocument t_jsonDocument = QJsonDocument::fromJson(p_jsonData);
|
2020-11-08 18:05:44 +01:00
|
|
|
if (t_jsonDocument.isNull())
|
|
|
|
return false;
|
|
|
|
p_jsonObject = t_jsonDocument.object();
|
2020-11-08 03:50:06 +01:00
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
size = dataBuffer.read(uInt32Buffer, 4);
|
2020-11-08 18:05:44 +01:00
|
|
|
if (size != 4)
|
|
|
|
return false;
|
2020-11-11 07:04:39 +01:00
|
|
|
p_titlOffset = charToUInt32LE(uInt32Buffer);
|
2020-11-08 03:50:06 +01:00
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
size = dataBuffer.read(uInt32Buffer, 4);
|
2020-11-08 18:05:44 +01:00
|
|
|
if (size != 4)
|
|
|
|
return false;
|
2020-11-11 07:04:39 +01:00
|
|
|
p_titlBuffer = charToUInt32LE(uInt32Buffer);
|
2020-11-08 03:50:06 +01:00
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
size = dataBuffer.read(uInt32Buffer, 4);
|
|
|
|
if (size != 4)
|
2020-11-08 18:05:44 +01:00
|
|
|
return false;
|
2020-11-11 07:04:39 +01:00
|
|
|
compressedSize = charToUInt32LE(uInt32Buffer);
|
|
|
|
|
|
|
|
char compressedTitl[compressedSize];
|
|
|
|
size = dataBuffer.read(compressedTitl, compressedSize);
|
|
|
|
if (size != compressedSize)
|
|
|
|
return false;
|
|
|
|
QByteArray t_titlBytes = QByteArray::fromRawData(compressedTitl, compressedSize);
|
2020-11-08 18:05:44 +01:00
|
|
|
t_titlBytes = qUncompress(t_titlBytes);
|
|
|
|
p_titleString = QString::fromUtf8(t_titlBytes);
|
2020-11-08 03:50:06 +01:00
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
size = dataBuffer.read(uInt32Buffer, 4);
|
|
|
|
if (size != 4)
|
|
|
|
return false;
|
|
|
|
p_descOffset = charToUInt32LE(uInt32Buffer);
|
|
|
|
|
|
|
|
size = dataBuffer.read(uInt32Buffer, 4);
|
2020-11-08 18:05:44 +01:00
|
|
|
if (size != 4)
|
|
|
|
return false;
|
2020-11-11 07:04:39 +01:00
|
|
|
p_descBuffer = charToUInt32LE(uInt32Buffer);
|
2020-11-08 03:50:06 +01:00
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
size = dataBuffer.read(uInt32Buffer, 4);
|
2020-11-08 18:05:44 +01:00
|
|
|
if (size != 4)
|
|
|
|
return false;
|
2020-11-11 07:04:39 +01:00
|
|
|
compressedSize = charToUInt32LE(uInt32Buffer);
|
2020-11-08 03:50:06 +01:00
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
char compressedDesc[compressedSize];
|
|
|
|
size = dataBuffer.read(compressedDesc, compressedSize);
|
|
|
|
if (size != compressedSize)
|
2020-11-08 18:05:44 +01:00
|
|
|
return false;
|
2020-11-11 07:04:39 +01:00
|
|
|
QByteArray t_descBytes = QByteArray::fromRawData(compressedDesc, compressedSize);
|
2020-11-08 18:05:44 +01:00
|
|
|
t_descBytes = qUncompress(t_descBytes);
|
|
|
|
p_descriptionString = QString::fromUtf8(t_descBytes);
|
2020-11-08 03:50:06 +01:00
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
size = dataBuffer.read(uInt32Buffer, 4);
|
2020-11-08 18:05:44 +01:00
|
|
|
if (size != 4)
|
|
|
|
return false;
|
2020-11-11 07:04:39 +01:00
|
|
|
p_endOfFile = charToUInt32LE(uInt32Buffer);
|
2020-11-08 03:50:06 +01:00
|
|
|
|
2020-11-09 01:08:51 +01:00
|
|
|
p_photoFormat = PhotoFormat::G5EX;
|
|
|
|
|
2020-11-08 18:05:44 +01:00
|
|
|
p_fileData.clear();
|
|
|
|
p_isLoaded = true;
|
|
|
|
return true;
|
|
|
|
}
|
2020-11-09 01:08:51 +01:00
|
|
|
else if (format == static_cast<quint32>(ExportFormat::G5E2P)) {
|
|
|
|
p_photoFormat = PhotoFormat::G5EX;
|
2020-11-09 02:13:06 +01:00
|
|
|
p_fileData = qUncompress(dataBuffer.readAll());
|
2020-11-11 07:04:39 +01:00
|
|
|
if (p_fileData.isEmpty())
|
|
|
|
return false;
|
2020-11-09 02:13:06 +01:00
|
|
|
p_inputMode = 0;
|
|
|
|
return load();
|
|
|
|
}
|
|
|
|
else if (format == static_cast<quint32>(ExportFormat::G5E1P)) {
|
2020-11-11 18:14:50 +01:00
|
|
|
#if QT_VERSION >= 0x050A00
|
2020-11-09 02:13:06 +01:00
|
|
|
size = dataBuffer.skip(1);
|
2020-11-11 18:14:50 +01:00
|
|
|
#else
|
|
|
|
QByteArray skipData = dataBuffer.read(1);
|
|
|
|
size = skipData.size();
|
|
|
|
#endif
|
2020-11-09 02:13:06 +01:00
|
|
|
if (size != 1)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
char length[1];
|
|
|
|
size = dataBuffer.read(length, 1);
|
|
|
|
if (size != 1)
|
|
|
|
return false;
|
|
|
|
int i_length = QByteArray::number((int)length[0], 16).toInt() + 6;
|
|
|
|
|
2020-11-11 18:14:50 +01:00
|
|
|
#if QT_VERSION >= 0x050A00
|
2020-11-09 02:13:06 +01:00
|
|
|
size = dataBuffer.skip(i_length);
|
2020-11-11 18:14:50 +01:00
|
|
|
#else
|
|
|
|
skipData = dataBuffer.read(i_length);
|
|
|
|
size = skipData.size();
|
|
|
|
#endif
|
2020-11-09 02:13:06 +01:00
|
|
|
if (size != i_length)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
p_photoFormat = PhotoFormat::G5EX;
|
|
|
|
p_fileData = qUncompress(dataBuffer.readAll());
|
2020-11-11 07:04:39 +01:00
|
|
|
if (p_fileData.isEmpty())
|
|
|
|
return false;
|
2020-11-08 18:05:44 +01:00
|
|
|
p_inputMode = 0;
|
|
|
|
return load();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
2020-11-08 03:50:06 +01:00
|
|
|
}
|
2020-11-08 18:05:44 +01:00
|
|
|
else {
|
2020-11-08 03:50:06 +01:00
|
|
|
return false;
|
2020-11-08 18:05:44 +01:00
|
|
|
}
|
2020-11-08 03:50:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void RagePhoto::clear()
|
|
|
|
{
|
2020-11-09 01:08:51 +01:00
|
|
|
p_photoFormat = PhotoFormat::Undefined;
|
2020-11-08 03:50:06 +01:00
|
|
|
p_jsonObject = QJsonObject();
|
|
|
|
p_descriptionString.clear();
|
2020-11-09 01:08:51 +01:00
|
|
|
p_jsonData.clear();
|
2020-11-08 03:50:06 +01:00
|
|
|
p_photoData.clear();
|
|
|
|
p_photoString.clear();
|
|
|
|
p_titleString.clear();
|
2020-11-08 18:05:44 +01:00
|
|
|
p_headerSum = 0;
|
2020-11-08 03:50:06 +01:00
|
|
|
p_isLoaded = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RagePhoto::setDescription(const QString &description)
|
|
|
|
{
|
|
|
|
p_descriptionString = description;
|
|
|
|
}
|
|
|
|
|
2020-11-09 01:08:51 +01:00
|
|
|
void RagePhoto::setFileData(const QByteArray &data)
|
|
|
|
{
|
|
|
|
p_fileData = data;
|
|
|
|
p_inputMode = 0;
|
|
|
|
}
|
|
|
|
|
2020-11-08 03:50:06 +01:00
|
|
|
void RagePhoto::setFilePath(const QString &filePath)
|
|
|
|
{
|
|
|
|
p_filePath = filePath;
|
2020-11-09 01:08:51 +01:00
|
|
|
p_inputMode = 1;
|
|
|
|
}
|
|
|
|
|
2020-11-09 01:23:01 +01:00
|
|
|
void RagePhoto::setIODevice(QIODevice *ioDevice)
|
|
|
|
{
|
|
|
|
p_ioDevice = ioDevice;
|
|
|
|
p_inputMode = 2;
|
|
|
|
}
|
|
|
|
|
2020-11-09 01:08:51 +01:00
|
|
|
bool RagePhoto::setJsonData(const QByteArray &data)
|
|
|
|
{
|
|
|
|
QJsonDocument t_jsonDocument = QJsonDocument::fromJson(data);
|
|
|
|
if (t_jsonDocument.isNull())
|
|
|
|
return false;
|
2020-11-11 07:04:39 +01:00
|
|
|
p_jsonData = t_jsonDocument.toJson(QJsonDocument::Compact);
|
2020-11-09 01:08:51 +01:00
|
|
|
p_jsonObject = t_jsonDocument.object();
|
|
|
|
return true;
|
2020-11-15 12:29:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2020-11-08 03:50:06 +01:00
|
|
|
}
|
|
|
|
|
2020-11-09 01:08:51 +01:00
|
|
|
bool RagePhoto::setPhotoData(const QByteArray &data)
|
2020-11-08 03:50:06 +01:00
|
|
|
{
|
2020-11-09 01:42:11 +01:00
|
|
|
quint32 size = data.size();
|
2020-11-11 07:04:39 +01:00
|
|
|
if (size > p_photoBuffer)
|
2020-11-09 01:08:51 +01:00
|
|
|
return false;
|
2020-11-08 03:50:06 +01:00
|
|
|
p_photoData = data;
|
2020-11-09 01:08:51 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RagePhoto::setPhotoData(const char *data, int size)
|
|
|
|
{
|
2020-11-12 00:24:21 +01:00
|
|
|
if (static_cast<quint32>(size) > p_photoBuffer)
|
2020-11-09 01:08:51 +01:00
|
|
|
return false;
|
|
|
|
p_photoData = QByteArray(data, size);
|
|
|
|
return true;
|
2020-11-08 03:50:06 +01:00
|
|
|
}
|
|
|
|
|
2020-11-09 01:08:51 +01:00
|
|
|
void RagePhoto::setPhotoFormat(PhotoFormat photoFormat)
|
2020-11-08 03:50:06 +01:00
|
|
|
{
|
2020-11-09 01:08:51 +01:00
|
|
|
p_photoFormat = photoFormat;
|
2020-11-08 03:50:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void RagePhoto::setTitle(const QString &title)
|
|
|
|
{
|
|
|
|
p_titleString = title;
|
|
|
|
}
|
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
const QByteArray RagePhoto::jsonData(JsonFormat jsonFormat)
|
2020-11-09 01:08:51 +01:00
|
|
|
{
|
2020-11-11 07:04:39 +01:00
|
|
|
if (jsonFormat == JsonFormat::Compact) {
|
|
|
|
return QJsonDocument(p_jsonObject).toJson(QJsonDocument::Compact);
|
|
|
|
}
|
|
|
|
else if (jsonFormat == JsonFormat::Indented) {
|
|
|
|
return QJsonDocument(p_jsonObject).toJson(QJsonDocument::Indented);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return p_jsonData;
|
|
|
|
}
|
2020-11-09 01:08:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const QJsonObject RagePhoto::jsonObject()
|
|
|
|
{
|
|
|
|
return p_jsonObject;
|
|
|
|
}
|
|
|
|
|
2020-11-08 03:50:06 +01:00
|
|
|
const QByteArray RagePhoto::photoData()
|
|
|
|
{
|
|
|
|
return p_photoData;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString RagePhoto::description()
|
|
|
|
{
|
|
|
|
return p_descriptionString;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString RagePhoto::photoString()
|
|
|
|
{
|
|
|
|
return p_photoString;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString RagePhoto::title()
|
|
|
|
{
|
|
|
|
return p_titleString;
|
|
|
|
}
|
|
|
|
|
2020-11-09 01:08:51 +01:00
|
|
|
quint32 RagePhoto::photoBuffer()
|
|
|
|
{
|
2020-11-11 07:04:39 +01:00
|
|
|
return p_photoBuffer;
|
2020-11-09 01:08:51 +01:00
|
|
|
}
|
|
|
|
|
2020-11-09 01:42:11 +01:00
|
|
|
quint32 RagePhoto::photoSize()
|
|
|
|
{
|
|
|
|
return p_photoData.size();
|
|
|
|
}
|
|
|
|
|
2020-11-09 01:08:51 +01:00
|
|
|
RagePhoto::PhotoFormat RagePhoto::photoFormat()
|
|
|
|
{
|
|
|
|
return p_photoFormat;
|
|
|
|
}
|
|
|
|
|
2020-11-09 03:43:46 +01:00
|
|
|
QByteArray RagePhoto::save(PhotoFormat photoFormat)
|
|
|
|
{
|
|
|
|
QByteArray data;
|
|
|
|
QBuffer dataBuffer(&data);
|
|
|
|
dataBuffer.open(QIODevice::WriteOnly);
|
|
|
|
save(&dataBuffer, photoFormat);
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RagePhoto::save(QIODevice *ioDevice, PhotoFormat photoFormat)
|
|
|
|
{
|
2020-11-11 07:04:39 +01:00
|
|
|
if (photoFormat == PhotoFormat::G5EX) {
|
|
|
|
char uInt32Buffer[4];
|
|
|
|
quint32 format = static_cast<quint32>(PhotoFormat::G5EX);
|
|
|
|
uInt32ToCharLE(&format, uInt32Buffer);
|
|
|
|
ioDevice->write(uInt32Buffer, 4);
|
|
|
|
format = static_cast<quint32>(ExportFormat::G5E3P);
|
|
|
|
uInt32ToCharLE(&format, uInt32Buffer);
|
|
|
|
ioDevice->write(uInt32Buffer, 4);
|
|
|
|
|
|
|
|
QByteArray compressedData = qCompress(p_photoString.toUtf8(), 9);
|
|
|
|
quint32 compressedSize = compressedData.size();
|
|
|
|
uInt32ToCharLE(&compressedSize, uInt32Buffer);
|
|
|
|
ioDevice->write(uInt32Buffer, 4);
|
|
|
|
ioDevice->write(compressedData);
|
|
|
|
|
|
|
|
uInt32ToCharLE(&p_headerSum, uInt32Buffer);
|
|
|
|
ioDevice->write(uInt32Buffer, 4);
|
|
|
|
|
|
|
|
uInt32ToCharLE(&p_photoBuffer, uInt32Buffer);
|
|
|
|
ioDevice->write(uInt32Buffer, 4);
|
|
|
|
|
|
|
|
compressedData = qCompress(p_photoData, 9);
|
|
|
|
compressedSize = compressedData.size();
|
|
|
|
uInt32ToCharLE(&compressedSize, uInt32Buffer);
|
|
|
|
ioDevice->write(uInt32Buffer, 4);
|
|
|
|
ioDevice->write(compressedData);
|
|
|
|
|
|
|
|
uInt32ToCharLE(&p_jsonOffset, uInt32Buffer);
|
|
|
|
ioDevice->write(uInt32Buffer, 4);
|
|
|
|
|
|
|
|
uInt32ToCharLE(&p_jsonBuffer, uInt32Buffer);
|
|
|
|
ioDevice->write(uInt32Buffer, 4);
|
|
|
|
|
|
|
|
compressedData = qCompress(p_jsonData, 9);
|
|
|
|
compressedSize = compressedData.size();
|
|
|
|
uInt32ToCharLE(&compressedSize, uInt32Buffer);
|
|
|
|
ioDevice->write(uInt32Buffer, 4);
|
|
|
|
ioDevice->write(compressedData);
|
|
|
|
|
|
|
|
uInt32ToCharLE(&p_titlOffset, uInt32Buffer);
|
|
|
|
ioDevice->write(uInt32Buffer, 4);
|
|
|
|
|
|
|
|
uInt32ToCharLE(&p_titlBuffer, uInt32Buffer);
|
|
|
|
ioDevice->write(uInt32Buffer, 4);
|
|
|
|
|
|
|
|
compressedData = qCompress(p_titleString.toUtf8(), 9);
|
|
|
|
compressedSize = compressedData.size();
|
|
|
|
uInt32ToCharLE(&compressedSize, uInt32Buffer);
|
|
|
|
ioDevice->write(uInt32Buffer, 4);
|
|
|
|
ioDevice->write(compressedData);
|
|
|
|
|
|
|
|
uInt32ToCharLE(&p_descOffset, uInt32Buffer);
|
|
|
|
ioDevice->write(uInt32Buffer, 4);
|
|
|
|
|
|
|
|
uInt32ToCharLE(&p_descBuffer, uInt32Buffer);
|
|
|
|
ioDevice->write(uInt32Buffer, 4);
|
|
|
|
|
|
|
|
compressedData = qCompress(p_descriptionString.toUtf8(), 9);
|
|
|
|
compressedSize = compressedData.size();
|
|
|
|
uInt32ToCharLE(&compressedSize, uInt32Buffer);
|
|
|
|
ioDevice->write(uInt32Buffer, 4);
|
|
|
|
ioDevice->write(compressedData);
|
|
|
|
|
|
|
|
uInt32ToCharLE(&p_endOfFile, uInt32Buffer);
|
|
|
|
ioDevice->write(uInt32Buffer, 4);
|
|
|
|
|
2020-11-11 19:43:54 +01:00
|
|
|
#if QT_VERSION >= 0x050000
|
2020-11-11 07:04:39 +01:00
|
|
|
ioDevice->aboutToClose();
|
2020-11-11 19:43:54 +01:00
|
|
|
#endif
|
2020-11-11 07:04:39 +01:00
|
|
|
}
|
|
|
|
else if (photoFormat == PhotoFormat::GTA5) {
|
|
|
|
char uInt32Buffer[4];
|
|
|
|
quint32 format = static_cast<quint32>(PhotoFormat::GTA5);
|
|
|
|
uInt32ToCharLE(&format, uInt32Buffer);
|
|
|
|
ioDevice->write(uInt32Buffer, 4);
|
2020-11-09 03:43:46 +01:00
|
|
|
|
2020-11-11 17:58:15 +01:00
|
|
|
QByteArray photoHeader = stringToUtf16LE(p_photoString);
|
2020-11-09 03:43:46 +01:00
|
|
|
if (photoHeader.left(2) == "\xFF\xFE") {
|
|
|
|
photoHeader.remove(0, 2);
|
|
|
|
}
|
|
|
|
qint64 photoHeaderSize = photoHeader.size();
|
|
|
|
if (photoHeaderSize > 256) {
|
|
|
|
photoHeader = photoHeader.left(256);
|
|
|
|
photoHeaderSize = 256;
|
|
|
|
}
|
|
|
|
ioDevice->write(photoHeader);
|
|
|
|
for (qint64 size = photoHeaderSize; size < 256; size++) {
|
|
|
|
ioDevice->write("\x00", 1);
|
|
|
|
}
|
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
uInt32ToCharLE(&p_headerSum, uInt32Buffer);
|
|
|
|
ioDevice->write(uInt32Buffer, 4);
|
2020-11-09 03:43:46 +01:00
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
uInt32ToCharLE(&p_endOfFile, uInt32Buffer);
|
|
|
|
ioDevice->write(uInt32Buffer, 4);
|
2020-11-09 03:43:46 +01:00
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
uInt32ToCharLE(&p_jsonOffset, uInt32Buffer);
|
|
|
|
ioDevice->write(uInt32Buffer, 4);
|
2020-11-09 03:43:46 +01:00
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
uInt32ToCharLE(&p_titlOffset, uInt32Buffer);
|
|
|
|
ioDevice->write(uInt32Buffer, 4);
|
2020-11-09 03:43:46 +01:00
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
uInt32ToCharLE(&p_descOffset, uInt32Buffer);
|
|
|
|
ioDevice->write(uInt32Buffer, 4);
|
2020-11-09 03:43:46 +01:00
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
ioDevice->write("JPEG", 4);
|
2020-11-09 03:43:46 +01:00
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
uInt32ToCharLE(&p_photoBuffer, uInt32Buffer);
|
|
|
|
ioDevice->write(uInt32Buffer, 4);
|
2020-11-09 03:43:46 +01:00
|
|
|
|
|
|
|
quint32 t_photoSize = p_photoData.size();
|
2020-11-11 07:04:39 +01:00
|
|
|
uInt32ToCharLE(&t_photoSize, uInt32Buffer);
|
|
|
|
ioDevice->write(uInt32Buffer, 4);
|
2020-11-09 03:43:46 +01:00
|
|
|
|
|
|
|
ioDevice->write(p_photoData);
|
2020-11-11 07:04:39 +01:00
|
|
|
for (qint64 size = t_photoSize; size < p_photoBuffer; size++) {
|
2020-11-09 03:43:46 +01:00
|
|
|
ioDevice->write("\x00", 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
ioDevice->seek(p_jsonOffset + 264);
|
2020-11-11 07:04:39 +01:00
|
|
|
ioDevice->write("JSON", 4);
|
2020-11-09 03:43:46 +01:00
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
uInt32ToCharLE(&p_jsonBuffer, uInt32Buffer);
|
|
|
|
ioDevice->write(uInt32Buffer, 4);
|
2020-11-09 03:43:46 +01:00
|
|
|
|
|
|
|
qint64 dataSize = p_jsonData.size();
|
|
|
|
ioDevice->write(p_jsonData);
|
2020-11-11 07:04:39 +01:00
|
|
|
for (qint64 size = dataSize; size < p_jsonBuffer; size++) {
|
2020-11-09 03:43:46 +01:00
|
|
|
ioDevice->write("\x00", 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
ioDevice->seek(p_titlOffset + 264);
|
2020-11-11 07:04:39 +01:00
|
|
|
ioDevice->write("TITL", 4);
|
2020-11-09 03:43:46 +01:00
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
uInt32ToCharLE(&p_titlBuffer, uInt32Buffer);
|
|
|
|
ioDevice->write(uInt32Buffer, 4);
|
2020-11-09 03:43:46 +01:00
|
|
|
|
|
|
|
QByteArray data = p_titleString.toUtf8();
|
|
|
|
dataSize = data.size();
|
|
|
|
ioDevice->write(data);
|
2020-11-11 07:04:39 +01:00
|
|
|
for (qint64 size = dataSize; size < p_titlBuffer; size++) {
|
2020-11-09 03:43:46 +01:00
|
|
|
ioDevice->write("\x00", 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
ioDevice->seek(p_descOffset + 264);
|
2020-11-11 07:04:39 +01:00
|
|
|
ioDevice->write("DESC", 4);
|
2020-11-09 03:43:46 +01:00
|
|
|
|
2020-11-11 07:04:39 +01:00
|
|
|
uInt32ToCharLE(&p_descBuffer, uInt32Buffer);
|
|
|
|
ioDevice->write(uInt32Buffer, 4);
|
2020-11-09 03:43:46 +01:00
|
|
|
|
|
|
|
data = p_descriptionString.toUtf8();
|
|
|
|
dataSize = data.size();
|
|
|
|
ioDevice->write(data);
|
2020-11-11 07:04:39 +01:00
|
|
|
for (qint64 size = dataSize; size < p_descBuffer; size++) {
|
2020-11-09 03:43:46 +01:00
|
|
|
ioDevice->write("\x00", 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
ioDevice->seek(p_endOfFile + 260);
|
2020-11-11 07:04:39 +01:00
|
|
|
ioDevice->write("JEND", 4);
|
2020-11-11 19:43:54 +01:00
|
|
|
|
|
|
|
#if QT_VERSION >= 0x050000
|
2020-11-09 03:43:46 +01:00
|
|
|
ioDevice->aboutToClose();
|
2020-11-11 19:43:54 +01:00
|
|
|
#endif
|
2020-11-09 03:43:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-08 03:50:06 +01:00
|
|
|
RagePhoto* RagePhoto::loadFile(const QString &filePath)
|
|
|
|
{
|
|
|
|
RagePhoto *ragePhoto = new RagePhoto(filePath);
|
|
|
|
ragePhoto->load();
|
|
|
|
return ragePhoto;
|
|
|
|
}
|
|
|
|
|
2020-11-08 18:05:44 +01:00
|
|
|
quint32 RagePhoto::charToUInt32BE(char *x)
|
|
|
|
{
|
2020-11-12 00:24:21 +01:00
|
|
|
return (static_cast<unsigned char>(x[0]) << 24 |
|
|
|
|
static_cast<unsigned char>(x[1]) << 16 |
|
|
|
|
static_cast<unsigned char>(x[2]) << 8 |
|
|
|
|
static_cast<unsigned char>(x[3]));
|
2020-11-08 18:05:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
quint32 RagePhoto::charToUInt32LE(char *x)
|
2020-11-08 03:50:06 +01:00
|
|
|
{
|
2020-11-12 00:24:21 +01:00
|
|
|
return (static_cast<unsigned char>(x[3]) << 24 |
|
|
|
|
static_cast<unsigned char>(x[2]) << 16 |
|
|
|
|
static_cast<unsigned char>(x[1]) << 8 |
|
|
|
|
static_cast<unsigned char>(x[0]));
|
2020-11-08 03:50:06 +01:00
|
|
|
}
|
2020-11-08 20:53:43 +01:00
|
|
|
|
|
|
|
void RagePhoto::uInt32ToCharBE(quint32 *x, char *y)
|
|
|
|
{
|
|
|
|
y[0] = (*x >> 24) & 0xFF;
|
|
|
|
y[1] = (*x >> 16) & 0xFF;
|
|
|
|
y[2] = (*x >> 8) & 0xFF;
|
|
|
|
y[3] = (*x) & 0xFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RagePhoto::uInt32ToCharLE(quint32 *x, char *y)
|
|
|
|
{
|
|
|
|
y[0] = (*x) & 0xFF;
|
|
|
|
y[1] = (*x >> 8) & 0xFF;
|
|
|
|
y[2] = (*x >> 16) & 0xFF;
|
|
|
|
y[3] = (*x >> 24) & 0xFF;
|
|
|
|
}
|
2020-11-11 17:58:15 +01:00
|
|
|
|
|
|
|
QByteArray RagePhoto::stringToUtf16LE(const QString &string)
|
|
|
|
{
|
|
|
|
#if QT_VERSION >= 0x060000
|
|
|
|
QStringEncoder stringEncoder = QStringEncoder(QStringEncoder::Utf16LE);
|
|
|
|
return stringEncoder(string);
|
|
|
|
#else
|
|
|
|
return QTextCodec::codecForName("UTF-16LE")->fromUnicode(string);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
QString RagePhoto::utf16LEToString(const QByteArray &data)
|
|
|
|
{
|
|
|
|
#if QT_VERSION >= 0x060000
|
|
|
|
QStringDecoder stringDecoder = QStringDecoder(QStringDecoder::Utf16LE);
|
|
|
|
return stringDecoder(data);
|
|
|
|
#else
|
|
|
|
return QTextCodec::codecForName("UTF-16LE")->toUnicode(data);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
QString RagePhoto::utf16LEToString(const char *data, int size)
|
|
|
|
{
|
|
|
|
#if QT_VERSION >= 0x060000
|
|
|
|
QStringDecoder stringDecoder = QStringDecoder(QStringDecoder::Utf16LE);
|
|
|
|
return stringDecoder(QByteArray::fromRawData(data, size));
|
|
|
|
#else
|
|
|
|
return QTextCodec::codecForName("UTF-16LE")->toUnicode(data, size);
|
|
|
|
#endif
|
|
|
|
}
|