Fix lag rendering issues, added in extra tests to test suite.
This commit is contained in:
parent
07e207ebed
commit
8cbdfeb062
@ -1,9 +1,11 @@
|
|||||||
package sig;
|
package sig;
|
||||||
|
import java.awt.Canvas;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.RenderingHints;
|
import java.awt.RenderingHints;
|
||||||
|
import java.awt.Toolkit;
|
||||||
import java.awt.font.TextAttribute;
|
import java.awt.font.TextAttribute;
|
||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
@ -24,9 +26,10 @@ import org.json.JSONObject;
|
|||||||
|
|
||||||
import sig.utils.DrawUtils;
|
import sig.utils.DrawUtils;
|
||||||
import sig.utils.FileUtils;
|
import sig.utils.FileUtils;
|
||||||
|
import sig.utils.ImageUtils;
|
||||||
import sig.utils.TextUtils;
|
import sig.utils.TextUtils;
|
||||||
|
|
||||||
public class DrawPanel extends JPanel{
|
public class DrawCanvas extends JPanel{
|
||||||
String difficulty;
|
String difficulty;
|
||||||
String panelText;
|
String panelText;
|
||||||
Font programFont = new Font("Open Sans Condensed", Font.PLAIN, 32);
|
Font programFont = new Font("Open Sans Condensed", Font.PLAIN, 32);
|
||||||
@ -51,26 +54,35 @@ public class DrawPanel extends JPanel{
|
|||||||
int scrollX = 0;
|
int scrollX = 0;
|
||||||
int scrollSpd = 2;
|
int scrollSpd = 2;
|
||||||
Timer scrollTimer = new Timer();
|
Timer scrollTimer = new Timer();
|
||||||
|
BufferedImage doubleBuffer=null,firstBuffer=null;
|
||||||
|
boolean targetBuffer=false;
|
||||||
|
|
||||||
DrawPanel() {
|
DrawCanvas() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
bar = ImageIO.read(new File("divabar.png"));
|
bar = ImageUtils.toCompatibleImage(ImageIO.read(new File("divabar.png")));
|
||||||
overallbar = ImageIO.read(new File("overlaybar.png"));
|
overallbar = ImageUtils.toCompatibleImage(ImageIO.read(new File("overlaybar.png")));
|
||||||
exextreme = ImageIO.read(new File("exex.png"));
|
exextreme = ImageUtils.toCompatibleImage(ImageIO.read(new File("exex.png")));
|
||||||
extreme = ImageIO.read(new File("ex.png"));
|
extreme = ImageUtils.toCompatibleImage(ImageIO.read(new File("ex.png")));
|
||||||
hard = ImageIO.read(new File("hd.png"));
|
hard = ImageUtils.toCompatibleImage(ImageIO.read(new File("hd.png")));
|
||||||
|
|
||||||
|
|
||||||
Timer t = new Timer();
|
Thread t = new Thread() {
|
||||||
t.scheduleAtFixedRate(new TimerTask() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
public void run() {
|
||||||
if (MyRobot.p.scrolling) {
|
while (true) {
|
||||||
MyRobot.p.scrollX-=MyRobot.p.scrollSpd;
|
if (MyRobot.p.scrolling) {
|
||||||
MyRobot.p.repaint();
|
MyRobot.p.scrollX-=MyRobot.p.scrollSpd;
|
||||||
|
}
|
||||||
|
MyRobot.p.repaint(0, 0, 1400, 100);
|
||||||
|
try {
|
||||||
|
Thread.sleep(20);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},0,20);
|
};
|
||||||
|
t.start();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -86,7 +98,7 @@ public class DrawPanel extends JPanel{
|
|||||||
passes=0;
|
passes=0;
|
||||||
fcCount=0;
|
fcCount=0;
|
||||||
artist="";
|
artist="";
|
||||||
this.repaint();
|
this.repaint(0,0,1400,100);
|
||||||
if (t!=null && t.isAlive()) {
|
if (t!=null && t.isAlive()) {
|
||||||
t.stop();
|
t.stop();
|
||||||
}
|
}
|
||||||
@ -112,8 +124,9 @@ public class DrawPanel extends JPanel{
|
|||||||
/*obj = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/rating/sigonasr2");
|
/*obj = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/rating/sigonasr2");
|
||||||
lastRating = overallrating;
|
lastRating = overallrating;
|
||||||
overallrating = (int)obj.getDouble("rating");
|
overallrating = (int)obj.getDouble("rating");
|
||||||
if (lastRating<overallrating) {ratingTime=System.currentTimeMillis();}*/
|
if (lastRating<overallrating) {ratingTime=System.currentTimeMillis();}
|
||||||
String text = songname+" / "+((romanizedname.length()>0)?romanizedname:englishname)+" "+(artist.length()>0?"by "+artist:"")+" "+((plays>0)?("Plays - "+(passes)+"/"+(plays)):"")+" "+((plays!=0)?"("+((int)(Math.floor(((float)passes)/plays*100)))+"% pass rate)":"No plays")+" "+((bestPlay!=null)?"Best Play - "+bestPlay.display():""+" Overall Rating: "+overallrating);
|
*/
|
||||||
|
String text = songname+" / "+((romanizedname.length()>0)?romanizedname:englishname)+" "+(artist.length()>0?"by "+artist:"")+" "+((plays>0)?("Plays - "+(passes)+"/"+(plays)):"")+" "+((plays!=0)?"("+((int)(Math.floor(((float)passes)/plays*100)))+"% pass rate)":"No plays")+" "+((bestPlay!=null)?"Best Play - "+bestPlay.display():"")+" Overall Rating: "+overallrating;
|
||||||
Rectangle2D bounds = TextUtils.calculateStringBoundsFont(text, programFont);
|
Rectangle2D bounds = TextUtils.calculateStringBoundsFont(text, programFont);
|
||||||
if (bounds.getWidth()>1345) {
|
if (bounds.getWidth()>1345) {
|
||||||
scrolling=true;
|
scrolling=true;
|
||||||
@ -121,7 +134,7 @@ public class DrawPanel extends JPanel{
|
|||||||
scrolling=false;
|
scrolling=false;
|
||||||
}
|
}
|
||||||
scrollX = 0;
|
scrollX = 0;
|
||||||
MyRobot.p.repaint();
|
MyRobot.p.repaint(0,0,1400,100);
|
||||||
} catch (JSONException | IOException e) {
|
} catch (JSONException | IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -130,41 +143,44 @@ public class DrawPanel extends JPanel{
|
|||||||
t.start();
|
t.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void paintComponent(Graphics g) {
|
public void paintComponent(Graphics g) {
|
||||||
super.paintComponent(g);
|
super.paintComponent(g);
|
||||||
((Graphics2D)g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
|
Graphics2D g2 = (Graphics2D)g;
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
|
||||||
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||||
((Graphics2D)g).setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
|
g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
|
||||||
RenderingHints.VALUE_FRACTIONALMETRICS_ON);
|
RenderingHints.VALUE_FRACTIONALMETRICS_ON);
|
||||||
g.setColor(new Color(0,255,0));
|
g2.setColor(new Color(0,255,0));
|
||||||
g.fillRect(0, 0, 1400, 100);
|
g2.fillRect(0, 0, 1400, 100);
|
||||||
if (!MyRobot.isOnSongSelect()) {
|
//if (!MyRobot.isOnSongSelect()) {
|
||||||
g.setFont(programFont);
|
//g2.setFont(programFont);
|
||||||
g.drawImage(bar, 0, 0, this);
|
g2.drawImage(bar, 0, 0,null);
|
||||||
if (ratingTime>System.currentTimeMillis()-10000) {
|
if (ratingTime>System.currentTimeMillis()-10000) {
|
||||||
DrawUtils.drawOutlineText(g, programFont, 32, 36, 3, new Color(220,220,255,(int)Math.min(((System.currentTimeMillis()-ratingTime))/5,255)), new Color(0,0,0,64), "Rating up! "+lastRating+" -> "+overallrating);
|
DrawUtils.drawOutlineText(g, programFont, 32, 36, 3, new Color(220,220,255,(int)Math.min(((System.currentTimeMillis()-ratingTime))/5,255)), new Color(0,0,0,64), "Rating up! "+lastRating+" -> "+overallrating);
|
||||||
} else {
|
} else {
|
||||||
String text = songname+" / "+((romanizedname.length()>0)?romanizedname:englishname)+" "+(artist.length()>0?"by "+artist:"")+" "+((plays>0)?("Plays - "+(passes)+"/"+(plays)):"")+" "+((plays!=0)?"("+((int)(Math.floor(((float)passes)/plays*100)))+"% pass rate)":"No plays")+" "+((bestPlay!=null)?"Best Play - "+bestPlay.display():""+" Overall Rating: "+overallrating);
|
String text = songname+" / "+((romanizedname.length()>0)?romanizedname:englishname)+" "+(artist.length()>0?"by "+artist:"")+" "+((plays>0)?("Plays - "+(passes)+"/"+(plays)):"")+" "+((plays!=0)?"("+((int)(Math.floor(((float)passes)/plays*100)))+"% pass rate)":"No plays")+" "+((bestPlay!=null)?"Best Play - "+bestPlay.display():"")+" Overall Rating: "+overallrating;
|
||||||
Rectangle2D bounds = TextUtils.calculateStringBoundsFont(text, programFont);
|
Rectangle2D bounds = TextUtils.calculateStringBoundsFont(text, programFont);
|
||||||
if (scrollX<-bounds.getWidth()-100) {
|
if (scrollX<-bounds.getWidth()-100) {
|
||||||
scrollX=(int)bounds.getWidth()+100;
|
scrollX=(int)bounds.getWidth()+100;
|
||||||
}
|
}
|
||||||
DrawUtils.drawOutlineText(g, programFont, 32+scrollX, 36, 3, Color.WHITE, new Color(0,0,0,64) , text);
|
DrawUtils.drawOutlineText(g2, programFont, 32+scrollX, 36, 3, Color.WHITE, new Color(0,0,0,64), text);
|
||||||
}
|
}
|
||||||
switch (difficulty) {
|
switch (difficulty) {
|
||||||
case "H":{
|
case "H":{
|
||||||
g.drawImage(hard,0,0,20,51,this);
|
g2.drawImage(hard,0,0,20,51,null);
|
||||||
}break;
|
}break;
|
||||||
case "EX":{
|
case "EX":{
|
||||||
g.drawImage(extreme,0,0,20,51,this);
|
g2.drawImage(extreme,0,0,20,51,null);
|
||||||
}break;
|
}break;
|
||||||
case "EXEX":{
|
case "EXEX":{
|
||||||
g.drawImage(exextreme,0,0,20,51,this);
|
g2.drawImage(exextreme,0,0,20,51,null);
|
||||||
}break;
|
}break;
|
||||||
}
|
}
|
||||||
}
|
//}
|
||||||
//as.addAttribute(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
|
//as.addAttribute(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
|
||||||
//g.drawString(songname, 24, 32);
|
//g2.drawString(songname, 24, 32);
|
||||||
g.drawImage(overallbar, 1349, 0, this);
|
g2.drawImage(overallbar, 1349, 0,null);
|
||||||
|
//System.out.println(System.currentTimeMillis()-startTime+"ms");
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -94,7 +94,7 @@ public class MyRobot{
|
|||||||
static JTextField title;
|
static JTextField title;
|
||||||
final int WIDTH = 200;
|
final int WIDTH = 200;
|
||||||
final int HEIGHT = 5;
|
final int HEIGHT = 5;
|
||||||
public static DrawPanel p;
|
public static DrawCanvas p;
|
||||||
static int currentSong = 0;
|
static int currentSong = 0;
|
||||||
static SongData selectedSong = null;
|
static SongData selectedSong = null;
|
||||||
static String difficulty = "H"; //H=Hard EX=Extreme EXEX=Extra Extreme
|
static String difficulty = "H"; //H=Hard EX=Extreme EXEX=Extra Extreme
|
||||||
@ -102,6 +102,7 @@ public class MyRobot{
|
|||||||
|
|
||||||
int lastcool,lastfine,lastsafe,lastsad,lastworst;
|
int lastcool,lastfine,lastsafe,lastsad,lastworst;
|
||||||
float lastpercent;
|
float lastpercent;
|
||||||
|
boolean lastfail;
|
||||||
long lastSongSelectTime = System.currentTimeMillis();
|
long lastSongSelectTime = System.currentTimeMillis();
|
||||||
|
|
||||||
static TypeFace typeface1,typeface2;
|
static TypeFace typeface1,typeface2;
|
||||||
@ -113,6 +114,8 @@ public class MyRobot{
|
|||||||
boolean recordingResults=false;
|
boolean recordingResults=false;
|
||||||
long lastReportedEyeTrackingTime = System.currentTimeMillis();
|
long lastReportedEyeTrackingTime = System.currentTimeMillis();
|
||||||
|
|
||||||
|
boolean overlayHidden=false;
|
||||||
|
static boolean onSongSelect=false;
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@ -122,13 +125,20 @@ public class MyRobot{
|
|||||||
boolean EyeTrackingIsOn() {
|
boolean EyeTrackingIsOn() {
|
||||||
//1888,760
|
//1888,760
|
||||||
if (System.currentTimeMillis()-5000>lastReportedEyeTrackingTime) {
|
if (System.currentTimeMillis()-5000>lastReportedEyeTrackingTime) {
|
||||||
BufferedImage img = MYROBOT.createScreenCapture(new Rectangle(1871,760,1,1));
|
BufferedImage img = ImageUtils.toCompatibleImage(MYROBOT.createScreenCapture(new Rectangle(1866,759,1,1)));
|
||||||
Color pixel = new Color(img.getRGB(0, 0));
|
Color pixel = new Color(img.getRGB(0, 0));
|
||||||
lastReportedEyeTrackingTime=System.currentTimeMillis();
|
lastReportedEyeTrackingTime=System.currentTimeMillis();
|
||||||
eyeTrackingSceneOn=pixel.getRed()<60 && pixel.getGreen()<60 && pixel.getBlue()<60;
|
eyeTrackingSceneOn=pixel.getRed()<60 && pixel.getGreen()<60 && pixel.getBlue()<60;
|
||||||
}
|
}
|
||||||
return eyeTrackingSceneOn;
|
return eyeTrackingSceneOn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean textFailPixel(BufferedImage img) {
|
||||||
|
Color failPixel = new Color(img.getRGB(0, 0));
|
||||||
|
//System.out.println(failPixel);
|
||||||
|
//r=128,g=5,b=232
|
||||||
|
return failPixel.getRed()>=50 && failPixel.getRed()<=150 && failPixel.getGreen()>=50 && failPixel.getGreen()<=150 && failPixel.getBlue()>=50 && failPixel.getBlue()<=150;
|
||||||
|
}
|
||||||
|
|
||||||
void BotMain() {
|
void BotMain() {
|
||||||
try {
|
try {
|
||||||
@ -145,8 +155,11 @@ public class MyRobot{
|
|||||||
t.scheduleAtFixedRate(new TimerTask() {
|
t.scheduleAtFixedRate(new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
if (checkSongSelect()) {
|
||||||
if (isOnSongSelect()) {
|
if (!overlayHidden) {
|
||||||
|
overlayHidden=true;
|
||||||
|
p.repaint(0, 0, 1400, 100);
|
||||||
|
}
|
||||||
GetCurrentSong();
|
GetCurrentSong();
|
||||||
GetCurrentDifficulty();
|
GetCurrentDifficulty();
|
||||||
recordedResults=false;
|
recordedResults=false;
|
||||||
@ -160,6 +173,10 @@ public class MyRobot{
|
|||||||
}
|
}
|
||||||
lastSongSelectTime = System.currentTimeMillis();
|
lastSongSelectTime = System.currentTimeMillis();
|
||||||
} else {
|
} else {
|
||||||
|
if (overlayHidden) {
|
||||||
|
overlayHidden=false;
|
||||||
|
p.repaint(0, 0, 1400, 100);
|
||||||
|
}
|
||||||
/*selectedSong=new SongData("test",new Color[] {});
|
/*selectedSong=new SongData("test",new Color[] {});
|
||||||
difficulty="EXEX";*/
|
difficulty="EXEX";*/
|
||||||
if ((selectedSong!=null && difficulty!=null) /*|| true*/) {
|
if ((selectedSong!=null && difficulty!=null) /*|| true*/) {
|
||||||
@ -172,6 +189,7 @@ public class MyRobot{
|
|||||||
lastSongSelectTime=System.currentTimeMillis();
|
lastSongSelectTime=System.currentTimeMillis();
|
||||||
if (EyeTrackingIsOn()) {
|
if (EyeTrackingIsOn()) {
|
||||||
eyeTrackingSceneOn=false;
|
eyeTrackingSceneOn=false;
|
||||||
|
lastReportedEyeTrackingTime=System.currentTimeMillis();
|
||||||
gotoxy(800,64);
|
gotoxy(800,64);
|
||||||
click();
|
click();
|
||||||
gotoxy(1870,761);
|
gotoxy(1870,761);
|
||||||
@ -195,6 +213,8 @@ public class MyRobot{
|
|||||||
int safe = typeface1.extractNumbersFromImage(MYROBOT.createScreenCapture(new Rectangle(1235,518,115,26)),new File(tmp,"safe"));
|
int safe = typeface1.extractNumbersFromImage(MYROBOT.createScreenCapture(new Rectangle(1235,518,115,26)),new File(tmp,"safe"));
|
||||||
int sad = typeface1.extractNumbersFromImage(MYROBOT.createScreenCapture(new Rectangle(1235,553,115,26)),new File(tmp,"sad"));
|
int sad = typeface1.extractNumbersFromImage(MYROBOT.createScreenCapture(new Rectangle(1235,553,115,26)),new File(tmp,"sad"));
|
||||||
int worst = typeface1.extractNumbersFromImage(MYROBOT.createScreenCapture(new Rectangle(1235,583,115,26)),new File(tmp,"worst"));
|
int worst = typeface1.extractNumbersFromImage(MYROBOT.createScreenCapture(new Rectangle(1235,583,115,26)),new File(tmp,"worst"));
|
||||||
|
|
||||||
|
boolean fail = textFailPixel(MYROBOT.createScreenCapture(new Rectangle(952,385,1,1)));
|
||||||
/*try {
|
/*try {
|
||||||
ImageIO.write(MYROBOT.createScreenCapture(new Rectangle(1235,583,115,26)),"png",new File("worst.png"));
|
ImageIO.write(MYROBOT.createScreenCapture(new Rectangle(1235,583,115,26)),"png",new File("worst.png"));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -204,7 +224,7 @@ public class MyRobot{
|
|||||||
if (cool==-1 || fine==-1 || safe==-1 || sad==-1 || worst==-1 || percent==-0.01f) {
|
if (cool==-1 || fine==-1 || safe==-1 || sad==-1 || worst==-1 || percent==-0.01f) {
|
||||||
System.out.println("Waiting for results to populate...");
|
System.out.println("Waiting for results to populate...");
|
||||||
} else
|
} else
|
||||||
if (cool!=lastcool || lastfine!=fine || lastsafe!=safe || lastsad!=sad || lastworst!=worst /*|| lastpercent!=percent*/){
|
if (fail!=lastfail || cool!=lastcool || lastfine!=fine || lastsafe!=safe || lastsad!=sad || lastworst!=worst /*|| lastpercent!=percent*/){
|
||||||
System.out.println("Results for "+selectedSong.title+" "+difficulty+": "+cool+"/"+fine+"/"+safe+"/"+sad+"/"+worst+" "+percent+"%");
|
System.out.println("Results for "+selectedSong.title+" "+difficulty+": "+cool+"/"+fine+"/"+safe+"/"+sad+"/"+worst+" "+percent+"%");
|
||||||
File songFolder = new File(selectedSong.title+"/"+difficulty);
|
File songFolder = new File(selectedSong.title+"/"+difficulty);
|
||||||
if (!songFolder.exists()) {
|
if (!songFolder.exists()) {
|
||||||
@ -233,10 +253,13 @@ public class MyRobot{
|
|||||||
lastsad=sad;
|
lastsad=sad;
|
||||||
lastworst=worst;
|
lastworst=worst;
|
||||||
lastpercent=percent;
|
lastpercent=percent;
|
||||||
results.add(new Result(selectedSong.title,difficulty,cool,fine,safe,sad,worst,percent));
|
lastfail=fail;
|
||||||
|
|
||||||
|
results.add(new Result(selectedSong.title,difficulty,cool,fine,safe,sad,worst,percent,fail));
|
||||||
SoundUtils.playSound("collect_item.wav");
|
SoundUtils.playSound("collect_item.wav");
|
||||||
if (!EyeTrackingIsOn()) {
|
if (!EyeTrackingIsOn()) {
|
||||||
eyeTrackingSceneOn=true;
|
eyeTrackingSceneOn=true;
|
||||||
|
lastReportedEyeTrackingTime=System.currentTimeMillis();
|
||||||
gotoxy(800,64);
|
gotoxy(800,64);
|
||||||
click();
|
click();
|
||||||
gotoxy(1870,761);
|
gotoxy(1870,761);
|
||||||
@ -263,6 +286,7 @@ public class MyRobot{
|
|||||||
params.add(new BasicNameValuePair("sad", Integer.toString(r.sad)));
|
params.add(new BasicNameValuePair("sad", Integer.toString(r.sad)));
|
||||||
params.add(new BasicNameValuePair("worst", Integer.toString(r.worst)));
|
params.add(new BasicNameValuePair("worst", Integer.toString(r.worst)));
|
||||||
params.add(new BasicNameValuePair("percent", Float.toString(r.percent)));
|
params.add(new BasicNameValuePair("percent", Float.toString(r.percent)));
|
||||||
|
params.add(new BasicNameValuePair("fail", Boolean.toString(r.fail)));
|
||||||
try {
|
try {
|
||||||
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
|
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
@ -296,9 +320,8 @@ public class MyRobot{
|
|||||||
p.lastRating = p.overallrating;
|
p.lastRating = p.overallrating;
|
||||||
p.overallrating = (int)obj.getDouble("rating");
|
p.overallrating = (int)obj.getDouble("rating");
|
||||||
if (p.lastRating<p.overallrating) {p.ratingTime=System.currentTimeMillis();}
|
if (p.lastRating<p.overallrating) {p.ratingTime=System.currentTimeMillis();}
|
||||||
} catch (JSONException e) {
|
p.pullData(selectedSong.title, difficulty);
|
||||||
e.printStackTrace();
|
} catch (JSONException | IOException e) {
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
/*MYROBOT.setAutoDelay(0);
|
/*MYROBOT.setAutoDelay(0);
|
||||||
@ -374,8 +397,8 @@ public class MyRobot{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean OnResultsScreen() {
|
private boolean OnResultsScreen() {
|
||||||
Color c1 = new Color(MYROBOT.createScreenCapture(new Rectangle(602,217,2,2)).getRGB(0, 0));
|
Color c1 = new Color(MYROBOT.createScreenCapture(new Rectangle(449,434,2,2)).getRGB(0, 0));
|
||||||
Color c2 = new Color(MYROBOT.createScreenCapture(new Rectangle(602,260,2,2)).getRGB(0, 0));
|
Color c2 = new Color(MYROBOT.createScreenCapture(new Rectangle(449,400,2,2)).getRGB(0, 0));
|
||||||
Color c3 = new Color(MYROBOT.createScreenCapture(new Rectangle(901,460,2,2)).getRGB(0, 0));
|
Color c3 = new Color(MYROBOT.createScreenCapture(new Rectangle(901,460,2,2)).getRGB(0, 0));
|
||||||
return c1.getRed()>=254 && c1.getGreen()>=254 && c1.getBlue()>=254 && c2.getRed()==16 && c2.getGreen()==222 && c2.getBlue()==202 &&
|
return c1.getRed()>=254 && c1.getGreen()>=254 && c1.getBlue()>=254 && c2.getRed()==16 && c2.getGreen()==222 && c2.getBlue()==202 &&
|
||||||
c3.getRed()>=220 && c3.getRed()<=255 && c3.getGreen()>=220 && c3.getGreen()<=255 && c3.getBlue()>=160 && c3.getBlue()<=220;
|
c3.getRed()>=220 && c3.getRed()<=255 && c3.getGreen()>=220 && c3.getGreen()<=255 && c3.getBlue()>=160 && c3.getBlue()<=220;
|
||||||
@ -395,7 +418,7 @@ public class MyRobot{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void GetCurrentSong() {
|
private void GetCurrentSong() {
|
||||||
BufferedImage img = MYROBOT.createScreenCapture(new Rectangle(460,426,WIDTH,HEIGHT));
|
BufferedImage img = ImageUtils.toCompatibleImage(MYROBOT.createScreenCapture(new Rectangle(460,426,WIDTH,HEIGHT)));
|
||||||
Color[] col = new Color[WIDTH*HEIGHT];
|
Color[] col = new Color[WIDTH*HEIGHT];
|
||||||
for (int i=0;i<WIDTH;i++) {
|
for (int i=0;i<WIDTH;i++) {
|
||||||
for (int j=0;j<HEIGHT;j++) {
|
for (int j=0;j<HEIGHT;j++) {
|
||||||
@ -435,19 +458,17 @@ public class MyRobot{
|
|||||||
System.setProperty("awt.useSystemAAFontSettings","on");
|
System.setProperty("awt.useSystemAAFontSettings","on");
|
||||||
JFrame f = new JFrame();
|
JFrame f = new JFrame();
|
||||||
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
p = new DrawPanel();
|
p = new DrawCanvas();
|
||||||
p.difficulty="EX";
|
p.difficulty="EXEX";
|
||||||
p.songname = "39みゅーじっく!";
|
p.songname = "Dear";
|
||||||
int condition = JComponent.WHEN_IN_FOCUSED_WINDOW;
|
int condition = JComponent.WHEN_IN_FOCUSED_WINDOW;
|
||||||
InputMap inputMap = p.getInputMap(condition);
|
|
||||||
ActionMap actionMap = p.getActionMap();
|
|
||||||
BufferedImage img1 = null;
|
BufferedImage img1 = null;
|
||||||
BufferedImage img2 = null;
|
BufferedImage img2 = null;
|
||||||
typeface1 = null;
|
typeface1 = null;
|
||||||
typeface2=null;
|
typeface2=null;
|
||||||
try {
|
try {
|
||||||
img1 = ImageIO.read(new File("typeface1.png"));
|
img1 = ImageUtils.toCompatibleImage(ImageIO.read(new File("typeface1.png")));
|
||||||
img2 = ImageIO.read(new File("typeface2.png"));
|
img2 = ImageUtils.toCompatibleImage(ImageIO.read(new File("typeface2.png")));
|
||||||
typeface1 = new TypeFace(img1);
|
typeface1 = new TypeFace(img1);
|
||||||
typeface2 = new TypeFace(img2);
|
typeface2 = new TypeFace(img2);
|
||||||
typeface2.green_minthreshold=typeface2.blue_minthreshold=100;
|
typeface2.green_minthreshold=typeface2.blue_minthreshold=100;
|
||||||
@ -460,10 +481,10 @@ public class MyRobot{
|
|||||||
/*inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0), "Press"); //DEBUG KEYS.
|
/*inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0), "Press"); //DEBUG KEYS.
|
||||||
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0), "Identifier");
|
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0), "Identifier");
|
||||||
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0), "Toggle");*/
|
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0), "Toggle");*/
|
||||||
actionMap.put("Press", new AbstractAction() {
|
/*actionMap.put("Press", new AbstractAction() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
BufferedImage img = MYROBOT.createScreenCapture(new Rectangle(460,426,WIDTH,HEIGHT));
|
BufferedImage img = ImageUtils.toCompatibleImage(MYROBOT.createScreenCapture(new Rectangle(460,426,WIDTH,HEIGHT)));
|
||||||
Color[] col = new Color[WIDTH*HEIGHT];
|
Color[] col = new Color[WIDTH*HEIGHT];
|
||||||
for (int i=0;i<WIDTH;i++) {
|
for (int i=0;i<WIDTH;i++) {
|
||||||
for (int j=0;j<HEIGHT;j++) {
|
for (int j=0;j<HEIGHT;j++) {
|
||||||
@ -479,7 +500,7 @@ public class MyRobot{
|
|||||||
actionMap.put("Identifier", new AbstractAction() {
|
actionMap.put("Identifier", new AbstractAction() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
BufferedImage img = MYROBOT.createScreenCapture(new Rectangle(460,426,WIDTH,HEIGHT));
|
BufferedImage img = ImageUtils.toCompatibleImage(MYROBOT.createScreenCapture(new Rectangle(460,426,WIDTH,HEIGHT)));
|
||||||
Color[] col = new Color[WIDTH*HEIGHT];
|
Color[] col = new Color[WIDTH*HEIGHT];
|
||||||
for (int i=0;i<WIDTH;i++) {
|
for (int i=0;i<WIDTH;i++) {
|
||||||
for (int j=0;j<HEIGHT;j++) {
|
for (int j=0;j<HEIGHT;j++) {
|
||||||
@ -495,8 +516,8 @@ public class MyRobot{
|
|||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
currentSong++;
|
currentSong++;
|
||||||
SongData s = SongData.getByTitle(SONGNAMES[currentSong]);
|
SongData s = SongData.getByTitle(SONGNAMES[currentSong]);
|
||||||
BufferedImage bufferedImage = new BufferedImage(WIDTH, HEIGHT,
|
BufferedImage bufferedImage = ImageUtils.toCompatibleImage(new BufferedImage(WIDTH, HEIGHT,
|
||||||
BufferedImage.TYPE_INT_RGB);
|
BufferedImage.TYPE_INT_RGB));
|
||||||
for (int i=0;i<WIDTH;i++) {
|
for (int i=0;i<WIDTH;i++) {
|
||||||
for (int j=0;j<HEIGHT;j++) {
|
for (int j=0;j<HEIGHT;j++) {
|
||||||
bufferedImage.setRGB(i, j, s.songCode[i*HEIGHT+j].getRGB());
|
bufferedImage.setRGB(i, j, s.songCode[i*HEIGHT+j].getRGB());
|
||||||
@ -504,7 +525,7 @@ public class MyRobot{
|
|||||||
}
|
}
|
||||||
p.getGraphics().drawImage(bufferedImage, 0, 0, f);
|
p.getGraphics().drawImage(bufferedImage, 0, 0, f);
|
||||||
}
|
}
|
||||||
});
|
});*/
|
||||||
f.setVisible(true);
|
f.setVisible(true);
|
||||||
f.setSize(1416, 51+48);
|
f.setSize(1416, 51+48);
|
||||||
f.add(p);
|
f.add(p);
|
||||||
@ -564,17 +585,19 @@ public class MyRobot{
|
|||||||
|
|
||||||
selectedSong=new SongData("packaged",new Color[] {});
|
selectedSong=new SongData("packaged",new Color[] {});
|
||||||
difficulty="EXEX";
|
difficulty="EXEX";
|
||||||
RunTest("shake it!_EXplay_568_88_8_4_7_96.03.png",580,80,0,4,7,95.03f);
|
RunTest("shake it!_EXplay_568_88_8_4_7_96.03.png",580,80,0,4,7,95.03f,false);
|
||||||
RunTest("え?あぁ、そう。_EXEXplay_499_121_11_9_43_77.11.png",439,121,11,5,43,77.11f);
|
RunTest("え?あぁ、そう。_EXEXplay_499_121_11_9_43_77.11.png",439,121,11,5,43,77.11f,false);
|
||||||
RunTest("サマーアイドル_EXplay_959_56_19_5_10_81.32.png",363,58,15,5,10,84.32f);
|
RunTest("サマーアイドル_EXplay_959_56_19_5_10_81.32.png",363,58,15,5,10,84.32f,false);
|
||||||
RunTest("テレカクシ思春期_EXplay_44_108_7_4_18_81.8.png",447,109,7,4,16,84.80f);
|
RunTest("テレカクシ思春期_EXplay_44_108_7_4_18_81.8.png",447,109,7,4,16,84.80f,false);
|
||||||
RunTest("どういうことなの!?_EXplay_449_85_3_0_3_95.01.png",448,85,2,0,3,95.01f);
|
RunTest("どういうことなの!?_EXplay_449_85_3_0_3_95.01.png",448,85,2,0,3,95.01f,false);
|
||||||
RunTest("天樂_EXplay_361_58_9_4_11_92.67.png",351,56,8,4,11,92.67f);
|
RunTest("天樂_EXplay_361_58_9_4_11_92.67.png",351,56,8,4,11,92.67f,false);
|
||||||
RunTest("番凩_EXEXplay_41_110_1_10_21_77.76.png",431,110,17,10,31,77.79f);
|
RunTest("番凩_EXEXplay_41_110_1_10_21_77.76.png",431,110,17,10,31,77.79f,false);
|
||||||
RunTest("結ンデ開イテ羅刹ト骸_EXEXplay_47_123_10_5_46_74.19.png",471,123,10,5,46,74.19f);
|
RunTest("結ンデ開イテ羅刹ト骸_EXEXplay_47_123_10_5_46_74.19.png",471,123,10,5,46,74.19f,false);
|
||||||
|
RunTest("エイリアンエイリアン_EXplay_505_278_3_0_5_89.19.png",505,218,3,0,5,89.19f,false);
|
||||||
|
RunTest("アンハッピーリフレイン_EXEXplay_716_163_15_6_64_72.69.png",716,163,15,6,64,72.69f,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RunTest(String _img,int _cool,int _fine, int _safe, int _sad, int _worst, float _percent) {
|
void RunTest(String _img,int _cool,int _fine, int _safe, int _sad, int _worst, float _percent,boolean _fail) {
|
||||||
System.out.println("Running test "+_img);
|
System.out.println("Running test "+_img);
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
String testdir="testsuite";
|
String testdir="testsuite";
|
||||||
@ -597,6 +620,7 @@ public class MyRobot{
|
|||||||
int sad = typeface1.extractNumbersFromImage(ImageUtils.cropImage(img,new Rectangle(1235-offset.x,553-offset.y,115,26)),new File(tmp,"sad"));
|
int sad = typeface1.extractNumbersFromImage(ImageUtils.cropImage(img,new Rectangle(1235-offset.x,553-offset.y,115,26)),new File(tmp,"sad"));
|
||||||
int worst = typeface1.extractNumbersFromImage(ImageUtils.cropImage(img,new Rectangle(1235-offset.x,583-offset.y,115,26)),new File(tmp,"worst"));
|
int worst = typeface1.extractNumbersFromImage(ImageUtils.cropImage(img,new Rectangle(1235-offset.x,583-offset.y,115,26)),new File(tmp,"worst"));
|
||||||
float percent = (float)typeface2.extractNumbersFromImage(ImageUtils.cropImage(img,new Rectangle(1428-offset.x,361-offset.y,128,30)),new File(tmp,"percent"))/100f;
|
float percent = (float)typeface2.extractNumbersFromImage(ImageUtils.cropImage(img,new Rectangle(1428-offset.x,361-offset.y,128,30)),new File(tmp,"percent"))/100f;
|
||||||
|
boolean fail = textFailPixel(ImageUtils.cropImage(img, new Rectangle(952-offset.x,385-offset.y,1,1))); ;
|
||||||
|
|
||||||
assert cool == _cool : "Expected cool count to be "+_cool+", got "+cool;
|
assert cool == _cool : "Expected cool count to be "+_cool+", got "+cool;
|
||||||
assert fine == _fine : "Expected fine count to be "+_fine+", got "+fine;
|
assert fine == _fine : "Expected fine count to be "+_fine+", got "+fine;
|
||||||
@ -604,15 +628,22 @@ public class MyRobot{
|
|||||||
assert sad == _sad : "Expected sad count to be "+_sad+", got "+sad;
|
assert sad == _sad : "Expected sad count to be "+_sad+", got "+sad;
|
||||||
assert worst == _worst : "Expected worst count to be "+_worst+", got "+worst;
|
assert worst == _worst : "Expected worst count to be "+_worst+", got "+worst;
|
||||||
assert percent == _percent : "Expected percent to be "+_percent+", got "+percent;
|
assert percent == _percent : "Expected percent to be "+_percent+", got "+percent;
|
||||||
|
assert fail == _fail : "Expected fail to be "+_fail+", got "+fail;
|
||||||
System.out.println(" Passed ("+(System.currentTimeMillis()-startTime)+"ms)!");
|
System.out.println(" Passed ("+(System.currentTimeMillis()-startTime)+"ms)!");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isOnSongSelect() {
|
public static boolean checkSongSelect() {
|
||||||
Color c = new Color(MYROBOT.createScreenCapture(new Rectangle(1255,824,20,20)).getRGB(10, 10));
|
Color c = new Color(MYROBOT.createScreenCapture(new Rectangle(1255,824,20,20)).getRGB(10, 10));
|
||||||
return c.getRed()==43 && c.getGreen()==88 && c.getBlue()==213;
|
onSongSelect = c.getRed()==43 && c.getGreen()==88 && c.getBlue()==213;
|
||||||
|
return onSongSelect;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isOnSongSelect() {
|
||||||
|
return onSongSelect;
|
||||||
}
|
}
|
||||||
|
|
||||||
void initialize() {
|
void initialize() {
|
||||||
|
System.setProperty("sun.java2d.opengl", "True");
|
||||||
grEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
grEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||||
grDevice = grEnv.getDefaultScreenDevice();
|
grDevice = grEnv.getDefaultScreenDevice();
|
||||||
updateScreenInfo();
|
updateScreenInfo();
|
||||||
|
@ -5,6 +5,7 @@ public class Result {
|
|||||||
String difficulty;
|
String difficulty;
|
||||||
int cool,fine,safe,sad,worst;
|
int cool,fine,safe,sad,worst;
|
||||||
float percent;
|
float percent;
|
||||||
|
boolean fail;
|
||||||
public Result(String song,String diff,int cool,int fine,int safe,int sad,int worst,float percent) {
|
public Result(String song,String diff,int cool,int fine,int safe,int sad,int worst,float percent) {
|
||||||
this.songName=song;
|
this.songName=song;
|
||||||
this.difficulty=diff;
|
this.difficulty=diff;
|
||||||
@ -15,6 +16,10 @@ public class Result {
|
|||||||
this.worst=worst;
|
this.worst=worst;
|
||||||
this.percent=percent;
|
this.percent=percent;
|
||||||
}
|
}
|
||||||
|
public Result(String song,String diff,int cool,int fine,int safe,int sad,int worst,float percent,boolean fail) {
|
||||||
|
this(song,diff,cool,fine,safe,sad,worst,percent);
|
||||||
|
this.fail=fail;
|
||||||
|
}
|
||||||
public String display() {
|
public String display() {
|
||||||
return new StringBuilder(Integer.toString(cool)).append("/").append(fine)
|
return new StringBuilder(Integer.toString(cool)).append("/").append(fine)
|
||||||
.append("/").append(safe).append("/").append(sad).append("/").append(worst).append(" ").append(percent).append("%").toString();
|
.append("/").append(safe).append("/").append(sad).append("/").append(worst).append(" ").append(percent).append("%").toString();
|
||||||
|
@ -31,7 +31,7 @@ public class TypeFace {
|
|||||||
int red_fillminthreshold = 0;
|
int red_fillminthreshold = 0;
|
||||||
int blue_fillmaxthreshold = 255;
|
int blue_fillmaxthreshold = 255;
|
||||||
int green_fillmaxthreshold = 150;
|
int green_fillmaxthreshold = 150;
|
||||||
int red_fillmaxthreshold = 100;
|
int red_fillmaxthreshold = 107;
|
||||||
boolean darkFillCheck = true;
|
boolean darkFillCheck = true;
|
||||||
Color[][] numbers = new Color[WIDTH*HEIGHT][NUMBER_COUNT];
|
Color[][] numbers = new Color[WIDTH*HEIGHT][NUMBER_COUNT];
|
||||||
BufferedImage baseImg;
|
BufferedImage baseImg;
|
||||||
@ -60,7 +60,7 @@ public class TypeFace {
|
|||||||
|
|
||||||
BufferedImage numberImg = null;
|
BufferedImage numberImg = null;
|
||||||
|
|
||||||
final boolean DEBUG_IMG = false;
|
final boolean DEBUG_IMG = true;
|
||||||
|
|
||||||
|
|
||||||
int iterations=0;
|
int iterations=0;
|
||||||
@ -77,7 +77,7 @@ public class TypeFace {
|
|||||||
state=1;
|
state=1;
|
||||||
if (DEBUG_IMG) {
|
if (DEBUG_IMG) {
|
||||||
try {
|
try {
|
||||||
BufferedImage img2 = ImageUtils.copyBufferedImage(img);
|
BufferedImage img2 = ImageUtils.toCompatibleImage(ImageUtils.copyBufferedImage(img));
|
||||||
img2.setRGB(X, midY, Color.RED.getRGB());
|
img2.setRGB(X, midY, Color.RED.getRGB());
|
||||||
ImageIO.write(img2,"png",new File("stage1_"+System.currentTimeMillis()+".png"));
|
ImageIO.write(img2,"png",new File("stage1_"+System.currentTimeMillis()+".png"));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -100,7 +100,7 @@ public class TypeFace {
|
|||||||
state=2;
|
state=2;
|
||||||
if (DEBUG_IMG) {
|
if (DEBUG_IMG) {
|
||||||
try {
|
try {
|
||||||
BufferedImage img2 = ImageUtils.copyBufferedImage(img);
|
BufferedImage img2 = ImageUtils.toCompatibleImage(ImageUtils.copyBufferedImage(img));
|
||||||
img2.setRGB(X, midY, Color.RED.getRGB());
|
img2.setRGB(X, midY, Color.RED.getRGB());
|
||||||
ImageIO.write(img2,"png",new File("stage2_"+System.currentTimeMillis()+".png"));
|
ImageIO.write(img2,"png",new File("stage2_"+System.currentTimeMillis()+".png"));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -124,7 +124,7 @@ public class TypeFace {
|
|||||||
state=3;
|
state=3;
|
||||||
if (DEBUG_IMG) {
|
if (DEBUG_IMG) {
|
||||||
try {
|
try {
|
||||||
BufferedImage img2 = ImageUtils.copyBufferedImage(img);
|
BufferedImage img2 = ImageUtils.toCompatibleImage(ImageUtils.copyBufferedImage(img));
|
||||||
img2.setRGB(X, midY, Color.RED.getRGB());
|
img2.setRGB(X, midY, Color.RED.getRGB());
|
||||||
ImageIO.write(img2,"png",new File("stage3_"+System.currentTimeMillis()+".png"));
|
ImageIO.write(img2,"png",new File("stage3_"+System.currentTimeMillis()+".png"));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -135,13 +135,13 @@ public class TypeFace {
|
|||||||
}break;
|
}break;
|
||||||
case 3:{
|
case 3:{
|
||||||
//Figure out which number in the typeface it best represents.
|
//Figure out which number in the typeface it best represents.
|
||||||
numberImg = ImageUtils.toBufferedImage(numberImg.getScaledInstance(WIDTH, HEIGHT, Image.SCALE_FAST));
|
numberImg = ImageUtils.toCompatibleImage(ImageUtils.toBufferedImage(numberImg.getScaledInstance(WIDTH, HEIGHT, Image.SCALE_FAST)));
|
||||||
//System.out.println(numberImg.getWidth()+"x"+numberImg.getHeight());
|
//System.out.println(numberImg.getWidth()+"x"+numberImg.getHeight());
|
||||||
int[] hits = new int[NUMBER_COUNT];
|
int[] hits = new int[NUMBER_COUNT];
|
||||||
double highestRatio = 0;
|
double highestRatio = 0;
|
||||||
int highest = 0;
|
int highest = 0;
|
||||||
for (int k=0;k<NUMBER_COUNT;k++) {
|
for (int k=0;k<NUMBER_COUNT;k++) {
|
||||||
BufferedImage img2 = ImageUtils.copyBufferedImage(numberImg);
|
BufferedImage img2 = ImageUtils.toCompatibleImage(ImageUtils.copyBufferedImage(numberImg));
|
||||||
for (int i=0;i<WIDTH;i++) {
|
for (int i=0;i<WIDTH;i++) {
|
||||||
for (int j=0;j<HEIGHT;j++) {
|
for (int j=0;j<HEIGHT;j++) {
|
||||||
if (i<numberImg.getWidth() &&
|
if (i<numberImg.getWidth() &&
|
||||||
@ -186,7 +186,7 @@ public class TypeFace {
|
|||||||
state=0;
|
state=0;
|
||||||
if (DEBUG_IMG) {
|
if (DEBUG_IMG) {
|
||||||
try {
|
try {
|
||||||
BufferedImage img2 = ImageUtils.copyBufferedImage(img);
|
BufferedImage img2 = ImageUtils.toCompatibleImage(ImageUtils.copyBufferedImage(img));
|
||||||
img2.setRGB(X, midY, Color.RED.getRGB());
|
img2.setRGB(X, midY, Color.RED.getRGB());
|
||||||
ImageIO.write(img2,"png",new File("stage4_"+System.currentTimeMillis()+".png"));
|
ImageIO.write(img2,"png",new File("stage4_"+System.currentTimeMillis()+".png"));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -327,8 +327,8 @@ public class TypeFace {
|
|||||||
finalWidth+= offsetX*2;
|
finalWidth+= offsetX*2;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
BufferedImage bufferedImage = new BufferedImage(finalWidth, finalHeight,
|
BufferedImage bufferedImage = ImageUtils.toCompatibleImage(new BufferedImage(finalWidth, finalHeight,
|
||||||
BufferedImage.TYPE_INT_RGB);
|
BufferedImage.TYPE_INT_RGB));
|
||||||
Graphics2D graphics = bufferedImage.createGraphics();
|
Graphics2D graphics = bufferedImage.createGraphics();
|
||||||
graphics.setPaint ( new Color ( 255, 255, 255 ) );
|
graphics.setPaint ( new Color ( 255, 255, 255 ) );
|
||||||
graphics.fillRect ( 0, 0, bufferedImage.getWidth(), bufferedImage.getHeight() );
|
graphics.fillRect ( 0, 0, bufferedImage.getWidth(), bufferedImage.getHeight() );
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package sig.utils;
|
package sig.utils;
|
||||||
|
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.GraphicsConfiguration;
|
||||||
|
import java.awt.GraphicsEnvironment;
|
||||||
import java.awt.Image;
|
import java.awt.Image;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
@ -12,6 +14,34 @@ public class ImageUtils {
|
|||||||
* @param img The Image to be converted
|
* @param img The Image to be converted
|
||||||
* @return The converted BufferedImage
|
* @return The converted BufferedImage
|
||||||
*/
|
*/
|
||||||
|
public static BufferedImage toCompatibleImage(BufferedImage image)
|
||||||
|
{
|
||||||
|
// obtain the current system graphical settings
|
||||||
|
GraphicsConfiguration gfxConfig = GraphicsEnvironment.
|
||||||
|
getLocalGraphicsEnvironment().getDefaultScreenDevice().
|
||||||
|
getDefaultConfiguration();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if image is already compatible and optimized for current system
|
||||||
|
* settings, simply return it
|
||||||
|
*/
|
||||||
|
if (image.getColorModel().equals(gfxConfig.getColorModel()))
|
||||||
|
return image;
|
||||||
|
|
||||||
|
// image is not optimized, so create a new image that is
|
||||||
|
BufferedImage newImage = gfxConfig.createCompatibleImage(
|
||||||
|
image.getWidth(), image.getHeight(), image.getTransparency());
|
||||||
|
|
||||||
|
// get the graphics context of the new image to draw the old image on
|
||||||
|
Graphics2D g2d = newImage.createGraphics();
|
||||||
|
|
||||||
|
// actually draw the image and dispose of context no longer needed
|
||||||
|
g2d.drawImage(image, 0, 0, null);
|
||||||
|
g2d.dispose();
|
||||||
|
|
||||||
|
// return the new optimized image
|
||||||
|
return newImage;
|
||||||
|
}
|
||||||
public static BufferedImage toBufferedImage(Image img)
|
public static BufferedImage toBufferedImage(Image img)
|
||||||
{
|
{
|
||||||
if (img instanceof BufferedImage)
|
if (img instanceof BufferedImage)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user