Rev 556 |
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 uk.me.parabola.imgfmt.Utils;
/**
* Standalone program to display the TRE file.
*
* @author Steve Ratcliffe
*/
public class TreDisplay
extends CommonDisplay
{
private Section tre7
;
@
Override
protected void print
() {
readCommonHeader
();
readHeader
();
if (tre7
!=
null)
readTre7
();
}
public static void main
(String[] args
) {
if (args.
length < 1) {
System.
err.
println("Usage: tredisplay <filename>");
System.
exit(1);
}
String name = args
[0];
CommonDisplay nd =
new TreDisplay
();
nd.
display(name,
"TRE");
}
void readHeader
() {
// assert reader.position() == 0x15;
int remain = getHeaderLen
() -
(int) reader.
position() + reader.
getGMPOffset();
Displayer d =
new Displayer
(reader
);
d.
setTitle("TRE Header");
int top = d.
int3sValue("north boundary %d");
int right = d.
int3sValue("east boundary %d");
int bottom = d.
int3sValue("south boundary %d");
int left = d.
int3sValue("west boundary %d");
// Deal with case where 180degrees is seen as a negative number.
if (right
< left
&& right == -0x800000
)
right = 0x800000
;
d.
item().
addText("In degrees lat,lon: %.4f,%.4f %.4f,%.4f",
Utils.
toDegrees(bottom
),
Utils.
toDegrees(left
),
Utils.
toDegrees(top
),
Utils.
toDegrees(right
));
remain -=
12;
readSection
(d,
"Map levels",
1,
false,
false);
remain -=
8;
readSection
(d,
"Subdivisions",
2,
false,
false);
remain -=
8;
readSection
(d,
"Copyrights",
3,
true,
false);
remain -=
10;
d.
rawValue(4,
"padding");
d.
byteValue("POI display flags");
d.
int3Value("layer (probably only one byte)");
d.
intValue("???");
d.
charValue("0x0001 ???");
d.
byteValue("zero byte");
remain -=
15;
readSection
(d,
"Polyline defs",
4,
true,
true);
remain -=
14;
readSection
(d,
"Polygon defs",
5,
true,
true);
remain -=
14;
readSection
(d,
"Point defs",
6,
true,
true);
remain -=
14;
if (remain
<=
0) {
if (remain
< 0)
d.
item().
addText("overread by %d bytes", -remain
);
d.
print(outStream
);
return;
}
d.
intValue("Map ID %d");
remain -=
4;
if (remain
<=
0) {
if (remain
< 0)
d.
item().
addText("overread by %d bytes", -remain
);
d.
print(outStream
);
return;
}
d.
intValue("0x00000000 ???");
remain -=
4;
System.
out.
println("remain " + remain
);
System.
out.
println("header len " + getHeaderLen
());
if (getHeaderLen
() > 122) {
tre7 = readSection
(d,
"TRE 7",
7,
true,
true);
remain -=
14;
readSection
(d,
"TRE 8",
8,
false,
false);
d.
intValue("???");
d.
intValue("0x00000000 ???");
remain -=
16;
if (remain
<=
0) {
if (remain
< 0)
d.
item().
addText("overread by %d bytes", -remain
);
d.
print(outStream
);
return;
}
for (int i =
0; i
< 4; i++
) {
d.
intValue("unk " + i +
" %08x");
remain -=
4;
}
d.
intValue("???");
remain -=
4;
readSection
(d,
"TRE 9",
9,
true,
true);
remain -=
14;
}
if (remain
> 0) {
readSection
(d,
"TRE 10",
10,
false,
false);
remain = getHeaderLen
() -
(int) reader.
position() + reader.
getGMPOffset();
}
if (remain
<=
0) {
if (remain
< 0)
d.
item().
addText("overread by %d bytes", -remain
);
d.
print(outStream
);
return;
}
d.
rawValue(remain,
"bytes remaining");
d.
print(outStream
);
}
void readTre7
() {
Displayer d =
new Displayer
(reader
);
d.
setTitle("TRE 7");
reader.
position(tre7.
getStart());
int n = tre7.
getNumberOfRecords();
for (int i =
0; i
< n
; i++
) {
d.
rawValue(tre7.
getRecordSize(),
"record " + i
);
}
d.
print(outStream
);
}
}