Add a keyframe system to refresh the entire region at times

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2 3 years ago
parent 67fd650384
commit d81ab8e569
  1. BIN
      bin/SigShare.jar
  2. BIN
      bin/screenshot.jpg
  3. BIN
      bin/screenshot_out.jpg
  4. BIN
      bin/screenshot_part.jpg
  5. 123
      src/sig/SigShare.java

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 122 KiB

After

Width:  |  Height:  |  Size: 109 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 0 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

@ -45,7 +45,7 @@ public class SigShare {
public static int REGION_WIDTH = SCREEN_WIDTH/REGION_X_COUNT; public static int REGION_WIDTH = SCREEN_WIDTH/REGION_X_COUNT;
public static int REGION_HEIGHT = SCREEN_HEIGHT/REGION_Y_COUNT; public static int REGION_HEIGHT = SCREEN_HEIGHT/REGION_Y_COUNT;
public static long LAST_CLEANUP = System.currentTimeMillis(); public static long LAST_CLEANUP = System.currentTimeMillis();
public static int CLEANUP_FREQUENCY = 2000; public static int CLEANUP_FREQUENCY = 5000;
public static HashMap<Character,Boolean> REGION_CHECK = new HashMap<>(); public static HashMap<Character,Boolean> REGION_CHECK = new HashMap<>();
public static void main(String[] args) throws AWTException { public static void main(String[] args) throws AWTException {
r = new Robot(); r = new Robot();
@ -97,48 +97,64 @@ public class SigShare {
in.readLine(); in.readLine();
System.out.println("Begin diff analysis mode."); System.out.println("Begin diff analysis mode.");
while (true) { while (true) {
boolean fullCleanup=false;
BufferedImage newCapture = CaptureScreen(SCREEN_WIDTH,SCREEN_HEIGHT); BufferedImage newCapture = CaptureScreen(SCREEN_WIDTH,SCREEN_HEIGHT);
REGION_CHECK.clear(); REGION_CHECK.clear();
for (int y=0;y<newCapture.getHeight();y++) { if (System.currentTimeMillis()-LAST_CLEANUP>=CLEANUP_FREQUENCY) {
for (int x=0;x<newCapture.getWidth();x++) { System.out.println("New full refresh");
int currentPixel = img[y*newCapture.getWidth()+x]; CaptureScreen(SCREEN_WIDTH,SCREEN_HEIGHT);
int newPixel = newCapture.getRGB(x, y)&0x00FFFFFF; clientOutput.write(255);
int gridX = x/REGION_WIDTH; stream = new FileInputStream(new File("screenshot.jpg"));
int gridY = y/REGION_HEIGHT; while (stream.available()>0) {
if (System.currentTimeMillis()-CLEANUP_FREQUENCY>=5000) { clientOutput.writeByte(stream.read());
if (!REGION_CHECK.containsKey((char)(gridY*REGION_X_COUNT+gridX))) { }
performSubimageUpdate(in, clientOutput, newCapture, gridX, gridY); stream.close();
image = ImageIO.read(new File("screenshot.jpg"));
for (int y=0;y<image.getHeight();y++) {
for (int x=0;x<image.getWidth();x++) {
img[y*image.getWidth()+x]=image.getRGB(x, y)&0x00FFFFFF;
} }
fullCleanup=true; }
} else for (int i=0;i<10;i++) {
if (currentPixel!=newPixel) { clientOutput.writeChar('-');
img[y*newCapture.getWidth()+x]=newPixel; }
//System.out.println("Changes ("+gridX+","+gridY+"): "+changes[gridY*REGION_X_COUNT+gridX]); System.out.println("Frame "+frame+++" processed. Waiting on client.");
if (!REGION_CHECK.containsKey((char)(gridY*REGION_X_COUNT+gridX))) { while (!in.ready()) {
changes[gridY*REGION_X_COUNT+gridX]+=2; }
if (gridY>0) { System.out.println("Client no longer idle.");
changes[(gridY-1)*REGION_X_COUNT+gridX]+=1; in.readLine();
} LAST_CLEANUP=System.currentTimeMillis();
if (gridY<REGION_Y_COUNT-1) { } else {
changes[(gridY+1)*REGION_X_COUNT+gridX]+=1; for (int y=0;y<newCapture.getHeight();y++) {
} for (int x=0;x<newCapture.getWidth();x++) {
if (gridX>0) { int currentPixel = img[y*newCapture.getWidth()+x];
changes[(gridY)*REGION_X_COUNT+(gridX-1)]+=1; int newPixel = newCapture.getRGB(x, y)&0x00FFFFFF;
} int gridX = x/REGION_WIDTH;
if (gridX<REGION_Y_COUNT-1) { int gridY = y/REGION_HEIGHT;
changes[(gridY)*REGION_X_COUNT+(gridX+1)]+=1; if (currentPixel!=newPixel) {
} img[y*newCapture.getWidth()+x]=newPixel;
if (changes[gridY*REGION_X_COUNT+gridX]>=CHANGE_THRESHOLD) { //System.out.println("Changes ("+gridX+","+gridY+"): "+changes[gridY*REGION_X_COUNT+gridX]);
performSubimageUpdate(in, clientOutput, newCapture, gridX, gridY); if (!REGION_CHECK.containsKey((char)(gridY*REGION_X_COUNT+gridX))) {
changes[gridY*REGION_X_COUNT+gridX]+=2;
if (gridY>0) {
changes[(gridY-1)*REGION_X_COUNT+gridX]+=1;
}
if (gridY<REGION_Y_COUNT-1) {
changes[(gridY+1)*REGION_X_COUNT+gridX]+=1;
}
if (gridX>0) {
changes[(gridY)*REGION_X_COUNT+(gridX-1)]+=1;
}
if (gridX<REGION_Y_COUNT-1) {
changes[(gridY)*REGION_X_COUNT+(gridX+1)]+=1;
}
if (changes[gridY*REGION_X_COUNT+gridX]>=CHANGE_THRESHOLD) {
performSubimageUpdate(in, clientOutput, newCapture, gridX, gridY);
}
} }
} }
} }
} }
} }
if (fullCleanup) {
LAST_CLEANUP=System.currentTimeMillis();
}
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
@ -223,6 +239,43 @@ public class SigShare {
while (in.available()>0) { while (in.available()>0) {
if (regionInfo==-1) { if (regionInfo==-1) {
regionInfo=in.read(); regionInfo=in.read();
if (regionInfo==255) {
System.out.println("Full refresh received.");
while (true) {
while (in.available()>0) {
if (stream==null) {
//System.out.println("Stream opened.");
stream=new BufferedOutputStream(new FileOutputStream(new File("screenshot_out.jpg"),true));
}
int val = in.read();
stream.write(val);
//System.out.print((char)val);
if (val=='-') {
dashCount++;
} else
if (val!=0) {
dashCount=0;
}
}
if (dashCount>=10) {
stream.close();
stream=null;
dashCount=0;
System.out.println("Frame "+frame+++" processed.");
BufferedImage i = ImageIO.read(new File("screenshot_out.jpg"));
if (i!=null) {
for (int y=0;y<i.getHeight();y++) {
for (int x=0;x<i.getWidth();x++) {
Panel.pixel[y*SCREEN_WIDTH+x]=i.getRGB(x,y);
}
}
}
out.writeChars("Done\r\n");
stream=new BufferedOutputStream(new FileOutputStream(new File("screenshot_out.jpg"),false));
break;
}
}
}
} else { } else {
while (in.available()>0) { while (in.available()>0) {
if (stream==null) { if (stream==null) {

Loading…
Cancel
Save