From 6ff79273522a44c2c3528a2f12b02eeb11baf2af Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Tue, 8 Aug 2017 23:14:11 -0700 Subject: [PATCH] Code cleanup, switch to MinimalLut3d for starters --- .gitignore | 1 + colorchecker.h | 17 ++++++++++++++++- lut.h | 3 +++ piphoto.cc | 20 ++------------------ 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 6b93b6d..36e2ec5 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,4 @@ # Custom piphoto test.* +*.swp diff --git a/colorchecker.h b/colorchecker.h index 713ec4c..a3a7761 100644 --- a/colorchecker.h +++ b/colorchecker.h @@ -3,6 +3,7 @@ #include #include "color.h" +#include "colors.h" #include "coord.h" #include "image.h" #include "lut.h" @@ -38,7 +39,7 @@ constexpr std::array kColorCheckerSrgb = {{ }}; template -std::array ColorCheckerClosest(const Image& image) { +std::array FindClosest(const Image& image) { std::array closest; std::array diff; diff.fill(UINT32_MAX); @@ -61,3 +62,17 @@ std::array ColorCheckerClosest(const Image +void HighlightClosest(Image* 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); + } +} diff --git a/lut.h b/lut.h index 1f8e06c..53e96b9 100644 --- a/lut.h +++ b/lut.h @@ -24,6 +24,9 @@ class Lut3d : public std::array, G>, R> { constexpr static uint32_t BlockSize(uint32_t points); }; +// Minimum size LUT +typedef Lut3d<2, 2, 2> MinimalLut3d; + template std::unique_ptr> Lut3d::Identity() { auto ret = std::make_unique>(); diff --git a/piphoto.cc b/piphoto.cc index 4491c86..9e0f159 100644 --- a/piphoto.cc +++ b/piphoto.cc @@ -1,30 +1,14 @@ #include -#include "color.h" #include "colorchecker.h" -#include "colors.h" -#include "coord.h" -#include "image.h" #include "lut.h" #include "piraw.h" #include "util.h" int main() { auto image = PiRaw2::FromJpeg(ReadFile("test.jpg")); - - auto lut = ColorCheckerLut3d::Identity(); + auto lut = MinimalLut3d::Identity(); auto image2 = lut->MapImage(*image); - - 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); - } + HighlightClosest(image2.get()); WriteFile("test.png", image2->ToPng()); }