Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions src/magick_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright (C) 2022 Lukáš Karas <lukas.karas@centrum.cz>
*
* 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 <Magick++.h>
#include <Magick++/Color.h>
#include <Magick++/Image.h>

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<Magick::Quantum>(d*QuantumRange);
#endif
}

inline double scaleQuantumToDouble(Magick::Quantum q) {
#if MagickLibVersion < 0x700
return Magick::Color::scaleQuantumToDouble(q);
#else
return static_cast<double>(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<unsigned int>(scaleDoubleToQuantum(opacity)));
#endif
}

}
23 changes: 14 additions & 9 deletions src/pipeline_deflicker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
#include "pipeline_deflicker.moc"

#include "timelapse.h"
#include "magick_utils.h"

#include <QtCore/QTextStream>
#include <QtCore/QString>

#include <Magick++.h>
#include <ImageMagick-6/Magick++/Color.h>
#include <Magick++/Color.h>

#include <exception>
#include <vector>
Expand All @@ -53,12 +54,12 @@ namespace timelapse {
unsigned long pixelCount = 0;
for (std::pair<Magick::Color, size_t> 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.
Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
10 changes: 6 additions & 4 deletions src/pipeline_frame_prepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
#include "pipeline_frame_prepare.moc"

#include "timelapse.h"
#include "magick_utils.h"

#include <QtCore/QTextStream>

#include <Magick++.h>
#include <Magick++/Color.h>

#include <exception>
#include <ImageMagick-6/Magick++/Color.h>

using namespace std;
using namespace timelapse;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/pipeline_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "scope_log.h"
#include "timelapse.h"

#include <ImageMagick-6/Magick++/Exception.h>
#include <Magick++/Exception.h>

#include <QtCore/QTextStream>
#include <QtCore/QCoreApplication>
Expand Down
2 changes: 1 addition & 1 deletion src/timelapse_capture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#include "pipeline_cpt_qcamera.h"

#include <Magick++.h>
#include <ImageMagick-6/Magick++/Color.h>
#include <Magick++/Color.h>

#include <QtCore/QObject>
#include <QtCore/QDebug>
Expand Down
2 changes: 1 addition & 1 deletion src/timelapse_capture.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "pipeline_cpt.h"

#include <Magick++.h>
#include <ImageMagick-6/Magick++/Color.h>
#include <Magick++/Color.h>

#include <QtCore/QObject>
#include <QtCore/QDebug>
Expand Down