2017-03-13 15:28:51 -04:00
|
|
|
'use strict';
|
2017-04-12 16:55:03 -04:00
|
|
|
var loadImage = require('../../lib/loadImage');
|
2017-03-13 15:28:51 -04:00
|
|
|
|
|
|
|
var pngImage = 'specs/data/box-complex-material/shininess.png';
|
|
|
|
var jpgImage = 'specs/data/box-complex-material/emission.jpg';
|
|
|
|
var jpegImage = 'specs/data/box-complex-material/specular.jpeg';
|
|
|
|
var gifImage = 'specs/data/box-complex-material/ambient.gif';
|
|
|
|
var grayscaleImage = 'specs/data/box-complex-material/alpha.png';
|
|
|
|
var transparentImage = 'specs/data/box-complex-material/diffuse.png';
|
2017-04-10 17:57:56 -04:00
|
|
|
|
2017-04-18 11:56:08 -04:00
|
|
|
describe('loadImage', function() {
|
2017-03-13 15:28:51 -04:00
|
|
|
it('loads png image', function(done) {
|
2017-05-04 17:58:13 -04:00
|
|
|
expect(loadImage(pngImage)
|
2017-03-13 15:28:51 -04:00
|
|
|
.then(function(info) {
|
|
|
|
expect(info.transparent).toBe(false);
|
2017-03-17 15:44:01 -04:00
|
|
|
expect(info.source).toBeDefined();
|
|
|
|
expect(info.extension).toBe('.png');
|
2017-05-04 17:58:13 -04:00
|
|
|
expect(info.path).toBe(pngImage);
|
|
|
|
expect(info.decoded).toBeUndefined();
|
|
|
|
expect(info.width).toBeUndefined();
|
|
|
|
expect(info.height).toBeUndefined();
|
2017-03-13 15:28:51 -04:00
|
|
|
}), done).toResolve();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('loads jpg image', function(done) {
|
2017-05-04 17:58:13 -04:00
|
|
|
expect(loadImage(jpgImage)
|
2017-03-13 15:28:51 -04:00
|
|
|
.then(function(info) {
|
|
|
|
expect(info.transparent).toBe(false);
|
2017-03-17 15:44:01 -04:00
|
|
|
expect(info.source).toBeDefined();
|
|
|
|
expect(info.extension).toBe('.jpg');
|
2017-05-04 17:58:13 -04:00
|
|
|
expect(info.decoded).toBeUndefined();
|
|
|
|
expect(info.width).toBeUndefined();
|
|
|
|
expect(info.height).toBeUndefined();
|
2017-03-13 15:28:51 -04:00
|
|
|
}), done).toResolve();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('loads jpeg image', function(done) {
|
2017-05-04 17:58:13 -04:00
|
|
|
expect(loadImage(jpegImage)
|
2017-03-13 15:28:51 -04:00
|
|
|
.then(function(info) {
|
|
|
|
expect(info.transparent).toBe(false);
|
2017-03-17 15:44:01 -04:00
|
|
|
expect(info.source).toBeDefined();
|
|
|
|
expect(info.extension).toBe('.jpeg');
|
2017-05-04 17:58:13 -04:00
|
|
|
expect(info.decoded).toBeUndefined();
|
|
|
|
expect(info.width).toBeUndefined();
|
|
|
|
expect(info.height).toBeUndefined();
|
2017-03-13 15:28:51 -04:00
|
|
|
}), done).toResolve();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('loads gif image', function(done) {
|
2017-05-04 17:58:13 -04:00
|
|
|
expect(loadImage(gifImage)
|
2017-03-13 15:28:51 -04:00
|
|
|
.then(function(info) {
|
|
|
|
expect(info.transparent).toBe(false);
|
2017-03-17 15:44:01 -04:00
|
|
|
expect(info.source).toBeDefined();
|
|
|
|
expect(info.extension).toBe('.gif');
|
2017-05-04 17:58:13 -04:00
|
|
|
expect(info.decoded).toBeUndefined();
|
|
|
|
expect(info.width).toBeUndefined();
|
|
|
|
expect(info.height).toBeUndefined();
|
2017-03-13 15:28:51 -04:00
|
|
|
}), done).toResolve();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('loads grayscale image', function(done) {
|
2017-05-04 17:58:13 -04:00
|
|
|
expect(loadImage(grayscaleImage)
|
2017-03-13 15:28:51 -04:00
|
|
|
.then(function(info) {
|
|
|
|
expect(info.transparent).toBe(false);
|
2017-03-17 15:44:01 -04:00
|
|
|
expect(info.source).toBeDefined();
|
|
|
|
expect(info.extension).toBe('.png');
|
2017-03-13 15:28:51 -04:00
|
|
|
}), done).toResolve();
|
|
|
|
});
|
|
|
|
|
2017-04-10 17:57:56 -04:00
|
|
|
it('loads image with alpha channel', function(done) {
|
2017-05-04 17:58:13 -04:00
|
|
|
expect(loadImage(transparentImage)
|
2017-03-13 15:28:51 -04:00
|
|
|
.then(function(info) {
|
2017-04-10 17:57:56 -04:00
|
|
|
expect(info.transparent).toBe(false);
|
2017-03-15 13:05:32 -04:00
|
|
|
}), done).toResolve();
|
|
|
|
});
|
|
|
|
|
2017-04-10 17:57:56 -04:00
|
|
|
it('loads image with checkTransparency flag', function(done) {
|
2017-05-04 17:58:13 -04:00
|
|
|
var options = {
|
|
|
|
checkTransparency : true
|
|
|
|
};
|
2017-03-17 16:05:51 -04:00
|
|
|
|
2017-04-10 17:57:56 -04:00
|
|
|
expect(loadImage(transparentImage, options)
|
2017-03-15 13:05:32 -04:00
|
|
|
.then(function(info) {
|
2017-04-10 17:57:56 -04:00
|
|
|
expect(info.transparent).toBe(true);
|
2017-03-13 15:28:51 -04:00
|
|
|
}), done).toResolve();
|
|
|
|
});
|
2017-05-04 17:58:13 -04:00
|
|
|
|
|
|
|
it('loads and decodes png', function(done) {
|
|
|
|
var options = {
|
|
|
|
decode : true
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(loadImage(pngImage, options)
|
|
|
|
.then(function(info) {
|
|
|
|
expect(info.decoded).toBeDefined();
|
|
|
|
expect(info.width).toBe(211);
|
|
|
|
expect(info.height).toBe(211);
|
|
|
|
}), done).toResolve();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('loads and decodes jpeg', function(done) {
|
|
|
|
var options = {
|
|
|
|
decode : true
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(loadImage(jpegImage, options)
|
|
|
|
.then(function(info) {
|
|
|
|
expect(info.decoded).toBeDefined();
|
|
|
|
expect(info.width).toBe(211);
|
|
|
|
expect(info.height).toBe(211);
|
|
|
|
}), done).toResolve();
|
|
|
|
});
|
2017-03-13 15:28:51 -04:00
|
|
|
});
|