📄 bitmap.java
字号:
case 3: /* Color */
color2 = cvalx(compressed_pixel, input, Bpp);
//color2 = (compressed_pixel[input++]&0x000000ff);
input += Bpp;
break;
case 6: /* SetMix/Mix */
case 7: /* SetMix/FillOrMix */
// mix = compressed_pixel[input++];
mix = cvalx(compressed_pixel, input, Bpp);
input += Bpp;
opcode -= 5;
break;
case 9: /* FillOrMix_1 */
mask = 0x03;
opcode = 0x02;
fom_mask = 3;
break;
case 0x0a: /* FillOrMix_2 */
mask = 0x05;
opcode = 0x02;
fom_mask = 5;
break;
}
lastopcode = opcode;
mixmask = 0;
/* Output body */
while (count > 0) {
if (x >= width) {
if (height <= 0) throw new RdesktopException("Decompressing bitmap failed! Height = " + height);
x = 0;
height--;
previous = line;
prevY = previous / width;
line = height * width;
}
switch (opcode) {
case 0: /* Fill */
if (insertmix) {
if (previous == -1) {
// pixel[line+x] = mix;
w.setRGB(x,height,mix);
} else {
w.setRGB(x,height,w.getRGB(x,prevY) ^ mix);
// pixel[line+x] = (pixel[previous+x] ^ mix);
}
insertmix = false;
count--;
x++;
}
if (previous == -1) {
while (((count & ~0x7) != 0) && ((x + 8) < width)) {
for (int i = 0; i < 8; i++) {
// pixel[line+x] = 0;
w.setRGB(x,height,0);
count--;
x++;
}
}
while ((count > 0) && (x < width)) {
// pixel[line+x] = 0;
w.setRGB(x,height,0);
count--;
x++;
}
} else {
while (((count & ~0x7) != 0) && ((x + 8) < width)) {
for (int i = 0; i < 8; i++) {
// pixel[line + x] = pixel[previous + x];
w.setRGB(x,height,w.getRGB(x,prevY));
count--;
x++;
}
}
while ((count > 0) && (x < width)) {
// pixel[line + x] = pixel[previous + x];
w.setRGB(x,height,w.getRGB(x,prevY));
count--;
x++;
}
}
break;
case 1: /* Mix */
if (previous == -1) {
while (((count & ~0x7) != 0) && ((x + 8) < width)) {
for (int i = 0; i < 8; i++) {
// pixel[line + x] = mix;
w.setRGB(x,height,mix);
count--;
x++;
}
}
while ((count > 0) && (x < width)) {
// pixel[line + x] = mix;
w.setRGB(x,height,mix);
count--;
x++;
}
} else {
while (((count & ~0x7) != 0) && ((x + 8) < width)) {
for (int i = 0; i < 8; i++) {
// pixel[line + x] = pixel[previous + x] ^ mix;
w.setRGB(x,height,w.getRGB(x,prevY) ^ mix);
count--;
x++;
}
}
while ((count > 0) && (x < width)) {
// pixel[line + x] = pixel[previous + x] ^ mix;
w.setRGB(x,height,w.getRGB(x,prevY) ^ mix);
count--;
x++;
}
}
break;
case 2: /* Fill or Mix */
if (previous == -1) {
while (((count & ~0x7) != 0) && ((x + 8) < width)) {
for (int i = 0; i < 8; i++) {
mixmask <<= 1;
if (mixmask == 0) {
mask = (fom_mask != 0) ? (byte) fom_mask
: compressed_pixel[input++];
mixmask = 1;
}
if ((mask & mixmask) != 0){
// pixel[line + x] = (byte) mix;
w.setRGB(x,height,(byte) mix);
}
else{
//pixel[line + x] = 0;
w.setRGB(x,height,0);
}
count--;
x++;
}
}
while ((count > 0) && (x < width)) {
mixmask <<= 1;
if (mixmask == 0) {
mask = (fom_mask != 0) ? (byte) fom_mask
: compressed_pixel[input++];
mixmask = 1;
}
if ((mask & mixmask) != 0){
//pixel[line + x] = mix;
w.setRGB(x,height,mix);
}
else{
//pixel[line + x] = 0;
w.setRGB(x,height,0);
}
count--;
x++;
}
} else {
while (((count & ~0x7) != 0) && ((x + 8) < width)) {
for (int i = 0; i < 8; i++) {
mixmask <<= 1;
if (mixmask == 0) {
mask = (fom_mask != 0) ? (byte) fom_mask
: compressed_pixel[input++];
mixmask = 1;
}
if ((mask & mixmask) != 0){
//pixel[line + x] = (pixel[previous + x] ^ mix);
w.setRGB(x,height,w.getRGB(x,prevY) ^ mix);
} else{
//pixel[line + x] = pixel[previous + x];
w.setRGB(x,height,w.getRGB(x,prevY));
}
count--;
x++;
}
}
while ((count > 0) && (x < width)) {
mixmask <<= 1;
if (mixmask == 0) {
mask = (fom_mask != 0) ? (byte) fom_mask
: compressed_pixel[input++];
mixmask = 1;
}
if ((mask & mixmask) != 0){
// pixel[line + x] = (pixel[previous + x] ^ mix);
w.setRGB(x,height,w.getRGB(x,prevY) ^ mix);
} else {
// pixel[line + x] = pixel[previous + x];
w.setRGB(x,height,w.getRGB(x,prevY));
}
count--;
x++;
}
}
break;
case 3: /* Color */
while (((count & ~0x7) != 0) && ((x + 8) < width)) {
for (int i = 0; i < 8; i++) {
// pixel[line + x] = color2;
w.setRGB(x,height,color2);
count--;
x++;
}
}
while ((count > 0) && (x < width)) {
// pixel[line + x] = color2;
w.setRGB(x,height,color2);
count--;
x++;
}
break;
case 4: /* Copy */
while (((count & ~0x7) != 0) && ((x + 8) < width)) {
for (int i = 0; i < 8; i++) {
// pixel[line + x] = cvalx(compressed_pixel, input, Bpp);
w.setRGB(x,height,cvalx(compressed_pixel, input, Bpp));
input += Bpp;
count--;
x++;
}
}
while ((count > 0) && (x < width)) {
// pixel[line + x] = cvalx(compressed_pixel, input, Bpp);
w.setRGB(x,height,cvalx(compressed_pixel, input, Bpp));
input += Bpp;
// pixel[line+x] = compressed_pixel[input++];
count--;
x++;
}
break;
case 8: /* Bicolor */
while (((count & ~0x7) != 0) && ((x + 8) < width)) {
for (int i = 0; i < 8; i++) {
if (bicolor) {
// pixel[line + x] = color2;
w.setRGB(x,height,color2);
bicolor = false;
} else {
// pixel[line + x] = color1;
w.setRGB(x,height,color1);
bicolor = true;
count++;
}
count--;
x++;
}
}
while ((count > 0) && (x < width)) {
if (bicolor) {
// pixel[line + x] = color2;
w.setRGB(x,height,color2);
bicolor = false;
} else {
// pixel[line + x] = color1;
w.setRGB(x,height,color1);
bicolor = true;
count++;
}
count--;
x++;
}
break;
case 0xd: /* White */
while (((count & ~0x7) != 0) && ((x + 8) < width)) {
for (int i = 0; i < 8; i++) {
// pixel[line + x] = 0xffffff;
w.setRGB(x,height,0xffffff);
count--;
x++;
}
}
while ((count > 0) && (x < width)) {
// pixel[line + x] = 0xffffff;
w.setRGB(x,height,0xffffff);
count--;
x++;
}
break;
case 0xe: /* Black */
while (((count & ~0x7) != 0) && ((x + 8) < width)) {
for (int i = 0; i < 8; i++) {
// pixel[line + x] = 0x00;
w.setRGB(x,height,0x00);
count--;
x++;
}
}
while ((count > 0) && (x < width)) {
// pixel[line + x] = 0x00;
w.setRGB(x,height,0x00);
count--;
x++;
}
break;
default:
throw new RdesktopException(
"Unimplemented decompress opcode " + opcode);// ;
}
}
}
/* if(Options.server_bpp == 16){
for(int i = 0; i < pixel.length; i++) pixel[i] = Bitmap.convert16to24(pixel[i]);
}*/
return w.getBufferedImage();
}
/**
* Decompress bitmap data from packet and store in array of integers
* @param width Width of bitmap
* @param height Height of bitmap
* @param size Size of compressed data in bytes
* @param data Packet containing bitmap data
* @param Bpp Bytes per-pixel for bitmap
* @return Integer array of pixels containing decompressed bitmap data
* @throws RdesktopException
*/
public static int[] decompressInt(int width, int height, int size, RdpPacket_Localised data, int Bpp) throws RdesktopException {
byte[] compressed_pixel = new byte[size];
data.copyToByteArray(compressed_pixel, 0, data.getPosition(), size);
data.incrementPosition(size);
int previous = -1, line = 0;
int input = 0, output = 0, end = size;
int opcode = 0, count = 0, offset = 0, x = width;
int lastopcode = -1, fom_mask = 0;
int code = 0, color1 = 0, color2 = 0;
byte mixmask = 0;
int mask = 0;
int mix = 0xffffffff;
boolean insertmix = false, bicolor = false, isfillormix = false;
int[] pixel = new int[width * height];
while (input < end) {
fom_mask = 0;
code = (compressed_pixel[input++] & 0x000000ff);
opcode = code >> 4;
/* Handle different opcode forms */
switch (opcode) {
case 0xc:
case 0xd:
case 0xe:
opcode -= 6;
count = code & 0xf;
offset = 16;
break;
case 0xf:
opcode = code & 0xf;
if (opcode < 9) {
count = (compressed_pixel[input++] & 0xff);
count |= ((compressed_pixel[input++] & 0xff) << 8);
} else {
count = (opcode < 0xb) ? 8 : 1;
}
offset = 0;
break;
default:
opcode >>= 1;
count = code & 0x1f;
offset = 32;
break;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -