From 9fb32eb6185e0bbf358d279a267d187c266b6656 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sat, 4 Mar 2017 09:39:50 -0500 Subject: Changed to RGB color interpolation It's way less accurate but actually kind of looks better. --- palette.cpp | 40 +++++++++------------------------------- 1 file changed, 9 insertions(+), 31 deletions(-) (limited to 'palette.cpp') diff --git a/palette.cpp b/palette.cpp index 4135756..e198c81 100644 --- a/palette.cpp +++ b/palette.cpp @@ -45,38 +45,16 @@ palette::palette(std::vector foci) int section = std::floor(static_cast(i) / sectionSize); double interpolation = (static_cast(i) / sectionSize) - section; - Magick::ColorHSL interpLeft = foci[section]; - Magick::ColorHSL interpRight = foci[section+1]; - - double newHue; - double diff = interpRight.hue() - interpLeft.hue(); - if (diff < 0) - { - std::swap(interpLeft, interpRight); - - diff = -diff; - interpolation = 1 - interpolation; - } + Magick::ColorRGB interpLeft = foci[section]; + Magick::ColorRGB interpRight = foci[section+1]; - if (diff > 0.5) - { - newHue = 1.0 + interpLeft.hue() - * (interpolation * (interpRight.hue() - interpLeft.hue() - 1.0)); - - if (newHue > 1.0) - { - newHue -= 1.0; - } - } else { - newHue = interpLeft.hue() + interpolation * diff; - } - - Magick::ColorHSL interpolated( - newHue, - ((1.0 - interpolation) * interpLeft.saturation()) - + (interpolation * interpRight.saturation()), - ((1.0 - interpolation) * interpLeft.luminosity()) - + (interpolation * interpRight.luminosity())); + Magick::ColorRGB interpolated( + ((1.0 - interpolation) * interpLeft.red()) + + (interpolation * interpRight.red()), + ((1.0 - interpolation) * interpLeft.green()) + + (interpolation * interpRight.green()), + ((1.0 - interpolation) * interpLeft.blue()) + + (interpolation * interpRight.blue())); gradient_.push_back(interpolated); } -- cgit 1.4.1