aboutsummaryrefslogtreecommitdiff
path: root/src/AsyncImageLoader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/AsyncImageLoader.cpp')
-rw-r--r--src/AsyncImageLoader.cpp25
1 files changed, 8 insertions, 17 deletions
diff --git a/src/AsyncImageLoader.cpp b/src/AsyncImageLoader.cpp
index ec9ae9a..98c7fee 100644
--- a/src/AsyncImageLoader.cpp
+++ b/src/AsyncImageLoader.cpp
@@ -2,23 +2,14 @@
#include "../include/DownloadUtils.hpp"
#include "../include/ImageUtils.hpp"
#include "../include/Scale.hpp"
+#include "../include/SfmlFixes.hpp"
#include "../external/hash-library/sha256.h"
#include <assert.h>
namespace QuickMedia {
- static sf::Vector2f to_vec2f(const sf::Vector2u &vec) {
- return sf::Vector2f(vec.x, vec.y);
- }
-
- static sf::Vector2f to_vec2f(const sf::Vector2i &vec) {
- return sf::Vector2f(vec.x, vec.y);
- }
-
- static sf::Vector2u to_vec2u(const sf::Vector2f &vec) {
- return sf::Vector2u(vec.x, vec.y);
- }
-
// Linear interpolation
+ // TODO: Is this implementation ok? it always uses +1 offset for interpolation but if we were to resize an image with near 1x1 scaling
+ // then it would be slightly blurry
static void copy_resize(const sf::Image &source, sf::Image &destination, sf::Vector2u destination_size) {
const sf::Vector2u source_size = source.getSize();
if(source_size.x == 0 || source_size.y == 0 || destination_size.x == 0 || destination_size.y == 0)
@@ -120,14 +111,14 @@ namespace QuickMedia {
}
thumbnail_load_data.thumbnail_data->image = std::make_unique<sf::Image>();
- if(thumbnail_load_data.thumbnail_data->image->loadFromFile(thumbnail_load_data.thumbnail_path.data)) {
+ if(load_image_from_file(*thumbnail_load_data.thumbnail_data->image, thumbnail_load_data.thumbnail_path.data)) {
fprintf(stderr, "Loaded %s from thumbnail cache\n", thumbnail_load_data.path.data.c_str());
thumbnail_load_data.thumbnail_data->loading_state = LoadingState::FINISHED_LOADING;
continue;
}
if(thumbnail_load_data.local) {
- if(thumbnail_load_data.thumbnail_data->image->loadFromFile(thumbnail_load_data.path.data)
+ if(load_image_from_file(*thumbnail_load_data.thumbnail_data->image, thumbnail_load_data.path.data)
&& thumbnail_load_data.resize_target_size.x != 0 && thumbnail_load_data.resize_target_size.y != 0)
{
create_thumbnail_if_thumbnail_smaller_than_image(thumbnail_load_data.path.data, thumbnail_load_data.thumbnail_path, thumbnail_load_data.thumbnail_data.get(), thumbnail_load_data.resize_target_size);
@@ -194,21 +185,21 @@ namespace QuickMedia {
// TODO: Keep the thread running and use conditional variable instead to sleep until a new image should be loaded. Same in ImageViewer.
download_image_thread[free_index] = std::thread([this, free_index, thumbnail_path, url, local, resize_target_size, thumbnail_data, use_tor]() mutable {
thumbnail_data->image = std::make_unique<sf::Image>();
- if(thumbnail_data->image->loadFromFile(thumbnail_path.data)) {
+ if(load_image_from_file(*thumbnail_data->image, thumbnail_path.data)) {
fprintf(stderr, "Loaded %s from thumbnail cache\n", url.c_str());
thumbnail_data->loading_state = LoadingState::FINISHED_LOADING;
loading_image[free_index] = false;
return;
} else {
if(local) {
- if(!thumbnail_data->image->loadFromFile(url)) {
+ if(!load_image_from_file(*thumbnail_data->image, url)) {
thumbnail_data->loading_state = LoadingState::FINISHED_LOADING;
loading_image[free_index] = false;
return;
}
} else {
// Use the same path as the thumbnail path, since it wont be overwritten if the image is smaller than the thumbnail target size
- if(download_to_file(url, thumbnail_path.data, {}, use_tor, true) != DownloadResult::OK || !thumbnail_data->image->loadFromFile(thumbnail_path.data)) {
+ if(download_to_file(url, thumbnail_path.data, {}, use_tor, true) != DownloadResult::OK || !load_image_from_file(*thumbnail_data->image, thumbnail_path.data)) {
thumbnail_data->loading_state = LoadingState::FINISHED_LOADING;
loading_image[free_index] = false;
return;