MCPcopy Create free account
hub / github.com/IENT/YUView / calculateDifference

Method calculateDifference

YUViewLib/src/video/FrameHandler.cpp:372–440  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

370}
371
372QImage FrameHandler::calculateDifference(FrameHandler *item2,
373 const int,
374 const int,
375 QList<InfoItem> &differenceInfoList,
376 const int amplificationFactor,
377 const bool markDifference)
378{
379 auto width = std::min(frameSize.width, item2->frameSize.width);
380 auto height = std::min(frameSize.height, item2->frameSize.height);
381
382 QImage diffImg(width, height, functionsGui::platformImageFormat(false));
383
384 // Also calculate the MSE while we're at it (R,G,B)
385 int64_t mseAdd[3] = {0, 0, 0};
386
387 for (unsigned y = 0; y < height; y++)
388 {
389 for (unsigned x = 0; x < width; x++)
390 {
391 auto pixel1 = getPixelVal(x, y);
392 auto pixel2 = item2->getPixelVal(x, y);
393
394 int dR = int(qRed(pixel1)) - int(qRed(pixel2));
395 int dG = int(qGreen(pixel1)) - int(qGreen(pixel2));
396 int dB = int(qBlue(pixel1)) - int(qBlue(pixel2));
397
398 int r, g, b;
399 if (markDifference)
400 {
401 r = (dR != 0) ? 255 : 0;
402 g = (dG != 0) ? 255 : 0;
403 b = (dB != 0) ? 255 : 0;
404 }
405 else if (amplificationFactor != 1)
406 {
407 r = functions::clip(128 + dR * amplificationFactor, 0, 255);
408 g = functions::clip(128 + dG * amplificationFactor, 0, 255);
409 b = functions::clip(128 + dB * amplificationFactor, 0, 255);
410 }
411 else
412 {
413 r = functions::clip(128 + dR, 0, 255);
414 g = functions::clip(128 + dG, 0, 255);
415 b = functions::clip(128 + dB, 0, 255);
416 }
417
418 mseAdd[0] += dR * dR;
419 mseAdd[1] += dG * dG;
420 mseAdd[2] += dB * dB;
421
422 auto val = qRgb(r, g, b);
423 diffImg.setPixel(x, y, val);
424 }
425 }
426
427 differenceInfoList.append(InfoItem("Difference Type", "RGB"));
428
429 double mse[4];

Callers 1

loadFrameDifferenceMethod · 0.45

Calls 5

platformImageFormatFunction · 0.85
clipFunction · 0.85
InfoItemClass · 0.85
appendMethod · 0.80
getPixelValMethod · 0.45

Tested by

no test coverage detected