From: Constantin Kaplinsky Date: Fri, 18 Apr 2008 17:48:16 +0000 (+0000) Subject: Automated code formatting by NetBeans IDE. X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=72e47efb3726b12ca97c188cdd4659472aac9c74;p=tigervnc.git Automated code formatting by NetBeans IDE. git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@2529 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- diff --git a/java/src/com/tightvnc/rfbplayer/ButtonPanel.java b/java/src/com/tightvnc/rfbplayer/ButtonPanel.java index 8b062e8a..95a7eb62 100644 --- a/java/src/com/tightvnc/rfbplayer/ButtonPanel.java +++ b/java/src/com/tightvnc/rfbplayer/ButtonPanel.java @@ -52,8 +52,7 @@ class ButtonPanel extends Panel implements ActionListener { timeScaleText.addActionListener(this); } - public void setPaused(boolean paused) - { + public void setPaused(boolean paused) { if (paused) { playButton.setLabel("Play"); } else { @@ -69,7 +68,7 @@ class ButtonPanel extends Panel implements ActionListener { char[] zeroes = {'0', '0', '0', '0'}; String text = String.valueOf(seconds); if (text.length() < 4) { - text = new String(zeroes, 0, 4 - text.length()) + text; + text = new String(zeroes, 0, 4 - text.length()) + text; } posText.setText(text); posText.setCaretPosition(text.length()); @@ -79,7 +78,6 @@ class ButtonPanel extends Panel implements ActionListener { // // Event processing. // - public void actionPerformed(ActionEvent evt) { if (evt.getSource() == playButton) { player.setPaused(playButton.getLabel().equals("Pause")); @@ -88,10 +86,11 @@ class ButtonPanel extends Panel implements ActionListener { } else if (evt.getSource() == timeScaleText) { double speed = Double.valueOf(timeScaleText.getText()).doubleValue(); if (speed <= 0.0) - speed = 1.0; + speed = 1.0; timeScaleText.setText(String.valueOf(speed)); player.setSpeed(speed); } } + } diff --git a/java/src/com/tightvnc/rfbplayer/FbsInputStream.java b/java/src/com/tightvnc/rfbplayer/FbsInputStream.java index d2cf5934..1dcdd093 100644 --- a/java/src/com/tightvnc/rfbplayer/FbsInputStream.java +++ b/java/src/com/tightvnc/rfbplayer/FbsInputStream.java @@ -43,7 +43,6 @@ class FbsInputStream extends InputStream { // // Constructors. // - FbsInputStream() throws IOException { throw new IOException("FbsInputStream: no such constructor"); } @@ -51,9 +50,7 @@ class FbsInputStream extends InputStream { // // Construct FbsInputStream object, begin playback. // - - FbsInputStream(InputStream in) throws IOException - { + FbsInputStream(InputStream in) throws IOException { this.in = in; startTime = System.currentTimeMillis(); timeOffset = 0; @@ -66,9 +63,9 @@ class FbsInputStream extends InputStream { readFully(b); if (b[0] != 'F' || b[1] != 'B' || b[2] != 'S' || b[3] != ' ' || - b[4] != '0' || b[5] != '0' || b[6] != '1' || b[7] != '.' || - b[8] < '0' || b[8] > '9' || b[9] < '0' || b[9] > '9' || - b[10] < '0' || b[10] > '9' || b[11] != '\n') { + b[4] != '0' || b[5] != '0' || b[6] != '1' || b[7] != '.' || + b[8] < '0' || b[8] > '9' || b[9] < '0' || b[9] > '9' || + b[10] < '0' || b[10] > '9' || b[11] != '\n') { throw new IOException("Incorrect protocol version"); } @@ -80,19 +77,16 @@ class FbsInputStream extends InputStream { // // Basic methods overriding InputStream's methods. // - - public int read() throws IOException - { + public int read() throws IOException { while (bufferSize == 0) { if (!fillBuffer()) - return -1; + return -1; } bufferSize--; return buffer[bufferPos++] & 0xFF; } - public int available() throws IOException - { + public int available() throws IOException { // FIXME: This will work incorrectly if our caller will wait until // some amount of data is available when the buffer contains less // data than then that. Current implementation never reads more @@ -100,8 +94,7 @@ class FbsInputStream extends InputStream { return bufferSize; } - public synchronized void close() throws IOException - { + public synchronized void close() throws IOException { in.close(); in = null; startTime = -1; @@ -121,15 +114,12 @@ class FbsInputStream extends InputStream { // // Methods providing additional functionality. // - - public synchronized long getTimeOffset() - { + public synchronized long getTimeOffset() { long off = Math.max(seekOffset, timeOffset); return (long)(off * playbackSpeed); } - public synchronized void setTimeOffset(long pos) - { + public synchronized void setTimeOffset(long pos) { seekOffset = (long)(pos / playbackSpeed); if (seekOffset < timeOffset) { seekBackwards = true; @@ -137,8 +127,7 @@ class FbsInputStream extends InputStream { notify(); } - public synchronized void setSpeed(double newSpeed) - { + public synchronized void setSpeed(double newSpeed) { long newOffset = (long)(timeOffset * playbackSpeed / newSpeed); startTime += timeOffset - newOffset; timeOffset = newOffset; @@ -148,45 +137,37 @@ class FbsInputStream extends InputStream { playbackSpeed = newSpeed; } - public boolean isSeeking() - { + public boolean isSeeking() { return (seekOffset >= 0); } - public long getSeekOffset() - { + public long getSeekOffset() { return (long)(seekOffset * playbackSpeed); } - public boolean isPaused() - { + public boolean isPaused() { return paused; } - public synchronized void pausePlayback() - { + public synchronized void pausePlayback() { paused = true; notify(); } - public synchronized void resumePlayback() - { + public synchronized void resumePlayback() { paused = false; startTime = System.currentTimeMillis() - timeOffset; notify(); } - public void addObserver(Observer target) - { + public void addObserver(Observer target) { obs = target; } // // Methods for internal use. // - - private synchronized boolean fillBuffer() throws IOException - { + private synchronized boolean fillBuffer() throws IOException { // The reading thread should be interrupted on backward seeking. if (seekBackwards) throw new EOFException("[REWIND]"); @@ -212,20 +193,20 @@ class FbsInputStream extends InputStream { if (seekOffset >= 0) { if (timeOffset >= seekOffset) { - startTime = System.currentTimeMillis() - seekOffset; - seekOffset = -1; + startTime = System.currentTimeMillis() - seekOffset; + seekOffset = -1; } else { - return true; + return true; } } while (true) { long timeDiff = startTime + timeOffset - System.currentTimeMillis(); if (timeDiff <= 0) { - break; + break; } try { - wait(timeDiff); + wait(timeDiff); } catch (InterruptedException e) { } waitWhilePaused(); @@ -237,48 +218,45 @@ class FbsInputStream extends InputStream { // // In paused mode, wait for external notification on this object. // - - private void waitWhilePaused() - { + private void waitWhilePaused() { while (paused && !isSeeking()) { synchronized(this) { - try { - // Note: we call Observer.update(Observable,Object) method - // directly instead of maintaining an Observable object. - obs.update(null, null); - wait(); - } catch (InterruptedException e) { - } + try { + // Note: we call Observer.update(Observable,Object) method + // directly instead of maintaining an Observable object. + obs.update(null, null); + wait(); + } catch (InterruptedException e) { + } } } } - private long readUnsigned32() throws IOException - { + private long readUnsigned32() throws IOException { byte[] buf = new byte[4]; if (!readFully(buf)) return -1; return ((long)(buf[0] & 0xFF) << 24 | - (buf[1] & 0xFF) << 16 | - (buf[2] & 0xFF) << 8 | - (buf[3] & 0xFF)); + (buf[1] & 0xFF) << 16 | + (buf[2] & 0xFF) << 8 | + (buf[3] & 0xFF)); } - private boolean readFully(byte[] b) throws IOException - { + private boolean readFully(byte[] b) throws IOException { int off = 0; int len = b.length; while (off != len) { int count = in.read(b, off, len - off); if (count < 0) { - return false; + return false; } off += count; } return true; } + } diff --git a/java/src/com/tightvnc/rfbplayer/RfbPlayer.java b/java/src/com/tightvnc/rfbplayer/RfbPlayer.java index 1cf16abe..0918bef1 100644 --- a/java/src/com/tightvnc/rfbplayer/RfbPlayer.java +++ b/java/src/com/tightvnc/rfbplayer/RfbPlayer.java @@ -24,7 +24,7 @@ import java.io.*; import java.net.*; public class RfbPlayer extends java.applet.Applet - implements java.lang.Runnable, WindowListener { + implements java.lang.Runnable, WindowListener { boolean inAnApplet = true; boolean inSeparateFrame = false; @@ -33,7 +33,6 @@ public class RfbPlayer extends java.applet.Applet // main() is called when run as a java program from the command line. // It simply runs the applet inside a newly-created frame. // - public static void main(String[] argv) { RfbPlayer p = new RfbPlayer(); p.mainArgs = argv; @@ -67,7 +66,6 @@ public class RfbPlayer extends java.applet.Applet // // init() // - public void init() { readParameters(); @@ -75,7 +73,7 @@ public class RfbPlayer extends java.applet.Applet if (inSeparateFrame) { vncFrame = new Frame("RFB Session Player"); if (!inAnApplet) { - vncFrame.add("Center", this); + vncFrame.add("Center", this); } vncContainer = vncFrame; } else { @@ -95,7 +93,6 @@ public class RfbPlayer extends java.applet.Applet // // run() - executed by the rfbThread to read RFB data. // - public void run() { gridbag = new GridBagLayout(); @@ -121,9 +118,9 @@ public class RfbPlayer extends java.applet.Applet try { if (inAnApplet) { - url = new URL(getCodeBase(), sessionURL); + url = new URL(getCodeBase(), sessionURL); } else { - url = new URL(sessionURL); + url = new URL(sessionURL); } rfb = new RfbProto(url); @@ -133,54 +130,54 @@ public class RfbPlayer extends java.applet.Applet if (inSeparateFrame) { - // Create a panel which itself is resizeable and can hold - // non-resizeable VncCanvas component at the top left corner. - Panel canvasPanel = new Panel(); - canvasPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); - canvasPanel.add(vc); - - // Create a ScrollPane which will hold a panel with VncCanvas - // inside. - desktopScrollPane = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED); - gbc.fill = GridBagConstraints.BOTH; - gridbag.setConstraints(desktopScrollPane, gbc); - desktopScrollPane.add(canvasPanel); - - // Finally, add our ScrollPane to the Frame window. - vncFrame.add(desktopScrollPane); - vncFrame.setTitle(rfb.desktopName); - vncFrame.pack(); - vc.resizeDesktopFrame(); + // Create a panel which itself is resizeable and can hold + // non-resizeable VncCanvas component at the top left corner. + Panel canvasPanel = new Panel(); + canvasPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); + canvasPanel.add(vc); + + // Create a ScrollPane which will hold a panel with VncCanvas + // inside. + desktopScrollPane = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED); + gbc.fill = GridBagConstraints.BOTH; + gridbag.setConstraints(desktopScrollPane, gbc); + desktopScrollPane.add(canvasPanel); + + // Finally, add our ScrollPane to the Frame window. + vncFrame.add(desktopScrollPane); + vncFrame.setTitle(rfb.desktopName); + vncFrame.pack(); + vc.resizeDesktopFrame(); } else { - // Just add the VncCanvas component to the Applet. - gridbag.setConstraints(vc, gbc); - add(vc); - validate(); + // Just add the VncCanvas component to the Applet. + gridbag.setConstraints(vc, gbc); + add(vc); + validate(); } while (true) { - try { - setPaused(!autoPlay); - rfb.fbs.setSpeed(playbackSpeed); - if (initialTimeOffset > rfb.fbs.getTimeOffset()) - setPos(initialTimeOffset); // don't seek backwards here - vc.processNormalProtocol(); - } catch (EOFException e) { - if (e.getMessage() != null && e.getMessage().equals("[REWIND]")) { - // A special type of EOFException allowing us to seek backwards. - initialTimeOffset = rfb.fbs.getSeekOffset(); - autoPlay = !rfb.fbs.isPaused(); - } else { - // Return to the beginning after the playback is finished. - initialTimeOffset = 0; - autoPlay = false; - } + try { + setPaused(!autoPlay); + rfb.fbs.setSpeed(playbackSpeed); + if (initialTimeOffset > rfb.fbs.getTimeOffset()) + setPos(initialTimeOffset); // don't seek backwards here + vc.processNormalProtocol(); + } catch (EOFException e) { + if (e.getMessage() != null && e.getMessage().equals("[REWIND]")) { + // A special type of EOFException allowing us to seek backwards. + initialTimeOffset = rfb.fbs.getSeekOffset(); + autoPlay = !rfb.fbs.isPaused(); + } else { + // Return to the beginning after the playback is finished. + initialTimeOffset = 0; + autoPlay = false; + } rfb.newSession(url); vc.updateFramebufferSize(); - } + } } } catch (FileNotFoundException e) { @@ -189,7 +186,7 @@ public class RfbPlayer extends java.applet.Applet e.printStackTrace(); fatalError(e.toString()); } - + } public void setPaused(boolean paused) { @@ -215,7 +212,6 @@ public class RfbPlayer extends java.applet.Applet rfb.fbs.setTimeOffset(pos); } - public void updatePos() { if (showControls) buttonPanel.setPos(rfb.fbs.getTimeOffset()); @@ -227,7 +223,6 @@ public class RfbPlayer extends java.applet.Applet // param_name/param_value pairs where the names and values correspond to // those expected in the html applet tag source. // - public void readParameters() { sessionURL = readParameter("URL", true); @@ -253,7 +248,7 @@ public class RfbPlayer extends java.applet.Applet if (inAnApplet) { str = readParameter("Open New Window", false); if (str != null && str.equalsIgnoreCase("Yes")) - inSeparateFrame = true; + inSeparateFrame = true; } // Fine tuning options. @@ -266,21 +261,21 @@ public class RfbPlayer extends java.applet.Applet if (inAnApplet) { String s = getParameter(name); if ((s == null) && required) { - fatalError(name + " parameter not specified"); + fatalError(name + " parameter not specified"); } return s; } for (int i = 0; i < mainArgs.length; i += 2) { if (mainArgs[i].equalsIgnoreCase(name)) { - try { - return mainArgs[i+1]; - } catch (Exception e) { - if (required) { - fatalError(name + " parameter not specified"); - } - return null; - } + try { + return mainArgs[i + 1]; + } catch (Exception e) { + if (required) { + fatalError(name + " parameter not specified"); + } + return null; + } } } if (required) { @@ -294,8 +289,9 @@ public class RfbPlayer extends java.applet.Applet long result = defaultValue; if (str != null) { try { - result = Long.parseLong(str); - } catch (NumberFormatException e) { } + result = Long.parseLong(str); + } catch (NumberFormatException e) { + } } return result; } @@ -305,8 +301,9 @@ public class RfbPlayer extends java.applet.Applet double result = defaultValue; if (str != null) { try { - result = Double.valueOf(str).doubleValue(); - } catch (NumberFormatException e) { } + result = Double.valueOf(str).doubleValue(); + } catch (NumberFormatException e) { + } } return result; } @@ -314,23 +311,22 @@ public class RfbPlayer extends java.applet.Applet // // fatalError() - print out a fatal error message. // - public void fatalError(String str) { System.out.println(str); if (inAnApplet) { vncContainer.removeAll(); if (rfb != null) { - rfb = null; + rfb = null; } Label errLabel = new Label(str); errLabel.setFont(new Font("Helvetica", Font.PLAIN, 12)); vncContainer.setLayout(new FlowLayout(FlowLayout.LEFT, 30, 30)); vncContainer.add(errLabel); if (inSeparateFrame) { - vncFrame.pack(); + vncFrame.pack(); } else { - validate(); + validate(); } Thread.currentThread().stop(); } else { @@ -342,7 +338,6 @@ public class RfbPlayer extends java.applet.Applet // // This method is called before the applet is destroyed. // - public void destroy() { vncContainer.removeAll(); if (rfb != null) { @@ -357,7 +352,6 @@ public class RfbPlayer extends java.applet.Applet // // Close application properly on window close event. // - public void windowClosing(WindowEvent evt) { vncContainer.removeAll(); if (rfb != null) @@ -372,11 +366,22 @@ public class RfbPlayer extends java.applet.Applet // // Ignore window events we're not interested in. // + public void windowActivated(WindowEvent evt) { + } + + public void windowDeactivated(WindowEvent evt) { + } + + public void windowOpened(WindowEvent evt) { + } + + public void windowClosed(WindowEvent evt) { + } + + public void windowIconified(WindowEvent evt) { + } + + public void windowDeiconified(WindowEvent evt) { + } - public void windowActivated (WindowEvent evt) {} - public void windowDeactivated (WindowEvent evt) {} - public void windowOpened(WindowEvent evt) {} - public void windowClosed(WindowEvent evt) {} - public void windowIconified(WindowEvent evt) {} - public void windowDeiconified(WindowEvent evt) {} } diff --git a/java/src/com/tightvnc/rfbplayer/RfbProto.java b/java/src/com/tightvnc/rfbplayer/RfbProto.java index 58140120..e8a5042b 100644 --- a/java/src/com/tightvnc/rfbplayer/RfbProto.java +++ b/java/src/com/tightvnc/rfbplayer/RfbProto.java @@ -32,46 +32,36 @@ import java.net.*; class RfbProto { final String versionMsg = "RFB 003.003\n"; - final static int ConnFailed = 0, NoAuth = 1, VncAuth = 2; - final static int VncAuthOK = 0, VncAuthFailed = 1, VncAuthTooMany = 2; - - final static int FramebufferUpdate = 0, SetColourMapEntries = 1, Bell = 2, - ServerCutText = 3; - - final int SetPixelFormat = 0, FixColourMapEntries = 1, SetEncodings = 2, - FramebufferUpdateRequest = 3, KeyboardEvent = 4, PointerEvent = 5, - ClientCutText = 6; - - final static int - EncodingRaw = 0, - EncodingCopyRect = 1, - EncodingRRE = 2, - EncodingCoRRE = 4, - EncodingHextile = 5, - EncodingZlib = 6, - EncodingTight = 7, - EncodingCompressLevel0 = 0xFFFFFF00, - EncodingQualityLevel0 = 0xFFFFFFE0, - EncodingXCursor = 0xFFFFFF10, - EncodingRichCursor = 0xFFFFFF11, - EncodingLastRect = 0xFFFFFF20, - EncodingNewFBSize = 0xFFFFFF21; - - final int HextileRaw = (1 << 0); - final int HextileBackgroundSpecified = (1 << 1); - final int HextileForegroundSpecified = (1 << 2); - final int HextileAnySubrects = (1 << 3); - final int HextileSubrectsColoured = (1 << 4); - - final static int TightExplicitFilter = 0x04; - final static int TightFill = 0x08; - final static int TightJpeg = 0x09; - final static int TightMaxSubencoding = 0x09; - final static int TightFilterCopy = 0x00; - final static int TightFilterPalette = 0x01; - final static int TightFilterGradient = 0x02; - - final static int TightMinToCompress = 12; + final static int ConnFailed = 0, NoAuth = 1, VncAuth = 2; + final static int VncAuthOK = 0, VncAuthFailed = 1, VncAuthTooMany = 2; + + final static int FramebufferUpdate = 0, SetColourMapEntries = 1, Bell = 2, ServerCutText = + 3; + + final int SetPixelFormat = 0, FixColourMapEntries = 1, SetEncodings = 2, FramebufferUpdateRequest = + 3, KeyboardEvent = 4, PointerEvent = 5, ClientCutText = 6; + + final static int EncodingRaw = 0, EncodingCopyRect = 1, EncodingRRE = 2, EncodingCoRRE = + 4, EncodingHextile = 5, EncodingZlib = 6, EncodingTight = 7, EncodingCompressLevel0 = + 0xFFFFFF00, EncodingQualityLevel0 = 0xFFFFFFE0, EncodingXCursor = + 0xFFFFFF10, EncodingRichCursor = 0xFFFFFF11, EncodingLastRect = + 0xFFFFFF20, EncodingNewFBSize = 0xFFFFFF21; + + final int HextileRaw = (1 << 0); + final int HextileBackgroundSpecified = (1 << 1); + final int HextileForegroundSpecified = (1 << 2); + final int HextileAnySubrects = (1 << 3); + final int HextileSubrectsColoured = (1 << 4); + + final static int TightExplicitFilter = 0x04; + final static int TightFill = 0x08; + final static int TightJpeg = 0x09; + final static int TightMaxSubencoding = 0x09; + final static int TightFilterCopy = 0x00; + final static int TightFilterPalette = 0x01; + final static int TightFilterGradient = 0x02; + + final static int TightMinToCompress = 12; FbsInputStream fbs; DataInputStream is; @@ -80,7 +70,6 @@ class RfbProto { // // Constructor. // - RfbProto(URL url) throws Exception { fbs = null; newSession(url); @@ -89,7 +78,6 @@ class RfbProto { // // Open new session URL. // - public void newSession(URL url) throws Exception { if (fbs != null) fbs.close(); @@ -106,7 +94,6 @@ class RfbProto { // // Read server's protocol version message. // - int serverMajor, serverMinor; void readVersionMsg() throws IOException { @@ -115,12 +102,11 @@ class RfbProto { is.readFully(b); - if ((b[0] != 'R') || (b[1] != 'F') || (b[2] != 'B') || (b[3] != ' ') - || (b[4] < '0') || (b[4] > '9') || (b[5] < '0') || (b[5] > '9') - || (b[6] < '0') || (b[6] > '9') || (b[7] != '.') - || (b[8] < '0') || (b[8] > '9') || (b[9] < '0') || (b[9] > '9') - || (b[10] < '0') || (b[10] > '9') || (b[11] != '\n')) - { + if ((b[0] != 'R') || (b[1] != 'F') || (b[2] != 'B') || (b[3] != ' ') || + (b[4] < '0') || (b[4] > '9') || (b[5] < '0') || (b[5] > '9') || (b[6] < + '0') || (b[6] > '9') || (b[7] != '.') || (b[8] < '0') || (b[8] > '9') || + (b[9] < '0') || (b[9] > '9') || (b[10] < '0') || (b[10] > '9') || + (b[11] != '\n')) { throw new IOException("Incorrect protocol version"); } @@ -132,7 +118,6 @@ class RfbProto { // // Find out the authentication scheme. // - int readAuthScheme() throws IOException { int authScheme = is.readInt(); @@ -158,7 +143,6 @@ class RfbProto { // // Read the server initialisation message // - String desktopName; int framebufferWidth, framebufferHeight; int bitsPerPixel, depth; @@ -190,7 +174,6 @@ class RfbProto { // // Set new framebuffer size // - void setFramebufferSize(int width, int height) { framebufferWidth = width; framebufferHeight = height; @@ -200,7 +183,6 @@ class RfbProto { // // Read the server message type // - int readServerMessageType() throws IOException { return is.readUnsignedByte(); } @@ -209,7 +191,6 @@ class RfbProto { // // Read a FramebufferUpdate message // - int updateNRects; void readFramebufferUpdate() throws IOException { @@ -218,7 +199,6 @@ class RfbProto { } // Read a FramebufferUpdate rectangle header - int updateRectX, updateRectY, updateRectW, updateRectH, updateRectEncoding; void readFramebufferUpdateRectHdr() throws IOException { @@ -229,19 +209,18 @@ class RfbProto { updateRectEncoding = is.readInt(); if ((updateRectEncoding == EncodingLastRect) || - (updateRectEncoding == EncodingNewFBSize)) + (updateRectEncoding == EncodingNewFBSize)) return; if ((updateRectX + updateRectW > framebufferWidth) || - (updateRectY + updateRectH > framebufferHeight)) { + (updateRectY + updateRectH > framebufferHeight)) { throw new IOException("Framebuffer update rectangle too large: " + - updateRectW + "x" + updateRectH + " at (" + - updateRectX + "," + updateRectY + ")"); + updateRectW + "x" + updateRectH + " at (" + + updateRectX + "," + updateRectY + ")"); } } // Read CopyRect source X and Y. - int copyRectSrcX, copyRectSrcY; void readCopyRect() throws IOException { @@ -253,7 +232,6 @@ class RfbProto { // // Read a ServerCutText message // - String readServerCutText() throws IOException { byte[] pad = new byte[3]; is.readFully(pad); @@ -267,7 +245,6 @@ class RfbProto { // // Read integer in compact representation // - int readCompactLen() throws IOException { int portion = is.readUnsignedByte(); int len = portion & 0x7F; @@ -275,8 +252,8 @@ class RfbProto { portion = is.readUnsignedByte(); len |= (portion & 0x7F) << 7; if ((portion & 0x80) != 0) { - portion = is.readUnsignedByte(); - len |= (portion & 0xFF) << 14; + portion = is.readUnsignedByte(); + len |= (portion & 0xFF) << 14; } } return len; diff --git a/java/src/com/tightvnc/rfbplayer/VncCanvas.java b/java/src/com/tightvnc/rfbplayer/VncCanvas.java index 82720164..57bb8588 100644 --- a/java/src/com/tightvnc/rfbplayer/VncCanvas.java +++ b/java/src/com/tightvnc/rfbplayer/VncCanvas.java @@ -32,7 +32,6 @@ import java.util.zip.*; // // VncCanvas is a subclass of Canvas which draws a VNC desktop on it. // - class VncCanvas extends Canvas implements Observer { RfbPlayer player; @@ -69,7 +68,6 @@ class VncCanvas extends Canvas implements Observer { // // The constructor. // - VncCanvas(RfbPlayer player) throws IOException { this.player = player; rfb = player.rfb; @@ -83,7 +81,6 @@ class VncCanvas extends Canvas implements Observer { // // Callback methods to determine geometry of our Component. // - public Dimension getPreferredSize() { return new Dimension(rfb.framebufferWidth, rfb.framebufferHeight); } @@ -99,7 +96,6 @@ class VncCanvas extends Canvas implements Observer { // // All painting is performed here. // - public void update(Graphics g) { paint(g); } @@ -114,22 +110,21 @@ class VncCanvas extends Canvas implements Observer { // Override the ImageObserver interface method to handle drawing of // JPEG-encoded data. // - public boolean imageUpdate(Image img, int infoflags, - int x, int y, int width, int height) { + int x, int y, int width, int height) { if ((infoflags & (ALLBITS | ABORT)) == 0) { return true; // We need more image data. } else { // If the whole image is available, draw it now. if ((infoflags & ALLBITS) != 0) { - if (jpegRect != null) { - synchronized(jpegRect) { - memGraphics.drawImage(img, jpegRect.x, jpegRect.y, null); - scheduleRepaint(jpegRect.x, jpegRect.y, - jpegRect.width, jpegRect.height); - jpegRect.notify(); - } - } + if (jpegRect != null) { + synchronized(jpegRect) { + memGraphics.drawImage(img, jpegRect.x, jpegRect.y, null); + scheduleRepaint(jpegRect.x, jpegRect.y, + jpegRect.width, jpegRect.height); + jpegRect.notify(); + } + } } return false; // All image data was processed. } @@ -148,10 +143,10 @@ class VncCanvas extends Canvas implements Observer { memImage = player.createImage(fbWidth, fbHeight); memGraphics = memImage.getGraphics(); } else if (memImage.getWidth(null) != fbWidth || - memImage.getHeight(null) != fbHeight) { + memImage.getHeight(null) != fbHeight) { synchronized(memImage) { - memImage = player.createImage(fbWidth, fbHeight); - memGraphics = memImage.getGraphics(); + memImage = player.createImage(fbWidth, fbHeight); + memGraphics = memImage.getGraphics(); } } @@ -159,14 +154,14 @@ class VncCanvas extends Canvas implements Observer { // of geometry or pixel format. pixels24 = new int[fbWidth * fbHeight]; pixelsSource = - new MemoryImageSource(fbWidth, fbHeight, cm24, pixels24, 0, fbWidth); + new MemoryImageSource(fbWidth, fbHeight, cm24, pixels24, 0, fbWidth); pixelsSource.setAnimated(true); rawPixelsImage = createImage(pixelsSource); // Update the size of desktop containers. if (player.inSeparateFrame) { if (player.desktopScrollPane != null) - resizeDesktopFrame(); + resizeDesktopFrame(); } else { setSize(fbWidth, fbHeight); } @@ -179,9 +174,9 @@ class VncCanvas extends Canvas implements Observer { // ScrollPane. -- const Insets insets = player.desktopScrollPane.getInsets(); player.desktopScrollPane.setSize(rfb.framebufferWidth + - 2 * Math.min(insets.left, insets.right), - rfb.framebufferHeight + - 2 * Math.min(insets.top, insets.bottom)); + 2 * Math.min(insets.left, insets.right), + rfb.framebufferHeight + + 2 * Math.min(insets.top, insets.bottom)); player.vncFrame.pack(); @@ -209,7 +204,6 @@ class VncCanvas extends Canvas implements Observer { // processNormalProtocol() - executed by the rfbThread to deal with // the RFB data. // - public void processNormalProtocol() throws Exception { zlibInflater = new Inflater(); @@ -230,70 +224,70 @@ class VncCanvas extends Canvas implements Observer { switch (msgType) { case RfbProto.FramebufferUpdate: - rfb.readFramebufferUpdate(); - - for (int i = 0; i < rfb.updateNRects; i++) { - rfb.readFramebufferUpdateRectHdr(); - int rx = rfb.updateRectX, ry = rfb.updateRectY; - int rw = rfb.updateRectW, rh = rfb.updateRectH; - - if (rfb.updateRectEncoding == rfb.EncodingLastRect) - break; - - if (rfb.updateRectEncoding == rfb.EncodingNewFBSize) { - rfb.setFramebufferSize(rfb.updateRectW, rfb.updateRectH); - updateFramebufferSize(); - break; - } - - if (rfb.updateRectEncoding == rfb.EncodingXCursor || - rfb.updateRectEncoding == rfb.EncodingRichCursor) { - throw new Exception("Sorry, no support for" + - " cursor shape updates yet"); - } - - switch (rfb.updateRectEncoding) { - case RfbProto.EncodingRaw: - handleRawRect(rx, ry, rw, rh); - break; - case RfbProto.EncodingCopyRect: - handleCopyRect(rx, ry, rw, rh); - break; - case RfbProto.EncodingRRE: - handleRRERect(rx, ry, rw, rh); - break; - case RfbProto.EncodingCoRRE: - handleCoRRERect(rx, ry, rw, rh); - break; - case RfbProto.EncodingHextile: - handleHextileRect(rx, ry, rw, rh); - break; - case RfbProto.EncodingZlib: + rfb.readFramebufferUpdate(); + + for (int i = 0; i < rfb.updateNRects; i++) { + rfb.readFramebufferUpdateRectHdr(); + int rx = rfb.updateRectX, ry = rfb.updateRectY; + int rw = rfb.updateRectW, rh = rfb.updateRectH; + + if (rfb.updateRectEncoding == rfb.EncodingLastRect) + break; + + if (rfb.updateRectEncoding == rfb.EncodingNewFBSize) { + rfb.setFramebufferSize(rfb.updateRectW, rfb.updateRectH); + updateFramebufferSize(); + break; + } + + if (rfb.updateRectEncoding == rfb.EncodingXCursor || + rfb.updateRectEncoding == rfb.EncodingRichCursor) { + throw new Exception("Sorry, no support for" + + " cursor shape updates yet"); + } + + switch (rfb.updateRectEncoding) { + case RfbProto.EncodingRaw: + handleRawRect(rx, ry, rw, rh); + break; + case RfbProto.EncodingCopyRect: + handleCopyRect(rx, ry, rw, rh); + break; + case RfbProto.EncodingRRE: + handleRRERect(rx, ry, rw, rh); + break; + case RfbProto.EncodingCoRRE: + handleCoRRERect(rx, ry, rw, rh); + break; + case RfbProto.EncodingHextile: + handleHextileRect(rx, ry, rw, rh); + break; + case RfbProto.EncodingZlib: handleZlibRect(rx, ry, rw, rh); - break; - case RfbProto.EncodingTight: - handleTightRect(rx, ry, rw, rh); - break; - default: - throw new Exception("Unknown RFB rectangle encoding " + - rfb.updateRectEncoding); - } - } - break; + break; + case RfbProto.EncodingTight: + handleTightRect(rx, ry, rw, rh); + break; + default: + throw new Exception("Unknown RFB rectangle encoding " + + rfb.updateRectEncoding); + } + } + break; case RfbProto.SetColourMapEntries: - throw new Exception("Can't handle SetColourMapEntries message"); + throw new Exception("Can't handle SetColourMapEntries message"); case RfbProto.Bell: Toolkit.getDefaultToolkit().beep(); - break; + break; case RfbProto.ServerCutText: - String s = rfb.readServerCutText(); - break; + String s = rfb.readServerCutText(); + break; default: - throw new Exception("Unknown RFB message type " + msgType); + throw new Exception("Unknown RFB message type " + msgType); } player.updatePos(); @@ -304,7 +298,6 @@ class VncCanvas extends Canvas implements Observer { // // Handle a raw rectangle. // - void handleRawRect(int x, int y, int w, int h) throws IOException { byte[] buf = new byte[w * 4]; @@ -313,10 +306,10 @@ class VncCanvas extends Canvas implements Observer { rfb.is.readFully(buf); offset = dy * rfb.framebufferWidth + x; for (i = 0; i < w; i++) { - pixels24[offset + i] = - (buf[i * 4 + 2] & 0xFF) << 16 | - (buf[i * 4 + 1] & 0xFF) << 8 | - (buf[i * 4] & 0xFF); + pixels24[offset + i] = + (buf[i * 4 + 2] & 0xFF) << 16 | + (buf[i * 4 + 1] & 0xFF) << 8 | + (buf[i * 4] & 0xFF); } } @@ -328,12 +321,11 @@ class VncCanvas extends Canvas implements Observer { // // Handle a CopyRect rectangle. // - void handleCopyRect(int x, int y, int w, int h) throws IOException { rfb.readCopyRect(); memGraphics.copyArea(rfb.copyRectSrcX, rfb.copyRectSrcY, w, h, - x - rfb.copyRectSrcX, y - rfb.copyRectSrcY); + x - rfb.copyRectSrcX, y - rfb.copyRectSrcY); scheduleRepaint(x, y, w, h); } @@ -341,7 +333,6 @@ class VncCanvas extends Canvas implements Observer { // // Handle an RRE-encoded rectangle. // - void handleRRERect(int x, int y, int w, int h) throws IOException { int nSubrects = rfb.is.readInt(); @@ -371,7 +362,6 @@ class VncCanvas extends Canvas implements Observer { // // Handle a CoRRE-encoded rectangle. // - void handleCoRRERect(int x, int y, int w, int h) throws IOException { int nSubrects = rfb.is.readInt(); @@ -403,7 +393,7 @@ class VncCanvas extends Canvas implements Observer { // // These colors should be kept between handleHextileSubrect() calls. - private Color hextile_bg, hextile_fg; + private Color hextile_bg, hextile_fg; void handleHextileRect(int x, int y, int w, int h) throws IOException { @@ -413,14 +403,14 @@ class VncCanvas extends Canvas implements Observer { for (int ty = y; ty < y + h; ty += 16) { int th = 16; if (y + h - ty < 16) - th = y + h - ty; + th = y + h - ty; for (int tx = x; tx < x + w; tx += 16) { - int tw = 16; - if (x + w - tx < 16) - tw = x + w - tx; + int tw = 16; + if (x + w - tx < 16) + tw = x + w - tx; - handleHextileSubrect(tx, ty, tw, th); + handleHextileSubrect(tx, ty, tw, th); } // Finished with a row of tiles, now let's show it. @@ -431,9 +421,8 @@ class VncCanvas extends Canvas implements Observer { // // Handle one tile in the Hextile-encoded data. // - void handleHextileSubrect(int tx, int ty, int tw, int th) - throws IOException { + throws IOException { byte[] buf = new byte[256 * 4]; @@ -443,14 +432,14 @@ class VncCanvas extends Canvas implements Observer { if ((subencoding & rfb.HextileRaw) != 0) { int count, offset; for (int j = ty; j < ty + th; j++) { - rfb.is.readFully(buf, 0, tw * 4); - offset = j * rfb.framebufferWidth + tx; - for (count = 0; count < tw; count++) { - pixels24[offset + count] = - (buf[count * 4 + 2] & 0xFF) << 16 | - (buf[count * 4 + 1] & 0xFF) << 8 | - (buf[count * 4] & 0xFF); - } + rfb.is.readFully(buf, 0, tw * 4); + offset = j * rfb.framebufferWidth + tx; + for (count = 0; count < tw; count++) { + pixels24[offset + count] = + (buf[count * 4 + 2] & 0xFF) << 16 | + (buf[count * 4 + 1] & 0xFF) << 8 | + (buf[count * 4] & 0xFF); + } } handleUpdatedPixels(tx, ty, tw, th); return; @@ -479,27 +468,27 @@ class VncCanvas extends Canvas implements Observer { int b1, b2, sx, sy, sw, sh; if ((subencoding & rfb.HextileSubrectsColoured) != 0) { for (int j = 0; j < nSubrects; j++) { - rfb.is.readFully(buf, 0, 4); - hextile_fg = new Color(buf[2] & 0xFF, buf[1] & 0xFF, buf[0] & 0xFF); - b1 = rfb.is.readUnsignedByte(); - b2 = rfb.is.readUnsignedByte(); - sx = tx + (b1 >> 4); - sy = ty + (b1 & 0xf); - sw = (b2 >> 4) + 1; - sh = (b2 & 0xf) + 1; - memGraphics.setColor(hextile_fg); - memGraphics.fillRect(sx, sy, sw, sh); + rfb.is.readFully(buf, 0, 4); + hextile_fg = new Color(buf[2] & 0xFF, buf[1] & 0xFF, buf[0] & 0xFF); + b1 = rfb.is.readUnsignedByte(); + b2 = rfb.is.readUnsignedByte(); + sx = tx + (b1 >> 4); + sy = ty + (b1 & 0xf); + sw = (b2 >> 4) + 1; + sh = (b2 & 0xf) + 1; + memGraphics.setColor(hextile_fg); + memGraphics.fillRect(sx, sy, sw, sh); } } else { memGraphics.setColor(hextile_fg); for (int j = 0; j < nSubrects; j++) { - b1 = rfb.is.readUnsignedByte(); - b2 = rfb.is.readUnsignedByte(); - sx = tx + (b1 >> 4); - sy = ty + (b1 & 0xf); - sw = (b2 >> 4) + 1; - sh = (b2 & 0xf) + 1; - memGraphics.fillRect(sx, sy, sw, sh); + b1 = rfb.is.readUnsignedByte(); + b2 = rfb.is.readUnsignedByte(); + sx = tx + (b1 >> 4); + sy = ty + (b1 & 0xf); + sw = (b2 >> 4) + 1; + sh = (b2 & 0xf) + 1; + memGraphics.fillRect(sx, sy, sw, sh); } } } @@ -507,7 +496,6 @@ class VncCanvas extends Canvas implements Observer { // // Handle a Zlib-encoded rectangle. // - void handleZlibRect(int x, int y, int w, int h) throws Exception { int nBytes = rfb.is.readInt(); @@ -524,17 +512,16 @@ class VncCanvas extends Canvas implements Observer { byte[] buf = new byte[w * 4]; int i, offset; for (int dy = y; dy < y + h; dy++) { - zlibInflater.inflate(buf); - offset = dy * rfb.framebufferWidth + x; - for (i = 0; i < w; i++) { - pixels24[offset + i] = - (buf[i * 4 + 2] & 0xFF) << 16 | - (buf[i * 4 + 1] & 0xFF) << 8 | - (buf[i * 4] & 0xFF); - } + zlibInflater.inflate(buf); + offset = dy * rfb.framebufferWidth + x; + for (i = 0; i < w; i++) { + pixels24[offset + i] = + (buf[i * 4 + 2] & 0xFF) << 16 | + (buf[i * 4 + 1] & 0xFF) << 8 | + (buf[i * 4] & 0xFF); + } } - } - catch (DataFormatException dfe) { + } catch (DataFormatException dfe) { throw new Exception(dfe.toString()); } @@ -545,7 +532,6 @@ class VncCanvas extends Canvas implements Observer { // // Handle a Tight-encoded rectangle. // - void handleTightRect(int x, int y, int w, int h) throws Exception { int comp_ctl = rfb.is.readUnsignedByte(); @@ -553,7 +539,7 @@ class VncCanvas extends Canvas implements Observer { // Flush zlib streams if we are told by the server to do so. for (int stream_id = 0; stream_id < 4; stream_id++) { if ((comp_ctl & 1) != 0 && tightInflaters[stream_id] != null) { - tightInflaters[stream_id] = null; + tightInflaters[stream_id] = null; } comp_ctl >>= 1; } @@ -589,13 +575,13 @@ class VncCanvas extends Canvas implements Observer { // Let the imageUpdate() method do the actual drawing, here just // wait until the image is fully loaded and drawn. synchronized(jpegRect) { - Toolkit.getDefaultToolkit().prepareImage(jpegImage, -1, -1, this); - try { - // Wait no longer than three seconds. - jpegRect.wait(3000); - } catch (InterruptedException e) { - throw new Exception("Interrupted while decoding JPEG image"); - } + Toolkit.getDefaultToolkit().prepareImage(jpegImage, -1, -1, this); + try { + // Wait no longer than three seconds. + jpegRect.wait(3000); + } catch (InterruptedException e) { + throw new Exception("Interrupted while decoding JPEG image"); + } } // Done, jpegRect is not needed any more. @@ -612,20 +598,20 @@ class VncCanvas extends Canvas implements Observer { if ((comp_ctl & rfb.TightExplicitFilter) != 0) { int filter_id = rfb.is.readUnsignedByte(); if (filter_id == rfb.TightFilterPalette) { - numColors = rfb.is.readUnsignedByte() + 1; - byte[] buf = new byte[numColors * 3]; - rfb.is.readFully(buf); - for (int i = 0; i < numColors; i++) { - palette24[i] = ((buf[i * 3] & 0xFF) << 16 | - (buf[i * 3 + 1] & 0xFF) << 8 | - (buf[i * 3 + 2] & 0xFF)); - } - if (numColors == 2) - rowSize = (w + 7) / 8; + numColors = rfb.is.readUnsignedByte() + 1; + byte[] buf = new byte[numColors * 3]; + rfb.is.readFully(buf); + for (int i = 0; i < numColors; i++) { + palette24[i] = ((buf[i * 3] & 0xFF) << 16 | + (buf[i * 3 + 1] & 0xFF) << 8 | + (buf[i * 3 + 2] & 0xFF)); + } + if (numColors == 2) + rowSize = (w + 7) / 8; } else if (filter_id == rfb.TightFilterGradient) { - useGradient = true; + useGradient = true; } else if (filter_id != rfb.TightFilterCopy) { - throw new Exception("Incorrect tight filter id: " + filter_id); + throw new Exception("Incorrect tight filter id: " + filter_id); } } if (numColors == 0) @@ -636,41 +622,41 @@ class VncCanvas extends Canvas implements Observer { if (dataSize < rfb.TightMinToCompress) { // Data size is small - not compressed with zlib. if (numColors != 0) { - // Indexed colors. - byte[] indexedData = new byte[dataSize]; - rfb.is.readFully(indexedData); - if (numColors == 2) { - // Two colors. - decodeMonoData(x, y, w, h, indexedData, palette24); - } else { - // 3..255 colors. - int i = 0; - for (int dy = y; dy < y + h; dy++) { - for (int dx = x; dx < x + w; dx++) { - pixels24[dy * rfb.framebufferWidth + dx] = - palette24[indexedData[i++] & 0xFF]; - } - } - } + // Indexed colors. + byte[] indexedData = new byte[dataSize]; + rfb.is.readFully(indexedData); + if (numColors == 2) { + // Two colors. + decodeMonoData(x, y, w, h, indexedData, palette24); + } else { + // 3..255 colors. + int i = 0; + for (int dy = y; dy < y + h; dy++) { + for (int dx = x; dx < x + w; dx++) { + pixels24[dy * rfb.framebufferWidth + dx] = + palette24[indexedData[i++] & 0xFF]; + } + } + } } else if (useGradient) { - // "Gradient"-processed data - byte[] buf = new byte[w * h * 3]; - rfb.is.readFully(buf); - decodeGradientData(x, y, w, h, buf); + // "Gradient"-processed data + byte[] buf = new byte[w * h * 3]; + rfb.is.readFully(buf); + decodeGradientData(x, y, w, h, buf); } else { - // Raw truecolor data. - byte[] buf = new byte[w * 3]; - int i, offset; - for (int dy = y; dy < y + h; dy++) { - rfb.is.readFully(buf); - offset = dy * rfb.framebufferWidth + x; - for (i = 0; i < w; i++) { - pixels24[offset + i] = - (buf[i * 3] & 0xFF) << 16 | - (buf[i * 3 + 1] & 0xFF) << 8 | - (buf[i * 3 + 2] & 0xFF); - } - } + // Raw truecolor data. + byte[] buf = new byte[w * 3]; + int i, offset; + for (int dy = y; dy < y + h; dy++) { + rfb.is.readFully(buf); + offset = dy * rfb.framebufferWidth + x; + for (i = 0; i < w; i++) { + pixels24[offset + i] = + (buf[i * 3] & 0xFF) << 16 | + (buf[i * 3 + 1] & 0xFF) << 8 | + (buf[i * 3 + 2] & 0xFF); + } + } } } else { // Data was compressed with zlib. @@ -679,51 +665,50 @@ class VncCanvas extends Canvas implements Observer { rfb.is.readFully(zlibData); int stream_id = comp_ctl & 0x03; if (tightInflaters[stream_id] == null) { - tightInflaters[stream_id] = new Inflater(); + tightInflaters[stream_id] = new Inflater(); } Inflater myInflater = tightInflaters[stream_id]; myInflater.setInput(zlibData); try { - if (numColors != 0) { - // Indexed colors. - byte[] indexedData = new byte[dataSize]; - myInflater.inflate(indexedData); - if (numColors == 2) { - // Two colors. - decodeMonoData(x, y, w, h, indexedData, palette24); - } else { - // More than two colors. - int i = 0; - for (int dy = y; dy < y + h; dy++) { - for (int dx = x; dx < x + w; dx++) { - pixels24[dy * rfb.framebufferWidth + dx] = - palette24[indexedData[i++] & 0xFF]; - } - } - } - } else if (useGradient) { - // Compressed "Gradient"-filtered data. - byte[] buf = new byte[w * h * 3]; - myInflater.inflate(buf); - decodeGradientData(x, y, w, h, buf); - } else { - // Compressed truecolor data. - byte[] buf = new byte[w * 3]; - int i, offset; - for (int dy = y; dy < y + h; dy++) { - myInflater.inflate(buf); - offset = dy * rfb.framebufferWidth + x; - for (i = 0; i < w; i++) { - pixels24[offset + i] = - (buf[i * 3] & 0xFF) << 16 | - (buf[i * 3 + 1] & 0xFF) << 8 | - (buf[i * 3 + 2] & 0xFF); - } - } - } - } - catch(DataFormatException dfe) { - throw new Exception(dfe.toString()); + if (numColors != 0) { + // Indexed colors. + byte[] indexedData = new byte[dataSize]; + myInflater.inflate(indexedData); + if (numColors == 2) { + // Two colors. + decodeMonoData(x, y, w, h, indexedData, palette24); + } else { + // More than two colors. + int i = 0; + for (int dy = y; dy < y + h; dy++) { + for (int dx = x; dx < x + w; dx++) { + pixels24[dy * rfb.framebufferWidth + dx] = + palette24[indexedData[i++] & 0xFF]; + } + } + } + } else if (useGradient) { + // Compressed "Gradient"-filtered data. + byte[] buf = new byte[w * h * 3]; + myInflater.inflate(buf); + decodeGradientData(x, y, w, h, buf); + } else { + // Compressed truecolor data. + byte[] buf = new byte[w * 3]; + int i, offset; + for (int dy = y; dy < y + h; dy++) { + myInflater.inflate(buf); + offset = dy * rfb.framebufferWidth + x; + for (i = 0; i < w; i++) { + pixels24[offset + i] = + (buf[i * 3] & 0xFF) << 16 | + (buf[i * 3 + 1] & 0xFF) << 8 | + (buf[i * 3 + 2] & 0xFF); + } + } + } + } catch (DataFormatException dfe) { + throw new Exception(dfe.toString()); } } @@ -734,7 +719,6 @@ class VncCanvas extends Canvas implements Observer { // // Decode 1bpp-encoded bi-color rectangle. // - void decodeMonoData(int x, int y, int w, int h, byte[] src, int[] palette) { int dx, dy, n; @@ -744,12 +728,12 @@ class VncCanvas extends Canvas implements Observer { for (dy = 0; dy < h; dy++) { for (dx = 0; dx < w / 8; dx++) { - b = src[dy*rowBytes+dx]; - for (n = 7; n >= 0; n--) - pixels24[i++] = palette[b >> n & 1]; + b = src[dy * rowBytes + dx]; + for (n = 7; n >= 0; n--) + pixels24[i++] = palette[b >> n & 1]; } for (n = 7; n >= 8 - w % 8; n--) { - pixels24[i++] = palette[src[dy*rowBytes+dx] >> n & 1]; + pixels24[i++] = palette[src[dy * rowBytes + dx] >> n & 1]; } i += (rfb.framebufferWidth - w); } @@ -758,8 +742,7 @@ class VncCanvas extends Canvas implements Observer { // // Decode data processed with the "Gradient" filter. // - - void decodeGradientData (int x, int y, int w, int h, byte[] buf) { + void decodeGradientData(int x, int y, int w, int h, byte[] buf) { int dx, dy, c; byte[] prevRow = new byte[w * 3]; @@ -773,27 +756,27 @@ class VncCanvas extends Canvas implements Observer { /* First pixel in a row */ for (c = 0; c < 3; c++) { - pix[c] = (byte)(prevRow[c] + buf[dy * w * 3 + c]); - thisRow[c] = pix[c]; + pix[c] = (byte)(prevRow[c] + buf[dy * w * 3 + c]); + thisRow[c] = pix[c]; } pixels24[offset++] = - (pix[0] & 0xFF) << 16 | (pix[1] & 0xFF) << 8 | (pix[2] & 0xFF); + (pix[0] & 0xFF) << 16 | (pix[1] & 0xFF) << 8 | (pix[2] & 0xFF); /* Remaining pixels of a row */ for (dx = 1; dx < w; dx++) { - for (c = 0; c < 3; c++) { - est[c] = ((prevRow[dx * 3 + c] & 0xFF) + (pix[c] & 0xFF) - - (prevRow[(dx-1) * 3 + c] & 0xFF)); - if (est[c] > 0xFF) { - est[c] = 0xFF; - } else if (est[c] < 0x00) { - est[c] = 0x00; - } - pix[c] = (byte)(est[c] + buf[(dy * w + dx) * 3 + c]); - thisRow[dx * 3 + c] = pix[c]; - } - pixels24[offset++] = - (pix[0] & 0xFF) << 16 | (pix[1] & 0xFF) << 8 | (pix[2] & 0xFF); + for (c = 0; c < 3; c++) { + est[c] = ((prevRow[dx * 3 + c] & 0xFF) + (pix[c] & 0xFF) - + (prevRow[(dx - 1) * 3 + c] & 0xFF)); + if (est[c] > 0xFF) { + est[c] = 0xFF; + } else if (est[c] < 0x00) { + est[c] = 0x00; + } + pix[c] = (byte)(est[c] + buf[(dy * w + dx) * 3 + c]); + thisRow[dx * 3 + c] = pix[c]; + } + pixels24[offset++] = + (pix[0] & 0xFF) << 16 | (pix[1] & 0xFF) << 8 | (pix[2] & 0xFF); } System.arraycopy(thisRow, 0, prevRow, 0, w * 3); @@ -805,7 +788,6 @@ class VncCanvas extends Canvas implements Observer { // // Display newly updated area of pixels. // - void handleUpdatedPixels(int x, int y, int w, int h) { // Draw updated pixels of the off-screen image. @@ -819,18 +801,17 @@ class VncCanvas extends Canvas implements Observer { // // Tell JVM to repaint specified desktop area. // - void scheduleRepaint(int x, int y, int w, int h) { if (rfb.fbs.isSeeking()) { // Do nothing, and remember we are seeking. seekMode = true; } else { if (seekMode) { - // Immediate repaint of the whole desktop after seeking. - repaint(); + // Immediate repaint of the whole desktop after seeking. + repaint(); } else { - // Usual incremental repaint. - repaint(player.deferScreenUpdates, x, y, w, h); + // Usual incremental repaint. + repaint(player.deferScreenUpdates, x, y, w, h); } seekMode = false; } @@ -841,7 +822,6 @@ class VncCanvas extends Canvas implements Observer { // switching to the `paused' mode. In such cases we want to repaint // our desktop if we were seeking. // - public void update(Observable o, Object arg) { // Immediate repaint of the whole desktop after seeking. repaint();