function hex2rgba(hex) {
        if (!hex) {
            // Invalid color
            return null;
        }
        var length = hex.length;
        if (length === 0) {
            // Invalid color
            return null;
        }
        if (hex.charCodeAt(0) !== 35 /* Hash */) {
            // Does not begin with a #
            return null;
        }
        if (length === 7) {
            // #RRGGBB format
            var r = 16 * _parseHexDigit(hex.charCodeAt(1)) + _parseHexDigit(hex.charCodeAt(2));
            var g = 16 * _parseHexDigit(hex.charCodeAt(3)) + _parseHexDigit(hex.charCodeAt(4));
            var b = 16 * _parseHexDigit(hex.charCodeAt(5)) + _parseHexDigit(hex.charCodeAt(6));
            return new RGBA(r, g, b, 255);
        }
        if (length === 9) {
            // #RRGGBBAA format
            var r = 16 * _parseHexDigit(hex.charCodeAt(1)) + _parseHexDigit(hex.charCodeAt(2));
            var g = 16 * _parseHexDigit(hex.charCodeAt(3)) + _parseHexDigit(hex.charCodeAt(4));
            var b = 16 * _parseHexDigit(hex.charCodeAt(5)) + _parseHexDigit(hex.charCodeAt(6));
            var a = 16 * _parseHexDigit(hex.charCodeAt(7)) + _parseHexDigit(hex.charCodeAt(8));
            return new RGBA(r, g, b, a);
        }
        if (length === 4) {
            // #RGB format
            var r = _parseHexDigit(hex.charCodeAt(1));
            var g = _parseHexDigit(hex.charCodeAt(2));
            var b = _parseHexDigit(hex.charCodeAt(3));
            return new RGBA(16 * r + r, 16 * g + g, 16 * b + b);
        }
        if (length === 5) {
            // #RGBA format
            var r = _parseHexDigit(hex.charCodeAt(1));
            var g = _parseHexDigit(hex.charCodeAt(2));
            var b = _parseHexDigit(hex.charCodeAt(3));
            var a = _parseHexDigit(hex.charCodeAt(4));
            return new RGBA(16 * r + r, 16 * g + g, 16 * b + b, 16 * a + a);
        }
        // Invalid color
        return null;
    }
Converts an Hex color value to RGB.
returns r, g, and b are contained in the set [0, 255]
@param hex string (#RGB, #RGBA, #RRGGBB or #RRGGBBAA).