diff --git a/build.py b/build.py index 1caaa60..1e517fb 100755 --- a/build.py +++ b/build.py @@ -17,7 +17,17 @@ def sources(): return [os.path.join(base, f) for base, folders, files in \ - os.walk(input_path) for f in files if f.endswith('.js')] + os.walk(input_path) for f in files if 'include' in sys.argv and includes(os.path.join(base, f)) or 'include' not in sys.argv and f.endswith('.js')] + +def includes(file): + if '/filters/' in file: + if 'common' in file: + return True + for name in sys.argv: + if name in file: + return True + return False + return True def compile(sources): return '\n'.join('// %s\n%s' % (path, open(path).read()) for path in sources) diff --git a/src/core/canvas.js b/src/core/canvas.js index b9bc4e1..18e0d0b 100644 --- a/src/core/canvas.js +++ b/src/core/canvas.js @@ -129,8 +129,8 @@ function wrap(func) { }; } -exports.canvas = function() { - var canvas = document.createElement('canvas'); +exports.canvas = function(canvas) { + canvas = canvas instanceof window.HTMLCanvasElement ? canvas : document.createElement('canvas'); try { gl = canvas.getContext('experimental-webgl', { premultipliedAlpha: false }); } catch (e) { @@ -156,29 +156,29 @@ exports.canvas = function() { canvas.getPixelArray = wrap(getPixelArray); // Filter methods - canvas.brightnessContrast = wrap(brightnessContrast); - canvas.hexagonalPixelate = wrap(hexagonalPixelate); - canvas.hueSaturation = wrap(hueSaturation); - canvas.colorHalftone = wrap(colorHalftone); - canvas.triangleBlur = wrap(triangleBlur); - canvas.unsharpMask = wrap(unsharpMask); - canvas.perspective = wrap(perspective); - canvas.matrixWarp = wrap(matrixWarp); - canvas.bulgePinch = wrap(bulgePinch); - canvas.tiltShift = wrap(tiltShift); - canvas.dotScreen = wrap(dotScreen); - canvas.edgeWork = wrap(edgeWork); - canvas.lensBlur = wrap(lensBlur); - canvas.zoomBlur = wrap(zoomBlur); - canvas.noise = wrap(noise); - canvas.denoise = wrap(denoise); - canvas.curves = wrap(curves); - canvas.swirl = wrap(swirl); - canvas.ink = wrap(ink); - canvas.vignette = wrap(vignette); - canvas.vibrance = wrap(vibrance); - canvas.sepia = wrap(sepia); + typeof brightnessContrast !== 'undefined' && (canvas.brightnessContrast = wrap(brightnessContrast)); + typeof hexagonalPixelate !== 'undefined' && (canvas.hexagonalPixelate = wrap(hexagonalPixelate)); + typeof hueSaturation !== 'undefined' && (canvas.hueSaturation = wrap(hueSaturation)); + typeof colorHalftone !== 'undefined' && (canvas.colorHalftone = wrap(colorHalftone)); + typeof triangleBlur !== 'undefined' && (canvas.triangleBlur = wrap(triangleBlur)); + typeof unsharpMask !== 'undefined' && (canvas.unsharpMask = wrap(unsharpMask)); + typeof perspective !== 'undefined' && (canvas.perspective = wrap(perspective)); + typeof matrixWarp !== 'undefined' && (canvas.matrixWarp = wrap(matrixWarp)); + typeof bulgePinch !== 'undefined' && (canvas.bulgePinch = wrap(bulgePinch)); + typeof tiltShift !== 'undefined' && (canvas.tiltShift = wrap(tiltShift)); + typeof dotScreen !== 'undefined' && (canvas.dotScreen = wrap(dotScreen)); + typeof edgeWork !== 'undefined' && (canvas.edgeWork = wrap(edgeWork)); + typeof lensBlur !== 'undefined' && (canvas.lensBlur = wrap(lensBlur)); + typeof zoomBlur !== 'undefined' && (canvas.zoomBlur = wrap(zoomBlur)); + typeof noise !== 'undefined' && (canvas.noise = wrap(noise)); + typeof denoise !== 'undefined' && (canvas.denoise = wrap(denoise)); + typeof curves !== 'undefined' && (canvas.curves = wrap(curves)); + typeof swirl !== 'undefined' && (canvas.swirl = wrap(swirl)); + typeof ink !== 'undefined' && (canvas.ink = wrap(ink)); + typeof vignette !== 'undefined' && (canvas.vignette = wrap(vignette)); + typeof vibrance !== 'undefined' && (canvas.vibrance = wrap(vibrance)); + typeof sepia !== 'undefined' && (canvas.sepia = wrap(sepia)); return canvas; }; -exports.splineInterpolate = splineInterpolate; +typeof splineInterpolate !== 'undefined' && (exports.splineInterpolate = splineInterpolate);