From 6e40010b2f6f8c92eb0493421692292274d987b6 Mon Sep 17 00:00:00 2001 From: "sigonasr2, Sig, Sigo" Date: Tue, 9 Aug 2022 16:28:06 +0000 Subject: [PATCH] Refactor color processing into a single method Co-authored-by: sigonasr2 --- readers/LoveLiveReader.java | 18 --- readers/PopnReader.java | 271 +++++---------------------------- readers/Reader.java | 39 +++++ readers/SoundVoltexReader.java | 18 --- 4 files changed, 81 insertions(+), 265 deletions(-) diff --git a/readers/LoveLiveReader.java b/readers/LoveLiveReader.java index 9e1b9fe..1ccb61f 100644 --- a/readers/LoveLiveReader.java +++ b/readers/LoveLiveReader.java @@ -35,25 +35,7 @@ public class LoveLiveReader extends Reader{ readRegions.add(new Box(782,452,158,50)); //maxcombo[10] } - void seek(int[]arr,int i,ColorRange SEEKCOLOR,Color FINALCOLOR,int width) { - seek(arr,i,SEEKCOLOR,FINALCOLOR,width,0); - } - - 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++) { - if (SEEKCOLOR.colorInRange(new Color(arr[i+x+y*width]))) { - farthestRight=seek(arr,i+x+y*width,SEEKCOLOR,FINALCOLOR,width,farthestRight); - } - } - } - return X>farthestRight?X:farthestRight; - } - void ColorFilter(int[] arr,int region,int width) { - final int TRANSPARENT = new Color(0,0,0,0).getRGB(); switch (region) { case 0:{ final ColorRange TARGETCOLOR = new ColorRange(240,255,130,150,0,10); diff --git a/readers/PopnReader.java b/readers/PopnReader.java index 0fed7e7..c317cec 100644 --- a/readers/PopnReader.java +++ b/readers/PopnReader.java @@ -16,7 +16,6 @@ public class PopnReader extends Reader{ final static int REGION_PADDING = 32; List extraRegions = new ArrayList<>(); static int lastJump=0; - final int TRANSPARENT = new Color(0,0,0,0).getRGB(); public PopnReader(){ readRegions.add(new Box(941,609,275,54)); //score[0] readRegions.add(new Box(1060,684,157,40)); //cool[1] @@ -38,263 +37,77 @@ public class PopnReader extends Reader{ extraRegions.add(new Box(970,290,194,47)); //diff text[6] } - void seek(int[]arr,int i,ColorRange SEEKCOLOR,Color FINALCOLOR,int width) { - seek(arr,i,SEEKCOLOR,FINALCOLOR,width,0); - } - - 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++) { - 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; - } - void ColorFilter(int[] arr,int region,int width) { switch (region) { case 0:{ - final ColorRange TARGETCOLOR = new ColorRange(240,255,100,130,0,10); - final ColorRange SEEKINGCOLOR = new ColorRange(240,255,100,255,0,100); - final Color FINALCOLOR = Color.MAGENTA; - for (int i=0;i readRegions = new ArrayList<>(); + final int TRANSPARENT = new Color(0,0,0,0).getRGB(); String readAllBoxes(Path img) { try { Process p = Runtime.getRuntime().exec(new String[]{"python3","runocr.py","ja",img.toAbsolutePath().toString()}); @@ -50,4 +54,39 @@ public abstract class Reader{ data[i]=sb.toString(); } } + + void seek(int[]arr,int i,ColorRange SEEKCOLOR,Color FINALCOLOR,int width) { + seek(arr,i,SEEKCOLOR,FINALCOLOR,width,0); + } + + 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++) { + 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; + } + void process(int[]arr,int width,int a,int b,int c,int d,int e,int f,int g,int h,int ii,int j,int k,int l) { + final ColorRange TARGETCOLOR = new ColorRange(a,b,c,d,e,f); + final ColorRange SEEKINGCOLOR = new ColorRange(g,h,ii,j,k,l); + final Color FINALCOLOR = Color.MAGENTA; + for (int i=0;i extraRegions = new ArrayList<>(); static int lastJump=0; - final int TRANSPARENT = new Color(0,0,0,0).getRGB(); public SoundVoltexReader(){ readRegions.add(new Box(430,1006,454,29)); //title[0] readRegions.add(new Box(458,1075,240,57)); //bigscore[1] @@ -65,23 +64,6 @@ public class SoundVoltexReader extends Reader{ extraRegions.add(new Box(71,1365,171,22)); //maximum chain text[17] } - void seek(int[]arr,int i,ColorRange SEEKCOLOR,Color FINALCOLOR,int width) { - seek(arr,i,SEEKCOLOR,FINALCOLOR,width,0); - } - - 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++) { - if (SEEKCOLOR.colorInRange(new Color(arr[i+x+y*width]))) { - farthestRight=seek(arr,i+x+y*width,SEEKCOLOR,FINALCOLOR,width,farthestRight); - } - } - } - return X>farthestRight?X:farthestRight; - } - void ColorFilter(int[] arr,int region,int width) { switch (region) { case 0:{