From f7be4e0ff6ce1f83201c083763ad8f02b4def451 Mon Sep 17 00:00:00 2001 From: montellese Date: Sun, 4 Jan 2015 20:28:37 +0100 Subject: [PATCH] CTextureCacheJob: add ResizeTexture() implementation --- xbmc/TextureCacheJob.cpp | 32 ++++++++++++++++++++++++++++++++ xbmc/TextureCacheJob.h | 3 +++ 2 files changed, 35 insertions(+) diff --git a/xbmc/TextureCacheJob.cpp b/xbmc/TextureCacheJob.cpp index cf111ed07d532..b28a66901cac6 100644 --- a/xbmc/TextureCacheJob.cpp +++ b/xbmc/TextureCacheJob.cpp @@ -127,6 +127,31 @@ bool CTextureCacheJob::CacheTexture(CBaseTexture **out_texture) return false; } +bool CTextureCacheJob::ResizeTexture(const std::string &url, uint8_t* &result, size_t &result_size) +{ + result = NULL; + result_size = 0; + + if (url.empty()) + return false; + + // unwrap the URL as required + std::string additional_info; + unsigned int width, height; + std::string image = DecodeImageURL(url, width, height, additional_info); + if (image.empty()) + return false; + + CBaseTexture *texture = LoadImage(image, width, height, additional_info, true); + if (texture == NULL) + return false; + + bool success = CPicture::ResizeTexture(image, texture, width, height, result, result_size); + delete texture; + + return success; +} + std::string CTextureCacheJob::DecodeImageURL(const std::string &url, unsigned int &width, unsigned int &height, std::string &additional_info) { // unwrap the URL as required @@ -150,6 +175,13 @@ std::string CTextureCacheJob::DecodeImageURL(const std::string &url, unsigned in if (thumbURL.GetOption("size") == "thumb") width = height = g_advancedSettings.GetThumbSize(); + else + { + if (thumbURL.HasOption("width") && StringUtils::IsInteger(thumbURL.GetOption("width"))) + width = strtol(thumbURL.GetOption("width").c_str(), NULL, 0); + if (thumbURL.HasOption("height") && StringUtils::IsInteger(thumbURL.GetOption("height"))) + height = strtol(thumbURL.GetOption("height").c_str(), NULL, 0); + } } return image; } diff --git a/xbmc/TextureCacheJob.h b/xbmc/TextureCacheJob.h index 0515db9a65f4c..aa9b6f027ad64 100644 --- a/xbmc/TextureCacheJob.h +++ b/xbmc/TextureCacheJob.h @@ -20,6 +20,7 @@ #pragma once +#include #include #include #include "utils/Job.h" @@ -76,6 +77,8 @@ class CTextureCacheJob : public CJob */ bool CacheTexture(CBaseTexture **texture = NULL); + static bool ResizeTexture(const std::string &url, uint8_t* &result, size_t &result_size); + std::string m_url; std::string m_oldHash; CTextureDetails m_details;