summary refs log tree commit diff stats
path: root/palette.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'palette.cpp')
-rw-r--r--palette.cpp40
1 files changed, 9 insertions, 31 deletions
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<Magick::Color> foci)
45 int section = std::floor(static_cast<double>(i) / sectionSize); 45 int section = std::floor(static_cast<double>(i) / sectionSize);
46 double interpolation = (static_cast<double>(i) / sectionSize) - section; 46 double interpolation = (static_cast<double>(i) / sectionSize) - section;
47 47
48 Magick::ColorHSL interpLeft = foci[section]; 48 Magick::ColorRGB interpLeft = foci[section];
49 Magick::ColorHSL interpRight = foci[section+1]; 49 Magick::ColorRGB interpRight = foci[section+1];
50
51 double newHue;
52 double diff = interpRight.hue() - interpLeft.hue();
53 if (diff < 0)
54 {
55 std::swap(interpLeft, interpRight);
56
57 diff = -diff;
58 interpolation = 1 - interpolation;
59 }
60 50
61 if (diff > 0.5) 51 Magick::ColorRGB interpolated(
62 { 52 ((1.0 - interpolation) * interpLeft.red())
63 newHue = 1.0 + interpLeft.hue() 53 + (interpolation * interpRight.red()),
64 * (interpolation * (interpRight.hue() - interpLeft.hue() - 1.0)); 54 ((1.0 - interpolation) * interpLeft.green())
65 55 + (interpolation * interpRight.green()),
66 if (newHue > 1.0) 56 ((1.0 - interpolation) * interpLeft.blue())
67 { 57 + (interpolation * interpRight.blue()));
68 newHue -= 1.0;
69 }
70 } else {
71 newHue = interpLeft.hue() + interpolation * diff;
72 }
73
74 Magick::ColorHSL interpolated(
75 newHue,
76 ((1.0 - interpolation) * interpLeft.saturation())
77 + (interpolation * interpRight.saturation()),
78 ((1.0 - interpolation) * interpLeft.luminosity())
79 + (interpolation * interpRight.luminosity()));
80 58
81 gradient_.push_back(interpolated); 59 gradient_.push_back(interpolated);
82 } 60 }