-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ColorConverter interface and RgbaToBgr impl
- Loading branch information
1 parent
3d5898d
commit 5c3dc92
Showing
12 changed files
with
95 additions
and
89 deletions.
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
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,20 @@ | ||
#ifndef PORYTILES_COLOR_COLOR_CONVERTER_H | ||
#define PORYTILES_COLOR_COLOR_CONVERTER_H | ||
|
||
#include <porytiles/Color/Color.h> | ||
|
||
namespace porytiles::color { | ||
|
||
/** | ||
* @brief Service interface for a converter service that transforms one Color implementation into a | ||
* different Color implementation. | ||
*/ | ||
class ColorConverter { | ||
public: | ||
virtual ~ColorConverter() = default; | ||
[[nodiscard]] virtual std::unique_ptr<Color> convert(const Color &input) const = 0; | ||
}; | ||
|
||
} // namespace porytiles::color | ||
|
||
#endif // PORYTILES_COLOR_COLOR_CONVERTER_H |
This file was deleted.
Oops, something went wrong.
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
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,20 @@ | ||
#ifndef PORYTILES_COLOR_RGBA_TO_BGR_H | ||
#define PORYTILES_COLOR_RGBA_TO_BGR_H | ||
|
||
#include <porytiles/Color/Color.h> | ||
#include <porytiles/Color/ColorConverter.h> | ||
|
||
namespace porytiles::color { | ||
|
||
/** | ||
* @brief Service interface for a converter service that transforms one Color implementation into a | ||
* different Color implementation. | ||
*/ | ||
class RgbaToBgr : public ColorConverter { | ||
public: | ||
[[nodiscard]] std::unique_ptr<Color> convert(const Color &input) const override; | ||
}; | ||
|
||
} // namespace porytiles::color | ||
|
||
#endif // PORYTILES_COLOR_RGBA_TO_BGR_H |
This file was deleted.
Oops, something went wrong.
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,14 @@ | ||
#include "porytiles/Color/RgbaToBgr.h" | ||
|
||
#include <porytiles/Color/Bgr15.h> | ||
#include <porytiles/Color/Rgba32.h> | ||
|
||
using namespace porytiles::color; | ||
|
||
std::unique_ptr<Color> RgbaToBgr::convert(const Color &input) const | ||
{ | ||
const auto &rgb = dynamic_cast<const Rgba32 &>(input); | ||
const Bgr15 bgr{rgb.computeRedComponent(), rgb.computeGreenComponent(), | ||
rgb.computeBlueComponent()}; | ||
return std::make_unique<Bgr15>(bgr); | ||
} |
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 was deleted.
Oops, something went wrong.
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,22 @@ | ||
#include <gtest/gtest.h> | ||
|
||
#include <porytiles/Color/Bgr15.h> | ||
#include <porytiles/Color/Rgba32.h> | ||
#include <porytiles/Color/RgbaToBgr.h> | ||
|
||
TEST(RgbaToBgrTest, RgbaToBgr) | ||
{ | ||
using namespace porytiles::color; | ||
|
||
const RgbaToBgr rgbaToBgr{}; | ||
|
||
const Rgba32 redRgba1{255, 0, 0}; | ||
const Bgr15 redBgr1{31}; | ||
const auto convertedBgr1 = rgbaToBgr.convert(redRgba1); | ||
EXPECT_EQ(dynamic_cast<const Bgr15 &>(*convertedBgr1), redBgr1); | ||
|
||
const Rgba32 redRgba2{250, 0, 0}; | ||
const auto convertedBgr2 = rgbaToBgr.convert(redRgba2); | ||
// should still match redBgr1 due to precision loss between formats | ||
EXPECT_EQ(dynamic_cast<const Bgr15 &>(*convertedBgr2), redBgr1); | ||
} |