Compare commits

...

5 Commits

Author SHA1 Message Date
Lovell Fuller
2f97d04dfa Keep shrink-on-load logic DRY. Ensure canvas option (crop vs embed) is always as requested. 2014-02-03 23:20:38 +00:00
Lovell Fuller
e4ca8f44ec Version bump 2014-02-01 23:00:37 +00:00
Lovell Fuller
6b3dc1e350 Ensure crop occurs on y-axis 2014-02-01 22:58:30 +00:00
Lovell Fuller
7ffcdb79e0 Add glib-2.0 path for Mac OS X 2014-01-30 18:28:24 +00:00
Lovell Fuller
10ce7c6693 Add parallel performance test to demonstrate effect of waiting for a worker thread 2014-01-26 20:16:42 +00:00
4 changed files with 42 additions and 12 deletions

View File

@@ -7,6 +7,8 @@
'<!@(PKG_CONFIG_PATH="/usr/lib/pkgconfig" pkg-config --libs vips)' '<!@(PKG_CONFIG_PATH="/usr/lib/pkgconfig" pkg-config --libs vips)'
], ],
'include_dirs': [ 'include_dirs': [
'/usr/local/include/glib-2.0',
'/usr/local/lib/glib-2.0/include',
'/usr/include/glib-2.0', '/usr/include/glib-2.0',
'/usr/lib/glib-2.0/include', '/usr/lib/glib-2.0/include',
'/usr/lib/x86_64-linux-gnu/glib-2.0/include' '/usr/lib/x86_64-linux-gnu/glib-2.0/include'

View File

@@ -1,6 +1,6 @@
{ {
"name": "sharp", "name": "sharp",
"version": "0.1.1", "version": "0.1.3",
"author": "Lovell Fuller", "author": "Lovell Fuller",
"description": "High performance module to resize JPEG and PNG images using the libvips image processing library", "description": "High performance module to resize JPEG and PNG images using the libvips image processing library",
"scripts": { "scripts": {

View File

@@ -98,22 +98,21 @@ void resize_async(uv_work_t *work) {
int shrink_on_load = 1; int shrink_on_load = 1;
if (inputImageType == JPEG) { if (inputImageType == JPEG) {
if (shrink >= 8) { if (shrink >= 8) {
factor = residual * shrink / 8; factor = factor / 8;
shrink_on_load = 8; shrink_on_load = 8;
shrink = floor(factor);
residual = shrink / factor;
} else if (shrink >= 4) { } else if (shrink >= 4) {
factor = residual * shrink / 4; factor = factor / 4;
shrink_on_load = 4; shrink_on_load = 4;
shrink = floor(factor);
residual = shrink / factor;
} else if (shrink >= 2) { } else if (shrink >= 2) {
factor = residual * shrink / 2; factor = factor / 2;
shrink_on_load = 2; shrink_on_load = 2;
shrink = floor(factor);
residual = shrink / factor;
} }
if (shrink_on_load > 1) { if (shrink_on_load > 1) {
// Recalculate integral shrink and double residual
factor = std::max(factor, 1.0);
shrink = floor(factor);
residual = shrink / factor;
// Reload input using shrink-on-load
g_object_unref(in); g_object_unref(in);
in = vips_image_new(); in = vips_image_new();
if (baton->buffer_in_len > 1) { if (baton->buffer_in_len > 1) {
@@ -151,8 +150,8 @@ void resize_async(uv_work_t *work) {
g_object_unref(shrunk); g_object_unref(shrunk);
VipsImage *canvased = vips_image_new(); VipsImage *canvased = vips_image_new();
if (affined->Xsize != baton->width && affined->Ysize != baton->height) { if (affined->Xsize != baton->width || affined->Ysize != baton->height) {
if (baton->crop && affined->Xsize != baton->width && affined->Ysize != baton->height) { if (baton->crop) {
// Crop // Crop
int width = std::min(affined->Xsize, baton->width); int width = std::min(affined->Xsize, baton->width);
int height = std::min(affined->Ysize, baton->height); int height = std::min(affined->Ysize, baton->height);

29
tests/parallel.js Executable file
View File

@@ -0,0 +1,29 @@
var sharp = require("../index");
var fs = require("fs");
var assert = require("assert");
var async = require("async");
var inputJpg = __dirname + "/2569067123_aca715a2ee_o.jpg"; // http://www.flickr.com/photos/grizdave/2569067123/
var width = 720;
var height = 480;
async.mapSeries([1, 1, 2, 4, 8, 16, 32, 64, 128], function(parallelism, next) {
var start = new Date().getTime();
async.times(parallelism,
function(id, callback) {
sharp.resize(inputJpg, sharp.buffer.jpeg, width, height, function(err, buffer) {
buffer = null;
callback(err, new Date().getTime() - start);
});
},
function(err, ids) {
assert(!err);
assert(ids.length === parallelism);
var mean = ids.reduce(function(a, b) {
return a + b;
}) / ids.length;
console.log(parallelism + " parallel calls: fastest=" + ids[0] + "ms slowest=" + ids[ids.length - 1] + "ms mean=" + mean + "ms");
next();
}
);
}, function() {});