Imported Upstream version 1.4
[deb_x265.git] / source / common / frame.cpp
CommitLineData
72b9787e
JB
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 "common.h"
25#include "frame.h"
26#include "picyuv.h"
27#include "framedata.h"
28
29using namespace x265;
30
31Frame::Frame()
32{
33 m_bChromaExtended = false;
34 m_reconRowCount.set(0);
35 m_countRefEncoders = 0;
36 m_encData = NULL;
37 m_reconPicYuv = NULL;
38 m_next = NULL;
39 m_prev = NULL;
40 memset(&m_lowres, 0, sizeof(m_lowres));
41}
42
43bool Frame::create(x265_param *param)
44{
45 m_origPicYuv = new PicYuv;
46
47 return m_origPicYuv->create(param->sourceWidth, param->sourceHeight, param->internalCsp) &&
48 m_lowres.create(m_origPicYuv, param->bframes, !!param->rc.aqMode);
49}
50
51bool Frame::allocEncodeData(x265_param *param, const SPS& sps)
52{
53 m_encData = new FrameData;
54 m_reconPicYuv = new PicYuv;
55 m_encData->m_reconPicYuv = m_reconPicYuv;
56 bool ok = m_encData->create(param, sps) && m_reconPicYuv->create(param->sourceWidth, param->sourceHeight, param->internalCsp);
57 if (ok)
58 {
59 /* initialize right border of m_reconpicYuv as SAO may read beyond the
60 * end of the picture accessing uninitialized pixels */
61 int maxHeight = sps.numCuInHeight * g_maxCUSize;
62 memset(m_reconPicYuv->m_picOrg[0], 0, m_reconPicYuv->m_stride * maxHeight);
63 memset(m_reconPicYuv->m_picOrg[1], 0, m_reconPicYuv->m_strideC * (maxHeight >> m_reconPicYuv->m_vChromaShift));
64 memset(m_reconPicYuv->m_picOrg[2], 0, m_reconPicYuv->m_strideC * (maxHeight >> m_reconPicYuv->m_vChromaShift));
65 }
66 return ok;
67}
68
69/* prepare to re-use a FrameData instance to encode a new picture */
70void Frame::reinit(const SPS& sps)
71{
72 m_bChromaExtended = false;
73 m_reconPicYuv = m_encData->m_reconPicYuv;
74 m_encData->reinit(sps);
75}
76
77void Frame::destroy()
78{
79 if (m_encData)
80 {
81 m_encData->destroy();
82 delete m_encData;
83 m_encData = NULL;
84 }
85
86 if (m_origPicYuv)
87 {
88 m_origPicYuv->destroy();
89 delete m_origPicYuv;
90 m_origPicYuv = NULL;
91 }
92
93 if (m_reconPicYuv)
94 {
95 m_reconPicYuv->destroy();
96 delete m_reconPicYuv;
97 m_reconPicYuv = NULL;
98 }
99
100 m_lowres.destroy();
101}