diff --git a/src/magick_utils.h b/src/magick_utils.h new file mode 100644 index 0000000..ad60722 --- /dev/null +++ b/src/magick_utils.h @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2022 Lukáš Karas + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#pragma once + +#include +#include +#include + +namespace timelapse { +// methods for Magick++ 6 vs. 7 compatibility + +inline Magick::Quantum scaleDoubleToQuantum(double d) { +#if MagickLibVersion < 0x700 + return Magick::Color::scaleDoubleToQuantum(d); +#else + return static_cast(d*QuantumRange); +#endif +} + +inline double scaleQuantumToDouble(Magick::Quantum q) { +#if MagickLibVersion < 0x700 + return Magick::Color::scaleQuantumToDouble(q); +#else + return static_cast(q)/QuantumRange; +#endif +} + +inline double redDouble(const Magick::Color &color) { +#if MagickLibVersion < 0x700 + return scaleQuantumToDouble(color.redQuantum()); +#else + return scaleQuantumToDouble(color.quantumRed()); +#endif +} + +inline double greenDouble(const Magick::Color &color) { +#if MagickLibVersion < 0x700 + return scaleQuantumToDouble(color.greenQuantum()); +#else + return scaleQuantumToDouble(color.quantumGreen()); +#endif +} + +inline double blueDouble(const Magick::Color &color) { +#if MagickLibVersion < 0x700 + return scaleQuantumToDouble(color.blueQuantum()); +#else + return scaleQuantumToDouble(color.quantumBlue()); +#endif +} + +inline void imageOpacity(Magick::Image &image, double opacity) { +#if MagickLibVersion < 0x700 + image.opacity(scaleDoubleToQuantum(opacity)); +#else + image.alpha(static_cast(scaleDoubleToQuantum(opacity))); +#endif +} + +} diff --git a/src/pipeline_deflicker.cpp b/src/pipeline_deflicker.cpp index 7674a71..7adda4e 100644 --- a/src/pipeline_deflicker.cpp +++ b/src/pipeline_deflicker.cpp @@ -21,12 +21,13 @@ #include "pipeline_deflicker.moc" #include "timelapse.h" +#include "magick_utils.h" #include #include #include -#include +#include #include #include @@ -53,12 +54,12 @@ namespace timelapse { unsigned long pixelCount = 0; for (std::pair p : histogram) { pixelCount += p.second; - sumR += p.second * Magick::Color::scaleDoubleToQuantum( - std::pow(Magick::Color::scaleQuantumToDouble(p.first.redQuantum()), powArg)); - sumG += p.second * Magick::Color::scaleDoubleToQuantum( - std::pow(Magick::Color::scaleQuantumToDouble(p.first.greenQuantum()), powArg)); - sumB += p.second * Magick::Color::scaleDoubleToQuantum( - std::pow(Magick::Color::scaleQuantumToDouble(p.first.blueQuantum()), powArg)); + sumR += p.second * scaleDoubleToQuantum( + std::pow(redDouble(p.first), powArg)); + sumG += p.second * scaleDoubleToQuantum( + std::pow(greenDouble(p.first), powArg)); + sumB += p.second * scaleDoubleToQuantum( + std::pow(blueDouble(p.first), powArg)); } // We use the following formula to get the perceived luminance. @@ -69,8 +70,12 @@ namespace timelapse { void ComputeLuminance::onInputImg(InputImageInfo info, Magick::Image img) { +#if MagickLibVersion < 0x700 Magick::Image::ImageStatistics stat; img.statistics(&stat); +#else + Magick::ImageStatistics stat=img.statistics(); +#endif // We use the following formula to get the perceived luminance. info.luminance = 0.299 * stat.red.mean + 0.587 * stat.green.mean + 0.114 * stat.blue.mean; @@ -166,8 +171,8 @@ namespace timelapse { for (int iteration = 0; iteration < 10; iteration++) { gamma *= 1 / ( - std::log(Magick::Color::scaleQuantumToDouble(targetLuminance)) / - std::log(Magick::Color::scaleQuantumToDouble(expectedLuminance))); + std::log(scaleQuantumToDouble(targetLuminance)) / + std::log(scaleQuantumToDouble(expectedLuminance))); expectedLuminance = ComputeLuminance::computeLuminance(histogram, gamma); diff --git a/src/pipeline_frame_prepare.cpp b/src/pipeline_frame_prepare.cpp index ad6ec90..c4f73d5 100644 --- a/src/pipeline_frame_prepare.cpp +++ b/src/pipeline_frame_prepare.cpp @@ -21,12 +21,14 @@ #include "pipeline_frame_prepare.moc" #include "timelapse.h" +#include "magick_utils.h" #include #include +#include + #include -#include using namespace std; using namespace timelapse; @@ -79,9 +81,9 @@ namespace timelapse { if (f - f1 > 0) { // for 100 % transparency, we don't have to composite Magick::Image secondLayer = *img2; *verboseOutput << "Blend with next image with " << (opacity * 100) << " % transparency" << endl; - - //secondLayer.opacity(((double) QuantumRange) * opacity); - secondLayer.opacity(Magick::Color::scaleDoubleToQuantum(opacity)); + + imageOpacity(secondLayer, opacity); + blended.composite(secondLayer, 0, 0, Magick::DissolveCompositeOp); } //writeFrame(f, blended); diff --git a/src/pipeline_handler.cpp b/src/pipeline_handler.cpp index 5f8e5a9..ffd001f 100644 --- a/src/pipeline_handler.cpp +++ b/src/pipeline_handler.cpp @@ -23,7 +23,7 @@ #include "scope_log.h" #include "timelapse.h" -#include +#include #include #include diff --git a/src/timelapse_capture.cpp b/src/timelapse_capture.cpp index 72a3b49..043b3a2 100644 --- a/src/timelapse_capture.cpp +++ b/src/timelapse_capture.cpp @@ -46,7 +46,7 @@ #include "pipeline_cpt_qcamera.h" #include -#include +#include #include #include diff --git a/src/timelapse_capture.h b/src/timelapse_capture.h index f3130be..fec8f90 100644 --- a/src/timelapse_capture.h +++ b/src/timelapse_capture.h @@ -27,7 +27,7 @@ #include "pipeline_cpt.h" #include -#include +#include #include #include