mirror of
https://github.com/konvajs/konva.git
synced 2025-04-05 20:48:28 +08:00
parent
36247c7bee
commit
268c6bef26
@ -49,6 +49,7 @@
|
||||
<script src="../src/filters/Blur.js" data-cover></script>
|
||||
<script src="../src/filters/Mask.js" data-cover></script>
|
||||
<script src="../src/filters/RGB.js" data-cover></script>
|
||||
<script src="../src/filters/RGBA.js" data-cover></script>
|
||||
<script src="../src/filters/HSV.js" data-cover></script>
|
||||
<script src="../src/filters/HSL.js" data-cover></script>
|
||||
<script src="../src/filters/Emboss.js" data-cover></script>
|
||||
@ -154,6 +155,7 @@
|
||||
<script src="unit/filters/Blur-test.js"></script>
|
||||
<script src="unit/filters/Brighten-test.js"></script>
|
||||
<script src="unit/filters/RGB-test.js"></script>
|
||||
<script src="unit/filters/RGBA-test.js"></script>
|
||||
<script src="unit/filters/HSV-test.js"></script>
|
||||
<script src="unit/filters/HSL-test.js"></script>
|
||||
<script src="unit/filters/Invert-test.js"></script>
|
||||
|
78
test/unit/filters/RGBA-test.js
Normal file
78
test/unit/filters/RGBA-test.js
Normal file
@ -0,0 +1,78 @@
|
||||
suite('RGBA', function() {
|
||||
// ======================================================
|
||||
test('colorize basic', function(done) {
|
||||
var data = [
|
||||
{
|
||||
color: '#ff0000',
|
||||
filter: [170, 170, 170, 0.5],
|
||||
// Actually 212 but in tests rounding half up
|
||||
result: [213, 85, 85, 255]
|
||||
},
|
||||
{
|
||||
color: '#2a6511',
|
||||
filter: [242, 193, 168, 0.33],
|
||||
result: [108, 131, 67, 255]
|
||||
},
|
||||
{
|
||||
color: '#e4d526',
|
||||
filter: [175, 98, 37, 0.79],
|
||||
result: [186, 122, 37, 255]
|
||||
},
|
||||
];
|
||||
|
||||
var stage = new Konva.Stage({
|
||||
container: 'konva-container',
|
||||
width: data.length,
|
||||
height: 1
|
||||
});
|
||||
|
||||
var layer = new Konva.Layer({
|
||||
id: 'layer'
|
||||
});
|
||||
|
||||
for (var i = 0; i < data.length; i += 1) {
|
||||
var d = data[i];
|
||||
|
||||
var rect = new Konva.Rect({
|
||||
x: i,
|
||||
y: 0,
|
||||
width: 1,
|
||||
height: 1,
|
||||
fill: d.color
|
||||
});
|
||||
|
||||
rect.cache();
|
||||
|
||||
rect.red(d.filter[0]);
|
||||
rect.green(d.filter[1]);
|
||||
rect.blue(d.filter[2]);
|
||||
rect.alpha(d.filter[3]);
|
||||
|
||||
rect.filters([Konva.Filters.RGBA]);
|
||||
layer.add(rect);
|
||||
}
|
||||
|
||||
stage.add(layer);
|
||||
layer.batchDraw();
|
||||
|
||||
var context = layer.getCanvas().getContext();
|
||||
|
||||
var imageDataToArray = function (x) {
|
||||
var imageData = context.getImageData(x, 0, 1, 1).data;
|
||||
|
||||
return [
|
||||
imageData['0'], imageData['1'], imageData['2'], imageData['3']
|
||||
];
|
||||
};
|
||||
|
||||
var a0 = imageDataToArray(0);
|
||||
var a1 = imageDataToArray(1);
|
||||
var a2 = imageDataToArray(2);
|
||||
|
||||
assert.deepEqual(a0, data[0].result);
|
||||
assert.deepEqual(a1, data[1].result);
|
||||
assert.deepEqual(a2, data[2].result);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user