00001 package testbench;
00002
00003 import java.io.BufferedReader;
00004 import java.io.File;
00005 import java.io.FileNotFoundException;
00006 import java.io.InputStream;
00007 import java.io.InputStreamReader;
00008
00009 import commandline.Encoder.Iterators.RateDistorion;
00010 import commandline.TxTPackage.DirectoryAndFileClass;
00011 import commandline.debuggingCode.Debug;
00012
00013
00014 public class JPEGcosRateDistortion extends RateDistorion {
00015
00016 public JPEGcosRateDistortion(File file, String path_to_original_fig,
00017 String path_to_out_dir) {
00018 super(file, path_to_original_fig, path_to_out_dir);
00019
00020 }
00021
00022 @Override
00023 protected String getCompressionType() {
00024 return "cosinus";
00025 }
00026
00027 @Override
00028 protected String getCompressionName() {
00029 return "JPG-compression";
00030 }
00031
00032 @Override
00033 protected void initType() {
00034 this.type="jpeg";
00035
00036 }
00037
00038 @Override
00039 public void makeRateDistortionFile() throws FileNotFoundException {
00040 super.makeRateDistortionFile("jpg","jpg");
00041
00042 }
00043
00044 public void createImages(float beginrate , float steprate, float endrate){
00045
00046 for(int quality=1;quality<=100;quality++){
00047 String command="cmd /c start convert -quality "+quality +" "+ path_to_original_fig + " jpg:"+path_to_out_dir+File.separator +""+quality+".jpg";
00048 Debug.print("batcommand = " + command);
00049 try{
00050 Runtime rt= Runtime.getRuntime();
00051 Process proc = rt.exec(command);
00052 InputStream stderr = proc.getErrorStream();
00053 InputStreamReader isr = new InputStreamReader(stderr);
00054 BufferedReader br = new BufferedReader(isr);
00055 String line = null;
00056 Debug.print("<ERROR>");
00057 while ( (line = br.readLine()) != null)
00058 Debug.print(line);
00059 Debug.print("</ERROR>");
00060 int exitVal = proc.waitFor();
00061 Debug.print("Process exitValue: " + exitVal);
00062 }catch (Throwable t)
00063 {
00064 t.printStackTrace();
00065 }
00066 }
00067 }
00068
00069
00070 public static void parameterPerform(String image_name, float beginrate,float eindrate) throws FileNotFoundException {
00071 String s=File.separator;
00072 String path_output_dir=Paths.pathToRateDistortionOutput+s+"jpg_"+image_name;
00073
00074 DirectoryAndFileClass.makeDir(path_output_dir);
00075
00076
00077
00078
00079 String path_original=Paths.getPathToImageDB()+File.separator+image_name+".pgm";
00080 Debug.print(path_original);
00081 Debug.print(path_output_dir);
00082
00083 JPEGcosRateDistortion rateDistortion=
00084 new JPEGcosRateDistortion(new File(Paths.pathToRateDistortionOutput+s+ image_name+"rate_distortion_jpg_.m"),path_original,path_output_dir);
00085 rateDistortion.createImages(-1,-1,-1);
00086 rateDistortion.makeRateDistortionFile();
00087 Debug.print("JPEGCosRATEDISTORTION- Job done. System will now exit.");
00088
00089
00090 }
00091
00092 }