srtm1 progress
This commit is contained in:
parent
95209148b4
commit
561b60c5cb
9 changed files with 289 additions and 166 deletions
|
|
@ -12,46 +12,74 @@ import java.io.InputStream;
|
|||
|
||||
public final class MixCoderDataInputStream extends DataInputStream
|
||||
{
|
||||
private long lastValue;
|
||||
private long repCount;
|
||||
private int lastValue;
|
||||
private int repCount;
|
||||
private int diffshift;
|
||||
|
||||
private int bm = 0x100;
|
||||
private int b;
|
||||
|
||||
public MixCoderDataInputStream( InputStream is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
|
||||
public long readSigned() throws IOException
|
||||
{
|
||||
long v = readUnsigned();
|
||||
return ( v & 1 ) == 0 ? v >> 1 : -(v >> 1 );
|
||||
}
|
||||
|
||||
public long readUnsigned() throws IOException
|
||||
{
|
||||
long v = 0;
|
||||
int shift = 0;
|
||||
for(;;)
|
||||
{
|
||||
long i7 = readByte() & 0xff;
|
||||
v |= (( i7 & 0x7f ) << shift);
|
||||
if ( ( i7 & 0x80 ) == 0 ) break;
|
||||
shift += 7;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
public long readMixed() throws IOException
|
||||
public int readMixed() throws IOException
|
||||
{
|
||||
if ( repCount == 0 )
|
||||
{
|
||||
long b = readByte() & 0xff;
|
||||
long repCode = b >> 6;
|
||||
long diffcode = b & 0x3f;
|
||||
repCount = repCode == 0 ? readUnsigned() : repCode;
|
||||
lastValue += diffcode == 0 ? readSigned() : diffcode - 32;
|
||||
boolean negative = decodeBit();
|
||||
int d = decodeVarBits() + diffshift;
|
||||
repCount = decodeVarBits() + 1;
|
||||
lastValue += negative ? -d : d;
|
||||
diffshift = 1;
|
||||
}
|
||||
repCount--;
|
||||
return lastValue;
|
||||
}
|
||||
|
||||
public final boolean decodeBit() throws IOException
|
||||
{
|
||||
if ( bm == 0x100 )
|
||||
{
|
||||
bm = 1;
|
||||
b = readByte();
|
||||
}
|
||||
boolean value = ( ( b & bm ) != 0 );
|
||||
bm <<= 1;
|
||||
return value;
|
||||
}
|
||||
|
||||
public final int decodeVarBits() throws IOException
|
||||
{
|
||||
int range = 0;
|
||||
int value = 0;
|
||||
while (!decodeBit())
|
||||
{
|
||||
value += range + 1;
|
||||
range = 2 * range + 1;
|
||||
}
|
||||
return value + decodeBounded( range );
|
||||
}
|
||||
|
||||
|
||||
public final int decodeBounded( int max ) throws IOException
|
||||
{
|
||||
int value = 0;
|
||||
int im = 1; // integer mask
|
||||
while (( value | im ) <= max)
|
||||
{
|
||||
if ( bm == 0x100 )
|
||||
{
|
||||
bm = 1;
|
||||
b = readByte();
|
||||
}
|
||||
if ( ( b & bm ) != 0 )
|
||||
value |= im;
|
||||
bm <<= 1;
|
||||
im <<= 1;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue