Colors more accurate

This commit is contained in:
Christophe Meneboeuf 2021-02-14 14:22:31 +01:00
parent 3e0174c142
commit 57b9ef69f5
5 changed files with 25 additions and 10 deletions

Binary file not shown.

View File

@ -27,13 +27,14 @@
namespace RgbToHires {
constexpr std::size_t SHIFT = sizeof(Magick::Quantum)*8 - 8;
#define WHITE Magick::Color{"white"}
#define BLACK Magick::Color{"black"}
#define BLUE Magick::Color{"blue"}
#define GREEN Magick::Color{"green"}
#define ORANGE Magick::Color{"orange"}
#define VIOLET Magick::Color{"purple"}
#define WHITE Magick::Color{0xFF << SHIFT, 0xFF << SHIFT, 0xFF << SHIFT}
#define BLACK Magick::Color{0x00 << SHIFT, 0x00 << SHIFT, 0x00 << SHIFT}
#define BLUE Magick::Color{0x07 << SHIFT, 0xA8 << SHIFT, 0xE0 << SHIFT}
#define GREEN Magick::Color{0x43 << SHIFT, 0xC8 << SHIFT, 0x00 << SHIFT}
#define ORANGE Magick::Color{0xF9 << SHIFT, 0x56 << SHIFT,0x1D << SHIFT}
#define VIOLET Magick::Color{0xBB << SHIFT, 0x36 << SHIFT, 0xFF << SHIFT}
constexpr unsigned WIDTH = 140u;

View File

@ -156,7 +156,7 @@ namespace RgbToHires
rgba8Bits_t{0x07,0xA8,0xE0, 0xFF}, // blue
rgba8Bits_t{0xF9,0x56,0x1D, 0xFF}, // orange
rgba8Bits_t{0x43,0xC8,0x00, 0xFF}, // green
rgba8Bits_t{0xBB,0x36,0xFF, 0xFF}, // black
rgba8Bits_t{0xBB,0x36,0xFF, 0xFF}, // violet
rgba8Bits_t{0x80,0x80,0x80, 0xFF} // dummy as AppleWin's code can overflow :( (no time to correct it)
};

View File

@ -90,9 +90,23 @@ namespace RgbToHires {
double ImageQuantized::Distance(const Magick::Color& color1, const Magick::Color& color2)
{
return pow(color1.redQuantum() - color2.redQuantum(), 2) \
+ pow(color1.greenQuantum() - color2.greenQuantum(), 2) \
+ pow(color1.blueQuantum() - color2.blueQuantum(), 2);
static constexpr double LUMA_RED = 0.299;
static constexpr double LUMA_GREEN = 0.587;
static constexpr double LUMA_BLUE = 0.114;
const auto y1 = LUMA_RED * color1.redQuantum() + LUMA_GREEN * color1.greenQuantum() + LUMA_BLUE * color1.blueQuantum();
const auto u1 = 0.492 * (color1.blueQuantum() - y1);
const auto v1 = 0.877 * (color1.redQuantum() - y1);
const auto y2 = LUMA_RED * color2.redQuantum() + LUMA_GREEN * color2.greenQuantum() + LUMA_BLUE * color2.blueQuantum();
const auto u2 = 0.492 * (color2.blueQuantum() - y2);
const auto v2 = 0.877 * (color2.redQuantum() - y2);
const auto dy = (y1 - y2);
const auto du = (u1 - u2);
const auto dv = (v1 - v2);
return (dy * dy + du * du + dv * dv);
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 4.1 KiB