Unpacks a single integer or array of integers into one or more
24-bit RGB values.
321925
def unpack_rgb(packed):

    '''

    '''

    orig_shape = None

    if isinstance(packed, np.ndarray):
        assert packed.dtype == int
        orig_shape = packed.shape
        packed = packed.reshape((-1, 1))

    rgb = ((packed >> 16) & 0xff,
           (packed >> 8) & 0xff,
           (packed) & 0xff)

    if orig_shape is None:
        return rgb
    else:
        return np.hstack(rgb).reshape(orig_shape + (3,))
563487
function UniArrayToUTF8(arr) {
    var count = 0;

    for (var ix=0; ix<arr.length; ix++) {
        var val = arr[ix];
        if (val < 0x80) {
            count += 1;
        }
        else if (val < 0x800) {
            count += 2;
        }
        else if (val < 0x10000) {
            count += 3;
        }
        else if (val < 0x200000) {
            count += 4;
        }
        else {
            count += 1;
        }
    }

    if (count == arr.length)
        return arr;

    var res = [];
    for (var ix=0; ix<arr.length; ix++) {
        var val = arr[ix];
        if (val < 0x80) {
            res.push(val);
        }
        else if (val < 0x800) {
            res.push(0xC0 | ((val & 0x7C0) >> 6));
            res.push(0x80 |  (val & 0x03F)     );
        }
        else if (val < 0x10000) {
            res.push(0xE0 | ((val & 0xF000) >> 12));
            res.push(0x80 | ((val & 0x0FC0) >>  6));
            res.push(0x80 |  (val & 0x003F)      );
        }
        else if (val < 0x200000) {
            res.push(0xF0 | ((val & 0x1C0000) >> 18));
            res.push(0x80 | ((val & 0x03F000) >> 12));
            res.push(0x80 | ((val & 0x000FC0) >>  6));
            res.push(0x80 |  (val & 0x00003F)      );
        }
        else {
            res.push(63);  // '?'
        }
    }

    return res;
}
1328958
public void unpack(long[] buffer, int offset, int len, int bitSize, InputStream input)
            throws IOException
    {
        checkArgument(len <= MAX_BUFFERED_POSITIONS, "Expected ORC files to have runs of at most 512 bit packed longs");
        switch (bitSize) {
            case 1:
                unpack1(buffer, offset, len, input);
                break;
            case 2:
                unpack2(buffer, offset, len, input);
                break;
            case 4:
                unpack4(buffer, offset, len, input);
                break;
            case 8:
                unpack8(buffer, offset, len, input);
                break;
            case 16:
                unpack16(buffer, offset, len, input);
                break;
            case 24:
                unpack24(buffer, offset, len, input);
                break;
            case 32:
                unpack32(buffer, offset, len, input);
                break;
            case 40:
                unpack40(buffer, offset, len, input);
                break;
            case 48:
                unpack48(buffer, offset, len, input);
                break;
            case 56:
                unpack56(buffer, offset, len, input);
                break;
            case 64:
                unpack64(buffer, offset, len, input);
                break;
            default:
                unpackGeneric(buffer, offset, len, bitSize, input);
        }
    }
629496
private int bytesToInt(byte[] bytes)
    {
        int result = -1;
        if (bytes.length >= 4)
        {
            result = ((bytes[0]&0xff) << 24) +
                     ((bytes[1]&0xff) << 16) +
                     ((bytes[2]&0xff) << 8) +
                     (bytes[3]&0xff);
        }
        return result;
    }
794511
public static boolean[] unpack(int[] packed, int length) {
    boolean[] bools = new boolean[length];
    for (int i = 0; i < length; ++i) {
      bools[i] = (packed[i >> 5] & (1 << (i & 0x1f))) != 0;
    }
    return bools;
  }
667336
def _rgbtomask(self, obj):
        """"""
        dat = obj.get_image().get_data()  # RGB arrays
        return dat.sum(axis=2).astype(np.bool)
631162
static public int unpackInt(DataInput in) throws IOException {
        int ret = 0;
        byte v;
        do{
            v = in.readByte();
            ret = (ret<<7 ) | (v & 0x7F);
        }while((v&0x80)==0);

        return ret;
    }
1158678
def parseBits(self, hexcode, width):
        """"""
        bitarray = []
        for byte in hexcode[::-1]:
            bits = int(byte, 16)
            for x in range(4):
                bitarray.append(bool((2 ** x) & bits))
        bitarray = bitarray[::-1]
        return enumerate(bitarray[:width])
1111788
def from_floats(red, green, blue):
        """"""

        return Color(int(red * Color.MAX_VALUE),
                     int(green * Color.MAX_VALUE),
                     int(blue * Color.MAX_VALUE))
433560
def to_bitarray(data, width=8):
    '''  '''
    if isinstance(data, list) or isinstance(data, bytearray):
        data = combine_hex(data)
    return [True if digit == '1' else False for digit in bin(data)[2:].zfill(width)]
479789
def pack_rgb(rgb):

    ''''''

    orig_shape = None

    if isinstance(rgb, np.ndarray):
        assert rgb.shape[-1] == 3
        orig_shape = rgb.shape[:-1]
    else:
        assert len(rgb) == 3
        rgb = np.array(rgb)

    rgb = rgb.astype(int).reshape((-1, 3))

    packed = (rgb[:, 0] << 16 |
              rgb[:, 1] << 8 |
              rgb[:, 2])

    if orig_shape is None:
        return packed
    else:
        return packed.reshape(orig_shape)
306652
function rgbToHex(r, g, b) {
    [r, g, b] = [limit(r, 0, 255), limit(g, 0, 255), limit(b, 0, 255)];
    return "#" + ("000000" + ((r << 16) | (g << 8) | b).toString(16)).slice(-6);
}
915331
static public int unpackInt(InputStream in) throws IOException {
        int ret = 0;
        int v;
        do{
            v = in.read();
            if(v==-1)
                throw new EOFException();
            ret = (ret<<7 ) | (v & 0x7F);
        }while((v&0x80)==0);

        return ret;
    }
1170957
function(RGBArray) {
    var hex = '#';
    RGBArray.forEach(function(value) {
        if (value < 16) {
            hex += 0;
        }
        hex += value.toString(16);
    });
    return hex;
}
60496
def hexa_to_rgb(color):
    """"""
    r = int(color[1:3], 16)
    g = int(color[3:5], 16)
    b = int(color[5:7], 16)
    if len(color) == 7:
        return r, g, b
    elif len(color) == 9:
        return r, g, b, int(color[7:9], 16)
    else:
        raise ValueError("Invalid hexadecimal notation.")
821034
public static int bytesToInt(byte[] bytes) {
        int value = ((int) bytes[0] & 0xFF) << 24;
        value += ((int) bytes[1] & 0xFF) << 16;
        value += ((int) bytes[2] & 0xFF) << 8;
        value += (int) bytes[3] & 0xFF;
        return value;
    }
375538
static public int unpackInt(ByteBuffer bb)
      throws IOException {
    for (int offset = 0, result = 0; offset < 32; offset += 7) {
      int b = bb.get() & 0xffff;
      result |= (b & 0x7F) << offset;
      if ((b & 0x80) == 0) {
        return result;
      }
    }
    throw new Error("Malformed integer.");
  }