Skip to content

Commit

Permalink
jpeg: hook up new jpeg encoder for thumbnailing
Browse files Browse the repository at this point in the history
  • Loading branch information
theuni committed May 7, 2012
1 parent fb57c76 commit 1725142
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion xbmc/pictures/Picture.cpp
Expand Up @@ -29,6 +29,7 @@
#include "utils/log.h"
#include "utils/URIUtils.h"
#include "DllSwScale.h"
#include "guilib/JpegIO.h"
#include "guilib/Texture.h"

using namespace XFILE;
Expand All @@ -48,15 +49,21 @@ bool CPicture::CacheImage(const CStdString& sourceUrl, const CStdString& destFil
{
CLog::Log(LOGINFO, "Caching image from: %s to %s with width %i and height %i", sourceUrl.c_str(), destFile.c_str(), width, height);

CJpegIO jpegImage;
DllImageLib dll;
if (!dll.Load()) return false;

if (URIUtils::IsInternetStream(sourceUrl, true))
{
CCurlFile http;
CStdString data;
if (http.Get(sourceUrl, data))
{
if (URIUtils::GetExtension(sourceUrl).Equals(".jpg") || URIUtils::GetExtension(sourceUrl).Equals(".tbn"))
{
if (jpegImage.CreateThumbnailFromMemory((unsigned char *)data.c_str(), data.GetLength(), destFile.c_str(), width, height))
return true;
}
if (!dll.Load()) return false;
if (!dll.CreateThumbnailFromMemory((BYTE *)data.c_str(), data.GetLength(), URIUtils::GetExtension(sourceUrl).c_str(), destFile.c_str(), width, height))
{
CLog::Log(LOGERROR, "%s Unable to create new image %s from image %s", __FUNCTION__, destFile.c_str(), sourceUrl.c_str());
Expand All @@ -67,6 +74,12 @@ bool CPicture::CacheImage(const CStdString& sourceUrl, const CStdString& destFil
return false;
}

if (URIUtils::GetExtension(sourceUrl).Equals(".jpg") || URIUtils::GetExtension(sourceUrl).Equals(".tbn"))
{
if (jpegImage.CreateThumbnail(sourceUrl, destFile, width, height, g_guiSettings.GetBool("pictures.useexifrotation")))
return true;
}
if (!dll.Load()) return false;
if (!dll.CreateThumbnail(sourceUrl.c_str(), destFile.c_str(), width, height, g_guiSettings.GetBool("pictures.useexifrotation")))
{
CLog::Log(LOGERROR, "%s Unable to create new image %s from image %s", __FUNCTION__, destFile.c_str(), sourceUrl.c_str());
Expand Down Expand Up @@ -98,6 +111,12 @@ bool CPicture::CacheFanart(const CStdString& sourceUrl, const CStdString& destFi
bool CPicture::CreateThumbnailFromMemory(const unsigned char* buffer, int bufSize, const CStdString& extension, const CStdString& thumbFile)
{
CLog::Log(LOGINFO, "Creating album thumb from memory: %s", thumbFile.c_str());
if (extension.Equals("jpg") || extension.Equals("tbn"))
{
CJpegIO jpegImage;
if (jpegImage.CreateThumbnailFromMemory((unsigned char*)buffer, bufSize, thumbFile.c_str(), g_advancedSettings.m_thumbSize, g_advancedSettings.m_thumbSize))
return true;
}
DllImageLib dll;
if (!dll.Load()) return false;
if (!dll.CreateThumbnailFromMemory((BYTE *)buffer, bufSize, extension.c_str(), thumbFile.c_str(), g_advancedSettings.m_thumbSize, g_advancedSettings.m_thumbSize))
Expand All @@ -124,6 +143,12 @@ void CPicture::CreateFolderThumb(const CStdString *thumbs, const CStdString &fol

bool CPicture::CreateThumbnailFromSurface(const unsigned char *buffer, int width, int height, int stride, const CStdString &thumbFile)
{
if (URIUtils::GetExtension(thumbFile).Equals(".jpg") || URIUtils::GetExtension(thumbFile).Equals(".tbn"))
{
CJpegIO jpegImage;
if (jpegImage.CreateThumbnailFromSurface((BYTE *)buffer, width, height, XB_FMT_A8R8G8B8, stride, thumbFile.c_str()))
return true;
}
DllImageLib dll;
if (!buffer || !dll.Load()) return false;
return dll.CreateThumbnailFromSurface((BYTE *)buffer, width, height, stride, thumbFile.c_str());
Expand Down

0 comments on commit 1725142

Please sign in to comment.