Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
68 changed files
with
1,371 additions
and
1,179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
'use strict'; | ||
|
||
var path = require('path'); | ||
|
||
module.exports = function(config) { | ||
var grep = config.grep, | ||
cfg = { | ||
frameworks: ['mocha'], | ||
preprocessors: {}, | ||
webpack: { | ||
devtool: 'inline-source-map', | ||
module: { | ||
loaders: [ | ||
{ | ||
test: /\/stylesheet\/.*\.js$/, | ||
exclude: /(node_modules|bower_components)/, | ||
loader: 'babel-loader', | ||
query: { | ||
plugins: ['static-fs'] | ||
} | ||
}, | ||
{ | ||
test: /\/test\/functional\/browser\.js$/, | ||
exclude: /(node_modules|bower_components)/, | ||
loader: 'babel-loader', | ||
query: { | ||
plugins: ['static-fs'] | ||
} | ||
}, | ||
{ | ||
test: /jimp\/browser\/lib\/jimp\.js$/, | ||
loader: 'exports-loader', | ||
options: { | ||
Jimp: true | ||
} | ||
} | ||
] | ||
}, | ||
resolve: { | ||
alias: { | ||
proxyquire: path.resolve(__dirname, './lib/browser/function.js'), | ||
canvas: path.resolve(__dirname, './lib/browser/canvasFacade.js'), | ||
mkdirp: path.resolve(__dirname, './lib/browser/function.js'), | ||
gm: path.resolve(__dirname, './lib/browser/function.js'), | ||
jimp: path.resolve(__dirname, './node_modules/jimp/browser/lib/jimp.js') | ||
} | ||
} | ||
}, | ||
plugins: [ | ||
'karma-webpack', | ||
'karma-mocha', | ||
'karma-sourcemap-loader', | ||
'karma-firefox-launcher' | ||
] | ||
}; | ||
|
||
cfg.files = [grep]; | ||
cfg.preprocessors[grep] = ['webpack', 'sourcemap']; | ||
|
||
config.set(cfg); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict'; | ||
|
||
module.exports = function () {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict'; | ||
|
||
var message = 'You are doing something that is not supported in the browser'; | ||
|
||
module.exports = function rejectWithNotInBrowser() { | ||
var callback = Array.prototype.slice.call(arguments).find(function (f) { | ||
return typeof f === 'function'; | ||
}); | ||
if (callback) { | ||
return callback(new Error(message)); | ||
} else { | ||
throw new Error(message); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict'; | ||
|
||
module.exports = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'use strict'; | ||
|
||
var Promise = require('bluebird'), | ||
_ = require('underscore'); | ||
|
||
module.exports = function createCanvasCompositor(window) { | ||
function readImage(rawImg) { | ||
const image = new window.Image(); | ||
|
||
return new Promise(function (resolve, reject) { | ||
image.onload = function () { | ||
resolve({ | ||
path: rawImg.path, | ||
width: image.width, | ||
height: image.height, | ||
data: image | ||
}); | ||
}; | ||
image.onerror = function (e) { | ||
reject(e); | ||
}; | ||
image.src = window.URL.createObjectURL(new window.Blob([rawImg.data])); | ||
}); | ||
} | ||
|
||
function renderSprite(layout) { | ||
const canvasEl = window.document.createElement('canvas'); | ||
|
||
canvasEl.width = layout.width; | ||
canvasEl.height = layout.height; | ||
|
||
const ctx = canvasEl.getContext('2d'); | ||
|
||
// render images to canvas | ||
_(layout.images).each(function (image) { | ||
ctx.drawImage(image.data, image.x, image.y, image.width, image.height); | ||
}); | ||
|
||
return Promise.fromCallback(function (callback) { | ||
canvasEl.toBlob((blob) => { | ||
const reader = new window.FileReader(); | ||
reader.onloadend = () => callback(null, new Uint8Array(reader.result)); | ||
reader.readAsArrayBuffer(blob); | ||
}); | ||
}); | ||
} | ||
|
||
return { | ||
readImage: readImage, | ||
render: renderSprite | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,53 @@ | ||
'use strict'; | ||
|
||
var Promise = require('bluebird'), | ||
_ = require('underscore'), | ||
Canvas = require('canvas'), | ||
Image = Canvas.Image; | ||
|
||
function readImage(rawImg) { | ||
var image = new Image(); | ||
|
||
image.src = rawImg.data; | ||
|
||
return Promise.resolve({ | ||
path: rawImg.path, | ||
width: image.width, | ||
height: image.height, | ||
data: image | ||
}); | ||
} | ||
|
||
function filterToParam(filter, canvasInstance) { | ||
var filterMap = { | ||
none: canvasInstance.PNG_FILTER_NONE, | ||
sub: canvasInstance.PNG_FILTER_SUB, | ||
up: canvasInstance.PNG_FILTER_UP, | ||
average: canvasInstance.PNG_FILTER_AVG, | ||
paeth: canvasInstance.PNG_FILTER_PAETH, | ||
all: canvasInstance.PNG_ALL_FILTERS | ||
}; | ||
|
||
return filterMap[filter]; | ||
} | ||
|
||
function renderSprite(layout, spritePath, options) { | ||
var canvas = new Canvas(layout.width, layout.height), | ||
ctx = canvas.getContext('2d'); | ||
|
||
// render images to canvas | ||
_(layout.images).each(function (image) { | ||
ctx.drawImage(image.data, image.x, image.y, image.width, image.height); | ||
}); | ||
|
||
// store canvas to file, we need to use this new promise because of the weird signature of toBuffer | ||
return Promise.fromCallback(function (promiseCallback) { | ||
return canvas.toBuffer(promiseCallback, options.compressionLevel, filterToParam(options.filter, canvas)); | ||
}); | ||
} | ||
|
||
module.exports = { | ||
readImage: readImage, | ||
render: renderSprite, | ||
filterToParam: filterToParam | ||
_ = require('underscore'); | ||
|
||
module.exports = function createCanvasCompositor(Canvas) { | ||
function readImage(rawImg) { | ||
var image = new Canvas.Image(); | ||
|
||
image.src = rawImg.data; | ||
|
||
return Promise.resolve({ | ||
path: rawImg.path, | ||
width: image.width, | ||
height: image.height, | ||
data: image | ||
}); | ||
} | ||
|
||
function filterToParam(filter, canvasInstance) { | ||
var filterMap = { | ||
none: canvasInstance.PNG_FILTER_NONE, | ||
sub: canvasInstance.PNG_FILTER_SUB, | ||
up: canvasInstance.PNG_FILTER_UP, | ||
average: canvasInstance.PNG_FILTER_AVG, | ||
paeth: canvasInstance.PNG_FILTER_PAETH, | ||
all: canvasInstance.PNG_ALL_FILTERS | ||
}; | ||
|
||
return filterMap[filter]; | ||
} | ||
|
||
function renderSprite(layout, spritePath, options) { | ||
var canvas = new Canvas(layout.width, layout.height), | ||
ctx = canvas.getContext('2d'); | ||
|
||
// render images to canvas | ||
_(layout.images).each(function (image) { | ||
ctx.drawImage(image.data, image.x, image.y, image.width, image.height); | ||
}); | ||
|
||
// store canvas to file, we need to use this new promise because of the weird signature of toBuffer | ||
return Promise.fromCallback(function (promiseCallback) { | ||
return canvas.toBuffer(promiseCallback, options.compressionLevel, filterToParam(options.filter, canvas)); | ||
}); | ||
} | ||
|
||
return { | ||
readImage: readImage, | ||
render: renderSprite, | ||
filterToParam: filterToParam | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
jimp: require('./jimp') | ||
jimp: require('./jimp')(require('jimp')) | ||
}; | ||
|
||
try { | ||
module.exports.canvas = require('./canvas'); | ||
module.exports.canvas = require('./canvas')(require('canvas')); | ||
} catch (e) { | ||
/*eslint no-empty: 0*/ | ||
} | ||
try { | ||
module.exports.gm = require('./gm'); | ||
module.exports.gm = require('./gm')(require('gm')); | ||
} catch (e) { | ||
/*eslint no-empty: 0*/ | ||
} |
Oops, something went wrong.