use of uk.me.parabola.imgfmt.app.BitReader in project mkgmap by openstreetmap.
the class RGNFileReader method readLineCommonExtType.
/**
* Common code to read extended type lines or polygons for a given sub division.
* @param reader The reader for the img file.
* @param div The subdivision.
* @param line The line or shape that is to be populated.
*/
private void readLineCommonExtType(ImgFileReader reader, Subdivision div, Polyline line) {
int type = reader.get();
type = (type & 0xff) << 8;
byte b1 = reader.get();
boolean hasExtraBytes = (b1 & 0x80) != 0;
boolean hasLabel = (b1 & 0x20) != 0;
type |= 0x10000 + (b1 & 0x1f);
line.setType(type);
line.setDeltaLong((short) reader.getChar());
line.setDeltaLat((short) reader.getChar());
b1 = reader.get();
int len;
// one byte or two byte length field?
if ((b1 & 0x01) != 0) {
len = (b1 >> 1) & 0x7f;
assert len < 0x7f;
} else {
byte b2 = reader.get();
len = (((b2 & 0xff) << 8) + (b1 & 0xff)) >> 2;
assert len >= 0x7f;
}
// the encoded value includes the base field
--len;
assert len > 0;
int base = reader.get();
byte[] bitstream = reader.get(len);
BitReader br = new BitReader(bitstream);
// This reads the bit stream and adds all the points found,
readBitStream(br, div, line, false, len, base);
if (hasLabel) {
int labelOffset = reader.getu3();
Label label;
if ((labelOffset & 0x800000) == 0) {
label = lblFile.fetchLabel(labelOffset & 0x7fffff);
} else {
int netoff = labelOffset & 0x3fffff;
labelOffset = netFile.getLabelOffset(netoff);
label = lblFile.fetchLabel(labelOffset);
RoadDef roadDef = new RoadDef(0, netoff, label.getText());
line.setRoadDef(roadDef);
}
line.setLabel(label);
}
if (hasExtraBytes) {
extractExtraBytes(reader, line);
}
}
use of uk.me.parabola.imgfmt.app.BitReader in project mkgmap by openstreetmap.
the class NumberPreparerTest method testKnownStream.
/**
* Just test that the test infrastructure is working with a known byte stream, this
* is testing the tests.
*/
@Test
public void testKnownStream() {
byte[] buf = { 0x41, 0x13, 0x27, 0x49, 0x60 };
BitReader br = new BitReader(buf);
NumberReader nr = new NumberReader(br);
nr.setNumberOfNodes(1);
List<Numbers> numbers = nr.readNumbers(true);
assertEquals(1, numbers.size());
assertEquals("0,E,24,8,O,23,13", numbers.get(0).toString());
}
use of uk.me.parabola.imgfmt.app.BitReader in project mkgmap by openstreetmap.
the class NumberPreparerTest method writeAndRead.
private List<Numbers> writeAndRead(List<Numbers> numbers) {
NumberPreparer preparer = new NumberPreparer(numbers);
BitWriter bw = preparer.fetchBitStream();
bytesUsed += bw.getLength();
assertTrue("check valid flag", preparer.isValid());
boolean swapped = preparer.getSwapped();
// Now read it all back in again
byte[] b1 = bw.getBytes();
byte[] bytes = new byte[bw.getLength()];
System.arraycopy(b1, 0, bytes, 0, bw.getLength());
BitReader br = new BitReader(bytes);
NumberReader nr = new NumberReader(br);
nr.setNumberOfNodes(numbers.get(numbers.size() - 1).getIndex() + 1);
List<Numbers> list = nr.readNumbers(swapped);
for (Numbers n : list) n.setNodeNumber(n.getIndex());
return list;
}
use of uk.me.parabola.imgfmt.app.BitReader in project mkgmap by openstreetmap.
the class NumberRangeTest method run.
private void run(String[] strings) {
List<Numbers> numbers = new ArrayList<Numbers>();
for (String s : strings) {
Numbers n = new Numbers(s);
n.setIndex(n.getNodeNumber());
numbers.add(n);
}
NumberPreparer np = new NumberPreparer(numbers);
BitWriter bitWriter = np.fetchBitStream();
bytesUsed += bitWriter.getLength();
// Now read it back in
byte[] bytes = new byte[bitWriter.getLength()];
System.arraycopy(bitWriter.getBytes(), 0, bytes, 0, bytes.length);
NumberReader nr = new NumberReader(new BitReader(bytes));
nr.setNumberOfNodes(numbers.get(numbers.size() - 1).getIndex() + 1);
List<Numbers> list = nr.readNumbers(np.getSwapped());
// Have to fix up the node numbers
for (Numbers n : list) {
n.setNodeNumber(n.getIndex());
}
// Test that they are the same.
String orig = numbers.toString();
String calculated = list.toString();
if (!orig.equals(calculated)) {
System.out.printf("Fail: expecting: %s\n Got: %s\n", orig, calculated);
}
}
use of uk.me.parabola.imgfmt.app.BitReader in project mkgmap by openstreetmap.
the class RGNFileReader method readLineCommon.
/**
* Since polygons are pretty much like polylines in the img format the
* reading code can be shared.
*
* @param reader The reader for the img file.
* @param div The subdivision.
* @param line The line or shape that is to be populated.
*/
private void readLineCommon(ImgFileReader reader, Subdivision div, Polyline line) {
byte type = reader.get();
if (line instanceof Polygon)
line.setType(type & 0x7f);
else {
line.setType(type & 0x3f);
line.setDirection((type & 0x40) != 0);
}
int labelOffset = reader.getu3();
// Extra bit (for bit stream)
boolean extra = (labelOffset & 0x400000) != 0;
Label label;
if ((labelOffset & 0x800000) == 0) {
label = lblFile.fetchLabel(labelOffset & 0x7fffff);
} else {
int netoff = labelOffset & 0x3fffff;
labelOffset = netFile.getLabelOffset(netoff);
label = lblFile.fetchLabel(labelOffset);
RoadDef roadDef = new RoadDef(0, netoff, label.getText());
line.setRoadDef(roadDef);
}
line.setLabel(label);
line.setDeltaLong((short) reader.getChar());
line.setDeltaLat((short) reader.getChar());
int len;
if ((type & 0x80) == 0)
len = reader.get() & 0xff;
else
len = reader.getChar();
int base = reader.get();
byte[] bitstream = reader.get(len);
BitReader br = new BitReader(bitstream);
// This reads the bit stream and adds all the points found
readBitStream(br, div, line, extra, len, base);
}
Aggregations