package mosaik;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

import javax.imageio.ImageIO;

import dataBase.DataBase;

import util.Timer;
import util.simpleIO.Out;

public class _RunMosaik_KRISI {

	static int partsX = 150;
	static int partsY = 150;
	static float resize = 1f;
	
	static File dbFile = _MakeDataBase_KRISI.dbFile;
//	static File dbFile = new File("D:/_testData_/DataBase1.db");
	
//	static File searchPicFile = new File("D:/_testData_/_big/_8147226.JPG");
//	static File searchPicFile = new File("D:/_testData_/_big/_8147228.JPG");		// Blume
//	static File searchPicFile = new File("D:/_testData_/_big/_8147233.JPG");		// Zaun
//	static File searchPicFile = new File("D:/_testData_/_big/_8147226.JPG");		// Aussicht 1
	static File searchPicFile = new File("./testdaten/big/Desert.jpg");			// Desert - 200x200
	
	static File target        = new File("./mosaikImage.png");
//	static File target        = new File("./mosaikImage_"+partsX+"_q"+MosaikConstants.MinNumberOfPicturesToSearch+"_.png");
	
	
	/**
	 * @param args
	 */
	public static void main(String[] args) throws IOException, ClassNotFoundException {
		
		Out.pl("Load DB:");
		Timer dbt = new Timer();
		DataBase db = MosaikFunctions.loadDatabase(dbFile);
		dbt.stop();
		
		run(searchPicFile, db, target, partsX, partsY, resize);
		
		Out.pl( "> Measured times:" );
		Out.pl("  DB loaded in        "+(float)(dbt.getMeasuredTime()/1000.0)+" sec.");
		Out.pl("  Mosaik generated in "+(float)(maket.getMeasuredTime()/1000.0)+" sec.");
//		Out.pl();
//		Out.pl("  Generate SubPicture    : " + MosaikConstants.subPictureGeneration.toStringNew() );
//		Out.pl("  Search for mosaik pic  : " + MosaikConstants.pictureSearch.toStringNew() );
//		Out.pl("  Load picture (buffered): " + MosaikConstants.pictureLoad.toStringNew() );
//		Out.pl("  Draw picture (g2d)     : " + MosaikConstants.pictureDraw.toStringNew() );
		
	}

	static Timer maket = new Timer();
	
	private static void run(File searchPicFile, DataBase db, File target, int partsX, int partsY, float resize) throws FileNotFoundException, ClassNotFoundException, IOException{
		
		maket.start();
		BufferedImage mosaikImage = MosaikFunctions.makeMosaik(searchPicFile, db, partsX, partsY, resize);
		maket.stop();
		
		ImageIO.write(mosaikImage, "png", target);
		//ImageIO.write(mosaikImage, "jpg", new File("mosaikImage.jpg"));
		//storeJPG(mosaikImage, new File("mosaikImage_4+.jpg"), 1);
		Out.pl("Finished.... File '"+target+"' saved"); 
	}
	
}

