Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

addNoise[Channel] blur[Channel]

  • Loading branch information...
commit 0845b8c64cb222fc8aaf084e858b0bddb90d3a20 1 parent d79f541
@tjfontaine authored
View
25 src/constants.h
@@ -4,10 +4,23 @@
void
ConstantsInitialize(v8::Handle<v8::Object> target)
{
- NODE_DEFINE_CONSTANT(target, Magick::UniformNoise);
- NODE_DEFINE_CONSTANT(target, Magick::GaussianNoise);
- NODE_DEFINE_CONSTANT(target, Magick::MultiplicativeGaussianNoise);
- NODE_DEFINE_CONSTANT(target, Magick::ImpulseNoise);
- NODE_DEFINE_CONSTANT(target, Magick::LaplacianNoise);
- NODE_DEFINE_CONSTANT(target, Magick::PoissonNoise);
+ using namespace Magick;
+
+ NODE_DEFINE_CONSTANT(target, UniformNoise);
+ NODE_DEFINE_CONSTANT(target, GaussianNoise);
+ NODE_DEFINE_CONSTANT(target, MultiplicativeGaussianNoise);
+ NODE_DEFINE_CONSTANT(target, ImpulseNoise);
+ NODE_DEFINE_CONSTANT(target, LaplacianNoise);
+ NODE_DEFINE_CONSTANT(target, PoissonNoise);
+
+ NODE_DEFINE_CONSTANT(target, UndefinedChannel);
+ NODE_DEFINE_CONSTANT(target, RedChannel);
+ NODE_DEFINE_CONSTANT(target, CyanChannel);
+ NODE_DEFINE_CONSTANT(target, GreenChannel);
+ NODE_DEFINE_CONSTANT(target, MagentaChannel);
+ NODE_DEFINE_CONSTANT(target, BlueChannel);
+ NODE_DEFINE_CONSTANT(target, YellowChannel);
+ NODE_DEFINE_CONSTANT(target, OpacityChannel);
+ NODE_DEFINE_CONSTANT(target, BlackChannel);
+ NODE_DEFINE_CONSTANT(target, MatteChannel);
}
View
53 src/image.cc
@@ -214,6 +214,50 @@ ImagickImage::adaptiveThreshold(const Arguments &args)
return args.This();
}
+Handle<Value>
+ImagickImage::addNoise(const Arguments &args)
+{
+ HandleScope scope;
+ ENSURE(Number, 0);
+ ImagickImage *image = IUNWRAP(args.This());
+ TRY_CATCH(image->image_.addNoise((MagickCore::NoiseType)args[0]->Uint32Value()));
+ return args.This();
+}
+
+Handle<Value>
+ImagickImage::addNoiseChannel(const Arguments &args)
+{
+ HandleScope scope;
+ ENSURE(Number, 0);
+ ENSURE(Number, 1);
+ ImagickImage *image = IUNWRAP(args.This());
+ TRY_CATCH(image->image_.addNoiseChannel((MagickCore::ChannelType)args[0]->Uint32Value(), (MagickCore::NoiseType)args[1]->Uint32Value()));
+ return args.This();
+}
+
+Handle<Value>
+ImagickImage::blur(const Arguments &args)
+{
+ HandleScope scope;
+ ENSURE(Number, 0);
+ ENSURE(Number, 1);
+ ImagickImage *image = IUNWRAP(args.This());
+ TRY_CATCH(image->image_.blur(args[0]->NumberValue(), args[1]->NumberValue()));
+ return args.This();
+}
+
+Handle<Value>
+ImagickImage::blurChannel(const Arguments &args)
+{
+ HandleScope scope;
+ ENSURE(Number, 0);
+ ENSURE(Number, 1);
+ ENSURE(Number, 2);
+ ImagickImage *image = IUNWRAP(args.This());
+ TRY_CATCH(image->image_.blurChannel((MagickCore::ChannelType)args[0]->Uint32Value(), args[1]->NumberValue(), args[2]->NumberValue()));
+ return args.This();
+}
+
void
ImagickImage::Initialize(Handle<Object> target)
{
@@ -244,12 +288,13 @@ ImagickImage::Initialize(Handle<Object> target)
IMAGICK_PROTOTYPE(t, zoom);
IMAGICK_PROTOTYPE(t, adaptiveThreshold);
- NODE_SET_PROTOTYPE_METHOD(t, "addNoise", NotImplemented);
- NODE_SET_PROTOTYPE_METHOD(t, "addNoiseChannel", NotImplemented);
+ IMAGICK_PROTOTYPE(t, addNoise);
+ IMAGICK_PROTOTYPE(t, addNoiseChannel);
+ IMAGICK_PROTOTYPE(t, blur);
+ IMAGICK_PROTOTYPE(t, blurChannel);
+
NODE_SET_PROTOTYPE_METHOD(t, "affineTransform", NotImplemented);
NODE_SET_PROTOTYPE_METHOD(t, "annotate", NotImplemented);
- NODE_SET_PROTOTYPE_METHOD(t, "blur", NotImplemented);
- NODE_SET_PROTOTYPE_METHOD(t, "blurChannel", NotImplemented);
NODE_SET_PROTOTYPE_METHOD(t, "cdl", NotImplemented);
NODE_SET_PROTOTYPE_METHOD(t, "channel", NotImplemented);
NODE_SET_PROTOTYPE_METHOD(t, "charcol", NotImplemented);
View
4 src/image.h
@@ -74,6 +74,10 @@ class ImagickImage : public node::ObjectWrap
IMAGICK_P(zoom);
IMAGICK_P(adaptiveThreshold);
+ IMAGICK_P(addNoise);
+ IMAGICK_P(addNoiseChannel);
+ IMAGICK_P(blur);
+ IMAGICK_P(blurChannel);
};
#endif
View
9 src/util.h
@@ -57,3 +57,12 @@ do { \
} while(0)
#endif
+
+#define TRY_CATCH(stmt) \
+do { \
+ try {\
+ stmt; \
+ } catch (Magick::Error &error) { \
+ return throw_exception(error); \
+ } \
+} while (0)
View
9 test.js
@@ -12,6 +12,14 @@ i.despeckle();
i.flip();
i.flop();
+i.adaptiveThreshold(75, 100);
+
+i.addNoise(imagick.UniformNoise);
+i.addNoiseChannel(imagick.BlueChannel, imagick.GaussianNoise);
+
+i.blur(1, .5);
+i.blurChannel(imagick.MagentaChannel, 1, .5);
+
var g = new imagick.geometry("50x50");
console.log(g.toString());
console.log('width', g.width);
@@ -22,7 +30,6 @@ console.log(g.toString());
i.zoom(g);
-i.adaptiveThreshold(75, 100);
var oblob = new imagick.blob();
console.log("blob length", oblob.length);
Please sign in to comment.
Something went wrong with that request. Please try again.