From 17e65a7167caaf9d55ae7ea0141c298d02689ea2 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Tue, 27 Dec 2016 16:32:32 +0100 Subject: VideoCommon: Replace SOIL with libpng for hires textures --- Source/Core/VideoCommon/HiresTextures.cpp | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) (limited to 'Source/Core/VideoCommon/HiresTextures.cpp') 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 #include #include #include @@ -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 extensions{ - ".png", ".bmp", ".tga", ".dds", - ".jpg" // Why not? Could be useful for large photo-like textures - }; + const std::vector extensions{".png", ".dds"}; const std::vector 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::Load(const std::string& base_filenam file.Open(filename_iter->second.path, "rb"); std::vector 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::Load(const std::string& base_filenam bool HiresTexture::LoadTexture(Level& level, const std::vector& 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(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(width); - level.height = static_cast(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(level.row_length) * 4 * level.height; return true; } -- cgit v1.2.3