Skip to content
Open
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
48 changes: 23 additions & 25 deletions src/common/image_operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace KTools {
}
namespace ImOp {
typedef std::unary_function<Magick::Image&, void> basic_image_operation_t;
typedef std::unary_function<Magick::PixelPacket*, void> basic_pixel_operation_t;
typedef std::unary_function<MagickCore::Quantum*, void> basic_pixel_operation_t;
typedef std::unary_function<KTEX::File&, void> basic_ktex_operation_t;

typedef basic_image_operation_t basic_unary_operation_t;
Expand Down Expand Up @@ -92,7 +92,7 @@ namespace ImOp {

typedef operation_t<KTEX::File&> ktex_operation_t;

typedef operation_t<Magick::PixelPacket*> pixel_operation_t;
typedef operation_t<MagickCore::Quantum*> pixel_operation_t;

///

Expand Down Expand Up @@ -328,8 +328,8 @@ namespace ImOp {
return SequenceWriter<Container>(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) {
Expand All @@ -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);
}
};

Expand All @@ -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;
}
}
}
Expand Down Expand Up @@ -420,15 +421,12 @@ namespace ImOp {
img.despeckle();

Image alpha = img;
alpha.channel(MatteChannel);
alpha.negate();
alpha.channel(MagickCore::AlphaChannel);
alpha.reduceNoise(static_cast<size_t>(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);
}
};
}}
Expand Down
14 changes: 7 additions & 7 deletions src/krane/kbuild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ namespace Krane {
mask.monochrome(true);
mask.fillColor(ColorMono(false));

list<Drawable> drawable_trigs;
vector<Drawable> drawable_trigs;
size_t ntrigs = uvwtriangles.size();
list<Coordinate> coords;
vector<Coordinate> coords;
for(size_t i = 0; i < ntrigs; i++) {
const uvwtriangle_type& trig = uvwtriangles[i];

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/krane/krane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -359,6 +359,6 @@ int main(int argc, char* argv[]) {
cerr << "ERROR" << endl;
return -1;
}

return 0;
}
6 changes: 3 additions & 3 deletions src/ktech/ktech_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace KTech {

int image_quality = 100;

Magick::FilterTypes filter = Magick::LanczosFilter;
MagickCore::FilterType filter = MagickCore::LanczosFilter;

bool no_premultiply = false;

Expand Down Expand Up @@ -124,10 +124,10 @@ namespace KTech {
}
};

class FilterTypeTranslator : public StrOptTranslator<Magick::FilterTypes> {
class FilterTypeTranslator : public StrOptTranslator<MagickCore::FilterType> {
public:
FilterTypeTranslator() {
using namespace Magick;
using namespace MagickCore;

push_opt("lanczos", LanczosFilter);
push_opt("mitchell", MitchellFilter);
Expand Down
2 changes: 1 addition & 1 deletion src/ktech/ktech_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace KTech {

extern int image_quality;

extern Magick::FilterTypes filter;
extern MagickCore::FilterType filter;

extern bool no_premultiply;

Expand Down