a206c9640e063d65750efc15b82a2c2827beee64
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"
35 struct ReferencePlanes
37 ReferencePlanes() { memset(this, 0, sizeof(ReferencePlanes
)); }
40 pixel
* lowresPlane
[4];
47 intptr_t chromaStride
;
56 pixel
* getLumaAddr(uint32_t ctuAddr
, uint32_t absPartIdx
) { return fpelPlane
[0] + reconPic
->m_cuOffsetY
[ctuAddr
] + reconPic
->m_buOffsetY
[absPartIdx
]; }
57 pixel
* getCbAddr(uint32_t ctuAddr
, uint32_t absPartIdx
) { return fpelPlane
[1] + reconPic
->m_cuOffsetC
[ctuAddr
] + reconPic
->m_buOffsetC
[absPartIdx
]; }
58 pixel
* getCrAddr(uint32_t ctuAddr
, uint32_t absPartIdx
) { return fpelPlane
[2] + reconPic
->m_cuOffsetC
[ctuAddr
] + reconPic
->m_buOffsetC
[absPartIdx
]; }
60 /* lowres motion compensation, you must provide a buffer and stride for QPEL averaged pixels
61 * in case QPEL is required. Else it returns a pointer to the HPEL pixels */
62 inline pixel
*lowresMC(intptr_t blockOffset
, const MV
& qmv
, pixel
*buf
, intptr_t& outstride
)
64 if ((qmv
.x
| qmv
.y
) & 1)
66 int hpelA
= (qmv
.y
& 2) | ((qmv
.x
& 2) >> 1);
67 pixel
*frefA
= lowresPlane
[hpelA
] + blockOffset
+ (qmv
.x
>> 2) + (qmv
.y
>> 2) * lumaStride
;
68 int qmvx
= qmv
.x
+ (qmv
.x
& 1);
69 int qmvy
= qmv
.y
+ (qmv
.y
& 1);
70 int hpelB
= (qmvy
& 2) | ((qmvx
& 2) >> 1);
71 pixel
*frefB
= lowresPlane
[hpelB
] + blockOffset
+ (qmvx
>> 2) + (qmvy
>> 2) * lumaStride
;
72 primitives
.pixelavg_pp
[LUMA_8x8
](buf
, outstride
, frefA
, lumaStride
, frefB
, lumaStride
, 32);
77 outstride
= lumaStride
;
78 int hpel
= (qmv
.y
& 2) | ((qmv
.x
& 2) >> 1);
79 return lowresPlane
[hpel
] + blockOffset
+ (qmv
.x
>> 2) + (qmv
.y
>> 2) * lumaStride
;
83 inline int lowresQPelCost(pixel
*fenc
, intptr_t blockOffset
, const MV
& qmv
, pixelcmp_t comp
)
85 if ((qmv
.x
| qmv
.y
) & 1)
87 ALIGN_VAR_16(pixel
, subpelbuf
[8 * 8]);
88 int hpelA
= (qmv
.y
& 2) | ((qmv
.x
& 2) >> 1);
89 pixel
*frefA
= lowresPlane
[hpelA
] + blockOffset
+ (qmv
.x
>> 2) + (qmv
.y
>> 2) * lumaStride
;
90 int qmvx
= qmv
.x
+ (qmv
.x
& 1);
91 int qmvy
= qmv
.y
+ (qmv
.y
& 1);
92 int hpelB
= (qmvy
& 2) | ((qmvx
& 2) >> 1);
93 pixel
*frefB
= lowresPlane
[hpelB
] + blockOffset
+ (qmvx
>> 2) + (qmvy
>> 2) * lumaStride
;
94 primitives
.pixelavg_pp
[LUMA_8x8
](subpelbuf
, 8, frefA
, lumaStride
, frefB
, lumaStride
, 32);
95 return comp(fenc
, FENC_STRIDE
, subpelbuf
, 8);
99 int hpel
= (qmv
.y
& 2) | ((qmv
.x
& 2) >> 1);
100 pixel
*fref
= lowresPlane
[hpel
] + blockOffset
+ (qmv
.x
>> 2) + (qmv
.y
>> 2) * lumaStride
;
101 return comp(fenc
, FENC_STRIDE
, fref
, lumaStride
);
106 /* lowres buffers, sizes and strides */
107 struct Lowres
: public ReferencePlanes
111 int frameNum
; // Presentation frame number
112 int sliceType
; // Slice type decided by lookahead
113 int width
; // width of lowres frame in pixels
114 int lines
; // height of lowres frame in pixel lines
115 int leadingBframes
; // number of leading B frames for P or I
117 bool bIntraCalculated
;
118 bool bScenecut
; // Set to false if the frame cannot possibly be part of a real scenecut.
120 bool bLastMiniGopBFrame
;
122 /* lookahead output data */
123 int64_t costEst
[X265_BFRAME_MAX
+ 2][X265_BFRAME_MAX
+ 2];
124 int64_t costEstAq
[X265_BFRAME_MAX
+ 2][X265_BFRAME_MAX
+ 2];
125 int32_t* rowSatds
[X265_BFRAME_MAX
+ 2][X265_BFRAME_MAX
+ 2];
126 int intraMbs
[X265_BFRAME_MAX
+ 2];
130 uint16_t* lowresCostForRc
;
131 uint16_t(*lowresCosts
[X265_BFRAME_MAX
+ 2][X265_BFRAME_MAX
+ 2]);
132 int32_t* lowresMvCosts
[2][X265_BFRAME_MAX
+ 1];
133 MV
* lowresMvs
[2][X265_BFRAME_MAX
+ 1];
135 /* used for vbvLookahead */
136 int plannedType
[X265_LOOKAHEAD_MAX
+ 1];
137 int64_t plannedSatd
[X265_LOOKAHEAD_MAX
+ 1];
141 /* rate control / adaptive quant data */
142 double* qpAqOffset
; // AQ QP offset values for each 16x16 CU
143 double* qpCuTreeOffset
; // cuTree QP offset values for each 16x16 CU
144 int* invQscaleFactor
; // qScale values for qp Aq Offsets
145 uint64_t wp_ssd
[3]; // This is different than SSDY, this is sum(pixel^2) - sum(pixel)^2 for entire frame
148 /* cutree intermediate data */
149 uint16_t* propagateCost
;
150 double weightedCostDelta
[X265_BFRAME_MAX
+ 2];
152 bool create(PicYuv
*origPic
, int _bframes
, bool bAqEnabled
);
154 void init(PicYuv
*origPic
, int poc
, int sliceType
);
158 #endif // ifndef X265_LOWRES_H