1 /*****************************************************************************
2 * Copyright (C) 2013 x265 project
4 * Authors: Gopu Govindaswamy <gopu@multicorewareinc.com>
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.
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.
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.
20 * This program is also available under a commercial proprietary license.
21 * For more information, contact us at license @ x265.com.
22 *****************************************************************************/
27 #include "primitives.h"
36 struct ReferencePlanes
38 ReferencePlanes() { memset(this, 0, sizeof(ReferencePlanes
)); }
41 pixel
* lowresPlane
[4];
51 /* lowres motion compensation, you must provide a buffer and stride for QPEL averaged pixels
52 * in case QPEL is required. Else it returns a pointer to the HPEL pixels */
53 inline pixel
*lowresMC(intptr_t blockOffset
, const MV
& qmv
, pixel
*buf
, intptr_t& outstride
)
55 if ((qmv
.x
| qmv
.y
) & 1)
57 int hpelA
= (qmv
.y
& 2) | ((qmv
.x
& 2) >> 1);
58 pixel
*frefA
= lowresPlane
[hpelA
] + blockOffset
+ (qmv
.x
>> 2) + (qmv
.y
>> 2) * lumaStride
;
60 MV qmvB
= qmv
+ MV((qmv
.x
& 1) * 2, (qmv
.y
& 1) * 2);
61 int hpelB
= (qmvB
.y
& 2) | ((qmvB
.x
& 2) >> 1);
63 pixel
*frefB
= lowresPlane
[hpelB
] + blockOffset
+ (qmvB
.x
>> 2) + (qmvB
.y
>> 2) * lumaStride
;
64 primitives
.pixelavg_pp
[LUMA_8x8
](buf
, outstride
, frefA
, lumaStride
, frefB
, lumaStride
, 32);
69 outstride
= lumaStride
;
70 int hpel
= (qmv
.y
& 2) | ((qmv
.x
& 2) >> 1);
71 return lowresPlane
[hpel
] + blockOffset
+ (qmv
.x
>> 2) + (qmv
.y
>> 2) * lumaStride
;
75 inline int lowresQPelCost(pixel
*fenc
, intptr_t blockOffset
, const MV
& qmv
, pixelcmp_t comp
)
77 if ((qmv
.x
| qmv
.y
) & 1)
79 ALIGN_VAR_16(pixel
, subpelbuf
[8 * 8]);
80 int hpelA
= (qmv
.y
& 2) | ((qmv
.x
& 2) >> 1);
81 pixel
*frefA
= lowresPlane
[hpelA
] + blockOffset
+ (qmv
.x
>> 2) + (qmv
.y
>> 2) * lumaStride
;
82 MV qmvB
= qmv
+ MV((qmv
.x
& 1) * 2, (qmv
.y
& 1) * 2);
83 int hpelB
= (qmvB
.y
& 2) | ((qmvB
.x
& 2) >> 1);
84 pixel
*frefB
= lowresPlane
[hpelB
] + blockOffset
+ (qmvB
.x
>> 2) + (qmvB
.y
>> 2) * lumaStride
;
85 primitives
.pixelavg_pp
[LUMA_8x8
](subpelbuf
, 8, frefA
, lumaStride
, frefB
, lumaStride
, 32);
86 return comp(fenc
, FENC_STRIDE
, subpelbuf
, 8);
90 int hpel
= (qmv
.y
& 2) | ((qmv
.x
& 2) >> 1);
91 pixel
*fref
= lowresPlane
[hpel
] + blockOffset
+ (qmv
.x
>> 2) + (qmv
.y
>> 2) * lumaStride
;
92 return comp(fenc
, FENC_STRIDE
, fref
, lumaStride
);
97 /* lowres buffers, sizes and strides */
98 struct Lowres
: public ReferencePlanes
102 int frameNum
; // Presentation frame number
103 int sliceType
; // Slice type decided by lookahead
104 int width
; // width of lowres frame in pixels
105 int lines
; // height of lowres frame in pixel lines
106 int leadingBframes
; // number of leading B frames for P or I
108 bool bIntraCalculated
;
109 bool bScenecut
; // Set to false if the frame cannot possibly be part of a real scenecut.
111 bool bLastMiniGopBFrame
;
113 /* lookahead output data */
114 int64_t costEst
[X265_BFRAME_MAX
+ 2][X265_BFRAME_MAX
+ 2];
115 int64_t costEstAq
[X265_BFRAME_MAX
+ 2][X265_BFRAME_MAX
+ 2];
116 int32_t* rowSatds
[X265_BFRAME_MAX
+ 2][X265_BFRAME_MAX
+ 2];
117 int intraMbs
[X265_BFRAME_MAX
+ 2];
120 uint16_t* lowresCostForRc
;
121 uint16_t(*lowresCosts
[X265_BFRAME_MAX
+ 2][X265_BFRAME_MAX
+ 2]);
122 int32_t* lowresMvCosts
[2][X265_BFRAME_MAX
+ 1];
123 MV
* lowresMvs
[2][X265_BFRAME_MAX
+ 1];
125 /* used for vbvLookahead */
126 int plannedType
[X265_LOOKAHEAD_MAX
+ 1];
127 int64_t plannedSatd
[X265_LOOKAHEAD_MAX
+ 1];
131 /* rate control / adaptive quant data */
132 double* qpAqOffset
; // AQ QP offset values for each 16x16 CU
133 double* qpCuTreeOffset
; // cuTree QP offset values for each 16x16 CU
134 int* invQscaleFactor
; // qScale values for qp Aq Offsets
135 uint64_t wp_ssd
[3]; // This is different than SSDY, this is sum(pixel^2) - sum(pixel)^2 for entire frame
138 /* cutree intermediate data */
139 uint16_t* propagateCost
;
140 double weightedCostDelta
[X265_BFRAME_MAX
+ 2];
142 bool create(PicYuv
*origPic
, int _bframes
, bool bAqEnabled
);
144 void init(PicYuv
*origPic
, int poc
, int sliceType
);
148 #endif // ifndef X265_LOWRES_H