Skip to content

Commit

Permalink
remove toDataURL() polyfill, fixes evanw#7
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Feb 10, 2013
1 parent f8a1eb2 commit a8a03b4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
18 changes: 0 additions & 18 deletions src/core/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,23 +111,6 @@ function getPixelArray() {
return array;
}

// Fix broken toDataURL() methods on some implementations
function toDataURL(mimeType) {
var w = this._.texture.width;
var h = this._.texture.height;
var array = getPixelArray.call(this);
var canvas2d = document.createElement('canvas');
var c = canvas2d.getContext('2d');
canvas2d.width = w;
canvas2d.height = h;
var data = c.createImageData(w, h);
for (var i = 0; i < array.length; i++) {
data.data[i] = array[i];
}
c.putImageData(data, 0, 0);
return canvas2d.toDataURL(mimeType);
}

function wrap(func) {
return function() {
// Make sure that we're using the correct global WebGL context
Expand Down Expand Up @@ -163,7 +146,6 @@ exports.canvas = function() {
canvas.replace = wrap(replace);
canvas.contents = wrap(contents);
canvas.getPixelArray = wrap(getPixelArray);
canvas.toDataURL = wrap(toDataURL);

// Filter methods
canvas.brightnessContrast = wrap(brightnessContrast);
Expand Down
15 changes: 15 additions & 0 deletions tests/canvas.toDataURL.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<script src="http://evanw.github.com/glfx.js/glfx.js"></script>
<script>

window.onload = function() {
var canvas = fx.canvas();
var texture = canvas.texture(document.getElementById('image'));
canvas.draw(texture).ink(0.25).update();
var image = new Image;
image.src = canvas.toDataURL();
document.body.appendChild(image);
};

</script>
<img id="image" src="image.jpg">
<p>This tests the toDataURL() method on the canvas, which is part of the native WebGLRenderingContext API. The above image should appear below with the ink filter applied.</p>

0 comments on commit a8a03b4

Please sign in to comment.