Imported Upstream version 1.4
[deb_x265.git] / source / common / framedata.cpp
1 /*****************************************************************************
2 * Copyright (C) 2013 x265 project
3 *
4 * Author: Steve Borho <steve@borho.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
19 *
20 * This program is also available under a commercial proprietary license.
21 * For more information, contact us at license @ x265.com.
22 *****************************************************************************/
23
24 #include "framedata.h"
25 #include "picyuv.h"
26
27 using namespace x265;
28
29 FrameData::FrameData()
30 {
31 memset(this, 0, sizeof(*this));
32 }
33
34 bool FrameData::create(x265_param *param, const SPS& sps)
35 {
36 m_param = param;
37 m_slice = new Slice;
38 m_picCTU = new CUData[sps.numCUsInFrame];
39
40 m_cuMemPool.create(0, param->internalCsp, sps.numCUsInFrame);
41 for (uint32_t ctuAddr = 0; ctuAddr < sps.numCUsInFrame; ctuAddr++)
42 m_picCTU[ctuAddr].initialize(m_cuMemPool, 0, param->internalCsp, ctuAddr);
43
44 CHECKED_MALLOC(m_cuStat, RCStatCU, sps.numCUsInFrame);
45 CHECKED_MALLOC(m_rowStat, RCStatRow, sps.numCuInHeight);
46 reinit(sps);
47 return true;
48
49 fail:
50 return false;
51 }
52
53 void FrameData::reinit(const SPS& sps)
54 {
55 memset(m_cuStat, 0, sps.numCUsInFrame * sizeof(*m_cuStat));
56 memset(m_rowStat, 0, sps.numCuInHeight * sizeof(*m_rowStat));
57 }
58
59 void FrameData::destroy()
60 {
61 delete [] m_picCTU;
62 delete m_slice;
63 delete m_saoParam;
64
65 m_cuMemPool.destroy();
66
67 X265_FREE(m_cuStat);
68 X265_FREE(m_rowStat);
69 }