diff options
| author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2017-03-04 09:39:50 -0500 |
|---|---|---|
| committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2017-03-04 09:39:50 -0500 |
| commit | 9fb32eb6185e0bbf358d279a267d187c266b6656 (patch) | |
| tree | 9301d937b621a8171be88fb65f332b99549d14bd | |
| parent | 7ba70196fd05a893a851f24a07868e3a1e9a7818 (diff) | |
| download | grunge-9fb32eb6185e0bbf358d279a267d187c266b6656.tar.gz grunge-9fb32eb6185e0bbf358d279a267d187c266b6656.tar.bz2 grunge-9fb32eb6185e0bbf358d279a267d187c266b6656.zip | |
Changed to RGB color interpolation
It's way less accurate but actually kind of looks better.
| -rw-r--r-- | palette.cpp | 40 |
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 | } |
