diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 18:07:22 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 18:07:22 +0000 |
commit | c04dcc2e7d834218ef2d4194331e383402495ae1 (patch) | |
tree | 7333e38d10d75386e60f336b80c2443c1166031d /xbmc/pictures/PictureScalingAlgorithm.cpp | |
parent | Initial commit. (diff) | |
download | kodi-c04dcc2e7d834218ef2d4194331e383402495ae1.tar.xz kodi-c04dcc2e7d834218ef2d4194331e383402495ae1.zip |
Adding upstream version 2:20.4+dfsg.upstream/2%20.4+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'xbmc/pictures/PictureScalingAlgorithm.cpp')
-rw-r--r-- | xbmc/pictures/PictureScalingAlgorithm.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/xbmc/pictures/PictureScalingAlgorithm.cpp b/xbmc/pictures/PictureScalingAlgorithm.cpp new file mode 100644 index 0000000..65cfcd9 --- /dev/null +++ b/xbmc/pictures/PictureScalingAlgorithm.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2015-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include <algorithm> + +extern "C" { +#include <libswscale/swscale.h> +} + +#include "PictureScalingAlgorithm.h" +#include "utils/StringUtils.h" + +CPictureScalingAlgorithm::Algorithm CPictureScalingAlgorithm::Default = CPictureScalingAlgorithm::Bicubic; + +CPictureScalingAlgorithm::AlgorithmMap CPictureScalingAlgorithm::m_algorithms = { + { FastBilinear, { "fast_bilinear", SWS_FAST_BILINEAR } }, + { Bilinear, { "bilinear", SWS_BILINEAR } }, + { Bicubic, { "bicubic", SWS_BICUBIC } }, + { Experimental, { "experimental", SWS_X } }, + { NearestNeighbor, { "nearest_neighbor", SWS_POINT } }, + { AveragingArea, { "averaging_area", SWS_AREA } }, + { Bicublin, { "bicublin", SWS_BICUBLIN } }, + { Gaussian, { "gaussian", SWS_GAUSS } }, + { Sinc, { "sinc", SWS_SINC } }, + { Lanczos, { "lanczos", SWS_LANCZOS } }, + { BicubicSpline, { "bicubic_spline", SWS_SPLINE } }, +}; + +CPictureScalingAlgorithm::Algorithm CPictureScalingAlgorithm::FromString(const std::string& scalingAlgorithm) +{ + const auto& algorithm = std::find_if(m_algorithms.begin(), m_algorithms.end(), + [&scalingAlgorithm](const std::pair<Algorithm, ScalingAlgorithm>& algo) { return StringUtils::EqualsNoCase(algo.second.name, scalingAlgorithm); }); + if (algorithm != m_algorithms.end()) + return algorithm->first; + + return NoAlgorithm; +} + +std::string CPictureScalingAlgorithm::ToString(Algorithm scalingAlgorithm) +{ + const auto& algorithm = m_algorithms.find(scalingAlgorithm); + if (algorithm != m_algorithms.end()) + return algorithm->second.name; + + return ""; +} + +int CPictureScalingAlgorithm::ToSwscale(const std::string& scalingAlgorithm) +{ + return ToSwscale(FromString(scalingAlgorithm)); +} + +int CPictureScalingAlgorithm::ToSwscale(Algorithm scalingAlgorithm) +{ + const auto& algorithm = m_algorithms.find(scalingAlgorithm); + if (algorithm != m_algorithms.end()) + return algorithm->second.swscale; + + return ToSwscale(Default); +} |