-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrol.js
More file actions
141 lines (114 loc) · 3.33 KB
/
Copy pathcontrol.js
File metadata and controls
141 lines (114 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
function readURL(e) {
if (e.target.files && e.target.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
var output = document.getElementById('img');
output.src = reader.result;
};
reader.readAsDataURL(e.target.files[0]);
}
}
function drawOnCanvas(loadedImg) {
var w = document.getElementById('winput');
var h = document.getElementById('hinput');
w.value = loadedImg.width;
h.value = loadedImg.height;
var img = new Image();
//var loadedImg = document.getElementById('img');
img.src = loadedImg.src;
console.log("%o", img);
//var canvas = document.createElement('canvas');
var canvas = document.getElementById('canvas');
canvas.width = img.width;
canvas.height = img.height;
var ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0, img.width, img.height);
console.log(img.width, img.height);
}
function loadTimer() {
var element = document.getElementById('timerProgress');
var seconds = new ProgressBar.Circle(element, {
duration: 200,
color: "#FCB03C",
trailColor: "#ddd"
});
setInterval(function() {
var second = new Date().getSeconds();
seconds.animate(second / 60, function() {
seconds.setText(second);
});
}, 1000);
}
function setupProgressBar() {
var element = document.getElementById('progressBar');
element.innerHTML = '';
var line = new ProgressBar.Line(element, {
color: '#6FD57F',
easing: 'linear',
text: {
style: {
color: "#aaa"
}
}
});
return line;
//line.animate(1.0); // Number from 0.0 to 1.0
}
function isNumber(obj) {
if (obj.toFixed) //check a method working on numbers is defined
return true;
else
return false;
}
function retargetImage(btn) {
btn.disabled = true;
var newW = document.getElementById('winput').value;
var newH = document.getElementById('hinput').value;
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
var w = canvas.width;
var h = canvas.height;
if (canvas.width < newW) {
var img = document.getElementById('img');
var w = img.width;
var h = img.height;
drawOnCanvas(img);
}
var progressBar = setupProgressBar();
var imgData = ctx.getImageData(0, 0, w, h);
gradients = computeGradient(imgData.data, w, h);
drawGradient(ctx, w, h, gradients);
if (window.Worker) {
var thread = new Worker("worker.js");
thread.postMessage([w - newW, h - newH, w, h, imgData.data]);
thread.onmessage = function(e) {
if (isNumber(e.data)) {
var percentage = e.data;
progressBar.animate(percentage);
progressBar.setText(percentage * 100 + "%");
}
else {
progressBar.animate(1);
progressBar.setText("100%");
console.log("Received");
console.log("%o", e);
//newPixels = removeVerticalSeams(1, img.width, img.height, imgData.data);
newPixels = e.data;
canvas.width = newW;
canvas.height = newH;
ctx = canvas.getContext('2d');
imgData = ctx.getImageData(0, 0, canvas.width, canvas.height);
//console.log("%o", newPixels.length);
//console.log("%o", imgData);
imgData.data.set(newPixels);
ctx.putImageData(imgData, 0, 0);
//seamEnergy = computeVerticalSeams(gradients, img.width, img.height);
//drawVerticalSeams(ctx, img.width, img.height, seamEnergy);
btn.disabled = false;
}
}
thread.onerror = function(e) {
console.log('ERROR: Line ', e.lineno, ' in ', e.filename, ': ', e.message);
}
}
}