use of uk.me.parabola.imgfmt.app.typ.ColourInfo in project mkgmap by openstreetmap.
the class CommonSection method readXpm.
/**
* Read an XMP image from the input scanner.
*
* Note that this is sometimes used just for colours so need to deal with
* different cases.
*/
protected Xpm readXpm(TokenScanner scanner, String header, boolean simple) {
ColourInfo colourInfo = readColourInfo(scanner, header);
String msg = colourInfo.analyseColours(simple);
if (msg != null)
throw new SyntaxException(scanner, msg);
Xpm xpm = new Xpm();
xpm.setColourInfo(colourInfo);
int height = colourInfo.getHeight();
int width = colourInfo.getWidth();
if (height > 0 && width > 0) {
colourInfo.setHasBitmap(true);
Image image;
if (colourInfo.getNumberOfColours() == 0)
image = readTrueImage(scanner, colourInfo);
else
image = readImage(scanner, colourInfo);
xpm.setImage(image);
}
hasXpm = true;
return xpm;
}
use of uk.me.parabola.imgfmt.app.typ.ColourInfo in project mkgmap by openstreetmap.
the class CommonSection method readColourInfo.
/**
* Read the colour lines from the XPM format image.
*/
protected ColourInfo readColourInfo(TokenScanner scanner, String header) {
ColourInfo colourInfo = new ColourInfo();
parseXpmHeader(scanner, colourInfo, header);
for (int i = 0; i < colourInfo.getNumberOfColours(); i++) {
scanner.validateNext("\"");
int cpp = colourInfo.getCharsPerPixel();
Token token = scanner.nextRawToken();
String colourTag = token.getValue();
while (colourTag.length() < cpp) colourTag += scanner.nextRawToken().getValue();
colourTag = colourTag.substring(0, cpp);
scanner.validateNext("c");
String colour = scanner.nextValue();
if (colour.charAt(0) == '#') {
colour = scanner.nextValue();
colourInfo.addColour(colourTag, new Rgb(colour));
} else if (colour.equalsIgnoreCase("none")) {
colourInfo.addTransparent(colourTag);
} else {
throw new SyntaxException(scanner, "Unrecognised colour: " + colour);
}
scanner.validateNext("\"");
readExtraColourInfo(scanner, colourInfo);
}
return colourInfo;
}
Aggregations