mirror of
https://github.com/publiclab/image-sequencer.git
synced 2025-12-16 05:10:00 +01:00
Add replace color module (#724)
* Add color separation module * changes * changes * changes * changes * Add test
This commit is contained in:
48
test/core/modules/replace-color.js
Normal file
48
test/core/modules/replace-color.js
Normal file
@@ -0,0 +1,48 @@
|
||||
var test = require('tape');
|
||||
var base64Img = require('base64-img');
|
||||
var looksSame = require('looks-same');
|
||||
|
||||
require('../../../src/ImageSequencer.js');
|
||||
|
||||
var sequencer = ImageSequencer({ ui: false });
|
||||
var options = {"replaceMethod": "greyscale",
|
||||
"replaceColor": "0 0 255",
|
||||
"color": "228 86 81",
|
||||
"tolerance": "50" };
|
||||
|
||||
var target = 'test_outputs';
|
||||
var red = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABlBMVEX+AAD///+KQee0AAAAAWJLR0QB/wIt3gAAAAd0SU1FB+EGHRIVAvrm6EMAAAAMSURBVAjXY2AgDQAAADAAAceqhY4AAAAldEVYdGRhdGU6Y3JlYXRlADIwMTctMDYtMjlUMTg6MjE6MDIrMDI6MDDGD83DAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE3LTA2LTI5VDE4OjIxOjAyKzAyOjAwt1J1fwAAAABJRU5ErkJggg==";
|
||||
var benchmark = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAklEQVR4AewaftIAAAApSURBVKXBAQEAAAiAIPP/5mqEMAtHIJFEEkkkkUQSSSSRRBJJJJFEEj1UXgIdx5M8pQAAAABJRU5ErkJggg==";
|
||||
|
||||
// Test 1 to check replace-color module is getting loaded
|
||||
test('Load replace-color module', function(t) {
|
||||
sequencer.loadImages('test', red);
|
||||
sequencer.addSteps('replace-color', options);
|
||||
t.equal(sequencer.images.test.steps[1].options.name, 'replace-color', 'replace-color module is getting loaded');
|
||||
t.end();
|
||||
});
|
||||
|
||||
// Test 2 to check options are correct
|
||||
test('Check Options', function(t) {
|
||||
t.equal(sequencer.images.test.steps[1].options.replaceMethod, "greyscale", 'replaceMethod option is correct');
|
||||
t.equal(sequencer.images.test.steps[1].options.replaceColor, "0 0 255", 'replaceColor option is correct');
|
||||
t.equal(sequencer.images.test.steps[1].options.color, "228 86 81", 'color option is correct');
|
||||
t.equal(sequencer.images.test.steps[1].options.tolerance, "50", 'tolerance option is correct');
|
||||
t.end();
|
||||
});
|
||||
|
||||
// Test 3 to check threshold module works as expected
|
||||
test('replace-color module works correctly', function(t) {
|
||||
sequencer.run({ mode: 'test' }, function(out) {
|
||||
var result = sequencer.images.test.steps[1].output.src
|
||||
base64Img.imgSync(result, target, 'result')
|
||||
base64Img.imgSync(benchmark, target, 'benchmark')
|
||||
result = './test_outputs/result.png'
|
||||
benchmark = './test_outputs/benchmark.png'
|
||||
looksSame(result, benchmark, function(err, res) {
|
||||
if (err) console.log(err)
|
||||
t.equal(res.equal, true)
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user