Rev 283 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
/*
* Copyright (C) 2007 Steve Ratcliffe
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* Author: Steve Ratcliffe
* Create date: Dec 16, 2007
*/
package test.display;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Standalone program to display the TYP file as it is worked out.
*
* Some resources about the format of the file.
* <ul>
* <li>http://ati.land.cz/gps/typdecomp/source.cgi
* <li>http://pinns.co.uk/osm/typformat.html</li>
* </ul>
*
* @author Steve Ratcliffe
*/
public class TypDisplay
extends CommonDisplay
{
private Map<Integer,
String> labels =
new HashMap<Integer,
String>();
private List<Integer> e2offsets =
new ArrayList<Integer>();
private Map<Integer,
String> e2Label =
new HashMap<Integer,
String>();
private Map<Integer,
String> poiStringMap =
new HashMap<Integer,
String>();
protected void print
() {
readCommonHeader
();
readFileHeader
();
LineSectDisplayer ld =
new LineSectDisplayer
(reader, outStream
);
ld.
print();
StackingDisplayer sd =
new StackingDisplayer
(reader, outStream
);
sd.
print();
PointDisplayer pd =
new PointDisplayer
(reader, outStream
);
pd.
print();
PolygonDisplayer pgd =
new PolygonDisplayer
(reader, outStream
);
pgd.
print();
int strSize =
0;
if (sections.
size() > 2) {
Section stringSection = sections.
get(2);
strSize = stringSection.
getBytesForSize();
printExtLabel
(stringSection
);
}
if (sections.
size() > 3) printExtLabIndex
(sections.
get(3), strSize
);
if (sections.
size() > 4) printExtPOIIndex
(sections.
get(4), strSize
);
if (sections.
size() > 0) printExtIndex
(sections.
get(0));
if (sections.
size() > 1) printExtPOI
(sections.
get(1));
}
private void readFileHeader
() {
Displayer d =
new Displayer
(reader
);
d.
setTitle("TYP Header");
d.
charValue("codepage: %d");
d.
intValue("Point data start %x");
d.
intValue("Point data size %d");
d.
intValue("Line data start %x");
d.
intValue("Line data size %d");
d.
intValue("Polygon data start %x");
d.
intValue("Polygon data size %d");
d.
charValue("family id %d");
d.
charValue("product id %d");
d.
intValue("Point index start %x");
d.
charValue("Point index item size %d");
d.
intValue("Point index size %d");
d.
intValue("Line types start %x");
d.
charValue("Line types sect item size %d");
d.
intValue("Line types sect size %d");
d.
intValue("Polygon index start %x");
d.
charValue("Polygon index item size %d");
d.
intValue("Polygon index size %d");
d.
intValue("Polygon stack order start %x");
d.
charValue("Polygon stack order item size %d");
d.
intValue("Polygon stack order size %d");
int start
;
int len
;
if (getHeaderLen
() > 0x5b
) {
start = d.
intValue("TYP 8 start %x");
int recSize = d.
charValue("TYP 8 recsize %d");
len = d.
intValue("TYP 8 length %d");
Section section =
new Section
("TYP 8", start, len
);
section.
setRecordSize(recSize
);
sections.
add(section
);
d.
byteValue("?? %d");
start = d.
intValue("TYP 9 start %x");
len = d.
intValue("TYP 9 length %d");
sections.
add(new Section
("TYP 9", start, len
));
}
if (getHeaderLen
() > 0x6e
) {
d.
intValue("?? %x");
start = d.
intValue("TYP 10 start %x");
len = d.
intValue("TYP 10 length %d");
sections.
add(new Section
("TYP 10", start, len
));
d.
intValue("?? %x");
d.
intValue("?? %x");
start = d.
intValue("TYP 11 (string idx) start %x");
len = d.
intValue("TYP 11 length %d");
sections.
add(new Section
("TYP 11", start, len
));
d.
intValue("?? %x");
d.
intValue("?? %x");
start = d.
intValue("TYP 12 (type idx) start %x");
len = d.
intValue("TYP 12 length %d");
sections.
add(new Section
("TYP 12", start, len
));
d.
charValue("?? %x");
}
if (getHeaderLen
() > 0x9c
) {
d.
intValue("TYP 13 start %x");
d.
intValue("TYP 13 len %x");
}
d.
rawValue((int) (getHeaderLen
() - reader.
position()));
d.
print(outStream
);
analyze
(outStream
);
}
private void printExtIndex
(Section s
) {
Displayer d =
new Displayer
(reader
);
d.
setTitle("TYP 8 - index to POIs (E1)");
d.
setSectStart(s.
getStart());
d.
print(outStream
);
d.
setTitle(null);
int recsize = s.
getRecordSize();
reader.
position(s.
getStart());
long start
;
while ((start = reader.
position()) < s.
getEnd()) {
DisplayItem item = d.
int3Item();
int type = item.
getValue();
item.
addText("Type %x/%x:", type
>> 5, type
& 0x1f
);
String lab = poiStringMap.
get(type
);
if (lab
!=
null)
item.
addText("Label: " + lab
);
int off = d.
intValue(recsize -
3,
" offset E2 %x");
e2offsets.
add(off
);
if (lab
!=
null)
e2Label.
put(off, lab
);
int remain =
(int) ((start + recsize
) - reader.
position());
if (remain
> 0)
d.
rawValue(remain
);
d.
print(outStream
);
}
}
private void printExtPOI
(Section s
) {
Displayer d =
new Displayer
(reader
);
d.
setTitle("TYP 9 - POIs");
d.
setSectStart(s.
getStart());
reader.
position(s.
getStart());
d.
print(outStream
);
d.
setTitle(null);
e2offsets.
add((int) s.
getEnd());
reader.
position(s.
getStart());
int totIcons =
0;
for (int i =
0; i
< e2offsets.
size()-
1; i++
) {
int off = e2offsets.
get(i
);
reader.
position(s.
getStart() + off
);
String lab = e2Label.
get(off
);
String fmt
;
if (lab
!=
null)
fmt =
"%d icons for " + lab
;
else
fmt =
"%d icons for this type";
int nIcons = d.
byteValue(fmt
);
totIcons += nIcons
;
for (int n =
0; n
< nIcons
; n++
) {
int nbits = d.
charValue("number of bits/2 %x");
d.
byteValue("b? %d");
int width = d.
byteValue("width %d");
int height = d.
byteValue("height %d");
int bitCheck = TypSectionDisplayer.
printBitmap(d, width, height
);
if (nbits
!= bitCheck
) {
d.
item().
addText("BITS wrong expected %x, calculated %x", nbits, bitCheck
);
d.
gap();
}
}
d.
print(outStream
);
}
d.
item().
addText("Total number of icons %d", totIcons
);
d.
print(outStream
);
}
private void printExtLabel
(Section s
) {
Displayer d =
new Displayer
(reader
);
d.
setTitle("TYP 10 - strings");
long start = s.
getStart();
d.
setSectStart(start
);
reader.
position(start
);
d.
print(outStream
);
d.
setTitle(null);
int count =
0;
while ((reader.
position()) < s.
getEnd()) {
int off =
(int) (reader.
position() - start
);
String lab = d.
zstringValue("Label: %s");
labels.
put(off, lab
);
count++
;
}
d.
item().
addText("There are %d labels (0x%x)", count, count
);
d.
print(outStream
);
}
private void printExtLabIndex
(Section s,
int strSize
) {
Displayer d =
new Displayer
(reader
);
d.
setTitle("TYP 11 - string/number sorted by string offset");
d.
setSectStart(s.
getStart());
reader.
position(s.
getStart());
d.
print(outStream
);
d.
setTitle(null);
while ((reader.
position()) < s.
getEnd()) {
DisplayItem item = d.
intItem(strSize
);
item.
addText("Label: %s", labels.
get(item.
getValue()));
item = d.
int3Item();
int type = item.
getValue();
item.
addText(" Type %x/%x", type
>> 5, type
& 0x1f
);
}
d.
print(outStream
);
}
private void printExtPOIIndex
(Section s,
int strSize
) {
Displayer d =
new Displayer
(reader
);
d.
setTitle("TYP 12 - number/string sorted by number");
d.
setSectStart(s.
getStart());
reader.
position(s.
getStart());
d.
print(outStream
);
d.
setTitle(null);
while ((reader.
position()) < s.
getEnd()) {
DisplayItem item = d.
int3Item();
int type = item.
getValue();
item.
addText("Type %x/%x", type
>> 5, type
& 0x1f
);
item = d.
intItem(strSize
);
String lab = labels.
get(item.
getValue());
item.
addText(" Label: %s", lab
);
if (lab
!=
null)
poiStringMap.
put(type, lab
);
}
d.
print(outStream
);
}
public static void main
(String[] args
) {
if (args.
length < 1) {
System.
err.
println("Usage: typdisplay <filename>");
System.
exit(1);
}
CommonDisplay td =
new TypDisplay
();
td.
display(args
[0],
"TYP");
}
}