source: 3DVCSoftware/branches/HTM-4.0-dev0/source/Lib/TLibEncoder/TEncAnalyze.h @ 134

Last change on this file since 134 was 56, checked in by hschwarz, 13 years ago

updated trunk (move to HM6.1)

  • Property svn:eol-style set to native
File size: 5.2 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license. 
5 *
6 * Copyright (c) 2010-2012, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/** \file     TEncAnalyze.h
35    \brief    encoder analyzer class (header)
36*/
37
38#ifndef __TENCANALYZE__
39#define __TENCANALYZE__
40
41#if _MSC_VER > 1000
42#pragma once
43#endif // _MSC_VER > 1000
44
45#include <stdio.h>
46#include <memory.h>
47#include <assert.h>
48#include "TLibCommon/CommonDef.h"
49
50//! \ingroup TLibEncoder
51//! \{
52
53// ====================================================================================================================
54// Class definition
55// ====================================================================================================================
56
57/// encoder analyzer class
58class TEncAnalyze
59{
60private:
61  Double    m_dPSNRSumY;
62  Double    m_dPSNRSumU;
63  Double    m_dPSNRSumV;
64  Double    m_dAddBits;
65  UInt      m_uiNumPic;
66  Double    m_dFrmRate; //--CFG_KDY
67 
68public:
69  TEncAnalyze() { m_dPSNRSumY = m_dPSNRSumU = m_dPSNRSumV = m_dAddBits = m_uiNumPic = 0;  }
70  virtual ~TEncAnalyze()  {}
71 
72  Void  addResult( Double psnrY, Double psnrU, Double psnrV, Double bits)
73  {
74    m_dPSNRSumY += psnrY;
75    m_dPSNRSumU += psnrU;
76    m_dPSNRSumV += psnrV;
77    m_dAddBits  += bits;
78   
79    m_uiNumPic++;
80  }
81 
82  Double  getPsnrY()  { return  m_dPSNRSumY;  }
83  Double  getPsnrU()  { return  m_dPSNRSumU;  }
84  Double  getPsnrV()  { return  m_dPSNRSumV;  }
85  Double  getBits()   { return  m_dAddBits;   }
86  UInt    getNumPic() { return  m_uiNumPic;   }
87 
88  Void    setFrmRate  (Double dFrameRate) { m_dFrmRate = dFrameRate; } //--CFG_KDY
89  Void    clear() { m_dPSNRSumY = m_dPSNRSumU = m_dPSNRSumV = m_dAddBits = m_uiNumPic = 0;  }
90  Void    printOut ( Char cDelim )
91  {
92    Double dFps     =   m_dFrmRate; //--CFG_KDY
93    Double dScale   = dFps / 1000 / (Double)m_uiNumPic;
94   
95    printf( "\tTotal Frames |  "   "Bitrate    "  "Y-PSNR    "  "U-PSNR    "  "V-PSNR \n" );
96    //printf( "\t------------ "  " ----------"   " -------- "  " -------- "  " --------\n" );
97    printf( "\t %8d    %c"          "%12.4lf  "    "%8.4lf  "   "%8.4lf  "    "%8.4lf\n",
98           getNumPic(), cDelim,
99           getBits() * dScale,
100           getPsnrY() / (Double)getNumPic(),
101           getPsnrU() / (Double)getNumPic(),
102           getPsnrV() / (Double)getNumPic() );
103  }
104 
105  Void    printSummaryOut ()
106  {
107    FILE* pFile = fopen ("summaryTotal.txt", "at");
108    Double dFps     =   m_dFrmRate; //--CFG_KDY
109    Double dScale   = dFps / 1000 / (Double)m_uiNumPic;
110   
111    fprintf(pFile, "%f\t %f\t %f\t %f\n", getBits() * dScale,
112            getPsnrY() / (Double)getNumPic(),
113            getPsnrU() / (Double)getNumPic(),
114            getPsnrV() / (Double)getNumPic() );
115    fclose(pFile);
116  }
117 
118  Void    printSummary(Char ch)
119  {
120    FILE* pFile = NULL;
121   
122    switch( ch ) 
123    {
124      case 'I':
125        pFile = fopen ("summary_I.txt", "at");
126        break;
127      case 'P':
128        pFile = fopen ("summary_P.txt", "at");
129        break;
130      case 'B':
131        pFile = fopen ("summary_B.txt", "at");
132        break;
133      default:
134        assert(0);
135        return;
136        break;
137    }
138   
139    Double dFps     =   m_dFrmRate; //--CFG_KDY
140    Double dScale   = dFps / 1000 / (Double)m_uiNumPic;
141   
142    fprintf(pFile, "%f\t %f\t %f\t %f\n",
143            getBits() * dScale,
144            getPsnrY() / (Double)getNumPic(),
145            getPsnrU() / (Double)getNumPic(),
146            getPsnrV() / (Double)getNumPic() );
147   
148    fclose(pFile);
149  }
150};
151
152//! \}
153
154#endif // !defined(AFX_TENCANALYZE_H__C79BCAA2_6AC8_4175_A0FE_CF02F5829233__INCLUDED_)
Note: See TracBrowser for help on using the repository browser.