aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ImageViewer.cpp46
1 files changed, 21 insertions, 25 deletions
diff --git a/src/ImageViewer.cpp b/src/ImageViewer.cpp
index 97ef7c9..416f27f 100644
--- a/src/ImageViewer.cpp
+++ b/src/ImageViewer.cpp
@@ -40,9 +40,9 @@ namespace QuickMedia {
assert(!loading_image);
loading_image = true;
image_loader_thread = std::thread([this, image_data, path]() {
- auto image_data_str = std::make_unique<std::string>();
- if(file_get_content(path, *image_data_str) == 0) {
- image_data->image_data_str = std::move(image_data_str);
+ auto image = std::make_unique<sf::Image>();
+ if(image->loadFromFile(path.data)) {
+ image_data->image = std::move(image);
image_data->image_status = ImageStatus::LOADED;
} else {
image_data->image_status = ImageStatus::FAILED_TO_LOAD;
@@ -57,18 +57,6 @@ namespace QuickMedia {
return false;
std::shared_ptr<ImageData> &page_image_data = image_data[page];
- if(page_image_data && page_image_data->image_status == ImageStatus::LOADED) {
- if(page_image_data->texture.loadFromMemory(page_image_data->image_data_str->data(), page_image_data->image_data_str->size())) {
- page_image_data->sprite.setTexture(page_image_data->texture, true);
- page_size[page].size = get_page_size(page);
- page_size[page].loaded = true;
- page_image_data->image_status = ImageStatus::APPLIED_TO_TEXTURE;
- } else {
- page_image_data->image_status = ImageStatus::FAILED_TO_LOAD;
- page_image_data->image_data_str.reset();
- }
- }
-
const sf::Vector2<double> image_size = get_page_size(page);
sf::Vector2<double> render_pos(std::floor(window_size.x * 0.5 - image_size.x * 0.5), - image_size.y * 0.5 + scroll + offset_y);
if(render_pos.y + image_size.y <= 0.0 || render_pos.y >= window_size.y) {
@@ -145,23 +133,15 @@ namespace QuickMedia {
Path image_path = chapter_cache_dir;
image_path.join(page_str);
- // TODO: Make image loading asynchronous
if(get_file_type(image_path) == FileType::REGULAR) {
fprintf(stderr, "ImageViewer: Loaded page %d\n", 1 + page);
page_image_data = std::make_shared<ImageData>();
page_image_data->visible_on_screen = true;
- std::string image_data;
- if(file_get_content(image_path, image_data) == 0) {
- page_image_data->image_status = ImageStatus::WAITING;
- page_image_data->texture.setSmooth(true);
- } else {
- show_notification("Manga", "Failed to load image for page " + page_str + ". Image filepath: " + image_path.data, Urgency::CRITICAL);
- page_image_data->image_status = ImageStatus::FAILED_TO_LOAD;
- }
+ page_image_data->image_status = ImageStatus::WAITING;
+ page_image_data->texture.setSmooth(true);
}
-
}
return true;
@@ -273,6 +253,22 @@ namespace QuickMedia {
min_page_center_dist = 9999999.0;
page_closest_to_center = -1;
+ int page_i = 0;
+ for(auto &page_data : image_data) {
+ if(page_data && page_data->image_status == ImageStatus::LOADED) {
+ if(page_data->texture.loadFromImage(*page_data->image)) {
+ page_data->sprite.setTexture(page_data->texture, true);
+ page_size[page_i].size = get_page_size(page_i);
+ page_size[page_i].loaded = true;
+ page_data->image_status = ImageStatus::APPLIED_TO_TEXTURE;
+ } else {
+ page_data->image_status = ImageStatus::FAILED_TO_LOAD;
+ }
+ page_data->image.reset();
+ }
+ ++page_i;
+ }
+
const sf::Vector2<double> selected_page_size = get_page_size(current_page);
render_page(window, current_page, window_size.y*0.5);
//if(!focused_page_rendered)