From 8bd8ac8989f465ae54f78f7f3bd7fe1329fbd5b2 Mon Sep 17 00:00:00 2001 From: Victor Popkov Date: Tue, 24 Aug 2021 06:15:26 +0300 Subject: [PATCH] Migrate ImageMagick from 6 to 7 Based on the porting guide: https://imagemagick.org/script/porting.php --- src/common/image_operations.hpp | 48 ++++++++++++++++----------------- src/krane/kbuild.cpp | 14 +++++----- src/krane/krane.cpp | 4 +-- src/ktech/ktech_options.cpp | 6 ++--- src/ktech/ktech_options.hpp | 2 +- 5 files changed, 36 insertions(+), 38 deletions(-) diff --git a/src/common/image_operations.hpp b/src/common/image_operations.hpp index 4efde24..2609834 100644 --- a/src/common/image_operations.hpp +++ b/src/common/image_operations.hpp @@ -29,7 +29,7 @@ namespace KTools { } namespace ImOp { typedef std::unary_function basic_image_operation_t; - typedef std::unary_function basic_pixel_operation_t; + typedef std::unary_function basic_pixel_operation_t; typedef std::unary_function basic_ktex_operation_t; typedef basic_image_operation_t basic_unary_operation_t; @@ -92,7 +92,7 @@ namespace ImOp { typedef operation_t ktex_operation_t; - typedef operation_t pixel_operation_t; + typedef operation_t pixel_operation_t; /// @@ -328,8 +328,8 @@ namespace ImOp { return SequenceWriter(c); } - inline Magick::Quantum multiplyQuantum(Magick::Quantum q, double factor) { - using namespace Magick; + inline MagickCore::Quantum multiplyQuantum(MagickCore::Quantum q, double factor) { + using namespace MagickCore; const double result = factor*q; if(result >= QuantumRange) { @@ -342,32 +342,32 @@ namespace ImOp { class premultiplyPixelAlpha : public pixel_operation_t { public: - virtual void call(Magick::PixelPacket* p) const { + virtual void call(MagickCore::Quantum* p) const { using namespace Magick; - double a = 1 - double(p->opacity)/QuantumRange; + double a = double(p[3])/QuantumRange; if(a <= 0.1) a = 0; else if(a >= 1) a = 1; - p->red = multiplyQuantum(p->red, a); - p->green = multiplyQuantum(p->green, a); - p->blue = multiplyQuantum(p->blue, a); + p[0] = multiplyQuantum(p[0], a); + p[1] = multiplyQuantum(p[1], a); + p[2] = multiplyQuantum(p[2], a); } }; class demultiplyPixelAlpha : public pixel_operation_t { public: - virtual void call(Magick::PixelPacket* p) const { + virtual void call(MagickCore::Quantum* p) const { using namespace Magick; - const double a = 1 - double(p->opacity)/QuantumRange; + const double a = double(p[3])/QuantumRange; if(a <= 0 || a >= 1) return; const double inva = 1/a; - p->red = multiplyQuantum(p->red, inva); - p->green = multiplyQuantum(p->green, inva); - p->blue = multiplyQuantum(p->blue, inva); + p[0] = multiplyQuantum(p[0], inva); + p[1] = multiplyQuantum(p[1], inva); + p[2] = multiplyQuantum(p[2], inva); } }; @@ -377,18 +377,19 @@ namespace ImOp { public: virtual void call(Magick::Image& img) const { using namespace Magick; - img.type(TrueColorMatteType); + img.type(TrueColorAlphaType); img.modifyImage(); Pixels view(img); const size_t w = img.columns(), h = img.rows(); { - PixelPacket * RESTRICT p = view.get(0, 0, w, h); + MagickCore::Quantum * RESTRICT p = view.get(0, 0, w, h); for(size_t i = 0; i < h; i++) { for(size_t j = 0; j < w; j++) { - op(p++); + op(p); + p += 4; } } } @@ -420,15 +421,12 @@ namespace ImOp { img.despeckle(); Image alpha = img; - alpha.channel(MatteChannel); - alpha.negate(); + alpha.channel(MagickCore::AlphaChannel); + alpha.reduceNoise(static_cast(1.6)); - alpha.reduceNoise(1.6); - - img.matte(false); - img.composite(alpha, 0, 0, CopyOpacityCompositeOp); - - img.matte(true); + img.alpha(false); + img.composite(alpha, 0, 0, MagickCore::CopyAlphaCompositeOp); + img.alpha(true); } }; }} diff --git a/src/krane/kbuild.cpp b/src/krane/kbuild.cpp index 83a26d4..4f735c2 100644 --- a/src/krane/kbuild.cpp +++ b/src/krane/kbuild.cpp @@ -44,9 +44,9 @@ namespace Krane { mask.monochrome(true); mask.fillColor(ColorMono(false)); - list drawable_trigs; + vector drawable_trigs; size_t ntrigs = uvwtriangles.size(); - list coords; + vector coords; for(size_t i = 0; i < ntrigs; i++) { const uvwtriangle_type& trig = uvwtriangles[i]; @@ -96,9 +96,9 @@ namespace Krane { // Returned image (clipped quad). Image img = Image(geo, "transparent"); - img.clipMask(mask); + img.readMask(mask); MAGICK_WRAP(img.composite( quad, Geometry(0, 0), OverCompositeOp )); - img.clipMask(Image()); + img.readMask(Image()); // This is to reverse the scaling down applied by the mod tools' scml compiler. @@ -177,13 +177,13 @@ namespace Krane { // Returned image. Magick::Image markedatlas(atlas.size(), "transparent"); - markedatlas.clipMask(inversemask); + markedatlas.readMask(inversemask); MAGICK_WRAP(markedatlas.composite( bg, Geometry(0, 0), OverCompositeOp )); - markedatlas.clipMask(mask); + markedatlas.readMask(mask); MAGICK_WRAP(markedatlas.composite( atlas, Geometry(0, 0), OverCompositeOp )); - markedatlas.clipMask(Image()); + markedatlas.readMask(Image()); markedatlas.flip(); return markedatlas; diff --git a/src/krane/krane.cpp b/src/krane/krane.cpp index 1049f05..0e836bc 100644 --- a/src/krane/krane.cpp +++ b/src/krane/krane.cpp @@ -234,7 +234,7 @@ static void configure_bank_collection(KAnimBankCollection& banks) { } static void sanitize_output_png(Magick::Image& img) { - img.type(Magick::TrueColorMatteType); + img.type(Magick::TrueColorAlphaType); img.colorSpace(Magick::sRGBColorspace); // png color type 6 means RGBA @@ -359,6 +359,6 @@ int main(int argc, char* argv[]) { cerr << "ERROR" << endl; return -1; } - + return 0; } diff --git a/src/ktech/ktech_options.cpp b/src/ktech/ktech_options.cpp index 2d03f38..b96aebd 100644 --- a/src/ktech/ktech_options.cpp +++ b/src/ktech/ktech_options.cpp @@ -53,7 +53,7 @@ namespace KTech { int image_quality = 100; - Magick::FilterTypes filter = Magick::LanczosFilter; + MagickCore::FilterType filter = MagickCore::LanczosFilter; bool no_premultiply = false; @@ -124,10 +124,10 @@ namespace KTech { } }; - class FilterTypeTranslator : public StrOptTranslator { + class FilterTypeTranslator : public StrOptTranslator { public: FilterTypeTranslator() { - using namespace Magick; + using namespace MagickCore; push_opt("lanczos", LanczosFilter); push_opt("mitchell", MitchellFilter); diff --git a/src/ktech/ktech_options.hpp b/src/ktech/ktech_options.hpp index f031479..3b2c569 100644 --- a/src/ktech/ktech_options.hpp +++ b/src/ktech/ktech_options.hpp @@ -30,7 +30,7 @@ namespace KTech { extern int image_quality; - extern Magick::FilterTypes filter; + extern MagickCore::FilterType filter; extern bool no_premultiply;