www.gusucode.com > 基于dwt的视频数字水印源代码 > 基于dwt的视频数字水印源代码\code\HaYDWT\PSNRVideo.cpp

    //Download by http://www.NewXing.com
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "PSNRVideo.h"
#include "Common.h"
#include "FileServices.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "RzButton"
#pragma link "RzEdit"
#pragma link "RzPanel"
#pragma link "RzRadChk"
#pragma link "RzPrgres"
#pragma resource "*.dfm"
TFormPSNRVideo *FormPSNRVideo;
//---------------------------------------------------------------------------
__fastcall TFormPSNRVideo::TFormPSNRVideo(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TFormPSNRVideo::ButtonInputFileClick(TObject *Sender)
{
    OpenDialog->Filter = "Supported Video Files|*.avi;*.cif;*.qcif;*.cif_g;*.qcif_g|CIF Format 352x288|*.cif|QCIF Format 176x144|*.qcif|AVI Files|*.avi|All Files|*.*";
    OpenDialog->FilterIndex = 0;
    OpenDialog->FileName = sVideo1;
    OpenDialog->Options <<  ofPathMustExist << ofFileMustExist;
    if (OpenDialog->Execute())
    {
        sVideo1 = OpenDialog->FileName;
        EditVideo1->Text = sVideo1;
    }
}
//---------------------------------------------------------------------------
void __fastcall TFormPSNRVideo::ButtonOutputFileClick(TObject *Sender)
{
    OpenDialog->Filter = "Supported Video Files|*.avi;*.cif;*.qcif;*.cif_g;*.qcif_g|CIF Format 352x288|*.cif|QCIF Format 176x144|*.qcif|AVI Files|*.avi|All Files|*.*";
    OpenDialog->FilterIndex = 0;
    OpenDialog->FileName = sVideo2;
    OpenDialog->Options <<  ofPathMustExist << ofFileMustExist;
    if (OpenDialog->Execute())
    {
        sVideo2 = OpenDialog->FileName;
        EditVideo2->Text = sVideo2;
    }

}
//---------------------------------------------------------------------------
void __fastcall TFormPSNRVideo::ButtonSaveTextClick(TObject *Sender)
{
    SaveDialog->Filter = "txt Files|*.txt|All Files|*.*";
    SaveDialog->DefaultExt = ".txt";
    SaveDialog->FileName = sText;
    SaveDialog->FilterIndex = 0;
    SaveDialog->Options << ofOverwritePrompt << ofPathMustExist;
    if (SaveDialog->Execute())
    {
        sText = SaveDialog->FileName;
        EditSaveText->Text = sText;
    }
}
//---------------------------------------------------------------------------
void __fastcall TFormPSNRVideo::RadioButtonAllFramesClick(TObject *Sender)
{
    if(RadioButtonAllFrames->Checked)
    {
        ButtonSaveText->Enabled = true;
        AllFrames = true;
    }

//
}
//---------------------------------------------------------------------------
void __fastcall TFormPSNRVideo::RadioButtonOneFrameClick(TObject *Sender)
{
    if (RadioButtonOneFrame->Checked)
    {
        ButtonSaveText->Enabled = false;
        AllFrames = false;
    }
}
//---------------------------------------------------------------------------
void __fastcall TFormPSNRVideo::EditFrameNoChange(TObject *Sender)
{
    FrameNo = (long)EditFrameNo->Value;
}
//---------------------------------------------------------------------------
void __fastcall TFormPSNRVideo::FormCreate(TObject *Sender)
{

    AllFrames = false;
    cancelPSNR = false;

}
//---------------------------------------------------------------------------
void __fastcall TFormPSNRVideo::ButtonPSNRClick(TObject *Sender)
{
    double PSNR;
    AnsiString str, sEx1, sEx2;

    sEx1 = UpperCase(ExtractFileExt(sVideo1));
    sEx2 = UpperCase(ExtractFileExt(sVideo2));
    if ((AllFrames) && (sText.Length() < 3))
    {
        MessageDlg("Please select a text file name.", mtError, TMsgDlgButtons() << mbOK, 0);
        return;
    }
    if ((sEx1 == ".AVI") && (sEx2 == ".AVI"))
    {
        if (AllFrames)
        {
            cancelPSNR = false;
            ButtonPSNR->Enabled = false;
            ButtonCancel->Enabled = true;
            Video_PSNR( sVideo1.c_str(),sVideo2.c_str(), sText.c_str(), true, 0, 0);
        }
        else
        {
            PSNR = Video_PSNR( sVideo1.c_str(),sVideo2.c_str(), sText.c_str(), false, FrameNo, 0);
            if ( PSNR >= 0.0)
            {
                str.sprintf("%3.2f", PSNR);
                str = "PSNR of the " + IntToStr(FrameNo) + ". frame is  " + str + " dB";
                MessageBox(this->Handle, str.c_str(), "PSNR Result", MB_ICONINFORMATION|MB_OK);
            }
        }
    }
    else if ((sEx1 == ".CIF") && (sEx2 == ".CIF"))
    {
        if (AllFrames)
        {
            cancelPSNR = false;
            ButtonPSNR->Enabled = false;
            ButtonCancel->Enabled = true;
            Video_PSNR( sVideo1.c_str(),sVideo2.c_str(), sText.c_str(), true, 0, 1);
        }
        else
        {
            PSNR = Video_PSNR( sVideo1.c_str(),sVideo2.c_str(), sText.c_str(), false, FrameNo, 1);
            if ( PSNR >= 0.0)
            {
                str.sprintf("%3.2f", PSNR);
                str = "PSNR of the " + IntToStr(FrameNo) + ". frame is  " + str + " dB";
                MessageBox(this->Handle, str.c_str(), "PSNR Result", MB_ICONINFORMATION|MB_OK);
            }
        }
    }
    else if ((sEx1 == ".QCIF") && (sEx2 == ".QCIF"))
    {
        if (AllFrames)
        {
            cancelPSNR = false;
            ButtonPSNR->Enabled = false;
            ButtonCancel->Enabled = true;
            Video_PSNR( sVideo1.c_str(),sVideo2.c_str(), sText.c_str(), true, 0, 2);
        }
        else
        {
            PSNR = Video_PSNR( sVideo1.c_str(),sVideo2.c_str(), sText.c_str(), false, FrameNo, 2);
            if ( PSNR >= 0.0)
            {
                str.sprintf("%3.2f", PSNR);
                str = "PSNR of the " + IntToStr(FrameNo) + ". frame is  " + str + " dB";
                MessageBox(this->Handle, str.c_str(), "PSNR Result", MB_ICONINFORMATION|MB_OK);
            }
        }
    }
    else if ((sEx1 == ".CIF") && (sEx2 == ".AVI"))
    {
        if (AllFrames)
        {
            cancelPSNR = false;
            ButtonPSNR->Enabled = false;
            ButtonCancel->Enabled = true;
            Video_PSNR( sVideo1.c_str(),sVideo2.c_str(), sText.c_str(), true, 0, 3);
        }
        else
        {
            PSNR = Video_PSNR( sVideo1.c_str(),sVideo2.c_str(), sText.c_str(), false, FrameNo, 3);
            if ( PSNR >= 0.0)
            {
                str.sprintf("%3.2f", PSNR);
                str = "PSNR of the " + IntToStr(FrameNo) + ". frame is  " + str + " dB";
                MessageBox(this->Handle, str.c_str(), "PSNR Result", MB_ICONINFORMATION|MB_OK);
            }
        }
    }
    else if ((sEx1 == ".AVI") && (sEx2 == ".CIF"))
    {
        if (AllFrames)
        {
            cancelPSNR = false;
            ButtonPSNR->Enabled = false;
            ButtonCancel->Enabled = true;
            Video_PSNR( sVideo1.c_str(),sVideo2.c_str(), sText.c_str(), true, 0, 4);
        }
        else
        {
            PSNR = Video_PSNR( sVideo1.c_str(),sVideo2.c_str(), sText.c_str(), false, FrameNo, 4);
            if ( PSNR >= 0.0)
            {
                str.sprintf("%3.2f", PSNR);
                str = "PSNR of the " + IntToStr(FrameNo) + ". frame is  " + str + " dB";
                MessageBox(this->Handle, str.c_str(), "PSNR Result", MB_ICONINFORMATION|MB_OK);
            }
        }
    }
    else if ((sEx1 == ".QCIF") && (sEx2 == ".AVI"))
    {
        if (AllFrames)
        {
            cancelPSNR = false;
            ButtonPSNR->Enabled = false;
            ButtonCancel->Enabled = true;
            Video_PSNR( sVideo1.c_str(),sVideo2.c_str(), sText.c_str(), true, 0, 5);
        }
        else
        {
            PSNR = Video_PSNR( sVideo1.c_str(),sVideo2.c_str(), sText.c_str(), false, FrameNo, 5);
            if ( PSNR >= 0.0)
            {
                str.sprintf("%3.2f", PSNR);
                str = "PSNR of the " + IntToStr(FrameNo) + ". frame is  " + str + " dB";
                MessageBox(this->Handle, str.c_str(), "PSNR Result", MB_ICONINFORMATION|MB_OK);
            }
        }
    }
    else if ((sEx1 == ".AVI") && (sEx2 == ".QCIF"))
    {
        if (AllFrames)
        {
            cancelPSNR = false;
            ButtonPSNR->Enabled = false;
            ButtonCancel->Enabled = true;
            Video_PSNR( sVideo1.c_str(),sVideo2.c_str(), sText.c_str(), true, 0, 6);
        }
        else
        {
            PSNR = Video_PSNR( sVideo1.c_str(),sVideo2.c_str(), sText.c_str(), false, FrameNo, 6);
            if ( PSNR >= 0.0)
            {
                str.sprintf("%3.2f", PSNR);
                str = "PSNR of the " + IntToStr(FrameNo) + ". frame is  " + str + " dB";
                MessageBox(this->Handle, str.c_str(), "PSNR Result", MB_ICONINFORMATION|MB_OK);
            }
        }
    }
    else
    {
        MessageDlg("This video format is not supported.", mtError, TMsgDlgButtons() << mbOK, 0);
        return;
    }

}
//---------------------------------------------------------------------------
void __fastcall TFormPSNRVideo::ButtonCancelClick(TObject *Sender)
{
    cancelPSNR = true;
}
//---------------------------------------------------------------------------