use of uk.me.parabola.imgfmt.app.ImgFileReader in project mkgmap by openstreetmap.
the class LBLFileReader method readLables.
/**
* Read and cache all the labels.
*
* Note: It is pretty pointless saving the whole label rather than just
* the text, except that other objects take a Label. Perhaps this can
* be changed.
*/
private void readLables(int mult) {
ImgFileReader reader = getReader();
labels.put(0, NULL_LABEL);
int start = header.getLabelStart();
int size = header.getLabelSize();
reader.position(start + mult);
int labelOffset = mult;
for (int off = mult; off <= size; off++) {
byte b = reader.get();
if (textDecoder.addByte(b)) {
labelOffset = saveLabel(labelOffset, off, mult);
// ensure that the labels are on suitable boundaries. We must skip over any such padding.
while ((labelOffset & (mult - 1)) != 0) {
textDecoder.reset();
if (labelOffset <= off) {
// In the 6bit decoder, we may have already read the (first) padding byte and so
// we increment the label offset without reading anything more.
labelOffset++;
} else {
reader.get();
// noinspection AssignmentToForLoopParameter
off++;
labelOffset++;
}
}
}
}
}
use of uk.me.parabola.imgfmt.app.ImgFileReader in project mkgmap by openstreetmap.
the class LBLFileReader method readCities.
/**
* Read in the city section and cache the results here. They are needed
* to read in the POI properties section.
*/
private void readCities() {
PlacesHeader placeHeader = header.getPlaceHeader();
int start = placeHeader.getCitiesStart();
int end = placeHeader.getCitiesEnd();
ImgFileReader reader = getReader();
// Since cities are indexed starting from 1, we add a null one at index 0
reader.position(start);
int index = 1;
while (reader.position() < end) {
// First is either a label offset or a point/subdiv combo, we
// don't know until we have read further
int label = reader.getu3();
int info = reader.getChar();
City city;
if ((info & 0x4000) == 0) {
Region region = regions.get(info & 0x3fff);
city = new City(region);
} else {
Country country = countries.get(info & 0x3fff);
city = new City(country);
}
city.setIndex(index);
if ((info & 0x8000) == 0) {
city.setSubdivision(Subdivision.createEmptySubdivision(1));
Label label1 = labels.get(label & 0x3fffff);
city.setLabel(label1);
} else {
// Has subdiv/point index
int pointIndex = label & 0xff;
int subdiv = (label >> 8) & 0xffff;
city.setPointIndex((byte) pointIndex);
city.setSubdivision(Subdivision.createEmptySubdivision(subdiv));
}
cities.add(city);
index++;
}
}
use of uk.me.parabola.imgfmt.app.ImgFileReader in project mkgmap by openstreetmap.
the class LBLFileReader method readCountries.
/**
* Read a cache the countries. These are used when reading cities.
*/
private void readCountries() {
ImgFileReader reader = getReader();
PlacesHeader placeHeader = header.getPlaceHeader();
// 1 based indexes
countries.add(null);
int start = placeHeader.getCountriesStart();
int end = placeHeader.getCountriesEnd();
reader.position(start);
int index = 1;
while (reader.position() < end) {
int offset = reader.getu3();
Label label = fetchLabel(offset);
if (label != null) {
Country country = new Country(index);
country.setLabel(label);
countries.add(country);
}
index++;
}
}
use of uk.me.parabola.imgfmt.app.ImgFileReader in project mkgmap by openstreetmap.
the class LBLFileReader method readPoiInfo.
/**
* Read all the POI information.
* This will create a POIRecord, but we just get the name at the minute.
*
* TODO: not finished
*/
private void readPoiInfo() {
ImgFileReader reader = getReader();
PlacesHeader placeHeader = header.getPlaceHeader();
int poiGlobalFlags = placeHeader.getPOIGlobalFlags();
int start = placeHeader.getPoiPropertiesStart();
int end = placeHeader.getPoiPropertiesEnd();
reader.position(start);
PoiMasks localMask = makeLocalMask(placeHeader);
while (reader.position() < end) {
int poiOffset = position() - start;
int val = reader.getu3();
int labelOffset = val & 0x3fffff;
boolean override = (val & 0x800000) != 0;
POIRecord poi = new POIRecord();
poi.setLabel(fetchLabel(labelOffset));
// We have what we want, but now have to find the start of the
// next record as they are not fixed length.
int flags;
boolean hasStreet;
boolean hasStreetNum;
boolean hasCity;
boolean hasZip;
boolean hasPhone;
boolean hasHighwayExit;
boolean hasTides;
if (override) {
flags = reader.get();
hasStreetNum = (flags & localMask.streetNumMask) != 0;
hasStreet = (flags & localMask.streetMask) != 0;
hasCity = (flags & localMask.cityMask) != 0;
hasZip = (flags & localMask.zipMask) != 0;
hasPhone = (flags & localMask.phoneMask) != 0;
hasHighwayExit = (flags & localMask.highwayExitMask) != 0;
hasTides = (flags & localMask.tidesMask) != 0;
} else {
flags = poiGlobalFlags;
hasStreetNum = (flags & POIRecord.HAS_STREET_NUM) != 0;
hasStreet = (flags & POIRecord.HAS_STREET) != 0;
hasCity = (flags & POIRecord.HAS_CITY) != 0;
hasZip = (flags & POIRecord.HAS_ZIP) != 0;
hasPhone = (flags & POIRecord.HAS_PHONE) != 0;
hasHighwayExit = (flags & POIRecord.HAS_EXIT) != 0;
hasTides = (flags & POIRecord.HAS_TIDE_PREDICTION) != 0;
}
if (hasStreetNum) {
byte b = reader.get();
if ((b & 0x80) == 0) {
int mpoffset = (b << 16) & 0xff0000;
mpoffset |= reader.getChar() & 0xffff;
poi.setComplexStreetNumber(fetchLabel(mpoffset));
} else {
poi.setSimpleStreetNumber(reader.getBase11str(b, '-'));
}
}
if (hasStreet) {
// label for street
int streetNameOffset = reader.getu3();
Label label = fetchLabel(streetNameOffset);
poi.setStreetName(label);
}
if (hasCity) {
int cityIndex = reader.getUint(Utils.numberToPointerSize(placeHeader.getNumCities()));
poi.setCity(cities.get(cityIndex - 1));
}
if (hasZip) {
int zipIndex = reader.getUint(Utils.numberToPointerSize(placeHeader.getNumZips()));
poi.setZip(zips.get(zipIndex - 1));
}
if (hasPhone) {
byte b = reader.get();
if ((b & 0x80) == 0) {
// Yes this is a bit strange it is a byte followed by a char
int mpoffset = (b << 16) & 0xff0000;
mpoffset |= reader.getChar() & 0xffff;
poi.setComplexPhoneNumber(fetchLabel(mpoffset));
} else {
poi.setSimplePhoneNumber(reader.getBase11str(b, '-'));
}
}
if (hasHighwayExit) {
int lblinfo = reader.getu3();
int highwayLabelOffset = lblinfo & 0x3FFFF;
boolean indexed = (lblinfo & 0x800000) != 0;
boolean overnightParking = (lblinfo & 0x400000) != 0;
int highwayIndex = reader.getUint(Utils.numberToPointerSize(placeHeader.getNumHighways()));
if (indexed) {
int eidx = reader.getUint(Utils.numberToPointerSize(placeHeader.getNumExits()));
}
}
if (hasTides) {
System.out.println("Map has tide prediction, please implement!");
}
pois.put(poiOffset, poi);
}
}
use of uk.me.parabola.imgfmt.app.ImgFileReader in project mkgmap by openstreetmap.
the class LBLFileReader method readRegions.
/**
* Read an cache the regions. These are used when reading cities.
*/
private void readRegions() {
ImgFileReader reader = getReader();
PlacesHeader placeHeader = header.getPlaceHeader();
int start = placeHeader.getRegionsStart();
int end = placeHeader.getRegionsEnd();
regions.add(null);
reader.position(start);
int index = 1;
while (reader.position() < end) {
int country = reader.getChar();
int offset = reader.getu3();
Label label = fetchLabel(offset);
if (label != null) {
Region region = new Region(countries.get(country));
region.setIndex(index);
region.setLabel(label);
regions.add(region);
}
index++;
}
}
Aggregations