Refactor color processing into a single method

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2, Sig, Sigo 2 years ago
parent 6270afa926
commit 6e40010b2f
  1. 18
      readers/LoveLiveReader.java
  2. 271
      readers/PopnReader.java
  3. 39
      readers/Reader.java
  4. 18
      readers/SoundVoltexReader.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);

@ -16,7 +16,6 @@ public class PopnReader extends Reader{
final static int REGION_PADDING = 32;
List<Box> 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<arr.length;i++) {
Color col = new Color(arr[i],true);
if (TARGETCOLOR.colorInRange(col)) {
seek(arr,i,SEEKINGCOLOR,FINALCOLOR,width);
}
}
for (int i=0;i<arr.length;i++) {
Color col = new Color(arr[i],true);
if (!col.equals(Color.MAGENTA)) {
arr[i]=TRANSPARENT;
}
}
process(arr,width,
240,255,100,130,0,10,
240,255,100,255,0,100);
}break;
case 1:{
final ColorRange TARGETCOLOR = new ColorRange(240,255,0,10,240,255);
final ColorRange SEEKINGCOLOR = new ColorRange(240,255,0,150,240,255);
final Color FINALCOLOR = Color.MAGENTA;
for (int i=0;i<arr.length;i++) {
Color col = new Color(arr[i],true);
if (TARGETCOLOR.colorInRange(col)) {
seek(arr,i,SEEKINGCOLOR,FINALCOLOR,width);
}
}
for (int i=0;i<arr.length;i++) {
Color col = new Color(arr[i],true);
if (!col.equals(Color.MAGENTA)) {
arr[i]=TRANSPARENT;
}
}
process(arr,width,
240,255,0,10,240,255,
240,255,0,150,240,255);
}break;
case 2:{
final ColorRange TARGETCOLOR = new ColorRange(240,255,180,225,0,10);
final ColorRange SEEKINGCOLOR = new ColorRange(240,255,180,255,0,140);
final Color FINALCOLOR = Color.MAGENTA;
for (int i=0;i<arr.length;i++) {
Color col = new Color(arr[i],true);
if (TARGETCOLOR.colorInRange(col)) {
seek(arr,i,SEEKINGCOLOR,FINALCOLOR,width);
}
}
for (int i=0;i<arr.length;i++) {
Color col = new Color(arr[i],true);
if (!col.equals(Color.MAGENTA)) {
arr[i]=TRANSPARENT;
}
}
process(arr,width,
240,255,180,225,0,10,
240,255,180,255,0,140);
}break;
case 3:{
final ColorRange TARGETCOLOR = new ColorRange(240,255,0,40,0,10);
final ColorRange SEEKINGCOLOR = new ColorRange(240,255,0,180,0,255);
final Color FINALCOLOR = Color.MAGENTA;
for (int i=0;i<arr.length;i++) {
Color col = new Color(arr[i],true);
if (TARGETCOLOR.colorInRange(col)) {
seek(arr,i,SEEKINGCOLOR,FINALCOLOR,width);
}
}
for (int i=0;i<arr.length;i++) {
Color col = new Color(arr[i],true);
if (!col.equals(Color.MAGENTA)) {
arr[i]=TRANSPARENT;
}
}
process(arr,width,
240,244,0,40,0,10,
240,255,0,180,0,255);
}break;
case 4:{
final ColorRange TARGETCOLOR = new ColorRange(90,120,180,220,240,255);
final ColorRange SEEKINGCOLOR = new ColorRange(90,255,180,255,0,255);
final Color FINALCOLOR = Color.MAGENTA;
for (int i=0;i<arr.length;i++) {
Color col = new Color(arr[i],true);
if (TARGETCOLOR.colorInRange(col)) {
seek(arr,i,SEEKINGCOLOR,FINALCOLOR,width);
}
}
for (int i=0;i<arr.length;i++) {
Color col = new Color(arr[i],true);
if (!col.equals(Color.MAGENTA)) {
arr[i]=TRANSPARENT;
}
}
process(arr,width,
90,120,180,220,240,255,
90,255,180,255,0,255);
}break;
case 5:{
final ColorRange TARGETCOLOR = new ColorRange(0,10,0,60,240,255);
final ColorRange SEEKINGCOLOR = new ColorRange(0,20,0,100,240,255);
final Color FINALCOLOR = Color.MAGENTA;
for (int i=0;i<arr.length;i++) {
Color col = new Color(arr[i],true);
if (TARGETCOLOR.colorInRange(col)) {
seek(arr,i,SEEKINGCOLOR,FINALCOLOR,width);
}
}
for (int i=0;i<arr.length;i++) {
Color col = new Color(arr[i],true);
if (!col.equals(Color.MAGENTA)) {
arr[i]=TRANSPARENT;
}
}
process(arr,width,
0,10,0,60,240,255,
0,20,0,100,240,255);
}break;
case 6:{
final ColorRange TARGETCOLOR = new ColorRange(240,255,230,255,0,40);
final ColorRange SEEKINGCOLOR = new ColorRange(240,255,230,255,0,240);
final Color FINALCOLOR = Color.MAGENTA;
for (int i=0;i<arr.length;i++) {
Color col = new Color(arr[i],true);
if (TARGETCOLOR.colorInRange(col)) {
seek(arr,i,SEEKINGCOLOR,FINALCOLOR,width);
}
}
for (int i=0;i<arr.length;i++) {
Color col = new Color(arr[i],true);
if (!col.equals(Color.MAGENTA)) {
arr[i]=TRANSPARENT;
}
}
process(arr,width,
240,255,230,255,0,40,
240,255,230,255,0,240);
}break;
case 400:{
final ColorRange TARGETCOLOR = new ColorRange(240,255,0,10,0,10);
final ColorRange SEEKINGCOLOR = new ColorRange(240,255,0,10,0,10);
final Color FINALCOLOR = Color.MAGENTA;
for (int i=0;i<arr.length;i++) {
Color col = new Color(arr[i],true);
if (TARGETCOLOR.colorInRange(col)) {
seek(arr,i,SEEKINGCOLOR,FINALCOLOR,width);
}
}
for (int i=0;i<arr.length;i++) {
Color col = new Color(arr[i],true);
if (!col.equals(Color.MAGENTA)) {
arr[i]=TRANSPARENT;
}
}
process(arr,width,
240,255,0,10,0,10,
240,255,0,10,0,10);
}break;
case 401:{
final ColorRange TARGETCOLOR = new ColorRange(230,255,0,10,240,255);
final ColorRange SEEKINGCOLOR = new ColorRange(230,255,0,10,240,255);
final Color FINALCOLOR = Color.MAGENTA;
for (int i=0;i<arr.length;i++) {
Color col = new Color(arr[i],true);
if (!col.equals(Color.MAGENTA)&&TARGETCOLOR.colorInRange(col)) {
seek(arr,i,SEEKINGCOLOR,FINALCOLOR,width);
}
}
for (int i=0;i<arr.length;i++) {
Color col = new Color(arr[i],true);
if (!col.equals(Color.MAGENTA)) {
arr[i]=TRANSPARENT;
}
}
process(arr,width,
230,255,0,10,240,255,
230,255,0,10,240,255);
}break;
case 402:{
final ColorRange TARGETCOLOR = new ColorRange(240,255,200,255,0,10);
final ColorRange SEEKINGCOLOR = new ColorRange(240,255,200,255,0,10);
final Color FINALCOLOR = Color.MAGENTA;
for (int i=0;i<arr.length;i++) {
Color col = new Color(arr[i],true);
if (!col.equals(Color.MAGENTA)&&TARGETCOLOR.colorInRange(col)) {
seek(arr,i,SEEKINGCOLOR,FINALCOLOR,width);
}
}
for (int i=0;i<arr.length;i++) {
Color col = new Color(arr[i],true);
if (!col.equals(Color.MAGENTA)) {
arr[i]=TRANSPARENT;
}
}
process(arr,width,
240,255,200,255,0,10,
240,255,200,255,0,10);
}break;
case 403:{
final ColorRange TARGETCOLOR = new ColorRange(240,255,0,50,0,10);
final ColorRange SEEKINGCOLOR = new ColorRange(240,255,0,50,0,10);
final Color FINALCOLOR = Color.MAGENTA;
for (int i=0;i<arr.length;i++) {
Color col = new Color(arr[i],true);
if (!col.equals(Color.MAGENTA)&&TARGETCOLOR.colorInRange(col)) {
seek(arr,i,SEEKINGCOLOR,FINALCOLOR,width);
}
}
for (int i=0;i<arr.length;i++) {
Color col = new Color(arr[i],true);
if (!col.equals(Color.MAGENTA)) {
arr[i]=TRANSPARENT;
}
}
process(arr,width,
240,255,0,50,0,10,
240,255,0,50,0,10);
}break;
case 404:{
final ColorRange TARGETCOLOR = new ColorRange(90,120,180,220,240,255);
final ColorRange SEEKINGCOLOR = new ColorRange(85,120,160,220,180,255);
final Color FINALCOLOR = Color.MAGENTA;
for (int i=0;i<arr.length;i++) {
Color col = new Color(arr[i],true);
if (!col.equals(Color.MAGENTA)&&TARGETCOLOR.colorInRange(col)) {
seek(arr,i,SEEKINGCOLOR,FINALCOLOR,width);
}
}
for (int i=0;i<arr.length;i++) {
Color col = new Color(arr[i],true);
if (!col.equals(Color.MAGENTA)) {
arr[i]=TRANSPARENT;
}
}
process(arr,width,
90,120,180,220,240,255,
85,120,160,220,180,255);
}break;
case 405:{
final ColorRange TARGETCOLOR = new ColorRange(0,20,0,80,240,255);
final ColorRange SEEKINGCOLOR = new ColorRange(0,20,0,80,240,255);
final Color FINALCOLOR = Color.MAGENTA;
for (int i=0;i<arr.length;i++) {
Color col = new Color(arr[i],true);
if (!col.equals(Color.MAGENTA)&&TARGETCOLOR.colorInRange(col)) {
seek(arr,i,SEEKINGCOLOR,FINALCOLOR,width);
}
}
for (int i=0;i<arr.length;i++) {
Color col = new Color(arr[i],true);
if (!col.equals(Color.MAGENTA)) {
arr[i]=TRANSPARENT;
}
}
process(arr,width,
0,20,0,80,240,255,
0,20,0,80,240,255);
}break;
case 406:{
final ColorRange TARGETCOLOR = new ColorRange(240,255,240,255,240,255);
final ColorRange SEEKINGCOLOR = new ColorRange(210,255,210,255,210,255);
final Color FINALCOLOR = Color.MAGENTA;
for (int i=0;i<arr.length;i++) {
Color col = new Color(arr[i],true);
if (!col.equals(Color.MAGENTA)&&TARGETCOLOR.colorInRange(col)) {
seek(arr,i,SEEKINGCOLOR,FINALCOLOR,width);
}
}
for (int i=0;i<arr.length;i++) {
Color col = new Color(arr[i],true);
if (!col.equals(Color.MAGENTA)) {
arr[i]=TRANSPARENT;
}
}
process(arr,width,
240,255,240,255,240,255,
210,255,210,255,210,255);
}break;
}
}

@ -4,6 +4,9 @@ import java.io.InputStreamReader;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.awt.Color;
import javax.imageio.metadata.IIOInvalidTreeException;
public abstract class Reader{
int score;
@ -15,6 +18,7 @@ public abstract class Reader{
int maxcombo;
String other;
List<Box> 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<arr.length;i++) {
Color col = new Color(arr[i],true);
if (TARGETCOLOR.colorInRange(col)) {
seek(arr,i,SEEKINGCOLOR,FINALCOLOR,width);
}
}
for (int i=0;i<arr.length;i++) {
Color col = new Color(arr[i],true);
if (!col.equals(Color.MAGENTA)) {
arr[i]=TRANSPARENT;
}
}
}
}

@ -17,7 +17,6 @@ public class SoundVoltexReader extends Reader{
final static int REGION_PADDING = 32;
List<Box> 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:{

Loading…
Cancel
Save