triangulate-image
Advanced tools
Comparing version 0.0.1 to 0.1.0
'use strict'; | ||
var clamp = require('./util/clamp.js'); | ||
var defaultParams = require('./defaultParams.js'); | ||
var fromImageToImageData = require('./input/fromImageToImageData.js'); | ||
var fromBufferToImageData = require('./input/fromBufferToImageData.js'); | ||
@@ -10,2 +12,4 @@ var polygonsToImageData = require('./output/polygonsToImageData.js'); | ||
var fromBufferToImageData; | ||
var polygonsToBuffer; | ||
@@ -17,2 +21,3 @@ var polygonsToPNGStream; | ||
if (process.env.NODE_ENV !== 'browser') { | ||
fromBufferToImageData = require('./input/fromBufferToImageData.js'); | ||
polygonsToSVGStream = require('./output/polygonsToSVGStream.js'); | ||
@@ -24,2 +29,42 @@ polygonsToBuffer = require('./output/polygonsToBuffer.js'); | ||
var allowedLineJoins = ['miter', 'round', 'bevel']; | ||
function checkParams(params) { | ||
if (typeof params !== 'object') { | ||
params = {}; | ||
} | ||
if (typeof params.accuracy !== 'number' || isNaN(params.accuracy)) { | ||
params.accuracy = defaultParams.accuracy; | ||
} else { | ||
params.accuracy = clamp(params.accuracy, 0, 1); | ||
} | ||
if (typeof params.blur !== 'number' || isNaN(params.blur)) { | ||
params.blur = defaultParams.blur; | ||
} | ||
if (typeof params.fill !== 'string' && typeof params.fill !== 'boolean') { | ||
params.fill = defaultParams.fill; | ||
} | ||
if (typeof params.stroke !== 'string' && typeof params.stroke !== 'boolean') { | ||
params.stroke = defaultParams.stroke; | ||
} | ||
if (typeof params.strokeWidth !== 'number' || isNaN(params.strokeWidth)) { | ||
params.strokeWidth = defaultParams.strokeWidth; | ||
} | ||
if (typeof params.lineJoin !== 'string' || allowedLineJoins.indexOf(params.lineJoin) === -1) { | ||
params.lineJoin = defaultParams.lineJoin; | ||
} | ||
if (typeof params.vertexCount !== 'number' || isNaN(params.vertexCount)) { | ||
params.vertexCount = defaultParams.vertexCount; | ||
} | ||
return params; | ||
} | ||
// constructing an object that allows for a chained interface. | ||
@@ -35,10 +80,12 @@ // for example stuff like: | ||
module.exports = function (params, callback) { | ||
var input = {}; | ||
var output = {}; | ||
params = checkParams(params); | ||
var input = { getParams: getParams }; | ||
var output = { getParams: getParams }; | ||
var inputFn; | ||
var outputFn; | ||
input.fromImageData = function () { | ||
inputFn = function (imageData) { | ||
input.fromImageData = function (imageData) { | ||
inputFn = function () { | ||
return imageData; | ||
@@ -115,2 +162,10 @@ }; | ||
}; | ||
output.toJPEGStream = function (jpgParams) { | ||
outputFn = function (polygons, size) { | ||
return polygonsToJPGStream(polygons, size, jpgParams); | ||
}; | ||
return go(getInput); | ||
}; | ||
} else { | ||
@@ -137,2 +192,6 @@ input.fromImage = function (imageEl) { | ||
function getParams() { | ||
return params; | ||
} | ||
function go(fn) { | ||
@@ -139,0 +198,0 @@ if (canStart()) { |
@@ -1,9 +0,23 @@ | ||
"use strict"; | ||
'use strict'; | ||
var Canvas = require('canvas-browserify'); | ||
module.exports = function (imageData) { | ||
return { | ||
width: imageData.width, | ||
height: imageData.height, | ||
data: new Uint8ClampedArray(imageData.data) | ||
}; | ||
// this is mainly required to run the browser tests. | ||
// phantomjs < v2 doesn't understand Uint8ClampedArray | ||
if (typeof Uint8ClampedArray === 'undefined') { | ||
// http://stackoverflow.com/a/11918126/229189 | ||
var canvas = Canvas(imageData.width, imageData.height); | ||
var ctx = canvas.getContext('2d'); | ||
ctx.putImageData(imageData, 0, 0); | ||
return ctx.getImageData(0, 0, imageData.width, imageData.height); | ||
} else { | ||
// http://stackoverflow.com/a/15238036/229189 | ||
return { | ||
width: imageData.width, | ||
height: imageData.height, | ||
data: new Uint8ClampedArray(imageData.data) | ||
}; | ||
} | ||
}; |
@@ -8,11 +8,16 @@ // https://github.com/Automattic/node-canvas#imagesrcbuffer | ||
module.exports = function (buffer) { | ||
var image = new Image(); | ||
image.src = buffer; | ||
if (buffer instanceof Buffer) { | ||
var image = new Image(); | ||
image.src = buffer; | ||
var canvas = new Canvas(image.width, image.height); | ||
var ctx = canvas.getContext('2d'); | ||
var canvas = new Canvas(image.width, image.height); | ||
var ctx = canvas.getContext('2d'); | ||
ctx.drawImage(image, 0, 0, canvas.width, canvas.height); | ||
ctx.drawImage(image, 0, 0, canvas.width, canvas.height); | ||
return ctx.getImageData(0, 0, canvas.width, canvas.height); | ||
return ctx.getImageData(0, 0, canvas.width, canvas.height); | ||
} else { | ||
throw new Error("Can't work with the buffer object provided."); | ||
return; | ||
} | ||
}; |
'use strict'; | ||
var Canvas = require('canvas-browserify'); | ||
var Image = Canvas.Image; | ||
module.exports = function (image) { | ||
var canvas = new Canvas(image.naturalWidth, image.naturalHeight); | ||
var ctx = canvas.getContext('2d'); | ||
ctx.drawImage(image, 0, 0, canvas.width, canvas.height); | ||
if (image instanceof HTMLImageElement) { | ||
// http://stackoverflow.com/a/3016076/229189 | ||
if (image.naturalWidth === 0 || image.naturalHeight === 0 || image.complete === false) { | ||
throw new Error("This this image hasn't finished loading: " + image.src); | ||
} | ||
return ctx.getImageData(0, 0, canvas.width, canvas.height); | ||
var canvas = new Canvas(image.naturalWidth, image.naturalHeight); | ||
var ctx = canvas.getContext('2d'); | ||
ctx.drawImage(image, 0, 0, canvas.width, canvas.height); | ||
return ctx.getImageData(0, 0, canvas.width, canvas.height); | ||
} else { | ||
throw new Error('This object does not seem to be an image.'); | ||
return; | ||
} | ||
}; |
@@ -6,3 +6,3 @@ 'use strict'; | ||
var clamp = require('../util/clamp.js'); | ||
var isImageData = require('../util/isImageData.js'); | ||
var copyImageData = require('../imagedata/copyImageData.js'); | ||
@@ -15,26 +15,22 @@ var greyscale = require('../imagedata/greyscale'); | ||
var allowedLineJoins = ['miter', 'round', 'bevel']; | ||
module.exports = function (imageData, params) { | ||
params.accuracy = clamp(params.accuracy || 0.7, 0, 1); | ||
params.blur = params.blur || 40; | ||
params.vertexCount = params.vertexCount || 700; | ||
params.fill = typeof params.fill === 'undefined' ? true : params.fill; | ||
params.stroke = typeof params.stroke === 'undefined' ? true : params.stroke; | ||
params.strokeWidth = typeof params.stroke === 'number' ? 0.5 : params.strokeWidth; | ||
params.lineJoin = allowedLineJoins.indexOf(params.lineJoin) !== -1 ? params.lineJoin : allowedLineJoins[0]; | ||
var imageSize = { width: imageData.width, height: imageData.height }; | ||
if (isImageData(imageData)) { | ||
var imageSize = { width: imageData.width, height: imageData.height }; | ||
var tmpImageData = copyImageData(imageData); | ||
var colorImageData = copyImageData(imageData); | ||
var tmpImageData = copyImageData(imageData); | ||
var colorImageData = copyImageData(imageData); | ||
var blurredImageData = stackBlur.imageDataRGBA(tmpImageData, 0, 0, imageSize.width, imageSize.height, params.blur); | ||
var greyscaleImageData = greyscale(blurredImageData); | ||
var edgesImageData = detectEdges(greyscaleImageData); | ||
var edgePoints = getEdgePoints(edgesImageData, 50, params.accuracy); | ||
var edgeVertices = getVerticesFromPoints(edgePoints, params.vertexCount, params.accuracy, imageSize.width, imageSize.height); | ||
var polygons = delaunay.triangulate(edgeVertices); | ||
var blurredImageData = stackBlur.imageDataRGBA(tmpImageData, 0, 0, imageSize.width, imageSize.height, params.blur); | ||
var greyscaleImageData = greyscale(blurredImageData); | ||
var edgesImageData = detectEdges(greyscaleImageData); | ||
var edgePoints = getEdgePoints(edgesImageData, 50, params.accuracy); | ||
var edgeVertices = getVerticesFromPoints(edgePoints, params.vertexCount, params.accuracy, imageSize.width, imageSize.height); | ||
var polygons = delaunay.triangulate(edgeVertices); | ||
return addColorToPolygons(polygons, colorImageData, params); | ||
return addColorToPolygons(polygons, colorImageData, params); | ||
} else { | ||
throw new Error("Can't work with the imageData provided. It seems to be corrupt"); | ||
return; | ||
} | ||
}; |
@@ -59,3 +59,25 @@ (function(f) { | ||
'use strict'; | ||
var fromImageToImageData = _dereq_('./input/fromImageToImageData.js'), fromBufferToImageData = _dereq_('./input/fromBufferToImageData.js'), polygonsToImageData = _dereq_('./output/polygonsToImageData.js'), polygonsToDataURL = _dereq_('./output/polygonsToDataURL.js'), polygonsToSVG = _dereq_('./output/polygonsToSVG.js'), polygonsToBuffer, polygonsToPNGStream, polygonsToJPGStream, polygonsToSVGStream; | ||
module.exports = { | ||
accuracy: .7, | ||
blur: 40, | ||
fill: !0, | ||
stroke: !0, | ||
strokeWidth: .5, | ||
lineJoin: 'miter', | ||
vertexCount: 700 | ||
}; | ||
}, {} ], | ||
2: [ function(_dereq_, module, exports) { | ||
'use strict'; | ||
function checkParams(params) { | ||
return 'object' != typeof params && (params = {}), 'number' != typeof params.accuracy || isNaN(params.accuracy) ? params.accuracy = defaultParams.accuracy : params.accuracy = clamp(params.accuracy, 0, 1), | ||
('number' != typeof params.blur || isNaN(params.blur)) && (params.blur = defaultParams.blur), | ||
'string' != typeof params.fill && 'boolean' != typeof params.fill && (params.fill = defaultParams.fill), | ||
'string' != typeof params.stroke && 'boolean' != typeof params.stroke && (params.stroke = defaultParams.stroke), | ||
('number' != typeof params.strokeWidth || isNaN(params.strokeWidth)) && (params.strokeWidth = defaultParams.strokeWidth), | ||
('string' != typeof params.lineJoin || -1 === allowedLineJoins.indexOf(params.lineJoin)) && (params.lineJoin = defaultParams.lineJoin), | ||
('number' != typeof params.vertexCount || isNaN(params.vertexCount)) && (params.vertexCount = defaultParams.vertexCount), | ||
params; | ||
} | ||
var clamp = _dereq_('./util/clamp.js'), defaultParams = _dereq_('./defaultParams.js'), fromImageToImageData = _dereq_('./input/fromImageToImageData.js'), polygonsToImageData = _dereq_('./output/polygonsToImageData.js'), polygonsToDataURL = _dereq_('./output/polygonsToDataURL.js'), polygonsToSVG = _dereq_('./output/polygonsToSVG.js'), fromBufferToImageData, polygonsToBuffer, polygonsToPNGStream, polygonsToJPGStream, polygonsToSVGStream, allowedLineJoins = [ 'miter', 'round', 'bevel' ]; | ||
module.exports = function(params, callback) { | ||
@@ -71,2 +93,5 @@ function getInput() { | ||
} | ||
function getParams() { | ||
return params; | ||
} | ||
function go(fn) { | ||
@@ -79,5 +104,10 @@ return canStart() ? start() : fn(); | ||
} | ||
var inputFn, outputFn, input = {}, output = {}; | ||
return input.fromImageData = function() { | ||
return inputFn = function(imageData) { | ||
params = checkParams(params); | ||
var inputFn, outputFn, input = { | ||
getParams: getParams | ||
}, output = { | ||
getParams: getParams | ||
}; | ||
return input.fromImageData = function(imageData) { | ||
return inputFn = function() { | ||
return imageData; | ||
@@ -106,11 +136,17 @@ }, go(getOutput); | ||
}, { | ||
'./input/fromBufferToImageData.js': 5, | ||
'./defaultParams.js': 1, | ||
'./input/fromImageToImageData.js': 6, | ||
'./output/polygonsToDataURL.js': 7, | ||
'./output/polygonsToImageData.js': 8, | ||
'./output/polygonsToSVG.js': 9 | ||
'./output/polygonsToSVG.js': 9, | ||
'./util/clamp.js': 14 | ||
} ], | ||
2: [ function(_dereq_, module, exports) { | ||
3: [ function(_dereq_, module, exports) { | ||
'use strict'; | ||
var Canvas = _dereq_('canvas-browserify'); | ||
module.exports = function(imageData) { | ||
if ('undefined' == typeof Uint8ClampedArray) { | ||
var canvas = Canvas(imageData.width, imageData.height), ctx = canvas.getContext('2d'); | ||
return ctx.putImageData(imageData, 0, 0), ctx.getImageData(0, 0, imageData.width, imageData.height); | ||
} | ||
return { | ||
@@ -122,4 +158,6 @@ width: imageData.width, | ||
}; | ||
}, {} ], | ||
3: [ function(_dereq_, module, exports) { | ||
}, { | ||
'canvas-browserify': 18 | ||
} ], | ||
4: [ function(_dereq_, module, exports) { | ||
'use strict'; | ||
@@ -165,3 +203,3 @@ function detectEdges(imageData, accuracy, edgeSize, divisor) { | ||
}, {} ], | ||
4: [ function(_dereq_, module, exports) { | ||
5: [ function(_dereq_, module, exports) { | ||
'use strict'; | ||
@@ -177,23 +215,17 @@ function greyscale(imageData) { | ||
}, {} ], | ||
5: [ function(_dereq_, module, exports) { | ||
6: [ function(_dereq_, module, exports) { | ||
'use strict'; | ||
var Canvas = _dereq_('canvas-browserify'), Image = Canvas.Image; | ||
module.exports = function(buffer) { | ||
var image = new Image(); | ||
image.src = buffer; | ||
var canvas = new Canvas(image.width, image.height), ctx = canvas.getContext('2d'); | ||
return ctx.drawImage(image, 0, 0, canvas.width, canvas.height), ctx.getImageData(0, 0, canvas.width, canvas.height); | ||
}; | ||
}, { | ||
'canvas-browserify': 17 | ||
} ], | ||
6: [ function(_dereq_, module, exports) { | ||
'use strict'; | ||
var Canvas = _dereq_('canvas-browserify'); | ||
module.exports = function(image) { | ||
var canvas = new Canvas(image.naturalWidth, image.naturalHeight), ctx = canvas.getContext('2d'); | ||
return ctx.drawImage(image, 0, 0, canvas.width, canvas.height), ctx.getImageData(0, 0, canvas.width, canvas.height); | ||
if (image instanceof HTMLImageElement) { | ||
if (0 === image.naturalWidth || 0 === image.naturalHeight || image.complete === !1) { | ||
throw new Error('This this image hasn\'t finished loading: ' + image.src); | ||
} | ||
var canvas = new Canvas(image.naturalWidth, image.naturalHeight), ctx = canvas.getContext('2d'); | ||
return ctx.drawImage(image, 0, 0, canvas.width, canvas.height), ctx.getImageData(0, 0, canvas.width, canvas.height); | ||
} | ||
throw new Error('This object does not seem to be an image.'); | ||
}; | ||
}, { | ||
'canvas-browserify': 17 | ||
'canvas-browserify': 18 | ||
} ], | ||
@@ -211,3 +243,3 @@ 7: [ function(_dereq_, module, exports) { | ||
'../util/drawPolygonsOnContext.js': 15, | ||
'canvas-browserify': 17 | ||
'canvas-browserify': 18 | ||
} ], | ||
@@ -225,3 +257,3 @@ 8: [ function(_dereq_, module, exports) { | ||
'../util/drawPolygonsOnContext.js': 15, | ||
'canvas-browserify': 17 | ||
'canvas-browserify': 18 | ||
} ], | ||
@@ -323,24 +355,23 @@ 9: [ function(_dereq_, module, exports) { | ||
'use strict'; | ||
var stackBlur = _dereq_('stackblur-canvas'), delaunay = _dereq_('delaunay-fast'), clamp = _dereq_('../util/clamp.js'), copyImageData = _dereq_('../imagedata/copyImageData.js'), greyscale = _dereq_('../imagedata/greyscale'), detectEdges = _dereq_('../imagedata/detectEdges'), getEdgePoints = _dereq_('./getEdgePoints.js'), getVerticesFromPoints = _dereq_('./getVerticesFromPoints.js'), addColorToPolygons = _dereq_('./addColorToPolygons.js'), allowedLineJoins = [ 'miter', 'round', 'bevel' ]; | ||
var stackBlur = _dereq_('stackblur-canvas'), delaunay = _dereq_('delaunay-fast'), isImageData = _dereq_('../util/isImageData.js'), copyImageData = _dereq_('../imagedata/copyImageData.js'), greyscale = _dereq_('../imagedata/greyscale'), detectEdges = _dereq_('../imagedata/detectEdges'), getEdgePoints = _dereq_('./getEdgePoints.js'), getVerticesFromPoints = _dereq_('./getVerticesFromPoints.js'), addColorToPolygons = _dereq_('./addColorToPolygons.js'); | ||
module.exports = function(imageData, params) { | ||
params.accuracy = clamp(params.accuracy || .7, 0, 1), params.blur = params.blur || 40, | ||
params.vertexCount = params.vertexCount || 700, params.fill = 'undefined' == typeof params.fill ? !0 : params.fill, | ||
params.stroke = 'undefined' == typeof params.stroke ? !0 : params.stroke, params.strokeWidth = 'number' == typeof params.stroke ? .5 : params.strokeWidth, | ||
params.lineJoin = -1 !== allowedLineJoins.indexOf(params.lineJoin) ? params.lineJoin : allowedLineJoins[0]; | ||
var imageSize = { | ||
width: imageData.width, | ||
height: imageData.height | ||
}, tmpImageData = copyImageData(imageData), colorImageData = copyImageData(imageData), blurredImageData = stackBlur.imageDataRGBA(tmpImageData, 0, 0, imageSize.width, imageSize.height, params.blur), greyscaleImageData = greyscale(blurredImageData), edgesImageData = detectEdges(greyscaleImageData), edgePoints = getEdgePoints(edgesImageData, 50, params.accuracy), edgeVertices = getVerticesFromPoints(edgePoints, params.vertexCount, params.accuracy, imageSize.width, imageSize.height), polygons = delaunay.triangulate(edgeVertices); | ||
return addColorToPolygons(polygons, colorImageData, params); | ||
if (isImageData(imageData)) { | ||
var imageSize = { | ||
width: imageData.width, | ||
height: imageData.height | ||
}, tmpImageData = copyImageData(imageData), colorImageData = copyImageData(imageData), blurredImageData = stackBlur.imageDataRGBA(tmpImageData, 0, 0, imageSize.width, imageSize.height, params.blur), greyscaleImageData = greyscale(blurredImageData), edgesImageData = detectEdges(greyscaleImageData), edgePoints = getEdgePoints(edgesImageData, 50, params.accuracy), edgeVertices = getVerticesFromPoints(edgePoints, params.vertexCount, params.accuracy, imageSize.width, imageSize.height), polygons = delaunay.triangulate(edgeVertices); | ||
return addColorToPolygons(polygons, colorImageData, params); | ||
} | ||
throw new Error('Can\'t work with the imageData provided. It seems to be corrupt'); | ||
}; | ||
}, { | ||
'../imagedata/copyImageData.js': 2, | ||
'../imagedata/detectEdges': 3, | ||
'../imagedata/greyscale': 4, | ||
'../util/clamp.js': 14, | ||
'../imagedata/copyImageData.js': 3, | ||
'../imagedata/detectEdges': 4, | ||
'../imagedata/greyscale': 5, | ||
'../util/isImageData.js': 16, | ||
'./addColorToPolygons.js': 10, | ||
'./getEdgePoints.js': 11, | ||
'./getVerticesFromPoints.js': 12, | ||
'delaunay-fast': 18, | ||
'stackblur-canvas': 19 | ||
'delaunay-fast': 19, | ||
'stackblur-canvas': 20 | ||
} ], | ||
@@ -368,2 +399,8 @@ 14: [ function(_dereq_, module, exports) { | ||
'use strict'; | ||
module.exports = function(imageData) { | ||
return imageData && 'number' == typeof imageData.width && 'number' == typeof imageData.height && imageData.data && 'number' == typeof imageData.data.length; | ||
}; | ||
}, {} ], | ||
17: [ function(_dereq_, module, exports) { | ||
'use strict'; | ||
function triangulate(params) { | ||
@@ -378,6 +415,6 @@ return getInterfaceObj(params, imageDataToPolygons); | ||
}, { | ||
'./getInterfaceObj': 1, | ||
'./getInterfaceObj': 2, | ||
'./polygons/imageDataToPolygons.js': 13 | ||
} ], | ||
17: [ function(_dereq_, module, exports) { | ||
18: [ function(_dereq_, module, exports) { | ||
var Canvas = module.exports = function Canvas(w, h) { | ||
@@ -394,3 +431,3 @@ var canvas = document.createElement('canvas'); | ||
}, {} ], | ||
18: [ function(_dereq_, module, exports) { | ||
19: [ function(_dereq_, module, exports) { | ||
function Triangle(a, b, c) { | ||
@@ -515,3 +552,3 @@ this.a = a; | ||
}, {} ], | ||
19: [ function(_dereq_, module, exports) { | ||
20: [ function(_dereq_, module, exports) { | ||
var mul_table = [ 512, 512, 456, 512, 328, 456, 335, 512, 405, 328, 271, 456, 388, 335, 292, 512, 454, 405, 364, 328, 298, 271, 496, 456, 420, 388, 360, 335, 312, 292, 273, 512, 482, 454, 428, 405, 383, 364, 345, 328, 312, 298, 284, 271, 259, 496, 475, 456, 437, 420, 404, 388, 374, 360, 347, 335, 323, 312, 302, 292, 282, 273, 265, 512, 497, 482, 468, 454, 441, 428, 417, 405, 394, 383, 373, 364, 354, 345, 337, 328, 320, 312, 305, 298, 291, 284, 278, 271, 265, 259, 507, 496, 485, 475, 465, 456, 446, 437, 428, 420, 412, 404, 396, 388, 381, 374, 367, 360, 354, 347, 341, 335, 329, 323, 318, 312, 307, 302, 297, 292, 287, 282, 278, 273, 269, 265, 261, 512, 505, 497, 489, 482, 475, 468, 461, 454, 447, 441, 435, 428, 422, 417, 411, 405, 399, 394, 389, 383, 378, 373, 368, 364, 359, 354, 350, 345, 341, 337, 332, 328, 324, 320, 316, 312, 309, 305, 301, 298, 294, 291, 287, 284, 281, 278, 274, 271, 268, 265, 262, 259, 257, 507, 501, 496, 491, 485, 480, 475, 470, 465, 460, 456, 451, 446, 442, 437, 433, 428, 424, 420, 416, 412, 408, 404, 400, 396, 392, 388, 385, 381, 377, 374, 370, 367, 363, 360, 357, 354, 350, 347, 344, 341, 338, 335, 332, 329, 326, 323, 320, 318, 315, 312, 310, 307, 304, 302, 299, 297, 294, 292, 289, 287, 285, 282, 280, 278, 275, 273, 271, 269, 267, 265, 263, 261, 259 ]; | ||
@@ -927,3 +964,3 @@ var shg_table = [ 9, 11, 12, 13, 13, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24 ]; | ||
}, {} ] | ||
}, {}, [ 16 ])(16); | ||
}, {}, [ 17 ])(17); | ||
}); |
@@ -1,1 +0,1 @@ | ||
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.triangulate=t()}}(function(){return function t(e,n,r){function o(i,s){if(!n[i]){if(!e[i]){var u="function"==typeof require&&require;if(!s&&u)return u(i,!0);if(a)return a(i,!0);var f=new Error("Cannot find module '"+i+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[i]={exports:{}};e[i][0].call(l.exports,function(t){var n=e[i][1][t];return o(n?n:t)},l,l.exports,t,e,n,r)}return n[i].exports}for(var a="function"==typeof require&&require,i=0;i<r.length;i++)o(r[i]);return o}({1:[function(t,e,n){"use strict";var r=t("./input/fromImageToImageData.js"),o=(t("./input/fromBufferToImageData.js"),t("./output/polygonsToImageData.js")),a=t("./output/polygonsToDataURL.js"),i=t("./output/polygonsToSVG.js");e.exports=function(t,e){function n(){return h}function s(){return d}function u(){return c&&g&&t}function f(t){return u()?l():t()}function l(){var n=c(),r=e(n,t);return g(r,n)}var c,g,h={},d={};return h.fromImageData=function(){return c=function(t){return t},f(s)},d.toDataURL=function(t){return g=function(e,n){return a(e,n,t)},f(n)},d.toImageData=function(t){return g=function(e,n){return o(e,n,t)},f(n)},d.toSVG=function(){return g=i,f(n)},d.toData=function(){return g=function(t){return t},f(n)},h.fromImage=function(t){return c=function(){return r(t)},f(s)},n()}},{"./input/fromBufferToImageData.js":5,"./input/fromImageToImageData.js":6,"./output/polygonsToDataURL.js":7,"./output/polygonsToImageData.js":8,"./output/polygonsToSVG.js":9}],2:[function(t,e,n){"use strict";e.exports=function(t){return{width:t.width,height:t.height,data:new Uint8ClampedArray(t.data)}}},{}],3:[function(t,e,n){"use strict";function r(t,e,n,r){var a=o(n).slice(),i=parseInt(10*(e||.5),10)||1;r=r||1;var s,u,f=r?1/r:0;if(1!==f)for(s=0,u=a.length;s<a.length;s++)a[s]*=f;var l=t.data;u=l.length>>2;var c=new Uint8Array(u);for(j=0;u>j;j++)c[j]=l[j<<2];var g,h,d,y,x,p,v,m,w,b,j,C,I,k,D=0|t.width,T=0|t.height,E=Math.sqrt(a.length),P=.5*E|0;for(h=0;T>h;h+=i)for(C=h*D,g=0;D>g;g+=i){for(d=y=x=0,m=-P;P>=m;m++)if(b=h+m,I=b*D,k=(m+P)*E,b>=0&&T>b)for(v=-P;P>=v;v++)w=g+v,w>=0&&D>w&&(p=a[v+P+k])&&(d+=c[w+I]*p);0>d?d=0:d>255&&(d=255),l[g+C<<2]=255&d}return t}function o(t){var e,n=[],r=2*t+1,o=r*r,a=.5*o|0;for(e=0;o>e;e++)n[e]=e===a?-o+1:1;return n}e.exports=r},{}],4:[function(t,e,n){"use strict";function r(t){for(var e=t.data.length,n=t.data,r=void 0,o=0;e>o;o+=4)r=.34*n[o]+.5*n[o+1]+.16*n[o+2],n[o]=r,n[o+1]=r,n[o+2]=r;return t.data=n,t}e.exports=r},{}],5:[function(t,e,n){"use strict";var r=t("canvas-browserify"),o=r.Image;e.exports=function(t){var e=new o;e.src=t;var n=new r(e.width,e.height),a=n.getContext("2d");return a.drawImage(e,0,0,n.width,n.height),a.getImageData(0,0,n.width,n.height)}},{"canvas-browserify":17}],6:[function(t,e,n){"use strict";var r=t("canvas-browserify");e.exports=function(t){var e=new r(t.naturalWidth,t.naturalHeight),n=e.getContext("2d");return n.drawImage(t,0,0,e.width,e.height),n.getImageData(0,0,e.width,e.height)}},{"canvas-browserify":17}],7:[function(t,e,n){"use strict";var r=t("canvas-browserify"),o=t("../util/drawPolygonsOnContext.js");e.exports=function(t,e,n){var a=n&&n.dpr?n.dpr:1,i=n&&n.backgroundColor?n.backgroundColor:!1,s=new r(e.width*a,e.height*a),u=s.getContext("2d");return i&&(u.fillStyle=i,u.fillRect(0,0,e.width*a,e.height*a),u.fillStyle="transparent"),o(u,t,e,a),s.toDataURL()}},{"../util/drawPolygonsOnContext.js":15,"canvas-browserify":17}],8:[function(t,e,n){"use strict";var r=t("canvas-browserify"),o=t("../util/drawPolygonsOnContext.js");e.exports=function(t,e,n){var a=n&&n.dpr?n.dpr:1,i=n&&n.backgroundColor?n.backgroundColor:!1,s=new r(e.width*a,e.height*a),u=s.getContext("2d");return i&&(u.fillStyle=i,u.fillRect(0,0,e.width*a,e.height*a),u.fillStyle="transparent"),o(u,t,e,a),u.getImageData(0,0,e.width*a,e.height*a)}},{"../util/drawPolygonsOnContext.js":15,"canvas-browserify":17}],9:[function(t,e,n){"use strict";e.exports=function(t,e){var n='<?xml version="1.0" standalone="yes"?>\n<svg width="'+e.width+'" height="'+e.height+'" xmlns="http://www.w3.org/2000/svg" version="1.1" >\n ';return t.forEach(function(t,e){var r=t.a,o=t.b,a=t.c;n+='<polygon points="'+r.x+","+r.y+" "+o.x+","+o.y+" "+a.x+","+a.y+'"',n+=t.fill?' fill="'+t.fill+'"':' fill="transparent"',t.strokeColor&&(n+=' stroke="'+t.strokeColor+'" stroke-width="'+t.strokeWidth+'" stroke-linejoin="'+t.lineJoin+'"'),n+="/>\n "}),n+="\n</svg>"}},{}],10:[function(t,e,n){"use strict";function r(t,e,n){var r=0,o=void 0,a=void 0,i=n.fill,s="string"==typeof i?n.fill:!1,u=n.stroke,f="string"==typeof u?n.stroke:!1,l=n.strokeWidth,c=n.lineJoin,g=void 0,h=void 0,d=void 0;return t.forEach(function(t,n){o=.33333*(t.a.x+t.b.x+t.c.x),a=.33333*(t.a.y+t.b.y+t.c.y),r=(0|o)+(0|a)*e.width<<2,g=e.data[r],h=e.data[r+1],d=e.data[r+2],i&&(t.fill=s||"rgb("+g+", "+h+", "+d+")"),u&&(f?t.strokeColor=f:t.strokeColor="rgb("+g+", "+h+", "+d+")",t.strokeWidth=l,t.lineJoin=c)}),t}e.exports=r},{}],11:[function(t,e,n){"use strict";function r(t,e,n){var r,o,a,i,s,u,f,l,c,g=parseInt(10*(n||.1),10)||1,h=e,d=t.width,y=t.height,x=t.data,p=[];for(o=0;y>o;o+=g)for(r=0;d>r;r+=g){for(l=c=0,a=-1;1>=a;a++)if(u=o+a,f=u*d,u>=0&&y>u)for(i=-1;1>=i;i++)s=r+i,s>=0&&d>s&&(l+=x[s+f<<2],c++);c&&(l/=c),l>h&&p.push({x:r,y:o})}return p}e.exports=r},{}],12:[function(t,e,n){"use strict";function r(t,e){return t.x*t.y-e.y*e.x}function o(t,e,n,o,i){var s=[],u=2*Math.ceil(o/(100-n))+2*Math.ceil(i/(100-n))+2,f=Math.max(t.length,e),l=a(f-u,0,e-u),c=f/l,g=0,h=0,d=0,y=0;for(t.sort(r),g=0,y=f;y>g;g+=c)s.push({x:t[~~g].x,y:t[~~g].y});for(h=0;o>h;h+=100-n)s.push({x:~~h,y:0}),s.push({x:~~h,y:i});for(d=0;i>d;d+=100-n)s.push({x:0,y:~~d}),s.push({x:o,y:~~d});return s.push({x:0,y:i}),s.push({x:o,y:i}),t=null,s}var a=t("../util/clamp.js");e.exports=o},{"../util/clamp.js":14}],13:[function(t,e,n){"use strict";var r=t("stackblur-canvas"),o=t("delaunay-fast"),a=t("../util/clamp.js"),i=t("../imagedata/copyImageData.js"),s=t("../imagedata/greyscale"),u=t("../imagedata/detectEdges"),f=t("./getEdgePoints.js"),l=t("./getVerticesFromPoints.js"),c=t("./addColorToPolygons.js"),g=["miter","round","bevel"];e.exports=function(t,e){e.accuracy=a(e.accuracy||.7,0,1),e.blur=e.blur||40,e.vertexCount=e.vertexCount||700,e.fill="undefined"==typeof e.fill?!0:e.fill,e.stroke="undefined"==typeof e.stroke?!0:e.stroke,e.strokeWidth="number"==typeof e.stroke?.5:e.strokeWidth,e.lineJoin=-1!==g.indexOf(e.lineJoin)?e.lineJoin:g[0];var n={width:t.width,height:t.height},h=i(t),d=i(t),y=r.imageDataRGBA(h,0,0,n.width,n.height,e.blur),x=s(y),p=u(x),v=f(p,50,e.accuracy),m=l(v,e.vertexCount,e.accuracy,n.width,n.height),w=o.triangulate(m);return c(w,d,e)}},{"../imagedata/copyImageData.js":2,"../imagedata/detectEdges":3,"../imagedata/greyscale":4,"../util/clamp.js":14,"./addColorToPolygons.js":10,"./getEdgePoints.js":11,"./getVerticesFromPoints.js":12,"delaunay-fast":18,"stackblur-canvas":19}],14:[function(t,e,n){"use strict";function r(t,e,n){return e>t?e:t>n?n:t}e.exports=r},{}],15:[function(t,e,n){"use strict";e.exports=function(t,e,n,r){return r=r||1,e.forEach(function(e,n){t.beginPath(),t.moveTo(e.a.x*r,e.a.y*r),t.lineTo(e.b.x*r,e.b.y*r),t.lineTo(e.c.x*r,e.c.y*r),t.lineTo(e.a.x*r,e.a.y*r),e.fill&&(t.fillStyle=e.fill,t.fill()),e.strokeColor&&(t.strokeStyle=e.strokeColor,t.lineWidth=e.strokeWidth*r,t.lineJoin=e.lineJoin,t.stroke()),t.closePath()}),t}},{}],16:[function(t,e,n){"use strict";function r(t){return o(t,a)}Object.defineProperty(n,"__esModule",{value:!0}),n["default"]=r;var o=t("./getInterfaceObj"),a=t("./polygons/imageDataToPolygons.js");e.exports=n["default"]},{"./getInterfaceObj":1,"./polygons/imageDataToPolygons.js":13}],17:[function(t,e,n){var r=e.exports=function(t,e){var n=document.createElement("canvas");return n.width=t||300,n.height=e||150,n};r.Image=function(){var t=document.createElement("img");return t}},{}],18:[function(t,e,n){function r(t,e,n){this.a=t,this.b=e,this.c=n;var r,o,a,i,s=e.x-t.x,u=e.y-t.y,f=n.x-t.x,l=n.y-t.y,c=s*(t.x+e.x)+u*(t.y+e.y),g=f*(t.x+n.x)+l*(t.y+n.y),h=2*(s*(n.y-e.y)-u*(n.x-e.x));Math.abs(h)<1e-6?(r=Math.min(t.x,e.x,n.x),o=Math.min(t.y,e.y,n.y),a=.5*(Math.max(t.x,e.x,n.x)-r),i=.5*(Math.max(t.y,e.y,n.y)-o),this.x=r+a,this.y=o+i,this.r=a*a+i*i):(this.x=(l*c-u*g)/h,this.y=(s*g-f*c)/h,a=this.x-t.x,i=this.y-t.y,this.r=a*a+i*i)}function o(t,e){return e.x-t.x}function a(t){var e,n,r,o,a,i=t.length;t:for(;i;)for(n=t[--i],e=t[--i],r=i;r;)if(a=t[--r],o=t[--r],e===o&&n===a||e===a&&n===o){t.splice(i,2),t.splice(r,2),i-=2;continue t}}function i(t){if(t.length<3)return[];t.sort(o);for(var e=t.length-1,n=t[e].x,i=t[0].x,s=t[e].y,u=s;e--;)t[e].y<s&&(s=t[e].y),t[e].y>u&&(u=t[e].y);var f,l,c,g=i-n,h=u-s,d=g>h?g:h,y=.5*(i+n),x=.5*(u+s),p=[new r({x:y-20*d,y:x-d,__sentinel:!0},{x:y,y:x+20*d,__sentinel:!0},{x:y+20*d,y:x-d,__sentinel:!0})],v=[],m=[];for(e=t.length;e--;){for(m.length=0,f=p.length;f--;)g=t[e].x-p[f].x,g>0&&g*g>p[f].r?(v.push(p[f]),p.splice(f,1)):(h=t[e].y-p[f].y,g*g+h*h>p[f].r||(m.push(p[f].a,p[f].b,p[f].b,p[f].c,p[f].c,p[f].a),p.splice(f,1)));for(a(m),f=m.length;f;)c=m[--f],l=m[--f],p.push(new r(l,c,t[e]))}for(Array.prototype.push.apply(v,p),e=v.length;e--;)(v[e].a.__sentinel||v[e].b.__sentinel||v[e].c.__sentinel)&&v.splice(e,1);return v}r.prototype.draw=function(t){t.beginPath(),t.moveTo(this.a.x,this.a.y),t.lineTo(this.b.x,this.b.y),t.lineTo(this.c.x,this.c.y),t.closePath(),t.stroke()},"undefined"!=typeof e&&(e.exports={Triangle:r,triangulate:i})},{}],19:[function(t,e,n){function r(t,e,n,r){if("string"==typeof t)var t=document.getElementById(t);else if(!t instanceof HTMLImageElement)return;var o=t.naturalWidth,i=t.naturalHeight;if("string"==typeof e)var e=document.getElementById(e);else if(!e instanceof HTMLCanvasElement)return;e.style.width=o+"px",e.style.height=i+"px",e.width=o,e.height=i;var u=e.getContext("2d");u.clearRect(0,0,o,i),u.drawImage(t,0,0),isNaN(n)||1>n||(r?a(e,0,0,o,i,n):s(e,0,0,o,i,n))}function o(t,e,n,r,o){if("string"==typeof t)var t=document.getElementById(t);else if(!t instanceof HTMLCanvasElement)return;var a,i=t.getContext("2d");try{try{a=i.getImageData(e,n,r,o)}catch(s){try{netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead"),a=i.getImageData(e,n,r,o)}catch(s){throw alert("Cannot access local image"),new Error("unable to access local image data: "+s)}}}catch(s){throw alert("Cannot access image"),new Error("unable to access image data: "+s)}return a}function a(t,e,n,r,a,s){if(!(isNaN(s)||1>s)){s|=0;var u=o(t,e,n,r,a);u=i(u,e,n,r,a,s),t.getContext("2d").putImageData(u,e,n)}}function i(t,e,n,r,o,a){var i,s,u,g,h,d,y,x,p,v,m,w,b,j,C,I,k,D,T,E,P,_,M,R,B=t.data,O=a+a+1,S=r-1,U=o-1,W=a+1,G=W*(W+1)/2,J=new f,L=J;for(u=1;O>u;u++)if(L=L.next=new f,u==W)var N=L;L.next=J;var A=null,q=null;y=d=0;var H=l[a],V=c[a];for(s=0;o>s;s++){for(I=k=D=T=x=p=v=m=0,w=W*(E=B[d]),b=W*(P=B[d+1]),j=W*(_=B[d+2]),C=W*(M=B[d+3]),x+=G*E,p+=G*P,v+=G*_,m+=G*M,L=J,u=0;W>u;u++)L.r=E,L.g=P,L.b=_,L.a=M,L=L.next;for(u=1;W>u;u++)g=d+((u>S?S:u)<<2),x+=(L.r=E=B[g])*(R=W-u),p+=(L.g=P=B[g+1])*R,v+=(L.b=_=B[g+2])*R,m+=(L.a=M=B[g+3])*R,I+=E,k+=P,D+=_,T+=M,L=L.next;for(A=J,q=N,i=0;r>i;i++)B[d+3]=M=m*H>>V,0!=M?(M=255/M,B[d]=(x*H>>V)*M,B[d+1]=(p*H>>V)*M,B[d+2]=(v*H>>V)*M):B[d]=B[d+1]=B[d+2]=0,x-=w,p-=b,v-=j,m-=C,w-=A.r,b-=A.g,j-=A.b,C-=A.a,g=y+((g=i+a+1)<S?g:S)<<2,I+=A.r=B[g],k+=A.g=B[g+1],D+=A.b=B[g+2],T+=A.a=B[g+3],x+=I,p+=k,v+=D,m+=T,A=A.next,w+=E=q.r,b+=P=q.g,j+=_=q.b,C+=M=q.a,I-=E,k-=P,D-=_,T-=M,q=q.next,d+=4;y+=r}for(i=0;r>i;i++){for(k=D=T=I=p=v=m=x=0,d=i<<2,w=W*(E=B[d]),b=W*(P=B[d+1]),j=W*(_=B[d+2]),C=W*(M=B[d+3]),x+=G*E,p+=G*P,v+=G*_,m+=G*M,L=J,u=0;W>u;u++)L.r=E,L.g=P,L.b=_,L.a=M,L=L.next;for(h=r,u=1;a>=u;u++)d=h+i<<2,x+=(L.r=E=B[d])*(R=W-u),p+=(L.g=P=B[d+1])*R,v+=(L.b=_=B[d+2])*R,m+=(L.a=M=B[d+3])*R,I+=E,k+=P,D+=_,T+=M,L=L.next,U>u&&(h+=r);for(d=i,A=J,q=N,s=0;o>s;s++)g=d<<2,B[g+3]=M=m*H>>V,M>0?(M=255/M,B[g]=(x*H>>V)*M,B[g+1]=(p*H>>V)*M,B[g+2]=(v*H>>V)*M):B[g]=B[g+1]=B[g+2]=0,x-=w,p-=b,v-=j,m-=C,w-=A.r,b-=A.g,j-=A.b,C-=A.a,g=i+((g=s+W)<U?g:U)*r<<2,x+=I+=A.r=B[g],p+=k+=A.g=B[g+1],v+=D+=A.b=B[g+2],m+=T+=A.a=B[g+3],A=A.next,w+=E=q.r,b+=P=q.g,j+=_=q.b,C+=M=q.a,I-=E,k-=P,D-=_,T-=M,q=q.next,d+=r}return t}function s(t,e,n,r,a,i){if(!(isNaN(i)||1>i)){i|=0;var s=o(t,e,n,r,a);s=u(s,e,n,r,a,i),t.getContext("2d").putImageData(s,e,n)}}function u(t,e,n,r,o,a){var i,s,u,g,h,d,y,x,p,v,m,w,b,j,C,I,k,D,T,E,P=t.data,_=a+a+1,M=r-1,R=o-1,B=a+1,O=B*(B+1)/2,S=new f,U=S;for(u=1;_>u;u++)if(U=U.next=new f,u==B)var W=U;U.next=S;var G=null,J=null;y=d=0;var L=l[a],N=c[a];for(s=0;o>s;s++){for(j=C=I=x=p=v=0,m=B*(k=P[d]),w=B*(D=P[d+1]),b=B*(T=P[d+2]),x+=O*k,p+=O*D,v+=O*T,U=S,u=0;B>u;u++)U.r=k,U.g=D,U.b=T,U=U.next;for(u=1;B>u;u++)g=d+((u>M?M:u)<<2),x+=(U.r=k=P[g])*(E=B-u),p+=(U.g=D=P[g+1])*E,v+=(U.b=T=P[g+2])*E,j+=k,C+=D,I+=T,U=U.next;for(G=S,J=W,i=0;r>i;i++)P[d]=x*L>>N,P[d+1]=p*L>>N,P[d+2]=v*L>>N,x-=m,p-=w,v-=b,m-=G.r,w-=G.g,b-=G.b,g=y+((g=i+a+1)<M?g:M)<<2,j+=G.r=P[g],C+=G.g=P[g+1],I+=G.b=P[g+2],x+=j,p+=C,v+=I,G=G.next,m+=k=J.r,w+=D=J.g,b+=T=J.b,j-=k,C-=D,I-=T,J=J.next,d+=4;y+=r}for(i=0;r>i;i++){for(C=I=j=p=v=x=0,d=i<<2,m=B*(k=P[d]),w=B*(D=P[d+1]),b=B*(T=P[d+2]),x+=O*k,p+=O*D,v+=O*T,U=S,u=0;B>u;u++)U.r=k,U.g=D,U.b=T,U=U.next;for(h=r,u=1;a>=u;u++)d=h+i<<2,x+=(U.r=k=P[d])*(E=B-u),p+=(U.g=D=P[d+1])*E,v+=(U.b=T=P[d+2])*E,j+=k,C+=D,I+=T,U=U.next,R>u&&(h+=r);for(d=i,G=S,J=W,s=0;o>s;s++)g=d<<2,P[g]=x*L>>N,P[g+1]=p*L>>N,P[g+2]=v*L>>N,x-=m,p-=w,v-=b,m-=G.r,w-=G.g,b-=G.b,g=i+((g=s+B)<R?g:R)*r<<2,x+=j+=G.r=P[g],p+=C+=G.g=P[g+1],v+=I+=G.b=P[g+2],G=G.next,m+=k=J.r,w+=D=J.g,b+=T=J.b,j-=k,C-=D,I-=T,J=J.next,d+=r}return t}function f(){this.r=0,this.g=0,this.b=0,this.a=0,this.next=null}var l=[512,512,456,512,328,456,335,512,405,328,271,456,388,335,292,512,454,405,364,328,298,271,496,456,420,388,360,335,312,292,273,512,482,454,428,405,383,364,345,328,312,298,284,271,259,496,475,456,437,420,404,388,374,360,347,335,323,312,302,292,282,273,265,512,497,482,468,454,441,428,417,405,394,383,373,364,354,345,337,328,320,312,305,298,291,284,278,271,265,259,507,496,485,475,465,456,446,437,428,420,412,404,396,388,381,374,367,360,354,347,341,335,329,323,318,312,307,302,297,292,287,282,278,273,269,265,261,512,505,497,489,482,475,468,461,454,447,441,435,428,422,417,411,405,399,394,389,383,378,373,368,364,359,354,350,345,341,337,332,328,324,320,316,312,309,305,301,298,294,291,287,284,281,278,274,271,268,265,262,259,257,507,501,496,491,485,480,475,470,465,460,456,451,446,442,437,433,428,424,420,416,412,408,404,400,396,392,388,385,381,377,374,370,367,363,360,357,354,350,347,344,341,338,335,332,329,326,323,320,318,315,312,310,307,304,302,299,297,294,292,289,287,285,282,280,278,275,273,271,269,267,265,263,261,259],c=[9,11,12,13,13,14,14,15,15,15,15,16,16,16,16,17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,18,19,19,19,19,19,19,19,19,19,19,19,19,19,19,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24];e.exports={image:r,canvasRGBA:a,canvasRGB:s,imageDataRGBA:i,imageDataRGB:u}},{}]},{},[16])(16)}); | ||
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.triangulate=t()}}(function(){return function t(e,n,r){function o(i,s){if(!n[i]){if(!e[i]){var u="function"==typeof require&&require;if(!s&&u)return u(i,!0);if(a)return a(i,!0);var f=new Error("Cannot find module '"+i+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[i]={exports:{}};e[i][0].call(l.exports,function(t){var n=e[i][1][t];return o(n?n:t)},l,l.exports,t,e,n,r)}return n[i].exports}for(var a="function"==typeof require&&require,i=0;i<r.length;i++)o(r[i]);return o}({1:[function(t,e,n){"use strict";e.exports={accuracy:.7,blur:40,fill:!0,stroke:!0,strokeWidth:.5,lineJoin:"miter",vertexCount:700}},{}],2:[function(t,e,n){"use strict";function r(t){return"object"!=typeof t&&(t={}),"number"!=typeof t.accuracy||isNaN(t.accuracy)?t.accuracy=a.accuracy:t.accuracy=o(t.accuracy,0,1),("number"!=typeof t.blur||isNaN(t.blur))&&(t.blur=a.blur),"string"!=typeof t.fill&&"boolean"!=typeof t.fill&&(t.fill=a.fill),"string"!=typeof t.stroke&&"boolean"!=typeof t.stroke&&(t.stroke=a.stroke),("number"!=typeof t.strokeWidth||isNaN(t.strokeWidth))&&(t.strokeWidth=a.strokeWidth),("string"!=typeof t.lineJoin||-1===l.indexOf(t.lineJoin))&&(t.lineJoin=a.lineJoin),("number"!=typeof t.vertexCount||isNaN(t.vertexCount))&&(t.vertexCount=a.vertexCount),t}var o=t("./util/clamp.js"),a=t("./defaultParams.js"),i=t("./input/fromImageToImageData.js"),s=t("./output/polygonsToImageData.js"),u=t("./output/polygonsToDataURL.js"),f=t("./output/polygonsToSVG.js"),l=["miter","round","bevel"];e.exports=function(t,e){function n(){return y}function o(){return x}function a(){return h&&d&&t}function l(){return t}function c(t){return a()?g():t()}function g(){var n=h(),r=e(n,t);return d(r,n)}t=r(t);var h,d,y={getParams:l},x={getParams:l};return y.fromImageData=function(t){return h=function(){return t},c(o)},x.toDataURL=function(t){return d=function(e,n){return u(e,n,t)},c(n)},x.toImageData=function(t){return d=function(e,n){return s(e,n,t)},c(n)},x.toSVG=function(){return d=f,c(n)},x.toData=function(){return d=function(t){return t},c(n)},y.fromImage=function(t){return h=function(){return i(t)},c(o)},n()}},{"./defaultParams.js":1,"./input/fromImageToImageData.js":6,"./output/polygonsToDataURL.js":7,"./output/polygonsToImageData.js":8,"./output/polygonsToSVG.js":9,"./util/clamp.js":14}],3:[function(t,e,n){"use strict";var r=t("canvas-browserify");e.exports=function(t){if("undefined"==typeof Uint8ClampedArray){var e=r(t.width,t.height),n=e.getContext("2d");return n.putImageData(t,0,0),n.getImageData(0,0,t.width,t.height)}return{width:t.width,height:t.height,data:new Uint8ClampedArray(t.data)}}},{"canvas-browserify":18}],4:[function(t,e,n){"use strict";function r(t,e,n,r){var a=o(n).slice(),i=parseInt(10*(e||.5),10)||1;r=r||1;var s,u,f=r?1/r:0;if(1!==f)for(s=0,u=a.length;s<a.length;s++)a[s]*=f;var l=t.data;u=l.length>>2;var c=new Uint8Array(u);for(C=0;u>C;C++)c[C]=l[C<<2];var g,h,d,y,x,p,m,v,b,w,C,j,k,I,D=0|t.width,T=0|t.height,E=Math.sqrt(a.length),P=.5*E|0;for(h=0;T>h;h+=i)for(j=h*D,g=0;D>g;g+=i){for(d=y=x=0,v=-P;P>=v;v++)if(w=h+v,k=w*D,I=(v+P)*E,w>=0&&T>w)for(m=-P;P>=m;m++)b=g+m,b>=0&&D>b&&(p=a[m+P+I])&&(d+=c[b+k]*p);0>d?d=0:d>255&&(d=255),l[g+j<<2]=255&d}return t}function o(t){var e,n=[],r=2*t+1,o=r*r,a=.5*o|0;for(e=0;o>e;e++)n[e]=e===a?-o+1:1;return n}e.exports=r},{}],5:[function(t,e,n){"use strict";function r(t){for(var e=t.data.length,n=t.data,r=void 0,o=0;e>o;o+=4)r=.34*n[o]+.5*n[o+1]+.16*n[o+2],n[o]=r,n[o+1]=r,n[o+2]=r;return t.data=n,t}e.exports=r},{}],6:[function(t,e,n){"use strict";var r=t("canvas-browserify");r.Image;e.exports=function(t){if(t instanceof HTMLImageElement){if(0===t.naturalWidth||0===t.naturalHeight||t.complete===!1)throw new Error("This this image hasn't finished loading: "+t.src);var e=new r(t.naturalWidth,t.naturalHeight),n=e.getContext("2d");return n.drawImage(t,0,0,e.width,e.height),n.getImageData(0,0,e.width,e.height)}throw new Error("This object does not seem to be an image.")}},{"canvas-browserify":18}],7:[function(t,e,n){"use strict";var r=t("canvas-browserify"),o=t("../util/drawPolygonsOnContext.js");e.exports=function(t,e,n){var a=n&&n.dpr?n.dpr:1,i=n&&n.backgroundColor?n.backgroundColor:!1,s=new r(e.width*a,e.height*a),u=s.getContext("2d");return i&&(u.fillStyle=i,u.fillRect(0,0,e.width*a,e.height*a),u.fillStyle="transparent"),o(u,t,e,a),s.toDataURL()}},{"../util/drawPolygonsOnContext.js":15,"canvas-browserify":18}],8:[function(t,e,n){"use strict";var r=t("canvas-browserify"),o=t("../util/drawPolygonsOnContext.js");e.exports=function(t,e,n){var a=n&&n.dpr?n.dpr:1,i=n&&n.backgroundColor?n.backgroundColor:!1,s=new r(e.width*a,e.height*a),u=s.getContext("2d");return i&&(u.fillStyle=i,u.fillRect(0,0,e.width*a,e.height*a),u.fillStyle="transparent"),o(u,t,e,a),u.getImageData(0,0,e.width*a,e.height*a)}},{"../util/drawPolygonsOnContext.js":15,"canvas-browserify":18}],9:[function(t,e,n){"use strict";e.exports=function(t,e){var n='<?xml version="1.0" standalone="yes"?>\n<svg width="'+e.width+'" height="'+e.height+'" xmlns="http://www.w3.org/2000/svg" version="1.1" >\n ';return t.forEach(function(t,e){var r=t.a,o=t.b,a=t.c;n+='<polygon points="'+r.x+","+r.y+" "+o.x+","+o.y+" "+a.x+","+a.y+'"',n+=t.fill?' fill="'+t.fill+'"':' fill="transparent"',t.strokeColor&&(n+=' stroke="'+t.strokeColor+'" stroke-width="'+t.strokeWidth+'" stroke-linejoin="'+t.lineJoin+'"'),n+="/>\n "}),n+="\n</svg>"}},{}],10:[function(t,e,n){"use strict";function r(t,e,n){var r=0,o=void 0,a=void 0,i=n.fill,s="string"==typeof i?n.fill:!1,u=n.stroke,f="string"==typeof u?n.stroke:!1,l=n.strokeWidth,c=n.lineJoin,g=void 0,h=void 0,d=void 0;return t.forEach(function(t,n){o=.33333*(t.a.x+t.b.x+t.c.x),a=.33333*(t.a.y+t.b.y+t.c.y),r=(0|o)+(0|a)*e.width<<2,g=e.data[r],h=e.data[r+1],d=e.data[r+2],i&&(t.fill=s||"rgb("+g+", "+h+", "+d+")"),u&&(f?t.strokeColor=f:t.strokeColor="rgb("+g+", "+h+", "+d+")",t.strokeWidth=l,t.lineJoin=c)}),t}e.exports=r},{}],11:[function(t,e,n){"use strict";function r(t,e,n){var r,o,a,i,s,u,f,l,c,g=parseInt(10*(n||.1),10)||1,h=e,d=t.width,y=t.height,x=t.data,p=[];for(o=0;y>o;o+=g)for(r=0;d>r;r+=g){for(l=c=0,a=-1;1>=a;a++)if(u=o+a,f=u*d,u>=0&&y>u)for(i=-1;1>=i;i++)s=r+i,s>=0&&d>s&&(l+=x[s+f<<2],c++);c&&(l/=c),l>h&&p.push({x:r,y:o})}return p}e.exports=r},{}],12:[function(t,e,n){"use strict";function r(t,e){return t.x*t.y-e.y*e.x}function o(t,e,n,o,i){var s=[],u=2*Math.ceil(o/(100-n))+2*Math.ceil(i/(100-n))+2,f=Math.max(t.length,e),l=a(f-u,0,e-u),c=f/l,g=0,h=0,d=0,y=0;for(t.sort(r),g=0,y=f;y>g;g+=c)s.push({x:t[~~g].x,y:t[~~g].y});for(h=0;o>h;h+=100-n)s.push({x:~~h,y:0}),s.push({x:~~h,y:i});for(d=0;i>d;d+=100-n)s.push({x:0,y:~~d}),s.push({x:o,y:~~d});return s.push({x:0,y:i}),s.push({x:o,y:i}),t=null,s}var a=t("../util/clamp.js");e.exports=o},{"../util/clamp.js":14}],13:[function(t,e,n){"use strict";var r=t("stackblur-canvas"),o=t("delaunay-fast"),a=t("../util/isImageData.js"),i=t("../imagedata/copyImageData.js"),s=t("../imagedata/greyscale"),u=t("../imagedata/detectEdges"),f=t("./getEdgePoints.js"),l=t("./getVerticesFromPoints.js"),c=t("./addColorToPolygons.js");e.exports=function(t,e){if(a(t)){var n={width:t.width,height:t.height},g=i(t),h=i(t),d=r.imageDataRGBA(g,0,0,n.width,n.height,e.blur),y=s(d),x=u(y),p=f(x,50,e.accuracy),m=l(p,e.vertexCount,e.accuracy,n.width,n.height),v=o.triangulate(m);return c(v,h,e)}throw new Error("Can't work with the imageData provided. It seems to be corrupt")}},{"../imagedata/copyImageData.js":3,"../imagedata/detectEdges":4,"../imagedata/greyscale":5,"../util/isImageData.js":16,"./addColorToPolygons.js":10,"./getEdgePoints.js":11,"./getVerticesFromPoints.js":12,"delaunay-fast":19,"stackblur-canvas":20}],14:[function(t,e,n){"use strict";function r(t,e,n){return e>t?e:t>n?n:t}e.exports=r},{}],15:[function(t,e,n){"use strict";e.exports=function(t,e,n,r){return r=r||1,e.forEach(function(e,n){t.beginPath(),t.moveTo(e.a.x*r,e.a.y*r),t.lineTo(e.b.x*r,e.b.y*r),t.lineTo(e.c.x*r,e.c.y*r),t.lineTo(e.a.x*r,e.a.y*r),e.fill&&(t.fillStyle=e.fill,t.fill()),e.strokeColor&&(t.strokeStyle=e.strokeColor,t.lineWidth=e.strokeWidth*r,t.lineJoin=e.lineJoin,t.stroke()),t.closePath()}),t}},{}],16:[function(t,e,n){"use strict";e.exports=function(t){return t&&"number"==typeof t.width&&"number"==typeof t.height&&t.data&&"number"==typeof t.data.length}},{}],17:[function(t,e,n){"use strict";function r(t){return o(t,a)}Object.defineProperty(n,"__esModule",{value:!0}),n["default"]=r;var o=t("./getInterfaceObj"),a=t("./polygons/imageDataToPolygons.js");e.exports=n["default"]},{"./getInterfaceObj":2,"./polygons/imageDataToPolygons.js":13}],18:[function(t,e,n){var r=e.exports=function(t,e){var n=document.createElement("canvas");return n.width=t||300,n.height=e||150,n};r.Image=function(){var t=document.createElement("img");return t}},{}],19:[function(t,e,n){function r(t,e,n){this.a=t,this.b=e,this.c=n;var r,o,a,i,s=e.x-t.x,u=e.y-t.y,f=n.x-t.x,l=n.y-t.y,c=s*(t.x+e.x)+u*(t.y+e.y),g=f*(t.x+n.x)+l*(t.y+n.y),h=2*(s*(n.y-e.y)-u*(n.x-e.x));Math.abs(h)<1e-6?(r=Math.min(t.x,e.x,n.x),o=Math.min(t.y,e.y,n.y),a=.5*(Math.max(t.x,e.x,n.x)-r),i=.5*(Math.max(t.y,e.y,n.y)-o),this.x=r+a,this.y=o+i,this.r=a*a+i*i):(this.x=(l*c-u*g)/h,this.y=(s*g-f*c)/h,a=this.x-t.x,i=this.y-t.y,this.r=a*a+i*i)}function o(t,e){return e.x-t.x}function a(t){var e,n,r,o,a,i=t.length;t:for(;i;)for(n=t[--i],e=t[--i],r=i;r;)if(a=t[--r],o=t[--r],e===o&&n===a||e===a&&n===o){t.splice(i,2),t.splice(r,2),i-=2;continue t}}function i(t){if(t.length<3)return[];t.sort(o);for(var e=t.length-1,n=t[e].x,i=t[0].x,s=t[e].y,u=s;e--;)t[e].y<s&&(s=t[e].y),t[e].y>u&&(u=t[e].y);var f,l,c,g=i-n,h=u-s,d=g>h?g:h,y=.5*(i+n),x=.5*(u+s),p=[new r({x:y-20*d,y:x-d,__sentinel:!0},{x:y,y:x+20*d,__sentinel:!0},{x:y+20*d,y:x-d,__sentinel:!0})],m=[],v=[];for(e=t.length;e--;){for(v.length=0,f=p.length;f--;)g=t[e].x-p[f].x,g>0&&g*g>p[f].r?(m.push(p[f]),p.splice(f,1)):(h=t[e].y-p[f].y,g*g+h*h>p[f].r||(v.push(p[f].a,p[f].b,p[f].b,p[f].c,p[f].c,p[f].a),p.splice(f,1)));for(a(v),f=v.length;f;)c=v[--f],l=v[--f],p.push(new r(l,c,t[e]))}for(Array.prototype.push.apply(m,p),e=m.length;e--;)(m[e].a.__sentinel||m[e].b.__sentinel||m[e].c.__sentinel)&&m.splice(e,1);return m}r.prototype.draw=function(t){t.beginPath(),t.moveTo(this.a.x,this.a.y),t.lineTo(this.b.x,this.b.y),t.lineTo(this.c.x,this.c.y),t.closePath(),t.stroke()},"undefined"!=typeof e&&(e.exports={Triangle:r,triangulate:i})},{}],20:[function(t,e,n){function r(t,e,n,r){if("string"==typeof t)var t=document.getElementById(t);else if(!t instanceof HTMLImageElement)return;var o=t.naturalWidth,i=t.naturalHeight;if("string"==typeof e)var e=document.getElementById(e);else if(!e instanceof HTMLCanvasElement)return;e.style.width=o+"px",e.style.height=i+"px",e.width=o,e.height=i;var u=e.getContext("2d");u.clearRect(0,0,o,i),u.drawImage(t,0,0),isNaN(n)||1>n||(r?a(e,0,0,o,i,n):s(e,0,0,o,i,n))}function o(t,e,n,r,o){if("string"==typeof t)var t=document.getElementById(t);else if(!t instanceof HTMLCanvasElement)return;var a,i=t.getContext("2d");try{try{a=i.getImageData(e,n,r,o)}catch(s){try{netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead"),a=i.getImageData(e,n,r,o)}catch(s){throw alert("Cannot access local image"),new Error("unable to access local image data: "+s)}}}catch(s){throw alert("Cannot access image"),new Error("unable to access image data: "+s)}return a}function a(t,e,n,r,a,s){if(!(isNaN(s)||1>s)){s|=0;var u=o(t,e,n,r,a);u=i(u,e,n,r,a,s),t.getContext("2d").putImageData(u,e,n)}}function i(t,e,n,r,o,a){var i,s,u,g,h,d,y,x,p,m,v,b,w,C,j,k,I,D,T,E,P,M,N,_,R=t.data,W=a+a+1,O=r-1,J=o-1,U=a+1,B=U*(U+1)/2,L=new f,S=L;for(u=1;W>u;u++)if(S=S.next=new f,u==U)var G=S;S.next=L;var A=null,H=null;y=d=0;var q=l[a],V=c[a];for(s=0;o>s;s++){for(k=I=D=T=x=p=m=v=0,b=U*(E=R[d]),w=U*(P=R[d+1]),C=U*(M=R[d+2]),j=U*(N=R[d+3]),x+=B*E,p+=B*P,m+=B*M,v+=B*N,S=L,u=0;U>u;u++)S.r=E,S.g=P,S.b=M,S.a=N,S=S.next;for(u=1;U>u;u++)g=d+((u>O?O:u)<<2),x+=(S.r=E=R[g])*(_=U-u),p+=(S.g=P=R[g+1])*_,m+=(S.b=M=R[g+2])*_,v+=(S.a=N=R[g+3])*_,k+=E,I+=P,D+=M,T+=N,S=S.next;for(A=L,H=G,i=0;r>i;i++)R[d+3]=N=v*q>>V,0!=N?(N=255/N,R[d]=(x*q>>V)*N,R[d+1]=(p*q>>V)*N,R[d+2]=(m*q>>V)*N):R[d]=R[d+1]=R[d+2]=0,x-=b,p-=w,m-=C,v-=j,b-=A.r,w-=A.g,C-=A.b,j-=A.a,g=y+((g=i+a+1)<O?g:O)<<2,k+=A.r=R[g],I+=A.g=R[g+1],D+=A.b=R[g+2],T+=A.a=R[g+3],x+=k,p+=I,m+=D,v+=T,A=A.next,b+=E=H.r,w+=P=H.g,C+=M=H.b,j+=N=H.a,k-=E,I-=P,D-=M,T-=N,H=H.next,d+=4;y+=r}for(i=0;r>i;i++){for(I=D=T=k=p=m=v=x=0,d=i<<2,b=U*(E=R[d]),w=U*(P=R[d+1]),C=U*(M=R[d+2]),j=U*(N=R[d+3]),x+=B*E,p+=B*P,m+=B*M,v+=B*N,S=L,u=0;U>u;u++)S.r=E,S.g=P,S.b=M,S.a=N,S=S.next;for(h=r,u=1;a>=u;u++)d=h+i<<2,x+=(S.r=E=R[d])*(_=U-u),p+=(S.g=P=R[d+1])*_,m+=(S.b=M=R[d+2])*_,v+=(S.a=N=R[d+3])*_,k+=E,I+=P,D+=M,T+=N,S=S.next,J>u&&(h+=r);for(d=i,A=L,H=G,s=0;o>s;s++)g=d<<2,R[g+3]=N=v*q>>V,N>0?(N=255/N,R[g]=(x*q>>V)*N,R[g+1]=(p*q>>V)*N,R[g+2]=(m*q>>V)*N):R[g]=R[g+1]=R[g+2]=0,x-=b,p-=w,m-=C,v-=j,b-=A.r,w-=A.g,C-=A.b,j-=A.a,g=i+((g=s+U)<J?g:J)*r<<2,x+=k+=A.r=R[g],p+=I+=A.g=R[g+1],m+=D+=A.b=R[g+2],v+=T+=A.a=R[g+3],A=A.next,b+=E=H.r,w+=P=H.g,C+=M=H.b,j+=N=H.a,k-=E,I-=P,D-=M,T-=N,H=H.next,d+=r}return t}function s(t,e,n,r,a,i){if(!(isNaN(i)||1>i)){i|=0;var s=o(t,e,n,r,a);s=u(s,e,n,r,a,i),t.getContext("2d").putImageData(s,e,n)}}function u(t,e,n,r,o,a){var i,s,u,g,h,d,y,x,p,m,v,b,w,C,j,k,I,D,T,E,P=t.data,M=a+a+1,N=r-1,_=o-1,R=a+1,W=R*(R+1)/2,O=new f,J=O;for(u=1;M>u;u++)if(J=J.next=new f,u==R)var U=J;J.next=O;var B=null,L=null;y=d=0;var S=l[a],G=c[a];for(s=0;o>s;s++){for(C=j=k=x=p=m=0,v=R*(I=P[d]),b=R*(D=P[d+1]),w=R*(T=P[d+2]),x+=W*I,p+=W*D,m+=W*T,J=O,u=0;R>u;u++)J.r=I,J.g=D,J.b=T,J=J.next;for(u=1;R>u;u++)g=d+((u>N?N:u)<<2),x+=(J.r=I=P[g])*(E=R-u),p+=(J.g=D=P[g+1])*E,m+=(J.b=T=P[g+2])*E,C+=I,j+=D,k+=T,J=J.next;for(B=O,L=U,i=0;r>i;i++)P[d]=x*S>>G,P[d+1]=p*S>>G,P[d+2]=m*S>>G,x-=v,p-=b,m-=w,v-=B.r,b-=B.g,w-=B.b,g=y+((g=i+a+1)<N?g:N)<<2,C+=B.r=P[g],j+=B.g=P[g+1],k+=B.b=P[g+2],x+=C,p+=j,m+=k,B=B.next,v+=I=L.r,b+=D=L.g,w+=T=L.b,C-=I,j-=D,k-=T,L=L.next,d+=4;y+=r}for(i=0;r>i;i++){for(j=k=C=p=m=x=0,d=i<<2,v=R*(I=P[d]),b=R*(D=P[d+1]),w=R*(T=P[d+2]),x+=W*I,p+=W*D,m+=W*T,J=O,u=0;R>u;u++)J.r=I,J.g=D,J.b=T,J=J.next;for(h=r,u=1;a>=u;u++)d=h+i<<2,x+=(J.r=I=P[d])*(E=R-u),p+=(J.g=D=P[d+1])*E,m+=(J.b=T=P[d+2])*E,C+=I,j+=D,k+=T,J=J.next,_>u&&(h+=r);for(d=i,B=O,L=U,s=0;o>s;s++)g=d<<2,P[g]=x*S>>G,P[g+1]=p*S>>G,P[g+2]=m*S>>G,x-=v,p-=b,m-=w,v-=B.r,b-=B.g,w-=B.b,g=i+((g=s+R)<_?g:_)*r<<2,x+=C+=B.r=P[g],p+=j+=B.g=P[g+1],m+=k+=B.b=P[g+2],B=B.next,v+=I=L.r,b+=D=L.g,w+=T=L.b,C-=I,j-=D,k-=T,L=L.next,d+=r}return t}function f(){this.r=0,this.g=0,this.b=0,this.a=0,this.next=null}var l=[512,512,456,512,328,456,335,512,405,328,271,456,388,335,292,512,454,405,364,328,298,271,496,456,420,388,360,335,312,292,273,512,482,454,428,405,383,364,345,328,312,298,284,271,259,496,475,456,437,420,404,388,374,360,347,335,323,312,302,292,282,273,265,512,497,482,468,454,441,428,417,405,394,383,373,364,354,345,337,328,320,312,305,298,291,284,278,271,265,259,507,496,485,475,465,456,446,437,428,420,412,404,396,388,381,374,367,360,354,347,341,335,329,323,318,312,307,302,297,292,287,282,278,273,269,265,261,512,505,497,489,482,475,468,461,454,447,441,435,428,422,417,411,405,399,394,389,383,378,373,368,364,359,354,350,345,341,337,332,328,324,320,316,312,309,305,301,298,294,291,287,284,281,278,274,271,268,265,262,259,257,507,501,496,491,485,480,475,470,465,460,456,451,446,442,437,433,428,424,420,416,412,408,404,400,396,392,388,385,381,377,374,370,367,363,360,357,354,350,347,344,341,338,335,332,329,326,323,320,318,315,312,310,307,304,302,299,297,294,292,289,287,285,282,280,278,275,273,271,269,267,265,263,261,259],c=[9,11,12,13,13,14,14,15,15,15,15,16,16,16,16,17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,18,19,19,19,19,19,19,19,19,19,19,19,19,19,19,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24];e.exports={image:r,canvasRGBA:a,canvasRGB:s,imageDataRGBA:i,imageDataRGB:u}},{}]},{},[17])(17)}); |
{ | ||
"name": "triangulate-image", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Converts images in to triangular polygons.", | ||
@@ -22,3 +22,6 @@ "author": "Georg Fischer <snorpey@gmail.com.com>", | ||
"build": "npm run clean && npm run build-node && npm run build-browser", | ||
"prepublish": "npm run build" | ||
"prepublish": "npm run build && npm run test", | ||
"test": "npm run test-node && npm run test-browser", | ||
"test-node": "mocha -R spec ./test/test-node.js", | ||
"test-browser": "mocha-phantomjs ./test/test-browser.html --ignore-resource-errors" | ||
}, | ||
@@ -35,3 +38,7 @@ "dependencies": { | ||
"envify": "^3.4.0", | ||
"expect.js": "^0.3.1", | ||
"libxmljs": "^0.17.0", | ||
"mkdirp": "^0.5.1", | ||
"mocha": "^2.3.4", | ||
"mocha-phantomjs": "^4.0.2", | ||
"rimraf": "^2.4.3", | ||
@@ -38,0 +45,0 @@ "uglify-js": "^2.5.0", |
@@ -7,4 +7,4 @@ triangulate-image | ||
* [triangulate-image.min.js](https://raw.githubusercontent.com/snorpey/triangulate-image/master/dist/triangulate-image.min.js) 16kb | ||
* [triangulate-image.js](https://raw.githubusercontent.com/snorpey/triangulate-image/master/dist/triangulate-image.js) 48kb | ||
* [triangulate-image.min.js](https://raw.githubusercontent.com/snorpey/triangulate-image/master/dist/triangulate-image.min.js) 17kb | ||
* [triangulate-image.js](https://raw.githubusercontent.com/snorpey/triangulate-image/master/dist/triangulate-image.js) 50kb | ||
* [triangulate-image-master.zip](https://github.com/snorpey/triangulate-image/archive/master.zip) | ||
@@ -57,3 +57,3 @@ | ||
* input: [``fromImage()``](#fromimage), [``fromImageData()``](#fromimagedata), [``fromBuffer()``](#frombuffer) | ||
* output: [``toDataURL()``](#todataurl), [``toImageData()``](#toimagedata), [``toData()``](#todata), [``toSVG()``](#tosvg), [``toJPGStream()``](#jpgstream), [``toPNGStream()``](#pngstream), [``toSVGStream()``](#svgstream) | ||
* output: [``toDataURL()``](#todataurl), [``toImageData()``](#toimagedata), [``toData()``](#todata), [``toSVG()``](#tosvg), [``toJPGStream()``](#tojpgstream), [``toPNGStream()``](#topngstream), [``toSVGStream()``](#tosvgstream) | ||
@@ -312,2 +312,6 @@ triangulate() | ||
toJPEGStream() | ||
--- | ||
see [``toJPGStream()``](#tojpgstream). | ||
toPNGStream() | ||
@@ -374,4 +378,6 @@ --- | ||
`npm run build` will build the node-ready and browser-ready versions, which are written to the `dist-node` and `dist` directories. | ||
`npm run build` will build the node-ready and browser-ready versions, which are saved to the `dist-node` and `dist` directories. | ||
`npm run test` will run the tests in both the browser and node. | ||
license | ||
@@ -378,0 +384,0 @@ === |
@@ -0,3 +1,5 @@ | ||
var clamp = require('./util/clamp.js'); | ||
var defaultParams = require('./defaultParams.js'); | ||
var fromImageToImageData = require('./input/fromImageToImageData.js'); | ||
var fromBufferToImageData = require('./input/fromBufferToImageData.js'); | ||
@@ -8,2 +10,4 @@ var polygonsToImageData = require('./output/polygonsToImageData.js'); | ||
var fromBufferToImageData | ||
var polygonsToBuffer; | ||
@@ -15,2 +19,3 @@ var polygonsToPNGStream; | ||
if ( process.env.NODE_ENV !== 'browser' ) { | ||
fromBufferToImageData = require('./input/fromBufferToImageData.js'); | ||
polygonsToSVGStream = require('./output/polygonsToSVGStream.js'); | ||
@@ -22,2 +27,42 @@ polygonsToBuffer = require('./output/polygonsToBuffer.js'); | ||
var allowedLineJoins = [ 'miter', 'round', 'bevel' ]; | ||
function checkParams ( params ) { | ||
if ( typeof params !== 'object' ) { | ||
params = { }; | ||
} | ||
if ( typeof params.accuracy !== 'number' || isNaN( params.accuracy ) ) { | ||
params.accuracy = defaultParams.accuracy; | ||
} else { | ||
params.accuracy = clamp( params.accuracy, 0, 1 ); | ||
} | ||
if ( typeof params.blur !== 'number' || isNaN( params.blur ) ) { | ||
params.blur = defaultParams.blur; | ||
} | ||
if ( typeof params.fill !== 'string' && typeof params.fill !== 'boolean' ) { | ||
params.fill = defaultParams.fill; | ||
} | ||
if ( typeof params.stroke !== 'string' && typeof params.stroke !== 'boolean' ) { | ||
params.stroke = defaultParams.stroke; | ||
} | ||
if ( typeof params.strokeWidth !== 'number' || isNaN( params.strokeWidth ) ) { | ||
params.strokeWidth = defaultParams.strokeWidth; | ||
} | ||
if ( typeof params.lineJoin !== 'string' || allowedLineJoins.indexOf( params.lineJoin ) === -1 ) { | ||
params.lineJoin = defaultParams.lineJoin; | ||
} | ||
if ( typeof params.vertexCount !== 'number' || isNaN( params.vertexCount ) ) { | ||
params.vertexCount = defaultParams.vertexCount; | ||
} | ||
return params; | ||
} | ||
// constructing an object that allows for a chained interface. | ||
@@ -33,10 +78,12 @@ // for example stuff like: | ||
module.exports = function ( params, callback ) { | ||
var input = { }; | ||
var output = { }; | ||
params = checkParams( params ); | ||
var input = { getParams }; | ||
var output = { getParams }; | ||
var inputFn; | ||
var outputFn; | ||
input.fromImageData = function () { | ||
inputFn = function ( imageData ) { return imageData; }; | ||
input.fromImageData = function ( imageData ) { | ||
inputFn = function () { return imageData; }; | ||
return go( getOutput ); | ||
@@ -111,2 +158,10 @@ }; | ||
} | ||
output.toJPEGStream = function ( jpgParams ) { | ||
outputFn = function ( polygons, size ) { | ||
return polygonsToJPGStream( polygons, size, jpgParams ); | ||
}; | ||
return go( getInput ); | ||
} | ||
} else { | ||
@@ -127,2 +182,6 @@ input.fromImage = function ( imageEl ) { | ||
function getParams () { | ||
return params; | ||
} | ||
function go ( fn ) { | ||
@@ -136,6 +195,7 @@ if ( canStart() ) { | ||
function start () { | ||
function start () { | ||
var imageData = inputFn(); | ||
var polygons = callback( imageData, params ); | ||
return outputFn( polygons, imageData ); | ||
@@ -142,0 +202,0 @@ } |
@@ -0,7 +1,21 @@ | ||
var Canvas = require('canvas-browserify'); | ||
module.exports = function ( imageData ) { | ||
return { | ||
width: imageData.width, | ||
height: imageData.height, | ||
data: new Uint8ClampedArray( imageData.data ) | ||
}; | ||
// this is mainly required to run the browser tests. | ||
// phantomjs < v2 doesn't understand Uint8ClampedArray | ||
if ( typeof Uint8ClampedArray === 'undefined' ) { | ||
// http://stackoverflow.com/a/11918126/229189 | ||
var canvas = Canvas( imageData.width, imageData.height ); | ||
var ctx = canvas.getContext( '2d' ); | ||
ctx.putImageData( imageData, 0, 0 ); | ||
return ctx.getImageData( 0, 0, imageData.width, imageData.height ); | ||
} else { | ||
// http://stackoverflow.com/a/15238036/229189 | ||
return { | ||
width: imageData.width, | ||
height: imageData.height, | ||
data: new Uint8ClampedArray( imageData.data ) | ||
}; | ||
} | ||
} |
@@ -6,11 +6,16 @@ // https://github.com/Automattic/node-canvas#imagesrcbuffer | ||
module.exports = function ( buffer ) { | ||
var image = new Image; | ||
image.src = buffer; | ||
if ( buffer instanceof Buffer ) { | ||
var image = new Image; | ||
image.src = buffer; | ||
var canvas = new Canvas( image.width, image.height ); | ||
var ctx = canvas.getContext('2d'); | ||
var canvas = new Canvas( image.width, image.height ); | ||
var ctx = canvas.getContext('2d'); | ||
ctx.drawImage( image, 0, 0, canvas.width, canvas.height ); | ||
ctx.drawImage( image, 0, 0, canvas.width, canvas.height ); | ||
return ctx.getImageData( 0, 0, canvas.width, canvas.height ); | ||
return ctx.getImageData( 0, 0, canvas.width, canvas.height ); | ||
} else { | ||
throw new Error( "Can't work with the buffer object provided." ); | ||
return; | ||
} | ||
}; |
var Canvas = require('canvas-browserify'); | ||
var Image = Canvas.Image; | ||
module.exports = function ( image ) { | ||
let canvas = new Canvas( image.naturalWidth, image.naturalHeight ); | ||
let ctx = canvas.getContext( '2d' ); | ||
ctx.drawImage( image, 0, 0, canvas.width, canvas.height ); | ||
if ( image instanceof HTMLImageElement ) { | ||
// http://stackoverflow.com/a/3016076/229189 | ||
if ( image.naturalWidth === 0 || image.naturalHeight === 0 || image.complete === false ) { | ||
throw new Error( "This this image hasn't finished loading: " + image.src ); | ||
} | ||
return ctx.getImageData( 0, 0, canvas.width, canvas.height ); | ||
let canvas = new Canvas( image.naturalWidth, image.naturalHeight ); | ||
let ctx = canvas.getContext( '2d' ); | ||
ctx.drawImage( image, 0, 0, canvas.width, canvas.height ); | ||
return ctx.getImageData( 0, 0, canvas.width, canvas.height ); | ||
} else { | ||
throw new Error( 'This object does not seem to be an image.' ); | ||
return; | ||
} | ||
} |
@@ -0,5 +1,7 @@ | ||
'use strict'; | ||
var stackBlur = require('stackblur-canvas'); | ||
var delaunay = require('delaunay-fast'); | ||
var clamp = require('../util/clamp.js'); | ||
var isImageData = require('../util/isImageData.js'); | ||
var copyImageData = require('../imagedata/copyImageData.js'); | ||
@@ -12,26 +14,22 @@ var greyscale = require('../imagedata/greyscale'); | ||
var allowedLineJoins = [ 'miter', 'round', 'bevel' ]; | ||
module.exports = function ( imageData, params ) { | ||
params.accuracy = clamp( params.accuracy || 0.7, 0, 1 ); | ||
params.blur = params.blur || 40; | ||
params.vertexCount = params.vertexCount || 700; | ||
params.fill = typeof params.fill === 'undefined' ? true : params.fill; | ||
params.stroke = typeof params.stroke === 'undefined' ? true : params.stroke; | ||
params.strokeWidth = typeof params.stroke === 'number' ? 0.5 : params.strokeWidth; | ||
params.lineJoin = allowedLineJoins.indexOf( params.lineJoin ) !== -1 ? params.lineJoin : allowedLineJoins[0]; | ||
var imageSize = { width: imageData.width, height: imageData.height }; | ||
if ( isImageData( imageData ) ) { | ||
var imageSize = { width: imageData.width, height: imageData.height }; | ||
var tmpImageData = copyImageData( imageData ); | ||
var colorImageData = copyImageData( imageData ); | ||
var tmpImageData = copyImageData( imageData ); | ||
var colorImageData = copyImageData( imageData ); | ||
var blurredImageData = stackBlur.imageDataRGBA( tmpImageData, 0, 0, imageSize.width, imageSize.height, params.blur ); | ||
var greyscaleImageData = greyscale( blurredImageData ); | ||
var edgesImageData = detectEdges( greyscaleImageData ); | ||
var edgePoints = getEdgePoints( edgesImageData, 50, params.accuracy ); | ||
var edgeVertices = getVerticesFromPoints( edgePoints, params.vertexCount, params.accuracy, imageSize.width, imageSize.height ); | ||
var polygons = delaunay.triangulate( edgeVertices ); | ||
var blurredImageData = stackBlur.imageDataRGBA( tmpImageData, 0, 0, imageSize.width, imageSize.height, params.blur ); | ||
var greyscaleImageData = greyscale( blurredImageData ); | ||
var edgesImageData = detectEdges( greyscaleImageData ); | ||
var edgePoints = getEdgePoints( edgesImageData, 50, params.accuracy ); | ||
var edgeVertices = getVerticesFromPoints( edgePoints, params.vertexCount, params.accuracy, imageSize.width, imageSize.height ); | ||
var polygons = delaunay.triangulate( edgeVertices ); | ||
return addColorToPolygons( polygons, colorImageData, params ); | ||
} | ||
return addColorToPolygons( polygons, colorImageData, params ); | ||
} else { | ||
throw new Error( "Can't work with the imageData provided. It seems to be corrupt" ); | ||
return; | ||
} | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
123145
51
2264
406
12