Search in sources :

Example 16 with ImgFileReader

use of uk.me.parabola.imgfmt.app.ImgFileReader in project mkgmap by openstreetmap.

the class NETFileReader method readOffsets.

/**
 * NET 3 contains a list of all the NET 1 record start positions.  They
 * are in alphabetical order of name.  So read them in and sort into
 * memory address order.
 * @return A list of start offsets in NET 1, sorted by increasing offset.
 */
private List<Integer> readOffsets() {
    int start = netHeader.getSortedRoadsStart();
    int end = netHeader.getSortedRoadsEnd();
    ImgFileReader reader = getReader();
    reader.position(start);
    Set<Integer> allOffsets = new HashSet<>();
    while (reader.position() < end) {
        int net1 = reader.getu3();
        // The offset is stored in the bottom 22 bits. The top 2 bits are an index into the list
        // of lbl pointers in the net1 entry.
        allOffsets.add((net1 & 0x3fffff) << netHeader.getRoadShift());
    }
    // Sort in address order in the hope of speeding up reading.
    List<Integer> offsets = new ArrayList<>(allOffsets);
    allOffsets = null;
    Collections.sort(offsets);
    return offsets;
}
Also used : ArrayList(java.util.ArrayList) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) ImgFileReader(uk.me.parabola.imgfmt.app.ImgFileReader) BufferedImgFileReader(uk.me.parabola.imgfmt.app.BufferedImgFileReader) HashSet(java.util.HashSet)

Example 17 with ImgFileReader

use of uk.me.parabola.imgfmt.app.ImgFileReader in project mkgmap by openstreetmap.

the class RGNFileReader method fetchPointsCommon.

/**
 * The indexed points and the points sections are both read just the same.
 */
private void fetchPointsCommon(Subdivision sd, long start, long end, List<Point> points) {
    position(start);
    ImgFileReader reader = getReader();
    int number = points.size() + 1;
    while (position() < end) {
        Point p = new Point(sd);
        byte t = reader.get();
        int val = reader.getu3();
        boolean hasSubtype = false;
        if ((val & 0x800000) != 0)
            hasSubtype = true;
        boolean hasPoi = false;
        if ((val & 0x400000) != 0)
            hasPoi = true;
        Label l;
        int labelOffset = val & 0x3fffff;
        if (hasPoi) {
            POIRecord record = lblFile.fetchPoi(labelOffset);
            if (record != null) {
                l = record.getNameLabel();
                p.setPOIRecord(record);
            } else
                l = lblFile.fetchLabel(0);
        } else {
            l = lblFile.fetchLabel(labelOffset);
        }
        p.setLabel(l);
        p.setDeltaLong((short) reader.getChar());
        p.setDeltaLat((short) reader.getChar());
        if (hasSubtype) {
            byte st = reader.get();
            p.setType(((t & 0xff) << 8) | (st & 0xff));
        // p.setHasSubtype(true);
        } else {
            p.setType(t & 0xff);
        }
        p.setNumber(number++);
        points.add(p);
    }
}
Also used : Label(uk.me.parabola.imgfmt.app.Label) POIRecord(uk.me.parabola.imgfmt.app.lbl.POIRecord) ImgFileReader(uk.me.parabola.imgfmt.app.ImgFileReader) BufferedImgFileReader(uk.me.parabola.imgfmt.app.BufferedImgFileReader)

Example 18 with ImgFileReader

use of uk.me.parabola.imgfmt.app.ImgFileReader in project mkgmap by openstreetmap.

the class TREFileReader method readExtTypeOffsetsRecords.

/**
 * Read the extended type info for the sub divisions. Corresponds to {@link TREFile#writeExtTypeOffsetsRecords()}.
 */
private void readExtTypeOffsetsRecords() {
    ImgFileReader reader = getReader();
    int start = header.getExtTypeOffsetsPos();
    int end = start + header.getExtTypeOffsetsSize();
    reader.position(start);
    Subdivision sd = null;
    Subdivision sdPrev = null;
    for (int count = 0; count < levelDivs.length && reader.position() < end; count++) {
        Subdivision[] divs = levelDivs[count];
        if (divs == null)
            break;
        for (int i = 0; i < divs.length; i++) {
            sdPrev = sd;
            sd = divs[i];
            sd.readExtTypeOffsetsRecord(reader, sdPrev, header.getExtTypeSectionSize());
        }
    }
    if (sd != null && reader.position() < end) {
        sd.readLastExtTypeOffsetsRecord(reader, header.getExtTypeSectionSize());
    }
}
Also used : ImgFileReader(uk.me.parabola.imgfmt.app.ImgFileReader) BufferedImgFileReader(uk.me.parabola.imgfmt.app.BufferedImgFileReader)

Example 19 with ImgFileReader

use of uk.me.parabola.imgfmt.app.ImgFileReader in project mkgmap by openstreetmap.

the class TREFileReader method readMapLevels.

/**
 * Read the map levels.  This is needed to make sense of the subdivision
 * data.  Unlike in the write case, we just keep an array of zoom levels
 * as found, there is no correspondence between the array index and level.
 */
private void readMapLevels() {
    ImgFileReader reader = getReader();
    int levelsPos = header.getMapLevelsPos();
    int levelsSize = header.getMapLevelsSize();
    reader.position(levelsPos);
    List<Subdivision[]> levelDivs = new ArrayList<Subdivision[]>();
    List<Zoom> mapLevels = new ArrayList<Zoom>();
    int end = levelsPos + levelsSize;
    while (reader.position() < end) {
        int level = reader.get();
        int nbits = reader.get();
        int ndivs = reader.getChar();
        Subdivision[] divs = new Subdivision[ndivs];
        levelDivs.add(divs);
        level &= 0x7f;
        Zoom z = new Zoom(level, nbits);
        mapLevels.add(z);
    }
    this.levelDivs = levelDivs.toArray(new Subdivision[levelDivs.size()][]);
    this.mapLevels = mapLevels.toArray(new Zoom[mapLevels.size()]);
}
Also used : ArrayList(java.util.ArrayList) ImgFileReader(uk.me.parabola.imgfmt.app.ImgFileReader) BufferedImgFileReader(uk.me.parabola.imgfmt.app.BufferedImgFileReader)

Example 20 with ImgFileReader

use of uk.me.parabola.imgfmt.app.ImgFileReader in project mkgmap by openstreetmap.

the class SrtFileReader method readCharPosition.

/**
 * Read the sort position information.  The format varies depending on the posLength parameter.
 *
 * @param posLength The length of the position information (not the record length, just the
 * part of it that encodes the positions).
 */
private CodePosition readCharPosition(int posLength) {
    ImgFileReader reader = getReader();
    CodePosition cp = new CodePosition();
    int rec;
    if (posLength == 2) {
        rec = reader.getChar();
        cp.setPrimary((char) (rec & 0xff));
        cp.setSecondary((byte) ((rec >> 8) & 0xf));
        cp.setTertiary((byte) ((rec >> 12) & 0xf));
    } else if (posLength == 3) {
        rec = reader.get3();
        cp.setPrimary((char) (rec & 0xff));
        cp.setSecondary((byte) ((rec >> 8) & 0xf));
        cp.setTertiary((byte) ((rec >> 12) & 0xf));
    } else if (posLength == 4) {
        rec = reader.getInt();
        cp.setPrimary((char) (rec & 0xffff));
        cp.setSecondary((byte) ((rec >> 16) & 0xff));
        cp.setTertiary((byte) ((rec >> 24) & 0xff));
    } else {
        throw new RuntimeException("unexpected value posLength " + posLength);
    }
    return cp;
}
Also used : ImgFileReader(uk.me.parabola.imgfmt.app.ImgFileReader) BufferedImgFileReader(uk.me.parabola.imgfmt.app.BufferedImgFileReader)

Aggregations

BufferedImgFileReader (uk.me.parabola.imgfmt.app.BufferedImgFileReader)23 ImgFileReader (uk.me.parabola.imgfmt.app.ImgFileReader)23 Label (uk.me.parabola.imgfmt.app.Label)7 ArrayList (java.util.ArrayList)6 IntArrayList (it.unimi.dsi.fastutil.ints.IntArrayList)2 POIRecord (uk.me.parabola.imgfmt.app.lbl.POIRecord)2 HashSet (java.util.HashSet)1 Section (uk.me.parabola.imgfmt.app.Section)1 CharacterDecoder (uk.me.parabola.imgfmt.app.labelenc.CharacterDecoder)1 CodeFunctions (uk.me.parabola.imgfmt.app.labelenc.CodeFunctions)1 DecodedText (uk.me.parabola.imgfmt.app.labelenc.DecodedText)1