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