source: 3DVCSoftware/branches/0.3-nokia/source/Lib/TLibEncoder/TEncAnalyze.h @ 36

Last change on this file since 36 was 5, checked in by hhi, 13 years ago

Clean version with cfg-files

  • Property svn:eol-style set to native
File size: 5.1 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-2011, 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 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
35
36/** \file     TEncAnalyze.h
37    \brief    encoder analyzer class (header)
38*/
39
40#ifndef __TENCANALYZE__
41#define __TENCANALYZE__
42
43#if _MSC_VER > 1000
44#pragma once
45#endif // _MSC_VER > 1000
46
47#include <stdio.h>
48#include <memory.h>
49#include <assert.h>
50#include "../TLibCommon/CommonDef.h"
51
52// ====================================================================================================================
53// Class definition
54// ====================================================================================================================
55
56/// encoder analyzer class
57class TEncAnalyze
58{
59private:
60  Double    m_dPSNRSumY;
61  Double    m_dPSNRSumU;
62  Double    m_dPSNRSumV;
63  Double    m_dAddBits;
64  UInt      m_uiNumPic;
65  Double    m_dFrmRate; //--CFG_KDY
66 
67public:
68  TEncAnalyze() { m_dPSNRSumY = m_dPSNRSumU = m_dPSNRSumV = m_dAddBits = m_uiNumPic = 0;  }
69  virtual ~TEncAnalyze()  {}
70 
71  Void  addResult( Double psnrY, Double psnrU, Double psnrV, Double bits)
72  {
73    m_dPSNRSumY += psnrY;
74    m_dPSNRSumU += psnrU;
75    m_dPSNRSumV += psnrV;
76    m_dAddBits  += bits;
77   
78    m_uiNumPic++;
79  }
80 
81  Double  getPsnrY()  { return  m_dPSNRSumY;  }
82  Double  getPsnrU()  { return  m_dPSNRSumU;  }
83  Double  getPsnrV()  { return  m_dPSNRSumV;  }
84  Double  getBits()   { return  m_dAddBits;   }
85  UInt    getNumPic() { return  m_uiNumPic;   }
86 
87  Void    setFrmRate  (Double dFrameRate) { m_dFrmRate = dFrameRate; } //--CFG_KDY
88  Void    clear() { m_dPSNRSumY = m_dPSNRSumU = m_dPSNRSumV = m_dAddBits = m_uiNumPic = 0;  }
89  Void    printOut ( Char cDelim )
90  {
91    Double dFps     =   m_dFrmRate; //--CFG_KDY
92    Double dScale   = dFps / 1000 / (Double)m_uiNumPic;
93   
94    printf( "\tTotal Frames |  "   "Bitrate    "  "Y-PSNR    "  "U-PSNR    "  "V-PSNR \n" );
95    //printf( "\t------------ "  " ----------"   " -------- "  " -------- "  " --------\n" );
96    printf( "\t %8d    %c"          "%12.4lf  "    "%8.4lf  "   "%8.4lf  "    "%8.4lf\n",
97           getNumPic(), cDelim,
98           getBits() * dScale,
99           getPsnrY() / (Double)getNumPic(),
100           getPsnrU() / (Double)getNumPic(),
101           getPsnrV() / (Double)getNumPic() );
102  }
103 
104  Void    printSummaryOut ()
105  {
106    FILE* pFile = fopen ("summaryTotal.txt", "at");
107    Double dFps     =   m_dFrmRate; //--CFG_KDY
108    Double dScale   = dFps / 1000 / (Double)m_uiNumPic;
109   
110    fprintf(pFile, "%f\t %f\t %f\t %f\n", getBits() * dScale,
111            getPsnrY() / (Double)getNumPic(),
112            getPsnrU() / (Double)getNumPic(),
113            getPsnrV() / (Double)getNumPic() );
114    fclose(pFile);
115  }
116 
117  Void    printSummary(Char ch)
118  {
119    FILE* pFile = NULL;
120   
121    switch( ch ) 
122    {
123      case 'I':
124        pFile = fopen ("summary_I.txt", "at");
125        break;
126      case 'P':
127        pFile = fopen ("summary_P.txt", "at");
128        break;
129      case 'B':
130        pFile = fopen ("summary_B.txt", "at");
131        break;
132      default:
133        assert(0);
134        return;
135        break;
136    }
137   
138    Double dFps     =   m_dFrmRate; //--CFG_KDY
139    Double dScale   = dFps / 1000 / (Double)m_uiNumPic;
140   
141    fprintf(pFile, "%f\t %f\t %f\t %f\n",
142            getBits() * dScale,
143            getPsnrY() / (Double)getNumPic(),
144            getPsnrU() / (Double)getNumPic(),
145            getPsnrV() / (Double)getNumPic() );
146   
147    fclose(pFile);
148  }
149};
150
151#endif // !defined(AFX_TENCANALYZE_H__C79BCAA2_6AC8_4175_A0FE_CF02F5829233__INCLUDED_)
152
Note: See TracBrowser for help on using the repository browser.