From 547117027e06cf50a91b0f0b5a33a576bcca02b6 Mon Sep 17 00:00:00 2001 From: Brian Hinz Date: Sat, 1 Sep 2012 02:00:51 +0000 Subject: [PATCH] r4960 broke support for pixel formats with depth < 24. This corrects that and also forces a full framebuffer update whenever the format is changed. git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4986 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- java/com/tigervnc/rfb/PixelBuffer.java | 5 ++- .../com/tigervnc/vncviewer/BIPixelBuffer.java | 39 ++++++++++++------- java/com/tigervnc/vncviewer/CConn.java | 8 +++- 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/java/com/tigervnc/rfb/PixelBuffer.java b/java/com/tigervnc/rfb/PixelBuffer.java index 392987d9..88b3a89e 100644 --- a/java/com/tigervnc/rfb/PixelBuffer.java +++ b/java/com/tigervnc/rfb/PixelBuffer.java @@ -44,8 +44,9 @@ public class PixelBuffer { int rmask = pf.redMax << pf.redShift; int gmask = pf.greenMax << pf.greenShift; int bmask = pf.blueMax << pf.blueShift; - cm = new DirectColorModel(8, rmask, gmask, bmask); - if (!pf.trueColour) + if (pf.trueColour) + cm = new DirectColorModel(8, rmask, gmask, bmask); + else cm = new IndexColorModel(8, 256, new byte[256], new byte[256], new byte[256]); break; case 16: diff --git a/java/com/tigervnc/vncviewer/BIPixelBuffer.java b/java/com/tigervnc/vncviewer/BIPixelBuffer.java index 88c93963..6690c79f 100644 --- a/java/com/tigervnc/vncviewer/BIPixelBuffer.java +++ b/java/com/tigervnc/vncviewer/BIPixelBuffer.java @@ -34,30 +34,33 @@ public class BIPixelBuffer extends PlatformPixelBuffer implements ImageObserver public void setPF(PixelFormat pf) { super.setPF(pf); + createImage(width(), height()); } public void updateColourMap() { cm = new IndexColorModel(8, nColours, reds, greens, blues); + createImage(width_, height_); } // resize() resizes the image, preserving the image data where possible. public void resize(int w, int h) { - if (w == width() && h == height()) return; + if (w == width() && h == height()) + return; width_ = w; height_ = h; - GraphicsEnvironment ge = - GraphicsEnvironment.getLocalGraphicsEnvironment(); - GraphicsDevice gd = ge.getDefaultScreenDevice(); - GraphicsConfiguration gc = gd.getDefaultConfiguration(); - image = gc.createCompatibleImage(w, h, Transparency.TRANSLUCENT); - image.setAccelerationPriority(1); - image.createGraphics(); - WritableRaster wr = image.getRaster(); - SinglePixelPackedSampleModel sm = - (SinglePixelPackedSampleModel)image.getSampleModel(); - DataBufferInt db = (DataBufferInt)wr.getDataBuffer(); - data = db.getData(); + createImage(w, h); + } + + private void createImage(int w, int h) { + if (w == 0 || h == 0) return; + WritableRaster wr; + if (cm instanceof IndexColorModel) + wr = ((IndexColorModel)cm).createCompatibleWritableRaster(w, h); + else + wr = ((DirectColorModel)cm).createCompatibleWritableRaster(w, h); + image = new BufferedImage(cm, wr, true, null); + db = wr.getDataBuffer(); } public void fillRect(int x, int y, int w, int h, int pix) { @@ -92,8 +95,13 @@ public class BIPixelBuffer extends PlatformPixelBuffer implements ImageObserver clip = null; img.flush(); } else { - for (int j = 0; j < h; j++) - System.arraycopy(pix, (w*j), data, width_ * (y + j) + x, w); + if (image.getSampleModel().getTransferType() == DataBuffer.TYPE_BYTE) { + byte[] bytes = new byte[((int[])pix).length]; + for (int i = 0; i < bytes.length; i++) + bytes[i] = (byte)((int[])pix)[i]; + pix = bytes; + } + image.getSampleModel().setDataElements(x, y, w, h, pix, db); } } @@ -126,6 +134,7 @@ public class BIPixelBuffer extends PlatformPixelBuffer implements ImageObserver } BufferedImage image; + DataBuffer db; Rectangle clip; static LogWriter vlog = new LogWriter("BIPixelBuffer"); diff --git a/java/com/tigervnc/vncviewer/CConn.java b/java/com/tigervnc/vncviewer/CConn.java index 0ad69067..498b4c87 100644 --- a/java/com/tigervnc/vncviewer/CConn.java +++ b/java/com/tigervnc/vncviewer/CConn.java @@ -625,6 +625,7 @@ public class CConn extends CConnection (newFullColour ? "enabled" : "disabled")); fullColour = newFullColour; formatChange = true; + forceNonincremental = true; } } @@ -680,7 +681,7 @@ public class CConn extends CConnection if (forceNonincremental || !continuousUpdates) { pendingUpdate = true; writer().writeFramebufferUpdateRequest(new Rect(0,0,cp.width,cp.height), - !formatChange && !forceNonincremental); + !forceNonincremental); } forceNonincremental = false; @@ -921,8 +922,10 @@ public class CConn extends CConnection public void getOptions() { autoSelect = options.autoSelect.isSelected(); - if (fullColour != options.fullColour.isSelected()) + if (fullColour != options.fullColour.isSelected()) { formatChange = true; + forceNonincremental = true; + } fullColour = options.fullColour.isSelected(); if (!fullColour) { int newLowColourLevel = (options.veryLowColour.isSelected() ? 0 : @@ -930,6 +933,7 @@ public class CConn extends CConnection if (newLowColourLevel != lowColourLevel) { lowColourLevel = newLowColourLevel; formatChange = true; + forceNonincremental = true; } } int newEncoding = (options.zrle.isSelected() ? Encodings.encodingZRLE : -- 2.39.5