From 60a17853ade06082c7adc5682d8437db319db5eb Mon Sep 17 00:00:00 2001 From: "Brian P. Hinz" Date: Wed, 24 May 2017 23:17:37 -0400 Subject: [PATCH] Extend JavaPixelBuffer to make further use of Graphics2D ops --- .../tigervnc/vncviewer/JavaPixelBuffer.java | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/java/com/tigervnc/vncviewer/JavaPixelBuffer.java b/java/com/tigervnc/vncviewer/JavaPixelBuffer.java index 4febec15..016b8cf8 100644 --- a/java/com/tigervnc/vncviewer/JavaPixelBuffer.java +++ b/java/com/tigervnc/vncviewer/JavaPixelBuffer.java @@ -24,6 +24,7 @@ import java.awt.image.*; import java.nio.*; import com.tigervnc.rfb.*; +import com.tigervnc.rfb.Point; public class JavaPixelBuffer extends PlatformPixelBuffer { @@ -36,6 +37,23 @@ public class JavaPixelBuffer extends PlatformPixelBuffer image.setAccelerationPriority(1); } + public WritableRaster getBufferRW(Rect r) + { + synchronized(image) { + return ((BufferedImage)image) + .getSubimage(r.tl.x, r.tl.y, r.width(), r.height()).getRaster(); + } + } + + public Raster getBuffer(Rect r) + { + Rectangle rect = + new Rectangle(r.tl.x, r.tl.y, r.width(), r.height()); + synchronized(image) { + return ((BufferedImage)image).getData(rect); + } + } + public void fillRect(Rect r, byte[] pix) { ColorModel cm = format.getColorModel(); @@ -43,7 +61,7 @@ public class JavaPixelBuffer extends PlatformPixelBuffer ByteBuffer.wrap(pix).order(format.getByteOrder()).asIntBuffer().get(0); Color c = new Color(cm.getRGB(pixel)); synchronized(image) { - Graphics2D g2 = ((BufferedImage)image).createGraphics(); + Graphics2D g2 = (Graphics2D)image.getGraphics(); g2.setColor(c); g2.fillRect(r.tl.x, r.tl.y, r.width(), r.height()); g2.dispose(); @@ -52,6 +70,20 @@ public class JavaPixelBuffer extends PlatformPixelBuffer commitBufferRW(r); } + public void copyRect(Rect rect, Point move_by_delta) + { + synchronized(image) { + Graphics2D g2 = (Graphics2D)image.getGraphics(); + g2.copyArea(rect.tl.x - move_by_delta.x, + rect.tl.y - move_by_delta.y, + rect.width(), rect.height(), + move_by_delta.x, move_by_delta.y); + g2.dispose(); + } + + commitBufferRW(rect); + } + private static PixelFormat getPreferredPF() { GraphicsEnvironment ge = -- 2.39.5