-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from seujorgenochurras/screen-parse
Major optimization, 10x faster
- Loading branch information
Showing
17 changed files
with
209 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/main/java/io/github/seujorgenochurras/ScreenParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package io.github.seujorgenochurras; | ||
|
||
import io.github.seujorgenochurras.color.BestSymbolPatternFinder; | ||
import io.github.seujorgenochurras.image.BetterImage; | ||
import io.github.seujorgenochurras.image.ascii.AsciiParser; | ||
import io.github.seujorgenochurras.image.ascii.ParserBuilder; | ||
import io.github.seujorgenochurras.image.ascii.ParserConfig; | ||
import io.github.seujorgenochurras.image.ascii.algorithm.pixel.bright.Algorithms; | ||
import io.github.seujorgenochurras.image.ascii.algorithm.pixel.color.DefaultColorType; | ||
|
||
import java.awt.*; | ||
import java.util.Timer; | ||
import java.util.TimerTask; | ||
|
||
import static io.github.seujorgenochurras.util.StringUtils.getUTFChars; | ||
|
||
public class ScreenParser { | ||
public static final String[] symbols = BestSymbolPatternFinder. | ||
findBestPattern(2, 55, getUTFChars(32, 126)).toArray(); | ||
|
||
|
||
public static final ParserConfig defaultParserConfig = ParserBuilder.startBuild() | ||
.symbols(symbols) | ||
.scaled() | ||
.height(80) | ||
.width(400) | ||
.getScale() | ||
.parserAlgorithm(Algorithms.HUMAN_EYE_ALGORITHM.getAlgorithm()) | ||
.colorAlgorithm(DefaultColorType.ANSI) | ||
.build(); | ||
|
||
|
||
public static void main(String[] args) throws AWTException { | ||
if (args[0] == null || args[1] == null) { | ||
args[0] = "80"; | ||
args[1] = "300"; | ||
} | ||
|
||
final ParserConfig defaultParserConfig = ParserBuilder.startBuild() | ||
.symbols(symbols) | ||
.scaled() | ||
.height(Integer.parseInt(args[1])) | ||
.width(Integer.parseInt(args[0])) | ||
.getScale() | ||
.parserAlgorithm(Algorithms.HUMAN_EYE_ALGORITHM.getAlgorithm()) | ||
// .colorAlgorithm(DefaultColorType.ANSI) | ||
.build(); | ||
|
||
|
||
Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize(); | ||
Rectangle screenRect = new Rectangle(screenDimension); | ||
Robot robot = new Robot(); | ||
System.out.print("\u001b[2J"); | ||
final double[] fps = {1}; | ||
final int[] framesThisSecond = {0}; | ||
TimerTask task = new TimerTask() { | ||
@Override | ||
public void run() { | ||
fps[0] = framesThisSecond[0]; | ||
framesThisSecond[0] = 0; | ||
|
||
} | ||
}; | ||
Timer timer = new Timer("Timer"); | ||
int delay = 1000; | ||
timer.scheduleAtFixedRate(task, 0, delay); | ||
|
||
while (true) { | ||
framesThisSecond[0]++; | ||
System.out.print("\u001B[1;1H"); | ||
System.out.print(AsciiParser.parse(new BetterImage(robot.createScreenCapture(screenRect)), defaultParserConfig)); | ||
System.out.println("\u001B[0;1000H Current fps: " + fps[0]); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.