1 /*****************************************************************************
2 * Copyright (C) 2014 x265 project
4 * Authors: Steve Borho <steve@borho.org>
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 *****************************************************************************/
28 #include "scalinglist.h"
36 struct TUEntropyCodingParameters
;
43 int64_t lambda2
; /* FIX8 */
44 int64_t lambda
; /* FIX8 */
46 QpParam() : qp(MAX_INT
) {}
48 void setQpParam(int qpScaled
)
55 lambda2
= (int64_t)(x265_lambda2_tab
[qp
- QP_BD_OFFSET
] * 256. + 0.5);
56 lambda
= (int64_t)(x265_lambda_tab
[qp
- QP_BD_OFFSET
] * 256. + 0.5);
65 const ScalingList
* m_scalingList
;
66 Entropy
* m_entropyCoder
;
71 int64_t m_psyRdoqScale
;
72 int32_t* m_resiDctCoeff
;
73 int32_t* m_fencDctCoeff
;
74 int16_t* m_fencShortBuf
;
76 enum { IEP_RATE
= 32768 }; /* FIX15 cost of an equal probable bit */
81 NoiseReduction
* m_frameNr
; // Array of NR structures, one for each frameEncoder
87 bool init(bool useRDOQ
, double psyScale
, const ScalingList
& scalingList
, Entropy
& entropy
);
88 bool allocNoiseReduction(const x265_param
& param
);
91 void setQPforQuant(const CUData
& ctu
);
93 uint32_t transformNxN(CUData
& cu
, pixel
*fenc
, uint32_t fencstride
, int16_t* residual
, uint32_t stride
, coeff_t
* coeff
,
94 uint32_t log2TrSize
, TextType ttype
, uint32_t absPartIdx
, bool useTransformSkip
);
96 void invtransformNxN(bool transQuantBypass
, int16_t* residual
, uint32_t stride
, coeff_t
* coeff
,
97 uint32_t log2TrSize
, TextType ttype
, bool bIntra
, bool useTransformSkip
, uint32_t numSig
);
99 /* static methods shared with entropy.cpp */
100 static uint32_t calcPatternSigCtx(uint64_t sigCoeffGroupFlag64
, uint32_t cgPosX
, uint32_t cgPosY
, uint32_t log2TrSizeCG
);
101 static uint32_t getSigCtxInc(uint32_t patternSigCtx
, uint32_t log2TrSize
, uint32_t trSize
, uint32_t blkPos
, bool bIsLuma
, uint32_t firstSignificanceMapContext
);
102 static uint32_t getSigCoeffGroupCtxInc(uint64_t sigCoeffGroupFlag64
, uint32_t cgPosX
, uint32_t cgPosY
, uint32_t log2TrSizeCG
);
106 void setChromaQP(int qpin
, TextType ttype
, int chFmt
);
108 uint32_t signBitHidingHDQ(int16_t* qcoeff
, int32_t* deltaU
, uint32_t numSig
, const TUEntropyCodingParameters
&codingParameters
);
110 uint32_t rdoQuant(CUData
& cu
, int16_t* dstCoeff
, uint32_t log2TrSize
, TextType ttype
, uint32_t absPartIdx
, bool usePsy
);
111 inline uint32_t getRateLast(uint32_t posx
, uint32_t posy
) const;
114 static inline uint32_t getGroupIdx(const uint32_t idx
)
116 // TODO: Why is this not a table lookup?
118 uint32_t group
= (idx
>> 3);
122 uint32_t groupIdx
= ((idx
>> (group
+ 1)) - 2) + 4 + (group
<< 1);
127 static const uint8_t g_groupIdx
[32] = { 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9 };
128 assert(groupIdx
== g_groupIdx
[idx
]);
136 #endif // ifndef X265_QUANT_H