Skip to content
Browse files

[imageloader] adds a static wrapper to CBaseTexture::LoadFromFile to …

…save worrying about deletion of the created texture object
  • Loading branch information...
1 parent 55db267 commit cc5ed3c2474084ebc0373a3046410e6f766e03f4 Jonathan Marshall committed Jul 4, 2012
Showing with 29 additions and 15 deletions.
  1. +2 −6 xbmc/GUILargeTextureManager.cpp
  2. +3 −5 xbmc/TextureCacheJob.cpp
  3. +9 −0 xbmc/guilib/Texture.cpp
  4. +13 −2 xbmc/guilib/Texture.h
  5. +2 −2 xbmc/guilib/TextureManager.cpp
View
8 xbmc/GUILargeTextureManager.cpp
@@ -64,14 +64,10 @@ bool CImageLoader::DoWork()
if (!loadPath.IsEmpty())
{
// direct route - load the image
- m_texture = new CTexture();
unsigned int start = XbmcThreads::SystemClockMillis();
- if (!m_texture->LoadFromFile(loadPath, g_graphicsContext.GetWidth(), g_graphicsContext.GetHeight(), g_guiSettings.GetBool("pictures.useexifrotation")))
- {
- delete m_texture;
- m_texture = NULL;
+ m_texture = CBaseTexture::LoadFromFile(loadPath, g_graphicsContext.GetWidth(), g_graphicsContext.GetHeight(), g_guiSettings.GetBool("pictures.useexifrotation"));
+ if (!m_texture)
return false;
- }
if (XbmcThreads::SystemClockMillis() - start > 100)
CLog::Log(LOGDEBUG, "%s - took %u ms to load %s", __FUNCTION__, XbmcThreads::SystemClockMillis() - start, loadPath.c_str());
View
8 xbmc/TextureCacheJob.cpp
@@ -175,12 +175,10 @@ CBaseTexture *CTextureCacheJob::LoadImage(const CStdString &image, unsigned int
&& !file.GetMimeType().Left(6).Equals("image/")) // ignore non-pictures
return NULL;
- CTexture *texture = new CTexture();
- if (!texture->LoadFromFile(image, width, height, g_guiSettings.GetBool("pictures.useexifrotation")))
- {
- delete texture;
+ CBaseTexture *texture = CBaseTexture::LoadFromFile(image, width, height, g_guiSettings.GetBool("pictures.useexifrotation"));
+ if (!texture)
return NULL;
- }
+
// EXIF bits are interpreted as: <flipXY><flipY*flipX><flipX>
// where to undo the operation we apply them in reverse order <flipX>*<flipY*flipX>*<flipXY>
// When flipped = true we have an additional <flipX> on the left, which is equivalent to toggling the last bit
View
9 xbmc/guilib/Texture.cpp
@@ -171,6 +171,15 @@ void CBaseTexture::ClampToEdge()
}
}
+CBaseTexture *CBaseTexture::LoadFromFile(const CStdString& texturePath, unsigned int idealWidth, unsigned int idealHeight, bool autoRotate)
+{
+ CTexture *texture = new CTexture();
+ if (texture->LoadFromFile(texturePath, idealWidth, idealHeight, autoRotate, NULL, NULL))
+ return texture;
+ delete texture;
+ return NULL;
+}
+
bool CBaseTexture::LoadFromFile(const CStdString& texturePath, unsigned int maxWidth, unsigned int maxHeight,
bool autoRotate, unsigned int *originalWidth, unsigned int *originalHeight)
{
View
15 xbmc/guilib/Texture.h
@@ -48,8 +48,19 @@ class CBaseTexture
virtual ~CBaseTexture();
- bool LoadFromFile(const CStdString& texturePath, unsigned int maxHeight = 0, unsigned int maxWidth = 0,
- bool autoRotate = false, unsigned int *originalWidth = NULL, unsigned int *originalHeight = NULL);
+ /*! \brief Load a texture from a file
+ Loads a texture from a file, restricting in size if needed based on maxHeight and maxWidth.
+ Note that these are the ideal size to load at - the returned texture may be smaller or larger than these.
+ \param texturePath the path of the texture to load.
+ \param idealWidth the ideal width of the texture (defaults to 0, no ideal width).
+ \param idealHeight the ideal height of the texture (defaults to 0, no ideal height).
+ \param autoRotate whether the textures should be autorotated based on EXIF information (defaults to false).
+ \return a CBaseTexture pointer to the created texture - NULL if the texture failed to load.
+ */
+ static CBaseTexture *LoadFromFile(const CStdString& texturePath, unsigned int idealWidth = 0, unsigned int idealHeight = 0,
+ bool autoRotate = false);
+ bool LoadFromFile(const CStdString& texturePath, unsigned int maxWidth, unsigned int maxHeight,
+ bool autoRotate, unsigned int *originalWidth, unsigned int *originalHeight);
bool LoadFromMemory(unsigned int width, unsigned int height, unsigned int pitch, unsigned int format, bool hasAlpha, unsigned char* pixels);
bool LoadPaletted(unsigned int width, unsigned int height, unsigned int pitch, unsigned int format, const unsigned char *pixels, const COLOR *palette);
View
4 xbmc/guilib/TextureManager.cpp
@@ -400,8 +400,8 @@ int CGUITextureManager::Load(const CStdString& strTextureName, bool checkBundleO
}
else
{
- pTexture = new CTexture();
- if(!pTexture->LoadFromFile(strPath))
+ pTexture = CBaseTexture::LoadFromFile(strPath);
+ if (!pTexture)
return 0;
width = pTexture->GetWidth();
height = pTexture->GetHeight();

0 comments on commit cc5ed3c

Please sign in to comment.
Something went wrong with that request. Please try again.