Search in sources :

Example 1 with ColourInfo

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;
}
Also used : Xpm(uk.me.parabola.imgfmt.app.typ.Xpm) SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException) BitmapImage(uk.me.parabola.imgfmt.app.typ.BitmapImage) TrueImage(uk.me.parabola.imgfmt.app.typ.TrueImage) Image(uk.me.parabola.imgfmt.app.typ.Image) ColourInfo(uk.me.parabola.imgfmt.app.typ.ColourInfo)

Example 2 with ColourInfo

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;
}
Also used : SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException) Token(uk.me.parabola.mkgmap.scan.Token) Rgb(uk.me.parabola.imgfmt.app.typ.Rgb) ColourInfo(uk.me.parabola.imgfmt.app.typ.ColourInfo)

Aggregations

ColourInfo (uk.me.parabola.imgfmt.app.typ.ColourInfo)2 SyntaxException (uk.me.parabola.mkgmap.scan.SyntaxException)2 BitmapImage (uk.me.parabola.imgfmt.app.typ.BitmapImage)1 Image (uk.me.parabola.imgfmt.app.typ.Image)1 Rgb (uk.me.parabola.imgfmt.app.typ.Rgb)1 TrueImage (uk.me.parabola.imgfmt.app.typ.TrueImage)1 Xpm (uk.me.parabola.imgfmt.app.typ.Xpm)1 Token (uk.me.parabola.mkgmap.scan.Token)1