Image base classes, hide some internal complexity
This commit is contained in:
@@ -74,20 +74,15 @@ int32_t ScoreLut(const Image<X, Y, RgbColor>& image, const LutBase& lut) {
|
|||||||
Array<int32_t, kColorCheckerSrgb.size()> diff;
|
Array<int32_t, kColorCheckerSrgb.size()> diff;
|
||||||
diff.fill(INT32_MAX);
|
diff.fill(INT32_MAX);
|
||||||
|
|
||||||
for (int32_t y = 0; y < Y; ++y) {
|
image.ForEach([&diff, &lut](const RgbColor& color) {
|
||||||
const auto& row = image.at(y);
|
const auto pixel = lut.MapColor(color);
|
||||||
|
for (int32_t cc = 0; cc < kColorCheckerSrgb.ssize(); ++cc) {
|
||||||
for (int32_t x = 0; x < X; ++x) {
|
auto pixel_diff = pixel.AbsDiff(kColorCheckerSrgb.at(cc));
|
||||||
const auto pixel = lut.MapColor(row.at(x));
|
if (pixel_diff < diff.at(cc)) {
|
||||||
|
diff.at(cc) = pixel_diff;
|
||||||
for (int32_t cc = 0; cc < kColorCheckerSrgb.ssize(); ++cc) {
|
|
||||||
auto pixel_diff = pixel.AbsDiff(kColorCheckerSrgb.at(cc));
|
|
||||||
if (pixel_diff < diff.at(cc)) {
|
|
||||||
diff.at(cc) = pixel_diff;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
return std::accumulate(diff.begin(), diff.end(), 0);
|
return std::accumulate(diff.begin(), diff.end(), 0);
|
||||||
}
|
}
|
||||||
|
|||||||
28
image.h
28
image.h
@@ -9,11 +9,27 @@
|
|||||||
#include "color.h"
|
#include "color.h"
|
||||||
#include "coord.h"
|
#include "coord.h"
|
||||||
|
|
||||||
|
class ImageBase {};
|
||||||
|
|
||||||
|
|
||||||
|
template <class C>
|
||||||
|
class ImageColorBase : public ImageBase {
|
||||||
|
public:
|
||||||
|
ImageColorBase() = default;
|
||||||
|
ImageColorBase(const ImageColorBase<C>&) = default;
|
||||||
|
virtual ~ImageColorBase() = default;
|
||||||
|
|
||||||
|
virtual void ForEach(std::function<void(const C&)> callback) const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
template <int32_t X, int32_t Y, class C>
|
template <int32_t X, int32_t Y, class C>
|
||||||
class Image : public Array<Array<C, X>, Y> {
|
class Image : public Array<Array<C, X>, Y>, ImageColorBase<C> {
|
||||||
public:
|
public:
|
||||||
constexpr const C& GetPixel(const Coord<2>& coord) const;
|
constexpr const C& GetPixel(const Coord<2>& coord) const;
|
||||||
|
|
||||||
|
void ForEach(std::function<void(const C&)> callback) const override;
|
||||||
|
|
||||||
void SetPixel(const Coord<2>& coord, const C& color);
|
void SetPixel(const Coord<2>& coord, const C& color);
|
||||||
void DrawXLine(const Coord<2>& start, const C& color, int32_t length);
|
void DrawXLine(const Coord<2>& start, const C& color, int32_t length);
|
||||||
void DrawYLine(const Coord<2>& start, const C& color, int32_t length);
|
void DrawYLine(const Coord<2>& start, const C& color, int32_t length);
|
||||||
@@ -28,6 +44,16 @@ constexpr const C& Image<X, Y, C>::GetPixel(const Coord<2>& coord) const {
|
|||||||
return this->at(coord.at(1)).at(coord.at(0));
|
return this->at(coord.at(1)).at(coord.at(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <int32_t X, int32_t Y, class C>
|
||||||
|
void Image<X, Y, C>::ForEach(std::function<void(const C&)> callback) const {
|
||||||
|
for (int32_t y = 0; y < Y; ++y) {
|
||||||
|
const auto& row = this->at(y);
|
||||||
|
for (int32_t x = 0; x < X; ++x) {
|
||||||
|
callback(row.at(x));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template <int32_t X, int32_t Y, class C>
|
template <int32_t X, int32_t Y, class C>
|
||||||
void Image<X, Y, C>::SetPixel(const Coord<2>& coord, const C& color) {
|
void Image<X, Y, C>::SetPixel(const Coord<2>& coord, const C& color) {
|
||||||
if (coord.at(0) >= X || coord.at(1) >= Y) {
|
if (coord.at(0) >= X || coord.at(1) >= Y) {
|
||||||
|
|||||||
Reference in New Issue
Block a user