diff --git a/bin/SigShare.jar b/bin/SigShare.jar index ad402b0..7ab39b3 100644 Binary files a/bin/SigShare.jar and b/bin/SigShare.jar differ diff --git a/src/sig/SigShare.java b/src/sig/SigShare.java index 7a65ccf..e8b8d61 100644 --- a/src/sig/SigShare.java +++ b/src/sig/SigShare.java @@ -1,6 +1,8 @@ package sig; import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.DataOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; @@ -13,9 +15,16 @@ import javax.swing.JFrame; import java.awt.Toolkit; import sig.engine.Panel; +import java.awt.AWTException; +import java.awt.GraphicsEnvironment; +import java.awt.image.BufferedImage; +import java.awt.Robot; + public class SigShare { + static Robot r; public static final String PROGRAM_NAME="SigShare"; - public static void main(String[] args) { + public static void main(String[] args) throws AWTException { + r = new Robot(); if (args.length==2&&args[1].equalsIgnoreCase("server")) { ServerSocket socket; try { @@ -25,16 +34,53 @@ public class SigShare { System.out.println("New client connection detected: "+client.toString()); System.out.println("Sending initial data..."); BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream(),"ISO-8859-1")); - OutputStream clientOutput = client.getOutputStream(); - int SCREEN_WIDTH=(int)Toolkit.getDefaultToolkit().getScreenSize().getWidth(); - int SCREEN_HEIGHT=(int)Toolkit.getDefaultToolkit().getScreenSize().getHeight(); - clientOutput.write(("DESKTOP "+(int)Toolkit.getDefaultToolkit().getScreenSize().getWidth()+" "+(int)Toolkit.getDefaultToolkit().getScreenSize().getHeight()+"\r\n").getBytes()); + DataOutputStream clientOutput = new DataOutputStream(client.getOutputStream()); + int SCREEN_WIDTH=(int)GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().getWidth(); + int SCREEN_HEIGHT=(int)GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().getHeight(); + int[] pixels = new int[SCREEN_WIDTH*SCREEN_HEIGHT]; + clientOutput.write(("DESKTOP "+SCREEN_WIDTH+" "+SCREEN_HEIGHT+"\r\n").getBytes()); System.out.println("Send initial screen"); + //char[] screen = new char[SCREEN_WIDTH*SCREEN_HEIGHT]; + BufferedImage screenshot = CaptureScreen(); for (int y=0;y>>16)/8; + int g = ((col&0x0000FF00)>>>8)/8; + int b = ((col&0x000000FF))/8; + char compressedCol=(char)((r<<10)+(g<<5)+b); + clientOutput.writeChar(compressedCol); + //screen[y*SCREEN_WIDTH+x]=compressedCol; } } + System.out.println("Begin diff monitoring..."); + int frame=0; + while (true) { + screenshot = CaptureScreen(); + for (int y=0;y>>8)+((y&0xF)<<4)); //bits 9-12 for x, bits 1-4 for y + b3=(byte)(y&0xFF0>>>4);//bits 5-12 for y + pixels[y*SCREEN_WIDTH+x]=col; + int r = ((col&0x00FF0000)>>>16)/8; + int g = ((col&0x0000FF00)>>>8)/8; + int b = ((col&0x000000FF))/8; + char compressedCol=(char)((r<<10)+(g<<5)+b); + clientOutput.writeChar(compressedCol); + clientOutput.writeByte(b1); + clientOutput.writeByte(b2); + clientOutput.writeByte(b3); + System.out.println(" Pixel ("+x+","+y+") "+b1+"/"+(b2&0xF)+"/"+(b2&0xF0)+"/"+b3+" sent"); + } + //screen[y*SCREEN_WIDTH+x]=compressedCol; + } + } + System.out.println("Frame "+frame+++" processed"); + } } catch (IOException e) { e.printStackTrace(); } @@ -45,7 +91,7 @@ public class SigShare { if (args.length==2&&args[1].equalsIgnoreCase("client")) { Socket socket; PrintWriter out; - BufferedReader in; + DataInputStream in; JFrame f = new JFrame(PROGRAM_NAME); Panel p = new Panel(f); @@ -53,25 +99,56 @@ public class SigShare { try { socket = new Socket(args[0],4191); out = new PrintWriter(socket.getOutputStream(),true); - in=new BufferedReader(new InputStreamReader(socket.getInputStream())); + in=new DataInputStream(socket.getInputStream()); while (true) { String line; - if (in.ready()) { + if (in.available()>0) { line=in.readLine(); //System.out.println(line); if (line.contains("DESKTOP")) { String[] split = line.split(Pattern.quote(" ")); - p.init(); + int SCREEN_WIDTH=Integer.parseInt(split[1]); + int SCREEN_HEIGHT=Integer.parseInt(split[2]); + p.init(SCREEN_WIDTH,SCREEN_HEIGHT); f.add(p); - f.setSize(Integer.parseInt(split[1]),Integer.parseInt(split[2])); + f.setSize(SCREEN_WIDTH,SCREEN_HEIGHT); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); - + + int expectedChars = SCREEN_WIDTH*SCREEN_HEIGHT; + System.out.println("Expecting "+(expectedChars)+" of data."); + int arrayIndex = 0; + while (expectedChars>0) { + if (in.available()>0) { + char col = in.readChar(); + int convert = ((((col&0b0111110000000000)>>>10)*8)<<16)+ + ((((col&0b0000001111100000)*8)>>>5)<<8)+ + ((((col&0b0000000000011111))*8)); + Panel.pixel[arrayIndex++]=convert; + //System.out.println("Received "+col+" / "+convert); + expectedChars--; + } + } p.render(); + System.out.println("Initial image processed!"); + int frame=0; + while (true) { + if (in.available()>0) { + char col = in.readChar(); + int convert = ((((col&0b0111110000000000)>>>10)*8)<<16)+ + ((((col&0b0000001111100000)*8)>>>5)<<8)+ + ((((col&0b0000000000011111))*8)); + int b1=in.readUnsignedByte(),b2=in.readUnsignedByte(),b3=in.readUnsignedByte(); + int x = b1+((b2&0xF)<<8); + int y = (b3<<4)+(b2&0xF0); + Panel.pixel[y*SCREEN_WIDTH+x]=convert; + System.out.println(" Pixel "+frame+++" ("+x+","+y+") "+b1+"/"+(b2&0xF)+"/"+(b2&0xF0)+"/"+b3+" processed"); + } + } } } } @@ -83,4 +160,9 @@ public class SigShare { return; } } + private static BufferedImage CaptureScreen() throws IOException { + BufferedImage screenshot = r.createScreenCapture(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds()); + //ImageIO.write(screenshot,"png",new File("screenshot.png")); + return screenshot; + } } diff --git a/src/sig/engine/Panel.java b/src/sig/engine/Panel.java index caa9363..146c6d0 100644 --- a/src/sig/engine/Panel.java +++ b/src/sig/engine/Panel.java @@ -16,7 +16,9 @@ import sig.SigShare; public class Panel extends JPanel implements Runnable { JFrame window; - public int pixel[]; + public static int pixel[]; + int SCREEN_WIDTH=0; + int SCREEN_HEIGHT=0; final int CIRCLE_PRECISION=32; final int OUTLINE_COL=Color.BRIGHT_WHITE.getColor(); private Thread thread; @@ -51,16 +53,18 @@ public class Panel extends JPanel implements Runnable { /** * Call it after been visible and after resizes. */ - public void init(){ + public void init(int width,int height){ + this.SCREEN_WIDTH=width; + this.SCREEN_HEIGHT=height; cm = getCompatibleColorModel(); - int screenSize = getWidth() * getHeight(); + int screenSize = SCREEN_WIDTH * SCREEN_HEIGHT; if(pixel == null || pixel.length < screenSize){ pixel = new int[screenSize]; } if(thread.isInterrupted() || !thread.isAlive()){ thread.start(); } - mImageProducer = new MemoryImageSource(getWidth(), getHeight(), cm, pixel,0, getWidth()); + mImageProducer = new MemoryImageSource(SCREEN_WIDTH, SCREEN_HEIGHT, cm, pixel,0, SCREEN_WIDTH); mImageProducer.setAnimated(true); mImageProducer.setFullBufferUpdates(true); imageBuffer = Toolkit.getDefaultToolkit().createImage(mImageProducer); @@ -106,7 +110,7 @@ public class Panel extends JPanel implements Runnable { public void FillRect(int[] p,Color col,double x,double y,double w,double h) { for (int xx=0;xx=0) { Draw(p,index,col.getColor()); }