Love Live Number parsing implemented (#1)
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
729432a693
commit
59ba8c0a80
@ -59,6 +59,6 @@ public class ArcadeReader {
|
||||
*
|
||||
*/
|
||||
public static void retrieveData(Path img) {
|
||||
new ITGReader().interpretBoxes(img);
|
||||
new LoveLiveReader().interpretBoxes(img);
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ 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;
|
||||
@ -12,27 +13,31 @@ import java.util.regex.Pattern;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import readers.fonts.Font;
|
||||
import readers.fonts.Glyph;
|
||||
|
||||
public class LoveLiveReader extends Reader{
|
||||
List<Box> extraRegions = new ArrayList<>();
|
||||
static int lastJump=0;
|
||||
public LoveLiveReader(){
|
||||
readRegions.add(new Box(713,401,232,50)); //score[0]
|
||||
readRegions.add(new Box(613,290,65,36)); //rank[1]
|
||||
addRegion(new Box(713,401,232,50),NUMBER); //score[0]
|
||||
addRegion(new Box(613,290,65,36)); //rank[1]
|
||||
extraRegions.add(new Box(65,604,250,53)); //perfect outline[0]
|
||||
extraRegions.add(new Box(65,680,250,53)); //great outline[1]
|
||||
extraRegions.add(new Box(65,760,250,53)); //good outline[2]
|
||||
extraRegions.add(new Box(65,840,250,53)); //bad outline[3]
|
||||
extraRegions.add(new Box(65,920,250,53)); //miss outline[4]
|
||||
readRegions.add(new Box(509,604,190,54)); //notes[2]
|
||||
readRegions.add(new Box(509,680,190,54)); //notes[3]
|
||||
readRegions.add(new Box(509,760,190,54)); //notes[4]
|
||||
readRegions.add(new Box(509,840,190,54)); //notes[5]
|
||||
readRegions.add(new Box(509,920,190,54)); //notes[6]
|
||||
readRegions.add(new Box(26,374,265,36)); //difficulty[7]
|
||||
readRegions.add(new Box(277,165,572,40)); //title[8]
|
||||
readRegions.add(new Box(716,502,226,45)); //pct[9]
|
||||
readRegions.add(new Box(782,452,158,50)); //maxcombo[10]
|
||||
readRegions.add(new Box(100,470,84,42)); //difficultylv[11]
|
||||
addRegion(new Box(509,604,190,54),NUMBER); //notes[2]
|
||||
addRegion(new Box(509,680,190,54),NUMBER); //notes[3]
|
||||
addRegion(new Box(509,760,190,54),NUMBER); //notes[4]
|
||||
addRegion(new Box(509,840,190,54),NUMBER); //notes[5]
|
||||
addRegion(new Box(509,920,190,54),NUMBER); //notes[6]
|
||||
addRegion(new Box(26,374,265,36)); //difficulty[7]
|
||||
addRegion(new Box(277,165,572,40)); //title[8]
|
||||
addRegion(new Box(716,502,226,45),NUMBER); //pct[9]
|
||||
addRegion(new Box(782,452,158,50),NUMBER); //maxcombo[10]
|
||||
addRegion(new Box(100,470,84,42)); //difficultylv[11]
|
||||
init();
|
||||
}
|
||||
|
||||
void ColorFilter(int[] arr,int region,int width) {
|
||||
@ -187,6 +192,7 @@ public class LoveLiveReader extends Reader{
|
||||
|
||||
int regionHeights = 0;
|
||||
int maxWidth = 0;
|
||||
int counter = 0;
|
||||
for (int i=0;i<readRegions.size();i++) {
|
||||
regionHeights+=readRegions.get(i).h+REGION_PADDING;
|
||||
if (readRegions.get(i).w>maxWidth) {
|
||||
@ -199,35 +205,21 @@ public class LoveLiveReader extends Reader{
|
||||
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);
|
||||
BufferedImage subRegion = new BufferedImage(readRegions.get(i).w, readRegions.get(i).h,BufferedImage.TYPE_INT_ARGB);
|
||||
|
||||
subRegion.setRGB(0,0,readRegions.get(i).w,readRegions.get(i).h,originalImg.getRGB(readRegions.get(i).x, readRegions.get(i).y, readRegions.get(i).w, readRegions.get(i).h, null, 0, readRegions.get(i).w),0,readRegions.get(i).w);
|
||||
|
||||
int[] arr = subRegion.getRGB(0, 0, 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>=2&&i<=6) {
|
||||
int[] arr2 = originalImg.getRGB(extraRegions.get(i-2).x, extraRegions.get(i-2).y, extraRegions.get(i-2).w, extraRegions.get(i-2).h, null, 0, extraRegions.get(i-2).w);
|
||||
int rightMost=0;
|
||||
ColorFilter(arr2,400+i-2,extraRegions.get(i-2).w);
|
||||
for (int j=0;j<arr2.length;j++) {
|
||||
if (arr2[j]==Color.MAGENTA.getRGB()&&j%extraRegions.get(i-2).w>rightMost) {
|
||||
rightMost=j%extraRegions.get(i-2).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-2).w,extraRegions.get(i-2).h,arr2,0,extraRegions.get(i-2).w);
|
||||
final int PADDING = 8;
|
||||
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);
|
||||
subRegion.setRGB(0,0,readRegions.get(i).w,readRegions.get(i).h,arr,0,readRegions.get(i).w);
|
||||
ImageIO.write(subRegion,"png",new File("sub.png"));
|
||||
cutImg.setRGB(0,currentHeight,readRegions.get(i).w,readRegions.get(i).h,arr,0,readRegions.get(i).w);
|
||||
String val = interpretImage(subRegion,i);
|
||||
if (!val.isEmpty()) {
|
||||
sig_data[counter++]=val;
|
||||
}
|
||||
//System.out.println(i+": "+currentHeight+"-"+(currentHeight+readRegions.get(i).h+REGION_PADDING));
|
||||
currentHeight+=readRegions.get(i).h+REGION_PADDING;
|
||||
@ -242,7 +234,8 @@ public class LoveLiveReader extends Reader{
|
||||
trimAllData(en_data);
|
||||
System.out.println(Arrays.toString(ja_data));
|
||||
System.out.println(Arrays.toString(en_data));
|
||||
interpretOutput(ja_data,en_data);
|
||||
System.out.println(Arrays.toString(sig_data));
|
||||
//interpretOutput(ja_data,en_data);
|
||||
g.dispose();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@ -251,6 +244,35 @@ public class LoveLiveReader extends Reader{
|
||||
//System.out.println(data[2]);
|
||||
}
|
||||
|
||||
private String interpretImage(BufferedImage cutImg, int i) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
case 10:{
|
||||
Font f = Font.FONT_LOVELIVE_SCORE;
|
||||
List<Glyph> glyphs = Glyph.split(cutImg);
|
||||
return f.convertGlyphs(glyphs);
|
||||
}
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:{
|
||||
Font f = Font.FONT_LOVELIVE_NOTECOUNT;
|
||||
List<Glyph> glyphs = Glyph.split(cutImg);
|
||||
return f.convertGlyphs(glyphs);
|
||||
}
|
||||
case 9:{
|
||||
Font f = Font.FONT_LOVELIVE_PCT;
|
||||
List<Glyph> glyphs = Glyph.split(cutImg);
|
||||
glyphs.remove(glyphs.size()-3);
|
||||
glyphs.remove(glyphs.size()-1);
|
||||
String res = f.convertGlyphs(glyphs,true);
|
||||
return res.substring(0,glyphs.size()-1)+"."+res.substring(glyphs.size()-1,glyphs.size());
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
void interpretResults(String[] finalData) {
|
||||
for (int i=0;i<finalData.length;i++) {
|
||||
String[] splitter = finalData[i].split(Pattern.quote("\n"));
|
||||
|
@ -146,8 +146,11 @@ public class Font {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public String convertGlyphs(List<Glyph> glyphs) {
|
||||
return convertGlyphs(glyphs,false);
|
||||
}
|
||||
|
||||
public String convertGlyphs(List<Glyph> glyphs,boolean debug) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i=0;i<glyphs.size();i++) {
|
||||
int bestScore=Integer.MIN_VALUE;
|
||||
@ -184,7 +187,9 @@ public class Font {
|
||||
if (score>bestScore) {
|
||||
bestScore=score;
|
||||
bestGlyph=j;
|
||||
//System.out.println("Glyph "+j+" has a score of "+bestScore+".");
|
||||
if (debug) {
|
||||
System.out.println("Glyph "+j+" has a score of "+bestScore+".");
|
||||
}
|
||||
}
|
||||
}
|
||||
sb.append(bestGlyph);
|
||||
|
BIN
result.png
BIN
result.png
Binary file not shown.
Before Width: | Height: | Size: 8.1 KiB After Width: | Height: | Size: 33 KiB |
@ -115,7 +115,7 @@ public class sigPlace {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}*/
|
||||
ArcadeReader.retrieveData(Paths.get("itg11.png"));
|
||||
ArcadeReader.retrieveData(Paths.get("lovelive2.png"));
|
||||
/* Path secretFile = Paths.get(".clientsecret");
|
||||
List<String> data;
|
||||
try {
|
||||
|
Loading…
x
Reference in New Issue
Block a user