Where people come together to learn, code, and play. Custom-built HTTP server, site generator, and website from scratch using no external libraries. Goal is to be as minimalistic and fun as possible.
http://projectdivar.com
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
194 lines
7.4 KiB
194 lines
7.4 KiB
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;
|
|
|
|
import readers.fonts.Font;
|
|
import readers.fonts.Glyph;
|
|
|
|
public class ITGReader extends Reader{
|
|
final static int REGION_PADDING = 32;
|
|
List<Box> extraRegions = new ArrayList<>();
|
|
static int lastJump=0;
|
|
public ITGReader(){
|
|
addRegion(new Box(388,552,227,60),NUMBER); //score[0]
|
|
addRegion(new Box(797,438,164,58),NUMBER); //fantastic+[1]
|
|
addRegion(new Box(797,493,164,58),NUMBER); //fantastic[2]
|
|
addRegion(new Box(797,551,164,58),NUMBER); //excellent[3]
|
|
addRegion(new Box(797,618,164,58),NUMBER); //great[4]
|
|
addRegion(new Box(797,673,164,58),NUMBER); //decent[5]
|
|
addRegion(new Box(797,736,164,58),NUMBER); //miss[6]
|
|
addRegion(new Box(279,443,340,104),NUMBER); //pct[7]
|
|
addRegion(new Box(277,364,64,60),NUMBER); //diffnumb[8]
|
|
addRegion(new Box(344,393,266,36)); //playstyle[9]
|
|
addRegion(new Box(277,174,324,171)); //grade[10]
|
|
addRegion(new Box(632,106,656,43)); //songname[11]
|
|
init();
|
|
}
|
|
|
|
void ColorFilter(int[] arr,int region,int width) {
|
|
switch (region) {
|
|
case 0:
|
|
case 1:{
|
|
process(arr,width,
|
|
20,40,195,215,225,240,
|
|
20,40,195,215,225,240);
|
|
}break;
|
|
case 2:
|
|
case 7:
|
|
case 10:{
|
|
process(arr,width,
|
|
240,255,240,255,240,255,
|
|
240,255,240,255,240,255);
|
|
}break;
|
|
case 3:{
|
|
process(arr,width,
|
|
215,240,145,165,10,30,
|
|
215,240,145,165,10,30);
|
|
}break;
|
|
case 4:{
|
|
process(arr,width,
|
|
90,110,190,210,75,100,
|
|
90,110,190,210,75,100);
|
|
}break;
|
|
case 5:{
|
|
process(arr,width,
|
|
170,190,80,105,240,255,
|
|
170,190,80,105,240,255);
|
|
}break;
|
|
case 6:{
|
|
process(arr,width,
|
|
240,255,40,55,40,55,
|
|
240,255,40,55,40,55);
|
|
}break;
|
|
case 8:{
|
|
process(arr,width,
|
|
0,5,0,5,0,5,
|
|
0,5,0,5,0,5);
|
|
}break;
|
|
case 9:{
|
|
process(arr,width,
|
|
170,255,170,255,170,255,
|
|
170,255,100,255,120,255);
|
|
}break;
|
|
case 11:{
|
|
process(arr,width,
|
|
180,255,180,255,180,255,
|
|
150,255,150,255,150,255);
|
|
}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;
|
|
int counter = 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*2;
|
|
}
|
|
}
|
|
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++) {
|
|
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);
|
|
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;
|
|
}
|
|
}
|
|
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));
|
|
System.out.println(Arrays.toString(sig_data));
|
|
//interpretOutput(ja_data,en_data);
|
|
g.dispose();
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
//System.out.println(data[0]);
|
|
//System.out.println(data[2]);
|
|
}
|
|
|
|
private String interpretImage(BufferedImage cutImg, int i) {
|
|
switch (i) {
|
|
case 0:{
|
|
Font f = Font.FONT_ITG_EX;
|
|
List<Glyph> glyphs = Glyph.split(cutImg);
|
|
glyphs.remove(glyphs.size()-3);
|
|
String res = f.convertGlyphs(glyphs);
|
|
return res.substring(0,res.length()-2)+"."+res.substring(res.length()-2,res.length());
|
|
}
|
|
case 7:{
|
|
Font f = Font.FONT_ITG_PCT;
|
|
List<Glyph> glyphs = Glyph.split(cutImg);
|
|
glyphs.remove(glyphs.size()-3);
|
|
String res = f.convertGlyphs(glyphs);
|
|
return res.substring(0,res.length()-2)+"."+res.substring(res.length()-2,res.length());
|
|
}
|
|
case 1:
|
|
case 2:
|
|
case 3:
|
|
case 4:
|
|
case 5:
|
|
case 6:{
|
|
Font f = Font.FONT_ITG_NOTECOUNT;
|
|
List<Glyph> glyphs = Glyph.split(cutImg);
|
|
return f.convertGlyphs(glyphs);
|
|
}
|
|
case 8:{
|
|
Font f = Font.FONT_ITG_DIFF;
|
|
List<Glyph> glyphs = Glyph.split(cutImg);
|
|
return f.convertGlyphs(glyphs);
|
|
}
|
|
}
|
|
return "";
|
|
}
|
|
|
|
@Override
|
|
void interpretResults(String[] finalData) {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
} |