Revision: 4844
          http://tigervnc.svn.sourceforge.net/tigervnc/?rev=4844&view=rev
Author:   bphinz
Date:     2012-02-05 21:46:32 +0000 (Sun, 05 Feb 2012)
Log Message:
-----------
Improved Tight JPEG decode time by ~25% using PixelGrabber rather than getting 
each pixel manually.

Modified Paths:
--------------
    trunk/java/com/tigervnc/rfb/TightDecoder.java

Modified: trunk/java/com/tigervnc/rfb/TightDecoder.java
===================================================================
--- trunk/java/com/tigervnc/rfb/TightDecoder.java       2012-02-05 13:51:58 UTC 
(rev 4843)
+++ trunk/java/com/tigervnc/rfb/TightDecoder.java       2012-02-05 21:46:32 UTC 
(rev 4844)
@@ -22,10 +22,9 @@
 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 @@
   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 @@
     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);
   }

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Tigervnc-commits mailing list
Tigervnc-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tigervnc-commits

Reply via email to