diff options
author | Brian Hinz <bphinz@users.sourceforge.net> | 2012-02-05 21:46:32 +0000 |
---|---|---|
committer | Brian Hinz <bphinz@users.sourceforge.net> | 2012-02-05 21:46:32 +0000 |
commit | c4053bb0de4fd3cd2a1c4b204a066140edfe0651 (patch) | |
tree | 5b29fcd4aace206777b23b2b0eaea27ccd1612e8 /java | |
parent | 3217fec049cb2bf9ffc4af37c2c4a6e7a1c81863 (diff) | |
download | tigervnc-c4053bb0de4fd3cd2a1c4b204a066140edfe0651.tar.gz tigervnc-c4053bb0de4fd3cd2a1c4b204a066140edfe0651.zip |
Improved Tight JPEG decode time by ~25% using PixelGrabber rather than getting each pixel manually.
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4844 3789f03b-4d11-0410-bbf8-ca57d06f2519
Diffstat (limited to 'java')
-rw-r--r-- | java/com/tigervnc/rfb/TightDecoder.java | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/java/com/tigervnc/rfb/TightDecoder.java b/java/com/tigervnc/rfb/TightDecoder.java index 3e894c0b..cfc259e5 100644 --- a/java/com/tigervnc/rfb/TightDecoder.java +++ b/java/com/tigervnc/rfb/TightDecoder.java @@ -22,10 +22,9 @@ package com.tigervnc.rfb; import com.tigervnc.rdr.InStream; import com.tigervnc.rdr.ZlibInStream; import java.util.ArrayList; -import java.awt.image.BufferedImage; -import java.io.ByteArrayInputStream; -import javax.imageio.ImageIO; import java.io.InputStream; +import java.awt.image.PixelGrabber; +import java.awt.*; public class TightDecoder extends Decoder { @@ -43,6 +42,8 @@ public class TightDecoder extends Decoder { final static int rfbTightFilterGradient = 0x02; final static int rfbTightMinToCompress = 12; + final static Toolkit tk = Toolkit.getDefaultToolkit(); + public TightDecoder(CMsgReader reader_) { reader = reader_; zis = new ZlibInStream[4]; @@ -247,26 +248,19 @@ public class TightDecoder extends Decoder { is.readBytes(netbuf, 0, compressedLen); // Create an Image object from the JPEG data. - int imageType = BufferedImage.TYPE_4BYTE_ABGR_PRE; + Image jpeg = tk.createImage(netbuf); int w = r.width(); int h = r.height(); - BufferedImage jpeg = - new BufferedImage(w, h, imageType); - jpeg.setAccelerationPriority(1); - try { - jpeg = ImageIO.read(new ByteArrayInputStream(netbuf)); - } catch (java.io.IOException e) { - e.printStackTrace(); - } + int[] buf = reader.getImageBuf(w*h); - int[] pix = new int[3]; - for (int y=0; y < h; y++) { - for (int x=0; x < w; x++) { - jpeg.getRaster().getPixel(x, y, pix); - buf[y*w+x] = (0xff << 24) | (pix[0] & 0xff) << 16 | (pix[1] & 0xff) << 8 | pix[2]; - } - } + PixelGrabber pg = new PixelGrabber(jpeg, 0, 0, w, h, buf, 0, w); + try { + pg.grabPixels(0); + } catch (InterruptedException e) { + System.out.println("Tight Decoding: Wrong JPEG data received."); + } + jpeg.flush(); handler.imageRect(r, buf); } |