Debian Codegraph @

src/uk/me/parabola/imgfmt/app/dem/DEMHeader.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2017.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 or
6 * version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 */
13 package uk.me.parabola.imgfmt.app.dem;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import uk.me.parabola.imgfmt.ReadFailedException;
19 import uk.me.parabola.imgfmt.app.CommonHeader;
20 import uk.me.parabola.imgfmt.app.ImgFileReader;
21 import uk.me.parabola.imgfmt.app.ImgFileWriter;
22
23 /**
24 * The header of the DEM file.
25 *
26 * @author Gerd Petermann
27 */
28 public class DEMHeader extends CommonHeader {
29 public static final int HEADER_LEN = 41; // Other lengths are possible
30
31 private final List<DEMSection> zoomLevels = new ArrayList<>();
32
33 private int offset;
34
35 public DEMHeader() {
36 super(HEADER_LEN, "GARMIN DEM");
37 }
38
39
40 /**
41 * Write the rest of the header. It is guaranteed that the writer will be set
42 * to the correct position before calling.
43 *
44 * @param writer The header is written here.
45 */
46 protected void writeFileHeader(ImgFileWriter writer) {
47 int pos = writer.position();
48 writer.position(HEADER_LEN);
49 for (int i = 0; i < zoomLevels.size(); i++) {
50 zoomLevels.get(i).writeRest(writer);
51 }
52 offset = writer.position();
53 for (int i = 0; i < zoomLevels.size(); i++) {
54 zoomLevels.get(i).writeHeader(writer);
55 }
56 writer.position(pos);
57
58 writer.put4(0); // 0: elevation in metres, 1: foot
59 writer.put2u(zoomLevels.size());
60 writer.put4(0); // unknown
61 writer.put2u(60); // size of zoom level record
62 writer.put4(offset); // offset to first DemSection header (they appear at the end of the file!)
63 writer.put4(1); // unknown, 0 and 1 spotted
64
65 }
66
67 @Override
68 protected void readFileHeader(ImgFileReader reader) throws ReadFailedException {
69 }
70
71
72 public void addSection(DEMSection section) {
73 zoomLevels.add(section);
74 }
75
76 }