958042b284b6e97b8b6378cf20bed16950d9f2ae
1 /*****************************************************************************
2 * Copyright (C) 2013 x265 project
4 * Authors: Steve Borho <steve@borho.org>
5 * Deepthi Devaki <deepthidevaki@multicorewareinc.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
21 * This program is also available under a commercial proprietary license.
22 * For more information, contact us at license @ x265.com.
23 *****************************************************************************/
26 #include "primitives.h"
30 #include "reference.h"
34 MotionReference::MotionReference()
36 m_weightBuffer
= NULL
;
39 int MotionReference::init(PicYuv
* recPic
, WeightParam
*w
)
42 lumaStride
= recPic
->m_stride
;
43 intptr_t startpad
= recPic
->m_lumaMarginY
* lumaStride
+ recPic
->m_lumaMarginX
;
45 /* directly reference the pre-extended integer pel plane */
46 fpelPlane
= recPic
->m_picBuf
[0] + startpad
;
53 uint32_t numCUinHeight
= (recPic
->m_picHeight
+ g_maxCUSize
- 1) / g_maxCUSize
;
54 size_t padheight
= (numCUinHeight
* g_maxCUSize
) + recPic
->m_lumaMarginY
* 2;
55 m_weightBuffer
= X265_MALLOC(pixel
, lumaStride
* padheight
);
61 weight
= w
->inputWeight
;
62 offset
= w
->inputOffset
* (1 << (X265_DEPTH
- 8));
63 shift
= w
->log2WeightDenom
;
64 round
= shift
? 1 << (shift
- 1) : 0;
65 m_numWeightedRows
= 0;
67 /* use our buffer which will have weighted pixels written to it */
68 fpelPlane
= m_weightBuffer
+ startpad
;
74 MotionReference::~MotionReference()
76 X265_FREE(m_weightBuffer
);
79 void MotionReference::applyWeight(int rows
, int numRows
)
81 rows
= X265_MIN(rows
, numRows
);
82 if (m_numWeightedRows
>= rows
)
84 int marginX
= m_reconPic
->m_lumaMarginX
;
85 int marginY
= m_reconPic
->m_lumaMarginY
;
86 pixel
* src
= (pixel
*)m_reconPic
->m_picOrg
[0] + (m_numWeightedRows
* (int)g_maxCUSize
* lumaStride
);
87 pixel
* dst
= fpelPlane
+ ((m_numWeightedRows
* (int)g_maxCUSize
) * lumaStride
);
88 int width
= m_reconPic
->m_picWidth
;
89 int height
= ((rows
- m_numWeightedRows
) * g_maxCUSize
);
91 height
= ((m_reconPic
->m_picHeight
% g_maxCUSize
) ? (m_reconPic
->m_picHeight
% g_maxCUSize
) : g_maxCUSize
);
93 // Computing weighted CU rows
94 int correction
= IF_INTERNAL_PREC
- X265_DEPTH
; // intermediate interpolation depth
95 int padwidth
= (width
+ 15) & ~15; // weightp assembly needs even 16 byte widths
96 primitives
.weight_pp(src
, dst
, lumaStride
, padwidth
, height
,
97 weight
, round
<< correction
, shift
+ correction
, offset
);
99 // Extending Left & Right
100 primitives
.extendRowBorder(dst
, lumaStride
, width
, height
, marginX
);
103 if (m_numWeightedRows
== 0)
105 pixel
*pixY
= fpelPlane
- marginX
;
106 for (int y
= 0; y
< marginY
; y
++)
107 memcpy(pixY
- (y
+ 1) * lumaStride
, pixY
, lumaStride
* sizeof(pixel
));
113 pixel
*pixY
= fpelPlane
- marginX
+ (m_reconPic
->m_picHeight
- 1) * lumaStride
;
114 for (int y
= 0; y
< marginY
; y
++)
115 memcpy(pixY
+ (y
+ 1) * lumaStride
, pixY
, lumaStride
* sizeof(pixel
));
117 m_numWeightedRows
= rows
;