RAM usage reduced (tested 107 pics 220MB to 68MB)
This commit is contained in:
parent
5af3dabcb8
commit
3be2e49d5c
4 changed files with 128 additions and 22 deletions
|
@ -105,6 +105,5 @@ void PictureWidget::updateWindowSize(int screenID)
|
||||||
this->resize(desktopRect.width(), desktopRect.height());
|
this->resize(desktopRect.width(), desktopRect.height());
|
||||||
this->showFullScreen();
|
this->showFullScreen();
|
||||||
pictureLabel->setPixmap(QPixmap::fromImage(image.scaled(desktopRect.width(), desktopRect.height(), Qt::KeepAspectRatio, Qt::SmoothTransformation)));
|
pictureLabel->setPixmap(QPixmap::fromImage(image.scaled(desktopRect.width(), desktopRect.height(), Qt::KeepAspectRatio, Qt::SmoothTransformation)));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,15 +67,25 @@ SnapmaticPicture::SnapmaticPicture(const QString &fileName, QObject *parent) : Q
|
||||||
jsonArea = "";
|
jsonArea = "";
|
||||||
jsonCreatedTimestamp = 0;
|
jsonCreatedTimestamp = 0;
|
||||||
jsonPlyrsList = QStringList();
|
jsonPlyrsList = QStringList();
|
||||||
|
jsonMeme = 0;
|
||||||
|
jsonMug = 0;
|
||||||
|
jsonSelfie = 0;
|
||||||
|
jsonDirector = 0;
|
||||||
|
jsonRockstarEditor = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SnapmaticPicture::readingPicture(bool writeEnabled_)
|
SnapmaticPicture::~SnapmaticPicture()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SnapmaticPicture::readingPicture(bool writeEnabled_, bool cacheEnabled_)
|
||||||
{
|
{
|
||||||
// Start opening file
|
// Start opening file
|
||||||
// lastStep is like currentStep
|
// lastStep is like currentStep
|
||||||
|
|
||||||
// Set boolean values
|
// Set boolean values
|
||||||
writeEnabled = writeEnabled_;
|
writeEnabled = writeEnabled_;
|
||||||
|
cacheEnabled = cacheEnabled_;
|
||||||
|
|
||||||
QFile *picFile = new QFile(picFileName);
|
QFile *picFile = new QFile(picFileName);
|
||||||
QIODevice *picStream;
|
QIODevice *picStream;
|
||||||
|
@ -88,6 +98,9 @@ bool SnapmaticPicture::readingPicture(bool writeEnabled_)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
rawPicContent = picFile->read(snapmaticFileMaxSize);
|
rawPicContent = picFile->read(snapmaticFileMaxSize);
|
||||||
|
picFile->close();
|
||||||
|
delete picFile;
|
||||||
|
|
||||||
picStream = new QBuffer(&rawPicContent);
|
picStream = new QBuffer(&rawPicContent);
|
||||||
picStream->open(QIODevice::ReadWrite);
|
picStream->open(QIODevice::ReadWrite);
|
||||||
|
|
||||||
|
@ -97,7 +110,7 @@ bool SnapmaticPicture::readingPicture(bool writeEnabled_)
|
||||||
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",1,NOHEADER";
|
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",1,NOHEADER";
|
||||||
picStream->close();
|
picStream->close();
|
||||||
picStream->deleteLater();
|
picStream->deleteLater();
|
||||||
delete picFile;
|
delete picStream;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
QByteArray snapmaticHeaderLine = picStream->read(snapmaticHeaderLength);
|
QByteArray snapmaticHeaderLine = picStream->read(snapmaticHeaderLength);
|
||||||
|
@ -109,7 +122,7 @@ bool SnapmaticPicture::readingPicture(bool writeEnabled_)
|
||||||
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",2,NOHEADER";
|
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",2,NOHEADER";
|
||||||
picStream->close();
|
picStream->close();
|
||||||
picStream->deleteLater();
|
picStream->deleteLater();
|
||||||
delete picFile;
|
delete picStream;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
QByteArray jpegHeaderLine = picStream->read(jpegPreHeaderLength);
|
QByteArray jpegHeaderLine = picStream->read(jpegPreHeaderLength);
|
||||||
|
@ -121,7 +134,7 @@ bool SnapmaticPicture::readingPicture(bool writeEnabled_)
|
||||||
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",2,NOJPEG";
|
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",2,NOJPEG";
|
||||||
picStream->close();
|
picStream->close();
|
||||||
picStream->deleteLater();
|
picStream->deleteLater();
|
||||||
delete picFile;
|
delete picStream;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,11 +144,16 @@ bool SnapmaticPicture::readingPicture(bool writeEnabled_)
|
||||||
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",2,NOPIC";
|
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",2,NOPIC";
|
||||||
picStream->close();
|
picStream->close();
|
||||||
picStream->deleteLater();
|
picStream->deleteLater();
|
||||||
delete picFile;
|
delete picStream;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
QByteArray jpegRawContent = picStream->read(jpegPicStreamLength);
|
QByteArray jpegRawContent = picStream->read(jpegPicStreamLength);
|
||||||
picOk = cachePicture.loadFromData(jpegRawContent, "JPEG");
|
if (cacheEnabled) picOk = cachePicture.loadFromData(jpegRawContent, "JPEG");
|
||||||
|
if (!cacheEnabled)
|
||||||
|
{
|
||||||
|
QImage tempPicture;
|
||||||
|
picOk = tempPicture.loadFromData(jpegRawContent, "JPEG");
|
||||||
|
}
|
||||||
|
|
||||||
// Read JSON Stream
|
// Read JSON Stream
|
||||||
if (!picStream->isReadable())
|
if (!picStream->isReadable())
|
||||||
|
@ -143,7 +161,7 @@ bool SnapmaticPicture::readingPicture(bool writeEnabled_)
|
||||||
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",3,NOJSON";
|
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",3,NOJSON";
|
||||||
picStream->close();
|
picStream->close();
|
||||||
picStream->deleteLater();
|
picStream->deleteLater();
|
||||||
delete picFile;
|
delete picStream;
|
||||||
return picOk;
|
return picOk;
|
||||||
}
|
}
|
||||||
else if (picStream->read(4) != "JSON")
|
else if (picStream->read(4) != "JSON")
|
||||||
|
@ -151,7 +169,7 @@ bool SnapmaticPicture::readingPicture(bool writeEnabled_)
|
||||||
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",3,CTJSON";
|
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",3,CTJSON";
|
||||||
picStream->close();
|
picStream->close();
|
||||||
picStream->deleteLater();
|
picStream->deleteLater();
|
||||||
delete picFile;
|
delete picStream;
|
||||||
return picOk;
|
return picOk;
|
||||||
}
|
}
|
||||||
QByteArray jsonRawContent = picStream->read(jsonStreamLength);
|
QByteArray jsonRawContent = picStream->read(jsonStreamLength);
|
||||||
|
@ -163,7 +181,7 @@ bool SnapmaticPicture::readingPicture(bool writeEnabled_)
|
||||||
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",4,NOTITL";
|
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",4,NOTITL";
|
||||||
picStream->close();
|
picStream->close();
|
||||||
picStream->deleteLater();
|
picStream->deleteLater();
|
||||||
delete picFile;
|
delete picStream;
|
||||||
return picOk;
|
return picOk;
|
||||||
}
|
}
|
||||||
else if (picStream->read(4) != "TITL")
|
else if (picStream->read(4) != "TITL")
|
||||||
|
@ -171,7 +189,7 @@ bool SnapmaticPicture::readingPicture(bool writeEnabled_)
|
||||||
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",4,CTTITL";
|
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",4,CTTITL";
|
||||||
picStream->close();
|
picStream->close();
|
||||||
picStream->deleteLater();
|
picStream->deleteLater();
|
||||||
delete picFile;
|
delete picStream;
|
||||||
return picOk;
|
return picOk;
|
||||||
}
|
}
|
||||||
QByteArray titlRawContent = picStream->read(tideStreamLength);
|
QByteArray titlRawContent = picStream->read(tideStreamLength);
|
||||||
|
@ -182,7 +200,7 @@ bool SnapmaticPicture::readingPicture(bool writeEnabled_)
|
||||||
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",5,NODESC";
|
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",5,NODESC";
|
||||||
picStream->close();
|
picStream->close();
|
||||||
picStream->deleteLater();
|
picStream->deleteLater();
|
||||||
delete picFile;
|
delete picStream;
|
||||||
return picOk;
|
return picOk;
|
||||||
}
|
}
|
||||||
else if (picStream->read(4) != "DESC")
|
else if (picStream->read(4) != "DESC")
|
||||||
|
@ -190,7 +208,7 @@ bool SnapmaticPicture::readingPicture(bool writeEnabled_)
|
||||||
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",5,CTDESC";
|
lastStep = "2;/3,ReadingFile," + StringParser::convertDrawStringForLog(picFileName) + ",5,CTDESC";
|
||||||
picStream->close();
|
picStream->close();
|
||||||
picStream->deleteLater();
|
picStream->deleteLater();
|
||||||
delete picFile;
|
delete picStream;
|
||||||
return picOk;
|
return picOk;
|
||||||
}
|
}
|
||||||
QByteArray descRawContent = picStream->read(tideStreamLength);
|
QByteArray descRawContent = picStream->read(tideStreamLength);
|
||||||
|
@ -200,9 +218,7 @@ bool SnapmaticPicture::readingPicture(bool writeEnabled_)
|
||||||
|
|
||||||
picStream->close();
|
picStream->close();
|
||||||
picStream->deleteLater();
|
picStream->deleteLater();
|
||||||
picFile->deleteLater();
|
|
||||||
delete picStream;
|
delete picStream;
|
||||||
delete picFile;
|
|
||||||
if (!writeEnabled) { rawPicContent.clear(); }
|
if (!writeEnabled) { rawPicContent.clear(); }
|
||||||
return picOk;
|
return picOk;
|
||||||
}
|
}
|
||||||
|
@ -271,12 +287,12 @@ void SnapmaticPicture::parseSnapmaticExportAndSortString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SnapmaticPicture::readingPictureFromFile(const QString &fileName, bool writeEnabled_)
|
bool SnapmaticPicture::readingPictureFromFile(const QString &fileName, bool writeEnabled_, bool cacheEnabled_)
|
||||||
{
|
{
|
||||||
if (fileName != "")
|
if (fileName != "")
|
||||||
{
|
{
|
||||||
picFileName = fileName;
|
picFileName = fileName;
|
||||||
return readingPicture(writeEnabled_);
|
return readingPicture(writeEnabled_, cacheEnabled_);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -384,7 +400,63 @@ QString SnapmaticPicture::getLastStep()
|
||||||
|
|
||||||
QImage SnapmaticPicture::getPicture()
|
QImage SnapmaticPicture::getPicture()
|
||||||
{
|
{
|
||||||
return cachePicture;
|
if (cacheEnabled)
|
||||||
|
{
|
||||||
|
return cachePicture;
|
||||||
|
}
|
||||||
|
else if (writeEnabled)
|
||||||
|
{
|
||||||
|
bool returnOk;
|
||||||
|
QImage returnPicture;
|
||||||
|
|
||||||
|
QBuffer snapmaticStream(&rawPicContent);
|
||||||
|
snapmaticStream.open(QIODevice::ReadOnly);
|
||||||
|
if (snapmaticStream.seek(jpegStreamEditorBegin))
|
||||||
|
{
|
||||||
|
QByteArray jpegRawContent = snapmaticStream.read(jpegPicStreamLength);
|
||||||
|
returnOk = returnPicture.loadFromData(jpegRawContent, "JPEG");
|
||||||
|
}
|
||||||
|
snapmaticStream.close();
|
||||||
|
|
||||||
|
if (returnOk)
|
||||||
|
{
|
||||||
|
return returnPicture;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bool returnOk;
|
||||||
|
QImage returnPicture;
|
||||||
|
QIODevice *picStream;
|
||||||
|
|
||||||
|
QFile *picFile = new QFile(picFileName);
|
||||||
|
if (!picFile->open(QFile::ReadOnly))
|
||||||
|
{
|
||||||
|
lastStep = "1;/1,OpenFile," + StringParser::convertDrawStringForLog(picFileName);
|
||||||
|
picFile->deleteLater();
|
||||||
|
delete picFile;
|
||||||
|
return QImage(0, 0, QImage::Format_RGB32);
|
||||||
|
}
|
||||||
|
rawPicContent = picFile->read(snapmaticFileMaxSize);
|
||||||
|
picFile->close();
|
||||||
|
delete picFile;
|
||||||
|
|
||||||
|
picStream = new QBuffer(&rawPicContent);
|
||||||
|
picStream->open(QIODevice::ReadWrite);
|
||||||
|
if (picStream->seek(jpegStreamEditorBegin))
|
||||||
|
{
|
||||||
|
QByteArray jpegRawContent = picStream->read(jpegPicStreamLength);
|
||||||
|
returnOk = returnPicture.loadFromData(jpegRawContent, "JPEG");
|
||||||
|
}
|
||||||
|
picStream->close();
|
||||||
|
delete picStream;
|
||||||
|
|
||||||
|
if (returnOk)
|
||||||
|
{
|
||||||
|
return returnPicture;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return QImage(0, 0, QImage::Format_RGB32);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SnapmaticPicture::isPicOk()
|
bool SnapmaticPicture::isPicOk()
|
||||||
|
@ -397,6 +469,12 @@ void SnapmaticPicture::setPicFileName(QString picFileName_)
|
||||||
picFileName = picFileName_;
|
picFileName = picFileName_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SnapmaticPicture::clearCache()
|
||||||
|
{
|
||||||
|
cacheEnabled = false;
|
||||||
|
cachePicture = QImage(0, 0, QImage::Format_RGB32);
|
||||||
|
}
|
||||||
|
|
||||||
// JSON part
|
// JSON part
|
||||||
|
|
||||||
void SnapmaticPicture::parseJsonContent()
|
void SnapmaticPicture::parseJsonContent()
|
||||||
|
@ -432,6 +510,26 @@ void SnapmaticPicture::parseJsonContent()
|
||||||
{
|
{
|
||||||
jsonPlyrsList = jsonMap["plyrs"].toStringList();
|
jsonPlyrsList = jsonMap["plyrs"].toStringList();
|
||||||
}
|
}
|
||||||
|
if (jsonMap.contains("meme"))
|
||||||
|
{
|
||||||
|
jsonMeme = jsonMap["meme"].toBool();
|
||||||
|
}
|
||||||
|
if (jsonMap.contains("mug"))
|
||||||
|
{
|
||||||
|
jsonMug = jsonMap["mug"].toBool();
|
||||||
|
}
|
||||||
|
if (jsonMap.contains("slf"))
|
||||||
|
{
|
||||||
|
jsonSelfie = jsonMap["slf"].toBool();
|
||||||
|
}
|
||||||
|
if (jsonMap.contains("drctr"))
|
||||||
|
{
|
||||||
|
jsonDirector = jsonMap["drctr"].toBool();
|
||||||
|
}
|
||||||
|
if (jsonMap.contains("rsedtr"))
|
||||||
|
{
|
||||||
|
jsonRockstarEditor = jsonMap["rsedtr"].toBool();
|
||||||
|
}
|
||||||
|
|
||||||
jsonOk = true;
|
jsonOk = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,9 +31,11 @@ class SnapmaticPicture : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit SnapmaticPicture(const QString &fileName = "", QObject *parent = 0);
|
explicit SnapmaticPicture(const QString &fileName = "", QObject *parent = 0);
|
||||||
bool readingPictureFromFile(const QString &fileName, bool writeEnabled = false);
|
~SnapmaticPicture();
|
||||||
bool readingPicture(bool writeEnabled = false);
|
bool readingPictureFromFile(const QString &fileName, bool writeEnabled = true, bool cacheEnabled = true);
|
||||||
|
bool readingPicture(bool writeEnabled = true, bool cacheEnabled = true);
|
||||||
bool isPicOk();
|
bool isPicOk();
|
||||||
|
void clearCache();
|
||||||
QImage getPicture();
|
QImage getPicture();
|
||||||
QString getLastStep();
|
QString getLastStep();
|
||||||
QString getPictureStr();
|
QString getPictureStr();
|
||||||
|
@ -77,6 +79,7 @@ private:
|
||||||
QString descStr;
|
QString descStr;
|
||||||
bool picOk;
|
bool picOk;
|
||||||
bool writeEnabled;
|
bool writeEnabled;
|
||||||
|
bool cacheEnabled;
|
||||||
|
|
||||||
// PARSE INT
|
// PARSE INT
|
||||||
int snapmaticHeaderLength;
|
int snapmaticHeaderLength;
|
||||||
|
@ -106,6 +109,11 @@ private:
|
||||||
QStringList jsonPlyrsList;
|
QStringList jsonPlyrsList;
|
||||||
uint jsonCreatedTimestamp;
|
uint jsonCreatedTimestamp;
|
||||||
QDateTime jsonCreatedDateTime;
|
QDateTime jsonCreatedDateTime;
|
||||||
|
bool jsonMeme;
|
||||||
|
bool jsonMug;
|
||||||
|
bool jsonSelfie;
|
||||||
|
bool jsonDirector;
|
||||||
|
bool jsonRockstarEditor;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
|
|
|
@ -86,11 +86,12 @@ void SnapmaticWidget::setSnapmaticPicture(SnapmaticPicture *picture, QString pic
|
||||||
picStr = picture->getPictureStr();
|
picStr = picture->getPictureStr();
|
||||||
picTitl = picture->getPictureTitl();
|
picTitl = picture->getPictureTitl();
|
||||||
|
|
||||||
QPixmap SnapmaticPixmap = QPixmap::fromImage(picture->getPicture(), Qt::AutoColor);
|
QPixmap SnapmaticPixmap = QPixmap::fromImage(picture->getPicture().scaled(ui->labPicture->width(), ui->labPicture->height(), Qt::KeepAspectRatio, Qt::SmoothTransformation), Qt::AutoColor);
|
||||||
SnapmaticPixmap.scaled(ui->labPicture->width(), ui->labPicture->height(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
|
||||||
ui->labPicStr->setText(picStr + "\n" + picTitl + "");
|
ui->labPicStr->setText(picStr + "\n" + picTitl + "");
|
||||||
ui->labPicture->setPixmap(SnapmaticPixmap);
|
ui->labPicture->setPixmap(SnapmaticPixmap);
|
||||||
|
|
||||||
|
picture->clearCache();
|
||||||
|
|
||||||
adjustTextColor();
|
adjustTextColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue