use of common.BitmapRectangle in project cloudstack by apache.
the class ServerBitmapUpdate method readRectangle.
public BitmapRectangle readRectangle(ByteBuffer buf) {
BitmapRectangle rectangle = new BitmapRectangle();
// (2 bytes): A 16-bit, unsigned integer. Left bound of the rectangle.
rectangle.x = buf.readSignedShortLE();
// (2 bytes): A 16-bit, unsigned integer. Top bound of the rectangle.
rectangle.y = buf.readSignedShortLE();
// (2 bytes): A 16-bit, unsigned integer. Inclusive right bound of the
// rectangle.
int destRight = buf.readSignedShortLE();
rectangle.width = destRight - rectangle.x + 1;
// (2 bytes): A 16-bit, unsigned integer. Inclusive bottom bound of the
// rectangle.
int destBottom = buf.readSignedShortLE();
rectangle.height = destBottom - rectangle.y + 1;
// (2 bytes): A 16-bit, unsigned integer. The width of the rectangle.
rectangle.bufferWidth = buf.readSignedShortLE();
// (2 bytes): A 16-bit, unsigned integer. The height of the rectangle.
rectangle.bufferHeight = buf.readSignedShortLE();
// (2 bytes): A 16-bit, unsigned integer. The color depth of the rectangle
// data in bits-per-pixel.
rectangle.colorDepth = buf.readSignedShortLE();
// (2 bytes): A 16-bit, unsigned integer. The flags describing the format of
// the bitmap data in the bitmapDataStream field.
int flags = buf.readSignedShortLE();
// BITMAP_COMPRESSION 0x0001
// Indicates that the bitmap data is compressed. The bitmapComprHdr field
// MUST be present if the NO_BITMAP_COMPRESSION_HDR (0x0400) flag is not
// set.
boolean compressed = ((flags & BITMAP_COMPRESSION) > 0);
// (2 bytes): A 16-bit, unsigned integer. The size in bytes of the data in
// the bitmapComprHdr and bitmapDataStream fields.
int bitmapLength = buf.readSignedShortLE();
// bandwidth efficiency to save 8 bytes).
if (compressed && (flags & NO_BITMAP_COMPRESSION_HDR) == 0) {
// (8 bytes): Optional Compressed Data Header structure specifying the
// bitmap data in the bitmapDataStream.
// This field MUST be present if the BITMAP_COMPRESSION (0x0001) flag is
// present in the Flags field, but the NO_BITMAP_COMPRESSION_HDR (0x0400)
// flag is not.
// Note: Even when compression header is enabled, server sends nothing.
// rectangle.compressedBitmapHeader = buf.readBytes(8);
}
// an RDP 6.0 Bitmap Compressed Stream structure.
if (!compressed) {
rectangle.bitmapDataStream = buf.readBytes(bitmapLength);
} else {
ByteBuffer compressedImage = buf.readBytes(bitmapLength);
//* DEBUG */System.out.println("Compressed image: " + compressedImage + ", depth: " + rectangle.bitsPerPixel + ".");
rectangle.bitmapDataStream = RLEBitmapDecompression.rleDecompress(compressedImage, rectangle.bufferWidth, rectangle.bufferHeight, rectangle.colorDepth);
compressedImage.unref();
}
return rectangle;
}
use of common.BitmapRectangle in project cloudstack by apache.
the class ServerBitmapUpdate method handleData.
@Override
public void handleData(ByteBuffer buf, Link link) {
if (verbose)
System.out.println("[" + this + "] INFO: Data received: " + buf + ".");
// * DEBUG */System.out.println(buf.toHexString(buf.length));
BitmapOrder order = new BitmapOrder();
// (2 bytes): A 16-bit, unsigned integer. The update type. This field MUST
// be set to UPDATETYPE_BITMAP (0x0001).
int updateType = buf.readSignedShortLE();
if (updateType != UPDATETYPE_BITMAP)
throw new RuntimeException("Unknown update type. Expected update type: UPDATETYPE_BITMAP (0x1). Actual update type: " + updateType + ", buf: " + buf + ".");
// (2 bytes): A 16-bit, unsigned integer. The number of screen rectangles
// present in the rectangles field.
int numberRectangles = buf.readSignedShortLE();
// (variable): Variable-length array of TS_BITMAP_DATA structures, each of
// which contains a rectangular clipping taken from the server-side screen
// frame buffer. The number of screen clippings in the array is specified by
// the numberRectangles field.
BitmapRectangle[] rectangles = new BitmapRectangle[numberRectangles];
for (int i = 0; i < numberRectangles; i++) {
rectangles[i] = readRectangle(buf);
}
order.rectangles = rectangles;
buf.assertThatBufferIsFullyRead();
ByteBuffer data = new ByteBuffer(order);
pushDataToAllOuts(data);
buf.unref();
}
use of common.BitmapRectangle in project cloudstack by apache.
the class VncMessageHandler method handleRawRectangle.
private boolean handleRawRectangle(ByteBuffer buf, Link link, int x, int y, int width, int height) {
// Raw rectangle is just array of pixels to draw on screen.
int rectDataLength = width * height * screen.getBytesPerPixel();
// rectangles.
if (!cap(buf, rectDataLength, UNLIMITED, link, true))
return false;
if (verbose)
System.out.println("[" + this + "] INFO: Raw rect. X: " + x + ", y: " + y + ", width: " + width + ", height: " + height + ", data length: " + rectDataLength + ".");
BitmapRectangle rectangle = new BitmapRectangle();
rectangle.x = x;
rectangle.y = y;
rectangle.width = width;
rectangle.height = height;
rectangle.bufferWidth = width;
rectangle.bufferHeight = height;
rectangle.bitmapDataStream = buf.readBytes(rectDataLength);
rectangle.colorDepth = screen.getColorDeph();
BitmapOrder order = new BitmapOrder();
order.rectangles = new BitmapRectangle[] { rectangle };
pushDataToPad(PIXEL_ADAPTER_PAD, new ByteBuffer(order));
return true;
}
use of common.BitmapRectangle in project cloudstack by apache.
the class AwtCanvasAdapter method handleBitmap.
private void handleBitmap(BitmapOrder order, ByteBuffer buf) {
// Draw rectangle on offline buffer
BufferedImage image = canvas.getOfflineImage();
Graphics2D g = (Graphics2D) image.getGraphics();
for (BitmapRectangle rectangle : order.rectangles) {
// *DEBUG*/System.out.println("["+this+"] DEBUG: Rectangle: " +
// rectangle.toString());
int x = rectangle.x;
int y = rectangle.y;
int width = rectangle.width;
int height = rectangle.height;
int bufferWidth = rectangle.bufferWidth;
int bufferHeight = rectangle.bufferHeight;
BufferedImage rectImage;
switch(rectangle.colorDepth) {
case 8:
{
rectImage = new BufferedImage(bufferWidth, height, BufferedImage.TYPE_BYTE_INDEXED, screen.colorMap);
WritableRaster raster = rectImage.getRaster();
raster.setDataElements(0, 0, bufferWidth, bufferHeight, rectangle.bitmapDataStream.toByteArray());
break;
}
case 15:
{
rectImage = new BufferedImage(bufferWidth, height, BufferedImage.TYPE_USHORT_555_RGB);
WritableRaster raster = rectImage.getRaster();
raster.setDataElements(0, 0, bufferWidth, bufferHeight, rectangle.bitmapDataStream.toShortArray());
break;
}
case 16:
{
rectImage = new BufferedImage(bufferWidth, height, BufferedImage.TYPE_USHORT_565_RGB);
WritableRaster raster = rectImage.getRaster();
raster.setDataElements(0, 0, bufferWidth, bufferHeight, rectangle.bitmapDataStream.toShortArray());
break;
}
case 24:
case 32:
{
rectImage = new BufferedImage(bufferWidth, height, BufferedImage.TYPE_INT_RGB);
WritableRaster raster = rectImage.getRaster();
raster.setDataElements(0, 0, bufferWidth, bufferHeight, rectangle.bitmapDataStream.toIntLEArray());
break;
}
default:
throw new RuntimeException("Unsupported color depth: " + rectangle.colorDepth + ".");
}
g.setClip(x, y, width, height);
g.drawImage(rectImage, x, y, null);
// Request update of repainted area
canvas.updateFrameBuffer(x, y, width, height);
canvas.repaint(x, y, width, height);
}
}
Aggregations