Rev 285 |
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 18, 2007
*/
package test.display;
import uk.me.parabola.imgfmt.app.ImgFileReader;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
/**
* For displaying points in a typ file.
*
* @author Steve Ratcliffe
*/
public class PointDisplayer
extends TypSectionDisplayer
{
private final ImgFileReader reader
;
private final PrintStream out
;
private final List<Integer> offsets =
new ArrayList<Integer>();
public PointDisplayer
(ImgFileReader reader,
PrintStream outStream
) {
this.
reader = reader
;
this.
out = outStream
;
}
public void print
() {
printPointDefs
();
}
private void printPointDefs
() {
reader.
position(0x33
); // sect6
int start = reader.
get4();
int itemsize = reader.
get2u();
int size = reader.
get4();
reader.
position(0x17
);
reader.
get4();
printTypes
(start, itemsize, size
);
reader.
position(0x17
);
int stylestart = reader.
get4();
size = reader.
get4();
printStyles
(stylestart, size
);
}
/**
* Some details of the layout of this section were obtained from the referenced documents.
*
* @see <a href="http://ati.land.cz/gps/typdecomp/">ati.land.cz TYP compiler and source code.</a>
* @see <a href="http://pinns.co.uk/osm/typformat.html">TYP format, N Willink</a>
*/
private void printStyles
(int start,
int size
) {
Displayer d =
new Displayer
(reader
);
d.
setTitle("Point styles");
d.
setSectStart(start
);
for (int i =
0; i
< offsets.
size(); i++
) {
int off = start + offsets.
get(i
);
int end = start +
((i
< offsets.
size() -
1) ? offsets.
get(i +
1) : size
);
reader.
position(off
);
int flags = d.
byteValue("Flags %x");
int width = d.
byteValue("Width of bmp %d") & 0xff
;
int height = d.
byteValue("Height of bmp %d") & 0xff
;
printBitmap
(d, width, height
);
if ((flags
& 0x2
) !=
0) {
d.
item().
addText("Has night xmp");
printBitmap
(d, width, height
);
}
if ((flags
& 0x4
) !=
0)
printLabels
(d
);
if ((flags
& 0x8
) !=
0) // Font info
printFontInfo
(d
);
d.
rawValue((int) (end - reader.
position()));
d.
gap();
}
d.
print(out
);
}
private void printTypes
(int start,
int itemsize,
int size
) {
Displayer d =
new Displayer
(reader
);
d.
setTitle("Point types");
int psize = itemsize -
2;
reader.
position(start
);
long end = start+size
;
for (long pos = start
; pos
< end
; pos += itemsize
) {
DisplayItem item = d.
charItem();
int type = item.
getValue();
item.
addText("Type %x/%x", type
>> 5, type
& 0x1f
);
// Get the offset into the line style section.
int off = d.
intValue(psize,
"offset into styles 0x%x");
offsets.
add(off
);
}
d.
print(out
);
}
}