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 static final String versionString = "Alpha-0.1";
public static final String versionString = "Alpha-0.21";
private static final String outputName = "Output";
private static final int gridX = 100, gridY = 100, targetMulti = 4,
@ -20,13 +20,13 @@ public class Mosaic {
adaptionCount = 300;
private static final double adaptionStep = 1.1, gridErrorThresh = 0.15;
/*
*
* TODO improve performance during closest match search. -> Loads ALOT of images
* FIX:
* 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
*
* Feature:
* TODO explore keeping Input Image Ratio's
* TODO explore guarantee of usage of at least once, each image.
*/
public FileHandler fh;
@ -51,7 +51,10 @@ public class Mosaic {
//
//Preparing Setup
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 ...");
int count = 0;
for(String path: fileList){
@ -66,6 +69,10 @@ public class Mosaic {
}
Log.log(LogLevel.Info, "Finished classification. Index is ready for production. Reloading index ...");
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, "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.OutputFolder = new File(sourceFolder.getAbsolutePath()+fs+"Output");
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 == "\\"){
Log.log(LogLevel.Debug, "Assumed Windows like Folder declaration. Therefore using "+fs+" as a separator.");
}else{
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(){
@ -56,32 +63,32 @@ public class FileHandler {
Log.log(LogLevel.Debug, "Detected Input folder at "+this.InputImagesFolder.getAbsolutePath());
if(this.OutputFolder.isDirectory()){
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{
Log.log(LogLevel.Info, "No Output folder found.");
Log.log(LogLevel.Info, "Creating one at "+this.OutputFolder.getAbsolutePath());
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{
Log.log(LogLevel.Critical, "No Input folder found.");
Log.log(LogLevel.Critical, "Creating one at "+this.InputImagesFolder.getAbsolutePath());
this.InputImagesFolder.mkdirs();
}
}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());
this.sourceFolder.mkdirs();
}
@ -123,6 +130,7 @@ public class FileHandler {
public void saveImage(BufferedImage img, File file){
Log.log(LogLevel.Info, "Saving image as file "+file.getAbsolutePath());
Log.log(LogLevel.Info, "This could take a moment ...");
try {
ImageIO.write(img, "png", file);
} catch (IOException e) {

@ -5,19 +5,33 @@ import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import peery.file.FileHandler;
public class Log {
public static Log log;
public static final boolean silenceDebug = false,
public static final boolean silenceDebug = true,
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;
private BufferedWriter eventWriter, errorWriter;
public Log(String location){
this.eventFile = new File(location+"/eventLog.log");
this.errorFile = new File(location+"/ERROR.log");
public Log(String location, FileHandler fh){
this.location = location;
this.eventFile = new File(location+fh.fs+"eventLog.log");
this.errorFile = new File(location+fh.fs+"ERROR.log");
try {
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){
return;
}
Log.log = new Log(location);
Log.log = new Log(location, fh);
}
public static void shutdownLog(){
@ -90,6 +104,19 @@ public class Log {
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){
Log.initLog("/home/peery/Software_Projects/EclipseWorkspace/Picture Mosaic/resources/");

@ -105,7 +105,7 @@ public class ImageAnalyzer {
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>();
for(String key: metrics.keySet()){
@ -179,7 +179,7 @@ public class ImageAnalyzer {
green = green/pixels;
blue = blue/pixels;
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);
return rgb;
}

Loading…
Cancel
Save