-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new enum mapper and first conversion to rgb test
- Loading branch information
1 parent
e9bd096
commit 42ea197
Showing
3 changed files
with
167 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* This file is part of YUView - The YUV player with advanced analytics toolset | ||
* <https://github.com/IENT/YUView> | ||
* Copyright (C) 2015 Institut für Nachrichtentechnik, RWTH Aachen University, GERMANY | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* In addition, as a special exception, the copyright holders give | ||
* permission to link the code of portions of this program with the | ||
* OpenSSL library under certain conditions as described in each | ||
* individual source file, and distribute linked combinations including | ||
* the two. | ||
* | ||
* You must obey the GNU General Public License in all respects for all | ||
* of the code used other than OpenSSL. If you modify file(s) with this | ||
* exception, you may extend this exception to your version of the | ||
* file(s), but you are not obligated to do so. If you do not wish to do | ||
* so, delete this exception statement from your version. If you delete | ||
* this exception statement from all source files in the program, then | ||
* also delete it here. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <algorithm> | ||
#include <array> | ||
#include <cuchar> | ||
|
||
template <class T, size_t N> struct NewEnumMapper | ||
{ | ||
using VALUE_AND_NAME = std::pair<T, const char *>; | ||
|
||
template <typename... Args> constexpr NewEnumMapper(Args... args) | ||
{ | ||
constexpr auto nrArguments = sizeof...(Args); | ||
static_assert(nrArguments == N); | ||
this->addElementsRecursively(0, args...); | ||
} | ||
|
||
constexpr const char *getName(const T value) const | ||
{ | ||
const auto it = std::find(this->items.begin(), this->items.end(), value); | ||
if (it == this->items.end()) | ||
throw std::logic_error( | ||
"The given type T was not registered in the mapper. All possible enums must be mapped."); | ||
const auto index = std::distance(this->items.begin(), it); | ||
return this->names.at(index); | ||
} | ||
|
||
constexpr const std::array<T, N> &getItems() const { return this->items; } | ||
|
||
private: | ||
constexpr void addElementsRecursively(const std::size_t index) {}; | ||
|
||
template <typename TArg, typename... Args> | ||
constexpr void addElementsRecursively(const std::size_t index, TArg first, Args... args) | ||
{ | ||
static_assert(std::is_same<VALUE_AND_NAME, TArg>()); | ||
|
||
const auto [value, name] = first; | ||
this->items[index] = value; | ||
this->names[index] = name; | ||
|
||
addElementsRecursively(index + 1, args...); | ||
} | ||
|
||
std::array<T, N> items{}; | ||
std::array<const char *, N> names{}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* This file is part of YUView - The YUV player with advanced analytics toolset | ||
* <https://github.com/IENT/YUView> | ||
* Copyright (C) 2015 Institut für Nachrichtentechnik, RWTH Aachen University, GERMANY | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* In addition, as a special exception, the copyright holders give | ||
* permission to link the code of portions of this program with the | ||
* OpenSSL library under certain conditions as described in each | ||
* individual source file, and distribute linked combinations including | ||
* the two. | ||
* | ||
* You must obey the GNU General Public License in all respects for all | ||
* of the code used other than OpenSSL. If you modify file(s) with this | ||
* exception, you may extend this exception to your version of the | ||
* file(s), but you are not obligated to do so. If you do not wish to do | ||
* so, delete this exception statement from your version. If you delete | ||
* this exception statement from all source files in the program, then | ||
* also delete it here. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "gtest/gtest.h" | ||
|
||
#include <common/NewEnumMapper.h> | ||
#include <video/rgb/ConversionRGB.h> | ||
|
||
using ::testing::Combine; | ||
using ::testing::TestWithParam; | ||
using ::testing::Values; | ||
using ::testing::ValuesIn; | ||
|
||
using video::Endianness; | ||
using BitDepth = int; | ||
using video::rgb::AlphaMode; | ||
using video::rgb::AlphaModeMapper; | ||
|
||
namespace | ||
{ | ||
|
||
constexpr auto ALL_MODES_MAPPER = | ||
NewEnumMapper<AlphaMode, 3>(std::make_pair(AlphaMode::First, "First"), | ||
std::make_pair(AlphaMode::Last, "Last"), | ||
std::make_pair(AlphaMode::None, "None")); | ||
|
||
constexpr auto EndianessMapper = NewEnumMapper<Endianness, 2>( | ||
std::make_pair(Endianness::Little, "Little"), std::make_pair(Endianness::Big, "Big")); | ||
|
||
using TestParameters = std::tuple<Endianness, BitDepth, AlphaMode>; | ||
|
||
class ConversionRGBTest : public TestWithParam<TestParameters> | ||
{ | ||
}; | ||
|
||
std::string getTestName(const testing::TestParamInfo<TestParameters> &testParam) | ||
{ | ||
const auto [endianess, bitDepth, alphaMode] = testParam.param; | ||
std::stringstream s; | ||
s << "Endianess_" << EndianessMapper.getName(endianess) << "_"; | ||
s << "BitDepth_" << bitDepth << "_"; | ||
s << "AlphaMode_" << ALL_MODES_MAPPER.getName(alphaMode) << "_"; | ||
return s.str(); | ||
} | ||
|
||
TEST_P(ConversionRGBTest, TestConversion) | ||
{ | ||
std::cout << "Example Test Param: "; | ||
} | ||
|
||
INSTANTIATE_TEST_SUITE_P(VideoRGB, | ||
ConversionRGBTest, | ||
Combine(ValuesIn(EndianessMapper.getItems()), | ||
Values(8, 10, 12), | ||
ValuesIn(ALL_MODES_MAPPER.getItems())), | ||
getTestName); | ||
|
||
} // namespace |