Setup popn regions

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2, Sig, Sigo 2 years ago
parent d1b55d19fc
commit 7f1388d95c
  1. 4
      ArcadeReader.java
  2. 155
      readers/PopnReader.java
  3. BIN
      result.png
  4. 2
      sigPlace.java

@ -1,6 +1,6 @@
import java.nio.file.Path;
import readers.SoundVoltexReader;
import readers.PopnReader;
public class ArcadeReader {
/*
@ -55,6 +55,6 @@ public class ArcadeReader {
*
*/
public static void retrieveData(Path img) {
new SoundVoltexReader().interpretBoxes(img);
new PopnReader().interpretBoxes(img);
}
}

@ -0,0 +1,155 @@
package readers;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;
import javax.imageio.ImageIO;
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]
readRegions.add(new Box(1060,724,157,39)); //great[2]
readRegions.add(new Box(1060,761,157,40)); //good[3]
readRegions.add(new Box(1060,800,157,40)); //bad[4]
readRegions.add(new Box(1060,858,157,42)); //combo[5]
readRegions.add(new Box(970,288,271,50)); //diff[6]
readRegions.add(new Box(689,345,547,128)); //song[7]
readRegions.add(new Box(502,23,314,288)); //rating[8]
readRegions.add(new Box(692,525,532,16)); //lifebar[9]
extraRegions.add(new Box(699,616,179,44)); //score text[0]
extraRegions.add(new Box(712,680,164,40)); //cool text[1]
extraRegions.add(new Box(712,721,168,38)); //great text[2]
extraRegions.add(new Box(712,759,150,40)); //good text[3]
extraRegions.add(new Box(712,800,101,38)); //bad text[4]
extraRegions.add(new Box(708,861,170,39)); //combo text[5]
}
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 999:{
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<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;
}
}
}break;
}
}
public void interpretBoxes(Path img){
/*String dataString = readAllBoxes(img);
String[] data = dataString.split(Pattern.quote("\n"));
String[] ja_data = data[0].split(Pattern.quote(")"));
String[] en_data = data[2].split(Pattern.quote(")"));
trimAllData(ja_data);
trimAllData(en_data);
System.out.println(Arrays.toString(ja_data));
System.out.println(Arrays.toString(en_data));*/
int regionHeights = 0;
int maxWidth = 0;
for (int i=0;i<readRegions.size();i++) {
regionHeights+=readRegions.get(i).h+REGION_PADDING;
if (readRegions.get(i).w>maxWidth) {
maxWidth=readRegions.get(i).w;
}
}
try {
BufferedImage originalImg = ImageIO.read(img.toFile());
BufferedImage cutImg = new BufferedImage(maxWidth,regionHeights,BufferedImage.TYPE_INT_ARGB);
Graphics2D g = cutImg.createGraphics();
int currentHeight=0;
for (int i=0;i<readRegions.size();i++) {
int[] arr = originalImg.getRGB(readRegions.get(i).x, readRegions.get(i).y, readRegions.get(i).w, readRegions.get(i).h, null, 0, readRegions.get(i).w);
//System.out.println(Arrays.toString(arr));
//System.out.println(i);
//ImageIO.write(originalImg.getSubimage(readRegions.get(i).x, readRegions.get(i).y, readRegions.get(i).w, readRegions.get(i).h),"png",new File("cut.png"));
ColorFilter(arr,i,readRegions.get(i).w);
//g.drawImage(originalImg, 0,currentHeight,readRegions.get(i).w,readRegions.get(i).h+currentHeight,readRegions.get(i).x, readRegions.get(i).y, readRegions.get(i).x+readRegions.get(i).w, readRegions.get(i).y+readRegions.get(i).h, null);
int leftMost=readRegions.get(i).w;
for (int j=0;j<arr.length;j++) {
if (arr[j]==Color.MAGENTA.getRGB()&&j%readRegions.get(i).w<leftMost) {
leftMost=j%readRegions.get(i).w;
}
}
if (i<=5) {
int[] arr2 = originalImg.getRGB(extraRegions.get(i).x, extraRegions.get(i).y, extraRegions.get(i).w, extraRegions.get(i).h, null, 0, extraRegions.get(i).w);
int rightMost=0;
ColorFilter(arr2,400+i,extraRegions.get(i).w);
for (int j=0;j<arr2.length;j++) {
if (arr2[j]==Color.MAGENTA.getRGB()&&j%extraRegions.get(i).w>rightMost) {
rightMost=j%extraRegions.get(i).w;
}
}
//cutImg.setRGB(rightMost-leftMost,currentHeight,readRegions.get(i).w,readRegions.get(i).h,arr,0,readRegions.get(i).w);
cutImg.setRGB(0,currentHeight,extraRegions.get(i).w,extraRegions.get(i).h,arr2,0,extraRegions.get(i).w);
final int PADDING = 4;
for (int x=leftMost;x<readRegions.get(i).w;x++) {
for (int y=0;y<readRegions.get(i).h;y++) {
cutImg.setRGB(x+rightMost-leftMost+PADDING, y+currentHeight, arr[y*readRegions.get(i).w+x]);
}
}
} else {
cutImg.setRGB(0,currentHeight,readRegions.get(i).w,readRegions.get(i).h,arr,0,readRegions.get(i).w);
}
currentHeight+=readRegions.get(i).h+REGION_PADDING;
}
Path output = Paths.get("result.png");
ImageIO.write(cutImg,"png",output.toFile());
String dataString = readAllBoxes(output);
String[] data = dataString.split(Pattern.quote("\n"));
String[] ja_data = data[0].split(Pattern.quote(")"));
String[] en_data = data[2].split(Pattern.quote(")"));
trimAllData(ja_data);
trimAllData(en_data);
System.out.println(Arrays.toString(ja_data));
System.out.println(Arrays.toString(en_data));
g.dispose();
} catch (IOException e) {
e.printStackTrace();
}
//System.out.println(data[0]);
//System.out.println(data[2]);
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 235 KiB

@ -48,7 +48,7 @@ public class sigPlace {
"%FOOTER", Paths.get(REFDIR,"FOOTER.html"))
));
public static void main(String[] args) {
ArcadeReader.retrieveData(Paths.get("sdvx1.png"));
ArcadeReader.retrieveData(Paths.get("popn2.png"));
/* Path secretFile = Paths.get(".clientsecret");
List<String> data;
try {

Loading…
Cancel
Save