From 0ae619dfc5fb2676a557475201301460798bf65e Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Sat, 21 Nov 2015 22:18:39 +0000 Subject: [PATCH] Remove stray win32 library that was causing segfaults Explicit int cast to prevent 'loss of precision' warnings Remove unnecessary semver checking from I/O tests --- binding.gyp | 1 - packaging/win/Dockerfile | 2 +- src/utilities.cc | 29 +++-- test/unit/io.js | 235 +++++++++++++++++++-------------------- 4 files changed, 134 insertions(+), 133 deletions(-) diff --git a/binding.gyp b/binding.gyp index 9f48d664..6ae5888d 100644 --- a/binding.gyp +++ b/binding.gyp @@ -165,7 +165,6 @@ '<(module_root_dir)/lib/libgmodule-2.0-0.dll', '<(module_root_dir)/lib/libgobject-2.0-0.dll', '<(module_root_dir)/lib/libgsf-1-114.dll', - '<(module_root_dir)/lib/libgsf-win32-1-114.dll', '<(module_root_dir)/lib/libgthread-2.0-0.dll', '<(module_root_dir)/lib/libintl-8.dll', '<(module_root_dir)/lib/libjpeg-62.dll', diff --git a/packaging/win/Dockerfile b/packaging/win/Dockerfile index a82f6962..3fc81a97 100644 --- a/packaging/win/Dockerfile +++ b/packaging/win/Dockerfile @@ -11,6 +11,6 @@ RUN unzip vips-dev-w64-8.1.1-2.zip # Clean and zip WORKDIR /vips/vips-dev-8.1.1 -RUN rm bin/libvipsCC-42.dll bin/libvips-cpp-42.dll +RUN rm bin/libvipsCC-42.dll bin/libvips-cpp-42.dll bin/libgsf-win32-1-114.dll RUN cp bin/*.dll lib/ RUN GZIP=-9 tar czf /libvips-8.1.1-win.tar.gz include lib/glib-2.0 lib/libvips.lib lib/libglib-2.0.lib lib/libgobject-2.0.lib lib/*.dll diff --git a/src/utilities.cc b/src/utilities.cc index f2c420ee..4a935b27 100644 --- a/src/utilities.cc +++ b/src/utilities.cc @@ -7,11 +7,12 @@ #include "operations.h" #include "utilities.h" -using v8::Local; -using v8::Object; -using v8::Number; -using v8::String; using v8::Boolean; +using v8::Integer; +using v8::Local; +using v8::Number; +using v8::Object; +using v8::String; using Nan::HandleScope; using Nan::New; @@ -38,10 +39,16 @@ NAN_METHOD(cache) { // Get cache statistics Local cache = New(); - Set(cache, New("current").ToLocalChecked(), New(vips_tracked_get_mem() / 1048576)); - Set(cache, New("high").ToLocalChecked(), New(vips_tracked_get_mem_highwater() / 1048576)); - Set(cache, New("memory").ToLocalChecked(), New(vips_cache_get_max_mem() / 1048576)); - Set(cache, New("items").ToLocalChecked(), New(vips_cache_get_max())); + Set(cache, New("current").ToLocalChecked(), + New(static_cast(round(vips_tracked_get_mem() / 1048576))) + ); + Set(cache, New("high").ToLocalChecked(), + New(static_cast(round(vips_tracked_get_mem_highwater() / 1048576))) + ); + Set(cache, New("memory").ToLocalChecked(), + New(static_cast(round(vips_cache_get_max_mem() / 1048576))) + ); + Set(cache, New("items").ToLocalChecked(), New(vips_cache_get_max())); info.GetReturnValue().Set(cache); } @@ -56,7 +63,7 @@ NAN_METHOD(concurrency) { vips_concurrency_set(To(info[0]).FromJust()); } // Get concurrency - info.GetReturnValue().Set(New(vips_concurrency_get())); + info.GetReturnValue().Set(New(vips_concurrency_get())); } /* @@ -68,8 +75,8 @@ NAN_METHOD(counters) { HandleScope(); Local counters = New(); - Set(counters, New("queue").ToLocalChecked(), New(counterQueue)); - Set(counters, New("process").ToLocalChecked(), New(counterProcess)); + Set(counters, New("queue").ToLocalChecked(), New(counterQueue)); + Set(counters, New("process").ToLocalChecked(), New(counterProcess)); info.GetReturnValue().Set(counters); } diff --git a/test/unit/io.js b/test/unit/io.js index 8ec88ff2..16afccf7 100644 --- a/test/unit/io.js +++ b/test/unit/io.js @@ -3,8 +3,6 @@ var fs = require('fs'); var assert = require('assert'); -var semver = require('semver'); - var sharp = require('../../index'); var fixtures = require('../fixtures'); @@ -483,37 +481,34 @@ describe('Input/output', function() { done(); }); - if (semver.gte(sharp.libvipsVersion(), '7.42.0')) { - it('withoutAdaptiveFiltering generates smaller file [libvips ' + sharp.libvipsVersion() + '>=7.42.0]', function(done) { - // First generate with adaptive filtering - sharp(fixtures.inputPng) - .resize(320, 240) - .withoutAdaptiveFiltering(false) - .toBuffer(function(err, adaptiveData, adaptiveInfo) { - if (err) throw err; - assert.strictEqual(true, adaptiveData.length > 0); - assert.strictEqual(adaptiveData.length, adaptiveInfo.size); - assert.strictEqual('png', adaptiveInfo.format); - assert.strictEqual(320, adaptiveInfo.width); - assert.strictEqual(240, adaptiveInfo.height); - // Then generate without - sharp(fixtures.inputPng) - .resize(320, 240) - .withoutAdaptiveFiltering() - .toBuffer(function(err, withoutAdaptiveData, withoutAdaptiveInfo) { - if (err) throw err; - assert.strictEqual(true, withoutAdaptiveData.length > 0); - assert.strictEqual(withoutAdaptiveData.length, withoutAdaptiveInfo.size); - assert.strictEqual('png', withoutAdaptiveInfo.format); - assert.strictEqual(320, withoutAdaptiveInfo.width); - assert.strictEqual(240, withoutAdaptiveInfo.height); - assert.strictEqual(true, withoutAdaptiveData.length < adaptiveData.length); - done(); - }); - }); - }); - } - + it('withoutAdaptiveFiltering generates smaller file', function(done) { + // First generate with adaptive filtering + sharp(fixtures.inputPng) + .resize(320, 240) + .withoutAdaptiveFiltering(false) + .toBuffer(function(err, adaptiveData, adaptiveInfo) { + if (err) throw err; + assert.strictEqual(true, adaptiveData.length > 0); + assert.strictEqual(adaptiveData.length, adaptiveInfo.size); + assert.strictEqual('png', adaptiveInfo.format); + assert.strictEqual(320, adaptiveInfo.width); + assert.strictEqual(240, adaptiveInfo.height); + // Then generate without + sharp(fixtures.inputPng) + .resize(320, 240) + .withoutAdaptiveFiltering() + .toBuffer(function(err, withoutAdaptiveData, withoutAdaptiveInfo) { + if (err) throw err; + assert.strictEqual(true, withoutAdaptiveData.length > 0); + assert.strictEqual(withoutAdaptiveData.length, withoutAdaptiveInfo.size); + assert.strictEqual('png', withoutAdaptiveInfo.format); + assert.strictEqual(320, withoutAdaptiveInfo.width); + assert.strictEqual(240, withoutAdaptiveInfo.height); + assert.strictEqual(true, withoutAdaptiveData.length < adaptiveData.length); + done(); + }); + }); + }); }); it('Without chroma subsampling generates larger file', function(done) { @@ -545,93 +540,93 @@ describe('Input/output', function() { }); }); - if (semver.gte(sharp.libvipsVersion(), '8.0.0')) { - it('Trellis quantisation [libvips ' + sharp.libvipsVersion() + '>=8.0.0]', function(done) { - // First generate without - sharp(fixtures.inputJpg) - .resize(320, 240) - .trellisQuantisation(false) - .toBuffer(function(err, withoutData, withoutInfo) { - if (err) throw err; - assert.strictEqual(true, withoutData.length > 0); - assert.strictEqual(withoutData.length, withoutInfo.size); - assert.strictEqual('jpeg', withoutInfo.format); - assert.strictEqual(320, withoutInfo.width); - assert.strictEqual(240, withoutInfo.height); - // Then generate with - sharp(fixtures.inputJpg) - .resize(320, 240) - .trellisQuantization() - .toBuffer(function(err, withData, withInfo) { - if (err) throw err; - assert.strictEqual(true, withData.length > 0); - assert.strictEqual(withData.length, withInfo.size); - assert.strictEqual('jpeg', withInfo.format); - assert.strictEqual(320, withInfo.width); - assert.strictEqual(240, withInfo.height); - // Verify image is same (as mozjpeg may not be present) size or less - assert.strictEqual(true, withData.length <= withoutData.length); - done(); - }); - }); - }); - it('Overshoot deringing [libvips ' + sharp.libvipsVersion() + '>=8.0.0]', function(done) { - // First generate without - sharp(fixtures.inputJpg) - .resize(320, 240) - .overshootDeringing(false) - .toBuffer(function(err, withoutData, withoutInfo) { - if (err) throw err; - assert.strictEqual(true, withoutData.length > 0); - assert.strictEqual(withoutData.length, withoutInfo.size); - assert.strictEqual('jpeg', withoutInfo.format); - assert.strictEqual(320, withoutInfo.width); - assert.strictEqual(240, withoutInfo.height); - // Then generate with - sharp(fixtures.inputJpg) - .resize(320, 240) - .overshootDeringing() - .toBuffer(function(err, withData, withInfo) { - if (err) throw err; - assert.strictEqual(true, withData.length > 0); - assert.strictEqual(withData.length, withInfo.size); - assert.strictEqual('jpeg', withInfo.format); - assert.strictEqual(320, withInfo.width); - assert.strictEqual(240, withInfo.height); - done(); - }); - }); - }); - it('Optimise scans [libvips ' + sharp.libvipsVersion() + '>=8.0.0]', function(done) { - // First generate without - sharp(fixtures.inputJpg) - .resize(320, 240) - .optimiseScans(false) - .toBuffer(function(err, withoutData, withoutInfo) { - if (err) throw err; - assert.strictEqual(true, withoutData.length > 0); - assert.strictEqual(withoutData.length, withoutInfo.size); - assert.strictEqual('jpeg', withoutInfo.format); - assert.strictEqual(320, withoutInfo.width); - assert.strictEqual(240, withoutInfo.height); - // Then generate with - sharp(fixtures.inputJpg) - .resize(320, 240) - .optimizeScans() - .toBuffer(function(err, withData, withInfo) { - if (err) throw err; - assert.strictEqual(true, withData.length > 0); - assert.strictEqual(withData.length, withInfo.size); - assert.strictEqual('jpeg', withInfo.format); - assert.strictEqual(320, withInfo.width); - assert.strictEqual(240, withInfo.height); - // Verify image is of a different size (progressive output even without mozjpeg) - assert.strictEqual(true, withData.length != withoutData.length); - done(); - }); - }); - }); - } + it('Trellis quantisation', function(done) { + // First generate without + sharp(fixtures.inputJpg) + .resize(320, 240) + .trellisQuantisation(false) + .toBuffer(function(err, withoutData, withoutInfo) { + if (err) throw err; + assert.strictEqual(true, withoutData.length > 0); + assert.strictEqual(withoutData.length, withoutInfo.size); + assert.strictEqual('jpeg', withoutInfo.format); + assert.strictEqual(320, withoutInfo.width); + assert.strictEqual(240, withoutInfo.height); + // Then generate with + sharp(fixtures.inputJpg) + .resize(320, 240) + .trellisQuantization() + .toBuffer(function(err, withData, withInfo) { + if (err) throw err; + assert.strictEqual(true, withData.length > 0); + assert.strictEqual(withData.length, withInfo.size); + assert.strictEqual('jpeg', withInfo.format); + assert.strictEqual(320, withInfo.width); + assert.strictEqual(240, withInfo.height); + // Verify image is same (as mozjpeg may not be present) size or less + assert.strictEqual(true, withData.length <= withoutData.length); + done(); + }); + }); + }); + + it('Overshoot deringing', function(done) { + // First generate without + sharp(fixtures.inputJpg) + .resize(320, 240) + .overshootDeringing(false) + .toBuffer(function(err, withoutData, withoutInfo) { + if (err) throw err; + assert.strictEqual(true, withoutData.length > 0); + assert.strictEqual(withoutData.length, withoutInfo.size); + assert.strictEqual('jpeg', withoutInfo.format); + assert.strictEqual(320, withoutInfo.width); + assert.strictEqual(240, withoutInfo.height); + // Then generate with + sharp(fixtures.inputJpg) + .resize(320, 240) + .overshootDeringing() + .toBuffer(function(err, withData, withInfo) { + if (err) throw err; + assert.strictEqual(true, withData.length > 0); + assert.strictEqual(withData.length, withInfo.size); + assert.strictEqual('jpeg', withInfo.format); + assert.strictEqual(320, withInfo.width); + assert.strictEqual(240, withInfo.height); + done(); + }); + }); + }); + + it('Optimise scans', function(done) { + // First generate without + sharp(fixtures.inputJpg) + .resize(320, 240) + .optimiseScans(false) + .toBuffer(function(err, withoutData, withoutInfo) { + if (err) throw err; + assert.strictEqual(true, withoutData.length > 0); + assert.strictEqual(withoutData.length, withoutInfo.size); + assert.strictEqual('jpeg', withoutInfo.format); + assert.strictEqual(320, withoutInfo.width); + assert.strictEqual(240, withoutInfo.height); + // Then generate with + sharp(fixtures.inputJpg) + .resize(320, 240) + .optimizeScans() + .toBuffer(function(err, withData, withInfo) { + if (err) throw err; + assert.strictEqual(true, withData.length > 0); + assert.strictEqual(withData.length, withInfo.size); + assert.strictEqual('jpeg', withInfo.format); + assert.strictEqual(320, withInfo.width); + assert.strictEqual(240, withInfo.height); + // Verify image is of a different size (progressive output even without mozjpeg) + assert.strictEqual(true, withData.length != withoutData.length); + done(); + }); + }); + }); if (sharp.format.magick.input.file) { it('Convert SVG, if supported, to PNG', function(done) {