Premultiply alpha channel to avoid dark artifacts during tranformation

Add `Sharp.compare(file1, file2, callback)` function for comparing images
using mean squared error (MSE). This is useful for unit tests.

See:
- https://github.com/jcupitt/libvips/issues/291
- http://entropymine.com/imageworsener/resizealpha/
This commit is contained in:
Daniel Gasienica
2015-05-06 20:58:22 -07:00
committed by Lovell Fuller
parent c792a047b1
commit ef8db1eebf
33 changed files with 755 additions and 85 deletions

View File

@@ -1,9 +1,8 @@
'use strict';
var assert = require('assert');
var sharp = require('../../index');
var fixtures = require('../fixtures');
var sharp = require('../../index');
sharp.cache(0);
@@ -76,4 +75,30 @@ describe('Alpha transparency', function() {
});
});
it('Enlargement with non-nearest neighbor interpolation shouldnt cause dark edges', function(done) {
var BASE_NAME = 'alpha-premultiply-enlargement-2048x1536-paper.png';
var actual = fixtures.path('output.' + BASE_NAME);
var expected = fixtures.expected(BASE_NAME);
sharp(fixtures.inputPngAlphaPremultiplicationSmall)
.resize(2048, 1536)
.interpolateWith('bicubic')
.toFile(actual, function(err) {
if (err) throw err;
fixtures.assertEqual(actual, expected, done);
});
});
it('Reduction with non-nearest neighbor interpolation shouldnt cause dark edges', function(done) {
var BASE_NAME = 'alpha-premultiply-reduction-1024x768-paper.png';
var actual = fixtures.path('output.' + BASE_NAME);
var expected = fixtures.expected(BASE_NAME);
sharp(fixtures.inputPngAlphaPremultiplicationLarge)
.resize(1024, 768)
.interpolateWith('bicubic')
.toFile(actual, function(err) {
if (err) throw err;
fixtures.assertEqual(actual, expected, done);
});
});
});