Browse Source

Merge branch 'master' of github.com:LearnBoost/node-canvas

v1.x
TJ Holowaychuk 12 years ago
parent
commit
15d03ab3b1
  1. 1
      lib/canvas.js
  2. 2
      lib/jpegstream.js
  3. 8
      src/Canvas.cc
  4. 4
      src/JPEGStream.h

1
lib/canvas.js

@ -185,6 +185,7 @@ Canvas.prototype.createSyncJPEGStream = function(options){
return new JPEGStream(this, {
bufsize: options.bufsize || 4096
, quality: options.quality || 75
, progressive: options.progressive || false
});
};

2
lib/jpegstream.js

@ -40,7 +40,7 @@ var JPEGStream = module.exports = function JPEGStream(canvas, options, sync) {
// TODO: implement async
if ('streamJPEG' == method) method = 'streamJPEGSync';
process.nextTick(function(){
canvas[method](options.bufsize, options.quality, function(err, chunk, len){
canvas[method](options.bufsize, options.quality, options.progressive, function(err, chunk, len){
if (err) {
self.emit('error', err);
self.readable = false;

8
src/Canvas.cc

@ -444,15 +444,17 @@ NAN_METHOD(Canvas::StreamJPEGSync) {
return NanThrowTypeError("buffer size required");
if (!args[1]->IsNumber())
return NanThrowTypeError("quality setting required");
if (!args[2]->IsFunction())
if (!args[2]->IsBoolean())
return NanThrowTypeError("progressive setting required");
if (!args[3]->IsFunction())
return NanThrowTypeError("callback function required");
Canvas *canvas = ObjectWrap::Unwrap<Canvas>(args.This());
closure_t closure;
closure.fn = Handle<Function>::Cast(args[2]);
closure.fn = Handle<Function>::Cast(args[3]);
TryCatch try_catch;
write_to_jpeg_stream(canvas->surface(), args[0]->NumberValue(), args[1]->NumberValue(), &closure);
write_to_jpeg_stream(canvas->surface(), args[0]->NumberValue(), args[1]->NumberValue(), args[2]->BooleanValue(), &closure);
if (try_catch.HasCaught())
NanReturnValue(try_catch.ReThrow());

4
src/JPEGStream.h

@ -96,7 +96,7 @@ jpeg_closure_dest(j_compress_ptr cinfo, closure_t * closure, int bufsize){
}
void
write_to_jpeg_stream(cairo_surface_t *surface, int bufsize, int quality, closure_t *closure){
write_to_jpeg_stream(cairo_surface_t *surface, int bufsize, int quality, bool progressive, closure_t *closure){
int w = cairo_image_surface_get_width(surface);
int h = cairo_image_surface_get_height(surface);
struct jpeg_compress_struct cinfo;
@ -110,6 +110,8 @@ write_to_jpeg_stream(cairo_surface_t *surface, int bufsize, int quality, closure
cinfo.image_width = w;
cinfo.image_height = h;
jpeg_set_defaults(&cinfo);
if (progressive)
jpeg_simple_progression(&cinfo);
jpeg_set_quality(&cinfo, quality, (quality<25)?0:1);
jpeg_closure_dest(&cinfo, closure, bufsize);

Loading…
Cancel
Save