I've reversed engineered the jar file from AndroidProjector. I am trying to modify AndroidProjector to accomodate different screen sizes and I am running into problems with org.eclipse.swt.graphics.ImageData.blit() - ArrayOutOfBoundsException.
The project also uses this file (RawData) as part of the solution.
My Android Projector call:
private void getFramebufferHeader(SocketChannel paramSocketChannel)
throws IOException
{
ByteBuffer localByteBuffer = ByteBuffer.wrap(new byte[4]);
readAdbChannel(paramSocketChannel, localByteBuffer);
localByteBuffer.rewind();
localByteBuffer.order(ByteOrder.LITTLE_ENDIAN);
int i = localByteBuffer.getInt();
int j = RawImage.getHeaderSize(i);
localByteBuffer = ByteBuffer.wrap(new byte[j * 4]);
readAdbChannel(paramSocketChannel, localByteBuffer);
localByteBuffer.rewind();
localByteBuffer.order(ByteOrder.LITTLE_ENDIAN);
this.mRawImage = new RawImage();
this.mRawImage.readHeader(i, localByteBuffer,percentSize);
}
ArrayOutOfBounds Exception Here:
private void updateDeviceImage(Shell paramShell, RawImage paramRawImage)
{
PaletteData localPaletteData = new PaletteData(paramRawImage.getRedMask(), paramRawImage.getGreenMask(), paramRawImage.getBlueMask());
//paramRawImage.getRedMask() = -16777216
//paramRawImage.getRedMask() = 16711680
//paramRawImage.getBlueMask() = 65289
ImageData localImageData = null;
//ArrayOutOfBounds Exception Here////////////////
//paramRawImage.width = 800
//paramRawImage.height = 1280
//paramRawImage.bpp = 32
//
localImageData = new ImageData(paramRawImage.width, paramRawImage.height, paramRawImage.bpp, localPaletteData, 1, paramRawImage.data);
Image localImage = new Image(paramShell.getDisplay(), localImageData);
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/////////////////////////////////////////
this.mImageLabel.setImage(localImage);
this.mImageLabel.pack();
paramShell.pack();
}
My modified RawData method call (the outofbounds exception occurs when percentSize is less than 100):
public boolean readHeader(int version, ByteBuffer buf, int percentSize) {
this.version = version;
if (version == 16) {
// compatibility mode with original protocol
this.bpp = 16;
// read actual values.
this.size = buf.getInt() * percentSize/100;
this.width = buf.getInt() * percentSize/100;
this.height = buf.getInt() * percentSize/100;
// create default values for the rest. Format is 565
this.red_offset = 11 * percentSize/100;
this.red_length = 5 * percentSize/100;
this.green_offset = 5 * percentSize/100;
this.green_length = 6 * percentSize/100;
this.blue_offset = 0 ;
this.blue_length = 5 * percentSize/100;
this.alpha_offset = 0;
this.alpha_length = 0;
} else if (version == 1) {
this.bpp = buf.getInt();
this.size = buf.getInt() * percentSize/100;
this.width = buf.getInt() * percentSize/100;
this.height = buf.getInt() * percentSize/100;
if (percentSize < 100) {
this.red_offset = 11;
this.red_length = 5;
this.green_offset = 5;
this.green_length = 6;
this.blue_offset = buf.getInt() ;
this.blue_length = 5;
this.alpha_offset = buf.getInt();
this.alpha_length = buf.getInt();
} else {
this.red_offset = buf.getInt() ;
this.red_length = buf.getInt();
this.blue_offset = buf.getInt();
this.blue_length = buf.getInt();
this.green_offset = buf.getInt();
this.green_length = buf.getInt();
this.alpha_offset = buf.getInt();
this.alpha_length = buf.getInt();
}
/*
*/
} else {
// unsupported protocol!
return false;
}
return true;
}
Here is my exception:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 16390
at org.eclipse.swt.graphics.ImageData.blit(Unknown Source)
at org.eclipse.swt.graphics.Image.init(Unknown Source)
at org.eclipse.swt.graphics.Image.init(Unknown Source)
at org.eclipse.swt.graphics.Image.<init>(Unknown Source)
at com.google.android.AndroidProjector.updateDeviceImage(AndroidProjector.java:262)
at com.google.android.AndroidProjector.open(AndroidProjector.java:56)
at com.google.android.AndroidProjector.main(AndroidProjector.java:273)
I was really barking up the wrong tree with my approach. After much googling, instead of messing with the RawImage, I recreated the shell size and the resized the image.
My code now lives here:
https://github.com/techartist/AndroidProjector
and then I resized the image on the fly:
and
}