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.
 
 
 
SigPlace/readers/ITGReader.java

144 lines
5.4 KiB

package readers;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
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 ITGReader extends Reader{
final static int REGION_PADDING = 32;
List<Box> extraRegions = new ArrayList<>();
static int lastJump=0;
public ITGReader(){
readRegions.add(new Box(388,552,227,60)); //score[0]
readRegions.add(new Box(797,438,164,58)); //fantastic+[1]
readRegions.add(new Box(797,493,164,58)); //fantastic[2]
readRegions.add(new Box(797,551,164,58)); //excellent[3]
readRegions.add(new Box(797,618,164,58)); //great[4]
readRegions.add(new Box(797,673,164,58)); //decent[5]
readRegions.add(new Box(797,736,164,58)); //miss[6]
readRegions.add(new Box(279,443,340,104)); //pct[7]
readRegions.add(new Box(277,364,64,60)); //diffnumb[8]
readRegions.add(new Box(344,393,266,36)); //playstyle[9]
readRegions.add(new Box(277,174,324,171)); //grade[10]
readRegions.add(new Box(632,106,656,43)); //songname[11]
}
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,
130,255,130,255,130,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;
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++) {
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"));
System.out.println(i);
ColorFilter(arr,i,readRegions.get(i).w);
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));
interpretOutput(ja_data,en_data);
g.dispose();
} catch (IOException e) {
e.printStackTrace();
}
//System.out.println(data[0]);
//System.out.println(data[2]);
}
@Override
void interpretResults(String[] finalData) {
// TODO Auto-generated method stub
}
}