diff options
| author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | 2016-12-27 16:32:32 +0100 |
|---|---|---|
| committer | JosJuice <josjuice@gmail.com> | 2018-05-20 13:44:38 +0200 |
| commit | 17e65a7167caaf9d55ae7ea0141c298d02689ea2 (patch) | |
| tree | a85016919258539bddc6d3847fe8932c6d882361 /Source/Core/VideoCommon/HiresTextures.cpp | |
| parent | 0706add5840edcc7faeca538dafcd4f56cee7940 (diff) | |
VideoCommon: Replace SOIL with libpng for hires textures
Diffstat (limited to 'Source/Core/VideoCommon/HiresTextures.cpp')
| -rw-r--r-- | Source/Core/VideoCommon/HiresTextures.cpp | 31 |
1 files changed, 8 insertions, 23 deletions
diff --git a/Source/Core/VideoCommon/HiresTextures.cpp b/Source/Core/VideoCommon/HiresTextures.cpp index 6a45f812fa..c6d8668a53 100644 --- a/Source/Core/VideoCommon/HiresTextures.cpp +++ b/Source/Core/VideoCommon/HiresTextures.cpp @@ -4,7 +4,6 @@ #include "VideoCommon/HiresTextures.h" -#include <SOIL/SOIL.h> #include <algorithm> #include <cinttypes> #include <cstring> @@ -22,6 +21,7 @@ #include "Common/FileUtil.h" #include "Common/Flag.h" #include "Common/Hash.h" +#include "Common/Image.h" #include "Common/Logging/Log.h" #include "Common/MemoryUtil.h" #include "Common/StringUtil.h" @@ -49,10 +49,6 @@ static std::thread s_prefetcher; static const std::string s_format_prefix = "tex1_"; -HiresTexture::Level::Level() : data(nullptr, SOIL_free_image_data) -{ -} - void HiresTexture::Init() { Update(); @@ -92,10 +88,7 @@ void HiresTexture::Update() const std::string& game_id = SConfig::GetInstance().GetGameID(); const std::string texture_directory = GetTextureDirectory(game_id); - std::vector<std::string> extensions{ - ".png", ".bmp", ".tga", ".dds", - ".jpg" // Why not? Could be useful for large photo-like textures - }; + const std::vector<std::string> extensions{".png", ".dds"}; const std::vector<std::string> texture_paths = Common::DoFileSearch({texture_directory}, extensions, /*recursive*/ true); @@ -183,9 +176,7 @@ void HiresTexture::Prefetch() if (iter != s_textureCache.end()) { for (const Level& l : iter->second->m_levels) - { - size_sum += l.data_size; - } + size_sum += l.data.size(); } } @@ -361,6 +352,7 @@ std::unique_ptr<HiresTexture> HiresTexture::Load(const std::string& base_filenam file.Open(filename_iter->second.path, "rb"); std::vector<u8> buffer(file.GetSize()); file.ReadBytes(buffer.data(), file.GetSize()); + if (!LoadTexture(level, buffer)) { ERROR_LOG(VIDEO, "Custom texture %s failed to load", filename.c_str()); @@ -440,22 +432,15 @@ std::unique_ptr<HiresTexture> HiresTexture::Load(const std::string& base_filenam bool HiresTexture::LoadTexture(Level& level, const std::vector<u8>& buffer) { - int channels; - int width; - int height; + if (!Common::LoadPNG(buffer, &level.data, &level.width, &level.height)) + return false; - u8* data = SOIL_load_image_from_memory(buffer.data(), static_cast<int>(buffer.size()), &width, - &height, &channels, SOIL_LOAD_RGBA); - if (!data) + if (level.data.empty()) return false; - // Images loaded by SOIL are converted to RGBA. - level.width = static_cast<u32>(width); - level.height = static_cast<u32>(height); + // Loaded PNG images are converted to RGBA. level.format = AbstractTextureFormat::RGBA8; - level.data = ImageDataPointer(data, SOIL_free_image_data); level.row_length = level.width; - level.data_size = static_cast<size_t>(level.row_length) * 4 * level.height; return true; } |
