Use endianness of server by default.

This commit is contained in:
Michael Jumper
2010-07-01 01:25:04 -07:00
parent 73cead9679
commit b35d9cda32
2 changed files with 45 additions and 12 deletions

View File

@@ -293,8 +293,21 @@ public class VNCClient extends Client {
log("Reading ServerInit...");
frameBufferWidth = input.readUnsignedShort();
frameBufferHeight = input.readUnsignedShort();
byte[] pixelFormat = new byte[16];
input.readFully(pixelFormat);
// Pixel format
int bpp = input.read();
int depth = input.read();
boolean bigEndian = input.readBoolean();
boolean trueColor = input.readBoolean();
int redMax = input.readUnsignedShort();
int greenMax = input.readUnsignedShort();
int blueMax = input.readUnsignedShort();
int redShift = input.read();
int greenShift = input.read();
int blueShift = input.read();
byte[] padding = new byte[3];
input.readFully(padding);
int nameLength = input.readInt();
byte[] nameBytes = new byte[nameLength];
input.readFully(nameBytes);
@@ -312,11 +325,11 @@ public class VNCClient extends Client {
// Set pixel format
VNCFullColorImageReader fullColorReader;
if (colorBits == 8)
fullColorReader = new VNCFullColorImageReader(3, 3, 2, 8);
fullColorReader = new VNCFullColorImageReader(bigEndian, 3, 3, 2, 8);
else if (colorBits == 16)
fullColorReader = new VNCFullColorImageReader(5, 6, 5, outputBPP);
fullColorReader = new VNCFullColorImageReader(bigEndian, 5, 6, 5, outputBPP);
else if (colorBits == 24)
fullColorReader = new VNCFullColorImageReader(8, 8, 8, outputBPP);
fullColorReader = new VNCFullColorImageReader(bigEndian, 8, 8, 8, outputBPP);
else
throw new VNCException("Color depth " + colorBits + " not supported. Only color depths of 8, 16, or 24 are allowed.");

View File

@@ -42,9 +42,10 @@ public class VNCFullColorImageReader extends VNCImageReader {
private int blueShift;
private boolean readAsIndexed;
private boolean bigEndian;
public boolean isBigEndian() {
return false;
return bigEndian;
}
public int getBitsPerPixel() {
@@ -80,7 +81,7 @@ public class VNCFullColorImageReader extends VNCImageReader {
}
// Set up BGR reader
public VNCFullColorImageReader(int redBits, int greenBits, int blueBits, int outputBPP) throws VNCException {
public VNCFullColorImageReader(boolean bigEndian, int redBits, int greenBits, int blueBits, int outputBPP) throws VNCException {
depth = redBits + greenBits + blueBits;
@@ -120,9 +121,20 @@ public class VNCFullColorImageReader extends VNCImageReader {
if (redBits != 8 || greenBits != 8 || blueBits != 8)
return readPixel(input);
int blue = input.read();
int green = input.read();
int red = input.read();
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();
}
int color = (red << 16) | (green << 8) | blue;
return color;
@@ -136,10 +148,18 @@ public class VNCFullColorImageReader extends VNCImageReader {
value = input.read();
break;
case 16:
value = Short.reverseBytes(input.readShort());
short inputShort = input.readShort();
if (!bigEndian) inputShort = Short.reverseBytes(inputShort);
value = inputShort;
break;
case 32:
value = Integer.reverseBytes(input.readInt());
int inputInt = input.readInt();
if (!bigEndian) inputInt = Integer.reverseBytes(inputInt);
value = inputInt;
break;
default:
throw new IOException("Invalid BPP.");