Skip to content

Commit

Permalink
TextureCacheJob: Use common file buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
popcornmix committed Apr 3, 2020
1 parent 1478885 commit 26d6338
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 35 deletions.
30 changes: 15 additions & 15 deletions xbmc/TextureCacheJob.cpp
Expand Up @@ -96,32 +96,32 @@ bool CTextureCacheJob::CacheTexture(CBaseTexture **out_texture)
if (!(!(file.IsPicture() && !(file.IsZIP() || file.IsRAR() || file.IsCBR() || file.IsCBZ() ))
&& !StringUtils::StartsWithNoCase(file.GetMimeType(), "image/") && !StringUtils::EqualsNoCase(file.GetMimeType(), "application/octet-stream"))) // ignore non-pictures
{
// Read image into memory to use our vfs
ssize_t fileRead = 0;
XFILE::CFile xfile;
XFILE::auto_buffer buf;
if (!URIUtils::HasExtension(image, ".dds"))
xfile.LoadFile(image, buf);

#if defined(TARGET_RASPBERRY_PI)
if (CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool("videoplayer.acceleratedjpegs"))
{
// Read image into memory to use our vfs
XFILE::CFile xfile;
XFILE::auto_buffer buf;

if (xfile.LoadFile(image, buf) > 0)
if (COMXImage::CreateThumb(image, buf, width, height, additional_info, CTextureCache::GetCachedPath(m_cachePath + ".jpg")))
{
if (COMXImage::CreateThumb(image, buf, width, height, additional_info, CTextureCache::GetCachedPath(m_cachePath + ".jpg")))
{
m_details.width = width;
m_details.height = height;
m_details.file = m_cachePath + ".jpg";
if (out_texture)
*out_texture = LoadImage(CTextureCache::GetCachedPath(m_details.file), width, height, "" /* already flipped */);
m_details.width = width;
m_details.height = height;
m_details.file = m_cachePath + ".jpg";
if (out_texture)
*out_texture = LoadImage(CTextureCache::GetCachedPath(m_details.file), width, height, "" /* already flipped */);
CLog::Log(LOGDEBUG, "Fast %s image '%s' to '%s': %p",
m_oldHash.empty() ? "Caching" : "Recaching", CURL::GetRedacted(image),
m_details.file, static_cast<void*>(out_texture));
return true;
}
return true;
}
}
#endif
texture = new CTexture();
if (!(texture->LoadFromFileInternal(image, width, height, true, file.GetMimeType())))
if (!(texture->LoadFromFileInternal(image, buf, width, height, true, file.GetMimeType())))
{
delete texture;
texture = nullptr;
Expand Down
17 changes: 8 additions & 9 deletions xbmc/guilib/Texture.cpp
Expand Up @@ -199,8 +199,14 @@ CBaseTexture *CBaseTexture::LoadFromFile(const std::string& texturePath, unsigne
}
}
#endif
// Read image into memory to use our vfs
XFILE::CFile file;
XFILE::auto_buffer buf;
if (!URIUtils::HasExtension(texturePath, ".dds"))
file.LoadFile(texturePath, buf);

CTexture *texture = new CTexture();
if (texture->LoadFromFileInternal(texturePath, idealWidth, idealHeight, requirePixels, strMimeType))
if (texture->LoadFromFileInternal(texturePath, buf, idealWidth, idealHeight, requirePixels, strMimeType))
return texture;
delete texture;
return NULL;
Expand All @@ -215,7 +221,7 @@ CBaseTexture *CBaseTexture::LoadFromFileInMemory(unsigned char *buffer, size_t b
return NULL;
}

bool CBaseTexture::LoadFromFileInternal(const std::string& texturePath, unsigned int maxWidth, unsigned int maxHeight, bool requirePixels, const std::string& strMimeType)
bool CBaseTexture::LoadFromFileInternal(const std::string& texturePath, const XFILE::auto_buffer &buf, unsigned int maxWidth, unsigned int maxHeight, bool requirePixels, const std::string& strMimeType)
{
if (URIUtils::HasExtension(texturePath, ".dds"))
{ // special case for DDS images
Expand All @@ -233,13 +239,6 @@ bool CBaseTexture::LoadFromFileInternal(const std::string& texturePath, unsigned
unsigned int height = maxHeight ? std::min(maxHeight, CServiceBroker::GetRenderSystem()->GetMaxTextureSize()) :
CServiceBroker::GetRenderSystem()->GetMaxTextureSize();

// Read image into memory to use our vfs
XFILE::CFile file;
XFILE::auto_buffer buf;

if (file.LoadFile(texturePath, buf) <= 0)
return false;

CURL url(texturePath);
// make sure resource:// paths are properly resolved
if (url.IsProtocol("resource"))
Expand Down
3 changes: 2 additions & 1 deletion xbmc/guilib/Texture.h
Expand Up @@ -10,6 +10,7 @@

#include "XBTF.h"
#include "guilib/imagefactory.h"
#include "filesystem/File.h"

#pragma pack(1)
struct COLOR {unsigned char b,g,r,x;}; // Windows GDI expects 4bytes per color
Expand Down Expand Up @@ -110,7 +111,7 @@ class CBaseTexture
bool LoadFromFileInMem(unsigned char* buffer, size_t size, const std::string& mimeType,
unsigned int maxWidth, unsigned int maxHeight);
public:
bool LoadFromFileInternal(const std::string& texturePath, unsigned int maxWidth, unsigned int maxHeight, bool requirePixels, const std::string& strMimeType = "");
bool LoadFromFileInternal(const std::string& texturePath, const XFILE::auto_buffer &buf, unsigned int maxWidth, unsigned int maxHeight, bool requirePixels, const std::string& strMimeType = "");
protected:
bool LoadIImage(IImage* pImage, unsigned char* buffer, unsigned int bufSize, unsigned int width, unsigned int height);
// helpers for computation of texture parameters for compressed textures
Expand Down
11 changes: 2 additions & 9 deletions xbmc/guilib/TexturePi.cpp
Expand Up @@ -102,17 +102,10 @@ void CPiTexture::Update(unsigned int width, unsigned int height, unsigned int pi
CGLTexture::Update(width, height, pitch, format, pixels, loadToGPU);
}

bool CPiTexture::LoadFromFileInternal(const std::string& texturePath, unsigned int maxWidth, unsigned int maxHeight, bool requirePixels, const std::string& strMimeType)
bool CPiTexture::LoadFromFileInternal(const std::string& texturePath, const XFILE::auto_buffer &buf, unsigned int maxWidth, unsigned int maxHeight, bool requirePixels, const std::string& strMimeType)
{
if (CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool("videoplayer.acceleratedjpegs") && URIUtils::HasExtension(texturePath, ".jpg|.tbn"))
{
// Read image into memory to use our vfs
XFILE::CFile file;
XFILE::auto_buffer buf;

if (file.LoadFile(texturePath, buf) <= 0)
return false;

unsigned int width = 0, height = 0;
int orientation = 0;
std::string error;
Expand Down Expand Up @@ -144,5 +137,5 @@ bool CPiTexture::LoadFromFileInternal(const std::string& texturePath, unsigned i
}
}
}
return CGLTexture::LoadFromFileInternal(texturePath, maxWidth, maxHeight, requirePixels);
return CGLTexture::LoadFromFileInternal(texturePath, buf, maxWidth, maxHeight, requirePixels);
}
2 changes: 1 addition & 1 deletion xbmc/guilib/TexturePi.h
Expand Up @@ -24,7 +24,7 @@ class CPiTexture : public CGLTexture
void LoadToGPU();
void Update(unsigned int width, unsigned int height, unsigned int pitch, unsigned int format, const unsigned char *pixels, bool loadToGPU);
void Allocate(unsigned int width, unsigned int height, unsigned int format);
bool LoadFromFileInternal(const std::string& texturePath, unsigned int maxWidth, unsigned int maxHeight, bool requirePixels, const std::string& strMimeType = "");
bool LoadFromFileInternal(const std::string& texturePath, const XFILE::auto_buffer &buf, unsigned int maxWidth, unsigned int maxHeight, bool requirePixels, const std::string& strMimeType = "");

protected:

Expand Down

0 comments on commit 26d6338

Please sign in to comment.