Merge pull request #3711 from marcjansen/color
Fix and test ol.color.blend
This commit is contained in:
@@ -64,12 +64,12 @@ ol.color.blend = function(dst, src, opt_color) {
|
|||||||
// FIXME do we need to scale by 255?
|
// FIXME do we need to scale by 255?
|
||||||
var out = goog.isDef(opt_color) ? opt_color : [];
|
var out = goog.isDef(opt_color) ? opt_color : [];
|
||||||
var dstA = dst[3];
|
var dstA = dst[3];
|
||||||
var srcA = dst[3];
|
var srcA = src[3];
|
||||||
if (dstA == 1) {
|
if (dstA == 1) {
|
||||||
out[0] = (src[0] * srcA + dst[0] * (1 - srcA) + 0.5) | 0;
|
out[0] = (src[0] * srcA + dst[0] * (1 - srcA) + 0.5) | 0;
|
||||||
out[1] = (src[1] * srcA + dst[1] * (1 - srcA) + 0.5) | 0;
|
out[1] = (src[1] * srcA + dst[1] * (1 - srcA) + 0.5) | 0;
|
||||||
out[2] = (src[2] * srcA + dst[2] * (1 - srcA) + 0.5) | 0;
|
out[2] = (src[2] * srcA + dst[2] * (1 - srcA) + 0.5) | 0;
|
||||||
out[4] = 1;
|
out[3] = 1;
|
||||||
} else if (srcA === 0) {
|
} else if (srcA === 0) {
|
||||||
out[0] = dst[0];
|
out[0] = dst[0];
|
||||||
out[1] = dst[1];
|
out[1] = dst[1];
|
||||||
|
|||||||
@@ -3,6 +3,33 @@ goog.provide('ol.test.color');
|
|||||||
|
|
||||||
describe('ol.color', function() {
|
describe('ol.color', function() {
|
||||||
|
|
||||||
|
describe('ol.color.blend', function() {
|
||||||
|
it('blends red (a=1) and blue (a=1) to blue (a=1)', function() {
|
||||||
|
var red = [255, 0, 0, 1];
|
||||||
|
var blue = [0, 0, 255, 1];
|
||||||
|
var blended = ol.color.blend(red, blue);
|
||||||
|
expect(blended).to.eql([0, 0, 255, 1]);
|
||||||
|
});
|
||||||
|
it('blends red (a=1) and blue (a=0) to red (a=1)', function() {
|
||||||
|
var red = [255, 0, 0, 1];
|
||||||
|
var blue = [0, 0, 255, 0];
|
||||||
|
var blended = ol.color.blend(red, blue);
|
||||||
|
expect(blended).to.eql([255, 0, 0, 1]);
|
||||||
|
});
|
||||||
|
it('blends red (a=0.5) and blue (a=0.5) to purple (a=0.75)', function() {
|
||||||
|
var red = [255, 0, 0, 0.5];
|
||||||
|
var blue = [0, 0, 255, 0.5];
|
||||||
|
var blended = ol.color.blend(red, blue);
|
||||||
|
expect(blended).to.eql([85, 0, 170, 0.75]);
|
||||||
|
});
|
||||||
|
it('blends red (a=0.5) and blue (a=0) to red (a=0.5)', function() {
|
||||||
|
var red = [255, 0, 0, 0.5];
|
||||||
|
var blue = [0, 0, 255, 0];
|
||||||
|
var blended = ol.color.blend(red, blue);
|
||||||
|
expect(blended).to.eql([255, 0, 0, 0.5]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('ol.color.fromString', function() {
|
describe('ol.color.fromString', function() {
|
||||||
|
|
||||||
before(function() {
|
before(function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user