[x265] [PATCH] common: unify clip templates, no output changes
Steve Borho
steve at borho.org
Fri Jan 2 21:10:15 CET 2015
# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1420186907 -19800
# Fri Jan 02 13:51:47 2015 +0530
# Node ID 9b553540a49bc071ee9cd9ab928ba1a1271dc2f1
# Parent 8379ff016b566e0f52fcb93448d2584fd8d4d423
common: unify clip templates, no output changes
replace Clip3 users with x265_clip3 and Clip with x265_clip. This commit cleans
up a few places that were using x265_clip3 when they could have used x265_clip
and some that were using 0 instead of QP_MIN (code written before QP_MIN
existed)
diff -r 8379ff016b56 -r 9b553540a49b source/common/common.h
--- a/source/common/common.h Wed Dec 31 12:55:54 2014 +0530
+++ b/source/common/common.h Fri Jan 02 13:51:47 2015 +0530
@@ -146,18 +146,6 @@
#define BITS_FOR_POC 8
template<typename T>
-inline pixel Clip(T x)
-{
- return (pixel)std::min<T>(T((1 << X265_DEPTH) - 1), std::max<T>(T(0), x));
-}
-
-template<typename T>
-inline T Clip3(T minVal, T maxVal, T a)
-{
- return std::min<T>(std::max<T>(minVal, a), maxVal);
-}
-
-template<typename T>
inline T x265_min(T a, T b) { return a < b ? a : b; }
template<typename T>
@@ -166,6 +154,9 @@
template<typename T>
inline T x265_clip3(T minVal, T maxVal, T a) { return x265_min(x265_max(minVal, a), maxVal); }
+template<typename T> /* clip to pixel range, 0..255 or 0..1023 */
+inline pixel x265_clip(T x) { return (pixel)x265_min<T>(T((1 << X265_DEPTH) - 1), x265_max<T>(T(0), x)); }
+
typedef int16_t coeff_t; // transform coefficient
#define X265_MIN(a, b) ((a) < (b) ? (a) : (b))
diff -r 8379ff016b56 -r 9b553540a49b source/common/cudata.cpp
--- a/source/common/cudata.cpp Wed Dec 31 12:55:54 2014 +0530
+++ b/source/common/cudata.cpp Fri Jan 02 13:51:47 2015 +0530
@@ -106,8 +106,8 @@
inline MV scaleMv(MV mv, int scale)
{
- int mvx = Clip3(-32768, 32767, (scale * mv.x + 127 + (scale * mv.x < 0)) >> 8);
- int mvy = Clip3(-32768, 32767, (scale * mv.y + 127 + (scale * mv.y < 0)) >> 8);
+ int mvx = x265_clip3(-32768, 32767, (scale * mv.x + 127 + (scale * mv.x < 0)) >> 8);
+ int mvy = x265_clip3(-32768, 32767, (scale * mv.y + 127 + (scale * mv.y < 0)) >> 8);
return MV((int16_t)mvx, (int16_t)mvy);
}
@@ -1986,10 +1986,10 @@
outMV = inMV;
else
{
- int tdb = Clip3(-128, 127, diffPocB);
- int tdd = Clip3(-128, 127, diffPocD);
+ int tdb = x265_clip3(-128, 127, diffPocB);
+ int tdd = x265_clip3(-128, 127, diffPocD);
int x = (0x4000 + abs(tdd / 2)) / tdd;
- int scale = Clip3(-4096, 4095, (tdb * x + 32) >> 6);
+ int scale = x265_clip3(-4096, 4095, (tdb * x + 32) >> 6);
outMV = scaleMv(inMV, scale);
}
}
diff -r 8379ff016b56 -r 9b553540a49b source/common/dct.cpp
--- a/source/common/dct.cpp Wed Dec 31 12:55:54 2014 +0530
+++ b/source/common/dct.cpp Fri Jan 02 13:51:47 2015 +0530
@@ -74,10 +74,10 @@
c[2] = tmp[i] - tmp[12 + i];
c[3] = 74 * tmp[4 + i];
- block[4 * i + 0] = (int16_t)Clip3(-32768, 32767, (29 * c[0] + 55 * c[1] + c[3] + rnd_factor) >> shift);
- block[4 * i + 1] = (int16_t)Clip3(-32768, 32767, (55 * c[2] - 29 * c[1] + c[3] + rnd_factor) >> shift);
- block[4 * i + 2] = (int16_t)Clip3(-32768, 32767, (74 * (tmp[i] - tmp[8 + i] + tmp[12 + i]) + rnd_factor) >> shift);
- block[4 * i + 3] = (int16_t)Clip3(-32768, 32767, (55 * c[0] + 29 * c[2] - c[3] + rnd_factor) >> shift);
+ block[4 * i + 0] = (int16_t)x265_clip3(-32768, 32767, (29 * c[0] + 55 * c[1] + c[3] + rnd_factor) >> shift);
+ block[4 * i + 1] = (int16_t)x265_clip3(-32768, 32767, (55 * c[2] - 29 * c[1] + c[3] + rnd_factor) >> shift);
+ block[4 * i + 2] = (int16_t)x265_clip3(-32768, 32767, (74 * (tmp[i] - tmp[8 + i] + tmp[12 + i]) + rnd_factor) >> shift);
+ block[4 * i + 3] = (int16_t)x265_clip3(-32768, 32767, (55 * c[0] + 29 * c[2] - c[3] + rnd_factor) >> shift);
}
}
@@ -255,10 +255,10 @@
E[1] = g_t4[0][1] * src[0] + g_t4[2][1] * src[2 * line];
/* Combining even and odd terms at each hierarchy levels to calculate the final spatial domain vector */
- dst[0] = (int16_t)(Clip3(-32768, 32767, (E[0] + O[0] + add) >> shift));
- dst[1] = (int16_t)(Clip3(-32768, 32767, (E[1] + O[1] + add) >> shift));
- dst[2] = (int16_t)(Clip3(-32768, 32767, (E[1] - O[1] + add) >> shift));
- dst[3] = (int16_t)(Clip3(-32768, 32767, (E[0] - O[0] + add) >> shift));
+ dst[0] = (int16_t)(x265_clip3(-32768, 32767, (E[0] + O[0] + add) >> shift));
+ dst[1] = (int16_t)(x265_clip3(-32768, 32767, (E[1] + O[1] + add) >> shift));
+ dst[2] = (int16_t)(x265_clip3(-32768, 32767, (E[1] - O[1] + add) >> shift));
+ dst[3] = (int16_t)(x265_clip3(-32768, 32767, (E[0] - O[0] + add) >> shift));
src++;
dst += 4;
@@ -292,8 +292,8 @@
E[2] = EE[1] - EO[1];
for (k = 0; k < 4; k++)
{
- dst[k] = (int16_t)Clip3(-32768, 32767, (E[k] + O[k] + add) >> shift);
- dst[k + 4] = (int16_t)Clip3(-32768, 32767, (E[3 - k] - O[3 - k] + add) >> shift);
+ dst[k] = (int16_t)x265_clip3(-32768, 32767, (E[k] + O[k] + add) >> shift);
+ dst[k + 4] = (int16_t)x265_clip3(-32768, 32767, (E[3 - k] - O[3 - k] + add) >> shift);
}
src++;
@@ -343,8 +343,8 @@
for (k = 0; k < 8; k++)
{
- dst[k] = (int16_t)Clip3(-32768, 32767, (E[k] + O[k] + add) >> shift);
- dst[k + 8] = (int16_t)Clip3(-32768, 32767, (E[7 - k] - O[7 - k] + add) >> shift);
+ dst[k] = (int16_t)x265_clip3(-32768, 32767, (E[k] + O[k] + add) >> shift);
+ dst[k + 8] = (int16_t)x265_clip3(-32768, 32767, (E[7 - k] - O[7 - k] + add) >> shift);
}
src++;
@@ -407,8 +407,8 @@
for (k = 0; k < 16; k++)
{
- dst[k] = (int16_t)Clip3(-32768, 32767, (E[k] + O[k] + add) >> shift);
- dst[k + 16] = (int16_t)Clip3(-32768, 32767, (E[15 - k] - O[15 - k] + add) >> shift);
+ dst[k] = (int16_t)x265_clip3(-32768, 32767, (E[k] + O[k] + add) >> shift);
+ dst[k + 16] = (int16_t)x265_clip3(-32768, 32767, (E[15 - k] - O[15 - k] + add) >> shift);
}
src++;
@@ -630,7 +630,7 @@
for (int n = 0; n < num; n++)
{
coeffQ = (quantCoef[n] * scale + add) >> shift;
- coef[n] = (int16_t)Clip3(-32768, 32767, coeffQ);
+ coef[n] = (int16_t)x265_clip3(-32768, 32767, coeffQ);
}
}
@@ -649,15 +649,15 @@
for (int n = 0; n < num; n++)
{
coeffQ = ((quantCoef[n] * deQuantCoef[n]) + add) >> (shift - per);
- coef[n] = (int16_t)Clip3(-32768, 32767, coeffQ);
+ coef[n] = (int16_t)x265_clip3(-32768, 32767, coeffQ);
}
}
else
{
for (int n = 0; n < num; n++)
{
- coeffQ = Clip3(-32768, 32767, quantCoef[n] * deQuantCoef[n]);
- coef[n] = (int16_t)Clip3(-32768, 32767, coeffQ << (per - shift));
+ coeffQ = x265_clip3(-32768, 32767, quantCoef[n] * deQuantCoef[n]);
+ coef[n] = (int16_t)x265_clip3(-32768, 32767, coeffQ << (per - shift));
}
}
}
@@ -680,7 +680,7 @@
if (level)
++numSig;
level *= sign;
- qCoef[blockpos] = (int16_t)Clip3(-32768, 32767, level);
+ qCoef[blockpos] = (int16_t)x265_clip3(-32768, 32767, level);
}
return numSig;
@@ -704,7 +704,7 @@
if (level)
++numSig;
level *= sign;
- qCoef[blockpos] = (int16_t)Clip3(-32768, 32767, level);
+ qCoef[blockpos] = (int16_t)x265_clip3(-32768, 32767, level);
}
return numSig;
diff -r 8379ff016b56 -r 9b553540a49b source/common/deblock.cpp
--- a/source/common/deblock.cpp Wed Dec 31 12:55:54 2014 +0530
+++ b/source/common/deblock.cpp Fri Jan 02 13:51:47 2015 +0530
@@ -297,12 +297,12 @@
int16_t m1 = (int16_t)src[-offset * 3];
int16_t m7 = (int16_t)src[offset * 3];
int16_t m0 = (int16_t)src[-offset * 4];
- src[-offset * 3] = (pixel)(Clip3(-tcP, tcP, ((2 * m0 + 3 * m1 + m2 + m3 + m4 + 4) >> 3) - m1) + m1);
- src[-offset * 2] = (pixel)(Clip3(-tcP, tcP, ((m1 + m2 + m3 + m4 + 2) >> 2) - m2) + m2);
- src[-offset] = (pixel)(Clip3(-tcP, tcP, ((m1 + 2 * m2 + 2 * m3 + 2 * m4 + m5 + 4) >> 3) - m3) + m3);
- src[0] = (pixel)(Clip3(-tcQ, tcQ, ((m2 + 2 * m3 + 2 * m4 + 2 * m5 + m6 + 4) >> 3) - m4) + m4);
- src[offset] = (pixel)(Clip3(-tcQ, tcQ, ((m3 + m4 + m5 + m6 + 2) >> 2) - m5) + m5);
- src[offset * 2] = (pixel)(Clip3(-tcQ, tcQ, ((m3 + m4 + m5 + 3 * m6 + 2 * m7 + 4) >> 3) - m6) + m6);
+ src[-offset * 3] = (pixel)(x265_clip3(-tcP, tcP, ((2 * m0 + 3 * m1 + m2 + m3 + m4 + 4) >> 3) - m1) + m1);
+ src[-offset * 2] = (pixel)(x265_clip3(-tcP, tcP, ((m1 + m2 + m3 + m4 + 2) >> 2) - m2) + m2);
+ src[-offset] = (pixel)(x265_clip3(-tcP, tcP, ((m1 + 2 * m2 + 2 * m3 + 2 * m4 + m5 + 4) >> 3) - m3) + m3);
+ src[0] = (pixel)(x265_clip3(-tcQ, tcQ, ((m2 + 2 * m3 + 2 * m4 + 2 * m5 + m6 + 4) >> 3) - m4) + m4);
+ src[offset] = (pixel)(x265_clip3(-tcQ, tcQ, ((m3 + m4 + m5 + m6 + 2) >> 2) - m5) + m5);
+ src[offset * 2] = (pixel)(x265_clip3(-tcQ, tcQ, ((m3 + m4 + m5 + 3 * m6 + 2 * m7 + 4) >> 3) - m6) + m6);
}
}
@@ -326,21 +326,21 @@
if (abs(delta) < thrCut)
{
- delta = Clip3(-tc, tc, delta);
+ delta = x265_clip3(-tc, tc, delta);
- src[-offset] = Clip(m3 + (delta & maskP));
- src[0] = Clip(m4 - (delta & maskQ));
+ src[-offset] = x265_clip(m3 + (delta & maskP));
+ src[0] = x265_clip(m4 - (delta & maskQ));
if (maskP1)
{
int16_t m1 = (int16_t)src[-offset * 3];
- int32_t delta1 = Clip3(-tc2, tc2, ((((m1 + m3 + 1) >> 1) - m2 + delta) >> 1));
- src[-offset * 2] = Clip(m2 + delta1);
+ int32_t delta1 = x265_clip3(-tc2, tc2, ((((m1 + m3 + 1) >> 1) - m2 + delta) >> 1));
+ src[-offset * 2] = x265_clip(m2 + delta1);
}
if (maskQ1)
{
int16_t m6 = (int16_t)src[offset * 2];
- int32_t delta2 = Clip3(-tc2, tc2, ((((m6 + m4 + 1) >> 1) - m5 - delta) >> 1));
- src[offset] = Clip(m5 + delta2);
+ int32_t delta2 = x265_clip3(-tc2, tc2, ((((m6 + m4 + 1) >> 1) - m5 - delta) >> 1));
+ src[offset] = x265_clip(m5 + delta2);
}
}
}
@@ -361,9 +361,9 @@
int16_t m5 = (int16_t)src[offset];
int16_t m2 = (int16_t)src[-offset * 2];
- int32_t delta = Clip3(-tc, tc, ((((m4 - m3) << 2) + m2 - m5 + 4) >> 3));
- src[-offset] = Clip(m3 + (delta & maskP));
- src[0] = Clip(m4 - (delta & maskQ));
+ int32_t delta = x265_clip3(-tc, tc, ((((m4 - m3) << 2) + m2 - m5 + 4) >> 3));
+ src[-offset] = x265_clip(m3 + (delta & maskP));
+ src[0] = x265_clip(m4 - (delta & maskQ));
}
}
@@ -413,7 +413,7 @@
int32_t qpP = cuP->m_qp[partP];
int32_t qp = (qpP + qpQ + 1) >> 1;
- int32_t indexB = Clip3(0, QP_MAX_SPEC, qp + betaOffset);
+ int32_t indexB = x265_clip3(0, QP_MAX_SPEC, qp + betaOffset);
const int32_t bitdepthShift = X265_DEPTH - 8;
int32_t beta = s_betaTable[indexB] << bitdepthShift;
@@ -438,7 +438,7 @@
maskQ = (cuQ->m_tqBypass[partQ] ? 0 : -1);
}
- int32_t indexTC = Clip3(0, QP_MAX_SPEC + DEFAULT_INTRA_TC_OFFSET, int32_t(qp + DEFAULT_INTRA_TC_OFFSET * (bs - 1) + tcOffset));
+ int32_t indexTC = x265_clip3(0, QP_MAX_SPEC + DEFAULT_INTRA_TC_OFFSET, int32_t(qp + DEFAULT_INTRA_TC_OFFSET * (bs - 1) + tcOffset));
int32_t tc = s_tcTable[indexTC] << bitdepthShift;
bool sw = (2 * d0 < (beta >> 2) &&
@@ -538,7 +538,7 @@
qp = X265_MIN(qp, 51);
}
- int32_t indexTC = Clip3(0, QP_MAX_SPEC + DEFAULT_INTRA_TC_OFFSET, int32_t(qp + DEFAULT_INTRA_TC_OFFSET + tcOffset));
+ int32_t indexTC = x265_clip3(0, QP_MAX_SPEC + DEFAULT_INTRA_TC_OFFSET, int32_t(qp + DEFAULT_INTRA_TC_OFFSET + tcOffset));
const int32_t bitdepthShift = X265_DEPTH - 8;
int32_t tc = s_tcTable[indexTC] << bitdepthShift;
pixel* srcC = srcChroma[chromaIdx];
diff -r 8379ff016b56 -r 9b553540a49b source/common/intrapred.cpp
--- a/source/common/intrapred.cpp Wed Dec 31 12:55:54 2014 +0530
+++ b/source/common/intrapred.cpp Fri Jan 02 13:51:47 2015 +0530
@@ -190,9 +190,7 @@
if (bFilter)
{
for (k = 0; k < width; k++)
- {
- dst[k * dstStride] = (pixel)Clip3((int16_t)0, (int16_t)((1 << X265_DEPTH) - 1), static_cast<int16_t>((dst[k * dstStride]) + ((refSide[k + 1] - refSide[0]) >> 1)));
- }
+ dst[k * dstStride] = x265_clip((int16_t)((dst[k * dstStride]) + ((refSide[k + 1] - refSide[0]) >> 1)));
}
}
else
diff -r 8379ff016b56 -r 9b553540a49b source/common/param.cpp
--- a/source/common/param.cpp Wed Dec 31 12:55:54 2014 +0530
+++ b/source/common/param.cpp Fri Jan 02 13:51:47 2015 +0530
@@ -770,7 +770,7 @@
OPT("nr-inter") p->noiseReductionInter = atoi(value);
OPT("pass")
{
- int pass = Clip3(0, 3, atoi(value));
+ int pass = x265_clip3(0, 3, atoi(value));
p->rc.bStatWrite = pass & 1;
p->rc.bStatRead = pass & 2;
}
diff -r 8379ff016b56 -r 9b553540a49b source/common/pixel.cpp
--- a/source/common/pixel.cpp Wed Dec 31 12:55:54 2014 +0530
+++ b/source/common/pixel.cpp Fri Jan 02 13:51:47 2015 +0530
@@ -567,7 +567,7 @@
for (x = 0; x <= width - 1; )
{
// note: width can be odd
- dst[x] = (pixel)Clip3(0, ((1 << X265_DEPTH) - 1), ((w0 * (src[x] + IF_INTERNAL_OFFS) + round) >> shift) + offset);
+ dst[x] = x265_clip(((w0 * (src[x] + IF_INTERNAL_OFFS) + round) >> shift) + offset);
x++;
}
@@ -594,7 +594,7 @@
{
// simulating pixel to short conversion
int16_t val = src[x] << correction;
- dst[x] = (pixel)Clip3(0, ((1 << X265_DEPTH) - 1), ((w0 * (val) + round) >> shift) + offset);
+ dst[x] = x265_clip(((w0 * (val) + round) >> shift) + offset);
x++;
}
@@ -913,7 +913,7 @@
for (int y = 0; y < by; y++)
{
for (int x = 0; x < bx; x++)
- a[x] = Clip(b0[x] + b1[x]);
+ a[x] = x265_clip(b0[x] + b1[x]);
b0 += sstride0;
b1 += sstride1;
@@ -933,8 +933,8 @@
{
for (int x = 0; x < bx; x += 2)
{
- dst[x + 0] = Clip((src0[x + 0] + src1[x + 0] + offset) >> shiftNum);
- dst[x + 1] = Clip((src0[x + 1] + src1[x + 1] + offset) >> shiftNum);
+ dst[x + 0] = x265_clip((src0[x + 0] + src1[x + 0] + offset) >> shiftNum);
+ dst[x + 1] = x265_clip((src0[x + 1] + src1[x + 1] + offset) >> shiftNum);
}
src0 += src0Stride;
diff -r 8379ff016b56 -r 9b553540a49b source/common/predict.cpp
--- a/source/common/predict.cpp Wed Dec 31 12:55:54 2014 +0530
+++ b/source/common/predict.cpp Fri Jan 02 13:51:47 2015 +0530
@@ -34,7 +34,7 @@
{
inline pixel weightBidir(int w0, int16_t P0, int w1, int16_t P1, int round, int shift, int offset)
{
- return Clip((w0 * (P0 + IF_INTERNAL_OFFS) + w1 * (P1 + IF_INTERNAL_OFFS) + round + (offset << (shift - 1))) >> shift);
+ return x265_clip((w0 * (P0 + IF_INTERNAL_OFFS) + w1 * (P1 + IF_INTERNAL_OFFS) + round + (offset << (shift - 1))) >> shift);
}
}
diff -r 8379ff016b56 -r 9b553540a49b source/common/quant.cpp
--- a/source/common/quant.cpp Wed Dec 31 12:55:54 2014 +0530
+++ b/source/common/quant.cpp Fri Jan 02 13:51:47 2015 +0530
@@ -201,7 +201,7 @@
void Quant::setChromaQP(int qpin, TextType ttype, int chFmt)
{
- int qp = Clip3(-QP_BD_OFFSET, 57, qpin);
+ int qp = x265_clip3(-QP_BD_OFFSET, 57, qpin);
if (qp >= 30)
{
if (chFmt == X265_CSP_I420)
diff -r 8379ff016b56 -r 9b553540a49b source/encoder/entropy.cpp
--- a/source/encoder/entropy.cpp Wed Dec 31 12:55:54 2014 +0530
+++ b/source/encoder/entropy.cpp Fri Jan 02 13:51:47 2015 +0530
@@ -930,7 +930,7 @@
/** initialize context model with respect to QP and initialization value */
uint8_t sbacInit(int qp, int initValue)
{
- qp = Clip3(0, 51, qp);
+ qp = x265_clip3(QP_MIN, QP_MAX_SPEC, qp);
int slope = (initValue >> 4) * 5 - 45;
int offset = ((initValue & 15) << 3) - 16;
diff -r 8379ff016b56 -r 9b553540a49b source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp Wed Dec 31 12:55:54 2014 +0530
+++ b/source/encoder/frameencoder.cpp Fri Jan 02 13:51:47 2015 +0530
@@ -275,7 +275,7 @@
m_rce.newQp = qp;
/* Clip slice QP to 0-51 spec range before encoding */
- slice->m_sliceQp = Clip3(-QP_BD_OFFSET, QP_MAX_SPEC, qp);
+ slice->m_sliceQp = x265_clip3(-QP_BD_OFFSET, QP_MAX_SPEC, qp);
m_initSliceContext.resetEntropy(*slice);
@@ -754,7 +754,7 @@
{
int qp = calcQpForCu(cuAddr, curEncData.m_cuStat[cuAddr].baseQp);
tld.analysis.setQP(*slice, qp);
- qp = Clip3(QP_MIN, QP_MAX_SPEC, qp);
+ qp = x265_clip3(QP_MIN, QP_MAX_SPEC, qp);
ctu->setQPSubParts((int8_t)qp, 0, 0);
curEncData.m_rowStat[row].sumQpAq += qp;
}
@@ -824,7 +824,7 @@
{
double qpBase = curEncData.m_cuStat[cuAddr].baseQp;
int reEncode = m_top->m_rateControl->rowDiagonalVbvRateControl(m_frame, row, &m_rce, qpBase);
- qpBase = Clip3((double)QP_MIN, (double)QP_MAX_MAX, qpBase);
+ qpBase = x265_clip3((double)QP_MIN, (double)QP_MAX_MAX, qpBase);
curEncData.m_rowStat[row].diagQp = qpBase;
curEncData.m_rowStat[row].diagQpScale = x265_qp2qScale(qpBase);
@@ -1140,7 +1140,7 @@
qp_offset /= cnt;
qp += qp_offset;
- return Clip3(QP_MIN, QP_MAX_MAX, (int)(qp + 0.5));
+ return x265_clip3(QP_MIN, QP_MAX_MAX, (int)(qp + 0.5));
}
Frame *FrameEncoder::getEncodedPicture(NALList& output)
diff -r 8379ff016b56 -r 9b553540a49b source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp Wed Dec 31 12:55:54 2014 +0530
+++ b/source/encoder/ratecontrol.cpp Fri Jan 02 13:51:47 2015 +0530
@@ -365,9 +365,9 @@
m_rce2Pass = NULL;
// vbv initialization
- m_param->rc.vbvBufferSize = Clip3(0, 2000000, m_param->rc.vbvBufferSize);
- m_param->rc.vbvMaxBitrate = Clip3(0, 2000000, m_param->rc.vbvMaxBitrate);
- m_param->rc.vbvBufferInit = Clip3(0.0, 2000000.0, m_param->rc.vbvBufferInit);
+ m_param->rc.vbvBufferSize = x265_clip3(0, 2000000, m_param->rc.vbvBufferSize);
+ m_param->rc.vbvMaxBitrate = x265_clip3(0, 2000000, m_param->rc.vbvMaxBitrate);
+ m_param->rc.vbvBufferInit = x265_clip3(0.0, 2000000.0, m_param->rc.vbvBufferInit);
m_singleFrameVbv = 0;
if (m_param->rc.vbvBufferSize)
{
@@ -428,8 +428,8 @@
if (m_qp && !m_param->bLossless)
{
m_qpConstant[P_SLICE] = m_qp;
- m_qpConstant[I_SLICE] = Clip3(0, QP_MAX_MAX, (int)(m_qp - m_ipOffset + 0.5));
- m_qpConstant[B_SLICE] = Clip3(0, QP_MAX_MAX, (int)(m_qp + m_pbOffset + 0.5));
+ m_qpConstant[I_SLICE] = x265_clip3(QP_MIN, QP_MAX_MAX, (int)(m_qp - m_ipOffset + 0.5));
+ m_qpConstant[B_SLICE] = x265_clip3(QP_MIN, QP_MAX_MAX, (int)(m_qp + m_pbOffset + 0.5));
}
else
{
@@ -471,8 +471,8 @@
m_singleFrameVbv = m_bufferRate * 1.1 > m_bufferSize;
if (m_param->rc.vbvBufferInit > 1.)
- m_param->rc.vbvBufferInit = Clip3(0.0, 1.0, m_param->rc.vbvBufferInit / m_param->rc.vbvBufferSize);
- m_param->rc.vbvBufferInit = Clip3(0.0, 1.0, X265_MAX(m_param->rc.vbvBufferInit, m_bufferRate / m_bufferSize));
+ m_param->rc.vbvBufferInit = x265_clip3(0.0, 1.0, m_param->rc.vbvBufferInit / m_param->rc.vbvBufferSize);
+ m_param->rc.vbvBufferInit = x265_clip3(0.0, 1.0, X265_MAX(m_param->rc.vbvBufferInit, m_bufferRate / m_bufferSize));
m_bufferFillFinal = m_bufferSize * m_param->rc.vbvBufferInit;
}
@@ -737,10 +737,10 @@
hrd->cbrFlag = m_isCbr;
// normalize HRD size and rate to the value / scale notation
- hrd->bitRateScale = Clip3(0, 15, calcScale(vbvMaxBitrate) - BR_SHIFT);
+ hrd->bitRateScale = x265_clip3(0, 15, calcScale(vbvMaxBitrate) - BR_SHIFT);
hrd->bitRateValue = (vbvMaxBitrate >> (hrd->bitRateScale + BR_SHIFT));
- hrd->cpbSizeScale = Clip3(0, 15, calcScale(vbvBufferSize) - CPB_SHIFT);
+ hrd->cpbSizeScale = x265_clip3(0, 15, calcScale(vbvBufferSize) - CPB_SHIFT);
hrd->cpbSizeValue = (vbvBufferSize >> (hrd->cpbSizeScale + CPB_SHIFT));
int bitRateUnscale = hrd->bitRateValue << (hrd->bitRateScale + BR_SHIFT);
int cpbSizeUnscale = hrd->cpbSizeValue << (hrd->cpbSizeScale + CPB_SHIFT);
@@ -753,9 +753,9 @@
int maxDpbOutputDelay = (int)(sps->maxDecPicBuffering * MAX_DURATION * time->timeScale / time->numUnitsInTick);
int maxDelay = (int)(90000.0 * cpbSizeUnscale / bitRateUnscale + 0.5);
- hrd->initialCpbRemovalDelayLength = 2 + Clip3(4, 22, 32 - calcLength(maxDelay));
- hrd->cpbRemovalDelayLength = Clip3(4, 31, 32 - calcLength(maxCpbOutputDelay));
- hrd->dpbOutputDelayLength = Clip3(4, 31, 32 - calcLength(maxDpbOutputDelay));
+ hrd->initialCpbRemovalDelayLength = 2 + x265_clip3(4, 22, 32 - calcLength(maxDelay));
+ hrd->cpbRemovalDelayLength = x265_clip3(4, 31, 32 - calcLength(maxCpbOutputDelay));
+ hrd->dpbOutputDelayLength = x265_clip3(4, 31, 32 - calcLength(maxDpbOutputDelay));
#undef MAX_DURATION
}
@@ -1024,9 +1024,9 @@
* adaptive B-frames, but that would be complicated.
* So just calculate the average QP used so far. */
m_param->rc.qp = (m_accumPQp < 1) ? ABR_INIT_QP_MAX : (int)(m_accumPQp + 0.5);
- m_qpConstant[P_SLICE] = Clip3(0, QP_MAX_MAX, m_param->rc.qp);
- m_qpConstant[I_SLICE] = Clip3(0, QP_MAX_MAX, (int)(m_param->rc.qp - m_ipOffset + 0.5));
- m_qpConstant[B_SLICE] = Clip3(0, QP_MAX_MAX, (int)(m_param->rc.qp + m_pbOffset + 0.5));
+ m_qpConstant[P_SLICE] = x265_clip3(QP_MIN, QP_MAX_MAX, m_param->rc.qp);
+ m_qpConstant[I_SLICE] = x265_clip3(QP_MIN, QP_MAX_MAX, (int)(m_param->rc.qp - m_ipOffset + 0.5));
+ m_qpConstant[B_SLICE] = x265_clip3(QP_MIN, QP_MAX_MAX, (int)(m_param->rc.qp + m_pbOffset + 0.5));
x265_log(m_param, X265_LOG_ERROR, "2nd pass has more frames than 1st pass (%d)\n", m_numEntries);
x265_log(m_param, X265_LOG_ERROR, "continuing anyway, at constant QP=%d\n", m_param->rc.qp);
@@ -1139,7 +1139,7 @@
rce->lastSatd = m_currentSatd;
}
double q = x265_qScale2qp(rateEstimateQscale(curFrame, rce));
- q = Clip3((double)QP_MIN, (double)QP_MAX_MAX, q);
+ q = x265_clip3((double)QP_MIN, (double)QP_MAX_MAX, q);
m_qp = int(q + 0.5);
rce->qpaRc = curEncData.m_avgQpRc = curEncData.m_avgQpAq = q;
/* copy value of lastRceq into thread local rce struct *to be used in RateControlEnd() */
@@ -1163,7 +1163,7 @@
if (curFrame->m_forceqp)
{
m_qp = (int32_t)(curFrame->m_forceqp + 0.5) - 1;
- m_qp = Clip3(QP_MIN, QP_MAX_MAX, m_qp);
+ m_qp = x265_clip3(QP_MIN, QP_MAX_MAX, m_qp);
rce->qpaRc = curEncData.m_avgQpRc = curEncData.m_avgQpAq = m_qp;
}
// Do not increment m_startEndOrder here. Make rateControlEnd of previous thread
@@ -1223,7 +1223,7 @@
{
double maxQscale = m_lastQScaleFor[rce->sliceType] * m_lstep;
double minQscale = m_lastQScaleFor[rce->sliceType] / m_lstep;
- q = Clip3(minQscale, maxQscale, q);
+ q = x265_clip3(minQscale, maxQscale, q);
}
m_lastQScaleFor[rce->sliceType] = q;
@@ -1271,7 +1271,7 @@
{
fill += (m_frameDuration * m_vbvMaxRate -
qScale2bits(&m_rce2Pass[i], m_rce2Pass[i].newQScale)) * parity;
- fill = Clip3(0.0, m_bufferSize, fill);
+ fill = x265_clip3(0.0, m_bufferSize, fill);
fills[i] = fill;
if (fill <= bufferMin || i == 0)
{
@@ -1296,9 +1296,9 @@
for (int i = t0; i <= t1; i++)
{
qscaleOrig = m_rce2Pass[i].newQScale;
- qscaleOrig = Clip3(qscaleMin, qscaleMax, qscaleOrig);
+ qscaleOrig = x265_clip3(qscaleMin, qscaleMax, qscaleOrig);
qscaleNew = qscaleOrig * adjustment;
- qscaleNew = Clip3(qscaleMin, qscaleMax, qscaleNew);
+ qscaleNew = x265_clip3(qscaleMin, qscaleMax, qscaleNew);
m_rce2Pass[i].newQScale = qscaleNew;
adjusted = adjusted || (qscaleNew != qscaleOrig);
}
@@ -1360,7 +1360,7 @@
if (wantedBits > 0 && m_totalBits > 0 && !m_partialResidualFrames)
{
abrBuffer *= X265_MAX(1, sqrt(timeDone));
- overflow = Clip3(.5, 2.0, 1.0 + (m_totalBits - wantedBits) / abrBuffer);
+ overflow = x265_clip3(.5, 2.0, 1.0 + (m_totalBits - wantedBits) / abrBuffer);
qScale *= overflow;
}
}
@@ -1448,7 +1448,7 @@
{
double lmin = m_lastQScaleFor[P_SLICE] / m_lstep;
double lmax = m_lastQScaleFor[P_SLICE] * m_lstep;
- qScale = Clip3(lmin, lmax, qScale);
+ qScale = x265_clip3(lmin, lmax, qScale);
}
q = x265_qScale2qp(qScale);
}
@@ -1494,13 +1494,13 @@
}
diff = m_predictedBits - (int64_t)rce->expectedBits;
q = rce->newQScale;
- q /= Clip3(0.5, 2.0, (double)(abrBuffer - diff) / abrBuffer);
+ q /= x265_clip3(0.5, 2.0, (double)(abrBuffer - diff) / abrBuffer);
if (m_expectedBitsSum > 0)
{
/* Adjust quant based on the difference between
* achieved and expected bitrate so far */
double curTime = (double)rce->encodeOrder / m_numEntries;
- double w = Clip3(0.0, 1.0, curTime * 100);
+ double w = x265_clip3(0.0, 1.0, curTime * 100);
q *= pow((double)m_totalBits / m_expectedBitsSum, w);
}
rce->qpNoVbv = x265_qScale2qp(q);
@@ -1524,7 +1524,7 @@
expectedVbv = m_bufferFill + m_bufferRate - expectedSize;
}
}
- q = Clip3(MIN_QPSCALE, MAX_MAX_QPSCALE, q);
+ q = x265_clip3(MIN_QPSCALE, MAX_MAX_QPSCALE, q);
}
else
{
@@ -1584,7 +1584,7 @@
else if (overflow < 0.9)
lqmin /= m_lstep;
}
- q = Clip3(lqmin, lqmax, q);
+ q = x265_clip3(lqmin, lqmax, q);
}
}
else if (m_qCompress != 1 && m_param->rc.rateControlMode == X265_RC_CRF)
@@ -1597,7 +1597,7 @@
double lqmax = x265_qp2qScale(ABR_INIT_QP_MAX) * m_lstep;
q = X265_MIN(lqmax, q);
}
- q = Clip3(MIN_QPSCALE, MAX_MAX_QPSCALE, q);
+ q = x265_clip3(MIN_QPSCALE, MAX_MAX_QPSCALE, q);
rce->qpNoVbv = x265_qScale2qp(q);
q = clipQscale(curFrame, rce, q);
}
@@ -1778,7 +1778,7 @@
continue;
}
/* Try to get the buffer atleast 50% filled, but don't set an impossible goal. */
- targetFill = Clip3(m_bufferSize - (m_bufferSize * totalDuration * 0.5), m_bufferSize, m_bufferFill - totalDuration * m_vbvMaxRate * 0.5);
+ targetFill = x265_clip3(m_bufferSize - (m_bufferSize * totalDuration * 0.5), m_bufferSize, m_bufferFill - totalDuration * m_vbvMaxRate * 0.5);
if (m_isCbr && bufferFillCur > targetFill)
{
q /= 1.01;
@@ -1796,7 +1796,7 @@
(m_sliceType == I_SLICE && m_lastNonBPictType == I_SLICE)) &&
m_bufferFill / m_bufferSize < 0.5)
{
- q /= Clip3(0.5, 1.0, 2.0 * m_bufferFill / m_bufferSize);
+ q /= x265_clip3(0.5, 1.0, 2.0 * m_bufferFill / m_bufferSize);
}
// Now a hard threshold to make sure the frame fits in VBV.
// This one is mostly for I-frames.
@@ -1812,7 +1812,7 @@
{
double qf = 1.0;
if (bits > m_bufferFill / maxFillFactor)
- qf = Clip3(0.2, 1.0, m_bufferFill / (maxFillFactor * bits));
+ qf = x265_clip3(0.2, 1.0, m_bufferFill / (maxFillFactor * bits));
q /= qf;
bits *= qf;
if (bits < m_bufferRate / minFillFactor)
@@ -1835,7 +1835,7 @@
{
double qpNoVbv = x265_qScale2qp(q0);
double qmax = X265_MIN(MAX_MAX_QPSCALE,x265_qp2qScale(qpNoVbv + m_rateFactorMaxIncrement));
- return Clip3(MIN_QPSCALE, qmax, q);
+ return x265_clip3(MIN_QPSCALE, qmax, q);
}
}
if (m_2pass)
@@ -1847,7 +1847,7 @@
q = q*(max - min) + min;
return exp(q);
}
- return Clip3(MIN_QPSCALE, MAX_MAX_QPSCALE, q);
+ return x265_clip3(MIN_QPSCALE, MAX_MAX_QPSCALE, q);
}
double RateControl::predictRowsSizeSum(Frame* curFrame, RateControlEntry* rce, double qpVbv, int32_t& encodedBitsSoFar)
@@ -2020,7 +2020,7 @@
if (qpVbv > qpMax && prevRowQp < qpMax && canReencodeRow)
{
/* Bump QP to halfway in between... close enough. */
- qpVbv = Clip3(prevRowQp + 1.0f, qpMax, (prevRowQp + qpVbv) * 0.5);
+ qpVbv = x265_clip3(prevRowQp + 1.0f, qpMax, (prevRowQp + qpVbv) * 0.5);
return -1;
}
@@ -2028,7 +2028,7 @@
{
if (qpVbv < qpMin && prevRowQp > qpMin && canReencodeRow)
{
- qpVbv = Clip3(qpMin, prevRowQp, (prevRowQp + qpVbv) * 0.5);
+ qpVbv = x265_clip3(qpMin, prevRowQp, (prevRowQp + qpVbv) * 0.5);
return -1;
}
}
@@ -2081,7 +2081,7 @@
const double range = 2;
double old_coeff = p->coeff / p->count;
double new_coeff = bits * q / var;
- double new_coeff_clipped = Clip3(old_coeff / range, old_coeff * range, new_coeff);
+ double new_coeff_clipped = x265_clip3(old_coeff / range, old_coeff * range, new_coeff);
double new_offset = bits * q - new_coeff_clipped * var;
if (new_offset >= 0)
new_coeff = new_coeff_clipped;
diff -r 8379ff016b56 -r 9b553540a49b source/encoder/ratecontrol.h
--- a/source/encoder/ratecontrol.h Wed Dec 31 12:55:54 2014 +0530
+++ b/source/encoder/ratecontrol.h Fri Jan 02 13:51:47 2015 +0530
@@ -42,7 +42,7 @@
#define MAX_FRAME_DURATION 1.00
#define MIN_FRAME_DURATION 0.01
-#define CLIP_DURATION(f) Clip3(MIN_FRAME_DURATION, MAX_FRAME_DURATION, f)
+#define CLIP_DURATION(f) x265_clip3(MIN_FRAME_DURATION, MAX_FRAME_DURATION, f)
/* Current frame stats for 2 pass */
struct FrameStats
diff -r 8379ff016b56 -r 9b553540a49b source/encoder/rdcost.h
--- a/source/encoder/rdcost.h Wed Dec 31 12:55:54 2014 +0530
+++ b/source/encoder/rdcost.h Fri Jan 02 13:51:47 2015 +0530
@@ -54,7 +54,7 @@
setLambda(x265_lambda2_tab[qp], x265_lambda_tab[qp]);
if (slice.m_sps->chromaFormatIdc == X265_CSP_I420)
- qpCb = Clip3(QP_MIN, QP_MAX_MAX, (int)g_chromaScale[qp + slice.m_pps->chromaQpOffset[0]]);
+ qpCb = x265_clip3(QP_MIN, QP_MAX_MAX, (int)g_chromaScale[qp + slice.m_pps->chromaQpOffset[0]]);
else
qpCb = X265_MIN(qp + slice.m_pps->chromaQpOffset[0], QP_MAX_SPEC);
int chroma_offset_idx = X265_MIN(qp - qpCb + 12, MAX_CHROMA_LAMBDA_OFFSET);
@@ -62,7 +62,7 @@
m_chromaDistWeight[0] = lambdaOffset;
if (slice.m_sps->chromaFormatIdc == X265_CSP_I420)
- qpCr = Clip3(QP_MIN, QP_MAX_MAX, (int)g_chromaScale[qp + slice.m_pps->chromaQpOffset[0]]);
+ qpCr = x265_clip3(QP_MIN, QP_MAX_MAX, (int)g_chromaScale[qp + slice.m_pps->chromaQpOffset[0]]);
else
qpCr = X265_MIN(qp + slice.m_pps->chromaQpOffset[0], QP_MAX_SPEC);
chroma_offset_idx = X265_MIN(qp - qpCr + 12, MAX_CHROMA_LAMBDA_OFFSET);
diff -r 8379ff016b56 -r 9b553540a49b source/encoder/sao.cpp
--- a/source/encoder/sao.cpp Wed Dec 31 12:55:54 2014 +0530
+++ b/source/encoder/sao.cpp Fri Jan 02 13:51:47 2015 +0530
@@ -178,7 +178,7 @@
Slice* slice = frame->m_encData->m_slice;
int qpCb = qp;
if (m_param->internalCsp == X265_CSP_I420)
- qpCb = Clip3(QP_MIN, QP_MAX_MAX, (int)g_chromaScale[qp + slice->m_pps->chromaQpOffset[0]]);
+ qpCb = x265_clip3(QP_MIN, QP_MAX_MAX, (int)g_chromaScale[qp + slice->m_pps->chromaQpOffset[0]]);
else
qpCb = X265_MIN(qp + slice->m_pps->chromaQpOffset[0], QP_MAX_SPEC);
m_lumaLambda = x265_lambda2_tab[qp];
@@ -1217,7 +1217,7 @@
if (count)
{
int offset = roundIBDI(offsetOrg, count << SAO_BIT_INC);
- offset = Clip3(-OFFSET_THRESH + 1, OFFSET_THRESH - 1, offset);
+ offset = x265_clip3(-OFFSET_THRESH + 1, OFFSET_THRESH - 1, offset);
if (typeIdx < SAO_BO)
{
if (classIdx < 3)
diff -r 8379ff016b56 -r 9b553540a49b source/encoder/slicetype.cpp
--- a/source/encoder/slicetype.cpp Wed Dec 31 12:55:54 2014 +0530
+++ b/source/encoder/slicetype.cpp Fri Jan 02 13:51:47 2015 +0530
@@ -1441,9 +1441,9 @@
/* Rescale considering the constraints on curOffset. We do it in this order
* because scale has a much wider range than offset (because of denom), so
* it should almost never need to be clamped. */
- curOffset = Clip3(-128, 127, curOffset);
+ curOffset = x265_clip3(-128, 127, curOffset);
curScale = (int)((1 << mindenom) * (fencMean - curOffset) / refMean + 0.5f);
- curScale = Clip3(0, 127, curScale);
+ curScale = x265_clip3(0, 127, curScale);
}
SET_WEIGHT(m_w, 1, curScale, mindenom, curOffset);
s = weightCostLuma(frames, b, p0, &m_w);
diff -r 8379ff016b56 -r 9b553540a49b source/encoder/weightPrediction.cpp
--- a/source/encoder/weightPrediction.cpp Wed Dec 31 12:55:54 2014 +0530
+++ b/source/encoder/weightPrediction.cpp Fri Jan 02 13:51:47 2015 +0530
@@ -303,7 +303,7 @@
if (plane)
{
- int scale = Clip3(0, 255, (int)(guessScale[plane] * (1 << denom) + 0.5f));
+ int scale = x265_clip3(0, 255, (int)(guessScale[plane] * (1 << denom) + 0.5f));
if (scale > 127)
continue;
weights[plane].inputWeight = scale;
@@ -413,8 +413,8 @@
static const int scaleDist = 4;
static const int offsetDist = 2;
- int startScale = Clip3(0, 127, minscale - scaleDist);
- int endScale = Clip3(0, 127, minscale + scaleDist);
+ int startScale = x265_clip3(0, 127, minscale - scaleDist);
+ int endScale = x265_clip3(0, 127, minscale + scaleDist);
for (int scale = startScale; scale <= endScale; scale++)
{
int deltaWeight = scale - (1 << mindenom);
@@ -429,13 +429,13 @@
/* Rescale considering the constraints on curOffset. We do it in this order
* because scale has a much wider range than offset (because of denom), so
* it should almost never need to be clamped. */
- curOffset = Clip3(-128, 127, curOffset);
+ curOffset = x265_clip3(-128, 127, curOffset);
curScale = (int)((1 << mindenom) * (fencMean[plane] - curOffset) / refMean[plane] + 0.5f);
- curScale = Clip3(0, 127, curScale);
+ curScale = x265_clip3(0, 127, curScale);
}
- int startOffset = Clip3(-128, 127, curOffset - offsetDist);
- int endOffset = Clip3(-128, 127, curOffset + offsetDist);
+ int startOffset = x265_clip3(-128, 127, curOffset - offsetDist);
+ int endOffset = x265_clip3(-128, 127, curOffset + offsetDist);
for (int off = startOffset; off <= endOffset; off++)
{
WeightParam wsp;
diff -r 8379ff016b56 -r 9b553540a49b source/filters/filters.cpp
--- a/source/filters/filters.cpp Wed Dec 31 12:55:54 2014 +0530
+++ b/source/filters/filters.cpp Fri Jan 02 13:51:47 2015 +0530
@@ -41,7 +41,7 @@
for (int x = 0; x < width; x++)
{
err = err * 2 + errors[x] + errors[x + 1];
- dst[x * pitch] = (pixel)Clip3(0, pixelMax, ((src[x * 1] << 2) + err + half) >> rShift);
+ dst[x * pitch] = (pixel)x265_clip3(0, pixelMax, ((src[x * 1] << 2) + err + half) >> rShift);
errors[x] = err = src[x * pitch] - (dst[x * pitch] << lShift);
}
}
diff -r 8379ff016b56 -r 9b553540a49b source/test/ipfilterharness.cpp
--- a/source/test/ipfilterharness.cpp Wed Dec 31 12:55:54 2014 +0530
+++ b/source/test/ipfilterharness.cpp Fri Jan 02 13:51:47 2015 +0530
@@ -84,10 +84,10 @@
rand_srcStride = rand_width;
rand_width &= ~(min_size - 1);
- rand_width = Clip3(min_size, max_size, rand_width);
+ rand_width = x265_clip3(min_size, max_size, rand_width);
rand_height &= ~(min_size - 1);
- rand_height = Clip3(min_size, max_size, rand_height);
+ rand_height = x265_clip3(min_size, max_size, rand_height);
ref(pixel_test_buff[index],
rand_srcStride,
More information about the x265-devel
mailing list