| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package uk.me.parabola.imgfmt.app.lbl; |
| 18 |
|
| 19 |
import java.nio.charset.StandardCharsets; |
| 20 |
|
| 21 |
import uk.me.parabola.imgfmt.app.CommonHeader; |
| 22 |
import uk.me.parabola.imgfmt.app.ImgFileReader; |
| 23 |
import uk.me.parabola.imgfmt.app.ImgFileWriter; |
| 24 |
import uk.me.parabola.imgfmt.app.labelenc.CodeFunctions; |
| 25 |
import uk.me.parabola.imgfmt.app.srt.Sort; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
public class LBLHeader extends CommonHeader { |
| 33 |
public static final int HEADER_LEN = 196; |
| 34 |
|
| 35 |
private static final char UNK3_REC_LEN = 0; |
| 36 |
|
| 37 |
private int labelStart; |
| 38 |
private int labelSize; |
| 39 |
|
| 40 |
private int offsetMultiplier; |
| 41 |
|
| 42 |
|
| 43 |
private Sort sort; |
| 44 |
|
| 45 |
private int sortDescriptionLength; |
| 46 |
|
| 47 |
|
| 48 |
private int encodingType = CodeFunctions.ENCODING_FORMAT6; |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
private final PlacesHeader placeHeader; |
| 53 |
|
| 54 |
public LBLHeader() { |
| 55 |
super(HEADER_LEN, "GARMIN LBL"); |
| 56 |
placeHeader = new PlacesHeader(); |
| 57 |
} |
| 58 |
|
| 59 |
public int getSortDescriptionLength() { |
| 60 |
return sortDescriptionLength; |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
protected void readFileHeader(ImgFileReader reader) { |
| 71 |
labelStart = reader.get4(); |
| 72 |
labelSize = reader.get4(); |
| 73 |
offsetMultiplier = 1 << reader.get(); |
| 74 |
encodingType = reader.get(); |
| 75 |
|
| 76 |
|
| 77 |
placeHeader.readFileHeader(reader); |
| 78 |
|
| 79 |
int codepage = reader.get2u(); |
| 80 |
int id1 = reader.get2u(); |
| 81 |
int id2 = reader.get2u(); |
| 82 |
int descOff = reader.get4(); |
| 83 |
int descLen = reader.get4(); |
| 84 |
|
| 85 |
reader.position(descOff); |
| 86 |
byte[] bytes = reader.get(descLen); |
| 87 |
String description; |
| 88 |
description = new String(bytes, StandardCharsets.US_ASCII); |
| 89 |
|
| 90 |
sort = new Sort(); |
| 91 |
sort.setCodepage(codepage); |
| 92 |
sort.setId1(id1); |
| 93 |
sort.setId2(id2); |
| 94 |
sort.setDescription(description); |
| 95 |
|
| 96 |
|
| 97 |
reader.position(labelStart); |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
protected void writeFileHeader(ImgFileWriter writer) { |
| 107 |
|
| 108 |
writer.put4(HEADER_LEN + sortDescriptionLength); |
| 109 |
writer.put4(getLabelSize()); |
| 110 |
|
| 111 |
writer.put1u(offsetMultiplier); |
| 112 |
writer.put1u(encodingType); |
| 113 |
|
| 114 |
placeHeader.writeFileHeader(writer); |
| 115 |
|
| 116 |
writer.put2u(getCodePage()); |
| 117 |
|
| 118 |
|
| 119 |
int id1 = sort.getId1(); |
| 120 |
writer.put2u(id1); |
| 121 |
|
| 122 |
int id2 = sort.getId2(); |
| 123 |
if (id1 != 0 && id2 != 0) |
| 124 |
id2 |= 0x8000; |
| 125 |
writer.put2u(id2); |
| 126 |
|
| 127 |
writer.put4(HEADER_LEN); |
| 128 |
writer.put4(sortDescriptionLength); |
| 129 |
|
| 130 |
writer.put4(placeHeader.getLastPos()); |
| 131 |
writer.put4(0); |
| 132 |
writer.put2u(UNK3_REC_LEN); |
| 133 |
writer.put2u(0); |
| 134 |
} |
| 135 |
|
| 136 |
protected int getEncodingType() { |
| 137 |
return encodingType; |
| 138 |
} |
| 139 |
|
| 140 |
public void setEncodingType(int type) { |
| 141 |
this.encodingType = type; |
| 142 |
} |
| 143 |
|
| 144 |
protected int getLabelSize() { |
| 145 |
return labelSize; |
| 146 |
} |
| 147 |
|
| 148 |
public void setLabelSize(int labelSize) { |
| 149 |
this.labelSize = labelSize; |
| 150 |
placeHeader.setLabelEnd(HEADER_LEN + sortDescriptionLength + labelSize); |
| 151 |
} |
| 152 |
|
| 153 |
protected int getCodePage() { |
| 154 |
return sort.getCodepage(); |
| 155 |
} |
| 156 |
|
| 157 |
public void setSort(Sort sort) { |
| 158 |
sortDescriptionLength = sort.getDescription().length() + 1; |
| 159 |
this.sort = sort; |
| 160 |
} |
| 161 |
|
| 162 |
public int getSortOrderId() { |
| 163 |
return sort.getSortOrderId(); |
| 164 |
} |
| 165 |
|
| 166 |
public int getLabelStart() { |
| 167 |
return labelStart; |
| 168 |
} |
| 169 |
|
| 170 |
public int getOffsetMultiplier() { |
| 171 |
return offsetMultiplier; |
| 172 |
} |
| 173 |
|
| 174 |
public PlacesHeader getPlaceHeader() { |
| 175 |
return placeHeader; |
| 176 |
} |
| 177 |
|
| 178 |
public void setOffsetMultiplier(int offsetMultiplier) { |
| 179 |
this.offsetMultiplier = offsetMultiplier; |
| 180 |
} |
| 181 |
} |