From 2cee2a960d4ce008705a1e5cf3f3d246bbbf64df Mon Sep 17 00:00:00 2001 From: Igor Agarlev Date: Mon, 1 Jul 2013 22:57:39 +0400 Subject: [PATCH 1/3] migrate to gyp --- binding.gyp | 24 ++++++++++++++++++++++++ examples/jpeg-example.js | 2 +- package.json | 5 +++-- src/dynamic_jpeg_stack.cpp | 12 +++++++----- src/dynamic_jpeg_stack.h | 4 ++-- src/fixed_jpeg_stack.cpp | 12 +++++++----- src/fixed_jpeg_stack.h | 4 ++-- src/jpeg.cpp | 12 +++++++----- src/jpeg.h | 4 ++-- src/module.cpp | 2 ++ wscript | 30 ------------------------------ 11 files changed, 57 insertions(+), 54 deletions(-) create mode 100644 binding.gyp delete mode 100644 wscript diff --git a/binding.gyp b/binding.gyp new file mode 100644 index 0000000..8c2abd8 --- /dev/null +++ b/binding.gyp @@ -0,0 +1,24 @@ +{ + "targets": [ + { + "target_name": "jpeg", + "sources": [ + "src/common.cpp", + "src/jpeg_encoder.cpp", + "src/jpeg.cpp", + "src/fixed_jpeg_stack.cpp", + "src/dynamic_jpeg_stack.cpp", + "src/module.cpp"], + "libraries": ["-lJPEG"], + 'cflags!': [ '-fno-exceptions' ], + 'cflags_cc!': [ '-fno-exceptions' ], + 'conditions': [ + ['OS=="mac"', { + 'xcode_settings': { + 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES' + } + }] + ] + } + ] +} diff --git a/examples/jpeg-example.js b/examples/jpeg-example.js index a12ab62..7e4ba93 100644 --- a/examples/jpeg-example.js +++ b/examples/jpeg-example.js @@ -1,6 +1,6 @@ var fs = require('fs'); var sys = require('sys'); -var Jpeg = require('../jpeg').Jpeg; +var Jpeg = require('../build/Release/jpeg').Jpeg; var Buffer = require('buffer').Buffer; var rgba = fs.readFileSync('./rgba-terminal.dat'); diff --git a/package.json b/package.json index ce43a89..b360cef 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,8 @@ "node": ">=0.1.93" }, "scripts": { - "install": "node-waf configure build" - } + "install": "node-gyp rebuild" + }, + "gypfile": true } diff --git a/src/dynamic_jpeg_stack.cpp b/src/dynamic_jpeg_stack.cpp index 77058a6..d34fd51 100644 --- a/src/dynamic_jpeg_stack.cpp +++ b/src/dynamic_jpeg_stack.cpp @@ -378,7 +378,7 @@ DynamicJpegStack::SetQuality(const Arguments &args) } void -DynamicJpegStack::EIO_JpegEncode(eio_req *req) +DynamicJpegStack::EIO_JpegEncode(uv_work_t *req) { encode_request *enc_req = (encode_request *)req->data; DynamicJpegStack *jpeg = (DynamicJpegStack *)enc_req->jpeg_obj; @@ -404,11 +404,10 @@ DynamicJpegStack::EIO_JpegEncode(eio_req *req) } int -DynamicJpegStack::EIO_JpegEncodeAfter(eio_req *req) +DynamicJpegStack::EIO_JpegEncodeAfter(uv_work_t *req) { HandleScope scope; - ev_unref(EV_DEFAULT_UC); encode_request *enc_req = (encode_request *)req->data; DynamicJpegStack *jpeg = (DynamicJpegStack *)enc_req->jpeg_obj; @@ -435,6 +434,8 @@ DynamicJpegStack::EIO_JpegEncodeAfter(eio_req *req) FatalException(try_catch); enc_req->callback.Dispose(); + delete req; + free(enc_req->jpeg); free(enc_req->error); @@ -468,9 +469,10 @@ DynamicJpegStack::JpegEncodeAsync(const Arguments &args) enc_req->jpeg_len = 0; enc_req->error = NULL; - eio_custom(EIO_JpegEncode, EIO_PRI_DEFAULT, EIO_JpegEncodeAfter, enc_req); + uv_work_t *_req = new uv_work_t; + _req->data = enc_req; + uv_queue_work(uv_default_loop(), _req, EIO_JpegEncode, (uv_after_work_cb)EIO_JpegEncodeAfter); - ev_ref(EV_DEFAULT_UC); jpeg->Ref(); return Undefined(); diff --git a/src/dynamic_jpeg_stack.h b/src/dynamic_jpeg_stack.h index dae3672..e739c58 100644 --- a/src/dynamic_jpeg_stack.h +++ b/src/dynamic_jpeg_stack.h @@ -21,8 +21,8 @@ class DynamicJpegStack : public node::ObjectWrap { void update_optimal_dimension(int x, int y, int w, int h); - static void EIO_JpegEncode(eio_req *req); - static int EIO_JpegEncodeAfter(eio_req *req); + static void EIO_JpegEncode(uv_work_t *req); + static int EIO_JpegEncodeAfter(uv_work_t *req); public: DynamicJpegStack(buffer_type bbuf_type); ~DynamicJpegStack(); diff --git a/src/fixed_jpeg_stack.cpp b/src/fixed_jpeg_stack.cpp index ed75fe1..a314930 100644 --- a/src/fixed_jpeg_stack.cpp +++ b/src/fixed_jpeg_stack.cpp @@ -248,7 +248,7 @@ FixedJpegStack::SetQuality(const Arguments &args) } void -FixedJpegStack::EIO_JpegEncode(eio_req *req) +FixedJpegStack::EIO_JpegEncode(uv_work_t *req) { encode_request *enc_req = (encode_request *)req->data; FixedJpegStack *jpeg = (FixedJpegStack *)enc_req->jpeg_obj; @@ -272,11 +272,10 @@ FixedJpegStack::EIO_JpegEncode(eio_req *req) } int -FixedJpegStack::EIO_JpegEncodeAfter(eio_req *req) +FixedJpegStack::EIO_JpegEncodeAfter(uv_work_t *req) { HandleScope scope; - ev_unref(EV_DEFAULT_UC); encode_request *enc_req = (encode_request *)req->data; Handle argv[2]; @@ -300,6 +299,8 @@ FixedJpegStack::EIO_JpegEncodeAfter(eio_req *req) FatalException(try_catch); enc_req->callback.Dispose(); + delete req; + free(enc_req->jpeg); free(enc_req->error); @@ -333,9 +334,10 @@ FixedJpegStack::JpegEncodeAsync(const Arguments &args) enc_req->jpeg_len = 0; enc_req->error = NULL; - eio_custom(EIO_JpegEncode, EIO_PRI_DEFAULT, EIO_JpegEncodeAfter, enc_req); + uv_work_t *_req = new uv_work_t; + _req->data = enc_req; + uv_queue_work(uv_default_loop(), _req, EIO_JpegEncode, (uv_after_work_cb)EIO_JpegEncodeAfter); - ev_ref(EV_DEFAULT_UC); jpeg->Ref(); return Undefined(); diff --git a/src/fixed_jpeg_stack.h b/src/fixed_jpeg_stack.h index 849505a..1842fb5 100644 --- a/src/fixed_jpeg_stack.h +++ b/src/fixed_jpeg_stack.h @@ -13,8 +13,8 @@ class FixedJpegStack : public node::ObjectWrap { unsigned char *data; - static void EIO_JpegEncode(eio_req *req); - static int EIO_JpegEncodeAfter(eio_req *req); + static void EIO_JpegEncode(uv_work_t *req); + static int EIO_JpegEncodeAfter(uv_work_t *req); public: static void Initialize(v8::Handle target); diff --git a/src/jpeg.cpp b/src/jpeg.cpp index cf0a0eb..d14c898 100644 --- a/src/jpeg.cpp +++ b/src/jpeg.cpp @@ -168,7 +168,7 @@ v8::Handle Jpeg::SetSmoothing(const v8::Arguments &args) } void -Jpeg::EIO_JpegEncode(eio_req *req) +Jpeg::EIO_JpegEncode(uv_work_t *req) { encode_request *enc_req = (encode_request *)req->data; Jpeg *jpeg = (Jpeg *)enc_req->jpeg_obj; @@ -191,11 +191,10 @@ Jpeg::EIO_JpegEncode(eio_req *req) } int -Jpeg::EIO_JpegEncodeAfter(eio_req *req) +Jpeg::EIO_JpegEncodeAfter(uv_work_t *req) { HandleScope scope; - ev_unref(EV_DEFAULT_UC); encode_request *enc_req = (encode_request *)req->data; Handle argv[2]; @@ -219,6 +218,8 @@ Jpeg::EIO_JpegEncodeAfter(eio_req *req) FatalException(try_catch); enc_req->callback.Dispose(); + delete req; + free(enc_req->jpeg); free(enc_req->error); @@ -252,9 +253,10 @@ Jpeg::JpegEncodeAsync(const Arguments &args) enc_req->jpeg_len = 0; enc_req->error = NULL; - eio_custom(EIO_JpegEncode, EIO_PRI_DEFAULT, EIO_JpegEncodeAfter, enc_req); + uv_work_t *_req = new uv_work_t; + _req->data = enc_req; + uv_queue_work(uv_default_loop(), _req, EIO_JpegEncode, (uv_after_work_cb)EIO_JpegEncodeAfter); - ev_ref(EV_DEFAULT_UC); jpeg->Ref(); return Undefined(); diff --git a/src/jpeg.h b/src/jpeg.h index c60b809..069ab89 100644 --- a/src/jpeg.h +++ b/src/jpeg.h @@ -9,8 +9,8 @@ class Jpeg : public node::ObjectWrap { JpegEncoder jpeg_encoder; - static void EIO_JpegEncode(eio_req *req); - static int EIO_JpegEncodeAfter(eio_req *req); + static void EIO_JpegEncode(uv_work_t *req); + static int EIO_JpegEncodeAfter(uv_work_t *req); public: static void Initialize(v8::Handle target); Jpeg(unsigned char *ddata, int wwidth, int hheight, buffer_type bbuf_type); diff --git a/src/module.cpp b/src/module.cpp index 593142d..d3bc7eb 100644 --- a/src/module.cpp +++ b/src/module.cpp @@ -15,3 +15,5 @@ init(Handle target) DynamicJpegStack::Initialize(target); } +NODE_MODULE(jpeg, init) + diff --git a/wscript b/wscript deleted file mode 100644 index 154af3f..0000000 --- a/wscript +++ /dev/null @@ -1,30 +0,0 @@ -import Options -from os import unlink, symlink, popen -from os.path import exists - -srcdir = "." -blddir = "build" -VERSION = "0.0.1" - -def set_options(opt): - opt.tool_options("compiler_cxx") - -def configure(conf): - conf.check_tool("compiler_cxx") - conf.check_tool("node_addon") - conf.check(lib='jpeg', libpath=['/lib', '/usr/lib', '/usr/local/lib', '/usr/local/libjpeg/lib', '/usr/local/pkg/jpeg-8b/lib']) - -def build(bld): - obj = bld.new_task_gen("cxx", "shlib", "node_addon") - obj.target = "jpeg" - obj.source = "src/common.cpp src/jpeg_encoder.cpp src/jpeg.cpp src/fixed_jpeg_stack.cpp src/dynamic_jpeg_stack.cpp src/module.cpp" - obj.uselib = "JPEG" - obj.cxxflags = ["-D_FILE_OFFSET_BITS=64", "-D_LARGEFILE_SOURCE"] - -def shutdown(): - if Options.commands['clean']: - if exists('jpeg.node'): unlink('jpeg.node') - else: - if exists('build/default/jpeg.node') and not exists('jpeg.node'): - symlink('build/default/jpeg.node', 'jpeg.node') - From 6311e4ce3cd8505d2453fe464542f3d2e15ffaa3 Mon Sep 17 00:00:00 2001 From: Igor Agarlev Date: Tue, 2 Jul 2013 23:05:55 +0400 Subject: [PATCH 2/3] add cflags, fix readme.txt --- binding.gyp | 15 ++++++++------- readme.txt | 6 +++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/binding.gyp b/binding.gyp index 8c2abd8..0a42a57 100644 --- a/binding.gyp +++ b/binding.gyp @@ -8,14 +8,15 @@ "src/jpeg.cpp", "src/fixed_jpeg_stack.cpp", "src/dynamic_jpeg_stack.cpp", - "src/module.cpp"], + "src/module.cpp" + ], "libraries": ["-lJPEG"], - 'cflags!': [ '-fno-exceptions' ], - 'cflags_cc!': [ '-fno-exceptions' ], - 'conditions': [ - ['OS=="mac"', { - 'xcode_settings': { - 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES' + "cflags!": [ "-fno-exceptions", "-D_FILE_OFFSET_BITS=64", "-D_LARGEFILE_SOURCE" ], + "cflags_cc!": [ "-fno-exceptions", "-D_FILE_OFFSET_BITS=64", "-D_LARGEFILE_SOURCE" ], + "conditions": [ + ["OS=='mac'", { + "xcode_settings": { + "GCC_ENABLE_CPP_EXCEPTIONS": "YES" } }] ] diff --git a/readme.txt b/readme.txt index 65334ac..5b3bd12 100644 --- a/readme.txt +++ b/readme.txt @@ -1,4 +1,4 @@ -This is a node.js module, writen in C++, that uses libjpeg to produce a JPEG +This is a node.js module, written in C++, that uses libjpeg to produce a JPEG image (in memory) from a buffer of RGBA or RGB values. Since JPEG has no notion of A (alpha), the module always uses just RGB values. @@ -23,7 +23,7 @@ Jpeg object that takes 4 arguments in its constructor: var jpeg = new Jpeg(buffer, width, height, [buffer_type]); -The first argument, `buffer`, is a nodee.js `Buffer` filled with RGBA or RGB +The first argument, `buffer`, is a node.js `Buffer` filled with RGBA or RGB values. The second argument is integer width of the image. The third argument is integer height of the image. @@ -108,7 +108,7 @@ How to install? To get it compiled, you need to have libjpeg and node installed. Then just run - node-waf configure build + node-gyp rebuild to build the Jpeg module. It will produce a `jpeg.node` file as the module. From 094ffa27318c167c030a4c85efcf667cec20a8de Mon Sep 17 00:00:00 2001 From: Igor Agarlev Date: Tue, 2 Jul 2013 23:16:51 +0400 Subject: [PATCH 3/3] fix examples --- examples/dynamic-jpeg-stack-async.js | 2 +- examples/dynamic-jpeg-stack.js | 2 +- examples/fixed-jpeg-stack-async.js | 2 +- examples/fixed-jpeg-stack.js | 2 +- examples/jpeg-example-async.js | 2 +- examples/jpeg-example2-async.js | 2 +- examples/jpeg-example2.js | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/dynamic-jpeg-stack-async.js b/examples/dynamic-jpeg-stack-async.js index 90b43e3..b66e892 100644 --- a/examples/dynamic-jpeg-stack-async.js +++ b/examples/dynamic-jpeg-stack-async.js @@ -1,4 +1,4 @@ -var JpegLib = require('jpeg'); +var JpegLib = require('../build/Release/jpeg'); var fs = require('fs'); var sys = require('sys'); var Buffer = require('buffer').Buffer; diff --git a/examples/dynamic-jpeg-stack.js b/examples/dynamic-jpeg-stack.js index bf05b53..e7b4f20 100644 --- a/examples/dynamic-jpeg-stack.js +++ b/examples/dynamic-jpeg-stack.js @@ -1,4 +1,4 @@ -var JpegLib = require('jpeg'); +var JpegLib = require('../build/Release/jpeg'); var fs = require('fs'); var sys = require('sys'); var Buffer = require('buffer').Buffer; diff --git a/examples/fixed-jpeg-stack-async.js b/examples/fixed-jpeg-stack-async.js index e8c8da7..18e894b 100644 --- a/examples/fixed-jpeg-stack-async.js +++ b/examples/fixed-jpeg-stack-async.js @@ -1,4 +1,4 @@ -var JpegLib = require('jpeg'); +var JpegLib = require('../build/Release/jpeg'); var fs = require('fs'); var sys = require('sys'); var Buffer = require('buffer').Buffer; diff --git a/examples/fixed-jpeg-stack.js b/examples/fixed-jpeg-stack.js index 0af0f73..9663d1a 100644 --- a/examples/fixed-jpeg-stack.js +++ b/examples/fixed-jpeg-stack.js @@ -1,4 +1,4 @@ -var JpegLib = require('jpeg'); +var JpegLib = require('../build/Release/jpeg'); var fs = require('fs'); var sys = require('sys'); var Buffer = require('buffer').Buffer; diff --git a/examples/jpeg-example-async.js b/examples/jpeg-example-async.js index 4553cff..957a968 100644 --- a/examples/jpeg-example-async.js +++ b/examples/jpeg-example-async.js @@ -1,6 +1,6 @@ var fs = require('fs'); var sys = require('sys'); -var Jpeg = require('../jpeg').Jpeg; +var Jpeg = require('../build/Release/jpeg').Jpeg; var Buffer = require('buffer').Buffer; var rgba = fs.readFileSync('./rgba-terminal.dat'); diff --git a/examples/jpeg-example2-async.js b/examples/jpeg-example2-async.js index dd04e6c..4dd96a3 100644 --- a/examples/jpeg-example2-async.js +++ b/examples/jpeg-example2-async.js @@ -1,6 +1,6 @@ var fs = require('fs'); var sys = require('sys'); -var Jpeg = require('../jpeg').Jpeg; +var Jpeg = require('../build/Release/jpeg').Jpeg; var Buffer = require('buffer').Buffer; var WIDTH = 400, HEIGHT = 300; diff --git a/examples/jpeg-example2.js b/examples/jpeg-example2.js index 26a1f11..2f6649e 100644 --- a/examples/jpeg-example2.js +++ b/examples/jpeg-example2.js @@ -1,6 +1,6 @@ var fs = require('fs'); var sys = require('sys'); -var Jpeg = require('../jpeg').Jpeg; +var Jpeg = require('../build/Release/jpeg').Jpeg; var Buffer = require('buffer').Buffer; var WIDTH = 400, HEIGHT = 300;