Fixed bugs and added ReadMe

fixed some Bugs including non-existing Folders or Files.
Added ReadMe for clarity. Spawns when folder verification failed.
dev
Peery 7 years ago
parent 9152b37c9f
commit f5a4438867

@ -12,7 +12,7 @@ import peery.picture.ImageAnalyzer;
public class Mosaic { public class Mosaic {
public static final String versionString = "Alpha-0.1"; public static final String versionString = "Alpha-0.21";
private static final String outputName = "Output"; private static final String outputName = "Output";
private static final int gridX = 100, gridY = 100, targetMulti = 4, private static final int gridX = 100, gridY = 100, targetMulti = 4,
@ -20,13 +20,13 @@ public class Mosaic {
adaptionCount = 300; adaptionCount = 300;
private static final double adaptionStep = 1.1, gridErrorThresh = 0.15; private static final double adaptionStep = 1.1, gridErrorThresh = 0.15;
/* /*
* * FIX:
* TODO improve performance during closest match search. -> Loads ALOT of images
* TODO investigate picture stretching -> is ImageUtils.resizeImage() even used? * TODO investigate picture stretching -> is ImageUtils.resizeImage() even used?
* TODO investigate why so few slots are actually present, I specified way more! <---
*
*
* TODO alphaThreshhold is currently dead * TODO alphaThreshhold is currently dead
*
* Feature:
* TODO explore keeping Input Image Ratio's
* TODO explore guarantee of usage of at least once, each image.
*/ */
public FileHandler fh; public FileHandler fh;
@ -51,7 +51,10 @@ public class Mosaic {
// //
//Preparing Setup //Preparing Setup
ArrayList<String> fileList = fh.listInputFiles(); ArrayList<String> fileList = fh.listInputFiles();
if(fileList.size() == 0){
Log.log(LogLevel.Error, "No files in Input folder! There NEED to be at least some Images! Exiting...");
System.exit(1);
}
Log.log(LogLevel.Info, "Starting classification of Input now ..."); Log.log(LogLevel.Info, "Starting classification of Input now ...");
int count = 0; int count = 0;
for(String path: fileList){ for(String path: fileList){
@ -66,6 +69,10 @@ public class Mosaic {
} }
Log.log(LogLevel.Info, "Finished classification. Index is ready for production. Reloading index ..."); Log.log(LogLevel.Info, "Finished classification. Index is ready for production. Reloading index ...");
index = fh.loadIndex(); index = fh.loadIndex();
if(index == null){
Log.log(LogLevel.Error, "No index after Classification of Input! Can't continue! Exiting...");
System.exit(1);
}
Log.log(LogLevel.Debug, "Canvas is "+ia.canvas.getWidth()+"x"+ia.canvas.getHeight()+" big."); Log.log(LogLevel.Debug, "Canvas is "+ia.canvas.getWidth()+"x"+ia.canvas.getHeight()+" big.");
Log.log(LogLevel.Debug, "Grid will span "+ia.slotWidth*gridX+"x"+ia.slotHeight*gridY+" ."); Log.log(LogLevel.Debug, "Grid will span "+ia.slotWidth*gridX+"x"+ia.slotHeight*gridY+" .");

@ -40,13 +40,20 @@ public class FileHandler {
this.TargetImageFile = new File(sourceFolder.getAbsolutePath()+fs+"Target"); this.TargetImageFile = new File(sourceFolder.getAbsolutePath()+fs+"Target");
this.OutputFolder = new File(sourceFolder.getAbsolutePath()+fs+"Output"); this.OutputFolder = new File(sourceFolder.getAbsolutePath()+fs+"Output");
this.indexFile = new File(this.InputImagesFolder.getAbsolutePath()+"Index.txt"); this.indexFile = new File(this.InputImagesFolder.getAbsolutePath()+"Index.txt");
Log.initLog(this.sourceFolder.getAbsolutePath()); if(!this.sourceFolder.exists()){
this.sourceFolder.mkdirs();
}
Log.initLog(this.sourceFolder.getAbsolutePath(), this);
if(fs == "\\"){ if(fs == "\\"){
Log.log(LogLevel.Debug, "Assumed Windows like Folder declaration. Therefore using "+fs+" as a separator."); Log.log(LogLevel.Debug, "Assumed Windows like Folder declaration. Therefore using "+fs+" as a separator.");
}else{ }else{
Log.log(LogLevel.Debug, "Detected Linux or OSX."); Log.log(LogLevel.Debug, "Detected Linux or OSX.");
} }
this.validateFolderStructure(); if(!this.validateFolderStructure()){
Log.log(LogLevel.Error, "Could not validate folder structure! Things are missing!");
Log.spawnReadMe(this);
System.exit(1);
}
} }
public boolean validateFolderStructure(){ public boolean validateFolderStructure(){
@ -56,32 +63,32 @@ public class FileHandler {
Log.log(LogLevel.Debug, "Detected Input folder at "+this.InputImagesFolder.getAbsolutePath()); Log.log(LogLevel.Debug, "Detected Input folder at "+this.InputImagesFolder.getAbsolutePath());
if(this.OutputFolder.isDirectory()){ if(this.OutputFolder.isDirectory()){
Log.log(LogLevel.Debug, "Detected Output folder at "+this.OutputFolder.getAbsolutePath()); Log.log(LogLevel.Debug, "Detected Output folder at "+this.OutputFolder.getAbsolutePath());
if(this.TargetImageFile.isFile()){
Log.log(LogLevel.Debug, "Detected Target Image at "+this.TargetImageFile.getAbsolutePath());
if(!this.indexFile.isDirectory()){
Log.log(LogLevel.Debug, "Found no directory blocking the index file.");
return true;
}
else{
Log.log(LogLevel.Error, "Following folder collides with the index file name: "+this.indexFile.getAbsolutePath());
System.exit(1);
}
}else{
Log.log(LogLevel.Critical, "No Target Image found! Exiting...");
System.exit(1);
}
}else{ }else{
Log.log(LogLevel.Info, "No Output folder found."); Log.log(LogLevel.Info, "No Output folder found.");
Log.log(LogLevel.Info, "Creating one at "+this.OutputFolder.getAbsolutePath()); Log.log(LogLevel.Info, "Creating one at "+this.OutputFolder.getAbsolutePath());
this.OutputFolder.mkdirs(); this.OutputFolder.mkdirs();
} }
if(this.TargetImageFile.isFile()){
Log.log(LogLevel.Debug, "Detected Target Image at "+this.TargetImageFile.getAbsolutePath());
if(!this.indexFile.isDirectory()){
Log.log(LogLevel.Debug, "Found no directory blocking the index file.");
return true;
}
else{
Log.log(LogLevel.Error, "Following folder collides with the index file name: "+this.indexFile.getAbsolutePath());
return false;
}
}else{
Log.log(LogLevel.Critical, "No Target Image found! Exiting...");
return false;
}
}else{ }else{
Log.log(LogLevel.Critical, "No Input folder found."); Log.log(LogLevel.Critical, "No Input folder found.");
Log.log(LogLevel.Critical, "Creating one at "+this.InputImagesFolder.getAbsolutePath()); Log.log(LogLevel.Critical, "Creating one at "+this.InputImagesFolder.getAbsolutePath());
this.InputImagesFolder.mkdirs(); this.InputImagesFolder.mkdirs();
} }
}else{ }else{
Log.log(LogLevel.Critical, "No source folder found."); Log.log(LogLevel.Critical, "No source folder found (redundant check).");
Log.log(LogLevel.Critical, "Creating one at "+this.sourceFolder.getAbsolutePath()); Log.log(LogLevel.Critical, "Creating one at "+this.sourceFolder.getAbsolutePath());
this.sourceFolder.mkdirs(); this.sourceFolder.mkdirs();
} }
@ -123,6 +130,7 @@ public class FileHandler {
public void saveImage(BufferedImage img, File file){ public void saveImage(BufferedImage img, File file){
Log.log(LogLevel.Info, "Saving image as file "+file.getAbsolutePath()); Log.log(LogLevel.Info, "Saving image as file "+file.getAbsolutePath());
Log.log(LogLevel.Info, "This could take a moment ...");
try { try {
ImageIO.write(img, "png", file); ImageIO.write(img, "png", file);
} catch (IOException e) { } catch (IOException e) {

@ -5,19 +5,33 @@ import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import peery.file.FileHandler;
public class Log { public class Log {
public static Log log; public static Log log;
public static final boolean silenceDebug = false, public static final boolean silenceDebug = true,
appendEvents = false, appendErrors = false; appendEvents = false, appendErrors = false;
private final static String readmeText =
"This is the ReadMe for Mosaic.\n"
+ "The folders that were created serve following purpose: \n"
+ "resources - Is the main folder where all images (Input AND Output are stored). \n"
+ "resources%sImages - Is the Input folder for all images you want to use as \"paint\" in the Mosaic. Put all your images in there!\n"
+ "resources%sOutput - Stores all resulting Mosaic pictures. There are all named Output-{number}.png \n"
+ "resources%sTarget - Is an Image (or symbolic Link to one) of your choice. Mosaic will try to create the mosaic after this inspiration. The name MUST be \"Target\" without any file extension or it will not be recognized."
+ "resources%sERROR.log - Is a log file where all non-fatal erros are stored. Take a peek if problems occur. \n"
+ "resources%seventLog.log - Is a log for more genereal events. Like progress, events and such with time stamps. Most useful for debugging problems.";
private String location;
public final File eventFile, errorFile; public final File eventFile, errorFile;
private BufferedWriter eventWriter, errorWriter; private BufferedWriter eventWriter, errorWriter;
public Log(String location){ public Log(String location, FileHandler fh){
this.eventFile = new File(location+"/eventLog.log"); this.location = location;
this.errorFile = new File(location+"/ERROR.log"); this.eventFile = new File(location+fh.fs+"eventLog.log");
this.errorFile = new File(location+fh.fs+"ERROR.log");
try { try {
if(!this.eventFile.exists()){ if(!this.eventFile.exists()){
@ -34,12 +48,12 @@ public class Log {
} }
} }
public static void initLog(String location){ public static void initLog(String location, FileHandler fh){
if(Log.log != null){ if(Log.log != null){
return; return;
} }
Log.log = new Log(location); Log.log = new Log(location, fh);
} }
public static void shutdownLog(){ public static void shutdownLog(){
@ -90,6 +104,19 @@ public class Log {
e.printStackTrace(); e.printStackTrace();
} }
} }
public static void spawnReadMe(FileHandler fh){
File readme = new File(Log.log.location+fh.fs+"README.txt");
Log.log(LogLevel.Info, "Spawning README file at "+readme.getAbsolutePath());
try {
BufferedWriter bw = new BufferedWriter(new FileWriter(readme));
String rdme = readmeText.replaceAll("%s", fh.fs);
bw.write(rdme);
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
/* /*
public static void main(String[] args){ public static void main(String[] args){
Log.initLog("/home/peery/Software_Projects/EclipseWorkspace/Picture Mosaic/resources/"); Log.initLog("/home/peery/Software_Projects/EclipseWorkspace/Picture Mosaic/resources/");

@ -105,7 +105,7 @@ public class ImageAnalyzer {
currBest = metric; currBest = metric;
} }
} }
Log.log(LogLevel.Info, "Calculated all metrics for rgb:"+rgb+" !"); Log.log(LogLevel.Debug, "Calculated all metrics for rgb:"+rgb+" !");
HashMap<String, Integer> matches = new HashMap<String, Integer>(); HashMap<String, Integer> matches = new HashMap<String, Integer>();
for(String key: metrics.keySet()){ for(String key: metrics.keySet()){
@ -179,7 +179,7 @@ public class ImageAnalyzer {
green = green/pixels; green = green/pixels;
blue = blue/pixels; blue = blue/pixels;
int rgb = new Color((int)red, (int)green, (int)blue).getRGB(); int rgb = new Color((int)red, (int)green, (int)blue).getRGB();
Log.log(LogLevel.Info, "Classified "+file.getPath()+" with following rgb result: value:"+rgb+ Log.log(LogLevel.Debug, "Classified "+file.getPath()+" with following rgb result: value:"+rgb+
" red:"+red+", green:"+green+", blue:"+blue); " red:"+red+", green:"+green+", blue:"+blue);
return rgb; return rgb;
} }

Loading…
Cancel
Save