private void setPixelVal(int x, int y, int v)
    {
        int i = x + y * width;
        int bpp = getBpp();

        if (bpp == 8)
            data[i] = (byte) v;
        else if (bpp == 16)
        {
            data[i * 2] = (byte) (v & 0xFF);
            data[i * 2] = (byte) ((v >> 8) & 0xFF);
        } else if (bpp == 4)
        {
            int res = data[i / 2];
            res &= ~(0xF << ((i % 2) * 4));
            res |= (v & 0xF) << ((i % 2) * 4);
            data[i / 2] = (byte) res;
        } else if (bpp == 2)
        {
            int res = data[i / 4];
            res &= ~(0xF << ((i % 4) * 2));
            res |= (v & 0xF) << ((i % 4) * 2);
            data[i / 4] = (byte) res;
        } else
            throw new RuntimeException("Unsupported BPP Value: " + bpp);
    }