tightvnc-jviewer

16:53:28.330 INFO  jd.cli.Main - Decompiling tightvnc-jviewer.jar
package com.glavsoft.rfb;

public abstract interface IRfbSessionListener
{
  public abstract void rfbSessionStopped(String paramString);
}

/* Location:
 * Qualified Name:     com.glavsoft.rfb.IRfbSessionListener
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.glavsoft.rfb;

import com.glavsoft.core.SettingsChangedEvent;

public abstract interface IChangeSettingsListener
{
  public abstract void settingsChanged(SettingsChangedEvent paramSettingsChangedEvent);
}

/* Location:
 * Qualified Name:     com.glavsoft.rfb.IChangeSettingsListener
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.glavsoft.rfb;

import com.glavsoft.drawing.Renderer;
import com.glavsoft.rfb.encoding.PixelFormat;
import com.glavsoft.rfb.encoding.decoder.FramebufferUpdateRectangle;
import com.glavsoft.transport.Reader;

public abstract interface IRepaintController
  extends IChangeSettingsListener
{
  public abstract void repaintBitmap(FramebufferUpdateRectangle paramFramebufferUpdateRectangle);
  
  public abstract void repaintBitmap(int paramInt1, int paramInt2, int paramInt3, int paramInt4);
  
  public abstract void repaintCursor();
  
  public abstract void updateCursorPosition(short paramShort1, short paramShort2);
  
  public abstract Renderer createRenderer(Reader paramReader, int paramInt1, int paramInt2, PixelFormat paramPixelFormat);
  
  public abstract void setPixelFormat(PixelFormat paramPixelFormat);
}

/* Location:
 * Qualified Name:     com.glavsoft.rfb.IRepaintController
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.glavsoft.rfb;

import com.glavsoft.exceptions.TransportException;
import com.glavsoft.transport.Reader;

public class RfbCapabilityInfo
{
  public static final String VENDOR_STANDARD = "STDV";
  public static final String VENDOR_TRIADA = "TRDV";
  public static final String VENDOR_TIGHT = "TGHT";
  public static final String TUNNELING_NO_TUNNELING = "NOTUNNEL";
  public static final String AUTHENTICATION_NO_AUTH = "NOAUTH__";
  public static final String AUTHENTICATION_VNC_AUTH = "VNCAUTH_";
  public static final String ENCODING_COPYRECT = "COPYRECT";
  public static final String ENCODING_HEXTILE = "HEXTILE_";
  public static final String ENCODING_ZLIB = "ZLIB____";
  public static final String ENCODING_ZRLE = "ZRLE____";
  public static final String ENCODING_RRE = "RRE_____";
  public static final String ENCODING_TIGHT = "TIGHT___";
  public static final String ENCODING_RICH_CURSOR = "RCHCURSR";
  public static final String ENCODING_CURSOR_POS = "POINTPOS";
  public static final String ENCODING_DESKTOP_SIZE = "NEWFBSIZ";
  private int code;
  private String vendorSignature;
  private String nameSignature;
  private boolean enable;
  
  public RfbCapabilityInfo(int code, String vendorSignature, String nameSignature)
  {
    this.code = code;
    this.vendorSignature = vendorSignature;
    this.nameSignature = nameSignature;
    enable = true;
  }
  
  public RfbCapabilityInfo(Reader reader)
    throws TransportException
  {
    code = reader.readInt32();
    vendorSignature = reader.readString(4);
    nameSignature = reader.readString(8);
  }
  
  public boolean equals(Object otherObj)
  {
    if (this == otherObj) {
      return true;
    }
    if (null == otherObj) {
      return false;
    }
    if (getClass() != otherObj.getClass()) {
      return false;
    }
    RfbCapabilityInfo other = (RfbCapabilityInfo)otherObj;
    return (code == code) && (vendorSignature.equals(vendorSignature)) && (nameSignature.equals(nameSignature));
  }
  
  public void setEnable(boolean enable)
  {
    this.enable = enable;
  }
  
  public int getCode()
  {
    return code;
  }
  
  public String getVendorSignature()
  {
    return vendorSignature;
  }
  
  public String getNameSignature()
  {
    return nameSignature;
  }
  
  public boolean isEnabled()
  {
    return enable;
  }
  
  public String toString()
  {
    return "RfbCapabilityInfo: [code: " + code + ", vendor: " + vendorSignature + ", name: " + nameSignature + "]";
  }
}

/* Location:
 * Qualified Name:     com.glavsoft.rfb.RfbCapabilityInfo
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.glavsoft.rfb;

public abstract interface IPasswordRetriever
{
  public abstract String getPassword();
}

/* Location:
 * Qualified Name:     com.glavsoft.rfb.IPasswordRetriever
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.glavsoft.rfb;

import com.glavsoft.exceptions.TransportException;
import com.glavsoft.rfb.encoding.EncodingType;
import com.glavsoft.transport.Reader;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.logging.Logger;

public class CapabilityContainer
{
  private final Map<Integer, RfbCapabilityInfo> caps = new HashMap();
  
  public void add(RfbCapabilityInfo capabilityInfo)
  {
    caps.put(Integer.valueOf(capabilityInfo.getCode()), capabilityInfo);
  }
  
  public void add(int code, String vendor, String name)
  {
    caps.put(Integer.valueOf(code), new RfbCapabilityInfo(code, vendor, name));
  }
  
  public void addEnabled(int code, String vendor, String name)
  {
    RfbCapabilityInfo capability = new RfbCapabilityInfo(code, vendor, name);
    capability.setEnable(true);
    caps.put(Integer.valueOf(code), capability);
  }
  
  public void setEnable(int id, boolean enable)
  {
    RfbCapabilityInfo c = (RfbCapabilityInfo)caps.get(Integer.valueOf(id));
    if (c != null) {
      c.setEnable(enable);
    }
  }
  
  public void setAllEnable(boolean enable)
  {
    for (RfbCapabilityInfo c : caps.values()) {
      c.setEnable(enable);
    }
  }
  
  public Collection<EncodingType> getEnabledEncodingTypes()
  {
    Collection<EncodingType> types = new LinkedList();
    for (RfbCapabilityInfo c : caps.values()) {
      if (c.isEnabled()) {
        types.add(EncodingType.byId(c.getCode()));
      }
    }
    return types;
  }
  
  public void read(Reader reader, int count)
    throws TransportException
  {
    while (count-- > 0)
    {
      RfbCapabilityInfo capInfoReceived = new RfbCapabilityInfo(reader);
      Logger.getLogger("com.glavsoft.rfb").fine(capInfoReceived.toString());
      RfbCapabilityInfo myCapInfo = (RfbCapabilityInfo)caps.get(Integer.valueOf(capInfoReceived.getCode()));
      if (myCapInfo != null) {
        myCapInfo.setEnable(true);
      }
    }
  }
  
  public boolean isSupported(int code)
  {
    RfbCapabilityInfo myCapInfo = (RfbCapabilityInfo)caps.get(Integer.valueOf(code));
    if (myCapInfo != null) {
      return myCapInfo.isEnabled();
    }
    return false;
  }
  
  public boolean isSupported(RfbCapabilityInfo rfbCapabilityInfo)
  {
    return isSupported(rfbCapabilityInfo.getCode());
  }
}

/* Location:
 * Qualified Name:     com.glavsoft.rfb.CapabilityContainer
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.glavsoft.rfb;

public abstract interface ClipboardController
  extends IChangeSettingsListener
{
  public abstract void updateSystemClipboard(byte[] paramArrayOfByte);
  
  public abstract String getRenewedClipboardText();
  
  public abstract String getClipboardText();
  
  public abstract void setEnabled(boolean paramBoolean);
}

/* Location:
 * Qualified Name:     com.glavsoft.rfb.ClipboardController
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.glavsoft.rfb.encoding;

import java.util.LinkedHashSet;

public enum EncodingType
{
  RAW_ENCODING(0, "Raw"),  COPY_RECT(1, "CopyRect"),  RRE(2, "RRE"),  HEXTILE(5, "Hextile"),  ZLIB(6, "ZLib"),  TIGHT(7, "Tight"),  ZRLE(16, "ZRLE"),  RICH_CURSOR(65297, "RichCursor"),  DESKTOP_SIZE(65313, "DesctopSize"),  CURSOR_POS(65304, "CursorPos"),  COMPRESS_LEVEL_0(65280, "CompressionLevel0"),  COMPRESS_LEVEL_1(65281, "CompressionLevel1"),  COMPRESS_LEVEL_2(65282, "CompressionLevel2"),  COMPRESS_LEVEL_3(65283, "CompressionLevel3"),  COMPRESS_LEVEL_4(65284, "CompressionLevel4"),  COMPRESS_LEVEL_5(65285, "CompressionLevel5"),  COMPRESS_LEVEL_6(65286, "CompressionLevel6"),  COMPRESS_LEVEL_7(65287, "CompressionLevel7"),  COMPRESS_LEVEL_8(65288, "CompressionLevel8"),  COMPRESS_LEVEL_9(65289, "CompressionLevel9"),  JPEG_QUALITY_LEVEL_0(-32, "JpegQualityLevel0"),  JPEG_QUALITY_LEVEL_1(-31, "JpegQualityLevel1"),  JPEG_QUALITY_LEVEL_2(-30, "JpegQualityLevel2"),  JPEG_QUALITY_LEVEL_3(-29, "JpegQualityLevel3"),  JPEG_QUALITY_LEVEL_4(-28, "JpegQualityLevel4"),  JPEG_QUALITY_LEVEL_5(-27, "JpegQualityLevel5"),  JPEG_QUALITY_LEVEL_6(-26, "JpegQualityLevel6"),  JPEG_QUALITY_LEVEL_7(-25, "JpegQualityLevel7"),  JPEG_QUALITY_LEVEL_8(-24, "JpegQualityLevel8"),  JPEG_QUALITY_LEVEL_9(-23, "JpegQualityLevel9");
  
  private int id;
  private final String name;
  public static LinkedHashSet<EncodingType> ordinaryEncodings;
  public static LinkedHashSet<EncodingType> pseudoEncodings;
  public static LinkedHashSet<EncodingType> compressionEncodings;
  
  private EncodingType(int id, String name)
  {
    this.id = id;
    this.name = name;
  }
  
  public int getId()
  {
    return id;
  }
  
  public String getName()
  {
    return name;
  }
  
  static
  {
    ordinaryEncodings = new LinkedHashSet();
    
    ordinaryEncodings.add(TIGHT);
    ordinaryEncodings.add(HEXTILE);
    ordinaryEncodings.add(ZRLE);
    ordinaryEncodings.add(ZLIB);
    ordinaryEncodings.add(RRE);
    ordinaryEncodings.add(COPY_RECT);
    
    pseudoEncodings = new LinkedHashSet();
    
    pseudoEncodings.add(RICH_CURSOR);
    pseudoEncodings.add(CURSOR_POS);
    pseudoEncodings.add(DESKTOP_SIZE);
    
    compressionEncodings = new LinkedHashSet();
    
    compressionEncodings.add(COMPRESS_LEVEL_0);
    compressionEncodings.add(JPEG_QUALITY_LEVEL_0);
  }
  
  public static EncodingType byId(int id)
  {
    for (EncodingType type : ) {
      if (type.getId() == id) {
        return type;
      }
    }
    throw new IllegalArgumentException("Unsupported encoding id: " + id);
  }
}

/* Location:
 * Qualified Name:     com.glavsoft.rfb.encoding.EncodingType
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.glavsoft.rfb.encoding;

import com.glavsoft.exceptions.TransportException;
import com.glavsoft.transport.Reader;
import com.glavsoft.transport.Writer;

public class PixelFormat
{
  public byte bitsPerPixel;
  public byte depth;
  public byte bigEndianFlag;
  public byte trueColourFlag;
  public short redMax;
  public short greenMax;
  public short blueMax;
  public byte redShift;
  public byte greenShift;
  public byte blueShift;
  
  public void fill(Reader reader)
    throws TransportException
  {
    bitsPerPixel = reader.readByte();
    depth = reader.readByte();
    bigEndianFlag = reader.readByte();
    trueColourFlag = reader.readByte();
    redMax = reader.readInt16();
    greenMax = reader.readInt16();
    blueMax = reader.readInt16();
    redShift = reader.readByte();
    greenShift = reader.readByte();
    blueShift = reader.readByte();
    reader.readBytes(3);
  }
  
  public void send(Writer writer)
    throws TransportException
  {
    writer.write(bitsPerPixel);
    writer.write(depth);
    writer.write(bigEndianFlag);
    writer.write(trueColourFlag);
    writer.write(redMax);
    writer.write(greenMax);
    writer.write(blueMax);
    writer.write(redShift);
    writer.write(greenShift);
    writer.write(blueShift);
    writer.writeInt16(0);
    writer.writeByte(0);
  }
  
  public static PixelFormat create32bppPixelFormat(int bigEndianFlag)
  {
    PixelFormat pixelFormat = new PixelFormat();
    bigEndianFlag = ((byte)bigEndianFlag);
    bitsPerPixel = 32;
    blueMax = 255;
    blueShift = 0;
    greenMax = 255;
    greenShift = 8;
    redMax = 255;
    redShift = 16;
    depth = 24;
    trueColourFlag = 1;
    return pixelFormat;
  }
  
  public static PixelFormat create16bppPixelFormat(int bigEndianFlag)
  {
    PixelFormat pixelFormat = new PixelFormat();
    bigEndianFlag = ((byte)bigEndianFlag);
    bitsPerPixel = 16;
    blueMax = 31;
    blueShift = 0;
    greenMax = 63;
    greenShift = 5;
    redMax = 31;
    redShift = 11;
    depth = 16;
    trueColourFlag = 1;
    return pixelFormat;
  }
  
  public static PixelFormat create8bppBGRPixelFormat(int bigEndianFlag)
  {
    PixelFormat pixelFormat = new PixelFormat();
    bigEndianFlag = ((byte)bigEndianFlag);
    bitsPerPixel = 8;
    redMax = 7;
    redShift = 0;
    greenMax = 7;
    greenShift = 3;
    blueMax = 3;
    blueShift = 6;
    depth = 8;
    trueColourFlag = 1;
    return pixelFormat;
  }
  
  public static PixelFormat create6bppPixelFormat(int bigEndianFlag)
  {
    PixelFormat pixelFormat = new PixelFormat();
    bigEndianFlag = ((byte)bigEndianFlag);
    bitsPerPixel = 8;
    blueMax = 3;
    blueShift = 0;
    greenMax = 3;
    greenShift = 2;
    redMax = 3;
    redShift = 4;
    depth = 6;
    trueColourFlag = 1;
    return pixelFormat;
  }
  
  public static PixelFormat create3bppPixelFormat(int bigEndianFlag)
  {
    PixelFormat pixelFormat = new PixelFormat();
    bigEndianFlag = ((byte)bigEndianFlag);
    bitsPerPixel = 8;
    blueMax = 1;
    blueShift = 0;
    greenMax = 1;
    greenShift = 1;
    redMax = 1;
    redShift = 2;
    depth = 3;
    trueColourFlag = 1;
    return pixelFormat;
  }
  
  public String toString()
  {
    return "PixelFormat: [bits-per-pixel: " + String.valueOf(0xFF & bitsPerPixel) + ", depth: " + String.valueOf(0xFF & depth) + ", big-endian-flag: " + String.valueOf(0xFF & bigEndianFlag) + ", true-color-flag: " + String.valueOf(0xFF & trueColourFlag) + ", red-max: " + String.valueOf(0xFFFF & redMax) + ", green-max: " + String.valueOf(0xFFFF & greenMax) + ", blue-max: " + String.valueOf(0xFFFF & blueMax) + ", red-shift: " + String.valueOf(0xFF & redShift) + ", green-shift: " + String.valueOf(0xFF & greenShift) + ", blue-shift: " + String.valueOf(0xFF & blueShift) + "]";
  }
}

/* Location:
 * Qualified Name:     com.glavsoft.rfb.encoding.PixelFormat
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.glavsoft.rfb.encoding;

import com.glavsoft.exceptions.TransportException;
import com.glavsoft.transport.Reader;

public class ServerInitMessage
{
  protected int frameBufferWidth;
  protected int frameBufferHeight;
  protected PixelFormat pixelFormat;
  protected String name;
  
  public ServerInitMessage(Reader reader)
    throws TransportException
  {
    frameBufferWidth = reader.readUInt16();
    frameBufferHeight = reader.readUInt16();
    pixelFormat = new PixelFormat();
    pixelFormat.fill(reader);
    name = reader.readString();
  }
  
  protected ServerInitMessage() {}
  
  public int getFrameBufferWidth()
  {
    return frameBufferWidth;
  }
  
  public int getFrameBufferHeight()
  {
    return frameBufferHeight;
  }
  
  public PixelFormat getPixelFormat()
  {
    return pixelFormat;
  }
  
  public String getName()
  {
    return name;
  }
  
  public String toString()
  {
    return "ServerInitMessage: [name: " + name + ", framebuffer-width: " + String.valueOf(frameBufferWidth) + ", framebuffer-height: " + String.valueOf(frameBufferHeight) + ", server-pixel-format: " + pixelFormat + "]";
  }
}

/* Location:
 * Qualified Name:     com.glavsoft.rfb.encoding.ServerInitMessage
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.glavsoft.rfb.encoding.decoder;

import com.glavsoft.drawing.Renderer;
import com.glavsoft.exceptions.TransportException;
import com.glavsoft.transport.Reader;

public class CopyRectDecoder
  extends Decoder
{
  public void decode(Reader reader, Renderer renderer, FramebufferUpdateRectangle rect)
    throws TransportException
  {
    int srcX = reader.readUInt16();
    int srcY = reader.readUInt16();
    if ((width == 0) || (height == 0)) {
      return;
    }
    renderer.copyRect(srcX, srcY, rect);
  }
}

/* Location:
 * Qualified Name:     com.glavsoft.rfb.encoding.decoder.CopyRectDecoder
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.glavsoft.rfb.encoding.decoder;

import com.glavsoft.drawing.Renderer;
import com.glavsoft.exceptions.TransportException;
import com.glavsoft.transport.Reader;

public class RawDecoder
  extends Decoder
{
  private static RawDecoder instance = new RawDecoder();
  
  public static RawDecoder getInstance()
  {
    return instance;
  }
  
  public void decode(Reader reader, Renderer renderer, FramebufferUpdateRectangle rect)
    throws TransportException
  {
    decode(reader, renderer, x, y, width, height);
  }
  
  public void decode(Reader reader, Renderer renderer, int x, int y, int width, int height)
    throws TransportException
  {
    int length = width * height * renderer.getBytesPerPixel();
    byte[] bytes = ByteBuffer.getInstance().getBuffer(length);
    reader.readBytes(bytes, 0, length);
    renderer.drawBytes(bytes, x, y, width, height);
  }
}

/* Location:
 * Qualified Name:     com.glavsoft.rfb.encoding.decoder.RawDecoder
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.glavsoft.rfb.encoding.decoder;

public class ByteBuffer
{
  private static ByteBuffer instance = new ByteBuffer();
  private byte[] buffer = new byte[0];
  
  public static ByteBuffer getInstance()
  {
    return instance;
  }
  
  public void correctBufferCapacity(int length)
  {
    assert (buffer != null);
    if (buffer.length < length) {
      buffer = new byte[length];
    }
  }
  
  public byte[] getBuffer(int length)
  {
    correctBufferCapacity(length);
    return buffer;
  }
}

/* Location:
 * Qualified Name:     com.glavsoft.rfb.encoding.decoder.ByteBuffer
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.glavsoft.rfb.encoding.decoder;

import com.glavsoft.drawing.ColorDecoder;
import com.glavsoft.drawing.Renderer;
import com.glavsoft.exceptions.TransportException;
import com.glavsoft.transport.Reader;
import java.util.logging.Logger;
import java.util.zip.DataFormatException;
import java.util.zip.Inflater;

public class TightDecoder
  extends Decoder
{
  private static Logger logger = Logger.getLogger("com.glavsoft.rfb.encoding.decoder");
  private static final int FILL_TYPE = 8;
  private static final int JPEG_TYPE = 9;
  private static final int FILTER_ID_MASK = 64;
  private static final int STREAM_ID_MASK = 48;
  private static final int BASIC_FILTER = 0;
  private static final int PALETTE_FILTER = 1;
  private static final int GRADIENT_FILTER = 2;
  private static final int MIN_SIZE_TO_COMPRESS = 12;
  static final int DECODERS_NUM = 4;
  Inflater[] decoders;
  private int decoderId;
  static final int tightZlibBufferSize = 512;
  
  public TightDecoder()
  {
    reset();
  }
  
  public void decode(Reader reader, Renderer renderer, FramebufferUpdateRectangle rect)
    throws TransportException
  {
    int bytesPerPixel = renderer.getBytesPerPixelSignificant();
    
    int compControl = reader.readUInt8();
    resetDecoders(compControl);
    
    int compType = compControl >> 4 & 0xF;
    switch (compType)
    {
    case 8: 
      int color = renderer.readTightPixelColor(reader);
      renderer.fillRect(color, rect);
      break;
    case 9: 
      if (bytesPerPixel != 3) {}
      processJpegType(reader, renderer, rect);
      break;
    default: 
      if (compType <= 9) {
        processBasicType(compControl, reader, renderer, rect);
      }
      break;
    }
  }
  
  private void processBasicType(int compControl, Reader reader, Renderer renderer, FramebufferUpdateRectangle rect)
    throws TransportException
  {
    decoderId = ((compControl & 0x30) >> 4);
    
    int filterId = 0;
    if ((compControl & 0x40) > 0) {
      filterId = reader.readUInt8();
    }
    int bytesPerCPixel = renderer.getBytesPerPixelSignificant();
    int lengthCurrentbpp = bytesPerCPixel * width * height;
    byte[] buffer;
    switch (filterId)
    {
    case 0: 
      buffer = readTightData(lengthCurrentbpp, reader);
      renderer.drawTightBytes(buffer, 0, x, y, width, height);
      break;
    case 1: 
      int paletteSize = reader.readUInt8() + 1;
      int[] palette = readPalette(paletteSize, reader, renderer);
      int dataLength = paletteSize == 2 ? height * ((width + 7) / 8) : width * height;
      
      buffer = readTightData(dataLength, reader);
      renderer.drawBytesWithPalette(buffer, rect, palette);
      break;
    case 2: 
      buffer = readTightData(bytesPerCPixel * width * height, reader);
      byte[][] opRows = new byte[2][width * 3 + 3];
      int opRowIndex = 0;
      byte[] components = new byte[3];
      int pixelOffset = 0;
      ColorDecoder colorDecoder = renderer.getColorDecoder();
      for (int i = 0; i < height; i++)
      {
        byte[] thisRow = opRows[opRowIndex];
        byte[] prevRow = opRows[(opRowIndex = (opRowIndex + 1) % 2)];
        for (int j = 3; j < width * 3 + 3; j += 3)
        {
          colorDecoder.fillRawComponents(components, buffer, pixelOffset);
          pixelOffset += bytesPerCPixel;
          
          int d = (0xFF & prevRow[(j + 0)]) + (0xFF & thisRow[(j + 0 - 3)]) - (0xFF & prevRow[(j + 0 - 3)]);
          
          thisRow[(j + 0)] = ((byte)(components[0] + (d > redMax ? redMax : d < 0 ? 0 : d) & redMax));
          d = (0xFF & prevRow[(j + 1)]) + (0xFF & thisRow[(j + 1 - 3)]) - (0xFF & prevRow[(j + 1 - 3)]);
          
          thisRow[(j + 1)] = ((byte)(components[1] + (d > greenMax ? greenMax : d < 0 ? 0 : d) & greenMax));
          d = (0xFF & prevRow[(j + 2)]) + (0xFF & thisRow[(j + 2 - 3)]) - (0xFF & prevRow[(j + 2 - 3)]);
          
          thisRow[(j + 2)] = ((byte)(components[2] + (d > blueMax ? blueMax : d < 0 ? 0 : d) & blueMax));
        }
        renderer.drawUncaliberedRGBLine(thisRow, x, y + i, width);
      }
      break;
    }
  }
  
  private int[] readPalette(int paletteSize, Reader reader, Renderer renderer)
    throws TransportException
  {
    int[] palette = new int[paletteSize];
    for (int i = 0; i < palette.length; i++) {
      palette[i] = renderer.readTightPixelColor(reader);
    }
    return palette;
  }
  
  private byte[] readTightData(int expectedLength, Reader reader)
    throws TransportException
  {
    if (expectedLength < 12)
    {
      byte[] buffer = ByteBuffer.getInstance().getBuffer(expectedLength);
      reader.readBytes(buffer, 0, expectedLength);
      return buffer;
    }
    return readCompressedData(expectedLength, reader);
  }
  
  private byte[] readCompressedData(int expectedLength, Reader reader)
    throws TransportException
  {
    int rawDataLength = readCompactSize(reader);
    
    byte[] buffer = ByteBuffer.getInstance().getBuffer(expectedLength + rawDataLength);
    
    reader.readBytes(buffer, expectedLength, rawDataLength);
    if (null == decoders[decoderId]) {
      decoders[decoderId] = new Inflater();
    }
    Inflater decoder = decoders[decoderId];
    decoder.setInput(buffer, expectedLength, rawDataLength);
    try
    {
      decoder.inflate(buffer, 0, expectedLength);
    }
    catch (DataFormatException e)
    {
      logger.throwing("TightDecoder", "readCompressedData", e);
      throw new TransportException("cannot inflate tight compressed data", e);
    }
    return buffer;
  }
  
  private void processJpegType(Reader reader, Renderer renderer, FramebufferUpdateRectangle rect)
    throws TransportException
  {
    int jpegBufferLength = readCompactSize(reader);
    byte[] bytes = ByteBuffer.getInstance().getBuffer(jpegBufferLength);
    reader.readBytes(bytes, 0, jpegBufferLength);
    renderer.drawJpegImage(bytes, 0, jpegBufferLength, rect);
  }
  
  private int readCompactSize(Reader reader)
    throws TransportException
  {
    int b = reader.readUInt8();
    int size = b & 0x7F;
    if ((b & 0x80) != 0)
    {
      b = reader.readUInt8();
      size += ((b & 0x7F) << 7);
      if ((b & 0x80) != 0) {
        size += (reader.readUInt8() << 14);
      }
    }
    return size;
  }
  
  private void resetDecoders(int compControl)
  {
    for (int i = 0; i < 4; i++)
    {
      if (((compControl & 0x1) != 0) && (decoders[i] != null)) {
        decoders[i].reset();
      }
      compControl >>= 1;
    }
  }
  
  public void reset()
  {
    decoders = new Inflater[4];
  }
}

/* Location:
 * Qualified Name:     com.glavsoft.rfb.encoding.decoder.TightDecoder
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.glavsoft.rfb.encoding.decoder;

import com.glavsoft.rfb.encoding.EncodingType;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.logging.Logger;

public class DecodersContainer
{
  private static Map<EncodingType, Class<? extends Decoder>> knownDecoders = new HashMap();
  
  static
  {
    knownDecoders.put(EncodingType.TIGHT, TightDecoder.class);
    knownDecoders.put(EncodingType.HEXTILE, HextileDecoder.class);
    knownDecoders.put(EncodingType.ZRLE, ZRLEDecoder.class);
    knownDecoders.put(EncodingType.ZLIB, ZlibDecoder.class);
    knownDecoders.put(EncodingType.RRE, RREDecoder.class);
    knownDecoders.put(EncodingType.COPY_RECT, CopyRectDecoder.class);
  }
  
  private final Map<EncodingType, Decoder> decoders = new HashMap();
  
  public DecodersContainer()
  {
    decoders.put(EncodingType.RAW_ENCODING, RawDecoder.getInstance());
  }
  
  public void instantiateDecodersWhenNeeded(Collection<EncodingType> encodings)
  {
    for (EncodingType enc : encodings) {
      if ((EncodingType.ordinaryEncodings.contains(enc)) && (!decoders.containsKey(enc))) {
        try
        {
          decoders.put(enc, ((Class)knownDecoders.get(enc)).newInstance());
        }
        catch (InstantiationException e)
        {
          logError(enc, e);
        }
        catch (IllegalAccessException e)
        {
          logError(enc, e);
        }
      }
    }
  }
  
  private void logError(EncodingType enc, Exception e)
  {
    Logger.getLogger(getClass().getName()).severe("Can not instantiate decoder for encoding type '" + enc.getName() + "' " + e.getMessage());
  }
  
  public Decoder getDecoderByType(EncodingType type)
  {
    return (Decoder)decoders.get(type);
  }
  
  public void resetDecoders()
  {
    for (Decoder decoder : decoders.values()) {
      if (decoder != null) {
        decoder.reset();
      }
    }
  }
}

/* Location:
 * Qualified Name:     com.glavsoft.rfb.encoding.decoder.DecodersContainer
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.glavsoft.rfb.encoding.decoder;

import com.glavsoft.drawing.Renderer;
import com.glavsoft.exceptions.TransportException;
import com.glavsoft.transport.Reader;

public class HextileDecoder
  extends Decoder
{
  private static final int DEFAULT_TILE_SIZE = 16;
  private static final int RAW_MASK = 1;
  private static final int BACKGROUND_SPECIFIED_MASK = 2;
  private static final int FOREGROUND_SPECIFIED_MASK = 4;
  private static final int ANY_SUBRECTS_MASK = 8;
  private static final int SUBRECTS_COLOURED_MASK = 16;
  private static final int FG_COLOR_INDEX = 0;
  private static final int BG_COLOR_INDEX = 1;
  
  public void decode(Reader reader, Renderer renderer, FramebufferUpdateRectangle rect)
    throws TransportException
  {
    if ((width == 0) || (height == 0)) {
      return;
    }
    int[] colors = { -1, -1 };
    int maxX = x + width;
    int maxY = y + height;
    for (int tileY = y; tileY < maxY; tileY += 16)
    {
      int tileHeight = Math.min(maxY - tileY, 16);
      for (int tileX = x; tileX < maxX; tileX += 16)
      {
        int tileWidth = Math.min(maxX - tileX, 16);
        decodeHextileSubrectangle(reader, renderer, colors, tileX, tileY, tileWidth, tileHeight);
      }
    }
  }
  
  private void decodeHextileSubrectangle(Reader reader, Renderer renderer, int[] colors, int tileX, int tileY, int tileWidth, int tileHeight)
    throws TransportException
  {
    int subencoding = reader.readUInt8();
    if ((subencoding & 0x1) != 0)
    {
      RawDecoder.getInstance().decode(reader, renderer, tileX, tileY, tileWidth, tileHeight);
      
      return;
    }
    if ((subencoding & 0x2) != 0) {
      colors[1] = renderer.readPixelColor(reader);
    }
    assert (colors[1] != -1);
    renderer.fillRect(colors[1], tileX, tileY, tileWidth, tileHeight);
    if ((subencoding & 0x4) != 0) {
      colors[0] = renderer.readPixelColor(reader);
    }
    if ((subencoding & 0x8) == 0) {
      return;
    }
    int numberOfSubrectangles = reader.readUInt8();
    boolean colorSpecified = (subencoding & 0x10) != 0;
    for (int i = 0; i < numberOfSubrectangles; i++)
    {
      if (colorSpecified) {
        colors[0] = renderer.readPixelColor(reader);
      }
      byte dimensions = reader.readByte();
      int subtileX = dimensions >> 4 & 0xF;
      int subtileY = dimensions & 0xF;
      dimensions = reader.readByte();
      int subtileWidth = 1 + (dimensions >> 4 & 0xF);
      int subtileHeight = 1 + (dimensions & 0xF);
      assert (colors[0] != -1);
      renderer.fillRect(colors[0], tileX + subtileX, tileY + subtileY, subtileWidth, subtileHeight);
    }
  }
}

/* Location:
 * Qualified Name:     com.glavsoft.rfb.encoding.decoder.HextileDecoder
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.glavsoft.rfb.encoding.decoder;

import com.glavsoft.drawing.Renderer;
import com.glavsoft.exceptions.TransportException;
import com.glavsoft.transport.Reader;

public class ZRLEDecoder
  extends ZlibDecoder
{
  private static final int DEFAULT_TILE_SIZE = 64;
  
  public void decode(Reader reader, Renderer renderer, FramebufferUpdateRectangle rect)
    throws TransportException
  {
    int zippedLength = (int)reader.readUInt32();
    if (0 == zippedLength) {
      return;
    }
    int length = width * height * renderer.getBytesPerPixel();
    byte[] bytes = unzip(reader, zippedLength, length);
    int offset = zippedLength;
    int maxX = x + width;
    int maxY = y + height;
    int[] palette = new int['?'];
    for (int tileY = y; tileY < maxY; tileY += 64)
    {
      int tileHeight = Math.min(maxY - tileY, 64);
      for (int tileX = x; tileX < maxX; tileX += 64)
      {
        int tileWidth = Math.min(maxX - tileX, 64);
        int subencoding = bytes[(offset++)] & 0xFF;
        
        boolean isRle = (subencoding & 0x80) != 0;
        
        int paletteSize = subencoding & 0x7F;
        offset += readPalette(bytes, offset, renderer, palette, paletteSize);
        if (1 == subencoding) {
          renderer.fillRect(palette[0], tileX, tileY, tileWidth, tileHeight);
        } else if (isRle)
        {
          if (0 == paletteSize) {
            offset += decodePlainRle(bytes, offset, renderer, tileX, tileY, tileWidth, tileHeight);
          } else {
            offset += decodePaletteRle(bytes, offset, renderer, palette, tileX, tileY, tileWidth, tileHeight, paletteSize);
          }
        }
        else if (0 == paletteSize) {
          offset += decodeRaw(bytes, offset, renderer, tileX, tileY, tileWidth, tileHeight);
        } else {
          offset += decodePacked(bytes, offset, renderer, palette, paletteSize, tileX, tileY, tileWidth, tileHeight);
        }
      }
    }
  }
  
  private int decodePlainRle(byte[] bytes, int offset, Renderer renderer, int tileX, int tileY, int tileWidth, int tileHeight)
  {
    int bytesPerCPixel = renderer.getBytesPerPixelSignificant();
    int[] decodedBitmap = new int[tileWidth * tileHeight];
    int decodedOffset = 0;
    int decodedEnd = tileWidth * tileHeight;
    int index = offset;
    while (decodedOffset < decodedEnd)
    {
      int color = renderer.getCompactPixelColor(bytes, index);
      index += bytesPerCPixel;
      int rlength = 1;
      do
      {
        rlength += (bytes[index] & 0xFF);
      } while ((bytes[(index++)] & 0xFF) == 255);
      assert (rlength <= decodedEnd - decodedOffset);
      renderer.fillColorBitmapWithColor(decodedBitmap, decodedOffset, rlength, color);
      decodedOffset += rlength;
    }
    renderer.drawColoredBitmap(decodedBitmap, tileX, tileY, tileWidth, tileHeight);
    return index - offset;
  }
  
  private int decodePaletteRle(byte[] bytes, int offset, Renderer renderer, int[] palette, int tileX, int tileY, int tileWidth, int tileHeight, int paletteSize)
  {
    int[] decodedBitmap = new int[tileWidth * tileHeight];
    int decodedOffset = 0;
    int decodedEnd = tileWidth * tileHeight;
    int index = offset;
    while (decodedOffset < decodedEnd)
    {
      int colorIndex = bytes[(index++)];
      int color = palette[(colorIndex & 0x7F)];
      int rlength = 1;
      if ((colorIndex & 0x80) != 0) {
        do
        {
          rlength += (bytes[index] & 0xFF);
        } while (bytes[(index++)] == -1);
      }
      assert (rlength <= decodedEnd - decodedOffset);
      renderer.fillColorBitmapWithColor(decodedBitmap, decodedOffset, rlength, color);
      decodedOffset += rlength;
    }
    renderer.drawColoredBitmap(decodedBitmap, tileX, tileY, tileWidth, tileHeight);
    return index - offset;
  }
  
  private int decodePacked(byte[] bytes, int offset, Renderer renderer, int[] palette, int paletteSize, int tileX, int tileY, int tileWidth, int tileHeight)
  {
    int[] decodedBytes = new int[tileWidth * tileHeight];
    int bitsPerPalletedPixel = paletteSize > 2 ? 2 : paletteSize > 4 ? 4 : paletteSize > 16 ? 8 : 1;
    
    int packedOffset = offset;
    int decodedOffset = 0;
    for (int i = 0; i < tileHeight; i++)
    {
      int decodedRowEnd = decodedOffset + tileWidth;
      int byteProcessed = 0;
      int bitsRemain = 0;
      while (decodedOffset < decodedRowEnd)
      {
        if (bitsRemain == 0)
        {
          byteProcessed = bytes[(packedOffset++)];
          bitsRemain = 8;
        }
        bitsRemain -= bitsPerPalletedPixel;
        int index = byteProcessed >> bitsRemain & (1 << bitsPerPalletedPixel) - 1 & 0x7F;
        int color = palette[index];
        renderer.fillColorBitmapWithColor(decodedBytes, decodedOffset, 1, color);
        decodedOffset++;
      }
    }
    renderer.drawColoredBitmap(decodedBytes, tileX, tileY, tileWidth, tileHeight);
    return packedOffset - offset;
  }
  
  private int decodeRaw(byte[] bytes, int offset, Renderer renderer, int tileX, int tileY, int tileWidth, int tileHeight)
    throws TransportException
  {
    return renderer.drawCompactBytes(bytes, offset, tileX, tileY, tileWidth, tileHeight);
  }
  
  private int readPalette(byte[] bytes, int offset, Renderer renderer, int[] palette, int paletteSize)
  {
    for (int i = 0; i < paletteSize; i++) {
      palette[i] = renderer.getCompactPixelColor(bytes, offset + i * renderer.getBytesPerPixelSignificant());
    }
    return paletteSize * renderer.getBytesPerPixelSignificant();
  }
}

/* Location:
 * Qualified Name:     com.glavsoft.rfb.encoding.decoder.ZRLEDecoder
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.glavsoft.rfb.encoding.decoder;

import com.glavsoft.drawing.Renderer;
import com.glavsoft.exceptions.TransportException;
import com.glavsoft.transport.Reader;

public class RichCursorDecoder
  extends Decoder
{
  private static RichCursorDecoder instance = new RichCursorDecoder();
  
  public static RichCursorDecoder getInstance()
  {
    return instance;
  }
  
  public void decode(Reader reader, Renderer renderer, FramebufferUpdateRectangle rect)
    throws TransportException
  {
    int bytesPerPixel = renderer.getBytesPerPixel();
    int length = width * height * bytesPerPixel;
    if (0 == length) {
      return;
    }
    byte[] buffer = ByteBuffer.getInstance().getBuffer(length);
    reader.readBytes(buffer, 0, length);
    
    StringBuilder sb = new StringBuilder(" ");
    for (int i = 0; i < length; i++) {
      sb.append(Integer.toHexString(buffer[i] & 0xFF)).append(" ");
    }
    int scanLine = (int)Math.floor((width + 7) / 8);
    byte[] bitmask = new byte[scanLine * height];
    reader.readBytes(bitmask, 0, bitmask.length);
    
    sb = new StringBuilder(" ");
    for (int i = 0; i < bitmask.length; i++) {
      sb.append(Integer.toHexString(bitmask[i] & 0xFF)).append(" ");
    }
    int[] cursorPixels = new int[width * height];
    for (int y = 0; y < height; y++) {
      for (int x = 0; x < width; x++)
      {
        int offset = y * width + x;
        cursorPixels[offset] = (isBitSet(bitmask[(y * scanLine + x / 8)], x % 8) ? 0xFF000000 | renderer.getPixelColor(buffer, offset * bytesPerPixel) : 0);
      }
    }
    renderer.createCursor(cursorPixels, rect);
  }
  
  private boolean isBitSet(byte aByte, int index)
  {
    return (aByte & 1 << 7 - index) > 0;
  }
}

/* Location:
 * Qualified Name:     com.glavsoft.rfb.encoding.decoder.RichCursorDecoder
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.glavsoft.rfb.encoding.decoder;

import com.glavsoft.drawing.Renderer;
import com.glavsoft.exceptions.TransportException;
import com.glavsoft.transport.Reader;

public class RREDecoder
  extends Decoder
{
  public void decode(Reader reader, Renderer renderer, FramebufferUpdateRectangle rect)
    throws TransportException
  {
    int numOfSubrectangles = reader.readInt32();
    int color = renderer.readPixelColor(reader);
    renderer.fillRect(color, rect);
    for (int i = 0; i < numOfSubrectangles; i++)
    {
      color = renderer.readPixelColor(reader);
      int x = reader.readUInt16();
      int y = reader.readUInt16();
      int width = reader.readUInt16();
      int height = reader.readUInt16();
      renderer.fillRect(color, x + x, y + y, width, height);
    }
  }
}

/* Location:
 * Qualified Name:     com.glavsoft.rfb.encoding.decoder.RREDecoder
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.glavsoft.rfb.encoding.decoder;

import com.glavsoft.drawing.Renderer;
import com.glavsoft.exceptions.TransportException;
import com.glavsoft.transport.Reader;

public abstract class Decoder
{
  public abstract void decode(Reader paramReader, Renderer paramRenderer, FramebufferUpdateRectangle paramFramebufferUpdateRectangle)
    throws TransportException;
  
  public void reset() {}
}

/* Location:
 * Qualified Name:     com.glavsoft.rfb.encoding.decoder.Decoder
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.glavsoft.rfb.encoding.decoder;

import com.glavsoft.exceptions.TransportException;
import com.glavsoft.rfb.encoding.EncodingType;
import com.glavsoft.transport.Reader;

public class FramebufferUpdateRectangle
{
  public int x;
  public int y;
  public int width;
  public int height;
  private EncodingType encodingType;
  
  public FramebufferUpdateRectangle() {}
  
  public FramebufferUpdateRectangle(int x, int y, int w, int h)
  {
    this.x = x;this.y = y;
    width = w;height = h;
  }
  
  public void fill(Reader reader)
    throws TransportException
  {
    x = reader.readUInt16();
    y = reader.readUInt16();
    width = reader.readUInt16();
    height = reader.readUInt16();
    int encoding = reader.readInt32();
    encodingType = EncodingType.byId(encoding);
  }
  
  public EncodingType getEncodingType()
  {
    return encodingType;
  }
  
  public String toString()
  {
    return "FramebufferUpdateRect: [x: " + x + ", y: " + y + ", width: " + width + ", height: " + height + ", encodingType: " + encodingType + "]";
  }
}

/* Location:
 * Qualified Name:     com.glavsoft.rfb.encoding.decoder.FramebufferUpdateRectangle
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.glavsoft.rfb.encoding.decoder;

import com.glavsoft.drawing.Renderer;
import com.glavsoft.exceptions.TransportException;
import com.glavsoft.transport.Reader;
import java.io.ByteArrayInputStream;
import java.util.zip.DataFormatException;
import java.util.zip.Inflater;

public class ZlibDecoder
  extends Decoder
{
  private Inflater decoder;
  
  public void decode(Reader reader, Render
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd