Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

start mapping the Magick++ api

  • Loading branch information...
commit 86290d5469cf5a6b3bf5f6927d57b3eaf6711699 1 parent 22cd32f
@tjfontaine authored
View
1  .gitignore
@@ -1 +1,2 @@
build/
+*.swp
View
198 src/image.cc
@@ -0,0 +1,198 @@
+#include <string.h>
+
+#include <node.h>
+#include <node_buffer.h>
+
+#include <Magick++.h>
+
+#include "util.h"
+#include "image.h"
+
+using namespace v8;
+using namespace node;
+
+Handle<Value>
+ImagickImage::New(const Arguments &args)
+{
+ HandleScope scope;
+
+ ImagickImage *image = new ImagickImage();
+ image->Wrap(args.This());
+
+ return args.This();
+}
+
+Handle<Value>
+ImagickImage::NotImplemented(const Arguments &args)
+{
+ return ThrowException(Exception::TypeError(String::New("This function not yet implemented")));
+}
+
+Handle<Value>
+ImagickImage::readSync(const Arguments &args)
+{
+ HandleScope scope;
+ ImagickImage *image = ObjectWrap::Unwrap<ImagickImage>(args.This());
+
+ if(args[0]->IsString())
+ {
+ image->image_.read(to_string(args[0]));
+ }
+ else if(Buffer::HasInstance(args[0]))
+ {
+ image->image_.read(to_blob(args[0]));
+ }
+ else
+ {
+ return ThrowException(Exception::TypeError(String::New("Reading from this type not implemented")));
+ }
+
+ return args.This();
+}
+
+Handle<Value>
+ImagickImage::writeSync(const Arguments &args)
+{
+ HandleScope scope;
+ ImagickImage *image = ObjectWrap::Unwrap<ImagickImage>(args.This());
+ Local<Value> ret;
+
+ if (args.Length() == 0)
+ {
+ Magick::Blob bl;
+ image->image_.write(&bl);
+ ret = from_blob(bl);
+ }
+ else if(args[0]->IsString())
+ {
+ image->image_.write(to_string(args[0]));
+ ret = args.This();
+ }
+ else
+ {
+ return ThrowException(Exception::TypeError(String::New("Writing to this type not implemented")));
+ }
+
+ return ret;
+}
+
+Handle<Value>
+ImagickImage::rotate(const Arguments &args)
+{
+ HandleScope scope;
+ ImagickImage *image = ObjectWrap::Unwrap<ImagickImage>(args.This());
+
+ if(args[0]->IsNumber())
+ {
+ image->image_.rotate(args[0]->NumberValue());
+ }
+
+ return args.This();
+}
+
+void
+ImagickImage::Initialize(Handle<Object> target)
+{
+ HandleScope scope;
+ Local<FunctionTemplate> t = FunctionTemplate::New(New);
+ t->InstanceTemplate()->SetInternalFieldCount(1);
+
+ NODE_SET_PROTOTYPE_METHOD(t, "adaptiveThreshold", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "addNoise", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "addNoiseChannel", NotImplemented);
+ 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, "border", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "cdl", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "channel", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "charcol", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "chop", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "colorize", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "comment", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "compare", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "composite", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "contrast", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "convolve", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "crop", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "cycleColormap", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "despeckle", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "display", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "distort", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "draw", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "edge", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "emboss", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "enhance", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "equalize", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "erase", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "extent", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "flip", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "floodFillColor", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "floodFillTexture", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "flop", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "frame", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "fx", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "gamma", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "gaussianBlur", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "gaussianBlurChannel", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "haldClut", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "implode", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "inverseFourierTransform", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "label", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "level", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "levelChannel", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "magnify", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "map", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "matteFloodfill", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "medianFilter", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "minify", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "modifyImage", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "modulate", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "motionBlur", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "negate", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "normalize", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "oilPaint", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "opacity", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "opaque", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "ping", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "process", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "quantize", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "raise", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "read", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "readSync", readSync);
+ NODE_SET_PROTOTYPE_METHOD(t, "reduceNoise", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "randomThreshold", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "randomThresholdChannel", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "roll", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "rotate", rotate);
+ NODE_SET_PROTOTYPE_METHOD(t, "sample", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "scale", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "segment", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "shade", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "sharpen", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "sharpenChannel", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "shave", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "shear", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "solarize", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "splice", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "spread", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "stegano", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "sparseColor", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "statistics", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "stereo", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "swirl", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "texture", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "transform", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "transparent", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "trim", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "unsharpmask", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "unsharpmaskChannel", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "wave", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "write", NotImplemented);
+ NODE_SET_PROTOTYPE_METHOD(t, "writeSync", writeSync);
+ NODE_SET_PROTOTYPE_METHOD(t, "zoom", NotImplemented);
+ //NODE_SET_PROTOTYPE_METHOD(t, "", NotImplemented);
+
+ target->Set(String::NewSymbol("image"), t->GetFunction());
+}
View
19 src/image.h
@@ -0,0 +1,19 @@
+#ifndef IMAGICK_IMAGE_H
+#define IMAGICK_IMAGE_H
+
+#include <node.h>
+#include <Magick++.h>
+
+class ImagickImage : public node::ObjectWrap
+{
+public:
+ Magick::Image image_;
+ static void Initialize(v8::Handle<v8::Object> target);
+ static v8::Handle<v8::Value> New(const v8::Arguments &args);
+ static v8::Handle<v8::Value> NotImplemented(const v8::Arguments &args);
+ static v8::Handle<v8::Value> readSync(const v8::Arguments &args);
+ static v8::Handle<v8::Value> writeSync(const v8::Arguments &args);
+ static v8::Handle<v8::Value> rotate(const v8::Arguments &args);
+};
+
+#endif
View
3  src/imagick.cc
@@ -1,5 +1,7 @@
#include <node.h>
+
#include "command.h"
+#include "image.h"
using namespace v8;
using namespace node;
@@ -9,4 +11,5 @@ init (Handle<Object> target)
{
HandleScope scope;
CommandInit(target);
+ ImagickImage::Initialize(target);
}
View
47 src/util.h
@@ -0,0 +1,47 @@
+#ifndef IMAGICK_UTIL_H
+#define IMAGICK_UTIL_H
+
+#include <node.h>
+
+template <typename T>
+T _to_string(v8::Handle<v8::String> str)
+{
+ v8::String::Utf8Value a(str);
+ return T(*a);
+}
+
+inline const std::string to_string(v8::Local<v8::String> str)
+{
+ return _to_string<std::string>(str);
+}
+
+inline const std::string to_string(const v8::Local<v8::Value> &arg)
+{
+ return to_string(arg->ToString());
+}
+
+inline const Magick::Blob to_blob(const v8::Local<v8::Value> &arg)
+{
+ v8::Local<v8::Object> buffer_obj = arg->ToObject();
+ return Magick::Blob(node::Buffer::Data(buffer_obj), node::Buffer::Length(buffer_obj));
+}
+
+inline const v8::Local<v8::Object> from_blob(const Magick::Blob &blob)
+{
+ node::Buffer *slowBuffer = node::Buffer::New(blob.length());
+ memcpy(node::Buffer::Data(slowBuffer), blob.data(), blob.length());
+
+ v8::Local<v8::Object> globalObj = v8::Context::GetCurrent()->Global();
+ v8::Local<v8::Function> bufferConstructor = v8::Local<v8::Function>::Cast(globalObj->Get(v8::String::New("Buffer")));
+
+ v8::Handle<v8::Value> constructorArgs[3] = {
+ slowBuffer->handle_,
+ v8::Integer::New(blob.length()),
+ v8::Integer::New(0)
+ };
+
+ v8::Local<v8::Object> actualBuffer = bufferConstructor->NewInstance(3, constructorArgs);
+ return actualBuffer;
+}
+
+#endif
View
12 test.js
@@ -0,0 +1,12 @@
+var imagick = require('./imagick');
+var fs = require('fs');
+
+var i = new imagick.image();
+
+var blob = fs.readFileSync('./wizard.jpg');
+
+i.readSync(blob).rotate(90)
+
+var oblob = i.writeSync();
+
+fs.writeFileSync('./wizard.rotate.jpg', oblob);
View
6 wscript
@@ -2,7 +2,7 @@ import Options
from os import unlink, symlink, popen
from os.path import exists
-VERSION = "0.0.2"
+VERSION = "0.0.3"
def set_options(opt):
opt.tool_options("compiler_cxx")
@@ -13,6 +13,7 @@ def configure(conf):
conf.check_tool("compiler_cc")
conf.check_tool("node_addon")
conf.check_cfg(package="MagickWand", args='--cflags --libs', uselib_store='MAGICKWAND')
+ conf.check_cfg(package="Magick++", args='--cflags --libs', uselib_store='MAGICKPP')
def build(bld):
obj = bld.new_task_gen("cxx", "shlib", "node_addon")
@@ -21,8 +22,9 @@ def build(bld):
obj.source = [
"src/imagick.cc",
"src/command.cc",
+ "src/image.cc",
]
- obj.uselib = ['MAGICKWAND']
+ obj.uselib = ['MAGICKWAND', 'MAGICKPP']
def shutdown():
if Options.commands['clean']:
Please sign in to comment.
Something went wrong with that request. Please try again.