]> source.dussan.org Git - tigervnc.git/commitdiff
Partial fix for java viewer performance regression
authorBrian P. Hinz <bphinz@users.sf.net>
Wed, 5 Apr 2017 01:10:00 +0000 (21:10 -0400)
committerBrian P. Hinz <bphinz@users.sf.net>
Wed, 5 Apr 2017 01:17:03 +0000 (21:17 -0400)
java/com/tigervnc/rfb/JpegDecompressor.java

index 9137847cb8202942e6c33cbbd01db83874b5ba51..c263736b598c9c94590bfe2e44080cb2b415cc2b 100644 (file)
@@ -17,6 +17,7 @@
  */
 package com.tigervnc.rfb;
 
+import java.awt.*;
 import java.awt.image.*;
 import java.io.*;
 import java.nio.ByteBuffer;
@@ -35,17 +36,16 @@ public class JpegDecompressor {
 
     jpegBuf.get(src);
     try {
-      BufferedImage image =
+      ImageIO.setUseCache(false);
+      BufferedImage jpeg =
         ImageIO.read(new MemoryCacheImageInputStream(new ByteArrayInputStream(src)));
       ColorModel cm = pf.getColorModel();
-      if (cm.isCompatibleRaster(image.getRaster()) &&
-          cm.isCompatibleSampleModel(image.getRaster().getSampleModel())) {
-        buf.setDataElements(0, 0, image.getRaster());
-      } else {
-        ColorConvertOp converter = pf.getColorConvertOp(cm.getColorSpace());
-        converter.filter(image.getRaster(), buf);
-      }
+      BufferedImage image = new BufferedImage(cm, buf, true, null);
+      Graphics2D g2 = image.createGraphics();
+      g2.drawImage(jpeg, 0, 0, null);
+      g2.dispose();
       image.flush();
+      jpeg.flush();
     } catch (IOException e) {
       throw new Exception(e.getMessage());
     }