// Path: Scalable_WM/src/Result/ImperceptibilityResult.java
// public class ImperceptibilityResult {
//     public void ImperceptibilityResult(String fileName, String wmVidName){
//         ReadParameter parameter = new ReadParameter();
//         VidRead read = new VidRead();
//         ErrorCalculation error = new ErrorCalculation();
//         
//         double RMSError, PSNR, tempRMS = 0, tempPSNR = 0;        
//         for(int offset=0; offset<parameter.getNumFrame(); offset++){
//             //Read original video
//             read.VidRead(parameter.getInName(),offset);
//             double[][] Yoriginal = read.getYpixel();
// 
//             //Read watermarked video
//             //read.VidRead(parameter.getOutName(),offset);
//             read.VidRead(wmVidName,offset);
//             double[][] Ywatermarked = read.getYpixel();
// 
//             //Calculate RMS Error
//             RMSError = error.RmsError(Yoriginal,Ywatermarked);
//             PSNR = error.PSNR(Yoriginal,Ywatermarked);
// 
//             tempRMS += RMSError;
//             tempPSNR += PSNR;
//             //Write down RMS and PSNR Value in a file to store
//             saveStatFile(fileName, RMSError, PSNR, offset);
//         }//End of rms value read
// 
//         double averageRMS = tempRMS / parameter.getNumFrame();
//         double averagePSNR = tempPSNR / parameter.getNumFrame();
//         saveStatFile(fileName, averageRMS, averagePSNR, -1);
//     }
// 
//     public void saveStatFile(String FileName, double RMSE, double PSNR, int ind){ //Function to save PSNR and RMS value inside the file
//         FileOutputStream coeffOutFile;
//         String outFileString;
// 
//         outFileString = FileName.substring(0,FileName.length()-4) + "_Stat.txt";
// 
//         try
//         {
//             // Open an output stream
//             if(ind==0){
//                 coeffOutFile = new FileOutputStream (outFileString);
//             } else{
//                 coeffOutFile = new FileOutputStream (outFileString,true);
//             }
//            
//             new PrintStream(coeffOutFile).println (+ ind + " " + RMSE + " # " + PSNR);
//             
//           // Close our output stream
// 	    coeffOutFile.close();
//         }
//         // Catches any error conditions
//         catch (IOException e)
//         {
//             JOptionPane.showMessageDialog(null,"Unable to write to file");
//             System.exit(-1);
//         }
//     }
// }
// 
// Path: Scalable_WM/src/Watermark/Watermark.java
// public class Watermark {
//     static int[] watermark;
//     static int[] watermarkSize;
//     
//     // Do the watermark pixel conversion.
//     // read only PGM images 
//     public void Watermark() {
//         Imread image = new Imread();
//         ReadParameter para = new ReadParameter();
//         
//         // Get the watermark name from parameter file
//            
//       //  System.out.println(para.getWatermarkName());
//         //Read PGM file
//         double[][] watermark2D = image.Imread(para.getWatermarkName());     
//         watermarkSize = image.Size();
//         
//         watermark = new int[watermarkSize[0]*watermarkSize[1]];
//         
//         /*Convert the 2D image into 1D and convert 
//          *  the gray scale image into binary form by threshold of 127
//         `*/
//         for(int i=0;i<watermarkSize[0];i++){
//             for(int j=0;j<watermarkSize[1];j++){
//                 if(watermark2D[i][j]>127){
//                     watermark[i*watermarkSize[0] + j] = 1;
//                 } else{
//                     watermark[i*watermarkSize[0] + j] = 0;
//                 } //End of if-else
//             } // End of inner loop
//         } // End of outer loop
//     } // End of function
//     
//     public int[] getWatermark(){
//         return watermark;
//     }
//     
//     public int[] getWatermarkSize(){
//         return watermarkSize;
//     }
//     
// } // End of watermark class


import Main.*;
import Wavelet.*;
import MCTF.*;
import Result.ImperceptibilityResult;
import Watermark.Watermark;
import java.io.*;
                        mvTempFileName = outVideoWv1.substring(0, outVideoWv1.length()-4) + ".mv";
                    } else{
                        outTempVideoName = param.getInName().substring(0, param.getInName().length()-4) + "_0" + (i-1) + "t.tmp";
                        mvTempFileName = param.getInName().substring(0, param.getInName().length()-4) + "_0" + (i-1) + "t.mv";
                    }
                    MCTFinVideoName = param.getInName().substring(0, param.getInName().length()-4) + "_0" + i + "t.tmp";

                    mctfRecon.MCTFrecon(MCTFinVideoName, outTempVideoName, mvTempFileName, tSize, orgSize, i);

                    System.out.println("--------------------------------------");
                    System.out.println("Level " + i + " temporal filter synthesis done. ");
                    System.out.println("--------------------------------------");

                    if(i>=1 && i<=tLevel){
                        DeleteFile(param.getInName().substring(0, param.getInName().length()-4) + "_0" + i + "t.tmp");
                    }
                }

                //----------------------------------------------------------------
                //-- 1st 2D synthesis
                //----------------------------------------------------------------
                System.out.println("1st 2D synthesis in progress... Total no of level: " + wv1Level);
                roundControl = 0; // Round control release for final result
          //      wmVidName = param.getInName().substring(0, param.getInName().length()-4) + "_" + tSubband[tempSubChoice] + "_" + subband[subChoice] + "_" + param.getEmbedProcedure() + ".yuv";
                recon.WaveletSyn(outVideoWv1, wmVidName, wv1size, orgSize, wv1Level, 1);
                DeleteFile(outVideoWv1);

                //----------------------------------------------------------------

                //Calculate statistics
// Path: Scalable_WM/src/Result/ImperceptibilityResult.java
// public class ImperceptibilityResult {
//     public void ImperceptibilityResult(String fileName, String wmVidName){
//         ReadParameter parameter = new ReadParameter();
//         VidRead read = new VidRead();
//         ErrorCalculation error = new ErrorCalculation();
//         
//         double RMSError, PSNR, tempRMS = 0, tempPSNR = 0;        
//         for(int offset=0; offset<parameter.getNumFrame(); offset++){
//             //Read original video
//             read.VidRead(parameter.getInName(),offset);
//             double[][] Yoriginal = read.getYpixel();
// 
//             //Read watermarked video
//             //read.VidRead(parameter.getOutName(),offset);
//             read.VidRead(wmVidName,offset);
//             double[][] Ywatermarked = read.getYpixel();
// 
//             //Calculate RMS Error
//             RMSError = error.RmsError(Yoriginal,Ywatermarked);
//             PSNR = error.PSNR(Yoriginal,Ywatermarked);
// 
//             tempRMS += RMSError;
//             tempPSNR += PSNR;
//             //Write down RMS and PSNR Value in a file to store
//             saveStatFile(fileName, RMSError, PSNR, offset);
//         }//End of rms value read
// 
//         double averageRMS = tempRMS / parameter.getNumFrame();
//         double averagePSNR = tempPSNR / parameter.getNumFrame();
//         saveStatFile(fileName, averageRMS, averagePSNR, -1);
//     }
// 
//     public void saveStatFile(String FileName, double RMSE, double PSNR, int ind){ //Function to save PSNR and RMS value inside the file
//         FileOutputStream coeffOutFile;
//         String outFileString;
// 
//         outFileString = FileName.substring(0,FileName.length()-4) + "_Stat.txt";
// 
//         try
//         {
//             // Open an output stream
//             if(ind==0){
//                 coeffOutFile = new FileOutputStream (outFileString);
//             } else{
//                 coeffOutFile = new FileOutputStream (outFileString,true);
//             }
//            
//             new PrintStream(coeffOutFile).println (+ ind + " " + RMSE + " # " + PSNR);
//             
//           // Close our output stream
// 	    coeffOutFile.close();
//         }
//         // Catches any error conditions
//         catch (IOException e)
//         {
//             JOptionPane.showMessageDialog(null,"Unable to write to file");
//             System.exit(-1);
//         }
//     }
// }
// 
// Path: Scalable_WM/src/Watermark/Watermark.java
// public class Watermark {
//     static int[] watermark;
//     static int[] watermarkSize;
//     
//     // Do the watermark pixel conversion.
//     // read only PGM images 
//     public void Watermark() {
//         Imread image = new Imread();
//         ReadParameter para = new ReadParameter();
//         
//         // Get the watermark name from parameter file
//            
//       //  System.out.println(para.getWatermarkName());
//         //Read PGM file
//         double[][] watermark2D = image.Imread(para.getWatermarkName());     
//         watermarkSize = image.Size();
//         
//         watermark = new int[watermarkSize[0]*watermarkSize[1]];
//         
//         /*Convert the 2D image into 1D and convert 
//          *  the gray scale image into binary form by threshold of 127
//         `*/
//         for(int i=0;i<watermarkSize[0];i++){
//             for(int j=0;j<watermarkSize[1];j++){
//                 if(watermark2D[i][j]>127){
//                     watermark[i*watermarkSize[0] + j] = 1;
//                 } else{
//                     watermark[i*watermarkSize[0] + j] = 0;
//                 } //End of if-else
//             } // End of inner loop
//         } // End of outer loop
//     } // End of function
//     
//     public int[] getWatermark(){
//         return watermark;
//     }
//     
//     public int[] getWatermarkSize(){
//         return watermarkSize;
//     }
//     
// } // End of watermark class


// Path: Scalable_WM/src/Embedding/preProcessEmbed.java
import Main.*;
import Wavelet.*;
import MCTF.*;
import Result.ImperceptibilityResult;
import Watermark.Watermark;
import java.io.*;

                        mvTempFileName = outVideoWv1.substring(0, outVideoWv1.length()-4) + ".mv";
                    } else{
                        outTempVideoName = param.getInName().substring(0, param.getInName().length()-4) + "_0" + (i-1) + "t.tmp";
                        mvTempFileName = param.getInName().substring(0, param.getInName().length()-4) + "_0" + (i-1) + "t.mv";
                    }
                    MCTFinVideoName = param.getInName().substring(0, param.getInName().length()-4) + "_0" + i + "t.tmp";

                    mctfRecon.MCTFrecon(MCTFinVideoName, outTempVideoName, mvTempFileName, tSize, orgSize, i);

                    System.out.println("--------------------------------------");
                    System.out.println("Level " + i + " temporal filter synthesis done. ");
                    System.out.println("--------------------------------------");

                    if(i>=1 && i<=tLevel){
                        DeleteFile(param.getInName().substring(0, param.getInName().length()-4) + "_0" + i + "t.tmp");
                    }
                }

                //----------------------------------------------------------------
                //-- 1st 2D synthesis
                //----------------------------------------------------------------
                System.out.println("1st 2D synthesis in progress... Total no of level: " + wv1Level);
                roundControl = 0; // Round control release for final result
          //      wmVidName = param.getInName().substring(0, param.getInName().length()-4) + "_" + tSubband[tempSubChoice] + "_" + subband[subChoice] + "_" + param.getEmbedProcedure() + ".yuv";
                recon.WaveletSyn(outVideoWv1, wmVidName, wv1size, orgSize, wv1Level, 1);
                DeleteFile(outVideoWv1);

                //----------------------------------------------------------------

                //Calculate statistics
                stat.ImperceptibilityResult(wmVidName, wmVidName); //Pos1=Stat File name, Pos2=Wm video name;