18
19
m_output(new HalideImage(this)),
22
m_updateInProgress(false),
23
m_pendingUpdate(false),
24
m_pendingRequiresImage(false)
22
26
connect(m_functionsModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
23
27
this, SLOT(onFunctionsInserted(QModelIndex,int,int)));
33
37
m_worker = new HalideTransformCpu(this);
35
39
connect(m_worker, SIGNAL(updateRequired()), this, SLOT(scheduleUpdate()), Qt::QueuedConnection);
40
connect(m_worker, SIGNAL(computeFinished(QSharedPointer<HalideImageData>)),
41
this, SLOT(onWorkedComputeFinished(QSharedPointer<HalideImageData>)), Qt::QueuedConnection);
36
42
setupOpenGLContextMonitoring();
39
45
HalideTransform::~HalideTransform()
48
m_worker->deleteLater();
45
51
delete m_functionsModel;
232
QStringList functionsNames;
233
Q_FOREACH(HalideFunction* function, m_functionsModel->toList()) {
234
functionsNames.append(function->name());
238
if (!m_updateInProgress) {
239
m_updateFunctionNames.clear();
240
Q_FOREACH(HalideFunction* function, m_functionsModel->toList()) {
241
m_updateFunctionNames.append(function->name());
243
m_updateInProgress = true;
244
m_updateTimer.start();
245
Q_EMIT updatingChanged();
246
m_worker->compute(m_input, m_functionsModel->toList(), outputImageRequired);
248
m_pendingUpdate = true;
249
m_pendingRequiresImage = outputImageRequired;
237
m_updateTimer.start();
238
Q_EMIT updatingChanged();
239
m_worker->compute(m_input, m_functionsModel->toList(), m_output, outputImageRequired);
253
void HalideTransform::onWorkedComputeFinished(QSharedPointer<HalideImageData> result)
255
m_output->setData(result);
241
257
qDebug() << QString("\"%1\" applied in %2 ms (%3x%4)")
242
.arg(functionsNames.join(" + "))
258
.arg(m_updateFunctionNames.join(" + "))
243
259
.arg(m_updateTimer.elapsed())
244
260
.arg(m_output->size().width())
245
261
.arg(m_output->size().height()).toLocal8Bit().constData();
246
262
m_updateTimer.invalidate();
247
263
Q_EMIT updatingChanged();
264
m_updateInProgress = false;
266
if (!m_pendingSaveFiles.isEmpty()) {
267
QtConcurrent::run(this, &HalideTransform::saveImageToFiles, m_output->data()->image, m_pendingSaveFiles);
268
m_pendingSaveFiles.clear();
271
if (m_pendingUpdate) {
272
m_pendingUpdate = false;
273
m_pendingRequiresImage = false;
274
doUpdate(m_pendingRequiresImage);
250
278
bool HalideTransform::saveToFile(QString fileName)
253
280
QString directory = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
254
281
QString filePath = directory + "/" + fileName;
255
bool success = m_output->data()->image.save(filePath);
257
qWarning() << "Failed to save image to file:" << filePath;
283
if (fileName.isEmpty()) {
284
qWarning() << "Empty file name to passed to HalideTransform::saveToFile";
288
if (m_output->data()->image.isNull() || !m_live) {
289
m_pendingSaveFiles.append(filePath);
293
QtConcurrent::run(this, &HalideTransform::saveImageToFiles, m_output->data()->image, QStringList(filePath));
298
void HalideTransform::saveImageToFiles(QImage image, QStringList filePaths)
301
Q_FOREACH(QString filePath, filePaths) {
302
success = image.save(filePath);
304
qWarning() << "Failed to save image to file:" << filePath;
263
309
QVariant HalideTransform::functions() const