[filesystem][SpecialProtocol] Removed assert from GetPath
[xbmc.git] / xbmc / pictures / PictureScalingAlgorithm.cpp
blob65cfcd9c7653ba362323569933552265a316b54a
1 /*
2 * Copyright (C) 2015-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include <algorithm>
11 extern "C" {
12 #include <libswscale/swscale.h>
15 #include "PictureScalingAlgorithm.h"
16 #include "utils/StringUtils.h"
18 CPictureScalingAlgorithm::Algorithm CPictureScalingAlgorithm::Default = CPictureScalingAlgorithm::Bicubic;
20 CPictureScalingAlgorithm::AlgorithmMap CPictureScalingAlgorithm::m_algorithms = {
21 { FastBilinear, { "fast_bilinear", SWS_FAST_BILINEAR } },
22 { Bilinear, { "bilinear", SWS_BILINEAR } },
23 { Bicubic, { "bicubic", SWS_BICUBIC } },
24 { Experimental, { "experimental", SWS_X } },
25 { NearestNeighbor, { "nearest_neighbor", SWS_POINT } },
26 { AveragingArea, { "averaging_area", SWS_AREA } },
27 { Bicublin, { "bicublin", SWS_BICUBLIN } },
28 { Gaussian, { "gaussian", SWS_GAUSS } },
29 { Sinc, { "sinc", SWS_SINC } },
30 { Lanczos, { "lanczos", SWS_LANCZOS } },
31 { BicubicSpline, { "bicubic_spline", SWS_SPLINE } },
34 CPictureScalingAlgorithm::Algorithm CPictureScalingAlgorithm::FromString(const std::string& scalingAlgorithm)
36 const auto& algorithm = std::find_if(m_algorithms.begin(), m_algorithms.end(),
37 [&scalingAlgorithm](const std::pair<Algorithm, ScalingAlgorithm>& algo) { return StringUtils::EqualsNoCase(algo.second.name, scalingAlgorithm); });
38 if (algorithm != m_algorithms.end())
39 return algorithm->first;
41 return NoAlgorithm;
44 std::string CPictureScalingAlgorithm::ToString(Algorithm scalingAlgorithm)
46 const auto& algorithm = m_algorithms.find(scalingAlgorithm);
47 if (algorithm != m_algorithms.end())
48 return algorithm->second.name;
50 return "";
53 int CPictureScalingAlgorithm::ToSwscale(const std::string& scalingAlgorithm)
55 return ToSwscale(FromString(scalingAlgorithm));
58 int CPictureScalingAlgorithm::ToSwscale(Algorithm scalingAlgorithm)
60 const auto& algorithm = m_algorithms.find(scalingAlgorithm);
61 if (algorithm != m_algorithms.end())
62 return algorithm->second.swscale;
64 return ToSwscale(Default);