Skip to content

Commit

Permalink
Picture: Use av_malloc when using ffmpeg scalers
Browse files Browse the repository at this point in the history
  • Loading branch information
fritsch committed Oct 29, 2016
1 parent a0d63d1 commit aadfc21
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions xbmc/pictures/Picture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

extern "C" {
#include "libswscale/swscale.h"
#include "libavutil/mem.h"
}

using namespace XFILE;
Expand Down Expand Up @@ -176,7 +177,7 @@ bool CPicture::ResizeTexture(const std::string &image, uint8_t *pixels, uint32_t
// create a buffer large enough for the resulting image
GetScale(width, height, dest_width, dest_height);

uint8_t *buffer = new uint8_t[dest_width * dest_height * sizeof(uint32_t)];
uint8_t *buffer = (uint8_t*) av_malloc(dest_width * dest_height * sizeof(uint32_t));
if (buffer == NULL)
{
result = NULL;
Expand All @@ -186,14 +187,14 @@ bool CPicture::ResizeTexture(const std::string &image, uint8_t *pixels, uint32_t

if (!ScaleImage(pixels, width, height, pitch, buffer, dest_width, dest_height, dest_width * sizeof(uint32_t), scalingAlgorithm))
{
delete[] buffer;
av_free(&buffer);
result = NULL;
result_size = 0;
return false;
}

bool success = GetThumbnailFromSurface(buffer, dest_width, dest_height, dest_width * sizeof(uint32_t), image, result, result_size);
delete[] buffer;
av_free(&buffer);

if (!success)
{
Expand Down Expand Up @@ -245,7 +246,7 @@ bool CPicture::CacheTexture(uint8_t *pixels, uint32_t width, uint32_t height, ui

// create a buffer large enough for the resulting image
GetScale(width, height, dest_width, dest_height);
uint32_t *buffer = new uint32_t[dest_width * dest_height];
uint32_t *buffer = (uint32_t*) av_malloc(dest_width * dest_height);
if (buffer)
{
if (ScaleImage(pixels, width, height, pitch,
Expand All @@ -257,7 +258,7 @@ bool CPicture::CacheTexture(uint8_t *pixels, uint32_t width, uint32_t height, ui
success = CreateThumbnailFromSurface((unsigned char*)buffer, dest_width, dest_height, dest_width * 4, dest);
}
}
delete[] buffer;
av_free(&buffer);
}
return success;
}
Expand Down Expand Up @@ -297,7 +298,7 @@ bool CPicture::CreateTiledThumb(const std::vector<std::string> &files, const std
GetScale(texture->GetWidth(), texture->GetHeight(), width, height);

// scale appropriately
uint32_t *scaled = new uint32_t[width * height];
uint32_t *scaled = (uint32_t*) av_malloc(width * height);
if (ScaleImage(texture->GetPixels(), texture->GetWidth(), texture->GetHeight(), texture->GetPitch(),
(uint8_t *)scaled, width, height, width * 4))
{
Expand All @@ -317,7 +318,7 @@ bool CPicture::CreateTiledThumb(const std::vector<std::string> &files, const std
}
}
}
delete[] scaled;
av_free(&scaled);
}
delete texture;
}
Expand Down

0 comments on commit aadfc21

Please sign in to comment.