diff --git a/src/QZXingFilter.cpp b/src/QZXingFilter.cpp index 1082fd1..a506608 100644 --- a/src/QZXingFilter.cpp +++ b/src/QZXingFilter.cpp @@ -126,6 +126,11 @@ QVideoFrame QZXingFilterRunnable::run(QVideoFrame * input, const QVideoSurfaceFo return * input; } +static bool isRectValid(const QRect& rect) +{ + return rect.x() > 0 && rect.y() > 0 && rect.isValid(); +} + static QImage rgbDataToGrayscale(const uchar* data, const int width, const int height, const int alpha, const int red, const int green, const int blue, @@ -134,10 +139,10 @@ static QImage rgbDataToGrayscale(const uchar* data, const int width, const int h { const int stride = (alpha < 0) ? 3 : 4; - const int startX = captureRect.x(); - const int startY = captureRect.y(); - const int targetWidth = captureRect.isNull() ? width : captureRect.width(); - const int targetHeight = captureRect.isNull() ? height : captureRect.height(); + const int startX = isRectValid(captureRect) ? captureRect.x() : 0; + const int startY = isRectValid(captureRect) ? captureRect.y() : 0; + const int targetWidth = isRectValid(captureRect) ? captureRect.width() : width; + const int targetHeight = isRectValid(captureRect) ? captureRect.height() : height; const int endX = width - startX - targetWidth; const int skipX = (endX + startX) * stride;