SnapmaticPicture: wrap getContentMaxLength
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Syping 2020-11-09 01:42:11 +01:00
parent 18083a3b0f
commit 2bb3f7f62d
6 changed files with 29 additions and 21 deletions

View File

@ -607,7 +607,7 @@ bool ProfileInterface::importFile(QString selectedFile, QDateTime importDateTime
if ((selectedFileName.left(4) == "PGTA" && !selectedFileName.contains('.')) || selectedFileName.right(4) == ".g5e") if ((selectedFileName.left(4) == "PGTA" && !selectedFileName.contains('.')) || selectedFileName.right(4) == ".g5e")
{ {
SnapmaticPicture *picture = new SnapmaticPicture(selectedFile); SnapmaticPicture *picture = new SnapmaticPicture(selectedFile);
if (picture->readingPicture(true, true, true)) if (picture->readingPicture(true))
{ {
bool success = importSnapmaticPicture(picture, notMultiple); bool success = importSnapmaticPicture(picture, notMultiple);
if (!success) delete picture; if (!success) delete picture;
@ -678,7 +678,7 @@ bool ProfileInterface::importFile(QString selectedFile, QDateTime importDateTime
else if (isSupportedImageFile(selectedFileName)) else if (isSupportedImageFile(selectedFileName))
{ {
SnapmaticPicture *picture = new SnapmaticPicture(":/template/template.g5e"); SnapmaticPicture *picture = new SnapmaticPicture(":/template/template.g5e");
if (picture->readingPicture(true, false, true, false)) if (picture->readingPicture(false))
{ {
if (!notMultiple) if (!notMultiple)
{ {
@ -1048,7 +1048,7 @@ bool ProfileInterface::importRemote(QUrl remoteUrl)
bool ProfileInterface::importImage(QImage *snapmaticImage, QDateTime importDateTime) bool ProfileInterface::importImage(QImage *snapmaticImage, QDateTime importDateTime)
{ {
SnapmaticPicture *picture = new SnapmaticPicture(":/template/template.g5e"); SnapmaticPicture *picture = new SnapmaticPicture(":/template/template.g5e");
if (picture->readingPicture(true, false, true, false)) if (picture->readingPicture(false))
{ {
bool success = false; bool success = false;
ImportDialog *importDialog = new ImportDialog(profileName, this); ImportDialog *importDialog = new ImportDialog(profileName, this);

View File

@ -76,7 +76,7 @@ void ProfileLoader::run()
emit loadingProgress(curFile, maximumV); emit loadingProgress(curFile, maximumV);
QString picturePath = profileFolder % "/" % SnapmaticPic; QString picturePath = profileFolder % "/" % SnapmaticPic;
SnapmaticPicture *picture = new SnapmaticPicture(picturePath); SnapmaticPicture *picture = new SnapmaticPicture(picturePath);
if (picture->readingPicture(true, true, true)) if (picture->readingPicture(true))
{ {
if (picture->isFormatSwitched()) if (picture->isFormatSwitched())
{ {

View File

@ -135,13 +135,13 @@ bool RagePhoto::load()
size = dataBuffer.read(photoSize, 4); size = dataBuffer.read(photoSize, 4);
if (size != 4) if (size != 4)
return false; return false;
p_photoSize = charToUInt32LE(photoSize); quint32 t_photoSize = charToUInt32LE(photoSize);
char photoData[p_photoSize]; char photoData[t_photoSize];
size = dataBuffer.read(photoData, p_photoSize); size = dataBuffer.read(photoData, t_photoSize);
if (size != p_photoSize) if (size != t_photoSize)
return false; return false;
p_photoData = QByteArray(photoData, p_photoSize); p_photoData = QByteArray(photoData, t_photoSize);
dataBuffer.seek(p_jsonOffset + 264); dataBuffer.seek(p_jsonOffset + 264);
char jsonMarker[4]; char jsonMarker[4];
@ -279,7 +279,6 @@ bool RagePhoto::load()
return false; return false;
QByteArray t_photoData = QByteArray::fromRawData(compressedPhoto, i_photoSize); QByteArray t_photoData = QByteArray::fromRawData(compressedPhoto, i_photoSize);
p_photoData = qUncompress(t_photoData); p_photoData = qUncompress(t_photoData);
p_photoSize = p_photoData.size();
char jsonOffset[4]; char jsonOffset[4];
size = dataBuffer.read(jsonOffset, 4); size = dataBuffer.read(jsonOffset, 4);
@ -419,7 +418,8 @@ bool RagePhoto::setJsonData(const QByteArray &data)
bool RagePhoto::setPhotoData(const QByteArray &data) bool RagePhoto::setPhotoData(const QByteArray &data)
{ {
if ((quint32)data.size() > p_photoSize) quint32 size = data.size();
if (size > p_jpegBuffer)
return false; return false;
p_photoData = data; p_photoData = data;
return true; return true;
@ -427,7 +427,7 @@ bool RagePhoto::setPhotoData(const QByteArray &data)
bool RagePhoto::setPhotoData(const char *data, int size) bool RagePhoto::setPhotoData(const char *data, int size)
{ {
if ((quint32)size > p_photoSize) if ((quint32)size > p_jpegBuffer)
return false; return false;
p_photoData = QByteArray(data, size); p_photoData = QByteArray(data, size);
return true; return true;
@ -478,6 +478,11 @@ quint32 RagePhoto::photoBuffer()
return p_jpegBuffer; return p_jpegBuffer;
} }
quint32 RagePhoto::photoSize()
{
return p_photoData.size();
}
RagePhoto::PhotoFormat RagePhoto::photoFormat() RagePhoto::PhotoFormat RagePhoto::photoFormat()
{ {
return p_photoFormat; return p_photoFormat;

View File

@ -62,6 +62,7 @@ public:
const QString photoString(); const QString photoString();
const QString title(); const QString title();
quint32 photoBuffer(); quint32 photoBuffer();
quint32 photoSize();
PhotoFormat photoFormat(); PhotoFormat photoFormat();
static RagePhoto* loadFile(const QString &filePath); static RagePhoto* loadFile(const QString &filePath);
@ -85,7 +86,6 @@ private:
quint32 p_headerSum; quint32 p_headerSum;
quint32 p_jpegBuffer; quint32 p_jpegBuffer;
quint32 p_jsonOffset; quint32 p_jsonOffset;
quint32 p_photoSize;
quint32 p_titlOffset; quint32 p_titlOffset;
bool p_isLoaded; bool p_isLoaded;
int p_inputMode; int p_inputMode;

View File

@ -112,11 +112,8 @@ bool SnapmaticPicture::preloadFile()
return ok; return ok;
} }
bool SnapmaticPicture::readingPicture(bool writeEnabled_, bool cacheEnabled_, bool fastLoad, bool lowRamMode_) bool SnapmaticPicture::readingPicture(bool cacheEnabled_)
{ {
Q_UNUSED(fastLoad)
Q_UNUSED(lowRamMode_)
Q_UNUSED(writeEnabled_)
// Start opening file // Start opening file
// lastStep is like currentStep // lastStep is like currentStep
@ -166,12 +163,12 @@ void SnapmaticPicture::updateStrings()
picExportFileName = exportStr % "_" % cmpPicTitl; picExportFileName = exportStr % "_" % cmpPicTitl;
} }
bool SnapmaticPicture::readingPictureFromFile(const QString &fileName, bool writeEnabled_, bool cacheEnabled_, bool fastLoad, bool lowRamMode_) bool SnapmaticPicture::readingPictureFromFile(const QString &fileName, bool cacheEnabled_)
{ {
if (!fileName.isEmpty()) if (!fileName.isEmpty())
{ {
picFilePath = fileName; picFilePath = fileName;
return readingPicture(writeEnabled_, cacheEnabled_, fastLoad, lowRamMode_); return readingPicture(cacheEnabled_);
} }
else else
{ {
@ -221,6 +218,11 @@ bool SnapmaticPicture::setPictureTitl(const QString &newTitle_)
return false; return false;
} }
int SnapmaticPicture::getContentMaxLength()
{
return ragePhoto.photoBuffer();
}
QString SnapmaticPicture::getExportPictureFileName() QString SnapmaticPicture::getExportPictureFileName()
{ {
return picExportFileName; return picExportFileName;

View File

@ -58,8 +58,8 @@ public:
~SnapmaticPicture(); ~SnapmaticPicture();
void reset(); void reset();
bool preloadFile(); bool preloadFile();
bool readingPictureFromFile(const QString &fileName, bool writeEnabled = true, bool cacheEnabled = false, bool fastLoad = true, bool lowRamMode = false); bool readingPictureFromFile(const QString &fileName, bool cacheEnabled = false);
bool readingPicture(bool writeEnabled = true, bool cacheEnabled = false, bool fastLoad = true, bool lowRamMode = false); bool readingPicture(bool cacheEnabled = false);
bool isPicOk(); // Please use isPictureOk instead bool isPicOk(); // Please use isPictureOk instead
void clearCache(); void clearCache();
QImage getImage(bool fastLoad = false); QImage getImage(bool fastLoad = false);
@ -73,6 +73,7 @@ public:
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);