private void process_bmpcache2(RdpPacket_Localised data, int flags,
			boolean compressed, Options option) throws RdesktopException,
			IOException {
		Bitmap bitmap;
		int y;
		int cache_id, cache_idx_low, width, height, Bpp;
		int cache_idx, bufsize;
		byte[] bmpdata, bitmap_id;

		bitmap_id = new byte[8]; /* prevent compiler warning */
		cache_id = flags & ID_MASK;
		Bpp = ((flags & MODE_MASK) >> MODE_SHIFT) - 2;
		Bpp = option.getColourDepthInBytes();
		if ((flags & PERSIST) != 0) {
			bitmap_id = new byte[8];
			data.copyToByteArray(bitmap_id, 0, data.getPosition(), 8);
		}

		if ((flags & SQUARE) != 0) {
			width = data.get8(); // in_uint8(s, width);
			height = width;
		} else {
			width = data.get8(); // in_uint8(s, width);
			height = data.get8(); // in_uint8(s, height);
		}

		bufsize = data.getBigEndian16(); // in_uint16_be(s, bufsize);
		bufsize &= BUFSIZE_MASK;
		cache_idx = data.get8(); // in_uint8(s, cache_idx);

		if ((cache_idx & LONG_FORMAT) != 0) {
			cache_idx_low = data.get8(); // in_uint8(s, cache_idx_low);
			cache_idx = ((cache_idx ^ LONG_FORMAT) << 8) + cache_idx_low;
		}

		// in_uint8p(s, data, bufsize);
/*
		//logger.info("BMPCACHE2(compr=" + compressed + ",flags=" + flags
				+ ",cx=" + width + ",cy=" + height + ",id=" + cache_id
				+ ",idx=" + cache_idx + ",Bpp=" + Bpp + ",bs=" + bufsize + ")");
*/
		bmpdata = new byte[width * height * Bpp];
		int[] bmpdataInt = new int[width * height];

		if (compressed) {
			if (Bpp == 1)
				bmpdataInt = Bitmap.convertImage(
						Bitmap.decompress(width, height, bufsize, data, Bpp),
						Bpp, option);
			else
				bmpdataInt = Bitmap.decompressInt(width, height, bufsize, data,
						Bpp, option);

			if (bmpdataInt == null) {
				//logger.debug("Failed to decompress bitmap data");
				// xfree(bmpdata);
				return;
			}
			bitmap = new Bitmap(bmpdataInt, width, height, 0, 0);
		} else {
			for (y = 0; y < height; y++)
				data.copyToByteArray(bmpdata, y * (width * Bpp),
						(height - y - 1) * (width * Bpp), width * Bpp); // memcpy(&bmpdata[(height
																		// - y -
																		// 1) *
																		// (width
																		// *
																		// Bpp)],
																		// &data[y
																		// *
																		// (width
																		// *
																		// Bpp)],
																		// width
																		// *
																		// Bpp);

			bitmap = new Bitmap(Bitmap.convertImage(bmpdata, Bpp, option),
					width, height, 0, 0);
		}

		// bitmap = ui_create_bitmap(width, height, bmpdata);

		if (bitmap != null) {
			cache.putBitmap(cache_id, cache_idx, bitmap, 0);
			// cache_put_bitmap(cache_id, cache_idx, bitmap, 0);
			if ((flags & PERSIST) != 0)
				PstCache.pstcache_put_bitmap(cache_id, cache_idx, bitmap_id,
						width, height, width * height * Bpp, bmpdata, option);
		} else {
			//logger.debug("process_bmpcache2: ui_create_bitmap failed");
		}

		// xfree(bmpdata);
	}