Removed VNC client, generalized description of Guac in copyright.

This commit is contained in:
Michael Jumper
2010-09-04 23:20:29 -07:00
parent c048537232
commit 2523a39df6
36 changed files with 36 additions and 1749 deletions

View File

@@ -2,7 +2,7 @@
package net.sourceforge.guacamole;
/*
* Guacamole - Pure JavaScript/HTML VNC Client
* Guacamole - Clientless Remote Desktop
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify

View File

@@ -2,7 +2,7 @@
package net.sourceforge.guacamole;
/*
* Guacamole - Pure JavaScript/HTML VNC Client
* Guacamole - Clientless Remote Desktop
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify

View File

@@ -2,7 +2,7 @@
package net.sourceforge.guacamole.event;
/*
* Guacamole - Pure JavaScript/HTML VNC Client
* Guacamole - Clientless Remote Desktop
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify

View File

@@ -2,7 +2,7 @@
package net.sourceforge.guacamole.event;
/*
* Guacamole - Pure JavaScript/HTML VNC Client
* Guacamole - Clientless Remote Desktop
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify

View File

@@ -2,7 +2,7 @@
package net.sourceforge.guacamole.event;
/*
* Guacamole - Pure JavaScript/HTML VNC Client
* Guacamole - Clientless Remote Desktop
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify

View File

@@ -1,7 +1,7 @@
package net.sourceforge.guacamole.event;
/*
* Guacamole - Pure JavaScript/HTML VNC Client
* Guacamole - Clientless Remote Desktop
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify

View File

@@ -1,7 +1,7 @@
package net.sourceforge.guacamole.event;
/*
* Guacamole - Pure JavaScript/HTML VNC Client
* Guacamole - Clientless Remote Desktop
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify

View File

@@ -2,7 +2,7 @@
package net.sourceforge.guacamole.instruction;
/*
* Guacamole - Pure JavaScript/HTML VNC Client
* Guacamole - Clientless Remote Desktop
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify

View File

@@ -2,7 +2,7 @@
package net.sourceforge.guacamole.instruction;
/*
* Guacamole - Pure JavaScript/HTML VNC Client
* Guacamole - Clientless Remote Desktop
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify

View File

@@ -2,7 +2,7 @@
package net.sourceforge.guacamole.instruction;
/*
* Guacamole - Pure JavaScript/HTML VNC Client
* Guacamole - Clientless Remote Desktop
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify

View File

@@ -2,7 +2,7 @@
package net.sourceforge.guacamole.instruction;
/*
* Guacamole - Pure JavaScript/HTML VNC Client
* Guacamole - Clientless Remote Desktop
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify

View File

@@ -2,7 +2,7 @@
package net.sourceforge.guacamole.instruction;
/*
* Guacamole - Pure JavaScript/HTML VNC Client
* Guacamole - Clientless Remote Desktop
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify

View File

@@ -2,7 +2,7 @@
package net.sourceforge.guacamole.instruction.framebuffer;
/*
* Guacamole - Pure JavaScript/HTML VNC Client
* Guacamole - Clientless Remote Desktop
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify

View File

@@ -3,7 +3,7 @@ package net.sourceforge.guacamole.instruction.framebuffer;
import net.sourceforge.guacamole.net.Base64;
/*
* Guacamole - Pure JavaScript/HTML VNC Client
* Guacamole - Clientless Remote Desktop
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify

View File

@@ -2,7 +2,7 @@
package net.sourceforge.guacamole.instruction.framebuffer;
/*
* Guacamole - Pure JavaScript/HTML VNC Client
* Guacamole - Clientless Remote Desktop
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify

View File

@@ -1,7 +1,7 @@
package net.sourceforge.guacamole.instruction.framebuffer;
/*
* Guacamole - Pure JavaScript/HTML VNC Client
* Guacamole - Clientless Remote Desktop
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify

View File

@@ -1,7 +1,7 @@
package net.sourceforge.guacamole.instruction.framebuffer;
/*
* Guacamole - Pure JavaScript/HTML VNC Client
* Guacamole - Clientless Remote Desktop
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify

View File

@@ -1,7 +1,7 @@
package net.sourceforge.guacamole.net;
/*
* Guacamole - Pure JavaScript/HTML VNC Client
* Guacamole - Clientless Remote Desktop
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify

View File

@@ -2,7 +2,7 @@
package net.sourceforge.guacamole.net;
/*
* Guacamole - Pure JavaScript/HTML VNC Client
* Guacamole - Clientless Remote Desktop
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify

View File

@@ -2,7 +2,7 @@
package net.sourceforge.guacamole.net;
/*
* Guacamole - Pure JavaScript/HTML VNC Client
* Guacamole - Clientless Remote Desktop
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify
@@ -27,7 +27,6 @@ public class GuacamoleConfiguration extends Configuration {
private String password;
private int outputBPP;
private boolean compressStream;
private String protocol;
private boolean swapRedAndBlue;
public GuacamoleConfiguration(ServletContext context) throws GuacamoleException {
@@ -37,7 +36,6 @@ public class GuacamoleConfiguration extends Configuration {
password = context.getInitParameter("password");
outputBPP = readIntParameter("output-bpp", 8, 8, 24);
compressStream = readBooleanParameter("compress-stream", false);
protocol = readParameter("protocol", "vnc", "vnc");
swapRedAndBlue = readBooleanParameter("swap-red-blue", false);
}
@@ -54,10 +52,6 @@ public class GuacamoleConfiguration extends Configuration {
return compressStream;
}
public String getProtocol() {
return protocol;
}
public boolean getSwapRedAndBlue() {
return swapRedAndBlue;
}

View File

@@ -2,7 +2,7 @@
package net.sourceforge.guacamole.net;
/*
* Guacamole - Pure JavaScript/HTML VNC Client
* Guacamole - Clientless Remote Desktop
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify

View File

@@ -2,7 +2,7 @@
package net.sourceforge.guacamole.net;
/*
* Guacamole - Pure JavaScript/HTML VNC Client
* Guacamole - Clientless Remote Desktop
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify
@@ -29,9 +29,6 @@ import net.sourceforge.guacamole.GuacamoleException;
import net.sourceforge.guacamole.instruction.Instruction;
import net.sourceforge.guacamole.event.KeyEvent;
import net.sourceforge.guacamole.event.PointerEvent;
import net.sourceforge.guacamole.vnc.VNCClient;
import net.sourceforge.guacamole.vnc.VNCConfiguration;
import net.sourceforge.guacamole.vnc.VNCException;
public class GuacamoleSession {
@@ -107,35 +104,9 @@ public class GuacamoleSession {
client.disconnect();
String protocol = config.getProtocol();
if (protocol.equals("vnc")) {
// Connect to VNC server
try {
// Read VNC-specific parameters
ServletContext context = session.getServletContext();
VNCConfiguration vncconfig = new VNCConfiguration(context);
client = new SessionClient(
new VNCClient(
vncconfig.getHostname(),
vncconfig.getPort(),
vncconfig.getPassword(),
vncconfig.getBPP(),
config.getOutputBPP(),
config.getSwapRedAndBlue()
)
);
}
catch (VNCException e) {
throw new GuacamoleException(e);
}
}
else
throw new GuacamoleException("Unsupported protocol: " + protocol);
client = new SessionClient(
null /* CLIENT GOES HERE */
);
session.setAttribute("CLIENT", client);

View File

@@ -2,7 +2,7 @@
package net.sourceforge.guacamole.net;
/*
* Guacamole - Pure JavaScript/HTML VNC Client
* Guacamole - Clientless Remote Desktop
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify

View File

@@ -1,7 +1,7 @@
package net.sourceforge.guacamole.net.control;
/*
* Guacamole - Pure JavaScript/HTML VNC Client
* Guacamole - Clientless Remote Desktop
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify

View File

@@ -1,7 +1,7 @@
package net.sourceforge.guacamole.net.control;
/*
* Guacamole - Pure JavaScript/HTML VNC Client
* Guacamole - Clientless Remote Desktop
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify
@@ -35,7 +35,7 @@ public class Disconnect extends XMLGuacamoleServlet {
session.disconnect(); // Disconnect client.
}
catch (GuacamoleException e) {
throw new GuacamoleException("Error disconnecting from VNC server: " + e.getMessage(), e);
throw new GuacamoleException("Error disconnecting from server: " + e.getMessage(), e);
}
}

View File

@@ -2,7 +2,7 @@
package net.sourceforge.guacamole.net.input;
/*
* Guacamole - Pure JavaScript/HTML VNC Client
* Guacamole - Clientless Remote Desktop
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify
@@ -25,13 +25,12 @@ import org.w3c.dom.Element;
import net.sourceforge.guacamole.net.GuacamoleSession;
import net.sourceforge.guacamole.net.XMLGuacamoleServlet;
import net.sourceforge.guacamole.vnc.VNCException;
import java.io.IOException;
import java.io.Reader;
/**
* Servlet which sets the VNC clipboard data.
* Servlet which sets the clipboard data.
*
* This servlet takes one parameter:
* data: The data to set the clipboard to.

View File

@@ -2,7 +2,7 @@
package net.sourceforge.guacamole.net.input;
/*
* Guacamole - Pure JavaScript/HTML VNC Client
* Guacamole - Clientless Remote Desktop
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify
@@ -26,11 +26,10 @@ import net.sourceforge.guacamole.event.KeyEvent;
import net.sourceforge.guacamole.net.GuacamoleSession;
import net.sourceforge.guacamole.net.XMLGuacamoleServlet;
import net.sourceforge.guacamole.vnc.VNCException;
/**
* Servlet which accepts keyboard input events, forwards these events to the
* VNC client associated with the session, and returns the result (if any)
* client associated with the session, and returns the result (if any)
* to the HTTP client via XML.
*
* This servlet takes three parameters:

View File

@@ -1,7 +1,7 @@
package net.sourceforge.guacamole.net.input;
/*
* Guacamole - Pure JavaScript/HTML VNC Client
* Guacamole - Clientless Remote Desktop
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify
@@ -25,7 +25,6 @@ import net.sourceforge.guacamole.event.PointerEvent;
import net.sourceforge.guacamole.net.GuacamoleSession;
import net.sourceforge.guacamole.net.XMLGuacamoleServlet;
import net.sourceforge.guacamole.vnc.VNCException;
public class Pointer extends XMLGuacamoleServlet {

View File

@@ -1,7 +1,7 @@
package net.sourceforge.guacamole.net.output;
/*
* Guacamole - Pure JavaScript/HTML VNC Client
* Guacamole - Clientless Remote Desktop
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify
@@ -79,7 +79,7 @@ public class InstructionStream extends GuacamoleServlet {
try {
// Query new update from VNC server
// Query new update from server
Client client = session.getClient();
// For all messages, until another stream is ready (we send at least one message)

View File

@@ -1,63 +0,0 @@
package net.sourceforge.guacamole.vnc;
import java.io.IOException;
import java.io.InputStream;
import java.util.LinkedList;
public class InputOutputStream extends InputStream {
private int pos = 0;
private byte[] current = null;
private LinkedList<byte[]> buffer = new LinkedList<byte[]>();
public void write(byte[] data) {
if (data.length == 0)
return;
if (current == null)
current = data;
else
buffer.addLast(data);
}
@Override
public int read() throws IOException {
if (pos >= current.length) {
if (buffer.size() == 0)
throw new IOException("Buffer underrun.");
current = buffer.removeFirst();
pos = 0;
}
return 0xFF & current[pos++];
}
@Override
public int read(byte[] data) throws IOException {
return read(data, 0, data.length);
}
@Override
public int read(byte[] data, int off, int len) throws IOException {
if (pos >= current.length) {
if (buffer.size() == 0)
throw new IOException("Buffer underrun.");
current = buffer.removeFirst();
pos = 0;
}
int amountRead = Math.min(current.length - pos, len);
System.arraycopy(current, pos, data, off, amountRead);
pos += amountRead;
return amountRead;
}
}

View File

@@ -1,60 +0,0 @@
package net.sourceforge.guacamole.vnc;
/*
* Guacamole - Pure JavaScript/HTML VNC Client
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import net.sourceforge.guacamole.net.Configuration;
import net.sourceforge.guacamole.GuacamoleException;
import javax.servlet.ServletContext;
public class VNCConfiguration extends Configuration {
private String hostname;
private int port;
private String password;
private int bpp;
public VNCConfiguration(ServletContext context) throws GuacamoleException {
super(context);
hostname = readParameter("host", null);
port = readIntParameter("port", null);
password = context.getInitParameter("password");
bpp = readIntParameter("bpp", 24, 8, 16, 24);
}
public int getBPP() {
return bpp;
}
public String getPassword() {
return password;
}
public String getHostname() {
return hostname;
}
public int getPort() {
return port;
}
}

View File

@@ -1,32 +0,0 @@
package net.sourceforge.guacamole.vnc;
/*
* Guacamole - Pure JavaScript/HTML VNC Client
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
public class VNCException extends Exception {
public VNCException(String message, Throwable cause) {
super(message, cause);
}
public VNCException(String message) {
super(message);
}
}

View File

@@ -1,239 +0,0 @@
package net.sourceforge.guacamole.vnc;
/*
* Guacamole - Pure JavaScript/HTML VNC Client
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import java.awt.image.BufferedImage;
import java.awt.image.IndexColorModel;
import java.io.DataInputStream;
import java.io.IOException;
public class VNCFullColorImageReader extends VNCImageReader {
private int bpp;
private int depth;
private int redBits;
private int greenBits;
private int blueBits;
private int redMax;
private int greenMax;
private int blueMax;
private int redShift;
private int greenShift;
private int blueShift;
private boolean readAsIndexed;
private boolean bigEndian;
private boolean swapRedAndBlue;
public boolean isBigEndian() {
return bigEndian;
}
public int getBitsPerPixel() {
return bpp;
}
public int getDepth() {
return depth;
}
public int getRedMax() {
return redMax;
}
public int getGreenMax() {
return greenMax;
}
public int getBlueMax() {
return blueMax;
}
public int getRedShift() {
return redShift;
}
public int getGreenShift() {
return greenShift;
}
public int getBlueShift() {
return blueShift;
}
// Set up BGR reader
public VNCFullColorImageReader(boolean bigEndian, int redBits, int greenBits, int blueBits, int outputBPP, boolean swapRedAndBlue) throws VNCException {
this.swapRedAndBlue = swapRedAndBlue;
depth = redBits + greenBits + blueBits;
if (depth > 0 && depth <= 8)
bpp = 8;
else if (depth <= 16)
bpp = 16;
else if (depth <= 32)
bpp = 32;
else
throw new VNCException("Illegal bit depth for VNC images: " + bpp);
this.redBits = redBits;
this.greenBits = greenBits;
this.blueBits = blueBits;
blueMax = (1 << blueBits) - 1;
greenMax = (1 << greenBits) - 1;
redMax = (1 << redBits) - 1;
redShift = greenBits + blueBits;
greenShift = blueBits;
blueShift = 0;
if (outputBPP == 8)
this.readAsIndexed = true;
else if (outputBPP == 24)
this.readAsIndexed = false;
else
throw new VNCException("Only 8-bit or 24-bit output is supported.");
}
@Override
public int readCPixel(DataInputStream input) throws IOException {
if (redBits != 8 || greenBits != 8 || blueBits != 8)
return readPixel(input);
int red;
int green;
int blue;
if (bigEndian) {
red = input.read();
green = input.read();
blue = input.read();
}
else {
blue = input.read();
green = input.read();
red = input.read();
}
if (swapRedAndBlue)
return (blue << 16) | (green << 8) | red;
else
return (red << 16) | (green << 8) | blue;
}
@Override
public int readPixel(DataInputStream input) throws IOException {
int value;
switch (bpp) {
case 8:
value = input.read();
break;
case 16:
short inputShort = input.readShort();
if (!bigEndian) inputShort = Short.reverseBytes(inputShort);
value = inputShort;
break;
case 32:
int inputInt = input.readInt();
if (!bigEndian) inputInt = Integer.reverseBytes(inputInt);
value = inputInt;
break;
default:
throw new IOException("Invalid BPP.");
}
int red = (value >> redShift) & redMax;
int green = (value >> greenShift) & greenMax;
int blue = (value >> blueShift) & blueMax;
red <<= 8 - redBits;
green <<= 8 - greenBits;
blue <<= 8 - blueBits;
if (swapRedAndBlue)
return (blue << 16) | (green << 8) | red;
else
return (red << 16) | (green << 8) | blue;
}
@Override
public BufferedImage generateBlankImage(int width, int height) {
if (readAsIndexed)
return new BufferedImage(width, height, BufferedImage.TYPE_BYTE_INDEXED, COLOR_MODEL);
return new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
}
// Load color model
public static final IndexColorModel COLOR_MODEL;
static {
// Construct color model
byte[] colorShade = {0, (byte) 51, (byte) 104, (byte) 153, (byte) 204, (byte) 255};
byte[] greyShade = new byte[39];
for (int i=1; i<40; i++)
greyShade[i-1] = (byte) (6*i);
byte[] red = new byte[colorShade.length*colorShade.length*colorShade.length+greyShade.length+1];
byte[] green = new byte[colorShade.length*colorShade.length*colorShade.length+greyShade.length+1];
byte[] blue = new byte[colorShade.length*colorShade.length*colorShade.length+greyShade.length+1];
byte[] alpha = new byte[colorShade.length*colorShade.length*colorShade.length+greyShade.length+1];
int color = 0;
for (int r=0; r<colorShade.length; r++) {
for (int g=0; g<colorShade.length; g++) {
for (int b=0; b<colorShade.length; b++) {
red[color] = colorShade[r];
green[color] = colorShade[g];
blue[color] = colorShade[b];
alpha[color] = (byte) 255;
color++;
}
}
}
for (int grey=0; grey<greyShade.length; grey++) {
red[color] = greyShade[grey];
green[color] = greyShade[grey];
blue[color] = greyShade[grey];
alpha[color] = (byte) 255;
color++;
}
red[color] = 0;
green[color] = 0;
blue[color] = 0;
alpha[color] = (byte) 0;
COLOR_MODEL = new IndexColorModel(8, 256, red, green, blue, alpha);
}
}

View File

@@ -1,64 +0,0 @@
package net.sourceforge.guacamole.vnc;
/*
* Guacamole - Pure JavaScript/HTML VNC Client
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import java.awt.image.BufferedImage;
import java.io.DataInputStream;
import java.io.IOException;
public abstract class VNCImageReader {
public BufferedImage readCImage(DataInputStream input, int width, int height) throws IOException {
BufferedImage image = generateBlankImage(width, height);
// Read image
for (int pixelY=0; pixelY<height; pixelY++) {
for (int pixelX=0; pixelX<width; pixelX++) {
int color = 0xFF000000 | readCPixel(input);
image.setRGB(pixelX, pixelY, color);
}
}
return image;
}
public BufferedImage readImage(DataInputStream input, int width, int height) throws IOException {
BufferedImage image = generateBlankImage(width, height);
// Read image
for (int pixelY=0; pixelY<height; pixelY++) {
for (int pixelX=0; pixelX<width; pixelX++) {
int color = 0xFF000000 | readPixel(input);
image.setRGB(pixelX, pixelY, color);
}
}
return image;
}
public abstract BufferedImage generateBlankImage(int width, int height);
public abstract int readPixel(DataInputStream input) throws IOException;
public int readCPixel(DataInputStream input) throws IOException {
return readPixel(input);
}
}

View File

@@ -1,104 +0,0 @@
package net.sourceforge.guacamole.vnc;
/*
* Guacamole - Pure JavaScript/HTML VNC Client
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import java.awt.image.BufferedImage;
import java.awt.image.IndexColorModel;
import java.io.DataInputStream;
import java.io.IOException;
public class VNCIndexedImageReader extends VNCImageReader {
private IndexColorModel palette;
private byte[] red;
private byte[] green;
private byte[] blue;
// Set up BGR reader
public VNCIndexedImageReader(byte[] red, byte[] green, byte[] blue) throws VNCException {
this.red = red;
this.green = green;
this.blue = blue;
palette = new IndexColorModel(8, 256, red, green, blue);
if (palette.getMapSize() != 256)
throw new VNCException("Currently, only 256-color maps are supported.");
}
@Override
public int readPixel(DataInputStream input) throws IOException {
int value = input.read();
int color = (red[value] << 16) | (green[value] << 8) | blue[value];
return color;
}
@Override
public BufferedImage generateBlankImage(int width, int height) {
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_INDEXED, palette);
return image;
}
// Load color model
public static final IndexColorModel COLOR_MODEL;
static {
// Construct color model
byte[] colorShade = {0, (byte) 51, (byte) 104, (byte) 153, (byte) 204, (byte) 255};
byte[] greyShade = new byte[39];
for (int i=1; i<40; i++)
greyShade[i-1] = (byte) (6*i);
byte[] red = new byte[colorShade.length*colorShade.length*colorShade.length+greyShade.length+1];
byte[] green = new byte[colorShade.length*colorShade.length*colorShade.length+greyShade.length+1];
byte[] blue = new byte[colorShade.length*colorShade.length*colorShade.length+greyShade.length+1];
byte[] alpha = new byte[colorShade.length*colorShade.length*colorShade.length+greyShade.length+1];
int color = 0;
for (int r=0; r<colorShade.length; r++) {
for (int g=0; g<colorShade.length; g++) {
for (int b=0; b<colorShade.length; b++) {
red[color] = colorShade[r];
green[color] = colorShade[g];
blue[color] = colorShade[b];
alpha[color] = (byte) 255;
color++;
}
}
}
for (int grey=0; grey<greyShade.length; grey++) {
red[color] = greyShade[grey];
green[color] = greyShade[grey];
blue[color] = greyShade[grey];
alpha[color] = (byte) 255;
color++;
}
red[color] = 0;
green[color] = 0;
blue[color] = 0;
alpha[color] = (byte) 0;
COLOR_MODEL = new IndexColorModel(8, 256, red, green, blue, alpha);
}
}