| 1 |
/* |
| 2 |
* Copyright (C) 2015-2018 Team Kodi |
| 3 |
* This file is part of Kodi - https://kodi.tv |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSES/README.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#include <algorithm> |
| 10 |
|
| 11 |
extern "C" { |
| 12 |
#include <libswscale/swscale.h> |
| 13 |
} |
| 14 |
|
| 15 |
#include "PictureScalingAlgorithm.h" |
| 16 |
#include "utils/StringUtils.h" |
| 17 |
|
| 18 |
CPictureScalingAlgorithm::Algorithm CPictureScalingAlgorithm::Default = CPictureScalingAlgorithm::Bicubic; |
| 19 |
|
| 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 } }, |
| 32 |
}; |
| 33 |
|
| 34 |
CPictureScalingAlgorithm::Algorithm CPictureScalingAlgorithm::FromString(const std::string& scalingAlgorithm) |
| 35 |
{ |
| 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; |
| 40 |
|
| 41 |
return NoAlgorithm; |
| 42 |
} |
| 43 |
|
| 44 |
std::string CPictureScalingAlgorithm::ToString(Algorithm scalingAlgorithm) |
| 45 |
{ |
| 46 |
const auto& algorithm = m_algorithms.find(scalingAlgorithm); |
| 47 |
if (algorithm != m_algorithms.end()) |
| 48 |
return algorithm->second.name; |
| 49 |
|
| 50 |
return ""; |
| 51 |
} |
| 52 |
|
| 53 |
int CPictureScalingAlgorithm::ToSwscale(const std::string& scalingAlgorithm) |
| 54 |
{ |
| 55 |
return ToSwscale(FromString(scalingAlgorithm)); |
| 56 |
} |
| 57 |
|
| 58 |
int CPictureScalingAlgorithm::ToSwscale(Algorithm scalingAlgorithm) |
| 59 |
{ |
| 60 |
const auto& algorithm = m_algorithms.find(scalingAlgorithm); |
| 61 |
if (algorithm != m_algorithms.end()) |
| 62 |
return algorithm->second.swscale; |
| 63 |
|
| 64 |
return ToSwscale(Default); |
| 65 |
} |