Commit 5ca5e2d8 authored by Mike Tinglof's avatar Mike Tinglof

implement tight indexed rectangle; remove some debug code

parent 6fbc3748
......@@ -355,7 +355,7 @@ this.read_bits = function(d, num, base)
return base;
var val = 0;
while (d.bitcount < num) {
while (d.bitcount < 24) {
d.tag = d.tag | (d.source[d.sourceIndex++] & 0xff) << d.bitcount;
d.bitcount += 8;
}
......@@ -368,7 +368,7 @@ this.read_bits = function(d, num, base)
/* given a data stream and a tree, decode a symbol */
this.decode_symbol = function(d, t)
{
while (d.bitcount < 10) {
while (d.bitcount < 16) {
d.tag = d.tag | (d.source[d.sourceIndex++] & 0xff) << d.bitcount;
d.bitcount += 8;
}
......
......@@ -1307,16 +1307,6 @@ encHandlers.TIGHT = function display_tight() {
throw("Invalid data in zlib stream");
Util.Warn("Decompressed " + data.length + " to " + uncompressed.data.length + " checksums " +
checksum(data) + ":" + checksum(uncompressed.data));
/*
var i;
var uncompressed2 = zip_inflate(data);
for (i=0;i<uncompressed.length;i++)
if (uncompressed[i] !== uncompressed2[i]) {
Util.Warn("Decompression difference at " + i);
break;
}
*/
return uncompressed.data;
}
......@@ -1345,14 +1335,54 @@ encHandlers.TIGHT = function display_tight() {
// Shift ctl, filter id, num colors, palette entries, and clength off
ws.rQshiftBytes(3 + paletteSize + clength[0]);
if (streamId == 0) throw ("Wrong stream");
// Process data
// Decompress data
if (raw)
data = ws.rQshiftBytes(clength[1]);
else
data = decompress(ws.rQshiftBytes(clength[1]));
var dest = [];
var x, y, b;
if (numColors == 2) {
var w = Math.floor((FBU.width + 7) / 8);
var w1 = Math.floor(FBU.width / 8);
for (y = 0; y < FBU.height; y++) {
for (x = 0; x < w1; x++) {
for (b = 7; b >= 0; b--) {
var dp = (y*FBU.width + x*8 + 7-b) * 3;
var sp = (data[y*w + x] >> b & 1) * 3;
dest[dp ] = FBU.palette[sp ];
dest[dp+1] = FBU.palette[sp+1];
dest[dp+2] = FBU.palette[sp+2];
}
for (b = 7; b >= 8 - FBU.width % 8; b--) {
var dp = (y*FBU.width + x*8 + 7-b) * 3;
var sp = (data[y*w + x] >> b & 1) * 3;
dest[dp ] = FBU.palette[sp ];
dest[dp+1] = FBU.palette[sp+1];
dest[dp+2] = FBU.palette[sp+2];
}
}
}
} else {
for (y = 0; y < FBU.height; y++) {
for (x = 0; x < FBU.width; x++) {
var dp = (y*FBU.width + x) * 3;
var sp = data[y*FBU.width + x] * 3;
dest[dp ] = FBU.palette[sp ];
dest[dp+1] = FBU.palette[sp+1];
dest[dp+2] = FBU.palette[sp+2];
}
}
}
FBU.imgQ.push({
'type': 'rgb',
'img': {'complete': true, 'data': dest},
'x': FBU.x,
'y': FBU.y,
'width': FBU.width,
'height': FBU.height});
return true;
}
......@@ -1368,8 +1398,6 @@ encHandlers.TIGHT = function display_tight() {
FBU.bytes = 1 + clength[0] + clength[1]; // ctl + clength size + zlib-data
if (ws.rQwait("TIGHT " + cmode, FBU.bytes)) { return false; }
if (streamId != 0) throw ("Wrong stream");
ws.rQshiftBytes(1 + clength[0]); // ctl + clength
if (raw)
data = ws.rQshiftBytes(clength[1]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment