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/DDRReader.java

261 lines
10 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 DDRReader extends Reader{
final static int REGION_PADDING = 32;
List<Box> extraRegions = new ArrayList<>();
static int lastJump=0;
public DDRReader(){
readRegions.add(new Box(305,428,402,69)); //score[0]
readRegions.add(new Box(603,565,133,37)); //max combo[1]
readRegions.add(new Box(603,612,133,37)); //marvelous[2]
readRegions.add(new Box(603,651,133,37)); //perfect[3]
readRegions.add(new Box(603,698,133,37)); //great[4]
readRegions.add(new Box(603,742,133,37)); //good[5]
readRegions.add(new Box(603,787,133,37)); //OK[6]
readRegions.add(new Box(603,830,133,37)); //miss[7]
readRegions.add(new Box(603,876,133,37)); //ex score[8]
readRegions.add(new Box(783,738,133,37)); //fast[9]
readRegions.add(new Box(783,821,133,37)); //slow[10]
readRegions.add(new Box(600,165,133,53)); //diffnumb[11]
readRegions.add(new Box(577,91,174,36)); //playstyle[12]
readRegions.add(new Box(253,207,357,183)); //grade[13]
readRegions.add(new Box(756,432,411,38)); //songname[14]
extraRegions.add(new Box(251,393,112,33)); //score text[0]
extraRegions.add(new Box(315,565,295,40)); //max combo text[1]
extraRegions.add(new Box(315,611,290,42)); //marvelous text[2]
extraRegions.add(new Box(315,651,290,42)); //perfect text[3]
extraRegions.add(new Box(315,698,290,42)); //great text[4]
extraRegions.add(new Box(315,742,290,42)); //good text[5]
extraRegions.add(new Box(315,787,290,42)); //OK text[6]
extraRegions.add(new Box(315,830,290,42)); //miss text[7]
extraRegions.add(new Box(345,874,258,39)); //ex score text[8]
extraRegions.add(new Box(805,706,88,30)); //fast text[9]
extraRegions.add(new Box(801,793,96,30)); //slow text[10]
extraRegions.add(new Box(576,126,185,40)); //difficulty text[11]
}
void ColorFilter(int[] arr,int region,int width) {
switch (region) {
case 0:{
process(arr,width,
247,255,247,255,247,255,
200,255,200,255,200,255);
}break;
case 400:{
process(arr,width,
180,255,180,255,180,255,
170,255,170,255,170,255);
}break;
case 1:{
process(arr,width,
180,255,180,255,180,255,
70,255,70,255,70,255);
}break;
case 401:{
process(arr,width,
240,255,240,255,240,255,
130,255,130,255,130,255);
}break;
case 2:{
process(arr,width,
0,50,0,50,0,50,
0,160,0,160,0,160);
}break;
case 402:{
process(arr,width,
50,120,50,120,50,120,
0,170,0,160,0,140);
}break;
case 3:{
process(arr,width,
0,50,0,50,0,50,
0,160,0,160,0,160);
}break;
case 403:{
process(arr,width,
60,100,50,100,0,40,
0,150,0,150,0,70);
}break;
case 4:{
process(arr,width,
0,50,0,50,0,50,
0,160,0,160,0,160);
}break;
case 404:{
process(arr,width,
10,50,50,170,0,50,
0,80,0,115,0,90);
}break;
case 5:{
process(arr,width,
0,50,0,50,0,50,
0,160,0,160,0,160);
}break;
case 405:{
process(arr,width,
30,80,60,110,70,140,
0,110,0,130,0,160);
}break;
case 6:{
process(arr,width,
0,50,0,50,0,50,
0,160,0,160,0,160);
}break;
case 406:{
process(arr,width,
50,100,20,70,0,40,
0,130,0,110,0,90);
}break;
case 7:{
process(arr,width,
0,50,0,50,0,50,
0,160,0,160,0,160);
}break;
case 407:{
process(arr,width,
40,70,20,50,20,70,
0,110,0,90,0,100);
}break;
case 8:{
process(arr,width,
190,255,190,255,190,255,
140,255,140,255,140,255);
}break;
case 408:{
process(arr,width,
200,255,200,255,0,90,
180,255,170,255,0,90);
}break;
case 9:{
process(arr,width,
0,50,0,50,0,50,
0,160,0,160,0,160);
}break;
case 409:{
process(arr,width,
160,200,200,240,240,255,
150,200,170,210,240,255);
}break;
case 10:{
process(arr,width,
0,50,0,50,0,50,
0,160,0,160,0,160);
}break;
case 410:{
process(arr,width,
240,255,180,200,220,255,
240,255,150,210,220,255);
}break;
case 11:{
process(arr,width,
190,255,190,255,190,255,
140,255,140,255,140,255);
}break;
case 411:{
processBrightness(arr,width,
300,275);
}break;
case 12:{
process(arr,width,
190,255,190,255,190,255,
140,255,140,255,140,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"));
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<=11) {
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));
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
}
}