Permalink
Browse files

progressive and examples

  • Loading branch information...
1 parent bc97b32 commit a2c961f40ff64d80bf1ea216eeb73feae5a0c6c0 @notmasteryet committed Aug 9, 2011
Showing with 29 additions and 17 deletions.
  1. +25 −12 example.html
  2. BIN j2.jpg
  3. BIN j3.jpg
  4. +4 −5 jpg.js
View
37 example.html
@@ -4,19 +4,32 @@
<script src="jpg.js"></script>
<script>
-var j = new JpegImage();
-j.onload = function() {
- var c = document.getElementById("c");
- c.width = j.width;
- c.height = j.height;
- var ctx = c.getContext("2d");
- var d = ctx.getImageData(0,0,j.width,j.height);
- j.copyToImageData(d);
- ctx.putImageData(d, 0, 0);
-};
-j.load("j1.jpg");
+function displayImage(canvasId, url) {
+ var j = new JpegImage();
+ j.onload = function() {
+ var c = document.getElementById(canvasId);
+ c.width = j.width;
+ c.height = j.height;
+ var ctx = c.getContext("2d");
+ var d = ctx.getImageData(0,0,j.width,j.height);
+ j.copyToImageData(d);
+ ctx.putImageData(d, 0, 0);
+ };
+ j.load(url);
+}
+
+displayImage("c1", "j1.jpg");
+displayImage("c2", "j2.jpg");
+displayImage("c3", "j3.jpg");
</script>
</head>
<body>
-<canvas id="c"></canvas>
+ <table>
+ <tr><th>baseline</th><th>progressive</th><th>baseline (gray)</th></tr>
+ <tr>
+ <td><canvas id="c1"></canvas></td>
+ <td><canvas id="c2"></canvas></td>
+ <td><canvas id="c3"></canvas></td>
+ </tr>
+ </table>
</body></html>
View
BIN j2.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN j3.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
9 jpg.js
@@ -175,7 +175,7 @@ var JpegImage = (function() {
continue;
}
k += r;
- zz[k] = receiveAndExtend(s);
+ zz[k] = receiveAndExtend(s) * (1 << successive);
k++;
}
}
@@ -205,7 +205,7 @@ var JpegImage = (function() {
case 1: // skipping r zero items
case 2:
if (zz[k])
- zz[k] |= readBit() << successive;
+ zz[k] += (readBit() << successive);
else {
r--;
if (r === 0)
@@ -214,15 +214,15 @@ var JpegImage = (function() {
break;
case 3: // set value for a zero item
if (zz[k])
- zz[k] |= readBit() << successive;
+ zz[k] += (readBit() << successive);
else {
zz[k] = successiveACNextValue << successive;
successiveACState = 0;
}
break;
case 4: // eob
if (zz[k])
- zz[k] |= readBit() << successive;
+ zz[k] += (readBit() << successive);
break;
}
k++;
@@ -351,7 +351,6 @@ var JpegImage = (function() {
var scanLine = blockRow << 3;
for (i = 0; i < 8; i++)
lines.push(new Uint8Array(samplesPerLine));
-
for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
var r = quantizeAndInverse(component.blocks[blockRow][blockCol]);

0 comments on commit a2c961f

Please sign in to comment.