Skip to content

Commit d6dba4d

Browse files
committed
actual size always
1 parent 9b4774d commit d6dba4d

File tree

9 files changed

+28
-12
lines changed

9 files changed

+28
-12
lines changed

SeamCarver.js

+3
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,9 @@ class SeamCarver {
293293
this.canvas.width = this.imageData.width;
294294
this.canvas.height = this.imageData.height;
295295

296+
this.canvas.style.width = this.imageData.width + 'px';
297+
this.canvas.style.height = this.imageData.height + 'px';
298+
296299
if (field === 'energy' || field === 'vminsum' || (field !== this.imageData.dataField)) {
297300
this.imageData = this.context.createImageData(this.width, this.height);
298301
this.imageData.dataField = field;

demo/javascript/build/bundle.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,9 @@ class SeamCarver {
294294
this.canvas.width = this.imageData.width;
295295
this.canvas.height = this.imageData.height;
296296

297+
this.canvas.style.width = this.imageData.width + 'px';
298+
this.canvas.style.height = this.imageData.height + 'px';
299+
297300
if (field === 'energy' || field === 'vminsum' || (field !== this.imageData.dataField)) {
298301
this.imageData = this.context.createImageData(this.width, this.height);
299302
this.imageData.dataField = field;
@@ -403,7 +406,7 @@ var demo = window.demo;
403406
demo.config = {
404407
drawField: 'rgb',
405408
seamColor: "#32cd32",
406-
autoIterations: 0,
409+
autoIterate: false,
407410
iterationState: 0
408411
};
409412
demo.image = new Image();
@@ -434,7 +437,7 @@ demo.iterate = function () {
434437
setTimeout(function () {
435438
demo.removeSeam()
436439
demo.iteration++;
437-
if (demo.iteration < demo.config.autoIterations) {
440+
if (demo.config.autoIterate) {
438441
demo.iterate();
439442
}
440443
}, 0);
@@ -461,6 +464,7 @@ demo.togglePixelation = function () {
461464
}
462465

463466
key('i', function () {
467+
demo.config.autoIterate = !demo.config.autoIterate;
464468
demo.iterate();
465469
});
466470

@@ -510,7 +514,11 @@ demo.reset = function () {
510514
// demo.image.src = 'images/200x100.png';
511515
// demo.image.src = 'images/chameleon.png';
512516
// demo.image.src = 'images/HJocean.png';
513-
demo.image.src = 'https://cdn.hyperdev.com/us-east-1%3A095124f7-7022-4119-9d6a-68fd1e3dd7ef%2Fchameleon.png';
517+
// demo.image.src = 'images/butterfly.png';
518+
// demo.image.src = 'images/1000x300.jpg';
519+
demo.image.src = 'images/1000x500.jpg';
520+
// demo.image.src = 'images/1600x1200.jpg';
521+
// demo.image.src = 'https://cdn.hyperdev.com/us-east-1%3A095124f7-7022-4119-9d6a-68fd1e3dd7ef%2Fchameleon.png';
514522
};
515523

516524
demo.reset();

demo/javascript/src/demo.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var demo = window.demo;
88
demo.config = {
99
drawField: 'rgb',
1010
seamColor: "#32cd32",
11-
autoIterations: 0,
11+
autoIterate: false,
1212
iterationState: 0
1313
};
1414
demo.image = new Image();
@@ -39,7 +39,7 @@ demo.iterate = function () {
3939
setTimeout(function () {
4040
demo.removeSeam()
4141
demo.iteration++;
42-
if (demo.iteration < demo.config.autoIterations) {
42+
if (demo.config.autoIterate) {
4343
demo.iterate();
4444
}
4545
}, 0);
@@ -66,6 +66,7 @@ demo.togglePixelation = function () {
6666
}
6767

6868
key('i', function () {
69+
demo.config.autoIterate = !demo.config.autoIterate;
6970
demo.iterate();
7071
});
7172

@@ -115,7 +116,11 @@ demo.reset = function () {
115116
// demo.image.src = 'images/200x100.png';
116117
// demo.image.src = 'images/chameleon.png';
117118
// demo.image.src = 'images/HJocean.png';
118-
demo.image.src = 'https://cdn.hyperdev.com/us-east-1%3A095124f7-7022-4119-9d6a-68fd1e3dd7ef%2Fchameleon.png';
119+
// demo.image.src = 'images/butterfly.png';
120+
// demo.image.src = 'images/1000x300.jpg';
121+
demo.image.src = 'images/1000x500.jpg';
122+
// demo.image.src = 'images/1600x1200.jpg';
123+
// demo.image.src = 'https://cdn.hyperdev.com/us-east-1%3A095124f7-7022-4119-9d6a-68fd1e3dd7ef%2Fchameleon.png';
119124
};
120125

121126
demo.reset();

images/1000x300.jpg

32.8 KB
Loading

images/1000x500.jpg

144 KB
Loading

images/1600x1200.jpg

287 KB
Loading

images/butterfly.png

4.15 MB
Loading

index.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020

2121
canvas.image {
2222
background: #eaeaea;
23-
max-width: 100%;
24-
max-height: 100%;
2523
image-rendering: pixelated;
26-
height: 100%;
24+
/*max-width: 100%;*/
25+
/*max-height: 100%;*/
26+
/*height: 100%;*/
2727
border: 1px solid #eaeaea;
2828
}
2929
header {
@@ -45,7 +45,7 @@
4545
<header>
4646
<button onclick="demo.togglePixelation()">Toggle pixelation (P)</button>
4747
<button onclick="demo.reDraw('energy')">Energy (E)</button>
48-
<button onclick="demo.reDraw('minsum')">Cumulative sum (S)</button>
48+
<button onclick="demo.reDraw('minsum')">Min sum (S)</button>
4949
<button onclick="demo.reDraw('minx')">Minx (X)</button>
5050
<button onclick="demo.reDraw()">Color (C)</button>
5151
<button onclick="demo.iterate()">Iterate (I)</button>

test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ describe('SeamCarver', function() {
5656
assert.equal(sm.energyMatrix[0][3], 1000);
5757
assert.equal(sm.minsumMatrix[0][3], 1000);
5858
assert.equal(sm.minxMatrix[0][3], 0);
59-
assert.equal(sm.energyMatrix[1][2], Math.sqrt(52024));
60-
assert.equal(sm.minsumMatrix[1][2], 1000 + Math.sqrt(52024));
59+
assert.equal(parseInt(sm.energyMatrix[1][2]), parseInt(Math.sqrt(52024)));
60+
assert.equal(parseInt(sm.minsumMatrix[1][2]), parseInt(1000 + Math.sqrt(52024)));
6161
assert.equal(sm.minxMatrix[1][2], 0);
6262
done();
6363
});

0 commit comments

Comments
 (0)