diff --git a/Gruntfile.js b/Gruntfile.js
index 10d5fc8c..f03071df 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -90,13 +90,15 @@ module.exports = function(grunt) {
browser : true,
trailing : true,
curly : true,
- globals : {'$':true, 'jQuery' : true, 'pskl':true, 'Events':true, 'Constants':true, 'console' : true, 'module':true, 'require':true, 'Q':true}
+ globals : {'$':true, 'jQuery' : true, 'pskl':true, 'Events':true, 'Constants':true, 'console' : true, 'module':true, 'require':true, 'Q':true, 'Promise': true}
},
files: [
+ // Includes
'Gruntfile.js',
'package.json',
'src/js/**/*.js',
- '!src/js/**/lib/**/*.js' // Exclude lib folder (note the leading !)
+ // Excludes
+ '!src/js/**/lib/**/*.js'
]
},
diff --git a/karma.conf.js b/karma.conf.js
index a54f4be0..5cfd162f 100644
--- a/karma.conf.js
+++ b/karma.conf.js
@@ -11,7 +11,7 @@ module.exports = function(config) {
// Polyfill for Object.assign (missing in PhantomJS)
piskelScripts.push('./node_modules/phantomjs-polyfill-object-assign/object-assign-polyfill.js');
-
+
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
@@ -24,7 +24,9 @@ module.exports = function(config) {
// list of files / patterns to load in the browser
- files: piskelScripts,
+ files: piskelScripts.concat([
+ './node_modules/promise-polyfill/promise.js'
+ ]),
// list of files to exclude
diff --git a/package.json b/package.json
index 44858ca6..818e34aa 100644
--- a/package.json
+++ b/package.json
@@ -52,7 +52,8 @@
"karma-phantomjs-launcher": "0.2.3",
"load-grunt-tasks": "3.5.0",
"phantomjs": "2.1.7",
- "phantomjs-polyfill-object-assign": "0.0.2"
+ "phantomjs-polyfill-object-assign": "0.0.2",
+ "promise-polyfill": "6.0.2"
},
"window": {
"title": "Piskel",
diff --git a/src/js/utils/FrameUtils.js b/src/js/utils/FrameUtils.js
index 810f0c36..c1f6bd63 100644
--- a/src/js/utils/FrameUtils.js
+++ b/src/js/utils/FrameUtils.js
@@ -177,74 +177,60 @@
},
/**
- * Alpha compositing using porter duff algorithm :
- * http://en.wikipedia.org/wiki/Alpha_compositing
- * http://keithp.com/~keithp/porterduff/p253-porter.pdf
- * @param {String} strColor1 color over
- * @param {String} strColor2 color under
- * @return {String} the composite color
+ * Create a Frame array from an Image object.
+ * Transparent pixels will either be converted to completely opaque or completely transparent pixels.
+ *
+ * @param {Image} image source image
+ * @param {Number} frameCount number of frames in the spritesheet
+ * @return {Array}
*/
- mergePixels__ : function (strColor1, strColor2, globalOpacity1) {
- var col1 = pskl.utils.FrameUtils.toRgba__(strColor1);
- var col2 = pskl.utils.FrameUtils.toRgba__(strColor2);
- if (typeof globalOpacity1 == 'number') {
- col1 = JSON.parse(JSON.stringify(col1));
- col1.a = globalOpacity1 * col1.a;
+ createFramesFromSpritesheet : function (image, frameCount) {
+ var layout = [];
+ for (var i = 0 ; i < frameCount ; i++) {
+ layout.push([i]);
}
- var a = col1.a + col2.a * (1 - col1.a);
-
- var r = ((col1.r * col1.a + col2.r * col2.a * (1 - col1.a)) / a) | 0;
- var g = ((col1.g * col1.a + col2.g * col2.a * (1 - col1.a)) / a) | 0;
- var b = ((col1.b * col1.a + col2.b * col2.a * (1 - col1.a)) / a) | 0;
-
- return 'rgba(' + r + ',' + g + ',' + b + ',' + a + ')';
+ var chunkFrames = pskl.utils.FrameUtils.createFramesFromChunk(image, layout);
+ return chunkFrames.map(function (chunkFrame) {
+ return chunkFrame.frame;
+ });
},
/**
- * Convert a color defined as a string (hex, rgba, rgb, 'TRANSPARENT') to an Object with r,g,b,a properties.
- * r, g and b are integers between 0 and 255, a is a float between 0 and 1
- * @param {String} c color as a string
- * @return {Object} {r:Number,g:Number,b:Number,a:Number}
+ * Create a Frame array from an Image object.
+ * Transparent pixels will either be converted to completely opaque or completely transparent pixels.
+ *
+ * @param {Image} image source image
+ * @param {Array } layout description of the frame indexes expected to be found in the chunk
+ * @return {Array