Skip to content

Commit

Permalink
[qtAV] imgserve: catch runtime_error when image cannot be read
Browse files Browse the repository at this point in the history
  • Loading branch information
mugulmd committed Jun 20, 2023
1 parent c24332c commit 40522c4
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 32 deletions.
54 changes: 36 additions & 18 deletions src/qtAliceVision/SequenceCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <cmath>
#include <thread>
#include <chrono>
#include <stdexcept>
#include <iostream>


namespace qtAliceVision {
Expand Down Expand Up @@ -53,25 +55,33 @@ void SequenceCache::setSequence(const QVariantList& paths)
// Fill sequence vector
for (const auto& var : paths)
{
// Initialize frame data
FrameData data;
data.path = var.toString().toStdString();
try
{
// Initialize frame data
FrameData data;
data.path = var.toString().toStdString();

// Retrieve metadata from disk
int width, height;
auto metadata = aliceVision::image::readImageMetadata(data.path, width, height);
// Retrieve metadata from disk
int width, height;
auto metadata = aliceVision::image::readImageMetadata(data.path, width, height);

// Store original image dimensions
data.dim = QSize(width, height);
// Store original image dimensions
data.dim = QSize(width, height);

// Copy metadata into a QVariantMap
for (const auto& item : metadata)
// Copy metadata into a QVariantMap
for (const auto& item : metadata)
{
data.metadata[QString::fromStdString(item.name().string())] = QString::fromStdString(item.get_string());
}

// Add to sequence
_sequence.push_back(data);
}
catch (const std::runtime_error& e)
{
data.metadata[QString::fromStdString(item.name().string())] = QString::fromStdString(item.get_string());
// Log error
std::cerr << e.what() << std::endl;
}

// Add to sequence
_sequence.push_back(data);
}

// Sort sequence by filepaths
Expand Down Expand Up @@ -313,10 +323,18 @@ void PrefetchingIORunnable::run()
}

// Load image in cache
const bool cachedOnly = false;
const bool lazyCleaning = false;
_cache->get<aliceVision::image::RGBAfColor>(data.path, 1, cachedOnly, lazyCleaning);
filled += memSize;
try
{
const bool cachedOnly = false;
const bool lazyCleaning = false;
_cache->get<aliceVision::image::RGBAfColor>(data.path, 1, cachedOnly, lazyCleaning);
filled += memSize;
}
catch (const std::runtime_error& e)
{
// Log error message
std::cerr << e.what() << std::endl;
}

// Wait a few milliseconds in case another thread needs to query the cache
std::this_thread::sleep_for(1ms);
Expand Down
39 changes: 25 additions & 14 deletions src/qtAliceVision/SingleImageLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

#include <QThreadPool>

#include <stdexcept>
#include <iostream>


namespace qtAliceVision {
namespace imgserve {
Expand Down Expand Up @@ -63,22 +66,30 @@ void SingleImageLoadingIORunnable::run()
{
Response response;

// Retrieve metadata from disk
int width, height;
auto metadata = aliceVision::image::readImageMetadata(_path, width, height);

// Store original image dimensions
response.dim = QSize(width, height);

// Copy metadata into a QVariantMap
for (const auto& item : metadata)
try
{
response.metadata[QString::fromStdString(item.name().string())] = QString::fromStdString(item.get_string());
// Retrieve metadata from disk
int width, height;
auto metadata = aliceVision::image::readImageMetadata(_path, width, height);

// Store original image dimensions
response.dim = QSize(width, height);

// Copy metadata into a QVariantMap
for (const auto& item : metadata)
{
response.metadata[QString::fromStdString(item.name().string())] = QString::fromStdString(item.get_string());
}

// Load image
response.img = std::make_shared<aliceVision::image::Image<aliceVision::image::RGBAfColor>>();
aliceVision::image::readImage(_path, *(response.img), aliceVision::image::EImageColorSpace::LINEAR);
}
catch (const std::runtime_error& e)
{
// Log error message
std::cerr << e.what() << std::endl;
}

// Load image
response.img = std::make_shared<aliceVision::image::Image<aliceVision::image::RGBAfColor>>();
aliceVision::image::readImage(_path, *(response.img), aliceVision::image::EImageColorSpace::LINEAR);

// Notify listeners that loading is finished
Q_EMIT done(QString::fromStdString(_path), response);
Expand Down

0 comments on commit 40522c4

Please sign in to comment.