Code cleanup, switch to MinimalLut3d for starters
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -34,3 +34,4 @@
|
|||||||
# Custom
|
# Custom
|
||||||
piphoto
|
piphoto
|
||||||
test.*
|
test.*
|
||||||
|
*.swp
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
#include "color.h"
|
#include "color.h"
|
||||||
|
#include "colors.h"
|
||||||
#include "coord.h"
|
#include "coord.h"
|
||||||
#include "image.h"
|
#include "image.h"
|
||||||
#include "lut.h"
|
#include "lut.h"
|
||||||
@@ -38,7 +39,7 @@ constexpr std::array<Color, 24> kColorCheckerSrgb = {{
|
|||||||
}};
|
}};
|
||||||
|
|
||||||
template <uint32_t X, uint32_t Y>
|
template <uint32_t X, uint32_t Y>
|
||||||
std::array<Coord, kColorCheckerSrgb.size()> ColorCheckerClosest(const Image<X, Y>& image) {
|
std::array<Coord, kColorCheckerSrgb.size()> FindClosest(const Image<X, Y>& image) {
|
||||||
std::array<Coord, kColorCheckerSrgb.size()> closest;
|
std::array<Coord, kColorCheckerSrgb.size()> closest;
|
||||||
std::array<uint32_t, kColorCheckerSrgb.size()> diff;
|
std::array<uint32_t, kColorCheckerSrgb.size()> diff;
|
||||||
diff.fill(UINT32_MAX);
|
diff.fill(UINT32_MAX);
|
||||||
@@ -61,3 +62,17 @@ std::array<Coord, kColorCheckerSrgb.size()> ColorCheckerClosest(const Image<X, Y
|
|||||||
|
|
||||||
return closest;
|
return closest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <uint32_t X, uint32_t Y>
|
||||||
|
void HighlightClosest(Image<X, Y>* image) {
|
||||||
|
auto closest = FindClosest(*image);
|
||||||
|
for (uint32_t cc = 0; cc < kColorCheckerSrgb.size(); ++cc) {
|
||||||
|
const auto& coord = closest.at(cc);
|
||||||
|
const auto& color = kColorCheckerSrgb.at(cc);
|
||||||
|
image->DrawSquare({std::max(5U, coord.x) - 5, std::max(5U, coord.y) - 5}, kBlack, 10);
|
||||||
|
image->DrawSquare({std::max(6U, coord.x) - 6, std::max(6U, coord.y) - 6}, color, 12);
|
||||||
|
image->DrawSquare({std::max(7U, coord.x) - 7, std::max(7U, coord.y) - 7}, color, 14);
|
||||||
|
image->DrawSquare({std::max(8U, coord.x) - 8, std::max(8U, coord.y) - 8}, color, 16);
|
||||||
|
image->DrawSquare({std::max(9U, coord.x) - 9, std::max(9U, coord.y) - 9}, kWhite, 18);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
3
lut.h
3
lut.h
@@ -24,6 +24,9 @@ class Lut3d : public std::array<std::array<std::array<Color, B>, G>, R> {
|
|||||||
constexpr static uint32_t BlockSize(uint32_t points);
|
constexpr static uint32_t BlockSize(uint32_t points);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Minimum size LUT
|
||||||
|
typedef Lut3d<2, 2, 2> MinimalLut3d;
|
||||||
|
|
||||||
template <uint32_t R, uint32_t G, uint32_t B>
|
template <uint32_t R, uint32_t G, uint32_t B>
|
||||||
std::unique_ptr<Lut3d<R, G, B>> Lut3d<R, G, B>::Identity() {
|
std::unique_ptr<Lut3d<R, G, B>> Lut3d<R, G, B>::Identity() {
|
||||||
auto ret = std::make_unique<Lut3d<R, G, B>>();
|
auto ret = std::make_unique<Lut3d<R, G, B>>();
|
||||||
|
|||||||
20
piphoto.cc
20
piphoto.cc
@@ -1,30 +1,14 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "color.h"
|
|
||||||
#include "colorchecker.h"
|
#include "colorchecker.h"
|
||||||
#include "colors.h"
|
|
||||||
#include "coord.h"
|
|
||||||
#include "image.h"
|
|
||||||
#include "lut.h"
|
#include "lut.h"
|
||||||
#include "piraw.h"
|
#include "piraw.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
auto image = PiRaw2::FromJpeg(ReadFile("test.jpg"));
|
auto image = PiRaw2::FromJpeg(ReadFile("test.jpg"));
|
||||||
|
auto lut = MinimalLut3d::Identity();
|
||||||
auto lut = ColorCheckerLut3d::Identity();
|
|
||||||
auto image2 = lut->MapImage(*image);
|
auto image2 = lut->MapImage(*image);
|
||||||
|
HighlightClosest(image2.get());
|
||||||
auto closest = ColorCheckerClosest(*image2);
|
|
||||||
for (uint32_t cc = 0; cc < kColorCheckerSrgb.size(); ++cc) {
|
|
||||||
const auto& coord = closest.at(cc);
|
|
||||||
const auto& color = kColorCheckerSrgb.at(cc);
|
|
||||||
std::cout << cc << ": " << coord << " difference=" << color.Difference(image2->GetPixel(coord)) << std::endl;
|
|
||||||
image2->DrawSquare({std::max(5U, coord.x) - 5, std::max(5U, coord.y) - 5}, kBlack, 10);
|
|
||||||
image2->DrawSquare({std::max(6U, coord.x) - 6, std::max(6U, coord.y) - 6}, color, 12);
|
|
||||||
image2->DrawSquare({std::max(7U, coord.x) - 7, std::max(7U, coord.y) - 7}, color, 14);
|
|
||||||
image2->DrawSquare({std::max(8U, coord.x) - 8, std::max(8U, coord.y) - 8}, color, 16);
|
|
||||||
image2->DrawSquare({std::max(9U, coord.x) - 9, std::max(9U, coord.y) - 9}, kWhite, 18);
|
|
||||||
}
|
|
||||||
WriteFile("test.png", image2->ToPng());
|
WriteFile("test.png", image2->ToPng());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user