Use an inline function instead of a macro for clipping which contains rand()

When using a macro, the macro parameters get evaluated
multiple times, which means that the rand() value compared
actually isn't the same that is used as return value.

This makes sure that clipping works as intended for the
random tests.
This commit is contained in:
Martin Storsjö 2014-12-16 11:08:19 +02:00
parent a9c2e1b431
commit 59fefbe7c7
3 changed files with 17 additions and 9 deletions

View File

@ -197,6 +197,14 @@ static inline uint8_t WelsClip1 (int32_t iX) {
#define WELS_CLIP3(iX, iY, iZ) ((iX) < (iY) ? (iY) : ((iX) > (iZ) ? (iZ) : (iX)))
#endif //WELS_CLIP3
template<typename T> T WelsClip3(T iX, T iY, T iZ) {
if (iX < iY)
return iY;
if (iX > iZ)
return iZ;
return iX;
}
/*
* Description: to check variable validation and return the specified result
* iResult: value to be checked

View File

@ -221,8 +221,8 @@ void EncodeDecodeTestAPI::InitialEncDec (int iWidth, int iHeight) {
void EncodeDecodeTestAPI::RandomParamExtCombination() {
param_.iPicWidth = WELS_CLIP3 ((((rand() % MAX_WIDTH) >> 1) + 1) << 1, 2, MAX_WIDTH);
param_.iPicHeight = WELS_CLIP3 ((((rand() % MAX_HEIGHT) >> 1) + 1) << 1, 2, MAX_HEIGHT);
param_.iPicWidth = WelsClip3 ((((rand() % MAX_WIDTH) >> 1) + 1) << 1, 2, MAX_WIDTH);
param_.iPicHeight = WelsClip3 ((((rand() % MAX_HEIGHT) >> 1) + 1) << 1, 2, MAX_HEIGHT);
param_.fMaxFrameRate = rand() % FRAME_RATE_RANGE + 0.5f;
param_.iUsageType = static_cast<EUsageType> (rand() % 2);
@ -271,8 +271,8 @@ void EncodeDecodeTestAPI::RandomParamExtCombination() {
//to do: profile and level id
//pSpatialLayer->uiProfileIdc = 0;
//pSpatialLayer->uiLevelIdc = 0;
pSpatialLayer->iVideoWidth = WELS_CLIP3 ((((rand() % MAX_WIDTH) >> 1) + 1) << 1, 2, MAX_WIDTH);
pSpatialLayer->iVideoHeight = WELS_CLIP3 ((((rand() % MAX_HEIGHT) >> 1) + 1) << 1, 2, MAX_HEIGHT);
pSpatialLayer->iVideoWidth = WelsClip3 ((((rand() % MAX_WIDTH) >> 1) + 1) << 1, 2, MAX_WIDTH);
pSpatialLayer->iVideoHeight = WelsClip3 ((((rand() % MAX_HEIGHT) >> 1) + 1) << 1, 2, MAX_HEIGHT);
pSpatialLayer->fFrameRate = rand() % FRAME_RATE_RANGE + 0.5f;
pSpatialLayer->iMaxSpatialBitrate = rand() % BIT_RATE_RANGE;
pSpatialLayer->iSpatialBitrate = rand() % BIT_RATE_RANGE;
@ -2057,10 +2057,10 @@ TEST_F (EncodeDecodeTestAPI, Engine_SVC_Switch_P) {
}
TEST_F (EncodeDecodeTestAPI, SetOptionEncParamExt) {
int iWidth = WELS_CLIP3 ((((rand() % MAX_WIDTH) >> 1) + 1) << 1, 2, MAX_WIDTH);
int iHeight = WELS_CLIP3 ((((rand() % MAX_HEIGHT) >> 1) + 1) << 1, 2, MAX_HEIGHT);
int iWidth = WelsClip3 ((((rand() % MAX_WIDTH) >> 1) + 1) << 1, 2, MAX_WIDTH);
int iHeight = WelsClip3 ((((rand() % MAX_HEIGHT) >> 1) + 1) << 1, 2, MAX_HEIGHT);
float fFrameRate = rand() + 0.5f;
int iEncFrameNum = WELS_CLIP3 ((rand() % ENCODE_FRAME_NUM) + 1, 1, ENCODE_FRAME_NUM);
int iEncFrameNum = WelsClip3 ((rand() % ENCODE_FRAME_NUM) + 1, 1, ENCODE_FRAME_NUM);
int iSpatialLayerNum = 4;
int iSliceNum = 1;
encoder_->GetDefaultParams (&param_);

View File

@ -26,7 +26,7 @@ if (iNum==0) { \
iTc[0] = iTc[1] = iTc[2] = iTc[3] = 25; \
pBase[0] = pRef[0] = 128; \
for (int i = 1; i < iWidth*iWidth; i++) { \
pBase[i] = pRef[i] = WELS_CLIP3( pBase[i-1] -16 + rand()%32, 0, 255 ); \
pBase[i] = pRef[i] = WelsClip3( pBase[i-1] -16 + rand()%32, 0, 255 ); \
} \
} else if (iNum==1) { \
iAlpha = 4; \
@ -34,7 +34,7 @@ if (iNum==0) { \
iTc[0] = iTc[1] = iTc[2] = iTc[3] = 9; \
pBase[0] = pRef[0] = 128; \
for (int i = 1; i < iWidth*iWidth; i++) { \
pBase[i] = pRef[i] = WELS_CLIP3( pBase[i-1] -4 + rand()%8, 0, 255 ); \
pBase[i] = pRef[i] = WelsClip3( pBase[i-1] -4 + rand()%8, 0, 255 ); \
} \
} else { \
iAlpha = rand() % 256; \