Search in sources :

Example 1 with AlphaAdder

use of uk.me.parabola.imgfmt.app.typ.AlphaAdder in project mkgmap by openstreetmap.

the class CommonSection method readTrueImageLine.

/**
 * Read a single line of pixel colours.
 *
 * There can be one or more colours on the line and the colours are surrounded
 * by quotes.  The can be trailing attribute that sets the opacity of
 * the final pixel.
 */
private int readTrueImageLine(TokenScanner scanner, final int[] image, int count) {
    do {
        scanner.validateNext("#");
        String col = scanner.nextValue();
        try {
            int val = (int) Long.parseLong(col, 16);
            if (col.length() <= 6)
                val = (val << 8) + 0xff;
            image[count++] = val;
        } catch (NumberFormatException e) {
            throw new SyntaxException(scanner, "Not a valid colour value ");
        }
    } while (scanner.checkToken("#"));
    scanner.validateNext("\"");
    // Look for any trailing alpha=N stuff.
    final int lastColourIndex = count - 1;
    readExtraColourInfo(scanner, new AlphaAdder() {

        /**
         * Add the alpha value to the last colour that was read in.
         *
         * @param alpha A true alpha value ie 0 is transparent, 255 opaque.
         */
        public void addAlpha(int alpha) {
            image[lastColourIndex] = (image[lastColourIndex] & ~0xff) | (alpha & 0xff);
        }
    });
    return count;
}
Also used : SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException) AlphaAdder(uk.me.parabola.imgfmt.app.typ.AlphaAdder)

Aggregations

AlphaAdder (uk.me.parabola.imgfmt.app.typ.AlphaAdder)1 SyntaxException (uk.me.parabola.mkgmap.scan.SyntaxException)1