| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package uk.me.parabola.imgfmt.app.typ; |
| 18 |
|
| 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 |
import uk.me.parabola.imgfmt.app.Section; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
g |
| 28 |
|
| 29 |
public class TYPHeader extends CommonHeader { |
| 30 |
public static final int HEADER_LEN = 0x9c; |
| 31 |
|
| 32 |
private char familyId; |
| 33 |
private char productId; |
| 34 |
private char codePage; |
| 35 |
|
| 36 |
private final Section pointData = new Section(); |
| 37 |
private final Section lineData = new Section(pointData); |
| 38 |
private final Section polygonData = new Section(lineData); |
| 39 |
|
| 40 |
private final Section pointIndex = new Section(polygonData, 2); |
| 41 |
private final Section lineIndex = new Section(pointIndex, 2); |
| 42 |
private final Section polygonIndex = new Section(lineIndex, 2); |
| 43 |
|
| 44 |
private final Section shapeStacking = new Section(polygonIndex, 5); |
| 45 |
|
| 46 |
private final Section iconData = new Section(polygonIndex); |
| 47 |
private final Section iconIndex = new Section(iconData, 3); |
| 48 |
|
| 49 |
private final Section labels = new Section(iconIndex); |
| 50 |
private final Section stringIndex = new Section(labels); |
| 51 |
private final Section typeIndex = new Section(stringIndex); |
| 52 |
|
| 53 |
public TYPHeader() { |
| 54 |
super(HEADER_LEN, "GARMIN TYP"); |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
protected void readFileHeader(ImgFileReader reader) { |
| 65 |
|
| 66 |
reader.position(COMMON_HEADER_LEN); |
| 67 |
codePage = (char) reader.get2u(); |
| 68 |
pointData.setPosition(reader.get4()); |
| 69 |
pointData.setSize(reader.get4()); |
| 70 |
|
| 71 |
lineData.setPosition(reader.get4()); |
| 72 |
lineData.setSize(reader.get4()); |
| 73 |
|
| 74 |
polygonData.setPosition(reader.get4()); |
| 75 |
polygonData.setSize(reader.get4()); |
| 76 |
|
| 77 |
familyId = (char) reader.get2u(); |
| 78 |
productId = (char) reader.get2u(); |
| 79 |
|
| 80 |
pointIndex.setPosition(reader.get4()); |
| 81 |
pointIndex.setItemSize(reader.get2u()); |
| 82 |
pointIndex.setSize(reader.get4()); |
| 83 |
|
| 84 |
lineIndex.setPosition(reader.get4()); |
| 85 |
lineIndex.setItemSize(reader.get2u()); |
| 86 |
lineIndex.setSize(reader.get4()); |
| 87 |
|
| 88 |
polygonIndex.setPosition(reader.get4()); |
| 89 |
polygonIndex.setItemSize(reader.get2u()); |
| 90 |
polygonIndex.setSize(reader.get4()); |
| 91 |
|
| 92 |
shapeStacking.setPosition(reader.get4()); |
| 93 |
shapeStacking.setItemSize(reader.get2u()); |
| 94 |
shapeStacking.setSize(reader.get4()); |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
protected void writeFileHeader(ImgFileWriter writer) { |
| 106 |
writer.put2u(codePage); |
| 107 |
|
| 108 |
pointData.writeSectionInfo(writer); |
| 109 |
lineData.writeSectionInfo(writer); |
| 110 |
polygonData.writeSectionInfo(writer); |
| 111 |
|
| 112 |
writer.put2u(familyId); |
| 113 |
writer.put2u(productId); |
| 114 |
|
| 115 |
|
| 116 |
writeSectionInfo(writer, pointIndex); |
| 117 |
writeSectionInfo(writer, lineIndex); |
| 118 |
writeSectionInfo(writer, polygonIndex); |
| 119 |
writeSectionInfo(writer, shapeStacking); |
| 120 |
|
| 121 |
if (getHeaderLength() > 0x5b) { |
| 122 |
writeSectionInfo(writer, iconIndex); |
| 123 |
writer.put1u(0x13); |
| 124 |
iconData.writeSectionInfo(writer); |
| 125 |
writer.put4(0); |
| 126 |
} |
| 127 |
|
| 128 |
if (getHeaderLength() > 0x6e) { |
| 129 |
labels.writeSectionInfo(writer); |
| 130 |
|
| 131 |
|
| 132 |
writer.put4(stringIndex.getItemSize()); |
| 133 |
writer.put4(0x1b); |
| 134 |
writer.put4(stringIndex.getPosition()); |
| 135 |
writer.put4(stringIndex.getSize()); |
| 136 |
|
| 137 |
writer.put4(typeIndex.getItemSize()); |
| 138 |
writer.put4(0x1b); |
| 139 |
writer.put4(typeIndex.getPosition()); |
| 140 |
writer.put4(typeIndex.getSize()); |
| 141 |
|
| 142 |
writer.put2u(0); |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
private void writeSectionInfo(ImgFileWriter writer, Section section) { |
| 151 |
writer.put4(section.getPosition()); |
| 152 |
writer.put2u(section.getItemSize()); |
| 153 |
writer.put4(section.getSize()); |
| 154 |
} |
| 155 |
|
| 156 |
void setCodePage(char codePage) { |
| 157 |
this.codePage = codePage; |
| 158 |
} |
| 159 |
|
| 160 |
Section getPointData() { |
| 161 |
return pointData; |
| 162 |
} |
| 163 |
|
| 164 |
void setFamilyId(char familyId) { |
| 165 |
this.familyId = familyId; |
| 166 |
} |
| 167 |
|
| 168 |
void setProductId(char productId) { |
| 169 |
this.productId = productId; |
| 170 |
} |
| 171 |
|
| 172 |
Section getPointIndex() { |
| 173 |
return pointIndex; |
| 174 |
} |
| 175 |
|
| 176 |
Section getShapeStacking() { |
| 177 |
return shapeStacking; |
| 178 |
} |
| 179 |
|
| 180 |
public Section getPolygonData() { |
| 181 |
return polygonData; |
| 182 |
} |
| 183 |
|
| 184 |
public Section getPolygonIndex() { |
| 185 |
return polygonIndex; |
| 186 |
} |
| 187 |
|
| 188 |
public Section getLineData() { |
| 189 |
return lineData; |
| 190 |
} |
| 191 |
|
| 192 |
public Section getLineIndex() { |
| 193 |
return lineIndex; |
| 194 |
} |
| 195 |
|
| 196 |
public Section getIconData() { |
| 197 |
return iconData; |
| 198 |
} |
| 199 |
|
| 200 |
public Section getIconIndex() { |
| 201 |
return iconIndex; |
| 202 |
} |
| 203 |
|
| 204 |
public Section getLabels() { |
| 205 |
return labels; |
| 206 |
} |
| 207 |
|
| 208 |
public Section getStringIndex() { |
| 209 |
return stringIndex; |
| 210 |
} |
| 211 |
|
| 212 |
public Section getTypeIndex() { |
| 213 |
return typeIndex; |
| 214 |
} |
| 215 |
} |