RawSpeed
fast raw decoding library
Loading...
Searching...
No Matches
BayerPhaseTest.cpp
Go to the documentation of this file.
1/*
2 RawSpeed - RAW file decoder.
3
4 Copyright (C) 2022 Roman Lebedev
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; withexpected even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19*/
20
21#include "common/BayerPhase.h"
22#include "adt/Optional.h"
24#include <array>
25#include <cassert>
26#include <map>
27#include <ostream>
28#include <tuple>
29#include <utility>
30#include <gtest/gtest.h>
31
35
36namespace rawspeed {
37
38static ::std::ostream& operator<<(::std::ostream& os, const BayerPhase p) {
39 switch (p) {
41 return os << "RGGB";
43 return os << "GRBG";
45 return os << "GBRG";
47 return os << "BGGR";
48 }
49 __builtin_unreachable();
50}
51
52} // namespace rawspeed
53
54namespace rawspeed_test {
55
56namespace {
57
62
63auto AllKnownBayerPhases = ::testing::Values(
65
66auto AllPossible2x2CFAs = ::testing::Combine(
68
70 ::testing::Combine(AllKnownBayerPhases, AllKnownBayerPhases);
71
82
83template <typename tuple_t>
84constexpr auto get_array_from_tuple(tuple_t&& tuple) {
85 constexpr auto get_array = [](auto&&... x) {
86 return std::array{std::forward<decltype(x)>(x)...};
87 };
88 return std::apply(get_array, std::forward<tuple_t>(tuple));
89}
90
92 : public ::testing::TestWithParam<
93 std::tuple<CFAColor, CFAColor, CFAColor, CFAColor>> {
94protected:
96 virtual void SetUp() {
97 in = get_array_from_tuple(GetParam());
98 if (auto it = KnownBayerCFAs.find(in); it != KnownBayerCFAs.end())
99 expected = it->second;
100 cfa.setCFA({2, 2}, in[0], in[1], in[2], in[3]);
101 }
102
103 std::array<CFAColor, 4> in;
106};
107
109TEST_P(BayerPhaseFromCFATest, getAsBayerPhaseTest) {
110 EXPECT_EQ(expected, rawspeed::getAsBayerPhase(cfa));
111}
112
113class BayerPhaseToCFATest : public ::testing::TestWithParam<BayerPhase> {
114protected:
116 virtual void SetUp() {
117 for (auto it : KnownBayerCFAs) {
118 if (it.second == GetParam()) {
119 in = it.second;
120 expected = it.first;
121 break;
122 }
123 }
124 assert(in.has_value());
125 }
126
128 std::array<CFAColor, 4> expected;
129};
130
133TEST_P(BayerPhaseToCFATest, getAsCFAColorsTest) {
134 EXPECT_EQ(expected, rawspeed::getAsCFAColors(*in));
135}
136
138 : public ::testing::TestWithParam<std::tuple<BayerPhase, BayerPhase>> {
139protected:
141 virtual void SetUp() {
142 src = std::get<0>(GetParam());
143 tgt = std::get<1>(GetParam());
144 }
145
148};
151
153
158
163
164::std::ostream& operator<<(::std::ostream& os, const AbstractElement* e) {
165 if (&e00 == e)
166 return os << "e00";
167 if (&e01 == e)
168 return os << "e01";
169 if (&e10 == e)
170 return os << "e10";
171 if (&e11 == e)
172 return os << "e11";
173 __builtin_unreachable();
174}
175
176const std::map<BayerPhase, std::array<const AbstractElement*, 4>>
178 {BayerPhase::RGGB, {&e00, &e01, &e10, &e11}}, // baseline
179 {BayerPhase::GRBG, {&e01, &e00, &e11, &e10}}, // swap columns
180 {BayerPhase::GBRG, {&e10, &e11, &e00, &e01}}, // swap rows
181 {BayerPhase::BGGR, {&e11, &e10, &e01, &e00}}, // swap rows and columns
182};
183
184TEST_P(BayerPhaseShifTest, applyPhaseShiftTest) {
185 EXPECT_EQ(
188}
189
191
196
201
202::std::ostream& operator<<(::std::ostream& os, const AbstractColorElement* e) {
203 if (&eR == e)
204 return os << "eR";
205 if (&eG0 == e)
206 return os << "eG0";
207 if (&eG1 == e)
208 return os << "eG1";
209 if (&eB == e)
210 return os << "eB";
211 __builtin_unreachable();
212}
213
214const std::map<BayerPhase, std::array<const AbstractColorElement*, 4>>
216 {BayerPhase::RGGB, {&eR, &eG0, &eG1, &eB}}, // baseline
217 {BayerPhase::GRBG, {&eG0, &eR, &eB, &eG1}}, // swap columns
218 {BayerPhase::GBRG, {&eG0, &eB, &eR, &eG1}}, // swap rows
219 {BayerPhase::BGGR, {&eB, &eG0, &eG1, &eR}}, // swap rows and columns
220};
221
222TEST_P(BayerPhaseShifTest, applyStablePhaseShiftTest) {
223 EXPECT_EQ(ExpectedBayerStablePhaseShifts.at(tgt),
225 ExpectedBayerStablePhaseShifts.at(src), src, tgt));
226}
227
228} // namespace
229
230} // namespace rawspeed_test
INSTANTIATE_TEST_SUITE_P(MD5Test, MD5Test, ::testing::ValuesIn(testCases))
TEST_P(MD5Test, CheckTestCaseSet)
Definition MD5Test.cpp:388
assert(dim.area() >=area)
dim x
Definition Common.cpp:50
const std::map< std::array< CFAColor, 4 >, BayerPhase > KnownBayerCFAs
const std::map< BayerPhase, std::array< const AbstractElement *, 4 > > ExpectedBayerPhaseShifts
::std::ostream & operator<<(::std::ostream &os, const AbstractElement *e)
const std::map< BayerPhase, std::array< const AbstractColorElement *, 4 > > ExpectedBayerStablePhaseShifts
std::array< CFAColor, 4 > getAsCFAColors(BayerPhase p)
Definition BayerPhase.h:97
Optional< BayerPhase > getAsBayerPhase(const ColorFilterArray &CFA)
Definition BayerPhase.h:131
std::array< T, 4 > applyPhaseShift(std::array< T, 4 > srcData, BayerPhase srcPhase, BayerPhase tgtPhase)
Definition BayerPhase.h:79
std::array< T, 4 > applyStablePhaseShift(std::array< T, 4 > srcData, BayerPhase srcPhase, BayerPhase tgtPhase)
Definition BayerPhase.h:107
static inline ::std::ostream & operator<<(::std::ostream &os, const T &b)