Skip to content

Commit 630facd

Browse files
authored
fix division by zero bug when all frames are lossless (#430)
* fix division by zero when all frames are lossless * cleanup * remove unused variables
1 parent c518805 commit 630facd

File tree

1 file changed

+77
-67
lines changed

1 file changed

+77
-67
lines changed

source/Lib/EncoderLib/Analyze.h

Lines changed: 77 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -205,22 +205,26 @@ class Analyze
205205
}
206206

207207
//info.append(prnt("\t------------ " " ----------" " -------- " " -------- " " --------\n" ));
208-
info.append(prnt("vvenc [info]: Average: \t %8d %c " "%12.4lf " "%8.4lf",
209-
getNumPic(), cDelim,
210-
getBits() * dScale,
211-
getPsnr(COMP_Y) / getNumPicLossy(COMP_Y) ) );
208+
info.append(prnt("vvenc [info]: Average: \t %8d %c " "%12.4lf ", getNumPic(), cDelim, getBits() * dScale ));
209+
info.append( getNumPicLossy(COMP_Y) ? prnt("%8.4lf ", getPsnr(COMP_Y ) / getNumPicLossy(COMP_Y)) : prnt(" inf%6s", " " ) );
212210

213211
if (printHexPsnr)
214212
{
215-
double dPsnr;
216-
uint64_t xPsnr;
217-
dPsnr = getPsnr(COMP_Y) / getNumPicLossy(COMP_Y);
218-
219-
std::copy(reinterpret_cast<uint8_t *>(&dPsnr),
220-
reinterpret_cast<uint8_t *>(&dPsnr) + sizeof(dPsnr),
221-
reinterpret_cast<uint8_t *>(&xPsnr));
222-
223-
info.append(prnt( " %16" PRIx64 " ", xPsnr ));
213+
if( getNumPicLossy(COMP_Y) )
214+
{
215+
double dPsnr;
216+
uint64_t xPsnr;
217+
dPsnr = getPsnr(COMP_Y) / getNumPicLossy(COMP_Y);
218+
219+
std::copy(reinterpret_cast<uint8_t *>(&dPsnr),
220+
reinterpret_cast<uint8_t *>(&dPsnr) + sizeof(dPsnr),
221+
reinterpret_cast<uint8_t *>(&xPsnr));
222+
info.append(prnt( " %16" PRIx64 " ", xPsnr ));
223+
}
224+
else
225+
{
226+
info.append(prnt( " inf%14s", " " ));
227+
}
224228
}
225229

226230
if (printSequenceMSE)
@@ -232,10 +236,8 @@ class Analyze
232236
info.append(prnt("\n"));
233237
}
234238

235-
info.append(prnt("vvenc [info]: From MSE:\t %8d %c " "%12.4lf " "%8.4lf\n",
236-
getNumPic(), cDelim,
237-
getBits() * dScale,
238-
MSEBasedSNR[COMP_Y] ));
239+
info.append(prnt("vvenc [info]: From MSE:\t %8d %c " "%12.4lf ", getNumPic(), cDelim, getBits() * dScale));
240+
info.append( MSEBasedSNR[COMP_Y] != MAX_DOUBLE ? prnt("%8.4lf\n" , MSEBasedSNR[COMP_Y]) : prnt(" inf%6s\n", " " ) );
239241
}
240242
else
241243
{
@@ -256,22 +258,27 @@ class Analyze
256258
}
257259

258260
//info.append(prnt("\t------------ " " ----------" " -------- " " -------- " " --------\n" ));
259-
info.append(prnt("vvenc[info]:\t %8d %c " "%12.4lf " "%8.4lf",
260-
getNumPic(), cDelim,
261-
getBits() * dScale,
262-
getPsnr(COMP_Y) / getNumPicLossy(COMP_Y) ) );
261+
info.append(prnt("vvenc[info]:\t %8d %c " "%12.4lf ", getNumPic(), cDelim, getBits() * dScale));
262+
info.append( getNumPicLossy(COMP_Y) ? prnt("%8.4lf ", getPsnr(COMP_Y ) / getNumPicLossy(COMP_Y)) : prnt(" inf%6s", " " ) );
263263

264264
if (printHexPsnr)
265265
{
266-
double dPsnr;
267-
uint64_t xPsnr;
268-
dPsnr = getPsnr(COMP_Y) / getNumPicLossy(COMP_Y);
266+
if( getNumPicLossy(COMP_Y) )
267+
{
268+
double dPsnr;
269+
uint64_t xPsnr;
270+
dPsnr = getPsnr(COMP_Y) / getNumPicLossy(COMP_Y);
269271

270-
std::copy(reinterpret_cast<uint8_t *>(&dPsnr),
271-
reinterpret_cast<uint8_t *>(&dPsnr) + sizeof(dPsnr),
272-
reinterpret_cast<uint8_t *>(&xPsnr));
272+
std::copy(reinterpret_cast<uint8_t *>(&dPsnr),
273+
reinterpret_cast<uint8_t *>(&dPsnr) + sizeof(dPsnr),
274+
reinterpret_cast<uint8_t *>(&xPsnr));
273275

274-
info.append(prnt(" %16" PRIx64 " ", xPsnr));
276+
info.append(prnt( " %16" PRIx64 " ", xPsnr ));
277+
}
278+
else
279+
{
280+
info.append(prnt( " inf%14s", " " ));
281+
}
275282
}
276283

277284
if (printSequenceMSE)
@@ -317,27 +324,30 @@ class Analyze
317324
}
318325

319326
//info.append(prnt("\t------------ " " ----------" " -------- " " -------- " " --------\n" ));
320-
info.append(prnt("vvenc [info]: Average: \t %8d %c " "%12.4lf " "%8.4lf " "%8.4lf " "%8.4lf " "%8.4lf",
321-
getNumPic(), cDelim,
322-
getBits() * dScale,
323-
getPsnr(COMP_Y ) / getNumPicLossy(COMP_Y),
324-
getPsnr(COMP_Cb) / getNumPicLossy(COMP_Cb),
325-
getPsnr(COMP_Cr) / getNumPicLossy(COMP_Cr),
326-
PSNRyuv ));
327+
info.append(prnt("vvenc [info]: Average: \t %8d %c " "%12.4lf ",getNumPic(), cDelim, getBits() * dScale ));
328+
info.append( getNumPicLossy(COMP_Y) ? prnt("%8.4lf ", getPsnr(COMP_Y ) / getNumPicLossy(COMP_Y)) : prnt(" inf%6s", " " ) );
329+
info.append( getNumPicLossy(COMP_Cb)? prnt("%8.4lf ", getPsnr(COMP_Cb ) / getNumPicLossy(COMP_Cb)) : prnt(" inf%6s", " " ) );
330+
info.append( getNumPicLossy(COMP_Cr)? prnt("%8.4lf ", getPsnr(COMP_Cr ) / getNumPicLossy(COMP_Cr)) : prnt(" inf%6s", " " ) );
331+
info.append( PSNRyuv != MAX_DOUBLE ? prnt("%8.4lf" , PSNRyuv) : prnt(" inf%6s", " " ) );
327332

328333
if (printHexPsnr)
329334
{
330-
double dPsnr[MAX_NUM_COMP];
331-
uint64_t xPsnr[MAX_NUM_COMP];
332335
for (int i = 0; i < MAX_NUM_COMP; i++)
333336
{
334-
dPsnr[i] = getPsnr((ComponentID)i) / getNumPicLossy((ComponentID)i);
335-
336-
std::copy(reinterpret_cast<uint8_t *>(&dPsnr[i]),
337-
reinterpret_cast<uint8_t *>(&dPsnr[i]) + sizeof(dPsnr[i]),
338-
reinterpret_cast<uint8_t *>(&xPsnr[i]));
337+
if( getNumPicLossy((ComponentID)i) )
338+
{
339+
double dPsnr = getPsnr((ComponentID)i) / getNumPicLossy((ComponentID)i);
340+
uint64_t xPsnr;
341+
std::copy(reinterpret_cast<uint8_t *>(&dPsnr),
342+
reinterpret_cast<uint8_t *>(&dPsnr) + sizeof(dPsnr),
343+
reinterpret_cast<uint8_t *>(&xPsnr));
344+
info.append(prnt( " %16" PRIx64 " ", xPsnr ));
345+
}
346+
else
347+
{
348+
info.append(prnt( " inf%14s", " " ));
349+
}
339350
}
340-
info.append(prnt(" %16" PRIx64 " %16" PRIx64 " %16" PRIx64, xPsnr[COMP_Y], xPsnr[COMP_Cb], xPsnr[COMP_Cr]));
341351
}
342352

343353
if (printSequenceMSE)
@@ -357,13 +367,11 @@ class Analyze
357367
info.append(prnt("\n"));
358368
}
359369

360-
info.append(prnt("vvenc [info]: From MSE:\t %8d %c " "%12.4lf " "%8.4lf " "%8.4lf " "%8.4lf " "%8.4lf\n",
361-
getNumPic(), cDelim,
362-
getBits() * dScale,
363-
MSEBasedSNR[COMP_Y ],
364-
MSEBasedSNR[COMP_Cb],
365-
MSEBasedSNR[COMP_Cr],
366-
PSNRyuv ));
370+
info.append(prnt("vvenc [info]: From MSE:\t %8d %c " "%12.4lf ", getNumPic(), cDelim, getBits() * dScale ));
371+
info.append( MSEBasedSNR[COMP_Y] != MAX_DOUBLE ? prnt("%8.4lf" , MSEBasedSNR[COMP_Y]) : prnt(" inf%6s", " " ) );
372+
info.append( MSEBasedSNR[COMP_Cb] != MAX_DOUBLE ? prnt("%8.4lf" , MSEBasedSNR[COMP_Cb]) : prnt(" inf%6s", " " ) );
373+
info.append( MSEBasedSNR[COMP_Cr] != MAX_DOUBLE ? prnt("%8.4lf" , MSEBasedSNR[COMP_Cr]) : prnt(" inf%6s", " " ) );
374+
info.append( PSNRyuv != MAX_DOUBLE ? prnt("%8.4lf\n", PSNRyuv) : prnt(" inf%6s\n", " " ) );
367375
}
368376
else
369377
{
@@ -387,28 +395,30 @@ class Analyze
387395
}
388396

389397
//info.append(prnt("\t------------ " " ----------" " -------- " " -------- " " --------\n" ));
390-
info.append(prnt("vvenc [info]:\t %8d %c " "%12.4lf " "%8.4lf " "%8.4lf " "%8.4lf " "%8.4lf",
391-
getNumPic(), cDelim,
392-
getBits() * dScale,
393-
getPsnr(COMP_Y ) / getNumPicLossy(COMP_Y),
394-
getPsnr(COMP_Cb) / getNumPicLossy(COMP_Cb),
395-
getPsnr(COMP_Cr) / getNumPicLossy(COMP_Cr),
396-
PSNRyuv ));
397-
398+
info.append(prnt("vvenc [info]:\t %8d %c " "%12.4lf ", getNumPic(), cDelim, getBits() * dScale ));
399+
info.append( getNumPicLossy(COMP_Y) ? prnt("%8.4lf ", getPsnr(COMP_Y ) / getNumPicLossy(COMP_Y)) : prnt(" inf%6s", " " ) );
400+
info.append( getNumPicLossy(COMP_Cb)? prnt("%8.4lf ", getPsnr(COMP_Cb ) / getNumPicLossy(COMP_Cb)) : prnt(" inf%6s", " " ) );
401+
info.append( getNumPicLossy(COMP_Cr)? prnt("%8.4lf ", getPsnr(COMP_Cr ) / getNumPicLossy(COMP_Cr)) : prnt(" inf%6s", " " ) );
402+
info.append( PSNRyuv != MAX_DOUBLE ? prnt("%8.4lf" , PSNRyuv) : prnt(" inf%6s", " " ) );
398403

399404
if (printHexPsnr)
400405
{
401-
double dPsnr[MAX_NUM_COMP];
402-
uint64_t xPsnr[MAX_NUM_COMP];
403406
for (int i = 0; i < MAX_NUM_COMP; i++)
404407
{
405-
dPsnr[i] = getPsnr((ComponentID)i) / getNumPicLossy((ComponentID)i);
406-
407-
std::copy(reinterpret_cast<uint8_t *>(&dPsnr[i]),
408-
reinterpret_cast<uint8_t *>(&dPsnr[i]) + sizeof(dPsnr[i]),
409-
reinterpret_cast<uint8_t *>(&xPsnr[i]));
408+
if( getNumPicLossy((ComponentID)i) )
409+
{
410+
double dPsnr = getPsnr((ComponentID)i) / getNumPicLossy((ComponentID)i);
411+
uint64_t xPsnr;
412+
std::copy(reinterpret_cast<uint8_t *>(&dPsnr),
413+
reinterpret_cast<uint8_t *>(&dPsnr) + sizeof(dPsnr),
414+
reinterpret_cast<uint8_t *>(&xPsnr));
415+
info.append(prnt( " %16" PRIx64 " ", xPsnr ));
416+
}
417+
else
418+
{
419+
info.append(prnt( " inf%14s", " " ));
420+
}
410421
}
411-
info.append(prnt(" %16" PRIx64 " %16" PRIx64 " %16" PRIx64 , xPsnr[COMP_Y], xPsnr[COMP_Cb], xPsnr[COMP_Cr]));
412422
}
413423
if (printSequenceMSE)
414424
{
@@ -420,7 +430,7 @@ class Analyze
420430
}
421431
if (printLosslessPlanes)
422432
{
423-
info.append(prnt(" %10d " "%10d " "%10d\n", getLosslessFrames(COMP_Y), getLosslessFrames(COMP_Cb), getLosslessFrames(COMP_Cr) ));
433+
info.append(prnt(" %8d " " %8d " " %8d \n", getLosslessFrames(COMP_Y), getLosslessFrames(COMP_Cb), getLosslessFrames(COMP_Cr) ));
424434
}
425435
else
426436
{

0 commit comments

Comments
 (0)