Skip to content

Commit

Permalink
CTextureCacheJob: add ResizeTexture() implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Montellese committed Feb 4, 2015
1 parent 49d8075 commit f7be4e0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
32 changes: 32 additions & 0 deletions xbmc/TextureCacheJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down
3 changes: 3 additions & 0 deletions xbmc/TextureCacheJob.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#pragma once

#include <stdint.h>
#include <string>
#include <vector>
#include "utils/Job.h"
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit f7be4e0

Please sign in to comment.