Brian Hinz | b213da6 | 2012-04-11 22:00:55 +0000 | [diff] [blame^] | 1 | /* Copyright (C) 2012 Brian P. Hinz |
Brian Hinz | 28aa3a8 | 2012-04-05 02:08:49 +0000 | [diff] [blame] | 2 | * |
| 3 | * This is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License as published by |
| 5 | * the Free Software Foundation; either version 2 of the License, or |
| 6 | * (at your option) any later version. |
| 7 | * |
| 8 | * This software is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this software; if not, write to the Free Software |
Brian Hinz | b213da6 | 2012-04-11 22:00:55 +0000 | [diff] [blame^] | 15 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, |
Brian Hinz | 28aa3a8 | 2012-04-05 02:08:49 +0000 | [diff] [blame] | 16 | * USA. |
| 17 | */ |
| 18 | |
| 19 | package com.tigervnc.vncviewer; |
| 20 | |
| 21 | import java.awt.*; |
| 22 | import java.awt.image.*; |
| 23 | |
| 24 | import com.tigervnc.rfb.*; |
| 25 | import com.tigervnc.rfb.Exception; |
| 26 | |
| 27 | public class BIPixelBuffer extends PlatformPixelBuffer |
| 28 | { |
| 29 | public BIPixelBuffer(int w, int h, CConn cc_, DesktopWindow desktop_) { |
| 30 | super(w, h, cc_, desktop_); |
| 31 | } |
| 32 | |
| 33 | // resize() resizes the image, preserving the image data where possible. |
| 34 | public void resize(int w, int h) { |
| 35 | if (w == width() && h == height()) return; |
| 36 | |
| 37 | width_ = w; |
| 38 | height_ = h; |
| 39 | GraphicsEnvironment ge = |
| 40 | GraphicsEnvironment.getLocalGraphicsEnvironment(); |
| 41 | GraphicsDevice gd = ge.getDefaultScreenDevice(); |
| 42 | GraphicsConfiguration gc = gd.getDefaultConfiguration(); |
| 43 | image = gc.createCompatibleImage(w, h, Transparency.OPAQUE); |
| 44 | image.setAccelerationPriority(1); |
| 45 | image.createGraphics(); |
| 46 | } |
| 47 | |
| 48 | public void fillRect(int x, int y, int w, int h, int pix) { |
| 49 | Graphics2D graphics = (Graphics2D)image.getGraphics(); |
| 50 | switch (format.depth) { |
| 51 | case 24: |
| 52 | graphics.setColor(new Color(pix)); |
| 53 | graphics.fillRect(x, y, w, h); |
| 54 | break; |
| 55 | default: |
| 56 | Color color = new Color((0xff << 24) | (cm.getRed(pix) << 16) | |
| 57 | (cm.getGreen(pix) << 8) | (cm.getBlue(pix))); |
| 58 | graphics.setColor(color); |
| 59 | graphics.fillRect(x, y, w, h); |
| 60 | break; |
| 61 | } |
| 62 | graphics.dispose(); |
| 63 | } |
| 64 | |
| 65 | public void imageRect(int x, int y, int w, int h, Object pix) { |
| 66 | Graphics2D graphics = (Graphics2D)image.getGraphics(); |
| 67 | Image img; |
| 68 | if (pix instanceof Image) { |
| 69 | img = (Image)pix; |
| 70 | } else { |
| 71 | img = tk.createImage(new MemoryImageSource(w, h, cm, (int[])pix, 0, w)); |
| 72 | img.setAccelerationPriority(1); |
| 73 | } |
| 74 | boolean ret = tk.prepareImage(img, -1, -1, null); |
| 75 | if (!ret) { |
| 76 | while ((tk.checkImage(img, -1, -1, null) & ImageObserver.ALLBITS) == 0) { |
| 77 | synchronized (this) { |
| 78 | try { |
| 79 | this.wait(0, 10000); |
| 80 | } catch (InterruptedException e) { |
| 81 | throw new Exception("Error decoding JPEG data"); |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | graphics.drawImage(img, x, y, w, h, null); |
| 87 | graphics.dispose(); |
| 88 | img.flush(); |
| 89 | } |
| 90 | |
| 91 | public void copyRect(int x, int y, int w, int h, int srcX, int srcY) { |
| 92 | Graphics2D graphics = (Graphics2D)image.getGraphics(); |
| 93 | graphics.copyArea(srcX, srcY, w, h, x - srcX, y - srcY); |
| 94 | graphics.dispose(); |
| 95 | } |
| 96 | |
| 97 | public Image getImage() { |
| 98 | return (Image)image; |
| 99 | } |
| 100 | |
| 101 | BufferedImage image; |
| 102 | |
| 103 | static LogWriter vlog = new LogWriter("BIPixelBuffer"); |
| 104 | } |