softCursorPixels = new int[width * height];  if (encodingType == rfb.EncodingXCursor) {   byte[] rgb = new byte[6]; rfb.is.readFully(rgb); int[] colors = {(0xFF000000 | (rgb[3] & 0xFF) << 16 | (rgb[4] & 0xFF) << 8 | (rgb[5] & 0xFF)), (0xFF000000 | (rgb[0] & 0xFF) << 16 | (rgb[1] & 0xFF) << 8 | (rgb[2] & 0xFF)) };   byte[] pixBuf = new byte[bytesMaskData]; rfb.is.readFully(pixBuf); byte[] maskBuf = new byte[bytesMaskData]; rfb.is.readFully(maskBuf);   byte pixByte, maskByte; int x, y, n, result; int i = 0; for (y = 0; y < height; y++) { for (x = 0; x < width / 8; x++) { pixByte = pixBuf[y * bytesPerRow + x]; maskByte = maskBuf[y * bytesPerRow + x]; for (n = 7; n >= 0; n--) { if ((maskByte >> n & 1) != 0) { result = colors[pixByte >> n & 1]; } else { result = 0; } softCursorPixels[i++] = result; } } for (n = 7; n >= 8 - width % 8; n--) { if ((maskBuf[y * bytesPerRow + x] >> n & 1) != 0) { result = colors[pixBuf[y * bytesPerRow + x] >> n & 1]; } else { result = 0; } softCursorPixels[i++] = result; } }  } else {    byte[] pixBuf = new byte[width * height * 4]; rfb.is.readFully(pixBuf); byte[] maskBuf = new byte[bytesMaskData]; rfb.is.readFully(maskBuf);   byte pixByte, maskByte; int x, y, n, result; int i = 0; for (y = 0; y < height; y++) { for (x = 0; x < width / 8; x++) { maskByte = maskBuf[y * bytesPerRow + x]; for (n = 7; n >= 0; n--) { if ((maskByte >> n & 1) != 0) {    result = (pixBuf[i * 4] & 0xFF) << 24 | (pixBuf[i * 4 + 1] & 0xFF) << 16 | (pixBuf[i * 4 + 2] & 0xFF) << 8 | (pixBuf[i * 4 + 3] & 0xFF);      } else { result = 0; } softCursorPixels[i++] = result; } }  for (n = 7; n >= 8 - width % 8; n--) { if ((maskBuf[y * bytesPerRow + x] >> n & 1) != 0) {    result = 0xFF000000 | (pixBuf[i * 4 + 1] & 0xFF) << 16 | (pixBuf[i * 4 + 2] & 0xFF) << 8 | (pixBuf[i * 4 + 3] & 0xFF);  } else { result = 0; } softCursorPixels[i++] = result; } }  }    softCursorSource = new MemoryImageSource(width, height, softCursorPixels, 0, width); softCursor = Toolkit.getDefaultToolkit().createImage(softCursorSource);           cursorWidth = width; cursorHeight = height; hotX = xhot; hotY = yhot;
  synchronized void handleCursorShapeUpdate(int encodingType,                                             int xhot, int yhot, int width,                                             int height)      throws IOException {    int bytesPerRow = (width + 7) / 8;    int bytesMaskData = bytesPerRow * height;    softCursorFree();    if (width * height == 0)      return;//    // Ignore cursor shape data if requested by user.////    if (viewer.options.ignoreCursorUpdates) {//      if (encodingType == rfb.EncodingXCursor) {//	rfb.is.skipBytes(6 + bytesMaskData * 2);//      } else {//	// rfb.EncodingRichCursor//	rfb.is.skipBytes(width * height + bytesMaskData);//      }//      return;//    }    // Decode cursor pixel data.    softCursorPixels = new int[width * height];    if (encodingType == rfb.EncodingXCursor) {      // Read foreground and background colors of the cursor.      byte[] rgb = new byte[6];      rfb.is.readFully(rgb);      int[] colors = {(0xFF000000 | (rgb[3] & 0xFF) << 16 |                      (rgb[4] & 0xFF) << 8 | (rgb[5] & 0xFF)),                      (0xFF000000 | (rgb[0] & 0xFF) << 16 |                      (rgb[1] & 0xFF) << 8 | (rgb[2] & 0xFF))      };      // Read pixel and mask data.      byte[] pixBuf = new byte[bytesMaskData];      rfb.is.readFully(pixBuf);      byte[] maskBuf = new byte[bytesMaskData];      rfb.is.readFully(maskBuf);      // Decode pixel data into softCursorPixels[].      byte pixByte, maskByte;      int x, y, n, result;      int i = 0;      for (y = 0; y < height; y++) {        for (x = 0; x < width / 8; x++) {          pixByte = pixBuf[y * bytesPerRow + x];          maskByte = maskBuf[y * bytesPerRow + x];          for (n = 7; n >= 0; n--) {            if ((maskByte >> n & 1) != 0) {              result = colors[pixByte >> n & 1];            } else {              result = 0;	// Transparent pixel            }            softCursorPixels[i++] = result;          }        }        for (n = 7; n >= 8 - width % 8; n--) {          if ((maskBuf[y * bytesPerRow + x] >> n & 1) != 0) {            result = colors[pixBuf[y * bytesPerRow + x] >> n & 1];          } else {            result = 0;		// Transparent pixel          }          softCursorPixels[i++] = result;        }      }    } else {      // encodingType == rfb.EncodingRichCursor      // Read pixel and mask data.      byte[] pixBuf = new byte[width * height * 4];      rfb.is.readFully(pixBuf);      byte[] maskBuf = new byte[bytesMaskData];      rfb.is.readFully(maskBuf);      // Decode pixel data into softCursorPixels[].      byte pixByte, maskByte;      int x, y, n, result;      int i = 0;      for (y = 0; y < height; y++) {        for (x = 0; x < width / 8; x++) {          maskByte = maskBuf[y * bytesPerRow + x];          for (n = 7; n >= 0; n--) {            if ((maskByte >> n & 1) != 0) {//	      if (bytesPerPixel == 1) {//		result = cm8.getRGB(pixBuf[i]);//	      } else {              result = (pixBuf[i * 4] & 0xFF) << 24 |                  (pixBuf[i * 4 + 1] & 0xFF) << 16 |                  (pixBuf[i * 4 + 2] & 0xFF) << 8 |                  (pixBuf[i * 4 + 3] & 0xFF);            //result = 0xFF000000 |            // (pixBuf[i * 4 + 1] & 0xFF) << 16 |            // (pixBuf[i * 4 + 2] & 0xFF) << 8 |            // (pixBuf[i * 4 + 3] & 0xFF);//	      }            } else {              result = 0;	// Transparent pixel            }            softCursorPixels[i++] = result;          }        }        for (n = 7; n >= 8 - width % 8; n--) {          if ((maskBuf[y * bytesPerRow + x] >> n & 1) != 0) {//	    if (bytesPerPixel == 1) {//	      result = cm8.getRGB(pixBuf[i]);//	    } else {            result = 0xFF000000 |                (pixBuf[i * 4 + 1] & 0xFF) << 16 |                (pixBuf[i * 4 + 2] & 0xFF) << 8 |                (pixBuf[i * 4 + 3] & 0xFF);//	    }          } else {            result = 0;		// Transparent pixel          }          softCursorPixels[i++] = result;        }      }    }    // Draw the cursor on an off-screen image.    softCursorSource =        new MemoryImageSource(width, height, softCursorPixels, 0, width);    softCursor = Toolkit.getDefaultToolkit().createImage(softCursorSource);//    if (inputEnabled && viewer.options.scaleCursor != 0) {//	int w = (width * viewer.options.scaleCursor) / 100;//	int h = (height * viewer.options.scaleCursor) / 100;//	Image newCursor = softCursor.getScaledInstance(w, h, Image.SCALE_SMOOTH);//	softCursor = newCursor;//	cursorWidth = w;//	cursorHeight = h;//	hotX = (xhot * viewer.options.scaleCursor) / 100;//	hotY = (yhot * viewer.options.scaleCursor) / 100;//    } else {    cursorWidth = width;    cursorHeight = height;    hotX = xhot;    hotY = yhot;//    }    // Set data associated with cursor.    origCursorWidth = width;    origCursorHeight = height;    origHotX = xhot;    origHotY = yhot;    showSoftCursor = true;    // Show the cursor.    scheduleRepaint(cursorX - hotX, cursorY - hotY, cursorWidth, cursorHeight);  }