@Override
    public ByteBuffer getData() {
        int cols = (int) colorsUsed;
        if (cols == 0) {
            cols = 1 << bitsPerPixel;
        }

        int rowsize = (int) width / 8;
        if ((rowsize % 4) > 0) {
            rowsize += 4 - (rowsize % 4);
        }

        ByteBuffer buf = ByteBuffer.allocate((int) (40 + (cols * 4) + (width * (height
                / 2) * bitsPerPixel) / 8 + (rowsize * (height / 2))));
        buf.order(ByteOrder.LITTLE_ENDIAN);
        buf.position(0);

        buf.putInt((int) size);
        buf.putInt((int) width);
        buf.putInt((int) height);
        buf.putShort((short) planes);
        buf.putShort((short) bitsPerPixel);
        buf.putInt((int) compression);
        buf.putInt((int) sizeOfBitmap);
        buf.putInt((int) horzResolution);
        buf.putInt((int) vertResolution);
        buf.putInt((int) colorsUsed);
        buf.putInt((int) colorsImportant);

        //		System.out.println("GET DATA :: palette.size= "+palette.length + " // position=" + buf.position());
        for (int i = 0; i < palette.length; i++) {
            PaletteElement el = palette[i];
            buf.put((byte) el.Blue);
            buf.put((byte) el.Green);
            buf.put((byte) el.Red);
            buf.put((byte) el.Reserved);
        }

        switch (bitsPerPixel) {
            case 4: {
                for (int i = 0; i < bitmapXOR.length; i += 2) {
                    int v1 = bitmapXOR[i];
                    int v2 = bitmapXOR[i + 1];
                    buf.put((byte) ((v1 << 4) | v2));
                }
            }
            break;

            case 8: {
                //				System.out.println("GET DATA :: XORBitmap.size= "+bitmapXOR.length + " // position=" + buf.position());
                for (int i = 0; i < bitmapXOR.length; i++) {
                    buf.put((byte) bitmapXOR[i]);
                }
            }
            break;

            default:
                throw new RuntimeException("BitRes " + bitsPerPixel
                        + " not supported!");
        }

        //		System.out.println("GET DATA :: AndBitmap.size= "+bitmapAND.length + " // position=" + buf.position());
        for (int i = 0; i < bitmapAND.length; i++) {
            buf.put((byte) bitmapAND[i]);
        }

        //		System.out.println("GET DATA END AT " + buf.position());
        buf.position(0);
        return buf;
    }