Skip to content

Commit

Permalink
fix: trying to fix support to Magick++ 7
Browse files Browse the repository at this point in the history
  • Loading branch information
rodolforg committed Jan 31, 2024
1 parent f4e1003 commit 0825053
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions synfig-core/src/modules/mod_magickpp/mptr_magickpp.cpp
Expand Up @@ -128,30 +128,47 @@ magickpp_mptr::get_frame(synfig::Surface& surface, const synfig::RendDesc& /*ren
const auto height = image.size().height();
surface.set_wh(width, height);

const MagickCore::PixelPacket* packet = image.getConstPixels(0, 0, width, height);
bool has_alpha =
image.type() == Magick::GrayscaleMatteType ||
image.type() == Magick::PaletteMatteType ||
image.type() == Magick::TrueColorMatteType ||
image.type() == Magick::ColorSeparationMatteType;

image.type(has_alpha ? Magick::TrueColorMatteType : Magick::TrueColorType);

// Sadly Magick++ API is a mess with namespaces...
{
using namespace Magick;
using namespace MagickCore;
#if MAGICKCORE_CHECK_VERSION(7,0,0)
const MagickCore::Quantum* packet = image.getConstPixels(0, 0, width, height);
#else
const Magick::PixelPacket* packet = image.getConstPixels(0, 0, width, height);
#endif
if (!packet) {
synfig::error(_("Magick++ importer: couldn't get pixel packet"));
return false;
}

// Sadly ImageMagick is a mess with this QuantumRange macro - it needs Magick namespace in its parsing...
// constexpr synfig::Color::value_type factor = 1. / QuantumRange;
// alternative way:
synfig::Color::value_type factor = 1.;
{
using namespace Magick;

factor = QuantumRange;
}
constexpr synfig::Color::value_type factor = QuantumRange;

for (size_t y = 0, i = 0; y < height; ++y) {
for (size_t x = 0; x < width; ++x, ++i) {
#if MAGICKCORE_CHECK_VERSION(7,0,0)
if (has_alpha)
surface[y][x] = synfig::Color(packet[i++] / factor, packet[i++] / factor, packet[i++] / factor, packet[i] / factor);
else
surface[y][x] = synfig::Color(packet[i++] / factor, packet[i++] / factor, packet[i] / factor, 1.);
#else
const auto& color = packet[i];
auto surface_color = synfig::Color(color.red / factor, color.green / factor, color.blue / factor, 1. - color.opacity / factor);

surface[y][x] = surface_color;
if (has_alpha)
surface[y][x] = synfig::Color(color.red / factor, color.green / factor, color.blue / factor, 1. - color.opacity / factor);
else
surface[y][x] = synfig::Color(color.red / factor, color.green / factor, color.blue / factor, 1.);
#endif
}
}
} // end Magick++ namespace mess
} catch (Magick::Error& err) {
synfig::error(_("Magick++ importer: error occurred fetching pixels: %s"), err.what());
return false;
Expand Down

0 comments on commit 0825053

Please sign in to comment.