create diff sending,

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2 3 years ago
parent 90ac96e9cb
commit 2c016ac217
  1. BIN
      bin/SigShare.jar
  2. 106
      src/sig/SigShare.java
  3. 16
      src/sig/engine/Panel.java

Binary file not shown.

@ -1,6 +1,8 @@
package sig; package sig;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
@ -13,9 +15,16 @@ import javax.swing.JFrame;
import java.awt.Toolkit; import java.awt.Toolkit;
import sig.engine.Panel; import sig.engine.Panel;
import java.awt.AWTException;
import java.awt.GraphicsEnvironment;
import java.awt.image.BufferedImage;
import java.awt.Robot;
public class SigShare { public class SigShare {
static Robot r;
public static final String PROGRAM_NAME="SigShare"; 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")) { if (args.length==2&&args[1].equalsIgnoreCase("server")) {
ServerSocket socket; ServerSocket socket;
try { try {
@ -25,16 +34,53 @@ public class SigShare {
System.out.println("New client connection detected: "+client.toString()); System.out.println("New client connection detected: "+client.toString());
System.out.println("Sending initial data..."); System.out.println("Sending initial data...");
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream(),"ISO-8859-1")); BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream(),"ISO-8859-1"));
OutputStream clientOutput = client.getOutputStream(); DataOutputStream clientOutput = new DataOutputStream(client.getOutputStream());
int SCREEN_WIDTH=(int)Toolkit.getDefaultToolkit().getScreenSize().getWidth(); int SCREEN_WIDTH=(int)GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().getWidth();
int SCREEN_HEIGHT=(int)Toolkit.getDefaultToolkit().getScreenSize().getHeight(); int SCREEN_HEIGHT=(int)GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().getHeight();
clientOutput.write(("DESKTOP "+(int)Toolkit.getDefaultToolkit().getScreenSize().getWidth()+" "+(int)Toolkit.getDefaultToolkit().getScreenSize().getHeight()+"\r\n").getBytes()); int[] pixels = new int[SCREEN_WIDTH*SCREEN_HEIGHT];
clientOutput.write(("DESKTOP "+SCREEN_WIDTH+" "+SCREEN_HEIGHT+"\r\n").getBytes());
System.out.println("Send initial screen"); System.out.println("Send initial screen");
//char[] screen = new char[SCREEN_WIDTH*SCREEN_HEIGHT];
BufferedImage screenshot = CaptureScreen();
for (int y=0;y<SCREEN_HEIGHT;y++) { for (int y=0;y<SCREEN_HEIGHT;y++) {
for (int x=0;x<SCREEN_WIDTH;x++) { for (int x=0;x<SCREEN_WIDTH;x++) {
int col = pixels[y*SCREEN_WIDTH+x] = screenshot.getRGB(x, y);
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);
//screen[y*SCREEN_WIDTH+x]=compressedCol;
} }
} }
System.out.println("Begin diff monitoring...");
int frame=0;
while (true) {
screenshot = CaptureScreen();
for (int y=0;y<SCREEN_HEIGHT;y++) {
for (int x=0;x<SCREEN_WIDTH;x++) {
int col = screenshot.getRGB(x, y);
byte b1=0,b2=0,b3=0;
if (col!=pixels[y*SCREEN_WIDTH+x]) {
b1=(byte)(x&0xFF); //bits 1-8 for x
b2=(byte)(((x&0xF00)>>>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) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -45,7 +91,7 @@ public class SigShare {
if (args.length==2&&args[1].equalsIgnoreCase("client")) { if (args.length==2&&args[1].equalsIgnoreCase("client")) {
Socket socket; Socket socket;
PrintWriter out; PrintWriter out;
BufferedReader in; DataInputStream in;
JFrame f = new JFrame(PROGRAM_NAME); JFrame f = new JFrame(PROGRAM_NAME);
Panel p = new Panel(f); Panel p = new Panel(f);
@ -53,25 +99,56 @@ public class SigShare {
try { try {
socket = new Socket(args[0],4191); socket = new Socket(args[0],4191);
out = new PrintWriter(socket.getOutputStream(),true); out = new PrintWriter(socket.getOutputStream(),true);
in=new BufferedReader(new InputStreamReader(socket.getInputStream())); in=new DataInputStream(socket.getInputStream());
while (true) { while (true) {
String line; String line;
if (in.ready()) { if (in.available()>0) {
line=in.readLine(); line=in.readLine();
//System.out.println(line); //System.out.println(line);
if (line.contains("DESKTOP")) { if (line.contains("DESKTOP")) {
String[] split = line.split(Pattern.quote(" ")); 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.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.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true); 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(); 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; return;
} }
} }
private static BufferedImage CaptureScreen() throws IOException {
BufferedImage screenshot = r.createScreenCapture(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds());
//ImageIO.write(screenshot,"png",new File("screenshot.png"));
return screenshot;
}
} }

@ -16,7 +16,9 @@ import sig.SigShare;
public class Panel extends JPanel implements Runnable { public class Panel extends JPanel implements Runnable {
JFrame window; JFrame window;
public int pixel[]; public static int pixel[];
int SCREEN_WIDTH=0;
int SCREEN_HEIGHT=0;
final int CIRCLE_PRECISION=32; final int CIRCLE_PRECISION=32;
final int OUTLINE_COL=Color.BRIGHT_WHITE.getColor(); final int OUTLINE_COL=Color.BRIGHT_WHITE.getColor();
private Thread thread; private Thread thread;
@ -51,16 +53,18 @@ public class Panel extends JPanel implements Runnable {
/** /**
* Call it after been visible and after resizes. * 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(); cm = getCompatibleColorModel();
int screenSize = getWidth() * getHeight(); int screenSize = SCREEN_WIDTH * SCREEN_HEIGHT;
if(pixel == null || pixel.length < screenSize){ if(pixel == null || pixel.length < screenSize){
pixel = new int[screenSize]; pixel = new int[screenSize];
} }
if(thread.isInterrupted() || !thread.isAlive()){ if(thread.isInterrupted() || !thread.isAlive()){
thread.start(); 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.setAnimated(true);
mImageProducer.setFullBufferUpdates(true); mImageProducer.setFullBufferUpdates(true);
imageBuffer = Toolkit.getDefaultToolkit().createImage(mImageProducer); 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) { public void FillRect(int[] p,Color col,double x,double y,double w,double h) {
for (int xx=0;xx<w;xx++) { for (int xx=0;xx<w;xx++) {
for (int yy=0;yy<h;yy++) { for (int yy=0;yy<h;yy++) {
int index = ((int)y+yy)*getWidth()+(int)x+xx; int index = ((int)y+yy)*SCREEN_WIDTH+(int)x+xx;
p[index]=col.getColor(); p[index]=col.getColor();
} }
} }
@ -179,7 +183,7 @@ public class Panel extends JPanel implements Runnable {
Edge e2 = active_edges.get(i+1); Edge e2 = active_edges.get(i+1);
//System.out.println("Drawing from "+((int)Math.round(e1.x_of_min_y))+" to "+e2.x_of_min_y+" on line "+scanLine); //System.out.println("Drawing from "+((int)Math.round(e1.x_of_min_y))+" to "+e2.x_of_min_y+" on line "+scanLine);
for (int x=(int)Math.round(e1.x_of_min_y);x<=e2.x_of_min_y;x++) { for (int x=(int)Math.round(e1.x_of_min_y);x<=e2.x_of_min_y;x++) {
int index = (scanLine+(int)y_offset)*getWidth()+x+(int)x_offset; int index = (scanLine+(int)y_offset)*SCREEN_WIDTH+x+(int)x_offset;
if (index<p.length&&index>=0) { if (index<p.length&&index>=0) {
Draw(p,index,col.getColor()); Draw(p,index,col.getColor());
} }

Loading…
Cancel
Save