From 4037757857d3ab1124c5beef3cdeecab56e8b203 Mon Sep 17 00:00:00 2001 From: "sigonasr2, Sig, Sigo" Date: Thu, 11 Aug 2022 20:31:12 +0000 Subject: [PATCH] Introduce beginnings of custom number reader / learner Co-authored-by: sigonasr2 --- readers/Box.java | 9 +++-- readers/ColorRange.java | 6 ++-- readers/fonts/Font.java | 78 ++++++++++++++++++++++++++++++++++++++++ readers/fonts/Glyph.java | 7 ++++ readers/fonts/testFont | 0 sigPlace.java | 63 +++++++++++++++++++++++++++++++- 6 files changed, 156 insertions(+), 7 deletions(-) create mode 100644 readers/fonts/Font.java create mode 100644 readers/fonts/Glyph.java create mode 100644 readers/fonts/testFont diff --git a/readers/Box.java b/readers/Box.java index 75b8e9e..2f0c678 100644 --- a/readers/Box.java +++ b/readers/Box.java @@ -1,10 +1,13 @@ package readers; -class Box{ - int x,y,w,h; +public class Box{ + public int x; + public int y; + public int w; + public int h; boolean ja_required; final static int BOX_THRESHOLD=8; //How many pixels outside the specified region the score can be. - Box(int x,int y,int w, int h) { + public Box(int x,int y,int w, int h) { this.x=x; this.y=y; this.w=w; diff --git a/readers/ColorRange.java b/readers/ColorRange.java index de4b157..dfdeea7 100644 --- a/readers/ColorRange.java +++ b/readers/ColorRange.java @@ -1,11 +1,11 @@ package readers; import java.awt.Color; -class ColorRange{ +public class ColorRange{ int r_h,r_l; int g_h,g_l; int b_h,b_l; - ColorRange(int r_l,int r_h,int g_l,int g_h,int b_l,int b_h) { + public ColorRange(int r_l,int r_h,int g_l,int g_h,int b_l,int b_h) { this.r_l=r_l; this.r_h=r_h; this.g_l=g_l; @@ -13,7 +13,7 @@ class ColorRange{ this.b_l=b_l; this.b_h=b_h; } - boolean colorInRange(Color col) { + public boolean colorInRange(Color col) { return col.getRed()>=r_l&&col.getRed()<=r_h&&col.getGreen()>=g_l&&col.getGreen()<=g_h&&col.getBlue()>=b_l&&col.getBlue()<=b_h; } } \ No newline at end of file diff --git a/readers/fonts/Font.java b/readers/fonts/Font.java new file mode 100644 index 0000000..8833275 --- /dev/null +++ b/readers/fonts/Font.java @@ -0,0 +1,78 @@ +package readers.fonts; + +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.awt.Color; + +public class Font { + Glyph[] data = new Glyph[9]; + final static int TRANSPARENT = new Color(0,0,0,0).getRGB(); + + public static Font LoadFont(String fontName) { + Path f = Paths.get("readers","fonts",fontName); + if (Files.exists(f)) { + //TODO Read the file. + return new Font(); + } + return new Font(); + } + + public static void TrainFont(String fontName,String expectedGlyphs,BufferedImage data) { + Path f = Paths.get("readers","fonts",fontName); + Font font = LoadFont(fontName); + try { + Files.createFile(f); + int startX=-1; + int endX=-1; + outer: + for (int x=0;xendY) { + endY=Y; + } + } + } + g.height=endY-startY; + g.data = new boolean[g.width*g.height]; + for (int X=0;X( "%FOOTER", Paths.get(REFDIR,"FOOTER.html")) )); + + static void seek(int[]arr,int i,ColorRange SEEKCOLOR,Color FINALCOLOR,int width) { + seek(arr,i,SEEKCOLOR,FINALCOLOR,width,0); + } + + static int seek(int[]arr,int i,ColorRange SEEKCOLOR,Color FINALCOLOR,int width,int farthestRight) { + arr[i]=FINALCOLOR.getRGB(); + int X = i%width; + for (int x=-1;x<=1;x++) { + for (int y=-1;y<=1;y++) { + int newX=(i+x+y*width)%width; + int newY=(i+x+y*width)/width; + if (newX>=0&&newY>=0&&newX<=width&&newY<=arr.length/width) { + Color col = new Color(arr[i+x+y*width]); + if (!col.equals(Color.MAGENTA)&&SEEKCOLOR.colorInRange(col)) { + farthestRight=seek(arr,i+x+y*width,SEEKCOLOR,FINALCOLOR,width,farthestRight); + } + } + } + } + return X>farthestRight?X:farthestRight; + } + final static int TRANSPARENT = new Color(0,0,0,0).getRGB(); + public static void main(String[] args) { - ArcadeReader.retrieveData(Paths.get("sdvx1.png")); + Path f = Paths.get("sdvx1.png"); + BufferedImage img; + try { + img = ImageIO.read(f.toFile()); + Box scoreBox = new Box(458,1075,240,57); + + int[] arr = img.getRGB(scoreBox.x, scoreBox.y, scoreBox.w, scoreBox.h, null, 0, scoreBox.w); + + final ColorRange TARGETCOLOR = new ColorRange(240,255,240,255,240,255); + final ColorRange SEEKINGCOLOR = new ColorRange(100,255,100,255,100,255); + final Color FINALCOLOR = Color.MAGENTA; + for (int i=0;i data; try {