Internal. Decodes 16 bit RGB565 into python list [R,G,B]
960634
def _unpack_bin(self, packed):
        

        output = struct.unpack('H', packed)
        bits16 = output[0]
        r = (bits16 & 0xF800) >> 11
        g = (bits16 & 0x7E0) >> 5
        b = (bits16 & 0x1F)
        return [int(r << 3), int(g << 2), int(b << 3)]
1099914
def b58encode(b, errors='strict'):
    ""
    len_ = len(b)

    # Convert big-endian bytes to integer
    n = BigInteger.deserialize(BytesIO(b), len_)

    # Divide that integer into base58
    res = []
    while n > 0:
        n, r = divmod (n, 58)
        res.append(b58digits[r])
    res = ''.join(res[::-1])

    # Encode leading zeros as base58 zeros
    pad = 0
    for c in b:
        if c == six.int2byte(0): pad += 1
        else: break
    return (b58digits[0] * pad + res, len_)
1326694
def decode(addr):
    """"""
    hrpgot, data = bech32_decode(addr)
    # if hrpgot != hrp:
    if hrpgot not in BECH32_VERSION_SET:
        return (None, None)
    decoded = convertbits(data[1:], 5, 8, False)
    if decoded is None or len(decoded) < 2 or len(decoded) > 40:
        return (None, None)
    if data[0] > 16:
        return (None, None)
    if data[0] == 0 and len(decoded) != 20 and len(decoded) != 32:
        return (None, None)
    return (data[0], decoded)
1086202
def rgb2hex(rgb):
    
    if len(rgb) > 3:
        rgb = rgb[:-1]
    return "#{0:02x}{1:02x}{2:02x}".format(*(int(v*255) for v in rgb))
545067
def dump_uint_b_into(n, width, buffer, offset=0):
    
    for idx in range(width):
        buffer[idx + offset] = n & 0xff
        n >>= 8
    return buffer
65896
def rgb_offset(r, g, b)
      16 + (36 * scale_color(r)) + (6 * scale_color(g)) + scale_color(b)
    end
592607
def hex_to_rgb(h):
    
    h = h.lstrip('#')
    return tuple(int(h[i:i+2], 16)/255. for i in (0, 2 ,4))
1029137
def _decode_byte(byte):
    
    bits = []
    for _ in range(8):
        bits.append(byte & 1)
        byte >>= 1
    return bits
336535
def _hex_to_rgba(hexs):
    """"""
    hexs = np.atleast_1d(np.array(hexs, '|U9'))
    out = np.ones((len(hexs), 4), np.float32)
    for hi, h in enumerate(hexs):
        assert isinstance(h, string_types)
        off = 1 if h[0] == '#' else 0
        assert len(h) in (6+off, 8+off)
        e = (len(h)-off) // 2
        out[hi, :e] = [int(h[i:i+2], 16) / 255.
                       for i in range(off, len(h), 2)]
    return out
222230
def hex16_to_u64be(data):
    """"""
    return int(data[14:16] + data[12:14] + data[10:12] + data[8:10] + data[6:8] + data[4:6] + data[2:4] + data[0:2], 16)
81104
function rgbToHex(r, g, b) {
  var integer = ((Math.round(r) & 0xFF) << 16)
    + ((Math.round(g) & 0xFF) << 8)
    + (Math.round(b) & 0xFF);

  var string = integer.toString(16).toUpperCase();
  return '#' + ('000000'.substring(string.length) + string);
}
1106221
def hex_to_bytes(s):
    
    if len(s) % 2:
        s = b'0' + s
    ia = [int(s[i:i+2], 16) for i in range(0, len(s), 2)]   # int array
    return bs(ia) if PYTHON_MAJOR_VER == 3 else b''.join([chr(c) for c in ia])
762083
function rgb(hexStr) {
  const hex = hexStr.replace(/^#/, '');
  const fullHex = hex.length === 3
    ? `${hex[0]}${hex[0]}${hex[1]}${hex[1]}${hex[2]}${hex[2]}`
    : hex;

  const num = parseInt(fullHex, 16);
  // eslint-disable-next-line no-bitwise, no-mixed-operators
  return [num >> 16, num >> 8 & 255, num & 255].join(', ');
}
470513
def unparse_color(r, g, b, a, type):
    
    if type == '#rgb':
        # Don't lose precision on rgb shortcut
        if r % 17 == 0 and g % 17 == 0 and b % 17 == 0:
            return '#%x%x%x' % (int(r / 17), int(g / 17), int(b / 17))
        type = '#rrggbb'

    if type == '#rgba':
        if r % 17 == 0 and g % 17 == 0 and b % 17 == 0:
            return '#%x%x%x%x' % (
                int(r / 17), int(g / 17), int(b / 17), int(a * 15)
            )
        type = '#rrggbbaa'

    if type == '#rrggbb':
        return '#%02x%02x%02x' % (r, g, b)

    if type == '#rrggbbaa':
        return '#%02x%02x%02x%02x' % (r, g, b, int(a * 255))

    if type == 'rgb':
        return 'rgb(%d, %d, %d)' % (r, g, b)

    if type == 'rgba':
        return 'rgba(%d, %d, %d, %g)' % (r, g, b, a)
197476
def crc16(frame):
    
    crc = 0xFFFF
    for index, item in enumerate(bytearray(frame)):
        next_byte = item
        crc ^= next_byte
        for i in range(8):
            lsb = crc & 1
            crc >>= 1
            if lsb:
                crc ^= 0xA001
    return crc
123651
def _hex_to_rgb(color):
    
    if color[0] == '#':
        color = color[1:]
    if len(color) == 3:
        color = color[0] * 2 + color[1] * 2 + color[2] * 2
    if len(color) != 6:
        raise ValueError('Input #{0} is not in #RRGGBB format'.format(color))
    return [int(n, 16) for n in (color[:2], color[2:4], color[4:])]
1043452
def try_rgb(s, default=None):
    
    if not s:
        return default
    try:
        r, g, b = (int(x.strip()) for x in s.split(','))
    except ValueError:
        raise InvalidRgb(s)
    if not all(in_range(x, 0, 255) for x in (r, g, b)):
        raise InvalidRgb(s)

    return r, g, b