bool CPicture::CreateThumbnailFromSurface(const unsigned char *buffer, int width, int height, int stride, const std::string &thumbFile) { CLog::Log(LOGDEBUG, "cached image '%s' size %dx%d", CURL::GetRedacted(thumbFile).c_str(), width, height); if (URIUtils::HasExtension(thumbFile, ".jpg")) { #if defined(HAS_OMXPLAYER) if (COMXImage::CreateThumbnailFromSurface((BYTE *)buffer, width, height, XB_FMT_A8R8G8B8, stride, thumbFile.c_str())) return true; #endif } unsigned char *thumb = NULL; unsigned int thumbsize=0; IImage* pImage = ImageFactory::CreateLoader(thumbFile); if(pImage == NULL || !pImage->CreateThumbnailFromSurface((BYTE *)buffer, width, height, XB_FMT_A8R8G8B8, stride, thumbFile.c_str(), thumb, thumbsize)) { CLog::Log(LOGERROR, "Failed to CreateThumbnailFromSurface for %s", CURL::GetRedacted(thumbFile).c_str()); delete pImage; return false; } XFILE::CFile file; const bool ret = file.OpenForWrite(thumbFile, true) && file.Write(thumb, thumbsize) == thumbsize; pImage->ReleaseThumbnailBuffer(); delete pImage; return ret; }
bool CPicture::CreateThumbnailFromSurface(const unsigned char *buffer, int width, int height, int stride, const CStdString &thumbFile) { CLog::Log(LOGDEBUG, "cached image '%s' size %dx%d", thumbFile.c_str(), width, height); if (URIUtils::GetExtension(thumbFile).Equals(".jpg")) { #if defined(HAS_OMXPLAYER) COMXImage *omxImage = new COMXImage(); if (omxImage && omxImage->CreateThumbnailFromSurface((BYTE *)buffer, width, height, XB_FMT_A8R8G8B8, stride, thumbFile.c_str())) { delete omxImage; return true; } delete omxImage; #endif } unsigned char *thumb = NULL; unsigned int thumbsize=0; IImage* pImage = ImageFactory::CreateLoader(thumbFile); if(pImage == NULL || !pImage->CreateThumbnailFromSurface((BYTE *)buffer, width, height, XB_FMT_A8R8G8B8, stride, thumbFile.c_str(), thumb, thumbsize)) { CLog::Log(LOGERROR, "Failed to CreateThumbnailFromSurface for %s", thumbFile.c_str()); delete pImage; return false; } XFILE::CFile file; if (file.OpenForWrite(thumbFile, true)) { file.Write(thumb, thumbsize); file.Close(); pImage->ReleaseThumbnailBuffer(); delete pImage; return true; } pImage->ReleaseThumbnailBuffer(); delete pImage; return false; }
bool CPicture::GetThumbnailFromSurface(const unsigned char* buffer, int width, int height, int stride, const std::string &thumbFile, uint8_t* &result, size_t& result_size) { unsigned char *thumb = NULL; unsigned int thumbsize = 0; // get an image handler IImage* image = ImageFactory::CreateLoader(thumbFile); if (image == NULL || !image->CreateThumbnailFromSurface((BYTE *)buffer, width, height, XB_FMT_A8R8G8B8, stride, thumbFile.c_str(), thumb, thumbsize)) { delete image; return false; } // copy the resulting buffer result_size = thumbsize; result = new uint8_t[result_size]; memcpy(result, thumb, result_size); // release the image buffer and the image handler image->ReleaseThumbnailBuffer(); delete image; return true; }