Repository: xbmc/xbmc
File: xbmc/pictures/Picture.cpp (C++)

Code before:
  { // no orientation needed
    dest_width = width;
    dest_height = height;
    return CreateThumbnailFromSurface(pixels, width, height, pitch, dest);
  }
  return false;
}

std::unique_ptr<CTexture> CPicture::CreateTiledThumb(const std::vector<std::string>& files)
{
  if (!files.size())
    return {};

  unsigned int num_across =
      static_cast<unsigned int>(std::ceil(std::sqrt(static_cast<float>(files.size()))));
  unsigned int num_down = (files.size() + num_across - 1) / num_across;

  unsigned int imageRes = CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_imageRes;

  unsigned int tile_width = imageRes / num_across;
  unsigned int tile_height = imageRes / num_down;
  unsigned int tile_gap = 1;
  bool success = false; // Flag that we at least had one successful image processed

  // create a buffer for the resulting thumb
  std::unique_ptr<uint32_t[]> buffer(new uint32_t[imageRes * imageRes]);
  if (!buffer)
    return {};
  for (unsigned int i = 0; i < files.size(); ++i)
  {
    int x = i % num_across;
    int y = i / num_across;
    // load in the image
    unsigned int width = tile_width - 2 * tile_gap, height = tile_height - 2 * tile_gap;
    std::unique_ptr<CTexture> texture = CTexture::LoadFromFile(files[i], width, height, true);
    if (texture && texture->GetWidth() && texture->GetHeight())
    {
      GetScale(texture->GetWidth(), texture->GetHeight(), width, height);

      // scale appropriately
      std::unique_ptr<uint32_t[]> scaled(new uint32_t[width * height]);
      if (ScaleImage(texture->GetPixels(), texture->GetWidth(), texture->GetHeight(),
                     texture->GetPitch(), AV_PIX_FMT_BGRA, reinterpret_cast<uint8_t*>(scaled.get()),
                     width, height, width * 4, AV_PIX_FMT_BGRA))
      {
        unsigned int stridePixels{width};
        uint32_t* scaledL = scaled.get();
        if (!texture->GetOrientation() ||
            OrientateImage(scaledL, width, height, texture->GetOrientation(), stridePixels))
        {
          success = true;

Review comment (suggestion):
Good job with this change. The only other step would be to use `std::make_unique`. That way, the pointer is hidden entirely, which should be our goal.

Code after:
  { // no orientation needed
    dest_width = width;
    dest_height = height;
    return CreateThumbnailFromSurface(pixels, width, height, pitch, dest);
  }
  return false;
}

std::unique_ptr<CTexture> CPicture::CreateTiledThumb(const std::vector<std::string>& files)
{
  if (!files.size())
    return {};

  unsigned int num_across =
      static_cast<unsigned int>(std::ceil(std::sqrt(static_cast<float>(files.size()))));
  unsigned int num_down = (files.size() + num_across - 1) / num_across;

  unsigned int imageRes = CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_imageRes;

  unsigned int tile_width = imageRes / num_across;
  unsigned int tile_height = imageRes / num_down;
  unsigned int tile_gap = 1;
  bool success = false; // Flag that we at least had one successful image processed

  // create a buffer for the resulting thumb
  std::unique_ptr<uint32_t[]> buffer = std::make_unique<uint32_t[]>(imageRes * imageRes);
  if (!buffer)
    return {};
  for (unsigned int i = 0; i < files.size(); ++i)
  {
    int x = i % num_across;
    int y = i / num_across;
    // load in the image
    unsigned int width = tile_width - 2 * tile_gap, height = tile_height - 2 * tile_gap;
    std::unique_ptr<CTexture> texture = CTexture::LoadFromFile(files[i], width, height, true);
    if (texture && texture->GetWidth() && texture->GetHeight())
    {
      GetScale(texture->GetWidth(), texture->GetHeight(), width, height);

      // scale appropriately
      std::unique_ptr<uint32_t[]> scaled = std::make_unique<uint32_t[]>(width * height);
      if (ScaleImage(texture->GetPixels(), texture->GetWidth(), texture->GetHeight(),
                     texture->GetPitch(), AV_PIX_FMT_BGRA, reinterpret_cast<uint8_t*>(scaled.get()),
                     width, height, width * 4, AV_PIX_FMT_BGRA))
      {
        unsigned int stridePixels{width};
        uint32_t* scaledL = scaled.get();
        if (!texture->GetOrientation() ||
            OrientateImage(scaledL, width, height, texture->GetOrientation(), stridePixels))
        {
          success = true;