Skip to content

Commit

Permalink
Forked off copying pixels in case of Chrome.
Browse files Browse the repository at this point in the history
Added Log Timers as Diffs.
  • Loading branch information
Parashuram committed Jan 30, 2011
1 parent 6795c7b commit 7a52cb0
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions index.html
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -153,12 +153,22 @@ <h1 style ="text-align:center"><a href = "http://en.wikipedia.org/wiki/Seam_carv
worker.addEventListener("message", function(e){ worker.addEventListener("message", function(e){
switch (e.data.action) { switch (e.data.action) {
case "done": case "done":
newImage = ctx.createImageData(e.data.image.width, e.data.image.height); var start = new Date().getTime();
log("Reduced image available, copying it to canvas") log("Reduced image available, copying it to canvas");
for (var i = 0; i < e.data.image.data.length; i++) { var result = e.data.image;
newImage.data[i] = e.data.image.data[i]; try {
ctx.putImageData(result, 0, 0);
}
catch (e) {
log("Could not simply reassign the canvas, so copying the entire array");
var newImage = ctx.createImageData(result.width, result.height);
for (var i = 0; i < result.data.length; i++) {
newImage.data[i] = result.data[i];
}
ctx.putImageData(newImage, 0, 0);
} }
ctx.putImageData(newImage, 0, 0);
log("Array Copy time " + (new Date().getTime() - start))
log("Reduced image placed on canvas"); log("Reduced image placed on canvas");
break; break;
default: default:
Expand Down Expand Up @@ -189,10 +199,10 @@ <h1 style ="text-align:center"><a href = "http://en.wikipedia.org/wiki/Seam_carv
} }


function log(msg){ function log(msg){
var time = new Date(); if (typeof startTime === "undefined") {
var t = time.toTimeString(); startTime = new Date().getTime();
t = "<span style = 'color:GREEN'>" + t + "</span> " + msg; }
$("#log").append($("<div>").html(t)); $("#log").append($("<div>").html("<span style = 'color:GREEN'>" + (new Date().getTime() - startTime) + "</span> : " + msg));
} }


$("#images img").first().click(); $("#images img").first().click();
Expand Down

0 comments on commit 7a52cb0

Please sign in to comment.