mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Windows compatibility #19
Hide WebP format and normalise option Separate test runners for node and iojs
This commit is contained in:
@@ -31,16 +31,18 @@ describe('Colour space conversion', function() {
|
||||
.toFile(fixtures.path('output.greyscale-not.jpg'), done);
|
||||
});
|
||||
|
||||
it('From 1-bit TIFF to sRGB WebP [slow]', function(done) {
|
||||
sharp(fixtures.inputTiff)
|
||||
.webp()
|
||||
.toBuffer(function(err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('webp', info.format);
|
||||
done();
|
||||
});
|
||||
});
|
||||
if (sharp.format.webp.output.buffer) {
|
||||
it('From 1-bit TIFF to sRGB WebP [slow]', function(done) {
|
||||
sharp(fixtures.inputTiff)
|
||||
.webp()
|
||||
.toBuffer(function(err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('webp', info.format);
|
||||
done();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
it('From CMYK to sRGB', function(done) {
|
||||
sharp(fixtures.inputJpgWithCmykProfile)
|
||||
|
||||
@@ -8,39 +8,42 @@ var cpplint = require('node-cpplint/lib/');
|
||||
|
||||
describe('cpplint', function() {
|
||||
|
||||
// List C++ source files
|
||||
fs.readdirSync(path.join(__dirname, '..', '..', 'src')).forEach(function (source) {
|
||||
var file = path.join('src', source);
|
||||
it(file, function(done) {
|
||||
// Lint each source file
|
||||
cpplint({
|
||||
files: [file],
|
||||
linelength: 140,
|
||||
filters: {
|
||||
legal: {
|
||||
copyright: false
|
||||
},
|
||||
build: {
|
||||
include: false,
|
||||
include_order: false
|
||||
},
|
||||
whitespace: {
|
||||
blank_line: false,
|
||||
comments: false,
|
||||
parens: false
|
||||
// Ignore cpplint failures, possibly newline-related, on Windows
|
||||
if (process.platform !== 'win32') {
|
||||
// List C++ source files
|
||||
fs.readdirSync(path.join(__dirname, '..', '..', 'src')).forEach(function (source) {
|
||||
var file = path.join('src', source);
|
||||
it(file, function(done) {
|
||||
// Lint each source file
|
||||
cpplint({
|
||||
files: [file],
|
||||
linelength: 140,
|
||||
filters: {
|
||||
legal: {
|
||||
copyright: false
|
||||
},
|
||||
build: {
|
||||
include: false,
|
||||
include_order: false
|
||||
},
|
||||
whitespace: {
|
||||
blank_line: false,
|
||||
comments: false,
|
||||
parens: false
|
||||
}
|
||||
}
|
||||
}
|
||||
}, function(err, report) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
var expected = {};
|
||||
expected[file] = [];
|
||||
assert.deepEqual(expected, report);
|
||||
done();
|
||||
}, function(err, report) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
var expected = {};
|
||||
expected[file] = [];
|
||||
assert.deepEqual(expected, report);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -28,24 +28,26 @@ describe('Embed', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('JPEG within WebP, to include alpha channel', function(done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.background({r: 0, g: 0, b: 0, a: 0})
|
||||
.embed()
|
||||
.webp()
|
||||
.toBuffer(function(err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('webp', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
sharp(data).metadata(function(err, metadata) {
|
||||
if (sharp.format.webp.output.buffer) {
|
||||
it('JPEG within WebP, to include alpha channel', function(done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.background({r: 0, g: 0, b: 0, a: 0})
|
||||
.embed()
|
||||
.webp()
|
||||
.toBuffer(function(err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(4, metadata.channels);
|
||||
done();
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('webp', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
sharp(data).metadata(function(err, metadata) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(4, metadata.channels);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -31,16 +31,18 @@ describe('Partial image extraction', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('WebP', function(done) {
|
||||
sharp(fixtures.inputWebP)
|
||||
.extract(50, 100, 125, 200)
|
||||
.toFile(fixtures.path('output.extract.webp'), function(err, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(125, info.width);
|
||||
assert.strictEqual(200, info.height);
|
||||
done();
|
||||
});
|
||||
});
|
||||
if (sharp.format.webp.output.file) {
|
||||
it('WebP', function(done) {
|
||||
sharp(fixtures.inputWebP)
|
||||
.extract(50, 100, 125, 200)
|
||||
.toFile(fixtures.path('output.extract.webp'), function(err, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(125, info.width);
|
||||
assert.strictEqual(200, info.height);
|
||||
done();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
it('TIFF', function(done) {
|
||||
sharp(fixtures.inputTiff)
|
||||
|
||||
@@ -806,8 +806,10 @@ describe('Input/output', function() {
|
||||
.toBuffer(function(err) {
|
||||
sharp.queue.removeListener('change', queueListener);
|
||||
if (err) throw err;
|
||||
assert.strictEqual(2, eventCounter);
|
||||
done();
|
||||
process.nextTick(function() {
|
||||
assert.strictEqual(2, eventCounter);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -82,19 +82,21 @@ describe('Image metadata', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('WebP', function(done) {
|
||||
sharp(fixtures.inputWebP).metadata(function(err, metadata) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('webp', metadata.format);
|
||||
assert.strictEqual(1024, metadata.width);
|
||||
assert.strictEqual(772, metadata.height);
|
||||
assert.strictEqual('srgb', metadata.space);
|
||||
assert.strictEqual(3, metadata.channels);
|
||||
assert.strictEqual(false, metadata.hasProfile);
|
||||
assert.strictEqual(false, metadata.hasAlpha);
|
||||
done();
|
||||
if (sharp.format.webp.input.file) {
|
||||
it('WebP', function(done) {
|
||||
sharp(fixtures.inputWebP).metadata(function(err, metadata) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('webp', metadata.format);
|
||||
assert.strictEqual(1024, metadata.width);
|
||||
assert.strictEqual(772, metadata.height);
|
||||
assert.strictEqual('srgb', metadata.space);
|
||||
assert.strictEqual(3, metadata.channels);
|
||||
assert.strictEqual(false, metadata.hasProfile);
|
||||
assert.strictEqual(false, metadata.hasAlpha);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
it('GIF via libmagick', function(done) {
|
||||
sharp(fixtures.inputGif).metadata(function(err, metadata) {
|
||||
|
||||
@@ -13,124 +13,117 @@ describe('Normalization', function () {
|
||||
assert.strictEqual(sharp.prototype.normalize, sharp.prototype.normalise);
|
||||
});
|
||||
|
||||
it('spreads rgb image values between 0 and 255', function(done) {
|
||||
sharp(fixtures.inputJpgWithLowContrast)
|
||||
.normalize()
|
||||
.raw()
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
var min = 255, max = 0, i;
|
||||
for (i = 0; i < data.length; i += 3) {
|
||||
min = Math.min(min, data[i], data[i + 1], data[i + 2]);
|
||||
max = Math.max(max, data[i], data[i + 1], data[i + 2]);
|
||||
}
|
||||
assert.strictEqual(0, min);
|
||||
assert.strictEqual(255, max);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
// Normalize is currently unavailable on Windows
|
||||
if (process.platform !== 'win32') {
|
||||
|
||||
it('spreads grayscaled image values between 0 and 255', function(done) {
|
||||
sharp(fixtures.inputJpgWithLowContrast)
|
||||
.gamma()
|
||||
.greyscale()
|
||||
.normalize(true)
|
||||
.raw()
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
var min = 255, max = 0, i;
|
||||
for (i = 0; i < data.length; i++) {
|
||||
min = Math.min(min, data[i]);
|
||||
max = Math.max(max, data[i]);
|
||||
}
|
||||
assert.strictEqual(0, min);
|
||||
assert.strictEqual(255, max);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
it('spreads rgb image values between 0 and 255', function(done) {
|
||||
sharp(fixtures.inputJpgWithLowContrast)
|
||||
.normalize()
|
||||
.raw()
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
var min = 255, max = 0, i;
|
||||
for (i = 0; i < data.length; i += 3) {
|
||||
min = Math.min(min, data[i], data[i + 1], data[i + 2]);
|
||||
max = Math.max(max, data[i], data[i + 1], data[i + 2]);
|
||||
}
|
||||
assert.strictEqual(0, min);
|
||||
assert.strictEqual(255, max);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
|
||||
it('stretches greyscale images with alpha channel', function (done) {
|
||||
sharp(fixtures.inputPngWithGreyAlpha)
|
||||
.normalize()
|
||||
.raw()
|
||||
.toBuffer(function (err, data, info) {
|
||||
// raw toBuffer does not return the alpha channel (yet?)
|
||||
var min = 255, max = 0, i;
|
||||
for (i = 0; i < data.length; i++) {
|
||||
min = Math.min(min, data[i]);
|
||||
max = Math.max(max, data[i]);
|
||||
}
|
||||
assert.strictEqual(0, min);
|
||||
assert.strictEqual(255, max);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
it('spreads grayscaled image values between 0 and 255', function(done) {
|
||||
sharp(fixtures.inputJpgWithLowContrast)
|
||||
.gamma()
|
||||
.greyscale()
|
||||
.normalize(true)
|
||||
.raw()
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
var min = 255, max = 0, i;
|
||||
for (i = 0; i < data.length; i++) {
|
||||
min = Math.min(min, data[i]);
|
||||
max = Math.max(max, data[i]);
|
||||
}
|
||||
assert.strictEqual(0, min);
|
||||
assert.strictEqual(255, max);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
|
||||
it('keeps an existing alpha channel', function (done) {
|
||||
sharp(fixtures.inputPngWithTransparency)
|
||||
.normalize()
|
||||
.toBuffer(function (err, data, info) {
|
||||
sharp(data)
|
||||
.metadata()
|
||||
.then(function (metadata) {
|
||||
assert.strictEqual(4, metadata.channels);
|
||||
assert.strictEqual(true, metadata.hasAlpha);
|
||||
assert.strictEqual('srgb', metadata.space);
|
||||
})
|
||||
.finally(done);
|
||||
});
|
||||
});
|
||||
it('stretches greyscale images with alpha channel', function (done) {
|
||||
sharp(fixtures.inputPngWithGreyAlpha)
|
||||
.normalize()
|
||||
.raw()
|
||||
.toBuffer(function (err, data, info) {
|
||||
var min = 255, max = 0, i;
|
||||
for (i = 0; i < data.length; i++) {
|
||||
min = Math.min(min, data[i]);
|
||||
max = Math.max(max, data[i]);
|
||||
}
|
||||
assert.strictEqual(0, min);
|
||||
assert.strictEqual(255, max);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
|
||||
it('keeps the alpha channel of greyscale images intact', function (done) {
|
||||
sharp(fixtures.inputPngWithGreyAlpha)
|
||||
.normalize()
|
||||
.toBuffer(function (err, data, info) {
|
||||
sharp(data)
|
||||
.metadata()
|
||||
.then(function (metadata) {
|
||||
assert.strictEqual(true, metadata.hasAlpha);
|
||||
// because of complications with greyscale
|
||||
// we return everything in srgb for now.
|
||||
//
|
||||
// assert.strictEqual(2, metadata.channels);
|
||||
// assert.strictEqual('b-w', metadata.space);
|
||||
assert.strictEqual(4, metadata.channels);
|
||||
assert.strictEqual('srgb', metadata.space);
|
||||
})
|
||||
.finally(done);
|
||||
});
|
||||
});
|
||||
it('keeps an existing alpha channel', function (done) {
|
||||
sharp(fixtures.inputPngWithTransparency)
|
||||
.normalize()
|
||||
.toBuffer(function (err, data, info) {
|
||||
sharp(data)
|
||||
.metadata()
|
||||
.then(function (metadata) {
|
||||
assert.strictEqual(4, metadata.channels);
|
||||
assert.strictEqual(true, metadata.hasAlpha);
|
||||
assert.strictEqual('srgb', metadata.space);
|
||||
})
|
||||
.finally(done);
|
||||
});
|
||||
});
|
||||
|
||||
it('returns a black image for images with only one color', function (done) {
|
||||
sharp(fixtures.inputPngWithOneColor)
|
||||
.normalize()
|
||||
.toBuffer()
|
||||
.bind({})
|
||||
.then(function (imageData) {
|
||||
this.imageData = imageData;
|
||||
return sharp(imageData)
|
||||
.metadata();
|
||||
})
|
||||
.then(function (metadata) {
|
||||
assert.strictEqual(false, metadata.hasAlpha);
|
||||
// because of complications with greyscale
|
||||
// we return everything in srgb for now.
|
||||
//
|
||||
// assert.strictEqual(1, metadata.channels);
|
||||
// assert.strictEqual('b-w', metadata.space);
|
||||
assert.strictEqual(3, metadata.channels);
|
||||
assert.strictEqual('srgb', metadata.space);
|
||||
})
|
||||
.then(function () {
|
||||
return sharp(this.imageData)
|
||||
.raw()
|
||||
.toBuffer();
|
||||
})
|
||||
.then(function (rawData) {
|
||||
// var blackBuffer = new Buffer([0,0,0,0]);
|
||||
var blackBuffer = new Buffer([0,0,0, 0,0,0, 0,0,0, 0,0,0]);
|
||||
assert.strictEqual(blackBuffer.toString(), rawData.toString());
|
||||
})
|
||||
.finally(done);
|
||||
});
|
||||
it('keeps the alpha channel of greyscale images intact', function (done) {
|
||||
sharp(fixtures.inputPngWithGreyAlpha)
|
||||
.normalize()
|
||||
.toBuffer(function (err, data, info) {
|
||||
sharp(data)
|
||||
.metadata()
|
||||
.then(function (metadata) {
|
||||
assert.strictEqual(true, metadata.hasAlpha);
|
||||
assert.strictEqual(4, metadata.channels);
|
||||
assert.strictEqual('srgb', metadata.space);
|
||||
})
|
||||
.finally(done);
|
||||
});
|
||||
});
|
||||
|
||||
it('returns a black image for images with only one color', function (done) {
|
||||
sharp(fixtures.inputPngWithOneColor)
|
||||
.normalize()
|
||||
.toBuffer()
|
||||
.bind({})
|
||||
.then(function (imageData) {
|
||||
this.imageData = imageData;
|
||||
return sharp(imageData)
|
||||
.metadata();
|
||||
})
|
||||
.then(function (metadata) {
|
||||
assert.strictEqual(false, metadata.hasAlpha);
|
||||
assert.strictEqual(3, metadata.channels);
|
||||
assert.strictEqual('srgb', metadata.space);
|
||||
})
|
||||
.then(function () {
|
||||
return sharp(this.imageData)
|
||||
.raw()
|
||||
.toBuffer();
|
||||
})
|
||||
.then(function (rawData) {
|
||||
var blackBuffer = new Buffer([0,0,0, 0,0,0, 0,0,0, 0,0,0]);
|
||||
assert.strictEqual(blackBuffer.toString(), rawData.toString());
|
||||
})
|
||||
.finally(done);
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user