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