Added missing image handler

This commit is contained in:
CURTLab 2020-07-30 03:05:25 +02:00
parent 654a4e7ee9
commit 3cdc9bb906
3 changed files with 23 additions and 2 deletions

View File

@ -48,11 +48,19 @@ LVGLImageData::LVGLImageData(QImage image, QString fileName, QString name)
}
LVGLImageData::LVGLImageData(QString fileName, QString name)
: m_name(name)
: m_size(0)
, m_data(nullptr)
, m_name(name)
, m_fileName(fileName)
, m_colorFormat(LV_COLOR_24Bit)
{
if (!QFile(fileName).exists())
return;
memset(&m_img_dsc, 0, sizeof(m_img_dsc));
QImage img = QImage(fileName).convertToFormat(QImage::Format_ARGB32);
m_size = static_cast<uint32_t>(img.width()*img.height()*4);
m_data = new uint8_t[m_size];
@ -96,6 +104,11 @@ LVGLImageData::~LVGLImageData()
delete [] m_data;
}
bool LVGLImageData::isValid()
{
return (m_size > 0) && (m_data != nullptr) && (m_img_dsc.header.w > 0) && (m_img_dsc.header.h > 0);
}
lv_img_dsc_t *LVGLImageData::img_des()
{
return &m_img_dsc;

View File

@ -22,6 +22,8 @@ public:
LV_COLOR_32Bit
};
bool isValid();
lv_img_dsc_t *img_des();
QString name() const;

View File

@ -6,6 +6,7 @@
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QMessageBox>
#include "LVGLCore.h"
#include "LVGLObject.h"
@ -60,7 +61,12 @@ LVGLProject *LVGLProject::load(const QString &fileName)
QJsonArray imageArr = doc["images"].toArray();
for (int i = 0; i < imageArr.size(); ++i) {
LVGLImageData *img = new LVGLImageData(imageArr[i].toObject());
lvgl.addImage(img);
if (img->isValid()) {
lvgl.addImage(img);
} else {
QMessageBox::critical(nullptr, "Error", QString("Could not load image (%1)").arg(img->fileName()));
delete img;
}
}
QJsonArray fontArr = doc["fonts"].toArray();