|
@ -29,13 +29,13 @@ init_closure_destination(j_compress_ptr cinfo){ |
|
|
|
|
|
|
|
|
boolean |
|
|
boolean |
|
|
empty_closure_output_buffer(j_compress_ptr cinfo){ |
|
|
empty_closure_output_buffer(j_compress_ptr cinfo){ |
|
|
closure_destination_mgr * dest = (closure_destination_mgr *) cinfo->dest; |
|
|
closure_destination_mgr *dest = (closure_destination_mgr *) cinfo->dest; |
|
|
Local<Buffer> buf = Buffer::New(dest->bufsize); |
|
|
Local<Buffer> buf = Buffer::New(dest->bufsize); |
|
|
memcpy(Buffer::Data(buf->handle_), dest->buffer, dest->bufsize); |
|
|
memcpy(Buffer::Data(buf->handle_), dest->buffer, dest->bufsize); |
|
|
Local<Value> argv[3] = { |
|
|
Local<Value> argv[3] = { |
|
|
Local<Value>::New(Null()), |
|
|
Local<Value>::New(Null()) |
|
|
Local<Value>::New(buf->handle_), |
|
|
, Local<Value>::New(buf->handle_) |
|
|
Integer::New(dest->bufsize) |
|
|
, Integer::New(dest->bufsize) |
|
|
}; |
|
|
}; |
|
|
dest->closure->fn->Call(Context::GetCurrent()->Global(), 3, argv); |
|
|
dest->closure->fn->Call(Context::GetCurrent()->Global(), 3, argv); |
|
|
cinfo->dest->next_output_byte = dest->buffer; |
|
|
cinfo->dest->next_output_byte = dest->buffer; |
|
@ -45,23 +45,27 @@ empty_closure_output_buffer(j_compress_ptr cinfo){ |
|
|
|
|
|
|
|
|
void |
|
|
void |
|
|
term_closure_destination(j_compress_ptr cinfo){ |
|
|
term_closure_destination(j_compress_ptr cinfo){ |
|
|
closure_destination_mgr * dest = (closure_destination_mgr *) cinfo->dest; |
|
|
closure_destination_mgr *dest = (closure_destination_mgr *) cinfo->dest; |
|
|
/* emit remaining data */ |
|
|
/* emit remaining data */ |
|
|
size_t remaining = dest->bufsize - cinfo->dest->free_in_buffer; |
|
|
size_t remaining = dest->bufsize - cinfo->dest->free_in_buffer; |
|
|
Local<Buffer> buf = Buffer::New(remaining); |
|
|
Local<Buffer> buf = Buffer::New(remaining); |
|
|
memcpy(Buffer::Data(buf->handle_), dest->buffer, remaining); |
|
|
memcpy(Buffer::Data(buf->handle_), dest->buffer, remaining); |
|
|
|
|
|
|
|
|
Local<Value> data_argv[3] = { |
|
|
Local<Value> data_argv[3] = { |
|
|
Local<Value>::New(Null()), |
|
|
Local<Value>::New(Null()) |
|
|
Local<Value>::New(buf->handle_), |
|
|
, Local<Value>::New(buf->handle_) |
|
|
Integer::New(remaining) |
|
|
, Integer::New(remaining) |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
dest->closure->fn->Call(Context::GetCurrent()->Global(), 3, data_argv); |
|
|
dest->closure->fn->Call(Context::GetCurrent()->Global(), 3, data_argv); |
|
|
/* emit 'end' */ |
|
|
|
|
|
|
|
|
// emit "end"
|
|
|
Local<Value> end_argv[3] = { |
|
|
Local<Value> end_argv[3] = { |
|
|
Local<Value>::New(Null()), |
|
|
Local<Value>::New(Null()) |
|
|
Local<Value>::New(Null()), |
|
|
, Local<Value>::New(Null()) |
|
|
Integer::New(0) |
|
|
, Integer::New(0) |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
dest->closure->fn->Call(Context::GetCurrent()->Global(), 3, end_argv); |
|
|
dest->closure->fn->Call(Context::GetCurrent()->Global(), 3, end_argv); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -93,11 +97,7 @@ jpeg_closure_dest(j_compress_ptr cinfo, closure_t * closure, int bufsize){ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void |
|
|
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, closure_t *closure){ |
|
|
/*
|
|
|
|
|
|
libjs code adapted from the Cairo R graphics project: |
|
|
|
|
|
http://www.rforge.net/Cairo/
|
|
|
|
|
|
*/ |
|
|
|
|
|
int w = cairo_image_surface_get_width(surface); |
|
|
int w = cairo_image_surface_get_width(surface); |
|
|
int h = cairo_image_surface_get_height(surface); |
|
|
int h = cairo_image_surface_get_height(surface); |
|
|
struct jpeg_compress_struct cinfo; |
|
|
struct jpeg_compress_struct cinfo; |
|
@ -116,10 +116,10 @@ write_to_jpeg_stream(cairo_surface_t *surface, int bufsize, int quality, closure |
|
|
|
|
|
|
|
|
jpeg_start_compress(&cinfo, TRUE); |
|
|
jpeg_start_compress(&cinfo, TRUE); |
|
|
unsigned char *dst; |
|
|
unsigned char *dst; |
|
|
unsigned int *src = (unsigned int*)cairo_image_surface_get_data(surface); |
|
|
unsigned int *src = (unsigned int *) cairo_image_surface_get_data(surface); |
|
|
int sl = 0; |
|
|
int sl = 0; |
|
|
dst = (unsigned char*) malloc(w*3); |
|
|
dst = (unsigned char *) malloc(w * 3); |
|
|
while (sl<h) { |
|
|
while (sl < h) { |
|
|
unsigned char *dp = dst; |
|
|
unsigned char *dp = dst; |
|
|
int x = 0; |
|
|
int x = 0; |
|
|
while (x < w) { |
|
|
while (x < w) { |
|
|