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
|
/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
* Copyright (C) 2011-2012 TigerVNC Team.
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*/
package com.tigervnc.vncviewer;
import java.awt.*;
import java.awt.image.*;
import com.tigervnc.rfb.*;
import com.tigervnc.rfb.Exception;
public class AWTPixelBuffer extends PlatformPixelBuffer
{
public AWTPixelBuffer(int w, int h, CConn cc_, DesktopWindow desktop_) {
super(w, h, cc_, desktop_);
}
public void setPF(PixelFormat pf) {
super.setPF(pf);
if (source != null)
source.newPixels(data, cm, 0, width_);
}
public void updateColourMap() {
cm = new IndexColorModel(8, nColours, reds, greens, blues);
if (source != null)
source.newPixels(data, cm, 0, width_);
}
// resize() resizes the image, preserving the image data where possible.
public void resize(int w, int h) {
if (w == width() && h == height()) return;
int rowsToCopy = h < height() ? h : height();
int copyWidth = w < width() ? w : width();
int[] oldData = data;
width_ = w;
height_ = h;
data = new int[width() * height()];
for (int i = 0; i < rowsToCopy; i++)
System.arraycopy(oldData, copyWidth * i,
data, width_ * i, copyWidth);
source = new MemoryImageSource(w, h, cm, data, 0, w);
source.setAnimated(true);
source.setFullBufferUpdates(false);
image = desktop.createImage(source);
source.newPixels(data, cm, 0, width_);
}
public void fillRect(int x, int y, int w, int h, int pix) {
super.fillRect(x, y, w, h, pix);
source.newPixels(x, y, w, h, true);
}
public void imageRect(int x, int y, int w, int h, Object pix) {
if (pix instanceof Image) {
PixelGrabber pg =
new PixelGrabber((Image)pix, 0, 0, w, h, data, (width_ * y) + x, width_);
try {
pg.grabPixels(0);
} catch (InterruptedException e) {
vlog.error("Tight Decoding: Wrong JPEG data recieved");
}
} else {
for (int j = 0; j < h; j++)
System.arraycopy(pix, (w*j), data, width_ * (y + j) + x, w);
}
source.newPixels(x, y, w, h, true);
}
public void copyRect(int x, int y, int w, int h, int srcX, int srcY) {
super.copyRect(x, y, w, h, srcX, srcY);
source.newPixels(x, y, w, h, true);
}
public Image getImage() {
return (Image)image;
}
Image image;
MemoryImageSource source;
static LogWriter vlog = new LogWriter("AWTPixelBuffer");
}
|