Skip to content

Commit 4c372e1

Browse files
committed
Core (LV::Video): Refactor image loading code.
1 parent e12321a commit 4c372e1

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

libvisual/libvisual/lv_video.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,24 @@
3737
#include "private/lv_video_bmp.hpp"
3838
#include "private/lv_video_png.hpp"
3939
#include <cstring>
40-
#include <iostream>
41-
#include <fstream>
4240
#include <filesystem>
41+
#include <fstream>
42+
#include <functional>
43+
#include <unordered_map>
4344

4445
namespace LV {
4546

4647
namespace fs = std::filesystem;
4748

4849
namespace {
4950

51+
using BitmapLoad = std::function<VideoPtr (std::istream&)>;
52+
std::unordered_map<std::string, BitmapLoad> const bitmap_load_map =
53+
{
54+
{ "bmp", bitmap_load_bmp },
55+
{ "png", bitmap_load_png }
56+
};
57+
5058
bool is_valid_scale_method (VisVideoScaleMethod scale_method)
5159
{
5260
return scale_method == VISUAL_VIDEO_SCALE_NEAREST
@@ -195,17 +203,14 @@ namespace LV {
195203

196204
VideoPtr Video::create_from_stream (std::istream& input)
197205
{
198-
auto image = bitmap_load_bmp (input);
199-
if (image) {
200-
return image;
201-
}
202-
203-
image = bitmap_load_png (input);
204-
if (image) {
205-
return image;
206+
for (auto entry : bitmap_load_map) {
207+
auto image {entry.second (input)};
208+
if (image) {
209+
return image;
210+
}
206211
}
207212

208-
return {};
213+
return nullptr;
209214
}
210215

211216
VideoPtr Video::create_scale_depth (VideoConstPtr const& src,

0 commit comments

Comments
 (0)