private int getPixelVal(int x, int y)
    {
        int i = x + y * width;
        int bpp = getBpp();
        if (bpp == 8)
            return data[i];
        if (bpp == 16)
            return data[i * 2] | data[i * 2 + 1] << 8;
        if (bpp == 4)
        {
            int res = data[i / 2];
            res = res >> ((i % 2) * 4);
            res &= 0xF;
            return res;
        }
        if (bpp == 2)
        {
            int res = data[i / 4];
            res = res >> ((i % 4) * 2);
            res &= 0x3;
            return res;
        }
        throw new RuntimeException("Unsupported BPP Value: " + bpp);
    }